2021-07-09 15:44:07 +03:00
#!/usr/bin/env bash
# Copyright (C) 2021 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Test conversion of VDO volumes made by vdo manager into VDO LV.
SKIP_WITH_LVMPOLLD = 1
. lib/inittest
# Use local for this test vdo configuratoin
2023-06-09 14:28:23 +03:00
VDO_CONFIG = "vdotestconf.yml"
VDOCONF = " -f $VDO_CONFIG "
2021-07-09 15:44:07 +03:00
#VDOCONF=""
2023-06-09 14:28:23 +03:00
export VDOCONF VDO_CONFIG
2021-07-09 15:44:07 +03:00
VDONAME = " ${ PREFIX } -TESTVDO "
2023-06-09 14:28:23 +03:00
export DM_UUID_PREFIX = $PREFIX
2021-07-09 15:44:07 +03:00
# VDO automatically starts dmeventd
aux prepare_dmeventd
#
# Main
#
2022-09-06 17:44:24 +03:00
if not which vdo ; then
which lvm_vdo_wrapper || skip "Missing 'lvm_vdo_wrapper'."
which oldvdoformat || skip "Emulation of vdo manager 'oldvdoformat' missing."
which oldvdoprepareforlvm || skip "Emulation of vdo manager 'oldvdoprepareforlvm' missing."
# enable expansion of aliasis within script itself
shopt -s expand_aliases
alias vdo = 'lvm_vdo_wrapper'
export VDO_BINARY = lvm_vdo_wrapper
echo "Using 'lvm_vdo_wrapper' emulation of 'vdo' manager."
fi
2021-07-09 15:44:07 +03:00
which mkfs.ext4 || skip
export MKE2FS_CONFIG = " $TESTDIR /lib/mke2fs.conf "
aux have_vdo 6 2 0 || skip
2023-06-09 14:28:23 +03:00
aux prepare_devs 2 20000
2021-07-09 15:44:07 +03:00
aux extend_filter_LVMTEST
2023-06-09 14:28:23 +03:00
export TMPDIR = $PWD
2021-09-21 22:43:02 +03:00
# Conversion can be made with this version of vdo driver
aux have_vdo 6 2 5 || skip
2021-07-09 15:44:07 +03:00
#
# Check conversion of VDO volume made on some LV
#
# In this case we do not need to move any VDO headers.
#
vgcreate $vg " $dev1 "
lvcreate -L5G -n $lv1 $vg
2023-06-09 14:28:23 +03:00
# use some not so 'well' aligned virtual|logical size
2022-06-07 17:52:30 +03:00
vdo create $VDOCONF --name " $VDONAME " --device " $DM_DEV_DIR / $vg / $lv1 " --vdoSlabSize 128M --vdoLogicalSize 10G
2021-07-09 15:44:07 +03:00
mkfs -E nodiscard " $DM_DEV_DIR /mapper/ $VDONAME "
2023-06-09 14:28:23 +03:00
##XXXXX
2021-07-09 15:44:07 +03:00
# Different VG name fails
2021-08-26 17:53:33 +03:00
not lvm_import_vdo -y -v --name $vg1 /$lv1 " $DM_DEV_DIR / $vg / $lv1 "
2021-07-09 15:44:07 +03:00
# Try just dry run and observe logging
2021-08-26 17:53:33 +03:00
lvm_import_vdo --dry-run -y -v --name $lv1 " $DM_DEV_DIR / $vg / $lv1 "
2021-07-09 15:44:07 +03:00
2021-08-26 17:53:33 +03:00
lvm_import_vdo -y --name $lv1 " $DM_DEV_DIR / $vg / $lv1 "
2021-07-09 15:44:07 +03:00
2021-08-31 21:52:26 +03:00
# ensure VDO device is not left in config file
vdo remove $VDOCONF --force --name " $VDONAME " 2>/dev/null || true
lvremove -f $vg
# Test user can specify different VDO LV name (so the original LV is renamed)
lvcreate -y -L5G -n $lv1 $vg
2022-06-07 17:52:30 +03:00
vdo create $VDOCONF --name " $VDONAME " --device " $DM_DEV_DIR / $vg / $lv1 " --vdoSlabSize 128M --vdoLogicalSize 10G
2021-08-31 21:52:26 +03:00
lvm_import_vdo -y --name $vg /$lv2 " $DM_DEV_DIR / $vg / $lv1 "
check lv_exists $vg $lv2
check lv_not_exists $vg $lv1
2021-07-09 15:44:07 +03:00
vgremove -f $vg
2021-08-31 21:52:26 +03:00
# ensure VDO device is not left in config file
vdo remove $VDOCONF --force --name " $VDONAME " 2>/dev/null || true
2021-07-09 15:44:07 +03:00
aux wipefs_a " $dev1 "
# prepare 'unused' $vg2
vgcreate $vg2 " $dev2 "
#
2021-08-31 21:52:26 +03:00
# Check conversion of VDO volume on non-LV device and with >2T size
2021-07-09 15:44:07 +03:00
#
2022-06-07 17:52:30 +03:00
vdo create $VDOCONF --name " $VDONAME " --device " $dev1 " --vdoSlabSize 128M --vdoLogicalSize 3T
2021-07-09 15:44:07 +03:00
# Fail with an already existing volume group $vg2
2021-08-26 17:53:33 +03:00
not lvm_import_vdo --dry-run -y -v --name $vg2 /$lv1 " $dev1 " | & tee err
2021-07-09 15:44:07 +03:00
grep "already existing volume group" err
# User can also convert already stopped VDO volume
vdo stop $VDOCONF --name " $VDONAME "
2021-08-26 17:53:33 +03:00
lvm_import_vdo -y -v --name $vg /$lv1 " $dev1 "
2021-07-09 15:44:07 +03:00
2021-08-31 21:52:26 +03:00
check lv_field $vg /$lv1 size "3.00t"
2021-07-09 15:44:07 +03:00
vgremove -f $vg
#
# Try once again with different vgname/lvname and sizes
#
aux teardown_devs
aux prepare_devs 1 23456
2022-06-07 17:52:30 +03:00
vdo create $VDOCONF --name " $VDONAME " --device " $dev1 " --vdoSlabSize 128M --vdoLogicalSize 23G
2021-07-09 15:44:07 +03:00
mkfs -E nodiscard " $DM_DEV_DIR /mapper/ $VDONAME "
2023-06-09 14:28:23 +03:00
lvm_import_vdo --vdo-config " $VDO_CONFIG " -y -v --name $vg1 /$lv2 " $dev1 "
2021-07-09 15:44:07 +03:00
fsck -n " $DM_DEV_DIR / $vg1 / $lv2 "
vgremove -f $vg1
2023-06-09 14:28:23 +03:00
aux wipefs_a " $dev1 "
2021-09-06 16:06:32 +03:00
2023-06-09 14:28:23 +03:00
# let's assume users with VDO target have 'new' enough version of stat too
# otherwise use more universal code from lvm_vdo_import
read major minor < <( stat -c '%Hr %Lr' $( readlink -e " $dev1 " ) )
dmsetup create " $PREFIX -vdotest " --table " 0 30280004 linear $major : $minor 32 "
2021-09-06 16:06:32 +03:00
2023-06-09 14:28:23 +03:00
TEST = " $DM_DEV_DIR /mapper/ $PREFIX -vdotest "
2021-09-06 16:06:32 +03:00
2023-06-09 14:28:23 +03:00
aux wipefs_a " $TEST "
aux extend_filter " a| $TEST | "
aux extend_devices " $TEST "
2021-09-06 16:06:32 +03:00
#
# Unfortunatelly generates this in syslog:
#
# vdo-start-by-dev@loop0.service: Main process exited, code=exited, status=1/FAILURE
# vdo-start-by-dev@loop0.service: Failed with result 'exit-code'.
# Failed to start Start VDO volume backed by loop0.
#
# TODO: Could be handled by:
#
# systemctl mask vdo-start-by-dev@
# systemctl unmask vdo-start-by-dev@
#
# automate...
#
2023-06-09 14:28:23 +03:00
# use slightly smaller size then 'rounded' 23G - to enforce vdo_logicalSize rounding
vdo create $VDOCONF --name " $VDONAME " --device " $TEST " --vdoSlabSize 128M --vdoLogicalSize 24117240K\
2021-09-06 16:06:32 +03:00
--blockMapCacheSize 192 \
--blockMapPeriod 2048 \
--emulate512 disabled \
--indexMem 0.5 \
--maxDiscardSize 10 \
--sparseIndex disabled \
--vdoAckThreads 2 \
--vdoBioRotationInterval 8 \
--vdoBioThreads 2 \
--vdoCpuThreads 5 \
--vdoHashZoneThreads 3 \
--vdoLogicalThreads 3 \
--writePolicy async-unsafe
2023-06-09 14:28:23 +03:00
dmsetup table
2021-09-06 16:06:32 +03:00
# Get VDO table line
dmsetup table " $VDONAME " | tr " " "\n" | sed -e '5,6d' -e '12d' | tee vdo-orig
2023-06-23 19:03:25 +03:00
mkfs.ext4 -E nodiscard " $DM_DEV_DIR /mapper/ $VDONAME "
2023-06-09 14:28:23 +03:00
# For conversion we
2022-07-09 00:35:06 +03:00
aux lvmconf 'global/vdo_disabled_features = [ "version4" ]'
2023-06-09 14:28:23 +03:00
#
# Try to prepare 'broken' case where header was moved by older tool to 2M position
#
export LVM_VDO_PREPARE = oldvdoprepareforlvm2M
if which " $LVM_VDO_PREPARE " ; then
# Use old vdoprepareforlvm tool, that always moves header to 2M offset
cp " $VDO_CONFIG " " $VDO_CONFIG .backup "
lvm_import_vdo --abort-after-vdo-convert --vdo-config " $VDO_CONFIG " -v -y --name $vg /$lv " $TEST "
# Restore VDO configuration (as it's been removed with succeful vdo conversion
cp " $VDO_CONFIG .backup " " $VDO_CONFIG "
# Check VDO header is seen at 2M offset
blkid -c /dev/null --probe --offset 2M " $TEST "
fi
unset LVM_VDO_PREPARE
#lvm_import_vdo --no-snapshot --vdo-config "$VDO_CONFIG" -v -y --name $vg/$lv "$TEST"
lvm_import_vdo --vdo-config " $VDO_CONFIG " --uuid-prefix " $PREFIX " -v -y --name $vg /$lv " $TEST "
2023-06-23 19:03:25 +03:00
dmsetup table
# check our filesystem is OK
fsck -n " $DM_DEV_DIR / $vg / $lv "
2021-09-06 16:06:32 +03:00
2023-06-09 14:28:23 +03:00
# Compare converted LV uses same VDO table line
2021-09-06 16:06:32 +03:00
dmsetup table " $vg - ${ lv } _vpool-vpool " | tr " " "\n" | sed -e '5,6d' -e '12d' | tee new-vdo-lv
2023-06-23 19:03:25 +03:00
tail -n+3 vdo-orig >vdo-orig-3
tail -n+3 new-vdo-lv >new-vdo-lv-3
2021-09-06 16:06:32 +03:00
# Check there is a match between VDO and LV managed volume
# (when differentiating parameters are deleted first)
2023-06-23 19:03:25 +03:00
# we need to skip first 2 lines as the device size gets rounded to match VG extent size
diff -u vdo-orig-3 new-vdo-lv-3 || die "Found mismatching VDO table lines!"
2021-09-06 16:06:32 +03:00
2023-06-23 19:03:25 +03:00
check lv_field $vg /$lv size "23.00g"
2023-06-09 14:28:23 +03:00
unset LVM_VDO_PREPARE