diff options
author | David Teigland <teigland@redhat.com> | 2022-10-11 11:50:47 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2022-10-11 12:48:31 -0500 |
commit | f6f2737015746b1b6c7fbd0d297a4596c584749b (patch) | |
tree | 295649dba582bed097f0ea3836c3232cdd9f171c | |
parent | fc52e87f06959f542ea78b75df104bc6c85fd973 (diff) | |
download | lvm2-f6f2737015746b1b6c7fbd0d297a4596c584749b.tar.gz |
lvreduce: require active LV when no fs option is used
Without an --fs option set, make lvreduce of an inactive LV
fail and report that the LV must be active.
-rw-r--r-- | lib/metadata/lv_manip.c | 4 | ||||
-rw-r--r-- | test/shell/lvresize-fs.sh | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index d6452e849..db97a019c 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -6873,6 +6873,10 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv, is_active = lv_is_active(lv_top); if (is_reduce && !is_active && !strcmp(lp->fsopt, "checksize")) { + if (!lp->user_set_fs) { + log_error("The LV must be active to safely reduce, or use --fs checksize."); + goto out; + } lv_top->status |= LV_TEMPORARY; if (!activate_lv(cmd, lv_top)) { log_error("Failed to activate %s to check for fs.", display_lvname(lv_top)); diff --git a/test/shell/lvresize-fs.sh b/test/shell/lvresize-fs.sh index d4b6484c0..0be6911a0 100644 --- a/test/shell/lvresize-fs.sh +++ b/test/shell/lvresize-fs.sh @@ -473,7 +473,8 @@ lvremove $vg/$lv lvcreate -n $lv -L 456M $vg aux wipefs_a "$DM_DEV_DIR/$vg/$lv" lvchange -an $vg/$lv -lvreduce -L-200M $vg/$lv +not lvreduce -L-200M $vg/$lv +lvreduce --fs checksize -L-200M $vg/$lv check lv_field $vg/$lv lv_size "256.00m" lvremove $vg/$lv @@ -1145,7 +1146,7 @@ df --output=size "$mount_dir" |tee df1 umount "$mount_dir" lvchange -an $vg/$lv # no fs reduce is needed -lvreduce -L200M $vg/$lv +lvreduce --fs checksize -L200M $vg/$lv check lv_field $vg/$lv lv_size "200.00m" lvchange -ay $vg/$lv mount "$DM_DEV_DIR/$vg/$lv" "$mount_dir" @@ -1167,7 +1168,7 @@ df --output=size "$mount_dir" |tee df1 umount "$mount_dir" lvchange -an $vg/$lv # fs is 200M, reduced size is 216M, so no fs reduce is needed -lvreduce -L216M $vg/$lv +lvreduce --fs checksize -L216M $vg/$lv check lv_field $vg/$lv lv_size "216.00m" lvchange -ay $vg/$lv mount "$DM_DEV_DIR/$vg/$lv" "$mount_dir" |