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 "
31 if [ -r /etc/redhat-release ]; then
32 rhel_version=$(cat /etc/redhat-release |
33 sed -e 's/^[^0-9.]*//g' | sed -e 's/[ ].*//')
34 if (( $(version_code $rhel_version) >= $(version_code 9.3.0) )); then
35 always_except LU-17675 61a
41 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
42 skip "Need MDS version at least 2.10.56"
44 check_and_setup_lustre
47 rm -rf $DIR/[Rdfs][0-9]*
49 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
50 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
52 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
55 # global array to store mirror IDs
56 declare -a mirror_array
63 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
64 array[${#array[@]}]=$((id >> 16))
67 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
69 echo ${#mirror_array[@]}
73 echo 3 > /proc/sys/vm/drop_caches
84 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
92 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
93 error "start ost$idx failed"
97 wait_recovery_complete ost$idx
102 # Verify mirror count with an expected value for a given file.
104 verify_mirror_count() {
107 local mirror_count=$($LFS getstripe -N $tf)
109 [[ $mirror_count = $expected ]] || {
110 $LFS getstripe -v $tf
111 error "verify mirror count failed on $tf:" \
112 "$mirror_count != $expected"
117 # Verify component count with an expected value for a given file.
118 # $1 coposited layout file
119 # $2 expected component number
121 verify_comp_count() {
124 local comp_count=$($LFS getstripe --component-count $tf)
126 [[ $comp_count = $expected ]] || {
127 $LFS getstripe -v $tf
128 error "verify component count failed on $tf:" \
129 "$comp_count != $expected"
134 # Verify component attribute with an expected value for a given file
142 local cmd="$LFS getstripe -I$comp_id"
143 local getstripe_cmd="$cmd -v"
147 stripe-size) cmd+=" -S $tf" ;;
148 stripe-count) cmd+=" -c $tf" ;;
149 stripe-index) cmd+=" -i $tf" ;;
150 pool) cmd+=" -p $tf" ;;
151 comp-start) cmd+=" --component-start $tf" ;;
152 comp-end) cmd+=" --component-end $tf" ;;
153 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
154 *) error "invalid attribute $attr";;
159 [ $attr = lcme_flags ] && {
161 local expected_list=$(comma_list $expected)
162 for fl in ${expected_list//,/ }; do
165 [[ ${fl:0:1} = "^" ]] && neg=1
166 [[ $neg = 1 ]] && fl=${fl:1}
168 $(echo $value | grep -q $fl)
170 # 0: matched; 1: not matched
172 if [[ $neg = 0 && $match != 0 ||
173 $neg = 1 && $match = 0 ]]; then
175 [[ $neg = 0 ]] && # expect the flag
176 error "expected flag '$fl' not in $comp_id"
177 [[ $neg = 1 ]] && # not expect the flag
178 error "not expected flag '$fl' in $comp_id"
184 [[ $value = $expected ]] || {
186 error "verify $attr failed on $tf: $value != $expected"
191 # Verify component extent with expected start and end extent values
192 # for a given file and component ID.
194 verify_comp_extent() {
197 local expected_start=$3
198 local expected_end=$4
200 verify_comp_attr comp-start $tf $comp_id $expected_start
201 verify_comp_attr comp-end $tf $comp_id $expected_end
205 # Verify component attribute with parent directory for a given file
208 verify_comp_attr_with_parent() {
212 local td=$(cd $(dirname $tf); echo $PWD)
213 local tf_cmd="$LFS getstripe -I$comp_id"
214 local td_cmd="$LFS getstripe"
220 stripe-size) opt="-S" ;;
221 stripe-count) opt="-c" ;;
223 *) error "invalid attribute $attr";;
226 expected=$($td_cmd $opt $td)
227 [[ $expected = -1 ]] && expected=$OSTCOUNT
229 value=$($tf_cmd $opt $tf)
230 [[ $value = -1 ]] && value=$OSTCOUNT
232 [[ $value = $expected ]] || {
235 error "verify $attr failed with parent on $tf:" \
236 "$value != $expected"
241 # Verify component attribute with filesystem-wide default value for a given file
244 verify_comp_attr_with_default() {
248 local tf_cmd="$LFS getstripe -I$comp_id"
256 expected=$($LCTL get_param -n \
257 lov.$FSNAME-clilov-*.stripesize)
261 expected=$($LCTL get_param -n \
262 lov.$FSNAME-clilov-*.stripecount)
263 [[ $expected = -1 ]] && expected=$OSTCOUNT
265 *) error "invalid attribute $attr";;
268 value=$($tf_cmd $opt $tf)
269 [[ $value = -1 ]] && value=$OSTCOUNT
271 [[ $value = $expected ]] || {
273 error "verify $attr failed with default value on $tf:" \
274 "$value != $expected"
279 # Verify unspecified component attributes for a given file
282 # This will only verify the inherited attributes:
283 # stripe size, stripe count and OST pool name
285 verify_comp_attrs() {
289 verify_comp_attr_with_default stripe-size $tf $comp_id
290 verify_comp_attr_with_default stripe-count $tf $comp_id
291 verify_comp_attr_with_parent pool $tf $comp_id
297 local expected_state=$2
299 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
300 [ $expected_state = $state ] ||
301 error "expected: $expected_state, actual $state"
304 # command line test cases
308 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
309 local mirror_cmd="$LFS mirror create"
314 # create parent directory
315 mkdir $td || error "mkdir $td failed"
317 $mirror_cmd $tf &> /dev/null && error "miss -N option"
319 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
320 verify_mirror_count $tf 1
321 id=$($LFS getstripe -I $tf)
322 verify_comp_attrs $tf $id
323 verify_comp_extent $tf $id 0 EOF
325 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
326 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
327 error "invalid mirror count $((mirror_count + 1))"
329 $mirror_cmd -N$mirror_count $tf-1 ||
330 error "create mirrored file $tf-1 failed"
331 verify_mirror_count $tf-1 $mirror_count
332 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
333 for ((i = 0; i < $mirror_count; i++)); do
334 verify_comp_attrs $tf-1 ${ids[$i]}
335 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
338 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
339 error "create mirrored file $tf-2 failed"
340 verify_mirror_count $tf-2 10
341 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
342 for ((i = 0; i < 10; i++)); do
343 verify_comp_attrs $tf-2 ${ids[$i]}
344 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
347 run_test 0a "lfs mirror create with -N option"
350 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
354 local mirror_cmd="$LFS mirror create"
358 # create a new OST pool
359 local pool_name=$TESTNAME
360 create_pool $FSNAME.$pool_name ||
361 error "create OST pool $pool_name failed"
363 # add OSTs into the pool
364 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
365 error "add OSTs into pool $pool_name failed"
367 # create parent directory
368 mkdir $td || error "mkdir $td failed"
369 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
370 error "$LFS setstripe $td failed"
372 create_pool $FSNAME.flash || error "create OST pool flash failed"
373 create_pool $FSNAME.archive || error "create OST pool archive failed"
375 # create a mirrored file with plain layout mirrors
376 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
377 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
378 error "create mirrored file $tf failed"
379 verify_mirror_count $tf 6
380 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
381 for ((i = 0; i < 6; i++)); do
382 verify_comp_extent $tf ${ids[$i]} 0 EOF
385 # verify component ${ids[0]}
386 verify_comp_attrs $tf ${ids[0]}
388 # verify component ${ids[1]}
389 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
390 verify_comp_attr stripe-count $tf ${ids[1]} 2
391 verify_comp_attr stripe-index $tf ${ids[1]} 2
393 # verify component ${ids[2]}
394 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
395 verify_comp_attr stripe-count $tf ${ids[2]} 2
396 verify_comp_attr pool $tf ${ids[2]} flash
398 # verify component ${ids[3]}
399 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
400 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
401 verify_comp_attr pool $tf ${ids[3]} flash
403 # verify component ${ids[4]}
404 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
405 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
406 verify_comp_attr pool $tf ${ids[4]} archive
408 # verify component ${ids[5]}
409 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
410 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
411 verify_comp_attr_with_parent pool $tf ${ids[5]}
413 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
414 # LU-11022 - remove mirror by pool name
415 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
416 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
417 $LFS mirror delete --pool archive $tf || error "delete mirror"
418 cnt=$($LFS getstripe $tf | grep archive | wc -l)
419 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
425 run_test 0b "lfs mirror create plain layout mirrors"
428 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
432 local mirror_cmd="$LFS mirror create"
436 # create a new OST pool
437 local pool_name=$TESTNAME
438 create_pool $FSNAME.$pool_name ||
439 error "create OST pool $pool_name failed"
441 # add OSTs into the pool
442 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
443 error "add OSTs into pool $pool_name failed"
445 # create parent directory
446 mkdir $td || error "mkdir $td failed"
447 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
448 error "$LFS setstripe $td failed"
450 create_pool $FSNAME.flash ||
451 error "create OST pool flash failed"
452 create_pool $FSNAME.archive ||
453 error "create OST pool archive failed"
455 # create a mirrored file with composite layout mirrors
456 $mirror_cmd -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
458 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
459 error "create mirrored file $tf failed"
460 verify_mirror_count $tf 6
461 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
463 # verify components ${ids[0]} and ${ids[2]}
465 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
466 verify_comp_attr stripe-count $tf ${ids[$i]} 2
467 verify_comp_attr stripe-index $tf ${ids[$i]} 1
468 verify_comp_extent $tf ${ids[$i]} 0 8388608
471 # verify components ${ids[1]} and ${ids[3]}
473 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
474 verify_comp_attr stripe-count $tf ${ids[$i]} 2
475 verify_comp_attr pool $tf ${ids[$i]} flash
476 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
479 # verify component ${ids[4]}
480 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
481 verify_comp_attr stripe-count $tf ${ids[4]} 4
482 verify_comp_attr_with_parent pool $tf ${ids[4]}
483 verify_comp_extent $tf ${ids[4]} 0 EOF
485 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
487 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
488 verify_comp_attr stripe-count $tf ${ids[$i]} 4
489 verify_comp_attr pool $tf ${ids[$i]} archive
490 verify_comp_extent $tf ${ids[$i]} 0 536870912
493 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
495 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
496 verify_comp_attr stripe-count $tf ${ids[$i]} -1
497 verify_comp_attr pool $tf ${ids[$i]} archive
498 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
504 run_test 0c "lfs mirror create composite layout mirrors"
509 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
510 local mirror_cmd="$LFS mirror extend"
514 # create parent directory
515 mkdir $td || error "mkdir $td failed"
517 $mirror_cmd $tf &> /dev/null && error "miss -N option"
518 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
520 # create a non-mirrored file, convert it to a mirrored file and extend
521 touch $tf || error "touch $tf failed"
522 $mirror_cmd -N $tf || error "convert and extend $tf failed"
523 verify_mirror_count $tf 2
524 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
525 for ((i = 0; i < 2; i++)); do
526 verify_comp_attrs $tf ${ids[$i]}
527 verify_comp_extent $tf ${ids[$i]} 0 EOF
530 lfsck_verify_pfid $tf || error "PFID is not set"
532 # create a mirrored file and extend it
533 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
534 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
535 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
537 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
538 error "extend mirror with -f failed"
540 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
541 error "extend mirrored file $tf-3 failed"
542 verify_mirror_count $tf-3 $mirror_count
543 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
544 for ((i = 0; i < $mirror_count; i++)); do
545 verify_comp_attrs $tf-3 ${ids[$i]}
546 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
549 $mirror_cmd -N $tf-3 &> /dev/null
552 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
554 run_test 0d "lfs mirror extend with -N option"
557 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
561 local mirror_cmd="$LFS mirror extend"
565 # create parent directory
566 mkdir $td || error "mkdir $td failed"
568 create_pool $FSNAME.ssd ||
569 error "create OST pool ssd failed"
571 # create a mirrored file with plain layout mirrors
572 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
573 error "create mirrored file $tf failed"
575 create_pool $FSNAME.flash ||
576 error "create OST pool flash failed"
577 create_pool $FSNAME.archive ||
578 error "create OST pool archive failed"
580 # extend the mirrored file with plain layout mirrors
581 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
582 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
583 error "extend mirrored file $tf failed"
584 verify_mirror_count $tf 6
585 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
586 for ((i = 0; i < 6; i++)); do
587 verify_comp_extent $tf ${ids[$i]} 0 EOF
590 # verify component ${ids[0]}
591 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
592 verify_comp_attr stripe-count $tf ${ids[0]} 3
593 verify_comp_attr stripe-index $tf ${ids[0]} 1
595 # verify component ${ids[1]}
596 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
597 verify_comp_attr stripe-count $tf ${ids[1]} 2
598 verify_comp_attr stripe-index $tf ${ids[1]} 2
600 # verify component ${ids[2]}
601 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
602 verify_comp_attr stripe-count $tf ${ids[2]} 2
603 verify_comp_attr pool $tf ${ids[2]} flash
605 # verify component ${ids[3]}
606 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
607 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
608 verify_comp_attr pool $tf ${ids[3]} flash
610 # verify component ${ids[4]}
611 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
612 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
613 verify_comp_attr pool $tf ${ids[4]} archive
615 # verify component ${ids[5]}
616 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
617 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
618 verify_comp_attr_with_parent pool $tf ${ids[5]}
620 run_test 0e "lfs mirror extend plain layout mirrors"
623 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
627 local mirror_cmd="$LFS mirror extend"
631 # create parent directory
632 mkdir $td || error "mkdir $td failed"
634 create_pool $FSNAME.ssd ||
635 error "create OST pool ssd failed"
637 # create a mirrored file with composite layout mirror
638 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
639 error "create mirrored file $tf failed"
641 create_pool $FSNAME.flash ||
642 error "create OST pool flash failed"
643 create_pool $FSNAME.archive ||
644 error "create OST pool archive failed"
646 # extend the mirrored file with composite layout mirrors
647 $mirror_cmd -N -p archive \
648 -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
650 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
651 error "extend mirrored file $tf failed"
652 verify_mirror_count $tf 8
653 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
655 # verify component ${ids[0]}
656 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
657 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
658 verify_comp_attr pool $tf ${ids[0]} ssd
659 verify_comp_extent $tf ${ids[0]} 0 33554432
661 # verify component ${ids[1]}
662 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
663 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
664 verify_comp_attr pool $tf ${ids[1]} ssd
665 verify_comp_extent $tf ${ids[1]} 33554432 EOF
667 # verify component ${ids[2]}
668 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
669 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
670 verify_comp_attr pool $tf ${ids[2]} archive
671 verify_comp_extent $tf ${ids[2]} 0 EOF
673 # verify components ${ids[3]} and ${ids[5]}
675 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
676 verify_comp_attr stripe-count $tf ${ids[$i]} 2
677 verify_comp_attr stripe-index $tf ${ids[$i]} 1
678 verify_comp_extent $tf ${ids[$i]} 0 8388608
681 # verify components ${ids[4]} and ${ids[6]}
683 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
684 verify_comp_attr stripe-count $tf ${ids[$i]} 2
685 verify_comp_attr pool $tf ${ids[$i]} flash
686 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
689 # verify component ${ids[7]}
690 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
691 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
692 verify_comp_attr_with_parent pool $tf ${ids[7]}
693 verify_comp_extent $tf ${ids[7]} 0 EOF
695 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
697 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
698 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
699 verify_comp_attr pool $tf ${ids[$i]} archive
700 verify_comp_extent $tf ${ids[$i]} 0 536870912
703 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
705 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
706 verify_comp_attr stripe-count $tf ${ids[$i]} -1
707 verify_comp_attr pool $tf ${ids[$i]} archive
708 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
711 run_test 0f "lfs mirror extend composite layout mirrors"
716 ! $LFS mirror create --flags prefer $tf ||
717 error "creating $tf w/ --flags but w/o -N option should fail"
719 ! $LFS mirror create -N --flags foo $tf ||
720 error "creating $tf with '--flags foo' should fail"
722 ! $LFS mirror create -N --flags stale $tf ||
723 error "creating $tf with '--flags stale' should fail"
725 ! $LFS mirror create -N --flags prefer,init $tf ||
726 error "creating $tf with '--flags prefer,init' should fail"
728 ! $LFS mirror create -N --flags ^prefer $tf ||
729 error "creating $tf with '--flags ^prefer' should fail"
731 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
732 -N -o1 $tf || error "create mirrored file $tf failed"
734 verify_comp_attr lcme_flags $tf 0x10001 prefer
735 verify_comp_attr lcme_flags $tf 0x10002 prefer
737 # write to the mirrored file and check primary
738 cp /etc/hosts $tf || error "error writing file '$tf'"
740 verify_comp_attr lcme_flags $tf 0x20003 stale
742 # resync file and check prefer flag
743 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
746 $LCTL set_param osc.*.stats=clear
747 cat $tf &> /dev/null || error "error reading file '$tf'"
749 # verify that the data was provided by OST1 where mirror 1 resides
750 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
751 awk '/ost_read/{print $2}')
752 [ -n "$nr_read" ] || error "read was not provided by OST1"
754 run_test 0g "lfs mirror create flags support"
757 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
758 skip "Need MDS version at least 2.11.57"
766 # create parent directory
767 test_mkdir $td || error "mkdir $td failed"
769 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
770 error "set default mirrored layout on directory $td failed"
772 # verify flags are inherited from the directory
775 verify_comp_attr lcme_flags $tf 0x10001 prefer
776 verify_comp_attr lcme_flags $tf 0x10002 prefer
778 # set flags to the first component
779 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
780 error "setting '^prefer,foo' flags should fail"
782 ! $LFS getstripe --component-flags=prefer,foo $tf ||
783 error "getting component(s) with 'prefer,foo' flags should fail"
785 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
787 verify_comp_attr lcme_flags $tf 0x10001 stale
788 verify_comp_attr lcme_flags $tf 0x10002 prefer
790 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
791 error "clearing 'stale' should fail"
793 # write and resync file. It can't resync the file directly because the
794 # file state is still 'ro'
795 cp /etc/hosts $tf || error "error writing file '$tf'"
796 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
798 for flag in prefer prefrd prefwr; do
799 $LFS setstripe --comp-set -I 0x20003 --comp-flags=$flag $tf ||
800 error "error setting flag $flag"
802 verify_comp_attr lcme_flags $tf 0x20003 $flag
804 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^$flag $tf ||
805 error "error clearing $flag flag from component 0x20003"
808 # MDS disallows setting stale flag on the last non-stale mirror
809 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
811 cp /etc/hosts $tf || error "error writing file '$tf'"
813 verify_comp_attr lcme_flags $tf 0x10002 prefer
814 verify_comp_attr lcme_flags $tf 0x20003 stale
815 verify_comp_attr lcme_flags $tf 0x30004 stale
817 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
819 error "setting stale flag on component 0x10002 should fail"
821 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
823 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
824 error "error setting stale flag on component 0x10001"
825 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
826 error "error setting stale flag on component 0x20003"
828 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
830 error "setting stale flag on component 0x30004 should fail"
832 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
834 run_test 0h "set, clear and test flags for FLR files"
837 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
839 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
840 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
841 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
843 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
844 stack_trap "rm -f $TMP/$tfile"
845 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
846 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
847 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
848 error "set component 1 stale failed"
849 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
850 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
852 run_test 0j "test lfs mirror read/write commands"
855 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
858 # default FLR with 2 mirrors
859 $LFS setstripe -N -c1 -i0 -N -c1 -i1 $DIR/$tdir ||
860 error "set default layout failed"
862 # plain file extension under default FLR dir
863 echo $tfile >> $DIR/$tdir/$tfile.append || error "create $tfile.append failed"
864 echo -n " before extend $tfile.append, mirror count = "
865 $LFS getstripe -N $DIR/$tdir/$tfile.append
867 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile.append ||
868 error "mirror extend failed"
869 echo -n " after extend $tfile.append, mirror count = "
870 $LFS getstripe -N $DIR/$tdir/$tfile.append
872 # normal file extension under default FLR dir
873 touch $DIR/$tdir/$tfile || error "create $tfile failed"
874 echo -n " before extend $tfile, mirror count = "
875 $LFS getstripe -N $DIR/$tdir/$tfile
877 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile ||
878 error "mirror extend $tfile failed"
879 echo -n " after extend $tfile, mirror count = "
880 $LFS getstripe -N $DIR/$tdir/$tfile
882 run_test 0k "mirroring a file in directory with default FLR layout"
886 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
887 local mirror_create_cmd="$LFS mirror create"
888 local stripes[0]=$OSTCOUNT
890 mirror_create_cmd+=" -N -c ${stripes[0]}"
891 for ((i = 1; i < $mirror_count; i++)); do
892 # add mirrors with different stripes to the file
893 stripes[$i]=$((RANDOM % OSTCOUNT))
894 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
896 mirror_create_cmd+=" -N -c ${stripes[$i]}"
899 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
900 verify_mirror_count $tf $mirror_count
902 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
903 $LFS mirror extend -N $tf &&
904 error "Creating the $((mirror_count+1))th mirror succeeded"
906 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
909 # verify the range of components and stripe counts
910 for ((i = 0; i < $mirror_count; i++)); do
911 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
912 verify_comp_extent $tf ${ids[$i]} 0 EOF
915 run_test 1 "create components with setstripe options"
919 local tf2=$DIR/$tfile-2
921 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
922 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
924 $LFS mirror extend -N -f $tf2 $tf ||
925 error "merging $tf2 into $tf failed"
927 verify_mirror_count $tf 2
928 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
930 run_test 2 "create components from existing files"
933 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
935 for ((i = 0; i < 2; i++)); do
936 $LFS mkdir -i $i $DIR/$tdir-$i
937 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
940 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
941 $DIR/$tdir-0/$tfile || error "creating mirrors"
943 # mdt doesn't support to cancel layout lock for remote objects, do
947 # make sure the mirrorted file was created successfully
948 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
949 { $LFS getstripe $DIR/$tdir-0/$tfile;
950 error "expected 2 components"; }
955 run_test 3 "create components from files located on different MDTs"
958 local tf=$DIR/$tdir/$tfile
961 test_mkdir $DIR/$tdir
963 # set mirror with setstripe options to directory
964 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
965 error "set mirror to directory error"
967 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
968 x"mirrored" ] || error "failed to create mirrored dir"
971 verify_mirror_count $tf 2
973 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
974 verify_comp_extent $tf ${ids[0]} 0 1048576
975 verify_comp_extent $tf ${ids[1]} 1048576 EOF
977 # sub directory should inherit mirror setting from parent
978 test_mkdir $DIR/$tdir/td
979 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
980 x"mirrored" ] || error "failed to inherit mirror from parent"
982 # mirror extend won't be applied to directory
983 $LFS mirror extend -N2 $DIR/$tdir &&
984 error "expecting mirror extend failure"
987 run_test 4 "Make sure mirror attributes can be inhertied from directory"
993 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
994 error "failed to create file with non-empty layout"
995 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
997 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
998 verify_mirror_count $tf 3
1000 $CHECKSTAT -t file -s 12345 $tf ||
1001 error "size error after attaching layout "
1003 run_test 5 "Make sure init size work for mirrored layout"
1006 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
1007 skip "MDS version older than 2.12.58"
1009 local tf=$DIR/$tfile
1011 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
1012 error "failure to create DoM file with mirror"
1014 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
1015 error "failure to create mirrored file with DoM"
1017 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
1018 error "failure to create PFL with DoM file"
1019 $LFS mirror extend -N2 $tf ||
1020 error "failure to extend mirror with DoM"
1022 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
1023 error "failure to create PFL with DoM file"
1024 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
1025 error "failure to create mirrored file"
1026 $LFS mirror extend -N -f $tf-1 $tf-2 ||
1027 error "failure to extend mirrored file with DoM extent"
1029 run_test 6a "DoM and FLR work together"
1032 (( $MDS1_VERSION >= $(version_code 2.15.58.1) )) ||
1033 skip "MDS version older than 2.15.58.1"
1035 local tf=$DIR/$tfile
1037 $LFS setstripe -E64K -L mdt -Eeof $tf ||
1038 error "failure to create PFL with DoM file"
1039 $LFS mirror extend -N -E1M -L mdt -Eeof $tf &&
1040 error "should not extend mirror with different DoM size"
1044 run_test 6b "extend mirror with different DoM size"
1047 local tf=$DIR/$tfile
1049 # create DoM with setting stripe_size == component size
1050 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
1051 error "failure to create DoM with stripe_size == comp size"
1052 rm -f $tf || error "delete $tf"
1054 # DoM should not inherit previous component stripe_size
1055 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
1056 error "DoM component shouldn't inherit previous stripe_size"
1058 run_test 7 "Create mirror with DoM component"
1061 local tf=$DIR/$tfile
1062 local tf2=$DIR/$tfile-2
1064 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1066 stack_trap "rm -f $tf $tf2"
1068 $LFS setstripe -E EOF -o 0 $tf
1069 $LFS setstripe -E EOF -o 1 $tf2
1071 local dd_count=$((RANDOM % 20 + 1))
1072 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
1073 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
1075 # for zfs - sync OST dataset so that du below will return
1077 [ "$FSTYPE" = "zfs" ] &&
1078 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1080 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1083 $LFS mirror extend -N -f $tf2 $tf ||
1084 error "merging $tf2 into $tf failed"
1086 # cancel layout lock
1087 cancel_lru_locks mdc
1089 local new_blocks=$(du -k $tf | awk '{print $1}')
1090 [ $new_blocks -eq $blocks ] ||
1091 error "i_blocks error expected: $blocks, actual: $new_blocks"
1093 run_test 21 "glimpse should report accurate i_blocks"
1095 get_osc_lock_count() {
1102 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1103 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1104 lock_count=$((lock_count + count))
1110 local tf=$DIR/$tfile
1112 stack_trap "rm -f $tf"
1114 $LFS setstripe -E EOF -o 0 $tf
1115 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1117 # add component, two mirrors located on the same OST ;-)
1118 $LFS mirror extend -N -o 0 $tf ||
1119 error "extending mirrored file $tf failed"
1121 size_blocks=$(stat --format="%b %s" $tf)
1123 cancel_lru_locks mdc
1124 cancel_lru_locks osc
1126 local new_size_blocks=$(stat --format="%b %s" $tf)
1128 # make sure there is no lock cached
1129 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1131 [ "$new_size_blocks" = "$size_blocks" ] ||
1132 echo "size expected: $size_blocks, actual: $new_size_blocks"
1136 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1139 local tf=$DIR/$tfile
1141 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1142 error "creating mirrored file $tf failed"
1145 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1146 cancel_lru_locks osc
1149 local tmpfile=$(mktemp)
1150 stat --format="%b %s" $tf > $tmpfile &
1154 while [ $cnt -le 5 ]; do
1155 kill -0 $pid > /dev/null 2>&1 || break
1159 kill -0 $pid > /dev/null 2>&1 &&
1160 error "stat process stuck due to unavailable OSTs"
1162 # make sure glimpse request has been sent
1163 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1164 error "OST $ost_idx: no glimpse request was sent"
1169 run_test 31 "make sure glimpse request can be retried"
1172 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1173 rm -f $DIR/$tfile $DIR/$tfile-2
1175 stack_trap "rm -f $DIR/$tfile"
1177 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1178 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1180 local fsize=$(stat -c %s $DIR/$tfile)
1181 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1183 local cksum=$(md5sum $DIR/$tfile)
1185 # create a new mirror in sync mode
1186 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1187 error "extending mirrored file $DIR/$tfile failed"
1189 # make sure the mirrored file was created successfully
1190 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1191 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1196 # check size is correct, glimpse request should go to the 2nd mirror
1197 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1198 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1200 echo "reading file from the 2nd mirror and verify checksum"
1201 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1202 error "checksum error: expected $cksum"
1206 run_test 32 "data should be mirrored to newly created mirror"
1209 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1211 rm -f $DIR/$tfile $DIR/$tfile-2
1213 # create a file with two mirrors
1214 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1217 while [ $count -lt $max_count ]; do
1218 echo "ost1" >> $DIR/$tfile
1219 count=$((count + 1));
1222 # tmp file that will be used as mirror
1223 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1225 while [ $count -lt $max_count ]; do
1226 echo "ost2" >> $DIR/$tfile-2
1227 count=$((count + 1));
1230 # create a mirrored file
1231 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1232 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1233 "with verification should fail"
1234 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1235 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1236 "without verification failed"
1238 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1239 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1240 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1242 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1244 # execpted file size
1245 local fsize=$((5 * max_count))
1246 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1247 error "mirrored file size is not $fsize"
1249 # read file - all OSTs are available
1250 echo "reading file (data can be provided by any ost)... "
1251 local rs=$(cat $DIR/$tfile | head -1)
1252 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1253 error "file content error: expected: \"ost1\" or \"ost2\""
1255 # read file again with ost1 failed
1259 echo "reading file (data should be provided by ost2)..."
1260 local rs=$(cat $DIR/$tfile | head -1)
1261 [[ "$rs" == "ost2" ]] ||
1262 error "file content error: expected: \"ost2\", actual: \"$rs\""
1267 # read file again with ost2 failed
1271 # check size, glimpse should work
1272 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1273 error "mirrored file size is not $fsize"
1275 echo "reading file (data should be provided by ost1)..."
1276 local rs=$(cat $DIR/$tfile | head -1)
1277 [[ "$rs" == "ost1" ]] ||
1278 error "file content error: expected: \"ost1\", actual: \"$rs\""
1282 run_test 33a "read can choose available mirror to read"
1285 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1289 stack_trap "rm -f $DIR/$tfile" EXIT
1291 # create a file with two mirrors on OST0000 and OST0001
1292 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1294 # make sure that $tfile has two mirrors
1295 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1296 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1299 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1300 error "write failed for $DIR/$tfile"
1301 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1302 verify_flr_state $DIR/$tfile "ro"
1307 # read file - all OSTs are available
1308 echo "reading file (data can be provided by any ost)... "
1310 time cat $DIR/$tfile > /dev/null || error "read all"
1314 # read file again with ost1 {OST0000} failed
1317 echo "reading file (data should be provided by ost2)..."
1319 time cat $DIR/$tfile > /dev/null || error "read ost2"
1326 # read file again with ost2 {OST0001} failed
1330 echo "reading file (data should be provided by ost1)..."
1332 time cat $DIR/$tfile > /dev/null || error "read ost1"
1339 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1340 error "read mirror too slow without ost1, from $ra to $r1"
1341 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1342 error "read mirror too slow without ost2, from $ra to $r2"
1344 wait_osc_import_ready client ost2
1346 run_test 33b "avoid reading from unhealthy mirror"
1349 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1353 stack_trap "rm -f $DIR/$tfile" EXIT
1355 # create a file with two mirrors
1356 # mirror1: {OST0000, OST0001}
1357 # mirror2: {OST0001, OST0002}
1358 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1360 # make sure that $tfile has two mirrors
1361 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1362 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1365 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1366 error "write failed for $DIR/$tfile"
1367 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1368 verify_flr_state $DIR/$tfile "ro"
1373 # read file - all OSTs are available
1374 echo "reading file (data can be provided by any ost)... "
1375 time cat $DIR/$tfile > /dev/null || error "read all"
1377 # read file again with ost2 (OST0001) failed
1381 echo "reading file (data should be provided by ost1 and ost3)..."
1382 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1387 wait_osc_import_ready client ost2
1389 run_test 33c "keep reading among unhealthy mirrors"
1392 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1394 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1397 $LFS setstripe -o 0 $DIR/$tfile-ref
1398 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1400 # create a file with two mirrors
1401 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1402 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1404 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1405 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1407 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1408 error "mirrored file size is not 3M"
1410 # merge a mirrored file
1411 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1412 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1414 cancel_lru_locks osc
1416 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1417 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1420 echo "comparing files ... "
1422 # however, read can still return the correct data. It should return
1423 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1424 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1425 $DIR/$tfile-ref || error "file reading error"
1429 run_test 34a "read mirrored file with multiple stripes"
1432 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1434 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1437 $LFS setstripe -o 0 $DIR/$tfile-ref
1438 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1440 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1441 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1443 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1444 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1446 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1447 error "mirrored file size is not 3M"
1449 # merge a mirrored file
1450 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1451 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1453 cancel_lru_locks osc
1455 # stop two OSTs, so the 2nd component of the 1st mirror and
1456 # the 1st component of the 2nd mirror will be inaccessible, ...
1459 echo "comparing files ... "
1461 # however, read can still return the correct data. It should return
1462 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1463 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1464 $DIR/$tfile-ref || error "file reading error"
1468 run_test 34b "read mirrored file with multiple components"
1471 local tf=$DIR/$tfile
1473 $LFS setstripe -E eof $tf
1475 # add an out-of-sync mirror to the file
1476 $LFS mirror extend -N -c 2 $tf ||
1477 error "extending mirrored file $tf failed"
1479 $MULTIOP $tf oO_WRONLY:c ||
1480 error "write open a mirrored file failed"
1482 # truncate file should return error
1483 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1485 run_test 35 "allow to write to mirrored files"
1487 get_file_layout_version() {
1488 $LFS getstripe $1 | awk '/lcm_layout_gen/{print $2}'
1491 get_ost_layout_version() {
1492 $MULTIOP $1 oXc | awk '/ostlayoutversion/{print $2}'
1495 verify_ost_layout_version() {
1498 # get file layout version
1499 local flv=$(get_file_layout_version $tf)
1501 # layout version from OST objects
1502 local olv=$(get_ost_layout_version $tf)
1504 (( flv >= olv )) || error "layout version mismatch: $flv vs. $olv"
1511 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1512 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1514 $LFS mirror extend -N -f $tf-tmp $tf ||
1515 error "merging $tf-tmp into $tf failed"
1520 local tf=$DIR/$tfile
1522 stack_trap "rm -f $tf $tf-2 $tf-3"
1524 create_file_36 $tf $tf-2 $tf-3
1526 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1528 # test case 1 - check file write and verify layout version
1529 $MULTIOP $tf oO_WRONLY:c ||
1530 error "write open a mirrored file failed"
1532 # write open file should not return error
1533 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1535 # instantiate components should work
1536 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1538 # verify OST layout version
1539 verify_ost_layout_version $tf
1542 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1545 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1547 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1548 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1550 # write should take at least $fail_loc seconds and succeed
1551 local st=$(date +%s)
1552 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1554 # verify OST layout version
1555 verify_ost_layout_version $tf
1557 do_facet $mds_facet $LCTL set_param fail_loc=0
1559 run_test 36a "write to mirrored files"
1562 local tf=$DIR/$tfile
1564 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1565 skip "Need OST version at least 2.15.50"
1567 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1569 # create 2 mirrors using different OSTs
1570 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1571 error "create mirrored file"
1573 # write 1M data to one mirror
1574 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1577 # set prefer mirror to another mirror
1578 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1579 error "clear prefer mirror error"
1580 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1581 error "set prefer mirror error"
1583 # the second write should not hung
1584 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1586 run_test 36b "write should not hung when prefered mirror is stale"
1589 local tf=$DIR/$tfile
1591 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1592 skip "Need OST version at least 2.15.50"
1594 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1596 # create 2 mirrors using different OSTs
1597 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1598 error "create mirrored file"
1599 stack_trap "rm -f $tf"
1601 # write it in the background
1602 $MULTIOP $tf Ow4096_w4096c &
1607 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1608 error "clear prefer mirror error"
1609 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1610 error "set prefer mirror error"
1615 run_test 36c "change prefer mirror during write shouldn't hung"
1618 local tf=$DIR/$tfile
1620 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1621 skip "Need OST version at least 2.15.50"
1623 echo " ** create $tf"
1624 $LFS mirror create -N $tf || error "create $tf failed"
1627 echo " ** mirror extend $tf ($i/2)"
1628 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1629 flv=$(get_file_layout_version $tf)
1630 olv=$(get_ost_layout_version $tf)
1631 echo " flv=$flv olv=$olv"
1635 echo " ** write $tf ($i/2)"
1636 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1637 flv=$(get_file_layout_version $tf)
1638 olv=$(get_ost_layout_version $tf)
1639 echo " flv=$flv olv=$olv"
1641 error "write update OST layout failed $flv/$olv"
1644 echo " ** resync $tf"
1645 $LFS mirror resync $tf || error "mirror resync $tf failed"
1646 flv=$(get_file_layout_version $tf)
1647 olv=$(get_ost_layout_version $tf)
1648 echo " flv=$flv olv=$olv"
1651 echo " ** truncate $tf ($i/2)"
1652 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1653 flv=$(get_file_layout_version $tf)
1654 olv=$(get_ost_layout_version $tf)
1655 echo " flv=$flv olv=$olv"
1656 (( flv == olv || flv == olv + 1 )) ||
1657 error "truncate update OST layout failed $flv/$olv"
1660 echo " ** resync $tf"
1661 $LFS mirror resync $tf || error "mirror resync $tf failed"
1662 flv=$(get_file_layout_version $tf)
1663 olv=$(get_ost_layout_version $tf)
1664 echo " flv=$flv olv=$olv"
1667 echo " ** write $tf ($i/2)"
1668 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1669 flv=$(get_file_layout_version $tf)
1670 olv=$(get_ost_layout_version $tf)
1671 echo " flv=$flv olv=$olv"
1673 error "write update OST layout failed $flv/$olv"
1676 run_test 36d "write/punch FLR file update OST layout version"
1682 echo "create test files with size $fsize .."
1686 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1688 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1689 $TRUNCATE $tf $fsize
1695 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1696 skip "Need MDS version at least 2.11.57"
1698 local tf=$DIR/$tfile
1699 local tf2=$DIR/$tfile-2
1700 local tf3=$DIR/$tfile-3
1701 local tf4=$DIR/$tfile-4
1703 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1705 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1708 # assume the mirror id will be 1, 2, and 3
1709 declare -A checksums
1710 checksums[1]=$(cat $tf | md5sum)
1711 checksums[2]=$(cat $tf2 | md5sum)
1712 checksums[3]=$(cat $tf3 | md5sum)
1714 printf '%s\n' "${checksums[@]}"
1716 # merge these files into a mirrored file
1717 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1718 error "merging $tf2 into $tf failed"
1719 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1720 error "merging $tf3 into $tf failed"
1724 # verify mirror read, checksums should equal to the original files'
1725 echo "Verifying mirror read .."
1728 for i in "${mirror_array[@]}"; do
1729 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1730 sum=$($LFS mirror read -N $i $tf | md5sum)
1731 [ "$sum" = "${checksums[$i]}" ] ||
1732 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1735 # verify mirror write
1736 echo "Verifying mirror write .."
1737 $LFS mirror write -N2 $tf < $tf4
1739 sum=$($LFS mirror read -N2 $tf | md5sum)
1740 [[ "$sum" = "${checksums[1]}" ]] ||
1741 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1743 # verify mirror copy, write to this mirrored file will invalidate
1744 # the other two mirrors
1745 echo "Verifying mirror copy .."
1747 local osts=$(comma_list $(osts_nodes))
1749 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1750 error "mirror copy error"
1752 # verify copying is successful by checking checksums
1753 remount_client $MOUNT
1754 for i in "${mirror_array[@]}"; do
1755 sum=$($LFS mirror read -N $i $tf | md5sum)
1756 [ "$sum" = "${checksums[1]}" ] ||
1757 error "$i: mismatch checksum after copy \'$sum\'"
1762 run_test 37 "mirror I/O API verification"
1765 local tf=$DIR/$tfile
1766 local ref=$DIR/${tfile}-ref
1768 stack_trap "rm -f $tf $ref"
1770 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1771 error "creating $tf failed"
1772 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1773 $tf-2 || error "creating $tf-2 failed"
1774 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1775 error "creating $tf-3 failed"
1777 # instantiate all components
1778 $LFS mirror extend -N -f $tf-2 $tf ||
1779 error "merging $tf-2 into $tf failed"
1780 $LFS mirror extend -N -f $tf-3 $tf ||
1781 error "merging $tf-3 into $tf failed"
1782 $LFS mirror extend -N -c 1 $tf ||
1783 error "extending mirrored file $tf failed"
1785 verify_flr_state $tf "ro"
1787 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1789 local fsize=$((RANDOM << 8 + 1048576))
1790 $TRUNCATE $ref $fsize
1792 local ref_cksum=$(cat $ref | md5sum)
1794 # case 1: verify write to mirrored file & resync work
1795 cp $ref $tf || error "copy from $ref to $f error"
1796 verify_flr_state $tf "wp"
1798 local file_cksum=$(cat $tf | md5sum)
1799 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1802 echo "mirror IDs: ${mirror_array[*]}"
1804 local valid_mirror stale_mirror id mirror_cksum
1805 for id in "${mirror_array[@]}"; do
1806 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1807 [ "$ref_cksum" == "$mirror_cksum" ] &&
1808 { valid_mirror=$id; continue; }
1813 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1814 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1816 $LFS mirror resync $tf || error "resync failed"
1817 verify_flr_state $tf "ro"
1819 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1820 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1822 # case 2: inject an error to make mirror_io exit after changing
1823 # the file state to sync_pending so that we can start a concurrent
1825 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1826 verify_flr_state $tf "wp"
1828 mirror_io resync -e resync_start $tf && error "resync succeeded"
1829 verify_flr_state $tf "sp"
1831 # from sync_pending to write_pending
1832 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1833 verify_flr_state $tf "wp"
1835 mirror_io resync -e resync_start $tf && error "resync succeeded"
1836 verify_flr_state $tf "sp"
1838 # from sync_pending to read_only
1839 $LFS mirror resync $tf || error "resync failed"
1840 verify_flr_state $tf "ro"
1842 run_test 38 "resync"
1845 local tf=$DIR/$tfile
1848 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1849 error "create PFL file $tf failed"
1851 verify_mirror_count $tf 2
1852 verify_comp_count $tf 4
1854 rm -f $tf || error "delete $tf failed"
1856 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1859 local tf=$DIR/$tfile
1862 for ops in "conv=notrunc" ""; do
1865 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1866 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1867 error "create PFLR file $tf failed"
1868 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1869 error "write PFLR file $tf failed"
1871 lfs getstripe -vy $tf
1875 # file mirror state should be write_pending
1876 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1878 error "file mirror state $flags"
1879 # the 1st component (in mirror 1) should be inited
1880 verify_comp_attr lcme_flags $tf 0x10001 init
1881 # the 2nd component (in mirror 1) should be inited
1882 verify_comp_attr lcme_flags $tf 0x10002 init
1883 # the 3rd component (in mirror 1) should be uninited
1884 verify_comp_attr lcme_flags $tf 0x10003 prefer
1885 # the 4th component (in mirror 2) should be inited
1886 verify_comp_attr lcme_flags $tf 0x20004 init
1887 # the 5th component (in mirror 2) should be uninited
1888 verify_comp_attr lcme_flags $tf 0x20005 0
1889 # the 6th component (in mirror 2) should be stale
1890 verify_comp_attr lcme_flags $tf 0x20006 stale
1891 # the 7th component (in mirror 2) should be uninited
1892 if [[ x$ops = "xconv=notrunc" ]]; then
1893 verify_comp_attr lcme_flags $tf 0x20007 0
1894 elif [[ x$ops = "x" ]]; then
1895 verify_comp_attr lcme_flags $tf 0x20007 stale
1899 rm -f $tf || error "delete $tf failed"
1901 run_test 40 "PFLR rdonly state instantiation check"
1904 local tf=$DIR/$tfile
1906 stack_trap "rm -f $tf $tf-1"
1909 echo " **create two FLR files $tf $tf-1"
1910 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1911 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1912 error "create PFLR file $tf failed"
1913 $LFS mirror create -N -E 2M -S 1M -E eof \
1914 -N -E 1M -E eof --flags prefer \
1915 -N -E 4m -E eof $tf-1 ||
1916 error "create PFLR file $tf-1 failed"
1918 # file should be in ro status
1919 echo " **verify files be RDONLY"
1920 verify_flr_state $tf "ro"
1921 verify_flr_state $tf-1 "ro"
1923 # write data in [0, 2M)
1924 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1925 error "writing $tf failed"
1926 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1927 error "writing $tf-1 failed"
1929 local sum0=$(cat $tf-1 | md5sum)
1931 echo " **verify files be WRITE_PENDING"
1932 verify_flr_state $tf "wp"
1933 verify_flr_state $tf-1 "wp"
1935 # file should have stale component
1936 echo " **verify files have stale component"
1937 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1938 error "after writing $tf, it does not contain stale component"
1939 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1940 error "after writing $tf-1, it does not contain stale component"
1942 echo " **full resync"
1943 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1945 echo " **verify $tf-1 data consistency in all mirrors"
1947 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1948 [[ "$sum" = "$sum0" ]] ||
1949 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1952 echo " **verify files be RDONLY"
1953 verify_flr_state $tf "ro"
1954 verify_flr_state $tf-1 "ro"
1956 # file should not have stale component
1957 echo " **verify files do not contain stale component"
1958 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1959 error "after resyncing $tf, it contains stale component"
1960 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1961 error "after resyncing $tf, it contains stale component"
1963 # verify partial resync
1964 echo " **write $tf-1 for partial resync test"
1965 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1966 error "writing $tf-1 failed"
1968 echo " **only resync mirror 2"
1969 verify_flr_state $tf-1 "wp"
1970 $LFS mirror resync --only 2 $tf-1 ||
1971 error "resync mirror 2 of $tf-1 failed"
1972 verify_flr_state $tf "ro"
1974 # resync synced mirror
1975 echo " **resync mirror 2 again"
1976 $LFS mirror resync --only 2 $tf-1 ||
1977 error "resync mirror 2 of $tf-1 failed"
1978 verify_flr_state $tf "ro"
1979 echo " **verify $tf-1 contains stale component"
1980 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1981 error "after writing $tf-1, it does not contain stale component"
1983 echo " **full resync $tf-1"
1984 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1985 verify_flr_state $tf "ro"
1986 echo " **full resync $tf-1 again"
1987 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1988 echo " **verify $tf-1 does not contain stale component"
1989 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1990 error "after resyncing $tf, it contains stale component"
1994 run_test 41 "lfs mirror resync check"
1997 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
2001 local mirror_cmd="$LFS mirror verify"
2004 stack_trap "rm -rf $td"
2006 # create parent directory
2007 mkdir $td || error "mkdir $td failed"
2009 $mirror_cmd &> /dev/null && error "no file name given"
2010 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
2011 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
2013 # create mirrored files
2014 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
2015 error "create mirrored file $tf failed"
2016 $LFS mirror create -N -E 2M -S 1M -E EOF \
2017 -N -E 6M -E 8M -E EOF \
2018 -N -E 16M -E EOF $tf-1 ||
2019 error "create mirrored file $tf-1 failed"
2020 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
2021 error "create mirrored file $tf-2 failed"
2023 # write data in [0, 10M)
2024 for i in $tf $tf-1 $tf-2; do
2025 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
2026 error "write $i failed"
2029 # resync the mirrored files
2030 $LFS mirror resync $tf-1 $tf-2 ||
2031 error "resync $tf-1 $tf-2 failed"
2033 # verify the mirrored files
2034 $mirror_cmd $tf-1 $tf-2 ||
2035 error "verify $tf-1 $tf-2 failed"
2037 get_mirror_ids $tf-1
2038 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2039 error "at least 2 mirror ids needed with '--only' option"
2040 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2042 error "'--only' option cannot be used upon multiple files"
2043 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2044 error "invalid specified mirror ids"
2046 # change the content of $tf and merge it into $tf-1
2048 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2049 error "change $tf with seek=$i failed"
2050 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2051 error "change $tf-1 with seek=$i failed"
2054 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2055 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2056 error "merge $tf into $tf-1 failed"
2058 # verify the mirrored files
2059 echo "Verify $tf-1 without -v option:"
2060 $mirror_cmd $tf-1 &&
2061 error "verify $tf-1 should fail" || echo "PASS"
2063 echo "Verify $tf-1 with -v option:"
2064 $mirror_cmd -v $tf-1 &&
2065 error "verify $tf-1 should fail"
2067 get_mirror_ids $tf-1
2068 echo "Verify $tf-1 with --only option:"
2069 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2070 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2071 "${mirror_array[-1]} should fail"
2073 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2074 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2075 "${mirror_array[1]} should succeed"
2077 # set stale components in $tf-1
2078 for i in 0x40002 0x40003; do
2079 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2080 error "set stale flag on component $i failed"
2083 # verify the mirrored file
2084 echo "Verify $tf-1 with stale components:"
2085 $mirror_cmd -vvv $tf-1 ||
2086 error "verify $tf-1 with stale components should succeed"
2088 echo "Verify $tf-1 with stale components and --only option:"
2089 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2090 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2091 "${mirror_array[-1]} should succeed"
2093 run_test 42 "lfs mirror verify"
2095 # inactivate one OST && write && restore the OST
2099 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2102 wait=$(do_facet $SINGLEMDS \
2103 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2104 wait=${wait%%[^0-9]*}
2106 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2107 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2108 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2109 sleep $(($wait * 2 + 2))
2110 echo " **write $file"
2111 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2112 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2113 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2114 sleep $((wait * 2 + 2))
2116 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2117 [ $flags = wp ] || error "file mirror state $flags != wp"
2121 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2123 local tf=$DIR/$tfile
2126 stack_trap "rm -f $tf"
2128 ## mirror 0 ost (0, 1)
2129 ## mirror 1 ost (1, 2)
2130 ## mirror 2 ost (2, 0)
2131 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2132 -N -Eeof -c2 -o2,0 $tf ||
2133 error "create 3 mirrors file $tf failed"
2135 ################## OST0 ###########################################
2137 echo " **verify components"
2138 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2139 verify_comp_attr lcme_flags $tf 0x20002 init
2140 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2143 echo " **resync $tf"
2144 $LFS mirror resync $tf
2145 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2146 [ $flags = ro ] || error "file mirror state $flags != ro"
2148 ################## OST1 ###########################################
2150 echo " **verify components"
2151 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2152 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2153 verify_comp_attr lcme_flags $tf 0x30003 init
2156 echo " **resync $tf"
2157 $LFS mirror resync $tf
2158 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2159 [ $flags = ro ] || error "file mirror state $flags != ro"
2161 ################## OST2 ###########################################
2163 echo " **verify components"
2164 verify_comp_attr lcme_flags $tf 0x10001 init
2165 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2166 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2168 run_test 43a "mirror pick on write"
2171 local tf=$DIR/$tdir/$tfile
2173 test_mkdir $DIR/$tdir
2175 stack_trap "rm -rf $tf"
2177 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2178 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2179 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2180 verify_flr_state $tf "ro"
2182 echo " ** write to $tf"
2183 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2184 verify_flr_state $tf "wp"
2186 echo " ** resync $tf"
2187 $LFS mirror resync $tf || error "resync $tf failed"
2188 verify_flr_state $tf "ro"
2190 run_test 43b "allow writing to multiple preferred mirror file"
2193 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2196 local tf=$DIR/$tdir/$tfile
2197 local tf1=$DIR/$tdir-1/$tfile-1
2199 stack_trap "rm -rf $tf $tf1"
2201 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2202 error "create directory failed"
2203 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2204 error "create remote directory failed"
2205 rm -f $tf $tf1 $tf.mirror~2
2206 # create file with 4 mirrors
2207 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2208 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2209 error "create PFLR file $tf failed"
2211 # file should be in ro status
2212 verify_flr_state $tf "ro"
2214 # write data in [0, 3M)
2215 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2216 error "writing $tf failed"
2218 verify_flr_state $tf "wp"
2220 # disallow destroying the last non-stale mirror
2221 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2222 error "destroying mirror 1 should fail"
2224 # synchronize all mirrors of the file
2225 $LFS mirror resync $tf || error "mirror resync $tf failed"
2227 verify_flr_state $tf "ro"
2230 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2231 error "split to $tf1 failed"
2233 local idx0=$($LFS getstripe -m $tf)
2234 local idx1=$($LFS getstripe -m $tf1)
2236 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2237 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2239 # verify mirror count
2240 verify_mirror_count $tf 3
2241 verify_mirror_count $tf1 1
2243 $LFS mirror split --mirror-id 2 $tf ||
2244 error "split mirror 2 failed"
2246 verify_mirror_count $tf 2
2247 verify_mirror_count $tf.mirror~2 1
2249 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2250 error "setting stale flag on component 0x30008 failed"
2252 # disallow destroying the last non-stale mirror
2253 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2254 error "destroying mirror 4 should fail"
2256 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2258 $LFS mirror split --mirror-id 3 -d $tf ||
2259 error "destroying mirror 3 failed"
2260 verify_mirror_count $tf 1
2262 # verify splitted file contains the same content as the orig file does
2263 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2264 diff $tf $tf.mirror~2 ||
2265 error "splited file $tf.mirror~2 diffs from $tf"
2267 run_test 44a "lfs mirror split check"
2270 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2271 skip "Need MDS version at least 2.14.56"
2274 local tf=$DIR/$tdir/$tfile
2276 mkdir -p $DIR/$tdir || error "create directory failed"
2280 # create 2 mirrors file
2281 $LFS mirror extend -N -c1 $tf
2285 verify_flr_state $tf "wp"
2287 local str=$(cat $tf)
2289 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2291 # get the non-stale mirror id
2292 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2294 local mirror_ids=($($LFS getstripe $tf |
2295 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2296 for ((i = 0; i < 2; i++)); do
2297 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2298 grep stale > /dev/null || break
2301 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2305 # split the updated mirror, should fail
2306 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2307 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2308 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2311 # split the stale mirror
2312 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2313 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2314 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2316 echo "make sure there's no stale comp in the file"
2317 # make sure there's no stale comp in the file
2318 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2319 ( $LFS getstripe $tf; error "stale mirror file" )
2322 [[ $str == "YYY" ]] ||
2323 ( cat $tf; error "$tf content is not YYY after split" )
2325 run_test 44b "mirror split does not create stale file"
2328 local tf=$DIR/$tdir/$tfile
2330 stack_trap "rm -f $tf"
2332 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2333 skip "Need MDS version at least 2.14.52"
2335 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2337 mkdir -p $DIR/$tdir || error "create directroy failed"
2339 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2341 block1=$(( $(stat -c "%b*%B" $tf) ))
2342 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2344 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2346 block2=$(( $(stat -c "%b*%B" $tf) ))
2347 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2349 $LFS mirror split -d --mirror-id=2 $tf ||
2350 error "mirror split $tfile failed"
2351 $LFS mirror split -d --mirror-id=3 $tf ||
2352 error "mirror split $tfile failed"
2355 block3=$(( $(stat -c "%b*%B" $tf) ))
2356 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2358 [[ $block1 -eq $block3 ]] ||
2359 error "mirror split does not reduce block# $block3 != $block1"
2361 run_test 44c "lfs mirror split reduces block size of a file"
2364 local tf=$DIR/$tdir/$tfile
2370 stack_trap "rm -f $tf"
2372 mkdir -p $DIR/$tdir || error "create directroy failed"
2374 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2376 size1=$(stat -c "%s" $tf)
2377 echo " ** before mirror ops, file size=$size1"
2379 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2381 size2=$(stat -c "%s" $tf)
2382 echo " ** after mirror extend, file size=$size2"
2384 (($size1 == $size2)) ||
2385 error "mirror extend should not change size, before: $size1, after $size2"
2387 $LFS mirror split -d --mirror-id=2 $tf ||
2388 error "mirror split $tfile failed"
2390 size2=$(stat -c "%s" $tf)
2391 echo " ** after mirror split, file size=$size2"
2392 (($size1 == $size2)) ||
2393 error "mirror split should not change size, before: $size1, after $size2"
2395 # Remount client to clear cached size information
2396 remount_client $MOUNT
2397 size2=$(stat -c "%s" $tf)
2398 echo " ** after mirror split & remount, file size=$size2"
2399 (($size1 == $size2)) ||
2400 error "mirror extend should not change size, before: $size1, after $size2"
2403 run_test 44d "lfs mirror split does not break size"
2406 local tf=$DIR/$tdir/$tfile
2407 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2411 test_mkdir $DIR/$tdir
2412 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2413 skip "Need MDS version at least 2.14.52"
2415 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2417 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2418 $LCTL set_param llite.*.xattr_cache=0
2419 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2420 stack_trap "rm -rf $tf"
2422 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2424 size1=$(stat -c "%s" $tf)
2425 echo " ** before mirror resync, file size=$size1"
2427 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2428 size1=$(stat -c "%s" $tf)
2429 size2=$($LFS getsom -s $tf)
2433 ((size1 == size2)) ||
2434 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2436 # Remount client to clear cached size information
2437 remount_client $MOUNT
2439 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2440 stack_trap "restore_lustre_params < $p; rm -f $p"
2441 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2443 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2445 size2=$(stat -c "%s" $tf)
2446 # 'getsom' here is just for debugging
2449 ((size2 == size1)) ||
2450 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2452 run_test 44e "basic FLR SOM tests + disable SOM"
2455 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2457 local file=$DIR/$tdir/$tfile
2458 local dir=$DIR/$tdir/$dir
2459 local temp=$DIR/$tdir/template
2461 test_mkdir $DIR/$tdir
2463 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2464 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2465 error "Create $file failed"
2467 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2468 rm -f $file $file.copy
2470 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2471 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2472 error "Create $file failed"
2474 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2476 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2483 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2485 local layout1=$(get_layout_param $src)
2486 local layout2=$(get_layout_param $dst)
2487 # compare their layout info
2488 [ "$layout1" == "$layout2" ] ||
2489 error "$msg_prefix $src <=> $dst layouts are not equal"
2493 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2495 local file=$DIR/$tdir/$tfile
2496 test_mkdir $DIR/$tdir
2498 ########################### 1. PFL file #############################
2499 echo " ** 1. PFL file"
2501 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2502 $file || error "1. Create PFL $file failed"
2505 verify_46 $file $file.copy "1. PFL file"
2507 ########################### 2. plain file ###########################
2508 echo " ** 2. plain file"
2510 $LFS setstripe -c2 -o0,1 -i1 $file ||
2511 error "2. Create plain $file failed"
2514 verify_46 $file $file.copy "2. plain file"
2516 ########################### 3. FLR file #############################
2517 echo " ** 3. FLR file"
2519 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2520 $file || error "3. Create FLR $file failed"
2523 verify_46 $file $file.copy "3. FLR file"
2525 local dir=$DIR/$tdir/dir
2526 ########################### 4. PFL dir ##############################
2527 echo " ** 4. PFL dir"
2529 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2530 error "4. setstripe PFL $dir failed"
2532 test_mkdir $dir.copy
2533 verify_46 $dir $dir.copy "4. PFL dir"
2535 ########################### 5. plain dir ############################
2536 echo " ** 5. plain dir"
2537 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2539 verify_46 $dir $dir.copy "5. plain dir"
2541 ########################### 6. FLR dir ##############################
2542 echo " ** 6. FLR dir"
2543 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2544 error "6. setstripe FLR $dir failed"
2546 verify_46 $dir $dir.copy "6. FLR dir"
2548 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2549 echo "server version $MDS1_VERSION does not support SEL" &&
2552 ########################### 7. SEL file ##############################
2553 echo " ** 7. SEL file"
2555 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2556 $file || error "Create $file failed"
2559 verify_46 $file $file.copy "7. SEL file"
2561 ########################### 8. SEL dir ##############################
2562 echo " ** 8. SEL dir"
2563 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2564 $dir || error "setstripe $dir failed"
2566 verify_46 $dir $dir.copy "8. SEL dir"
2568 ########################### 9. FLR SEL file ##########################
2569 echo " ** 9. FLR SEL file"
2571 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2572 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2575 verify_46 $file $file.copy "9. SEL file"
2577 ########################### 10. FLR SEL dir #########################
2578 echo " ** 10. FLR SEL dir"
2579 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2580 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2582 verify_46 $dir $dir.copy "10. SEL dir"
2584 run_test 46 "Verify setstripe --copy option"
2587 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2589 local file=$DIR/$tdir/$tfile
2594 test_mkdir $DIR/$tdir
2595 stack_trap "rm -f $file"
2599 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2600 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2601 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2602 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2603 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2605 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2606 $LFS mirror resync $file || error "resync $file failed"
2608 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2609 if [[ x$ost == "x0," ]]; then
2610 $LFS getstripe $file
2611 error "component ${ids[2]} objects allocated on $ost " \
2615 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2616 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2617 $LFS getstripe $file
2618 error "component ${ids[3]} objects allocated on $ost " \
2619 "shouldn't on OST1 or on OST2"
2624 # mirror1: [comp0] [comp1]
2625 # mirror2: [comp2] [comp3]
2626 # mirror3: [comp4] [comp5]
2627 # mirror4: [comp6] [comp7]
2628 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2629 error "create FLR $file failed"
2630 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2632 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2633 $LFS mirror resync $file || error "resync $file failed"
2635 for ((i = 0; i < 6; i++)); do
2636 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2637 awk '/l_ost_idx/{print $5}')
2639 # comp[0],comp[2],comp[4] should use different osts
2640 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2641 ${osts[2]} == ${osts[4]} ]]; then
2642 $LFS getstripe $file
2643 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2644 "allocated on duplicated OSTs"
2646 # comp[1],comp[3],comp[5] should use different osts
2647 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2648 ${osts[3]} == ${osts[5]} ]]; then
2649 $LFS getstripe $file
2650 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2651 "allocated on duplicated OSTs"
2656 run_test 47 "Verify mirror obj alloc"
2659 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2660 skip "Need MDS version at least 2.11.55"
2662 local tf=$DIR/$tfile
2664 stack_trap "rm -f $tf"
2666 echo " ** create 2 mirrors FLR file $tf"
2667 $LFS mirror create -N -E2M -Eeof --flags prefer \
2668 -N -E1M -Eeof $tf ||
2669 error "create FLR file $tf failed"
2672 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2673 verify_flr_state $tf "wp"
2675 local sum0=$(md5sum < $tf)
2677 echo " ** resync the file"
2678 $LFS mirror resync $tf
2680 echo " ** snapshot mirror 2"
2681 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2683 echo " ** write it again"
2684 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2685 echo " ** resync it again"
2686 $LFS mirror resync $tf
2688 verify_flr_state $tf "wp"
2689 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2691 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2692 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2694 echo " ** verify mirror 2 doesn't change"
2695 echo "original checksum: $sum0"
2696 echo "mirror 1 checksum: $sum1"
2697 echo "mirror 2 checksum: $sum2"
2698 [[ $sum0 = $sum2 ]] ||
2699 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2700 echo " ** mirror 2 stripe info"
2701 $LFS getstripe -v --mirror-index=2 $tf
2703 echo " ** resync mirror 2"
2704 $LFS mirror resync --only 2 $tf
2706 verify_flr_state $tf "ro"
2707 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2709 sum1=$($LFS mirror read -N1 $tf | md5sum)
2710 sum2=$($LFS mirror read -N2 $tf | md5sum)
2712 echo " ** verify mirror 2 resync-ed"
2713 echo "original checksum: $sum0"
2714 echo "mirror 1 checksum: $sum1"
2715 echo "mirror 2 checksum: $sum2"
2716 [[ $sum1 = $sum2 ]] ||
2717 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2718 echo " ** mirror 2 stripe info"
2719 $LFS getstripe -v --mirror-index=2 $tf
2721 run_test 48 "Verify snapshot mirror"
2730 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2731 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2732 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2733 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2734 skip "LU-1941: FIEMAP unimplemented on ZFS"
2736 trap cleanup_49 EXIT RETURN
2738 local file=$DIR/$tfile
2740 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2741 error "setstripe on $file"
2742 stack_trap "rm -f $file"
2744 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2745 $LFS mirror resync $file
2747 filefrag -ves $file || error "filefrag $file failed"
2748 filefrag_op=$(filefrag -ve -k $file |
2749 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2751 #Filesystem type is: bd00bd0
2752 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2753 # ext: device_logical: physical_offset: length: dev: flags:
2754 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2755 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2756 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2758 last_lun=$(echo $filefrag_op | cut -d: -f5)
2762 for line in $filefrag_op; do
2763 frag_lun=$(echo $line | cut -d: -f5)
2764 ext_len=$(echo $line | cut -d: -f4)
2765 if [[ "$frag_lun" != "$last_lun" ]]; then
2766 if (( tot_len != 1024 )); then
2768 error "$file: OST$last_lun $tot_len != 1024"
2774 (( tot_len += ext_len ))
2777 if (( num_luns != 2 || tot_len != 1024 )); then
2779 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2782 echo "FIEMAP on $file succeeded"
2784 run_test 49a "FIEMAP upon FLR file"
2786 test_50A() { # EX-2179
2789 local file=$DIR/$tdir/$tfile
2791 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2793 $LFS mirror extend -N -c1 -i1 $file ||
2794 error "extending mirror for $file failed"
2796 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2800 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2802 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2804 echo "$file layout generation from $olv to $flv"
2805 (( $flv != ($olv + 1) )) &&
2806 error "split does not increase layout gen from $olv to $flv"
2808 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2810 $LFS getstripe -v $file || error "getstripe $file failed"
2812 run_test 50A "mirror split update layout generation"
2815 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2816 skip "OST does not support SEEK_HOLE"
2817 [ "$FSTYPE" != "zfs" ] ||
2818 skip "lseek for ZFS is not accurate if obj is not committed"
2820 local file=$DIR/$tdir/$tfile
2828 echo " ** create striped file $file"
2829 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2830 error "cannot create file with PFL layout"
2831 echo " ** write 1st data chunk at 1M boundary"
2832 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2833 error "cannot write data at 1M boundary"
2834 echo " ** write 2nd data chunk at 2M boundary"
2835 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2836 error "cannot write data at 2M boundary"
2837 echo " ** create hole at the file end"
2838 $TRUNCATE $file 3700000 || error "truncate fails"
2840 echo " ** verify sparseness"
2841 offset=$(lseek_test -d 1000 $file)
2842 echo " first data offset: $offset"
2843 [[ $offset == 1000 ]] &&
2844 error "src: data is not expected at offset $offset"
2845 offset=$(lseek_test -l 3500000 $file)
2846 echo " hole at the end: $offset"
2847 [[ $offset == 3500000 ]] ||
2848 error "src: hole is expected at offset $offset"
2850 echo " ** extend the file with new mirror"
2851 # migrate_copy_data() is used
2852 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2853 error "cannot create mirror"
2854 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2855 error "$file still has stale component"
2857 # check migrate_data_copy() was correct
2858 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2859 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2860 [[ $sum_1 == $sum_2 ]] ||
2861 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2863 # stale first mirror
2864 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2865 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2867 echo " ** verify mirror #2 sparseness"
2868 offset=$(lseek_test -d 1000 $file)
2869 echo " first data offset: $offset"
2870 [[ $offset == 1000 ]] &&
2871 error "dst: data is not expected at offset $offset"
2872 offset=$(lseek_test -l 3500000 $file)
2873 echo " hole at the end: $offset"
2874 [[ $offset == 3500000 ]] ||
2875 error "dst: hole is expected at offset $offset"
2877 echo " ** copy mirror #2 to mirror #1"
2878 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2879 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2880 error "$file still has stale component"
2882 # check llapi_mirror_copy_many correctness
2883 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2884 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2885 [[ $sum_1 == $sum_2 ]] ||
2886 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2888 # stale 1st component of mirror #2 before lseek call
2889 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2891 echo " ** verify mirror #1 sparseness again"
2892 offset=$(lseek_test -d 1000 $file)
2893 echo " first data offset: $offset"
2894 [[ $offset == 1000 ]] &&
2895 error "dst: data is not expected at offset $offset"
2896 offset=$(lseek_test -l 3500000 $file)
2897 echo " hole at the end: $offset"
2898 [[ $offset == 3500000 ]] ||
2899 error "dst: hole is expected at offset $offset"
2901 cancel_lru_locks osc
2903 blocks=$(stat -c%b $file)
2904 echo " ** final consumed blocks: $blocks"
2905 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2906 # that file is still sparse
2907 (( blocks < 1000 )) ||
2908 error "Mirrored file consumes $blocks blocks"
2910 run_test 50a "mirror extend/copy preserves sparseness"
2913 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2914 skip "OST does not support SEEK_HOLE"
2915 [ "$FSTYPE" != "zfs" ] ||
2916 skip "lseek for ZFS is not accurate if obj is not committed"
2918 local file=$DIR/$tdir/$tfile
2925 stack_trap "rm -f $file"
2927 echo " ** create mirrored file $file"
2928 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2929 -N -E2M -S1M -E eof -S2M $file ||
2930 error "cannot create mirrored file"
2931 echo " ** write data chunk at 1M boundary"
2932 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2933 error "cannot write data at 1M boundary"
2934 echo " ** create hole at the file end"
2935 $TRUNCATE $file 3700000 || error "truncate fails"
2937 echo " ** verify sparseness"
2938 offset=$(lseek_test -d 1000 $file)
2939 echo " first data offset: $offset"
2940 [[ $offset == 1000 ]] &&
2941 error "src: data is not expected at offset $offset"
2942 offset=$(lseek_test -l 3500000 $file)
2943 echo " hole at the end: $offset"
2944 [[ $offset == 3500000 ]] ||
2945 error "src: hole is expected at 3500000"
2947 echo " ** resync mirror #2 to mirror #1"
2948 $LFS mirror resync $file
2950 # check llapi_mirror_copy_many correctness
2951 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2952 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2953 [[ $sum_1 == $sum_2 ]] ||
2954 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2956 cancel_lru_locks osc
2958 blocks=$(stat -c%b $file)
2959 echo " ** consumed blocks: $blocks"
2960 # without full punch() support the first component can be not sparse
2961 # but the last one should be, so file should use far fewer blocks
2962 (( blocks < 5000 )) ||
2963 error "Mirrored file consumes $blocks blocks"
2965 # stale first component in mirror #1
2966 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2967 echo " ** truncate file down"
2969 echo " ** write data chunk at 2M boundary"
2970 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2971 error "cannot write data at 2M boundary"
2972 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2973 $LFS mirror resync $file || error "mirror rsync fails"
2974 # first component is still stale
2975 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2976 error "$file still has no stale component"
2977 echo " ** resync mirror #2 to mirror #1 again"
2978 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2979 $LFS mirror resync $file || error "mirror rsync fails"
2980 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2981 error "$file still has stale component"
2983 # check llapi_mirror_copy_many correctness
2984 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2985 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2986 [[ $sum_1 == $sum_2 ]] ||
2987 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2989 cancel_lru_locks osc
2991 blocks=$(stat -c%b $file)
2992 echo " ** final consumed blocks: $blocks"
2993 # while the first component can lose sparseness, the last one should
2994 # not, so whole file should still use far fewer blocks in total
2995 (( blocks < 3000 )) ||
2996 error "Mirrored file consumes $blocks blocks"
2998 run_test 50b "mirror rsync handles sparseness"
3001 local tf=$DIR/$tdir/$tfile
3003 test_mkdir $DIR/$tdir
3005 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
3006 verify_flr_state $tf "ro"
3008 if [[ "$FSTYPE" == "ldiskfs" ]]; then
3009 # ZFS does not support fallocate for now
3010 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
3011 skip_eopnotsupp "$out|punch hole in $tf failed"
3012 verify_flr_state $tf "wp"
3015 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
3016 $LFS mirror resync $tf || error "mirror resync $tf failed"
3017 verify_flr_state $tf "ro"
3019 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
3020 verify_flr_state $tf "wp"
3022 run_test 50c "punch_hole/mmap_write stale other mirrors"
3025 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3026 skip "OST does not support SEEK_HOLE"
3027 [ "$FSTYPE" != "zfs" ] ||
3028 skip "lseek for ZFS is not accurate if obj is not committed"
3030 local file=$DIR/$tdir/$tfile
3037 echo " ** create mirrored file $file"
3038 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3039 -N -E2M -S1M -E eof -S2M $file ||
3040 error "cannot create mirrored file"
3041 echo " ** write data chunk at 1M boundary"
3042 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3043 error "cannot write data at 1M boundary"
3044 echo " ** create hole at the file start"
3045 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3048 if [[ $rc -eq 0 ]]; then
3049 verify_flr_state $file "wp"
3050 elif [[ ! $prt =~ unsupported ]]; then
3051 error "punch hole in $file failed: $prt"
3053 skip "Fallocate punch is not supported: $prt"
3056 echo " ** verify sparseness"
3057 offset=$(lseek_test -d 1000 $file)
3058 echo " first data offset: $offset"
3059 (( $offset >= 1024 * 1024 )) ||
3060 error "src: data is not expected at offset $offset"
3062 echo " ** resync mirror #2"
3063 $LFS mirror resync $file
3065 # check llapi_mirror_copy_many correctness
3066 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3067 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3068 [[ $sum_1 == $sum_2 ]] ||
3069 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3071 cancel_lru_locks osc
3073 # stale first component in mirror #1
3074 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3075 echo " ** verify sparseness of mirror #2"
3076 offset=$(lseek_test -d 1000 $file)
3077 echo " first data offset: $offset"
3078 (( $offset >= 1024 * 1024 )) ||
3079 error "src: data is not expected at offset $offset"
3081 run_test 50d "mirror rsync keep holes"
3084 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3085 skip "OST does not support SEEK_HOLE"
3087 local file=$DIR/$tdir/$tfile
3088 local old_size=2147483648 # 2GiB
3092 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3093 $TRUNCATE $file $old_size
3095 $LFS mirror extend -N -c 1 $file
3096 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3097 $LFS mirror resync $file
3099 new_size=$(stat --format='%s' $file)
3100 if ((new_size != old_size)); then
3101 error "new_size ($new_size) is not equal to old_size ($old_size)"
3104 run_test 60a "mirror extend sets correct size on sparse file"
3106 get_flr_layout_gen() {
3107 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3108 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3111 check_layout_gen() {
3114 local v1=$(get_flr_layout_gen $tf)
3115 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3117 [[ $v1 -eq $v2 ]] ||
3118 error "$tf in-memory layout gen $v1 != $v2 after $2"
3122 local tf=$DIR/$tdir/$tfile
3124 test_mkdir $DIR/$tdir
3126 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3128 for ((i = 0; i < 20; i++)); do
3129 $LFS mirror extend -N $tf ||
3130 error "extending mirror for $tf failed"
3131 check_layout_gen $tf "extend"
3133 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3134 error "split $tf failed"
3135 check_layout_gen $tf "split"
3138 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3141 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3146 local -a old=( $2 $3 $4 )
3149 new=( $(get_times_61 $file) )
3150 ((${old[0]} == ${new[0]})) ||
3151 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3153 ((${old[1]} == ${new[1]})) ||
3154 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3157 test_61a() { # LU-14508
3158 local file=$DIR/$tdir/$tfile
3159 local old_diff=($(do_facet mds1 "$LCTL get_param -n mdd.*.atime_diff"))
3160 local mdts=$(comma_list $(mdts_nodes))
3164 do_nodes $mdts "$LCTL set_param mdd.*.atime_diff=1"
3165 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.atime_diff=$old_diff"
3169 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3170 echo "create $file-2"
3171 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3173 echo XXX > $file || error "write $file failed"
3174 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3176 echo "sleep $nap seconds, then cat $tfile"
3178 cat $file || error "cat $file failed"
3180 echo "sleep $nap seconds, then re-write $tfile"
3182 echo XXXX > $file || error "write $file failed"
3183 cp -p $file $file-2 || error "copy $file-2 failed"
3185 echo "sleep $nap seconds"
3188 tim=( $(get_times_61 $file) )
3190 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3191 $LFS mirror extend -N -f $file-2 $file ||
3192 error "cannot mirror merge $file-2 to $file"
3193 check_times_61 $file "${tim[@]}"
3195 echo "mirror extend $tfile and test timestamps"
3196 $LFS mirror extend -N -c1 -i1 $file ||
3197 error "cannot extend mirror $file"
3198 check_times_61 $file "${tim[@]}"
3200 echo "migrate $tfile and test timestamps"
3201 $LFS migrate -n $file || error "cannot migrate $file"
3202 check_times_61 $file "${tim[@]}"
3204 echo "normal user migrate $tfile and test timestamps"
3205 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3206 check_times_61 $file "${tim[@]}"
3208 run_test 61a "mirror extend and migrate preserve timestamps"
3210 test_61b() { # LU-14508
3211 local file=$DIR/$tdir/$tfile
3217 echo XXX > $file || error "create $file failed"
3218 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3220 echo "sleep $nap seconds, then cat $tfile"
3222 cat $file || error "cat $file failed"
3224 echo "sleep $nap seconds, then re-write $tfile"
3226 echo XXXX > $file || error "write $file failed"
3228 echo "sleep $nap seconds, then test timestamps"
3231 tim=( $(get_times_61 $file) )
3233 echo "mirror extend $tfile and test timestamps"
3234 $LFS mirror extend -N -c1 -i1 $file ||
3235 error "cannot extend mirror $file"
3236 check_times_61 $file "${tim[@]}"
3238 echo "mirror split $tfile and test timestamps"
3239 $LFS mirror split -d --mirror-id=1 $file ||
3240 error "cannot split mirror 1 off $file"
3241 check_times_61 $file "${tim[@]}"
3243 echo "normal user mirror extend $tfile and test timestamps"
3244 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3245 error "cannot extend mirror $file"
3246 check_times_61 $file "${tim[@]}"
3248 run_test 61b "mirror extend and split preserve timestamps"
3250 test_61c() { # LU-14508
3251 local file=$DIR/$tdir/$tfile
3257 echo XXX > $file || error "create $file failed"
3258 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3260 echo "sleep $nap seconds, then cat $tfile"
3262 cat $file || error "cat $file failed"
3264 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3266 $LFS mirror extend -N -c1 -i1 $file ||
3267 error "cannot extend mirror $file"
3268 echo XXXX > $file || error "write $file failed"
3270 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3271 tim=( $(get_times_61 $file) )
3273 $LFS mirror resync $file || error "cannot resync mirror $file"
3274 check_times_61 $file "${tim[@]}"
3276 echo XXXXXX > $file || error "write $tfile failed"
3278 echo "normal user resync $tfile and test timestamps"
3279 tim=( $(get_times_61 $file) )
3280 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3281 check_times_61 $file "${tim[@]}"
3283 run_test 61c "mirror resync preserves timestamps"
3286 local file=$DIR/$tdir/$tfile
3290 echo "create mirror file with unknown magic"
3291 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3292 # mirror 2 in-memory magic is bad
3293 $LCTL set_param fail_loc=0x1426 fail_val=2
3294 $LFS setstripe -N --flags=prefer -N2 $file ||
3295 error "failed to create mirror file $file"
3296 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3297 [[ $magic == 0x0BAD0BD0 ]] ||
3298 error "mirror 2 magic $magic is not bad as expected"
3299 cat /etc/passwd > $file || error "cannot write to $file"
3300 diff /etc/passwd $file || error "read $file error"
3304 echo "create mirror file with unknown pattern"
3305 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3306 # mirror 1 in-memory pattern is bad
3307 $LCTL set_param fail_loc=0x1427 fail_val=1
3308 $LFS setstripe -N -N --flags=prefer $file ||
3309 error "failed to create mirror file $file"
3310 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3311 [[ $pattern == 502 ]] ||
3312 error "mirror 1 pattern $pattern is not bad as expected"
3313 cat /etc/passwd > $file || error "cannot write to $file"
3314 diff /etc/passwd $file || error "read $file error"
3316 run_test 62 "read/write with unknown type of mirror"
3319 local tf=$DIR/$tdir/$tfile
3321 test_mkdir $DIR/$tdir
3322 stack_trap "rm -f $tf"
3326 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3330 echo "mirror create pid $c_pid"
3333 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3336 echo "mirror split pid $s_pid"
3338 echo "mirror create and split race for 60 seconds, should not crash"
3340 kill -9 $c_pid &> /dev/null
3341 kill -9 $s_pid &> /dev/null
3345 run_test 70 "mirror create and split race"
3348 local tf=$DIR/$tdir/$tfile
3350 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3351 skip "Need OST version at least 2.14.51"
3354 test_mkdir $DIR/$tdir
3355 stack_trap "rm -f $tf"
3357 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3358 error "setstripe $tf failed"
3360 FSXNUM=${FSXNUM:-1000}
3361 $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3363 run_test 70a "flr mode fsx test"
3368 local fsize=$(stat --printf=%s $tf)
3370 while [ -f $ctrl_file ]; do
3371 local off=$((RANDOM << 8))
3372 local len=$((RANDOM << 5 + 131072))
3374 [ $((off + len)) -gt $fsize ] && {
3375 fsize=$((off + len))
3376 echo "Extending file size to $fsize .."
3379 flock -s $lock_file -c \
3380 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3382 error "failed writing to $off:$len"; }
3383 sleep 0.$((RANDOM % 2 + 1))
3390 while [ -f $ctrl_file ]; do
3391 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3392 { rm -f $ctrl_file; error "read failed"; }
3393 sleep 0.$((RANDOM % 2 + 1))
3400 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3402 exec 200<>$lock_file
3403 while [ -f $ctrl_file ]; do
3404 local lock_taken=false
3405 local index=$((RANDOM % ${#options[@]}))
3406 local cmd="mirror_io resync ${options[$index]}"
3408 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3410 [ $((RANDOM % 4)) -eq 0 ] && {
3416 echo -n "resync file $tf with '$cmd' .."
3418 if [[ $lock_taken = "true" ]]; then
3420 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3423 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3426 sleep 0.$((RANDOM % 8 + 1))
3430 # this was test_200 before adding "b" and "c" subtests
3432 local tf=$DIR/$tfile
3433 local tf2=$DIR2/$tfile
3434 local tf3=$DIR3/$tfile
3436 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3437 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3438 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3440 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3441 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3442 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3444 $LFS mirror extend -N -f $tf-2 $tf ||
3445 error "merging $tf-2 into $tf failed"
3446 $LFS mirror extend -N -f $tf-3 $tf ||
3447 error "merging $tf-3 into $tf failed"
3449 mkdir -p $MOUNT2 && mount_client $MOUNT2
3451 mkdir -p $MOUNT3 && mount_client $MOUNT3
3453 verify_flr_state $tf3 "ro"
3455 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3456 $LCTL set_param fail_loc=0x1A03
3458 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3459 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3463 write_file_200 $tf &
3469 write_file_200 $tf2 &
3472 read_file_200 $tf2 &
3475 resync_file_200 $tf3 &
3479 [ "$SLOW" = "yes" ] && sleep_time=360
3480 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3487 echo "Waiting ${pids[*]}"
3490 umount_client $MOUNT2
3491 umount_client $MOUNT3
3493 # resync and verify mirrors
3494 $LFS mirror resync $tf || error "final resync failed"
3497 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3499 for id in "${mirror_array[@]:1}"; do
3500 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3501 error "checksum error for mirror $id"
3506 run_test 200a "stress test"
3509 local tf=$DIR/$tfile
3510 local tf2=$DIR2/$tfile
3511 local tf3=$DIR3/$tfile
3513 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3514 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3515 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3517 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3518 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3519 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3521 $LFS mirror extend -N -f $tf-2 $tf ||
3522 error "merging $tf-2 into $tf failed"
3523 $LFS mirror extend -N -f $tf-3 $tf ||
3524 error "merging $tf-3 into $tf failed"
3526 mkdir -p $MOUNT2 && mount_client $MOUNT2
3528 mkdir -p $MOUNT3 && mount_client $MOUNT3
3530 verify_flr_state $tf3 "ro"
3532 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3533 $LCTL set_param fail_loc=0x1423
3537 write_file_200 $tf &
3543 write_file_200 $tf2 &
3546 read_file_200 $tf2 &
3549 resync_file_200 $tf3 &
3553 [ "$SLOW" = "yes" ] && sleep_time=400
3557 echo "Waiting ${pids[@]}"
3560 umount_client $MOUNT2
3561 umount_client $MOUNT3
3563 # resync and verify mirrors
3564 $LFS mirror resync $tf || {
3566 error "final resync failed"
3570 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3571 for id in ${mirror_array[@]:1}; do
3572 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3573 error "checksum error for mirror $id"
3578 run_test 200b "racing IO, mirror extend and resync"
3581 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3582 skip "Need MDS version at least 2.15.53"
3584 local tf=$DIR/$tfile
3585 local tf2=$DIR2/$tfile
3587 mkdir -p $MOUNT2 && mount_client $MOUNT2
3588 stack_trap "umount_client $MOUNT2"
3589 stack_trap "rm -f $tf"
3593 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3595 mdt_idx=$($LFS getstripe -m $tf)
3597 cancel_lru_locks mdc
3598 cancel_lru_locks osc
3600 # start a process modifying file, block it just
3601 # before layout lock acquisition
3602 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3603 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3604 #log "dd to stale replica"
3605 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3611 $LFS mirror extend -N -c -1 $tf2 || {
3613 error "can't mirror"
3615 log "mirror extend done"
3616 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3618 # wait for blocking dd to complete and modify file
3619 wait $PID || error "2nd dd failed"
3622 verify_mirror_count $tf 2
3624 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3627 error "both replicas are still in sync"
3630 $LFS mirror verify -vvv $tf || {
3632 error "corrupted in-sync file"
3635 run_test 200c "layout change racing with open: LOVEA changes"
3637 cleanup_test_201() {
3638 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3640 umount_client $MOUNT2
3644 local delay=${RESYNC_DELAY:-5}
3646 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3647 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3649 stack_trap cleanup_test_201 EXIT
3651 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3652 changelog_register -n)
3654 mkdir -p $MOUNT2 && mount_client $MOUNT2
3658 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3659 [ -z "$log" ] && { sleep 1; continue; }
3661 index=$(echo $log | awk '{print $1}')
3662 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3663 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3664 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3667 [ -z "$file" ] && continue
3669 local now=$(date +%s)
3671 echo "file: $file $fid was modified at $ts, now: $now, " \
3672 "will be resynced at $((ts+delay))"
3674 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3676 $LFS mirror resync $file
3677 echo "$file resync done"
3680 run_test 201 "FLR data mover"
3683 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3685 local tf=$DIR/$tfile
3688 $LFS setstripe -E 1M -S 1M -c 1 $tf
3689 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3690 verify_comp_attr stripe-count $tf ${ids[0]} 1
3692 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3693 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3694 verify_comp_attr stripe-count $tf ${ids[0]} 1
3695 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3697 dd if=/dev/zero of=$tf bs=1M count=2
3698 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3699 verify_comp_attr stripe-count $tf ${ids[0]} 1
3700 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3702 run_test 202 "lfs setstripe --add-component wide striping"
3705 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3706 skip "Need MDS version at least 2.11.55"
3707 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3709 local tf=$DIR/$tfile
3712 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3713 #delete first mirror
3714 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3717 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3718 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3719 error "getstripe count of mirror 2"
3720 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3722 #extend a mirror with 2 OSTs
3723 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3726 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3727 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3728 error "getstripe count of mirror 2"
3729 [[ x$old_id = x$new_id ]] ||
3730 error "mirror 2 changed ID from $old_id to $new_id"
3731 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3733 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3734 error "getstripe count of mirror 3"
3735 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3737 run_test 203 "mirror file preserve mirror ID"
3739 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3741 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3742 skip "skipped for lustre < $SEL_VER"
3744 local comp_file=$DIR/$tdir/$tfile
3748 test_mkdir $DIR/$tdir
3749 stack_trap "rm -f $comp_file"
3751 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3752 # by extension space to -1
3753 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3754 error "Create $comp_file failed"
3756 # Write to first component, extending & staling second mirror
3757 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3758 error "dd to extend + stale failed"
3760 $LFS getstripe $comp_file
3762 flg_opts="--component-flags init,stale"
3763 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3764 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3766 flg_opts="--component-flags extension"
3767 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3768 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3770 # mirror resync should not change the extents
3771 $LFS mirror resync $comp_file
3773 flg_opts="--component-flags init"
3774 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3775 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3777 flg_opts="--component-flags extension"
3778 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3779 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3781 sel_layout_sanity $comp_file 5
3783 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3785 # Simple test of FLR + self-extending layout, SEL in primary mirror
3787 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3788 skip "skipped for lustre < $SEL_VER"
3790 local comp_file=$DIR/$tdir/$tfile
3794 test_mkdir $DIR/$tdir
3795 stack_trap "rm -f $comp_file"
3797 # first mirror is 1M followed by extension space to -1, second mirror
3798 # is 0-10M, then 10M-(-1),
3799 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3800 error "Create $comp_file failed"
3802 # Write to first component, extending first component & staling
3804 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3805 error "dd to extend + stale failed"
3807 $LFS getstripe $comp_file
3809 flg_opts="--component-flags init"
3810 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3811 [ $found -eq 1 ] || error "write: First comp end incorrect"
3813 flg_opts="--component-flags extension"
3814 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3815 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3817 flg_opts="--component-flags init,stale"
3818 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3819 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3821 # This component is staled because it overlaps the extended first
3822 # component of the primary mirror, even though it doesn't overlap
3823 # the actual write - thus not inited.
3824 flg_opts="--component-flags stale"
3825 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3826 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3828 # mirror resync should not change the extents
3829 $LFS mirror resync $comp_file
3831 $LFS getstripe $comp_file
3833 flg_opts="--component-flags init"
3834 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3835 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3837 flg_opts="--component-flags extension"
3838 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3839 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3841 flg_opts="--component-flags init"
3842 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3843 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3845 flg_opts="--component-flags init"
3846 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3847 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3849 sel_layout_sanity $comp_file 5
3851 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3853 # FLR + SEL failed extension & component removal
3854 # extension space in second mirror
3856 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3857 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3858 skip "skipped for lustre < $SEL_VER"
3860 local comp_file=$DIR/$tdir/$tfile
3863 local ost_name=$(ostname_from_index $ost_idx1)
3865 test_mkdir $DIR/$tdir
3866 stack_trap "rm -f $comp_file"
3868 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3869 # extension space from 1M to 1G, then normal space to -1
3870 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3871 -E -1 $comp_file || error "Create $comp_file failed"
3873 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3876 # write to first comp (0 - 10M) of mirror 1, extending + staling
3877 # first + second comp of mirror 2
3878 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3881 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3884 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3886 $LFS getstripe $comp_file
3888 found=$($LFS find --component-start 0m --component-end 1m \
3889 --comp-flags init,stale $comp_file | wc -l)
3890 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3892 found=$($LFS find --component-start 1m --component-end EOF \
3893 --comp-flags stale,^init $comp_file | wc -l)
3894 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3896 local mirror_id=$($LFS getstripe --component-start=1m \
3897 --component-end=EOF $comp_file | \
3898 grep lcme_mirror_id | awk '{ print $2 }')
3900 [[ $mirror_id -eq 2 ]] ||
3901 error "component not in correct mirror? $mirror_id"
3903 $LFS mirror resync $comp_file
3905 $LFS getstripe $comp_file
3907 # component dimensions should not change from resync
3908 found=$($LFS find --component-start 1m --component-end EOF \
3909 --component-flags init $comp_file | wc -l)
3910 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3912 sel_layout_sanity $comp_file 4
3914 run_test 204c "FLR write/stale/resync test with component removal"
3916 # Successful repeated component in primary mirror
3918 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3919 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3920 skip "skipped for lustre < $SEL_VER"
3922 local comp_file=$DIR/$tdir/$tfile
3925 wait_delete_completed
3927 test_mkdir $DIR/$tdir
3928 stack_trap "rm -f $comp_file"
3930 # first mirror is 64M followed by extension space to -1, second mirror
3931 # is 0-10M, then 10M-(-1)
3932 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3933 error "Create $comp_file failed"
3935 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3936 local ost_name=$(ostname_from_index $ost_idx1)
3937 # degrade OST for first comp so we won't extend there
3938 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3939 obdfilter.$ost_name.degraded=1
3942 # Write beyond first component, causing repeat & stale second mirror
3943 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3946 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3947 obdfilter.$ost_name.degraded=0
3950 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3952 $LFS getstripe $comp_file
3954 found=$($LFS find --component-start 64m --component-end 128m \
3955 --component-flags init $comp_file | wc -l)
3956 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3958 local ost_idx2=$($LFS getstripe --component-start=64m \
3959 --component-end=128m --component-flags=init \
3961 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3962 local mirror_id=$($LFS getstripe --component-start=64m \
3963 --component-end=128m --component-flags=init \
3964 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3965 [[ $mirror_id -eq 1 ]] ||
3966 error "component not in correct mirror: $mirror_id, not 1"
3968 $LFS mirror resync $comp_file
3970 $LFS getstripe $comp_file
3972 # component dimensions should not change from resync
3973 found=$($LFS find --component-start 0m --component-end 64m \
3974 --component-flags init $comp_file | wc -l)
3975 [ $found -eq 1 ] || error "resync: first comp incorrect"
3976 found=$($LFS find --component-start 64m --component-end 128m \
3977 --component-flags init $comp_file | wc -l)
3978 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3980 sel_layout_sanity $comp_file 5
3982 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3984 # Successful repeated component, SEL in non-primary mirror
3986 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3987 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3988 skip "skipped for lustre < $SEL_VER"
3990 local comp_file=$DIR/$tdir/$tfile
3993 wait_delete_completed
3996 test_mkdir $DIR/$tdir
3997 stack_trap "rm -f $comp_file"
3999 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4000 # space to -1 (-z 64M, so first comp is 0-64M)
4001 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
4002 # will be not enough - one will be degraded, the other is used on
4003 # an overlapping mirror.
4004 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
4005 error "Create $comp_file failed"
4007 local ost_idx1=$($LFS getstripe --component-start=0 \
4008 --component-end=64m -i $comp_file)
4009 local ost_name=$(ostname_from_index $ost_idx1)
4010 # degrade OST for first comp of 2nd mirror so we won't extend there
4011 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4012 obdfilter.$ost_name.degraded=1
4015 $LFS getstripe $comp_file
4017 # Write to first component, stale & instantiate second mirror components
4018 # overlapping with the written component (0-100M);
4019 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4022 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4023 obdfilter.$ost_name.degraded=0
4025 $LFS getstripe $comp_file
4027 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
4029 found=$($LFS find --component-start 0m --component-end 64m \
4030 --component-flags init,stale $comp_file | wc -l)
4031 [ $found -eq 1 ] || error "write: first comp incorrect"
4033 # was repeated due to degraded ost
4034 found=$($LFS find --component-start 64m --component-end 128m \
4035 --component-flags init,stale $comp_file | wc -l)
4036 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4038 local ost_idx2=$($LFS getstripe --component-start=64m \
4039 --component-end=128m --component-flags=init \
4041 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4042 local mirror_id=$($LFS getstripe --component-start=0m \
4043 --component-end=64m --component-flags=init \
4044 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4045 [[ $mirror_id -eq 2 ]] ||
4046 error "component not in correct mirror? $mirror_id"
4048 $LFS mirror resync $comp_file
4050 $LFS getstripe $comp_file
4052 # component dimensions should not change from resync
4053 found=$($LFS find --component-start 0m --component-end 64m \
4054 --component-flags init,^stale $comp_file | wc -l)
4055 [ $found -eq 1 ] || error "resync: first comp incorrect"
4056 found=$($LFS find --component-start 64m --component-end 128m \
4057 --component-flags init,^stale $comp_file | wc -l)
4058 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4060 sel_layout_sanity $comp_file 5
4062 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4064 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4066 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4067 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4068 skip "skipped for lustre < $SEL_VER"
4070 local comp_file=$DIR/$tdir/$tfile
4073 wait_delete_completed
4075 test_mkdir $DIR/$tdir
4076 stack_trap "rm -f $comp_file"
4078 pool_add $TESTNAME || error "Pool creation failed"
4079 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4081 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4082 # space to -1 (-z 64M, so first comp is 0-64M)
4083 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4084 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4086 local ost_name0=$(ostname_from_index 0)
4087 local ost_name1=$(ostname_from_index 1)
4089 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4090 # extend original comp
4091 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4092 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4095 # a write to the 1st component, 100M length, which will try to stale
4096 # the first 100M of mirror 2, attempting to extend its 0-64M component
4097 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4100 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4101 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4104 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4106 $LFS getstripe $comp_file
4108 found=$($LFS find --component-start 0m --component-end 128m \
4109 --component-flags init,stale $comp_file | wc -l)
4110 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4112 local mirror_id=$($LFS getstripe --component-start=0m \
4113 --component-end=128m --component-flags=init \
4114 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4116 [[ $mirror_id -eq 2 ]] ||
4117 error "component not in correct mirror? $mirror_id, not 2"
4119 $LFS mirror resync $comp_file
4121 $LFS getstripe $comp_file
4123 # component dimensions should not change from resync
4124 found=$($LFS find --component-start 0m --component-end 128m \
4125 --component-flags init,^stale $comp_file | wc -l)
4126 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4128 sel_layout_sanity $comp_file 4
4130 run_test 204f "FLR write/stale/resync sel w/forced extension"
4132 function test_205() {
4133 local tf=$DIR/$tfile
4136 $LFS setstripe -c1 $tf
4137 $LFS mirror extend -N $tf
4138 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4139 (( $mirrors == 2 )) || error "no new mirror was created?"
4141 $LFS mirror extend -N --flags=prefer $tf
4142 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4143 (( $mirrors == 3 )) || error "no new mirror with prefer flag was created?"
4145 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4146 error "prefer flag was not set on the new mirror"
4148 $LFS mirror extend -N --flags=nocompr $tf
4149 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4150 (( $mirrors == 4 )) || error "no new mirror with nocompr flag was created?"
4152 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q nocompr) ||
4153 error "nocompr flag was not set on the new mirror"
4155 $LFS mirror extend -N --flags=prefer,nocompr $tf
4156 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4157 (( $mirrors == 5 )) || error "no new mirror with prefer,nocompr flags was created?"
4159 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q "prefer,nocompr") ||
4160 error "prefer,nocompr flags were not set on the new mirror"
4162 run_test 205 "lfs mirror extend to set prefer and nocompr flags"
4164 function test_206() {
4165 # create a new OST pool
4166 local pool_name=$TESTNAME
4168 create_pool $FSNAME.$pool_name ||
4169 error "create OST pool $pool_name failed"
4170 # add OSTs into the pool
4171 pool_add_targets $pool_name 0 1 ||
4172 error "add OSTs into pool $pool_name failed"
4174 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4175 error "can't setstripe"
4176 $LFS mirror extend -N $DIR/$tfile ||
4177 error "can't create replica"
4178 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4179 $LFS getstripe $DIR/$tfile
4180 error "prefer found"
4182 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4183 $LFS getstripe $DIR/$tfile
4184 error "can't setstripe prefer"
4187 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4188 $LFS getstripe $DIR/$tfile
4189 error "no prefer found"
4195 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4198 local file=$DIR/$tfile
4199 local tmpfile=$DIR/$tfile-tt
4201 [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
4202 skip "Need MDS version at least 2.14.50"
4204 stack_trap "rm -f $tmpfile $file"
4206 # generate data for verification
4207 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4208 error "can't generate file with random data"
4210 # create a mirrored file with one stale replica
4211 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4212 error "create mirrored file $file failed"
4213 get_mirror_ids $file
4214 echo "mirror IDs: ${mirror_array[*]}"
4216 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4217 get_mirror_ids $file
4218 echo "mirror IDs: ${mirror_array[*]}"
4221 cmp $tmpfile $file || error "files don't match"
4222 get_mirror_ids $file
4223 echo "mirror IDs: ${mirror_array[*]}"
4225 # mirror creation should work fine
4226 $LFS mirror extend -N -S 8M -c -1 $file ||
4227 error "mirror extend $file failed"
4229 get_mirror_ids $file
4230 echo "mirror IDs: ${mirror_array[*]}"
4233 $LFS mirror verify -v $file || error "verification failed"
4234 cmp $tmpfile $file || error "files don't match"
4236 run_test 207 "create another replica with existing out-of-sync one"
4238 function check_ost_used() {
4247 cancel_lru_locks osc # to drop pages
4248 cancel_lru_locks mdc # to refresh layout
4249 # XXX: cancel_lru_locks mdc doesn't work
4250 # XXX: need a better way to reload the layout
4251 umount_client $MOUNT || error "umount failed"
4252 mount_client $MOUNT || error "mount failed"
4254 # refresh non-rotation status on MDTs
4256 touch $DIR/$tfile-temp
4257 rm -f $DIR/$tfile-temp
4258 # refresh non-rotational status on the client
4262 $LCTL set_param osc.*.stats=clear >/dev/null
4263 if [[ $io == "read" ]]; then
4264 ddarg="if=$file of=/dev/null"
4265 elif [[ $io == "write" ]]; then
4266 ddarg="if=/dev/zero of=$file"
4268 error "unknown type $io"
4270 dd $ddarg bs=8M count=1 || error "can't $io $file"
4271 cancel_lru_locks osc
4273 # check only specified OSTs got reads
4274 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4275 local nr=$($LCTL get_param -n \
4276 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4277 awk "/ost_$io/{print \$2}")
4279 if [[ " $* " =~ $ost ]]; then
4280 (( nr > 0 )) || error "expected reads on $ost"
4282 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4288 local tf=$DIR/$tfile
4289 local osts=$(comma_list $(osts_nodes))
4291 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4292 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4293 skip "Need MDS version at least 2.14.55"
4295 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4297 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4298 stack_trap "restore_lustre_params < $p; rm -f $p"
4300 stack_trap "rm -f $tf"
4301 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4302 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4303 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4304 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4305 $LFS mirror resync $tf || error "can't resync"
4308 log "set OST0000 non-rotational"
4310 $LCTL set_param osd*.*OST*.nonrotational=0
4312 $LCTL set_param osd*.*OST0000*.nonrotational=1
4313 check_ost_used $tf read 0
4315 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4317 $LCTL set_param osd*.*OST*.nonrotational=0
4319 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4320 osd*.*OST0003*.nonrotational=1
4321 check_ost_used $tf read 2 3
4323 log "set mirror 1 on OST0001 preferred"
4324 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4325 error "can't set prefer"
4326 check_ost_used $tf read 1
4328 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4331 local tf=$DIR/$tfile
4332 local osts=$(comma_list $(osts_nodes))
4334 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4335 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4336 skip "Need MDS version at least 2.14.55"
4338 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4340 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4341 stack_trap "restore_lustre_params < $p; rm -f $p"
4343 stack_trap "rm -f $tf"
4344 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4345 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4346 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4347 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4348 $LFS mirror resync $tf || error "can't resync"
4349 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4351 log "set OST0000 non-rotational"
4353 $LCTL set_param osd*.*OST*.nonrotational=0
4355 $LCTL set_param osd*.*OST0000*.nonrotational=1
4356 check_ost_used $tf write 0
4357 $LFS mirror resync $tf || error "can't resync"
4359 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4361 $LCTL set_param osd*.*OST*.nonrotational=0
4363 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4364 osd*.*OST0003*.nonrotational=1
4365 check_ost_used $tf write 2 3
4366 $LFS mirror resync $tf || error "can't resync"
4368 log "set mirror 1 on OST0001 preferred"
4369 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4370 error "can't set prefer"
4371 check_ost_used $tf write 1
4373 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4376 local tf=$DIR/$tfile
4377 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4378 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4379 local osts=$(comma_list $(osts_nodes))
4381 stack_trap "rm -f $tmpfile"
4383 mkdir -p $MOUNT2 && mount_client $MOUNT2
4384 stack_trap "umount_client $MOUNT2"
4386 # to make replica on ost1 preferred for new writes
4387 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4388 stack_trap "restore_lustre_params < $p; rm -f $p"
4390 $LCTL set_param osd*.*OST*.nonrotational=0
4392 $LCTL set_param osd*.*OST0001*.nonrotational=1
4394 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4396 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4397 log "replicated file created"
4399 cancel_lru_locks mdc
4400 cancel_lru_locks osc
4402 log "open(O_RDONLY) and first read from OST"
4403 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4406 log "first read complete"
4408 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4409 error "can't write BBBB"
4410 log "BBBB written which made replica on ost1 stale"
4412 log "fast read from pagecache in the original process"
4416 log "read via $DIR2 new open(2)"
4417 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4419 log "fast read from pagecache after 5s in the original process"
4424 local nr=$(grep "BBBB" $tmpfile | wc -l)
4430 log "read via new open(2)"
4431 $MULTIOP $tf vvoO_RDONLY:r4c
4433 run_test 209a "skip fast reads after layout invalidation"
4435 function sum_ost_reads() {
4436 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4437 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4441 local tf=$DIR/$tfile
4443 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4444 cancel_lru_locks osc
4445 echo "the very first read"
4446 cat $tf >/dev/null || error "can't read"
4448 # cancel layout lock
4449 cancel_lru_locks mdc
4451 # now read again, data must be in the cache, so no ost reads
4452 $LCTL set_param osc.*.stats=clear >/dev/null
4453 echo "read with warm cache"
4454 cat $tf >/dev/null || error "can't read"
4456 (( nr == 0 )) || error "reads with warm cache"
4458 # now verify we can catch reads at all
4459 cancel_lru_locks osc
4460 cat $tf >/dev/null || error "can't read"
4462 (( nr > 0 )) || error "no reads with cold cache"
4464 run_test 209b "pagecache can be used after LL cancellation"
4467 local tf=$DIR/$tfile
4469 stack_trap "rm -f $tf"
4470 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4471 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4472 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4473 $LFS mirror extend -N $tf || error "can't mirror"
4474 $LFS getstripe -v $tf
4475 stat $tf || error "can't stat"
4477 run_test 210a "handle broken mirrored lovea"
4480 local tf=$DIR/$tfile
4485 [ "$FSTYPE" != "zfs" ] || skip "ZFS file number is not accurate"
4487 stack_trap "rm -f $tf"
4489 # XXX: how to avoid precreate
4490 wait_delete_completed
4491 $LFS df -i | grep OST
4492 before=$($LFS df -i|grep OST|awk '{sum=sum+$3}END{print sum}')
4493 echo "before file creation: $before"
4494 $LFS setstripe -c 2 $tf || error "can't create file"
4495 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4497 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4498 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4499 $LFS mirror extend -N $tf || error "can't mirror"
4500 $LFS df -i | grep OST
4501 mirrored=$($LFS df -i|grep OST|awk '{sum=sum+$3}END{print sum}')
4502 echo "after mirror: $mirrored"
4504 rm $tf || error "can't remove"
4505 [[ -f $tf ]] && error "rm failed"
4506 wait_delete_completed
4508 $LFS df -i | grep OST
4509 after=$($LFS df -i|grep OST|awk '{sum=sum+$3}END{print sum}')
4510 echo "after rm: $after"
4511 (( after < before )) || error "something went wrong with unlink"
4513 run_test 210b "handle broken mirrored lovea (unlink)"
4515 complete_test $SECONDS
4516 check_and_cleanup_lustre