mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_03_13-vdo-add-vdoimport-support.patch

4aaf76
 WHATS_NEW                 |   3 +
4aaf76
 configure                 |  25 +++
4aaf76
 configure.ac              |  15 ++
4aaf76
 include/configure.h.in    |   3 +
4aaf76
 man/Makefile.in           |   7 +-
4aaf76
 scripts/Makefile.in       |   4 +
4aaf76
 scripts/vdoimport.sh      | 376 ++++++++++++++++++++++++++++++++++++++++++++++
4aaf76
 test/Makefile.in          |   1 +
4aaf76
 test/shell/vdo-convert.sh | 110 ++++++++++++++
4aaf76
 9 files changed, 543 insertions(+), 1 deletion(-)
4aaf76
 create mode 100755 scripts/vdoimport.sh
4aaf76
 create mode 100644 test/shell/vdo-convert.sh
4aaf76
4aaf76
diff --git a/WHATS_NEW b/WHATS_NEW
4aaf76
index 04c6dcd..5806ecb 100644
4aaf76
--- a/WHATS_NEW
4aaf76
+++ b/WHATS_NEW
4aaf76
@@ -1,5 +1,8 @@
4aaf76
 Version 2.03.13 - 
4aaf76
 ===============================
4aaf76
+  Add vdoimport tool to support conversion of VDO volumes.
4aaf76
+  Support configurable allocation/vdo_pool_header_size.
4aaf76
+  Fix handling of lvconvert --type vdo-pool --virtualsize.
4aaf76
   Fix load of kvdo target when it is not present in memory (2.03.12).
4aaf76
 
4aaf76
 Version 2.03.12 - 07th May 2021
4aaf76
diff --git a/configure b/configure
4aaf76
index 7c6bd48..661702d 100755
4aaf76
--- a/configure
4aaf76
+++ b/configure
4aaf76
@@ -643,6 +643,8 @@ WRITE_INSTALL
4aaf76
 WRITECACHE
4aaf76
 VDO_LIB
4aaf76
 VDO_INCLUDE
4aaf76
+VDOIMPORT_PATH
4aaf76
+VDOIMPORT
4aaf76
 VDO
4aaf76
 VALGRIND_POOL
4aaf76
 USRSBINDIR
4aaf76
@@ -966,6 +968,7 @@ enable_dbus_service
4aaf76
 enable_pkgconfig
4aaf76
 enable_write_install
4aaf76
 enable_fsadm
4aaf76
+enable_vdoimport
4aaf76
 enable_blkdeactivate
4aaf76
 enable_dmeventd
4aaf76
 enable_selinux
4aaf76
@@ -1701,6 +1704,7 @@ Optional Features:
4aaf76
   --enable-pkgconfig      install pkgconfig support
4aaf76
   --enable-write_install  install user writable files
4aaf76
   --disable-fsadm         disable fsadm
4aaf76
+  --disable-vdoimport     disable vdoimport
4aaf76
   --disable-blkdeactivate disable blkdeactivate
4aaf76
   --enable-dmeventd       enable the device-mapper event daemon
4aaf76
   --disable-selinux       disable selinux support
4aaf76
@@ -3128,6 +3132,7 @@ case "$host_os" in
4aaf76
 		DM_IOCTLS=yes
4aaf76
 		SELINUX=yes
4aaf76
 		FSADM=yes
4aaf76
+		VDOIMPORT=yes
4aaf76
 		BLKDEACTIVATE=yes
4aaf76
 		;;
4aaf76
 	darwin*)
4aaf76
@@ -3141,6 +3146,7 @@ case "$host_os" in
4aaf76
 		DM_IOCTLS=no
4aaf76
 		SELINUX=no
4aaf76
 		FSADM=no
4aaf76
+		VDOIMPORT=no
4aaf76
 		BLKDEACTIVATE=no
4aaf76
 		;;
4aaf76
 	*)
4aaf76
@@ -12371,6 +12377,18 @@ fi
4aaf76
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FSADM" >&5
4aaf76
 $as_echo "$FSADM" >&6; }
4aaf76
 
4aaf76
+
4aaf76
+################################################################################
4aaf76
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to install vdoimport" >&5
4aaf76
+$as_echo_n "checking whether to install vdoimport... " >&6; }
4aaf76
+# Check whether --enable-vdoimport was given.
4aaf76
+if test "${enable_vdoimport+set}" = set; then :
4aaf76
+  enableval=$enable_vdoimport; VDOIMPORT=$enableval
4aaf76
+fi
4aaf76
+
4aaf76
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $VDOIMPORT" >&5
4aaf76
+$as_echo "$VDOIMPORT" >&6; }
4aaf76
+
4aaf76
 ################################################################################
4aaf76
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to install blkdeactivate" >&5
4aaf76
 $as_echo_n "checking whether to install blkdeactivate... " >&6; }
4aaf76
@@ -13857,6 +13875,13 @@ cat >>confdefs.h <<_ACEOF
4aaf76
 _ACEOF
4aaf76
 
4aaf76
 
4aaf76
+VDOIMPORT_PATH="$SBINDIR/vdoimport"
4aaf76
+
4aaf76
+cat >>confdefs.h <<_ACEOF
4aaf76
+#define VDOIMPORT_PATH "$VDOIMPORT_PATH"
4aaf76
+_ACEOF
4aaf76
+
4aaf76
+
4aaf76
 ################################################################################
4aaf76
 if test "$BUILD_DMEVENTD" = yes; then
4aaf76
 
4aaf76
diff --git a/configure.ac b/configure.ac
4aaf76
index 1a49e7f..5a8b486 100644
4aaf76
--- a/configure.ac
4aaf76
+++ b/configure.ac
4aaf76
@@ -45,6 +45,7 @@ case "$host_os" in
4aaf76
 		DM_IOCTLS=yes
4aaf76
 		SELINUX=yes
4aaf76
 		FSADM=yes
4aaf76
+		VDOIMPORT=yes
4aaf76
 		BLKDEACTIVATE=yes
4aaf76
 		;;
4aaf76
 	darwin*)
4aaf76
@@ -58,6 +59,7 @@ case "$host_os" in
4aaf76
 		DM_IOCTLS=no
4aaf76
 		SELINUX=no
4aaf76
 		FSADM=no
4aaf76
+		VDOIMPORT=no
4aaf76
 		BLKDEACTIVATE=no
4aaf76
 		;;
4aaf76
 	*)
4aaf76
@@ -1291,6 +1293,14 @@ AC_ARG_ENABLE(fsadm, AC_HELP_STRING([--disable-fsadm], [disable fsadm]),
4aaf76
 	      FSADM=$enableval)
4aaf76
 AC_MSG_RESULT($FSADM)
4aaf76
 
4aaf76
+
4aaf76
+################################################################################
4aaf76
+dnl -- Enable vdoimport
4aaf76
+AC_MSG_CHECKING(whether to install vdoimport)
4aaf76
+AC_ARG_ENABLE(vdoimport, AC_HELP_STRING([--disable-vdoimport], [disable vdoimport]),
4aaf76
+	      VDOIMPORT=$enableval)
4aaf76
+AC_MSG_RESULT($VDOIMPORT)
4aaf76
+
4aaf76
 ################################################################################
4aaf76
 dnl -- Enable blkdeactivate
4aaf76
 AC_MSG_CHECKING(whether to install blkdeactivate)
4aaf76
@@ -1646,6 +1656,9 @@ USRSBINDIR="$(eval echo $(eval echo $usrsbindir))"
4aaf76
 FSADM_PATH="$SBINDIR/fsadm"
4aaf76
 AC_DEFINE_UNQUOTED(FSADM_PATH, ["$FSADM_PATH"], [Path to fsadm binary.])
4aaf76
 
4aaf76
+VDOIMPORT_PATH="$SBINDIR/vdoimport"
4aaf76
+AC_DEFINE_UNQUOTED(VDOIMPORT_PATH, ["$VDOIMPORT_PATH"], [Path to vdoimport binary.])
4aaf76
+
4aaf76
 ################################################################################
4aaf76
 dnl -- dmeventd pidfile and executable path
4aaf76
 if test "$BUILD_DMEVENTD" = yes; then
4aaf76
@@ -1882,6 +1895,8 @@ AC_SUBST(SILENT_RULES)
4aaf76
 AC_SUBST(USRSBINDIR)
4aaf76
 AC_SUBST(VALGRIND_POOL)
4aaf76
 AC_SUBST(VDO)
4aaf76
+AC_SUBST(VDOIMPORT)
4aaf76
+AC_SUBST(VDOIMPORT_PATH)
4aaf76
 AC_SUBST(VDO_FORMAT_CMD)
4aaf76
 AC_SUBST(VDO_INCLUDE)
4aaf76
 AC_SUBST(VDO_LIB)
4aaf76
diff --git a/include/configure.h.in b/include/configure.h.in
4aaf76
index 671d201..6df8d89 100644
4aaf76
--- a/include/configure.h.in
4aaf76
+++ b/include/configure.h.in
4aaf76
@@ -684,6 +684,9 @@
4aaf76
 /* Enable a valgrind aware build of pool */
4aaf76
 #undef VALGRIND_POOL
4aaf76
 
4aaf76
+/* Path to vdoimport binary. */
4aaf76
+#undef VDOIMPORT_PATH
4aaf76
+
4aaf76
 /* The path to 'vdoformat', if available. */
4aaf76
 #undef VDO_FORMAT_CMD
4aaf76
 
4aaf76
diff --git a/man/Makefile.in b/man/Makefile.in
4aaf76
index 29afc77..d60a92c 100644
4aaf76
--- a/man/Makefile.in
4aaf76
+++ b/man/Makefile.in
4aaf76
@@ -23,6 +23,7 @@ else
4aaf76
 endif
4aaf76
 
4aaf76
 FSADMMAN = fsadm.8
4aaf76
+VDOIMPORTMAN = vdoimport.8
4aaf76
 BLKDEACTIVATEMAN = blkdeactivate.8
4aaf76
 DMEVENTDMAN = dmeventd.8
4aaf76
 DMFILEMAPDMAN = dmfilemapd.8
4aaf76
@@ -50,7 +51,7 @@ MAN8SYSTEMD_GENERATORS=lvm2-activation-generator.8
4aaf76
 
4aaf76
 ifeq (,$(findstring $(MAKECMDGOALS), distclean all_man install_all_man))
4aaf76
   MAN7 += lvmcache.7 lvmthin.7 lvmvdo.7
4aaf76
-  MAN8+=$(FSADMMAN) $(LVMPOLLDMAN) $(LVMLOCKDMAN) $(LVMDBUSDMAN)
4aaf76
+  MAN8+=$(FSADMMAN) $(LVMPOLLDMAN) $(LVMLOCKDMAN) $(LVMDBUSDMAN) $(VDOIMPORTMAN)
4aaf76
   MAN8DM+=$(BLKDEACTIVATEMAN) $(DMEVENTDMAN) $(DMFILEMAPDMAN)
4aaf76
   MAN8CLUSTER+=$(CMIRRORDMAN)
4aaf76
 else
4aaf76
@@ -58,6 +59,10 @@ else
4aaf76
     MAN8+=$(FSADMMAN)
4aaf76
   endif
4aaf76
 
4aaf76
+  ifeq ("@VDOIMPORT@", "yes")
4aaf76
+    MAN8+=$(VDOIMPORTMAN)
4aaf76
+  endif
4aaf76
+
4aaf76
   ifeq ("@BUILD_LVMDBUSD@", "yes")
4aaf76
     MAN8+=$(LVMDBUSDMAN)
4aaf76
   endif
4aaf76
diff --git a/scripts/Makefile.in b/scripts/Makefile.in
4aaf76
index e8f6742..1fe88ca 100644
4aaf76
--- a/scripts/Makefile.in
4aaf76
+++ b/scripts/Makefile.in
4aaf76
@@ -31,6 +31,10 @@ ifeq ("@FSADM@", "yes")
4aaf76
 	LVM_SCRIPTS += fsadm.sh
4aaf76
 endif
4aaf76
 
4aaf76
+ifeq ("@VDOIMPORT@", "yes")
4aaf76
+	LVM_SCRIPTS += vdoimport.sh
4aaf76
+endif
4aaf76
+
4aaf76
 ifeq ("@BLKDEACTIVATE@", "yes")
4aaf76
 	DM_SCRIPTS += blkdeactivate.sh
4aaf76
 endif
4aaf76
diff --git a/scripts/vdoimport.sh b/scripts/vdoimport.sh
4aaf76
new file mode 100755
4aaf76
index 0000000..ef96591
4aaf76
--- /dev/null
4aaf76
+++ b/scripts/vdoimport.sh
4aaf76
@@ -0,0 +1,376 @@
4aaf76
+#!/bin/bash
4aaf76
+#
4aaf76
+# Copyright (C) 2021 Red Hat, Inc. All rights reserved.
4aaf76
+#
4aaf76
+# This file is part of LVM2.
4aaf76
+#
4aaf76
+# This copyrighted material is made available to anyone wishing to use,
4aaf76
+# modify, copy, or redistribute it subject to the terms and conditions
4aaf76
+# of the GNU General Public License v.2.
4aaf76
+#
4aaf76
+# You should have received a copy of the GNU General Public License
4aaf76
+# along with this program; if not, write to the Free Software Foundation,
4aaf76
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4aaf76
+#
4aaf76
+# Author: Zdenek Kabelac <zkabelac at redhat.com>
4aaf76
+#
4aaf76
+# Script for converting VDO volumes to lvm2 VDO LVs
4aaf76
+#
4aaf76
+# Needed utilities:
4aaf76
+#  lvm, dmsetup,
4aaf76
+#  vdo, vdo2lvm,
4aaf76
+#  grep, awk, sed, blockdev, readlink, mkdir
4aaf76
+#
4aaf76
+# Conversion is using  'vdo convert' support from VDO manager to move
4aaf76
+# existing VDO header by 2M which makes space to place in PV header
4aaf76
+# and VG metadata area, and then create VDOPOOL LV and VDO LV in such VG.
4aaf76
+#
4aaf76
+
4aaf76
+set -euE -o pipefail
4aaf76
+
4aaf76
+TOOL=vdoimport
4aaf76
+
4aaf76
+_SAVEPATH=$PATH
4aaf76
+PATH="/sbin:/usr/sbin:/bin:/usr/sbin:$PATH"
4aaf76
+
4aaf76
+# user may override lvm location by setting LVM_BINARY
4aaf76
+LVM=${LVM_BINARY:-lvm}
4aaf76
+VDO=${VDO_BINARY:-vdo}
4aaf76
+VDOCONF=${VDOCONF:-}
4aaf76
+BLOCKDEV="blockdev"
4aaf76
+READLINK="readlink"
4aaf76
+READLINK_E="-e"
4aaf76
+MKDIR="mkdir"
4aaf76
+
4aaf76
+TEMPDIR="${TMPDIR:-/tmp}/${TOOL}_${RANDOM}$$"
4aaf76
+DM_DEV_DIR="${DM_DEV_DIR:-/dev}"
4aaf76
+
4aaf76
+DRY=0
4aaf76
+VERB=""
4aaf76
+FORCE=""
4aaf76
+YES=""
4aaf76
+
4aaf76
+# default name for converted VG and its VDO LV
4aaf76
+NAME="vdovg/vdolvol"
4aaf76
+
4aaf76
+# help message
4aaf76
+tool_usage() {
4aaf76
+	echo "${TOOL}: Utility to convert VDO volume to VDO LV."
4aaf76
+	echo
4aaf76
+	echo "	${TOOL} [options] <vdo_device_path>"
4aaf76
+	echo
4aaf76
+	echo "	Options:"
4aaf76
+	echo "	  -f | --force	      Bypass sanity checks"
4aaf76
+	echo "	  -h | --help	      Show this help message"
4aaf76
+	echo "	  -n | --name	      Specifies VG/LV name for converted VDO volume"
4aaf76
+	echo "	  -v | --verbose      Be verbose"
4aaf76
+	echo "	  -y | --yes	      Answer \"yes\" at any prompts"
4aaf76
+	echo "	       --dry-run      Print commands without running them"
4aaf76
+
4aaf76
+	exit
4aaf76
+}
4aaf76
+
4aaf76
+verbose() {
4aaf76
+	test -z "$VERB" || echo "$TOOL:" "$@"
4aaf76
+}
4aaf76
+
4aaf76
+# Support multi-line error messages
4aaf76
+error() {
4aaf76
+	for i in "$@" ;  do
4aaf76
+		echo "$TOOL: $i" >&2
4aaf76
+	done
4aaf76
+	cleanup 1
4aaf76
+}
4aaf76
+
4aaf76
+dry() {
4aaf76
+	if [ "$DRY" -ne 0 ]; then
4aaf76
+		verbose "Dry execution" "$@"
4aaf76
+		return 0
4aaf76
+	fi
4aaf76
+	verbose "Executing" "$@"
4aaf76
+	"$@"
4aaf76
+}
4aaf76
+
4aaf76
+cleanup() {
4aaf76
+	trap '' 2
4aaf76
+
4aaf76
+	rm -rf "$TEMPDIR"
4aaf76
+	# error exit status for break
4aaf76
+	exit "${1:-1}"
4aaf76
+}
4aaf76
+
4aaf76
+get_enabled_value_() {
4aaf76
+	case "$1" in
4aaf76
+	enabled) echo "1" ;;
4aaf76
+	*) echo "0" ;;
4aaf76
+	esac
4aaf76
+}
4aaf76
+
4aaf76
+get_kb_size_with_unit_() {
4aaf76
+	case "$1" in
4aaf76
+	*[kK]) echo $(( ${1%[kK]} )) ;;
4aaf76
+	*[mM]) echo $(( ${1%[mM]} * 1024 )) ;;
4aaf76
+	*[gG]) echo $(( ${1%[gG]} * 1024 * 1024 )) ;;
4aaf76
+	*[tT]) echo $(( ${1%[tT]} * 1024 * 1024 * 1024 )) ;;
4aaf76
+	*[pP]) echo $(( ${1%[pP]} * 1024 * 1024 * 1024 * 1024 )) ;;
4aaf76
+	esac
4aaf76
+}
4aaf76
+
4aaf76
+get_mb_size_with_unit_() {
4aaf76
+	case "$1" in
4aaf76
+	*[mM]) echo $(( ${1%[mM]} )) ;;
4aaf76
+	*[gG]) echo $(( ${1%[gG]} * 1024 )) ;;
4aaf76
+	*[tT]) echo $(( ${1%[tT]} * 1024 * 1024 )) ;;
4aaf76
+	*[pP]) echo $(( ${1%[pP]} * 1024 * 1024 * 1024 )) ;;
4aaf76
+	esac
4aaf76
+}
4aaf76
+
4aaf76
+# Figure out largest possible extent size usable for VG
4aaf76
+# $1   physical size
4aaf76
+# $2   logical size
4aaf76
+get_largest_extent_size_() {
4aaf76
+	local max=4
4aaf76
+	local i
4aaf76
+	local d
4aaf76
+
4aaf76
+	for i in 8 16 32 64 128 256 512 1024 2048 4096 ; do
4aaf76
+		d=$(( $1 / i ))
4aaf76
+		test $(( d * i )) -eq "$1" || break
4aaf76
+		d=$(( $2 / i ))
4aaf76
+		test $(( d * i )) -eq "$2" || break
4aaf76
+		max=$i
4aaf76
+	done
4aaf76
+	echo "$max"
4aaf76
+}
4aaf76
+
4aaf76
+# detect LV on the given device
4aaf76
+# dereference device name if it is symbolic link
4aaf76
+detect_lv_() {
4aaf76
+	local DEVICE=$1
4aaf76
+	local MAJOR
4aaf76
+	local MINOR
4aaf76
+	local SYSVOLUME
4aaf76
+	local MAJORMINOR
4aaf76
+
4aaf76
+	DEVICE=${1/#"${DM_DEV_DIR}/"/}
4aaf76
+	DEVICE=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$DEVICE")
4aaf76
+	test -n "$DEVICE" || error "Cannot get readlink \"$1\"."
4aaf76
+	RDEVICE=$DEVICE
4aaf76
+	case "$RDEVICE" in
4aaf76
+	  # hardcoded /dev  since udev does not create these entries elsewhere
4aaf76
+	  /dev/dm-[0-9]*)
4aaf76
+		read -r <"/sys/block/${RDEVICE#/dev/}/dm/name" SYSVOLUME 2>&1 && DEVICE="$DM_DEV_DIR/mapper/$SYSVOLUME"
4aaf76
+		read -r <"/sys/block/${RDEVICE#/dev/}/dev" MAJORMINOR 2>&1 || error "Cannot get major:minor for \"$DEVICE\"."
4aaf76
+		MAJOR=${MAJORMINOR%%:*}
4aaf76
+		MINOR=${MAJORMINOR##*:}
4aaf76
+		;;
4aaf76
+	  *)
4aaf76
+		STAT=$(stat --format "MAJOR=\$((0x%t)) MINOR=\$((0x%T))" "$RDEVICE")
4aaf76
+		test -n "$STAT" || error "Cannot get major:minor for \"$DEVICE\"."
4aaf76
+		eval "$STAT"
4aaf76
+		;;
4aaf76
+	esac
4aaf76
+
4aaf76
+	eval "$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o uuid,name --noheadings --nameprefixes --separator ' ')"
4aaf76
+}
4aaf76
+
4aaf76
+# parse yaml config files into 'prefix_yaml_part_names=("value")' strings
4aaf76
+parse_yaml_() {
4aaf76
+	local yaml_file=$1
4aaf76
+	local prefix=$2
4aaf76
+	local s
4aaf76
+	local w
4aaf76
+	local fs
4aaf76
+
4aaf76
+	s='[[:space:]]*'
4aaf76
+	w='[a-zA-Z0-9_.-]*'
4aaf76
+	fs="$(echo @|tr @ '\034')"
4aaf76
+
4aaf76
+	(
4aaf76
+	    sed -ne '/^--/s|--||g; s|\"|\\\"|g; s/[[:space:]]*$//g;' \
4aaf76
+		-e 's/\$/\\\$/g' \
4aaf76
+		-e "/#.*[\"\']/!s| #.*||g; /^#/s|#.*||g;" \
4aaf76
+		-e "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
4aaf76
+		-e "s|^\($s\)\($w\)${s}[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" |
4aaf76
+
4aaf76
+	    awk -F"$fs" '{
4aaf76
+		indent = length($1)/2;
4aaf76
+		if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
4aaf76
+		vname[indent] = $2;
4aaf76
+		for (i in vname) {if (i > indent) {delete vname[i]}}
4aaf76
+		    if (length($3) > 0) {
4aaf76
+			vn=""; for (i=0; i
4aaf76
+			printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1], $3);
4aaf76
+		    }
4aaf76
+		}' |
4aaf76
+
4aaf76
+	    sed -e 's/_=/+=/g' |
4aaf76
+
4aaf76
+	    awk 'BEGIN {
4aaf76
+		    FS="=";
4aaf76
+		    OFS="="
4aaf76
+		}
4aaf76
+		/(-|\.).*=/ {
4aaf76
+		    gsub("-|\\.", "_", $1)
4aaf76
+		}
4aaf76
+		{ print }'
4aaf76
+	) < "$yaml_file"
4aaf76
+}
4aaf76
+
4aaf76
+# convert existing VDO volume into lvm2 volume
4aaf76
+convert2lvm_() {
4aaf76
+	local DEVICE=$1
4aaf76
+	local VGNAME=${NAME%/*}
4aaf76
+	local LVNAME=${NAME#*/}
4aaf76
+	local VDONAME
4aaf76
+	local TRVDONAME
4aaf76
+	local EXTENTSZ
4aaf76
+	local IS_LV=1
4aaf76
+
4aaf76
+	DM_UUID=""
4aaf76
+	detect_lv_ "$DEVICE"
4aaf76
+	case "$DM_UUID" in
4aaf76
+		LVM-*)	eval "$(dmsetup splitname --nameprefixes --noheadings --separator ' ' "$DM_NAME")"
4aaf76
+			if [ -z "$VGNAME" ] || [ "$VGNAME" = "$LVNAME" ]  ; then
4aaf76
+				VGNAME=$DM_VG_NAME
4aaf76
+			elif test "$VGNAME" != "$DM_VG_NAME" ; then
4aaf76
+				error "Volume group name \"$VGNAME\" does not match name \"$DM_VG_NAME\" for device \"$DEVICE\"."
4aaf76
+			fi
4aaf76
+			;;
4aaf76
+		*) IS_LV=0
4aaf76
+			# Check $VGNANE does not already exists
4aaf76
+			"$LVM" vgs "$VGNAME" && error "Cannot use already existing volume group name \"$VGNAME\"."
4aaf76
+			;;
4aaf76
+	esac
4aaf76
+
4aaf76
+	verbose "Checked whether device $1 is already LV ($IS_LV)."
4aaf76
+
4aaf76
+	"$MKDIR" -p -m 0000 "$TEMPDIR" || error "Failed to create $TEMPDIR."
4aaf76
+
4aaf76
+	verbose "Getting YAML VDO configuration."
4aaf76
+	"$VDO" printConfigFile $VDOCONF >"$TEMPDIR/vdoconf.yml"
4aaf76
+
4aaf76
+	VDONAME=$(awk -v DNAME="$DEVICE" '/.*VDOService$/ {VNAME=substr($1, 0, length($1) - 1)} /[[:space:]]*device:/ { if ($2 ~ DNAME) {print VNAME}}' "$TEMPDIR/vdoconf.yml")
4aaf76
+	TRVDONAME=$(echo "$VDONAME" | tr '-' '_')
4aaf76
+
4aaf76
+	# When VDO volume is 'active', check it's not mounted/being used
4aaf76
+	eval "$(dmsetup info -c -o open  "$VDONAME" --noheadings --nameprefixes || true)"
4aaf76
+	test "${DM_OPEN:-0}" -eq 0 || error "Cannot converted VDO volume \"$VDONAME\" which is in use!"
4aaf76
+
4aaf76
+	#parse_yaml_ "$TEMPDIR/vdoconf.yml" _
4aaf76
+	eval "$(parse_yaml_ "$TEMPDIR/vdoconf.yml" _ | grep "$TRVDONAME" | sed -e "s/_config_vdos_$TRVDONAME/vdo/g")"
4aaf76
+
4aaf76
+	vdo_logicalSize=$(get_kb_size_with_unit_ "$vdo_logicalSize")
4aaf76
+	vdo_physicalSize=$(get_kb_size_with_unit_ "$vdo_physicalSize")
4aaf76
+
4aaf76
+	verbose "Going to convert physical sized VDO device $vdo_physicalSize KiB."
4aaf76
+	verbose "With logical volume of size $vdo_logicalSize KiB."
4aaf76
+
4aaf76
+	PARAMS=$(cat <
4aaf76
+allocation {
4aaf76
+	vdo_use_compression = $(get_enabled_value_ "$vdo_compression")
4aaf76
+	vdo_use_deduplication = $(get_enabled_value_ "$vdo_deduplication")
4aaf76
+	vdo_use_metadata_hints=1
4aaf76
+	vdo_minimum_io_size = $vdo_logicalBlockSize
4aaf76
+	vdo_block_map_cache_size_mb = $(get_mb_size_with_unit_ "$vdo_blockMapCacheSize")
4aaf76
+	vdo_block_map_period = $vdo_blockMapPeriod
4aaf76
+	vdo_check_point_frequency = $vdo_indexCfreq
4aaf76
+	vdo_use_sparse_index = $(get_enabled_value_ "$vdo_indexSparse")
4aaf76
+	vdo_index_memory_size_mb = $(awk "BEGIN {print $vdo_indexMemory * 1024}")
4aaf76
+	vdo_slab_size_mb = $(get_mb_size_with_unit_ "$vdo_blockMapCacheSize")
4aaf76
+	vdo_ack_threads = $vdo_ackThreads
4aaf76
+	vdo_bio_threads = $vdo_bioThreads
4aaf76
+	vdo_bio_rotation = $vdo_bioRotationInterval
4aaf76
+	vdo_cpu_threads = $vdo_cpuThreads
4aaf76
+	vdo_hash_zone_threads = $vdo_hashZoneThreads
4aaf76
+	vdo_logical_threads = $vdo_logicalThreads
4aaf76
+	vdo_physical_threads = $vdo_physicalThreads
4aaf76
+	vdo_write_policy = $vdo_writePolicy
4aaf76
+	vdo_max_discard = $(( $(get_kb_size_with_unit_ "$vdo_maxDiscardSize") * 1024 ))
4aaf76
+	vdo_pool_header_size = 0
4aaf76
+}
4aaf76
+EOF
4aaf76
+)
4aaf76
+	verbose "VDO conversion paramaters: $PARAMS"
4aaf76
+
4aaf76
+	verbose "Stopping VDO volume."
4aaf76
+	dry "$VDO" stop $VDOCONF --name "$VDONAME"
4aaf76
+
4aaf76
+	if [ "$IS_LV" = "0" ]; then
4aaf76
+		verbose "Moving VDO header by 2MiB."
4aaf76
+		dry "$VDO" convert $VDOCONF --force --name "$VDONAME"
4aaf76
+
4aaf76
+		dry "$LVM" pvcreate $YES --dataalignment 2M "$DEVICE" || {
4aaf76
+			error "Creation of PV on \"$DEVICE\" failed, while VDO header has been already moved!"
4aaf76
+		}
4aaf76
+
4aaf76
+		# Obtain free space in this new PV
4aaf76
+		# after 'vdo convert/vdo2lvm' call there is +2M free space at the front of the device
4aaf76
+		case "$DRY" in
4aaf76
+		0) pvfree=$("$LVM" pvs -o devsize --units b --nosuffix --noheadings "$DEVICE") ;;
4aaf76
+		*) pvfree=$("$BLOCKDEV" --getsize64 "$DEVICE") ;;
4aaf76
+		esac
4aaf76
+
4aaf76
+		pvfree=$(( pvfree / 1024 - 2048 ))	# to KiB
4aaf76
+	else
4aaf76
+		pvfree=$("$LVM" lvs -o size --units b --nosuffix --noheadings "$VGNAME/$LVNAME")
4aaf76
+		pvfree=$(( pvfree / 1024 ))		# to KiB
4aaf76
+	fi
4aaf76
+
4aaf76
+	# select largest possible extent size that can exactly express both sizes
4aaf76
+	EXTENTSZ=$(get_largest_extent_size_ "$pvfree" "$vdo_logicalSize")
4aaf76
+
4aaf76
+	if [ "$IS_LV" = "0" ]; then
4aaf76
+		verbose "Creating VG \"${NAME%/*}\" with extent size $EXTENTSZ KiB."
4aaf76
+		dry "$LVM" vgcreate $YES $VERB -s "${EXTENTSZ}k" "$VGNAME" "$DEVICE" || {
4aaf76
+			error "Creation of VG \"$VGNAME\" failed, while VDO header has been already moved!"
4aaf76
+		}
4aaf76
+
4aaf76
+		verbose "Creating VDO pool data LV from all extents in volume group $VGNAME."
4aaf76
+		dry "$LVM" lvcreate -Zn -Wn $YES $VERB -l100%VG -n "${LVNAME}_vpool" "$VGNAME"
4aaf76
+	else
4aaf76
+		# validate existing  VG extent_size can express virtual VDO size
4aaf76
+		vg_extent_size=$("$LVM" vgs -o vg_extent_size --units b --nosuffix --noheadings "$VGNAME" || true)
4aaf76
+		vg_extent_size=$(( vg_extent_size / 1024 ))
4aaf76
+
4aaf76
+		test "$vg_extent_size" -le "$EXTENTSZ" || {
4aaf76
+			error "Please vgchange extent_size to at most $EXTENTSZ KiB or extend and align virtual size on $vg_extent_size KiB."
4aaf76
+		}
4aaf76
+		verbose "Renaming existing LV to be used as _vdata volume for VDO pool LV."
4aaf76
+		dry "$LVM" lvrename $YES $VERB "$VGNAME/$LVNAME" "$VGNAME/${LVNAME}_vpool" || {
4aaf76
+			error "Rename of LV \"$VGNAME/$LVNAME\" failed, while VDO header has been already moved!"
4aaf76
+		}
4aaf76
+	fi
4aaf76
+
4aaf76
+	verbose "Converting to VDO pool."
4aaf76
+	dry "$LVM" lvconvert $YES $VERB $FORCE --config "$PARAMS" -Zn -V "${vdo_logicalSize}k" -n "$LVNAME" --type vdo-pool "$VGNAME/${LVNAME}_vpool"
4aaf76
+
4aaf76
+	rm -fr "$TEMPDIR"
4aaf76
+}
4aaf76
+
4aaf76
+#############################
4aaf76
+# start point of this script
4aaf76
+# - parsing parameters
4aaf76
+#############################
4aaf76
+trap "cleanup 2" 2
4aaf76
+
4aaf76
+test "$#" -eq 0 && tool_usage
4aaf76
+
4aaf76
+while [ "$#" -ne 0 ]
4aaf76
+do
4aaf76
+	 case "$1" in
4aaf76
+	  "") ;;
4aaf76
+	  "-f"|"--force"  ) FORCE="-f" ;;
4aaf76
+	  "-h"|"--help"   ) tool_usage ;;
4aaf76
+	  "-n"|"--name"   ) shift; NAME=$1 ;;
4aaf76
+	  "-v"|"--verbose") VERB="-v" ;;
4aaf76
+	  "-y"|"--yes"    ) YES="-y" ;;
4aaf76
+	  "--dry-run"     ) DRY="1" ;;
4aaf76
+	  "-*") error "Wrong argument \"$1\". (see: $TOOL --help)" ;;
4aaf76
+	  *) DEVICENAME=$1 ;;  # device name does not start with '-'
4aaf76
+	esac
4aaf76
+	shift
4aaf76
+done
4aaf76
+
4aaf76
+# do conversion
4aaf76
+convert2lvm_ "$DEVICENAME"
4aaf76
diff --git a/test/Makefile.in b/test/Makefile.in
4aaf76
index e4cd3aa..6be03aa 100644
4aaf76
--- a/test/Makefile.in
4aaf76
+++ b/test/Makefile.in
4aaf76
@@ -353,6 +353,7 @@ LIB = $(addprefix lib/, $(LIB_SECURETEST) $(LIB_DMSECURETEST) $(LIB_SHARED) $(LI
4aaf76
 	$(Q) $(LN_S) -f $(abs_top_srcdir)/conf/lvmdbusd.profile lib/
4aaf76
 	$(Q) $(LN_S) -f $(abs_top_srcdir)/conf/thin-performance.profile lib/
4aaf76
 	$(Q) $(LN_S) -f $(abs_top_srcdir)/scripts/fsadm.sh lib/fsadm
4aaf76
+	$(Q) $(LN_S) -f $(abs_top_srcdir)/scripts/vdoimport.sh lib/vdoimport
4aaf76
 	@test "$(srcdir)" = . || \
4aaf76
 		for i in $(LIB_LVMLOCKD_CONF) $(LIB_MKE2FS_CONF); do \
4aaf76
 			test -n "$(Q)" || echo "$(LN_S) -f $(abs_top_srcdir)/test/lib/$$i lib/"; \
4aaf76
diff --git a/test/shell/vdo-convert.sh b/test/shell/vdo-convert.sh
4aaf76
new file mode 100644
4aaf76
index 0000000..538147b
4aaf76
--- /dev/null
4aaf76
+++ b/test/shell/vdo-convert.sh
4aaf76
@@ -0,0 +1,110 @@
4aaf76
+#!/usr/bin/env bash
4aaf76
+
4aaf76
+# Copyright (C) 2021 Red Hat, Inc. All rights reserved.
4aaf76
+#
4aaf76
+# This copyrighted material is made available to anyone wishing to use,
4aaf76
+# modify, copy, or redistribute it subject to the terms and conditions
4aaf76
+# of the GNU General Public License v.2.
4aaf76
+#
4aaf76
+# You should have received a copy of the GNU General Public License
4aaf76
+# along with this program; if not, write to the Free Software Foundation,
4aaf76
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4aaf76
+
4aaf76
+# Test conversion of VDO volumes made by vdo manager into VDO LV.
4aaf76
+
4aaf76
+
4aaf76
+SKIP_WITH_LVMPOLLD=1
4aaf76
+
4aaf76
+. lib/inittest
4aaf76
+
4aaf76
+# Use local for this test vdo configuratoin
4aaf76
+VDOCONF="-f vdotestconf.yml"
4aaf76
+#VDOCONF=""
4aaf76
+export VDOCONF
4aaf76
+VDONAME="${PREFIX}-TESTVDO"
4aaf76
+
4aaf76
+# VDO automatically starts dmeventd
4aaf76
+aux prepare_dmeventd
4aaf76
+
4aaf76
+#
4aaf76
+# Main
4aaf76
+#
4aaf76
+which vdo || skip
4aaf76
+which mkfs.ext4 || skip
4aaf76
+export MKE2FS_CONFIG="$TESTDIR/lib/mke2fs.conf"
4aaf76
+
4aaf76
+aux have_vdo 6 2 0 || skip
4aaf76
+
4aaf76
+aux prepare_devs 2 10000
4aaf76
+
4aaf76
+aux extend_filter_LVMTEST
4aaf76
+
4aaf76
+
4aaf76
+#
4aaf76
+#  Check conversion of VDO volume made on some LV
4aaf76
+#
4aaf76
+#  In this case we do not need to move any VDO headers.
4aaf76
+#
4aaf76
+vgcreate $vg "$dev1"
4aaf76
+
4aaf76
+lvcreate -L5G -n $lv1 $vg
4aaf76
+
4aaf76
+vdo create $VDOCONF --name "$VDONAME" --device="$DM_DEV_DIR/$vg/$lv1" --vdoLogicalSize=10G
4aaf76
+
4aaf76
+mkfs -E nodiscard "$DM_DEV_DIR/mapper/$VDONAME"
4aaf76
+
4aaf76
+# Different VG name fails
4aaf76
+not vdoimport -y -v --name $vg1/$lv1 "$DM_DEV_DIR/$vg/$lv1"
4aaf76
+
4aaf76
+# Try just dry run and observe logging
4aaf76
+vdoimport --dry-run -y -v --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
4aaf76
+
4aaf76
+vdoimport -y --name $lv1 "$DM_DEV_DIR/$vg/$lv1"
4aaf76
+
4aaf76
+# ATM needed - since we do not call 'vdo convert' in this case
4aaf76
+vdo remove $VDOCONF --force --name "$VDONAME" || true
4aaf76
+
4aaf76
+vgremove -f $vg
4aaf76
+
4aaf76
+aux wipefs_a "$dev1"
4aaf76
+
4aaf76
+# prepare 'unused' $vg2
4aaf76
+vgcreate $vg2 "$dev2"
4aaf76
+
4aaf76
+#
4aaf76
+# Check conversion of VDO volume on  non-LV device
4aaf76
+#
4aaf76
+vdo create $VDOCONF --name "$VDONAME" --device="$dev1" --vdoLogicalSize=31G
4aaf76
+
4aaf76
+mkfs -E nodiscard "$DM_DEV_DIR/mapper/$VDONAME"
4aaf76
+
4aaf76
+# Fail with an already existing volume group $vg2
4aaf76
+not vdoimport --dry-run -y -v --name $vg2/$lv1 "$dev1" |& tee err
4aaf76
+grep "already existing volume group" err
4aaf76
+
4aaf76
+# User can also convert already stopped VDO volume
4aaf76
+vdo stop $VDOCONF --name "$VDONAME"
4aaf76
+
4aaf76
+vdoimport -y -v --name $vg/$lv1 "$dev1"
4aaf76
+
4aaf76
+fsck -n "$DM_DEV_DIR/$vg/$lv1"
4aaf76
+
4aaf76
+vgremove -f $vg
4aaf76
+
4aaf76
+
4aaf76
+#
4aaf76
+# Try once again with different vgname/lvname and sizes
4aaf76
+#
4aaf76
+aux teardown_devs
4aaf76
+aux prepare_devs 1 23456
4aaf76
+
4aaf76
+vdo create $VDOCONF --name "$VDONAME" --device="$dev1" --vdoLogicalSize=23G
4aaf76
+
4aaf76
+mkfs -E nodiscard "$DM_DEV_DIR/mapper/$VDONAME"
4aaf76
+
4aaf76
+vdoimport -y -v --name $vg1/$lv2 "$dev1"
4aaf76
+
4aaf76
+fsck -n "$DM_DEV_DIR/$vg1/$lv2"
4aaf76
+
4aaf76
+vgremove -f $vg1
4aaf76
+