Skip to content

Commit

Permalink
storage: Be smart about default filesystem type
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Jan 18, 2024
1 parent e2f3e9e commit eaf4cdd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
38 changes: 36 additions & 2 deletions pkg/storaged/block/format-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import cockpit from "cockpit";
import client from "../client.js";

import {
edit_crypto_config, parse_options, unparse_options, extract_option,
get_parent_blocks, is_netdev,
Expand Down Expand Up @@ -154,6 +156,17 @@ export function format_dialog(client, path, start, size, enable_dos_extended) {
}
}

function find_root_fsys_block() {
const root = client.anaconda?.mount_point_prefix || "/";
for (const p in client.blocks) {
if (client.blocks_fsys[p] && client.blocks_fsys[p].MountPoints.map(decode_filename).indexOf(root) >= 0)
return client.blocks[p];
if (client.blocks[p].Configuration.find(c => c[0] == "fstab" && decode_filename(c[1].dir.v) == root))
return client.blocks[p];
}
return null;
}

function format_dialog_internal(client, path, start, size, enable_dos_extended, old_luks_version) {
const block = client.blocks[path];
const block_part = client.blocks_part[path];
Expand Down Expand Up @@ -182,7 +195,7 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
}

const filesystem_options = [];
add_fsys("xfs", { value: "xfs", title: "XFS " + _("(recommended)") });
add_fsys("xfs", { value: "xfs", title: "XFS" });
add_fsys("ext4", { value: "ext4", title: "EXT4" });
add_fsys("vfat", { value: "vfat", title: "VFAT" });
add_fsys("ntfs", { value: "ntfs", title: "NTFS" });
Expand All @@ -196,6 +209,24 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
if (create_partition && enable_dos_extended)
add_fsys(true, { value: "dos-extended", title: _("Extended partition") });

function is_supported(type) {
return filesystem_options.find(o => o.value == type);
}

let default_type = null;
if (block.IdUsage == "filesystem" && is_supported(block.IdType))
default_type = block.IdType;
else {
const root_block = find_root_fsys_block();
console.log("ROOT", root_block);
if (root_block && is_supported(root_block.IdType))
default_type = root_block.IdType;
else if (client.anaconda?.default_fsys_type && is_supported(client.anaconda.default_fsys_type))
default_type = client.anaconda.default_fsys_type;
else
default_type = "ext4";
}

function is_encrypted(vals) {
return vals.crypto && vals.crypto !== "none";
}
Expand Down Expand Up @@ -315,7 +346,10 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
}
}),
SelectOne("type", _("Type"),
{ choices: filesystem_options }),
{
value: default_type,
choices: filesystem_options
}),
SizeSlider("size", _("Size"),
{
value: size,
Expand Down
27 changes: 20 additions & 7 deletions test/verify/check-storage-anaconda
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class TestStorageAnaconda(storagelib.StorageCase):
self.dialog({"type": "efi"})
b.wait_text(self.card_desc("Partition", "Type"), "EFI system partition")

def testNoMounting(self):
def testFormat(self):
m = self.machine
b = self.browser

Expand All @@ -293,21 +293,24 @@ class TestStorageAnaconda(storagelib.StorageCase):
anaconda_config = {
"mount_point_prefix": "/sysroot",
"available_devices": [disk],
"default_fsys_type": "vfat",
}

self.login_and_go("/storage")
self.enterAnacondaMode(anaconda_config)

# Create a partition, there should be no "Create and mount" button
b.wait_text(self.card_row_col("Storage", 1, 3), "Unformatted data")
self.click_dropdown(self.card_row("Storage", 1), "Create partition table")
self.confirm()
b.wait_text(self.card_row_col("Storage", 2, 2), "Free space")

# Only one apply button in the Create Partition dialog
# Only one apply button in the Create Partition dialog,
# default filesystem type should be "vfat".
self.click_dropdown(self.card_row("Storage", 2), "Create partition")
self.dialog_wait_open()
self.dialog_wait_val("type", "vfat")
self.dialog_set_val("type", "ext4")
self.dialog_set_val("size", "30")
b.wait(lambda: b.call_js_func('ph_count', "#dialog button.apply") == 1)
b.wait_text("#dialog button.apply", "Create")
self.dialog_apply()
Expand All @@ -316,19 +319,29 @@ class TestStorageAnaconda(storagelib.StorageCase):
# Page talks about assigned mount points instead of "not mounted".
b.wait_text(self.card_row_col("Storage", 2, 4), "(no assigned mount point)")

# Only one apply button in the Format dialog
# Format it again and make it the root filesystem. It should
# keep ext4 as the type.
self.click_dropdown(self.card_row("Storage", 2), "Format")
self.dialog_wait_open()
self.dialog_set_val("mount_point", "/boot")
self.dialog_set_val("type", "ext4")
self.dialog_set_val("mount_point", "/")
self.dialog_wait_val("type", "ext4")
b.wait(lambda: b.call_js_func('ph_count', "#dialog button.apply") == 1)
b.wait_text("#dialog button.apply", "Format")
self.dialog_apply()
self.dialog_wait_close()

# Filesystem is not mounted but page doesn't mention "not mounted".
m.execute(f"! findmnt {disk}")
b.wait_text(self.card_row_col("Storage", 2, 4), "/boot")
b.wait_text(self.card_row_col("Storage", 2, 4), "/")

# Create another partition, it should inherit ext4
# from the root
b.wait_text(self.card_row_col("Storage", 3, 2), "Free space")
self.click_dropdown(self.card_row("Storage", 3), "Create partition")
self.dialog_wait_open()
self.dialog_wait_val("type", "ext4")
self.dialog_apply()
self.dialog_wait_close()


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions test/verify/check-storage-format
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TestStorageFormat(storagelib.StorageCase):
# Format without mount point
self.click_card_dropdown("Unformatted data", "Format")
self.dialog_wait_open()
self.dialog_set_val("type", "xfs")
self.dialog_apply_secondary()
self.dialog_wait_close()

Expand Down

0 comments on commit eaf4cdd

Please sign in to comment.