main - shellcheck: avoid assign warnings
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e5e957e3308a6a03503...
Commit: e5e957e3308a6a03503b6ded290dc975494204e5
Parent: 8a92f7070941172e1671cf6b0fd1296776daefb7
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 15 10:49:47 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:13:24 2021 +0100
shellcheck: avoid assign warnings
Shellcheck seems to be happier when assigning variables with quotes.
---
scripts/fsadm.sh | 54 +++++++++++++++++------------------
scripts/lvmdump.sh.in | 36 +++++++++++------------
test/lib/aux.sh | 4 +--
test/lib/utils.sh | 2 +-
test/shell/lvcreate-cache-no-tools.sh | 4 +--
5 files changed, 50 insertions(+), 50 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 4f59cee13..d98833c3a 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -31,34 +31,34 @@
set -euE -o pipefail
-TOOL=fsadm
+TOOL="fsadm"
_SAVEPATH=$PATH
PATH="/sbin:/usr/sbin:/bin:/usr/sbin:$PATH"
# utilities
-TUNE_EXT=tune2fs
-RESIZE_EXT=resize2fs
-TUNE_REISER=reiserfstune
-RESIZE_REISER=resize_reiserfs
-TUNE_XFS=xfs_info
-RESIZE_XFS=xfs_growfs
-
-MOUNT=mount
-UMOUNT=umount
-MKDIR=mkdir
-RMDIR=rmdir
-BLOCKDEV=blockdev
-BLKID=blkid
-DATE=date
-GREP=grep
-READLINK=readlink
+TUNE_EXT="tune2fs"
+RESIZE_EXT="resize2fs"
+TUNE_REISER="reiserfstune"
+RESIZE_REISER="resize_reiserfs"
+TUNE_XFS="xfs_info"
+RESIZE_XFS="xfs_growfs"
+
+MOUNT="mount"
+UMOUNT="umount"
+MKDIR="mkdir"
+RMDIR="rmdir"
+BLOCKDEV="blockdev"
+BLKID="blkid"
+DATE="date"
+GREP="grep"
+READLINK="readlink"
READLINK_E="-e"
-FSCK=fsck
-XFS_CHECK=xfs_check
+FSCK="fsck"
+XFS_CHECK="xfs_check"
# XFS_REPAIR -n is used when XFS_CHECK is not found
-XFS_REPAIR=xfs_repair
-CRYPTSETUP=cryptsetup
+XFS_REPAIR="xfs_repair"
+CRYPTSETUP="cryptsetup"
# user may override lvm location by setting LVM_BINARY
LVM=${LVM_BINARY:-lvm}
@@ -69,8 +69,8 @@ VERB=
FORCE=
EXTOFF=${_FSADM_EXTOFF:-0}
DO_LVRESIZE=0
-FSTYPE=unknown
-VOLUME=unknown
+FSTYPE="unknown"
+VOLUME="unknown"
TEMPDIR="${TMPDIR:-/tmp}/${TOOL}_${RANDOM}$$/m"
DM_DEV_DIR="${DM_DEV_DIR:-/dev}"
BLOCKSIZE=
@@ -321,10 +321,10 @@ detect_mounted_with_proc_self_mountinfo() {
# device (which could have been renamed).
# We need to visit every mount point and check it's major minor
detect_mounted_with_proc_mounts() {
- MOUNTED=$("$GREP" "^$VOLUME[ \\t]" "$PROCMOUNTS")
+ MOUNTED=$("$GREP" "^${VOLUME}[ \\t]" "$PROCMOUNTS")
# for empty string try again with real volume name
- test -z "$MOUNTED" && MOUNTED=$("$GREP" "^$RVOLUME[ \\t]" "$PROCMOUNTS")
+ test -z "$MOUNTED" && MOUNTED=$("$GREP" "^${RVOLUME}[ \\t]" "$PROCMOUNTS")
MOUNTDEV=$(echo -n -e "${MOUNTED%% *}")
# cut device name prefix and trim everything past mountpoint
@@ -335,8 +335,8 @@ detect_mounted_with_proc_mounts() {
# for systems with different device names - check also mount output
if test -z "$MOUNTED" ; then
# will not work with spaces in paths
- MOUNTED=$(LC_ALL=C "$MOUNT" | "$GREP" "^$VOLUME[ \\t]")
- test -z "$MOUNTED" && MOUNTED=$(LC_ALL=C "$MOUNT" | "$GREP" "^$RVOLUME[ \\t]")
+ MOUNTED=$(LC_ALL=C "$MOUNT" | "$GREP" "^${VOLUME}[ \\t]")
+ test -z "$MOUNTED" && MOUNTED=$(LC_ALL=C "$MOUNT" | "$GREP" "^${RVOLUME}[ \\t]")
MOUNTDEV=${MOUNTED%% on *}
MOUNTED=${MOUNTED##* on }
MOUNTED=${MOUNTED% type *} # allow type in the mount name
diff --git a/scripts/lvmdump.sh.in b/scripts/lvmdump.sh.in
index 24e395661..8507151d8 100644
--- a/scripts/lvmdump.sh.in
+++ b/scripts/lvmdump.sh.in
@@ -18,24 +18,24 @@
# following external commands are used throughout the script
# echo and test are internal in bash at least
-MKDIR=mkdir # need -p
-TAR=tar # need czf
-RM=rm # need -rf
-CP=cp
-TAIL=tail # we need -n
-LS=ls # need -la
-PS=ps # need alx
-SED=sed
-DD=dd
-CUT=cut
-GREP=grep
-DATE=date
-BASENAME=basename
-UDEVADM=udevadm
-UNAME=uname
-TR=tr
-SOCAT=socat # either socat or nc is needed for dumping lvmetad state
-NC=nc
+MKDIR="mkdir" # need -p
+TAR="tar" # need czf
+RM="rm" # need -rf
+CP="cp"
+TAIL="tail" # we need -n
+LS="ls" # need -la
+PS="ps" # need alx
+SED="sed"
+DD="dd"
+CUT="cut"
+GREP="grep"
+DATE="date"
+BASENAME="basename"
+UDEVADM="udevadm"
+UNAME="uname"
+TR="tr"
+SOCAT="socat" # either socat or nc is needed for dumping lvmetad state
+NC="nc"
if test "@ODIRECT@" = yes; then
DDFLAGS='iflag=direct oflag=direct'
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 2e6191d70..53975301a 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -807,7 +807,7 @@ wait_md_create() {
local md=$1
while :; do
- if ! grep `basename $md` /proc/mdstat; then
+ if ! grep "$(basename $md)" /proc/mdstat; then
echo "$md not ready"
cat /proc/mdstat
sleep 2
@@ -1365,7 +1365,7 @@ EOF
echo "$s {"
local k
for k in $(grep ^"$s"/ "$config_values" | cut -f1 -d= | sed -e 's, *$,,' | sort | uniq); do
- grep "^$k[ \t=]" "$config_values" | tail -n 1 | sed -e "s,^$s/, ," || true
+ grep "^${k}[ \t=]" "$config_values" | tail -n 1 | sed -e "s,^$s/, ," || true
done
echo "}"
echo
diff --git a/test/lib/utils.sh b/test/lib/utils.sh
index 9da9a966e..400cacd0c 100644
--- a/test/lib/utils.sh
+++ b/test/lib/utils.sh
@@ -267,7 +267,7 @@ get_devs() {
prepare_test_vars() {
vg="${PREFIX}vg"
- lv=LV
+ lv="LV"
for i in {1..16}; do
eval "lv$i=\"LV$i\""
diff --git a/test/shell/lvcreate-cache-no-tools.sh b/test/shell/lvcreate-cache-no-tools.sh
index bbab0fef3..2e4ee4623 100644
--- a/test/shell/lvcreate-cache-no-tools.sh
+++ b/test/shell/lvcreate-cache-no-tools.sh
@@ -20,9 +20,9 @@ SKIP_WITH_LVMPOLLD=1
if test -e LOCAL_CLVMD ; then
# In cluster, the error from activation is logged in clvmd
# so we can only check resulting state of activation
- GREP=echo
+ GREP="echo"
else
- GREP=grep
+ GREP="grep"
fi
make_fake_() {
3 years, 2 months
main - cov: void unused result
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8a92f7070941172e167...
Commit: 8a92f7070941172e1671cf6b0fd1296776daefb7
Parent: f69ff4b84a559a5795479489cf834fc0c3999e8d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 15 10:49:20 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:13:24 2021 +0100
cov: void unused result
---
lib/device/bcache.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index a5f2a5a86..285d92bc7 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -1401,7 +1401,7 @@ bool bcache_invalidate_di(struct bcache *cache, int di)
radix_tree_iterate(cache->rtree, k.bytes, k.bytes + sizeof(k.parts.di), &it.it);
if (it.success)
- radix_tree_remove_prefix(cache->rtree, k.bytes, k.bytes + sizeof(k.parts.di));
+ (void) radix_tree_remove_prefix(cache->rtree, k.bytes, k.bytes + sizeof(k.parts.di));
return it.success;
}
@@ -1436,7 +1436,7 @@ void bcache_abort_di(struct bcache *cache, int di)
it.visit = _abort_v;
radix_tree_iterate(cache->rtree, k.bytes, k.bytes + sizeof(k.parts.di), &it);
- radix_tree_remove_prefix(cache->rtree, k.bytes, k.bytes + sizeof(k.parts.di));
+ (void) radix_tree_remove_prefix(cache->rtree, k.bytes, k.bytes + sizeof(k.parts.di));
}
//----------------------------------------------------------------
3 years, 2 months
main - debug: update message
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f69ff4b84a559a57954...
Commit: f69ff4b84a559a5795479489cf834fc0c3999e8d
Parent: 6e9ccf7b6f58cd3e31a79c35d3a312560809e85a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 14 13:15:50 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:13:24 2021 +0100
debug: update message
---
lib/metadata/lv_manip.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 6fc7afbac..12b1505df 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -6799,7 +6799,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!suppress_remove_message && (visible || historical)) {
(void) dm_snprintf(msg, sizeof(msg),
- "%sogical volume \"%s\" successfully removed",
+ "%sogical volume \"%s\" successfully removed.",
historical ? "Historical l" : "L",
historical ? lv->this_glv->historical->name : lv->name);
if (!vg->needs_write_and_commit)
@@ -6820,11 +6820,11 @@ static int _lv_remove_segs_using_this_lv(struct cmd_context *cmd, struct logical
struct seg_list *sl;
if ((force == PROMPT) &&
- yes_no_prompt("Removing %s \"%s\" will remove %u dependent volume(s). "
- "Proceed? [y/n]: ", lv_type, lv->name,
+ yes_no_prompt("Removing %s %s will remove %u dependent volume(s). "
+ "Proceed? [y/n]: ", lv_type, display_lvname(lv),
dm_list_size(&lv->segs_using_this_lv)) == 'n') {
lv->to_remove = 0;
- log_error("Logical volume \"%s\" not removed.", lv->name);
+ log_error("Logical volume %s not removed.", display_lvname(lv));
return 0;
}
3 years, 2 months
main - debug: keep microseconds aligned
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6e9ccf7b6f58cd3e31a...
Commit: 6e9ccf7b6f58cd3e31a79c35d3a312560809e85a
Parent: bc1bc4cffc2b5faa113b5c232aa5fc2faae8771a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Mar 12 22:39:42 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:13:24 2021 +0100
debug: keep microseconds aligned
---
lib/log/log.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/log/log.c b/lib/log/log.c
index cd676f2ae..53ff5b156 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -472,7 +472,7 @@ static void _set_time_prefix(char *prefix, int buflen)
if (!len)
goto fail;
- len = dm_snprintf(prefix + len, buflen - len, ".%ld ", ts.tv_nsec/1000);
+ len = dm_snprintf(prefix + len, buflen - len, ".%06ld ", ts.tv_nsec/1000);
if (len < 0)
goto fail;
3 years, 2 months
main - debug: drop stack from regular code flow
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bc1bc4cffc2b5faa113...
Commit: bc1bc4cffc2b5faa113b5c232aa5fc2faae8771a
Parent: eadd58a97dd9a199b74260e8a2bdb5657bf7a88d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Mar 12 22:30:29 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:13:24 2021 +0100
debug: drop stack from regular code flow
---
lib/label/hints.c | 2 +-
lib/metadata/metadata.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/label/hints.c b/lib/label/hints.c
index aed0ea2ff..47236a15a 100644
--- a/lib/label/hints.c
+++ b/lib/label/hints.c
@@ -448,7 +448,7 @@ static int _dev_in_hint_hash(struct cmd_context *cmd, struct device *dev)
return 0;
if (!dev_get_size(dev, &devsize) || !devsize)
- return_0;
+ return 0;
return 1;
}
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index cee236e3e..47d3d8b3e 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4603,7 +4603,7 @@ static bool _scan_text_mismatch(struct cmd_context *cmd, const char *vgname, con
/* For other commands, return mismatch immediately. */
if (ret)
- goto_out;
+ goto out;
}
if (ret) {
3 years, 2 months
main - lvpoll: improve merge polling
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=eadd58a97dd9a199b74...
Commit: eadd58a97dd9a199b74260e8a2bdb5657bf7a88d
Parent: 1a451207b8ddbd15519ff9556c59287023ab50fa
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 14 22:03:41 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:13:24 2021 +0100
lvpoll: improve merge polling
When multiple polling tasks are watching for same LV, clearly
when some of them wins the game - other polling tasks will fail.
Improve the logic and report success if the merged LV is
actually not a merging origin anymore (since likely someone
else has already finished merging).
---
tools/lvconvert_poll.c | 11 +++++++----
tools/polldaemon.c | 9 +++++++--
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/tools/lvconvert_poll.c b/tools/lvconvert_poll.c
index 5adb14506..b64cffe21 100644
--- a/tools/lvconvert_poll.c
+++ b/tools/lvconvert_poll.c
@@ -111,9 +111,9 @@ int lvconvert_merge_finish(struct cmd_context *cmd,
struct lv_segment *snap_seg = find_snapshot(lv);
if (!lv_is_merging_origin(lv)) {
- log_error("Logical volume %s has no merging snapshot.",
+ log_print("Logical volume %s is no longer merging origin, polling has finished.",
display_lvname(lv));
- return 0;
+ return 1;
}
log_print_unless_silent("Merge of snapshot into logical volume %s has finished.",
@@ -141,8 +141,11 @@ progress_t poll_merge_progress(struct cmd_context *cmd,
{
dm_percent_t percent = DM_PERCENT_0;
- if (!lv_is_merging_origin(lv) ||
- !lv_snapshot_percent(lv, &percent)) {
+ if (!lv_is_merging_origin(lv))
+ /* Nothing to monitor here */
+ return PROGRESS_FINISHED_ALL;
+
+ if (!lv_snapshot_percent(lv, &percent)) {
log_error("%s: Failed query for merging percentage. Aborting merge.",
display_lvname(lv));
return PROGRESS_CHECK_FAILED;
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index 32733b8ea..c182e548e 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -172,8 +172,13 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id,
vg = vg_read(cmd, id->vg_name, NULL, READ_FOR_UPDATE, lockd_state, &error_flags, NULL);
if (!vg) {
/* What more could we do here? */
- log_error("ABORTING: Can't reread VG for %s error flags %x.", id->display_name, error_flags);
- ret = 0;
+ if (error_flags & FAILED_NOTFOUND) {
+ log_print_unless_silent("Can't find VG %s. No longer active.", id->display_name);
+ ret = 1;
+ } else {
+ log_error("ABORTING: Can't reread VG for %s error flags %x.", id->display_name, error_flags);
+ ret = 0;
+ }
goto out;
}
3 years, 2 months
main - pooldaemon: increase min polling interval
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1a451207b8ddbd15519...
Commit: 1a451207b8ddbd15519ff9556c59287023ab50fa
Parent: 5edb353062b26bbe93002717d77aa5d1707f1f70
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 14 22:00:42 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:13:24 2021 +0100
pooldaemon: increase min polling interval
Although we support '0' interval - it's highly inefficent to
do so many scans in busy-loop.
So ATM raise minimal rescan time to 100ms.
TODO: revisit whole timing logic here as it does have some sideeffect
hiddent impact and can considerably eat CPU in some cases.
---
tools/polldaemon.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index d4e0be13e..32733b8ea 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -21,7 +21,7 @@
#include <time.h>
-#define WAIT_AT_LEAST_NANOSECS 100000
+#define WAIT_AT_LEAST_NANOSECS 100000000
progress_t poll_mirror_progress(struct cmd_context *cmd,
struct logical_volume *lv, const char *name,
@@ -127,7 +127,7 @@ static void _nanosleep(unsigned secs, unsigned allow_zero_time)
static void _sleep_and_rescan_devices(struct cmd_context *cmd, struct daemon_parms *parms)
{
- if (parms->interval && !parms->aborting) {
+ if (!parms->aborting) {
/*
* FIXME: do we really need to drop everything and then rescan
* everything between each iteration? What change exactly does
@@ -136,7 +136,7 @@ static void _sleep_and_rescan_devices(struct cmd_context *cmd, struct daemon_par
*/
lvmcache_destroy(cmd, 1, 0);
label_scan_destroy(cmd);
- _nanosleep(parms->interval, 1);
+ _nanosleep(parms->interval, 0);
lvmcache_label_scan(cmd);
}
}
3 years, 2 months
main - lvremove: use to_remove for snapshot removal
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5edb353062b26bbe930...
Commit: 5edb353062b26bbe93002717d77aa5d1707f1f70
Parent: 0a2d7c57a1120045e1a93a63bc568dc1e3dbb734
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 14 13:18:45 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:11:35 2021 +0100
lvremove: use to_remove for snapshot removal
Reuse similar 'acceleration' as used for dependent volumes also
for snapshot - so when origin is being removed with all thick
snapshots, don't bother with individual 'COW' detachments
and write&commits, and when possible handle this all within
a single commit.
---
lib/metadata/lv_manip.c | 15 ++++++++-------
lib/metadata/snapshot_manip.c | 10 ++++++++++
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 1d341eea2..6fc7afbac 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -6823,13 +6823,10 @@ static int _lv_remove_segs_using_this_lv(struct cmd_context *cmd, struct logical
yes_no_prompt("Removing %s \"%s\" will remove %u dependent volume(s). "
"Proceed? [y/n]: ", lv_type, lv->name,
dm_list_size(&lv->segs_using_this_lv)) == 'n') {
- log_error("Logical volume \"%s\" not removed.", lv->name);
- return 0;
- }
-
- /* Make aware users of this LV, it's going to be removed, so they
- * can skip any updates of itself */
- lv->to_remove = 1;
+ lv->to_remove = 0;
+ log_error("Logical volume \"%s\" not removed.", lv->name);
+ return 0;
+ }
/*
* Not using _safe iterator here - since we may delete whole subtree
@@ -6859,6 +6856,10 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
struct lv_list *lvl;
struct logical_volume *origin;
+ /* Make aware users of this LV, it's going to be removed, so they
+ * can skip any updates of itself */
+ lv->to_remove = 1;
+
if (!level && lv_is_cow(lv)) {
/*
* A merging snapshot cannot be removed directly unless
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index 3ee5f4a86..463bb291b 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -325,6 +325,16 @@ int vg_remove_snapshot(struct logical_volume *cow)
cow->snapshot = NULL;
lv_set_visible(cow);
+ /* When origin with all its snapshots is going to be remove
+ * don't bother with individual manipulation with COWs
+ * Note: removal proceeds only when origin is inactive */
+ if (is_origin_active && origin->to_remove) {
+ origin->vg->needs_write_and_commit = 1;
+ log_debug_metadata("Postponing write and commit for remove of snapshot %s.",
+ display_lvname(cow));
+ return 1;
+ }
+
if (!vg_write(origin->vg))
return_0;
3 years, 2 months
main - lvremove: use common routine for prompting
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0a2d7c57a1120045e1a...
Commit: 0a2d7c57a1120045e1a93a63bc568dc1e3dbb734
Parent: a18409b6d1d6a90e432b0b0079ce702d0055fa5a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 14 13:17:03 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 11:08:47 2021 +0100
lvremove: use common routine for prompting
Move code for prompting about removed LV to a single function
and use it also to prompt for removal of origin and all its thick
snapshots and also when removing merging origin.
Function does handle postponed write_and_commit so there is
no 'in-flight' operation while waiting on [y|n] answer.
---
lib/metadata/lv_manip.c | 136 +++++++++++++++++++++++++++---------------------
1 file changed, 76 insertions(+), 60 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index ec8704ce7..1d341eea2 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -6527,6 +6527,65 @@ void lv_set_hidden(struct logical_volume *lv)
log_debug_metadata("LV %s in VG %s is now hidden.", lv->name, lv->vg->name);
}
+static int _lv_remove_check_in_use(struct logical_volume *lv, force_t force)
+{
+ struct volume_group *vg = lv->vg;
+ const char *volume_type = "";
+ char buffer[50 * NAME_LEN * 2] = "";
+ int active;
+ int issue_discards =
+ (vg->cmd->current_settings.issue_discards &&
+ !lv_is_thin_volume(lv) &&
+ !lv_is_vdo(lv) &&
+ !lv_is_virtual_origin(lv)) ? 1 : 0;
+
+ switch (lv_check_not_in_use(lv, 1)) {
+ case 2: /* Not active, prompt when discarding real LVs */
+ if (!issue_discards ||
+ lv_is_historical(lv))
+ return 1;
+ active = 0;
+ break;
+ case 1: /* Active, not in use, prompt when visible */
+ if (!lv_is_visible(lv) ||
+ lv_is_pending_delete(lv))
+ return 1;
+ active = 1;
+ break;
+ default: /* Active, in use, can't remove */
+ return_0;
+ }
+
+ if (force == PROMPT) {
+ if (vg->needs_write_and_commit && (!vg_write(vg) || !vg_commit(vg)))
+ return_0;
+
+ if (lv_is_origin(lv)) {
+ volume_type = " origin";
+ (void) dm_snprintf(buffer, sizeof(buffer), " with %u snapshots(s)",
+ lv->origin_count);
+ } else if (lv_is_merging_origin(lv)) {
+ volume_type = " merging origin";
+ (void) dm_snprintf(buffer, sizeof(buffer), " with snapshot %s",
+ display_lvname(find_snapshot(lv)->lv));
+ }
+
+ if (yes_no_prompt("Do you really want to remove%s%s%s%s "
+ "logical volume %s%s? [y/n]: ",
+ issue_discards ? " and DISCARD" : "",
+ active ? " active" : "",
+ vg_is_clustered(vg) ? " clustered" : "",
+ volume_type, display_lvname(lv),
+ buffer) == 'n') {
+ lv->to_remove = 0;
+ log_error("Logical volume %s not removed.", display_lvname(lv));
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
force_t force, int suppress_remove_message)
{
@@ -6535,7 +6594,6 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
struct logical_volume *pool_lv = NULL;
struct logical_volume *lock_lv = lv;
struct lv_segment *cache_seg = NULL;
- int ask_discard;
struct seg_list *sl;
struct lv_segment *seg = first_seg(lv);
char msg[NAME_LEN + 300], *msg_dup;
@@ -6602,31 +6660,9 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!lockd_lv(cmd, lock_lv, "ex", LDLV_PERSISTENT))
return_0;
- /* FIXME Ensure not referred to by another existing LVs */
- ask_discard = find_config_tree_bool(cmd, devices_issue_discards_CFG, NULL);
-
if (!lv_is_cache_vol(lv)) {
- switch (lv_check_not_in_use(lv, 1)) {
- case 0: return_0;
- case 1: /* Active, not in use */
- if ((force == PROMPT) &&
- !lv_is_pending_delete(lv) &&
- lv_is_visible(lv)) {
- if (vg->needs_write_and_commit && (!vg_write(vg) || !vg_commit(vg)))
- return_0;
- if (yes_no_prompt("Do you really want to remove%s active "
- "%slogical volume %s? [y/n]: ",
- ask_discard ? " and DISCARD" : "",
- vg_is_clustered(vg) ? "clustered " : "",
- display_lvname(lv)) == 'n') {
- log_error("Logical volume %s not removed.", display_lvname(lv));
- return 0;
- }
- ask_discard = 0;
- }
- break;
- default: /* Not active */ ;
- }
+ if (!_lv_remove_check_in_use(lv, force))
+ return_0;
}
if (lv_is_writecache(lv)) {
@@ -6651,17 +6687,6 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
}
}
- if (!lv_is_historical(lv) && (force == PROMPT) && ask_discard) {
- /* try to store on disks already confirmed removals */
- if (vg->needs_write_and_commit && (!vg_write(vg) || !vg_commit(vg)))
- return_0;
- if (yes_no_prompt("Do you really want to remove and DISCARD "
- "logical volume %s? [y/n]: ",
- display_lvname(lv)) == 'n') {
- log_error("Logical volume %s not removed.", display_lvname(lv));
- return 0;
- }
- }
/* Used cache pool, COW or historical LV cannot be activated */
if (!lv_is_used_cache_pool(lv) &&
@@ -6872,20 +6897,12 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
if (lv_is_origin(lv)) {
/* Remove snapshot LVs first */
- if ((force == PROMPT) &&
- /* Active snapshot already needs to confirm each active LV */
- (yes_no_prompt("Do you really want to remove%s "
- "%sorigin logical volume %s with %u snapshot(s)? [y/n]: ",
- lv_is_active(lv) ? " active" : "",
- vg_is_clustered(lv->vg) ? "clustered " : "",
- display_lvname(lv),
- lv->origin_count) == 'n'))
- goto no_remove;
+ if (!_lv_remove_check_in_use(lv, force))
+ return_0;
- if (!deactivate_lv(cmd, lv)) {
- stack;
+ if (!deactivate_lv(cmd, lv))
goto no_remove;
- }
+
log_verbose("Removing origin logical volume %s with %u snapshots(s).",
display_lvname(lv), lv->origin_count);
@@ -6894,20 +6911,19 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
origin_list)->cow,
force, level + 1))
return_0;
- }
+ } else if (lv_is_merging_origin(lv)) {
+ /* Removing thin merging origin requires to remove its merging snapshot first */
+ if (!_lv_remove_check_in_use(lv, force))
+ return_0;
+
+ if (!deactivate_lv(cmd, lv))
+ goto no_remove;
+
+ log_verbose("Removing merging origin logical volume %s.", display_lvname(lv));
- if (lv_is_merging_origin(lv)) {
- if (!deactivate_lv(cmd, lv)) {
- log_error("Unable to fully deactivate merging origin %s.",
- display_lvname(lv));
- return 0;
- }
if (!lv_remove_with_dependencies(cmd, find_snapshot(lv)->lv,
- force, level + 1)) {
- log_error("Unable to remove merging origin %s.",
- display_lvname(lv));
- return 0;
- }
+ force, level + 1))
+ return_0;
}
if (!level && lv_is_merging_thin_snapshot(lv)) {
3 years, 2 months
main - vg_validate: fix validation of merging thin origin
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a18409b6d1d6a90e432...
Commit: a18409b6d1d6a90e432b0b0079ce702d0055fa5a
Parent: ff712987a5792cfc3fba03889ec4485294386a03
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 14 11:44:54 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 15 10:59:09 2021 +0100
vg_validate: fix validation of merging thin origin
Compat code and handle unusual case, where
thin snapshot is also a 'thick snapshot origin' and such
snapshot gets merged into a thin origin.
However since now lv_is_visible() (which is complex function)
replaced &VISIBLE_LV check, the whole this check seems to be
no longer useful as sum of all 3 will always match??
---
lib/metadata/metadata.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index ed1c05f75..cee236e3e 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -2397,12 +2397,6 @@ int vg_validate(struct volume_group *vg)
}
}
- if (lv_is_cow(lvl->lv))
- num_snapshots++;
-
- if (lv_is_visible(lvl->lv))
- lv_visible_count++;
-
if (!check_lv_segments(lvl->lv, 0)) {
log_error(INTERNAL_ERROR "LV segments corrupted in %s.",
lvl->lv->name);
@@ -2427,19 +2421,12 @@ int vg_validate(struct volume_group *vg)
r = 0;
}
- if (lvl->lv->status & VISIBLE_LV)
- continue;
-
- /* snapshots */
- if (lv_is_cow(lvl->lv))
- continue;
-
- /* virtual origins are always hidden */
- if (lv_is_origin(lvl->lv) && !lv_is_virtual_origin(lvl->lv))
- continue;
-
- /* count other non-snapshot invisible volumes */
- hidden_lv_count++;
+ if (lv_is_visible(lvl->lv))
+ lv_visible_count++;
+ else if (lv_is_cow(lvl->lv))
+ num_snapshots++;
+ else /* count other non-snapshot invisible volumes */
+ hidden_lv_count++;
/*
* FIXME: add check for unreferenced invisible LVs
3 years, 2 months