Whamcloud - gitweb
LU-10670 test: make sanity-flr test_43 more reliable
[fs/lustre-release.git] / lustre / tests / sanity-flr.sh
index a64cb98..f21f3d8 100644 (file)
@@ -1340,8 +1340,9 @@ test_40() {
        for ops in "conv=notrunc" ""; do
                rm -f $tf
 
-               $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E4m -E-1 \
-                       $tf || error "create PFLR file $tf failed"
+               $LFS mirror create -N -E2m -E4m -E-1  --flags=prefer \
+                               -N -E1m -E2m -E4m -E-1 $tf ||
+                       error "create PFLR file $tf failed"
                dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
                        error "write PFLR file $tf failed"
 
@@ -1358,7 +1359,7 @@ test_40() {
                # the 2nd component (in mirror 1) should be inited
                verify_comp_attr lcme_flags $tf 0x10002 init
                # the 3rd component (in mirror 1) should be uninited
-               verify_comp_attr lcme_flags $tf 0x10003 0
+               verify_comp_attr lcme_flags $tf 0x10003 prefer
                # the 4th component (in mirror 2) should be inited
                verify_comp_attr lcme_flags $tf 0x20004 init
                # the 5th component (in mirror 2) should be uninited
@@ -1420,6 +1421,238 @@ test_41() {
 }
 run_test 41 "lfs mirror resync check"
 
+test_42() {
+       [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
+
+       local td=$DIR/$tdir
+       local tf=$td/$tfile
+       local mirror_cmd="$LFS mirror verify"
+       local i
+
+       # create parent directory
+       mkdir $td || error "mkdir $td failed"
+
+       $mirror_cmd &> /dev/null && error "no file name given"
+       $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
+       $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
+
+       # create mirrored files
+       $LFS mirror create -N -E 4M -E 10M -E EOF $tf ||
+               error "create mirrored file $tf failed"
+       $LFS mirror create -N -E 2M -E EOF \
+                          -N -E 6M -E 8M -E EOF \
+                          -N -E 16M -E EOF $tf-1 ||
+               error "create mirrored file $tf-1 failed"
+       $LFS mirror create -N -c 2 -o 1,3 -N -S 4M -c -1 $tf-2 ||
+               error "create mirrored file $tf-2 failed"
+
+       # write data in [0, 10M)
+       for i in $tf $tf-1 $tf-2; do
+               yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
+                       error "write $i failed"
+       done
+
+       # resync the mirrored files
+       $LFS mirror resync $tf-1 $tf-2 ||
+               error "resync $tf-1 $tf-2 failed"
+
+       # verify the mirrored files
+       $mirror_cmd $tf-1 $tf-2 ||
+               error "verify $tf-1 $tf-2 failed"
+
+       get_mirror_ids $tf-1
+       $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
+               error "at least 2 mirror ids needed with '--only' option"
+       $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
+               &> /dev/null &&
+               error "'--only' option cannot be used upon multiple files"
+       $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
+               error "invalid specified mirror ids"
+
+       # change the content of $tf and merge it into $tf-1
+       for i in 6 10; do
+               echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
+                       error "change $tf with seek=$i failed"
+               echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
+                       error "change $tf-1 with seek=$i failed"
+       done
+
+       $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
+       $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
+               error "merge $tf into $tf-1 failed"
+
+       # verify the mirrored files
+       echo "Verify $tf-1 without -v option:"
+       $mirror_cmd $tf-1 &&
+               error "verify $tf-1 should fail" || echo "PASS"
+
+       echo "Verify $tf-1 with -v option:"
+       $mirror_cmd -v $tf-1 &&
+               error "verify $tf-1 should fail"
+
+       get_mirror_ids $tf-1
+       echo "Verify $tf-1 with --only option:"
+       $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
+               error "verify $tf-1 with mirror ${mirror_array[1]} and" \
+                     "${mirror_array[-1]} should fail"
+
+       $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
+               error "verify $tf-1 with mirror ${mirror_array[0]} and" \
+                     "${mirror_array[1]} should succeed"
+
+       # set stale components in $tf-1
+       for i in 0x40002 0x40003; do
+               $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
+                       error "set stale flag on component $i failed"
+       done
+
+       # verify the mirrored file
+       echo "Verify $tf-1 with stale components:"
+       $mirror_cmd -vvv $tf-1 ||
+               error "verify $tf-1 with stale components should succeed"
+
+       echo "Verify $tf-1 with stale components and --only option:"
+       $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
+               error "verify $tf-1 with mirror ${mirror_array[1]} and" \
+                     "${mirror_array[-1]} should succeed"
+}
+run_test 42 "lfs mirror verify"
+
+# inactivate one OST && write && restore the OST
+write_file_43() {
+       local file=$1
+       local ost=$2
+       local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
+       local wait
+
+       wait=$(do_facet $SINGLEMDS \
+               "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
+       wait=${wait%%[^0-9]*}
+
+       echo "  **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
+       $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
+       # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
+       sleep $(($wait * 2 + 2))
+       echo "  **write $file"
+       dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
+       echo "  **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
+       $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
+       sleep $((wait * 2 + 2))
+
+       local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
+       [ $flags = wp ] || error "file mirror state $flags != wp"
+}
+
+test_43() {
+       [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
+
+       local tf=$DIR/$tfile
+       local flags
+
+       rm -f $tf
+       ##   mirror 0  ost (0, 1)
+       ##   mirror 1  ost (1, 2)
+       ##   mirror 2  ost (2, 0)
+       $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
+               -N -Eeof -c2 -o2,0 $tf ||
+               error "create 3 mirrors file $tf failed"
+
+       ################## OST0 ###########################################
+       write_file_43 $tf 0
+       echo "  **verify components"
+       verify_comp_attr lcme_flags $tf 0x10001 init,stale
+       verify_comp_attr lcme_flags $tf 0x20002 init
+       verify_comp_attr lcme_flags $tf 0x30003 init,stale
+
+       # resync
+       echo "  **resync $tf"
+       $LFS mirror resync $tf
+       flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
+       [ $flags = ro ] || error "file mirror state $flags != ro"
+
+       ################## OST1 ###########################################
+       write_file_43 $tf 1
+       echo "  **verify components"
+       verify_comp_attr lcme_flags $tf 0x10001 init,stale
+       verify_comp_attr lcme_flags $tf 0x20002 init,stale
+       verify_comp_attr lcme_flags $tf 0x30003 init
+
+       # resync
+       echo "  **resync $tf"
+       $LFS mirror resync $tf
+       flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
+       [ $flags = ro ] || error "file mirror state $flags != ro"
+
+       ################## OST2 ###########################################
+       write_file_43 $tf 2
+       echo "  **verify components"
+       verify_comp_attr lcme_flags $tf 0x10001 init
+       verify_comp_attr lcme_flags $tf 0x20002 init,stale
+       verify_comp_attr lcme_flags $tf 0x30003 init,stale
+}
+run_test 43 "mirror pick on write"
+
+test_44() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       rm -rf $DIR/$tdir
+       rm -rf $DIR/$tdir-1
+       local tf=$DIR/$tdir/$tfile
+       local tf1=$DIR/$tdir-1/$tfile-1
+
+       $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
+               error "create directory failed"
+       $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
+               error "create remote directory failed"
+       rm -f $tf $tf1 $tf.mirror~2
+       # create file with 4 mirrors
+       $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 -N2 $tf ||
+               error "create PFLR file $tf failed"
+
+       # file should be in ro status
+       verify_flr_state $tf "ro"
+
+       # write data in [0, 3M)
+       dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
+               error "writing $tf failed"
+
+       verify_flr_state $tf "wp"
+
+       # synchronize all mirrors of the file
+       $LFS mirror resync $tf || error "mirror resync $tf failed"
+
+       verify_flr_state $tf "ro"
+
+       # split mirror 1
+       $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
+               error "split to $tf1 failed"
+
+       local idx0=$($LFS getstripe -m $tf)
+       local idx1=$($LFS getstripe -m $tf1)
+
+       [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
+       [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
+
+       # verify mirror count
+       verify_mirror_count $tf 3
+       verify_mirror_count $tf1 1
+
+       $LFS mirror split --mirror-id 2 $tf ||
+               error "split mirror 2 failed"
+
+       verify_mirror_count $tf 2
+       verify_mirror_count $tf.mirror~2 1
+
+       $LFS mirror split --mirror-id 3 -d $tf ||
+               error "split and delte mirror 3 failed"
+       verify_mirror_count $tf 1
+
+       # verify splitted file contains the same content as the orig file does
+       diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
+       diff $tf $tf.mirror~2 ||
+               error "splited file $tf.mirror~2 diffs from $tf"
+}
+run_test 44 "lfs mirror split check"
+
 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
 lock_file=$(mktemp /var/lock/FLR.XXXXXX)