3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
16 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT "
17 # Bug number for skipped test: LU-14818 LU-11381 LU-14765
18 ALWAYS_EXCEPT+=" 6 201 44c "
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
21 # skip all tests for PPC until we can get sanity-pfl to pass
22 if [[ $(uname -m) = ppc64 ]]; then
23 skip "Skip FLR testing for PPC clients"
26 if [[ "$ost1_FSTYPE" == "zfs" ]]; then
28 ALWAYS_EXCEPT+=" 49a "
33 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
34 skip "Need MDS version at least 2.10.56"
36 check_and_setup_lustre
39 rm -rf $DIR/[Rdfs][0-9]*
41 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
42 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
47 # global array to store mirror IDs
48 declare -a mirror_array
55 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
56 array[${#array[@]}]=$((id >> 16))
59 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
61 echo ${#mirror_array[@]}
65 echo 3 > /proc/sys/vm/drop_caches
76 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
84 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
85 error "start ost$idx failed"
89 wait_recovery_complete ost$idx
94 # Verify mirror count with an expected value for a given file.
96 verify_mirror_count() {
99 local mirror_count=$($LFS getstripe -N $tf)
101 [[ $mirror_count = $expected ]] || {
102 $LFS getstripe -v $tf
103 error "verify mirror count failed on $tf:" \
104 "$mirror_count != $expected"
109 # Verify component count with an expected value for a given file.
110 # $1 coposited layout file
111 # $2 expected component number
113 verify_comp_count() {
116 local comp_count=$($LFS getstripe --component-count $tf)
118 [[ $comp_count = $expected ]] || {
119 $LFS getstripe -v $tf
120 error "verify component count failed on $tf:" \
121 "$comp_count != $expected"
126 # Verify component attribute with an expected value for a given file
134 local cmd="$LFS getstripe -I$comp_id"
135 local getstripe_cmd="$cmd -v"
139 stripe-size) cmd+=" -S $tf" ;;
140 stripe-count) cmd+=" -c $tf" ;;
141 stripe-index) cmd+=" -i $tf" ;;
142 pool) cmd+=" -p $tf" ;;
143 comp-start) cmd+=" --component-start $tf" ;;
144 comp-end) cmd+=" --component-end $tf" ;;
145 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
146 *) error "invalid attribute $attr";;
151 [ $attr = lcme_flags ] && {
153 local expected_list=$(comma_list $expected)
154 for fl in ${expected_list//,/ }; do
157 [[ ${fl:0:1} = "^" ]] && neg=1
158 [[ $neg = 1 ]] && fl=${fl:1}
160 $(echo $value | grep -q $fl)
162 # 0: matched; 1: not matched
164 if [[ $neg = 0 && $match != 0 ||
165 $neg = 1 && $match = 0 ]]; then
167 [[ $neg = 0 ]] && # expect the flag
168 error "expected flag '$fl' not in $comp_id"
169 [[ $neg = 1 ]] && # not expect the flag
170 error "not expected flag '$fl' in $comp_id"
176 [[ $value = $expected ]] || {
178 error "verify $attr failed on $tf: $value != $expected"
183 # Verify component extent with expected start and end extent values
184 # for a given file and component ID.
186 verify_comp_extent() {
189 local expected_start=$3
190 local expected_end=$4
192 verify_comp_attr comp-start $tf $comp_id $expected_start
193 verify_comp_attr comp-end $tf $comp_id $expected_end
197 # Verify component attribute with parent directory for a given file
200 verify_comp_attr_with_parent() {
204 local td=$(cd $(dirname $tf); echo $PWD)
205 local tf_cmd="$LFS getstripe -I$comp_id"
206 local td_cmd="$LFS getstripe"
212 stripe-size) opt="-S" ;;
213 stripe-count) opt="-c" ;;
215 *) error "invalid attribute $attr";;
218 expected=$($td_cmd $opt $td)
219 [[ $expected = -1 ]] && expected=$OSTCOUNT
221 value=$($tf_cmd $opt $tf)
222 [[ $value = -1 ]] && value=$OSTCOUNT
224 [[ $value = $expected ]] || {
227 error "verify $attr failed with parent on $tf:" \
228 "$value != $expected"
233 # Verify component attribute with filesystem-wide default value for a given file
236 verify_comp_attr_with_default() {
240 local tf_cmd="$LFS getstripe -I$comp_id"
248 expected=$($LCTL get_param -n \
249 lov.$FSNAME-clilov-*.stripesize)
253 expected=$($LCTL get_param -n \
254 lov.$FSNAME-clilov-*.stripecount)
255 [[ $expected = -1 ]] && expected=$OSTCOUNT
257 *) error "invalid attribute $attr";;
260 value=$($tf_cmd $opt $tf)
261 [[ $value = -1 ]] && value=$OSTCOUNT
263 [[ $value = $expected ]] || {
265 error "verify $attr failed with default value on $tf:" \
266 "$value != $expected"
271 # Verify unspecified component attributes for a given file
274 # This will only verify the inherited attributes:
275 # stripe size, stripe count and OST pool name
277 verify_comp_attrs() {
281 verify_comp_attr_with_default stripe-size $tf $comp_id
282 verify_comp_attr_with_default stripe-count $tf $comp_id
283 verify_comp_attr_with_parent pool $tf $comp_id
289 local expected_state=$2
291 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
292 [ $expected_state = $state ] ||
293 error "expected: $expected_state, actual $state"
296 # command line test cases
300 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
301 local mirror_cmd="$LFS mirror create"
306 # create parent directory
307 mkdir $td || error "mkdir $td failed"
309 $mirror_cmd $tf &> /dev/null && error "miss -N option"
311 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
312 verify_mirror_count $tf 1
313 id=$($LFS getstripe -I $tf)
314 verify_comp_attrs $tf $id
315 verify_comp_extent $tf $id 0 EOF
317 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
318 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
319 error "invalid mirror count $((mirror_count + 1))"
321 $mirror_cmd -N$mirror_count $tf-1 ||
322 error "create mirrored file $tf-1 failed"
323 verify_mirror_count $tf-1 $mirror_count
324 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
325 for ((i = 0; i < $mirror_count; i++)); do
326 verify_comp_attrs $tf-1 ${ids[$i]}
327 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
330 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
331 error "create mirrored file $tf-2 failed"
332 verify_mirror_count $tf-2 10
333 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
334 for ((i = 0; i < 10; i++)); do
335 verify_comp_attrs $tf-2 ${ids[$i]}
336 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
339 run_test 0a "lfs mirror create with -N option"
342 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
346 local mirror_cmd="$LFS mirror create"
350 # create a new OST pool
351 local pool_name=$TESTNAME
352 create_pool $FSNAME.$pool_name ||
353 error "create OST pool $pool_name failed"
355 # add OSTs into the pool
356 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
357 error "add OSTs into pool $pool_name failed"
359 # create parent directory
360 mkdir $td || error "mkdir $td failed"
361 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
362 error "$LFS setstripe $td failed"
364 create_pool $FSNAME.flash || error "create OST pool flash failed"
365 create_pool $FSNAME.archive || error "create OST pool archive failed"
367 # create a mirrored file with plain layout mirrors
368 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
369 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
370 error "create mirrored file $tf failed"
371 verify_mirror_count $tf 6
372 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
373 for ((i = 0; i < 6; i++)); do
374 verify_comp_extent $tf ${ids[$i]} 0 EOF
377 # verify component ${ids[0]}
378 verify_comp_attrs $tf ${ids[0]}
380 # verify component ${ids[1]}
381 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
382 verify_comp_attr stripe-count $tf ${ids[1]} 2
383 verify_comp_attr stripe-index $tf ${ids[1]} 2
385 # verify component ${ids[2]}
386 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
387 verify_comp_attr stripe-count $tf ${ids[2]} 2
388 verify_comp_attr pool $tf ${ids[2]} flash
390 # verify component ${ids[3]}
391 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
392 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
393 verify_comp_attr pool $tf ${ids[3]} flash
395 # verify component ${ids[4]}
396 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
397 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
398 verify_comp_attr pool $tf ${ids[4]} archive
400 # verify component ${ids[5]}
401 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
402 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
403 verify_comp_attr_with_parent pool $tf ${ids[5]}
405 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
406 # LU-11022 - remove mirror by pool name
407 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
408 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
409 $LFS mirror delete --pool archive $tf || error "delete mirror"
410 cnt=$($LFS getstripe $tf | grep archive | wc -l)
411 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
417 run_test 0b "lfs mirror create plain layout mirrors"
420 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
424 local mirror_cmd="$LFS mirror create"
428 # create a new OST pool
429 local pool_name=$TESTNAME
430 create_pool $FSNAME.$pool_name ||
431 error "create OST pool $pool_name failed"
433 # add OSTs into the pool
434 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
435 error "add OSTs into pool $pool_name failed"
437 # create parent directory
438 mkdir $td || error "mkdir $td failed"
439 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
440 error "$LFS setstripe $td failed"
442 create_pool $FSNAME.flash ||
443 error "create OST pool flash failed"
444 create_pool $FSNAME.archive ||
445 error "create OST pool archive failed"
447 # create a mirrored file with composite layout mirrors
448 $mirror_cmd -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
450 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
451 error "create mirrored file $tf failed"
452 verify_mirror_count $tf 6
453 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
455 # verify components ${ids[0]} and ${ids[2]}
457 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
458 verify_comp_attr stripe-count $tf ${ids[$i]} 2
459 verify_comp_attr stripe-index $tf ${ids[$i]} 1
460 verify_comp_extent $tf ${ids[$i]} 0 8388608
463 # verify components ${ids[1]} and ${ids[3]}
465 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
466 verify_comp_attr stripe-count $tf ${ids[$i]} 2
467 verify_comp_attr pool $tf ${ids[$i]} flash
468 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
471 # verify component ${ids[4]}
472 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
473 verify_comp_attr stripe-count $tf ${ids[4]} 4
474 verify_comp_attr_with_parent pool $tf ${ids[4]}
475 verify_comp_extent $tf ${ids[4]} 0 EOF
477 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
479 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
480 verify_comp_attr stripe-count $tf ${ids[$i]} 4
481 verify_comp_attr pool $tf ${ids[$i]} archive
482 verify_comp_extent $tf ${ids[$i]} 0 536870912
485 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
487 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
488 verify_comp_attr stripe-count $tf ${ids[$i]} -1
489 verify_comp_attr pool $tf ${ids[$i]} archive
490 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
496 run_test 0c "lfs mirror create composite layout mirrors"
501 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
502 local mirror_cmd="$LFS mirror extend"
506 # create parent directory
507 mkdir $td || error "mkdir $td failed"
509 $mirror_cmd $tf &> /dev/null && error "miss -N option"
510 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
512 # create a non-mirrored file, convert it to a mirrored file and extend
513 touch $tf || error "touch $tf failed"
514 $mirror_cmd -N $tf || error "convert and extend $tf failed"
515 verify_mirror_count $tf 2
516 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
517 for ((i = 0; i < 2; i++)); do
518 verify_comp_attrs $tf ${ids[$i]}
519 verify_comp_extent $tf ${ids[$i]} 0 EOF
522 lfsck_verify_pfid $tf || error "PFID is not set"
524 # create a mirrored file and extend it
525 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
526 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
527 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
529 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
530 error "extend mirror with -f failed"
532 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
533 error "extend mirrored file $tf-3 failed"
534 verify_mirror_count $tf-3 $mirror_count
535 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
536 for ((i = 0; i < $mirror_count; i++)); do
537 verify_comp_attrs $tf-3 ${ids[$i]}
538 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
541 $mirror_cmd -N $tf-3 &> /dev/null
544 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
546 run_test 0d "lfs mirror extend with -N option"
549 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
553 local mirror_cmd="$LFS mirror extend"
557 # create parent directory
558 mkdir $td || error "mkdir $td failed"
560 create_pool $FSNAME.ssd ||
561 error "create OST pool ssd failed"
563 # create a mirrored file with plain layout mirrors
564 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
565 error "create mirrored file $tf failed"
567 create_pool $FSNAME.flash ||
568 error "create OST pool flash failed"
569 create_pool $FSNAME.archive ||
570 error "create OST pool archive failed"
572 # extend the mirrored file with plain layout mirrors
573 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
574 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
575 error "extend mirrored file $tf failed"
576 verify_mirror_count $tf 6
577 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
578 for ((i = 0; i < 6; i++)); do
579 verify_comp_extent $tf ${ids[$i]} 0 EOF
582 # verify component ${ids[0]}
583 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
584 verify_comp_attr stripe-count $tf ${ids[0]} 3
585 verify_comp_attr stripe-index $tf ${ids[0]} 1
587 # verify component ${ids[1]}
588 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
589 verify_comp_attr stripe-count $tf ${ids[1]} 2
590 verify_comp_attr stripe-index $tf ${ids[1]} 2
592 # verify component ${ids[2]}
593 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
594 verify_comp_attr stripe-count $tf ${ids[2]} 2
595 verify_comp_attr pool $tf ${ids[2]} flash
597 # verify component ${ids[3]}
598 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
599 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
600 verify_comp_attr pool $tf ${ids[3]} flash
602 # verify component ${ids[4]}
603 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
604 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
605 verify_comp_attr pool $tf ${ids[4]} archive
607 # verify component ${ids[5]}
608 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
609 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
610 verify_comp_attr_with_parent pool $tf ${ids[5]}
612 run_test 0e "lfs mirror extend plain layout mirrors"
615 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
619 local mirror_cmd="$LFS mirror extend"
623 # create parent directory
624 mkdir $td || error "mkdir $td failed"
626 create_pool $FSNAME.ssd ||
627 error "create OST pool ssd failed"
629 # create a mirrored file with composite layout mirror
630 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
631 error "create mirrored file $tf failed"
633 create_pool $FSNAME.flash ||
634 error "create OST pool flash failed"
635 create_pool $FSNAME.archive ||
636 error "create OST pool archive failed"
638 # extend the mirrored file with composite layout mirrors
639 $mirror_cmd -N -p archive \
640 -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
642 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
643 error "extend mirrored file $tf failed"
644 verify_mirror_count $tf 8
645 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
647 # verify component ${ids[0]}
648 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
649 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
650 verify_comp_attr pool $tf ${ids[0]} ssd
651 verify_comp_extent $tf ${ids[0]} 0 33554432
653 # verify component ${ids[1]}
654 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
655 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
656 verify_comp_attr pool $tf ${ids[1]} ssd
657 verify_comp_extent $tf ${ids[1]} 33554432 EOF
659 # verify component ${ids[2]}
660 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
661 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
662 verify_comp_attr pool $tf ${ids[2]} archive
663 verify_comp_extent $tf ${ids[2]} 0 EOF
665 # verify components ${ids[3]} and ${ids[5]}
667 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
668 verify_comp_attr stripe-count $tf ${ids[$i]} 2
669 verify_comp_attr stripe-index $tf ${ids[$i]} 1
670 verify_comp_extent $tf ${ids[$i]} 0 8388608
673 # verify components ${ids[4]} and ${ids[6]}
675 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
676 verify_comp_attr stripe-count $tf ${ids[$i]} 2
677 verify_comp_attr pool $tf ${ids[$i]} flash
678 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
681 # verify component ${ids[7]}
682 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
683 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
684 verify_comp_attr_with_parent pool $tf ${ids[7]}
685 verify_comp_extent $tf ${ids[7]} 0 EOF
687 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
689 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
690 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
691 verify_comp_attr pool $tf ${ids[$i]} archive
692 verify_comp_extent $tf ${ids[$i]} 0 536870912
695 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
697 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
698 verify_comp_attr stripe-count $tf ${ids[$i]} -1
699 verify_comp_attr pool $tf ${ids[$i]} archive
700 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
703 run_test 0f "lfs mirror extend composite layout mirrors"
708 ! $LFS mirror create --flags prefer $tf ||
709 error "creating $tf w/ --flags but w/o -N option should fail"
711 ! $LFS mirror create -N --flags foo $tf ||
712 error "creating $tf with '--flags foo' should fail"
714 ! $LFS mirror create -N --flags stale $tf ||
715 error "creating $tf with '--flags stale' should fail"
717 ! $LFS mirror create -N --flags prefer,init $tf ||
718 error "creating $tf with '--flags prefer,init' should fail"
720 ! $LFS mirror create -N --flags ^prefer $tf ||
721 error "creating $tf with '--flags ^prefer' should fail"
723 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
724 -N -o1 $tf || error "create mirrored file $tf failed"
726 verify_comp_attr lcme_flags $tf 0x10001 prefer
727 verify_comp_attr lcme_flags $tf 0x10002 prefer
729 # write to the mirrored file and check primary
730 cp /etc/hosts $tf || error "error writing file '$tf'"
732 verify_comp_attr lcme_flags $tf 0x20003 stale
734 # resync file and check prefer flag
735 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
738 $LCTL set_param osc.*.stats=clear
739 cat $tf &> /dev/null || error "error reading file '$tf'"
741 # verify that the data was provided by OST1 where mirror 1 resides
742 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
743 awk '/ost_read/{print $2}')
744 [ -n "$nr_read" ] || error "read was not provided by OST1"
746 run_test 0g "lfs mirror create flags support"
749 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
750 skip "Need MDS version at least 2.11.57"
758 # create parent directory
759 test_mkdir $td || error "mkdir $td failed"
761 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
762 error "set default mirrored layout on directory $td failed"
764 # verify flags are inherited from the directory
767 verify_comp_attr lcme_flags $tf 0x10001 prefer
768 verify_comp_attr lcme_flags $tf 0x10002 prefer
770 # set flags to the first component
771 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
772 error "setting '^prefer,foo' flags should fail"
774 ! $LFS getstripe --component-flags=prefer,foo $tf ||
775 error "getting component(s) with 'prefer,foo' flags should fail"
777 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
779 verify_comp_attr lcme_flags $tf 0x10001 stale
780 verify_comp_attr lcme_flags $tf 0x10002 prefer
782 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
783 error "clearing 'stale' should fail"
785 # write and resync file. It can't resync the file directly because the
786 # file state is still 'ro'
787 cp /etc/hosts $tf || error "error writing file '$tf'"
788 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
790 for flag in prefer prefrd prefwr; do
791 $LFS setstripe --comp-set -I 0x20003 --comp-flags=$flag $tf ||
792 error "error setting flag $flag"
794 verify_comp_attr lcme_flags $tf 0x20003 $flag
796 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^$flag $tf ||
797 error "error clearing $flag flag from component 0x20003"
800 # MDS disallows setting stale flag on the last non-stale mirror
801 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
803 cp /etc/hosts $tf || error "error writing file '$tf'"
805 verify_comp_attr lcme_flags $tf 0x10002 prefer
806 verify_comp_attr lcme_flags $tf 0x20003 stale
807 verify_comp_attr lcme_flags $tf 0x30004 stale
809 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
811 error "setting stale flag on component 0x10002 should fail"
813 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
815 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
816 error "error setting stale flag on component 0x10001"
817 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
818 error "error setting stale flag on component 0x20003"
820 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
822 error "setting stale flag on component 0x30004 should fail"
824 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
826 run_test 0h "set, clear and test flags for FLR files"
829 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
831 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
832 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
833 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
835 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
836 stack_trap "rm -f $TMP/$tfile"
837 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
838 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
839 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
840 error "set component 1 stale failed"
841 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
842 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
844 run_test 0j "test lfs mirror read/write commands"
847 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
850 # default FLR with 2 mirrors
851 $LFS setstripe -N -c1 -i0 -N -c1 -i1 $DIR/$tdir ||
852 error "set default layout failed"
854 # plain file extension under default FLR dir
855 echo $tfile >> $DIR/$tdir/$tfile.append || error "create $tfile.append failed"
856 echo -n " before extend $tfile.append, mirror count = "
857 $LFS getstripe -N $DIR/$tdir/$tfile.append
859 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile.append ||
860 error "mirror extend failed"
861 echo -n " after extend $tfile.append, mirror count = "
862 $LFS getstripe -N $DIR/$tdir/$tfile.append
864 # normal file extension under default FLR dir
865 touch $DIR/$tdir/$tfile || error "create $tfile failed"
866 echo -n " before extend $tfile, mirror count = "
867 $LFS getstripe -N $DIR/$tdir/$tfile
869 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile ||
870 error "mirror extend $tfile failed"
871 echo -n " after extend $tfile, mirror count = "
872 $LFS getstripe -N $DIR/$tdir/$tfile
874 run_test 0k "mirroring a file in directory with default FLR layout"
878 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
879 local mirror_create_cmd="$LFS mirror create"
880 local stripes[0]=$OSTCOUNT
882 mirror_create_cmd+=" -N -c ${stripes[0]}"
883 for ((i = 1; i < $mirror_count; i++)); do
884 # add mirrors with different stripes to the file
885 stripes[$i]=$((RANDOM % OSTCOUNT))
886 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
888 mirror_create_cmd+=" -N -c ${stripes[$i]}"
891 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
892 verify_mirror_count $tf $mirror_count
894 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
895 $LFS mirror extend -N $tf &&
896 error "Creating the $((mirror_count+1))th mirror succeeded"
898 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
901 # verify the range of components and stripe counts
902 for ((i = 0; i < $mirror_count; i++)); do
903 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
904 verify_comp_extent $tf ${ids[$i]} 0 EOF
907 run_test 1 "create components with setstripe options"
911 local tf2=$DIR/$tfile-2
913 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
914 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
916 $LFS mirror extend -N -f $tf2 $tf ||
917 error "merging $tf2 into $tf failed"
919 verify_mirror_count $tf 2
920 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
922 run_test 2 "create components from existing files"
925 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
927 for ((i = 0; i < 2; i++)); do
928 $LFS mkdir -i $i $DIR/$tdir-$i
929 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
932 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
933 $DIR/$tdir-0/$tfile || error "creating mirrors"
935 # mdt doesn't support to cancel layout lock for remote objects, do
939 # make sure the mirrorted file was created successfully
940 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
941 { $LFS getstripe $DIR/$tdir-0/$tfile;
942 error "expected 2 components"; }
947 run_test 3 "create components from files located on different MDTs"
950 local tf=$DIR/$tdir/$tfile
953 test_mkdir $DIR/$tdir
955 # set mirror with setstripe options to directory
956 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
957 error "set mirror to directory error"
959 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
960 x"mirrored" ] || error "failed to create mirrored dir"
963 verify_mirror_count $tf 2
965 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
966 verify_comp_extent $tf ${ids[0]} 0 1048576
967 verify_comp_extent $tf ${ids[1]} 1048576 EOF
969 # sub directory should inherit mirror setting from parent
970 test_mkdir $DIR/$tdir/td
971 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
972 x"mirrored" ] || error "failed to inherit mirror from parent"
974 # mirror extend won't be applied to directory
975 $LFS mirror extend -N2 $DIR/$tdir &&
976 error "expecting mirror extend failure"
979 run_test 4 "Make sure mirror attributes can be inhertied from directory"
985 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
986 error "failed to create file with non-empty layout"
987 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
989 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
990 verify_mirror_count $tf 3
992 $CHECKSTAT -t file -s 12345 $tf ||
993 error "size error after attaching layout "
995 run_test 5 "Make sure init size work for mirrored layout"
998 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
999 skip "MDS version older than 2.12.58"
1001 local tf=$DIR/$tfile
1003 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
1004 error "failure to create DoM file with mirror"
1006 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
1007 error "failure to create mirrored file with DoM"
1009 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
1010 error "failure to create PFL with DoM file"
1011 $LFS mirror extend -N2 $tf ||
1012 error "failure to extend mirror with DoM"
1014 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
1015 error "failure to create PFL with DoM file"
1016 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
1017 error "failure to create mirrored file"
1018 $LFS mirror extend -N -f $tf-1 $tf-2 ||
1019 error "failure to extend mirrored file with DoM extent"
1021 run_test 6a "DoM and FLR work together"
1024 (( $MDS1_VERSION >= $(version_code 2.15.58.1) )) ||
1025 skip "MDS version older than 2.15.58.1"
1027 local tf=$DIR/$tfile
1029 $LFS setstripe -E64K -L mdt -Eeof $tf ||
1030 error "failure to create PFL with DoM file"
1031 $LFS mirror extend -N -E1M -L mdt -Eeof $tf &&
1032 error "should not extend mirror with different DoM size"
1036 run_test 6b "extend mirror with different DoM size"
1039 local tf=$DIR/$tfile
1041 # create DoM with setting stripe_size == component size
1042 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
1043 error "failure to create DoM with stripe_size == comp size"
1044 rm -f $tf || error "delete $tf"
1046 # DoM should not inherit previous component stripe_size
1047 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
1048 error "DoM component shouldn't inherit previous stripe_size"
1050 run_test 7 "Create mirror with DoM component"
1053 local tf=$DIR/$tfile
1054 local tf2=$DIR/$tfile-2
1056 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1058 stack_trap "rm -f $tf $tf2"
1060 $LFS setstripe -E EOF -o 0 $tf
1061 $LFS setstripe -E EOF -o 1 $tf2
1063 local dd_count=$((RANDOM % 20 + 1))
1064 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
1065 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
1067 # for zfs - sync OST dataset so that du below will return
1069 [ "$FSTYPE" = "zfs" ] &&
1070 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1072 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1075 $LFS mirror extend -N -f $tf2 $tf ||
1076 error "merging $tf2 into $tf failed"
1078 # cancel layout lock
1079 cancel_lru_locks mdc
1081 local new_blocks=$(du -k $tf | awk '{print $1}')
1082 [ $new_blocks -eq $blocks ] ||
1083 error "i_blocks error expected: $blocks, actual: $new_blocks"
1085 run_test 21 "glimpse should report accurate i_blocks"
1087 get_osc_lock_count() {
1094 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1095 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1096 lock_count=$((lock_count + count))
1102 local tf=$DIR/$tfile
1104 stack_trap "rm -f $tf"
1106 $LFS setstripe -E EOF -o 0 $tf
1107 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1109 # add component, two mirrors located on the same OST ;-)
1110 $LFS mirror extend -N -o 0 $tf ||
1111 error "extending mirrored file $tf failed"
1113 size_blocks=$(stat --format="%b %s" $tf)
1115 cancel_lru_locks mdc
1116 cancel_lru_locks osc
1118 local new_size_blocks=$(stat --format="%b %s" $tf)
1120 # make sure there is no lock cached
1121 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1123 [ "$new_size_blocks" = "$size_blocks" ] ||
1124 echo "size expected: $size_blocks, actual: $new_size_blocks"
1128 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1131 local tf=$DIR/$tfile
1133 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1134 error "creating mirrored file $tf failed"
1137 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1138 cancel_lru_locks osc
1141 local tmpfile=$(mktemp)
1142 stat --format="%b %s" $tf > $tmpfile &
1146 while [ $cnt -le 5 ]; do
1147 kill -0 $pid > /dev/null 2>&1 || break
1151 kill -0 $pid > /dev/null 2>&1 &&
1152 error "stat process stuck due to unavailable OSTs"
1154 # make sure glimpse request has been sent
1155 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1156 error "OST $ost_idx: no glimpse request was sent"
1161 run_test 31 "make sure glimpse request can be retried"
1164 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1165 rm -f $DIR/$tfile $DIR/$tfile-2
1167 stack_trap "rm -f $DIR/$tfile"
1169 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1170 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1172 local fsize=$(stat -c %s $DIR/$tfile)
1173 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1175 local cksum=$(md5sum $DIR/$tfile)
1177 # create a new mirror in sync mode
1178 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1179 error "extending mirrored file $DIR/$tfile failed"
1181 # make sure the mirrored file was created successfully
1182 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1183 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1188 # check size is correct, glimpse request should go to the 2nd mirror
1189 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1190 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1192 echo "reading file from the 2nd mirror and verify checksum"
1193 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1194 error "checksum error: expected $cksum"
1198 run_test 32 "data should be mirrored to newly created mirror"
1201 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1203 rm -f $DIR/$tfile $DIR/$tfile-2
1205 # create a file with two mirrors
1206 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1209 while [ $count -lt $max_count ]; do
1210 echo "ost1" >> $DIR/$tfile
1211 count=$((count + 1));
1214 # tmp file that will be used as mirror
1215 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1217 while [ $count -lt $max_count ]; do
1218 echo "ost2" >> $DIR/$tfile-2
1219 count=$((count + 1));
1222 # create a mirrored file
1223 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1224 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1225 "with verification should fail"
1226 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1227 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1228 "without verification failed"
1230 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1231 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1232 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1234 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1236 # execpted file size
1237 local fsize=$((5 * max_count))
1238 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1239 error "mirrored file size is not $fsize"
1241 # read file - all OSTs are available
1242 echo "reading file (data can be provided by any ost)... "
1243 local rs=$(cat $DIR/$tfile | head -1)
1244 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1245 error "file content error: expected: \"ost1\" or \"ost2\""
1247 # read file again with ost1 failed
1251 echo "reading file (data should be provided by ost2)..."
1252 local rs=$(cat $DIR/$tfile | head -1)
1253 [[ "$rs" == "ost2" ]] ||
1254 error "file content error: expected: \"ost2\", actual: \"$rs\""
1259 # read file again with ost2 failed
1263 # check size, glimpse should work
1264 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1265 error "mirrored file size is not $fsize"
1267 echo "reading file (data should be provided by ost1)..."
1268 local rs=$(cat $DIR/$tfile | head -1)
1269 [[ "$rs" == "ost1" ]] ||
1270 error "file content error: expected: \"ost1\", actual: \"$rs\""
1274 run_test 33a "read can choose available mirror to read"
1277 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1281 stack_trap "rm -f $DIR/$tfile" EXIT
1283 # create a file with two mirrors on OST0000 and OST0001
1284 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1286 # make sure that $tfile has two mirrors
1287 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1288 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1291 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1292 error "write failed for $DIR/$tfile"
1293 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1294 verify_flr_state $DIR/$tfile "ro"
1299 # read file - all OSTs are available
1300 echo "reading file (data can be provided by any ost)... "
1302 time cat $DIR/$tfile > /dev/null || error "read all"
1306 # read file again with ost1 {OST0000} failed
1309 echo "reading file (data should be provided by ost2)..."
1311 time cat $DIR/$tfile > /dev/null || error "read ost2"
1318 # read file again with ost2 {OST0001} failed
1322 echo "reading file (data should be provided by ost1)..."
1324 time cat $DIR/$tfile > /dev/null || error "read ost1"
1331 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1332 error "read mirror too slow without ost1, from $ra to $r1"
1333 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1334 error "read mirror too slow without ost2, from $ra to $r2"
1336 wait_osc_import_ready client ost2
1338 run_test 33b "avoid reading from unhealthy mirror"
1341 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1345 stack_trap "rm -f $DIR/$tfile" EXIT
1347 # create a file with two mirrors
1348 # mirror1: {OST0000, OST0001}
1349 # mirror2: {OST0001, OST0002}
1350 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1352 # make sure that $tfile has two mirrors
1353 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1354 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1357 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1358 error "write failed for $DIR/$tfile"
1359 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1360 verify_flr_state $DIR/$tfile "ro"
1365 # read file - all OSTs are available
1366 echo "reading file (data can be provided by any ost)... "
1367 time cat $DIR/$tfile > /dev/null || error "read all"
1369 # read file again with ost2 (OST0001) failed
1373 echo "reading file (data should be provided by ost1 and ost3)..."
1374 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1379 wait_osc_import_ready client ost2
1381 run_test 33c "keep reading among unhealthy mirrors"
1384 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1386 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1389 $LFS setstripe -o 0 $DIR/$tfile-ref
1390 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1392 # create a file with two mirrors
1393 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1394 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1396 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1397 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1399 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1400 error "mirrored file size is not 3M"
1402 # merge a mirrored file
1403 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1404 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1406 cancel_lru_locks osc
1408 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1409 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1412 echo "comparing files ... "
1414 # however, read can still return the correct data. It should return
1415 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1416 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1417 $DIR/$tfile-ref || error "file reading error"
1421 run_test 34a "read mirrored file with multiple stripes"
1424 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1426 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1429 $LFS setstripe -o 0 $DIR/$tfile-ref
1430 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1432 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1433 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1435 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1436 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1438 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1439 error "mirrored file size is not 3M"
1441 # merge a mirrored file
1442 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1443 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1445 cancel_lru_locks osc
1447 # stop two OSTs, so the 2nd component of the 1st mirror and
1448 # the 1st component of the 2nd mirror will be inaccessible, ...
1451 echo "comparing files ... "
1453 # however, read can still return the correct data. It should return
1454 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1455 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1456 $DIR/$tfile-ref || error "file reading error"
1460 run_test 34b "read mirrored file with multiple components"
1463 local tf=$DIR/$tfile
1465 $LFS setstripe -E eof $tf
1467 # add an out-of-sync mirror to the file
1468 $LFS mirror extend -N -c 2 $tf ||
1469 error "extending mirrored file $tf failed"
1471 $MULTIOP $tf oO_WRONLY:c ||
1472 error "write open a mirrored file failed"
1474 # truncate file should return error
1475 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1477 run_test 35 "allow to write to mirrored files"
1479 get_file_layout_version() {
1480 $LFS getstripe $1 | awk '/lcm_layout_gen/{print $2}'
1483 get_ost_layout_version() {
1484 $MULTIOP $1 oXc | awk '/ostlayoutversion/{print $2}'
1487 verify_ost_layout_version() {
1490 # get file layout version
1491 local flv=$(get_file_layout_version $tf)
1493 # layout version from OST objects
1494 local olv=$(get_ost_layout_version $tf)
1496 (( flv >= olv )) || error "layout version mismatch: $flv vs. $olv"
1503 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1504 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1506 $LFS mirror extend -N -f $tf-tmp $tf ||
1507 error "merging $tf-tmp into $tf failed"
1512 local tf=$DIR/$tfile
1514 stack_trap "rm -f $tf $tf-2 $tf-3"
1516 create_file_36 $tf $tf-2 $tf-3
1518 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1520 # test case 1 - check file write and verify layout version
1521 $MULTIOP $tf oO_WRONLY:c ||
1522 error "write open a mirrored file failed"
1524 # write open file should not return error
1525 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1527 # instantiate components should work
1528 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1530 # verify OST layout version
1531 verify_ost_layout_version $tf
1534 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1537 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1539 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1540 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1542 # write should take at least $fail_loc seconds and succeed
1543 local st=$(date +%s)
1544 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1546 # verify OST layout version
1547 verify_ost_layout_version $tf
1549 do_facet $mds_facet $LCTL set_param fail_loc=0
1551 run_test 36a "write to mirrored files"
1554 local tf=$DIR/$tfile
1556 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1557 skip "Need OST version at least 2.15.50"
1559 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1561 # create 2 mirrors using different OSTs
1562 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1563 error "create mirrored file"
1565 # write 1M data to one mirror
1566 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1569 # set prefer mirror to another mirror
1570 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1571 error "clear prefer mirror error"
1572 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1573 error "set prefer mirror error"
1575 # the second write should not hung
1576 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1578 run_test 36b "write should not hung when prefered mirror is stale"
1581 local tf=$DIR/$tfile
1583 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1584 skip "Need OST version at least 2.15.50"
1586 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1588 # create 2 mirrors using different OSTs
1589 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1590 error "create mirrored file"
1591 stack_trap "rm -f $tf"
1593 # write it in the background
1594 $MULTIOP $tf Ow4096_w4096c &
1599 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1600 error "clear prefer mirror error"
1601 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1602 error "set prefer mirror error"
1607 run_test 36c "change prefer mirror during write shouldn't hung"
1610 local tf=$DIR/$tfile
1612 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1613 skip "Need OST version at least 2.15.50"
1615 echo " ** create $tf"
1616 $LFS mirror create -N $tf || error "create $tf failed"
1619 echo " ** mirror extend $tf ($i/2)"
1620 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1621 flv=$(get_file_layout_version $tf)
1622 olv=$(get_ost_layout_version $tf)
1623 echo " flv=$flv olv=$olv"
1627 echo " ** write $tf ($i/2)"
1628 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1629 flv=$(get_file_layout_version $tf)
1630 olv=$(get_ost_layout_version $tf)
1631 echo " flv=$flv olv=$olv"
1633 error "write update OST layout failed $flv/$olv"
1636 echo " ** resync $tf"
1637 $LFS mirror resync $tf || error "mirror resync $tf failed"
1638 flv=$(get_file_layout_version $tf)
1639 olv=$(get_ost_layout_version $tf)
1640 echo " flv=$flv olv=$olv"
1643 echo " ** truncate $tf ($i/2)"
1644 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1645 flv=$(get_file_layout_version $tf)
1646 olv=$(get_ost_layout_version $tf)
1647 echo " flv=$flv olv=$olv"
1648 (( flv == olv || flv == olv + 1 )) ||
1649 error "truncate update OST layout failed $flv/$olv"
1652 echo " ** resync $tf"
1653 $LFS mirror resync $tf || error "mirror resync $tf failed"
1654 flv=$(get_file_layout_version $tf)
1655 olv=$(get_ost_layout_version $tf)
1656 echo " flv=$flv olv=$olv"
1659 echo " ** write $tf ($i/2)"
1660 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1661 flv=$(get_file_layout_version $tf)
1662 olv=$(get_ost_layout_version $tf)
1663 echo " flv=$flv olv=$olv"
1665 error "write update OST layout failed $flv/$olv"
1668 run_test 36d "write/punch FLR file update OST layout version"
1674 echo "create test files with size $fsize .."
1678 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1680 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1681 $TRUNCATE $tf $fsize
1687 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1688 skip "Need MDS version at least 2.11.57"
1690 local tf=$DIR/$tfile
1691 local tf2=$DIR/$tfile-2
1692 local tf3=$DIR/$tfile-3
1693 local tf4=$DIR/$tfile-4
1695 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1697 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1700 # assume the mirror id will be 1, 2, and 3
1701 declare -A checksums
1702 checksums[1]=$(cat $tf | md5sum)
1703 checksums[2]=$(cat $tf2 | md5sum)
1704 checksums[3]=$(cat $tf3 | md5sum)
1706 printf '%s\n' "${checksums[@]}"
1708 # merge these files into a mirrored file
1709 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1710 error "merging $tf2 into $tf failed"
1711 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1712 error "merging $tf3 into $tf failed"
1716 # verify mirror read, checksums should equal to the original files'
1717 echo "Verifying mirror read .."
1720 for i in "${mirror_array[@]}"; do
1721 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1722 sum=$($LFS mirror read -N $i $tf | md5sum)
1723 [ "$sum" = "${checksums[$i]}" ] ||
1724 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1727 # verify mirror write
1728 echo "Verifying mirror write .."
1729 $LFS mirror write -N2 $tf < $tf4
1731 sum=$($LFS mirror read -N2 $tf | md5sum)
1732 [[ "$sum" = "${checksums[1]}" ]] ||
1733 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1735 # verify mirror copy, write to this mirrored file will invalidate
1736 # the other two mirrors
1737 echo "Verifying mirror copy .."
1739 local osts=$(comma_list $(osts_nodes))
1741 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1742 error "mirror copy error"
1744 # verify copying is successful by checking checksums
1745 remount_client $MOUNT
1746 for i in "${mirror_array[@]}"; do
1747 sum=$($LFS mirror read -N $i $tf | md5sum)
1748 [ "$sum" = "${checksums[1]}" ] ||
1749 error "$i: mismatch checksum after copy \'$sum\'"
1754 run_test 37 "mirror I/O API verification"
1757 local tf=$DIR/$tfile
1758 local ref=$DIR/${tfile}-ref
1760 stack_trap "rm -f $tf $ref"
1762 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1763 error "creating $tf failed"
1764 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1765 $tf-2 || error "creating $tf-2 failed"
1766 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1767 error "creating $tf-3 failed"
1769 # instantiate all components
1770 $LFS mirror extend -N -f $tf-2 $tf ||
1771 error "merging $tf-2 into $tf failed"
1772 $LFS mirror extend -N -f $tf-3 $tf ||
1773 error "merging $tf-3 into $tf failed"
1774 $LFS mirror extend -N -c 1 $tf ||
1775 error "extending mirrored file $tf failed"
1777 verify_flr_state $tf "ro"
1779 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1781 local fsize=$((RANDOM << 8 + 1048576))
1782 $TRUNCATE $ref $fsize
1784 local ref_cksum=$(cat $ref | md5sum)
1786 # case 1: verify write to mirrored file & resync work
1787 cp $ref $tf || error "copy from $ref to $f error"
1788 verify_flr_state $tf "wp"
1790 local file_cksum=$(cat $tf | md5sum)
1791 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1794 echo "mirror IDs: ${mirror_array[*]}"
1796 local valid_mirror stale_mirror id mirror_cksum
1797 for id in "${mirror_array[@]}"; do
1798 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1799 [ "$ref_cksum" == "$mirror_cksum" ] &&
1800 { valid_mirror=$id; continue; }
1805 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1806 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1808 $LFS mirror resync $tf || error "resync failed"
1809 verify_flr_state $tf "ro"
1811 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1812 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1814 # case 2: inject an error to make mirror_io exit after changing
1815 # the file state to sync_pending so that we can start a concurrent
1817 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1818 verify_flr_state $tf "wp"
1820 mirror_io resync -e resync_start $tf && error "resync succeeded"
1821 verify_flr_state $tf "sp"
1823 # from sync_pending to write_pending
1824 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1825 verify_flr_state $tf "wp"
1827 mirror_io resync -e resync_start $tf && error "resync succeeded"
1828 verify_flr_state $tf "sp"
1830 # from sync_pending to read_only
1831 $LFS mirror resync $tf || error "resync failed"
1832 verify_flr_state $tf "ro"
1834 run_test 38 "resync"
1837 local tf=$DIR/$tfile
1840 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1841 error "create PFL file $tf failed"
1843 verify_mirror_count $tf 2
1844 verify_comp_count $tf 4
1846 rm -f $tf || error "delete $tf failed"
1848 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1851 local tf=$DIR/$tfile
1854 for ops in "conv=notrunc" ""; do
1857 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1858 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1859 error "create PFLR file $tf failed"
1860 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1861 error "write PFLR file $tf failed"
1863 lfs getstripe -vy $tf
1867 # file mirror state should be write_pending
1868 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1870 error "file mirror state $flags"
1871 # the 1st component (in mirror 1) should be inited
1872 verify_comp_attr lcme_flags $tf 0x10001 init
1873 # the 2nd component (in mirror 1) should be inited
1874 verify_comp_attr lcme_flags $tf 0x10002 init
1875 # the 3rd component (in mirror 1) should be uninited
1876 verify_comp_attr lcme_flags $tf 0x10003 prefer
1877 # the 4th component (in mirror 2) should be inited
1878 verify_comp_attr lcme_flags $tf 0x20004 init
1879 # the 5th component (in mirror 2) should be uninited
1880 verify_comp_attr lcme_flags $tf 0x20005 0
1881 # the 6th component (in mirror 2) should be stale
1882 verify_comp_attr lcme_flags $tf 0x20006 stale
1883 # the 7th component (in mirror 2) should be uninited
1884 if [[ x$ops = "xconv=notrunc" ]]; then
1885 verify_comp_attr lcme_flags $tf 0x20007 0
1886 elif [[ x$ops = "x" ]]; then
1887 verify_comp_attr lcme_flags $tf 0x20007 stale
1891 rm -f $tf || error "delete $tf failed"
1893 run_test 40 "PFLR rdonly state instantiation check"
1896 local tf=$DIR/$tfile
1898 stack_trap "rm -f $tf $tf-1"
1901 echo " **create two FLR files $tf $tf-1"
1902 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1903 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1904 error "create PFLR file $tf failed"
1905 $LFS mirror create -N -E 2M -S 1M -E eof \
1906 -N -E 1M -E eof --flags prefer \
1907 -N -E 4m -E eof $tf-1 ||
1908 error "create PFLR file $tf-1 failed"
1910 # file should be in ro status
1911 echo " **verify files be RDONLY"
1912 verify_flr_state $tf "ro"
1913 verify_flr_state $tf-1 "ro"
1915 # write data in [0, 2M)
1916 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1917 error "writing $tf failed"
1918 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1919 error "writing $tf-1 failed"
1921 local sum0=$(cat $tf-1 | md5sum)
1923 echo " **verify files be WRITE_PENDING"
1924 verify_flr_state $tf "wp"
1925 verify_flr_state $tf-1 "wp"
1927 # file should have stale component
1928 echo " **verify files have stale component"
1929 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1930 error "after writing $tf, it does not contain stale component"
1931 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1932 error "after writing $tf-1, it does not contain stale component"
1934 echo " **full resync"
1935 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1937 echo " **verify $tf-1 data consistency in all mirrors"
1939 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1940 [[ "$sum" = "$sum0" ]] ||
1941 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1944 echo " **verify files be RDONLY"
1945 verify_flr_state $tf "ro"
1946 verify_flr_state $tf-1 "ro"
1948 # file should not have stale component
1949 echo " **verify files do not contain stale component"
1950 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1951 error "after resyncing $tf, it contains stale component"
1952 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1953 error "after resyncing $tf, it contains stale component"
1955 # verify partial resync
1956 echo " **write $tf-1 for partial resync test"
1957 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1958 error "writing $tf-1 failed"
1960 echo " **only resync mirror 2"
1961 verify_flr_state $tf-1 "wp"
1962 $LFS mirror resync --only 2 $tf-1 ||
1963 error "resync mirror 2 of $tf-1 failed"
1964 verify_flr_state $tf "ro"
1966 # resync synced mirror
1967 echo " **resync mirror 2 again"
1968 $LFS mirror resync --only 2 $tf-1 ||
1969 error "resync mirror 2 of $tf-1 failed"
1970 verify_flr_state $tf "ro"
1971 echo " **verify $tf-1 contains stale component"
1972 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1973 error "after writing $tf-1, it does not contain stale component"
1975 echo " **full resync $tf-1"
1976 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1977 verify_flr_state $tf "ro"
1978 echo " **full resync $tf-1 again"
1979 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1980 echo " **verify $tf-1 does not contain stale component"
1981 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1982 error "after resyncing $tf, it contains stale component"
1986 run_test 41 "lfs mirror resync check"
1989 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1993 local mirror_cmd="$LFS mirror verify"
1996 stack_trap "rm -rf $td"
1998 # create parent directory
1999 mkdir $td || error "mkdir $td failed"
2001 $mirror_cmd &> /dev/null && error "no file name given"
2002 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
2003 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
2005 # create mirrored files
2006 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
2007 error "create mirrored file $tf failed"
2008 $LFS mirror create -N -E 2M -S 1M -E EOF \
2009 -N -E 6M -E 8M -E EOF \
2010 -N -E 16M -E EOF $tf-1 ||
2011 error "create mirrored file $tf-1 failed"
2012 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
2013 error "create mirrored file $tf-2 failed"
2015 # write data in [0, 10M)
2016 for i in $tf $tf-1 $tf-2; do
2017 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
2018 error "write $i failed"
2021 # resync the mirrored files
2022 $LFS mirror resync $tf-1 $tf-2 ||
2023 error "resync $tf-1 $tf-2 failed"
2025 # verify the mirrored files
2026 $mirror_cmd $tf-1 $tf-2 ||
2027 error "verify $tf-1 $tf-2 failed"
2029 get_mirror_ids $tf-1
2030 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2031 error "at least 2 mirror ids needed with '--only' option"
2032 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2034 error "'--only' option cannot be used upon multiple files"
2035 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2036 error "invalid specified mirror ids"
2038 # change the content of $tf and merge it into $tf-1
2040 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2041 error "change $tf with seek=$i failed"
2042 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2043 error "change $tf-1 with seek=$i failed"
2046 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2047 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2048 error "merge $tf into $tf-1 failed"
2050 # verify the mirrored files
2051 echo "Verify $tf-1 without -v option:"
2052 $mirror_cmd $tf-1 &&
2053 error "verify $tf-1 should fail" || echo "PASS"
2055 echo "Verify $tf-1 with -v option:"
2056 $mirror_cmd -v $tf-1 &&
2057 error "verify $tf-1 should fail"
2059 get_mirror_ids $tf-1
2060 echo "Verify $tf-1 with --only option:"
2061 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2062 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2063 "${mirror_array[-1]} should fail"
2065 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2066 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2067 "${mirror_array[1]} should succeed"
2069 # set stale components in $tf-1
2070 for i in 0x40002 0x40003; do
2071 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2072 error "set stale flag on component $i failed"
2075 # verify the mirrored file
2076 echo "Verify $tf-1 with stale components:"
2077 $mirror_cmd -vvv $tf-1 ||
2078 error "verify $tf-1 with stale components should succeed"
2080 echo "Verify $tf-1 with stale components and --only option:"
2081 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2082 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2083 "${mirror_array[-1]} should succeed"
2085 run_test 42 "lfs mirror verify"
2087 # inactivate one OST && write && restore the OST
2091 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2094 wait=$(do_facet $SINGLEMDS \
2095 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2096 wait=${wait%%[^0-9]*}
2098 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2099 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2100 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2101 sleep $(($wait * 2 + 2))
2102 echo " **write $file"
2103 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2104 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2105 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2106 sleep $((wait * 2 + 2))
2108 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2109 [ $flags = wp ] || error "file mirror state $flags != wp"
2113 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2115 local tf=$DIR/$tfile
2118 stack_trap "rm -f $tf"
2120 ## mirror 0 ost (0, 1)
2121 ## mirror 1 ost (1, 2)
2122 ## mirror 2 ost (2, 0)
2123 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2124 -N -Eeof -c2 -o2,0 $tf ||
2125 error "create 3 mirrors file $tf failed"
2127 ################## OST0 ###########################################
2129 echo " **verify components"
2130 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2131 verify_comp_attr lcme_flags $tf 0x20002 init
2132 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2135 echo " **resync $tf"
2136 $LFS mirror resync $tf
2137 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2138 [ $flags = ro ] || error "file mirror state $flags != ro"
2140 ################## OST1 ###########################################
2142 echo " **verify components"
2143 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2144 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2145 verify_comp_attr lcme_flags $tf 0x30003 init
2148 echo " **resync $tf"
2149 $LFS mirror resync $tf
2150 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2151 [ $flags = ro ] || error "file mirror state $flags != ro"
2153 ################## OST2 ###########################################
2155 echo " **verify components"
2156 verify_comp_attr lcme_flags $tf 0x10001 init
2157 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2158 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2160 run_test 43a "mirror pick on write"
2163 local tf=$DIR/$tdir/$tfile
2165 test_mkdir $DIR/$tdir
2167 stack_trap "rm -rf $tf"
2169 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2170 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2171 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2172 verify_flr_state $tf "ro"
2174 echo " ** write to $tf"
2175 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2176 verify_flr_state $tf "wp"
2178 echo " ** resync $tf"
2179 $LFS mirror resync $tf || error "resync $tf failed"
2180 verify_flr_state $tf "ro"
2182 run_test 43b "allow writing to multiple preferred mirror file"
2185 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2188 local tf=$DIR/$tdir/$tfile
2189 local tf1=$DIR/$tdir-1/$tfile-1
2191 stack_trap "rm -rf $tf $tf1"
2193 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2194 error "create directory failed"
2195 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2196 error "create remote directory failed"
2197 rm -f $tf $tf1 $tf.mirror~2
2198 # create file with 4 mirrors
2199 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2200 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2201 error "create PFLR file $tf failed"
2203 # file should be in ro status
2204 verify_flr_state $tf "ro"
2206 # write data in [0, 3M)
2207 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2208 error "writing $tf failed"
2210 verify_flr_state $tf "wp"
2212 # disallow destroying the last non-stale mirror
2213 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2214 error "destroying mirror 1 should fail"
2216 # synchronize all mirrors of the file
2217 $LFS mirror resync $tf || error "mirror resync $tf failed"
2219 verify_flr_state $tf "ro"
2222 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2223 error "split to $tf1 failed"
2225 local idx0=$($LFS getstripe -m $tf)
2226 local idx1=$($LFS getstripe -m $tf1)
2228 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2229 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2231 # verify mirror count
2232 verify_mirror_count $tf 3
2233 verify_mirror_count $tf1 1
2235 $LFS mirror split --mirror-id 2 $tf ||
2236 error "split mirror 2 failed"
2238 verify_mirror_count $tf 2
2239 verify_mirror_count $tf.mirror~2 1
2241 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2242 error "setting stale flag on component 0x30008 failed"
2244 # disallow destroying the last non-stale mirror
2245 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2246 error "destroying mirror 4 should fail"
2248 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2250 $LFS mirror split --mirror-id 3 -d $tf ||
2251 error "destroying mirror 3 failed"
2252 verify_mirror_count $tf 1
2254 # verify splitted file contains the same content as the orig file does
2255 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2256 diff $tf $tf.mirror~2 ||
2257 error "splited file $tf.mirror~2 diffs from $tf"
2259 run_test 44a "lfs mirror split check"
2262 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2263 skip "Need MDS version at least 2.14.56"
2266 local tf=$DIR/$tdir/$tfile
2268 mkdir -p $DIR/$tdir || error "create directory failed"
2272 # create 2 mirrors file
2273 $LFS mirror extend -N -c1 $tf
2277 verify_flr_state $tf "wp"
2279 local str=$(cat $tf)
2281 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2283 # get the non-stale mirror id
2284 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2286 local mirror_ids=($($LFS getstripe $tf |
2287 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2288 for ((i = 0; i < 2; i++)); do
2289 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2290 grep stale > /dev/null || break
2293 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2297 # split the updated mirror, should fail
2298 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2299 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2300 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2303 # split the stale mirror
2304 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2305 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2306 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2308 echo "make sure there's no stale comp in the file"
2309 # make sure there's no stale comp in the file
2310 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2311 ( $LFS getstripe $tf; error "stale mirror file" )
2314 [[ $str == "YYY" ]] ||
2315 ( cat $tf; error "$tf content is not YYY after split" )
2317 run_test 44b "mirror split does not create stale file"
2320 local tf=$DIR/$tdir/$tfile
2322 stack_trap "rm -f $tf"
2324 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2325 skip "Need MDS version at least 2.14.52"
2327 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2329 mkdir -p $DIR/$tdir || error "create directroy failed"
2331 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2333 block1=$(( $(stat -c "%b*%B" $tf) ))
2334 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2336 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2338 block2=$(( $(stat -c "%b*%B" $tf) ))
2339 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2341 $LFS mirror split -d --mirror-id=2 $tf ||
2342 error "mirror split $tfile failed"
2343 $LFS mirror split -d --mirror-id=3 $tf ||
2344 error "mirror split $tfile failed"
2347 block3=$(( $(stat -c "%b*%B" $tf) ))
2348 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2350 [[ $block1 -eq $block3 ]] ||
2351 error "mirror split does not reduce block# $block3 != $block1"
2353 run_test 44c "lfs mirror split reduces block size of a file"
2356 local tf=$DIR/$tdir/$tfile
2362 stack_trap "rm -f $tf"
2364 mkdir -p $DIR/$tdir || error "create directroy failed"
2366 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2368 size1=$(stat -c "%s" $tf)
2369 echo " ** before mirror ops, file size=$size1"
2371 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2373 size2=$(stat -c "%s" $tf)
2374 echo " ** after mirror extend, file size=$size2"
2376 (($size1 == $size2)) ||
2377 error "mirror extend should not change size, before: $size1, after $size2"
2379 $LFS mirror split -d --mirror-id=2 $tf ||
2380 error "mirror split $tfile failed"
2382 size2=$(stat -c "%s" $tf)
2383 echo " ** after mirror split, file size=$size2"
2384 (($size1 == $size2)) ||
2385 error "mirror split should not change size, before: $size1, after $size2"
2387 # Remount client to clear cached size information
2388 remount_client $MOUNT
2389 size2=$(stat -c "%s" $tf)
2390 echo " ** after mirror split & remount, file size=$size2"
2391 (($size1 == $size2)) ||
2392 error "mirror extend should not change size, before: $size1, after $size2"
2395 run_test 44d "lfs mirror split does not break size"
2398 local tf=$DIR/$tdir/$tfile
2399 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2403 test_mkdir $DIR/$tdir
2404 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2405 skip "Need MDS version at least 2.14.52"
2407 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2409 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2410 $LCTL set_param llite.*.xattr_cache=0
2411 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2412 stack_trap "rm -rf $tf"
2414 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2416 size1=$(stat -c "%s" $tf)
2417 echo " ** before mirror resync, file size=$size1"
2419 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2420 size1=$(stat -c "%s" $tf)
2421 size2=$($LFS getsom -s $tf)
2425 ((size1 == size2)) ||
2426 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2428 # Remount client to clear cached size information
2429 remount_client $MOUNT
2431 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2432 stack_trap "restore_lustre_params < $p; rm -f $p"
2433 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2435 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2437 size2=$(stat -c "%s" $tf)
2438 # 'getsom' here is just for debugging
2441 ((size2 == size1)) ||
2442 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2444 run_test 44e "basic FLR SOM tests + disable SOM"
2447 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2449 local file=$DIR/$tdir/$tfile
2450 local dir=$DIR/$tdir/$dir
2451 local temp=$DIR/$tdir/template
2453 test_mkdir $DIR/$tdir
2455 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2456 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2457 error "Create $file failed"
2459 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2460 rm -f $file $file.copy
2462 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2463 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2464 error "Create $file failed"
2466 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2468 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2475 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2477 local layout1=$(get_layout_param $src)
2478 local layout2=$(get_layout_param $dst)
2479 # compare their layout info
2480 [ "$layout1" == "$layout2" ] ||
2481 error "$msg_prefix $src <=> $dst layouts are not equal"
2485 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2487 local file=$DIR/$tdir/$tfile
2488 test_mkdir $DIR/$tdir
2490 ########################### 1. PFL file #############################
2491 echo " ** 1. PFL file"
2493 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2494 $file || error "1. Create PFL $file failed"
2497 verify_46 $file $file.copy "1. PFL file"
2499 ########################### 2. plain file ###########################
2500 echo " ** 2. plain file"
2502 $LFS setstripe -c2 -o0,1 -i1 $file ||
2503 error "2. Create plain $file failed"
2506 verify_46 $file $file.copy "2. plain file"
2508 ########################### 3. FLR file #############################
2509 echo " ** 3. FLR file"
2511 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2512 $file || error "3. Create FLR $file failed"
2515 verify_46 $file $file.copy "3. FLR file"
2517 local dir=$DIR/$tdir/dir
2518 ########################### 4. PFL dir ##############################
2519 echo " ** 4. PFL dir"
2521 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2522 error "4. setstripe PFL $dir failed"
2524 test_mkdir $dir.copy
2525 verify_46 $dir $dir.copy "4. PFL dir"
2527 ########################### 5. plain dir ############################
2528 echo " ** 5. plain dir"
2529 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2531 verify_46 $dir $dir.copy "5. plain dir"
2533 ########################### 6. FLR dir ##############################
2534 echo " ** 6. FLR dir"
2535 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2536 error "6. setstripe FLR $dir failed"
2538 verify_46 $dir $dir.copy "6. FLR dir"
2540 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2541 echo "server version $MDS1_VERSION does not support SEL" &&
2544 ########################### 7. SEL file ##############################
2545 echo " ** 7. SEL file"
2547 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2548 $file || error "Create $file failed"
2551 verify_46 $file $file.copy "7. SEL file"
2553 ########################### 8. SEL dir ##############################
2554 echo " ** 8. SEL dir"
2555 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2556 $dir || error "setstripe $dir failed"
2558 verify_46 $dir $dir.copy "8. SEL dir"
2560 ########################### 9. FLR SEL file ##########################
2561 echo " ** 9. FLR SEL file"
2563 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2564 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2567 verify_46 $file $file.copy "9. SEL file"
2569 ########################### 10. FLR SEL dir #########################
2570 echo " ** 10. FLR SEL dir"
2571 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2572 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2574 verify_46 $dir $dir.copy "10. SEL dir"
2576 run_test 46 "Verify setstripe --copy option"
2579 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2581 local file=$DIR/$tdir/$tfile
2586 test_mkdir $DIR/$tdir
2587 stack_trap "rm -f $file"
2591 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2592 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2593 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2594 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2595 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2597 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2598 $LFS mirror resync $file || error "resync $file failed"
2600 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2601 if [[ x$ost == "x0," ]]; then
2602 $LFS getstripe $file
2603 error "component ${ids[2]} objects allocated on $ost " \
2607 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2608 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2609 $LFS getstripe $file
2610 error "component ${ids[3]} objects allocated on $ost " \
2611 "shouldn't on OST1 or on OST2"
2616 # mirror1: [comp0] [comp1]
2617 # mirror2: [comp2] [comp3]
2618 # mirror3: [comp4] [comp5]
2619 # mirror4: [comp6] [comp7]
2620 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2621 error "create FLR $file failed"
2622 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2624 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2625 $LFS mirror resync $file || error "resync $file failed"
2627 for ((i = 0; i < 6; i++)); do
2628 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2629 awk '/l_ost_idx/{print $5}')
2631 # comp[0],comp[2],comp[4] should use different osts
2632 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2633 ${osts[2]} == ${osts[4]} ]]; then
2634 $LFS getstripe $file
2635 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2636 "allocated on duplicated OSTs"
2638 # comp[1],comp[3],comp[5] should use different osts
2639 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2640 ${osts[3]} == ${osts[5]} ]]; then
2641 $LFS getstripe $file
2642 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2643 "allocated on duplicated OSTs"
2648 run_test 47 "Verify mirror obj alloc"
2651 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2652 skip "Need MDS version at least 2.11.55"
2654 local tf=$DIR/$tfile
2656 stack_trap "rm -f $tf"
2658 echo " ** create 2 mirrors FLR file $tf"
2659 $LFS mirror create -N -E2M -Eeof --flags prefer \
2660 -N -E1M -Eeof $tf ||
2661 error "create FLR file $tf failed"
2664 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2665 verify_flr_state $tf "wp"
2667 local sum0=$(md5sum < $tf)
2669 echo " ** resync the file"
2670 $LFS mirror resync $tf
2672 echo " ** snapshot mirror 2"
2673 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2675 echo " ** write it again"
2676 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2677 echo " ** resync it again"
2678 $LFS mirror resync $tf
2680 verify_flr_state $tf "wp"
2681 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2683 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2684 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2686 echo " ** verify mirror 2 doesn't change"
2687 echo "original checksum: $sum0"
2688 echo "mirror 1 checksum: $sum1"
2689 echo "mirror 2 checksum: $sum2"
2690 [[ $sum0 = $sum2 ]] ||
2691 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2692 echo " ** mirror 2 stripe info"
2693 $LFS getstripe -v --mirror-index=2 $tf
2695 echo " ** resync mirror 2"
2696 $LFS mirror resync --only 2 $tf
2698 verify_flr_state $tf "ro"
2699 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2701 sum1=$($LFS mirror read -N1 $tf | md5sum)
2702 sum2=$($LFS mirror read -N2 $tf | md5sum)
2704 echo " ** verify mirror 2 resync-ed"
2705 echo "original checksum: $sum0"
2706 echo "mirror 1 checksum: $sum1"
2707 echo "mirror 2 checksum: $sum2"
2708 [[ $sum1 = $sum2 ]] ||
2709 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2710 echo " ** mirror 2 stripe info"
2711 $LFS getstripe -v --mirror-index=2 $tf
2713 run_test 48 "Verify snapshot mirror"
2722 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2723 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2724 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2725 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2726 skip "LU-1941: FIEMAP unimplemented on ZFS"
2728 trap cleanup_49 EXIT RETURN
2730 local file=$DIR/$tfile
2732 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2733 error "setstripe on $file"
2734 stack_trap "rm -f $file"
2736 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2737 $LFS mirror resync $file
2739 filefrag -ves $file || error "filefrag $file failed"
2740 filefrag_op=$(filefrag -ve -k $file |
2741 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2743 #Filesystem type is: bd00bd0
2744 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2745 # ext: device_logical: physical_offset: length: dev: flags:
2746 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2747 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2748 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2750 last_lun=$(echo $filefrag_op | cut -d: -f5)
2754 for line in $filefrag_op; do
2755 frag_lun=$(echo $line | cut -d: -f5)
2756 ext_len=$(echo $line | cut -d: -f4)
2757 if [[ "$frag_lun" != "$last_lun" ]]; then
2758 if (( tot_len != 1024 )); then
2760 error "$file: OST$last_lun $tot_len != 1024"
2766 (( tot_len += ext_len ))
2769 if (( num_luns != 2 || tot_len != 1024 )); then
2771 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2774 echo "FIEMAP on $file succeeded"
2776 run_test 49a "FIEMAP upon FLR file"
2778 test_50A() { # EX-2179
2781 local file=$DIR/$tdir/$tfile
2783 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2785 $LFS mirror extend -N -c1 -i1 $file ||
2786 error "extending mirror for $file failed"
2788 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2792 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2794 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2796 echo "$file layout generation from $olv to $flv"
2797 (( $flv != ($olv + 1) )) &&
2798 error "split does not increase layout gen from $olv to $flv"
2800 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2802 $LFS getstripe -v $file || error "getstripe $file failed"
2804 run_test 50A "mirror split update layout generation"
2807 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2808 skip "OST does not support SEEK_HOLE"
2809 [ "$FSTYPE" != "zfs" ] ||
2810 skip "lseek for ZFS is not accurate if obj is not committed"
2812 local file=$DIR/$tdir/$tfile
2820 echo " ** create striped file $file"
2821 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2822 error "cannot create file with PFL layout"
2823 echo " ** write 1st data chunk at 1M boundary"
2824 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2825 error "cannot write data at 1M boundary"
2826 echo " ** write 2nd data chunk at 2M boundary"
2827 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2828 error "cannot write data at 2M boundary"
2829 echo " ** create hole at the file end"
2830 $TRUNCATE $file 3700000 || error "truncate fails"
2832 echo " ** verify sparseness"
2833 offset=$(lseek_test -d 1000 $file)
2834 echo " first data offset: $offset"
2835 [[ $offset == 1000 ]] &&
2836 error "src: data is not expected at offset $offset"
2837 offset=$(lseek_test -l 3500000 $file)
2838 echo " hole at the end: $offset"
2839 [[ $offset == 3500000 ]] ||
2840 error "src: hole is expected at offset $offset"
2842 echo " ** extend the file with new mirror"
2843 # migrate_copy_data() is used
2844 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2845 error "cannot create mirror"
2846 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2847 error "$file still has stale component"
2849 # check migrate_data_copy() was correct
2850 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2851 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2852 [[ $sum_1 == $sum_2 ]] ||
2853 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2855 # stale first mirror
2856 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2857 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2859 echo " ** verify mirror #2 sparseness"
2860 offset=$(lseek_test -d 1000 $file)
2861 echo " first data offset: $offset"
2862 [[ $offset == 1000 ]] &&
2863 error "dst: data is not expected at offset $offset"
2864 offset=$(lseek_test -l 3500000 $file)
2865 echo " hole at the end: $offset"
2866 [[ $offset == 3500000 ]] ||
2867 error "dst: hole is expected at offset $offset"
2869 echo " ** copy mirror #2 to mirror #1"
2870 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2871 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2872 error "$file still has stale component"
2874 # check llapi_mirror_copy_many correctness
2875 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2876 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2877 [[ $sum_1 == $sum_2 ]] ||
2878 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2880 # stale 1st component of mirror #2 before lseek call
2881 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2883 echo " ** verify mirror #1 sparseness again"
2884 offset=$(lseek_test -d 1000 $file)
2885 echo " first data offset: $offset"
2886 [[ $offset == 1000 ]] &&
2887 error "dst: data is not expected at offset $offset"
2888 offset=$(lseek_test -l 3500000 $file)
2889 echo " hole at the end: $offset"
2890 [[ $offset == 3500000 ]] ||
2891 error "dst: hole is expected at offset $offset"
2893 cancel_lru_locks osc
2895 blocks=$(stat -c%b $file)
2896 echo " ** final consumed blocks: $blocks"
2897 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2898 # that file is still sparse
2899 (( blocks < 1000 )) ||
2900 error "Mirrored file consumes $blocks blocks"
2902 run_test 50a "mirror extend/copy preserves sparseness"
2905 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2906 skip "OST does not support SEEK_HOLE"
2907 [ "$FSTYPE" != "zfs" ] ||
2908 skip "lseek for ZFS is not accurate if obj is not committed"
2910 local file=$DIR/$tdir/$tfile
2917 stack_trap "rm -f $file"
2919 echo " ** create mirrored file $file"
2920 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2921 -N -E2M -S1M -E eof -S2M $file ||
2922 error "cannot create mirrored file"
2923 echo " ** write data chunk at 1M boundary"
2924 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2925 error "cannot write data at 1M boundary"
2926 echo " ** create hole at the file end"
2927 $TRUNCATE $file 3700000 || error "truncate fails"
2929 echo " ** verify sparseness"
2930 offset=$(lseek_test -d 1000 $file)
2931 echo " first data offset: $offset"
2932 [[ $offset == 1000 ]] &&
2933 error "src: data is not expected at offset $offset"
2934 offset=$(lseek_test -l 3500000 $file)
2935 echo " hole at the end: $offset"
2936 [[ $offset == 3500000 ]] ||
2937 error "src: hole is expected at 3500000"
2939 echo " ** resync mirror #2 to mirror #1"
2940 $LFS mirror resync $file
2942 # check llapi_mirror_copy_many correctness
2943 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2944 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2945 [[ $sum_1 == $sum_2 ]] ||
2946 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2948 cancel_lru_locks osc
2950 blocks=$(stat -c%b $file)
2951 echo " ** consumed blocks: $blocks"
2952 # without full punch() support the first component can be not sparse
2953 # but the last one should be, so file should use far fewer blocks
2954 (( blocks < 5000 )) ||
2955 error "Mirrored file consumes $blocks blocks"
2957 # stale first component in mirror #1
2958 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2959 echo " ** truncate file down"
2961 echo " ** write data chunk at 2M boundary"
2962 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2963 error "cannot write data at 2M boundary"
2964 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2965 $LFS mirror resync $file || error "mirror rsync fails"
2966 # first component is still stale
2967 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2968 error "$file still has no stale component"
2969 echo " ** resync mirror #2 to mirror #1 again"
2970 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2971 $LFS mirror resync $file || error "mirror rsync fails"
2972 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2973 error "$file still has stale component"
2975 # check llapi_mirror_copy_many correctness
2976 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2977 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2978 [[ $sum_1 == $sum_2 ]] ||
2979 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2981 cancel_lru_locks osc
2983 blocks=$(stat -c%b $file)
2984 echo " ** final consumed blocks: $blocks"
2985 # while the first component can lose sparseness, the last one should
2986 # not, so whole file should still use far fewer blocks in total
2987 (( blocks < 3000 )) ||
2988 error "Mirrored file consumes $blocks blocks"
2990 run_test 50b "mirror rsync handles sparseness"
2993 local tf=$DIR/$tdir/$tfile
2995 test_mkdir $DIR/$tdir
2997 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
2998 verify_flr_state $tf "ro"
3000 if [[ "$FSTYPE" == "ldiskfs" ]]; then
3001 # ZFS does not support fallocate for now
3002 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
3003 skip_eopnotsupp "$out|punch hole in $tf failed"
3004 verify_flr_state $tf "wp"
3007 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
3008 $LFS mirror resync $tf || error "mirror resync $tf failed"
3009 verify_flr_state $tf "ro"
3011 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
3012 verify_flr_state $tf "wp"
3014 run_test 50c "punch_hole/mmap_write stale other mirrors"
3017 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3018 skip "OST does not support SEEK_HOLE"
3019 [ "$FSTYPE" != "zfs" ] ||
3020 skip "lseek for ZFS is not accurate if obj is not committed"
3022 local file=$DIR/$tdir/$tfile
3029 echo " ** create mirrored file $file"
3030 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3031 -N -E2M -S1M -E eof -S2M $file ||
3032 error "cannot create mirrored file"
3033 echo " ** write data chunk at 1M boundary"
3034 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3035 error "cannot write data at 1M boundary"
3036 echo " ** create hole at the file start"
3037 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3040 if [[ $rc -eq 0 ]]; then
3041 verify_flr_state $file "wp"
3042 elif [[ ! $prt =~ unsupported ]]; then
3043 error "punch hole in $file failed: $prt"
3045 skip "Fallocate punch is not supported: $prt"
3048 echo " ** verify sparseness"
3049 offset=$(lseek_test -d 1000 $file)
3050 echo " first data offset: $offset"
3051 (( $offset >= 1024 * 1024 )) ||
3052 error "src: data is not expected at offset $offset"
3054 echo " ** resync mirror #2"
3055 $LFS mirror resync $file
3057 # check llapi_mirror_copy_many correctness
3058 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3059 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3060 [[ $sum_1 == $sum_2 ]] ||
3061 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3063 cancel_lru_locks osc
3065 # stale first component in mirror #1
3066 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3067 echo " ** verify sparseness of mirror #2"
3068 offset=$(lseek_test -d 1000 $file)
3069 echo " first data offset: $offset"
3070 (( $offset >= 1024 * 1024 )) ||
3071 error "src: data is not expected at offset $offset"
3073 run_test 50d "mirror rsync keep holes"
3076 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3077 skip "OST does not support SEEK_HOLE"
3079 local file=$DIR/$tdir/$tfile
3080 local old_size=2147483648 # 2GiB
3084 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3085 $TRUNCATE $file $old_size
3087 $LFS mirror extend -N -c 1 $file
3088 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3089 $LFS mirror resync $file
3091 new_size=$(stat --format='%s' $file)
3092 if ((new_size != old_size)); then
3093 error "new_size ($new_size) is not equal to old_size ($old_size)"
3096 run_test 60a "mirror extend sets correct size on sparse file"
3098 get_flr_layout_gen() {
3099 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3100 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3103 check_layout_gen() {
3106 local v1=$(get_flr_layout_gen $tf)
3107 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3109 [[ $v1 -eq $v2 ]] ||
3110 error "$tf in-memory layout gen $v1 != $v2 after $2"
3114 local tf=$DIR/$tdir/$tfile
3116 test_mkdir $DIR/$tdir
3118 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3120 for ((i = 0; i < 20; i++)); do
3121 $LFS mirror extend -N $tf ||
3122 error "extending mirror for $tf failed"
3123 check_layout_gen $tf "extend"
3125 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3126 error "split $tf failed"
3127 check_layout_gen $tf "split"
3130 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3133 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3138 local -a old=( $2 $3 $4 )
3141 new=( $(get_times_61 $file) )
3142 ((${old[0]} == ${new[0]})) ||
3143 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3145 ((${old[1]} == ${new[1]})) ||
3146 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3149 test_61a() { # LU-14508
3150 local file=$DIR/$tdir/$tfile
3151 local old_diff=($(do_facet mds1 "$LCTL get_param -n mdd.*.atime_diff"))
3152 local mdts=$(comma_list $(mdts_nodes))
3156 do_nodes $mdts "$LCTL set_param mdd.*.atime_diff=1"
3157 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.atime_diff=$old_diff"
3161 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3162 echo "create $file-2"
3163 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3165 echo XXX > $file || error "write $file failed"
3166 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3168 echo "sleep $nap seconds, then cat $tfile"
3170 cat $file || error "cat $file failed"
3172 echo "sleep $nap seconds, then re-write $tfile"
3174 echo XXXX > $file || error "write $file failed"
3175 cp -p $file $file-2 || error "copy $file-2 failed"
3177 echo "sleep $nap seconds"
3180 tim=( $(get_times_61 $file) )
3182 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3183 $LFS mirror extend -N -f $file-2 $file ||
3184 error "cannot mirror merge $file-2 to $file"
3185 check_times_61 $file "${tim[@]}"
3187 echo "mirror extend $tfile and test timestamps"
3188 $LFS mirror extend -N -c1 -i1 $file ||
3189 error "cannot extend mirror $file"
3190 check_times_61 $file "${tim[@]}"
3192 echo "migrate $tfile and test timestamps"
3193 $LFS migrate -n $file || error "cannot migrate $file"
3194 check_times_61 $file "${tim[@]}"
3196 echo "normal user migrate $tfile and test timestamps"
3197 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3198 check_times_61 $file "${tim[@]}"
3200 run_test 61a "mirror extend and migrate preserve timestamps"
3202 test_61b() { # LU-14508
3203 local file=$DIR/$tdir/$tfile
3209 echo XXX > $file || error "create $file failed"
3210 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3212 echo "sleep $nap seconds, then cat $tfile"
3214 cat $file || error "cat $file failed"
3216 echo "sleep $nap seconds, then re-write $tfile"
3218 echo XXXX > $file || error "write $file failed"
3220 echo "sleep $nap seconds, then test timestamps"
3223 tim=( $(get_times_61 $file) )
3225 echo "mirror extend $tfile and test timestamps"
3226 $LFS mirror extend -N -c1 -i1 $file ||
3227 error "cannot extend mirror $file"
3228 check_times_61 $file "${tim[@]}"
3230 echo "mirror split $tfile and test timestamps"
3231 $LFS mirror split -d --mirror-id=1 $file ||
3232 error "cannot split mirror 1 off $file"
3233 check_times_61 $file "${tim[@]}"
3235 echo "normal user mirror extend $tfile and test timestamps"
3236 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3237 error "cannot extend mirror $file"
3238 check_times_61 $file "${tim[@]}"
3240 run_test 61b "mirror extend and split preserve timestamps"
3242 test_61c() { # LU-14508
3243 local file=$DIR/$tdir/$tfile
3249 echo XXX > $file || error "create $file failed"
3250 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3252 echo "sleep $nap seconds, then cat $tfile"
3254 cat $file || error "cat $file failed"
3256 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3258 $LFS mirror extend -N -c1 -i1 $file ||
3259 error "cannot extend mirror $file"
3260 echo XXXX > $file || error "write $file failed"
3262 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3263 tim=( $(get_times_61 $file) )
3265 $LFS mirror resync $file || error "cannot resync mirror $file"
3266 check_times_61 $file "${tim[@]}"
3268 echo XXXXXX > $file || error "write $tfile failed"
3270 echo "normal user resync $tfile and test timestamps"
3271 tim=( $(get_times_61 $file) )
3272 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3273 check_times_61 $file "${tim[@]}"
3275 run_test 61c "mirror resync preserves timestamps"
3278 local file=$DIR/$tdir/$tfile
3282 echo "create mirror file with unknown magic"
3283 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3284 # mirror 2 in-memory magic is bad
3285 $LCTL set_param fail_loc=0x1426 fail_val=2
3286 $LFS setstripe -N --flags=prefer -N2 $file ||
3287 error "failed to create mirror file $file"
3288 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3289 [[ $magic == 0x0BAD0BD0 ]] ||
3290 error "mirror 2 magic $magic is not bad as expected"
3291 cat /etc/passwd > $file || error "cannot write to $file"
3292 diff /etc/passwd $file || error "read $file error"
3296 echo "create mirror file with unknown pattern"
3297 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3298 # mirror 1 in-memory pattern is bad
3299 $LCTL set_param fail_loc=0x1427 fail_val=1
3300 $LFS setstripe -N -N --flags=prefer $file ||
3301 error "failed to create mirror file $file"
3302 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3303 [[ $pattern == 502 ]] ||
3304 error "mirror 1 pattern $pattern is not bad as expected"
3305 cat /etc/passwd > $file || error "cannot write to $file"
3306 diff /etc/passwd $file || error "read $file error"
3308 run_test 62 "read/write with unknown type of mirror"
3311 local tf=$DIR/$tdir/$tfile
3313 test_mkdir $DIR/$tdir
3314 stack_trap "rm -f $tf"
3318 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3322 echo "mirror create pid $c_pid"
3325 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3328 echo "mirror split pid $s_pid"
3330 echo "mirror create and split race for 60 seconds, should not crash"
3332 kill -9 $c_pid &> /dev/null
3333 kill -9 $s_pid &> /dev/null
3337 run_test 70 "mirror create and split race"
3340 local tf=$DIR/$tdir/$tfile
3342 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3343 skip "Need OST version at least 2.14.51"
3346 test_mkdir $DIR/$tdir
3347 stack_trap "rm -f $tf"
3349 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3350 error "setstripe $tf failed"
3352 FSXNUM=${FSXNUM:-1000}
3353 $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3355 run_test 70a "flr mode fsx test"
3360 local fsize=$(stat --printf=%s $tf)
3362 while [ -f $ctrl_file ]; do
3363 local off=$((RANDOM << 8))
3364 local len=$((RANDOM << 5 + 131072))
3366 [ $((off + len)) -gt $fsize ] && {
3367 fsize=$((off + len))
3368 echo "Extending file size to $fsize .."
3371 flock -s $lock_file -c \
3372 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3374 error "failed writing to $off:$len"; }
3375 sleep 0.$((RANDOM % 2 + 1))
3382 while [ -f $ctrl_file ]; do
3383 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3384 { rm -f $ctrl_file; error "read failed"; }
3385 sleep 0.$((RANDOM % 2 + 1))
3392 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3394 exec 200<>$lock_file
3395 while [ -f $ctrl_file ]; do
3396 local lock_taken=false
3397 local index=$((RANDOM % ${#options[@]}))
3398 local cmd="mirror_io resync ${options[$index]}"
3400 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3402 [ $((RANDOM % 4)) -eq 0 ] && {
3408 echo -n "resync file $tf with '$cmd' .."
3410 if [[ $lock_taken = "true" ]]; then
3412 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3415 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3418 sleep 0.$((RANDOM % 8 + 1))
3422 # this was test_200 before adding "b" and "c" subtests
3424 local tf=$DIR/$tfile
3425 local tf2=$DIR2/$tfile
3426 local tf3=$DIR3/$tfile
3428 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3429 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3430 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3432 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3433 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3434 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3436 $LFS mirror extend -N -f $tf-2 $tf ||
3437 error "merging $tf-2 into $tf failed"
3438 $LFS mirror extend -N -f $tf-3 $tf ||
3439 error "merging $tf-3 into $tf failed"
3441 mkdir -p $MOUNT2 && mount_client $MOUNT2
3443 mkdir -p $MOUNT3 && mount_client $MOUNT3
3445 verify_flr_state $tf3 "ro"
3447 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3448 $LCTL set_param fail_loc=0x1A03
3450 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3451 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3455 write_file_200 $tf &
3461 write_file_200 $tf2 &
3464 read_file_200 $tf2 &
3467 resync_file_200 $tf3 &
3471 [ "$SLOW" = "yes" ] && sleep_time=360
3472 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3479 echo "Waiting ${pids[*]}"
3482 umount_client $MOUNT2
3483 umount_client $MOUNT3
3485 # resync and verify mirrors
3486 $LFS mirror resync $tf || error "final resync failed"
3489 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3491 for id in "${mirror_array[@]:1}"; do
3492 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3493 error "checksum error for mirror $id"
3498 run_test 200a "stress test"
3501 local tf=$DIR/$tfile
3502 local tf2=$DIR2/$tfile
3503 local tf3=$DIR3/$tfile
3505 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3506 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3507 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3509 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3510 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3511 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3513 $LFS mirror extend -N -f $tf-2 $tf ||
3514 error "merging $tf-2 into $tf failed"
3515 $LFS mirror extend -N -f $tf-3 $tf ||
3516 error "merging $tf-3 into $tf failed"
3518 mkdir -p $MOUNT2 && mount_client $MOUNT2
3520 mkdir -p $MOUNT3 && mount_client $MOUNT3
3522 verify_flr_state $tf3 "ro"
3524 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3525 $LCTL set_param fail_loc=0x1423
3529 write_file_200 $tf &
3535 write_file_200 $tf2 &
3538 read_file_200 $tf2 &
3541 resync_file_200 $tf3 &
3545 [ "$SLOW" = "yes" ] && sleep_time=400
3549 echo "Waiting ${pids[@]}"
3552 umount_client $MOUNT2
3553 umount_client $MOUNT3
3555 # resync and verify mirrors
3556 $LFS mirror resync $tf || {
3558 error "final resync failed"
3562 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3563 for id in ${mirror_array[@]:1}; do
3564 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3565 error "checksum error for mirror $id"
3570 run_test 200b "racing IO, mirror extend and resync"
3573 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3574 skip "Need MDS version at least 2.15.53"
3576 local tf=$DIR/$tfile
3577 local tf2=$DIR2/$tfile
3579 mkdir -p $MOUNT2 && mount_client $MOUNT2
3580 stack_trap "umount_client $MOUNT2"
3581 stack_trap "rm -f $tf"
3585 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3587 mdt_idx=$($LFS getstripe -m $tf)
3589 cancel_lru_locks mdc
3590 cancel_lru_locks osc
3592 # start a process modifying file, block it just
3593 # before layout lock acquisition
3594 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3595 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3596 #log "dd to stale replica"
3597 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3603 $LFS mirror extend -N -c -1 $tf2 || {
3605 error "can't mirror"
3607 log "mirror extend done"
3608 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3610 # wait for blocking dd to complete and modify file
3611 wait $PID || error "2nd dd failed"
3614 verify_mirror_count $tf 2
3616 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3619 error "both replicas are still in sync"
3622 $LFS mirror verify -vvv $tf || {
3624 error "corrupted in-sync file"
3627 run_test 200c "layout change racing with open: LOVEA changes"
3629 cleanup_test_201() {
3630 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3632 umount_client $MOUNT2
3636 local delay=${RESYNC_DELAY:-5}
3638 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3639 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3641 stack_trap cleanup_test_201 EXIT
3643 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3644 changelog_register -n)
3646 mkdir -p $MOUNT2 && mount_client $MOUNT2
3650 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3651 [ -z "$log" ] && { sleep 1; continue; }
3653 index=$(echo $log | awk '{print $1}')
3654 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3655 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3656 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3659 [ -z "$file" ] && continue
3661 local now=$(date +%s)
3663 echo "file: $file $fid was modified at $ts, now: $now, " \
3664 "will be resynced at $((ts+delay))"
3666 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3668 $LFS mirror resync $file
3669 echo "$file resync done"
3672 run_test 201 "FLR data mover"
3675 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3677 local tf=$DIR/$tfile
3680 $LFS setstripe -E 1M -S 1M -c 1 $tf
3681 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3682 verify_comp_attr stripe-count $tf ${ids[0]} 1
3684 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3685 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3686 verify_comp_attr stripe-count $tf ${ids[0]} 1
3687 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3689 dd if=/dev/zero of=$tf bs=1M count=2
3690 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3691 verify_comp_attr stripe-count $tf ${ids[0]} 1
3692 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3694 run_test 202 "lfs setstripe --add-component wide striping"
3697 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3698 skip "Need MDS version at least 2.11.55"
3699 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3701 local tf=$DIR/$tfile
3704 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3705 #delete first mirror
3706 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3709 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3710 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3711 error "getstripe count of mirror 2"
3712 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3714 #extend a mirror with 2 OSTs
3715 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3718 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3719 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3720 error "getstripe count of mirror 2"
3721 [[ x$old_id = x$new_id ]] ||
3722 error "mirror 2 changed ID from $old_id to $new_id"
3723 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3725 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3726 error "getstripe count of mirror 3"
3727 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3729 run_test 203 "mirror file preserve mirror ID"
3731 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3733 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3734 skip "skipped for lustre < $SEL_VER"
3736 local comp_file=$DIR/$tdir/$tfile
3740 test_mkdir $DIR/$tdir
3741 stack_trap "rm -f $comp_file"
3743 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3744 # by extension space to -1
3745 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3746 error "Create $comp_file failed"
3748 # Write to first component, extending & staling second mirror
3749 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3750 error "dd to extend + stale failed"
3752 $LFS getstripe $comp_file
3754 flg_opts="--component-flags init,stale"
3755 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3756 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3758 flg_opts="--component-flags extension"
3759 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3760 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3762 # mirror resync should not change the extents
3763 $LFS mirror resync $comp_file
3765 flg_opts="--component-flags init"
3766 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3767 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3769 flg_opts="--component-flags extension"
3770 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3771 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3773 sel_layout_sanity $comp_file 5
3775 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3777 # Simple test of FLR + self-extending layout, SEL in primary mirror
3779 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3780 skip "skipped for lustre < $SEL_VER"
3782 local comp_file=$DIR/$tdir/$tfile
3786 test_mkdir $DIR/$tdir
3787 stack_trap "rm -f $comp_file"
3789 # first mirror is 1M followed by extension space to -1, second mirror
3790 # is 0-10M, then 10M-(-1),
3791 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3792 error "Create $comp_file failed"
3794 # Write to first component, extending first component & staling
3796 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3797 error "dd to extend + stale failed"
3799 $LFS getstripe $comp_file
3801 flg_opts="--component-flags init"
3802 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3803 [ $found -eq 1 ] || error "write: First comp end incorrect"
3805 flg_opts="--component-flags extension"
3806 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3807 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3809 flg_opts="--component-flags init,stale"
3810 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3811 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3813 # This component is staled because it overlaps the extended first
3814 # component of the primary mirror, even though it doesn't overlap
3815 # the actual write - thus not inited.
3816 flg_opts="--component-flags stale"
3817 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3818 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3820 # mirror resync should not change the extents
3821 $LFS mirror resync $comp_file
3823 $LFS getstripe $comp_file
3825 flg_opts="--component-flags init"
3826 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3827 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3829 flg_opts="--component-flags extension"
3830 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3831 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3833 flg_opts="--component-flags init"
3834 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3835 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3837 flg_opts="--component-flags init"
3838 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3839 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3841 sel_layout_sanity $comp_file 5
3843 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3845 # FLR + SEL failed extension & component removal
3846 # extension space in second mirror
3848 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3849 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3850 skip "skipped for lustre < $SEL_VER"
3852 local comp_file=$DIR/$tdir/$tfile
3855 local ost_name=$(ostname_from_index $ost_idx1)
3857 test_mkdir $DIR/$tdir
3858 stack_trap "rm -f $comp_file"
3860 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3861 # extension space from 1M to 1G, then normal space to -1
3862 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3863 -E -1 $comp_file || error "Create $comp_file failed"
3865 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3868 # write to first comp (0 - 10M) of mirror 1, extending + staling
3869 # first + second comp of mirror 2
3870 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3873 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3876 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3878 $LFS getstripe $comp_file
3880 found=$($LFS find --component-start 0m --component-end 1m \
3881 --comp-flags init,stale $comp_file | wc -l)
3882 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3884 found=$($LFS find --component-start 1m --component-end EOF \
3885 --comp-flags stale,^init $comp_file | wc -l)
3886 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3888 local mirror_id=$($LFS getstripe --component-start=1m \
3889 --component-end=EOF $comp_file | \
3890 grep lcme_mirror_id | awk '{ print $2 }')
3892 [[ $mirror_id -eq 2 ]] ||
3893 error "component not in correct mirror? $mirror_id"
3895 $LFS mirror resync $comp_file
3897 $LFS getstripe $comp_file
3899 # component dimensions should not change from resync
3900 found=$($LFS find --component-start 1m --component-end EOF \
3901 --component-flags init $comp_file | wc -l)
3902 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3904 sel_layout_sanity $comp_file 4
3906 run_test 204c "FLR write/stale/resync test with component removal"
3908 # Successful repeated component in primary mirror
3910 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3911 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3912 skip "skipped for lustre < $SEL_VER"
3914 local comp_file=$DIR/$tdir/$tfile
3917 wait_delete_completed
3919 test_mkdir $DIR/$tdir
3920 stack_trap "rm -f $comp_file"
3922 # first mirror is 64M followed by extension space to -1, second mirror
3923 # is 0-10M, then 10M-(-1)
3924 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3925 error "Create $comp_file failed"
3927 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3928 local ost_name=$(ostname_from_index $ost_idx1)
3929 # degrade OST for first comp so we won't extend there
3930 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3931 obdfilter.$ost_name.degraded=1
3934 # Write beyond first component, causing repeat & stale second mirror
3935 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3938 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3939 obdfilter.$ost_name.degraded=0
3942 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3944 $LFS getstripe $comp_file
3946 found=$($LFS find --component-start 64m --component-end 128m \
3947 --component-flags init $comp_file | wc -l)
3948 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3950 local ost_idx2=$($LFS getstripe --component-start=64m \
3951 --component-end=128m --component-flags=init \
3953 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3954 local mirror_id=$($LFS getstripe --component-start=64m \
3955 --component-end=128m --component-flags=init \
3956 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3957 [[ $mirror_id -eq 1 ]] ||
3958 error "component not in correct mirror: $mirror_id, not 1"
3960 $LFS mirror resync $comp_file
3962 $LFS getstripe $comp_file
3964 # component dimensions should not change from resync
3965 found=$($LFS find --component-start 0m --component-end 64m \
3966 --component-flags init $comp_file | wc -l)
3967 [ $found -eq 1 ] || error "resync: first comp incorrect"
3968 found=$($LFS find --component-start 64m --component-end 128m \
3969 --component-flags init $comp_file | wc -l)
3970 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3972 sel_layout_sanity $comp_file 5
3974 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3976 # Successful repeated component, SEL in non-primary mirror
3978 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3979 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3980 skip "skipped for lustre < $SEL_VER"
3982 local comp_file=$DIR/$tdir/$tfile
3985 wait_delete_completed
3988 test_mkdir $DIR/$tdir
3989 stack_trap "rm -f $comp_file"
3991 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
3992 # space to -1 (-z 64M, so first comp is 0-64M)
3993 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
3994 # will be not enough - one will be degraded, the other is used on
3995 # an overlapping mirror.
3996 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
3997 error "Create $comp_file failed"
3999 local ost_idx1=$($LFS getstripe --component-start=0 \
4000 --component-end=64m -i $comp_file)
4001 local ost_name=$(ostname_from_index $ost_idx1)
4002 # degrade OST for first comp of 2nd mirror so we won't extend there
4003 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4004 obdfilter.$ost_name.degraded=1
4007 $LFS getstripe $comp_file
4009 # Write to first component, stale & instantiate second mirror components
4010 # overlapping with the written component (0-100M);
4011 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4014 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4015 obdfilter.$ost_name.degraded=0
4017 $LFS getstripe $comp_file
4019 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
4021 found=$($LFS find --component-start 0m --component-end 64m \
4022 --component-flags init,stale $comp_file | wc -l)
4023 [ $found -eq 1 ] || error "write: first comp incorrect"
4025 # was repeated due to degraded ost
4026 found=$($LFS find --component-start 64m --component-end 128m \
4027 --component-flags init,stale $comp_file | wc -l)
4028 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4030 local ost_idx2=$($LFS getstripe --component-start=64m \
4031 --component-end=128m --component-flags=init \
4033 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4034 local mirror_id=$($LFS getstripe --component-start=0m \
4035 --component-end=64m --component-flags=init \
4036 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4037 [[ $mirror_id -eq 2 ]] ||
4038 error "component not in correct mirror? $mirror_id"
4040 $LFS mirror resync $comp_file
4042 $LFS getstripe $comp_file
4044 # component dimensions should not change from resync
4045 found=$($LFS find --component-start 0m --component-end 64m \
4046 --component-flags init,^stale $comp_file | wc -l)
4047 [ $found -eq 1 ] || error "resync: first comp incorrect"
4048 found=$($LFS find --component-start 64m --component-end 128m \
4049 --component-flags init,^stale $comp_file | wc -l)
4050 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4052 sel_layout_sanity $comp_file 5
4054 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4056 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4058 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4059 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4060 skip "skipped for lustre < $SEL_VER"
4062 local comp_file=$DIR/$tdir/$tfile
4065 wait_delete_completed
4067 test_mkdir $DIR/$tdir
4068 stack_trap "rm -f $comp_file"
4070 pool_add $TESTNAME || error "Pool creation failed"
4071 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4073 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4074 # space to -1 (-z 64M, so first comp is 0-64M)
4075 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4076 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4078 local ost_name0=$(ostname_from_index 0)
4079 local ost_name1=$(ostname_from_index 1)
4081 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4082 # extend original comp
4083 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4084 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4087 # a write to the 1st component, 100M length, which will try to stale
4088 # the first 100M of mirror 2, attempting to extend its 0-64M component
4089 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4092 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4093 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4096 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4098 $LFS getstripe $comp_file
4100 found=$($LFS find --component-start 0m --component-end 128m \
4101 --component-flags init,stale $comp_file | wc -l)
4102 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4104 local mirror_id=$($LFS getstripe --component-start=0m \
4105 --component-end=128m --component-flags=init \
4106 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4108 [[ $mirror_id -eq 2 ]] ||
4109 error "component not in correct mirror? $mirror_id, not 2"
4111 $LFS mirror resync $comp_file
4113 $LFS getstripe $comp_file
4115 # component dimensions should not change from resync
4116 found=$($LFS find --component-start 0m --component-end 128m \
4117 --component-flags init,^stale $comp_file | wc -l)
4118 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4120 sel_layout_sanity $comp_file 4
4122 run_test 204f "FLR write/stale/resync sel w/forced extension"
4124 function test_205() {
4125 local tf=$DIR/$tfile
4128 $LFS setstripe -c1 $tf
4129 $LFS mirror extend -N $tf
4130 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4131 (( $mirrors == 2 )) || error "no new mirror was created?"
4133 $LFS mirror extend -N --flags=prefer $tf
4134 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4135 (( $mirrors == 3 )) || error "no new mirror was created?"
4137 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4138 error "prefer flag was not set on the new mirror"
4140 run_test 205 "lfs mirror extend to set prefer flag"
4142 function test_206() {
4143 # create a new OST pool
4144 local pool_name=$TESTNAME
4146 create_pool $FSNAME.$pool_name ||
4147 error "create OST pool $pool_name failed"
4148 # add OSTs into the pool
4149 pool_add_targets $pool_name 0 1 ||
4150 error "add OSTs into pool $pool_name failed"
4152 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4153 error "can't setstripe"
4154 $LFS mirror extend -N $DIR/$tfile ||
4155 error "can't create replica"
4156 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4157 $LFS getstripe $DIR/$tfile
4158 error "prefer found"
4160 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4161 $LFS getstripe $DIR/$tfile
4162 error "can't setstripe prefer"
4165 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4166 $LFS getstripe $DIR/$tfile
4167 error "no prefer found"
4173 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4176 local file=$DIR/$tfile
4177 local tmpfile=$DIR/$tfile-tt
4179 [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
4180 skip "Need MDS version at least 2.14.50"
4182 stack_trap "rm -f $tmpfile $file"
4184 # generate data for verification
4185 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4186 error "can't generate file with random data"
4188 # create a mirrored file with one stale replica
4189 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4190 error "create mirrored file $file failed"
4191 get_mirror_ids $file
4192 echo "mirror IDs: ${mirror_array[*]}"
4194 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4195 get_mirror_ids $file
4196 echo "mirror IDs: ${mirror_array[*]}"
4199 cmp $tmpfile $file || error "files don't match"
4200 get_mirror_ids $file
4201 echo "mirror IDs: ${mirror_array[*]}"
4203 # mirror creation should work fine
4204 $LFS mirror extend -N -S 8M -c -1 $file ||
4205 error "mirror extend $file failed"
4207 get_mirror_ids $file
4208 echo "mirror IDs: ${mirror_array[*]}"
4211 $LFS mirror verify -v $file || error "verification failed"
4212 cmp $tmpfile $file || error "files don't match"
4214 run_test 207 "create another replica with existing out-of-sync one"
4216 function check_ost_used() {
4225 cancel_lru_locks osc # to drop pages
4226 cancel_lru_locks mdc # to refresh layout
4227 # XXX: cancel_lru_locks mdc doesn't work
4228 # XXX: need a better way to reload the layout
4229 umount_client $MOUNT || error "umount failed"
4230 mount_client $MOUNT || error "mount failed"
4232 # refresh non-rotation status on MDTs
4234 touch $DIR/$tfile-temp
4235 rm -f $DIR/$tfile-temp
4236 # refresh non-rotational status on the client
4240 $LCTL set_param osc.*.stats=clear >/dev/null
4241 if [[ $io == "read" ]]; then
4242 ddarg="if=$file of=/dev/null"
4243 elif [[ $io == "write" ]]; then
4244 ddarg="if=/dev/zero of=$file"
4246 error "unknown type $io"
4248 dd $ddarg bs=8M count=1 || error "can't $io $file"
4249 cancel_lru_locks osc
4251 # check only specified OSTs got reads
4252 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4253 local nr=$($LCTL get_param -n \
4254 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4255 awk "/ost_$io/{print \$2}")
4257 if [[ " $* " =~ $ost ]]; then
4258 (( nr > 0 )) || error "expected reads on $ost"
4260 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4266 local tf=$DIR/$tfile
4267 local osts=$(comma_list $(osts_nodes))
4269 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4270 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4271 skip "Need MDS version at least 2.14.55"
4273 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4275 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4276 stack_trap "restore_lustre_params < $p; rm -f $p"
4278 stack_trap "rm -f $tf"
4279 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4280 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4281 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4282 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4283 $LFS mirror resync $tf || error "can't resync"
4286 log "set OST0000 non-rotational"
4288 $LCTL set_param osd*.*OST*.nonrotational=0
4290 $LCTL set_param osd*.*OST0000*.nonrotational=1
4291 check_ost_used $tf read 0
4293 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4295 $LCTL set_param osd*.*OST*.nonrotational=0
4297 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4298 osd*.*OST0003*.nonrotational=1
4299 check_ost_used $tf read 2 3
4301 log "set mirror 1 on OST0001 preferred"
4302 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4303 error "can't set prefer"
4304 check_ost_used $tf read 1
4306 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4309 local tf=$DIR/$tfile
4310 local osts=$(comma_list $(osts_nodes))
4312 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4313 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4314 skip "Need MDS version at least 2.14.55"
4316 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4318 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4319 stack_trap "restore_lustre_params < $p; rm -f $p"
4321 stack_trap "rm -f $tf"
4322 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4323 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4324 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4325 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4326 $LFS mirror resync $tf || error "can't resync"
4327 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4329 log "set OST0000 non-rotational"
4331 $LCTL set_param osd*.*OST*.nonrotational=0
4333 $LCTL set_param osd*.*OST0000*.nonrotational=1
4334 check_ost_used $tf write 0
4335 $LFS mirror resync $tf || error "can't resync"
4337 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4339 $LCTL set_param osd*.*OST*.nonrotational=0
4341 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4342 osd*.*OST0003*.nonrotational=1
4343 check_ost_used $tf write 2 3
4344 $LFS mirror resync $tf || error "can't resync"
4346 log "set mirror 1 on OST0001 preferred"
4347 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4348 error "can't set prefer"
4349 check_ost_used $tf write 1
4351 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4354 local tf=$DIR/$tfile
4355 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4356 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4357 local osts=$(comma_list $(osts_nodes))
4359 stack_trap "rm -f $tmpfile"
4361 mkdir -p $MOUNT2 && mount_client $MOUNT2
4362 stack_trap "umount_client $MOUNT2"
4364 # to make replica on ost1 preferred for new writes
4365 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4366 stack_trap "restore_lustre_params < $p; rm -f $p"
4368 $LCTL set_param osd*.*OST*.nonrotational=0
4370 $LCTL set_param osd*.*OST0001*.nonrotational=1
4372 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4374 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4375 log "replicated file created"
4377 cancel_lru_locks mdc
4378 cancel_lru_locks osc
4380 log "open(O_RDONLY) and first read from OST"
4381 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4384 log "first read complete"
4386 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4387 error "can't write BBBB"
4388 log "BBBB written which made replica on ost1 stale"
4390 log "fast read from pagecache in the original process"
4394 log "read via $DIR2 new open(2)"
4395 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4397 log "fast read from pagecache after 5s in the original process"
4402 local nr=$(grep "BBBB" $tmpfile | wc -l)
4408 log "read via new open(2)"
4409 $MULTIOP $tf vvoO_RDONLY:r4c
4411 run_test 209a "skip fast reads after layout invalidation"
4413 function sum_ost_reads() {
4414 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4415 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4419 local tf=$DIR/$tfile
4421 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4422 cancel_lru_locks osc
4423 echo "the very first read"
4424 cat $tf >/dev/null || error "can't read"
4426 # cancel layout lock
4427 cancel_lru_locks mdc
4429 # now read again, data must be in the cache, so no ost reads
4430 $LCTL set_param osc.*.stats=clear >/dev/null
4431 echo "read with warm cache"
4432 cat $tf >/dev/null || error "can't read"
4434 (( nr == 0 )) || error "reads with warm cache"
4436 # now verify we can catch reads at all
4437 cancel_lru_locks osc
4438 cat $tf >/dev/null || error "can't read"
4440 (( nr > 0 )) || error "no reads with cold cache"
4442 run_test 209b "pagecache can be used after LL cancellation"
4445 local tf=$DIR/$tfile
4447 stack_trap "rm -f $tf"
4448 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4449 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4450 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4451 $LFS mirror extend -N $tf || error "can't mirror"
4452 $LFS getstripe -v $tf
4453 stat $tf || error "can't stat"
4455 run_test 210a "handle broken mirrored lovea"
4458 local tf=$DIR/$tfile
4463 [ "$FSTYPE" != "zfs" ] || skip "ZFS file number is not accurate"
4465 stack_trap "rm -f $tf"
4467 # XXX: how to avoid precreate
4468 wait_delete_completed
4469 $LFS df -i | grep OST
4470 before=$($LFS df -i|grep OST|awk '{sum=sum+$3}END{print sum}')
4471 echo "before file creation: $before"
4472 $LFS setstripe -c 2 $tf || error "can't create file"
4473 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4475 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4476 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4477 $LFS mirror extend -N $tf || error "can't mirror"
4478 $LFS df -i | grep OST
4479 mirrored=$($LFS df -i|grep OST|awk '{sum=sum+$3}END{print sum}')
4480 echo "after mirror: $mirrored"
4482 rm $tf || error "can't remove"
4483 [[ -f $tf ]] && error "rm failed"
4484 wait_delete_completed
4486 $LFS df -i | grep OST
4487 after=$($LFS df -i|grep OST|awk '{sum=sum+$3}END{print sum}')
4488 echo "after rm: $after"
4489 (( after < before )) || error "something went wrong with unlink"
4491 run_test 210b "handle broken mirrored lovea (unlink)"
4493 complete_test $SECONDS
4494 check_and_cleanup_lustre