Whamcloud - gitweb
LU-12350 tests: Do not use background failover
[fs/lustre-release.git] / lustre / tests / sanity-flr.sh
index e906140..33732e3 100644 (file)
@@ -9,7 +9,7 @@ SRCDIR=$(dirname $0)
 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
 
 ONLY=${ONLY:-"$*"}
-# Bug number for skipped test:
+# Bug number for skipped test:    LU-11381
 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT 201"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
@@ -17,6 +17,7 @@ LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
 . $LUSTRE/tests/test-framework.sh
 init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
+get_lustre_env
 init_logging
 
 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
@@ -87,7 +88,7 @@ start_osts() {
 verify_mirror_count() {
        local tf=$1
        local expected=$2
-       local mirror_count=$(get_mirror_ids $tf)
+       local mirror_count=$($LFS getstripe -N $tf)
 
        [[ $mirror_count = $expected ]] || {
                $LFS getstripe -v $tf
@@ -143,10 +144,23 @@ verify_comp_attr() {
                local fl
                local expected_list=$(comma_list $expected)
                for fl in ${expected_list//,/ }; do
-                       echo $value | grep -q $fl || {
+                       local neg=0
+
+                       [[ ${fl:0:1} = "^" ]] && neg=1
+                       [[ $neg = 1 ]] && fl=${fl:1}
+
+                       $(echo $value | grep -q $fl)
+                       local match=$?
+                       # 0: matched; 1: not matched
+
+                       if  [[ $neg = 0 && $match != 0 ||
+                              $neg = 1 && $match = 0 ]]; then
                                $getstripe_cmd $tf
-                               error "expected flag $fl existing on $comp_id"
-                       }
+                               [[ $neg = 0 ]] && # expect the flag
+                                   error "expected flag '$fl' not in $comp_id"
+                               [[ $neg = 1 ]] && # not expect the flag
+                                   error "not expected flag '$fl' in $comp_id"
+                       fi
                done
                return
        }
@@ -654,17 +668,29 @@ test_0g() {
        cat $tf &> /dev/null || error "error reading file '$tf'"
 
        # verify that the data was provided by OST1 where mirror 1 resides
-       local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-ffff*.stats |
+       local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
                        awk '/ost_read/{print $2}')
        [ -n "$nr_read" ] || error "read was not provided by OST1"
 }
 run_test 0g "lfs mirror create flags support"
 
 test_0h() {
-       local tf=$DIR/$tfile
+       [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
+               skip "Need MDS version at least 2.11.57"
 
-       $LFS mirror create -N -E 1M -S 1M --flags=prefer -E eof -N2 $tf ||
-               error "create mirrored file $tf failed"
+       local td=$DIR/$tdir
+       local tf=$td/$tfile
+       local ids
+       local i
+
+       # create parent directory
+       test_mkdir $td || error "mkdir $td failed"
+
+       $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
+               error "set default mirrored layout on directory $td failed"
+
+       # verify flags are inherited from the directory
+       touch $tf
 
        verify_comp_attr lcme_flags $tf 0x10001 prefer
        verify_comp_attr lcme_flags $tf 0x10002 prefer
@@ -873,7 +899,7 @@ get_osc_lock_count() {
                local osc_name
                local count
 
-               osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'ffff*'
+               osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
                count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
                lock_count=$((lock_count + count))
        done
@@ -960,7 +986,7 @@ test_32() {
                error "extending mirrored file $DIR/$tfile failed"
 
        # make sure the mirrored file was created successfully
-       [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
+       [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
                { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
 
        drop_client_cache
@@ -1009,7 +1035,7 @@ test_33() {
                      "without verification failed"
 
        # make sure that $tfile has two mirrors and $tfile-2 does not exist
-       [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
+       [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
                { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
 
        [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
@@ -1038,10 +1064,8 @@ test_33() {
        start_osts 1
 
        # read file again with ost2 failed
-       $LCTL set_param ldlm.namespaces.lustre-*-osc-ffff*.lru_size=clear
-
-       fail ost2 &
-       sleep 1
+       stop_osts 2
+       drop_client_cache
 
        # check size, glimpse should work
        $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
@@ -1052,7 +1076,7 @@ test_33() {
        [[ "$rs" == "ost1" ]] ||
                error "file content error: expected: \"ost1\", actual: \"$rs\""
 
-       wait_osc_import_state client ost2 FULL
+       start_osts 2
 }
 run_test 33 "read can choose available mirror to read"
 
@@ -1181,7 +1205,7 @@ test_36() {
 
        create_file_36 $tf $tf-2 $tf-3
 
-       [ $(get_mirror_ids $tf) -gt 1 ] || error "wrong mirror count"
+       [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
 
        # test case 1 - check file write and verify layout version
        $MULTIOP $tf oO_WRONLY:c ||
@@ -1197,13 +1221,13 @@ test_36() {
        verify_ost_layout_version $tf
 
        # test case 2
-       local mds_idx=mds$(($($LFS getstripe -m $tf-2) + 1))
+       local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
 
        local delay_sec=10
-       do_facet $mds_idx $LCTL set_param fail_val=$delay_sec
+       do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
 
        #define OBD_FAIL_FLR_LV_DELAY 0x1A01
-       do_facet $mds_idx $LCTL set_param fail_loc=0x1A01
+       do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
 
        # write should take at least $fail_loc seconds and succeed
        local st=$(date +%s)
@@ -1215,19 +1239,19 @@ test_36() {
        # verify OST layout version
        verify_ost_layout_version $tf
 
-       do_facet $mds_idx $LCTL set_param fail_loc=0
+       do_facet $mds_facet $LCTL set_param fail_loc=0
 
        # test case 3
        mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
 
        #define OBD_FAIL_FLR_LV_INC 0x1A02
-       do_facet $mds_idx $LCTL set_param fail_loc=0x1A02
+       do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
 
        # write open file should return error
        $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
                error "write a mirrored file succeeded" || true
 
-       do_facet $mds_idx $LCTL set_param fail_loc=0
+       do_facet $mds_facet $LCTL set_param fail_loc=0
 }
 run_test 36 "write to mirrored files"
 
@@ -1248,17 +1272,23 @@ create_files_37() {
 
 test_37()
 {
+       [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
+               skip "Need MDS version at least 2.11.57"
+
        local tf=$DIR/$tfile
        local tf2=$DIR/$tfile-2
        local tf3=$DIR/$tfile-3
+       local tf4=$DIR/$tfile-4
 
        create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
+       rm -f $tf4
+       cp $tf $tf4
 
        # assume the mirror id will be 1, 2, and 3
        declare -A checksums
-       checksums[1]=$(md5sum $tf | cut -f 1 -d' ')
-       checksums[2]=$(md5sum $tf2 | cut -f 1 -d' ')
-       checksums[3]=$(md5sum $tf3 | cut -f 1 -d' ')
+       checksums[1]=$(cat $tf | md5sum)
+       checksums[2]=$(cat $tf2 | md5sum)
+       checksums[3]=$(cat $tf3 | md5sum)
 
        printf '%s\n' "${checksums[@]}"
 
@@ -1275,32 +1305,35 @@ test_37()
 
        local sum
        for i in ${mirror_array[@]}; do
-               sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
+               $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
+               sum=$($LFS mirror read -N $i $tf | md5sum)
                [ "$sum" = "${checksums[$i]}" ] ||
                        error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
        done
 
+       # verify mirror write
+       echo "Verifying mirror write .."
+       $LFS mirror write -N2 $tf < $tf4
+
+       sum=$($LFS mirror read -N2 $tf | md5sum)
+       [[ "$sum" = "${checksums[1]}" ]] ||
+               error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
+
        # verify mirror copy, write to this mirrored file will invalidate
        # the other two mirrors
        echo "Verifying mirror copy .."
 
        local osts=$(comma_list $(osts_nodes))
 
-       # define OBD_FAIL_OST_SKIP_LV_CHECK     0x241
-       do_nodes $osts lctl set_param fail_loc=0x241
-
-       mirror_io copy -i ${mirror_array[0]} \
-               -t $(echo ${mirror_array[@]:1} | tr ' ' ',') $tf ||
-                       error "mirror copy error"
-
-       do_nodes $osts lctl set_param fail_loc=0
+       $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
+               error "mirror copy error"
 
        # verify copying is successful by checking checksums
        remount_client $MOUNT
        for i in ${mirror_array[@]}; do
-               sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
+               sum=$($LFS mirror read -N $i $tf | md5sum)
                [ "$sum" = "${checksums[1]}" ] ||
-                       error "$i: mismatch checksum after copy"
+                       error "$i: mismatch checksum after copy \'$sum\'"
        done
 
        rm -f $tf
@@ -1343,13 +1376,13 @@ test_38() {
        local fsize=$((RANDOM << 8 + 1048576))
        $TRUNCATE $ref $fsize
 
-       local ref_cksum=$(md5sum $ref | cut -f 1 -d' ')
+       local ref_cksum=$(cat $ref | md5sum)
 
        # case 1: verify write to mirrored file & resync work
        cp $ref $tf || error "copy from $ref to $f error"
        verify_flr_state $tf "wp"
 
-       local file_cksum=$(md5sum $tf | cut -f 1 -d' ')
+       local file_cksum=$(cat $tf | md5sum)
        [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
 
        get_mirror_ids $tf
@@ -1357,8 +1390,7 @@ test_38() {
 
        local valid_mirror stale_mirror id mirror_cksum
        for id in "${mirror_array[@]}"; do
-               mirror_cksum=$(mirror_io dump -i $id $tf |
-                               md5sum | cut -f 1 -d' ')
+               mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
                [ "$ref_cksum" == "$mirror_cksum" ] &&
                        { valid_mirror=$id; continue; }
 
@@ -1371,8 +1403,7 @@ test_38() {
        mirror_io resync $tf || error "resync failed"
        verify_flr_state $tf "ro"
 
-       mirror_cksum=$(mirror_io dump -i $stale_mirror $tf |
-                       md5sum | cut -f 1 -d' ')
+       mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
        [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
 
        # case 2: inject an error to make mirror_io exit after changing
@@ -1480,7 +1511,7 @@ test_41() {
        dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
                error "writing $tf-1 failed"
 
-       local sum0=$(cat $tf-1 | md5sum | cut -f 1 -d' ')
+       local sum0=$(cat $tf-1 | md5sum)
 
        echo " **verify files be WRITE_PENDING"
        verify_flr_state $tf "wp"
@@ -1497,11 +1528,10 @@ test_41() {
        $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
 
        echo " **verify $tf-1 data consistency in all mirrors"
-       local sum
        for i in 1 2 3; do
-               sum=$(mirror_io dump -i $i $tf-1 | md5sum | cut -f 1 -d' ')
-               [ "$sum" = "$sum0" ] ||
-                       error "$i: mismatch: $sum vs. $sum0"
+               local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
+               [[ "$sum" = "$sum0" ]] ||
+                       error "$tf-1.$i: checksum mismatch: $sum != $sum0"
        done
 
        echo " **verify files be RDONLY"
@@ -1782,7 +1812,7 @@ test_44() {
 run_test 44 "lfs mirror split check"
 
 test_45() {
-       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
+       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
 
        local file=$DIR/$tdir/$tfile
        local dir=$DIR/$tdir/$dir
@@ -1794,16 +1824,14 @@ test_45() {
                -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
                        error "Create $file failed"
 
-       echo "getstripe --yaml $file"
-       $LFS getstripe --yaml $file > $temp || error "getstripe $file failed"
-       echo "setstripe --yaml=$temp $file.2"
-       $LFS setstripe --yaml=$temp $file.2 || error "setstripe $file.2 failed"
+       verify_yaml_layout $file $file.copy $temp "1. FLR file"
+       rm -f $file $file.copy
 
-       echo "compare layout"
-       local layout1=$(get_layout_param $file)
-       local layout2=$(get_layout_param $file.2)
-       [ "$layout1" == "$layout2" ] ||
-               error "FLR file $file/$file.2 layouts are not equal"
+       $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
+               -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
+                       error "Create $file failed"
+
+       verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
 }
 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
 
@@ -1949,6 +1977,70 @@ test_47() {
 }
 run_test 47 "Verify mirror obj alloc"
 
+test_48() {
+       [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
+               skip "Need MDS version at least 2.11.55"
+
+       local tf=$DIR/$tfile
+
+       rm -f $tf
+       echo " ** create 2 mirrors FLR file $tf"
+       $LFS mirror create -N -E2M -Eeof --flags prefer \
+                          -N -E1M -Eeof $tf ||
+               error "create FLR file $tf failed"
+
+       echo " ** write it"
+       dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
+       verify_flr_state $tf "wp"
+
+       local sum0=$(md5sum < $tf)
+
+       echo " ** resync the file"
+       $LFS mirror resync $tf
+
+       echo " ** snapshot mirror 2"
+       $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
+
+       echo " ** write it again"
+       dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
+       echo " ** resync it again"
+       $LFS mirror resync $tf
+
+       verify_flr_state $tf "wp"
+       verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
+
+       local sum1=$($LFS mirror read -N1 $tf | md5sum)
+       local sum2=$($LFS mirror read -N2 $tf | md5sum)
+
+       echo " ** verify mirror 2 doesn't change"
+       echo "original checksum: $sum0"
+       echo "mirror 1 checksum: $sum1"
+       echo "mirror 2 checksum: $sum2"
+       [[ $sum0 = $sum2 ]] ||
+               error "original checksum: $sum0, mirror 2 checksum: $sum2"
+       echo " ** mirror 2 stripe info"
+       $LFS getstripe -v --mirror-index=2 $tf
+
+       echo " ** resync mirror 2"
+       $LFS mirror resync --only 2 $tf
+
+       verify_flr_state $tf "ro"
+       verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
+
+       sum1=$($LFS mirror read -N1 $tf | md5sum)
+       sum2=$($LFS mirror read -N2 $tf | md5sum)
+
+       echo " ** verify mirror 2 resync-ed"
+       echo "original checksum: $sum0"
+       echo "mirror 1 checksum: $sum1"
+       echo "mirror 2 checksum: $sum2"
+       [[ $sum1 = $sum2 ]] ||
+               error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
+       echo " ** mirror 2 stripe info"
+       $LFS getstripe -v --mirror-index=2 $tf
+}
+run_test 48 "Verify snapshot mirror"
+
 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
 
@@ -2081,9 +2173,9 @@ test_200() {
        mirror_io resync $tf
        get_mirror_ids $tf
 
-       local csum=$(mirror_io dump -i ${mirror_array[0]} $tf | md5sum)
+       local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
        for id in ${mirror_array[@]:1}; do
-               [ "$(mirror_io dump -i $id $tf | md5sum)" = "$csum" ] ||
+               [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
                        error "checksum error for mirror $id"
        done
 
@@ -2162,7 +2254,9 @@ test_202() {
 run_test 202 "lfs setstripe --add-component wide striping"
 
 test_203() {
-       [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
+       [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
+               skip "Need MDS version at least 2.11.55"
+       [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
 
        local tf=$DIR/$tfile