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 authored and jelly committed Jan 23, 2024
1 parent 5a5f852 commit 37fe4a4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
15 changes: 15 additions & 0 deletions doc/anaconda.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,18 @@ This is done by setting the "efi" flag to true or false:
"efi": true
}
```

Default filesystem type
-----------------------

Cockpit tries to be smart about which filesystem type to select by
default when formatting something. In normal operation, it will fall
back to the type of the filesystem mounted as "/". When in Anaconda
mode, there might not be anything assigned to "/" yet, and in this
case, Cockpit will use the type from "default_fsys_type".

```
{
"default_fsys_type": "xfs"
}
```
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 @@ -155,6 +157,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 @@ -183,7 +196,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 @@ -198,6 +211,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();
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 @@ -322,7 +353,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

3 comments on commit 37fe4a4

@luis-apodaca
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys , Im not a software engineer, and I dont know were can I ask this question, In the official web page of the project didnt found any place for ask to somebody,

So if some of you could help I appreciate it so much, the qustion is, can cockpit be used as a freeradius gui with all the functions free-radius has ??

thanks in advance.

@jelly
Copy link
Member

@jelly jelly commented on 37fe4a4 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys , Im not a software engineer, and I dont know were can I ask this question, In the official web page of the project didnt found any place for ask to somebody,

So if some of you could help I appreciate it so much, the qustion is, can cockpit be used as a freeradius gui with all the functions free-radius has ??

thanks in advance.

We have discussions which is the perfect place for this. But as far as I know we can't gui freeradius.

@luis-apodaca
Copy link

@luis-apodaca luis-apodaca commented on 37fe4a4 Jan 24, 2024 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.