2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2016-04-25 14:39:30 +03:00
# Copyright (C) 2014-2016 Red Hat, Inc. All rights reserved.
2014-06-17 03:15:39 +04:00
#
# 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,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2014-06-17 03:15:39 +04:00
2014-10-06 13:49:49 +04:00
# Exercise conversion of cache and cache pool
2016-02-23 01:13:42 +03:00
SKIP_WITH_LVMLOCKD = 1
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2014-06-17 03:15:39 +04:00
2015-10-27 17:10:06 +03:00
. lib/inittest
2015-05-09 02:59:18 +03:00
2014-06-17 03:15:39 +04:00
aux have_cache 1 3 0 || skip
aux prepare_vg 5 80
2014-11-05 01:24:56 +03:00
lvcreate --type cache-pool -an -v -L 2 -n cpool $vg
lvcreate -H -L 4 -n corigin --cachepool $vg /cpool
fail lvcreate -s -L2 $vg /cpool
fail lvcreate -s -L2 $vg /cpool_cdata
fail lvcreate -s -L2 $vg /cpool_cmeta
2014-10-06 13:49:49 +04:00
###########################
# Check regular converion #
###########################
2014-06-17 03:15:39 +04:00
# lvcreate origin, lvcreate cache-pool, and lvconvert to cache
2014-10-06 13:49:49 +04:00
lvcreate -an -Zn -L 2 -n $lv1 $vg
2014-07-11 14:15:46 +04:00
lvcreate -L 8 -n $lv2 $vg
2014-10-06 13:49:49 +04:00
lvcreate -an -Zn -L 8 -n $lv3 $vg
lvcreate -an -Zn -L 8 -n $lv4 $vg
lvcreate -an -Zn -L 16 -n $lv5 $vg
2014-07-11 14:15:46 +04:00
2015-08-25 16:10:53 +03:00
# check validation of cachemode arg works
2016-04-25 14:39:30 +03:00
invalid lvconvert --yes --type cache-pool --cachemode writethroughX --cachepool $vg /$lv1
2015-08-25 16:10:53 +03:00
# by default no cache settings are attached to converted cache-pool
lvconvert --yes --type cache-pool --chunksize 256 $vg /$lv1
2014-10-06 13:49:49 +04:00
check inactive $vg ${ lv1 } _cdata
2015-08-25 16:10:53 +03:00
check lv_field $vg /$lv1 cache_mode ""
check lv_field $vg /$lv1 cache_policy ""
check lv_field $vg /$lv1 cache_settings ""
check lv_field $vg /$lv1 chunk_size "256.00k"
# but allow to set them when specified explicitely on command line
lvconvert --yes --type cache-pool --cachemode writeback --cachepolicy mq \
--cachesettings sequential_threshold = 1234 --cachesettings random_threshold = 56 \
--cachepool $vg /$lv2
2014-10-06 13:49:49 +04:00
check inactive $vg ${ lv2 } _cdata
2015-08-25 16:10:53 +03:00
check lv_field $vg /$lv2 cache_mode "writeback"
check lv_field $vg /$lv2 cache_policy "mq"
check lv_field $vg /$lv2 cache_settings "random_threshold=56,sequential_threshold=1234"
2014-07-11 14:15:46 +04:00
2014-10-06 13:49:49 +04:00
# Check swap of cache pool metadata
lvconvert --yes --type cache-pool --poolmetadata $lv4 $vg /$lv3
UUID = $( get lv_field $vg /$lv5 uuid)
2017-04-03 16:57:32 +03:00
lvconvert --yes --cachepool $vg /$lv3 --poolmetadata $lv5
2014-10-06 13:49:49 +04:00
check lv_field $vg /${ lv3 } _cmeta uuid " $UUID "
2014-07-11 14:15:46 +04:00
2017-04-12 16:01:12 +03:00
# Check swap of cache pool metadata with --swapmetadata
# (should swap back to lv5)
lvconvert --yes --swapmetadata $vg /$lv3 --poolmetadata $lv5
check lv_field $vg /$lv5 uuid " $UUID "
2014-07-11 14:15:46 +04:00
#fail lvconvert --cachepool $vg/$lv1 --poolmetadata $vg/$lv2
#lvconvert --yes --type cache-pool --poolmetadata $vg/$lv2 $vg/$lv1
#lvconvert --yes --poolmetadata $vg/$lv2 --cachepool $vg/$lv1
lvremove -ff $vg
lvcreate -L 2 -n $lv1 $vg
2014-06-17 03:15:39 +04:00
lvcreate --type cache-pool -l 1 -n ${ lv1 } _cachepool $vg
2016-07-23 22:18:30 +03:00
lvconvert --cache --cachepool $vg /${ lv1 } _cachepool --cachemode writeback -Zy $vg /$lv1
2015-08-25 16:10:53 +03:00
check lv_field $vg /$lv1 cache_mode "writeback"
2014-06-17 03:15:39 +04:00
dmsetup table ${ vg } -$lv1 | grep cache # ensure it is loaded in kernel
2014-07-11 14:15:46 +04:00
#lvconvert --cachepool $vg/${lv1}_cachepool $vg/$lv1
#lvconvert --cachepool $vg/${lv1}_cachepool --poolmetadatasize 20 "$dev3"
2016-07-23 22:18:30 +03:00
fail lvconvert --type cache --cachepool $vg /${ lv1 } _cachepool -Zy $vg /$lv1
2014-10-06 13:49:49 +04:00
# Test --splitcache leaves both cache origin and cache pool
lvconvert --splitcache $vg /$lv1
check lv_exists $vg $lv1 ${ lv1 } _cachepool
lvremove -f $vg
2014-06-17 03:15:39 +04:00
2017-10-24 16:05:13 +03:00
lvcreate -L 2 -n $lv1 $vg
lvcreate --type cache-pool -l 1 -n ${ lv1 } _cachepool " $DM_DEV_DIR / $vg "
lvconvert --cache --cachepool " $DM_DEV_DIR / $vg / ${ lv1 } _cachepool " --cachemode writeback -Zy " $DM_DEV_DIR / $vg / $lv1 "
lvremove -f $vg
2014-10-06 10:11:06 +04:00
lvcreate -n corigin -l 10 $vg
lvcreate -n pool -l 10 $vg
lvs -a -o +devices
2014-10-06 13:49:49 +04:00
fail lvconvert --type cache --cachepool $vg /pool $vg /corigin
lvconvert --yes --cache --cachepool $vg /pool $vg /corigin
2018-08-17 23:45:52 +03:00
lvconvert --splitcache $vg /corigin
2014-10-06 10:11:06 +04:00
lvremove -ff $vg
2018-06-08 13:46:47 +03:00
# Check we also support conversion that uses 'cleaner' cache policy
lvcreate -n corigin -l 10 $vg
lvcreate -n pool -l 10 $vg
lvconvert --yes --cache --cachepool $vg /pool $vg /corigin --cachepolicy cleaner
lvremove -ff $vg
2014-10-07 10:55:09 +04:00
2014-10-06 13:49:49 +04:00
#######################
# Invalid conversions #
#######################
lvcreate -an -Zn -L 2 -n $lv1 $vg
lvcreate -an -Zn -L 8 -n $lv2 $vg
lvcreate -an -Zn -L 8 -n $lv3 $vg
lvcreate -an -Zn -L 8 -n $lv4 $vg
# Undefined cachepool
invalid lvconvert --type cache --poolmetadata $vg /$lv2 $vg /$lv1
# Cannot mix with thins
2017-04-03 16:57:32 +03:00
invalid lvconvert --type cache --poolmetadata $vg /$lv2 --thinpool $vg /$lv1
invalid lvconvert --type cache --thin --poolmetadata $vg /$lv2 $vg /$lv1
2014-10-06 13:49:49 +04:00
# Undefined cached volume
2017-04-03 16:57:32 +03:00
invalid lvconvert --type cache --cachepool $vg /$lv1
invalid lvconvert --cache --cachepool $vg /$lv1
2014-10-06 13:49:49 +04:00
2017-04-03 16:57:32 +03:00
# FIXME: temporarily we return error code 5
INVALID = not
2014-10-06 13:49:49 +04:00
# Single vg is required
2017-04-03 16:57:32 +03:00
$INVALID lvconvert --type cache --cachepool $vg /$lv1 --poolmetadata $vg1 /$lv2 $vg /$lv3
2017-10-24 16:05:13 +03:00
$INVALID lvconvert --type cache --cachepool " $DM_DEV_DIR / $vg / $lv1 " --poolmetadata " $DM_DEV_DIR / $vg1 / $lv2 " $vg /$lv3
2017-04-03 16:57:32 +03:00
$INVALID lvconvert --type cache --cachepool $vg /$lv1 --poolmetadata $lv2 $vg1 /$lv3
$INVALID lvconvert --type cache --cachepool $vg1 /$lv1 --poolmetadata $vg2 /$lv2 $vg /$lv3
2017-10-24 16:05:13 +03:00
$INVALID lvconvert --type cache --cachepool $vg1 /$lv1 --poolmetadata $vg2 /$lv2 " $DM_DEV_DIR / $vg / $lv3 "
2017-04-03 16:57:32 +03:00
$INVALID lvconvert --type cache-pool --poolmetadata $vg2 /$lv2 $vg1 /$lv1
2014-10-06 13:49:49 +04:00
2017-04-03 16:57:32 +03:00
$INVALID lvconvert --cachepool $vg1 /$lv1 --poolmetadata $vg2 /$lv2
2014-10-06 13:49:49 +04:00
# Invalid syntax, vg is unknown
2017-04-03 16:57:32 +03:00
$INVALID lvconvert --yes --cachepool $lv3 --poolmetadata $lv4
2014-10-06 13:49:49 +04:00
# Invalid chunk size is <32KiB >1GiB
2017-04-03 16:57:32 +03:00
$INVALID lvconvert --type cache-pool --chunksize 16 --poolmetadata $lv2 $vg /$lv1
$INVALID lvconvert --type cache-pool --chunksize 2G --poolmetadata $lv2 $vg /$lv1
2014-10-06 13:49:49 +04:00
# Invalid chunk size is bigger then data size, needs to open VG
2017-04-03 16:57:32 +03:00
fail lvconvert --yes --type cache-pool --chunksize 16M --poolmetadata $lv2 $vg /$lv1
2014-10-06 13:49:49 +04:00
lvremove -f $vg
2015-11-19 16:31:58 +03:00
########################
# Repair of cache pool #
########################
lvcreate --type cache-pool -an -v -L 2 -n cpool $vg
lvcreate -H -L 4 -n corigin --cachepool $vg /cpool
# unsupported yet
2017-04-03 16:57:32 +03:00
fail lvconvert --repair $vg /cpool 2>& 1 | tee out
2016-07-11 22:58:14 +03:00
#grep "Cannot convert internal LV" out
2015-11-19 16:31:58 +03:00
lvremove -f $vg
2014-10-06 13:49:49 +04:00
##########################
# Prohibited conversions #
##########################
lvcreate --type cache-pool -L10 $vg /$lv1
lvcreate --cache -L20 $vg /$lv1
lvcreate -L10 -n $lv2 $vg
2017-04-03 16:57:32 +03:00
fail lvconvert --yes --type cache $vg /$lv2 --cachepool $vg /$lv1
fail lvconvert --yes --type cache $vg /$lv1 --cachepool $vg /$lv2
fail lvconvert --yes --type cache-pool $vg /$lv1
fail lvconvert --yes --type mirror -m1 $vg /$lv1
2014-10-07 12:12:49 +04:00
not aux have_raid 1 0 0 || fail lvconvert --yes --type raid1 -m1 $vg /$lv1
2017-04-03 16:57:32 +03:00
fail lvconvert --yes --type snapshot $vg /$lv1 $vg /$lv2
fail lvconvert --yes --type snapshot $vg /$lv2 $vg /$lv1
2014-10-07 12:12:49 +04:00
not aux have_thin 1 0 0 || fail lvconvert --yes -T --thinpool $vg /$lv2 $vg /$lv1
2014-10-06 13:49:49 +04:00
lvremove -f $vg
2014-06-17 03:15:39 +04:00
vgremove -f $vg