LCOV - code coverage report
Current view: top level - pkg/storaged/block - create-pages.jsx Coverage Total Hit
Test: cockpit Lines: 100.0 % 73 73
Test Date: 2026-07-17 07:33:01

            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           33 :     let content_block = is_crypto ? client.blocks_cleartext[block.path] : block;
      35           33 :     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           55 :     const is_stratis = ((content_block && content_block.IdUsage == "raid" && content_block.IdType == "stratis") ||
      42           14 :                         (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           12 :     if (legacy_vdo) {
      57           12 :         make_legacy_vdo_page(parent, legacy_vdo, block, card);
      58           12 :         return;
      59           12 :     }
      60              : 
      61              :     // Adjust for encryption leaking out of Stratis
      62           13 :     if (is_crypto && is_stratis) {
      63           13 :         is_crypto = false;
      64           13 :         content_block = block;
      65           13 :     }
      66              : 
      67          112 :     if (is_crypto)
      68           33 :         card = make_encryption_card(card, block);
      69              : 
      70           33 :     if (!content_block) {
      71           12 :         if (!is_crypto) {
      72              :             // can not happen unless there is a bug in the code above.
      73           12 :             console.error("Assertion failure: is_crypto == false");
      74           12 :         }
      75           22 :         if (fstab_config.length > 0 && !is_btrfs) {
      76           22 :             card = make_filesystem_card(card, block, null, fstab_config);
      77           22 :         } else {
      78           33 :             card = make_locked_encrypted_data_card(card, block);
      79           33 :         }
      80           33 :     } 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           12 :                 card = make_btrfs_filesystem_card(card, block, content_block);
      88              :             else
      89           13 :                 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           53 :         } else if ((content_block.IdUsage == "raid" && content_block.IdType == "LVM2_member") ||
      93           16 :                    (block_pvol && client.vgroups[block_pvol.VolumeGroup])) {
      94           37 :             card = make_lvm2_physical_volume_card(card, block, content_block);
      95           14 :         } else if (is_stratis) {
      96           26 :             card = make_stratis_blockdev_card(card, block, content_block);
      97           26 :         } else if ((content_block.IdUsage == "raid") ||
      98           18 :                    (client.mdraids[content_block.MDRaidMember])) {
      99           18 :             card = make_mdraid_disk_card(card, block, content_block);
     100           18 :         } else if (block_swap ||
     101           15 :                    (content_block.IdUsage == "other" && content_block.IdType == "swap")) {
     102           15 :             card = make_swap_card(card, block, content_block);
     103           15 :         } else if (!content_block.IdUsage) {
     104          112 :             if (!block.HintIgnore)
     105           99 :                 register_available_block_space(client, content_block);
     106          112 :             card = make_unformatted_data_card(card, block, content_block);
     107           14 :         } else {
     108           14 :             card = make_unrecognized_data_card(card, block, content_block);
     109           14 :         }
     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 : }
        

Generated by: LCOV version 2.0-1