2017-07-02 21:38:32 +02:00
#!/usr/bin/env bash
2013-02-05 14:24:05 +01:00
2014-10-06 11:52:40 +02:00
# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
2013-02-05 14:24:05 +01: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 11:49:46 +01:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2013-02-05 14:24:05 +01:00
# Test creation of thin snapshots using external origin
2018-05-24 09:49:48 -05:00
2015-10-27 15:10:06 +01:00
SKIP_WITH_LVMPOLLD = 1
2015-05-17 17:22:18 +02:00
export LVM_TEST_THIN_REPAIR_CMD = ${ LVM_TEST_THIN_REPAIR_CMD -/bin/false }
2014-06-06 17:40:04 +02:00
. lib/inittest
2013-02-05 14:24:05 +01:00
which mkfs.ext2 || skip
which fsck || skip
#
# Main
#
aux have_thin 1 3 0 || skip
aux prepare_pvs 2 64
2017-07-06 19:41:25 +02:00
get_devs
2013-02-05 14:24:05 +01:00
2018-05-24 09:49:48 -05:00
vgcreate $SHARED -s 64K " $vg " " ${ DEVICES [@] } "
2013-02-05 14:24:05 +01:00
2015-06-26 22:16:01 +02:00
# Newer thin-pool target (>= 1.13) supports unaligned external origin
# But this test is written to test and expect older behavior
aux lvmconf 'global/thin_disabled_features = [ "external_origin_extend" ]'
2014-01-29 14:23:50 +01:00
# Test validation for external origin being multiple of thin pool chunk size
lvcreate -L10M -T $vg /pool192 -c 192k
lvcreate -an -pr -Zn -l1 -n $lv1 $vg
not lvcreate -s $vg /$lv1 --thinpool $vg /pool192
lvcreate -an -pr -Zn -l5 -n $lv2 $vg
not lvcreate -s $vg /$lv2 --thinpool $vg /pool192
lvremove -f $vg
# Prepare pool and external origin with filesystem
2013-02-05 14:24:05 +01:00
lvcreate -L10M -V10M -T $vg /pool --name $lv1
2014-02-22 23:08:55 +01:00
mkfs.ext2 " $DM_DEV_DIR / $vg / $lv1 "
2013-02-05 14:24:05 +01:00
lvcreate -L4M -n $lv2 $vg
2014-02-22 23:08:55 +01:00
mkfs.ext2 " $DM_DEV_DIR / $vg / $lv2 "
2013-02-05 14:24:05 +01:00
2013-07-15 14:46:52 +02:00
# Fail to create external origin snapshot of rw LV
not lvcreate -s $vg /$lv2 --thinpool $vg /pool
2013-02-05 14:24:05 +01:00
lvchange -p r $vg /$lv2
# Fail to create snapshot of active r LV
# FIXME: kernel update needed
2013-07-15 14:46:52 +02:00
not lvcreate -s $vg /$lv2 --thinpool $vg /pool
2013-02-05 14:24:05 +01:00
# Deactivate LV we want to use as external origin
# once kernel will ensure read-only this condition may go away
lvchange -an $vg /$lv2
2013-07-15 14:46:52 +02:00
lvcreate -s $vg /$lv2 --thinpool $vg /pool
2013-02-05 14:24:05 +01:00
# Fail with --thin and --snapshot
2013-07-15 14:46:52 +02:00
not lvcreate -s $vg /$lv5 --name $vg /$lv7 -T $vg /newpool
2013-02-05 14:24:05 +01:00
2014-10-06 11:52:40 +02:00
# Cannot specify size and thin pool.
# TODO: maybe with --poolsize
invalid lvcreate -s $vg /$lv2 -L10 --thinpool $vg /pool
invalid lvcreate -s -K $vg /$lv2 --name $vg /$lv3 -L20 --chunksize 128 --thinpool $vg /newpool
2013-07-15 14:46:52 +02:00
not lvcreate -s $vg /$lv2 --chunksize 64 --thinpool $vg /pool
not lvcreate -s $vg /$lv2 --zero y --thinpool $vg /pool
not lvcreate -s $vg /$lv2 --poolmetadata $vg /$lv1 --thinpool $vg /pool
2013-02-05 14:24:05 +01:00
# Fail with nonexistent pool
2013-07-15 14:46:52 +02:00
not lvcreate -s $vg /$lv2 --thinpool $vg /newpool
2013-02-05 14:24:05 +01:00
# Create pool and snap
2014-10-06 11:52:40 +02:00
lvcreate -T --name $vg /$lv3 -V10 -L20 --chunksize 128 --thinpool $vg /newpool
2013-07-12 13:54:53 +02:00
lvcreate -s -K $vg /$lv3 --name $vg /$lv4
lvcreate -s -K $vg /$lv2 --name $vg /$lv5 --thinpool $vg /newpool
2013-02-05 14:24:05 +01:00
# Make normal thin snapshot
2013-07-12 13:54:53 +02:00
lvcreate -s -K $vg /$lv5 --name $vg /$lv6
2013-02-05 14:24:05 +01:00
# We do not need to specify thinpool when doing thin snap, but it should work
2013-07-12 13:54:53 +02:00
lvcreate -s -K $vg /$lv5 --name $vg /$lv7 --thinpool $vg /newpool
2013-02-05 14:24:05 +01:00
check inactive $vg $lv2
lvchange -ay $vg /$lv2
2013-07-12 13:54:53 +02:00
lvcreate -s -K $vg /$lv2 --name $vg /$lv8 --thinpool $vg /newpool
2013-02-05 14:24:05 +01:00
lvs -o+chunksize $vg
check active $vg $lv3
check active $vg $lv4
check active $vg $lv5
check active $vg $lv6
check active $vg $lv7
2014-02-22 23:08:55 +01:00
fsck -n " $DM_DEV_DIR / $vg / $lv1 "
fsck -n " $DM_DEV_DIR / $vg / $lv7 "
2013-02-05 14:24:05 +01:00
vgremove -ff $vg