Blame SOURCES/lvm2-2_03_14-vdo-Rename-vdoimport-to-lvm_import_vdo.patch

ffcdab
 WHATS_NEW                 |   4 +
ffcdab
 configure                 |   6 +-
ffcdab
 configure.ac              |   8 +-
ffcdab
 include/configure.h.in    |   2 +-
ffcdab
 man/Makefile.in           |   2 +-
ffcdab
 man/lvm_import_vdo.8_main |  92 ++++++++++++
ffcdab
 man/vdoimport.8_main      |  92 ------------
ffcdab
 scripts/Makefile.in       |   2 +-
ffcdab
 scripts/lvm_import_vdo.sh | 376 ++++++++++++++++++++++++++++++++++++++++++++++
ffcdab
 scripts/vdoimport.sh      | 376 ----------------------------------------------
ffcdab
 test/Makefile.in          |   2 +-
ffcdab
 test/shell/vdo-convert.sh |  12 +-
ffcdab
 12 files changed, 489 insertions(+), 485 deletions(-)
ffcdab
 create mode 100644 man/lvm_import_vdo.8_main
ffcdab
 delete mode 100644 man/vdoimport.8_main
ffcdab
 create mode 100755 scripts/lvm_import_vdo.sh
ffcdab
 delete mode 100755 scripts/vdoimport.sh
ffcdab
ffcdab
diff --git a/WHATS_NEW b/WHATS_NEW
ffcdab
index 5556789..3637e31 100644
ffcdab
--- a/WHATS_NEW
ffcdab
+++ b/WHATS_NEW
ffcdab
@@ -1,3 +1,7 @@
ffcdab
+Version 2.03.14 - 
ffcdab
+==================================
ffcdab
+  Rename vdoimport to lvm_import_vdo.
ffcdab
+
ffcdab
 Version 2.03.13 - 
ffcdab
 ===============================
ffcdab
   Support --poolmetadataspare with vgsplit and vgmerge.
ffcdab
diff --git a/configure b/configure
ffcdab
index 661702d..897a810 100755
ffcdab
--- a/configure
ffcdab
+++ b/configure
ffcdab
@@ -12379,8 +12379,8 @@ $as_echo "$FSADM" >&6; }
ffcdab
 
ffcdab
 
ffcdab
 ################################################################################
ffcdab
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to install vdoimport" >&5
ffcdab
-$as_echo_n "checking whether to install vdoimport... " >&6; }
ffcdab
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to install lvm_import_vdo" >&5
ffcdab
+$as_echo_n "checking whether to install lvm_import_vdo... " >&6; }
ffcdab
 # Check whether --enable-vdoimport was given.
ffcdab
 if test "${enable_vdoimport+set}" = set; then :
ffcdab
   enableval=$enable_vdoimport; VDOIMPORT=$enableval
ffcdab
@@ -13875,7 +13875,7 @@ cat >>confdefs.h <<_ACEOF
ffcdab
 _ACEOF
ffcdab
 
ffcdab
 
ffcdab
-VDOIMPORT_PATH="$SBINDIR/vdoimport"
ffcdab
+VDOIMPORT_PATH="$SBINDIR/lvm_import_vdo"
ffcdab
 
ffcdab
 cat >>confdefs.h <<_ACEOF
ffcdab
 #define VDOIMPORT_PATH "$VDOIMPORT_PATH"
ffcdab
diff --git a/configure.ac b/configure.ac
ffcdab
index 5a8b486..f769a63 100644
ffcdab
--- a/configure.ac
ffcdab
+++ b/configure.ac
ffcdab
@@ -1295,8 +1295,8 @@ AC_MSG_RESULT($FSADM)
ffcdab
 
ffcdab
 
ffcdab
 ################################################################################
ffcdab
-dnl -- Enable vdoimport
ffcdab
-AC_MSG_CHECKING(whether to install vdoimport)
ffcdab
+dnl -- Enable lvm_import_vdo
ffcdab
+AC_MSG_CHECKING(whether to install lvm_import_vdo)
ffcdab
 AC_ARG_ENABLE(vdoimport, AC_HELP_STRING([--disable-vdoimport], [disable vdoimport]),
ffcdab
 	      VDOIMPORT=$enableval)
ffcdab
 AC_MSG_RESULT($VDOIMPORT)
ffcdab
@@ -1656,8 +1656,8 @@ USRSBINDIR="$(eval echo $(eval echo $usrsbindir))"
ffcdab
 FSADM_PATH="$SBINDIR/fsadm"
ffcdab
 AC_DEFINE_UNQUOTED(FSADM_PATH, ["$FSADM_PATH"], [Path to fsadm binary.])
ffcdab
 
ffcdab
-VDOIMPORT_PATH="$SBINDIR/vdoimport"
ffcdab
-AC_DEFINE_UNQUOTED(VDOIMPORT_PATH, ["$VDOIMPORT_PATH"], [Path to vdoimport binary.])
ffcdab
+VDOIMPORT_PATH="$SBINDIR/lvm_import_vdo"
ffcdab
+AC_DEFINE_UNQUOTED(VDOIMPORT_PATH, ["$VDOIMPORT_PATH"], [Path to lvm_import_vdo binary.])
ffcdab
 
ffcdab
 ################################################################################
ffcdab
 dnl -- dmeventd pidfile and executable path
ffcdab
diff --git a/include/configure.h.in b/include/configure.h.in
ffcdab
index 6df8d89..028ae48 100644
ffcdab
--- a/include/configure.h.in
ffcdab
+++ b/include/configure.h.in
ffcdab
@@ -684,7 +684,7 @@
ffcdab
 /* Enable a valgrind aware build of pool */
ffcdab
 #undef VALGRIND_POOL
ffcdab
 
ffcdab
-/* Path to vdoimport binary. */
ffcdab
+/* Path to lvm_import_vdo binary. */
ffcdab
 #undef VDOIMPORT_PATH
ffcdab
 
ffcdab
 /* The path to 'vdoformat', if available. */
ffcdab
diff --git a/man/Makefile.in b/man/Makefile.in
ffcdab
index d60a92c..45ebf54 100644
ffcdab
--- a/man/Makefile.in
ffcdab
+++ b/man/Makefile.in
ffcdab
@@ -23,7 +23,7 @@ else
ffcdab
 endif
ffcdab
 
ffcdab
 FSADMMAN = fsadm.8
ffcdab
-VDOIMPORTMAN = vdoimport.8
ffcdab
+VDOIMPORTMAN = lvm_import_vdo.8
ffcdab
 BLKDEACTIVATEMAN = blkdeactivate.8
ffcdab
 DMEVENTDMAN = dmeventd.8
ffcdab
 DMFILEMAPDMAN = dmfilemapd.8
ffcdab
diff --git a/man/lvm_import_vdo.8_main b/man/lvm_import_vdo.8_main
ffcdab
new file mode 100644
ffcdab
index 0000000..ee817a0
ffcdab
--- /dev/null
ffcdab
+++ b/man/lvm_import_vdo.8_main
ffcdab
@@ -0,0 +1,92 @@
ffcdab
+.TH "FSADM" "8" "LVM TOOLS #VERSION#" "Red Hat, Inc" "\""
ffcdab
+.
ffcdab
+.SH "NAME"
ffcdab
+.
ffcdab
+lvm_import_vdo \(em utility to import VDO volumes into a new volume group.
ffcdab
+.
ffcdab
+.SH SYNOPSIS
ffcdab
+.
ffcdab
+.PD 0
ffcdab
+.ad l
ffcdab
+.TP 10
ffcdab
+.B lvm_import_vdo
ffcdab
+.RI [ options ]
ffcdab
+.IR device
ffcdab
+.
ffcdab
+.PD
ffcdab
+.
ffcdab
+.SH DESCRIPTION
ffcdab
+.
ffcdab
+lvm_import_vdo utility imports VDO volumes created and managed by
ffcdab
+.BR vdo (8)
ffcdab
+manager into
ffcdab
+.BR lvm2 (8)
ffcdab
+managed VDO LV. This is realized by moving VDO superblock by 2MiB
ffcdab
+and creating lvm2 metadata at the front of this device. The operation is not reversible,
ffcdab
+thus after conversion to lvm2 the access to VDO data is only possible with
ffcdab
+.BR lvm2 (8)
ffcdab
+commands,
ffcdab
+.BR vdo (8)
ffcdab
+manager no longer control such volume.
ffcdab
+.
ffcdab
+.SH OPTIONS
ffcdab
+.
ffcdab
+.TP
ffcdab
+.BR -f | --force
ffcdab
+Bypass some sanity checks.
ffcdab
+.
ffcdab
+.TP
ffcdab
+.BR -h | --help
ffcdab
+Display the help text.
ffcdab
+.
ffcdab
+.TP
ffcdab
+.BR -n | --name
ffcdab
+Specifies the name of converted VDO LV. When the name is not specified,
ffcdab
+some automatic name is selected. In case the converted VDO volume is
ffcdab
+already using LV a backend device, the name of this LV is used for VDO LV.
ffcdab
+In this case also the of volume group must stay same.
ffcdab
+.
ffcdab
+.TP
ffcdab
+.BR -v | --verbose
ffcdab
+Be more verbose.
ffcdab
+.
ffcdab
+.TP
ffcdab
+.BR -y | --yes
ffcdab
+Answer "yes" at any prompts.
ffcdab
+.
ffcdab
+.TP
ffcdab
+.BR --dry-run
ffcdab
+Print commands without running them.
ffcdab
+.
ffcdab
+.
ffcdab
+.SH DIAGNOSTICS
ffcdab
+.
ffcdab
+On successful completion, the status code is 0.
ffcdab
+A status code of 1 is used for failure.
ffcdab
+.
ffcdab
+.SH EXAMPLES
ffcdab
+.
ffcdab
+Convert VDO volume created by vdo manager into logical volume LV1 with within volume group VG1.
ffcdab
+.P
ffcdab
+#
ffcdab
+.B lvm_import_vdo --name VG1/LV1 /dev/mapper/vdo-volume
ffcdab
+.
ffcdab
+.SH ENVIRONMENT VARIABLES
ffcdab
+.
ffcdab
+.TP
ffcdab
+.B TMPDIR
ffcdab
+The temporary directory name for mount points. Defaults to "\fI/tmp\fP".
ffcdab
+.TP
ffcdab
+.B DM_DEV_DIR
ffcdab
+The device directory name.
ffcdab
+Defaults to "\fI/dev\fP" and must be an absolute path.
ffcdab
+.
ffcdab
+.SH SEE ALSO
ffcdab
+.
ffcdab
+.nh
ffcdab
+.ad l
ffcdab
+.BR lvm (8),
ffcdab
+.BR lvm.conf (5),
ffcdab
+.P
ffcdab
+.BR vdo (8),
ffcdab
+.BR vdo2lvm (8),
ffcdab
diff --git a/man/vdoimport.8_main b/man/vdoimport.8_main
ffcdab
deleted file mode 100644
ffcdab
index 1f32909..0000000
ffcdab
--- a/man/vdoimport.8_main
ffcdab
+++ /dev/null
ffcdab
@@ -1,92 +0,0 @@
ffcdab
-.TH "FSADM" "8" "LVM TOOLS #VERSION#" "Red Hat, Inc" "\""
ffcdab
-.
ffcdab
-.SH "NAME"
ffcdab
-.
ffcdab
-vdoimport \(em utility to import VDO volumes into a new volume group.
ffcdab
-.
ffcdab
-.SH SYNOPSIS
ffcdab
-.
ffcdab
-.PD 0
ffcdab
-.ad l
ffcdab
-.TP 10
ffcdab
-.B vdoimport
ffcdab
-.RI [ options ]
ffcdab
-.IR device
ffcdab
-.
ffcdab
-.PD
ffcdab
-.
ffcdab
-.SH DESCRIPTION
ffcdab
-.
ffcdab
-vdoimport utility imports VDO volumes created and managed by
ffcdab
-.BR vdo (8)
ffcdab
-manager into
ffcdab
-.BR lvm2 (8)
ffcdab
-managed VDO LV. This is realized by moving VDO superblock by 2MiB
ffcdab
-and creating lvm2 metadata at the front of this device. The operation is not reversible,
ffcdab
-thus after conversion to lvm2 the access to VDO data is only possible with
ffcdab
-.BR lvm2 (8)
ffcdab
-commands,
ffcdab
-.BR vdo (8)
ffcdab
-manager no longer control such volume.
ffcdab
-.
ffcdab
-.SH OPTIONS
ffcdab
-.
ffcdab
-.TP
ffcdab
-.BR -f | --force
ffcdab
-Bypass some sanity checks.
ffcdab
-.
ffcdab
-.TP
ffcdab
-.BR -h | --help
ffcdab
-Display the help text.
ffcdab
-.
ffcdab
-.TP
ffcdab
-.BR -n | --name
ffcdab
-Specifies the name of converted VDO LV. When the name is not specified,
ffcdab
-some automatic name is selected. In case the converted VDO volume is
ffcdab
-already using LV a backend device, the name of this LV is used for VDO LV.
ffcdab
-In this case also the of volume group must stay same.
ffcdab
-.
ffcdab
-.TP
ffcdab
-.BR -v | --verbose
ffcdab
-Be more verbose.
ffcdab
-.
ffcdab
-.TP
ffcdab
-.BR -y | --yes
ffcdab
-Answer "yes" at any prompts.
ffcdab
-.
ffcdab
-.TP
ffcdab
-.BR --dry-run
ffcdab
-Print commands without running them.
ffcdab
-.
ffcdab
-.
ffcdab
-.SH DIAGNOSTICS
ffcdab
-.
ffcdab
-On successful completion, the status code is 0.
ffcdab
-A status code of 1 is used for failure.
ffcdab
-.
ffcdab
-.SH EXAMPLES
ffcdab
-.
ffcdab
-Convert VDO volume created by vdo manager into logical volume LV1 with within volume group VG1.
ffcdab
-.P
ffcdab
-#
ffcdab
-.B vdoimport --name VG1/LV1 /dev/mapper/vdo-volume
ffcdab
-.
ffcdab
-.SH ENVIRONMENT VARIABLES
ffcdab
-.
ffcdab
-.TP
ffcdab
-.B TMPDIR
ffcdab
-The temporary directory name for mount points. Defaults to "\fI/tmp\fP".
ffcdab
-.TP
ffcdab
-.B DM_DEV_DIR
ffcdab
-The device directory name.
ffcdab
-Defaults to "\fI/dev\fP" and must be an absolute path.
ffcdab
-.
ffcdab
-.SH SEE ALSO
ffcdab
-.
ffcdab
-.nh
ffcdab
-.ad l
ffcdab
-.BR lvm (8),
ffcdab
-.BR lvm.conf (5),
ffcdab
-.P
ffcdab
-.BR vdo (8),
ffcdab
-.BR vdo2lvm (8),
ffcdab
diff --git a/scripts/Makefile.in b/scripts/Makefile.in
ffcdab
index 1fe88ca..f16c37d 100644
ffcdab
--- a/scripts/Makefile.in
ffcdab
+++ b/scripts/Makefile.in
ffcdab
@@ -32,7 +32,7 @@ ifeq ("@FSADM@", "yes")
ffcdab
 endif
ffcdab
 
ffcdab
 ifeq ("@VDOIMPORT@", "yes")
ffcdab
-	LVM_SCRIPTS += vdoimport.sh
ffcdab
+	LVM_SCRIPTS += lvm_import_vdo.sh
ffcdab
 endif
ffcdab
 
ffcdab
 ifeq ("@BLKDEACTIVATE@", "yes")
ffcdab
diff --git a/scripts/lvm_import_vdo.sh b/scripts/lvm_import_vdo.sh
ffcdab
new file mode 100755
ffcdab
index 0000000..35140a0
ffcdab
--- /dev/null
ffcdab
+++ b/scripts/lvm_import_vdo.sh
ffcdab
@@ -0,0 +1,376 @@
ffcdab
+#!/bin/bash
ffcdab
+#
ffcdab
+# Copyright (C) 2021 Red Hat, Inc. All rights reserved.
ffcdab
+#
ffcdab
+# This file is part of LVM2.
ffcdab
+#
ffcdab
+# This copyrighted material is made available to anyone wishing to use,
ffcdab
+# modify, copy, or redistribute it subject to the terms and conditions
ffcdab
+# of the GNU General Public License v.2.
ffcdab
+#
ffcdab
+# You should have received a copy of the GNU General Public License
ffcdab
+# along with this program; if not, write to the Free Software Foundation,
ffcdab
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ffcdab
+#
ffcdab
+# Author: Zdenek Kabelac <zkabelac at redhat.com>
ffcdab
+#
ffcdab
+# Script for converting VDO volumes to lvm2 VDO LVs
ffcdab
+#
ffcdab
+# Needed utilities:
ffcdab
+#  lvm, dmsetup,
ffcdab
+#  vdo, vdo2lvm,
ffcdab
+#  grep, awk, sed, blockdev, readlink, mkdir
ffcdab
+#
ffcdab
+# Conversion is using  'vdo convert' support from VDO manager to move
ffcdab
+# existing VDO header by 2M which makes space to place in PV header
ffcdab
+# and VG metadata area, and then create VDOPOOL LV and VDO LV in such VG.
ffcdab
+#
ffcdab
+
ffcdab
+set -euE -o pipefail
ffcdab
+
ffcdab
+TOOL=lvm_import_vdo
ffcdab
+
ffcdab
+_SAVEPATH=$PATH
ffcdab
+PATH="/sbin:/usr/sbin:/bin:/usr/sbin:$PATH"
ffcdab
+
ffcdab
+# user may override lvm location by setting LVM_BINARY
ffcdab
+LVM=${LVM_BINARY:-lvm}
ffcdab
+VDO=${VDO_BINARY:-vdo}
ffcdab
+VDOCONF=${VDOCONF:-}
ffcdab
+BLOCKDEV="blockdev"
ffcdab
+READLINK="readlink"
ffcdab
+READLINK_E="-e"
ffcdab
+MKDIR="mkdir"
ffcdab
+
ffcdab
+TEMPDIR="${TMPDIR:-/tmp}/${TOOL}_${RANDOM}$$"
ffcdab
+DM_DEV_DIR="${DM_DEV_DIR:-/dev}"
ffcdab
+
ffcdab
+DRY=0
ffcdab
+VERB=""
ffcdab
+FORCE=""
ffcdab
+YES=""
ffcdab
+
ffcdab
+# default name for converted VG and its VDO LV
ffcdab
+NAME="vdovg/vdolvol"
ffcdab
+
ffcdab
+# help message
ffcdab
+tool_usage() {
ffcdab
+	echo "${TOOL}: Utility to convert VDO volume to VDO LV."
ffcdab
+	echo
ffcdab
+	echo "	${TOOL} [options] <vdo_device_path>"
ffcdab
+	echo
ffcdab
+	echo "	Options:"
ffcdab
+	echo "	  -f | --force	      Bypass sanity checks"
ffcdab
+	echo "	  -h | --help	      Show this help message"
ffcdab
+	echo "	  -n | --name	      Specifies VG/LV name for converted VDO volume"
ffcdab
+	echo "	  -v | --verbose      Be verbose"
ffcdab
+	echo "	  -y | --yes	      Answer \"yes\" at any prompts"
ffcdab
+	echo "	       --dry-run      Print commands without running them"
ffcdab
+
ffcdab
+	exit
ffcdab
+}
ffcdab
+
ffcdab
+verbose() {
ffcdab
+	test -z "$VERB" || echo "$TOOL:" "$@"
ffcdab
+}
ffcdab
+
ffcdab
+# Support multi-line error messages
ffcdab
+error() {
ffcdab
+	for i in "$@" ;  do
ffcdab
+		echo "$TOOL: $i" >&2
ffcdab
+	done
ffcdab
+	cleanup 1
ffcdab
+}
ffcdab
+
ffcdab
+dry() {
ffcdab
+	if [ "$DRY" -ne 0 ]; then
ffcdab
+		verbose "Dry execution" "$@"
ffcdab
+		return 0
ffcdab
+	fi
ffcdab
+	verbose "Executing" "$@"
ffcdab
+	"$@"
ffcdab
+}
ffcdab
+
ffcdab
+cleanup() {
ffcdab
+	trap '' 2
ffcdab
+
ffcdab
+	rm -rf "$TEMPDIR"
ffcdab
+	# error exit status for break
ffcdab
+	exit "${1:-1}"
ffcdab
+}
ffcdab
+
ffcdab
+get_enabled_value_() {
ffcdab
+	case "$1" in
ffcdab
+	enabled) echo "1" ;;
ffcdab
+	*) echo "0" ;;
ffcdab
+	esac
ffcdab
+}
ffcdab
+
ffcdab
+get_kb_size_with_unit_() {
ffcdab
+	case "$1" in
ffcdab
+	*[kK]) echo $(( ${1%[kK]} )) ;;
ffcdab
+	*[mM]) echo $(( ${1%[mM]} * 1024 )) ;;
ffcdab
+	*[gG]) echo $(( ${1%[gG]} * 1024 * 1024 )) ;;
ffcdab
+	*[tT]) echo $(( ${1%[tT]} * 1024 * 1024 * 1024 )) ;;
ffcdab
+	*[pP]) echo $(( ${1%[pP]} * 1024 * 1024 * 1024 * 1024 )) ;;
ffcdab
+	esac
ffcdab
+}
ffcdab
+
ffcdab
+get_mb_size_with_unit_() {
ffcdab
+	case "$1" in
ffcdab
+	*[mM]) echo $(( ${1%[mM]} )) ;;
ffcdab
+	*[gG]) echo $(( ${1%[gG]} * 1024 )) ;;
ffcdab
+	*[tT]) echo $(( ${1%[tT]} * 1024 * 1024 )) ;;
ffcdab
+	*[pP]) echo $(( ${1%[pP]} * 1024 * 1024 * 1024 )) ;;
ffcdab
+	esac
ffcdab
+}
ffcdab
+
ffcdab
+# Figure out largest possible extent size usable for VG
ffcdab
+# $1   physical size
ffcdab
+# $2   logical size
ffcdab
+get_largest_extent_size_() {
ffcdab
+	local max=4
ffcdab
+	local i
ffcdab
+	local d
ffcdab
+
ffcdab
+	for i in 8 16 32 64 128 256 512 1024 2048 4096 ; do
ffcdab
+		d=$(( $1 / i ))
ffcdab
+		test $(( d * i )) -eq "$1" || break
ffcdab
+		d=$(( $2 / i ))
ffcdab
+		test $(( d * i )) -eq "$2" || break
ffcdab
+		max=$i
ffcdab
+	done
ffcdab
+	echo "$max"
ffcdab
+}
ffcdab
+
ffcdab
+# detect LV on the given device
ffcdab
+# dereference device name if it is symbolic link
ffcdab
+detect_lv_() {
ffcdab
+	local DEVICE=$1
ffcdab
+	local MAJOR
ffcdab
+	local MINOR
ffcdab
+	local SYSVOLUME
ffcdab
+	local MAJORMINOR
ffcdab
+
ffcdab
+	DEVICE=${1/#"${DM_DEV_DIR}/"/}
ffcdab
+	DEVICE=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$DEVICE")
ffcdab
+	test -n "$DEVICE" || error "Cannot get readlink \"$1\"."
ffcdab
+	RDEVICE=$DEVICE
ffcdab
+	case "$RDEVICE" in
ffcdab
+	  # hardcoded /dev  since udev does not create these entries elsewhere
ffcdab
+	  /dev/dm-[0-9]*)
ffcdab
+		read -r <"/sys/block/${RDEVICE#/dev/}/dm/name" SYSVOLUME 2>&1 && DEVICE="$DM_DEV_DIR/mapper/$SYSVOLUME"
ffcdab
+		read -r <"/sys/block/${RDEVICE#/dev/}/dev" MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$DEVICE\"."
ffcdab
+		MAJOR=${MAJORMINOR%%:*}
ffcdab
+		MINOR=${MAJORMINOR##*:}
ffcdab
+		;;
ffcdab
+	  *)
ffcdab
+		STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$RDEVICE")
ffcdab
+		test -n "$STAT" || error "Cannot get major:minor for \"$DEVICE\"."
ffcdab
+		eval "$STAT"
ffcdab
+		;;
ffcdab
+	esac
ffcdab
+
ffcdab
+	eval "$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o uuid,name --noheadings --nameprefixes --separator ' ')"
ffcdab
+}
ffcdab
+
ffcdab
+# parse yaml config files into 'prefix_yaml_part_names=("value")' strings
ffcdab
+parse_yaml_() {
ffcdab
+	local yaml_file=$1
ffcdab
+	local prefix=$2
ffcdab
+	local s
ffcdab
+	local w
ffcdab
+	local fs
ffcdab
+
ffcdab
+	s='[[:space:]]*'
ffcdab
+	w='[a-zA-Z0-9_.-]*'
ffcdab
+	fs="$(echo @|tr @ '\034')"
ffcdab
+
ffcdab
+	(
ffcdab
+	    sed -ne '/^--/s|--||g; s|\"|\\\"|g; s/[[:space:]]*$//g;' \
ffcdab
+		-e 's/\$/\\\$/g' \
ffcdab
+		-e "/#.*[\"\']/!s| #.*||g; /^#/s|#.*||g;" \
ffcdab
+		-e "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
ffcdab
+		-e "s|^\($s\)\($w\)${s}[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" |
ffcdab
+
ffcdab
+	    awk -F"$fs" '{
ffcdab
+		indent = length($1)/2;
ffcdab
+		if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
ffcdab
+		vname[indent] = $2;
ffcdab
+		for (i in vname) {if (i > indent) {delete vname[i]}}
ffcdab
+		    if (length($3) > 0) {
ffcdab
+			vn=""; for (i=0; i
ffcdab
+			printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1], $3);
ffcdab
+		    }
ffcdab
+		}' |
ffcdab
+
ffcdab
+	    sed -e 's/_=/+=/g' |
ffcdab
+
ffcdab
+	    awk 'BEGIN {
ffcdab
+		    FS="=";
ffcdab
+		    OFS="="
ffcdab
+		}
ffcdab
+		/(-|\.).*=/ {
ffcdab
+		    gsub("-|\\.", "_", $1)
ffcdab
+		}
ffcdab
+		{ print }'
ffcdab
+	) < "$yaml_file"
ffcdab
+}
ffcdab
+
ffcdab
+# convert existing VDO volume into lvm2 volume
ffcdab
+convert2lvm_() {
ffcdab
+	local DEVICE=$1
ffcdab
+	local VGNAME=${NAME%/*}
ffcdab
+	local LVNAME=${NAME#*/}
ffcdab
+	local VDONAME
ffcdab
+	local TRVDONAME
ffcdab
+	local EXTENTSZ
ffcdab
+	local IS_LV=1
ffcdab
+
ffcdab
+	DM_UUID=""
ffcdab
+	detect_lv_ "$DEVICE"
ffcdab
+	case "$DM_UUID" in
ffcdab
+		LVM-*)	eval "$(dmsetup splitname --nameprefixes --noheadings --separator ' ' "$DM_NAME")"
ffcdab
+			if [ -z "$VGNAME" ] || [ "$VGNAME" = "$LVNAME" ]  ; then
ffcdab
+				VGNAME=$DM_VG_NAME
ffcdab
+			elif test "$VGNAME" != "$DM_VG_NAME" ; then
ffcdab
+				error "Volume group name \"$VGNAME\" does not match name \"$DM_VG_NAME\" for device \"$DEVICE\"."
ffcdab
+			fi
ffcdab
+			;;
ffcdab
+		*) IS_LV=0
ffcdab
+			# Check $VGNANE does not already exists
ffcdab
+			"$LVM" vgs "$VGNAME" && error "Cannot use already existing volume group name \"$VGNAME\"."
ffcdab
+			;;
ffcdab
+	esac
ffcdab
+
ffcdab
+	verbose "Checked whether device $1 is already LV ($IS_LV)."
ffcdab
+
ffcdab
+	"$MKDIR" -p -m 0000 "$TEMPDIR" || error "Failed to create $TEMPDIR."
ffcdab
+
ffcdab
+	verbose "Getting YAML VDO configuration."
ffcdab
+	"$VDO" printConfigFile $VDOCONF >"$TEMPDIR/vdoconf.yml"
ffcdab
+
ffcdab
+	VDONAME=$(awk -v DNAME="$DEVICE" '/.*VDOService$/ {VNAME=substr($1, 0, length($1) - 1)} /[[:space:]]*device:/ { if ($2 ~ DNAME) {print VNAME}}' "$TEMPDIR/vdoconf.yml")
ffcdab
+	TRVDONAME=$(echo "$VDONAME" | tr '-' '_')
ffcdab
+
ffcdab
+	# When VDO volume is 'active', check it's not mounted/being used
ffcdab
+	eval "$(dmsetup info -c -o open  "$VDONAME" --noheadings --nameprefixes || true)"
ffcdab
+	test "${DM_OPEN:-0}" -eq 0 || error "Cannot converted VDO volume \"$VDONAME\" which is in use!"
ffcdab
+
ffcdab
+	#parse_yaml_ "$TEMPDIR/vdoconf.yml" _
ffcdab
+	eval "$(parse_yaml_ "$TEMPDIR/vdoconf.yml" _ | grep "$TRVDONAME" | sed -e "s/_config_vdos_$TRVDONAME/vdo/g")"
ffcdab
+
ffcdab
+	vdo_logicalSize=$(get_kb_size_with_unit_ "$vdo_logicalSize")
ffcdab
+	vdo_physicalSize=$(get_kb_size_with_unit_ "$vdo_physicalSize")
ffcdab
+
ffcdab
+	verbose "Going to convert physical sized VDO device $vdo_physicalSize KiB."
ffcdab
+	verbose "With logical volume of size $vdo_logicalSize KiB."
ffcdab
+
ffcdab
+	PARAMS=$(cat <
ffcdab
+allocation {
ffcdab
+	vdo_use_compression = $(get_enabled_value_ "$vdo_compression")
ffcdab
+	vdo_use_deduplication = $(get_enabled_value_ "$vdo_deduplication")
ffcdab
+	vdo_use_metadata_hints=1
ffcdab
+	vdo_minimum_io_size = $vdo_logicalBlockSize
ffcdab
+	vdo_block_map_cache_size_mb = $(get_mb_size_with_unit_ "$vdo_blockMapCacheSize")
ffcdab
+	vdo_block_map_period = $vdo_blockMapPeriod
ffcdab
+	vdo_check_point_frequency = $vdo_indexCfreq
ffcdab
+	vdo_use_sparse_index = $(get_enabled_value_ "$vdo_indexSparse")
ffcdab
+	vdo_index_memory_size_mb = $(awk "BEGIN {print $vdo_indexMemory * 1024}")
ffcdab
+	vdo_slab_size_mb = $(get_mb_size_with_unit_ "$vdo_blockMapCacheSize")
ffcdab
+	vdo_ack_threads = $vdo_ackThreads
ffcdab
+	vdo_bio_threads = $vdo_bioThreads
ffcdab
+	vdo_bio_rotation = $vdo_bioRotationInterval
ffcdab
+	vdo_cpu_threads = $vdo_cpuThreads
ffcdab
+	vdo_hash_zone_threads = $vdo_hashZoneThreads
ffcdab
+	vdo_logical_threads = $vdo_logicalThreads
ffcdab
+	vdo_physical_threads = $vdo_physicalThreads
ffcdab
+	vdo_write_policy = $vdo_writePolicy
ffcdab
+	vdo_max_discard = $(( $(get_kb_size_with_unit_ "$vdo_maxDiscardSize") * 1024 ))
ffcdab
+	vdo_pool_header_size = 0
ffcdab
+}
ffcdab
+EOF
ffcdab
+)
ffcdab
+	verbose "VDO conversion paramaters: $PARAMS"
ffcdab
+
ffcdab
+	verbose "Stopping VDO volume."
ffcdab
+	dry "$VDO" stop $VDOCONF --name "$VDONAME"
ffcdab
+
ffcdab
+	if [ "$IS_LV" = "0" ]; then
ffcdab
+		verbose "Moving VDO header by 2MiB."
ffcdab
+		dry "$VDO" convert $VDOCONF --force --name "$VDONAME"
ffcdab
+
ffcdab
+		dry "$LVM" pvcreate $YES --dataalignment 2M "$DEVICE" || {
ffcdab
+			error "Creation of PV on \"$DEVICE\" failed, while VDO header has been already moved!"
ffcdab
+		}
ffcdab
+
ffcdab
+		# Obtain free space in this new PV
ffcdab
+		# after 'vdo convert/vdo2lvm' call there is +2M free space at the front of the device
ffcdab
+		case "$DRY" in
ffcdab
+		0) pvfree=$("$LVM" pvs -o devsize --units b --nosuffix --noheadings "$DEVICE") ;;
ffcdab
+		*) pvfree=$("$BLOCKDEV" --getsize64 "$DEVICE") ;;
ffcdab
+		esac
ffcdab
+
ffcdab
+		pvfree=$(( pvfree / 1024 - 2048 ))	# to KiB
ffcdab
+	else
ffcdab
+		pvfree=$("$LVM" lvs -o size --units b --nosuffix --noheadings "$VGNAME/$LVNAME")
ffcdab
+		pvfree=$(( pvfree / 1024 ))		# to KiB
ffcdab
+	fi
ffcdab
+
ffcdab
+	# select largest possible extent size that can exactly express both sizes
ffcdab
+	EXTENTSZ=$(get_largest_extent_size_ "$pvfree" "$vdo_logicalSize")
ffcdab
+
ffcdab
+	if [ "$IS_LV" = "0" ]; then
ffcdab
+		verbose "Creating VG \"${NAME%/*}\" with extent size $EXTENTSZ KiB."
ffcdab
+		dry "$LVM" vgcreate $YES $VERB -s "${EXTENTSZ}k" "$VGNAME" "$DEVICE" || {
ffcdab
+			error "Creation of VG \"$VGNAME\" failed, while VDO header has been already moved!"
ffcdab
+		}
ffcdab
+
ffcdab
+		verbose "Creating VDO pool data LV from all extents in volume group $VGNAME."
ffcdab
+		dry "$LVM" lvcreate -Zn -Wn $YES $VERB -l100%VG -n "${LVNAME}_vpool" "$VGNAME"
ffcdab
+	else
ffcdab
+		# validate existing  VG extent_size can express virtual VDO size
ffcdab
+		vg_extent_size=$("$LVM" vgs -o vg_extent_size --units b --nosuffix --noheadings "$VGNAME" || true)
ffcdab
+		vg_extent_size=$(( vg_extent_size / 1024 ))
ffcdab
+
ffcdab
+		test "$vg_extent_size" -le "$EXTENTSZ" || {
ffcdab
+			error "Please vgchange extent_size to at most $EXTENTSZ KiB or extend and align virtual size on $vg_extent_size KiB."
ffcdab
+		}
ffcdab
+		verbose "Renaming existing LV to be used as _vdata volume for VDO pool LV."
ffcdab
+		dry "$LVM" lvrename $YES $VERB "$VGNAME/$LVNAME" "$VGNAME/${LVNAME}_vpool" || {
ffcdab
+			error "Rename of LV \"$VGNAME/$LVNAME\" failed, while VDO header has been already moved!"
ffcdab
+		}
ffcdab
+	fi
ffcdab
+
ffcdab
+	verbose "Converting to VDO pool."
ffcdab
+	dry "$LVM" lvconvert $YES $VERB $FORCE --config "$PARAMS" -Zn -V "${vdo_logicalSize}k" -n "$LVNAME" --type vdo-pool "$VGNAME/${LVNAME}_vpool"
ffcdab
+
ffcdab
+	rm -fr "$TEMPDIR"
ffcdab
+}
ffcdab
+
ffcdab
+#############################
ffcdab
+# start point of this script
ffcdab
+# - parsing parameters
ffcdab
+#############################
ffcdab
+trap "cleanup 2" 2
ffcdab
+
ffcdab
+test "$#" -eq 0 && tool_usage
ffcdab
+
ffcdab
+while [ "$#" -ne 0 ]
ffcdab
+do
ffcdab
+	 case "$1" in
ffcdab
+	  "") ;;
ffcdab
+	  "-f"|"--force"  ) FORCE="-f" ;;
ffcdab
+	  "-h"|"--help"   ) tool_usage ;;
ffcdab
+	  "-n"|"--name"   ) shift; NAME=$1 ;;
ffcdab
+	  "-v"|"--verbose") VERB="-v" ;;
ffcdab
+	  "-y"|"--yes"    ) YES="-y" ;;
ffcdab
+	  "--dry-run"     ) DRY="1" ;;
ffcdab
+	  "-*") error "Wrong argument \"$1\". (see: $TOOL --help)" ;;
ffcdab
+	  *) DEVICENAME=$1 ;;  # device name does not start with '-'
ffcdab
+	esac
ffcdab
+	shift
ffcdab
+done
ffcdab
+
ffcdab
+# do conversion
ffcdab
+convert2lvm_ "$DEVICENAME"
ffcdab
diff --git a/scripts/vdoimport.sh b/scripts/vdoimport.sh
ffcdab
deleted file mode 100755
ffcdab
index ef96591..0000000
ffcdab
--- a/scripts/vdoimport.sh
ffcdab
+++ /dev/null
ffcdab
@@ -1,376 +0,0 @@
ffcdab
-#!/bin/bash
ffcdab
-#
ffcdab
-# Copyright (C) 2021 Red Hat, Inc. All rights reserved.
ffcdab
-#
ffcdab
-# This file is part of LVM2.
ffcdab
-#
ffcdab
-# This copyrighted material is made available to anyone wishing to use,
ffcdab
-# modify, copy, or redistribute it subject to the terms and conditions
ffcdab
-# of the GNU General Public License v.2.
ffcdab
-#
ffcdab
-# You should have received a copy of the GNU General Public License
ffcdab
-# along with this program; if not, write to the Free Software Foundation,
ffcdab
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ffcdab
-#
ffcdab
-# Author: Zdenek Kabelac <zkabelac at redhat.com>
ffcdab
-#
ffcdab
-# Script for converting VDO volumes to lvm2 VDO LVs
ffcdab
-#
ffcdab
-# Needed utilities:
ffcdab
-#  lvm, dmsetup,
ffcdab
-#  vdo, vdo2lvm,
ffcdab
-#  grep, awk, sed, blockdev, readlink, mkdir
ffcdab
-#
ffcdab
-# Conversion is using  'vdo convert' support from VDO manager to move
ffcdab
-# existing VDO header by 2M which makes space to place in PV header
ffcdab
-# and VG metadata area, and then create VDOPOOL LV and VDO LV in such VG.
ffcdab
-#
ffcdab
-
ffcdab
-set -euE -o pipefail
ffcdab
-
ffcdab
-TOOL=vdoimport
ffcdab
-
ffcdab
-_SAVEPATH=$PATH
ffcdab
-PATH="/sbin:/usr/sbin:/bin:/usr/sbin:$PATH"
ffcdab
-
ffcdab
-# user may override lvm location by setting LVM_BINARY
ffcdab
-LVM=${LVM_BINARY:-lvm}
ffcdab
-VDO=${VDO_BINARY:-vdo}
ffcdab
-VDOCONF=${VDOCONF:-}
ffcdab
-BLOCKDEV="blockdev"
ffcdab
-READLINK="readlink"
ffcdab
-READLINK_E="-e"
ffcdab
-MKDIR="mkdir"
ffcdab
-
ffcdab
-TEMPDIR="${TMPDIR:-/tmp}/${TOOL}_${RANDOM}$$"
ffcdab
-DM_DEV_DIR="${DM_DEV_DIR:-/dev}"
ffcdab
-
ffcdab
-DRY=0
ffcdab
-VERB=""
ffcdab
-FORCE=""
ffcdab
-YES=""
ffcdab
-
ffcdab
-# default name for converted VG and its VDO LV
ffcdab
-NAME="vdovg/vdolvol"
ffcdab
-
ffcdab
-# help message
ffcdab
-tool_usage() {
ffcdab
-	echo "${TOOL}: Utility to convert VDO volume to VDO LV."
ffcdab
-	echo
ffcdab
-	echo "	${TOOL} [options] <vdo_device_path>"
ffcdab
-	echo
ffcdab
-	echo "	Options:"
ffcdab
-	echo "	  -f | --force	      Bypass sanity checks"
ffcdab
-	echo "	  -h | --help	      Show this help message"
ffcdab
-	echo "	  -n | --name	      Specifies VG/LV name for converted VDO volume"
ffcdab
-	echo "	  -v | --verbose      Be verbose"
ffcdab
-	echo "	  -y | --yes	      Answer \"yes\" at any prompts"
ffcdab
-	echo "	       --dry-run      Print commands without running them"
ffcdab
-
ffcdab
-	exit
ffcdab
-}
ffcdab
-
ffcdab
-verbose() {
ffcdab
-	test -z "$VERB" || echo "$TOOL:" "$@"
ffcdab
-}
ffcdab
-
ffcdab
-# Support multi-line error messages
ffcdab
-error() {
ffcdab
-	for i in "$@" ;  do
ffcdab
-		echo "$TOOL: $i" >&2
ffcdab
-	done
ffcdab
-	cleanup 1
ffcdab
-}
ffcdab
-
ffcdab
-dry() {
ffcdab
-	if [ "$DRY" -ne 0 ]; then
ffcdab
-		verbose "Dry execution" "$@"
ffcdab
-		return 0
ffcdab
-	fi
ffcdab
-	verbose "Executing" "$@"
ffcdab
-	"$@"
ffcdab
-}
ffcdab
-
ffcdab
-cleanup() {
ffcdab
-	trap '' 2
ffcdab
-
ffcdab
-	rm -rf "$TEMPDIR"
ffcdab
-	# error exit status for break
ffcdab
-	exit "${1:-1}"
ffcdab
-}
ffcdab
-
ffcdab
-get_enabled_value_() {
ffcdab
-	case "$1" in
ffcdab
-	enabled) echo "1" ;;
ffcdab
-	*) echo "0" ;;
ffcdab
-	esac
ffcdab
-}
ffcdab
-
ffcdab
-get_kb_size_with_unit_() {
ffcdab
-	case "$1" in
ffcdab
-	*[kK]) echo $(( ${1%[kK]} )) ;;
ffcdab
-	*[mM]) echo $(( ${1%[mM]} * 1024 )) ;;
ffcdab
-	*[gG]) echo $(( ${1%[gG]} * 1024 * 1024 )) ;;
ffcdab
-	*[tT]) echo $(( ${1%[tT]} * 1024 * 1024 * 1024 )) ;;
ffcdab
-	*[pP]) echo $(( ${1%[pP]} * 1024 * 1024 * 1024 * 1024 )) ;;
ffcdab
-	esac
ffcdab
-}
ffcdab
-
ffcdab
-get_mb_size_with_unit_() {
ffcdab
-	case "$1" in
ffcdab
-	*[mM]) echo $(( ${1%[mM]} )) ;;
ffcdab
-	*[gG]) echo $(( ${1%[gG]} * 1024 )) ;;
ffcdab
-	*[tT]) echo $(( ${1%[tT]} * 1024 * 1024 )) ;;
ffcdab
-	*[pP]) echo $(( ${1%[pP]} * 1024 * 1024 * 1024 )) ;;
ffcdab
-	esac
ffcdab
-}
ffcdab
-
ffcdab
-# Figure out largest possible extent size usable for VG
ffcdab
-# $1   physical size
ffcdab
-# $2   logical size
ffcdab
-get_largest_extent_size_() {
ffcdab
-	local max=4
ffcdab
-	local i
ffcdab
-	local d
ffcdab
-
ffcdab
-	for i in 8 16 32 64 128 256 512 1024 2048 4096 ; do
ffcdab
-		d=$(( $1 / i ))
ffcdab
-		test $(( d * i )) -eq "$1" || break
ffcdab
-		d=$(( $2 / i ))
ffcdab
-		test $(( d * i )) -eq "$2" || break
ffcdab
-		max=$i
ffcdab
-	done
ffcdab
-	echo "$max"
ffcdab
-}
ffcdab
-
ffcdab
-# detect LV on the given device
ffcdab
-# dereference device name if it is symbolic link
ffcdab
-detect_lv_() {
ffcdab
-	local DEVICE=$1
ffcdab
-	local MAJOR
ffcdab
-	local MINOR
ffcdab
-	local SYSVOLUME
ffcdab
-	local MAJORMINOR
ffcdab
-
ffcdab
-	DEVICE=${1/#"${DM_DEV_DIR}/"/}
ffcdab
-	DEVICE=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$DEVICE")
ffcdab
-	test -n "$DEVICE" || error "Cannot get readlink \"$1\"."
ffcdab
-	RDEVICE=$DEVICE
ffcdab
-	case "$RDEVICE" in
ffcdab
-	  # hardcoded /dev  since udev does not create these entries elsewhere
ffcdab
-	  /dev/dm-[0-9]*)
ffcdab
-		read -r <"/sys/block/${RDEVICE#/dev/}/dm/name" SYSVOLUME 2>&1 && DEVICE="$DM_DEV_DIR/mapper/$SYSVOLUME"
ffcdab
-		read -r <"/sys/block/${RDEVICE#/dev/}/dev" MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$DEVICE\"."
ffcdab
-		MAJOR=${MAJORMINOR%%:*}
ffcdab
-		MINOR=${MAJORMINOR##*:}
ffcdab
-		;;
ffcdab
-	  *)
ffcdab
-		STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$RDEVICE")
ffcdab
-		test -n "$STAT" || error "Cannot get major:minor for \"$DEVICE\"."
ffcdab
-		eval "$STAT"
ffcdab
-		;;
ffcdab
-	esac
ffcdab
-
ffcdab
-	eval "$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o uuid,name --noheadings --nameprefixes --separator ' ')"
ffcdab
-}
ffcdab
-
ffcdab
-# parse yaml config files into 'prefix_yaml_part_names=("value")' strings
ffcdab
-parse_yaml_() {
ffcdab
-	local yaml_file=$1
ffcdab
-	local prefix=$2
ffcdab
-	local s
ffcdab
-	local w
ffcdab
-	local fs
ffcdab
-
ffcdab
-	s='[[:space:]]*'
ffcdab
-	w='[a-zA-Z0-9_.-]*'
ffcdab
-	fs="$(echo @|tr @ '\034')"
ffcdab
-
ffcdab
-	(
ffcdab
-	    sed -ne '/^--/s|--||g; s|\"|\\\"|g; s/[[:space:]]*$//g;' \
ffcdab
-		-e 's/\$/\\\$/g' \
ffcdab
-		-e "/#.*[\"\']/!s| #.*||g; /^#/s|#.*||g;" \
ffcdab
-		-e "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
ffcdab
-		-e "s|^\($s\)\($w\)${s}[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" |
ffcdab
-
ffcdab
-	    awk -F"$fs" '{
ffcdab
-		indent = length($1)/2;
ffcdab
-		if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
ffcdab
-		vname[indent] = $2;
ffcdab
-		for (i in vname) {if (i > indent) {delete vname[i]}}
ffcdab
-		    if (length($3) > 0) {
ffcdab
-			vn=""; for (i=0; i
ffcdab
-			printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1], $3);
ffcdab
-		    }
ffcdab
-		}' |
ffcdab
-
ffcdab
-	    sed -e 's/_=/+=/g' |
ffcdab
-
ffcdab
-	    awk 'BEGIN {
ffcdab
-		    FS="=";
ffcdab
-		    OFS="="
ffcdab
-		}
ffcdab
-		/(-|\.).*=/ {
ffcdab
-		    gsub("-|\\.", "_", $1)
ffcdab
-		}
ffcdab
-		{ print }'
ffcdab
-	) < "$yaml_file"
ffcdab
-}
ffcdab
-
ffcdab
-# convert existing VDO volume into lvm2 volume
ffcdab
-convert2lvm_() {
ffcdab
-	local DEVICE=$1
ffcdab
-	local VGNAME=${NAME%/*}
ffcdab
-	local LVNAME=${NAME#*/}
ffcdab
-	local VDONAME
ffcdab
-	local TRVDONAME
ffcdab
-	local EXTENTSZ
ffcdab
-	local IS_LV=1
ffcdab
-
ffcdab
-	DM_UUID=""
ffcdab
-	detect_lv_ "$DEVICE"
ffcdab
-	case "$DM_UUID" in
ffcdab
-		LVM-*)	eval "$(dmsetup splitname --nameprefixes --noheadings --separator ' ' "$DM_NAME")"
ffcdab
-			if [ -z "$VGNAME" ] || [ "$VGNAME" = "$LVNAME" ]  ; then
ffcdab
-				VGNAME=$DM_VG_NAME
ffcdab
-			elif test "$VGNAME" != "$DM_VG_NAME" ; then
ffcdab
-				error "Volume group name \"$VGNAME\" does not match name \"$DM_VG_NAME\" for device \"$DEVICE\"."
ffcdab
-			fi
ffcdab
-			;;
ffcdab
-		*) IS_LV=0
ffcdab
-			# Check $VGNANE does not already exists
ffcdab
-			"$LVM" vgs "$VGNAME" && error "Cannot use already existing volume group name \"$VGNAME\"."
ffcdab
-			;;
ffcdab
-	esac
ffcdab
-
ffcdab
-	verbose "Checked whether device $1 is already LV ($IS_LV)."
ffcdab
-
ffcdab
-	"$MKDIR" -p -m 0000 "$TEMPDIR" || error "Failed to create $TEMPDIR."
ffcdab
-
ffcdab
-	verbose "Getting YAML VDO configuration."
ffcdab
-	"$VDO" printConfigFile $VDOCONF >"$TEMPDIR/vdoconf.yml"
ffcdab
-
ffcdab
-	VDONAME=$(awk -v DNAME="$DEVICE" '/.*VDOService$/ {VNAME=substr($1, 0, length($1) - 1)} /[[:space:]]*device:/ { if ($2 ~ DNAME) {print VNAME}}' "$TEMPDIR/vdoconf.yml")
ffcdab
-	TRVDONAME=$(echo "$VDONAME" | tr '-' '_')
ffcdab
-
ffcdab
-	# When VDO volume is 'active', check it's not mounted/being used
ffcdab
-	eval "$(dmsetup info -c -o open  "$VDONAME" --noheadings --nameprefixes || true)"
ffcdab
-	test "${DM_OPEN:-0}" -eq 0 || error "Cannot converted VDO volume \"$VDONAME\" which is in use!"
ffcdab
-
ffcdab
-	#parse_yaml_ "$TEMPDIR/vdoconf.yml" _
ffcdab
-	eval "$(parse_yaml_ "$TEMPDIR/vdoconf.yml" _ | grep "$TRVDONAME" | sed -e "s/_config_vdos_$TRVDONAME/vdo/g")"
ffcdab
-
ffcdab
-	vdo_logicalSize=$(get_kb_size_with_unit_ "$vdo_logicalSize")
ffcdab
-	vdo_physicalSize=$(get_kb_size_with_unit_ "$vdo_physicalSize")
ffcdab
-
ffcdab
-	verbose "Going to convert physical sized VDO device $vdo_physicalSize KiB."
ffcdab
-	verbose "With logical volume of size $vdo_logicalSize KiB."
ffcdab
-
ffcdab
-	PARAMS=$(cat <
ffcdab
-allocation {
ffcdab
-	vdo_use_compression = $(get_enabled_value_ "$vdo_compression")
ffcdab
-	vdo_use_deduplication = $(get_enabled_value_ "$vdo_deduplication")
ffcdab
-	vdo_use_metadata_hints=1
ffcdab
-	vdo_minimum_io_size = $vdo_logicalBlockSize
ffcdab
-	vdo_block_map_cache_size_mb = $(get_mb_size_with_unit_ "$vdo_blockMapCacheSize")
ffcdab
-	vdo_block_map_period = $vdo_blockMapPeriod
ffcdab
-	vdo_check_point_frequency = $vdo_indexCfreq
ffcdab
-	vdo_use_sparse_index = $(get_enabled_value_ "$vdo_indexSparse")
ffcdab
-	vdo_index_memory_size_mb = $(awk "BEGIN {print $vdo_indexMemory * 1024}")
ffcdab
-	vdo_slab_size_mb = $(get_mb_size_with_unit_ "$vdo_blockMapCacheSize")
ffcdab
-	vdo_ack_threads = $vdo_ackThreads
ffcdab
-	vdo_bio_threads = $vdo_bioThreads
ffcdab
-	vdo_bio_rotation = $vdo_bioRotationInterval
ffcdab
-	vdo_cpu_threads = $vdo_cpuThreads
ffcdab
-	vdo_hash_zone_threads = $vdo_hashZoneThreads
ffcdab
-	vdo_logical_threads = $vdo_logicalThreads
ffcdab
-	vdo_physical_threads = $vdo_physicalThreads
ffcdab
-	vdo_write_policy = $vdo_writePolicy
ffcdab
-	vdo_max_discard = $(( $(get_kb_size_with_unit_ "$vdo_maxDiscardSize") * 1024 ))
ffcdab
-	vdo_pool_header_size = 0
ffcdab
-}
ffcdab
-EOF
ffcdab
-)
ffcdab
-	verbose "VDO conversion paramaters: $PARAMS"
ffcdab
-
ffcdab
-	verbose "Stopping VDO volume."
ffcdab
-	dry "$VDO" stop $VDOCONF --name "$VDONAME"
ffcdab
-
ffcdab
-	if [ "$IS_LV" = "0" ]; then
ffcdab
-		verbose "Moving VDO header by 2MiB."
ffcdab
-		dry "$VDO" convert $VDOCONF --force --name "$VDONAME"
ffcdab
-
ffcdab
-		dry "$LVM" pvcreate $YES --dataalignment 2M "$DEVICE" || {
ffcdab
-			error "Creation of PV on \"$DEVICE\" failed, while VDO header has been already moved!"
ffcdab
-		}
ffcdab
-
ffcdab
-		# Obtain free space in this new PV
ffcdab
-		# after 'vdo convert/vdo2lvm' call there is +2M free space at the front of the device
ffcdab
-		case "$DRY" in
ffcdab
-		0) pvfree=$("$LVM" pvs -o devsize --units b --nosuffix --noheadings "$DEVICE") ;;
ffcdab
-		*) pvfree=$("$BLOCKDEV" --getsize64 "$DEVICE") ;;
ffcdab
-		esac
ffcdab
-
ffcdab
-		pvfree=$(( pvfree / 1024 - 2048 ))	# to KiB
ffcdab
-	else
ffcdab
-		pvfree=$("$LVM" lvs -o size --units b --nosuffix --noheadings "$VGNAME/$LVNAME")
ffcdab
-		pvfree=$(( pvfree / 1024 ))		# to KiB
ffcdab
-	fi
ffcdab
-
ffcdab
-	# select largest possible extent size that can exactly express both sizes
ffcdab
-	EXTENTSZ=$(get_largest_extent_size_ "$pvfree" "$vdo_logicalSize")
ffcdab
-
ffcdab
-	if [ "$IS_LV" = "0" ]; then
ffcdab
-		verbose "Creating VG \"${NAME%/*}\" with extent size $EXTENTSZ KiB."
ffcdab
-		dry "$LVM" vgcreate $YES $VERB -s "${EXTENTSZ}k" "$VGNAME" "$DEVICE" || {
ffcdab
-			error "Creation of VG \"$VGNAME\" failed, while VDO header has been already moved!"
ffcdab
-		}
ffcdab
-
ffcdab
-		verbose "Creating VDO pool data LV from all extents in volume group $VGNAME."
ffcdab
-		dry "$LVM" lvcreate -Zn -Wn $YES $VERB -l100%VG -n "${LVNAME}_vpool" "$VGNAME"
ffcdab
-	else
ffcdab
-		# validate existing  VG extent_size can express virtual VDO size
ffcdab
-		vg_extent_size=$("$LVM" vgs -o vg_extent_size --units b --nosuffix --noheadings "$VGNAME" || true)
ffcdab
-		vg_extent_size=$(( vg_extent_size / 1024 ))
ffcdab
-
ffcdab
-		test "$vg_extent_size" -le "$EXTENTSZ" || {
ffcdab
-			error "Please vgchange extent_size to at most $EXTENTSZ KiB or extend and align virtual size on $vg_extent_size KiB."
ffcdab
-		}
ffcdab
-		verbose "Renaming existing LV to be used as _vdata volume for VDO pool LV."
ffcdab
-		dry "$LVM" lvrename $YES $VERB "$VGNAME/$LVNAME" "$VGNAME/${LVNAME}_vpool" || {
ffcdab
-			error "Rename of LV \"$VGNAME/$LVNAME\" failed, while VDO header has been already moved!"
ffcdab
-		}
ffcdab
-	fi
ffcdab
-
ffcdab
-	verbose "Converting to VDO pool."
ffcdab
-	dry "$LVM" lvconvert $YES $VERB $FORCE --config "$PARAMS" -Zn -V "${vdo_logicalSize}k" -n "$LVNAME" --type vdo-pool "$VGNAME/${LVNAME}_vpool"
ffcdab
-
ffcdab
-	rm -fr "$TEMPDIR"
ffcdab
-}
ffcdab
-
ffcdab
-#############################
ffcdab
-# start point of this script
ffcdab
-# - parsing parameters
ffcdab
-#############################
ffcdab
-trap "cleanup 2" 2
ffcdab
-
ffcdab
-test "$#" -eq 0 && tool_usage
ffcdab
-
ffcdab
-while [ "$#" -ne 0 ]
ffcdab
-do
ffcdab
-	 case "$1" in
ffcdab
-	  "") ;;
ffcdab
-	  "-f"|"--force"  ) FORCE="-f" ;;
ffcdab
-	  "-h"|"--help"   ) tool_usage ;;
ffcdab
-	  "-n"|"--name"   ) shift; NAME=$1 ;;
ffcdab
-	  "-v"|"--verbose") VERB="-v" ;;
ffcdab
-	  "-y"|"--yes"    ) YES="-y" ;;
ffcdab
-	  "--dry-run"     ) DRY="1" ;;
ffcdab
-	  "-*") error "Wrong argument \"$1\". (see: $TOOL --help)" ;;
ffcdab
-	  *) DEVICENAME=$1 ;;  # device name does not start with '-'
ffcdab
-	esac
ffcdab
-	shift
ffcdab
-done
ffcdab
-
ffcdab
-# do conversion
ffcdab
-convert2lvm_ "$DEVICENAME"
ffcdab
diff --git a/test/Makefile.in b/test/Makefile.in
ffcdab
index 6be03aa..0f2cc25 100644
ffcdab
--- a/test/Makefile.in
ffcdab
+++ b/test/Makefile.in
ffcdab
@@ -353,7 +353,7 @@ LIB = $(addprefix lib/, $(LIB_SECURETEST) $(LIB_DMSECURETEST) $(LIB_SHARED) $(LI
ffcdab
 	$(Q) $(LN_S) -f $(abs_top_srcdir)/conf/lvmdbusd.profile lib/
ffcdab
 	$(Q) $(LN_S) -f $(abs_top_srcdir)/conf/thin-performance.profile lib/
ffcdab
 	$(Q) $(LN_S) -f $(abs_top_srcdir)/scripts/fsadm.sh lib/fsadm
ffcdab
-	$(Q) $(LN_S) -f $(abs_top_srcdir)/scripts/vdoimport.sh lib/vdoimport
ffcdab
+	$(Q) $(LN_S) -f $(abs_top_srcdir)/scripts/lvm_import_vdo.sh lib/lvm_import_vdo
ffcdab
 	@test "$(srcdir)" = . || \
ffcdab
 		for i in $(LIB_LVMLOCKD_CONF) $(LIB_MKE2FS_CONF); do \
ffcdab
 			test -n "$(Q)" || echo "$(LN_S) -f $(abs_top_srcdir)/test/lib/$$i lib/"; \
ffcdab
diff --git a/test/shell/vdo-convert.sh b/test/shell/vdo-convert.sh
ffcdab
index 538147b..2d16c97 100644
ffcdab
--- a/test/shell/vdo-convert.sh
ffcdab
+++ b/test/shell/vdo-convert.sh
ffcdab
@@ -54,12 +54,12 @@ vdo create $VDOCONF --name "$VDONAME" --device="$DM_DEV_DIR/$vg/$lv1" --vdoLogic
ffcdab
 mkfs -E nodiscard "$DM_DEV_DIR/mapper/$VDONAME"
ffcdab
 
ffcdab
 # Different VG name fails
ffcdab
-not vdoimport -y -v --name $vg1/$lv1 "$DM_DEV_DIR/$vg/$lv1"
ffcdab
+not lvm_import_vdo -y -v --name $vg1/$lv1 "$DM_DEV_DIR/$vg/$lv1"
ffcdab
 
ffcdab
 # Try just dry run and observe logging
ffcdab
-vdoimport --dry-run -y -v --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
ffcdab
+lvm_import_vdo --dry-run -y -v --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
ffcdab
 
ffcdab
-vdoimport -y --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
ffcdab
+lvm_import_vdo -y --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
ffcdab
 
ffcdab
 # ATM needed - since we do not call 'vdo convert' in this case
ffcdab
 vdo remove $VDOCONF --force --name "$VDONAME" || true
ffcdab
@@ -79,13 +79,13 @@ vdo create $VDOCONF --name "$VDONAME" --device="$dev1" --vdoLogicalSize=31G
ffcdab
 mkfs -E nodiscard "$DM_DEV_DIR/mapper/$VDONAME"
ffcdab
 
ffcdab
 # Fail with an already existing volume group $vg2
ffcdab
-not vdoimport --dry-run -y -v --name $vg2/$lv1 "$dev1" |& tee err
ffcdab
+not lvm_import_vdo --dry-run -y -v --name $vg2/$lv1 "$dev1" |& tee err
ffcdab
 grep "already existing volume group" err
ffcdab
 
ffcdab
 # User can also convert already stopped VDO volume
ffcdab
 vdo stop $VDOCONF --name "$VDONAME"
ffcdab
 
ffcdab
-vdoimport -y -v --name $vg/$lv1 "$dev1"
ffcdab
+lvm_import_vdo -y -v --name $vg/$lv1 "$dev1"
ffcdab
 
ffcdab
 fsck -n "$DM_DEV_DIR/$vg/$lv1"
ffcdab
 
ffcdab
@@ -102,7 +102,7 @@ vdo create $VDOCONF --name "$VDONAME" --device="$dev1" --vdoLogicalSize=23G
ffcdab
 
ffcdab
 mkfs -E nodiscard "$DM_DEV_DIR/mapper/$VDONAME"
ffcdab
 
ffcdab
-vdoimport -y -v --name $vg1/$lv2 "$dev1"
ffcdab
+lvm_import_vdo -y -v --name $vg1/$lv2 "$dev1"
ffcdab
 
ffcdab
 fsck -n "$DM_DEV_DIR/$vg1/$lv2"
ffcdab