2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
2013-10-16 12:17:17 +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
2013-10-16 12:17:17 +04:00
2014-02-23 02:08:55 +04:00
# Test repairing of broken thin pool metadata
2013-10-16 12:17:17 +04: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
2013-10-16 12:17:17 +04:00
2015-10-27 17:10:06 +03:00
. lib/inittest
2015-05-09 02:59:18 +03:00
2013-10-16 12:17:17 +04:00
which mkfs.ext2 || skip
#
# Main
#
aux have_thin 1 0 0 || skip
aux prepare_vg 4
# Create LV
2015-01-28 17:12:38 +03:00
# TODO: investigate problem with --zero n and my repairable damage trick
#lvcreate -T -L20 -V10 -n $lv1 $vg/pool --discards ignore --zero n --chunksize 128 "$dev1" "$dev2"
lvcreate -T -L20 -V10 -n $lv1 $vg /pool --chunksize 128 --discards ignore " $dev1 " " $dev2 "
2013-10-16 12:17:17 +04:00
lvcreate -T -V10 -n $lv2 $vg /pool
2014-02-23 02:08:55 +04:00
mkfs.ext2 " $DM_DEV_DIR / $vg / $lv1 "
mkfs.ext2 " $DM_DEV_DIR / $vg / $lv2 "
2013-10-16 12:17:17 +04:00
lvcreate -L20 -n repair $vg
lvcreate -L2 -n fixed $vg
lvs -a -o+seg_pe_ranges $vg
#aux error_dev "$dev2" 2050:1
2014-11-22 20:15:52 +03:00
lvchange -an $vg /$lv2 $vg /$lv1 $vg /pool $vg /repair
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
# Manual repair steps:
2013-10-16 12:17:17 +04:00
# Test swapping - swap out thin-pool's metadata with our repair volume
2017-04-03 16:57:32 +03:00
lvconvert -y -f --poolmetadata $vg /repair --thinpool $vg /pool
2013-10-16 12:17:17 +04:00
2014-11-22 20:15:52 +03:00
lvchange -ay $vg /repair
2014-11-17 02:41:33 +03:00
#
# To continue this test - we need real tools available
# When they are not present mark test as skipped, but still
# let proceed initial part which should work even without tools
#
aux have_tool_at_least " $LVM_TEST_THIN_CHECK_CMD " 0 3 1 || skip
aux have_tool_at_least " $LVM_TEST_THIN_DUMP_CMD " 0 3 1 || skip
aux have_tool_at_least " $LVM_TEST_THIN_REPAIR_CMD " 0 3 1 || skip
2013-10-16 12:17:17 +04:00
# Make some 'repairable' damage??
2014-02-23 02:08:55 +04:00
dd if = /dev/zero of = " $DM_DEV_DIR / $vg /repair " bs = 1 seek = 40960 count = 1
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
not " $LVM_TEST_THIN_CHECK_CMD " " $DM_DEV_DIR / $vg /repair "
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
not " $LVM_TEST_THIN_DUMP_CMD " " $DM_DEV_DIR / $vg /repair " | tee dump
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
" $LVM_TEST_THIN_REPAIR_CMD " -i " $DM_DEV_DIR / $vg /repair " -o " $DM_DEV_DIR / $vg /fixed "
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
" $LVM_TEST_THIN_DUMP_CMD " --repair " $DM_DEV_DIR / $vg /repair " | tee repaired_xml
2013-10-17 12:41:08 +04:00
2014-11-17 02:41:33 +03:00
" $LVM_TEST_THIN_CHECK_CMD " " $DM_DEV_DIR / $vg /fixed "
2013-10-16 12:17:17 +04:00
2014-11-17 10:44:53 +03:00
lvchange -an $vg
2013-10-16 12:17:17 +04:00
# Swap repaired metadata back
2017-04-03 16:57:32 +03:00
lvconvert -y -f --poolmetadata $vg /fixed --thinpool $vg /pool
2013-10-16 12:17:17 +04:00
2015-01-28 17:12:38 +03:00
# Check pool still preserves its original settings
check lv_field $vg /pool chunksize "128.00k"
check lv_field $vg /pool discards "ignore"
check lv_field $vg /pool zero "zero"
2013-10-16 12:17:17 +04:00
# Activate pool - this should now work
2014-11-17 02:41:33 +03:00
vgchange -ay $vg
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
vgchange -an $vg
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
# Put back 'broken' metadata
2017-04-03 16:57:32 +03:00
lvconvert -y -f --poolmetadata $vg /repair --thinpool $vg /pool
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
# Check --repair usage
lvconvert -v --repair $vg /pool
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
# Check repaired pool could be activated
lvchange -ay $vg /pool
2013-10-16 12:17:17 +04:00
2014-11-22 20:15:52 +03:00
vgchange -an $vg
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
# Restore damaged metadata
2017-04-03 16:57:32 +03:00
lvconvert -y -f --poolmetadata $vg /pool_meta0 --thinpool $vg /pool
2013-10-16 12:17:17 +04:00
2014-11-17 02:41:33 +03:00
# Check lvremove -ff works even with damaged pool
lvremove -ff $vg