From 9668d40d5a714314fee746876ccd68cf258111ca Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sat, 14 Oct 2023 21:19:21 +0200 Subject: [PATCH] resize: reduce without prompt for no-fs case Apply the same logic for 'lvreduce' which exists for newer systems (compiled with HAVE_BLKID_SUBLKS_FSINFO) also for older systems for one very common practical case where the active LV does not have any blkid known signature/filesystem. New variant recognized this situation and allowed to proceed without requesting a prompt, while the older variant always requested confirmation prompt. With this patch command now works equily for both variants for 'active LV' without signature and allows to reduce LV without prompting. --- lib/metadata/lv_manip.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 722e41a63..55c411af7 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -7017,8 +7017,29 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv, /* * Warn and confirm if checksize has been disabled for reduce. */ - if (is_reduce && !lp->fsopt[0] && !_lv_reduce_confirmation(lv_top, lp)) - goto_out; + if (!lp->fsopt[0] && is_reduce) { + int nofs = 0; + + if (is_active) { + /* When active, prompt only for confirmation when FS is detected */ + char lv_path[PATH_MAX]; + char fstype[FSTYPE_MAX]; + + if (dm_snprintf(lv_path, sizeof(lv_path), "%s%s/%s", cmd->dev_dir, + lv_top->vg->name, lv_top->name) < 0) { + log_error("Couldn't create LV path for %s.", display_lvname(lv_top)); + goto out; + } + + if (!fs_block_size_and_type(lv_path, NULL, fstype, &nofs)) { + stack; /* Continue as if FS would have been detected */ + nofs = 0; + } + } + + if (!nofs && !_lv_reduce_confirmation(lv_top, lp)) + goto_out; + } /* Part of old approach to fs handling using fsadm. */ if (!strcmp(lp->fsopt, "resize_fsadm") && !lp->nofsck &&