| 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 |
export function make_block_page(parent, block, card, options) { |
| 33 |
let is_crypto = block.IdUsage == 'crypto'; |
| 34 |
let content_block = is_crypto ? client.blocks_cleartext[block.path] : block; |
| 35 |
const fstab_config = get_fstab_config(content_block || block, true); |
| 36 |
|
| 37 |
const block_stratis_blockdev = client.blocks_stratis_blockdev[block.path]; |
| 38 |
const block_stratis_stopped_pool = client.blocks_stratis_stopped_pool[block.path]; |
| 39 |
const legacy_vdo = client.legacy_vdo_overlay.find_by_backing_block(block); |
| 40 |
|
| 41 |
const is_stratis = ((content_block && content_block.IdUsage == "raid" && content_block.IdType == "stratis") || |
| 42 |
(block_stratis_blockdev && client.stratis_pools[block_stratis_blockdev.Pool]) || |
| 43 |
block_stratis_stopped_pool); |
| 44 |
|
| 45 |
const is_btrfs = (fstab_config.length > 0 && |
| 46 |
(fstab_config[2].indexOf("subvol=") >= 0 || fstab_config[2].indexOf("subvolid=") >= 0)); |
| 47 |
|
| 48 |
const block_btrfs_blockdev = content_block && client.blocks_fsys_btrfs[content_block.path]; |
| 49 |
const single_device_volume = block_btrfs_blockdev && block_btrfs_blockdev.data.num_devices === 1; |
| 50 |
|
| 51 |
if (client.blocks_ptable[block.path]) { |
| 52 |
make_partition_table_page(parent, block, card, options && options.partitionable); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
if (legacy_vdo) { |
| 57 |
make_legacy_vdo_page(parent, legacy_vdo, block, card); |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
// Adjust for encryption leaking out of Stratis |
| 62 |
if (is_crypto && is_stratis) { |
| 63 |
is_crypto = false; |
| 64 |
content_block = block; |
| 65 |
} |
| 66 |
|
| 67 |
if (is_crypto) |
| 68 |
card = make_encryption_card(card, block); |
| 69 |
|
| 70 |
if (!content_block) { |
| 71 |
if (!is_crypto) { |
| 72 |
// can not happen unless there is a bug in the code above. |
| 73 |
console.error("Assertion failure: is_crypto == false"); |
| 74 |
} |
| 75 |
if (fstab_config.length > 0 && !is_btrfs) { |
| 76 |
card = make_filesystem_card(card, block, null, fstab_config); |
| 77 |
} else { |
| 78 |
card = make_locked_encrypted_data_card(card, block); |
| 79 |
} |
| 80 |
} else { |
| 81 |
const is_filesystem = content_block.IdUsage == 'filesystem'; |
| 82 |
const block_pvol = client.blocks_pvol[content_block.path]; |
| 83 |
const block_swap = client.blocks_swap[content_block.path]; |
| 84 |
|
| 85 |
if (block_btrfs_blockdev) { |
| 86 |
if (single_device_volume) |
| 87 |
card = make_btrfs_filesystem_card(card, block, content_block); |
| 88 |
else |
| 89 |
card = make_btrfs_device_card(card, block, content_block, block_btrfs_blockdev); |
| 90 |
} else if (is_filesystem) { |
| 91 |
card = make_filesystem_card(card, block, content_block, fstab_config); |
| 92 |
} else if ((content_block.IdUsage == "raid" && content_block.IdType == "LVM2_member") || |
| 93 |
(block_pvol && client.vgroups[block_pvol.VolumeGroup])) { |
| 94 |
card = make_lvm2_physical_volume_card(card, block, content_block); |
| 95 |
} else if (is_stratis) { |
| 96 |
card = make_stratis_blockdev_card(card, block, content_block); |
| 97 |
} else if ((content_block.IdUsage == "raid") || |
| 98 |
(client.mdraids[content_block.MDRaidMember])) { |
| 99 |
card = make_mdraid_disk_card(card, block, content_block); |
| 100 |
} else if (block_swap || |
| 101 |
(content_block.IdUsage == "other" && content_block.IdType == "swap")) { |
| 102 |
card = make_swap_card(card, block, content_block); |
| 103 |
} else if (!content_block.IdUsage) { |
| 104 |
if (!block.HintIgnore) |
| 105 |
register_available_block_space(client, content_block); |
| 106 |
card = make_unformatted_data_card(card, block, content_block); |
| 107 |
} else { |
| 108 |
card = make_unrecognized_data_card(card, block, content_block); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
if (card) { |
| 113 |
const page = new_page(parent, card); |
| 114 |
if (block_btrfs_blockdev && single_device_volume) |
| 115 |
make_btrfs_subvolume_pages(page, block_btrfs_blockdev); |
| 116 |
return page; |
| 117 |
} |
| 118 |
} |