|
|
0c180e |
From 6621116b61f4c9ee53166a994be2ef7d80a3c346 Mon Sep 17 00:00:00 2001
|
|
|
0c180e |
From: Zdenek Kabelac <zkabelac@redhat.com>
|
|
|
0c180e |
Date: Mon, 6 Sep 2021 15:06:32 +0200
|
|
|
0c180e |
Subject: [PATCH 4/5] vdo: more lvm_import_vdo fixes
|
|
|
0c180e |
|
|
|
0c180e |
Do not call 'dmsetup info' for non-dm devices.
|
|
|
0c180e |
|
|
|
0c180e |
Better handling for VGNAME and LVNAME - so when convering LV as
|
|
|
0c180e |
backend device automatically recognize it and reuse LV name for VDOLV.
|
|
|
0c180e |
|
|
|
0c180e |
Add prompt for final confirmation before actual conversion is started
|
|
|
0c180e |
(once confirmed, lvm2 commands no longer prompts to avoid leaving
|
|
|
0c180e |
conversion in the middle of its process.)
|
|
|
0c180e |
|
|
|
0c180e |
(cherry picked from commit 89595a366554191c3df1a18e1f82b79c450a21ad)
|
|
|
0c180e |
---
|
|
|
0c180e |
scripts/lvm_import_vdo.sh | 48 ++++++++++++++++++++++++++++++++++------
|
|
|
0c180e |
test/shell/vdo-convert.sh | 56 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
0c180e |
2 files changed, 97 insertions(+), 7 deletions(-)
|
|
|
0c180e |
|
|
|
0c180e |
diff --git a/scripts/lvm_import_vdo.sh b/scripts/lvm_import_vdo.sh
|
|
|
0c180e |
index dec32bc..70904f7 100755
|
|
|
0c180e |
--- a/scripts/lvm_import_vdo.sh
|
|
|
0c180e |
+++ b/scripts/lvm_import_vdo.sh
|
|
|
0c180e |
@@ -50,6 +50,7 @@ DM_DEV_DIR="${DM_DEV_DIR:-/dev}"
|
|
|
0c180e |
DEVICENAME=""
|
|
|
0c180e |
DEVMAJOR=0
|
|
|
0c180e |
DEVMINOR=0
|
|
|
0c180e |
+PROMPTING=""
|
|
|
0c180e |
|
|
|
0c180e |
DRY=0
|
|
|
0c180e |
VERB=""
|
|
|
0c180e |
@@ -57,7 +58,8 @@ FORCE=""
|
|
|
0c180e |
YES=""
|
|
|
0c180e |
|
|
|
0c180e |
# default name for converted VG and its VDO LV
|
|
|
0c180e |
-NAME="vdovg/vdolvol"
|
|
|
0c180e |
+DEFAULT_NAME="vdovg/vdolvol"
|
|
|
0c180e |
+NAME=""
|
|
|
0c180e |
|
|
|
0c180e |
# help message
|
|
|
0c180e |
tool_usage() {
|
|
|
0c180e |
@@ -100,6 +102,7 @@ dry() {
|
|
|
0c180e |
cleanup() {
|
|
|
0c180e |
trap '' 2
|
|
|
0c180e |
|
|
|
0c180e |
+ test -z "$PROMPTING" || echo "No"
|
|
|
0c180e |
rm -rf "$TEMPDIR"
|
|
|
0c180e |
# error exit status for break
|
|
|
0c180e |
exit "${1:-1}"
|
|
|
0c180e |
@@ -175,7 +178,9 @@ detect_lv_() {
|
|
|
0c180e |
;;
|
|
|
0c180e |
esac
|
|
|
0c180e |
|
|
|
0c180e |
- DEV="$("$DMSETUP" info -c -j "$DEVMAJOR" -m "$DEVMINOR" -o uuid,name --noheadings --nameprefixes --separator ' ' 2>/dev/null)"
|
|
|
0c180e |
+ test "$DEVMAJOR" != "$(grep device-mapper /proc/devices | cut -f1 -d' ')" && return
|
|
|
0c180e |
+
|
|
|
0c180e |
+ DEV="$("$DMSETUP" info -c -j "$DEVMAJOR" -m "$DEVMINOR" -o uuid,name --noheadings --nameprefixes --separator ' ')"
|
|
|
0c180e |
case "$DEV" in
|
|
|
0c180e |
Device*) ;; # no devices
|
|
|
0c180e |
*) eval "$DEV" ;;
|
|
|
0c180e |
@@ -244,15 +249,31 @@ convert2lvm_() {
|
|
|
0c180e |
detect_lv_ "$DEVICE"
|
|
|
0c180e |
case "$DM_UUID" in
|
|
|
0c180e |
LVM-*) eval "$("$DMSETUP" splitname --nameprefixes --noheadings --separator ' ' "$DM_NAME")"
|
|
|
0c180e |
- if [ -z "$VGNAME" ] || [ "$VGNAME" = "$LVNAME" ] ; then
|
|
|
0c180e |
+ if [ -z "$VGNAME" ] || [ "$VGNAME" = "$LVNAME" ] ; then
|
|
|
0c180e |
VGNAME=$DM_VG_NAME
|
|
|
0c180e |
- LVNAME=$DM_LV_NAME
|
|
|
0c180e |
+ verbose "Using existing volume group name $VGNAME."
|
|
|
0c180e |
+ test -n "$LVNAME" || LVNAME=$DM_LV_NAME
|
|
|
0c180e |
elif test "$VGNAME" != "$DM_VG_NAME" ; then
|
|
|
0c180e |
- error "Volume group name \"$VGNAME\" does not match name \"$DM_VG_NAME\" for device \"$DEVICE\"."
|
|
|
0c180e |
+ error "Volume group name \"$VGNAME\" does not match name \"$DM_VG_NAME\" for VDO device \"$DEVICE\"."
|
|
|
0c180e |
fi
|
|
|
0c180e |
;;
|
|
|
0c180e |
- *) IS_LV=0
|
|
|
0c180e |
- # Check $VGNANE does not already exists
|
|
|
0c180e |
+ *) IS_LV=0
|
|
|
0c180e |
+ # Check if we need to generate unused $VGNANE
|
|
|
0c180e |
+ if [ -z "$VGNAME" ] || [ "$VGNAME" = "$LVNAME" ] ; then
|
|
|
0c180e |
+ VGNAME=${DEFAULT_NAME%/*}
|
|
|
0c180e |
+ # Find largest matching VG name to our 'default' vgname
|
|
|
0c180e |
+ LASTVGNAME=$(LC_ALL=C "$LVM" vgs -oname -O-name --noheadings -S name=~${VGNAME} | grep -E "$VGNAME[0-9]? ?" | head -1)
|
|
|
0c180e |
+ if test -n "$LASTVGNAME" ; then
|
|
|
0c180e |
+ LASTVGNAME=${LASTVGNAME#*${VGNAME}}
|
|
|
0c180e |
+ # If the number is becoming too high, try some random number
|
|
|
0c180e |
+ test "$LASTVGNAME" -gt 99999999 2>/dev/null && LASTVGNAME=$RANDOM
|
|
|
0c180e |
+ # Generate new unused VG name
|
|
|
0c180e |
+ VGNAME="${VGNAME}$(( ${LASTVGNAME} + 1 ))"
|
|
|
0c180e |
+ verbose "Selected unused volume group name $VGNAME."
|
|
|
0c180e |
+ fi
|
|
|
0c180e |
+ fi
|
|
|
0c180e |
+ # New VG is created, LV name should be always unused.
|
|
|
0c180e |
+ test -n "$LVNAME" || LVNAME=${DEFAULT_NAME#*/}
|
|
|
0c180e |
"$LVM" vgs "$VGNAME" >/dev/null 2>&1 && error "Cannot use already existing volume group name \"$VGNAME\"."
|
|
|
0c180e |
;;
|
|
|
0c180e |
esac
|
|
|
0c180e |
@@ -328,6 +349,19 @@ EOF
|
|
|
0c180e |
)
|
|
|
0c180e |
verbose "VDO conversion paramaters: $PARAMS"
|
|
|
0c180e |
|
|
|
0c180e |
+ # If user has not provided '--yes', prompt before conversion
|
|
|
0c180e |
+ if test -z "$YES" ; then
|
|
|
0c180e |
+ PROMPTING=yes
|
|
|
0c180e |
+ echo -n "Convert VDO device \"$DEVICE\" to VDO LV \"$VGNAME/$LVNAME\"? [y|N]: "
|
|
|
0c180e |
+ read -n 1 -s ANSWER
|
|
|
0c180e |
+ case "${ANSWER:0:1}" in
|
|
|
0c180e |
+ y|Y ) echo "Yes" ;;
|
|
|
0c180e |
+ * ) echo "No" ; PROMPTING=""; exit ;;
|
|
|
0c180e |
+ esac
|
|
|
0c180e |
+ PROMPTING=""
|
|
|
0c180e |
+ YES="-y" # From now, now prompting
|
|
|
0c180e |
+ fi
|
|
|
0c180e |
+
|
|
|
0c180e |
verbose "Stopping VDO volume."
|
|
|
0c180e |
dry "$VDO" stop $VDOCONF --name "$VDONAME"
|
|
|
0c180e |
|
|
|
0c180e |
diff --git a/test/shell/vdo-convert.sh b/test/shell/vdo-convert.sh
|
|
|
0c180e |
index 493f415..632f86a 100644
|
|
|
0c180e |
--- a/test/shell/vdo-convert.sh
|
|
|
0c180e |
+++ b/test/shell/vdo-convert.sh
|
|
|
0c180e |
@@ -122,3 +122,59 @@ fsck -n "$DM_DEV_DIR/$vg1/$lv2"
|
|
|
0c180e |
|
|
|
0c180e |
vgremove -f $vg1
|
|
|
0c180e |
|
|
|
0c180e |
+aux teardown_devs
|
|
|
0c180e |
+
|
|
|
0c180e |
+
|
|
|
0c180e |
+# Check with some real non-DM device from system
|
|
|
0c180e |
+# this needs to dropping DM_DEV_DIR
|
|
|
0c180e |
+
|
|
|
0c180e |
+aux prepare_loop 60000 || skip
|
|
|
0c180e |
+
|
|
|
0c180e |
+test -f LOOP
|
|
|
0c180e |
+LOOP=$(< LOOP)
|
|
|
0c180e |
+
|
|
|
0c180e |
+aux extend_filter "a|$LOOP|"
|
|
|
0c180e |
+aux extend_devices "$LOOP"
|
|
|
0c180e |
+
|
|
|
0c180e |
+#
|
|
|
0c180e |
+# Unfortunatelly generates this in syslog:
|
|
|
0c180e |
+#
|
|
|
0c180e |
+# vdo-start-by-dev@loop0.service: Main process exited, code=exited, status=1/FAILURE
|
|
|
0c180e |
+# vdo-start-by-dev@loop0.service: Failed with result 'exit-code'.
|
|
|
0c180e |
+# Failed to start Start VDO volume backed by loop0.
|
|
|
0c180e |
+#
|
|
|
0c180e |
+# TODO: Could be handled by:
|
|
|
0c180e |
+#
|
|
|
0c180e |
+# systemctl mask vdo-start-by-dev@
|
|
|
0c180e |
+# systemctl unmask vdo-start-by-dev@
|
|
|
0c180e |
+#
|
|
|
0c180e |
+# automate...
|
|
|
0c180e |
+#
|
|
|
0c180e |
+vdo create $VDOCONF --name "$VDONAME" --device="$LOOP" --vdoLogicalSize=23G \
|
|
|
0c180e |
+ --blockMapCacheSize 192 \
|
|
|
0c180e |
+ --blockMapPeriod 2048 \
|
|
|
0c180e |
+ --emulate512 disabled \
|
|
|
0c180e |
+ --indexMem 0.5 \
|
|
|
0c180e |
+ --maxDiscardSize 10 \
|
|
|
0c180e |
+ --sparseIndex disabled \
|
|
|
0c180e |
+ --vdoAckThreads 2 \
|
|
|
0c180e |
+ --vdoBioRotationInterval 8 \
|
|
|
0c180e |
+ --vdoBioThreads 2 \
|
|
|
0c180e |
+ --vdoCpuThreads 5 \
|
|
|
0c180e |
+ --vdoHashZoneThreads 3 \
|
|
|
0c180e |
+ --vdoLogicalThreads 3 \
|
|
|
0c180e |
+ --writePolicy async-unsafe
|
|
|
0c180e |
+
|
|
|
0c180e |
+# Get VDO table line
|
|
|
0c180e |
+dmsetup table "$VDONAME" | tr " " "\n" | sed -e '5,6d' -e '12d' | tee vdo-orig
|
|
|
0c180e |
+
|
|
|
0c180e |
+DM_DEV_DIR= lvm_import_vdo -y --name $vg/$lv "$LOOP"
|
|
|
0c180e |
+lvs -a $vg
|
|
|
0c180e |
+
|
|
|
0c180e |
+dmsetup table "$vg-${lv}_vpool-vpool" | tr " " "\n" | sed -e '5,6d' -e '12d' | tee new-vdo-lv
|
|
|
0c180e |
+
|
|
|
0c180e |
+# Check there is a match between VDO and LV managed volume
|
|
|
0c180e |
+# (when differentiating parameters are deleted first)
|
|
|
0c180e |
+diff -u vdo-orig new-vdo-lv || die "Found mismatching VDO table lines!"
|
|
|
0c180e |
+
|
|
|
0c180e |
+check lv_field $vg/$lv size "23.00g"
|
|
|
0c180e |
--
|
|
|
0c180e |
1.8.3.1
|
|
|
0c180e |
|