2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2017-11-06 00:59:43 +03:00
# Copyright (C) 2010-2017 Red Hat, Inc. All rights reserved.
2010-01-20 01:55:00 +03: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
2010-01-20 01:55:00 +03:00
2018-05-24 17:49:48 +03:00
2016-02-23 01:13:42 +03:00
2014-06-06 19:40:04 +04:00
. lib/inittest
2010-01-20 01:55:00 +03:00
2015-09-14 12:02:48 +03:00
# test if snapshot-merge target is available
2015-10-01 17:05:51 +03:00
aux target_at_least dm-snapshot-merge 1 0 0 || skip
2015-09-14 12:02:48 +03:00
2012-03-16 17:00:05 +04:00
which mkfs.ext3 || skip
lvdev_( ) {
2010-04-07 18:46:26 +04:00
echo " $DM_DEV_DIR / $1 / $2 "
2010-01-20 01:55:00 +03:00
}
snap_lv_name_( ) {
2017-07-10 11:40:09 +03:00
echo " ${ 1 } _snap "
2010-01-20 01:55:00 +03:00
}
2012-03-16 17:00:05 +04:00
setup_merge_( ) {
2010-01-20 01:55:00 +03:00
local VG_NAME = $1
local LV_NAME = $2
2012-03-16 17:00:05 +04:00
local NUM_EXTRA_SNAPS = ${ 3 :- 0 }
2014-06-30 22:04:24 +04:00
local BASE_SNAP_LV_NAME
BASE_SNAP_LV_NAME = $( snap_lv_name_ $LV_NAME )
2010-01-20 01:55:00 +03:00
2013-06-15 13:21:03 +04:00
lvcreate -aey -n $LV_NAME -l 50%FREE $VG_NAME
2010-01-20 01:55:00 +03:00
lvcreate -s -n $BASE_SNAP_LV_NAME -l 20%FREE ${ VG_NAME } /${ LV_NAME }
2012-03-16 17:00:05 +04:00
mkfs.ext3 " $( lvdev_ $VG_NAME $LV_NAME ) "
2010-01-20 01:55:00 +03:00
if [ $NUM_EXTRA_SNAPS -gt 0 ] ; then
2013-06-15 13:21:03 +04:00
for i in $( seq 1 $NUM_EXTRA_SNAPS ) ; do
2014-06-17 15:35:40 +04:00
lvcreate -s -n ${ BASE_SNAP_LV_NAME } _${ i } -l 20%ORIGIN ${ VG_NAME } /${ LV_NAME }
2010-01-20 01:55:00 +03:00
done
fi
}
aux prepare_vg 1 100
2012-03-16 17:00:05 +04:00
mkdir test_mnt
2010-01-20 01:55:00 +03:00
2010-04-23 23:27:10 +04:00
# test full merge of a single LV
2012-03-16 17:00:05 +04:00
setup_merge_ $vg $lv1
2017-04-03 16:57:32 +03:00
# make sure lvconvert --merge requires explicit LV listing
not lvconvert --merge
2018-01-15 15:29:14 +03:00
2021-02-17 13:38:28 +03:00
# check read-only origin is protected from being merge
lvchange -pr $vg /$lv1
not lvconvert --merge " $vg / $( snap_lv_name_ " $lv1 " ) " | & tee out
grep "read-only origin" out
lvchange -prw $vg /$lv1
2018-01-15 15:29:14 +03:00
# check exclusive lock is preserved after merge
check lv_field " $vg / $lv1 " lv_active_exclusively "active exclusively"
2017-07-10 11:40:09 +03:00
lvconvert --merge " $vg / $( snap_lv_name_ " $lv1 " ) "
2018-01-15 15:29:14 +03:00
check lv_field " $vg / $lv1 " lv_active_exclusively "active exclusively"
2010-01-20 01:55:00 +03:00
lvremove -f $vg /$lv1
2017-04-12 16:01:12 +03:00
setup_merge_ $vg $lv1
2017-07-10 11:40:09 +03:00
lvconvert --mergesnapshot " $vg / $( snap_lv_name_ " $lv1 " ) "
2017-04-12 16:01:12 +03:00
lvremove -f $vg /$lv1
2010-01-20 01:55:00 +03:00
2010-04-23 23:27:10 +04:00
# test that an actively merging snapshot may not be removed
2012-03-16 17:00:05 +04:00
setup_merge_ $vg $lv1
2017-07-10 11:40:09 +03:00
lvconvert -i+100 --merge --background " $vg / $( snap_lv_name_ " $lv1 " ) "
not lvremove -f " $vg / $( snap_lv_name_ " $lv1 " ) "
2010-04-23 23:27:10 +04:00
lvremove -f $vg /$lv1
2010-04-20 02:44:42 +04:00
# "onactivate merge" test
2012-03-16 17:00:05 +04:00
setup_merge_ $vg $lv1
mount " $( lvdev_ $vg $lv1 ) " test_mnt
2017-07-10 11:40:09 +03:00
lvconvert --merge " $vg / $( snap_lv_name_ " $lv1 " ) "
2010-04-20 02:44:42 +04:00
# -- refresh LV while FS is still mounted (merge must not start),
# verify 'snapshot-origin' target is still being used
2010-01-20 01:55:00 +03:00
lvchange --refresh $vg /$lv1
umount test_mnt
2012-03-28 15:10:08 +04:00
dm_table $vg -$lv1 | grep " snapshot-origin "
2011-03-30 17:39:24 +04:00
2010-04-20 02:44:42 +04:00
# -- refresh LV to start merge (now that FS is unmounted),
# an active merge uses the 'snapshot-merge' target
lvchange --refresh $vg /$lv1
2012-02-15 17:51:17 +04:00
# check whether it's still merging - or maybe got already merged (slow test)
2012-03-28 15:10:08 +04:00
dm_table $vg -$lv1 | grep " snapshot-merge " || dm_table $vg -$lv1 | grep " linear "
2010-04-20 02:44:42 +04:00
# -- don't care if merge is still active; lvremove at this point
# may test stopping an active merge
2010-01-20 01:55:00 +03:00
lvremove -f $vg /$lv1
2010-04-23 06:57:39 +04:00
# "onactivate merge" test
# -- deactivate/remove after disallowed merge attempt, tests
# to make sure preload of origin's metadata is _not_ performed
2012-03-16 17:00:05 +04:00
setup_merge_ $vg $lv1
mount " $( lvdev_ $vg $lv1 ) " test_mnt
2017-07-10 11:40:09 +03:00
lvconvert --merge " $vg / $( snap_lv_name_ " $lv1 " ) "
2010-04-23 06:57:39 +04:00
# -- refresh LV while FS is still mounted (merge must not start),
# verify 'snapshot-origin' target is still being used
lvchange --refresh $vg /$lv1
umount test_mnt
2012-03-28 15:10:08 +04:00
dm_table $vg -$lv1 | grep " snapshot-origin " >/dev/null
2010-04-23 06:57:39 +04:00
lvremove -f $vg /$lv1
2010-01-20 01:55:00 +03:00
# test multiple snapshot merge; tests copy out that is driven by merge
2012-03-16 17:00:05 +04:00
setup_merge_ $vg $lv1 1
2017-07-10 11:40:09 +03:00
lvconvert --merge " $vg / $( snap_lv_name_ " $lv1 " ) "
2010-01-20 01:55:00 +03:00
lvremove -f $vg /$lv1
2017-11-06 00:59:43 +03:00
# test merging cannot start on already merging origin
setup_merge_ $vg $lv1 3
lvchange -an $vg
lvs -a $vg
lvconvert --merge " $vg / $( snap_lv_name_ " $lv1 " ) "
not lvconvert --merge " $vg / $( snap_lv_name_ " $lv1 " ) _1 " 2>& 1 | tee err
grep "Cannot merge snapshot" err
lvremove -f $vg /$lv1
2010-04-23 23:27:10 +04:00
2010-02-06 01:44:37 +03:00
# test merging multiple snapshots that share the same tag
2012-03-16 17:00:05 +04:00
setup_merge_ $vg $lv1
setup_merge_ $vg $lv2
2017-07-10 11:40:09 +03:00
lvchange --addtag this_is_a_test " $vg / $( snap_lv_name_ " $lv1 " ) "
lvchange --addtag this_is_a_test " $vg / $( snap_lv_name_ " $lv2 " ) "
2017-04-03 16:57:32 +03:00
lvconvert --merge @this_is_a_test
2013-06-15 13:21:03 +04:00
lvs $vg | tee out
2017-07-10 11:40:09 +03:00
not grep " $( snap_lv_name_ " $lv1 " ) " out
not grep " $( snap_lv_name_ " $lv2 " ) " out
2012-03-16 17:00:05 +04:00
lvremove -f $vg /$lv1 $vg /$lv2
2010-01-20 01:55:00 +03:00
# FIXME following tests would need to poll merge progress, via periodic lvs?
# Background processes don't lend themselves to lvm testsuite...
# test: onactivate merge of a single lv
# test: do onactivate, deactivate the origin LV, reactivate the LV, merge should resume
# test: multiple onactivate merge
2012-03-16 17:00:05 +04:00
vgremove -f $vg