+test_31() {
+ local tf=$DIR/$tfile
+
+ $LFS mirror create -N -o 0 -N -o 1 $tf ||
+ error "creating mirrored file $tf failed"
+
+ #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
+ $LCTL set_param fail_loc=0x1A00
+
+ local ost_idx
+ for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
+ cancel_lru_locks osc
+ stop_osts $ost_idx
+
+ local tmpfile=$(mktemp)
+ stat --format="%b %s" $tf > $tmpfile &
+ local pid=$!
+
+ local cnt=0
+ while [ $cnt -le 5 ]; do
+ kill -0 $pid > /dev/null 2>&1 || break
+ sleep 1
+ ((cnt += 1))
+ done
+ kill -0 $pid > /dev/null 2>&1 &&
+ error "stat process stuck due to unavailable OSTs"
+
+ # make sure glimpse request has been sent
+ [ $(get_osc_lock_count 1 2) -ne 0 ] ||
+ error "OST $ost_idx: no glimpse request was sent"
+
+ start_osts $ost_idx
+ done
+}
+run_test 31 "make sure glimpse request can be retried"
+
+test_32() {
+ [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
+ rm -f $DIR/$tfile $DIR/$tfile-2
+
+ $LFS setstripe -E EOF -o 0 $DIR/$tfile
+ dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
+
+ local fsize=$(stat -c %s $DIR/$tfile)
+ [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
+
+ local cksum=$(md5sum $DIR/$tfile)
+
+ # create a new mirror in sync mode
+ $LFS mirror extend -N -o 1 $DIR/$tfile ||
+ error "extending mirrored file $DIR/$tfile failed"
+
+ # make sure the mirrored file was created successfully
+ [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
+ { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
+
+ drop_client_cache
+ stop_osts 1
+
+ # check size is correct, glimpse request should go to the 2nd mirror
+ $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
+ error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
+
+ echo "reading file from the 2nd mirror and verify checksum"
+ [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
+ error "checksum error: expected $cksum"
+
+ start_osts 1
+}
+run_test 32 "data should be mirrored to newly created mirror"
+
+test_33() {
+ [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
+
+ rm -f $DIR/$tfile $DIR/$tfile-2
+
+ # create a file with two mirrors
+ $LFS setstripe -E EOF -o 0 $DIR/$tfile
+ local max_count=100
+ local count=0
+ while [ $count -lt $max_count ]; do
+ echo "ost1" >> $DIR/$tfile
+ count=$((count + 1));
+ done
+
+ # tmp file that will be used as mirror
+ $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
+ count=0
+ while [ $count -lt $max_count ]; do
+ echo "ost2" >> $DIR/$tfile-2
+ count=$((count + 1));
+ done
+
+ # create a mirrored file
+ $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
+ error "merging $DIR/$tfile-2 into $DIR/$tfile" \
+ "with verification should fail"
+ $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
+ error "merging $DIR/$tfile-2 into $DIR/$tfile" \
+ "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 $DIR/$tfile; error "expected count 2"; }
+
+ [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
+
+ # execpted file size
+ local fsize=$((5 * max_count))
+ $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
+ error "mirrored file size is not $fsize"
+
+ # read file - all OSTs are available
+ echo "reading file (data can be provided by any ost)... "
+ local rs=$(cat $DIR/$tfile | head -1)
+ [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
+ error "file content error: expected: \"ost1\" or \"ost2\""
+
+ # read file again with ost1 failed
+ stop_osts 1
+ drop_client_cache
+
+ echo "reading file (data should be provided by ost2)..."
+ local rs=$(cat $DIR/$tfile | head -1)
+ [[ "$rs" == "ost2" ]] ||
+ error "file content error: expected: \"ost2\", actual: \"$rs\""
+
+ # remount ost1
+ start_osts 1
+
+ # read file again with ost2 failed
+ $LCTL set_param ldlm.namespaces.lustre-*-osc-ffff*.lru_size=clear
+
+ fail ost2 &
+ sleep 1
+
+ # check size, glimpse should work
+ $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
+ error "mirrored file size is not $fsize"
+
+ echo "reading file (data should be provided by ost1)..."
+ local rs=$(cat $DIR/$tfile | head -1)
+ [[ "$rs" == "ost1" ]] ||
+ error "file content error: expected: \"ost1\", actual: \"$rs\""
+
+ wait_osc_import_state client ost2 FULL
+}
+run_test 33 "read can choose available mirror to read"
+
+test_34a() {
+ [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
+
+ rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
+
+ # reference file
+ $LFS setstripe -o 0 $DIR/$tfile-ref
+ dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
+
+ # create a file with two mirrors
+ $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
+ dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
+
+ $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
+ dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
+
+ $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
+ error "mirrored file size is not 3M"
+
+ # merge a mirrored file
+ $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
+ error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
+
+ cancel_lru_locks osc
+
+ # stop two OSTs, so the 2nd stripe of the 1st mirror and
+ # the 1st stripe of the 2nd mirror will be inaccessible, ...
+ stop_osts 2 3
+
+ echo "comparing files ... "
+
+ # however, read can still return the correct data. It should return
+ # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
+ cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
+ $DIR/$tfile-ref || error "file reading error"
+
+ start_osts 2 3
+}
+run_test 34a "read mirrored file with multiple stripes"
+
+test_34b() {
+ [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
+
+ rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
+
+ # reference file
+ $LFS setstripe -o 0 $DIR/$tfile-ref
+ dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
+
+ $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
+ dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
+
+ $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
+ dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
+
+ $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
+ error "mirrored file size is not 3M"
+
+ # merge a mirrored file
+ $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
+ error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
+
+ cancel_lru_locks osc
+
+ # stop two OSTs, so the 2nd component of the 1st mirror and
+ # the 1st component of the 2nd mirror will be inaccessible, ...
+ stop_osts 2 3
+
+ echo "comparing files ... "
+
+ # however, read can still return the correct data. It should return
+ # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
+ cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
+ $DIR/$tfile-ref || error "file reading error"
+
+ start_osts 2 3
+}
+run_test 34b "read mirrored file with multiple components"
+
+test_35() {
+ local tf=$DIR/$tfile
+
+ $LFS setstripe -E eof $tf
+
+ # add an out-of-sync mirror to the file
+ $LFS mirror extend -N -c 2 $tf ||
+ error "extending mirrored file $tf failed"
+
+ $MULTIOP $tf oO_WRONLY:c ||
+ error "write open a mirrored file failed"
+
+ # truncate file should return error
+ $TRUNCATE $tf 100 || error "error truncating a mirrored file"
+}
+run_test 35 "allow to write to mirrored files"
+
+verify_ost_layout_version() {
+ local tf=$1
+
+ # get file layout version
+ local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
+
+ # layout version from OST objects
+ local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
+
+ [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
+}
+
+create_file_36() {
+ local tf
+
+ for tf in "$@"; do
+ $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"
+ done
+}
+
+test_36() {
+ local tf=$DIR/$tfile
+
+ create_file_36 $tf $tf-2 $tf-3
+
+ [ $(get_mirror_ids $tf) -gt 1 ] || error "wrong mirror count"
+
+ # test case 1 - check file write and verify layout version
+ $MULTIOP $tf oO_WRONLY:c ||
+ error "write open a mirrored file failed"
+
+ # write open file should not return error
+ $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
+
+ # instantiate components should work
+ dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
+
+ # verify OST layout version
+ verify_ost_layout_version $tf
+
+ # test case 2
+ local mds_idx=mds$(($($LFS getstripe -m $tf-2) + 1))
+
+ local delay_sec=10
+ do_facet $mds_idx $LCTL set_param fail_val=$delay_sec
+
+ #define OBD_FAIL_FLR_LV_DELAY 0x1A01
+ do_facet $mds_idx $LCTL set_param fail_loc=0x1A01
+
+ # write should take at least $fail_loc seconds and succeed
+ local st=$(date +%s)
+ $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
+
+ [ $(date +%s) -ge $((st+delay_sec)) ] ||
+ error "write finished before layout version is transmitted"
+
+ # verify OST layout version
+ verify_ost_layout_version $tf
+
+ do_facet $mds_idx $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
+
+ # 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
+}
+run_test 36 "write to mirrored files"
+
+create_files_37() {
+ local tf
+ local fsize=$1
+
+ echo "create test files with size $fsize .."
+
+ shift
+ for tf in "$@"; do
+ $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
+ done
+}
+
+test_37()
+{
+ local tf=$DIR/$tfile
+ local tf2=$DIR/$tfile-2
+ local tf3=$DIR/$tfile-3
+
+ create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
+
+ # 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' ')
+
+ printf '%s\n' "${checksums[@]}"
+
+ # merge these files into a mirrored file
+ $LFS mirror extend --no-verify -N -f $tf2 $tf ||
+ error "merging $tf2 into $tf failed"
+ $LFS mirror extend --no-verify -N -f $tf3 $tf ||
+ error "merging $tf3 into $tf failed"
+
+ get_mirror_ids $tf
+
+ # verify mirror read, checksums should equal to the original files'
+ echo "Verifying mirror read .."
+
+ local sum
+ for i in ${mirror_array[@]}; do
+ sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
+ [ "$sum" = "${checksums[$i]}" ] ||
+ error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
+ done
+
+ # 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
+
+ # 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" = "${checksums[1]}" ] ||
+ error "$i: mismatch checksum after copy"
+ done
+
+ rm -f $tf
+}
+run_test 37 "mirror I/O API verification"
+
+verify_flr_state()
+{
+ local tf=$1
+ local expected_state=$2
+
+ local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
+ [ $expected_state = $state ] ||
+ error "expected: $expected_state, actual $state"
+}
+
+test_38() {
+ local tf=$DIR/$tfile
+ local ref=$DIR/${tfile}-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 \
+ $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 ||
+ error "merging $tf-2 into $tf failed"
+ $LFS mirror extend -N -f $tf-3 $tf ||
+ error "merging $tf-3 into $tf failed"
+ $LFS mirror extend -N -c 1 $tf ||
+ error "extending mirrored file $tf failed"
+
+ verify_flr_state $tf "ro"
+
+ dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
+
+ local fsize=$((RANDOM << 8 + 1048576))
+ $TRUNCATE $ref $fsize
+
+ local ref_cksum=$(md5sum $ref | cut -f 1 -d' ')
+
+ # 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' ')
+ [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
+
+ get_mirror_ids $tf
+ echo "mirror IDs: ${mirror_array[@]}"
+
+ 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' ')
+ [ "$ref_cksum" == "$mirror_cksum" ] &&
+ { valid_mirror=$id; continue; }
+
+ stale_mirror=$id
+ done
+
+ [ -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"
+ verify_flr_state $tf "ro"
+
+ mirror_cksum=$(mirror_io dump -i $stale_mirror $tf |
+ md5sum | cut -f 1 -d' ')
+ [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
+
+ # case 2: inject an error to make mirror_io exit after changing
+ # the file state to sync_pending so that we can start a concurrent
+ # write.
+ $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
+ verify_flr_state $tf "wp"
+
+ mirror_io resync -e resync_start $tf && error "resync succeeded"
+ verify_flr_state $tf "sp"
+
+ # from sync_pending to write_pending
+ $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
+ verify_flr_state $tf "wp"
+
+ mirror_io resync -e resync_start $tf && error "resync succeeded"
+ verify_flr_state $tf "sp"
+
+ # from sync_pending to read_only
+ mirror_io resync $tf || error "resync failed"
+ verify_flr_state $tf "ro"
+}
+run_test 38 "resync"
+
+test_39() {
+ local tf=$DIR/$tfile
+
+ rm -f $tf
+ $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
+ error "create PFL file $tf failed"
+
+ verify_mirror_count $tf 2
+ verify_comp_count $tf 4
+
+ rm -f $tf || error "delete $tf failed"
+}
+run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
+
+test_40() {
+ local tf=$DIR/$tfile
+ local ops
+
+ for ops in "conv=notrunc" ""; do
+ rm -f $tf
+
+ $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"
+
+ lfs getstripe -vy $tf
+
+ local flags
+
+ # file mirror state should be write_pending
+ flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
+ [ $flags = wp ] ||
+ error "file mirror state $flags"
+ # the 1st component (in mirror 1) should be inited
+ verify_comp_attr lcme_flags $tf 0x10001 init
+ # 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 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
+ verify_comp_attr lcme_flags $tf 0x20005 0
+ # the 6th component (in mirror 2) should be stale
+ verify_comp_attr lcme_flags $tf 0x20006 stale
+ # the 7th component (in mirror 2) should be uninited
+ if [[ x$ops = "xconv=notrunc" ]]; then
+ verify_comp_attr lcme_flags $tf 0x20007 0
+ elif [[ x$ops = "x" ]]; then
+ verify_comp_attr lcme_flags $tf 0x20007 stale
+ fi
+ done
+
+ rm -f $tf || error "delete $tf failed"
+}
+run_test 40 "PFLR rdonly state instantiation check"
+
+test_41() {
+ local tf=$DIR/$tfile
+
+ 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 \
+ -N -E 1M -E 2M -E 3M -E -1 $tf ||
+ error "create PFLR file $tf failed"
+ $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"
+
+ # write data in [0, 2M)
+ dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
+ error "writing $tf failed"
+ 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)
+
+write_file_200() {
+ local tf=$1
+
+ local fsize=$(stat --printf=%s $tf)
+
+ while [ -f $ctrl_file ]; do
+ local off=$((RANDOM << 8))
+ local len=$((RANDOM << 5 + 131072))
+
+ [ $((off + len)) -gt $fsize ] && {
+ fsize=$((off + len))
+ echo "Extending file size to $fsize .."
+ }
+
+ flock -s $lock_file -c \
+ "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
+ { rm -f $ctrl_file;
+ error "failed writing to $off:$len"; }
+ sleep 0.$((RANDOM % 2 + 1))
+ done
+}
+
+read_file_200() {
+ local tf=$1
+
+ while [ -f $ctrl_file ]; do
+ flock -s $lock_file -c "cat $tf &> /dev/null" ||
+ { rm -f $ctrl_file; error "read failed"; }
+ sleep 0.$((RANDOM % 2 + 1))
+ done
+}
+
+resync_file_200() {
+ local tf=$1
+
+ options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
+
+ exec 200<>$lock_file
+ while [ -f $ctrl_file ]; do
+ local lock_taken=false
+ local index=$((RANDOM % ${#options[@]}))
+ local cmd="mirror_io resync ${options[$index]}"
+
+ [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
+
+ [ $((RANDOM % 4)) -eq 0 ] && {
+ index=0
+ lock_taken=true
+ echo -n "lock to "
+ }
+
+ echo -n "resync file $tf with '$cmd' .."
+
+ $lock_taken && flock -x 200
+ $cmd $tf &> /dev/null && echo "done" || echo "failed"
+ $lock_taken && flock -u 200
+
+ sleep 0.$((RANDOM % 8 + 1))
+ done
+}
+
+test_200() {
+ local tf=$DIR/$tfile
+ local tf2=$DIR2/$tfile
+ local tf3=$DIR3/$tfile
+
+ $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 ||
+ error "merging $tf-2 into $tf failed"
+ $LFS mirror extend -N -f $tf-3 $tf ||
+ error "merging $tf-3 into $tf failed"
+
+ mkdir -p $MOUNT2 && mount_client $MOUNT2
+
+ mkdir -p $MOUNT3 && mount_client $MOUNT3
+
+ verify_flr_state $tf3 "ro"
+
+ #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
+ $LCTL set_param fail_loc=0x1A03
+
+ local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
+ do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
+
+ declare -a pids
+
+ write_file_200 $tf &
+ pids+=($!)
+
+ read_file_200 $tf &
+ pids+=($!)
+
+ write_file_200 $tf2 &
+ pids+=($!)
+
+ read_file_200 $tf2 &
+ pids+=($!)
+
+ resync_file_200 $tf3 &
+ pids+=($!)
+
+ local sleep_time=60
+ [ "$SLOW" = "yes" ] && sleep_time=360
+ while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
+ sleep 1
+ ((--sleep_time))
+ done
+
+ rm -f $ctrl_file
+
+ echo "Waiting ${pids[@]}"
+ wait ${pids[@]}
+
+ umount_client $MOUNT2
+ umount_client $MOUNT3
+
+ rm -f $lock_file
+
+ # resync and verify mirrors
+ mirror_io resync $tf
+ get_mirror_ids $tf
+
+ local csum=$(mirror_io dump -i ${mirror_array[0]} $tf | md5sum)
+ for id in ${mirror_array[@]:1}; do
+ [ "$(mirror_io dump -i $id $tf | md5sum)" = "$csum" ] ||
+ error "checksum error for mirror $id"
+ done
+
+ true
+}
+run_test 200 "stress test"
+
+cleanup_test_201() {
+ trap 0
+ do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
+
+ umount_client $MOUNT2
+}
+
+test_201() {
+ local delay=${RESYNC_DELAY:-5}
+
+ MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
+ awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
+
+ trap cleanup_test_201 EXIT
+
+ CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+ changelog_register -n)
+
+ mkdir -p $MOUNT2 && mount_client $MOUNT2
+
+ local index=0
+ while :; do
+ local log=$($LFS changelog $MDT0 $index | grep FLRW)
+ [ -z "$log" ] && { sleep 1; continue; }
+
+ index=$(echo $log | awk '{print $1}')
+ local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
+ local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
+ local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
+
+ ((++index))
+ [ -z "$file" ] && continue
+
+ local now=$(date +%s)
+
+ echo "file: $file $fid was modified at $ts, now: $now, " \
+ "will be resynced at $((ts+delay))"
+
+ [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
+
+ mirror_io resync $file
+ echo "$file resync done"
+ done
+
+ cleanup_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"
+