mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_03_14-vdo-fixes.patch

0c180e
From 5d0756fc33bced8453fb5cf5807c5a3fa2b59dbb Mon Sep 17 00:00:00 2001
0c180e
From: Zdenek Kabelac <zkabelac@redhat.com>
0c180e
Date: Tue, 31 Aug 2021 20:52:26 +0200
0c180e
Subject: [PATCH 1/5] vdo: fixes
0c180e
0c180e
Better identify VDO device with major:minor.
0c180e
Handle different LV name from originally converted origin LV.
0c180e
Improve --dry-run handling.
0c180e
0c180e
(cherry picked from commit 1ae157a0f67e984ef3037d19d62b84a3b0201c84)
0c180e
---
0c180e
 WHATS_NEW                 |  4 +++
0c180e
 scripts/lvm_import_vdo.sh | 70 +++++++++++++++++++++++++++++++++++------------
0c180e
 test/shell/vdo-convert.sh | 28 ++++++++++++++-----
0c180e
 3 files changed, 78 insertions(+), 24 deletions(-)
0c180e
0c180e
diff --git a/WHATS_NEW b/WHATS_NEW
0c180e
index 3637e31..b751009 100644
0c180e
--- a/WHATS_NEW
0c180e
+++ b/WHATS_NEW
0c180e
@@ -1,5 +1,9 @@
0c180e
 Version 2.03.14 - 
0c180e
 ==================================
0c180e
+  Improve lvm_import_vdo script.
0c180e
+  Support VDO LV with lvcreate -ky.
0c180e
+  Fix lvconvert for VDO LV bigger then 2T.
0c180e
+  Create VDO LVs automatically without zeroing.
0c180e
   Rename vdoimport to lvm_import_vdo.
0c180e
 
0c180e
 Version 2.03.13 - 
0c180e
diff --git a/scripts/lvm_import_vdo.sh b/scripts/lvm_import_vdo.sh
0c180e
index 35140a0..bc73306 100755
0c180e
--- a/scripts/lvm_import_vdo.sh
0c180e
+++ b/scripts/lvm_import_vdo.sh
0c180e
@@ -41,10 +41,15 @@ BLOCKDEV="blockdev"
0c180e
 READLINK="readlink"
0c180e
 READLINK_E="-e"
0c180e
 MKDIR="mkdir"
0c180e
+DMSETUP="dmsetup"
0c180e
 
0c180e
 TEMPDIR="${TMPDIR:-/tmp}/${TOOL}_${RANDOM}$$"
0c180e
 DM_DEV_DIR="${DM_DEV_DIR:-/dev}"
0c180e
 
0c180e
+DEVICENAME=""
0c180e
+DEVMAJOR=0
0c180e
+DEVMINOR=0
0c180e
+
0c180e
 DRY=0
0c180e
 VERB=""
0c180e
 FORCE=""
0c180e
@@ -147,8 +152,6 @@ get_largest_extent_size_() {
0c180e
 # dereference device name if it is symbolic link
0c180e
 detect_lv_() {
0c180e
 	local DEVICE=$1
0c180e
-	local MAJOR
0c180e
-	local MINOR
0c180e
 	local SYSVOLUME
0c180e
 	local MAJORMINOR
0c180e
 
0c180e
@@ -161,17 +164,21 @@ detect_lv_() {
0c180e
 	  /dev/dm-[0-9]*)
0c180e
 		read -r <"/sys/block/${RDEVICE#/dev/}/dm/name" SYSVOLUME 2>&1 && DEVICE="$DM_DEV_DIR/mapper/$SYSVOLUME"
0c180e
 		read -r <"/sys/block/${RDEVICE#/dev/}/dev" MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$DEVICE\"."
0c180e
-		MAJOR=${MAJORMINOR%%:*}
0c180e
-		MINOR=${MAJORMINOR##*:}
0c180e
+		DEVMAJOR=${MAJORMINOR%%:*}
0c180e
+		DEVMINOR=${MAJORMINOR##*:}
0c180e
 		;;
0c180e
 	  *)
0c180e
-		STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$RDEVICE")
0c180e
+		STAT=$(stat --format "DEVMAJOR=\$((0x%t)) DEVMINOR=\$((0x%T))" "$RDEVICE")
0c180e
 		test -n "$STAT" || error "Cannot get major:minor for \"$DEVICE\"."
0c180e
 		eval "$STAT"
0c180e
 		;;
0c180e
 	esac
0c180e
 
0c180e
-	eval "$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o uuid,name --noheadings --nameprefixes --separator ' ')"
0c180e
+	DEV="$("$DMSETUP" info -c -j "$DEVMAJOR" -m "$DEVMINOR" -o uuid,name --noheadings --nameprefixes --separator ' ' 2>/dev/null)"
0c180e
+	case "$DEV" in
0c180e
+	Device*)  ;; # no devices
0c180e
+	*)	eval "$DEV" ;;
0c180e
+	esac
0c180e
 }
0c180e
 
0c180e
 # parse yaml config files into 'prefix_yaml_part_names=("value")' strings
0c180e
@@ -226,20 +233,26 @@ convert2lvm_() {
0c180e
 	local TRVDONAME
0c180e
 	local EXTENTSZ
0c180e
 	local IS_LV=1
0c180e
+	local FOUND=""
0c180e
+	local MAJOR=0
0c180e
+	local MINOR=0
0c180e
+	local DM_VG_NAME
0c180e
+	local DM_LV_NAME
0c180e
 
0c180e
 	DM_UUID=""
0c180e
 	detect_lv_ "$DEVICE"
0c180e
 	case "$DM_UUID" in
0c180e
-		LVM-*)	eval "$(dmsetup splitname --nameprefixes --noheadings --separator ' ' "$DM_NAME")"
0c180e
+		LVM-*)	eval "$("$DMSETUP" splitname --nameprefixes --noheadings --separator ' ' "$DM_NAME")"
0c180e
 			if [ -z "$VGNAME" ] || [ "$VGNAME" = "$LVNAME" ]  ; then
0c180e
 				VGNAME=$DM_VG_NAME
0c180e
+				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
 			fi
0c180e
 			;;
0c180e
 		*) IS_LV=0
0c180e
 			# Check $VGNANE does not already exists
0c180e
-			"$LVM" vgs "$VGNAME" && error "Cannot use already existing volume group name \"$VGNAME\"."
0c180e
+			"$LVM" vgs "$VGNAME" >/dev/null 2>&1 && error "Cannot use already existing volume group name \"$VGNAME\"."
0c180e
 			;;
0c180e
 	esac
0c180e
 
0c180e
@@ -247,15 +260,37 @@ convert2lvm_() {
0c180e
 
0c180e
 	"$MKDIR" -p -m 0000 "$TEMPDIR" || error "Failed to create $TEMPDIR."
0c180e
 
0c180e
+	# TODO: might use directly  /etc/vdoconf.yml (avoding need of 'vdo' manager)
0c180e
 	verbose "Getting YAML VDO configuration."
0c180e
 	"$VDO" printConfigFile $VDOCONF >"$TEMPDIR/vdoconf.yml"
0c180e
 
0c180e
-	VDONAME=$(awk -v DNAME="$DEVICE" '/.*VDOService$/ {VNAME=substr($1, 0, length($1) - 1)} /[[:space:]]*device:/ { if ($2 ~ DNAME) {print VNAME}}' "$TEMPDIR/vdoconf.yml")
0c180e
+	# Check list of devices in VDO configure file for their major:minor
0c180e
+	# and match with given $DEVICE devmajor:devminor
0c180e
+	for i in $(awk '/.*device:/ {print $2}' "$TEMPDIR/vdoconf.yml") ; do
0c180e
+		local DEV
0c180e
+		DEV=$("$READLINK" $READLINK_E "$i") || continue
0c180e
+		STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$DEV" 2>/dev/null) || continue
0c180e
+		eval "$STAT"
0c180e
+		test "$MAJOR" = "$DEVMAJOR" && test "$MINOR" = "$DEVMINOR" && {
0c180e
+			test -z "$FOUND" || error "VDO configuration contains duplicate entries $FOUND and $i"
0c180e
+			FOUND=$i
0c180e
+		}
0c180e
+	done
0c180e
+
0c180e
+	test -n "$FOUND" || error "Can't find matching device in vdo configuration file."
0c180e
+	verbose "Found matching device $FOUND  $MAJOR:$MINOR"
0c180e
+
0c180e
+	VDONAME=$(awk -v DNAME="$FOUND" '/.*VDOService$/ {VNAME=substr($1, 0, length($1) - 1)} /[[:space:]]*device:/ { if ($2 ~ DNAME) {print VNAME}}' "$TEMPDIR/vdoconf.yml")
0c180e
 	TRVDONAME=$(echo "$VDONAME" | tr '-' '_')
0c180e
 
0c180e
 	# When VDO volume is 'active', check it's not mounted/being used
0c180e
-	eval "$(dmsetup info -c -o open  "$VDONAME" --noheadings --nameprefixes || true)"
0c180e
-	test "${DM_OPEN:-0}" -eq 0 || error "Cannot converted VDO volume \"$VDONAME\" which is in use!"
0c180e
+	DM_OPEN="$("$DMSETUP" info -c -o open  "$VDONAME" --noheadings --nameprefixes 2>/dev/null || true)"
0c180e
+	case "$DM_OPEN" in
0c180e
+	Device*) ;; # no devices
0c180e
+	*) 	eval "$DM_OPEN"
0c180e
+		test "${DM_OPEN:-0}" -eq 0 || error "Cannot converted VDO volume \"$VDONAME\" which is in use!"
0c180e
+		;;
0c180e
+	esac
0c180e
 
0c180e
 	#parse_yaml_ "$TEMPDIR/vdoconf.yml" _
0c180e
 	eval "$(parse_yaml_ "$TEMPDIR/vdoconf.yml" _ | grep "$TRVDONAME" | sed -e "s/_config_vdos_$TRVDONAME/vdo/g")"
0c180e
@@ -263,8 +298,7 @@ convert2lvm_() {
0c180e
 	vdo_logicalSize=$(get_kb_size_with_unit_ "$vdo_logicalSize")
0c180e
 	vdo_physicalSize=$(get_kb_size_with_unit_ "$vdo_physicalSize")
0c180e
 
0c180e
-	verbose "Going to convert physical sized VDO device $vdo_physicalSize KiB."
0c180e
-	verbose "With logical volume of size $vdo_logicalSize KiB."
0c180e
+	verbose "Converted VDO device has logical/physical size $vdo_logicalSize/$vdo_physicalSize KiB."
0c180e
 
0c180e
 	PARAMS=$(cat <
0c180e
 allocation {
0c180e
@@ -313,7 +347,7 @@ EOF
0c180e
 
0c180e
 		pvfree=$(( pvfree / 1024 - 2048 ))	# to KiB
0c180e
 	else
0c180e
-		pvfree=$("$LVM" lvs -o size --units b --nosuffix --noheadings "$VGNAME/$LVNAME")
0c180e
+		pvfree=$("$LVM" lvs -o size --units b --nosuffix --noheadings "$DM_VG_NAME/$DM_LV_NAME")
0c180e
 		pvfree=$(( pvfree / 1024 ))		# to KiB
0c180e
 	fi
0c180e
 
0c180e
@@ -334,11 +368,11 @@ EOF
0c180e
 		vg_extent_size=$(( vg_extent_size / 1024 ))
0c180e
 
0c180e
 		test "$vg_extent_size" -le "$EXTENTSZ" || {
0c180e
-			error "Please vgchange extent_size to at most $EXTENTSZ KiB or extend and align virtual size on $vg_extent_size KiB."
0c180e
+			error "Please vgchange extent_size to at most $EXTENTSZ KiB or extend and align virtual size of VDO device on $vg_extent_size KiB."
0c180e
 		}
0c180e
 		verbose "Renaming existing LV to be used as _vdata volume for VDO pool LV."
0c180e
-		dry "$LVM" lvrename $YES $VERB "$VGNAME/$LVNAME" "$VGNAME/${LVNAME}_vpool" || {
0c180e
-			error "Rename of LV \"$VGNAME/$LVNAME\" failed, while VDO header has been already moved!"
0c180e
+		dry "$LVM" lvrename $YES $VERB "$VGNAME/$DM_LV_NAME" "$VGNAME/${LVNAME}_vpool" || {
0c180e
+			error "Rename of LV \"$VGNAME/$DM_LV_NAME\" failed, while VDO header has been already moved!"
0c180e
 		}
0c180e
 	fi
0c180e
 
0c180e
@@ -372,5 +406,7 @@ do
0c180e
 	shift
0c180e
 done
0c180e
 
0c180e
+test -n "$DEVICENAME" || error "Device name is not specified. (see: $TOOL --help)"
0c180e
+
0c180e
 # do conversion
0c180e
 convert2lvm_ "$DEVICENAME"
0c180e
diff --git a/test/shell/vdo-convert.sh b/test/shell/vdo-convert.sh
0c180e
index 2d16c97..493f415 100644
0c180e
--- a/test/shell/vdo-convert.sh
0c180e
+++ b/test/shell/vdo-convert.sh
0c180e
@@ -61,22 +61,36 @@ lvm_import_vdo --dry-run -y -v --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
0c180e
 
0c180e
 lvm_import_vdo -y --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
0c180e
 
0c180e
-# ATM needed - since we do not call 'vdo convert' in this case
0c180e
-vdo remove $VDOCONF --force --name "$VDONAME" || true
0c180e
+# ensure VDO device is not left in config file
0c180e
+vdo remove $VDOCONF --force --name "$VDONAME" 2>/dev/null || true
0c180e
+
0c180e
+lvremove -f $vg
0c180e
+
0c180e
+
0c180e
+# Test user can specify different VDO LV name (so the original LV is renamed)
0c180e
+lvcreate -y -L5G -n $lv1 $vg
0c180e
+
0c180e
+vdo create $VDOCONF --name "$VDONAME" --device="$DM_DEV_DIR/$vg/$lv1" --vdoLogicalSize=10G
0c180e
+
0c180e
+lvm_import_vdo -y --name $vg/$lv2 "$DM_DEV_DIR/$vg/$lv1"
0c180e
+
0c180e
+check lv_exists $vg $lv2
0c180e
+check lv_not_exists $vg $lv1
0c180e
 
0c180e
 vgremove -f $vg
0c180e
 
0c180e
+# ensure VDO device is not left in config file
0c180e
+vdo remove $VDOCONF --force --name "$VDONAME" 2>/dev/null || true
0c180e
+
0c180e
 aux wipefs_a "$dev1"
0c180e
 
0c180e
 # prepare 'unused' $vg2
0c180e
 vgcreate $vg2 "$dev2"
0c180e
 
0c180e
 #
0c180e
-# Check conversion of VDO volume on  non-LV device
0c180e
+# Check conversion of VDO volume on non-LV device and with >2T size
0c180e
 #
0c180e
-vdo create $VDOCONF --name "$VDONAME" --device="$dev1" --vdoLogicalSize=31G
0c180e
-
0c180e
-mkfs -E nodiscard "$DM_DEV_DIR/mapper/$VDONAME"
0c180e
+vdo create $VDOCONF --name "$VDONAME" --device="$dev1" --vdoLogicalSize=3T
0c180e
 
0c180e
 # Fail with an already existing volume group $vg2
0c180e
 not lvm_import_vdo --dry-run -y -v --name $vg2/$lv1 "$dev1" |& tee err
0c180e
@@ -87,7 +101,7 @@ vdo stop $VDOCONF --name "$VDONAME"
0c180e
 
0c180e
 lvm_import_vdo -y -v --name $vg/$lv1 "$dev1"
0c180e
 
0c180e
-fsck -n "$DM_DEV_DIR/$vg/$lv1"
0c180e
+check lv_field $vg/$lv1 size "3.00t"
0c180e
 
0c180e
 vgremove -f $vg
0c180e
 
0c180e
-- 
0c180e
1.8.3.1
0c180e