Whamcloud - gitweb
LU-14514 flr: mirror split should not make stale file
[fs/lustre-release.git] / lustre / tests / sanity-flr.sh
index 671be84..fd811a2 100644 (file)
@@ -14,8 +14,8 @@ init_test_env $@
 init_logging
 
 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT "
-# Bug number for skipped test:    LU-11381
-ALWAYS_EXCEPT+="                  201 "
+# Bug number for skipped test:    LU-14818 LU-11381
+ALWAYS_EXCEPT+="                  6        201 "
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 # skip all tests for PPC until we can get sanity-pfl to pass
@@ -516,20 +516,21 @@ test_0d() {
        # create a mirrored file and extend it
        $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
        $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
+       $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
 
-       $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
-               error "setstripe options should not be specified with -f option"
+       $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
+               error "extend mirror with -f failed"
 
-       $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
-               error "extend mirrored file $tf-1 failed"
-       verify_mirror_count $tf-1 $mirror_count
-       ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
+       $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
+               error "extend mirrored file $tf-3 failed"
+       verify_mirror_count $tf-3 $mirror_count
+       ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
        for ((i = 0; i < $mirror_count; i++)); do
-               verify_comp_attrs $tf-1 ${ids[$i]}
-               verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
+               verify_comp_attrs $tf-3 ${ids[$i]}
+               verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
        done
 
-       $mirror_cmd -N $tf-1 &> /dev/null &&
+       $mirror_cmd -N $tf-3 &> /dev/null &&
                error "exceeded maximum mirror count $mirror_count" || true
 }
 run_test 0d "lfs mirror extend with -N option"
@@ -934,27 +935,45 @@ test_5() {
 }
 run_test 5 "Make sure init size work for mirrored layout"
 
-# LU=10112: disable dom+flr for phase 1
 test_6() {
+       (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
+               skip "MDS version older than 2.12.58"
+
        local tf=$DIR/$tfile
 
-       $LFS mirror create -N -E 1M -S 1M -L mdt -E eof -N -E eof $tf &&
-               error "expect failure to create mirrored file with DoM"
+       $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
+               error "failure to create DoM file with mirror"
 
-       $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf &&
-               error "expect failure to create mirrored file with DoM"
+       $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
+               error "failure to create mirrored file with DoM"
 
-       $LFS setstripe -E 1M -S 1M -L mdt -E eof $tf
-       $LFS mirror extend -N2 $tf &&
-               error "expect failure to extend mirror with DoM"
+       $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
+               error "failure to create PFL with DoM file"
+       $LFS mirror extend -N2 $tf ||
+               error "failure to extend mirror with DoM"
 
-       $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2
-       $LFS mirror extend -N -f $tf $tf-2 &&
-               error "expect failure to extend mirrored file with DoM extent"
+       $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
+               error "failure to create PFL with DoM file"
+       $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
+               error "failure to create mirrored file"
+       $LFS mirror extend -N -f $tf-1 $tf-2 ||
+               error "failure to extend mirrored file with DoM extent"
+}
+run_test 6 "DoM and FLR work together"
 
-       true
+test_7() {
+       local tf=$DIR/$tfile
+
+       # create DoM with setting stripe_size == component size
+       $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
+               error "failure to create DoM with stripe_size == comp size"
+       rm -f $tf || error "delete $tf"
+
+       # DoM should not inherit previous component stripe_size
+       $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
+               error "DoM component shouldn't inherit previous stripe_size"
 }
-run_test 6 "DoM and FLR won't co-exist for phase 1"
+run_test 7 "Create mirror with DoM component"
 
 test_21() {
        local tf=$DIR/$tfile
@@ -962,6 +981,8 @@ test_21() {
 
        [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
 
+       stack_trap "rm -f $tf $tf2"
+
        $LFS setstripe -E EOF -o 0 $tf
        $LFS setstripe -E EOF -o 1 $tf2
 
@@ -1006,6 +1027,8 @@ get_osc_lock_count() {
 test_22() {
        local tf=$DIR/$tfile
 
+       stack_trap "rm -f $tf"
+
        $LFS setstripe -E EOF -o 0 $tf
        dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
 
@@ -1070,6 +1093,8 @@ test_32() {
        [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
        rm -f $DIR/$tfile $DIR/$tfile-2
 
+       stack_trap "rm -f $DIR/$tfile"
+
        $LFS setstripe -E EOF -o 0 $DIR/$tfile
        dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
 
@@ -1407,6 +1432,8 @@ create_file_36() {
 test_36() {
        local tf=$DIR/$tfile
 
+       stack_trap "rm -f $tf $tf-2 $tf-3"
+
        create_file_36 $tf $tf-2 $tf-3
 
        [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
@@ -1484,6 +1511,8 @@ test_37()
        local tf3=$DIR/$tfile-3
        local tf4=$DIR/$tfile-4
 
+       stack_trap "rm -f $tf $tf2 $tf3 $tf4"
+
        create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
        rm -f $tf4
        cp $tf $tf4
@@ -1548,6 +1577,8 @@ test_38() {
        local tf=$DIR/$tfile
        local ref=$DIR/${tfile}-ref
 
+       stack_trap "rm -f $tf $ref"
+
        $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
                error "creating $tf failed"
        $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
@@ -1594,7 +1625,7 @@ test_38() {
        [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
        [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
 
-       mirror_io resync $tf || error "resync failed"
+       $LFS mirror resync $tf || error "resync failed"
        verify_flr_state $tf "ro"
 
        mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
@@ -1617,7 +1648,7 @@ test_38() {
        verify_flr_state $tf "sp"
 
        # from sync_pending to read_only
-       mirror_io resync $tf || error "resync failed"
+       $LFS mirror resync $tf || error "resync failed"
        verify_flr_state $tf "ro"
 }
 run_test 38 "resync"
@@ -1684,6 +1715,8 @@ run_test 40 "PFLR rdonly state instantiation check"
 test_41() {
        local tf=$DIR/$tfile
 
+       stack_trap "rm -f $tf $tf-1"
+
        rm -f $tf $tf-1
        echo " **create two FLR files $tf $tf-1"
        $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
@@ -1780,6 +1813,8 @@ test_42() {
        local mirror_cmd="$LFS mirror verify"
        local i
 
+       stack_trap "rm -rf $td"
+
        # create parent directory
        mkdir $td || error "mkdir $td failed"
 
@@ -1948,6 +1983,7 @@ test_43b() {
 
        test_mkdir $DIR/$tdir
        rm -f $tf
+       stack_trap "rm -rf $tf"
 
        # create 3 mirrors FLR file, the first 2 mirrors are preferred
        $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
@@ -1964,13 +2000,15 @@ test_43b() {
 }
 run_test 43b "allow writing to multiple preferred mirror file"
 
-test_44() {
+test_44a() {
        [ $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
 
+       stack_trap "rm -rf $tf $tf1"
+
        $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
                error "create directory failed"
        $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
@@ -2037,7 +2075,98 @@ test_44() {
        diff $tf $tf.mirror~2 ||
                error "splited file $tf.mirror~2 diffs from $tf"
 }
-run_test 44 "lfs mirror split check"
+run_test 44a "lfs mirror split check"
+
+test_44b() {
+       rm -rf $DIR/$tdir
+       local tf=$DIR/$tdir/$tfile
+
+       mkdir -p $DIR/$tdir || error "create directory failed"
+
+       echo XXX > $tf
+
+       # create 2 mirrors file
+       $LFS mirror extend -N -c1 $tf
+
+       echo YYY > $tf
+
+       verify_flr_state $tf "wp"
+
+       local str=$(cat $tf)
+
+       [[ $str == "YYY" ]] || error "$tf content is not YYY"
+
+       # get the non-stale mirror id
+       local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
+                       tr '\n' ' '))
+       local mirror_ids=($($LFS getstripe $tf |
+                       awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
+       for ((i = 0; i < 2; i++)); do
+               $LFS getstripe -I${ids[$i]} --component-flags $tf |
+                       grep stale > /dev/null || break
+       done
+
+       [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
+
+       $LFS getstripe $tf
+
+       # split the updated mirror, should fail
+       echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
+       $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
+               error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
+
+       i=$(( 1 - i ))
+       # split the stale mirror
+       echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
+       $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
+               error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
+
+       echo "make sure there's no stale comp in the file"
+       # make sure there's no stale comp in the file
+       $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
+               ( $LFS getstripe $tf; error "stale mirror file" )
+
+       str=$(cat $tf)
+       [[ $str == "YYY" ]] ||
+               ( cat $tf; error "$tf content is not YYY after split" )
+}
+run_test 44b "mirror split does not create stale file"
+
+test_44c() {
+       local tf=$DIR/$tdir/$tfile
+
+       stack_trap "rm -f $tf"
+
+       [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
+               skip "Need MDS version at least 2.14.52"
+
+       [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
+
+       mkdir -p $DIR/$tdir || error "create directroy failed"
+
+       dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
+       sync
+       block1=$(( $(stat -c "%b*%B" $tf) ))
+       echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
+
+       $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
+       sync
+       block2=$(( $(stat -c "%b*%B" $tf) ))
+       echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
+
+       $LFS mirror split -d --mirror-id=2 $tf ||
+               error "mirror split $tfile failed"
+       $LFS mirror split -d --mirror-id=3 $tf ||
+               error "mirror split $tfile failed"
+       sync
+       lfs getsom $tf
+       block3=$(( $(stat -c "%b*%B" $tf) ))
+       echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
+
+       [[ $block1 -eq $block3 ]] ||
+               error "mirror split does not reduce block# $block3 != $block1"
+}
+run_test 44c "lfs mirror split reduces block size of a file"
 
 test_45() {
        [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
@@ -2133,6 +2262,10 @@ test_46() {
 
        verify_46 $dir $dir.copy "6. FLR dir"
 
+       (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
+               echo "server version $MDS1_VERSION does not support SEL" &&
+               return 0
+
        ########################### 7. SEL file ##############################
        echo "  ** 7. SEL file"
        rm -f $file
@@ -2572,6 +2705,89 @@ test_50b() {
 }
 run_test 50b "mirror rsync handles sparseness"
 
+test_50c() {
+       local tf=$DIR/$tdir/$tfile
+
+       test_mkdir $DIR/$tdir
+
+       $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
+       verify_flr_state $tf "ro"
+
+       if [[ "$FSTYPE" == "ldiskfs" ]]; then
+               # ZFS does not support fallocate for now
+               fallocate -p -o 1MiB -l 1MiB $tf ||
+                       error "punch hole in $tf failed"
+               verify_flr_state $tf "wp"
+       fi
+
+       dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
+       $LFS mirror resync $tf || error "mirror resync $tf failed"
+       verify_flr_state $tf "ro"
+
+       $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
+       verify_flr_state $tf "wp"
+}
+run_test 50c "punch_hole/mmap_write stale other mirrors"
+
+test_50d() {
+       $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
+               skip "OST does not support SEEK_HOLE"
+       (( $LINUX_VERSION_CODE > $(version_code 3.0.0) )) ||
+               skip "client kernel does not support SEEK_HOLE"
+
+       local file=$DIR/$tdir/$tfile
+       local offset
+       local prt
+       local rc
+
+       mkdir -p $DIR/$tdir
+
+       echo " ** create mirrored file $file"
+       $LFS mirror create -N -E1M -c1 -S1M -E eof \
+               -N -E2M -S1M -E eof -S2M $file ||
+               error "cannot create mirrored file"
+       echo " ** write data chunk at 1M boundary"
+       dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
+               error "cannot write data at 1M boundary"
+       echo " ** create hole at the file start"
+       prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
+       rc=$?
+
+       if [[ $rc -eq 0 ]]; then
+               verify_flr_state $file "wp"
+       elif [[ ! $prt =~ "unsupported" ]]; then
+               error "punch hole in $file failed: $prt"
+       else
+               skip "Fallocate punch is not supported"
+       fi
+
+       echo " ** verify sparseness"
+       offset=$(lseek_test -d 1000 $file)
+       echo "    first data offset: $offset"
+       (( $offset >= 1024 * 1024 )) ||
+               error "src: data is not expected at offset $offset"
+
+       echo " ** resync mirror #2"
+       $LFS mirror resync $file
+
+       # check llapi_mirror_copy_many correctness
+       sum_1=$($LFS mirror read -N 1 $file | md5sum)
+       sum_2=$($LFS mirror read -N 2 $file | md5sum)
+       [[ $sum_1 == $sum_2 ]] ||
+               error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
+
+       cancel_lru_locks osc
+
+       # stale first component in mirror #1
+       $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
+       echo " ** verify sparseness of mirror #2"
+       offset=$(lseek_test -d 1000 $file)
+       echo "    first data offset: $offset"
+       (( $offset >= 1024 * 1024 )) ||
+               error "src: data is not expected at offset $offset"
+}
+run_test 50d "mirror rsync keep holes"
+
 test_60a() {
        $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
                skip "OST does not support SEEK_HOLE"
@@ -2597,6 +2813,180 @@ test_60a() {
 }
 run_test 60a "mirror extend sets correct size on sparse file"
 
+get_flr_layout_gen() {
+       getfattr -n lustre.lov --only-values $tf 2>/dev/null |
+               od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
+}
+
+check_layout_gen() {
+       local tf=$1
+
+       local v1=$(get_flr_layout_gen $tf)
+       local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
+
+       [[ $v1 -eq $v2 ]] ||
+               error "$tf in-memory layout gen $v1 != $v2 after $2"
+}
+
+test_60b() {
+       local tf=$DIR/$tdir/$tfile
+
+       test_mkdir $DIR/$tdir
+
+       $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
+
+       for ((i = 0; i < 20; i++)); do
+               $LFS mirror extend -N $tf ||
+                       error "extending mirror for $tf failed"
+               check_layout_gen $tf "extend"
+
+               $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
+                       error "split $tf failed"
+               check_layout_gen $tf "split"
+       done
+}
+run_test 60b "mirror merge/split cancel client's in-memory layout gen"
+
+get_times_61() {
+       stat --format='%X %Y %Z' $file || error "$file: cannot get times"
+}
+
+check_times_61() {
+       local file=$1
+       local -a old=( $2 $3 $4 )
+       local -a new
+
+       new=( $(get_times_61 $file) )
+       ((${old[0]} == ${new[0]})) ||
+               error "$file: atime: old '${old[0]}' != new '${new[0]}'"
+
+       ((${old[1]} == ${new[1]})) ||
+               error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
+}
+
+test_61a() { # LU-14508
+       local file=$DIR/$tdir/$tfile
+       local -a tim
+       local nap=5
+
+       mkdir -p $DIR/$tdir
+       echo "create $file"
+       $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
+       echo "create $file-2"
+       $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
+
+       echo XXX > $file || error "write $file failed"
+       chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
+
+       echo "sleep $nap seconds, then cat $tfile"
+       sleep $nap
+       cat $file || error "cat $file failed"
+
+       echo "sleep $nap seconds, then re-write $tfile"
+       sleep $nap
+       echo XXXX > $file || error "write $file failed"
+       cp -p $file $file-2 || error "copy $file-2 failed"
+
+       echo "sleep $nap seconds"
+       sleep $nap
+
+       tim=( $(get_times_61 $file) )
+
+       echo "mirror merge $tfile-2 to $tfile and test timestamps"
+       $LFS mirror extend -N -f $file-2 $file ||
+               error "cannot mirror merge $file-2 to $file"
+       check_times_61 $file ${tim[@]}
+
+       echo "mirror extend $tfile and test timestamps"
+       $LFS mirror extend -N -c1 -i1 $file ||
+               error "cannot extend mirror $file"
+       check_times_61 $file ${tim[@]}
+
+       echo "migrate $tfile and test timestamps"
+       $LFS migrate -n $file || error "cannot migrate $file"
+       check_times_61 $file ${tim[@]}
+
+       echo "normal user migrate $tfile and test timestamps"
+       $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
+       check_times_61 $file ${tim[@]}
+}
+run_test 61a "mirror extend and migrate preserve timestamps"
+
+test_61b() { # LU-14508
+       local file=$DIR/$tdir/$tfile
+       local -a tim
+       local nap=5
+
+       mkdir -p $DIR/$tdir
+       echo "create $file"
+       echo XXX > $file || error "create $file failed"
+       chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
+
+       echo "sleep $nap seconds, then cat $tfile"
+       sleep $nap
+       cat $file || error "cat $file failed"
+
+       echo "sleep $nap seconds, then re-write $tfile"
+       sleep $nap
+       echo XXXX > $file || error "write $file failed"
+
+       echo "sleep $nap seconds, then test timestamps"
+       sleep $nap
+
+       tim=( $(get_times_61 $file) )
+
+       echo "mirror extend $tfile and test timestamps"
+       $LFS mirror extend -N -c1 -i1 $file ||
+               error "cannot extend mirror $file"
+       check_times_61 $file ${tim[@]}
+
+       echo "mirror split $tfile and test timestamps"
+       $LFS mirror split -d --mirror-id=1 $file ||
+               error "cannot split mirror 1 off $file"
+       check_times_61 $file ${tim[@]}
+
+       echo "normal user mirror extend $tfile and test timestamps"
+       $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
+               error "cannot extend mirror $file"
+       check_times_61 $file ${tim[@]}
+}
+run_test 61b "mirror extend and split preserve timestamps"
+
+test_61c() { # LU-14508
+       local file=$DIR/$tdir/$tfile
+       local -a tim
+       local nap=5
+
+       mkdir -p $DIR/$tdir
+       echo "create $file"
+       echo XXX > $file || error "create $file failed"
+       chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
+
+       echo "sleep $nap seconds, then cat $tfile"
+       sleep $nap
+       cat $file || error "cat $file failed"
+
+       echo "sleep $nap seconds, then mirror extend $tfile and write it"
+       sleep $nap
+       $LFS mirror extend -N -c1 -i1 $file ||
+               error "cannot extend mirror $file"
+       echo XXXX > $file || error "write $file failed"
+
+       echo "sleep $nap seconds, then resync $tfile and test timestamps"
+       tim=( $(get_times_61 $file) )
+       sleep $nap
+       $LFS mirror resync $file || error "cannot resync mirror $file"
+       check_times_61 $file ${tim[@]}
+
+       echo XXXXXX > $file || error "write $tfile failed"
+
+       echo "normal user resync $tfile and test timestamps"
+       tim=( $(get_times_61 $file) )
+       $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
+       check_times_61 $file ${tim[@]}
+}
+run_test 61c "mirror resync preserves timestamps"
+
 test_70() {
        local tf=$DIR/$tdir/$tfile
 
@@ -2683,8 +3073,8 @@ resync_file_200() {
                echo -n "resync file $tf with '$cmd' .."
 
                if [[ $lock_taken = "true" ]]; then
-                       flock -x 200 -c "$cmd $tf &> /dev/null" &&
-                               echo "done" || echo "failed"
+                       flock -x 200
+                       $cmd $tf &> /dev/null && echo "done" || echo "failed"
                        flock -u 200
                else
                        $cmd $tf &> /dev/null && echo "done" || echo "failed"
@@ -2755,7 +3145,7 @@ test_200() {
        rm -f $lock_file
 
        # resync and verify mirrors
-       mirror_io resync $tf
+       $LFS mirror resync $tf || error "final resync failed"
        get_mirror_ids $tf
 
        local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
@@ -2808,7 +3198,7 @@ test_201() {
 
                [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
 
-               mirror_io resync $file
+               $LFS mirror resync $file
                echo "$file resync done"
        done
 
@@ -3364,6 +3754,131 @@ test_207() {
 }
 run_test 207 "create another replica with existing out-of-sync one"
 
+function check_ost_used() {
+       local ddarg
+       local ost
+       local i
+       local file=$1
+       local io=$2
+
+       shift 2
+
+       cancel_lru_locks osc # to drop pages
+       cancel_lru_locks mdc # to refresh layout
+       # XXX: cancel_lru_locks mdc doesn't work
+       # XXX: need a better way to reload the layout
+       umount_client $MOUNT || error "umount failed"
+       mount_client $MOUNT || error "mount failed"
+
+       # refresh non-rotation status on MDTs
+       sleep 10
+       touch $DIR/$tfile-temp
+       rm -f $DIR/$tfile-temp
+       # refresh non-rotational status on the client
+       $LFS df >&/dev/null
+       sleep 2
+
+       $LCTL set_param osc.*.stats=clear >/dev/null
+       if [[ $io == "read" ]]; then
+               ddarg="if=$file of=/dev/null"
+       elif [[ $io == "write" ]]; then
+               ddarg="if=/dev/zero of=$file"
+       else
+               error "unknown type $io"
+       fi
+       dd $ddarg bs=2M count=1 || error "can't $io $file"
+       cancel_lru_locks osc
+
+       # check only specified OSTs got reads
+       for ((ost = 0; ost < $OSTCOUNT; ost++)); do
+               local nr=$($LCTL get_param -n \
+                       osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
+                       awk "/ost_$io/{print \$2}")
+               nr=${nr:-0}
+               if [[ " $* " =~ " $ost " ]]; then
+                       (( nr > 0 )) || error "expected reads on $ost"
+               else
+                       (( nr == 0 )) || error "unexpected $nr reads on $ost"
+               fi
+       done
+}
+
+test_208a() {
+       local tf=$DIR/$tfile
+       local osts=$(comma_list $(osts_nodes))
+
+       (( $OSTCOUNT >= 4 )) || skip_env "needs >= 4 OSTs"
+
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+
+       save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
+       stack_trap "restore_lustre_params < $p; rm -f $p"
+
+       stack_trap "rm -f $tf"
+       $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
+       dd if=/dev/zero of=$tf bs=2M count=1 || error "can't dd (1)"
+       $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
+       $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
+       $LFS mirror resync $tf || error "can't resync"
+       $LFS getstripe $tf
+
+       log "set OST0000 non-rotational"
+       do_nodes $osts \
+               $LCTL set_param osd*.*OST0000*.nonrotational=1
+       check_ost_used $tf read 0
+
+       log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
+       do_nodes $osts \
+               $LCTL set_param osd*.*OST0002*.nonrotational=1 \
+                       osd*.*OST0003*.nonrotational=1
+       check_ost_used $tf read 2 3
+
+       log "set mirror 1 on OST0001 preferred"
+       $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
+               error "can't set prefer"
+       check_ost_used $tf read 1
+}
+run_test 208a "mirror selection to prefer non-rotational devices for reads"
+
+test_208b() {
+       local tf=$DIR/$tfile
+       local osts=$(comma_list $(osts_nodes))
+
+       (( $OSTCOUNT >= 4 )) || skip_env "needs >= 4 OSTs"
+
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+
+       save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
+       stack_trap "restore_lustre_params < $p; rm -f $p"
+
+       stack_trap "rm -f $tf"
+       $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
+       dd if=/dev/zero of=$tf bs=2M count=1 || error "can't dd (1)"
+       $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
+       $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
+       $LFS mirror resync $tf || error "can't resync"
+       $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
+
+       log "set OST0000 non-rotational"
+       do_nodes $osts \
+               $LCTL set_param osd*.*OST0000*.nonrotational=1
+       check_ost_used $tf write 0
+       $LFS mirror resync $tf || error "can't resync"
+
+       log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
+       do_nodes $osts \
+               $LCTL set_param osd*.*OST0002*.nonrotational=1 \
+                       osd*.*OST0003*.nonrotational=1
+       check_ost_used $tf write 2 3
+       $LFS mirror resync $tf || error "can't resync"
+
+       log "set mirror 1 on OST0001 preferred"
+       $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
+               error "can't set prefer"
+       check_ost_used $tf write 1
+}
+run_test 208b "mirror selection to prefer non-rotational devices for writes"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status