Skip to content

Commit

Permalink
storage: Remount filesystems after resizing them
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Oct 5, 2023
1 parent ad2748f commit e8510ce
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 11 additions & 4 deletions pkg/storaged/resize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import cockpit from "cockpit";
import {
block_name, get_active_usage, teardown_active_usage,
is_mounted_synch, get_partitions
undo_temporary_teardown, is_mounted_synch, get_partitions
} from "./utils.js";
import {
existing_passphrase_fields, init_existing_passphrase,
Expand Down Expand Up @@ -255,7 +255,10 @@ export function grow_dialog(client, lvol_or_part, info, to_fit) {
round_size = 1024 * 1024;
}

const usage = get_active_usage(client, block && info.grow_needs_unmount ? block.path : null, _("grow"));
const usage = get_active_usage(client,
block && info.grow_needs_unmount ? block.path : null,
_("grow"), null,
true);

if (usage.Blocking) {
dialog_open({
Expand Down Expand Up @@ -304,6 +307,7 @@ export function grow_dialog(client, lvol_or_part, info, to_fit) {
to_fit ? grow_size : vals.size,
info.grow_needs_unmount,
vals.passphrase || recovered_passphrase)
.then(() => undo_temporary_teardown(client, usage))
.catch(request_passphrase_on_error_handler(dlg, vals, recovered_passphrase, block)));
});
}
Expand Down Expand Up @@ -336,8 +340,10 @@ export function shrink_dialog(client, lvol_or_part, info, to_fit) {
round_size = 1024 * 1024;
}

const usage = get_active_usage(client, block && !to_fit && info.shrink_needs_unmount ? block.path : null,
_("shrink"));
const usage = get_active_usage(client,
block && !to_fit && info.shrink_needs_unmount ? block.path : null,
_("shrink"), null,
true);

if (usage.Blocking) {
dialog_open({
Expand Down Expand Up @@ -413,6 +419,7 @@ export function shrink_dialog(client, lvol_or_part, info, to_fit) {
to_fit ? shrink_size : vals.size,
to_fit ? false : info.shrink_needs_unmount,
vals.passphrase || recovered_passphrase)
.then(() => undo_temporary_teardown(client, usage))
.catch(request_passphrase_on_error_handler(dlg, vals, recovered_passphrase, block)));
});
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/storaged/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ export function find_children_for_mount_point(client, mount_point, self) {
return children;
}

export function get_active_usage(client, path, top_action, child_action) {
export function get_active_usage(client, path, top_action, child_action, is_temporary) {
function get_usage(usage, path, level) {
const block = client.blocks[path];
const fsys = client.blocks_fsys[path];
Expand Down Expand Up @@ -805,7 +805,7 @@ export function get_active_usage(client, path, top_action, child_action) {
block,
usage: 'mounted',
location,
set_noauto: !is_top,
set_noauto: !is_top && !is_temporary,
actions: is_top ? get_actions(_("unmount")) : [_("unmount")],
blocking: false
});
Expand Down Expand Up @@ -967,6 +967,15 @@ export function teardown_active_usage(client, usage) {
));
}

export async function undo_temporary_teardown(client, usage) {
for (let i = usage.length - 1; i >= 0; i--) {
const u = usage[i];
if (u.usage == "mounted") {
await client.mount_at(u.block, u.location);
}
}
}

// TODO - generalize this to arbitrary number of arguments (when needed)
export function fmt_to_array(fmt, arg) {
const index = fmt.indexOf("$0");
Expand Down
8 changes: 1 addition & 7 deletions test/verify/check-storage-resize
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class TestStorageResize(storagelib.StorageCase):
self.dialog_apply()
self.dialog_wait_close()
self.content_tab_wait_in_info(1, 1, "Size", "398 MB")
if grow_needs_unmount:
self.content_row_action(fsys_row, "Mount")
self.confirm()
with b.wait_timeout(30):
self.wait_mounted(fsys_row, fsys_tab)
size = int(m.execute("df -k --output=size /run/foo | tail -1").strip())
Expand All @@ -100,10 +97,7 @@ class TestStorageResize(storagelib.StorageCase):
self.dialog_apply()
self.dialog_wait_close()
self.content_tab_wait_in_info(1, 1, "Size", "201 MB")
if shrink_needs_unmount:
self.content_row_action(fsys_row, "Mount")
self.confirm()
self.wait_mounted(fsys_row, fsys_tab)
self.wait_mounted(fsys_row, fsys_tab)
size = int(m.execute("df -k --output=size /run/foo | tail -1").strip())
self.assertLess(size, 300000)
else:
Expand Down

0 comments on commit e8510ce

Please sign in to comment.