3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
16 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT "
17 # Bug number for skipped test: LU-14818 LU-11381 LU-14765
18 ALWAYS_EXCEPT+=" 6 201 44c "
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
21 # skip all tests for PPC until we can get sanity-pfl to pass
22 if [[ $(uname -m) = ppc64 ]]; then
23 skip "Skip FLR testing for PPC clients"
26 if [[ "$ost1_FSTYPE" == "zfs" ]]; then
28 ALWAYS_EXCEPT+=" 49a "
33 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
34 skip "Need MDS version at least 2.10.56"
36 check_and_setup_lustre
39 rm -rf $DIR/[Rdfs][0-9]*
41 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
42 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
47 # global array to store mirror IDs
48 declare -a mirror_array
55 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
56 array[${#array[@]}]=$((id >> 16))
59 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
61 echo ${#mirror_array[@]}
65 echo 3 > /proc/sys/vm/drop_caches
76 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
84 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
85 error "start ost$idx failed"
89 wait_recovery_complete ost$idx
94 # Verify mirror count with an expected value for a given file.
96 verify_mirror_count() {
99 local mirror_count=$($LFS getstripe -N $tf)
101 [[ $mirror_count = $expected ]] || {
102 $LFS getstripe -v $tf
103 error "verify mirror count failed on $tf:" \
104 "$mirror_count != $expected"
109 # Verify component count with an expected value for a given file.
110 # $1 coposited layout file
111 # $2 expected component number
113 verify_comp_count() {
116 local comp_count=$($LFS getstripe --component-count $tf)
118 [[ $comp_count = $expected ]] || {
119 $LFS getstripe -v $tf
120 error "verify component count failed on $tf:" \
121 "$comp_count != $expected"
126 # Verify component attribute with an expected value for a given file
134 local cmd="$LFS getstripe -I$comp_id"
135 local getstripe_cmd="$cmd -v"
139 stripe-size) cmd+=" -S $tf" ;;
140 stripe-count) cmd+=" -c $tf" ;;
141 stripe-index) cmd+=" -i $tf" ;;
142 pool) cmd+=" -p $tf" ;;
143 comp-start) cmd+=" --component-start $tf" ;;
144 comp-end) cmd+=" --component-end $tf" ;;
145 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
146 *) error "invalid attribute $attr";;
151 [ $attr = lcme_flags ] && {
153 local expected_list=$(comma_list $expected)
154 for fl in ${expected_list//,/ }; do
157 [[ ${fl:0:1} = "^" ]] && neg=1
158 [[ $neg = 1 ]] && fl=${fl:1}
160 $(echo $value | grep -q $fl)
162 # 0: matched; 1: not matched
164 if [[ $neg = 0 && $match != 0 ||
165 $neg = 1 && $match = 0 ]]; then
167 [[ $neg = 0 ]] && # expect the flag
168 error "expected flag '$fl' not in $comp_id"
169 [[ $neg = 1 ]] && # not expect the flag
170 error "not expected flag '$fl' in $comp_id"
176 [[ $value = $expected ]] ||
177 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
178 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
180 error "verify $attr failed on $tf: $value != $expected"
185 # Verify component extent with expected start and end extent values
186 # for a given file and component ID.
188 verify_comp_extent() {
191 local expected_start=$3
192 local expected_end=$4
194 verify_comp_attr comp-start $tf $comp_id $expected_start
195 verify_comp_attr comp-end $tf $comp_id $expected_end
199 # Verify component attribute with parent directory for a given file
202 verify_comp_attr_with_parent() {
206 local td=$(cd $(dirname $tf); echo $PWD)
207 local tf_cmd="$LFS getstripe -I$comp_id"
208 local td_cmd="$LFS getstripe"
214 stripe-size) opt="-S" ;;
215 stripe-count) opt="-c" ;;
217 *) error "invalid attribute $attr";;
220 expected=$($td_cmd $opt $td)
221 [[ $expected = -1 ]] && expected=$OSTCOUNT
223 value=$($tf_cmd $opt $tf)
224 [[ $value = -1 ]] && value=$OSTCOUNT
226 [[ $value = $expected ]] ||
227 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
228 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
231 error "verify $attr failed with parent on $tf:" \
232 "$value != $expected"
237 # Verify component attribute with filesystem-wide default value for a given file
240 verify_comp_attr_with_default() {
244 local tf_cmd="$LFS getstripe -I$comp_id"
252 expected=$($LCTL get_param -n \
253 lov.$FSNAME-clilov-*.stripesize)
257 expected=$($LCTL get_param -n \
258 lov.$FSNAME-clilov-*.stripecount)
259 [[ $expected = -1 ]] && expected=$OSTCOUNT
261 *) error "invalid attribute $attr";;
264 value=$($tf_cmd $opt $tf)
265 [[ $value = -1 ]] && value=$OSTCOUNT
267 [[ $value = $expected ]] ||
268 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
269 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
271 error "verify $attr failed with default value on $tf:" \
272 "$value != $expected"
277 # Verify unspecified component attributes for a given file
280 # This will only verify the inherited attributes:
281 # stripe size, stripe count and OST pool name
283 verify_comp_attrs() {
287 verify_comp_attr_with_default stripe-size $tf $comp_id
288 verify_comp_attr_with_default stripe-count $tf $comp_id
289 verify_comp_attr_with_parent pool $tf $comp_id
295 local expected_state=$2
297 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
298 [ $expected_state = $state ] ||
299 error "expected: $expected_state, actual $state"
302 # command line test cases
306 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
307 local mirror_cmd="$LFS mirror create"
312 # create parent directory
313 mkdir $td || error "mkdir $td failed"
315 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
316 verify_mirror_count $tf 1
317 id=$($LFS getstripe -I $tf)
318 verify_comp_attrs $tf $id
319 verify_comp_extent $tf $id 0 EOF
321 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
322 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
323 error "invalid mirror count $((mirror_count + 1))"
325 $mirror_cmd -N$mirror_count $tf-1 ||
326 error "create mirrored file $tf-1 failed"
327 verify_mirror_count $tf-1 $mirror_count
328 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
329 for ((i = 0; i < $mirror_count; i++)); do
330 verify_comp_attrs $tf-1 ${ids[$i]}
331 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
334 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
335 error "create mirrored file $tf-2 failed"
336 verify_mirror_count $tf-2 10
337 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
338 for ((i = 0; i < 10; i++)); do
339 verify_comp_attrs $tf-2 ${ids[$i]}
340 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
343 run_test 0a "lfs mirror create with -N option"
346 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
350 local mirror_cmd="$LFS mirror create"
354 # create a new OST pool
355 local pool_name=$TESTNAME
356 create_pool $FSNAME.$pool_name ||
357 error "create OST pool $pool_name failed"
359 # add OSTs into the pool
360 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
361 error "add OSTs into pool $pool_name failed"
363 # create parent directory
364 mkdir $td || error "mkdir $td failed"
365 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
366 error "$LFS setstripe $td failed"
368 create_pool $FSNAME.flash || error "create OST pool flash failed"
369 create_pool $FSNAME.archive || error "create OST pool archive failed"
371 # create a mirrored file with plain layout mirrors
372 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
373 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
374 error "create mirrored file $tf failed"
375 verify_mirror_count $tf 6
376 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
377 for ((i = 0; i < 6; i++)); do
378 verify_comp_extent $tf ${ids[$i]} 0 EOF
381 # verify component ${ids[0]}
382 verify_comp_attrs $tf ${ids[0]}
384 # verify component ${ids[1]}
385 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
386 verify_comp_attr stripe-count $tf ${ids[1]} 2
387 verify_comp_attr stripe-index $tf ${ids[1]} 2
389 # verify component ${ids[2]}
390 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
391 verify_comp_attr stripe-count $tf ${ids[2]} 2
392 verify_comp_attr pool $tf ${ids[2]} flash
394 # verify component ${ids[3]}
395 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
396 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
397 verify_comp_attr pool $tf ${ids[3]} flash
399 # verify component ${ids[4]}
400 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
401 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
402 verify_comp_attr pool $tf ${ids[4]} archive
404 # verify component ${ids[5]}
405 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
406 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
407 verify_comp_attr_with_parent pool $tf ${ids[5]}
409 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
410 # LU-11022 - remove mirror by pool name
411 local cnt=$($LFS getstripe $tf | grep archive | wc -l)
412 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
413 $LFS mirror delete --pool archive $tf || error "delete mirror"
414 cnt=$($LFS getstripe $tf | grep archive | wc -l)
415 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
421 run_test 0b "lfs mirror create plain layout mirrors"
424 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
428 local mirror_cmd="$LFS mirror create"
432 # create a new OST pool
433 local pool_name=$TESTNAME
434 create_pool $FSNAME.$pool_name ||
435 error "create OST pool $pool_name failed"
437 # add OSTs into the pool
438 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
439 error "add OSTs into pool $pool_name failed"
441 # create parent directory
442 mkdir $td || error "mkdir $td failed"
443 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
444 error "$LFS setstripe $td failed"
446 create_pool $FSNAME.flash ||
447 error "create OST pool flash failed"
448 create_pool $FSNAME.archive ||
449 error "create OST pool archive failed"
451 # create a mirrored file with composite layout mirrors
452 $mirror_cmd -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
454 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
455 error "create mirrored file $tf failed"
456 verify_mirror_count $tf 6
457 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
459 # verify components ${ids[0]} and ${ids[2]}
461 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
462 verify_comp_attr stripe-count $tf ${ids[$i]} 2
463 verify_comp_attr stripe-index $tf ${ids[$i]} 1
464 verify_comp_extent $tf ${ids[$i]} 0 8388608
467 # verify components ${ids[1]} and ${ids[3]}
469 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
470 verify_comp_attr stripe-count $tf ${ids[$i]} 2
471 verify_comp_attr pool $tf ${ids[$i]} flash
472 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
475 # verify component ${ids[4]}
476 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
477 verify_comp_attr stripe-count $tf ${ids[4]} 4
478 verify_comp_attr_with_parent pool $tf ${ids[4]}
479 verify_comp_extent $tf ${ids[4]} 0 EOF
481 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
483 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
484 verify_comp_attr stripe-count $tf ${ids[$i]} 4
485 verify_comp_attr pool $tf ${ids[$i]} archive
486 verify_comp_extent $tf ${ids[$i]} 0 536870912
489 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
491 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
492 verify_comp_attr stripe-count $tf ${ids[$i]} -1
493 verify_comp_attr pool $tf ${ids[$i]} archive
494 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
500 run_test 0c "lfs mirror create composite layout mirrors"
505 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
506 local mirror_cmd="$LFS mirror extend"
510 # create parent directory
511 mkdir $td || error "mkdir $td failed"
513 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
515 # create a non-mirrored file, convert it to a mirrored file and extend
516 touch $tf || error "touch $tf failed"
517 $mirror_cmd -N $tf || error "convert and extend $tf failed"
518 verify_mirror_count $tf 2
519 $mirror_cmd $tf || error "extend $tf without --mirror-count|-N failed"
520 verify_mirror_count $tf 3
521 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
522 for ((i = 0; i < 3; i++)); do
523 verify_comp_attrs $tf ${ids[$i]}
524 verify_comp_extent $tf ${ids[$i]} 0 EOF
527 lfsck_verify_pfid $tf || error "PFID is not set"
529 # create a mirrored file and extend it
530 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
531 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
532 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
534 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
535 error "extend mirror with -f failed"
537 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
538 error "extend mirrored file $tf-3 failed"
539 verify_mirror_count $tf-3 $mirror_count
540 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
541 for ((i = 0; i < $mirror_count; i++)); do
542 verify_comp_attrs $tf-3 ${ids[$i]}
543 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
546 $mirror_cmd -N $tf-3 &> /dev/null
548 (( $rc == 34 || $MDS1_VERSION < $(version_code v2_14_57-72-gf468093cb6) )) ||
549 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
551 run_test 0d "lfs mirror extend with -N option"
554 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
558 local mirror_cmd="$LFS mirror extend"
562 # create parent directory
563 mkdir $td || error "mkdir $td failed"
565 create_pool $FSNAME.ssd ||
566 error "create OST pool ssd failed"
568 # create a mirrored file with plain layout mirrors
569 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
570 error "create mirrored file $tf failed"
572 create_pool $FSNAME.flash ||
573 error "create OST pool flash failed"
574 create_pool $FSNAME.archive ||
575 error "create OST pool archive failed"
577 # extend the mirrored file with plain layout mirrors
578 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
579 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
580 error "extend mirrored file $tf failed"
581 verify_mirror_count $tf 6
582 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
583 for ((i = 0; i < 6; i++)); do
584 verify_comp_extent $tf ${ids[$i]} 0 EOF
587 # verify component ${ids[0]}
588 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
589 verify_comp_attr stripe-count $tf ${ids[0]} 3
590 verify_comp_attr stripe-index $tf ${ids[0]} 1
592 # verify component ${ids[1]}
593 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
594 verify_comp_attr stripe-count $tf ${ids[1]} 2
595 verify_comp_attr stripe-index $tf ${ids[1]} 2
597 # verify component ${ids[2]}
598 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
599 verify_comp_attr stripe-count $tf ${ids[2]} 2
600 verify_comp_attr pool $tf ${ids[2]} flash
602 # verify component ${ids[3]}
603 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
604 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
605 verify_comp_attr pool $tf ${ids[3]} flash
607 # verify component ${ids[4]}
608 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
609 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
610 verify_comp_attr pool $tf ${ids[4]} archive
612 # verify component ${ids[5]}
613 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
614 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
615 verify_comp_attr_with_parent pool $tf ${ids[5]}
617 run_test 0e "lfs mirror extend plain layout mirrors"
620 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
624 local mirror_cmd="$LFS mirror extend"
628 # create parent directory
629 mkdir $td || error "mkdir $td failed"
631 create_pool $FSNAME.ssd ||
632 error "create OST pool ssd failed"
634 # create a mirrored file with composite layout mirror
635 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
636 error "create mirrored file $tf failed"
638 create_pool $FSNAME.flash ||
639 error "create OST pool flash failed"
640 create_pool $FSNAME.archive ||
641 error "create OST pool archive failed"
643 # extend the mirrored file with composite layout mirrors
644 $mirror_cmd -N -p archive \
645 -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
647 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
648 error "extend mirrored file $tf failed"
649 verify_mirror_count $tf 8
650 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
652 # verify component ${ids[0]}
653 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
654 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
655 verify_comp_attr pool $tf ${ids[0]} ssd
656 verify_comp_extent $tf ${ids[0]} 0 33554432
658 # verify component ${ids[1]}
659 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
660 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
661 verify_comp_attr pool $tf ${ids[1]} ssd
662 verify_comp_extent $tf ${ids[1]} 33554432 EOF
664 # verify component ${ids[2]}
665 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
666 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
667 verify_comp_attr pool $tf ${ids[2]} archive
668 verify_comp_extent $tf ${ids[2]} 0 EOF
670 # verify components ${ids[3]} and ${ids[5]}
672 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
673 verify_comp_attr stripe-count $tf ${ids[$i]} 2
674 verify_comp_attr stripe-index $tf ${ids[$i]} 1
675 verify_comp_extent $tf ${ids[$i]} 0 8388608
678 # verify components ${ids[4]} and ${ids[6]}
680 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
681 verify_comp_attr stripe-count $tf ${ids[$i]} 2
682 verify_comp_attr pool $tf ${ids[$i]} flash
683 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
686 # verify component ${ids[7]}
687 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
688 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
689 verify_comp_attr_with_parent pool $tf ${ids[7]}
690 verify_comp_extent $tf ${ids[7]} 0 EOF
692 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
694 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
695 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
696 verify_comp_attr pool $tf ${ids[$i]} archive
697 verify_comp_extent $tf ${ids[$i]} 0 536870912
700 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
702 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
703 verify_comp_attr stripe-count $tf ${ids[$i]} -1
704 verify_comp_attr pool $tf ${ids[$i]} archive
705 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
708 run_test 0f "lfs mirror extend composite layout mirrors"
713 ! $LFS mirror create --flags prefer $tf ||
714 error "creating $tf w/ --flags but w/o -N option should fail"
716 ! $LFS mirror create -N --flags foo $tf ||
717 error "creating $tf with '--flags foo' should fail"
719 ! $LFS mirror create -N --flags stale $tf ||
720 error "creating $tf with '--flags stale' should fail"
722 ! $LFS mirror create -N --flags prefer,init $tf ||
723 error "creating $tf with '--flags prefer,init' should fail"
725 ! $LFS mirror create -N --flags ^prefer $tf ||
726 error "creating $tf with '--flags ^prefer' should fail"
728 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
729 -N -o1 $tf || error "create mirrored file $tf failed"
731 verify_comp_attr lcme_flags $tf 0x10001 prefer
732 verify_comp_attr lcme_flags $tf 0x10002 prefer
734 # write to the mirrored file and check primary
735 cp /etc/hosts $tf || error "error writing file '$tf'"
737 verify_comp_attr lcme_flags $tf 0x20003 stale
739 # resync file and check prefer flag
740 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
743 $LCTL set_param osc.*.stats=clear
744 cat $tf &> /dev/null || error "error reading file '$tf'"
746 # verify that the data was provided by OST1 where mirror 1 resides
747 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
748 awk '/ost_read/{print $2}')
749 [ -n "$nr_read" ] || error "read was not provided by OST1"
751 run_test 0g "lfs mirror create flags support"
754 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
755 skip "Need MDS version at least 2.11.57"
763 # create parent directory
764 test_mkdir $td || error "mkdir $td failed"
766 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
767 error "set default mirrored layout on directory $td failed"
769 # verify flags are inherited from the directory
772 verify_comp_attr lcme_flags $tf 0x10001 prefer
773 verify_comp_attr lcme_flags $tf 0x10002 prefer
775 # set flags to the first component
776 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
777 error "setting '^prefer,foo' flags should fail"
779 ! $LFS getstripe --component-flags=prefer,foo $tf ||
780 error "getting component(s) with 'prefer,foo' flags should fail"
782 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
784 verify_comp_attr lcme_flags $tf 0x10001 stale
785 verify_comp_attr lcme_flags $tf 0x10002 prefer
787 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
788 error "clearing 'stale' should fail"
790 # write and resync file. It can't resync the file directly because the
791 # file state is still 'ro'
792 cp /etc/hosts $tf || error "error writing file '$tf'"
793 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
795 for flag in prefer prefrd prefwr; do
796 $LFS setstripe --comp-set -I 0x20003 --comp-flags=$flag $tf ||
797 error "error setting flag $flag"
799 verify_comp_attr lcme_flags $tf 0x20003 $flag
801 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^$flag $tf ||
802 error "error clearing $flag flag from component 0x20003"
805 # MDS disallows setting stale flag on the last non-stale mirror
806 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
808 cp /etc/hosts $tf || error "error writing file '$tf'"
810 verify_comp_attr lcme_flags $tf 0x10002 prefer
811 verify_comp_attr lcme_flags $tf 0x20003 stale
812 verify_comp_attr lcme_flags $tf 0x30004 stale
814 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
816 error "setting stale flag on component 0x10002 should fail"
818 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
820 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
821 error "error setting stale flag on component 0x10001"
822 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
823 error "error setting stale flag on component 0x20003"
825 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
827 error "setting stale flag on component 0x30004 should fail"
829 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
831 run_test 0h "set, clear and test flags for FLR files"
834 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
836 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
837 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
838 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
840 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
841 stack_trap "rm -f $TMP/$tfile"
842 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
843 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
844 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
845 error "set component 1 stale failed"
846 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
847 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
849 run_test 0j "test lfs mirror read/write commands"
852 (( $MDS1_VERSION >= $(version_code 2.15.6) )) ||
853 skip "MDS version older than 2.15.6"
854 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
857 # default FLR with 2 mirrors
858 $LFS setstripe -N -c1 -i0 -N -c1 -i1 $DIR/$tdir ||
859 error "set default layout failed"
861 # plain file extension under default FLR dir
862 echo $tfile >> $DIR/$tdir/$tfile.append || error "create $tfile.append failed"
863 echo -n " before extend $tfile.append, mirror count = "
864 $LFS getstripe -N $DIR/$tdir/$tfile.append
866 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile.append ||
867 error "mirror extend failed"
868 echo -n " after extend $tfile.append, mirror count = "
869 $LFS getstripe -N $DIR/$tdir/$tfile.append
871 # normal file extension under default FLR dir
872 touch $DIR/$tdir/$tfile || error "create $tfile failed"
873 echo -n " before extend $tfile, mirror count = "
874 $LFS getstripe -N $DIR/$tdir/$tfile
876 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile ||
877 error "mirror extend $tfile failed"
878 echo -n " after extend $tfile, mirror count = "
879 $LFS getstripe -N $DIR/$tdir/$tfile
881 run_test 0k "mirroring a file in directory with default FLR layout"
885 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
886 local mirror_create_cmd="$LFS mirror create"
887 local stripes[0]=$OSTCOUNT
889 mirror_create_cmd+=" -N -c ${stripes[0]}"
890 for ((i = 1; i < $mirror_count; i++)); do
891 # add mirrors with different stripes to the file
892 stripes[$i]=$((RANDOM % OSTCOUNT))
893 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
895 mirror_create_cmd+=" -N -c ${stripes[$i]}"
898 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
899 verify_mirror_count $tf $mirror_count
901 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
902 $LFS mirror extend -N $tf &&
903 error "Creating the $((mirror_count+1))th mirror succeeded"
905 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
908 # verify the range of components and stripe counts
909 for ((i = 0; i < $mirror_count; i++)); do
910 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
911 verify_comp_extent $tf ${ids[$i]} 0 EOF
914 run_test 1 "create components with setstripe options"
918 local tf2=$DIR/$tfile-2
920 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
921 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
923 $LFS mirror extend -N -f $tf2 $tf ||
924 error "merging $tf2 into $tf failed"
926 verify_mirror_count $tf 2
927 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
929 run_test 2 "create components from existing files"
932 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
934 for ((i = 0; i < 2; i++)); do
935 $LFS mkdir -i $i $DIR/$tdir-$i
936 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
939 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
940 $DIR/$tdir-0/$tfile || error "creating mirrors"
942 # mdt doesn't support to cancel layout lock for remote objects, do
946 # make sure the mirrorted file was created successfully
947 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
948 { $LFS getstripe $DIR/$tdir-0/$tfile;
949 error "expected 2 components"; }
954 run_test 3 "create components from files located on different MDTs"
957 local tf=$DIR/$tdir/$tfile
960 test_mkdir $DIR/$tdir
962 # set mirror with setstripe options to directory
963 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
964 error "set mirror to directory error"
966 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
967 x"mirrored" ] || error "failed to create mirrored dir"
970 verify_mirror_count $tf 2
972 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
973 verify_comp_extent $tf ${ids[0]} 0 1048576
974 verify_comp_extent $tf ${ids[1]} 1048576 EOF
976 # sub directory should inherit mirror setting from parent
977 test_mkdir $DIR/$tdir/td
978 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
979 x"mirrored" ] || error "failed to inherit mirror from parent"
981 # mirror extend won't be applied to directory
982 $LFS mirror extend -N2 $DIR/$tdir &&
983 error "expecting mirror extend failure"
986 run_test 4 "Make sure mirror attributes can be inhertied from directory"
992 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
993 error "failed to create file with non-empty layout"
994 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
996 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
997 verify_mirror_count $tf 3
999 $CHECKSTAT -t file -s 12345 $tf ||
1000 error "size error after attaching layout "
1002 run_test 5 "Make sure init size work for mirrored layout"
1005 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
1006 skip "MDS version older than 2.12.58"
1008 local tf=$DIR/$tfile
1010 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
1011 error "failure to create DoM file with mirror"
1013 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
1014 error "failure to create mirrored file with DoM"
1016 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
1017 error "failure to create PFL with DoM file"
1018 $LFS mirror extend -N2 $tf ||
1019 error "failure to extend mirror with DoM"
1021 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
1022 error "failure to create PFL with DoM file"
1023 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
1024 error "failure to create mirrored file"
1025 $LFS mirror extend -N -f $tf-1 $tf-2 ||
1026 error "failure to extend mirrored file with DoM extent"
1028 run_test 6a "DoM and FLR work together"
1031 (( $MDS1_VERSION >= $(version_code 2.15.58.1) )) ||
1032 skip "MDS version older than 2.15.58.1"
1034 local tf=$DIR/$tfile
1036 $LFS setstripe -E64K -L mdt -Eeof $tf ||
1037 error "failure to create PFL with DoM file"
1038 $LFS mirror extend -N -E1M -L mdt -Eeof $tf &&
1039 error "should not extend mirror with different DoM size"
1043 run_test 6b "extend mirror with different DoM size"
1046 local tf=$DIR/$tfile
1048 # create DoM with setting stripe_size == component size
1049 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
1050 error "failure to create DoM with stripe_size == comp size"
1051 rm -f $tf || error "delete $tf"
1053 # DoM should not inherit previous component stripe_size
1054 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
1055 error "DoM component shouldn't inherit previous stripe_size"
1057 run_test 7 "Create mirror with DoM component"
1060 local tf=$DIR/$tfile
1061 local tf2=$DIR/$tfile-2
1063 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1065 stack_trap "rm -f $tf $tf2"
1067 $LFS setstripe -E EOF -o 0 $tf
1068 $LFS setstripe -E EOF -o 1 $tf2
1070 local dd_count=$((RANDOM % 20 + 1))
1071 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
1072 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
1074 # for zfs - sync OST dataset so that du below will return
1076 [[ "$FSTYPE" != "zfs" ]] || do_nodes $(osts_nodes) "$ZPOOL sync"
1078 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1081 $LFS mirror extend -N -f $tf2 $tf ||
1082 error "merging $tf2 into $tf failed"
1084 # cancel layout lock
1085 cancel_lru_locks mdc
1087 local new_blocks=$(du -k $tf | awk '{print $1}')
1088 [ $new_blocks -eq $blocks ] ||
1089 error "i_blocks error expected: $blocks, actual: $new_blocks"
1091 run_test 21 "glimpse should report accurate i_blocks"
1093 get_osc_lock_count() {
1100 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1101 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1102 lock_count=$((lock_count + count))
1108 local tf=$DIR/$tfile
1110 stack_trap "rm -f $tf"
1112 $LFS setstripe -E EOF -o 0 $tf
1113 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1115 # add component, two mirrors located on the same OST ;-)
1116 $LFS mirror extend -N -o 0 $tf ||
1117 error "extending mirrored file $tf failed"
1119 size_blocks=$(stat --format="%b %s" $tf)
1121 cancel_lru_locks mdc
1122 cancel_lru_locks osc
1124 local new_size_blocks=$(stat --format="%b %s" $tf)
1126 # make sure there is no lock cached
1127 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1129 [ "$new_size_blocks" = "$size_blocks" ] ||
1130 echo "size expected: $size_blocks, actual: $new_size_blocks"
1134 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1137 local tf=$DIR/$tfile
1139 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1140 error "creating mirrored file $tf failed"
1143 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1144 cancel_lru_locks osc
1147 local tmpfile=$(mktemp)
1148 stat --format="%b %s" $tf > $tmpfile &
1152 while [ $cnt -le 5 ]; do
1153 kill -0 $pid > /dev/null 2>&1 || break
1157 kill -0 $pid > /dev/null 2>&1 &&
1158 error "stat process stuck due to unavailable OSTs"
1160 # make sure glimpse request has been sent
1161 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1162 error "OST $ost_idx: no glimpse request was sent"
1167 run_test 31 "make sure glimpse request can be retried"
1170 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1171 rm -f $DIR/$tfile $DIR/$tfile-2
1173 stack_trap "rm -f $DIR/$tfile"
1175 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1176 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1178 local fsize=$(stat -c %s $DIR/$tfile)
1179 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1181 local cksum=$(md5sum $DIR/$tfile)
1183 # create a new mirror in sync mode
1184 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1185 error "extending mirrored file $DIR/$tfile failed"
1187 # make sure the mirrored file was created successfully
1188 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1189 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1194 # check size is correct, glimpse request should go to the 2nd mirror
1195 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1196 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1198 echo "reading file from the 2nd mirror and verify checksum"
1199 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1200 error "checksum error: expected $cksum"
1204 run_test 32 "data should be mirrored to newly created mirror"
1207 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1209 rm -f $DIR/$tfile $DIR/$tfile-2
1211 # create a file with two mirrors
1212 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1215 while [ $count -lt $max_count ]; do
1216 echo "ost1" >> $DIR/$tfile
1217 count=$((count + 1));
1220 # tmp file that will be used as mirror
1221 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1223 while [ $count -lt $max_count ]; do
1224 echo "ost2" >> $DIR/$tfile-2
1225 count=$((count + 1));
1228 # create a mirrored file
1229 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1230 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1231 "with verification should fail"
1232 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1233 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1234 "without verification failed"
1236 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1237 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1238 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1240 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1242 # execpted file size
1243 local fsize=$((5 * max_count))
1244 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1245 error "mirrored file size is not $fsize"
1247 # read file - all OSTs are available
1248 echo "reading file (data can be provided by any ost)... "
1249 local rs=$(cat $DIR/$tfile | head -1)
1250 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1251 error "file content error: expected: \"ost1\" or \"ost2\""
1253 # read file again with ost1 failed
1257 echo "reading file (data should be provided by ost2)..."
1258 local rs=$(cat $DIR/$tfile | head -1)
1259 [[ "$rs" == "ost2" ]] ||
1260 error "file content error: expected: \"ost2\", actual: \"$rs\""
1265 # read file again with ost2 failed
1269 # check size, glimpse should work
1270 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1271 error "mirrored file size is not $fsize"
1273 echo "reading file (data should be provided by ost1)..."
1274 local rs=$(cat $DIR/$tfile | head -1)
1275 [[ "$rs" == "ost1" ]] ||
1276 error "file content error: expected: \"ost1\", actual: \"$rs\""
1280 run_test 33a "read can choose available mirror to read"
1283 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1287 stack_trap "rm -f $DIR/$tfile" EXIT
1289 # create a file with two mirrors on OST0000 and OST0001
1290 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1292 # make sure that $tfile has two mirrors
1293 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1294 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1297 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1298 error "write failed for $DIR/$tfile"
1299 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1300 verify_flr_state $DIR/$tfile "ro"
1305 # read file - all OSTs are available
1306 echo "reading file (data can be provided by any ost)... "
1308 time cat $DIR/$tfile > /dev/null || error "read all"
1312 # read file again with ost1 {OST0000} failed
1315 echo "reading file (data should be provided by ost2)..."
1317 time cat $DIR/$tfile > /dev/null || error "read ost2"
1324 # read file again with ost2 {OST0001} failed
1328 echo "reading file (data should be provided by ost1)..."
1330 time cat $DIR/$tfile > /dev/null || error "read ost1"
1337 (( (r1 * 100) > (ra * 105) && (r1 > ra + 30) )) &&
1338 error "read mirror too slow without ost1, from $ra to $r1"
1339 (( (r2 * 100) > (ra * 105) && (r2 > ra + 30) )) &&
1340 error "read mirror too slow without ost2, from $ra to $r2"
1342 wait_osc_import_ready client ost2
1344 run_test 33b "avoid reading from unhealthy mirror"
1347 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1351 stack_trap "rm -f $DIR/$tfile" EXIT
1353 # create a file with two mirrors
1354 # mirror1: {OST0000, OST0001}
1355 # mirror2: {OST0001, OST0002}
1356 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1358 # make sure that $tfile has two mirrors
1359 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1360 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1363 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1364 error "write failed for $DIR/$tfile"
1365 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1366 verify_flr_state $DIR/$tfile "ro"
1371 # read file - all OSTs are available
1372 echo "reading file (data can be provided by any ost)... "
1373 time cat $DIR/$tfile > /dev/null || error "read all"
1375 # read file again with ost2 (OST0001) failed
1379 echo "reading file (data should be provided by ost1 and ost3)..."
1380 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1385 wait_osc_import_ready client ost2
1387 run_test 33c "keep reading among unhealthy mirrors"
1390 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1392 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1395 $LFS setstripe -o 0 $DIR/$tfile-ref
1396 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1398 # create a file with two mirrors
1399 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1400 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1402 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1403 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1405 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1406 error "mirrored file size is not 3M"
1408 # merge a mirrored file
1409 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1410 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1412 cancel_lru_locks osc
1414 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1415 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1418 echo "comparing files ... "
1420 # however, read can still return the correct data. It should return
1421 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1422 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1423 $DIR/$tfile-ref || error "file reading error"
1427 run_test 34a "read mirrored file with multiple stripes"
1430 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1432 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1435 $LFS setstripe -o 0 $DIR/$tfile-ref
1436 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1438 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1439 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1441 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1442 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1444 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1445 error "mirrored file size is not 3M"
1447 # merge a mirrored file
1448 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1449 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1451 cancel_lru_locks osc
1453 # stop two OSTs, so the 2nd component of the 1st mirror and
1454 # the 1st component of the 2nd mirror will be inaccessible, ...
1457 echo "comparing files ... "
1459 # however, read can still return the correct data. It should return
1460 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1461 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1462 $DIR/$tfile-ref || error "file reading error"
1466 run_test 34b "read mirrored file with multiple components"
1469 local tf=$DIR/$tfile
1471 $LFS setstripe -E eof $tf
1473 # add an out-of-sync mirror to the file
1474 $LFS mirror extend -N -c 2 $tf ||
1475 error "extending mirrored file $tf failed"
1477 $MULTIOP $tf oO_WRONLY:c ||
1478 error "write open a mirrored file failed"
1480 # truncate file should return error
1481 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1483 run_test 35 "allow to write to mirrored files"
1485 get_file_layout_version() {
1486 $LFS getstripe $1 | awk '/lcm_layout_gen/{print $2}'
1489 get_ost_layout_version() {
1490 $MULTIOP $1 oXc | awk '/ostlayoutversion/{print $2}'
1493 verify_ost_layout_version() {
1496 # get file layout version
1497 local flv=$(get_file_layout_version $tf)
1499 # layout version from OST objects
1500 local olv=$(get_ost_layout_version $tf)
1502 (( flv >= olv )) || error "layout version mismatch: $flv vs. $olv"
1509 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1510 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1512 $LFS mirror extend -N -f $tf-tmp $tf ||
1513 error "merging $tf-tmp into $tf failed"
1518 local tf=$DIR/$tfile
1520 stack_trap "rm -f $tf $tf-2 $tf-3"
1522 create_file_36 $tf $tf-2 $tf-3
1524 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1526 # test case 1 - check file write and verify layout version
1527 $MULTIOP $tf oO_WRONLY:c ||
1528 error "write open a mirrored file failed"
1530 # write open file should not return error
1531 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1533 # instantiate components should work
1534 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1536 # verify OST layout version
1537 verify_ost_layout_version $tf
1540 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1543 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1545 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1546 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1548 # write should take at least $fail_loc seconds and succeed
1549 local st=$(date +%s)
1550 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1552 # verify OST layout version
1553 verify_ost_layout_version $tf
1555 do_facet $mds_facet $LCTL set_param fail_loc=0
1557 run_test 36a "write to mirrored files"
1560 local tf=$DIR/$tfile
1562 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1563 skip "Need OST version at least 2.15.50"
1565 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1567 # create 2 mirrors using different OSTs
1568 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1569 error "create mirrored file"
1571 # write 1M data to one mirror
1572 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1575 # set prefer mirror to another mirror
1576 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1577 error "clear prefer mirror error"
1578 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1579 error "set prefer mirror error"
1581 # the second write should not hung
1582 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1584 run_test 36b "write should not hung when prefered mirror is stale"
1587 local tf=$DIR/$tfile
1589 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1590 skip "Need OST version at least 2.15.50"
1592 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1594 # create 2 mirrors using different OSTs
1595 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1596 error "create mirrored file"
1597 stack_trap "rm -f $tf"
1599 # write it in the background
1600 $MULTIOP $tf Ow4096_w4096c &
1605 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1606 error "clear prefer mirror error"
1607 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1608 error "set prefer mirror error"
1613 run_test 36c "change prefer mirror during write shouldn't hung"
1616 local tf=$DIR/$tfile
1618 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1619 skip "Need OST version at least 2.15.50"
1621 echo " ** create $tf"
1622 $LFS mirror create -N $tf || error "create $tf failed"
1625 echo " ** mirror extend $tf ($i/2)"
1626 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1627 flv=$(get_file_layout_version $tf)
1628 olv=$(get_ost_layout_version $tf)
1629 echo " flv=$flv olv=$olv"
1633 echo " ** write $tf ($i/2)"
1634 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1635 flv=$(get_file_layout_version $tf)
1636 olv=$(get_ost_layout_version $tf)
1637 echo " flv=$flv olv=$olv"
1639 error "write update OST layout failed $flv/$olv"
1642 echo " ** resync $tf"
1643 $LFS mirror resync $tf || error "mirror resync $tf failed"
1644 flv=$(get_file_layout_version $tf)
1645 olv=$(get_ost_layout_version $tf)
1646 echo " flv=$flv olv=$olv"
1649 echo " ** truncate $tf ($i/2)"
1650 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1651 flv=$(get_file_layout_version $tf)
1652 olv=$(get_ost_layout_version $tf)
1653 echo " flv=$flv olv=$olv"
1654 (( flv == olv || flv == olv + 1 )) ||
1655 error "truncate update OST layout failed $flv/$olv"
1658 echo " ** resync $tf"
1659 $LFS mirror resync $tf || error "mirror resync $tf failed"
1660 flv=$(get_file_layout_version $tf)
1661 olv=$(get_ost_layout_version $tf)
1662 echo " flv=$flv olv=$olv"
1665 echo " ** write $tf ($i/2)"
1666 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1667 flv=$(get_file_layout_version $tf)
1668 olv=$(get_ost_layout_version $tf)
1669 echo " flv=$flv olv=$olv"
1671 error "write update OST layout failed $flv/$olv"
1674 run_test 36d "write/punch FLR file update OST layout version"
1680 echo "create test files with size $fsize .."
1684 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1686 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1687 $TRUNCATE $tf $fsize
1693 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1694 skip "Need MDS version at least 2.11.57"
1696 local tf=$DIR/$tfile
1697 local tf2=$DIR/$tfile-2
1698 local tf3=$DIR/$tfile-3
1699 local tf4=$DIR/$tfile-4
1701 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1703 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1706 # assume the mirror id will be 1, 2, and 3
1707 declare -A checksums
1708 checksums[1]=$(cat $tf | md5sum)
1709 checksums[2]=$(cat $tf2 | md5sum)
1710 checksums[3]=$(cat $tf3 | md5sum)
1712 printf '%s\n' "${checksums[@]}"
1714 # merge these files into a mirrored file
1715 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1716 error "merging $tf2 into $tf failed"
1717 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1718 error "merging $tf3 into $tf failed"
1722 # verify mirror read, checksums should equal to the original files'
1723 echo "Verifying mirror read .."
1726 for i in "${mirror_array[@]}"; do
1727 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1728 sum=$($LFS mirror read -N $i $tf | md5sum)
1729 [ "$sum" = "${checksums[$i]}" ] ||
1730 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1733 # verify mirror write
1734 echo "Verifying mirror write .."
1735 $LFS mirror write -N2 $tf < $tf4
1737 sum=$($LFS mirror read -N2 $tf | md5sum)
1738 [[ "$sum" = "${checksums[1]}" ]] ||
1739 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1741 # verify mirror copy, write to this mirrored file will invalidate
1742 # the other two mirrors
1743 echo "Verifying mirror copy .."
1744 local osts=$(osts_nodes)
1746 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1747 error "mirror copy error"
1749 # verify copying is successful by checking checksums
1750 remount_client $MOUNT
1751 for i in "${mirror_array[@]}"; do
1752 sum=$($LFS mirror read -N $i $tf | md5sum)
1753 [ "$sum" = "${checksums[1]}" ] ||
1754 error "$i: mismatch checksum after copy \'$sum\'"
1759 run_test 37 "mirror I/O API verification"
1762 local tf=$DIR/$tfile
1763 local ref=$DIR/${tfile}-ref
1765 stack_trap "rm -f $tf $ref"
1767 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1768 error "creating $tf failed"
1769 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1770 $tf-2 || error "creating $tf-2 failed"
1771 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1772 error "creating $tf-3 failed"
1774 # instantiate all components
1775 $LFS mirror extend -N -f $tf-2 $tf ||
1776 error "merging $tf-2 into $tf failed"
1777 $LFS mirror extend -N -f $tf-3 $tf ||
1778 error "merging $tf-3 into $tf failed"
1779 $LFS mirror extend -N -c 1 $tf ||
1780 error "extending mirrored file $tf failed"
1782 verify_flr_state $tf "ro"
1784 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1786 local fsize=$((RANDOM << 8 + 1048576))
1787 $TRUNCATE $ref $fsize
1789 local ref_cksum=$(cat $ref | md5sum)
1791 # case 1: verify write to mirrored file & resync work
1792 cp $ref $tf || error "copy from $ref to $f error"
1793 verify_flr_state $tf "wp"
1795 local file_cksum=$(cat $tf | md5sum)
1796 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1799 echo "mirror IDs: ${mirror_array[*]}"
1801 local valid_mirror stale_mirror id mirror_cksum
1802 for id in "${mirror_array[@]}"; do
1803 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1804 [ "$ref_cksum" == "$mirror_cksum" ] &&
1805 { valid_mirror=$id; continue; }
1810 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1811 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1813 $LFS mirror resync $tf || error "resync failed"
1814 verify_flr_state $tf "ro"
1816 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1817 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1819 # case 2: inject an error to make mirror_io exit after changing
1820 # the file state to sync_pending so that we can start a concurrent
1822 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1823 verify_flr_state $tf "wp"
1825 mirror_io resync -e resync_start $tf && error "resync succeeded"
1826 verify_flr_state $tf "sp"
1828 # from sync_pending to write_pending
1829 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1830 verify_flr_state $tf "wp"
1832 mirror_io resync -e resync_start $tf && error "resync succeeded"
1833 verify_flr_state $tf "sp"
1835 # from sync_pending to read_only
1836 $LFS mirror resync $tf || error "resync failed"
1837 verify_flr_state $tf "ro"
1839 run_test 38 "resync"
1842 local tf=$DIR/$tfile
1845 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1846 error "create PFL file $tf failed"
1848 verify_mirror_count $tf 2
1849 verify_comp_count $tf 4
1851 rm -f $tf || error "delete $tf failed"
1853 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1856 local tf=$DIR/$tfile
1859 for ops in "conv=notrunc" ""; do
1862 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1863 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1864 error "create PFLR file $tf failed"
1865 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1866 error "write PFLR file $tf failed"
1868 lfs getstripe -vy $tf
1872 # file mirror state should be write_pending
1873 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1875 error "file mirror state $flags"
1876 # the 1st component (in mirror 1) should be inited
1877 verify_comp_attr lcme_flags $tf 0x10001 init
1878 # the 2nd component (in mirror 1) should be inited
1879 verify_comp_attr lcme_flags $tf 0x10002 init
1880 # the 3rd component (in mirror 1) should be uninited
1881 verify_comp_attr lcme_flags $tf 0x10003 prefer
1882 # the 4th component (in mirror 2) should be inited
1883 verify_comp_attr lcme_flags $tf 0x20004 init
1884 # the 5th component (in mirror 2) should be uninited
1885 verify_comp_attr lcme_flags $tf 0x20005 0
1886 # the 6th component (in mirror 2) should be stale
1887 verify_comp_attr lcme_flags $tf 0x20006 stale
1888 # the 7th component (in mirror 2) should be uninited
1889 if [[ x$ops = "xconv=notrunc" ]]; then
1890 verify_comp_attr lcme_flags $tf 0x20007 0
1891 elif [[ x$ops = "x" ]]; then
1892 verify_comp_attr lcme_flags $tf 0x20007 stale
1896 rm -f $tf || error "delete $tf failed"
1898 run_test 40 "PFLR rdonly state instantiation check"
1901 local tf=$DIR/$tfile
1903 stack_trap "rm -f $tf $tf-1"
1906 echo " **create two FLR files $tf $tf-1"
1907 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1908 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1909 error "create PFLR file $tf failed"
1910 $LFS mirror create -N -E 2M -S 1M -E eof \
1911 -N -E 1M -E eof --flags prefer \
1912 -N -E 4m -E eof $tf-1 ||
1913 error "create PFLR file $tf-1 failed"
1915 # file should be in ro status
1916 echo " **verify files be RDONLY"
1917 verify_flr_state $tf "ro"
1918 verify_flr_state $tf-1 "ro"
1920 # write data in [0, 2M)
1921 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1922 error "writing $tf failed"
1923 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1924 error "writing $tf-1 failed"
1926 local sum0=$(cat $tf-1 | md5sum)
1928 echo " **verify files be WRITE_PENDING"
1929 verify_flr_state $tf "wp"
1930 verify_flr_state $tf-1 "wp"
1932 # file should have stale component
1933 echo " **verify files have stale component"
1934 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1935 error "after writing $tf, it does not contain stale component"
1936 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1937 error "after writing $tf-1, it does not contain stale component"
1939 echo " **full resync"
1940 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1942 echo " **verify $tf-1 data consistency in all mirrors"
1944 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1945 [[ "$sum" = "$sum0" ]] ||
1946 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1949 echo " **verify files be RDONLY"
1950 verify_flr_state $tf "ro"
1951 verify_flr_state $tf-1 "ro"
1953 # file should not have stale component
1954 echo " **verify files do not contain stale component"
1955 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1956 error "after resyncing $tf, it contains stale component"
1957 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1958 error "after resyncing $tf, it contains stale component"
1960 # verify partial resync
1961 echo " **write $tf-1 for partial resync test"
1962 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1963 error "writing $tf-1 failed"
1965 echo " **only resync mirror 2"
1966 verify_flr_state $tf-1 "wp"
1967 $LFS mirror resync --only 2 $tf-1 ||
1968 error "resync mirror 2 of $tf-1 failed"
1969 verify_flr_state $tf "ro"
1971 # resync synced mirror
1972 echo " **resync mirror 2 again"
1973 $LFS mirror resync --only 2 $tf-1 ||
1974 error "resync mirror 2 of $tf-1 failed"
1975 verify_flr_state $tf "ro"
1976 echo " **verify $tf-1 contains stale component"
1977 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1978 error "after writing $tf-1, it does not contain stale component"
1980 echo " **full resync $tf-1"
1981 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1982 verify_flr_state $tf "ro"
1983 echo " **full resync $tf-1 again"
1984 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1985 echo " **verify $tf-1 does not contain stale component"
1986 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1987 error "after resyncing $tf, it contains stale component"
1991 run_test 41 "lfs mirror resync check"
1994 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1998 local mirror_cmd="$LFS mirror verify"
2001 stack_trap "rm -rf $td"
2003 # create parent directory
2004 mkdir $td || error "mkdir $td failed"
2006 $mirror_cmd &> /dev/null && error "no file name given"
2007 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
2008 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
2010 # create mirrored files
2011 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
2012 error "create mirrored file $tf failed"
2013 $LFS mirror create -N -E 2M -S 1M -E EOF \
2014 -N -E 6M -E 8M -E EOF \
2015 -N -E 16M -E EOF $tf-1 ||
2016 error "create mirrored file $tf-1 failed"
2017 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
2018 error "create mirrored file $tf-2 failed"
2020 # write data in [0, 10M)
2021 for i in $tf $tf-1 $tf-2; do
2022 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
2023 error "write $i failed"
2026 # resync the mirrored files
2027 $LFS mirror resync $tf-1 $tf-2 ||
2028 error "resync $tf-1 $tf-2 failed"
2030 # verify the mirrored files
2031 $mirror_cmd $tf-1 $tf-2 ||
2032 error "verify $tf-1 $tf-2 failed"
2034 get_mirror_ids $tf-1
2035 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2036 error "at least 2 mirror ids needed with '--only' option"
2037 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2039 error "'--only' option cannot be used upon multiple files"
2040 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2041 error "invalid specified mirror ids"
2043 # change the content of $tf and merge it into $tf-1
2045 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2046 error "change $tf with seek=$i failed"
2047 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2048 error "change $tf-1 with seek=$i failed"
2051 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2052 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2053 error "merge $tf into $tf-1 failed"
2055 # verify the mirrored files
2056 echo "Verify $tf-1 without -v option:"
2057 $mirror_cmd $tf-1 &&
2058 error "verify $tf-1 should fail" || echo "PASS"
2060 echo "Verify $tf-1 with -v option:"
2061 $mirror_cmd -v $tf-1 &&
2062 error "verify $tf-1 should fail"
2064 get_mirror_ids $tf-1
2065 echo "Verify $tf-1 with --only option:"
2066 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2067 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2068 "${mirror_array[-1]} should fail"
2070 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2071 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2072 "${mirror_array[1]} should succeed"
2074 # set stale components in $tf-1
2075 for i in 0x40002 0x40003; do
2076 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2077 error "set stale flag on component $i failed"
2080 # verify the mirrored file
2081 echo "Verify $tf-1 with stale components:"
2082 $mirror_cmd -vvv $tf-1 ||
2083 error "verify $tf-1 with stale components should succeed"
2085 echo "Verify $tf-1 with stale components and --only option:"
2086 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2087 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2088 "${mirror_array[-1]} should succeed"
2090 run_test 42 "lfs mirror verify"
2092 # inactivate one OST && write && restore the OST
2096 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2099 wait=$(do_facet $SINGLEMDS \
2100 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2101 wait=${wait%%[^0-9]*}
2103 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2104 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2105 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2106 sleep $(($wait * 2 + 2))
2107 echo " **write $file"
2108 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2109 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2110 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2111 sleep $((wait * 2 + 2))
2113 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2114 [ $flags = wp ] || error "file mirror state $flags != wp"
2118 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2120 local tf=$DIR/$tfile
2123 stack_trap "rm -f $tf"
2125 ## mirror 0 ost (0, 1)
2126 ## mirror 1 ost (1, 2)
2127 ## mirror 2 ost (2, 0)
2128 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2129 -N -Eeof -c2 -o2,0 $tf ||
2130 error "create 3 mirrors file $tf failed"
2132 ################## OST0 ###########################################
2134 echo " **verify components"
2135 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2136 verify_comp_attr lcme_flags $tf 0x20002 init
2137 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2140 echo " **resync $tf"
2141 $LFS mirror resync $tf
2142 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2143 [ $flags = ro ] || error "file mirror state $flags != ro"
2145 ################## OST1 ###########################################
2147 echo " **verify components"
2148 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2149 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2150 verify_comp_attr lcme_flags $tf 0x30003 init
2153 echo " **resync $tf"
2154 $LFS mirror resync $tf
2155 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2156 [ $flags = ro ] || error "file mirror state $flags != ro"
2158 ################## OST2 ###########################################
2160 echo " **verify components"
2161 verify_comp_attr lcme_flags $tf 0x10001 init
2162 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2163 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2165 run_test 43a "mirror pick on write"
2168 local tf=$DIR/$tdir/$tfile
2170 test_mkdir $DIR/$tdir
2172 stack_trap "rm -rf $tf"
2174 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2175 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2176 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2177 verify_flr_state $tf "ro"
2179 echo " ** write to $tf"
2180 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2181 verify_flr_state $tf "wp"
2183 echo " ** resync $tf"
2184 $LFS mirror resync $tf || error "resync $tf failed"
2185 verify_flr_state $tf "ro"
2187 run_test 43b "allow writing to multiple preferred mirror file"
2190 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2193 local tf=$DIR/$tdir/$tfile
2194 local tf1=$DIR/$tdir-1/$tfile-1
2196 stack_trap "rm -rf $tf $tf1"
2198 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2199 error "create directory failed"
2200 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2201 error "create remote directory failed"
2202 rm -f $tf $tf1 $tf.mirror~2
2203 # create file with 4 mirrors
2204 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2205 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2206 error "create PFLR file $tf failed"
2208 # file should be in ro status
2209 verify_flr_state $tf "ro"
2211 # write data in [0, 3M)
2212 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2213 error "writing $tf failed"
2214 verify_flr_state $tf "wp"
2217 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2218 error "split to $tf1 failed"
2220 local idx0=$($LFS getstripe -m $tf)
2221 local idx1=$($LFS getstripe -m $tf1)
2223 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2224 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2226 # verify mirror count
2227 verify_mirror_count $tf 3
2228 verify_mirror_count $tf1 1
2230 $LFS mirror split --mirror-id 2 $tf ||
2231 error "split mirror 2 failed"
2233 verify_mirror_count $tf 2
2234 verify_mirror_count $tf.mirror~2 1
2236 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2237 error "setting stale flag on component 0x30008 failed"
2239 # allow destroying the last non-stale mirror
2240 $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2241 error "destroying mirror 4 failed"
2242 verify_mirror_count $tf 1
2244 # verify splitted file contains the same content as the orig file does
2245 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2246 diff $tf $tf.mirror~2 ||
2247 error "splited file $tf.mirror~2 diffs from $tf"
2249 run_test 44a "lfs mirror split check"
2252 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2253 skip "Need MDS version at least 2.14.56"
2256 local tf=$DIR/$tdir/$tfile
2258 mkdir -p $DIR/$tdir || error "create directory failed"
2262 # create 2 mirrors file
2263 $LFS mirror extend -N -c1 $tf
2267 verify_flr_state $tf "wp"
2269 local str=$(cat $tf)
2271 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2273 # get the non-stale mirror id
2274 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2276 local mirror_ids=($($LFS getstripe $tf |
2277 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2278 for ((i = 0; i < 2; i++)); do
2279 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2280 grep stale > /dev/null || break
2283 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2287 # split the updated mirror
2288 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2289 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null ||
2290 error "split --mirror-id=${mirror_ids[$i]} $tf should succeed"
2293 # split the stale mirror
2295 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2296 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf &&
2297 error "Should fail due to only one mirror now"
2299 echo "make sure there's no stale comp in the file"
2300 # make sure there's no stale comp in the file
2301 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2302 ( $LFS getstripe $tf; error "stale mirror file" )
2305 [[ $str == "YYY" ]] ||
2306 ( cat $tf; error "$tf content is not YYY after split" )
2308 run_test 44b "mirror split does not create stale file"
2311 local tf=$DIR/$tdir/$tfile
2313 stack_trap "rm -f $tf"
2315 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2316 skip "Need MDS version at least 2.14.52"
2318 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2320 mkdir -p $DIR/$tdir || error "create directroy failed"
2322 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2324 block1=$(( $(stat -c "%b*%B" $tf) ))
2325 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2327 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2329 block2=$(( $(stat -c "%b*%B" $tf) ))
2330 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2332 $LFS mirror split -d --mirror-id=2 $tf ||
2333 error "mirror split $tfile failed"
2334 $LFS mirror split -d --mirror-id=3 $tf ||
2335 error "mirror split $tfile failed"
2338 block3=$(( $(stat -c "%b*%B" $tf) ))
2339 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2341 [[ $block1 -eq $block3 ]] ||
2342 error "mirror split does not reduce block# $block3 != $block1"
2344 run_test 44c "lfs mirror split reduces block size of a file"
2347 local tf=$DIR/$tdir/$tfile
2353 stack_trap "rm -f $tf"
2355 mkdir -p $DIR/$tdir || error "create directroy failed"
2357 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2359 size1=$(stat -c "%s" $tf)
2360 echo " ** before mirror ops, file size=$size1"
2362 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2364 size2=$(stat -c "%s" $tf)
2365 echo " ** after mirror extend, file size=$size2"
2367 (($size1 == $size2)) ||
2368 error "mirror extend should not change size, before: $size1, after $size2"
2370 $LFS mirror split -d --mirror-id=2 $tf ||
2371 error "mirror split $tfile failed"
2373 size2=$(stat -c "%s" $tf)
2374 echo " ** after mirror split, file size=$size2"
2375 (($size1 == $size2)) ||
2376 error "mirror split should not change size, before: $size1, after $size2"
2378 # Remount client to clear cached size information
2379 remount_client $MOUNT
2380 size2=$(stat -c "%s" $tf)
2381 echo " ** after mirror split & remount, file size=$size2"
2382 (($size1 == $size2)) ||
2383 error "mirror extend should not change size, before: $size1, after $size2"
2386 run_test 44d "lfs mirror split does not break size"
2389 local tf=$DIR/$tdir/$tfile
2390 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2394 test_mkdir $DIR/$tdir
2395 (( $MDS1_VERSION >= $(version_code v2_15_50-155-ga3f1c4622a) )) ||
2396 skip "Need MDS version >= 2.15.50.155 for SOM tunable"
2398 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2400 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2401 $LCTL set_param llite.*.xattr_cache=0
2402 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2403 stack_trap "rm -rf $tf"
2405 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2407 size1=$(stat -c "%s" $tf)
2408 echo " ** before mirror resync, file size=$size1"
2410 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2411 size1=$(stat -c "%s" $tf)
2412 size2=$($LFS getsom -s $tf)
2416 ((size1 == size2)) ||
2417 error "mirrored file with strict SOM $size1 != no SOM $size2"
2419 # Remount client to clear cached size information
2420 remount_client $MOUNT
2422 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2423 stack_trap "restore_lustre_params < $p; rm -f $p"
2424 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2426 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2428 size2=$(stat -c "%s" $tf)
2429 # 'getsom' here is just for debugging
2432 (( size2 == size1 )) ||
2433 error "mirror file with SOM disabled, SOM size $size2 != $size1"
2435 run_test 44e "basic FLR SOM tests + disable SOM"
2438 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2440 local file=$DIR/$tdir/$tfile
2441 local dir=$DIR/$tdir/$dir
2442 local temp=$DIR/$tdir/template
2444 test_mkdir $DIR/$tdir
2446 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2447 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2448 error "Create $file failed"
2450 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2451 rm -f $file $file.copy
2453 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2454 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2455 error "Create $file failed"
2457 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2459 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2466 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2468 local layout1=$(SKIP_INDEX=yes get_layout_param $src)
2469 local layout2=$(SKIP_INDEX=yes get_layout_param $dst)
2470 # compare their layout info
2471 [ "$layout1" == "$layout2" ] ||
2472 error "$msg_prefix $src <=> $dst layouts are not equal"
2476 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2478 local file=$DIR/$tdir/$tfile
2479 test_mkdir $DIR/$tdir
2481 ########################### 1. PFL file #############################
2482 echo " ** 1. PFL file"
2484 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2485 $file || error "1. Create PFL $file failed"
2488 verify_46 $file $file.copy "1. PFL file"
2490 ########################### 2. plain file ###########################
2491 echo " ** 2. plain file"
2493 $LFS setstripe -c2 -o0,1 -i1 $file ||
2494 error "2. Create plain $file failed"
2497 verify_46 $file $file.copy "2. plain file"
2499 ########################### 3. FLR file #############################
2500 echo " ** 3. FLR file"
2502 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2503 $file || error "3. Create FLR $file failed"
2506 verify_46 $file $file.copy "3. FLR file"
2508 local dir=$DIR/$tdir/dir
2509 ########################### 4. PFL dir ##############################
2510 echo " ** 4. PFL dir"
2512 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2513 error "4. setstripe PFL $dir failed"
2515 test_mkdir $dir.copy
2516 verify_46 $dir $dir.copy "4. PFL dir"
2518 ########################### 5. plain dir ############################
2519 echo " ** 5. plain dir"
2520 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2522 verify_46 $dir $dir.copy "5. plain dir"
2524 ########################### 6. FLR dir ##############################
2525 echo " ** 6. FLR dir"
2526 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2527 error "6. setstripe FLR $dir failed"
2529 verify_46 $dir $dir.copy "6. FLR dir"
2531 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2532 echo "server version $MDS1_VERSION does not support SEL" &&
2535 ########################### 7. SEL file ##############################
2536 echo " ** 7. SEL file"
2538 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2539 $file || error "Create $file failed"
2542 verify_46 $file $file.copy "7. SEL file"
2544 ########################### 8. SEL dir ##############################
2545 echo " ** 8. SEL dir"
2546 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2547 $dir || error "setstripe $dir failed"
2549 verify_46 $dir $dir.copy "8. SEL dir"
2551 ########################### 9. FLR SEL file ##########################
2552 echo " ** 9. FLR SEL file"
2554 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2555 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2558 verify_46 $file $file.copy "9. SEL file"
2560 ########################### 10. FLR SEL dir #########################
2561 echo " ** 10. FLR SEL dir"
2562 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2563 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2565 verify_46 $dir $dir.copy "10. SEL dir"
2567 run_test 46 "Verify setstripe --copy option"
2570 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2572 local file=$DIR/$tdir/$tfile
2577 test_mkdir $DIR/$tdir
2578 stack_trap "rm -f $file"
2582 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2583 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2584 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2585 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2586 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2588 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2589 $LFS mirror resync $file || error "resync $file failed"
2591 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2592 if [[ x$ost == "x0," ]]; then
2593 $LFS getstripe $file
2594 error "component ${ids[2]} objects allocated on $ost " \
2598 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2599 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2600 $LFS getstripe $file
2601 error "component ${ids[3]} objects allocated on $ost " \
2602 "shouldn't on OST1 or on OST2"
2607 # mirror1: [comp0] [comp1]
2608 # mirror2: [comp2] [comp3]
2609 # mirror3: [comp4] [comp5]
2610 # mirror4: [comp6] [comp7]
2611 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2612 error "create FLR $file failed"
2613 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2615 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2616 $LFS mirror resync $file || error "resync $file failed"
2618 for ((i = 0; i < 6; i++)); do
2619 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2620 awk '/l_ost_idx/{print $5}')
2622 # comp[0],comp[2],comp[4] should use different osts
2623 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2624 ${osts[2]} == ${osts[4]} ]]; then
2625 $LFS getstripe $file
2626 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2627 "allocated on duplicated OSTs"
2629 # comp[1],comp[3],comp[5] should use different osts
2630 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2631 ${osts[3]} == ${osts[5]} ]]; then
2632 $LFS getstripe $file
2633 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2634 "allocated on duplicated OSTs"
2639 run_test 47 "Verify mirror obj alloc"
2642 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2643 skip "Need MDS version at least 2.11.55"
2645 local tf=$DIR/$tfile
2647 stack_trap "rm -f $tf"
2649 echo " ** create 2 mirrors FLR file $tf"
2650 $LFS mirror create -N -E2M -Eeof --flags prefer \
2651 -N -E1M -Eeof $tf ||
2652 error "create FLR file $tf failed"
2655 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2656 verify_flr_state $tf "wp"
2658 local sum0=$(md5sum < $tf)
2660 echo " ** resync the file"
2661 $LFS mirror resync $tf
2663 echo " ** snapshot mirror 2"
2664 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2666 echo " ** write it again"
2667 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2668 echo " ** resync it again"
2669 $LFS mirror resync $tf
2671 verify_flr_state $tf "wp"
2672 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2674 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2675 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2677 echo " ** verify mirror 2 doesn't change"
2678 echo "original checksum: $sum0"
2679 echo "mirror 1 checksum: $sum1"
2680 echo "mirror 2 checksum: $sum2"
2681 [[ $sum0 = $sum2 ]] ||
2682 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2683 echo " ** mirror 2 stripe info"
2684 $LFS getstripe -v --mirror-index=2 $tf
2686 echo " ** resync mirror 2"
2687 $LFS mirror resync --only 2 $tf
2689 verify_flr_state $tf "ro"
2690 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2692 sum1=$($LFS mirror read -N1 $tf | md5sum)
2693 sum2=$($LFS mirror read -N2 $tf | md5sum)
2695 echo " ** verify mirror 2 resync-ed"
2696 echo "original checksum: $sum0"
2697 echo "mirror 1 checksum: $sum1"
2698 echo "mirror 2 checksum: $sum2"
2699 [[ $sum1 = $sum2 ]] ||
2700 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2701 echo " ** mirror 2 stripe info"
2702 $LFS getstripe -v --mirror-index=2 $tf
2704 run_test 48 "Verify snapshot mirror"
2713 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2714 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2715 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2716 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2717 skip "LU-1941: FIEMAP unimplemented on ZFS"
2719 trap cleanup_49 EXIT RETURN
2721 local file=$DIR/$tfile
2723 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2724 error "setstripe on $file"
2725 stack_trap "rm -f $file"
2727 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2728 $LFS mirror resync $file
2730 filefrag -ves $file || error "filefrag $file failed"
2731 filefrag_op=$(filefrag -ve -k $file |
2732 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2734 #Filesystem type is: bd00bd0
2735 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2736 # ext: device_logical: physical_offset: length: dev: flags:
2737 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2738 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2739 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2741 last_lun=$(echo $filefrag_op | cut -d: -f5)
2745 for line in $filefrag_op; do
2746 frag_lun=$(echo $line | cut -d: -f5)
2747 ext_len=$(echo $line | cut -d: -f4)
2748 if [[ "$frag_lun" != "$last_lun" ]]; then
2749 if (( tot_len != 1024 )); then
2751 error "$file: OST$last_lun $tot_len != 1024"
2757 (( tot_len += ext_len ))
2760 if (( num_luns != 2 || tot_len != 1024 )); then
2762 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2765 echo "FIEMAP on $file succeeded"
2767 run_test 49a "FIEMAP upon FLR file"
2769 test_50A() { # EX-2179
2772 local file=$DIR/$tdir/$tfile
2774 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2776 $LFS mirror extend -N -c1 -i1 $file ||
2777 error "extending mirror for $file failed"
2779 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2783 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2785 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2787 echo "$file layout generation from $olv to $flv"
2788 (( $flv != ($olv + 1) )) &&
2789 error "split does not increase layout gen from $olv to $flv"
2791 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2793 $LFS getstripe -v $file || error "getstripe $file failed"
2795 run_test 50A "mirror split update layout generation"
2798 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2799 skip "OST does not support SEEK_HOLE"
2800 [ "$FSTYPE" != "zfs" ] ||
2801 skip "lseek for ZFS is not accurate if obj is not committed"
2802 (( OST1_VERSION >= $(version_code 2.15.58) )) ||
2803 skip "Need OST version at least 2.15.58 for unaligned DIO"
2805 local file=$DIR/$tdir/$tfile
2813 echo " ** create striped file $file"
2814 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2815 error "cannot create file with PFL layout"
2816 echo " ** write 1st data chunk at 1M boundary"
2817 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2818 error "cannot write data at 1M boundary"
2819 echo " ** write 2nd data chunk at 2M boundary"
2820 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2821 error "cannot write data at 2M boundary"
2822 echo " ** create hole at the file end"
2823 $TRUNCATE $file 3700000 || error "truncate fails"
2825 echo " ** verify sparseness"
2826 offset=$(lseek_test -d 1000 $file)
2827 echo " first data offset: $offset"
2828 [[ $offset == 1000 ]] &&
2829 error "src: data is not expected at offset $offset"
2830 offset=$(lseek_test -l 3500000 $file)
2831 echo " hole at the end: $offset"
2832 [[ $offset == 3500000 ]] ||
2833 error "src: hole is expected at offset $offset"
2835 echo " ** extend the file with new mirror"
2836 # migrate_copy_data() is used
2837 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2838 error "cannot create mirror"
2839 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2840 error "$file still has stale component"
2842 # check migrate_data_copy() was correct
2843 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2844 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2845 [[ $sum_1 == $sum_2 ]] ||
2846 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2848 # stale first mirror
2849 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2850 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2852 echo " ** verify mirror #2 sparseness"
2853 offset=$(lseek_test -d 1000 $file)
2854 echo " first data offset: $offset"
2855 [[ $offset == 1000 ]] &&
2856 error "dst: data is not expected at offset $offset"
2857 offset=$(lseek_test -l 3500000 $file)
2858 echo " hole at the end: $offset"
2859 [[ $offset == 3500000 ]] ||
2860 error "dst: hole is expected at offset $offset"
2862 echo " ** copy mirror #2 to mirror #1"
2863 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2864 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2865 error "$file still has stale component"
2867 # check llapi_mirror_copy_many correctness
2868 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2869 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2870 [[ $sum_1 == $sum_2 ]] ||
2871 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2873 # stale 1st component of mirror #2 before lseek call
2874 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2876 echo " ** verify mirror #1 sparseness again"
2877 offset=$(lseek_test -d 1000 $file)
2878 echo " first data offset: $offset"
2879 [[ $offset == 1000 ]] &&
2880 error "dst: data is not expected at offset $offset"
2881 offset=$(lseek_test -l 3500000 $file)
2882 echo " hole at the end: $offset"
2883 [[ $offset == 3500000 ]] ||
2884 error "dst: hole is expected at offset $offset"
2886 cancel_lru_locks osc
2888 blocks=$(stat -c%b $file)
2889 echo " ** final consumed blocks: $blocks"
2890 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2891 # that file is still sparse
2892 (( blocks < 1000 )) ||
2893 error "Mirrored file consumes $blocks blocks"
2895 run_test 50a "mirror extend/copy preserves sparseness"
2898 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2899 skip "OST does not support SEEK_HOLE"
2900 [ "$FSTYPE" != "zfs" ] ||
2901 skip "lseek for ZFS is not accurate if obj is not committed"
2903 local file=$DIR/$tdir/$tfile
2910 stack_trap "rm -f $file"
2912 echo " ** create mirrored file $file"
2913 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2914 -N -E2M -S1M -E eof -S2M $file ||
2915 error "cannot create mirrored file"
2916 echo " ** write data chunk at 1M boundary"
2917 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2918 error "cannot write data at 1M boundary"
2919 echo " ** create hole at the file end"
2920 $TRUNCATE $file 3700000 || error "truncate fails"
2922 echo " ** verify sparseness"
2923 offset=$(lseek_test -d 1000 $file)
2924 echo " first data offset: $offset"
2925 [[ $offset == 1000 ]] &&
2926 error "src: data is not expected at offset $offset"
2927 offset=$(lseek_test -l 3500000 $file)
2928 echo " hole at the end: $offset"
2929 [[ $offset == 3500000 ]] ||
2930 error "src: hole is expected at 3500000"
2932 echo " ** resync mirror #2 to mirror #1"
2933 $LFS mirror resync $file
2935 # check llapi_mirror_copy_many correctness
2936 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2937 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2938 [[ $sum_1 == $sum_2 ]] ||
2939 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2941 cancel_lru_locks osc
2943 blocks=$(stat -c%b $file)
2944 echo " ** consumed blocks: $blocks"
2945 # without full punch() support the first component can be not sparse
2946 # but the last one should be, so file should use far fewer blocks
2947 (( blocks < 5000 )) ||
2948 error "Mirrored file consumes $blocks blocks"
2950 # stale first component in mirror #1
2951 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2952 echo " ** truncate file down"
2954 echo " ** write data chunk at 2M boundary"
2955 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2956 error "cannot write data at 2M boundary"
2957 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2958 $LFS mirror resync $file || error "mirror rsync fails"
2959 # first component is still stale
2960 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2961 error "$file still has no stale component"
2962 echo " ** resync mirror #2 to mirror #1 again"
2963 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2964 $LFS mirror resync $file || error "mirror rsync fails"
2965 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2966 error "$file still has stale component"
2968 # check llapi_mirror_copy_many correctness
2969 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2970 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2971 [[ $sum_1 == $sum_2 ]] ||
2972 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2974 cancel_lru_locks osc
2976 blocks=$(stat -c%b $file)
2977 echo " ** final consumed blocks: $blocks"
2978 # while the first component can lose sparseness, the last one should
2979 # not, so whole file should still use far fewer blocks in total
2980 (( blocks < 3000 )) ||
2981 error "Mirrored file consumes $blocks blocks"
2983 run_test 50b "mirror rsync handles sparseness"
2986 local tf=$DIR/$tdir/$tfile
2988 test_mkdir $DIR/$tdir
2990 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
2991 verify_flr_state $tf "ro"
2993 if [[ "$FSTYPE" == "ldiskfs" ]]; then
2994 # ZFS does not support fallocate for now
2995 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
2996 skip_eopnotsupp "$out|punch hole in $tf failed"
2997 verify_flr_state $tf "wp"
3000 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
3001 $LFS mirror resync $tf || error "mirror resync $tf failed"
3002 verify_flr_state $tf "ro"
3004 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
3005 verify_flr_state $tf "wp"
3007 run_test 50c "punch_hole/mmap_write stale other mirrors"
3010 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3011 skip "OST does not support SEEK_HOLE"
3012 [ "$FSTYPE" != "zfs" ] ||
3013 skip "lseek for ZFS is not accurate if obj is not committed"
3015 local file=$DIR/$tdir/$tfile
3022 echo " ** create mirrored file $file"
3023 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3024 -N -E2M -S1M -E eof -S2M $file ||
3025 error "cannot create mirrored file"
3026 echo " ** write data chunk at 1M boundary"
3027 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3028 error "cannot write data at 1M boundary"
3029 echo " ** create hole at the file start"
3030 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3033 if [[ $rc -eq 0 ]]; then
3034 verify_flr_state $file "wp"
3035 elif [[ ! $prt =~ unsupported ]]; then
3036 error "punch hole in $file failed: $prt"
3038 skip "Fallocate punch is not supported: $prt"
3041 echo " ** verify sparseness"
3042 offset=$(lseek_test -d 1000 $file)
3043 echo " first data offset: $offset"
3044 (( $offset >= 1024 * 1024 )) ||
3045 error "src: data is not expected at offset $offset"
3047 echo " ** resync mirror #2"
3048 $LFS mirror resync $file
3050 # check llapi_mirror_copy_many correctness
3051 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3052 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3053 [[ $sum_1 == $sum_2 ]] ||
3054 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3056 cancel_lru_locks osc
3058 # stale first component in mirror #1
3059 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3060 echo " ** verify sparseness of mirror #2"
3061 offset=$(lseek_test -d 1000 $file)
3062 echo " first data offset: $offset"
3063 (( $offset >= 1024 * 1024 )) ||
3064 error "src: data is not expected at offset $offset"
3066 run_test 50d "mirror rsync keep holes"
3069 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3070 skip "OST does not support SEEK_HOLE"
3072 local file=$DIR/$tdir/$tfile
3073 local old_size=2147483648 # 2GiB
3077 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3078 $TRUNCATE $file $old_size
3080 $LFS mirror extend -N -c 1 $file
3081 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3082 $LFS mirror resync $file
3084 new_size=$(stat --format='%s' $file)
3085 if ((new_size != old_size)); then
3086 error "new_size ($new_size) is not equal to old_size ($old_size)"
3089 run_test 60a "mirror extend sets correct size on sparse file"
3091 get_flr_layout_gen() {
3092 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3093 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3096 check_layout_gen() {
3099 local v1=$(get_flr_layout_gen $tf)
3100 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3102 [[ $v1 -eq $v2 ]] ||
3103 error "$tf in-memory layout gen $v1 != $v2 after $2"
3107 local tf=$DIR/$tdir/$tfile
3109 test_mkdir $DIR/$tdir
3111 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3113 for ((i = 0; i < 20; i++)); do
3114 $LFS mirror extend -N $tf ||
3115 error "extending mirror for $tf failed"
3116 check_layout_gen $tf "extend"
3118 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3119 error "split $tf failed"
3120 check_layout_gen $tf "split"
3123 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3126 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3131 local -a old=( $2 $3 $4 )
3134 new=( $(get_times_61 $file) )
3135 ((${old[0]} == ${new[0]})) ||
3136 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3138 ((${old[1]} == ${new[1]})) ||
3139 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3142 test_61a() { # LU-14508
3143 local file=$DIR/$tdir/$tfile
3144 local old_diff=($(do_facet mds1 "$LCTL get_param -n mdd.*.atime_diff"))
3145 local mdts=$(comma_list $(mdts_nodes))
3149 do_nodes $mdts "$LCTL set_param mdd.*.atime_diff=1"
3150 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.atime_diff=$old_diff"
3154 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3155 echo "create $file-2"
3156 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3158 echo XXX > $file || error "write $file failed"
3159 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3161 echo "sleep $nap seconds, then cat $tfile"
3163 cat $file || error "cat $file failed"
3165 echo "sleep $nap seconds, then re-write $tfile"
3167 echo XXXX > $file || error "write $file failed"
3168 cp -p $file $file-2 || error "copy $file-2 failed"
3170 # flush opencache to update atime with close rpc
3171 cancel_lru_locks mdc
3173 echo "sleep $nap seconds"
3176 tim=( $(get_times_61 $file) )
3178 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3179 $LFS mirror extend -N -f $file-2 $file ||
3180 error "cannot mirror merge $file-2 to $file"
3181 check_times_61 $file "${tim[@]}"
3183 echo "mirror extend $tfile and test timestamps"
3184 $LFS mirror extend -N -c1 -i1 $file ||
3185 error "cannot extend mirror $file"
3186 check_times_61 $file "${tim[@]}"
3188 echo "migrate $tfile and test timestamps"
3189 $LFS migrate -n $file || error "cannot migrate $file"
3190 check_times_61 $file "${tim[@]}"
3192 echo "normal user migrate $tfile and test timestamps"
3193 $RUNAS -G0 $LFS migrate -n $file || error "cannot migrate $file"
3194 check_times_61 $file "${tim[@]}"
3196 run_test 61a "mirror extend and migrate preserve timestamps"
3198 test_61b() { # LU-14508
3199 local file=$DIR/$tdir/$tfile
3205 echo XXX > $file || error "create $file failed"
3206 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3208 echo "sleep $nap seconds, then cat $tfile"
3210 cat $file || error "cat $file failed"
3212 echo "sleep $nap seconds, then re-write $tfile"
3214 echo XXXX > $file || error "write $file failed"
3216 echo "sleep $nap seconds, then test timestamps"
3219 tim=( $(get_times_61 $file) )
3221 echo "mirror extend $tfile and test timestamps"
3222 $LFS mirror extend -N -c1 -i1 $file ||
3223 error "cannot extend mirror $file"
3224 check_times_61 $file "${tim[@]}"
3226 echo "mirror split $tfile and test timestamps"
3227 $LFS mirror split -d --mirror-id=1 $file ||
3228 error "cannot split mirror 1 off $file"
3229 check_times_61 $file "${tim[@]}"
3231 echo "normal user mirror extend $tfile and test timestamps"
3232 $RUNAS -G0 $LFS mirror extend -N -c1 -i1 $file ||
3233 error "cannot extend mirror $file"
3234 check_times_61 $file "${tim[@]}"
3236 run_test 61b "mirror extend and split preserve timestamps"
3238 test_61c() { # LU-14508
3239 local file=$DIR/$tdir/$tfile
3245 echo XXX > $file || error "create $file failed"
3246 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3248 echo "sleep $nap seconds, then cat $tfile"
3250 cat $file || error "cat $file failed"
3252 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3254 $LFS mirror extend -N -c1 -i1 $file ||
3255 error "cannot extend mirror $file"
3256 echo XXXX > $file || error "write $file failed"
3258 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3259 tim=( $(get_times_61 $file) )
3261 $LFS mirror resync $file || error "cannot resync mirror $file"
3262 check_times_61 $file "${tim[@]}"
3264 echo XXXXXX > $file || error "write $tfile failed"
3266 echo "normal user resync $tfile and test timestamps"
3267 tim=( $(get_times_61 $file) )
3268 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3269 check_times_61 $file "${tim[@]}"
3271 run_test 61c "mirror resync preserves timestamps"
3274 local file=$DIR/$tdir/$tfile
3278 echo "create mirror file with unknown magic"
3279 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3280 # mirror 2 in-memory magic is bad
3281 $LCTL set_param fail_loc=0x1426 fail_val=2
3282 $LFS setstripe -N --flags=prefer -N2 $file ||
3283 error "failed to create mirror file $file"
3284 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3285 [[ $magic == 0x0BAD0BD0 ]] ||
3286 error "mirror 2 magic $magic is not bad as expected"
3287 cat /etc/passwd > $file || error "cannot write to $file"
3288 diff /etc/passwd $file || error "read $file error"
3292 echo "create mirror file with unknown pattern"
3293 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3294 # mirror 1 in-memory pattern is bad
3295 $LCTL set_param fail_loc=0x1427 fail_val=1
3296 $LFS setstripe -N -N --flags=prefer $file ||
3297 error "failed to create mirror file $file"
3298 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3299 [[ $pattern == 502 ]] ||
3300 error "mirror 1 pattern $pattern is not bad as expected"
3301 cat /etc/passwd > $file || error "cannot write to $file"
3302 diff /etc/passwd $file || error "read $file error"
3304 run_test 62 "read/write with unknown type of mirror"
3307 local tf=$DIR/$tdir/$tfile
3309 test_mkdir $DIR/$tdir
3310 stack_trap "rm -f $tf"
3314 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3318 echo "mirror create pid $c_pid"
3321 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3324 echo "mirror split pid $s_pid"
3326 echo "mirror create and split race for 60 seconds, should not crash"
3328 kill -9 $c_pid &> /dev/null
3329 kill -9 $s_pid &> /dev/null
3333 run_test 70 "mirror create and split race"
3336 local tf=$DIR/$tdir/$tfile
3338 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3339 skip "Need OST version at least 2.14.51"
3342 test_mkdir $DIR/$tdir
3343 stack_trap "rm -f $tf"
3345 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3346 error "setstripe $tf failed"
3348 FSXNUM=${FSXNUM:-1000}
3349 FSXSEED=${FSXSEED:-0}
3350 $FSX -p 1 -N $FSXNUM -S $FSXSEED -M $tf ||
3351 error "fsx FLR file $tf failed"
3353 run_test 70a "flr mode fsx test"
3356 remote_ost_nodsh && skip "remote OST with nodsh"
3357 [[ "$ost1_FSTYPE" == "ldiskfs" ]] || skip "ldiskfs only test"
3359 local tf=$DIR/$tdir/$tfile
3361 test_mkdir $DIR/$tdir
3362 $LFS setstripe -c1 -i1 $tf|| error "setstripe $tf failed"
3363 $LFS mirror extend -N -c1 -i0 $tf || error "mirror extend $tf failed"
3365 local id=$($LFS getstripe -I $tf)
3366 local ost=$($LFS getstripe -v -I$id $tf | awk '/l_ost_idx/ {print $5}')
3367 local fid=$($LFS getstripe -v -I$id $tf | awk '/l_fid/ {print $7}')
3368 local pfid=$($LFS getstripe -v -I$id $tf | awk '/lmm_fid/ {print $2}')
3370 ost=$(echo $ost | sed -e "s/,$//g")
3373 local dev=$(ostdevname $ost)
3374 local obj_file=$(ost_fid2_objpath ost$ost $fid)
3376 ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' $dev \
3377 2>/dev/null" | grep "parent=")
3378 if [ -z "$ff" ]; then
3380 mount_fstype ost$ost
3381 ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
3382 $(facet_mntpt ost$ost)/$obj_file)
3383 unmount_fstype ost$ost
3384 start ost$ost $dev $OST_MOUNT_OPTS
3388 local pseq=$(echo $ff | awk -F '[:= ]' '/parent/ { print $4 }')
3389 local poid=$(echo $ff | awk -F '[:= ]' '/parent/ { print $5 }')
3390 local pver=$(echo $ff | awk -F '[:= ]' '/parent/ { print $6 }')
3391 local parent="$pseq:$poid:$pver"
3393 log " ** lfs fid2path $MOUNT $parent"
3394 $LFS fid2path $MOUNT "$parent" || {
3396 error "cannot find parent $parent of OST object $fid"
3398 [ "$parent" == "$pfid" ] || {
3400 error "parent $parent of OST object $fid is not $pfid"
3403 run_test 71 "check mirror extend parent fid"
3408 local fsize=$(stat --printf=%s $tf)
3410 while [ -f $ctrl_file ]; do
3411 local off=$((RANDOM << 8))
3412 local len=$((RANDOM << 5 + 131072))
3414 [ $((off + len)) -gt $fsize ] && {
3415 fsize=$((off + len))
3416 echo "Extending file size to $fsize .."
3419 flock -s $lock_file -c \
3420 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3422 error "failed writing to $off:$len"; }
3423 sleep 0.$((RANDOM % 2 + 1))
3430 while [ -f $ctrl_file ]; do
3431 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3432 { rm -f $ctrl_file; error "read failed"; }
3433 sleep 0.$((RANDOM % 2 + 1))
3440 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3442 exec 200<>$lock_file
3443 while [ -f $ctrl_file ]; do
3444 local lock_taken=false
3445 local index=$((RANDOM % ${#options[@]}))
3446 local cmd="mirror_io resync ${options[$index]}"
3448 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3450 [ $((RANDOM % 4)) -eq 0 ] && {
3456 echo -n "resync file $tf with '$cmd' .."
3458 if [[ $lock_taken = "true" ]]; then
3460 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3463 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3466 sleep 0.$((RANDOM % 8 + 1))
3470 # this was test_200 before adding "b" and "c" subtests
3472 local tf=$DIR/$tfile
3473 local tf2=$DIR2/$tfile
3474 local tf3=$DIR3/$tfile
3476 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3477 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3478 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3480 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3481 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3482 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3484 $LFS mirror extend -N -f $tf-2 $tf ||
3485 error "merging $tf-2 into $tf failed"
3486 $LFS mirror extend -N -f $tf-3 $tf ||
3487 error "merging $tf-3 into $tf failed"
3489 mkdir -p $MOUNT2 && mount_client $MOUNT2
3491 mkdir -p $MOUNT3 && mount_client $MOUNT3
3493 verify_flr_state $tf3 "ro"
3495 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3496 $LCTL set_param fail_loc=0x1A03
3498 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3499 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3503 write_file_200 $tf &
3509 write_file_200 $tf2 &
3512 read_file_200 $tf2 &
3515 resync_file_200 $tf3 &
3519 [ "$SLOW" = "yes" ] && sleep_time=360
3520 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3527 echo "Waiting ${pids[*]}"
3530 umount_client $MOUNT2
3531 umount_client $MOUNT3
3533 # resync and verify mirrors
3534 $LFS mirror resync $tf || error "final resync failed"
3537 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3539 for id in "${mirror_array[@]:1}"; do
3540 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3541 error "checksum error for mirror $id"
3546 run_test 200a "stress test"
3549 local tf=$DIR/$tfile
3550 local tf2=$DIR2/$tfile
3551 local tf3=$DIR3/$tfile
3553 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3554 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3555 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3557 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3558 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3559 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3561 $LFS mirror extend -N -f $tf-2 $tf ||
3562 error "merging $tf-2 into $tf failed"
3563 $LFS mirror extend -N -f $tf-3 $tf ||
3564 error "merging $tf-3 into $tf failed"
3566 mkdir -p $MOUNT2 && mount_client $MOUNT2
3568 mkdir -p $MOUNT3 && mount_client $MOUNT3
3570 verify_flr_state $tf3 "ro"
3572 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3573 $LCTL set_param fail_loc=0x1423
3577 write_file_200 $tf &
3583 write_file_200 $tf2 &
3586 read_file_200 $tf2 &
3589 resync_file_200 $tf3 &
3593 [ "$SLOW" = "yes" ] && sleep_time=400
3597 echo "Waiting ${pids[@]}"
3600 umount_client $MOUNT2
3601 umount_client $MOUNT3
3603 # resync and verify mirrors
3604 $LFS mirror resync $tf || {
3606 error "final resync failed"
3610 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3611 for id in ${mirror_array[@]:1}; do
3612 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3613 error "checksum error for mirror $id"
3618 run_test 200b "racing IO, mirror extend and resync"
3621 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3622 skip "Need MDS version at least 2.15.53"
3624 local tf=$DIR/$tfile
3625 local tf2=$DIR2/$tfile
3627 mkdir -p $MOUNT2 && mount_client $MOUNT2
3628 stack_trap "umount_client $MOUNT2"
3629 stack_trap "rm -f $tf"
3633 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3635 mdt_idx=$($LFS getstripe -m $tf)
3637 cancel_lru_locks mdc
3638 cancel_lru_locks osc
3640 # start a process modifying file, block it just
3641 # before layout lock acquisition
3642 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3643 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3644 #log "dd to stale replica"
3645 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3651 $LFS mirror extend -N -c -1 $tf2 || {
3653 error "can't mirror"
3655 log "mirror extend done"
3656 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3658 # wait for blocking dd to complete and modify file
3659 wait $PID || error "2nd dd failed"
3662 verify_mirror_count $tf 2
3664 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3667 error "both replicas are still in sync"
3670 $LFS mirror verify -vvv $tf || {
3672 error "corrupted in-sync file"
3675 run_test 200c "layout change racing with open: LOVEA changes"
3677 cleanup_test_201() {
3678 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3680 umount_client $MOUNT2
3684 local delay=${RESYNC_DELAY:-5}
3686 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3687 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3689 stack_trap cleanup_test_201 EXIT
3691 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3692 changelog_register -n)
3694 mkdir -p $MOUNT2 && mount_client $MOUNT2
3698 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3699 [ -z "$log" ] && { sleep 1; continue; }
3701 index=$(echo $log | awk '{print $1}')
3702 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3703 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3704 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3707 [ -z "$file" ] && continue
3709 local now=$(date +%s)
3711 echo "file: $file $fid was modified at $ts, now: $now, " \
3712 "will be resynced at $((ts+delay))"
3714 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3716 $LFS mirror resync $file
3717 echo "$file resync done"
3720 run_test 201 "FLR data mover"
3723 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3725 local tf=$DIR/$tfile
3728 $LFS setstripe -E 1M -S 1M -c 1 $tf
3729 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3730 verify_comp_attr stripe-count $tf ${ids[0]} 1
3732 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3733 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3734 verify_comp_attr stripe-count $tf ${ids[0]} 1
3735 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3737 dd if=/dev/zero of=$tf bs=1M count=2
3738 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3739 verify_comp_attr stripe-count $tf ${ids[0]} 1
3740 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3742 run_test 202 "lfs setstripe --add-component wide striping"
3745 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3746 skip "Need MDS version at least 2.11.55"
3747 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3749 local tf=$DIR/$tfile
3752 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3753 #delete first mirror
3754 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3757 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3758 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3759 error "getstripe count of mirror 2"
3760 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3762 #extend a mirror with 2 OSTs
3763 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3766 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3767 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3768 error "getstripe count of mirror 2"
3769 [[ x$old_id = x$new_id ]] ||
3770 error "mirror 2 changed ID from $old_id to $new_id"
3771 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3773 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3774 error "getstripe count of mirror 3"
3775 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3777 run_test 203 "mirror file preserve mirror ID"
3779 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3781 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3782 skip "skipped for lustre < $SEL_VER"
3784 local comp_file=$DIR/$tdir/$tfile
3788 test_mkdir $DIR/$tdir
3789 stack_trap "rm -f $comp_file"
3791 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3792 # by extension space to -1
3793 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3794 error "Create $comp_file failed"
3796 # Write to first component, extending & staling second mirror
3797 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3798 error "dd to extend + stale failed"
3800 $LFS getstripe $comp_file
3802 flg_opts="--component-flags init,stale"
3803 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3804 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3806 flg_opts="--component-flags extension"
3807 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3808 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3810 # mirror resync should not change the extents
3811 $LFS mirror resync $comp_file
3813 flg_opts="--component-flags init"
3814 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3815 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3817 flg_opts="--component-flags extension"
3818 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3819 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3821 sel_layout_sanity $comp_file 5
3823 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3825 # Simple test of FLR + self-extending layout, SEL in primary mirror
3827 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3828 skip "skipped for lustre < $SEL_VER"
3830 local comp_file=$DIR/$tdir/$tfile
3834 test_mkdir $DIR/$tdir
3835 stack_trap "rm -f $comp_file"
3837 # first mirror is 1M followed by extension space to -1, second mirror
3838 # is 0-10M, then 10M-(-1),
3839 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3840 error "Create $comp_file failed"
3842 # Write to first component, extending first component & staling
3844 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3845 error "dd to extend + stale failed"
3847 $LFS getstripe $comp_file
3849 flg_opts="--component-flags init"
3850 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3851 [ $found -eq 1 ] || error "write: First comp end incorrect"
3853 flg_opts="--component-flags extension"
3854 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3855 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3857 flg_opts="--component-flags init,stale"
3858 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3859 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3861 # This component is staled because it overlaps the extended first
3862 # component of the primary mirror, even though it doesn't overlap
3863 # the actual write - thus not inited.
3864 flg_opts="--component-flags stale"
3865 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3866 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3868 # mirror resync should not change the extents
3869 $LFS mirror resync $comp_file
3871 $LFS getstripe $comp_file
3873 flg_opts="--component-flags init"
3874 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3875 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3877 flg_opts="--component-flags extension"
3878 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3879 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3881 flg_opts="--component-flags init"
3882 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3883 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3885 flg_opts="--component-flags init"
3886 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3887 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3889 sel_layout_sanity $comp_file 5
3891 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3893 # FLR + SEL failed extension & component removal
3894 # extension space in second mirror
3896 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3897 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3898 skip "skipped for lustre < $SEL_VER"
3900 local comp_file=$DIR/$tdir/$tfile
3903 local ost_name=$(ostname_from_index $ost_idx1)
3905 test_mkdir $DIR/$tdir
3906 stack_trap "rm -f $comp_file"
3908 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3909 # extension space from 1M to 1G, then normal space to -1
3910 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3911 -E -1 $comp_file || error "Create $comp_file failed"
3913 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3916 # write to first comp (0 - 10M) of mirror 1, extending + staling
3917 # first + second comp of mirror 2
3918 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3921 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3924 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3926 $LFS getstripe $comp_file
3928 found=$($LFS find --component-start 0m --component-end 1m \
3929 --comp-flags init,stale $comp_file | wc -l)
3930 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3932 found=$($LFS find --component-start 1m --component-end EOF \
3933 --comp-flags stale,^init $comp_file | wc -l)
3934 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3936 local mirror_id=$($LFS getstripe --component-start=1m \
3937 --component-end=EOF $comp_file | \
3938 grep lcme_mirror_id | awk '{ print $2 }')
3940 [[ $mirror_id -eq 2 ]] ||
3941 error "component not in correct mirror? $mirror_id"
3943 $LFS mirror resync $comp_file
3945 $LFS getstripe $comp_file
3947 # component dimensions should not change from resync
3948 found=$($LFS find --component-start 1m --component-end EOF \
3949 --component-flags init $comp_file | wc -l)
3950 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3952 sel_layout_sanity $comp_file 4
3954 run_test 204c "FLR write/stale/resync test with component removal"
3956 # Successful repeated component in primary mirror
3958 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3959 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3960 skip "skipped for lustre < $SEL_VER"
3962 local comp_file=$DIR/$tdir/$tfile
3965 wait_delete_completed
3967 test_mkdir $DIR/$tdir
3968 stack_trap "rm -f $comp_file"
3970 # first mirror is 64M followed by extension space to -1, second mirror
3971 # is 0-10M, then 10M-(-1)
3972 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3973 error "Create $comp_file failed"
3975 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3976 local ost_name=$(ostname_from_index $ost_idx1)
3977 # degrade OST for first comp so we won't extend there
3978 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3979 obdfilter.$ost_name.degraded=1
3982 # Write beyond first component, causing repeat & stale second mirror
3983 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3986 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3987 obdfilter.$ost_name.degraded=0
3990 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3992 $LFS getstripe $comp_file
3994 found=$($LFS find --component-start 64m --component-end 128m \
3995 --component-flags init $comp_file | wc -l)
3996 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3998 local ost_idx2=$($LFS getstripe --component-start=64m \
3999 --component-end=128m --component-flags=init \
4001 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4002 local mirror_id=$($LFS getstripe --component-start=64m \
4003 --component-end=128m --component-flags=init \
4004 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4005 [[ $mirror_id -eq 1 ]] ||
4006 error "component not in correct mirror: $mirror_id, not 1"
4008 $LFS mirror resync $comp_file
4010 $LFS getstripe $comp_file
4012 # component dimensions should not change from resync
4013 found=$($LFS find --component-start 0m --component-end 64m \
4014 --component-flags init $comp_file | wc -l)
4015 [ $found -eq 1 ] || error "resync: first comp incorrect"
4016 found=$($LFS find --component-start 64m --component-end 128m \
4017 --component-flags init $comp_file | wc -l)
4018 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
4020 sel_layout_sanity $comp_file 5
4022 run_test 204d "FLR write/stale/resync sel test with repeated comp"
4024 # Successful repeated component, SEL in non-primary mirror
4026 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4027 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4028 skip "skipped for lustre < $SEL_VER"
4030 local comp_file=$DIR/$tdir/$tfile
4033 wait_delete_completed
4036 test_mkdir $DIR/$tdir
4037 stack_trap "rm -f $comp_file"
4039 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4040 # space to -1 (-z 64M, so first comp is 0-64M)
4041 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
4042 # will be not enough - one will be degraded, the other is used on
4043 # an overlapping mirror.
4044 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
4045 error "Create $comp_file failed"
4047 local ost_idx1=$($LFS getstripe --component-start=0 \
4048 --component-end=64m -i $comp_file)
4049 local ost_name=$(ostname_from_index $ost_idx1)
4050 # degrade OST for first comp of 2nd mirror so we won't extend there
4051 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4052 obdfilter.$ost_name.degraded=1
4055 $LFS getstripe $comp_file
4057 # Write to first component, stale & instantiate second mirror components
4058 # overlapping with the written component (0-100M);
4059 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4062 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4063 obdfilter.$ost_name.degraded=0
4065 $LFS getstripe $comp_file
4067 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
4069 found=$($LFS find --component-start 0m --component-end 64m \
4070 --component-flags init,stale $comp_file | wc -l)
4071 [ $found -eq 1 ] || error "write: first comp incorrect"
4073 # was repeated due to degraded ost
4074 found=$($LFS find --component-start 64m --component-end 128m \
4075 --component-flags init,stale $comp_file | wc -l)
4076 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4078 local ost_idx2=$($LFS getstripe --component-start=64m \
4079 --component-end=128m --component-flags=init \
4081 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4082 local mirror_id=$($LFS getstripe --component-start=0m \
4083 --component-end=64m --component-flags=init \
4084 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4085 [[ $mirror_id -eq 2 ]] ||
4086 error "component not in correct mirror? $mirror_id"
4088 $LFS mirror resync $comp_file
4090 $LFS getstripe $comp_file
4092 # component dimensions should not change from resync
4093 found=$($LFS find --component-start 0m --component-end 64m \
4094 --component-flags init,^stale $comp_file | wc -l)
4095 [ $found -eq 1 ] || error "resync: first comp incorrect"
4096 found=$($LFS find --component-start 64m --component-end 128m \
4097 --component-flags init,^stale $comp_file | wc -l)
4098 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4100 sel_layout_sanity $comp_file 5
4102 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4104 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4106 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4107 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4108 skip "skipped for lustre < $SEL_VER"
4110 local comp_file=$DIR/$tdir/$tfile
4113 wait_delete_completed
4115 test_mkdir $DIR/$tdir
4116 stack_trap "rm -f $comp_file"
4118 pool_add $TESTNAME || error "Pool creation failed"
4119 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4121 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4122 # space to -1 (-z 64M, so first comp is 0-64M)
4123 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4124 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4126 local ost_name0=$(ostname_from_index 0)
4127 local ost_name1=$(ostname_from_index 1)
4129 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4130 # extend original comp
4131 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4132 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4135 # a write to the 1st component, 100M length, which will try to stale
4136 # the first 100M of mirror 2, attempting to extend its 0-64M component
4137 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4140 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4141 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4144 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4146 $LFS getstripe $comp_file
4148 found=$($LFS find --component-start 0m --component-end 128m \
4149 --component-flags init,stale $comp_file | wc -l)
4150 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4152 local mirror_id=$($LFS getstripe --component-start=0m \
4153 --component-end=128m --component-flags=init \
4154 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4156 [[ $mirror_id -eq 2 ]] ||
4157 error "component not in correct mirror? $mirror_id, not 2"
4159 $LFS mirror resync $comp_file
4161 $LFS getstripe $comp_file
4163 # component dimensions should not change from resync
4164 found=$($LFS find --component-start 0m --component-end 128m \
4165 --component-flags init,^stale $comp_file | wc -l)
4166 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4168 sel_layout_sanity $comp_file 4
4170 run_test 204f "FLR write/stale/resync sel w/forced extension"
4172 function test_205a() {
4173 local tf=$DIR/$tfile
4176 $LFS setstripe -c1 $tf
4177 $LFS mirror extend -N $tf
4178 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4179 (( $mirrors == 2 )) || error "no new mirror was created?"
4181 $LFS mirror extend -N --flags=prefer $tf
4182 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4183 (( $mirrors == 3 )) || error "no new mirror with prefer flag was created?"
4185 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4186 error "prefer flag was not set on the new mirror"
4188 run_test 205a "lfs mirror extend to set prefer flag"
4190 function test_205b() {
4191 if (( MDS1_VERSION <= $(version_code v2_15_61-245-g37e1316050) )) ; then
4192 skip "Need MDS > v2_15_61-245-g37e1316050 to test nocompr flag"
4195 local tf=$DIR/$tfile
4198 $LFS setstripe -c1 $tf ||
4199 error "$LFS setstripe -c $tf failed"
4201 $LFS mirror extend -N --flags=nocompr $tf ||
4202 error "$LFS mirror extend -N --flags=nocompr $tf failed"
4204 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4205 (( $mirrors == 2 )) || error "no new mirror with nocompr flag was created?"
4207 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q nocompr) ||
4208 error "nocompr flag was not set on the new mirror"
4210 $LFS mirror extend -N --flags=prefer,nocompr $tf ||
4211 error "$LFS mirror extend -N --flags=prefer,nocompr $tf failed"
4212 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4214 (( $mirrors == 3 )) || error "no new mirror with prefer,nocompr flags was created?"
4216 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q "prefer,nocompr") ||
4217 error "prefer,nocompr flags were not set on the new mirror"
4219 run_test 205b "lfs mirror extend to set nocompr flag"
4221 function test_206() {
4222 # create a new OST pool
4223 local pool_name=$TESTNAME
4225 create_pool $FSNAME.$pool_name ||
4226 error "create OST pool $pool_name failed"
4227 # add OSTs into the pool
4228 pool_add_targets $pool_name 0 1 ||
4229 error "add OSTs into pool $pool_name failed"
4231 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4232 error "can't setstripe"
4233 $LFS mirror extend -N $DIR/$tfile ||
4234 error "can't create replica"
4235 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4236 $LFS getstripe $DIR/$tfile
4237 error "prefer found"
4239 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4240 $LFS getstripe $DIR/$tfile
4241 error "can't setstripe prefer"
4244 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4245 $LFS getstripe $DIR/$tfile
4246 error "no prefer found"
4252 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4255 local file=$DIR/$tfile
4256 local tmpfile=$DIR/$tfile-tt
4258 (( $MDS1_VERSION >= $(version_code v2_14_50-161-g571f3cf111) )) ||
4259 skip "Need MDS >= 2.14.50.161 for stale components fix"
4261 stack_trap "rm -f $tmpfile $file"
4263 # generate data for verification
4264 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4265 error "can't generate file with random data"
4267 # create a mirrored file with one stale replica
4268 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4269 error "create mirrored file $file failed"
4270 get_mirror_ids $file
4271 echo "mirror IDs: ${mirror_array[*]}"
4273 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4274 get_mirror_ids $file
4275 echo "mirror IDs: ${mirror_array[*]}"
4278 cmp $tmpfile $file || error "files don't match"
4279 get_mirror_ids $file
4280 echo "mirror IDs: ${mirror_array[*]}"
4282 # mirror creation should work fine
4283 $LFS mirror extend -N -S 8M -c -1 $file ||
4284 error "mirror extend $file failed"
4286 get_mirror_ids $file
4287 echo "mirror IDs: ${mirror_array[*]}"
4290 $LFS mirror verify -v $file || error "verification failed"
4291 cmp $tmpfile $file || error "files don't match"
4293 run_test 207 "create another replica with existing out-of-sync one"
4295 function check_ost_used() {
4304 cancel_lru_locks osc # to drop pages
4305 cancel_lru_locks mdc # to refresh layout
4306 # XXX: cancel_lru_locks mdc doesn't work
4307 # XXX: need a better way to reload the layout
4308 umount_client $MOUNT || error "umount failed"
4309 mount_client $MOUNT || error "mount failed"
4311 # refresh non-rotation status on MDTs
4313 touch $DIR/$tfile-temp
4314 rm -f $DIR/$tfile-temp
4315 # refresh non-rotational status on the client
4319 $LCTL set_param osc.*.stats=clear >/dev/null
4320 if [[ $io == "read" ]]; then
4321 ddarg="if=$file of=/dev/null"
4322 elif [[ $io == "write" ]]; then
4323 ddarg="if=/dev/zero of=$file"
4325 error "unknown type $io"
4327 dd $ddarg bs=8M count=1 || error "can't $io $file"
4328 cancel_lru_locks osc
4330 # check only specified OSTs got reads
4331 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4332 local nr=$($LCTL get_param -n \
4333 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4334 awk "/ost_$io/{print \$2}")
4336 if [[ " $* " =~ $ost ]]; then
4337 (( nr > 0 )) || error "expected reads on $ost"
4339 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4345 local tf=$DIR/$tfile
4346 local osts=$(osts_nodes)
4348 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4349 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4350 skip "Need MDS version at least 2.14.55"
4352 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4354 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4355 stack_trap "restore_lustre_params < $p; rm -f $p"
4357 stack_trap "rm -f $tf"
4358 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4359 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4360 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4361 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4362 $LFS mirror resync $tf || error "can't resync"
4365 log "set OST0000 non-rotational"
4367 $LCTL set_param osd*.*OST*.nonrotational=0
4369 $LCTL set_param osd*.*OST0000*.nonrotational=1
4370 check_ost_used $tf read 0
4372 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4374 $LCTL set_param osd*.*OST*.nonrotational=0
4376 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4377 osd*.*OST0003*.nonrotational=1
4378 check_ost_used $tf read 2 3
4380 log "set mirror 1 on OST0001 preferred"
4381 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4382 error "can't set prefer"
4383 check_ost_used $tf read 1
4385 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4388 local tf=$DIR/$tfile
4389 local osts=$(osts_nodes)
4391 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4392 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4393 skip "Need MDS version at least 2.14.55"
4395 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4397 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4398 stack_trap "restore_lustre_params < $p; rm -f $p"
4400 stack_trap "rm -f $tf"
4401 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4402 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4403 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4404 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4405 $LFS mirror resync $tf || error "can't resync"
4406 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4408 log "set OST0000 non-rotational"
4410 $LCTL set_param osd*.*OST*.nonrotational=0
4412 $LCTL set_param osd*.*OST0000*.nonrotational=1
4413 check_ost_used $tf write 0
4414 $LFS mirror resync $tf || error "can't resync"
4416 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4418 $LCTL set_param osd*.*OST*.nonrotational=0
4420 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4421 osd*.*OST0003*.nonrotational=1
4422 check_ost_used $tf write 2 3
4423 $LFS mirror resync $tf || error "can't resync"
4425 log "set mirror 1 on OST0001 preferred"
4426 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4427 error "can't set prefer"
4428 check_ost_used $tf write 1
4430 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4433 local tf=$DIR/$tfile
4434 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4435 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4436 local osts=$(osts_nodes)
4438 stack_trap "rm -f $tmpfile"
4440 mkdir -p $MOUNT2 && mount_client $MOUNT2
4441 stack_trap "umount_client $MOUNT2"
4443 # to make replica on ost1 preferred for new writes
4444 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4445 stack_trap "restore_lustre_params < $p; rm -f $p"
4447 $LCTL set_param osd*.*OST*.nonrotational=0
4449 $LCTL set_param osd*.*OST0001*.nonrotational=1
4451 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4453 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4454 log "replicated file created"
4456 cancel_lru_locks mdc
4457 cancel_lru_locks osc
4459 log "open(O_RDONLY) and first read from OST"
4460 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4463 log "first read complete"
4465 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4466 error "can't write BBBB"
4467 log "BBBB written which made replica on ost1 stale"
4469 log "fast read from pagecache in the original process"
4473 log "read via $DIR2 new open(2)"
4474 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4476 log "fast read from pagecache after 5s in the original process"
4481 local nr=$(grep "BBBB" $tmpfile | wc -l)
4487 log "read via new open(2)"
4488 $MULTIOP $tf vvoO_RDONLY:r4c
4490 run_test 209a "skip fast reads after layout invalidation"
4492 function sum_ost_reads() {
4493 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4494 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4498 local tf=$DIR/$tfile
4500 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4501 cancel_lru_locks osc
4502 echo "the very first read"
4503 cat $tf >/dev/null || error "can't read"
4505 # cancel layout lock
4506 cancel_lru_locks mdc
4508 # now read again, data must be in the cache, so no ost reads
4509 $LCTL set_param osc.*.stats=clear >/dev/null
4510 echo "read with warm cache"
4511 cat $tf >/dev/null || error "can't read"
4513 (( nr == 0 )) || error "reads with warm cache"
4515 # now verify we can catch reads at all
4516 cancel_lru_locks osc
4517 cat $tf >/dev/null || error "can't read"
4519 (( nr > 0 )) || error "no reads with cold cache"
4521 run_test 209b "pagecache can be used after LL cancellation"
4524 local tf=$DIR/$tfile
4526 stack_trap "rm -f $tf"
4527 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4528 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4529 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4530 $LFS mirror extend -N $tf || error "can't mirror"
4531 $LFS getstripe -v $tf
4532 stat $tf || error "can't stat"
4534 run_test 210a "handle broken mirrored lovea"
4537 local tf=$DIR/$tfile
4539 [ "$FSTYPE" != "zfs" ] || skip "ZFS file number is not accurate"
4541 $LFS setstripe -i0 -c1 $tf || error "can't create file"
4542 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4544 local ostdev=$(ostdevname 1)
4545 local fids=($($LFS getstripe $DIR/$tfile | grep 0x))
4546 local fid="${fids[3]}:${fids[2]}:0"
4547 local objpath=$(ost_fid2_objpath ost1 $fid)
4548 local cmd="$DEBUGFS -c -R \\\"stat $objpath\\\" $ostdev"
4550 local ino=$(do_facet ost1 $cmd | grep Inode:)
4551 [[ -n $ino ]] || error "can't access obj object: $objpath"
4553 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4554 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4555 $LFS mirror extend -N $tf || error "can't mirror"
4557 # now remove the file with bogus ostidx in the striping info
4558 rm $tf || error "can't remove"
4559 [[ -f $tf ]] && error "rm failed"
4560 wait_delete_completed
4562 local ino=$(do_facet ost1 $cmd | grep Inode:)
4563 [[ -z $ino ]] || error "still CAN access obj object: $objpath"
4565 run_test 210b "handle broken mirrored lovea (unlink)"
4569 local tf=$DIR/$tfile
4571 dd if=/dev/zero of=$tf bs=$PAGE_SIZE count=10 oflag=direct ||
4572 error "error writing initial data to '$tf'"
4574 $LFS mirror extend -N $tf || error "error extending mirror for '$tf'"
4576 dd if=/dev/zero of=$tf bs=$PAGE_SIZE count=1 oflag=direct ||
4577 error "error writing $((PAGE_SIZE/1024))k to '$tf'"
4578 echo "size after second write"
4580 md5_1=$(md5sum $tf) || error "error getting first md5sum of '$tf'"
4582 $LFS mirror delete --mirror-id=1 $tf ||
4583 error "error deleting mirror 1 of '$tf'"
4584 echo "size after mirror delete"
4586 md5_2=$(md5sum $tf) || error "error getting second md5sum of '$tf'"
4587 [[ "${md5_1%% *}" = "${md5_2%% *}" ]] ||
4588 error "md5sums don't match after mirror ops on '$tf'"
4590 run_test 211 "mirror delete should not cause bad size"
4592 complete_test $SECONDS
4593 check_and_cleanup_lustre