2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2013-12-04 17:17:54 +04:00
# Copyright (C) 2013 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,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2013-12-04 17:17:54 +04:00
# test merge of thin snapshot
2018-05-24 17:49:48 +03:00
2016-02-23 01:13:42 +03:00
2015-05-17 18:22:18 +03:00
export LVM_TEST_THIN_REPAIR_CMD = ${ LVM_TEST_THIN_REPAIR_CMD -/bin/false }
2014-06-06 19:40:04 +04:00
. lib/inittest
2013-12-04 17:17:54 +04:00
2014-02-18 00:48:27 +04:00
MKFS = mkfs.ext2
which $MKFS || skip
2013-12-04 17:17:54 +04:00
which fsck || skip
2018-05-13 00:22:20 +03:00
MKFS = " $MKFS -b4096 "
2013-12-04 17:17:54 +04:00
#
# Main
#
aux have_thin 1 0 0 || skip
aux prepare_vg 2
2018-01-15 15:29:14 +03:00
lvcreate -T -L8M $vg /pool -V10M -n $lv1
lvcreate -s -K -n snap $vg /$lv1
# check exclusive lock is preserved after merge
check lv_field " $vg / $lv1 " lv_active_exclusively "active exclusively"
lvconvert --merge $vg /snap
check lv_field " $vg / $lv1 " lv_active_exclusively "active exclusively"
lvremove -ff $vg
2013-12-04 17:17:54 +04:00
lvcreate -T -L8M $vg /pool -V10M -n $lv1
lvchange --addtag tagL $vg /$lv1
mkdir mnt
2014-02-23 02:08:55 +04:00
$MKFS " $DM_DEV_DIR / $vg / $lv1 "
mount " $DM_DEV_DIR / $vg / $lv1 " mnt
2013-12-04 17:17:54 +04:00
touch mnt/test
lvcreate -K -s -n snap --addtag tagS $vg /$lv1
mkdir mntsnap
2014-02-23 02:08:55 +04:00
$MKFS " $DM_DEV_DIR / $vg /snap "
mount " $DM_DEV_DIR / $vg /snap " mntsnap
2013-12-04 17:17:54 +04:00
touch mntsnap/test_snap
lvs -o+tags,thin_id $vg
2017-11-06 00:59:43 +03:00
lvcreate -s -n snap1 $vg /$lv1
2017-10-30 13:00:31 +03:00
lvconvert --merge $vg /snap & >out
grep " Merging of thin snapshot $vg /snap will occur on next activation of $vg / ${ lv1 } . " out
2013-12-04 17:17:54 +04:00
2017-11-06 00:59:43 +03:00
# Can't merge another snapshot while "snap" is still being 'merged'.
not lvconvert --merge $vg /snap1 & >out
grep "Cannot merge snapshot" out
2021-02-14 01:10:15 +03:00
# Check lvdisplay is not crashing while merge needs to wait
lvdisplay -a $vg
2013-12-04 17:17:54 +04:00
umount mnt
# Merge cannot happen
lvchange --refresh $vg /$lv1
check lv_field $vg /$lv1 thin_id "1"
# Fails since it cannot deactivate both
not lvchange -an $vg /$lv1
# But test $lv1 is not active
check inactive $vg $lv1
# Also still cannot reactivate $lv1
not lvchange -ay $vg /$lv1
umount mntsnap
lvdisplay -a $vg | tee out
grep "merged with" out
grep "merging to" out
# Check there is no support for manipulation with hidden 'snap'
not lvchange --refresh $vg /snap
not lvchange -an $vg /snap
not lvremove $vg /snap
# Finally deactivate 'snap' again via $lv1
lvchange -an $vg /$lv1
# Still must not be activable
not lvchange -K -ay $vg /snap
lvs -a -o +tags,thin_id $vg
# Test if merge happens
lvchange -ay $vg /$lv1
check lv_exists $vg $lv1
check lv_field $vg /$lv1 thin_id "2"
check lv_field $vg /$lv1 tags "tagL"
2014-02-18 00:48:27 +04:00
check lv_not_exists $vg snap
2013-12-04 17:17:54 +04:00
2014-02-23 02:08:55 +04:00
fsck -n " $DM_DEV_DIR / $vg / $lv1 "
mount " $DM_DEV_DIR / $vg / $lv1 " mnt
2013-12-04 17:17:54 +04:00
test -e mnt/test_snap
umount mnt
# test if thin snapshot has also 'old-snapshot'
lvcreate -s -n snap $vg /$lv1
# Also add old snapshot to thin origin
lvcreate -s -L10 -n oldsnapof_${ lv1 } $vg /$lv1
not lvconvert --merge $vg /snap
2014-02-23 02:08:55 +04:00
$MKFS " $DM_DEV_DIR / $vg /oldsnapof_ ${ lv1 } "
2017-04-03 16:57:32 +03:00
lvconvert --merge $vg /oldsnapof_${ lv1 }
2014-02-23 02:08:55 +04:00
fsck -n " $DM_DEV_DIR / $vg / $lv1 "
2014-02-18 00:48:27 +04:00
check lv_not_exists $vg oldsnapof_${ lv1 }
2013-12-04 17:17:54 +04:00
# Add old snapshot to thin snapshot
lvcreate -s -L10 -n oldsnapof_snap $vg /snap
2017-04-03 16:57:32 +03:00
lvconvert --merge $vg /snap
2013-12-04 17:17:54 +04:00
lvremove -f $vg /oldsnapof_snap
2017-11-06 00:59:43 +03:00
check lv_field $vg /$lv1 thin_id "4"
2017-04-12 16:01:12 +03:00
# Check --mergethin
lvcreate -s -n snap $vg /$lv1
2017-11-06 00:59:43 +03:00
check lv_field $vg /snap thin_id "5"
2017-10-30 13:00:31 +03:00
lvconvert --mergethin $vg /snap & >out
grep " Volume $vg /snap replaced origin $vg / ${ lv1 } . " out
2017-11-06 00:59:43 +03:00
check lv_field $vg /$lv1 thin_id "5"
2013-12-04 17:17:54 +04:00
vgremove -ff $vg