Skip to content

Commit a98db30

Browse files
committed
storage: Detect partition tables in supported places
These likely belong to virtual machines and we shouldn't touch them.
1 parent 09ebd7d commit a98db30

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

pkg/storaged/block/create-pages.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { new_page } from "../pages.jsx";
4242
/* CARD must have page_name, page_location, and page_size set.
4343
*/
4444

45-
export function make_block_page(parent, block, card) {
45+
export function make_block_page(parent, block, card, options) {
4646
let is_crypto = block.IdUsage == 'crypto';
4747
let content_block = is_crypto ? client.blocks_cleartext[block.path] : block;
4848
const fstab_config = get_fstab_config(content_block || block, true);
@@ -62,7 +62,7 @@ export function make_block_page(parent, block, card) {
6262
const single_device_volume = block_btrfs_blockdev && block_btrfs_blockdev.data.num_devices === 1;
6363

6464
if (client.blocks_ptable[block.path]) {
65-
make_partition_table_page(parent, block, card);
65+
make_partition_table_page(parent, block, card, options && options.partitionable);
6666
return;
6767
}
6868

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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import cockpit from "cockpit";
2121
import React from "react";
2222
import client from "../client";
2323

24+
import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
25+
2426
import { get_partitions } from "../utils.js";
2527
import { StorageCard, ChildrenTable, new_page, new_card } from "../pages.jsx";
2628
import { format_dialog } from "../block/format-dialog.jsx";
@@ -83,20 +85,21 @@ function make_partition_pages(parent, block) {
8385
block_ptable.Type == 'dos');
8486
}
8587

86-
export function make_partition_table_page(parent, block, next_card) {
88+
export function make_partition_table_page(parent, block, next_card, partitionable) {
8789
const block_ptable = client.blocks_ptable[block.path];
8890

8991
const parts_card = new_card({
9092
title: (block_ptable.Type
9193
? cockpit.format(_("$0 partitions"), block_ptable.Type.toLocaleUpperCase())
9294
: _("Partitions")),
9395
next: next_card,
94-
component: PartitionsCard,
96+
component: partitionable ? PartitionsCard : UnexpectedPartitionsCard,
9597
props: { },
9698
});
9799

98100
const p = new_page(parent, parts_card, { sorted: false });
99-
make_partition_pages(p, block);
101+
if (partitionable)
102+
make_partition_pages(p, block);
100103
}
101104

102105
const PartitionsCard = ({ card }) => {
@@ -109,3 +112,13 @@ const PartitionsCard = ({ card }) => {
109112
</StorageCard>
110113
);
111114
};
115+
116+
const UnexpectedPartitionsCard = ({ card }) => {
117+
return (
118+
<StorageCard card={card}>
119+
<CardBody>
120+
{_("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.")}
121+
</CardBody>
122+
</StorageCard>
123+
);
124+
};

test/verify/check-storage-lvm2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,22 @@ class TestStorageLvm2(storagelib.StorageCase):
841841
b.wait_in_text(self.card_desc("LVM2 logical volume", "Physical volumes"), bn(disk))
842842
b.wait_in_text(self.card_desc("LVM2 logical volume", "Physical volumes"), bn(disk2))
843843

844+
def testUnsupportedPartitions(self):
845+
b = self.browser
846+
m = self.machine
847+
848+
self.login_and_go("/storage")
849+
850+
dev_1 = self.add_ram_disk()
851+
self.addCleanupVG("vgroup0")
852+
m.execute(f"vgcreate vgroup0 {dev_1}")
853+
m.execute("lvcreate vgroup0 -n lvol0 -l100%FREE")
854+
m.execute("parted /dev/vgroup0/lvol0 -s mktable gpt mkpart primary ext2 1M 50M")
855+
856+
b.wait_text(self.card_row_col("Storage", row_name="lvol0", col_index=3), "GPT partitions")
857+
self.click_card_row("Storage", name="lvol0")
858+
b.wait_in_text(self.card("GPT partitions"), "Partitions are not supported on this block device.")
859+
844860

845861
class TestStorageLvm2Destructive(storagelib.StorageCase):
846862

0 commit comments

Comments
 (0)