2010-01-20 01:55:00 +03:00
#!/bin/sh
# Copyright (C) 2010 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
set -xv
which mkfs.ext3 || exit 200
2011-01-05 03:16:18 +03:00
. lib/test
2010-01-20 01:55:00 +03:00
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_( ) {
echo ${ 1 } _snap
}
setup_merge( ) {
local VG_NAME = $1
local LV_NAME = $2
local NUM_EXTRA_SNAPS = " $3 "
test -z " $NUM_EXTRA_SNAPS " && NUM_EXTRA_SNAPS = 0
local BASE_SNAP_LV_NAME = $( snap_lv_name_ $LV_NAME )
lvcreate -n $LV_NAME -l 50%FREE $VG_NAME
lvcreate -s -n $BASE_SNAP_LV_NAME -l 20%FREE ${ VG_NAME } /${ LV_NAME }
mkfs.ext3 $( lvdev_ $VG_NAME $LV_NAME )
if [ $NUM_EXTRA_SNAPS -gt 0 ] ; then
for i in ` seq 1 $NUM_EXTRA_SNAPS ` ; do
lvcreate -s -n ${ BASE_SNAP_LV_NAME } _${ i } -l 20%FREE ${ VG_NAME } /${ LV_NAME }
done
fi
}
aux prepare_vg 1 100
2010-04-23 23:27:10 +04:00
# test full merge of a single LV
2010-01-20 01:55:00 +03:00
setup_merge $vg $lv1
# now that snapshot LV is created: test if snapshot-merge target is available
2011-03-30 17:39:24 +04:00
$( dmsetup targets | grep snapshot-merge >/dev/null) || exit 200
2010-01-20 01:55:00 +03:00
lvs -a
2010-08-04 00:22:31 +04:00
# make sure lvconvert --merge requires explicit LV listing
not lvconvert --merge 2>err
2010-01-20 01:55:00 +03:00
lvconvert --merge $vg /$( snap_lv_name_ $lv1 )
lvremove -f $vg /$lv1
2010-04-23 23:27:10 +04:00
# test that an actively merging snapshot may not be removed
setup_merge $vg $lv1
lvconvert -i+100 --merge --background $vg /$( snap_lv_name_ $lv1 )
not lvremove -f $vg /$( snap_lv_name_ $lv1 )
lvremove -f $vg /$lv1
2010-04-20 02:44:42 +04:00
# "onactivate merge" test
2010-01-20 01:55:00 +03:00
setup_merge $vg $lv1
lvs -a
mkdir test_mnt
mount $( lvdev_ $vg $lv1 ) test_mnt
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
rm -r test_mnt
2011-03-30 17:39:24 +04:00
dmsetup table ${ vg } -${ lv1 } | grep " snapshot-origin "
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)
dmsetup table ${ vg } -${ lv1 } | grep " snapshot-merge " || dmsetup 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
setup_merge $vg $lv1
lvs -a
mkdir test_mnt
mount $( lvdev_ $vg $lv1 ) test_mnt
lvconvert --merge $vg /$( snap_lv_name_ $lv1 )
# -- 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
rm -r test_mnt
2011-03-30 17:39:24 +04:00
dmsetup 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
setup_merge $vg $lv1 1
lvs -a
lvconvert --merge $vg /$( snap_lv_name_ $lv1 )
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
setup_merge $vg $lv1
setup_merge $vg $lv2
lvs -a
lvchange --addtag this_is_a_test $vg /$( snap_lv_name_ $lv1 )
lvchange --addtag this_is_a_test $vg /$( snap_lv_name_ $lv2 )
lvconvert --merge @this_is_a_test
lvs | not grep $( snap_lv_name_ $lv1 )
lvs | not grep $( snap_lv_name_ $lv2 )
lvremove -f $vg /$lv1
lvremove -f $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
vgremove -f " $vg "