Line data Source code
1 : /*
2 : * Copyright (C) 2023 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 : import client from "../client";
7 :
8 : import { get_fstab_config } from "../filesystem/utils.jsx";
9 :
10 : import { make_partition_table_page } from "../partitions/partition-table.jsx";
11 : import { make_legacy_vdo_page } from "../legacy-vdo/legacy-vdo.jsx";
12 :
13 : import { make_unrecognized_data_card } from "./unrecognized-data.jsx";
14 : import { make_unformatted_data_card } from "./unformatted-data.jsx";
15 : import { make_locked_encrypted_data_card } from "../crypto/locked-encrypted-data.jsx";
16 : import { make_filesystem_card } from "../filesystem/filesystem.jsx";
17 : import { make_lvm2_physical_volume_card } from "../lvm2/physical-volume.jsx";
18 : import { make_mdraid_disk_card } from "../mdraid/mdraid-disk.jsx";
19 : import { make_stratis_blockdev_card } from "../stratis/blockdev.jsx";
20 : import { make_swap_card } from "../swap/swap.jsx";
21 : import { make_encryption_card } from "../crypto/encryption.jsx";
22 : import { make_btrfs_device_card } from "../btrfs/device.jsx";
23 : import { make_btrfs_filesystem_card } from "../btrfs/filesystem.jsx";
24 : import { make_btrfs_subvolume_pages } from "../btrfs/subvolume.jsx";
25 :
26 : import { new_page } from "../pages.jsx";
27 : import { register_available_block_space } from "../utils";
28 :
29 : /* CARD must have page_name, page_location, and page_size set.
30 : */
31 :
32 112 : export function make_block_page(parent, block, card, options) {
33 112 : let is_crypto = block.IdUsage == 'crypto';
34 34 : let content_block = is_crypto ? client.blocks_cleartext[block.path] : block;
35 34 : const fstab_config = get_fstab_config(content_block || block, true);
36 :
37 112 : const block_stratis_blockdev = client.blocks_stratis_blockdev[block.path];
38 112 : const block_stratis_stopped_pool = client.blocks_stratis_stopped_pool[block.path];
39 112 : const legacy_vdo = client.legacy_vdo_overlay.find_by_backing_block(block);
40 :
41 56 : const is_stratis = ((content_block && content_block.IdUsage == "raid" && content_block.IdType == "stratis") ||
42 16 : (block_stratis_blockdev && client.stratis_pools[block_stratis_blockdev.Pool]) ||
43 112 : block_stratis_stopped_pool);
44 :
45 112 : const is_btrfs = (fstab_config.length > 0 &&
46 105 : (fstab_config[2].indexOf("subvol=") >= 0 || fstab_config[2].indexOf("subvolid=") >= 0));
47 :
48 112 : const block_btrfs_blockdev = content_block && client.blocks_fsys_btrfs[content_block.path];
49 104 : const single_device_volume = block_btrfs_blockdev && block_btrfs_blockdev.data.num_devices === 1;
50 :
51 105 : if (client.blocks_ptable[block.path]) {
52 105 : make_partition_table_page(parent, block, card, options && options.partitionable);
53 105 : return;
54 105 : }
55 :
56 13 : if (legacy_vdo) {
57 13 : make_legacy_vdo_page(parent, legacy_vdo, block, card);
58 13 : return;
59 13 : }
60 :
61 : // Adjust for encryption leaking out of Stratis
62 14 : if (is_crypto && is_stratis) {
63 14 : is_crypto = false;
64 14 : content_block = block;
65 14 : }
66 :
67 112 : if (is_crypto)
68 34 : card = make_encryption_card(card, block);
69 :
70 34 : if (!content_block) {
71 13 : if (!is_crypto) {
72 : // can not happen unless there is a bug in the code above.
73 13 : console.error("Assertion failure: is_crypto == false");
74 13 : }
75 23 : if (fstab_config.length > 0 && !is_btrfs) {
76 23 : card = make_filesystem_card(card, block, null, fstab_config);
77 23 : } else {
78 34 : card = make_locked_encrypted_data_card(card, block);
79 34 : }
80 34 : } else {
81 112 : const is_filesystem = content_block.IdUsage == 'filesystem';
82 112 : const block_pvol = client.blocks_pvol[content_block.path];
83 112 : const block_swap = client.blocks_swap[content_block.path];
84 :
85 104 : if (block_btrfs_blockdev) {
86 104 : if (single_device_volume)
87 13 : card = make_btrfs_filesystem_card(card, block, content_block);
88 : else
89 14 : card = make_btrfs_device_card(card, block, content_block, block_btrfs_blockdev);
90 103 : } else if (is_filesystem) {
91 107 : card = make_filesystem_card(card, block, content_block, fstab_config);
92 54 : } else if ((content_block.IdUsage == "raid" && content_block.IdType == "LVM2_member") ||
93 20 : (block_pvol && client.vgroups[block_pvol.VolumeGroup])) {
94 38 : card = make_lvm2_physical_volume_card(card, block, content_block);
95 15 : } else if (is_stratis) {
96 27 : card = make_stratis_blockdev_card(card, block, content_block);
97 27 : } else if ((content_block.IdUsage == "raid") ||
98 19 : (client.mdraids[content_block.MDRaidMember])) {
99 19 : card = make_mdraid_disk_card(card, block, content_block);
100 19 : } else if (block_swap ||
101 16 : (content_block.IdUsage == "other" && content_block.IdType == "swap")) {
102 16 : card = make_swap_card(card, block, content_block);
103 16 : } else if (!content_block.IdUsage) {
104 112 : if (!block.HintIgnore)
105 100 : register_available_block_space(client, content_block);
106 112 : card = make_unformatted_data_card(card, block, content_block);
107 15 : } else {
108 15 : card = make_unrecognized_data_card(card, block, content_block);
109 15 : }
110 112 : }
111 :
112 112 : if (card) {
113 112 : const page = new_page(parent, card);
114 104 : if (block_btrfs_blockdev && single_device_volume)
115 103 : make_btrfs_subvolume_pages(page, block_btrfs_blockdev);
116 112 : return page;
117 112 : }
118 112 : }
|