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 dd if=/dev/zero of=$tf bs=1M count=600 &
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"
1606 run_test 36c "change prefer mirror during write shouldn't hung"
1609 local tf=$DIR/$tfile
1611 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1612 skip "Need OST version at least 2.15.50"
1614 echo " ** create $tf"
1615 $LFS mirror create -N $tf || error "create $tf failed"
1618 echo " ** mirror extend $tf ($i/2)"
1619 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1620 flv=$(get_file_layout_version $tf)
1621 olv=$(get_ost_layout_version $tf)
1622 echo " flv=$flv olv=$olv"
1626 echo " ** write $tf ($i/2)"
1627 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1628 flv=$(get_file_layout_version $tf)
1629 olv=$(get_ost_layout_version $tf)
1630 echo " flv=$flv olv=$olv"
1632 error "write update OST layout failed $flv/$olv"
1635 echo " ** resync $tf"
1636 $LFS mirror resync $tf || error "mirror resync $tf failed"
1637 flv=$(get_file_layout_version $tf)
1638 olv=$(get_ost_layout_version $tf)
1639 echo " flv=$flv olv=$olv"
1642 echo " ** truncate $tf ($i/2)"
1643 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1644 flv=$(get_file_layout_version $tf)
1645 olv=$(get_ost_layout_version $tf)
1646 echo " flv=$flv olv=$olv"
1647 (( flv == olv || flv == olv + 1 )) ||
1648 error "truncate update OST layout failed $flv/$olv"
1651 echo " ** resync $tf"
1652 $LFS mirror resync $tf || error "mirror resync $tf failed"
1653 flv=$(get_file_layout_version $tf)
1654 olv=$(get_ost_layout_version $tf)
1655 echo " flv=$flv olv=$olv"
1658 echo " ** write $tf ($i/2)"
1659 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1660 flv=$(get_file_layout_version $tf)
1661 olv=$(get_ost_layout_version $tf)
1662 echo " flv=$flv olv=$olv"
1664 error "write update OST layout failed $flv/$olv"
1667 run_test 36d "write/punch FLR file update OST layout version"
1673 echo "create test files with size $fsize .."
1677 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1679 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1680 $TRUNCATE $tf $fsize
1686 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1687 skip "Need MDS version at least 2.11.57"
1689 local tf=$DIR/$tfile
1690 local tf2=$DIR/$tfile-2
1691 local tf3=$DIR/$tfile-3
1692 local tf4=$DIR/$tfile-4
1694 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1696 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1699 # assume the mirror id will be 1, 2, and 3
1700 declare -A checksums
1701 checksums[1]=$(cat $tf | md5sum)
1702 checksums[2]=$(cat $tf2 | md5sum)
1703 checksums[3]=$(cat $tf3 | md5sum)
1705 printf '%s\n' "${checksums[@]}"
1707 # merge these files into a mirrored file
1708 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1709 error "merging $tf2 into $tf failed"
1710 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1711 error "merging $tf3 into $tf failed"
1715 # verify mirror read, checksums should equal to the original files'
1716 echo "Verifying mirror read .."
1719 for i in "${mirror_array[@]}"; do
1720 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1721 sum=$($LFS mirror read -N $i $tf | md5sum)
1722 [ "$sum" = "${checksums[$i]}" ] ||
1723 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1726 # verify mirror write
1727 echo "Verifying mirror write .."
1728 $LFS mirror write -N2 $tf < $tf4
1730 sum=$($LFS mirror read -N2 $tf | md5sum)
1731 [[ "$sum" = "${checksums[1]}" ]] ||
1732 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1734 # verify mirror copy, write to this mirrored file will invalidate
1735 # the other two mirrors
1736 echo "Verifying mirror copy .."
1738 local osts=$(comma_list $(osts_nodes))
1740 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1741 error "mirror copy error"
1743 # verify copying is successful by checking checksums
1744 remount_client $MOUNT
1745 for i in "${mirror_array[@]}"; do
1746 sum=$($LFS mirror read -N $i $tf | md5sum)
1747 [ "$sum" = "${checksums[1]}" ] ||
1748 error "$i: mismatch checksum after copy \'$sum\'"
1753 run_test 37 "mirror I/O API verification"
1756 local tf=$DIR/$tfile
1757 local ref=$DIR/${tfile}-ref
1759 stack_trap "rm -f $tf $ref"
1761 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1762 error "creating $tf failed"
1763 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1764 $tf-2 || error "creating $tf-2 failed"
1765 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1766 error "creating $tf-3 failed"
1768 # instantiate all components
1769 $LFS mirror extend -N -f $tf-2 $tf ||
1770 error "merging $tf-2 into $tf failed"
1771 $LFS mirror extend -N -f $tf-3 $tf ||
1772 error "merging $tf-3 into $tf failed"
1773 $LFS mirror extend -N -c 1 $tf ||
1774 error "extending mirrored file $tf failed"
1776 verify_flr_state $tf "ro"
1778 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1780 local fsize=$((RANDOM << 8 + 1048576))
1781 $TRUNCATE $ref $fsize
1783 local ref_cksum=$(cat $ref | md5sum)
1785 # case 1: verify write to mirrored file & resync work
1786 cp $ref $tf || error "copy from $ref to $f error"
1787 verify_flr_state $tf "wp"
1789 local file_cksum=$(cat $tf | md5sum)
1790 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1793 echo "mirror IDs: ${mirror_array[*]}"
1795 local valid_mirror stale_mirror id mirror_cksum
1796 for id in "${mirror_array[@]}"; do
1797 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1798 [ "$ref_cksum" == "$mirror_cksum" ] &&
1799 { valid_mirror=$id; continue; }
1804 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1805 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1807 $LFS mirror resync $tf || error "resync failed"
1808 verify_flr_state $tf "ro"
1810 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1811 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1813 # case 2: inject an error to make mirror_io exit after changing
1814 # the file state to sync_pending so that we can start a concurrent
1816 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1817 verify_flr_state $tf "wp"
1819 mirror_io resync -e resync_start $tf && error "resync succeeded"
1820 verify_flr_state $tf "sp"
1822 # from sync_pending to write_pending
1823 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1824 verify_flr_state $tf "wp"
1826 mirror_io resync -e resync_start $tf && error "resync succeeded"
1827 verify_flr_state $tf "sp"
1829 # from sync_pending to read_only
1830 $LFS mirror resync $tf || error "resync failed"
1831 verify_flr_state $tf "ro"
1833 run_test 38 "resync"
1836 local tf=$DIR/$tfile
1839 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1840 error "create PFL file $tf failed"
1842 verify_mirror_count $tf 2
1843 verify_comp_count $tf 4
1845 rm -f $tf || error "delete $tf failed"
1847 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1850 local tf=$DIR/$tfile
1853 for ops in "conv=notrunc" ""; do
1856 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1857 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1858 error "create PFLR file $tf failed"
1859 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1860 error "write PFLR file $tf failed"
1862 lfs getstripe -vy $tf
1866 # file mirror state should be write_pending
1867 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1869 error "file mirror state $flags"
1870 # the 1st component (in mirror 1) should be inited
1871 verify_comp_attr lcme_flags $tf 0x10001 init
1872 # the 2nd component (in mirror 1) should be inited
1873 verify_comp_attr lcme_flags $tf 0x10002 init
1874 # the 3rd component (in mirror 1) should be uninited
1875 verify_comp_attr lcme_flags $tf 0x10003 prefer
1876 # the 4th component (in mirror 2) should be inited
1877 verify_comp_attr lcme_flags $tf 0x20004 init
1878 # the 5th component (in mirror 2) should be uninited
1879 verify_comp_attr lcme_flags $tf 0x20005 0
1880 # the 6th component (in mirror 2) should be stale
1881 verify_comp_attr lcme_flags $tf 0x20006 stale
1882 # the 7th component (in mirror 2) should be uninited
1883 if [[ x$ops = "xconv=notrunc" ]]; then
1884 verify_comp_attr lcme_flags $tf 0x20007 0
1885 elif [[ x$ops = "x" ]]; then
1886 verify_comp_attr lcme_flags $tf 0x20007 stale
1890 rm -f $tf || error "delete $tf failed"
1892 run_test 40 "PFLR rdonly state instantiation check"
1895 local tf=$DIR/$tfile
1897 stack_trap "rm -f $tf $tf-1"
1900 echo " **create two FLR files $tf $tf-1"
1901 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1902 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1903 error "create PFLR file $tf failed"
1904 $LFS mirror create -N -E 2M -S 1M -E eof \
1905 -N -E 1M -E eof --flags prefer \
1906 -N -E 4m -E eof $tf-1 ||
1907 error "create PFLR file $tf-1 failed"
1909 # file should be in ro status
1910 echo " **verify files be RDONLY"
1911 verify_flr_state $tf "ro"
1912 verify_flr_state $tf-1 "ro"
1914 # write data in [0, 2M)
1915 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1916 error "writing $tf failed"
1917 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1918 error "writing $tf-1 failed"
1920 local sum0=$(cat $tf-1 | md5sum)
1922 echo " **verify files be WRITE_PENDING"
1923 verify_flr_state $tf "wp"
1924 verify_flr_state $tf-1 "wp"
1926 # file should have stale component
1927 echo " **verify files have stale component"
1928 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1929 error "after writing $tf, it does not contain stale component"
1930 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1931 error "after writing $tf-1, it does not contain stale component"
1933 echo " **full resync"
1934 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1936 echo " **verify $tf-1 data consistency in all mirrors"
1938 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1939 [[ "$sum" = "$sum0" ]] ||
1940 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1943 echo " **verify files be RDONLY"
1944 verify_flr_state $tf "ro"
1945 verify_flr_state $tf-1 "ro"
1947 # file should not have stale component
1948 echo " **verify files do not contain stale component"
1949 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1950 error "after resyncing $tf, it contains stale component"
1951 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1952 error "after resyncing $tf, it contains stale component"
1954 # verify partial resync
1955 echo " **write $tf-1 for partial resync test"
1956 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1957 error "writing $tf-1 failed"
1959 echo " **only resync mirror 2"
1960 verify_flr_state $tf-1 "wp"
1961 $LFS mirror resync --only 2 $tf-1 ||
1962 error "resync mirror 2 of $tf-1 failed"
1963 verify_flr_state $tf "ro"
1965 # resync synced mirror
1966 echo " **resync mirror 2 again"
1967 $LFS mirror resync --only 2 $tf-1 ||
1968 error "resync mirror 2 of $tf-1 failed"
1969 verify_flr_state $tf "ro"
1970 echo " **verify $tf-1 contains stale component"
1971 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1972 error "after writing $tf-1, it does not contain stale component"
1974 echo " **full resync $tf-1"
1975 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1976 verify_flr_state $tf "ro"
1977 echo " **full resync $tf-1 again"
1978 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1979 echo " **verify $tf-1 does not contain stale component"
1980 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1981 error "after resyncing $tf, it contains stale component"
1985 run_test 41 "lfs mirror resync check"
1988 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1992 local mirror_cmd="$LFS mirror verify"
1995 stack_trap "rm -rf $td"
1997 # create parent directory
1998 mkdir $td || error "mkdir $td failed"
2000 $mirror_cmd &> /dev/null && error "no file name given"
2001 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
2002 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
2004 # create mirrored files
2005 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
2006 error "create mirrored file $tf failed"
2007 $LFS mirror create -N -E 2M -S 1M -E EOF \
2008 -N -E 6M -E 8M -E EOF \
2009 -N -E 16M -E EOF $tf-1 ||
2010 error "create mirrored file $tf-1 failed"
2011 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
2012 error "create mirrored file $tf-2 failed"
2014 # write data in [0, 10M)
2015 for i in $tf $tf-1 $tf-2; do
2016 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
2017 error "write $i failed"
2020 # resync the mirrored files
2021 $LFS mirror resync $tf-1 $tf-2 ||
2022 error "resync $tf-1 $tf-2 failed"
2024 # verify the mirrored files
2025 $mirror_cmd $tf-1 $tf-2 ||
2026 error "verify $tf-1 $tf-2 failed"
2028 get_mirror_ids $tf-1
2029 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2030 error "at least 2 mirror ids needed with '--only' option"
2031 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2033 error "'--only' option cannot be used upon multiple files"
2034 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2035 error "invalid specified mirror ids"
2037 # change the content of $tf and merge it into $tf-1
2039 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2040 error "change $tf with seek=$i failed"
2041 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2042 error "change $tf-1 with seek=$i failed"
2045 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2046 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2047 error "merge $tf into $tf-1 failed"
2049 # verify the mirrored files
2050 echo "Verify $tf-1 without -v option:"
2051 $mirror_cmd $tf-1 &&
2052 error "verify $tf-1 should fail" || echo "PASS"
2054 echo "Verify $tf-1 with -v option:"
2055 $mirror_cmd -v $tf-1 &&
2056 error "verify $tf-1 should fail"
2058 get_mirror_ids $tf-1
2059 echo "Verify $tf-1 with --only option:"
2060 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2061 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2062 "${mirror_array[-1]} should fail"
2064 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2065 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2066 "${mirror_array[1]} should succeed"
2068 # set stale components in $tf-1
2069 for i in 0x40002 0x40003; do
2070 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2071 error "set stale flag on component $i failed"
2074 # verify the mirrored file
2075 echo "Verify $tf-1 with stale components:"
2076 $mirror_cmd -vvv $tf-1 ||
2077 error "verify $tf-1 with stale components should succeed"
2079 echo "Verify $tf-1 with stale components and --only option:"
2080 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2081 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2082 "${mirror_array[-1]} should succeed"
2084 run_test 42 "lfs mirror verify"
2086 # inactivate one OST && write && restore the OST
2090 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2093 wait=$(do_facet $SINGLEMDS \
2094 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2095 wait=${wait%%[^0-9]*}
2097 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2098 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2099 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2100 sleep $(($wait * 2 + 2))
2101 echo " **write $file"
2102 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2103 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2104 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2105 sleep $((wait * 2 + 2))
2107 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2108 [ $flags = wp ] || error "file mirror state $flags != wp"
2112 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2114 local tf=$DIR/$tfile
2117 stack_trap "rm -f $tf"
2119 ## mirror 0 ost (0, 1)
2120 ## mirror 1 ost (1, 2)
2121 ## mirror 2 ost (2, 0)
2122 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2123 -N -Eeof -c2 -o2,0 $tf ||
2124 error "create 3 mirrors file $tf failed"
2126 ################## OST0 ###########################################
2128 echo " **verify components"
2129 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2130 verify_comp_attr lcme_flags $tf 0x20002 init
2131 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2134 echo " **resync $tf"
2135 $LFS mirror resync $tf
2136 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2137 [ $flags = ro ] || error "file mirror state $flags != ro"
2139 ################## OST1 ###########################################
2141 echo " **verify components"
2142 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2143 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2144 verify_comp_attr lcme_flags $tf 0x30003 init
2147 echo " **resync $tf"
2148 $LFS mirror resync $tf
2149 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2150 [ $flags = ro ] || error "file mirror state $flags != ro"
2152 ################## OST2 ###########################################
2154 echo " **verify components"
2155 verify_comp_attr lcme_flags $tf 0x10001 init
2156 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2157 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2159 run_test 43a "mirror pick on write"
2162 local tf=$DIR/$tdir/$tfile
2164 test_mkdir $DIR/$tdir
2166 stack_trap "rm -rf $tf"
2168 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2169 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2170 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2171 verify_flr_state $tf "ro"
2173 echo " ** write to $tf"
2174 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2175 verify_flr_state $tf "wp"
2177 echo " ** resync $tf"
2178 $LFS mirror resync $tf || error "resync $tf failed"
2179 verify_flr_state $tf "ro"
2181 run_test 43b "allow writing to multiple preferred mirror file"
2184 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2187 local tf=$DIR/$tdir/$tfile
2188 local tf1=$DIR/$tdir-1/$tfile-1
2190 stack_trap "rm -rf $tf $tf1"
2192 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2193 error "create directory failed"
2194 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2195 error "create remote directory failed"
2196 rm -f $tf $tf1 $tf.mirror~2
2197 # create file with 4 mirrors
2198 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2199 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2200 error "create PFLR file $tf failed"
2202 # file should be in ro status
2203 verify_flr_state $tf "ro"
2205 # write data in [0, 3M)
2206 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2207 error "writing $tf failed"
2209 verify_flr_state $tf "wp"
2211 # disallow destroying the last non-stale mirror
2212 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2213 error "destroying mirror 1 should fail"
2215 # synchronize all mirrors of the file
2216 $LFS mirror resync $tf || error "mirror resync $tf failed"
2218 verify_flr_state $tf "ro"
2221 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2222 error "split to $tf1 failed"
2224 local idx0=$($LFS getstripe -m $tf)
2225 local idx1=$($LFS getstripe -m $tf1)
2227 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2228 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2230 # verify mirror count
2231 verify_mirror_count $tf 3
2232 verify_mirror_count $tf1 1
2234 $LFS mirror split --mirror-id 2 $tf ||
2235 error "split mirror 2 failed"
2237 verify_mirror_count $tf 2
2238 verify_mirror_count $tf.mirror~2 1
2240 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2241 error "setting stale flag on component 0x30008 failed"
2243 # disallow destroying the last non-stale mirror
2244 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2245 error "destroying mirror 4 should fail"
2247 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2249 $LFS mirror split --mirror-id 3 -d $tf ||
2250 error "destroying mirror 3 failed"
2251 verify_mirror_count $tf 1
2253 # verify splitted file contains the same content as the orig file does
2254 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2255 diff $tf $tf.mirror~2 ||
2256 error "splited file $tf.mirror~2 diffs from $tf"
2258 run_test 44a "lfs mirror split check"
2261 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2262 skip "Need MDS version at least 2.14.56"
2265 local tf=$DIR/$tdir/$tfile
2267 mkdir -p $DIR/$tdir || error "create directory failed"
2271 # create 2 mirrors file
2272 $LFS mirror extend -N -c1 $tf
2276 verify_flr_state $tf "wp"
2278 local str=$(cat $tf)
2280 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2282 # get the non-stale mirror id
2283 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2285 local mirror_ids=($($LFS getstripe $tf |
2286 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2287 for ((i = 0; i < 2; i++)); do
2288 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2289 grep stale > /dev/null || break
2292 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2296 # split the updated mirror, should fail
2297 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2298 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2299 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2302 # split the stale mirror
2303 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2304 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2305 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2307 echo "make sure there's no stale comp in the file"
2308 # make sure there's no stale comp in the file
2309 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2310 ( $LFS getstripe $tf; error "stale mirror file" )
2313 [[ $str == "YYY" ]] ||
2314 ( cat $tf; error "$tf content is not YYY after split" )
2316 run_test 44b "mirror split does not create stale file"
2319 local tf=$DIR/$tdir/$tfile
2321 stack_trap "rm -f $tf"
2323 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2324 skip "Need MDS version at least 2.14.52"
2326 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2328 mkdir -p $DIR/$tdir || error "create directroy failed"
2330 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2332 block1=$(( $(stat -c "%b*%B" $tf) ))
2333 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2335 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2337 block2=$(( $(stat -c "%b*%B" $tf) ))
2338 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2340 $LFS mirror split -d --mirror-id=2 $tf ||
2341 error "mirror split $tfile failed"
2342 $LFS mirror split -d --mirror-id=3 $tf ||
2343 error "mirror split $tfile failed"
2346 block3=$(( $(stat -c "%b*%B" $tf) ))
2347 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2349 [[ $block1 -eq $block3 ]] ||
2350 error "mirror split does not reduce block# $block3 != $block1"
2352 run_test 44c "lfs mirror split reduces block size of a file"
2355 local tf=$DIR/$tdir/$tfile
2361 stack_trap "rm -f $tf"
2363 mkdir -p $DIR/$tdir || error "create directroy failed"
2365 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2367 size1=$(stat -c "%s" $tf)
2368 echo " ** before mirror ops, file size=$size1"
2370 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2372 size2=$(stat -c "%s" $tf)
2373 echo " ** after mirror extend, file size=$size2"
2375 (($size1 == $size2)) ||
2376 error "mirror extend should not change size, before: $size1, after $size2"
2378 $LFS mirror split -d --mirror-id=2 $tf ||
2379 error "mirror split $tfile failed"
2381 size2=$(stat -c "%s" $tf)
2382 echo " ** after mirror split, file size=$size2"
2383 (($size1 == $size2)) ||
2384 error "mirror split should not change size, before: $size1, after $size2"
2386 # Remount client to clear cached size information
2387 remount_client $MOUNT
2388 size2=$(stat -c "%s" $tf)
2389 echo " ** after mirror split & remount, file size=$size2"
2390 (($size1 == $size2)) ||
2391 error "mirror extend should not change size, before: $size1, after $size2"
2394 run_test 44d "lfs mirror split does not break size"
2397 local tf=$DIR/$tdir/$tfile
2398 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2402 test_mkdir $DIR/$tdir
2403 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2404 skip "Need MDS version at least 2.14.52"
2406 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2408 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2409 $LCTL set_param llite.*.xattr_cache=0
2410 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2411 stack_trap "rm -rf $tf"
2413 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2415 size1=$(stat -c "%s" $tf)
2416 echo " ** before mirror resync, file size=$size1"
2418 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2419 size1=$(stat -c "%s" $tf)
2420 size2=$($LFS getsom -s $tf)
2424 ((size1 == size2)) ||
2425 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2427 # Remount client to clear cached size information
2428 remount_client $MOUNT
2430 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2431 stack_trap "restore_lustre_params < $p; rm -f $p"
2432 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2434 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2436 size2=$(stat -c "%s" $tf)
2437 # 'getsom' here is just for debugging
2440 ((size2 == size1)) ||
2441 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2443 run_test 44e "basic FLR SOM tests + disable SOM"
2446 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2448 local file=$DIR/$tdir/$tfile
2449 local dir=$DIR/$tdir/$dir
2450 local temp=$DIR/$tdir/template
2452 test_mkdir $DIR/$tdir
2454 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2455 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2456 error "Create $file failed"
2458 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2459 rm -f $file $file.copy
2461 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2462 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2463 error "Create $file failed"
2465 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2467 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2474 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2476 local layout1=$(get_layout_param $src)
2477 local layout2=$(get_layout_param $dst)
2478 # compare their layout info
2479 [ "$layout1" == "$layout2" ] ||
2480 error "$msg_prefix $src <=> $dst layouts are not equal"
2484 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2486 local file=$DIR/$tdir/$tfile
2487 test_mkdir $DIR/$tdir
2489 ########################### 1. PFL file #############################
2490 echo " ** 1. PFL file"
2492 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2493 $file || error "1. Create PFL $file failed"
2496 verify_46 $file $file.copy "1. PFL file"
2498 ########################### 2. plain file ###########################
2499 echo " ** 2. plain file"
2501 $LFS setstripe -c2 -o0,1 -i1 $file ||
2502 error "2. Create plain $file failed"
2505 verify_46 $file $file.copy "2. plain file"
2507 ########################### 3. FLR file #############################
2508 echo " ** 3. FLR file"
2510 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2511 $file || error "3. Create FLR $file failed"
2514 verify_46 $file $file.copy "3. FLR file"
2516 local dir=$DIR/$tdir/dir
2517 ########################### 4. PFL dir ##############################
2518 echo " ** 4. PFL dir"
2520 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2521 error "4. setstripe PFL $dir failed"
2523 test_mkdir $dir.copy
2524 verify_46 $dir $dir.copy "4. PFL dir"
2526 ########################### 5. plain dir ############################
2527 echo " ** 5. plain dir"
2528 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2530 verify_46 $dir $dir.copy "5. plain dir"
2532 ########################### 6. FLR dir ##############################
2533 echo " ** 6. FLR dir"
2534 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2535 error "6. setstripe FLR $dir failed"
2537 verify_46 $dir $dir.copy "6. FLR dir"
2539 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2540 echo "server version $MDS1_VERSION does not support SEL" &&
2543 ########################### 7. SEL file ##############################
2544 echo " ** 7. SEL file"
2546 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2547 $file || error "Create $file failed"
2550 verify_46 $file $file.copy "7. SEL file"
2552 ########################### 8. SEL dir ##############################
2553 echo " ** 8. SEL dir"
2554 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2555 $dir || error "setstripe $dir failed"
2557 verify_46 $dir $dir.copy "8. SEL dir"
2559 ########################### 9. FLR SEL file ##########################
2560 echo " ** 9. FLR SEL file"
2562 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2563 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2566 verify_46 $file $file.copy "9. SEL file"
2568 ########################### 10. FLR SEL dir #########################
2569 echo " ** 10. FLR SEL dir"
2570 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2571 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2573 verify_46 $dir $dir.copy "10. SEL dir"
2575 run_test 46 "Verify setstripe --copy option"
2578 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2580 local file=$DIR/$tdir/$tfile
2585 test_mkdir $DIR/$tdir
2586 stack_trap "rm -f $file"
2590 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2591 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2592 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2593 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2594 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2596 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2597 $LFS mirror resync $file || error "resync $file failed"
2599 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2600 if [[ x$ost == "x0," ]]; then
2601 $LFS getstripe $file
2602 error "component ${ids[2]} objects allocated on $ost " \
2606 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2607 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2608 $LFS getstripe $file
2609 error "component ${ids[3]} objects allocated on $ost " \
2610 "shouldn't on OST1 or on OST2"
2615 # mirror1: [comp0] [comp1]
2616 # mirror2: [comp2] [comp3]
2617 # mirror3: [comp4] [comp5]
2618 # mirror4: [comp6] [comp7]
2619 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2620 error "create FLR $file failed"
2621 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2623 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2624 $LFS mirror resync $file || error "resync $file failed"
2626 for ((i = 0; i < 6; i++)); do
2627 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2628 awk '/l_ost_idx/{print $5}')
2630 # comp[0],comp[2],comp[4] should use different osts
2631 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2632 ${osts[2]} == ${osts[4]} ]]; then
2633 $LFS getstripe $file
2634 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2635 "allocated on duplicated OSTs"
2637 # comp[1],comp[3],comp[5] should use different osts
2638 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2639 ${osts[3]} == ${osts[5]} ]]; then
2640 $LFS getstripe $file
2641 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2642 "allocated on duplicated OSTs"
2647 run_test 47 "Verify mirror obj alloc"
2650 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2651 skip "Need MDS version at least 2.11.55"
2653 local tf=$DIR/$tfile
2655 stack_trap "rm -f $tf"
2657 echo " ** create 2 mirrors FLR file $tf"
2658 $LFS mirror create -N -E2M -Eeof --flags prefer \
2659 -N -E1M -Eeof $tf ||
2660 error "create FLR file $tf failed"
2663 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2664 verify_flr_state $tf "wp"
2666 local sum0=$(md5sum < $tf)
2668 echo " ** resync the file"
2669 $LFS mirror resync $tf
2671 echo " ** snapshot mirror 2"
2672 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2674 echo " ** write it again"
2675 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2676 echo " ** resync it again"
2677 $LFS mirror resync $tf
2679 verify_flr_state $tf "wp"
2680 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2682 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2683 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2685 echo " ** verify mirror 2 doesn't change"
2686 echo "original checksum: $sum0"
2687 echo "mirror 1 checksum: $sum1"
2688 echo "mirror 2 checksum: $sum2"
2689 [[ $sum0 = $sum2 ]] ||
2690 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2691 echo " ** mirror 2 stripe info"
2692 $LFS getstripe -v --mirror-index=2 $tf
2694 echo " ** resync mirror 2"
2695 $LFS mirror resync --only 2 $tf
2697 verify_flr_state $tf "ro"
2698 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2700 sum1=$($LFS mirror read -N1 $tf | md5sum)
2701 sum2=$($LFS mirror read -N2 $tf | md5sum)
2703 echo " ** verify mirror 2 resync-ed"
2704 echo "original checksum: $sum0"
2705 echo "mirror 1 checksum: $sum1"
2706 echo "mirror 2 checksum: $sum2"
2707 [[ $sum1 = $sum2 ]] ||
2708 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2709 echo " ** mirror 2 stripe info"
2710 $LFS getstripe -v --mirror-index=2 $tf
2712 run_test 48 "Verify snapshot mirror"
2721 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2722 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2723 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2724 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2725 skip "LU-1941: FIEMAP unimplemented on ZFS"
2727 trap cleanup_49 EXIT RETURN
2729 local file=$DIR/$tfile
2731 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2732 error "setstripe on $file"
2733 stack_trap "rm -f $file"
2735 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2736 $LFS mirror resync $file
2738 filefrag -ves $file || error "filefrag $file failed"
2739 filefrag_op=$(filefrag -ve -k $file |
2740 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2742 #Filesystem type is: bd00bd0
2743 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2744 # ext: device_logical: physical_offset: length: dev: flags:
2745 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2746 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2747 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2749 last_lun=$(echo $filefrag_op | cut -d: -f5)
2753 for line in $filefrag_op; do
2754 frag_lun=$(echo $line | cut -d: -f5)
2755 ext_len=$(echo $line | cut -d: -f4)
2756 if [[ "$frag_lun" != "$last_lun" ]]; then
2757 if (( tot_len != 1024 )); then
2759 error "$file: OST$last_lun $tot_len != 1024"
2765 (( tot_len += ext_len ))
2768 if (( num_luns != 2 || tot_len != 1024 )); then
2770 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2773 echo "FIEMAP on $file succeeded"
2775 run_test 49a "FIEMAP upon FLR file"
2777 test_50A() { # EX-2179
2780 local file=$DIR/$tdir/$tfile
2782 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2784 $LFS mirror extend -N -c1 -i1 $file ||
2785 error "extending mirror for $file failed"
2787 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2791 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2793 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2795 echo "$file layout generation from $olv to $flv"
2796 (( $flv != ($olv + 1) )) &&
2797 error "split does not increase layout gen from $olv to $flv"
2799 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2801 $LFS getstripe -v $file || error "getstripe $file failed"
2803 run_test 50A "mirror split update layout generation"
2806 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2807 skip "OST does not support SEEK_HOLE"
2808 [ "$FSTYPE" != "zfs" ] ||
2809 skip "lseek for ZFS is not accurate if obj is not committed"
2811 local file=$DIR/$tdir/$tfile
2819 echo " ** create striped file $file"
2820 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2821 error "cannot create file with PFL layout"
2822 echo " ** write 1st data chunk at 1M boundary"
2823 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2824 error "cannot write data at 1M boundary"
2825 echo " ** write 2nd data chunk at 2M boundary"
2826 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2827 error "cannot write data at 2M boundary"
2828 echo " ** create hole at the file end"
2829 $TRUNCATE $file 3700000 || error "truncate fails"
2831 echo " ** verify sparseness"
2832 offset=$(lseek_test -d 1000 $file)
2833 echo " first data offset: $offset"
2834 [[ $offset == 1000 ]] &&
2835 error "src: data is not expected at offset $offset"
2836 offset=$(lseek_test -l 3500000 $file)
2837 echo " hole at the end: $offset"
2838 [[ $offset == 3500000 ]] ||
2839 error "src: hole is expected at offset $offset"
2841 echo " ** extend the file with new mirror"
2842 # migrate_copy_data() is used
2843 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2844 error "cannot create mirror"
2845 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2846 error "$file still has stale component"
2848 # check migrate_data_copy() was correct
2849 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2850 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2851 [[ $sum_1 == $sum_2 ]] ||
2852 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2854 # stale first mirror
2855 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2856 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2858 echo " ** verify mirror #2 sparseness"
2859 offset=$(lseek_test -d 1000 $file)
2860 echo " first data offset: $offset"
2861 [[ $offset == 1000 ]] &&
2862 error "dst: data is not expected at offset $offset"
2863 offset=$(lseek_test -l 3500000 $file)
2864 echo " hole at the end: $offset"
2865 [[ $offset == 3500000 ]] ||
2866 error "dst: hole is expected at offset $offset"
2868 echo " ** copy mirror #2 to mirror #1"
2869 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2870 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2871 error "$file still has stale component"
2873 # check llapi_mirror_copy_many correctness
2874 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2875 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2876 [[ $sum_1 == $sum_2 ]] ||
2877 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2879 # stale 1st component of mirror #2 before lseek call
2880 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2882 echo " ** verify mirror #1 sparseness again"
2883 offset=$(lseek_test -d 1000 $file)
2884 echo " first data offset: $offset"
2885 [[ $offset == 1000 ]] &&
2886 error "dst: data is not expected at offset $offset"
2887 offset=$(lseek_test -l 3500000 $file)
2888 echo " hole at the end: $offset"
2889 [[ $offset == 3500000 ]] ||
2890 error "dst: hole is expected at offset $offset"
2892 cancel_lru_locks osc
2894 blocks=$(stat -c%b $file)
2895 echo " ** final consumed blocks: $blocks"
2896 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2897 # that file is still sparse
2898 (( blocks < 1000 )) ||
2899 error "Mirrored file consumes $blocks blocks"
2901 run_test 50a "mirror extend/copy preserves sparseness"
2904 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2905 skip "OST does not support SEEK_HOLE"
2906 [ "$FSTYPE" != "zfs" ] ||
2907 skip "lseek for ZFS is not accurate if obj is not committed"
2909 local file=$DIR/$tdir/$tfile
2916 stack_trap "rm -f $file"
2918 echo " ** create mirrored file $file"
2919 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2920 -N -E2M -S1M -E eof -S2M $file ||
2921 error "cannot create mirrored file"
2922 echo " ** write data chunk at 1M boundary"
2923 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2924 error "cannot write data at 1M boundary"
2925 echo " ** create hole at the file end"
2926 $TRUNCATE $file 3700000 || error "truncate fails"
2928 echo " ** verify sparseness"
2929 offset=$(lseek_test -d 1000 $file)
2930 echo " first data offset: $offset"
2931 [[ $offset == 1000 ]] &&
2932 error "src: data is not expected at offset $offset"
2933 offset=$(lseek_test -l 3500000 $file)
2934 echo " hole at the end: $offset"
2935 [[ $offset == 3500000 ]] ||
2936 error "src: hole is expected at 3500000"
2938 echo " ** resync mirror #2 to mirror #1"
2939 $LFS mirror resync $file
2941 # check llapi_mirror_copy_many correctness
2942 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2943 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2944 [[ $sum_1 == $sum_2 ]] ||
2945 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2947 cancel_lru_locks osc
2949 blocks=$(stat -c%b $file)
2950 echo " ** consumed blocks: $blocks"
2951 # without full punch() support the first component can be not sparse
2952 # but the last one should be, so file should use far fewer blocks
2953 (( blocks < 5000 )) ||
2954 error "Mirrored file consumes $blocks blocks"
2956 # stale first component in mirror #1
2957 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2958 echo " ** truncate file down"
2960 echo " ** write data chunk at 2M boundary"
2961 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2962 error "cannot write data at 2M boundary"
2963 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2964 $LFS mirror resync $file || error "mirror rsync fails"
2965 # first component is still stale
2966 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2967 error "$file still has no stale component"
2968 echo " ** resync mirror #2 to mirror #1 again"
2969 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2970 $LFS mirror resync $file || error "mirror rsync fails"
2971 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2972 error "$file still has stale component"
2974 # check llapi_mirror_copy_many correctness
2975 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2976 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2977 [[ $sum_1 == $sum_2 ]] ||
2978 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2980 cancel_lru_locks osc
2982 blocks=$(stat -c%b $file)
2983 echo " ** final consumed blocks: $blocks"
2984 # while the first component can lose sparseness, the last one should
2985 # not, so whole file should still use far fewer blocks in total
2986 (( blocks < 3000 )) ||
2987 error "Mirrored file consumes $blocks blocks"
2989 run_test 50b "mirror rsync handles sparseness"
2992 local tf=$DIR/$tdir/$tfile
2994 test_mkdir $DIR/$tdir
2996 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
2997 verify_flr_state $tf "ro"
2999 if [[ "$FSTYPE" == "ldiskfs" ]]; then
3000 # ZFS does not support fallocate for now
3001 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
3002 skip_eopnotsupp "$out|punch hole in $tf failed"
3003 verify_flr_state $tf "wp"
3006 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
3007 $LFS mirror resync $tf || error "mirror resync $tf failed"
3008 verify_flr_state $tf "ro"
3010 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
3011 verify_flr_state $tf "wp"
3013 run_test 50c "punch_hole/mmap_write stale other mirrors"
3016 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3017 skip "OST does not support SEEK_HOLE"
3018 [ "$FSTYPE" != "zfs" ] ||
3019 skip "lseek for ZFS is not accurate if obj is not committed"
3021 local file=$DIR/$tdir/$tfile
3028 echo " ** create mirrored file $file"
3029 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3030 -N -E2M -S1M -E eof -S2M $file ||
3031 error "cannot create mirrored file"
3032 echo " ** write data chunk at 1M boundary"
3033 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3034 error "cannot write data at 1M boundary"
3035 echo " ** create hole at the file start"
3036 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3039 if [[ $rc -eq 0 ]]; then
3040 verify_flr_state $file "wp"
3041 elif [[ ! $prt =~ unsupported ]]; then
3042 error "punch hole in $file failed: $prt"
3044 skip "Fallocate punch is not supported: $prt"
3047 echo " ** verify sparseness"
3048 offset=$(lseek_test -d 1000 $file)
3049 echo " first data offset: $offset"
3050 (( $offset >= 1024 * 1024 )) ||
3051 error "src: data is not expected at offset $offset"
3053 echo " ** resync mirror #2"
3054 $LFS mirror resync $file
3056 # check llapi_mirror_copy_many correctness
3057 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3058 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3059 [[ $sum_1 == $sum_2 ]] ||
3060 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3062 cancel_lru_locks osc
3064 # stale first component in mirror #1
3065 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3066 echo " ** verify sparseness of mirror #2"
3067 offset=$(lseek_test -d 1000 $file)
3068 echo " first data offset: $offset"
3069 (( $offset >= 1024 * 1024 )) ||
3070 error "src: data is not expected at offset $offset"
3072 run_test 50d "mirror rsync keep holes"
3075 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3076 skip "OST does not support SEEK_HOLE"
3078 local file=$DIR/$tdir/$tfile
3079 local old_size=2147483648 # 2GiB
3083 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3084 $TRUNCATE $file $old_size
3086 $LFS mirror extend -N -c 1 $file
3087 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3088 $LFS mirror resync $file
3090 new_size=$(stat --format='%s' $file)
3091 if ((new_size != old_size)); then
3092 error "new_size ($new_size) is not equal to old_size ($old_size)"
3095 run_test 60a "mirror extend sets correct size on sparse file"
3097 get_flr_layout_gen() {
3098 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3099 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3102 check_layout_gen() {
3105 local v1=$(get_flr_layout_gen $tf)
3106 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3108 [[ $v1 -eq $v2 ]] ||
3109 error "$tf in-memory layout gen $v1 != $v2 after $2"
3113 local tf=$DIR/$tdir/$tfile
3115 test_mkdir $DIR/$tdir
3117 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3119 for ((i = 0; i < 20; i++)); do
3120 $LFS mirror extend -N $tf ||
3121 error "extending mirror for $tf failed"
3122 check_layout_gen $tf "extend"
3124 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3125 error "split $tf failed"
3126 check_layout_gen $tf "split"
3129 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3132 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3137 local -a old=( $2 $3 $4 )
3140 new=( $(get_times_61 $file) )
3141 ((${old[0]} == ${new[0]})) ||
3142 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3144 ((${old[1]} == ${new[1]})) ||
3145 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3148 test_61a() { # LU-14508
3149 local file=$DIR/$tdir/$tfile
3155 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3156 echo "create $file-2"
3157 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3159 echo XXX > $file || error "write $file failed"
3160 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3162 echo "sleep $nap seconds, then cat $tfile"
3164 cat $file || error "cat $file failed"
3166 echo "sleep $nap seconds, then re-write $tfile"
3168 echo XXXX > $file || error "write $file failed"
3169 cp -p $file $file-2 || error "copy $file-2 failed"
3171 echo "sleep $nap seconds"
3174 tim=( $(get_times_61 $file) )
3176 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3177 $LFS mirror extend -N -f $file-2 $file ||
3178 error "cannot mirror merge $file-2 to $file"
3179 check_times_61 $file "${tim[@]}"
3181 echo "mirror extend $tfile and test timestamps"
3182 $LFS mirror extend -N -c1 -i1 $file ||
3183 error "cannot extend mirror $file"
3184 check_times_61 $file "${tim[@]}"
3186 echo "migrate $tfile and test timestamps"
3187 $LFS migrate -n $file || error "cannot migrate $file"
3188 check_times_61 $file "${tim[@]}"
3190 echo "normal user migrate $tfile and test timestamps"
3191 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3192 check_times_61 $file "${tim[@]}"
3194 run_test 61a "mirror extend and migrate preserve timestamps"
3196 test_61b() { # LU-14508
3197 local file=$DIR/$tdir/$tfile
3203 echo XXX > $file || error "create $file failed"
3204 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3206 echo "sleep $nap seconds, then cat $tfile"
3208 cat $file || error "cat $file failed"
3210 echo "sleep $nap seconds, then re-write $tfile"
3212 echo XXXX > $file || error "write $file failed"
3214 echo "sleep $nap seconds, then test timestamps"
3217 tim=( $(get_times_61 $file) )
3219 echo "mirror extend $tfile and test timestamps"
3220 $LFS mirror extend -N -c1 -i1 $file ||
3221 error "cannot extend mirror $file"
3222 check_times_61 $file "${tim[@]}"
3224 echo "mirror split $tfile and test timestamps"
3225 $LFS mirror split -d --mirror-id=1 $file ||
3226 error "cannot split mirror 1 off $file"
3227 check_times_61 $file "${tim[@]}"
3229 echo "normal user mirror extend $tfile and test timestamps"
3230 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3231 error "cannot extend mirror $file"
3232 check_times_61 $file "${tim[@]}"
3234 run_test 61b "mirror extend and split preserve timestamps"
3236 test_61c() { # LU-14508
3237 local file=$DIR/$tdir/$tfile
3243 echo XXX > $file || error "create $file failed"
3244 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3246 echo "sleep $nap seconds, then cat $tfile"
3248 cat $file || error "cat $file failed"
3250 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3252 $LFS mirror extend -N -c1 -i1 $file ||
3253 error "cannot extend mirror $file"
3254 echo XXXX > $file || error "write $file failed"
3256 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3257 tim=( $(get_times_61 $file) )
3259 $LFS mirror resync $file || error "cannot resync mirror $file"
3260 check_times_61 $file "${tim[@]}"
3262 echo XXXXXX > $file || error "write $tfile failed"
3264 echo "normal user resync $tfile and test timestamps"
3265 tim=( $(get_times_61 $file) )
3266 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3267 check_times_61 $file "${tim[@]}"
3269 run_test 61c "mirror resync preserves timestamps"
3272 local file=$DIR/$tdir/$tfile
3276 echo "create mirror file with unknown magic"
3277 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3278 # mirror 2 in-memory magic is bad
3279 $LCTL set_param fail_loc=0x1426 fail_val=2
3280 $LFS setstripe -N --flags=prefer -N2 $file ||
3281 error "failed to create mirror file $file"
3282 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3283 [[ $magic == 0x0BAD0BD0 ]] ||
3284 error "mirror 2 magic $magic is not bad as expected"
3285 cat /etc/passwd > $file || error "cannot write to $file"
3286 diff /etc/passwd $file || error "read $file error"
3290 echo "create mirror file with unknown pattern"
3291 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3292 # mirror 1 in-memory pattern is bad
3293 $LCTL set_param fail_loc=0x1427 fail_val=1
3294 $LFS setstripe -N -N --flags=prefer $file ||
3295 error "failed to create mirror file $file"
3296 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3297 [[ $pattern == 502 ]] ||
3298 error "mirror 1 pattern $pattern is not bad as expected"
3299 cat /etc/passwd > $file || error "cannot write to $file"
3300 diff /etc/passwd $file || error "read $file error"
3302 run_test 62 "read/write with unknown type of mirror"
3305 local tf=$DIR/$tdir/$tfile
3307 test_mkdir $DIR/$tdir
3308 stack_trap "rm -f $tf"
3312 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3316 echo "mirror create pid $c_pid"
3319 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3322 echo "mirror split pid $s_pid"
3324 echo "mirror create and split race for 60 seconds, should not crash"
3326 kill -9 $c_pid &> /dev/null
3327 kill -9 $s_pid &> /dev/null
3331 run_test 70 "mirror create and split race"
3334 local tf=$DIR/$tdir/$tfile
3336 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3337 skip "Need OST version at least 2.14.51"
3340 test_mkdir $DIR/$tdir
3341 stack_trap "rm -f $tf"
3343 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3344 error "setstripe $tf failed"
3346 FSXNUM=${FSXNUM:-1000}
3347 $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3349 run_test 70a "flr mode fsx test"
3354 local fsize=$(stat --printf=%s $tf)
3356 while [ -f $ctrl_file ]; do
3357 local off=$((RANDOM << 8))
3358 local len=$((RANDOM << 5 + 131072))
3360 [ $((off + len)) -gt $fsize ] && {
3361 fsize=$((off + len))
3362 echo "Extending file size to $fsize .."
3365 flock -s $lock_file -c \
3366 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3368 error "failed writing to $off:$len"; }
3369 sleep 0.$((RANDOM % 2 + 1))
3376 while [ -f $ctrl_file ]; do
3377 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3378 { rm -f $ctrl_file; error "read failed"; }
3379 sleep 0.$((RANDOM % 2 + 1))
3386 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3388 exec 200<>$lock_file
3389 while [ -f $ctrl_file ]; do
3390 local lock_taken=false
3391 local index=$((RANDOM % ${#options[@]}))
3392 local cmd="mirror_io resync ${options[$index]}"
3394 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3396 [ $((RANDOM % 4)) -eq 0 ] && {
3402 echo -n "resync file $tf with '$cmd' .."
3404 if [[ $lock_taken = "true" ]]; then
3406 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3409 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3412 sleep 0.$((RANDOM % 8 + 1))
3416 # this was test_200 before adding "b" and "c" subtests
3418 local tf=$DIR/$tfile
3419 local tf2=$DIR2/$tfile
3420 local tf3=$DIR3/$tfile
3422 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3423 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3424 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3426 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3427 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3428 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3430 $LFS mirror extend -N -f $tf-2 $tf ||
3431 error "merging $tf-2 into $tf failed"
3432 $LFS mirror extend -N -f $tf-3 $tf ||
3433 error "merging $tf-3 into $tf failed"
3435 mkdir -p $MOUNT2 && mount_client $MOUNT2
3437 mkdir -p $MOUNT3 && mount_client $MOUNT3
3439 verify_flr_state $tf3 "ro"
3441 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3442 $LCTL set_param fail_loc=0x1A03
3444 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3445 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3449 write_file_200 $tf &
3455 write_file_200 $tf2 &
3458 read_file_200 $tf2 &
3461 resync_file_200 $tf3 &
3465 [ "$SLOW" = "yes" ] && sleep_time=360
3466 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3473 echo "Waiting ${pids[*]}"
3476 umount_client $MOUNT2
3477 umount_client $MOUNT3
3479 # resync and verify mirrors
3480 $LFS mirror resync $tf || error "final resync failed"
3483 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3485 for id in "${mirror_array[@]:1}"; do
3486 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3487 error "checksum error for mirror $id"
3492 run_test 200a "stress test"
3495 local tf=$DIR/$tfile
3496 local tf2=$DIR2/$tfile
3497 local tf3=$DIR3/$tfile
3499 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3500 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3501 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3503 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3504 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3505 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3507 $LFS mirror extend -N -f $tf-2 $tf ||
3508 error "merging $tf-2 into $tf failed"
3509 $LFS mirror extend -N -f $tf-3 $tf ||
3510 error "merging $tf-3 into $tf failed"
3512 mkdir -p $MOUNT2 && mount_client $MOUNT2
3514 mkdir -p $MOUNT3 && mount_client $MOUNT3
3516 verify_flr_state $tf3 "ro"
3518 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3519 $LCTL set_param fail_loc=0x1423
3523 write_file_200 $tf &
3529 write_file_200 $tf2 &
3532 read_file_200 $tf2 &
3535 resync_file_200 $tf3 &
3539 [ "$SLOW" = "yes" ] && sleep_time=400
3543 echo "Waiting ${pids[@]}"
3546 umount_client $MOUNT2
3547 umount_client $MOUNT3
3549 # resync and verify mirrors
3550 $LFS mirror resync $tf || {
3552 error "final resync failed"
3556 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3557 for id in ${mirror_array[@]:1}; do
3558 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3559 error "checksum error for mirror $id"
3564 run_test 200b "racing IO, mirror extend and resync"
3567 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3568 skip "Need MDS version at least 2.15.53"
3570 local tf=$DIR/$tfile
3571 local tf2=$DIR2/$tfile
3573 mkdir -p $MOUNT2 && mount_client $MOUNT2
3574 stack_trap "umount_client $MOUNT2"
3575 stack_trap "rm -f $tf"
3579 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3581 mdt_idx=$($LFS getstripe -m $tf)
3583 cancel_lru_locks mdc
3584 cancel_lru_locks osc
3586 # start a process modifying file, block it just
3587 # before layout lock acquisition
3588 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3589 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3590 #log "dd to stale replica"
3591 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3597 $LFS mirror extend -N -c -1 $tf2 || {
3599 error "can't mirror"
3601 log "mirror extend done"
3602 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3604 # wait for blocking dd to complete and modify file
3605 wait $PID || error "2nd dd failed"
3608 verify_mirror_count $tf 2
3610 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3613 error "both replicas are still in sync"
3616 $LFS mirror verify -vvv $tf || {
3618 error "corrupted in-sync file"
3621 run_test 200c "layout change racing with open: LOVEA changes"
3623 cleanup_test_201() {
3624 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3626 umount_client $MOUNT2
3630 local delay=${RESYNC_DELAY:-5}
3632 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3633 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3635 stack_trap cleanup_test_201 EXIT
3637 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3638 changelog_register -n)
3640 mkdir -p $MOUNT2 && mount_client $MOUNT2
3644 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3645 [ -z "$log" ] && { sleep 1; continue; }
3647 index=$(echo $log | awk '{print $1}')
3648 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3649 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3650 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3653 [ -z "$file" ] && continue
3655 local now=$(date +%s)
3657 echo "file: $file $fid was modified at $ts, now: $now, " \
3658 "will be resynced at $((ts+delay))"
3660 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3662 $LFS mirror resync $file
3663 echo "$file resync done"
3666 run_test 201 "FLR data mover"
3669 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3671 local tf=$DIR/$tfile
3674 $LFS setstripe -E 1M -S 1M -c 1 $tf
3675 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3676 verify_comp_attr stripe-count $tf ${ids[0]} 1
3678 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3679 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3680 verify_comp_attr stripe-count $tf ${ids[0]} 1
3681 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3683 dd if=/dev/zero of=$tf bs=1M count=2
3684 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3685 verify_comp_attr stripe-count $tf ${ids[0]} 1
3686 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3688 run_test 202 "lfs setstripe --add-component wide striping"
3691 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3692 skip "Need MDS version at least 2.11.55"
3693 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3695 local tf=$DIR/$tfile
3698 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3699 #delete first mirror
3700 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3703 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3704 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3705 error "getstripe count of mirror 2"
3706 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3708 #extend a mirror with 2 OSTs
3709 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3712 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3713 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3714 error "getstripe count of mirror 2"
3715 [[ x$old_id = x$new_id ]] ||
3716 error "mirror 2 changed ID from $old_id to $new_id"
3717 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3719 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3720 error "getstripe count of mirror 3"
3721 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3723 run_test 203 "mirror file preserve mirror ID"
3725 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3727 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3728 skip "skipped for lustre < $SEL_VER"
3730 local comp_file=$DIR/$tdir/$tfile
3734 test_mkdir $DIR/$tdir
3735 stack_trap "rm -f $comp_file"
3737 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3738 # by extension space to -1
3739 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3740 error "Create $comp_file failed"
3742 # Write to first component, extending & staling second mirror
3743 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3744 error "dd to extend + stale failed"
3746 $LFS getstripe $comp_file
3748 flg_opts="--component-flags init,stale"
3749 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3750 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3752 flg_opts="--component-flags extension"
3753 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3754 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3756 # mirror resync should not change the extents
3757 $LFS mirror resync $comp_file
3759 flg_opts="--component-flags init"
3760 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3761 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3763 flg_opts="--component-flags extension"
3764 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3765 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3767 sel_layout_sanity $comp_file 5
3769 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3771 # Simple test of FLR + self-extending layout, SEL in primary mirror
3773 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3774 skip "skipped for lustre < $SEL_VER"
3776 local comp_file=$DIR/$tdir/$tfile
3780 test_mkdir $DIR/$tdir
3781 stack_trap "rm -f $comp_file"
3783 # first mirror is 1M followed by extension space to -1, second mirror
3784 # is 0-10M, then 10M-(-1),
3785 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3786 error "Create $comp_file failed"
3788 # Write to first component, extending first component & staling
3790 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3791 error "dd to extend + stale failed"
3793 $LFS getstripe $comp_file
3795 flg_opts="--component-flags init"
3796 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3797 [ $found -eq 1 ] || error "write: First comp end incorrect"
3799 flg_opts="--component-flags extension"
3800 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3801 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3803 flg_opts="--component-flags init,stale"
3804 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3805 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3807 # This component is staled because it overlaps the extended first
3808 # component of the primary mirror, even though it doesn't overlap
3809 # the actual write - thus not inited.
3810 flg_opts="--component-flags stale"
3811 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3812 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3814 # mirror resync should not change the extents
3815 $LFS mirror resync $comp_file
3817 $LFS getstripe $comp_file
3819 flg_opts="--component-flags init"
3820 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3821 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3823 flg_opts="--component-flags extension"
3824 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3825 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3827 flg_opts="--component-flags init"
3828 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3829 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3831 flg_opts="--component-flags init"
3832 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3833 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3835 sel_layout_sanity $comp_file 5
3837 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3839 # FLR + SEL failed extension & component removal
3840 # extension space in second mirror
3842 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3843 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3844 skip "skipped for lustre < $SEL_VER"
3846 local comp_file=$DIR/$tdir/$tfile
3849 local ost_name=$(ostname_from_index $ost_idx1)
3851 test_mkdir $DIR/$tdir
3852 stack_trap "rm -f $comp_file"
3854 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3855 # extension space from 1M to 1G, then normal space to -1
3856 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3857 -E -1 $comp_file || error "Create $comp_file failed"
3859 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3862 # write to first comp (0 - 10M) of mirror 1, extending + staling
3863 # first + second comp of mirror 2
3864 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3867 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3870 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3872 $LFS getstripe $comp_file
3874 found=$($LFS find --component-start 0m --component-end 1m \
3875 --comp-flags init,stale $comp_file | wc -l)
3876 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3878 found=$($LFS find --component-start 1m --component-end EOF \
3879 --comp-flags stale,^init $comp_file | wc -l)
3880 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3882 local mirror_id=$($LFS getstripe --component-start=1m \
3883 --component-end=EOF $comp_file | \
3884 grep lcme_mirror_id | awk '{ print $2 }')
3886 [[ $mirror_id -eq 2 ]] ||
3887 error "component not in correct mirror? $mirror_id"
3889 $LFS mirror resync $comp_file
3891 $LFS getstripe $comp_file
3893 # component dimensions should not change from resync
3894 found=$($LFS find --component-start 1m --component-end EOF \
3895 --component-flags init $comp_file | wc -l)
3896 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3898 sel_layout_sanity $comp_file 4
3900 run_test 204c "FLR write/stale/resync test with component removal"
3902 # Successful repeated component in primary mirror
3904 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3905 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3906 skip "skipped for lustre < $SEL_VER"
3908 local comp_file=$DIR/$tdir/$tfile
3911 wait_delete_completed
3913 test_mkdir $DIR/$tdir
3914 stack_trap "rm -f $comp_file"
3916 # first mirror is 64M followed by extension space to -1, second mirror
3917 # is 0-10M, then 10M-(-1)
3918 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3919 error "Create $comp_file failed"
3921 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3922 local ost_name=$(ostname_from_index $ost_idx1)
3923 # degrade OST for first comp so we won't extend there
3924 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3925 obdfilter.$ost_name.degraded=1
3928 # Write beyond first component, causing repeat & stale second mirror
3929 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3932 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3933 obdfilter.$ost_name.degraded=0
3936 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3938 $LFS getstripe $comp_file
3940 found=$($LFS find --component-start 64m --component-end 128m \
3941 --component-flags init $comp_file | wc -l)
3942 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3944 local ost_idx2=$($LFS getstripe --component-start=64m \
3945 --component-end=128m --component-flags=init \
3947 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3948 local mirror_id=$($LFS getstripe --component-start=64m \
3949 --component-end=128m --component-flags=init \
3950 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3951 [[ $mirror_id -eq 1 ]] ||
3952 error "component not in correct mirror: $mirror_id, not 1"
3954 $LFS mirror resync $comp_file
3956 $LFS getstripe $comp_file
3958 # component dimensions should not change from resync
3959 found=$($LFS find --component-start 0m --component-end 64m \
3960 --component-flags init $comp_file | wc -l)
3961 [ $found -eq 1 ] || error "resync: first comp incorrect"
3962 found=$($LFS find --component-start 64m --component-end 128m \
3963 --component-flags init $comp_file | wc -l)
3964 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3966 sel_layout_sanity $comp_file 5
3968 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3970 # Successful repeated component, SEL in non-primary mirror
3972 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3973 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3974 skip "skipped for lustre < $SEL_VER"
3976 local comp_file=$DIR/$tdir/$tfile
3979 wait_delete_completed
3982 test_mkdir $DIR/$tdir
3983 stack_trap "rm -f $comp_file"
3985 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
3986 # space to -1 (-z 64M, so first comp is 0-64M)
3987 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
3988 # will be not enough - one will be degraded, the other is used on
3989 # an overlapping mirror.
3990 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
3991 error "Create $comp_file failed"
3993 local ost_idx1=$($LFS getstripe --component-start=0 \
3994 --component-end=64m -i $comp_file)
3995 local ost_name=$(ostname_from_index $ost_idx1)
3996 # degrade OST for first comp of 2nd mirror so we won't extend there
3997 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3998 obdfilter.$ost_name.degraded=1
4001 $LFS getstripe $comp_file
4003 # Write to first component, stale & instantiate second mirror components
4004 # overlapping with the written component (0-100M);
4005 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4008 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4009 obdfilter.$ost_name.degraded=0
4011 $LFS getstripe $comp_file
4013 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
4015 found=$($LFS find --component-start 0m --component-end 64m \
4016 --component-flags init,stale $comp_file | wc -l)
4017 [ $found -eq 1 ] || error "write: first comp incorrect"
4019 # was repeated due to degraded ost
4020 found=$($LFS find --component-start 64m --component-end 128m \
4021 --component-flags init,stale $comp_file | wc -l)
4022 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4024 local ost_idx2=$($LFS getstripe --component-start=64m \
4025 --component-end=128m --component-flags=init \
4027 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4028 local mirror_id=$($LFS getstripe --component-start=0m \
4029 --component-end=64m --component-flags=init \
4030 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4031 [[ $mirror_id -eq 2 ]] ||
4032 error "component not in correct mirror? $mirror_id"
4034 $LFS mirror resync $comp_file
4036 $LFS getstripe $comp_file
4038 # component dimensions should not change from resync
4039 found=$($LFS find --component-start 0m --component-end 64m \
4040 --component-flags init,^stale $comp_file | wc -l)
4041 [ $found -eq 1 ] || error "resync: first comp incorrect"
4042 found=$($LFS find --component-start 64m --component-end 128m \
4043 --component-flags init,^stale $comp_file | wc -l)
4044 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4046 sel_layout_sanity $comp_file 5
4048 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4050 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4052 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4053 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4054 skip "skipped for lustre < $SEL_VER"
4056 local comp_file=$DIR/$tdir/$tfile
4059 wait_delete_completed
4061 test_mkdir $DIR/$tdir
4062 stack_trap "rm -f $comp_file"
4064 pool_add $TESTNAME || error "Pool creation failed"
4065 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4067 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4068 # space to -1 (-z 64M, so first comp is 0-64M)
4069 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4070 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4072 local ost_name0=$(ostname_from_index 0)
4073 local ost_name1=$(ostname_from_index 1)
4075 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4076 # extend original comp
4077 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4078 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4081 # a write to the 1st component, 100M length, which will try to stale
4082 # the first 100M of mirror 2, attempting to extend its 0-64M component
4083 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4086 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4087 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4090 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4092 $LFS getstripe $comp_file
4094 found=$($LFS find --component-start 0m --component-end 128m \
4095 --component-flags init,stale $comp_file | wc -l)
4096 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4098 local mirror_id=$($LFS getstripe --component-start=0m \
4099 --component-end=128m --component-flags=init \
4100 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4102 [[ $mirror_id -eq 2 ]] ||
4103 error "component not in correct mirror? $mirror_id, not 2"
4105 $LFS mirror resync $comp_file
4107 $LFS getstripe $comp_file
4109 # component dimensions should not change from resync
4110 found=$($LFS find --component-start 0m --component-end 128m \
4111 --component-flags init,^stale $comp_file | wc -l)
4112 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4114 sel_layout_sanity $comp_file 4
4116 run_test 204f "FLR write/stale/resync sel w/forced extension"
4118 function test_205() {
4119 local tf=$DIR/$tfile
4122 $LFS setstripe -c1 $tf
4123 $LFS mirror extend -N $tf
4124 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4125 (( $mirrors == 2 )) || error "no new mirror was created?"
4127 $LFS mirror extend -N --flags=prefer $tf
4128 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4129 (( $mirrors == 3 )) || error "no new mirror was created?"
4131 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4132 error "prefer flag was not set on the new mirror"
4134 run_test 205 "lfs mirror extend to set prefer flag"
4136 function test_206() {
4137 # create a new OST pool
4138 local pool_name=$TESTNAME
4140 create_pool $FSNAME.$pool_name ||
4141 error "create OST pool $pool_name failed"
4142 # add OSTs into the pool
4143 pool_add_targets $pool_name 0 1 ||
4144 error "add OSTs into pool $pool_name failed"
4146 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4147 error "can't setstripe"
4148 $LFS mirror extend -N $DIR/$tfile ||
4149 error "can't create replica"
4150 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4151 $LFS getstripe $DIR/$tfile
4152 error "prefer found"
4154 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4155 $LFS getstripe $DIR/$tfile
4156 error "can't setstripe prefer"
4159 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4160 $LFS getstripe $DIR/$tfile
4161 error "no prefer found"
4167 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4170 local file=$DIR/$tfile
4171 local tmpfile=$DIR/$tfile-tt
4173 [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
4174 skip "Need MDS version at least 2.14.50"
4176 stack_trap "rm -f $tmpfile $file"
4178 # generate data for verification
4179 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4180 error "can't generate file with random data"
4182 # create a mirrored file with one stale replica
4183 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4184 error "create mirrored file $file failed"
4185 get_mirror_ids $file
4186 echo "mirror IDs: ${mirror_array[*]}"
4188 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4189 get_mirror_ids $file
4190 echo "mirror IDs: ${mirror_array[*]}"
4193 cmp $tmpfile $file || error "files don't match"
4194 get_mirror_ids $file
4195 echo "mirror IDs: ${mirror_array[*]}"
4197 # mirror creation should work fine
4198 $LFS mirror extend -N -S 8M -c -1 $file ||
4199 error "mirror extend $file failed"
4201 get_mirror_ids $file
4202 echo "mirror IDs: ${mirror_array[*]}"
4205 $LFS mirror verify -v $file || error "verification failed"
4206 cmp $tmpfile $file || error "files don't match"
4208 run_test 207 "create another replica with existing out-of-sync one"
4210 function check_ost_used() {
4219 cancel_lru_locks osc # to drop pages
4220 cancel_lru_locks mdc # to refresh layout
4221 # XXX: cancel_lru_locks mdc doesn't work
4222 # XXX: need a better way to reload the layout
4223 umount_client $MOUNT || error "umount failed"
4224 mount_client $MOUNT || error "mount failed"
4226 # refresh non-rotation status on MDTs
4228 touch $DIR/$tfile-temp
4229 rm -f $DIR/$tfile-temp
4230 # refresh non-rotational status on the client
4234 $LCTL set_param osc.*.stats=clear >/dev/null
4235 if [[ $io == "read" ]]; then
4236 ddarg="if=$file of=/dev/null"
4237 elif [[ $io == "write" ]]; then
4238 ddarg="if=/dev/zero of=$file"
4240 error "unknown type $io"
4242 dd $ddarg bs=8M count=1 || error "can't $io $file"
4243 cancel_lru_locks osc
4245 # check only specified OSTs got reads
4246 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4247 local nr=$($LCTL get_param -n \
4248 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4249 awk "/ost_$io/{print \$2}")
4251 if [[ " $* " =~ $ost ]]; then
4252 (( nr > 0 )) || error "expected reads on $ost"
4254 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4260 local tf=$DIR/$tfile
4261 local osts=$(comma_list $(osts_nodes))
4263 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4264 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4265 skip "Need MDS version at least 2.14.55"
4267 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4269 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4270 stack_trap "restore_lustre_params < $p; rm -f $p"
4272 stack_trap "rm -f $tf"
4273 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4274 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4275 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4276 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4277 $LFS mirror resync $tf || error "can't resync"
4280 log "set OST0000 non-rotational"
4282 $LCTL set_param osd*.*OST*.nonrotational=0
4284 $LCTL set_param osd*.*OST0000*.nonrotational=1
4285 check_ost_used $tf read 0
4287 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4289 $LCTL set_param osd*.*OST*.nonrotational=0
4291 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4292 osd*.*OST0003*.nonrotational=1
4293 check_ost_used $tf read 2 3
4295 log "set mirror 1 on OST0001 preferred"
4296 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4297 error "can't set prefer"
4298 check_ost_used $tf read 1
4300 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4303 local tf=$DIR/$tfile
4304 local osts=$(comma_list $(osts_nodes))
4306 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4307 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4308 skip "Need MDS version at least 2.14.55"
4310 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4312 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4313 stack_trap "restore_lustre_params < $p; rm -f $p"
4315 stack_trap "rm -f $tf"
4316 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4317 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4318 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4319 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4320 $LFS mirror resync $tf || error "can't resync"
4321 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4323 log "set OST0000 non-rotational"
4325 $LCTL set_param osd*.*OST*.nonrotational=0
4327 $LCTL set_param osd*.*OST0000*.nonrotational=1
4328 check_ost_used $tf write 0
4329 $LFS mirror resync $tf || error "can't resync"
4331 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4333 $LCTL set_param osd*.*OST*.nonrotational=0
4335 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4336 osd*.*OST0003*.nonrotational=1
4337 check_ost_used $tf write 2 3
4338 $LFS mirror resync $tf || error "can't resync"
4340 log "set mirror 1 on OST0001 preferred"
4341 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4342 error "can't set prefer"
4343 check_ost_used $tf write 1
4345 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4348 local tf=$DIR/$tfile
4349 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4350 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4351 local osts=$(comma_list $(osts_nodes))
4353 stack_trap "rm -f $tmpfile"
4355 mkdir -p $MOUNT2 && mount_client $MOUNT2
4356 stack_trap "umount_client $MOUNT2"
4358 # to make replica on ost1 preferred for new writes
4359 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4360 stack_trap "restore_lustre_params < $p; rm -f $p"
4362 $LCTL set_param osd*.*OST*.nonrotational=0
4364 $LCTL set_param osd*.*OST0001*.nonrotational=1
4366 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4368 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4369 log "replicated file created"
4371 cancel_lru_locks mdc
4372 cancel_lru_locks osc
4374 log "open(O_RDONLY) and first read from OST"
4375 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4378 log "first read complete"
4380 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4381 error "can't write BBBB"
4382 log "BBBB written which made replica on ost1 stale"
4384 log "fast read from pagecache in the original process"
4388 log "read via $DIR2 new open(2)"
4389 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4391 log "fast read from pagecache after 5s in the original process"
4396 local nr=$(grep "BBBB" $tmpfile | wc -l)
4402 log "read via new open(2)"
4403 $MULTIOP $tf vvoO_RDONLY:r4c
4405 run_test 209a "skip fast reads after layout invalidation"
4407 function sum_ost_reads() {
4408 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4409 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4413 local tf=$DIR/$tfile
4415 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4416 cancel_lru_locks osc
4417 echo "the very first read"
4418 cat $tf >/dev/null || error "can't read"
4420 # cancel layout lock
4421 cancel_lru_locks mdc
4423 # now read again, data must be in the cache, so no ost reads
4424 $LCTL set_param osc.*.stats=clear >/dev/null
4425 echo "read with warm cache"
4426 cat $tf >/dev/null || error "can't read"
4428 (( nr == 0 )) || error "reads with warm cache"
4430 # now verify we can catch reads at all
4431 cancel_lru_locks osc
4432 cat $tf >/dev/null || error "can't read"
4434 (( nr > 0 )) || error "no reads with cold cache"
4436 run_test 209b "pagecache can be used after LL cancellation"
4439 local tf=$DIR/$tfile
4441 stack_trap "rm -f $tf"
4442 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4443 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4444 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4445 $LFS mirror extend -N $tf || error "can't mirror"
4446 $LFS getstripe -v $tf
4447 stat $tf || error "can't stat"
4449 run_test 210a "handle broken mirrored lovea"
4451 complete_test $SECONDS
4452 check_and_cleanup_lustre