2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2016-09-16 22:55:04 +03:00
# Copyright (C) 2014-2016 Red Hat, Inc. All rights reserved.
2014-01-21 13:04:23 +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-01-21 13:04:23 +04:00
# Test autoextension of thin metadata volume
2015-05-17 18:22:18 +03:00
2016-02-23 01:13:42 +03:00
SKIP_WITH_LVMLOCKD = 1
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
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
2014-01-21 13:04:23 +04:00
meta_percent_( ) {
get lv_field $vg /pool metadata_percent | cut -d. -f1
}
wait_for_change_( ) {
# dmeventd only checks every 10 seconds :(
2015-10-29 17:11:16 +03:00
for i in $( seq 1 12) ; do
test " $( meta_percent_) " -lt " $1 " && return
2014-01-21 13:04:23 +04:00
sleep 1
done
return 1 # timeout
}
#
# Temporary solution to create some occupied thin metadata
# This heavily depends on thin metadata output format to stay as is.
# Currently it expects 2MB thin metadata and 200MB data volume size
# Argument specifies how many devices should be created.
fake_metadata_( ) {
2015-10-13 15:33:24 +03:00
echo '<superblock uuid="" time="0" transaction="' $2 '" data_block_size="128" nr_data_blocks="3200">'
echo ' <device dev_id="1" mapped_blocks="0" transaction="0" creation_time="0" snap_time="0">'
echo ' </device>'
echo ' <device dev_id="2" mapped_blocks="0" transaction="0" creation_time="0" snap_time="0">'
echo ' </device>'
for i in $( seq 10 $1 )
2014-01-21 13:04:23 +04:00
do
2015-10-13 15:33:24 +03:00
echo ' <device dev_id="' $i '" mapped_blocks="30" transaction="0" creation_time="0" snap_time="0">'
echo ' <range_mapping origin_begin="0" data_begin="0" length="29" time="0"/>'
2014-01-21 13:04:23 +04:00
echo ' </device>'
2015-10-13 15:33:24 +03:00
set +x
2014-01-21 13:04:23 +04:00
done
echo "</superblock>"
2015-10-13 15:33:24 +03:00
set -x
2014-01-21 13:04:23 +04:00
}
2014-05-27 01:28:03 +04:00
test -n " $LVM_TEST_THIN_RESTORE_CMD " || LVM_TEST_THIN_RESTORE_CMD = $( which thin_restore) || skip
2014-06-16 19:46:54 +04:00
" $LVM_TEST_THIN_RESTORE_CMD " -V || skip
2014-01-21 13:04:23 +04:00
aux have_thin 1 10 0 || skip
aux prepare_dmeventd
aux prepare_pvs 3 256
2017-07-06 20:41:25 +03:00
get_devs
2014-01-21 13:04:23 +04:00
2017-07-06 20:41:25 +03:00
vgcreate -s 1M " $vg " " ${ DEVICES [@] } "
2014-01-21 13:04:23 +04:00
2016-09-16 22:55:04 +03:00
# Testing dmeventd does NOT autoresize when default threshold 100% is left
lvcreate -L200M -V50M -n thin -T $vg /pool
lvcreate -V2M -n thin2 $vg /pool
lvcreate -L2M -n $lv1 $vg
lvcreate -L32M -n $lv2 $vg
lvcreate -L32M -n $lv3 $vg
lvchange -an $vg /thin $vg /thin2 $vg /pool
# Filling 2M metadata volume
# (Test for less then 25% free space in metadata)
fake_metadata_ 400 2 >data
" $LVM_TEST_THIN_RESTORE_CMD " -i data -o " $DM_DEV_DIR /mapper/ $vg - $lv1 "
# Swap volume with restored fake metadata
2017-04-03 16:57:32 +03:00
lvconvert -y --chunksize 64k --thinpool $vg /pool --poolmetadata $vg /$lv1
2016-09-16 22:55:04 +03:00
# Not alllowed when thin-pool metadata free space is <75% for 2M meta
fail lvcreate -V20 $vg /pool
lvchange -an $vg /pool
# Consume more then (100% - 4MiB) out of 32MiB metadata volume (>87.5%)
# (Test for less then 4MiB free space in metadata, which is less then 25%)
fake_metadata_ 7400 2 >data
" $LVM_TEST_THIN_RESTORE_CMD " -i data -o " $DM_DEV_DIR /mapper/ $vg - $lv2 "
# Swap volume with restored fake metadata
2017-04-03 16:57:32 +03:00
lvconvert -y --chunksize 64k --thinpool $vg /pool --poolmetadata $vg /$lv2
2016-09-16 22:55:04 +03:00
lvchange -ay $vg /pool
# Check generated metadata consume more then 88%
test " $( meta_percent_) " -gt "88"
lvchange -an $vg /pool
# Creation of thin LV is prohibited when metadata are above this value
fail lvcreate -V20 $vg /pool 2>& 1 | tee out
grep "free space" out
lvs -a $vg
# Check that even with 99% threshold policy - metadata will go below 88%
lvextend --use-policies --config " \
activation/thin_pool_autoextend_percent= 1 \
activation/thin_pool_autoextend_threshold= 99" $vg /pool
test " $( meta_percent_) " -lt "88"
# After such operatoin creation of thin LV has to pass
lvcreate -V20 $vg /pool
# Let's revalidate pool metadata (thin_check upon deactivation/activation)
lvchange -an $vg
lvchange -ay $vg /pool
lvremove -f $vg
#########################################################
# Test automatic resize with help of dmeventd DOES work #
#########################################################
aux lvmconf "activation/thin_pool_autoextend_percent = 10" \
"activation/thin_pool_autoextend_threshold = 70"
2014-01-21 13:04:23 +04:00
# Testing dmeventd autoresize
2015-07-13 12:08:49 +03:00
lvcreate -L200M -V500M -n thin -T $vg /pool 2>& 1 | tee out
not grep "WARNING: Sum" out
2015-08-17 18:07:09 +03:00
lvcreate -V2M -n thin2 $vg /pool
2014-01-21 13:04:23 +04:00
lvcreate -L2M -n $lv1 $vg
2015-08-17 18:07:09 +03:00
lvchange -an $vg /thin $vg /thin2 $vg /pool
2014-01-21 13:04:23 +04:00
2014-02-24 12:46:09 +04:00
# Prepare some fake metadata with unmatching id
2015-09-04 00:05:33 +03:00
# Transaction_id is lower by 1 and there are no messages -> ERROR
2014-02-24 12:46:09 +04:00
fake_metadata_ 10 0 >data
2014-06-16 19:46:54 +04:00
" $LVM_TEST_THIN_RESTORE_CMD " -i data -o " $DM_DEV_DIR /mapper/ $vg - $lv1 "
2017-04-03 16:57:32 +03:00
lvconvert -y --thinpool $vg /pool --poolmetadata $vg /$lv1
2014-02-24 12:46:09 +04:00
not vgchange -ay $vg 2>& 1 | tee out
grep expected out
2014-01-21 13:04:23 +04:00
2014-02-24 12:46:09 +04:00
check inactive $vg pool_tmeta
# Transaction_id is higher by 1
2015-08-17 18:07:09 +03:00
fake_metadata_ 10 3 >data
2014-06-16 19:46:54 +04:00
" $LVM_TEST_THIN_RESTORE_CMD " -i data -o " $DM_DEV_DIR /mapper/ $vg - $lv1 "
2017-04-03 16:57:32 +03:00
lvconvert -y --thinpool $vg /pool --poolmetadata $vg /$lv1
2014-02-24 12:46:09 +04:00
not vgchange -ay $vg 2>& 1 | tee out
grep expected out
check inactive $vg pool_tmeta
# Prepare some fake metadata prefilled to ~81% (>70%)
2015-08-17 18:07:09 +03:00
fake_metadata_ 400 2 >data
2014-06-16 19:46:54 +04:00
" $LVM_TEST_THIN_RESTORE_CMD " -i data -o " $DM_DEV_DIR /mapper/ $vg - $lv1 "
2014-02-24 12:46:09 +04:00
2014-01-21 13:04:23 +04:00
# Swap volume with restored fake metadata
2017-04-03 16:57:32 +03:00
lvconvert -y --chunksize 64k --thinpool $vg /pool --poolmetadata $vg /$lv1
2014-01-21 13:04:23 +04:00
vgchange -ay $vg
2015-10-29 17:11:16 +03:00
# Check dmeventd resizes metadata via timeout (nothing is written to pool)
2014-01-21 13:04:23 +04:00
pre = $( meta_percent_)
wait_for_change_ $pre
2014-02-24 12:46:09 +04:00
2015-10-13 15:33:24 +03:00
lvchange -an $vg
#
fake_metadata_ 350 2 >data
lvchange -ay $vg /$lv1
" $LVM_TEST_THIN_RESTORE_CMD " -i data -o " $DM_DEV_DIR /mapper/ $vg - $lv1 "
2017-04-03 16:57:32 +03:00
lvconvert -y --chunksize 64k --thinpool $vg /pool --poolmetadata $vg /$lv1
2015-10-13 15:33:24 +03:00
lvchange -ay $vg /pool $vg /$lv1
lvs -a $vg
lvcreate -s -Ky -n $lv2 $vg /thin
2015-10-29 17:11:16 +03:00
pre = $( meta_percent_)
2015-10-13 15:33:24 +03:00
2015-10-29 17:11:16 +03:00
# go over thin metadata threshold
echo 2 >" $DM_DEV_DIR /mapper/ $vg - $lv2 "
2015-10-13 15:33:24 +03:00
wait_for_change_ $pre
lvs -a $vg
2014-02-24 12:46:09 +04:00
vgremove -f $vg