Skip to content

Commit

Permalink
storage: Validate mount point even with "Format only"
Browse files Browse the repository at this point in the history
We still want to check whether it is unique etc.
  • Loading branch information
mvollmer committed Oct 2, 2023
1 parent 8bededc commit 8fd9cae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
3 changes: 1 addition & 2 deletions pkg/storaged/format-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ function format_dialog_internal(client, path, start, size, enable_dos_extended,
visible: is_filesystem,
value: old_dir || "",
validate: (val, values, variant) => {
if (variant !== "nomount")
return is_valid_mount_point(client, block, val);
return is_valid_mount_point(client, block, val, variant == "nomount");
}
}),
SelectOne("type", _("Type"),
Expand Down
14 changes: 8 additions & 6 deletions pkg/storaged/fsys-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,19 @@ function nice_block_name(block) {
return utils.block_name(client.blocks[block.CryptoBackingDevice] || block);
}

export async function is_valid_mount_point(client, block, val, ignore_overmounting) {
if (val === "")
return _("Mount point cannot be empty");
export function is_valid_mount_point(client, block, val, format_only, for_fstab) {
if (val === "") {
if (!format_only || for_fstab)
return _("Mount point cannot be empty");
return null;
}

const other_blocks = find_blocks_for_mount_point(client, val, block);
if (other_blocks.length > 0)
return cockpit.format(_("Mount point is already used for $0"),
other_blocks.map(nice_block_name).join(", "));

if (!ignore_overmounting) {
if (!format_only) {
const children = utils.find_children_for_mount_point(client, val, block);
if (Object.keys(children).length > 0)
return <>
Expand Down Expand Up @@ -329,8 +332,7 @@ export function mounting_dialog(client, block, mode, forced_options) {
TextInput("mount_point", _("Mount point"),
{
value: old_dir,
validate: val => is_valid_mount_point(client, block, val,
mode == "update" && !is_filesystem_mounted)
validate: val => is_valid_mount_point(client, block, val, mode == "update" && !is_filesystem_mounted, true)
}),
CheckBoxes("mount_options", _("Mount options"),
{
Expand Down
6 changes: 2 additions & 4 deletions pkg/storaged/stratis-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ export function stratis_content_rows(client, pool, options) {
TextInput("mount_point", _("Mount point"),
{
validate: (val, values, variant) => {
if (variant !== "nomount")
return is_valid_mount_point(client, null, val);
return is_valid_mount_point(client, null, val, variant == "nomount");
}
}),
CheckBoxes("mount_options", _("Mount options"),
Expand Down Expand Up @@ -514,8 +513,7 @@ function create_fs(client, pool) {
TextInput("mount_point", _("Mount point"),
{
validate: (val, values, variant) => {
if (variant !== "nomount")
return is_valid_mount_point(client, null, val);
return is_valid_mount_point(client, null, val, variant == "nomount");
}
}),
CheckBoxes("mount_options", _("Mount options"),
Expand Down
3 changes: 3 additions & 0 deletions test/verify/check-storage-mounting
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ class TestStorageMountingLUKS(storagelib.StorageCase):
self.dialog_set_val("mount_point", "/run/data")
self.dialog_apply()
self.dialog_wait_error("mount_point", "Mount point is already used for /dev/test/one")
self.dialog_set_val("mount_point", "/run/data") # to clear the error
self.dialog_apply_secondary()
self.dialog_wait_error("mount_point", "Mount point is already used for /dev/test/one")
self.dialog_cancel()
self.dialog_wait_close()

Expand Down

0 comments on commit 8fd9cae

Please sign in to comment.