From 5096335277fa9360a413e28c30040838786ba99b Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Thu, 19 Sep 2024 12:45:25 +0200 Subject: [PATCH] lv_manip: handle swap devices in fs-related checks for lvreduce/lvextend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This provides better hints when trying to resize the fs on top of an LV. Also needs a3f6d2f593a4d278daf9ba3a1ba30bae38d8396a for proper operation. ❯ lvs -o name,size vg/swap lv_name lv_size swap 60.00m Before: ❯ lvextend -L72m vg/swap Size of logical volume vg/swap changed from 60.00 MiB (15 extents) to 72.00 MiB (18 extents). Logical volume vg/swap successfully resized. ❯ lvreduce -L60m vg/swap File system swap found on vg/swap. File system device usage is not available from libblkid. ❯ lvreduce -L50m vg/swap Rounding size to boundary between physical extents: 52.00 MiB. File system swap found on vg/swap. File system device usage is not available from libblkid. After: ❯ lvextend -L72m vg/swap Size of logical volume vg/swap changed from 60.00 MiB (15 extents) to 72.00 MiB (18 extents). Logical volume vg/swap successfully resized. ❯ lvreduce -L60m vg/swap File system swap found on vg/swap. File system size (60.00 MiB) is equal to the requested size (60.00 MiB). File system reduce is not needed, skipping. Size of logical volume vg/swap changed from 72.00 MiB (18 extents) to 60.00 MiB (15 extents). Logical volume vg/swap successfully resized. ❯ lvreduce -L50m vg/swap Rounding size to boundary between physical extents: 52.00 MiB. File system swap found on vg/swap. File system size (60.00 MiB) is larger than the requested size (52.00 MiB). File system reduce is required and not supported (swap). --- lib/metadata/lv_manip.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 0f509e19b..a0cdab127 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -6144,6 +6144,8 @@ static int _fs_reduce_allow(struct cmd_context *cmd, struct logical_volume *lv, if (fsi->mounted) fsi->needs_unmount = 1; + fsi->needs_reduce = 1; + } else if (!strcmp(fsi->fstype, "swap")) { fsi->needs_reduce = 1; } else { /* @@ -6314,6 +6316,8 @@ static int _fs_extend_allow(struct cmd_context *cmd, struct logical_volume *lv, if (lp->nofsck) fsi->needs_fsck = 0; + } else if (!strcmp(fsi->fstype, "swap")) { + fsi->needs_extend = 1; } else if (!strcmp(fsi->fstype, "xfs")) { fs_extend_cmd = " xfs_growfs";