Skip to content

Commit

Permalink
storage: Fix listing of btrfs subvols in fstab
Browse files Browse the repository at this point in the history
The parse_subvol_from_options function wants the whole options string,
not individual options.
  • Loading branch information
mvollmer authored and jelly committed Jan 19, 2024
1 parent 42522f9 commit 4bdef0b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
15 changes: 2 additions & 13 deletions pkg/storaged/btrfs/volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,11 @@ function make_btrfs_subvolume_pages(parent, volume) {
let has_root = false;
for (const config of block.Configuration) {
if (config[0] == "fstab") {
const fstab_subvol = {};
let opts = config[1].opts;
const opts = config[1].opts;
if (!opts)
continue;

opts = decode_filename(opts.v).split(",");
for (const opt of opts) {
const fstab_subvol = parse_subvol_from_options(opt);

if (!fstab_subvol)
continue;

if (fstab_subvol.id && fstab_subvol.pathname) {
break;
}
}
const fstab_subvol = parse_subvol_from_options(decode_filename(opts.v));

if (fstab_subvol && fstab_subvol.pathname === "/") {
has_root = true;
Expand Down
4 changes: 2 additions & 2 deletions test/common/storagelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ def click_card_row(self, title, index=None, name=None, location=None):
# We need to click on a <td> element since that's where the handlers are...
self.browser.click(self.card_row(title, index, name, location) + " td:nth-child(1)")

def card_row_col(self, title, row_index, col_index):
return self.card_row(title, row_index) + f" td:nth-child({col_index})"
def card_row_col(self, title, row_index=None, col_index=None, row_name=None, row_location=None):
return self.card_row(title, row_index, row_name, row_location) + f" td:nth-child({col_index})"

def card_desc(self, card_title, desc_title):
return self.card(card_title) + f" [data-test-desc-title='{desc_title}'] [data-test-value=true]"
Expand Down
24 changes: 24 additions & 0 deletions test/verify/check-storage-btrfs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,30 @@ ExecStart=/usr/bin/sleep infinity
self.confirm()
b.wait_in_text(self.card_row("Storage", location=mount_point), "btrfs subvolume")

def testNothingMounted(self):
m = self.machine
b = self.browser

disk = self.add_ram_disk(size=128)

m.execute(f"mkfs.btrfs -L butter {disk}; mount {disk} /mnt; btrfs subvolume create /mnt/home; btrfs subvolume create /mnt/backups; umount /mnt")

self.login_and_go("/storage")

self.click_card_row("Storage", name="butter")
b.wait_visible(self.card_row("btrfs subvolumes", name="/"))
b.wait_not_present(self.card_row("btrfs subvolumes", name="home"))
b.wait_not_present(self.card_row("btrfs subvolumes", name="backups"))

# Add some fstab entries. Cockpit should pick up the
# subvolumes mentioned in them and show them.

m.execute(f"echo >>/etc/fstab '{disk} /home auto noauto,subvol=home 0 0'")
m.execute(f"echo >>/etc/fstab '{disk} /mnt/backups auto noauto,subvol=backups 0 0'")

b.wait_text(self.card_row_col("btrfs subvolumes", row_name="home", col_index=3), "/home (not mounted)")
b.wait_text(self.card_row_col("btrfs subvolumes", row_name="backups", col_index=3), "/mnt/backups (not mounted)")


if __name__ == '__main__':
testlib.test_main()

0 comments on commit 4bdef0b

Please sign in to comment.