Skip to content

Commit dbe892f

Browse files
committed
storage: Detect partition tables in unsupported places
These likely belong to virtual machines and we shouldn't touch them. See https://bugzilla.redhat.com/show_bug.cgi?id=2364699
1 parent 7da4d37 commit dbe892f

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

pkg/storaged/block/create-pages.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ import { make_btrfs_filesystem_card } from "../btrfs/filesystem.jsx";
3838
import { make_btrfs_subvolume_pages } from "../btrfs/subvolume.jsx";
3939

4040
import { new_page } from "../pages.jsx";
41+
import { register_available_block_space } from "../utils";
4142

4243
/* CARD must have page_name, page_location, and page_size set.
4344
*/
4445

45-
export function make_block_page(parent, block, card) {
46+
export function make_block_page(parent, block, card, options) {
4647
let is_crypto = block.IdUsage == 'crypto';
4748
let content_block = is_crypto ? client.blocks_cleartext[block.path] : block;
4849
const fstab_config = get_fstab_config(content_block || block, true);
@@ -62,7 +63,7 @@ export function make_block_page(parent, block, card) {
6263
const single_device_volume = block_btrfs_blockdev && block_btrfs_blockdev.data.num_devices === 1;
6364

6465
if (client.blocks_ptable[block.path]) {
65-
make_partition_table_page(parent, block, card);
66+
make_partition_table_page(parent, block, card, options && options.partitionable);
6667
return;
6768
}
6869

pkg/storaged/block/other.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function make_other_page(parent, block) {
4949
actions: partitionable_block_actions(block),
5050
});
5151

52-
make_block_page(parent, block, other_card);
52+
make_block_page(parent, block, other_card, { partitionable: true });
5353
}
5454

5555
const OtherCard = ({ card, block }) => {

pkg/storaged/drive/drive.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function make_drive_page(parent, drive) {
105105
}
106106

107107
if (block.Size > 0) {
108-
make_block_page(parent, block, card);
108+
make_block_page(parent, block, card, { partitionable: true });
109109
} else {
110110
new_page(parent, card);
111111
}

pkg/storaged/mdraid/mdraid.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export function make_mdraid_page(parent, mdraid) {
247247
if (!block) {
248248
new_page(parent, mdraid_card);
249249
} else
250-
make_block_page(parent, block, mdraid_card);
250+
make_block_page(parent, block, mdraid_card, { partitionable: true });
251251
}
252252

253253
const MDRaidCard = ({ card, mdraid, block }) => {

pkg/storaged/partitions/partition-table.jsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import cockpit from "cockpit";
2121
import React from "react";
2222
import client from "../client";
2323

24+
import { Alert } from "@patternfly/react-core/dist/esm/components/Alert/index.js";
25+
import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
26+
2427
import { get_partitions, register_available_free_space } from "../utils.js";
2528
import { StorageCard, ChildrenTable, new_page, new_card } from "../pages.jsx";
2629
import { format_dialog } from "../block/format-dialog.jsx";
@@ -84,20 +87,21 @@ function make_partition_pages(parent, block) {
8487
block_ptable.Type == 'dos');
8588
}
8689

87-
export function make_partition_table_page(parent, block, next_card) {
90+
export function make_partition_table_page(parent, block, next_card, partitionable) {
8891
const block_ptable = client.blocks_ptable[block.path];
8992

9093
const parts_card = new_card({
9194
title: (block_ptable.Type
9295
? cockpit.format(_("$0 partitions"), block_ptable.Type.toLocaleUpperCase())
9396
: _("Partitions")),
9497
next: next_card,
95-
component: PartitionsCard,
98+
component: partitionable ? PartitionsCard : UnexpectedPartitionsCard,
9699
props: { },
97100
});
98101

99102
const p = new_page(parent, parts_card, { sorted: false });
100-
make_partition_pages(p, block);
103+
if (partitionable)
104+
make_partition_pages(p, block);
101105
}
102106

103107
const PartitionsCard = ({ card }) => {
@@ -110,3 +114,15 @@ const PartitionsCard = ({ card }) => {
110114
</StorageCard>
111115
);
112116
};
117+
118+
const UnexpectedPartitionsCard = ({ card }) => {
119+
return (
120+
<StorageCard card={card}>
121+
<CardBody>
122+
<Alert isInline isPlain variant="info" title={_("Unexpected partitions")}>
123+
<p>{_("Partitions are not supported on this block device. If it is used as a disk for a virtual machine, the partitions must be managed by the operating system inside the virtual machine.")}</p>
124+
</Alert>
125+
</CardBody>
126+
</StorageCard>
127+
);
128+
};

test/verify/check-storage-lvm2

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,31 @@ class TestStorageLvm2(storagelib.StorageCase):
847847
b.wait_in_text(self.card_desc("LVM2 logical volume", "Physical volumes"), bn(disk))
848848
b.wait_in_text(self.card_desc("LVM2 logical volume", "Physical volumes"), bn(disk2))
849849

850+
def testUnsupportedPartitions(self):
851+
b = self.browser
852+
m = self.machine
853+
854+
self.login_and_go("/storage")
855+
856+
dev_1 = self.add_ram_disk(100)
857+
m.execute(f"vgcreate vgroup0 {dev_1}")
858+
self.addCleanupVG("vgroup0")
859+
m.execute("lvcreate vgroup0 -n lvol0 -l100%FREE")
860+
m.execute("parted /dev/vgroup0/lvol0 -s mktable gpt mkpart primary ext2 1M 50M")
861+
self.addCleanup(m.execute, "parted /dev/vgroup0/lvol0 -s mktable gpt; wipefs -a /dev/vgroup0/lvol0")
862+
863+
b.wait_text(self.card_row_col("Storage", row_name="lvol0", col_index=3), "GPT partitions")
864+
self.click_card_row("Storage", name="lvol0")
865+
b.wait_in_text(self.card("GPT partitions"), "Partitions are not supported on this block device.")
866+
867+
# Neither the partition nor the free space should be offered
868+
# for creating new things.
869+
870+
b.click(self.card_parent_link())
871+
b.click(self.card_parent_link())
872+
self.click_devices_dropdown("Create LVM2 volume group")
873+
b.wait_in_text("#dialog", "No disks are available")
874+
850875

851876
class TestStorageLvm2Destructive(storagelib.StorageCase):
852877

0 commit comments

Comments
 (0)