Whamcloud - gitweb
LU-10829 utils: don't print lmm_stripe_offset for DoM layout
[fs/lustre-release.git] / lustre / tests / sanity-flr.sh
index abf81d5..722d100 100644 (file)
@@ -19,6 +19,9 @@ init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
 init_logging
 
+[[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
+       { skip "Need MDS version at least 2.10.56"; exit 0; }
+
 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
        error "\$RUNAS_ID set to 0, but \$UID is also 0!"
 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
@@ -29,6 +32,9 @@ assert_DIR
 
 build_test_filter
 
+assert_DIR
+rm -rf $DIR/[Rdfs][0-9]*
+
 # global array to store mirror IDs
 declare -a mirror_array
 get_mirror_ids() {
@@ -133,6 +139,18 @@ verify_comp_attr() {
 
        value=$(eval $cmd)
 
+       [ $attr = lcme_flags ] && {
+               local fl
+               local expected_list=$(comma_list $expected)
+               for fl in ${expected_list//,/ }; do
+                       echo $value | grep -q $fl || {
+                               $getstripe_cmd $tf
+                               error "expected flag $fl existing on $comp_id"
+                       }
+               done
+               return
+       }
+
        [[ $value = $expected ]] || {
                $getstripe_cmd $tf
                error "verify $attr failed on $tf: $value != $expected"
@@ -190,18 +208,56 @@ verify_comp_attr_with_parent() {
 }
 
 #
-# Verify component attributes with parent directory for a given file
+# Verify component attribute with filesystem-wide default value for a given file
+# and component ID.
+#
+verify_comp_attr_with_default() {
+       local attr=$1
+       local tf=$2
+       local comp_id=$3
+       local tf_cmd="$LFS getstripe -I$comp_id"
+       local opt
+       local expected
+       local value
+
+       case $attr in
+               stripe-size)
+                       opt="-S"
+                       expected=$($LCTL get_param -n \
+                                  lov.$FSNAME-clilov-*.stripesize)
+                       ;;
+               stripe-count)
+                       opt="-c"
+                       expected=$($LCTL get_param -n \
+                                  lov.$FSNAME-clilov-*.stripecount)
+                       [[ $expected = -1 ]] && expected=$OSTCOUNT
+                       ;;
+               *) error "invalid attribute $attr";;
+       esac
+
+       value=$($tf_cmd $opt $tf)
+       [[ $value = -1 ]] && value=$OSTCOUNT
+
+       [[ $value = $expected ]] || {
+               $tf_cmd -v $tf
+               error "verify $attr failed with default value on $tf:" \
+                     "$value != $expected"
+       }
+}
+
+#
+# Verify unspecified component attributes for a given file
 # and component ID.
 #
 # This will only verify the inherited attributes:
 # stripe size, stripe count and OST pool name
 #
-verify_comp_attrs_with_parent() {
+verify_comp_attrs() {
        local tf=$1
        local comp_id=$2
 
-       verify_comp_attr_with_parent stripe-size $tf $comp_id
-       verify_comp_attr_with_parent stripe-count $tf $comp_id
+       verify_comp_attr_with_default stripe-size $tf $comp_id
+       verify_comp_attr_with_default stripe-count $tf $comp_id
        verify_comp_attr_with_parent pool $tf $comp_id
 }
 
@@ -223,7 +279,7 @@ test_0a() {
        $mirror_cmd -N $tf || error "create mirrored file $tf failed"
        verify_mirror_count $tf 1
        id=$($LFS getstripe -I $tf)
-       verify_comp_attrs_with_parent $tf $id
+       verify_comp_attrs $tf $id
        verify_comp_extent $tf $id 0 EOF
 
        $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
@@ -235,7 +291,7 @@ test_0a() {
        verify_mirror_count $tf-1 $mirror_count
        ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
        for ((i = 0; i < $mirror_count; i++)); do
-               verify_comp_attrs_with_parent $tf-1 ${ids[$i]}
+               verify_comp_attrs $tf-1 ${ids[$i]}
                verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
        done
 
@@ -244,7 +300,7 @@ test_0a() {
        verify_mirror_count $tf-2 10
        ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
        for ((i = 0; i < 10; i++)); do
-               verify_comp_attrs_with_parent $tf-2 ${ids[$i]}
+               verify_comp_attrs $tf-2 ${ids[$i]}
                verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
        done
 }
@@ -259,42 +315,61 @@ test_0b() {
        local ids
        local i
 
+       # create a new OST pool
+       local pool_name=$TESTNAME
+       create_pool $FSNAME.$pool_name ||
+               error "create OST pool $pool_name failed"
+
+       # add OSTs into the pool
+       pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
+               error "add OSTs into pool $pool_name failed"
+
        # create parent directory
        mkdir $td || error "mkdir $td failed"
+       $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
+               error "$LFS setstripe $td failed"
 
        # create a mirrored file with plain layout mirrors
-       $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
-                   -N -S 16M -N -c -1 -N -p archive -N --parent $tf ||
+       $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
+                   -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
                error "create mirrored file $tf failed"
-       verify_mirror_count $tf 5
+       verify_mirror_count $tf 6
        ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
-       for ((i = 0; i < 5; i++)); do
+       for ((i = 0; i < 6; i++)); do
                verify_comp_extent $tf ${ids[$i]} 0 EOF
        done
 
        # verify component ${ids[0]}
-       verify_comp_attr stripe-size $tf ${ids[0]} 4194304
-       verify_comp_attr stripe-count $tf ${ids[0]} 2
-       verify_comp_attr stripe-index $tf ${ids[0]} 2
-       verify_comp_attr pool $tf ${ids[0]} flash
+       verify_comp_attrs $tf ${ids[0]}
 
        # verify component ${ids[1]}
-       verify_comp_attr stripe-size $tf ${ids[1]} 16777216
+       verify_comp_attr stripe-size $tf ${ids[1]} 4194304
        verify_comp_attr stripe-count $tf ${ids[1]} 2
+       verify_comp_attr stripe-index $tf ${ids[1]} 2
        verify_comp_attr pool $tf ${ids[1]} flash
 
        # verify component ${ids[2]}
        verify_comp_attr stripe-size $tf ${ids[2]} 16777216
-       verify_comp_attr stripe-count $tf ${ids[2]} $OSTCOUNT
+       verify_comp_attr stripe-count $tf ${ids[2]} 2
        verify_comp_attr pool $tf ${ids[2]} flash
 
        # verify component ${ids[3]}
        verify_comp_attr stripe-size $tf ${ids[3]} 16777216
        verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
-       verify_comp_attr pool $tf ${ids[3]} archive
+       verify_comp_attr pool $tf ${ids[3]} flash
 
        # verify component ${ids[4]}
-       verify_comp_attrs_with_parent $tf ${ids[4]}
+       verify_comp_attr stripe-size $tf ${ids[4]} 16777216
+       verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
+       verify_comp_attr pool $tf ${ids[4]} archive
+
+       # verify component ${ids[5]}
+       verify_comp_attr stripe-size $tf ${ids[5]} 16777216
+       verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
+       verify_comp_attr_with_parent pool $tf ${ids[5]}
+
+       # destroy OST pool
+       destroy_test_pools
 }
 run_test 0b "lfs mirror create plain layout mirrors"
 
@@ -307,12 +382,23 @@ test_0c() {
        local ids
        local i
 
+       # create a new OST pool
+       local pool_name=$TESTNAME
+       create_pool $FSNAME.$pool_name ||
+               error "create OST pool $pool_name failed"
+
+       # add OSTs into the pool
+       pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
+               error "add OSTs into pool $pool_name failed"
+
        # create parent directory
        mkdir $td || error "mkdir $td failed"
+       $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
+               error "$LFS setstripe $td failed"
 
        # create a mirrored file with composite layout mirrors
        $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
-                   -N --parent \
+                   -N -c 4 -p none \
                    -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
                error "create mirrored file $tf failed"
        verify_mirror_count $tf 6
@@ -320,7 +406,7 @@ test_0c() {
 
        # verify components ${ids[0]} and ${ids[2]}
        for i in 0 2; do
-               verify_comp_attr_with_parent stripe-size $tf ${ids[$i]}
+               verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
                verify_comp_attr stripe-count $tf ${ids[$i]} 2
                verify_comp_attr stripe-index $tf ${ids[$i]} 1
                verify_comp_attr pool $tf ${ids[$i]} flash
@@ -336,13 +422,15 @@ test_0c() {
        done
 
        # verify component ${ids[4]}
-       verify_comp_attrs_with_parent $tf ${ids[4]}
+       verify_comp_attr stripe-size $tf ${ids[4]} 4194304
+       verify_comp_attr stripe-count $tf ${ids[4]} 4
+       verify_comp_attr_with_parent pool $tf ${ids[4]}
        verify_comp_extent $tf ${ids[4]} 0 EOF
 
        # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
        for i in 5 7 9; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
-               verify_comp_attr_with_parent stripe-count $tf ${ids[$i]}
+               verify_comp_attr stripe-count $tf ${ids[$i]} 4
                verify_comp_attr pool $tf ${ids[$i]} archive
                verify_comp_extent $tf ${ids[$i]} 0 536870912
        done
@@ -354,6 +442,9 @@ test_0c() {
                verify_comp_attr pool $tf ${ids[$i]} archive
                verify_comp_extent $tf ${ids[$i]} 536870912 EOF
        done
+
+       # destroy OST pool
+       destroy_test_pools
 }
 run_test 0c "lfs mirror create composite layout mirrors"
 
@@ -377,10 +468,12 @@ test_0d() {
        verify_mirror_count $tf 2
        ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
        for ((i = 0; i < 2; i++)); do
-               verify_comp_attrs_with_parent $tf ${ids[$i]}
+               verify_comp_attrs $tf ${ids[$i]}
                verify_comp_extent $tf ${ids[$i]} 0 EOF
        done
 
+       lfsck_verify_pfid $tf || error "PFID is not set"
+
        # 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"
@@ -388,15 +481,12 @@ test_0d() {
        $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 -f $tf-2 -N --parent $tf-1 &> /dev/null &&
-               error "--parent option should not be specified with -f option"
-
        $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' ' '))
        for ((i = 0; i < $mirror_count; i++)); do
-               verify_comp_attrs_with_parent $tf-1 ${ids[$i]}
+               verify_comp_attrs $tf-1 ${ids[$i]}
                verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
        done
 
@@ -423,7 +513,7 @@ test_0e() {
 
        # extend the mirrored file with plain layout mirrors
        $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
-                   -N -S 16M -N -c -1 -N -p archive -N --parent $tf ||
+                   -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
                error "extend mirrored file $tf failed"
        verify_mirror_count $tf 6
        ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
@@ -459,7 +549,9 @@ test_0e() {
        verify_comp_attr pool $tf ${ids[4]} archive
 
        # verify component ${ids[5]}
-       verify_comp_attrs_with_parent $tf ${ids[5]}
+       verify_comp_attr stripe-size $tf ${ids[5]} 16777216
+       verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
+       verify_comp_attr_with_parent pool $tf ${ids[5]}
 }
 run_test 0e "lfs mirror extend plain layout mirrors"
 
@@ -481,7 +573,7 @@ test_0f() {
 
        # extend the mirrored file with composite layout mirrors
        $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
-                   -N --parent \
+                   -N -c -1 -p none \
                    -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
                error "extend mirrored file $tf failed"
        verify_mirror_count $tf 7
@@ -489,19 +581,19 @@ test_0f() {
 
        # verify component ${ids[0]}
        verify_comp_attr stripe-size $tf ${ids[0]} 16777216
-       verify_comp_attr_with_parent stripe-count $tf ${ids[0]}
+       verify_comp_attr_with_default stripe-count $tf ${ids[0]}
        verify_comp_attr pool $tf ${ids[0]} ssd
        verify_comp_extent $tf ${ids[0]} 0 33554432
 
        # verify component ${ids[1]}
        verify_comp_attr stripe-size $tf ${ids[1]} 33554432
-       verify_comp_attr_with_parent stripe-count $tf ${ids[1]}
+       verify_comp_attr_with_default stripe-count $tf ${ids[1]}
        verify_comp_attr pool $tf ${ids[1]} ssd
        verify_comp_extent $tf ${ids[1]} 33554432 EOF
 
        # verify components ${ids[2]} and ${ids[4]}
        for i in 2 4; do
-               verify_comp_attr_with_parent stripe-size $tf ${ids[$i]}
+               verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
                verify_comp_attr stripe-count $tf ${ids[$i]} 2
                verify_comp_attr stripe-index $tf ${ids[$i]} 1
                verify_comp_attr pool $tf ${ids[$i]} flash
@@ -517,13 +609,15 @@ test_0f() {
        done
 
        # verify component ${ids[6]}
-       verify_comp_attrs_with_parent $tf ${ids[6]}
+       verify_comp_attr stripe-size $tf ${ids[6]} 4194304
+       verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
+       verify_comp_attr_with_parent pool $tf ${ids[6]}
        verify_comp_extent $tf ${ids[6]} 0 EOF
 
        # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
        for i in 7 9 11; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
-               verify_comp_attr_with_parent stripe-count $tf ${ids[$i]}
+               verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
                verify_comp_attr pool $tf ${ids[$i]} archive
                verify_comp_extent $tf ${ids[$i]} 0 536870912
        done
@@ -538,6 +632,64 @@ test_0f() {
 }
 run_test 0f "lfs mirror extend composite layout mirrors"
 
+test_0g() {
+       local tf=$DIR/$tfile
+
+       $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
+                          -N -o1 $tf || error "create mirrored file $tf failed"
+
+       verify_comp_attr lcme_flags $tf 0x10001 prefer
+       verify_comp_attr lcme_flags $tf 0x10002 prefer
+
+       # write to the mirrored file and check primary
+       cp /etc/hosts $tf || error "error writing file '$tf'"
+
+       verify_comp_attr lcme_flags $tf 0x20003 stale
+
+       # resync file and check prefer flag
+       $LFS mirror resync $tf || error "error resync-ing file '$tf'"
+
+       cancel_lru_locks osc
+       $LCTL set_param osc.*.stats=clear
+       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 |
+                       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
+
+       $LFS mirror create -N -E 1M -S 1M --flags=prefer -E eof -N2 $tf ||
+               error "create mirrored file $tf failed"
+
+       verify_comp_attr lcme_flags $tf 0x10001 prefer
+       verify_comp_attr lcme_flags $tf 0x10002 prefer
+
+       # set flags to the first component
+       $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
+
+       verify_comp_attr lcme_flags $tf 0x10001 stale
+       verify_comp_attr lcme_flags $tf 0x10002 prefer
+
+       $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
+               error "clearing 'stale' should fail"
+
+       # write and resync file. It can't resync the file directly because the
+       # file state is still 'ro'
+       cp /etc/hosts $tf || error "error writing file '$tf'"
+       $LFS mirror resync $tf || error "error resync-ing file '$tf'"
+
+       $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
+               error "error setting flag prefer"
+
+       verify_comp_attr lcme_flags $tf 0x20003 prefer
+}
+run_test 0h "set, clear and test flags for FLR files"
+
 test_1() {
        local tf=$DIR/$tfile
        local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
@@ -575,10 +727,8 @@ test_2() {
        local tf=$DIR/$tfile
        local tf2=$DIR/$tfile-2
 
-       $LFS setstripe -E 1M -E EOF -c 1 $tf
-       $LFS setstripe -E 2M -E EOF -c -1 $tf2
-
-       local layout=$($LFS getstripe $tf2 | grep -A 4 lmm_objects)
+       $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
+       $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
 
        $LFS mirror extend -N -f $tf2 $tf ||
                error "merging $tf2 into $tf failed"
@@ -620,7 +770,7 @@ test_4() {
        test_mkdir $DIR/$tdir
 
        # set mirror with setstripe options to directory
-       $LFS mirror create -N2 -E 1M -E eof $DIR/$tdir ||
+       $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
                error "set mirror to directory error"
 
        [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
@@ -665,17 +815,17 @@ run_test 5 "Make sure init size work for mirrored layout"
 test_6() {
        local tf=$DIR/$tfile
 
-       $LFS mirror create -N -E 1M -L mdt -E eof -N -E eof $tf &&
+       $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 -E eof -N -E 1M -L mdt -E eof $tf &&
+       $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 setstripe -E 1M -L mdt -E eof $tf
+       $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 mirror create -N2 -E 1M -E eof $tf-2
+       $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"
 
@@ -693,9 +843,13 @@ test_21() {
        $LFS setstripe -E EOF -o 1 $tf2
 
        local dd_count=$((RANDOM % 20 + 1))
-       dd if=/dev/zero of=$tf bs=1M count=$dd_count
-       dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1))
-       cancel_lru_locks osc
+       dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
+       dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
+
+       # for zfs - sync OST dataset so that du below will return
+       # accurate results
+       [ "$FSTYPE" = "zfs" ] &&
+               do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
 
        local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
 
@@ -866,10 +1020,10 @@ test_33() {
                error "mirrored file size is not $fsize"
 
        # read file - all OSTs are available
-       echo "reading file (data should be provided by ost1)... "
+       echo "reading file (data can be provided by any ost)... "
        local rs=$(cat $DIR/$tfile | head -1)
-       [[ "$rs" == "ost1" ]] ||
-               error "file content error: expected: \"ost1\", actual: \"$rs\""
+       [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
+               error "file content error: expected: \"ost1\" or \"ost2\""
 
        # read file again with ost1 failed
        stop_osts 1
@@ -1014,8 +1168,8 @@ create_file_36() {
        local tf
 
        for tf in "$@"; do
-               $LFS setstripe -E 1M -E 2M -E 4M -E eof -c -1 $tf
-               $LFS setstripe -E 3M -E 6M -E eof -c -1 $tf-tmp
+               $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
+               $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
 
                $LFS mirror extend -N -f $tf-tmp $tf ||
                        error "merging $tf-tmp into $tf failed"
@@ -1085,7 +1239,7 @@ create_files_37() {
 
        shift
        for tf in "$@"; do
-               $LFS setstripe -E 1M -c 1 -E eof -c -1 $tf
+               $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
 
                dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
                $TRUNCATE $tf $fsize
@@ -1167,9 +1321,12 @@ test_38() {
        local tf=$DIR/$tfile
        local ref=$DIR/${tfile}-ref
 
-       $LFS setstripe -E 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf
-       $LFS setstripe -E 2M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 $tf-2
-       $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3
+       $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 \
+               $tf-2 || error "creating $tf-2 failed"
+       $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
+               error "creating $tf-3 failed"
 
        # instantiate all components
        $LFS mirror extend -N -f $tf-2 $tf ||
@@ -1261,8 +1418,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 -E 2M -S 1M -E 4M -E -1 --flags=prefer \
+                                  -N -E 1M -E 2M -E 4M -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"
 
@@ -1279,7 +1437,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
@@ -1302,12 +1460,17 @@ test_41() {
        local tf=$DIR/$tfile
 
        rm -f $tf $tf-1
-       $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 $tf ||
+       echo " **create two FLR files $tf $tf-1"
+       $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
+                          -N -E 1M -E 2M -E 3M -E -1 $tf ||
                error "create PFLR file $tf failed"
-       $LFS mirror create -N -E4m -E-1 -N -E2m -E3m -E-1 $tf-1 ||
+       $LFS mirror create -N -E 2M -S 1M -E eof \
+                          -N -E 1M -E eof --flags prefer \
+                          -N -E 4m -E eof $tf-1 ||
                error "create PFLR file $tf-1 failed"
 
        # file should be in ro status
+       echo " **verify files be RDONLY"
        verify_flr_state $tf "ro"
        verify_flr_state $tf-1 "ro"
 
@@ -1317,30 +1480,394 @@ test_41() {
        dd if=/dev/zero of=$tf-1 bs=1M count=4 conv=notrunc ||
                error "writing $tf-1 failed"
 
+       echo " **verify files be WRITE_PENDING"
        verify_flr_state $tf "wp"
        verify_flr_state $tf-1 "wp"
 
        # file should have stale component
+       echo " **verify files have stale component"
        $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
                error "after writing $tf, it does not contain stale component"
        $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
                error "after writing $tf-1, it does not contain stale component"
 
+       echo " **full resync"
        $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
 
+       echo " **verify files be RDONLY"
        verify_flr_state $tf "ro"
        verify_flr_state $tf-1 "ro"
 
        # file should not have stale component
+       echo " **verify files do not contain stale component"
        $LFS getstripe $tf | grep lcme_flags | grep stale &&
                error "after resyncing $tf, it contains stale component"
        $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
                error "after resyncing $tf, it contains stale component"
 
+       # verify partial resync
+       echo " **write $tf-1 for partial resync test"
+       dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
+               error "writing $tf-1 failed"
+
+       echo " **only resync mirror 2"
+       verify_flr_state $tf-1 "wp"
+       $LFS mirror resync --only 2 $tf-1 ||
+               error "resync mirror 2 of $tf-1 failed"
+       verify_flr_state $tf "ro"
+
+       # resync synced mirror
+       echo " **resync mirror 2 again"
+       $LFS mirror resync --only 2 $tf-1 ||
+               error "resync mirror 2 of $tf-1 failed"
+       verify_flr_state $tf "ro"
+       echo " **verify $tf-1 contains stale component"
+       $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
+               error "after writing $tf-1, it does not contain stale component"
+
+       echo " **full resync $tf-1"
+       $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
+       verify_flr_state $tf "ro"
+       echo " **full resync $tf-1 again"
+       $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
+       echo " **verify $tf-1 does not contain stale component"
+       $LFS getstripe $tf | grep lcme_flags | grep stale &&
+               error "after resyncing $tf, it contains stale component"
+
        return 0
 }
 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 -S 1M -E 10M -E EOF $tf ||
+               error "create mirrored file $tf failed"
+       $LFS mirror create -N -E 2M -S 1M -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 2M -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 -E 2M -S 1M -E 4M -E -1 \
+                          -N -E 1M -E 2M -E 3M -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"
+
+test_45() {
+       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
+
+       local file=$DIR/$tdir/$tfile
+       local dir=$DIR/$tdir/$dir
+       local temp=$DIR/$tdir/template
+       rm -rf $DIR/$tdir
+       test_mkdir $DIR/$tdir
+
+       $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
+               -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"
+
+       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"
+}
+run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
+
+verify_46() {
+       local src=$1
+       local dst=$2
+       local msg_prefix=$3
+
+       $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
+
+       local layout1=$(get_layout_param $src)
+       local layout2=$(get_layout_param $dst)
+       # compare their layout info
+       [ "$layout1" == "$layout2" ] ||
+               error "$msg_prefix $src <=> $dst layouts are not equal"
+}
+
+test_46() {
+       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
+
+       local file=$DIR/$tdir/$tfile
+       test_mkdir $DIR/$tdir
+
+       ########################### 1. PFL file #############################
+       echo "  ** 1. PFL file"
+       rm -f $file
+       $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
+               $file || error "1. Create PFL $file failed"
+
+       rm -f $file.copy
+       verify_46 $file $file.copy "1. PFL file"
+
+       ########################### 2. plain file ###########################
+       echo "  ** 2. plain file"
+       rm -f $file
+       $LFS setstripe -c2 -o0,1 -i1 $file ||
+               error "2. Create plain $file failed"
+
+       rm -f $file.copy
+       verify_46 $file $file.copy "2. plain file"
+
+       ########################### 3. FLR file #############################
+       echo "  ** 3. FLR file"
+       $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
+               $file || error "3. Create FLR $file failed"
+
+       rm -f $file.copy
+       verify_46 $file $file.copy "3. FLR file"
+
+       local dir=$DIR/$tdir/dir
+       ########################### 4. PFL dir ##############################
+       echo "  ** 4. PFL dir"
+       test_mkdir $dir
+       $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
+               error "4. setstripe PFL $dir failed"
+
+       test_mkdir $dir.copy
+       verify_46 $dir $dir.copy "4. PFL dir"
+
+       ########################### 5. plain dir ############################
+       echo "  ** 5. plain dir"
+       $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
+
+       verify_46 $dir $dir.copy "5. plain dir"
+
+       ########################### 6. FLR dir ##############################
+       echo "  ** 6. FLR dir"
+       $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
+               error "6. setstripe FLR $dir failed"
+
+       verify_46 $dir $dir.copy "6. FLR dir"
+}
+run_test 46 "Verify setstripe --copy option"
+
 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
 
@@ -1410,8 +1937,8 @@ test_200() {
        local tf2=$DIR2/$tfile
        local tf3=$DIR3/$tfile
 
-       $LFS setstripe -E 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
-       $LFS setstripe -E 2M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
+       $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
+       $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
        $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
 
        $LFS mirror extend -N -f $tf-2 $tf ||
@@ -1527,6 +2054,28 @@ test_201() {
 }
 run_test 201 "FLR data mover"
 
+test_202() {
+       [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
+
+       local tf=$DIR/$tfile
+       local ids
+
+       $LFS setstripe -E 1M -S 1M -c 1 $tf
+       ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
+       verify_comp_attr stripe-count $tf ${ids[0]} 1
+
+       $LFS setstripe --component-add -E 2M -c -1 $tf
+       ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
+       verify_comp_attr stripe-count $tf ${ids[0]} 1
+       verify_comp_attr stripe-count $tf ${ids[1]} -1
+
+       dd if=/dev/zero of=$tf bs=1M count=2
+       ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
+       verify_comp_attr stripe-count $tf ${ids[0]} 1
+       verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
+}
+run_test 202 "lfs setstripe --add-component wide striping"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status