2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2016-02-18 18:44:42 +03:00
# Copyright (C) 2016 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# test presence of various thin-pool/thin flags
2016-02-23 01:13:42 +03:00
SKIP_WITH_LVMLOCKD = 1
2016-02-18 18:44:42 +03:00
SKIP_WITH_LVMPOLLD = 1
export LVM_TEST_THIN_REPAIR_CMD = ${ LVM_TEST_THIN_REPAIR_CMD -/bin/false }
. lib/inittest
#
# Main
#
aux have_thin 1 3 0 || skip
2016-02-22 16:52:01 +03:00
aux thin_pool_error_works_32 || skip
2016-02-18 18:44:42 +03:00
aux prepare_vg 2 256
###############################################
# Testing failing thin-pool metadata device #
###############################################
lvcreate -T -L1M --errorwhenfull y $vg /pool
lvcreate -V2 -n $lv2 $vg /pool
aux error_dev " $dev2 " 2054:2
2016-05-27 18:24:18 +03:00
# Check our 'lvs' is not flushing pool - should be still OK
check lv_attr_bit health $vg /pool "-"
# Enforce flush on thin pool device to notice error device.
dmsetup status $vg -pool-tpool
2016-02-18 18:44:42 +03:00
check lv_attr_bit health $vg /pool "F"
check lv_attr_bit health $vg /$lv2 "F"
aux enable_dev " $dev2 "
lvchange -an $vg
# Overfill data area
lvchange -ay $vg
2020-09-22 17:27:21 +03:00
dd if = /dev/zero of = " $DM_DEV_DIR /mapper/ $vg - $lv2 " bs = 1M count = 2 oflag = direct || true
2016-02-18 18:44:42 +03:00
check lv_attr_bit health $vg /pool "D"
# TODO use spaces ??
check lv_field $vg /pool lv_health_status "out_of_data"
lvremove -ff $vg
#######################################################
# Testing what happens on system without thin-check #
#######################################################
lvcreate -L200M --errorwhenfull y -T $vg /pool
lvcreate -V2 -n $lv2 $vg /pool
lvchange -an $vg
# Drop usage of thin_check
aux lvmconf 'global/thin_check_executable = ""'
# Prepare some fake metadata prefilled to ~100%
2020-09-22 17:27:21 +03:00
lvcreate -L2 -n $lv1 $vg " $dev2 " # tmp for metadata
VOLS = 490
aux thin_restore_needs_more_volumes || VOLS = 445
aux prepare_thin_metadata $VOLS 1 | tee data
# Note: we like want to test BOTH sizes (445 & 490) as ATM it gives
# different errors (5.9-rc5 kernel does not handle it as expected by this test)
2016-02-18 18:44:42 +03:00
" $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 --thinpool $vg /pool --poolmetadata $vg /$lv1
2016-02-18 18:44:42 +03:00
lvchange -ay $vg
lvchange -ay $vg /$lv2
# Provisiong and last free bits in metadata
2020-09-22 17:27:21 +03:00
dd if = /dev/zero of = " $DM_DEV_DIR /mapper/ $vg - $lv2 " bs = 1M count = 1 oflag = direct || true
2016-02-18 18:44:42 +03:00
check lv_attr_bit health $vg /pool "M"
# TODO - use spaces ??
check lv_field $vg /pool lv_health_status "metadata_read_only"
check lv_attr_bit health $vg /$lv2 "-"
2020-09-27 02:24:17 +03:00
not lvcreate -s $vg /$lv2
not lvcreate -V10 -n $lv3 $vg /pool
2020-09-22 17:27:21 +03:00
lvs -ao+seg_pe_ranges $vg
2016-02-18 20:10:31 +03:00
# needs_check needs newer version
2021-03-27 21:28:43 +03:00
THINMINVER = "1 20 0"
2021-03-28 02:16:54 +03:00
aux kernel_at_least 4 18 && THINMINVER = "1 19 0" # kernel >=4.18 already had changes from 1.20
2021-03-27 21:28:43 +03:00
2021-03-28 02:16:54 +03:00
if aux have_thin $THINMINVER ; then
2021-03-26 18:53:18 +03:00
check lv_attr_bit state $vg /pool "a"
dmsetup suspend $vg -pool-tpool
check lv_attr_bit state $vg /pool "s"
dmsetup resume $vg -pool-tpool
lvresize -L+2M $vg /pool_tmeta
# Newer version recovers when metadata grow up
check lv_attr_bit state $vg /pool "a"
check lv_field $vg /pool lv_health_status ""
elif aux have_thin 1 16 0 ; then
2016-02-18 20:10:31 +03:00
check lv_attr_bit state $vg /pool "c"
check lv_field $vg /pool lv_check_needed "check needed"
dmsetup suspend $vg -pool-tpool
2016-02-18 18:44:42 +03:00
2016-02-18 20:10:31 +03:00
# suspended thin-pool with Capital 'c'
check lv_attr_bit state $vg /pool "C"
2016-02-18 18:44:42 +03:00
2016-02-18 20:10:31 +03:00
dmsetup resume $vg -pool-tpool
2016-02-18 18:44:42 +03:00
2016-02-18 20:10:31 +03:00
lvresize -L+2M $vg /pool_tmeta
2016-02-18 18:44:42 +03:00
2016-02-18 20:10:31 +03:00
# still require thin_check
check lv_attr_bit state $vg /pool "c"
fi
2016-02-18 18:44:42 +03:00
vgremove -ff $vg