diff options
Diffstat (limited to 'test/shell/mirror-vgreduce-removemissing.sh')
-rw-r--r-- | test/shell/mirror-vgreduce-removemissing.sh | 222 |
1 files changed, 133 insertions, 89 deletions
diff --git a/test/shell/mirror-vgreduce-removemissing.sh b/test/shell/mirror-vgreduce-removemissing.sh index 232c2be..ff7eea5 100644 --- a/test/shell/mirror-vgreduce-removemissing.sh +++ b/test/shell/mirror-vgreduce-removemissing.sh @@ -1,5 +1,6 @@ -#!/bin/sh -# Copyright (C) 2008-2012 Red Hat, Inc. All rights reserved. +#!/usr/bin/env bash + +# Copyright (C) 2008-2017 Red Hat, Inc. All rights reserved. # Copyright (C) 2007 NEC Corporation # # This copyrighted material is made available to anyone wishing to use, @@ -8,24 +9,28 @@ # # 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA test_description="ensure that 'vgreduce --removemissing' works on mirrored LV" -. lib/test +SKIP_WITH_LVMPOLLD=1 + +. lib/inittest + +list_pvs=() lv_is_on_ () { local lv=$vg/$1 shift - local pvs=$@ + local list_pvs=( "$@" ) - echo "Check if $lv is exactly on PVs $pvs" + echo "Check if $lv is exactly on PVs" "${list_pvs[@]}" rm -f out1 out2 - echo $pvs | sed 's/ /\n/g' | sort | uniq > out1 + printf "%s\n" "${list_pvs[@]}" | sort | uniq > out1 lvs -a -o+devices $lv - get lv_devices $lv | sed 's/ /\n/g' | sort | uniq > out2 || true + get lv_devices "$lv" | sort | uniq > out2 diff --ignore-blank-lines out1 out2 } @@ -34,23 +39,23 @@ mimages_are_on_ () { local lv=$1 shift - local pvs=$@ - local mimages + local list_pvs=( "$@" ) + local mimages=() local i - echo "Check if mirror images of $lv are on PVs $pvs" - rm -f out1 out2 - echo $pvs | sed 's/ /\n/g' | sort | uniq > out1 - lvs --noheadings -a -o lv_name $vg > lvs_log - mimages=$(grep "${lv}_mimage_" lvs_log | \ - sed 's/\[//g; s/\]//g' || true) - - for i in $mimages; do - echo "Checking $vg/$i" - lvs -a -o+devices $vg/$i - lvs -a -odevices --noheadings $vg/$i > lvs_log - sed 's/([^)]*)//g; s/ //g; s/,/ /g' lvs_log | sort | uniq >> out2 || true - done + echo "Check if mirror images of $lv are on PVs" "${list_pvs[@]}" + printf "%s\n" "${list_pvs[@]}" | sort | uniq | tee out1 + + get lv_field_lv_ "$vg" lv_name -a | grep "${lv}_mimage_" | tee lvs_log + test -s lvs_log || return 1 + + while IFS= read -r i ; do + mimages+=( "$i" ) + done < lvs_log + + for i in "${mimages[@]}"; do + get lv_devices "$vg/$i" + done | sort | uniq | tee out2 diff --ignore-blank-lines out1 out2 } @@ -65,29 +70,35 @@ mirrorlog_is_on_() lv_is_linear_() { echo "Check if $1 is linear LV (i.e. not a mirror)" - get lv_field $vg/$1 "stripes,attr" | grep "^1 -" >/dev/null + get lv_field $vg/$1 "stripes,attr" | tee out + grep "^1 -" out >/dev/null } rest_pvs_() { local index=$1 local num=$2 - local rem= + local rem=() local n + local dev - for n in $(seq 1 $(($index - 1))) $(seq $(($index + 1)) $num); do - eval local dev=$\dev$n - rem="$rem $dev" + for n in $(seq 1 $(( index - 1 )) ) $(seq $(( index + 1 )) $num); do + eval "dev=\$dev$n" + rem+=( "$dev" ) done - echo "$rem" + printf "%s\n" "${rem[@]}" } # --------------------------------------------------------------------- # Initialize PVs and VGs -aux prepare_vg 5 +aux prepare_pvs 5 80 +get_devs +vgcreate $SHARED -s 64k "$vg" "${DEVICES[@]}" +BLOCKS=0-7 +BLOCKS1=8-15 # --------------------------------------------------------------------- # Common environment setup/cleanup for each sub testcases @@ -100,15 +111,23 @@ prepare_lvs_() check_and_cleanup_lvs_() { - lvs -a -o+devices $vg + lvs -a -o+lv_uuid,devices $vg prepare_lvs_ } recover_vg_() { aux enable_dev "$@" + + # clear outdated metadata on PVs so they can be used again + vgck --updatemetadata $vg + + pvscan --cache + pvcreate -ff "$@" + # wipefs -a "$@" vgextend $vg "$@" + check_and_cleanup_lvs_ } @@ -121,10 +140,9 @@ check_and_cleanup_lvs_ #COMM "basic: fail the 2nd mirror image of 2-way mirrored LV" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev3":0 -lvchange -an $vg/$lv1 -mimages_are_on_ $lv1 $dev1 $dev2 -mirrorlog_is_on_ $lv1 $dev3 +lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg "$dev1" "$dev2" "$dev3":$BLOCKS +mimages_are_on_ $lv1 "$dev1" "$dev2" +mirrorlog_is_on_ $lv1 "$dev3" aux disable_dev "$dev2" vgreduce --removemissing --force $vg lv_is_linear_ $lv1 @@ -142,14 +160,17 @@ test_3way_mirror_fail_1_() { local index=$1 - lvcreate -l2 -m2 -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev4":0 - lvchange -an $vg/$lv1 + lvcreate -an -Zn -l2 --type mirror -m2 --nosync -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev4":$BLOCKS mimages_are_on_ $lv1 "$dev1" "$dev2" "$dev3" mirrorlog_is_on_ $lv1 "$dev4" - eval aux disable_dev \$dev$index + eval aux disable_dev "\$dev$index" vgreduce --removemissing --force $vg - lvs -a -o+devices $vg - mimages_are_on_ $lv1 $(rest_pvs_ $index 3) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$index" 3 ) + + mimages_are_on_ "$lv1" "${list_pvs[@]}" mirrorlog_is_on_ $lv1 "$dev4" } @@ -157,7 +178,7 @@ for n in $(seq 1 3); do #COMM fail mirror image $(($n - 1)) of 3-way mirrored LV" prepare_lvs_ test_3way_mirror_fail_1_ $n - eval recover_vg_ \$dev$n + eval recover_vg_ "\$dev$n" done # --------------------------------------------------------------------- @@ -169,23 +190,30 @@ test_3way_mirror_fail_2_() { local index=$1 - lvcreate -l2 -m2 -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev4":0 - lvchange -an $vg/$lv1 + lvcreate -an -Zn -l2 --type mirror -m2 --nosync -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev4":$BLOCKS mimages_are_on_ $lv1 "$dev1" "$dev2" "$dev3" mirrorlog_is_on_ $lv1 "$dev4" - rest_pvs_ $index 3 - aux disable_dev $(rest_pvs_ $index 3) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$index" 3 ) + + aux disable_dev "${list_pvs[@]}" vgreduce --force --removemissing $vg - lvs -a -o+devices $vg lv_is_linear_ $lv1 - eval lv_is_on_ $lv1 \$dev$n + eval lv_is_on_ $lv1 "\$dev$n" } for n in $(seq 1 3); do #COMM fail mirror images other than mirror image $(($n - 1)) of 3-way mirrored LV prepare_lvs_ test_3way_mirror_fail_2_ $n - recover_vg_ $(rest_pvs_ $n 3) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$n" 3 ) + + recover_vg_ "${list_pvs[@]}" done # --------------------------------------------------------------------- @@ -197,16 +225,18 @@ test_3way_mirror_plus_1_fail_1_() { local index=$1 - lvcreate -l2 -m2 -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev5":0 - lvchange -an $vg/$lv1 + lvcreate -an -Zn -l2 --type mirror -m2 -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev5":$BLOCKS lvconvert -m+1 $vg/$lv1 "$dev4" check mirror_images_on $vg $lv1 "$dev1" "$dev2" "$dev3" "$dev4" check mirror_log_on $vg $lv1 "$dev5" eval aux disable_dev \$dev$index - lvs -a -o +devices vgreduce --removemissing --force $vg - lvs -a -o+devices # $vg - check mirror_images_on $vg $lv1 "$dev5" # $(rest_pvs_ $index 4) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$index" 4 ) + + check mirror_images_on $vg $lv1 "${list_pvs[@]}" check mirror_log_on $vg $lv1 "$dev5" } @@ -225,26 +255,35 @@ done test_3way_mirror_plus_1_fail_3_() { local index=$1 + local dev - lvcreate -l2 -m2 -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev5":0 - lvchange -an $vg/$lv1 + lvcreate -an -Zn -l2 --type mirror -m2 -n $lv1 $vg "$dev1" "$dev2" "$dev3" "$dev5":$BLOCKS lvconvert -m+1 $vg/$lv1 "$dev4" check mirror_images_on $vg $lv1 "$dev1" "$dev2" "$dev3" "$dev4" check mirror_log_on $vg $lv1 "$dev5" - lvs -a -o+devices $vg - aux disable_dev $(rest_pvs_ $index 4) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$index" 4 ) + + aux disable_dev "${list_pvs[@]}" vgreduce --removemissing --force $vg lvs -a -o+devices $vg - eval local dev=\$dev$n + eval dev=\$dev$n check linear $vg $lv1 - check lv_on $vg $lv1 $dev + check lv_on $vg $lv1 "$dev" } for n in $(seq 1 4); do #COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV" prepare_lvs_ test_3way_mirror_plus_1_fail_3_ $n - recover_vg_ $(rest_pvs_ $n 4) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$n" 4 ) + + recover_vg_ "${list_pvs[@]}" done # --------------------------------------------------------------------- @@ -256,15 +295,18 @@ test_2way_mirror_plus_2_fail_1_() { local index=$1 - lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 - lvchange -an $vg/$lv1 + lvcreate -an -Zn -l2 --type mirror -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS lvconvert -m+2 $vg/$lv1 "$dev3" "$dev4" mimages_are_on_ $lv1 "$dev1" "$dev2" "$dev3" "$dev4" mirrorlog_is_on_ $lv1 "$dev5" eval aux disable_dev \$dev$n vgreduce --removemissing --force $vg - lvs -a -o+devices $vg - mimages_are_on_ $lv1 $(rest_pvs_ $index 4) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$index" 4 ) + + mimages_are_on_ "$lv1" "${list_pvs[@]}" mirrorlog_is_on_ $lv1 "$dev5" } @@ -272,7 +314,7 @@ for n in $(seq 1 4); do #COMM "fail mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV" prepare_lvs_ test_2way_mirror_plus_2_fail_1_ $n - eval recover_vg_ \$dev$n + eval recover_vg_ "\$dev$n" done # --------------------------------------------------------------------- @@ -283,17 +325,23 @@ done test_2way_mirror_plus_2_fail_3_() { local index=$1 + local dev - lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 - lvchange -an $vg/$lv1 + lvcreate -an -Zn -l2 --type mirror -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS lvconvert -m+2 $vg/$lv1 "$dev3" "$dev4" mimages_are_on_ $lv1 "$dev1" "$dev2" "$dev3" "$dev4" mirrorlog_is_on_ $lv1 "$dev5" - aux disable_dev $(rest_pvs_ $index 4) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$index" 4 ) + + aux disable_dev "${list_pvs[@]}" vgreduce --removemissing --force $vg lvs -a -o+devices $vg - eval local dev=\$dev$n - mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev + eval dev=\$dev$n + not mimages_are_on_ $lv1 "$dev" + lv_is_on_ $lv1 "$dev" not mirrorlog_is_on_ $lv1 "$dev5" } @@ -301,7 +349,12 @@ for n in $(seq 1 4); do #COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV" prepare_lvs_ test_2way_mirror_plus_2_fail_3_ $n - recover_vg_ $(rest_pvs_ $n 4) + + list_pvs=(); while IFS= read -r line ; do + list_pvs+=( "$line" ) + done < <( rest_pvs_ "$n" 4 ) + + recover_vg_ "${list_pvs[@]}" done # --------------------------------------------------------------------- @@ -309,8 +362,7 @@ done #COMM "fail mirror log of 2-way mirrored LV" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 -lvchange -an $vg/$lv1 +lvcreate -aey -l2 --type mirror -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS mimages_are_on_ $lv1 "$dev1" "$dev2" mirrorlog_is_on_ $lv1 "$dev5" aux disable_dev "$dev5" @@ -321,8 +373,7 @@ recover_vg_ "$dev5" #COMM "fail mirror log of 3-way (1 converting) mirrored LV" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 -lvchange -an $vg/$lv1 +lvcreate -aey -l2 --type mirror -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS lvconvert -m+1 $vg/$lv1 "$dev3" mimages_are_on_ $lv1 "$dev1" "$dev2" "$dev3" mirrorlog_is_on_ $lv1 "$dev5" @@ -337,8 +388,7 @@ recover_vg_ "$dev5" #COMM "fail all mirror images of 2-way mirrored LV" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 -lvchange -an $vg/$lv1 +lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS mimages_are_on_ $lv1 "$dev1" "$dev2" mirrorlog_is_on_ $lv1 "$dev5" aux disable_dev "$dev1" "$dev2" @@ -348,8 +398,7 @@ recover_vg_ "$dev1" "$dev2" #COMM "fail all mirror images of 3-way (1 converting) mirrored LV" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 -lvchange -an $vg/$lv1 +lvcreate -an -Zn -l2 --type mirror -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS lvconvert -m+1 $vg/$lv1 "$dev3" mimages_are_on_ $lv1 "$dev1" "$dev2" "$dev3" mirrorlog_is_on_ $lv1 "$dev5" @@ -363,10 +412,8 @@ recover_vg_ "$dev1" "$dev2" "$dev3" #COMM "fail a mirror image of one of mirrored LV" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 -lvchange -an $vg/$lv1 -lvcreate -l2 -m1 -n $lv2 $vg "$dev3" "$dev4" "$dev5":1 -lvchange -an $vg/$lv2 +lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS +lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv2 $vg "$dev3" "$dev4" "$dev5":$BLOCKS1 mimages_are_on_ $lv1 "$dev1" "$dev2" mimages_are_on_ $lv2 "$dev3" "$dev4" mirrorlog_is_on_ $lv1 "$dev5" @@ -381,10 +428,8 @@ recover_vg_ "$dev2" #COMM "fail mirror images, one for each mirrored LV" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 -lvchange -an $vg/$lv1 -lvcreate -l2 -m1 -n $lv2 $vg "$dev3" "$dev4" "$dev5":1 -lvchange -an $vg/$lv2 +lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS +lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv2 $vg "$dev3" "$dev4" "$dev5":$BLOCKS1 mimages_are_on_ $lv1 "$dev1" "$dev2" mimages_are_on_ $lv2 "$dev3" "$dev4" mirrorlog_is_on_ $lv1 "$dev5" @@ -403,8 +448,7 @@ recover_vg_ "$dev2" "$dev4" #COMM "no failures" prepare_lvs_ -lvcreate -l2 -m1 -n $lv1 $vg "$dev1" "$dev2" "$dev5":0 -lvchange -an $vg/$lv1 +lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg "$dev1" "$dev2" "$dev5":$BLOCKS mimages_are_on_ $lv1 "$dev1" "$dev2" mirrorlog_is_on_ $lv1 "$dev5" vgreduce --removemissing --force $vg |