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 a mirrored file with plain layout mirrors
365 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
366 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
367 error "create mirrored file $tf failed"
368 verify_mirror_count $tf 6
369 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
370 for ((i = 0; i < 6; i++)); do
371 verify_comp_extent $tf ${ids[$i]} 0 EOF
374 # verify component ${ids[0]}
375 verify_comp_attrs $tf ${ids[0]}
377 # verify component ${ids[1]}
378 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
379 verify_comp_attr stripe-count $tf ${ids[1]} 2
380 verify_comp_attr stripe-index $tf ${ids[1]} 2
382 # verify component ${ids[2]}
383 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
384 verify_comp_attr stripe-count $tf ${ids[2]} 2
385 verify_comp_attr pool $tf ${ids[2]} flash
387 # verify component ${ids[3]}
388 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
389 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
390 verify_comp_attr pool $tf ${ids[3]} flash
392 # verify component ${ids[4]}
393 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
394 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
395 verify_comp_attr pool $tf ${ids[4]} archive
397 # verify component ${ids[5]}
398 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
399 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
400 verify_comp_attr_with_parent pool $tf ${ids[5]}
402 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
403 # LU-11022 - remove mirror by pool name
404 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
405 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
406 $LFS mirror delete --pool archive $tf || error "delete mirror"
407 cnt=$($LFS getstripe $tf | grep archive | wc -l)
408 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
414 run_test 0b "lfs mirror create plain layout mirrors"
417 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
421 local mirror_cmd="$LFS mirror create"
425 # create a new OST pool
426 local pool_name=$TESTNAME
427 create_pool $FSNAME.$pool_name ||
428 error "create OST pool $pool_name failed"
430 # add OSTs into the pool
431 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
432 error "add OSTs into pool $pool_name failed"
434 # create parent directory
435 mkdir $td || error "mkdir $td failed"
436 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
437 error "$LFS setstripe $td failed"
439 # create a mirrored file with composite layout mirrors
440 $mirror_cmd -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
442 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
443 error "create mirrored file $tf failed"
444 verify_mirror_count $tf 6
445 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
447 # verify components ${ids[0]} and ${ids[2]}
449 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
450 verify_comp_attr stripe-count $tf ${ids[$i]} 2
451 verify_comp_attr stripe-index $tf ${ids[$i]} 1
452 verify_comp_extent $tf ${ids[$i]} 0 8388608
455 # verify components ${ids[1]} and ${ids[3]}
457 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
458 verify_comp_attr stripe-count $tf ${ids[$i]} 2
459 verify_comp_attr pool $tf ${ids[$i]} flash
460 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
463 # verify component ${ids[4]}
464 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
465 verify_comp_attr stripe-count $tf ${ids[4]} 4
466 verify_comp_attr_with_parent pool $tf ${ids[4]}
467 verify_comp_extent $tf ${ids[4]} 0 EOF
469 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
471 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
472 verify_comp_attr stripe-count $tf ${ids[$i]} 4
473 verify_comp_attr pool $tf ${ids[$i]} archive
474 verify_comp_extent $tf ${ids[$i]} 0 536870912
477 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
479 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
480 verify_comp_attr stripe-count $tf ${ids[$i]} -1
481 verify_comp_attr pool $tf ${ids[$i]} archive
482 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
488 run_test 0c "lfs mirror create composite layout mirrors"
493 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
494 local mirror_cmd="$LFS mirror extend"
498 # create parent directory
499 mkdir $td || error "mkdir $td failed"
501 $mirror_cmd $tf &> /dev/null && error "miss -N option"
502 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
504 # create a non-mirrored file, convert it to a mirrored file and extend
505 touch $tf || error "touch $tf failed"
506 $mirror_cmd -N $tf || error "convert and extend $tf failed"
507 verify_mirror_count $tf 2
508 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
509 for ((i = 0; i < 2; i++)); do
510 verify_comp_attrs $tf ${ids[$i]}
511 verify_comp_extent $tf ${ids[$i]} 0 EOF
514 lfsck_verify_pfid $tf || error "PFID is not set"
516 # create a mirrored file and extend it
517 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
518 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
519 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
521 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
522 error "extend mirror with -f failed"
524 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
525 error "extend mirrored file $tf-3 failed"
526 verify_mirror_count $tf-3 $mirror_count
527 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
528 for ((i = 0; i < $mirror_count; i++)); do
529 verify_comp_attrs $tf-3 ${ids[$i]}
530 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
533 $mirror_cmd -N $tf-3 &> /dev/null
536 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
538 run_test 0d "lfs mirror extend with -N option"
541 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
545 local mirror_cmd="$LFS mirror extend"
549 # create parent directory
550 mkdir $td || error "mkdir $td failed"
552 # create a mirrored file with plain layout mirrors
553 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
554 error "create mirrored file $tf failed"
556 # extend the mirrored file with plain layout mirrors
557 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
558 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
559 error "extend mirrored file $tf failed"
560 verify_mirror_count $tf 6
561 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
562 for ((i = 0; i < 6; i++)); do
563 verify_comp_extent $tf ${ids[$i]} 0 EOF
566 # verify component ${ids[0]}
567 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
568 verify_comp_attr stripe-count $tf ${ids[0]} 3
569 verify_comp_attr stripe-index $tf ${ids[0]} 1
571 # verify component ${ids[1]}
572 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
573 verify_comp_attr stripe-count $tf ${ids[1]} 2
574 verify_comp_attr stripe-index $tf ${ids[1]} 2
576 # verify component ${ids[2]}
577 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
578 verify_comp_attr stripe-count $tf ${ids[2]} 2
579 verify_comp_attr pool $tf ${ids[2]} flash
581 # verify component ${ids[3]}
582 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
583 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
584 verify_comp_attr pool $tf ${ids[3]} flash
586 # verify component ${ids[4]}
587 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
588 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
589 verify_comp_attr pool $tf ${ids[4]} archive
591 # verify component ${ids[5]}
592 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
593 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
594 verify_comp_attr_with_parent pool $tf ${ids[5]}
596 run_test 0e "lfs mirror extend plain layout mirrors"
599 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
603 local mirror_cmd="$LFS mirror extend"
607 # create parent directory
608 mkdir $td || error "mkdir $td failed"
610 # create a mirrored file with composite layout mirror
611 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
612 error "create mirrored file $tf failed"
614 # extend the mirrored file with composite layout mirrors
615 $mirror_cmd -N -p archive \
616 -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
618 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
619 error "extend mirrored file $tf failed"
620 verify_mirror_count $tf 8
621 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
623 # verify component ${ids[0]}
624 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
625 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
626 verify_comp_attr pool $tf ${ids[0]} ssd
627 verify_comp_extent $tf ${ids[0]} 0 33554432
629 # verify component ${ids[1]}
630 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
631 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
632 verify_comp_attr pool $tf ${ids[1]} ssd
633 verify_comp_extent $tf ${ids[1]} 33554432 EOF
635 # verify component ${ids[2]}
636 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
637 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
638 verify_comp_attr pool $tf ${ids[2]} archive
639 verify_comp_extent $tf ${ids[2]} 0 EOF
641 # verify components ${ids[3]} and ${ids[5]}
643 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
644 verify_comp_attr stripe-count $tf ${ids[$i]} 2
645 verify_comp_attr stripe-index $tf ${ids[$i]} 1
646 verify_comp_extent $tf ${ids[$i]} 0 8388608
649 # verify components ${ids[4]} and ${ids[6]}
651 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
652 verify_comp_attr stripe-count $tf ${ids[$i]} 2
653 verify_comp_attr pool $tf ${ids[$i]} flash
654 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
657 # verify component ${ids[7]}
658 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
659 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
660 verify_comp_attr_with_parent pool $tf ${ids[7]}
661 verify_comp_extent $tf ${ids[7]} 0 EOF
663 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
665 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
666 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
667 verify_comp_attr pool $tf ${ids[$i]} archive
668 verify_comp_extent $tf ${ids[$i]} 0 536870912
671 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
673 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
674 verify_comp_attr stripe-count $tf ${ids[$i]} -1
675 verify_comp_attr pool $tf ${ids[$i]} archive
676 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
679 run_test 0f "lfs mirror extend composite layout mirrors"
684 ! $LFS mirror create --flags prefer $tf ||
685 error "creating $tf w/ --flags but w/o -N option should fail"
687 ! $LFS mirror create -N --flags foo $tf ||
688 error "creating $tf with '--flags foo' should fail"
690 ! $LFS mirror create -N --flags stale $tf ||
691 error "creating $tf with '--flags stale' should fail"
693 ! $LFS mirror create -N --flags prefer,init $tf ||
694 error "creating $tf with '--flags prefer,init' should fail"
696 ! $LFS mirror create -N --flags ^prefer $tf ||
697 error "creating $tf with '--flags ^prefer' should fail"
699 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
700 -N -o1 $tf || error "create mirrored file $tf failed"
702 verify_comp_attr lcme_flags $tf 0x10001 prefer
703 verify_comp_attr lcme_flags $tf 0x10002 prefer
705 # write to the mirrored file and check primary
706 cp /etc/hosts $tf || error "error writing file '$tf'"
708 verify_comp_attr lcme_flags $tf 0x20003 stale
710 # resync file and check prefer flag
711 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
714 $LCTL set_param osc.*.stats=clear
715 cat $tf &> /dev/null || error "error reading file '$tf'"
717 # verify that the data was provided by OST1 where mirror 1 resides
718 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
719 awk '/ost_read/{print $2}')
720 [ -n "$nr_read" ] || error "read was not provided by OST1"
722 run_test 0g "lfs mirror create flags support"
725 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
726 skip "Need MDS version at least 2.11.57"
734 # create parent directory
735 test_mkdir $td || error "mkdir $td failed"
737 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
738 error "set default mirrored layout on directory $td failed"
740 # verify flags are inherited from the directory
743 verify_comp_attr lcme_flags $tf 0x10001 prefer
744 verify_comp_attr lcme_flags $tf 0x10002 prefer
746 # set flags to the first component
747 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
748 error "setting '^prefer,foo' flags should fail"
750 ! $LFS getstripe --component-flags=prefer,foo $tf ||
751 error "getting component(s) with 'prefer,foo' flags should fail"
753 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
755 verify_comp_attr lcme_flags $tf 0x10001 stale
756 verify_comp_attr lcme_flags $tf 0x10002 prefer
758 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
759 error "clearing 'stale' should fail"
761 # write and resync file. It can't resync the file directly because the
762 # file state is still 'ro'
763 cp /etc/hosts $tf || error "error writing file '$tf'"
764 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
766 for flag in prefer prefrd prefwr; do
767 $LFS setstripe --comp-set -I 0x20003 --comp-flags=$flag $tf ||
768 error "error setting flag $flag"
770 verify_comp_attr lcme_flags $tf 0x20003 $flag
772 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^$flag $tf ||
773 error "error clearing $flag flag from component 0x20003"
776 # MDS disallows setting stale flag on the last non-stale mirror
777 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
779 cp /etc/hosts $tf || error "error writing file '$tf'"
781 verify_comp_attr lcme_flags $tf 0x10002 prefer
782 verify_comp_attr lcme_flags $tf 0x20003 stale
783 verify_comp_attr lcme_flags $tf 0x30004 stale
785 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
787 error "setting stale flag on component 0x10002 should fail"
789 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
791 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
792 error "error setting stale flag on component 0x10001"
793 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
794 error "error setting stale flag on component 0x20003"
796 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
798 error "setting stale flag on component 0x30004 should fail"
800 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
802 run_test 0h "set, clear and test flags for FLR files"
805 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
807 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
808 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
809 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
811 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
812 stack_trap "rm -f $TMP/$tfile"
813 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
814 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
815 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
816 error "set component 1 stale failed"
817 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
818 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
820 run_test 0j "test lfs mirror read/write commands"
823 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
826 # default FLR with 2 mirrors
827 $LFS setstripe -N -c1 -i0 -N -c1 -i1 $DIR/$tdir ||
828 error "set default layout failed"
830 # plain file extension under default FLR dir
831 echo $tfile >> $DIR/$tdir/$tfile.append || error "create $tfile.append failed"
832 echo -n " before extend $tfile.append, mirror count = "
833 $LFS getstripe -N $DIR/$tdir/$tfile.append
835 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile.append ||
836 error "mirror extend failed"
837 echo -n " after extend $tfile.append, mirror count = "
838 $LFS getstripe -N $DIR/$tdir/$tfile.append
840 # normal file extension under default FLR dir
841 touch $DIR/$tdir/$tfile || error "create $tfile failed"
842 echo -n " before extend $tfile, mirror count = "
843 $LFS getstripe -N $DIR/$tdir/$tfile
845 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile ||
846 error "mirror extend $tfile failed"
847 echo -n " after extend $tfile, mirror count = "
848 $LFS getstripe -N $DIR/$tdir/$tfile
850 run_test 0k "mirroring a file in directory with default FLR layout"
854 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
855 local mirror_create_cmd="$LFS mirror create"
856 local stripes[0]=$OSTCOUNT
858 mirror_create_cmd+=" -N -c ${stripes[0]}"
859 for ((i = 1; i < $mirror_count; i++)); do
860 # add mirrors with different stripes to the file
861 stripes[$i]=$((RANDOM % OSTCOUNT))
862 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
864 mirror_create_cmd+=" -N -c ${stripes[$i]}"
867 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
868 verify_mirror_count $tf $mirror_count
870 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
871 $LFS mirror extend -N $tf &&
872 error "Creating the $((mirror_count+1))th mirror succeeded"
874 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
877 # verify the range of components and stripe counts
878 for ((i = 0; i < $mirror_count; i++)); do
879 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
880 verify_comp_extent $tf ${ids[$i]} 0 EOF
883 run_test 1 "create components with setstripe options"
887 local tf2=$DIR/$tfile-2
889 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
890 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
892 $LFS mirror extend -N -f $tf2 $tf ||
893 error "merging $tf2 into $tf failed"
895 verify_mirror_count $tf 2
896 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
898 run_test 2 "create components from existing files"
901 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
903 for ((i = 0; i < 2; i++)); do
904 $LFS mkdir -i $i $DIR/$tdir-$i
905 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
908 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
909 $DIR/$tdir-0/$tfile || error "creating mirrors"
911 # mdt doesn't support to cancel layout lock for remote objects, do
915 # make sure the mirrorted file was created successfully
916 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
917 { $LFS getstripe $DIR/$tdir-0/$tfile;
918 error "expected 2 components"; }
923 run_test 3 "create components from files located on different MDTs"
926 local tf=$DIR/$tdir/$tfile
929 test_mkdir $DIR/$tdir
931 # set mirror with setstripe options to directory
932 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
933 error "set mirror to directory error"
935 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
936 x"mirrored" ] || error "failed to create mirrored dir"
939 verify_mirror_count $tf 2
941 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
942 verify_comp_extent $tf ${ids[0]} 0 1048576
943 verify_comp_extent $tf ${ids[1]} 1048576 EOF
945 # sub directory should inherit mirror setting from parent
946 test_mkdir $DIR/$tdir/td
947 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
948 x"mirrored" ] || error "failed to inherit mirror from parent"
950 # mirror extend won't be applied to directory
951 $LFS mirror extend -N2 $DIR/$tdir &&
952 error "expecting mirror extend failure"
955 run_test 4 "Make sure mirror attributes can be inhertied from directory"
961 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
962 error "failed to create file with non-empty layout"
963 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
965 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
966 verify_mirror_count $tf 3
968 $CHECKSTAT -t file -s 12345 $tf ||
969 error "size error after attaching layout "
971 run_test 5 "Make sure init size work for mirrored layout"
974 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
975 skip "MDS version older than 2.12.58"
979 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
980 error "failure to create DoM file with mirror"
982 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
983 error "failure to create mirrored file with DoM"
985 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
986 error "failure to create PFL with DoM file"
987 $LFS mirror extend -N2 $tf ||
988 error "failure to extend mirror with DoM"
990 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
991 error "failure to create PFL with DoM file"
992 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
993 error "failure to create mirrored file"
994 $LFS mirror extend -N -f $tf-1 $tf-2 ||
995 error "failure to extend mirrored file with DoM extent"
997 run_test 6a "DoM and FLR work together"
1000 (( $MDS1_VERSION >= $(version_code 2.15.58.1) )) ||
1001 skip "MDS version older than 2.15.58.1"
1003 local tf=$DIR/$tfile
1005 $LFS setstripe -E64K -L mdt -Eeof $tf ||
1006 error "failure to create PFL with DoM file"
1007 $LFS mirror extend -N -E1M -L mdt -Eeof $tf &&
1008 error "should not extend mirror with different DoM size"
1012 run_test 6b "extend mirror with different DoM size"
1015 local tf=$DIR/$tfile
1017 # create DoM with setting stripe_size == component size
1018 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
1019 error "failure to create DoM with stripe_size == comp size"
1020 rm -f $tf || error "delete $tf"
1022 # DoM should not inherit previous component stripe_size
1023 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
1024 error "DoM component shouldn't inherit previous stripe_size"
1026 run_test 7 "Create mirror with DoM component"
1029 local tf=$DIR/$tfile
1030 local tf2=$DIR/$tfile-2
1032 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1034 stack_trap "rm -f $tf $tf2"
1036 $LFS setstripe -E EOF -o 0 $tf
1037 $LFS setstripe -E EOF -o 1 $tf2
1039 local dd_count=$((RANDOM % 20 + 1))
1040 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
1041 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
1043 # for zfs - sync OST dataset so that du below will return
1045 [ "$FSTYPE" = "zfs" ] &&
1046 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1048 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1051 $LFS mirror extend -N -f $tf2 $tf ||
1052 error "merging $tf2 into $tf failed"
1054 # cancel layout lock
1055 cancel_lru_locks mdc
1057 local new_blocks=$(du -k $tf | awk '{print $1}')
1058 [ $new_blocks -eq $blocks ] ||
1059 error "i_blocks error expected: $blocks, actual: $new_blocks"
1061 run_test 21 "glimpse should report accurate i_blocks"
1063 get_osc_lock_count() {
1070 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1071 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1072 lock_count=$((lock_count + count))
1078 local tf=$DIR/$tfile
1080 stack_trap "rm -f $tf"
1082 $LFS setstripe -E EOF -o 0 $tf
1083 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1085 # add component, two mirrors located on the same OST ;-)
1086 $LFS mirror extend -N -o 0 $tf ||
1087 error "extending mirrored file $tf failed"
1089 size_blocks=$(stat --format="%b %s" $tf)
1091 cancel_lru_locks mdc
1092 cancel_lru_locks osc
1094 local new_size_blocks=$(stat --format="%b %s" $tf)
1096 # make sure there is no lock cached
1097 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1099 [ "$new_size_blocks" = "$size_blocks" ] ||
1100 echo "size expected: $size_blocks, actual: $new_size_blocks"
1104 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1107 local tf=$DIR/$tfile
1109 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1110 error "creating mirrored file $tf failed"
1113 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1114 cancel_lru_locks osc
1117 local tmpfile=$(mktemp)
1118 stat --format="%b %s" $tf > $tmpfile &
1122 while [ $cnt -le 5 ]; do
1123 kill -0 $pid > /dev/null 2>&1 || break
1127 kill -0 $pid > /dev/null 2>&1 &&
1128 error "stat process stuck due to unavailable OSTs"
1130 # make sure glimpse request has been sent
1131 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1132 error "OST $ost_idx: no glimpse request was sent"
1137 run_test 31 "make sure glimpse request can be retried"
1140 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1141 rm -f $DIR/$tfile $DIR/$tfile-2
1143 stack_trap "rm -f $DIR/$tfile"
1145 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1146 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1148 local fsize=$(stat -c %s $DIR/$tfile)
1149 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1151 local cksum=$(md5sum $DIR/$tfile)
1153 # create a new mirror in sync mode
1154 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1155 error "extending mirrored file $DIR/$tfile failed"
1157 # make sure the mirrored file was created successfully
1158 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1159 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1164 # check size is correct, glimpse request should go to the 2nd mirror
1165 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1166 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1168 echo "reading file from the 2nd mirror and verify checksum"
1169 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1170 error "checksum error: expected $cksum"
1174 run_test 32 "data should be mirrored to newly created mirror"
1177 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1179 rm -f $DIR/$tfile $DIR/$tfile-2
1181 # create a file with two mirrors
1182 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1185 while [ $count -lt $max_count ]; do
1186 echo "ost1" >> $DIR/$tfile
1187 count=$((count + 1));
1190 # tmp file that will be used as mirror
1191 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1193 while [ $count -lt $max_count ]; do
1194 echo "ost2" >> $DIR/$tfile-2
1195 count=$((count + 1));
1198 # create a mirrored file
1199 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1200 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1201 "with verification should fail"
1202 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1203 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1204 "without verification failed"
1206 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1207 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1208 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1210 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1212 # execpted file size
1213 local fsize=$((5 * max_count))
1214 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1215 error "mirrored file size is not $fsize"
1217 # read file - all OSTs are available
1218 echo "reading file (data can be provided by any ost)... "
1219 local rs=$(cat $DIR/$tfile | head -1)
1220 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1221 error "file content error: expected: \"ost1\" or \"ost2\""
1223 # read file again with ost1 failed
1227 echo "reading file (data should be provided by ost2)..."
1228 local rs=$(cat $DIR/$tfile | head -1)
1229 [[ "$rs" == "ost2" ]] ||
1230 error "file content error: expected: \"ost2\", actual: \"$rs\""
1235 # read file again with ost2 failed
1239 # check size, glimpse should work
1240 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1241 error "mirrored file size is not $fsize"
1243 echo "reading file (data should be provided by ost1)..."
1244 local rs=$(cat $DIR/$tfile | head -1)
1245 [[ "$rs" == "ost1" ]] ||
1246 error "file content error: expected: \"ost1\", actual: \"$rs\""
1250 run_test 33a "read can choose available mirror to read"
1253 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1257 stack_trap "rm -f $DIR/$tfile" EXIT
1259 # create a file with two mirrors on OST0000 and OST0001
1260 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1262 # make sure that $tfile has two mirrors
1263 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1264 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1267 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1268 error "write failed for $DIR/$tfile"
1269 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1270 verify_flr_state $DIR/$tfile "ro"
1275 # read file - all OSTs are available
1276 echo "reading file (data can be provided by any ost)... "
1278 time cat $DIR/$tfile > /dev/null || error "read all"
1282 # read file again with ost1 {OST0000} failed
1285 echo "reading file (data should be provided by ost2)..."
1287 time cat $DIR/$tfile > /dev/null || error "read ost2"
1294 # read file again with ost2 {OST0001} failed
1298 echo "reading file (data should be provided by ost1)..."
1300 time cat $DIR/$tfile > /dev/null || error "read ost1"
1307 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1308 error "read mirror too slow without ost1, from $ra to $r1"
1309 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1310 error "read mirror too slow without ost2, from $ra to $r2"
1312 wait_osc_import_ready client ost2
1314 run_test 33b "avoid reading from unhealthy mirror"
1317 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1321 stack_trap "rm -f $DIR/$tfile" EXIT
1323 # create a file with two mirrors
1324 # mirror1: {OST0000, OST0001}
1325 # mirror2: {OST0001, OST0002}
1326 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1328 # make sure that $tfile has two mirrors
1329 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1330 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1333 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1334 error "write failed for $DIR/$tfile"
1335 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1336 verify_flr_state $DIR/$tfile "ro"
1341 # read file - all OSTs are available
1342 echo "reading file (data can be provided by any ost)... "
1343 time cat $DIR/$tfile > /dev/null || error "read all"
1345 # read file again with ost2 (OST0001) failed
1349 echo "reading file (data should be provided by ost1 and ost3)..."
1350 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1355 wait_osc_import_ready client ost2
1357 run_test 33c "keep reading among unhealthy mirrors"
1360 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1362 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1365 $LFS setstripe -o 0 $DIR/$tfile-ref
1366 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1368 # create a file with two mirrors
1369 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1370 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1372 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1373 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1375 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1376 error "mirrored file size is not 3M"
1378 # merge a mirrored file
1379 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1380 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1382 cancel_lru_locks osc
1384 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1385 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1388 echo "comparing files ... "
1390 # however, read can still return the correct data. It should return
1391 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1392 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1393 $DIR/$tfile-ref || error "file reading error"
1397 run_test 34a "read mirrored file with multiple stripes"
1400 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1402 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1405 $LFS setstripe -o 0 $DIR/$tfile-ref
1406 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1408 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1409 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1411 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1412 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1414 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1415 error "mirrored file size is not 3M"
1417 # merge a mirrored file
1418 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1419 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1421 cancel_lru_locks osc
1423 # stop two OSTs, so the 2nd component of the 1st mirror and
1424 # the 1st component of the 2nd mirror will be inaccessible, ...
1427 echo "comparing files ... "
1429 # however, read can still return the correct data. It should return
1430 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1431 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1432 $DIR/$tfile-ref || error "file reading error"
1436 run_test 34b "read mirrored file with multiple components"
1439 local tf=$DIR/$tfile
1441 $LFS setstripe -E eof $tf
1443 # add an out-of-sync mirror to the file
1444 $LFS mirror extend -N -c 2 $tf ||
1445 error "extending mirrored file $tf failed"
1447 $MULTIOP $tf oO_WRONLY:c ||
1448 error "write open a mirrored file failed"
1450 # truncate file should return error
1451 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1453 run_test 35 "allow to write to mirrored files"
1455 get_file_layout_version() {
1456 $LFS getstripe $1 | awk '/lcm_layout_gen/{print $2}'
1459 get_ost_layout_version() {
1460 $MULTIOP $1 oXc | awk '/ostlayoutversion/{print $2}'
1463 verify_ost_layout_version() {
1466 # get file layout version
1467 local flv=$(get_file_layout_version $tf)
1469 # layout version from OST objects
1470 local olv=$(get_ost_layout_version $tf)
1472 (( flv >= olv )) || error "layout version mismatch: $flv vs. $olv"
1479 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1480 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1482 $LFS mirror extend -N -f $tf-tmp $tf ||
1483 error "merging $tf-tmp into $tf failed"
1488 local tf=$DIR/$tfile
1490 stack_trap "rm -f $tf $tf-2 $tf-3"
1492 create_file_36 $tf $tf-2 $tf-3
1494 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1496 # test case 1 - check file write and verify layout version
1497 $MULTIOP $tf oO_WRONLY:c ||
1498 error "write open a mirrored file failed"
1500 # write open file should not return error
1501 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1503 # instantiate components should work
1504 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1506 # verify OST layout version
1507 verify_ost_layout_version $tf
1510 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1513 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1515 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1516 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1518 # write should take at least $fail_loc seconds and succeed
1519 local st=$(date +%s)
1520 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1522 # verify OST layout version
1523 verify_ost_layout_version $tf
1525 do_facet $mds_facet $LCTL set_param fail_loc=0
1527 run_test 36a "write to mirrored files"
1530 local tf=$DIR/$tfile
1532 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1533 skip "Need OST version at least 2.15.50"
1535 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1537 # create 2 mirrors using different OSTs
1538 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1539 error "create mirrored file"
1541 # write 1M data to one mirror
1542 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1545 # set prefer mirror to another mirror
1546 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1547 error "clear prefer mirror error"
1548 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1549 error "set prefer mirror error"
1551 # the second write should not hung
1552 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1554 run_test 36b "write should not hung when prefered mirror is stale"
1557 local tf=$DIR/$tfile
1559 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1560 skip "Need OST version at least 2.15.50"
1562 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1564 # create 2 mirrors using different OSTs
1565 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1566 error "create mirrored file"
1567 stack_trap "rm -f $tf"
1569 # write it in the background
1570 dd if=/dev/zero of=$tf bs=1M count=600 &
1575 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1576 error "clear prefer mirror error"
1577 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1578 error "set prefer mirror error"
1582 run_test 36c "change prefer mirror during write shouldn't hung"
1585 local tf=$DIR/$tfile
1587 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1588 skip "Need OST version at least 2.15.50"
1590 echo " ** create $tf"
1591 $LFS mirror create -N $tf || error "create $tf failed"
1594 echo " ** mirror extend $tf ($i/2)"
1595 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1596 flv=$(get_file_layout_version $tf)
1597 olv=$(get_ost_layout_version $tf)
1598 echo " flv=$flv olv=$olv"
1602 echo " ** write $tf ($i/2)"
1603 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1604 flv=$(get_file_layout_version $tf)
1605 olv=$(get_ost_layout_version $tf)
1606 echo " flv=$flv olv=$olv"
1608 error "write update OST layout failed $flv/$olv"
1611 echo " ** resync $tf"
1612 $LFS mirror resync $tf || error "mirror resync $tf failed"
1613 flv=$(get_file_layout_version $tf)
1614 olv=$(get_ost_layout_version $tf)
1615 echo " flv=$flv olv=$olv"
1618 echo " ** truncate $tf ($i/2)"
1619 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1620 flv=$(get_file_layout_version $tf)
1621 olv=$(get_ost_layout_version $tf)
1622 echo " flv=$flv olv=$olv"
1623 (( flv == olv || flv == olv + 1 )) ||
1624 error "truncate update OST layout failed $flv/$olv"
1627 echo " ** resync $tf"
1628 $LFS mirror resync $tf || error "mirror resync $tf failed"
1629 flv=$(get_file_layout_version $tf)
1630 olv=$(get_ost_layout_version $tf)
1631 echo " flv=$flv olv=$olv"
1634 echo " ** write $tf ($i/2)"
1635 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1636 flv=$(get_file_layout_version $tf)
1637 olv=$(get_ost_layout_version $tf)
1638 echo " flv=$flv olv=$olv"
1640 error "write update OST layout failed $flv/$olv"
1643 run_test 36d "write/punch FLR file update OST layout version"
1649 echo "create test files with size $fsize .."
1653 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1655 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1656 $TRUNCATE $tf $fsize
1662 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1663 skip "Need MDS version at least 2.11.57"
1665 local tf=$DIR/$tfile
1666 local tf2=$DIR/$tfile-2
1667 local tf3=$DIR/$tfile-3
1668 local tf4=$DIR/$tfile-4
1670 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1672 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1675 # assume the mirror id will be 1, 2, and 3
1676 declare -A checksums
1677 checksums[1]=$(cat $tf | md5sum)
1678 checksums[2]=$(cat $tf2 | md5sum)
1679 checksums[3]=$(cat $tf3 | md5sum)
1681 printf '%s\n' "${checksums[@]}"
1683 # merge these files into a mirrored file
1684 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1685 error "merging $tf2 into $tf failed"
1686 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1687 error "merging $tf3 into $tf failed"
1691 # verify mirror read, checksums should equal to the original files'
1692 echo "Verifying mirror read .."
1695 for i in "${mirror_array[@]}"; do
1696 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1697 sum=$($LFS mirror read -N $i $tf | md5sum)
1698 [ "$sum" = "${checksums[$i]}" ] ||
1699 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1702 # verify mirror write
1703 echo "Verifying mirror write .."
1704 $LFS mirror write -N2 $tf < $tf4
1706 sum=$($LFS mirror read -N2 $tf | md5sum)
1707 [[ "$sum" = "${checksums[1]}" ]] ||
1708 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1710 # verify mirror copy, write to this mirrored file will invalidate
1711 # the other two mirrors
1712 echo "Verifying mirror copy .."
1714 local osts=$(comma_list $(osts_nodes))
1716 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1717 error "mirror copy error"
1719 # verify copying is successful by checking checksums
1720 remount_client $MOUNT
1721 for i in "${mirror_array[@]}"; do
1722 sum=$($LFS mirror read -N $i $tf | md5sum)
1723 [ "$sum" = "${checksums[1]}" ] ||
1724 error "$i: mismatch checksum after copy \'$sum\'"
1729 run_test 37 "mirror I/O API verification"
1732 local tf=$DIR/$tfile
1733 local ref=$DIR/${tfile}-ref
1735 stack_trap "rm -f $tf $ref"
1737 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1738 error "creating $tf failed"
1739 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1740 $tf-2 || error "creating $tf-2 failed"
1741 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1742 error "creating $tf-3 failed"
1744 # instantiate all components
1745 $LFS mirror extend -N -f $tf-2 $tf ||
1746 error "merging $tf-2 into $tf failed"
1747 $LFS mirror extend -N -f $tf-3 $tf ||
1748 error "merging $tf-3 into $tf failed"
1749 $LFS mirror extend -N -c 1 $tf ||
1750 error "extending mirrored file $tf failed"
1752 verify_flr_state $tf "ro"
1754 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1756 local fsize=$((RANDOM << 8 + 1048576))
1757 $TRUNCATE $ref $fsize
1759 local ref_cksum=$(cat $ref | md5sum)
1761 # case 1: verify write to mirrored file & resync work
1762 cp $ref $tf || error "copy from $ref to $f error"
1763 verify_flr_state $tf "wp"
1765 local file_cksum=$(cat $tf | md5sum)
1766 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1769 echo "mirror IDs: ${mirror_array[*]}"
1771 local valid_mirror stale_mirror id mirror_cksum
1772 for id in "${mirror_array[@]}"; do
1773 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1774 [ "$ref_cksum" == "$mirror_cksum" ] &&
1775 { valid_mirror=$id; continue; }
1780 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1781 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1783 $LFS mirror resync $tf || error "resync failed"
1784 verify_flr_state $tf "ro"
1786 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1787 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1789 # case 2: inject an error to make mirror_io exit after changing
1790 # the file state to sync_pending so that we can start a concurrent
1792 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1793 verify_flr_state $tf "wp"
1795 mirror_io resync -e resync_start $tf && error "resync succeeded"
1796 verify_flr_state $tf "sp"
1798 # from sync_pending to write_pending
1799 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1800 verify_flr_state $tf "wp"
1802 mirror_io resync -e resync_start $tf && error "resync succeeded"
1803 verify_flr_state $tf "sp"
1805 # from sync_pending to read_only
1806 $LFS mirror resync $tf || error "resync failed"
1807 verify_flr_state $tf "ro"
1809 run_test 38 "resync"
1812 local tf=$DIR/$tfile
1815 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1816 error "create PFL file $tf failed"
1818 verify_mirror_count $tf 2
1819 verify_comp_count $tf 4
1821 rm -f $tf || error "delete $tf failed"
1823 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1826 local tf=$DIR/$tfile
1829 for ops in "conv=notrunc" ""; do
1832 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1833 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1834 error "create PFLR file $tf failed"
1835 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1836 error "write PFLR file $tf failed"
1838 lfs getstripe -vy $tf
1842 # file mirror state should be write_pending
1843 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1845 error "file mirror state $flags"
1846 # the 1st component (in mirror 1) should be inited
1847 verify_comp_attr lcme_flags $tf 0x10001 init
1848 # the 2nd component (in mirror 1) should be inited
1849 verify_comp_attr lcme_flags $tf 0x10002 init
1850 # the 3rd component (in mirror 1) should be uninited
1851 verify_comp_attr lcme_flags $tf 0x10003 prefer
1852 # the 4th component (in mirror 2) should be inited
1853 verify_comp_attr lcme_flags $tf 0x20004 init
1854 # the 5th component (in mirror 2) should be uninited
1855 verify_comp_attr lcme_flags $tf 0x20005 0
1856 # the 6th component (in mirror 2) should be stale
1857 verify_comp_attr lcme_flags $tf 0x20006 stale
1858 # the 7th component (in mirror 2) should be uninited
1859 if [[ x$ops = "xconv=notrunc" ]]; then
1860 verify_comp_attr lcme_flags $tf 0x20007 0
1861 elif [[ x$ops = "x" ]]; then
1862 verify_comp_attr lcme_flags $tf 0x20007 stale
1866 rm -f $tf || error "delete $tf failed"
1868 run_test 40 "PFLR rdonly state instantiation check"
1871 local tf=$DIR/$tfile
1873 stack_trap "rm -f $tf $tf-1"
1876 echo " **create two FLR files $tf $tf-1"
1877 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1878 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1879 error "create PFLR file $tf failed"
1880 $LFS mirror create -N -E 2M -S 1M -E eof \
1881 -N -E 1M -E eof --flags prefer \
1882 -N -E 4m -E eof $tf-1 ||
1883 error "create PFLR file $tf-1 failed"
1885 # file should be in ro status
1886 echo " **verify files be RDONLY"
1887 verify_flr_state $tf "ro"
1888 verify_flr_state $tf-1 "ro"
1890 # write data in [0, 2M)
1891 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1892 error "writing $tf failed"
1893 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1894 error "writing $tf-1 failed"
1896 local sum0=$(cat $tf-1 | md5sum)
1898 echo " **verify files be WRITE_PENDING"
1899 verify_flr_state $tf "wp"
1900 verify_flr_state $tf-1 "wp"
1902 # file should have stale component
1903 echo " **verify files have stale component"
1904 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1905 error "after writing $tf, it does not contain stale component"
1906 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1907 error "after writing $tf-1, it does not contain stale component"
1909 echo " **full resync"
1910 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1912 echo " **verify $tf-1 data consistency in all mirrors"
1914 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1915 [[ "$sum" = "$sum0" ]] ||
1916 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1919 echo " **verify files be RDONLY"
1920 verify_flr_state $tf "ro"
1921 verify_flr_state $tf-1 "ro"
1923 # file should not have stale component
1924 echo " **verify files do not contain stale component"
1925 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1926 error "after resyncing $tf, it contains stale component"
1927 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1928 error "after resyncing $tf, it contains stale component"
1930 # verify partial resync
1931 echo " **write $tf-1 for partial resync test"
1932 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1933 error "writing $tf-1 failed"
1935 echo " **only resync mirror 2"
1936 verify_flr_state $tf-1 "wp"
1937 $LFS mirror resync --only 2 $tf-1 ||
1938 error "resync mirror 2 of $tf-1 failed"
1939 verify_flr_state $tf "ro"
1941 # resync synced mirror
1942 echo " **resync mirror 2 again"
1943 $LFS mirror resync --only 2 $tf-1 ||
1944 error "resync mirror 2 of $tf-1 failed"
1945 verify_flr_state $tf "ro"
1946 echo " **verify $tf-1 contains stale component"
1947 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1948 error "after writing $tf-1, it does not contain stale component"
1950 echo " **full resync $tf-1"
1951 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1952 verify_flr_state $tf "ro"
1953 echo " **full resync $tf-1 again"
1954 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1955 echo " **verify $tf-1 does not contain stale component"
1956 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1957 error "after resyncing $tf, it contains stale component"
1961 run_test 41 "lfs mirror resync check"
1964 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1968 local mirror_cmd="$LFS mirror verify"
1971 stack_trap "rm -rf $td"
1973 # create parent directory
1974 mkdir $td || error "mkdir $td failed"
1976 $mirror_cmd &> /dev/null && error "no file name given"
1977 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1978 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1980 # create mirrored files
1981 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1982 error "create mirrored file $tf failed"
1983 $LFS mirror create -N -E 2M -S 1M -E EOF \
1984 -N -E 6M -E 8M -E EOF \
1985 -N -E 16M -E EOF $tf-1 ||
1986 error "create mirrored file $tf-1 failed"
1987 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1988 error "create mirrored file $tf-2 failed"
1990 # write data in [0, 10M)
1991 for i in $tf $tf-1 $tf-2; do
1992 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1993 error "write $i failed"
1996 # resync the mirrored files
1997 $LFS mirror resync $tf-1 $tf-2 ||
1998 error "resync $tf-1 $tf-2 failed"
2000 # verify the mirrored files
2001 $mirror_cmd $tf-1 $tf-2 ||
2002 error "verify $tf-1 $tf-2 failed"
2004 get_mirror_ids $tf-1
2005 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2006 error "at least 2 mirror ids needed with '--only' option"
2007 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2009 error "'--only' option cannot be used upon multiple files"
2010 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2011 error "invalid specified mirror ids"
2013 # change the content of $tf and merge it into $tf-1
2015 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2016 error "change $tf with seek=$i failed"
2017 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2018 error "change $tf-1 with seek=$i failed"
2021 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2022 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2023 error "merge $tf into $tf-1 failed"
2025 # verify the mirrored files
2026 echo "Verify $tf-1 without -v option:"
2027 $mirror_cmd $tf-1 &&
2028 error "verify $tf-1 should fail" || echo "PASS"
2030 echo "Verify $tf-1 with -v option:"
2031 $mirror_cmd -v $tf-1 &&
2032 error "verify $tf-1 should fail"
2034 get_mirror_ids $tf-1
2035 echo "Verify $tf-1 with --only option:"
2036 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2037 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2038 "${mirror_array[-1]} should fail"
2040 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2041 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2042 "${mirror_array[1]} should succeed"
2044 # set stale components in $tf-1
2045 for i in 0x40002 0x40003; do
2046 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2047 error "set stale flag on component $i failed"
2050 # verify the mirrored file
2051 echo "Verify $tf-1 with stale components:"
2052 $mirror_cmd -vvv $tf-1 ||
2053 error "verify $tf-1 with stale components should succeed"
2055 echo "Verify $tf-1 with stale components and --only option:"
2056 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2057 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2058 "${mirror_array[-1]} should succeed"
2060 run_test 42 "lfs mirror verify"
2062 # inactivate one OST && write && restore the OST
2066 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2069 wait=$(do_facet $SINGLEMDS \
2070 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2071 wait=${wait%%[^0-9]*}
2073 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2074 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2075 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2076 sleep $(($wait * 2 + 2))
2077 echo " **write $file"
2078 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2079 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2080 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2081 sleep $((wait * 2 + 2))
2083 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2084 [ $flags = wp ] || error "file mirror state $flags != wp"
2088 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2090 local tf=$DIR/$tfile
2093 stack_trap "rm -f $tf"
2095 ## mirror 0 ost (0, 1)
2096 ## mirror 1 ost (1, 2)
2097 ## mirror 2 ost (2, 0)
2098 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2099 -N -Eeof -c2 -o2,0 $tf ||
2100 error "create 3 mirrors file $tf failed"
2102 ################## OST0 ###########################################
2104 echo " **verify components"
2105 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2106 verify_comp_attr lcme_flags $tf 0x20002 init
2107 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2110 echo " **resync $tf"
2111 $LFS mirror resync $tf
2112 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2113 [ $flags = ro ] || error "file mirror state $flags != ro"
2115 ################## OST1 ###########################################
2117 echo " **verify components"
2118 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2119 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2120 verify_comp_attr lcme_flags $tf 0x30003 init
2123 echo " **resync $tf"
2124 $LFS mirror resync $tf
2125 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2126 [ $flags = ro ] || error "file mirror state $flags != ro"
2128 ################## OST2 ###########################################
2130 echo " **verify components"
2131 verify_comp_attr lcme_flags $tf 0x10001 init
2132 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2133 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2135 run_test 43a "mirror pick on write"
2138 local tf=$DIR/$tdir/$tfile
2140 test_mkdir $DIR/$tdir
2142 stack_trap "rm -rf $tf"
2144 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2145 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2146 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2147 verify_flr_state $tf "ro"
2149 echo " ** write to $tf"
2150 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2151 verify_flr_state $tf "wp"
2153 echo " ** resync $tf"
2154 $LFS mirror resync $tf || error "resync $tf failed"
2155 verify_flr_state $tf "ro"
2157 run_test 43b "allow writing to multiple preferred mirror file"
2160 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2163 local tf=$DIR/$tdir/$tfile
2164 local tf1=$DIR/$tdir-1/$tfile-1
2166 stack_trap "rm -rf $tf $tf1"
2168 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2169 error "create directory failed"
2170 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2171 error "create remote directory failed"
2172 rm -f $tf $tf1 $tf.mirror~2
2173 # create file with 4 mirrors
2174 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2175 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2176 error "create PFLR file $tf failed"
2178 # file should be in ro status
2179 verify_flr_state $tf "ro"
2181 # write data in [0, 3M)
2182 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2183 error "writing $tf failed"
2185 verify_flr_state $tf "wp"
2187 # disallow destroying the last non-stale mirror
2188 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2189 error "destroying mirror 1 should fail"
2191 # synchronize all mirrors of the file
2192 $LFS mirror resync $tf || error "mirror resync $tf failed"
2194 verify_flr_state $tf "ro"
2197 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2198 error "split to $tf1 failed"
2200 local idx0=$($LFS getstripe -m $tf)
2201 local idx1=$($LFS getstripe -m $tf1)
2203 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2204 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2206 # verify mirror count
2207 verify_mirror_count $tf 3
2208 verify_mirror_count $tf1 1
2210 $LFS mirror split --mirror-id 2 $tf ||
2211 error "split mirror 2 failed"
2213 verify_mirror_count $tf 2
2214 verify_mirror_count $tf.mirror~2 1
2216 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2217 error "setting stale flag on component 0x30008 failed"
2219 # disallow destroying the last non-stale mirror
2220 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2221 error "destroying mirror 4 should fail"
2223 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2225 $LFS mirror split --mirror-id 3 -d $tf ||
2226 error "destroying mirror 3 failed"
2227 verify_mirror_count $tf 1
2229 # verify splitted file contains the same content as the orig file does
2230 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2231 diff $tf $tf.mirror~2 ||
2232 error "splited file $tf.mirror~2 diffs from $tf"
2234 run_test 44a "lfs mirror split check"
2237 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2238 skip "Need MDS version at least 2.14.56"
2241 local tf=$DIR/$tdir/$tfile
2243 mkdir -p $DIR/$tdir || error "create directory failed"
2247 # create 2 mirrors file
2248 $LFS mirror extend -N -c1 $tf
2252 verify_flr_state $tf "wp"
2254 local str=$(cat $tf)
2256 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2258 # get the non-stale mirror id
2259 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2261 local mirror_ids=($($LFS getstripe $tf |
2262 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2263 for ((i = 0; i < 2; i++)); do
2264 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2265 grep stale > /dev/null || break
2268 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2272 # split the updated mirror, should fail
2273 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2274 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2275 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2278 # split the stale mirror
2279 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2280 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2281 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2283 echo "make sure there's no stale comp in the file"
2284 # make sure there's no stale comp in the file
2285 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2286 ( $LFS getstripe $tf; error "stale mirror file" )
2289 [[ $str == "YYY" ]] ||
2290 ( cat $tf; error "$tf content is not YYY after split" )
2292 run_test 44b "mirror split does not create stale file"
2295 local tf=$DIR/$tdir/$tfile
2297 stack_trap "rm -f $tf"
2299 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2300 skip "Need MDS version at least 2.14.52"
2302 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2304 mkdir -p $DIR/$tdir || error "create directroy failed"
2306 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2308 block1=$(( $(stat -c "%b*%B" $tf) ))
2309 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2311 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2313 block2=$(( $(stat -c "%b*%B" $tf) ))
2314 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2316 $LFS mirror split -d --mirror-id=2 $tf ||
2317 error "mirror split $tfile failed"
2318 $LFS mirror split -d --mirror-id=3 $tf ||
2319 error "mirror split $tfile failed"
2322 block3=$(( $(stat -c "%b*%B" $tf) ))
2323 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2325 [[ $block1 -eq $block3 ]] ||
2326 error "mirror split does not reduce block# $block3 != $block1"
2328 run_test 44c "lfs mirror split reduces block size of a file"
2331 local tf=$DIR/$tdir/$tfile
2337 stack_trap "rm -f $tf"
2339 mkdir -p $DIR/$tdir || error "create directroy failed"
2341 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2343 size1=$(stat -c "%s" $tf)
2344 echo " ** before mirror ops, file size=$size1"
2346 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2348 size2=$(stat -c "%s" $tf)
2349 echo " ** after mirror extend, file size=$size2"
2351 (($size1 == $size2)) ||
2352 error "mirror extend should not change size, before: $size1, after $size2"
2354 $LFS mirror split -d --mirror-id=2 $tf ||
2355 error "mirror split $tfile failed"
2357 size2=$(stat -c "%s" $tf)
2358 echo " ** after mirror split, file size=$size2"
2359 (($size1 == $size2)) ||
2360 error "mirror split should not change size, before: $size1, after $size2"
2362 # Remount client to clear cached size information
2363 remount_client $MOUNT
2364 size2=$(stat -c "%s" $tf)
2365 echo " ** after mirror split & remount, file size=$size2"
2366 (($size1 == $size2)) ||
2367 error "mirror extend should not change size, before: $size1, after $size2"
2370 run_test 44d "lfs mirror split does not break size"
2373 local tf=$DIR/$tdir/$tfile
2374 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2378 test_mkdir $DIR/$tdir
2379 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2380 skip "Need MDS version at least 2.14.52"
2382 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2384 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2385 $LCTL set_param llite.*.xattr_cache=0
2386 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2387 stack_trap "rm -rf $tf"
2389 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2391 size1=$(stat -c "%s" $tf)
2392 echo " ** before mirror resync, file size=$size1"
2394 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2395 size1=$(stat -c "%s" $tf)
2396 size2=$($LFS getsom -s $tf)
2400 ((size1 == size2)) ||
2401 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2403 # Remount client to clear cached size information
2404 remount_client $MOUNT
2406 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2407 stack_trap "restore_lustre_params < $p; rm -f $p"
2408 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2410 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2412 size2=$(stat -c "%s" $tf)
2413 # 'getsom' here is just for debugging
2416 ((size2 == size1)) ||
2417 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2419 run_test 44e "basic FLR SOM tests + disable SOM"
2422 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2424 local file=$DIR/$tdir/$tfile
2425 local dir=$DIR/$tdir/$dir
2426 local temp=$DIR/$tdir/template
2428 test_mkdir $DIR/$tdir
2430 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2431 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2432 error "Create $file failed"
2434 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2435 rm -f $file $file.copy
2437 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2438 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2439 error "Create $file failed"
2441 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2443 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2450 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2452 local layout1=$(get_layout_param $src)
2453 local layout2=$(get_layout_param $dst)
2454 # compare their layout info
2455 [ "$layout1" == "$layout2" ] ||
2456 error "$msg_prefix $src <=> $dst layouts are not equal"
2460 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2462 local file=$DIR/$tdir/$tfile
2463 test_mkdir $DIR/$tdir
2465 ########################### 1. PFL file #############################
2466 echo " ** 1. PFL file"
2468 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2469 $file || error "1. Create PFL $file failed"
2472 verify_46 $file $file.copy "1. PFL file"
2474 ########################### 2. plain file ###########################
2475 echo " ** 2. plain file"
2477 $LFS setstripe -c2 -o0,1 -i1 $file ||
2478 error "2. Create plain $file failed"
2481 verify_46 $file $file.copy "2. plain file"
2483 ########################### 3. FLR file #############################
2484 echo " ** 3. FLR file"
2486 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2487 $file || error "3. Create FLR $file failed"
2490 verify_46 $file $file.copy "3. FLR file"
2492 local dir=$DIR/$tdir/dir
2493 ########################### 4. PFL dir ##############################
2494 echo " ** 4. PFL dir"
2496 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2497 error "4. setstripe PFL $dir failed"
2499 test_mkdir $dir.copy
2500 verify_46 $dir $dir.copy "4. PFL dir"
2502 ########################### 5. plain dir ############################
2503 echo " ** 5. plain dir"
2504 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2506 verify_46 $dir $dir.copy "5. plain dir"
2508 ########################### 6. FLR dir ##############################
2509 echo " ** 6. FLR dir"
2510 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2511 error "6. setstripe FLR $dir failed"
2513 verify_46 $dir $dir.copy "6. FLR dir"
2515 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2516 echo "server version $MDS1_VERSION does not support SEL" &&
2519 ########################### 7. SEL file ##############################
2520 echo " ** 7. SEL file"
2522 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2523 $file || error "Create $file failed"
2526 verify_46 $file $file.copy "7. SEL file"
2528 ########################### 8. SEL dir ##############################
2529 echo " ** 8. SEL dir"
2530 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2531 $dir || error "setstripe $dir failed"
2533 verify_46 $dir $dir.copy "8. SEL dir"
2535 ########################### 9. FLR SEL file ##########################
2536 echo " ** 9. FLR SEL file"
2538 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2539 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2542 verify_46 $file $file.copy "9. SEL file"
2544 ########################### 10. FLR SEL dir #########################
2545 echo " ** 10. FLR SEL dir"
2546 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2547 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2549 verify_46 $dir $dir.copy "10. SEL dir"
2551 run_test 46 "Verify setstripe --copy option"
2554 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2556 local file=$DIR/$tdir/$tfile
2561 test_mkdir $DIR/$tdir
2562 stack_trap "rm -f $file"
2566 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2567 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2568 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2569 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2570 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2572 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2573 $LFS mirror resync $file || error "resync $file failed"
2575 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2576 if [[ x$ost == "x0," ]]; then
2577 $LFS getstripe $file
2578 error "component ${ids[2]} objects allocated on $ost " \
2582 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2583 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2584 $LFS getstripe $file
2585 error "component ${ids[3]} objects allocated on $ost " \
2586 "shouldn't on OST1 or on OST2"
2591 # mirror1: [comp0] [comp1]
2592 # mirror2: [comp2] [comp3]
2593 # mirror3: [comp4] [comp5]
2594 # mirror4: [comp6] [comp7]
2595 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2596 error "create FLR $file failed"
2597 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2599 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2600 $LFS mirror resync $file || error "resync $file failed"
2602 for ((i = 0; i < 6; i++)); do
2603 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2604 awk '/l_ost_idx/{print $5}')
2606 # comp[0],comp[2],comp[4] should use different osts
2607 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2608 ${osts[2]} == ${osts[4]} ]]; then
2609 $LFS getstripe $file
2610 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2611 "allocated on duplicated OSTs"
2613 # comp[1],comp[3],comp[5] should use different osts
2614 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2615 ${osts[3]} == ${osts[5]} ]]; then
2616 $LFS getstripe $file
2617 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2618 "allocated on duplicated OSTs"
2623 run_test 47 "Verify mirror obj alloc"
2626 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2627 skip "Need MDS version at least 2.11.55"
2629 local tf=$DIR/$tfile
2631 stack_trap "rm -f $tf"
2633 echo " ** create 2 mirrors FLR file $tf"
2634 $LFS mirror create -N -E2M -Eeof --flags prefer \
2635 -N -E1M -Eeof $tf ||
2636 error "create FLR file $tf failed"
2639 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2640 verify_flr_state $tf "wp"
2642 local sum0=$(md5sum < $tf)
2644 echo " ** resync the file"
2645 $LFS mirror resync $tf
2647 echo " ** snapshot mirror 2"
2648 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2650 echo " ** write it again"
2651 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2652 echo " ** resync it again"
2653 $LFS mirror resync $tf
2655 verify_flr_state $tf "wp"
2656 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2658 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2659 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2661 echo " ** verify mirror 2 doesn't change"
2662 echo "original checksum: $sum0"
2663 echo "mirror 1 checksum: $sum1"
2664 echo "mirror 2 checksum: $sum2"
2665 [[ $sum0 = $sum2 ]] ||
2666 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2667 echo " ** mirror 2 stripe info"
2668 $LFS getstripe -v --mirror-index=2 $tf
2670 echo " ** resync mirror 2"
2671 $LFS mirror resync --only 2 $tf
2673 verify_flr_state $tf "ro"
2674 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2676 sum1=$($LFS mirror read -N1 $tf | md5sum)
2677 sum2=$($LFS mirror read -N2 $tf | md5sum)
2679 echo " ** verify mirror 2 resync-ed"
2680 echo "original checksum: $sum0"
2681 echo "mirror 1 checksum: $sum1"
2682 echo "mirror 2 checksum: $sum2"
2683 [[ $sum1 = $sum2 ]] ||
2684 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2685 echo " ** mirror 2 stripe info"
2686 $LFS getstripe -v --mirror-index=2 $tf
2688 run_test 48 "Verify snapshot mirror"
2697 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2698 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2699 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2700 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2701 skip "LU-1941: FIEMAP unimplemented on ZFS"
2703 trap cleanup_49 EXIT RETURN
2705 local file=$DIR/$tfile
2707 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2708 error "setstripe on $file"
2709 stack_trap "rm -f $file"
2711 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2712 $LFS mirror resync $file
2714 filefrag -ves $file || error "filefrag $file failed"
2715 filefrag_op=$(filefrag -ve -k $file |
2716 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2718 #Filesystem type is: bd00bd0
2719 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2720 # ext: device_logical: physical_offset: length: dev: flags:
2721 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2722 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2723 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2725 last_lun=$(echo $filefrag_op | cut -d: -f5)
2729 for line in $filefrag_op; do
2730 frag_lun=$(echo $line | cut -d: -f5)
2731 ext_len=$(echo $line | cut -d: -f4)
2732 if [[ "$frag_lun" != "$last_lun" ]]; then
2733 if (( tot_len != 1024 )); then
2735 error "$file: OST$last_lun $tot_len != 1024"
2741 (( tot_len += ext_len ))
2744 if (( num_luns != 2 || tot_len != 1024 )); then
2746 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2749 echo "FIEMAP on $file succeeded"
2751 run_test 49a "FIEMAP upon FLR file"
2753 test_50A() { # EX-2179
2756 local file=$DIR/$tdir/$tfile
2758 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2760 $LFS mirror extend -N -c1 -i1 $file ||
2761 error "extending mirror for $file failed"
2763 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2767 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2769 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2771 echo "$file layout generation from $olv to $flv"
2772 (( $flv != ($olv + 1) )) &&
2773 error "split does not increase layout gen from $olv to $flv"
2775 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2777 $LFS getstripe -v $file || error "getstripe $file failed"
2779 run_test 50A "mirror split update layout generation"
2782 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2783 skip "OST does not support SEEK_HOLE"
2784 [ "$FSTYPE" != "zfs" ] ||
2785 skip "lseek for ZFS is not accurate if obj is not committed"
2787 local file=$DIR/$tdir/$tfile
2795 echo " ** create striped file $file"
2796 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2797 error "cannot create file with PFL layout"
2798 echo " ** write 1st data chunk at 1M boundary"
2799 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2800 error "cannot write data at 1M boundary"
2801 echo " ** write 2nd data chunk at 2M boundary"
2802 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2803 error "cannot write data at 2M boundary"
2804 echo " ** create hole at the file end"
2805 $TRUNCATE $file 3700000 || error "truncate fails"
2807 echo " ** verify sparseness"
2808 offset=$(lseek_test -d 1000 $file)
2809 echo " first data offset: $offset"
2810 [[ $offset == 1000 ]] &&
2811 error "src: data is not expected at offset $offset"
2812 offset=$(lseek_test -l 3500000 $file)
2813 echo " hole at the end: $offset"
2814 [[ $offset == 3500000 ]] ||
2815 error "src: hole is expected at offset $offset"
2817 echo " ** extend the file with new mirror"
2818 # migrate_copy_data() is used
2819 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2820 error "cannot create mirror"
2821 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2822 error "$file still has stale component"
2824 # check migrate_data_copy() was correct
2825 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2826 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2827 [[ $sum_1 == $sum_2 ]] ||
2828 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2830 # stale first mirror
2831 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2832 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2834 echo " ** verify mirror #2 sparseness"
2835 offset=$(lseek_test -d 1000 $file)
2836 echo " first data offset: $offset"
2837 [[ $offset == 1000 ]] &&
2838 error "dst: data is not expected at offset $offset"
2839 offset=$(lseek_test -l 3500000 $file)
2840 echo " hole at the end: $offset"
2841 [[ $offset == 3500000 ]] ||
2842 error "dst: hole is expected at offset $offset"
2844 echo " ** copy mirror #2 to mirror #1"
2845 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2846 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2847 error "$file still has stale component"
2849 # check llapi_mirror_copy_many correctness
2850 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2851 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2852 [[ $sum_1 == $sum_2 ]] ||
2853 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2855 # stale 1st component of mirror #2 before lseek call
2856 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2858 echo " ** verify mirror #1 sparseness again"
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 cancel_lru_locks osc
2870 blocks=$(stat -c%b $file)
2871 echo " ** final consumed blocks: $blocks"
2872 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2873 # that file is still sparse
2874 (( blocks < 1000 )) ||
2875 error "Mirrored file consumes $blocks blocks"
2877 run_test 50a "mirror extend/copy preserves sparseness"
2880 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2881 skip "OST does not support SEEK_HOLE"
2882 [ "$FSTYPE" != "zfs" ] ||
2883 skip "lseek for ZFS is not accurate if obj is not committed"
2885 local file=$DIR/$tdir/$tfile
2892 stack_trap "rm -f $file"
2894 echo " ** create mirrored file $file"
2895 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2896 -N -E2M -S1M -E eof -S2M $file ||
2897 error "cannot create mirrored file"
2898 echo " ** write data chunk at 1M boundary"
2899 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2900 error "cannot write data at 1M boundary"
2901 echo " ** create hole at the file end"
2902 $TRUNCATE $file 3700000 || error "truncate fails"
2904 echo " ** verify sparseness"
2905 offset=$(lseek_test -d 1000 $file)
2906 echo " first data offset: $offset"
2907 [[ $offset == 1000 ]] &&
2908 error "src: data is not expected at offset $offset"
2909 offset=$(lseek_test -l 3500000 $file)
2910 echo " hole at the end: $offset"
2911 [[ $offset == 3500000 ]] ||
2912 error "src: hole is expected at 3500000"
2914 echo " ** resync mirror #2 to mirror #1"
2915 $LFS mirror resync $file
2917 # check llapi_mirror_copy_many correctness
2918 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2919 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2920 [[ $sum_1 == $sum_2 ]] ||
2921 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2923 cancel_lru_locks osc
2925 blocks=$(stat -c%b $file)
2926 echo " ** consumed blocks: $blocks"
2927 # without full punch() support the first component can be not sparse
2928 # but the last one should be, so file should use far fewer blocks
2929 (( blocks < 5000 )) ||
2930 error "Mirrored file consumes $blocks blocks"
2932 # stale first component in mirror #1
2933 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2934 echo " ** truncate file down"
2936 echo " ** write data chunk at 2M boundary"
2937 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2938 error "cannot write data at 2M boundary"
2939 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2940 $LFS mirror resync $file || error "mirror rsync fails"
2941 # first component is still stale
2942 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2943 error "$file still has no stale component"
2944 echo " ** resync mirror #2 to mirror #1 again"
2945 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2946 $LFS mirror resync $file || error "mirror rsync fails"
2947 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2948 error "$file still has stale component"
2950 # check llapi_mirror_copy_many correctness
2951 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2952 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2953 [[ $sum_1 == $sum_2 ]] ||
2954 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2956 cancel_lru_locks osc
2958 blocks=$(stat -c%b $file)
2959 echo " ** final consumed blocks: $blocks"
2960 # while the first component can lose sparseness, the last one should
2961 # not, so whole file should still use far fewer blocks in total
2962 (( blocks < 3000 )) ||
2963 error "Mirrored file consumes $blocks blocks"
2965 run_test 50b "mirror rsync handles sparseness"
2968 local tf=$DIR/$tdir/$tfile
2970 test_mkdir $DIR/$tdir
2972 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
2973 verify_flr_state $tf "ro"
2975 if [[ "$FSTYPE" == "ldiskfs" ]]; then
2976 # ZFS does not support fallocate for now
2977 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
2978 skip_eopnotsupp "$out|punch hole in $tf failed"
2979 verify_flr_state $tf "wp"
2982 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
2983 $LFS mirror resync $tf || error "mirror resync $tf failed"
2984 verify_flr_state $tf "ro"
2986 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
2987 verify_flr_state $tf "wp"
2989 run_test 50c "punch_hole/mmap_write stale other mirrors"
2992 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2993 skip "OST does not support SEEK_HOLE"
2994 [ "$FSTYPE" != "zfs" ] ||
2995 skip "lseek for ZFS is not accurate if obj is not committed"
2997 local file=$DIR/$tdir/$tfile
3004 echo " ** create mirrored file $file"
3005 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3006 -N -E2M -S1M -E eof -S2M $file ||
3007 error "cannot create mirrored file"
3008 echo " ** write data chunk at 1M boundary"
3009 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3010 error "cannot write data at 1M boundary"
3011 echo " ** create hole at the file start"
3012 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3015 if [[ $rc -eq 0 ]]; then
3016 verify_flr_state $file "wp"
3017 elif [[ ! $prt =~ unsupported ]]; then
3018 error "punch hole in $file failed: $prt"
3020 skip "Fallocate punch is not supported: $prt"
3023 echo " ** verify sparseness"
3024 offset=$(lseek_test -d 1000 $file)
3025 echo " first data offset: $offset"
3026 (( $offset >= 1024 * 1024 )) ||
3027 error "src: data is not expected at offset $offset"
3029 echo " ** resync mirror #2"
3030 $LFS mirror resync $file
3032 # check llapi_mirror_copy_many correctness
3033 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3034 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3035 [[ $sum_1 == $sum_2 ]] ||
3036 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3038 cancel_lru_locks osc
3040 # stale first component in mirror #1
3041 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3042 echo " ** verify sparseness of mirror #2"
3043 offset=$(lseek_test -d 1000 $file)
3044 echo " first data offset: $offset"
3045 (( $offset >= 1024 * 1024 )) ||
3046 error "src: data is not expected at offset $offset"
3048 run_test 50d "mirror rsync keep holes"
3051 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3052 skip "OST does not support SEEK_HOLE"
3054 local file=$DIR/$tdir/$tfile
3055 local old_size=2147483648 # 2GiB
3059 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3060 $TRUNCATE $file $old_size
3062 $LFS mirror extend -N -c 1 $file
3063 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3064 $LFS mirror resync $file
3066 new_size=$(stat --format='%s' $file)
3067 if ((new_size != old_size)); then
3068 error "new_size ($new_size) is not equal to old_size ($old_size)"
3071 run_test 60a "mirror extend sets correct size on sparse file"
3073 get_flr_layout_gen() {
3074 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3075 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3078 check_layout_gen() {
3081 local v1=$(get_flr_layout_gen $tf)
3082 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3084 [[ $v1 -eq $v2 ]] ||
3085 error "$tf in-memory layout gen $v1 != $v2 after $2"
3089 local tf=$DIR/$tdir/$tfile
3091 test_mkdir $DIR/$tdir
3093 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3095 for ((i = 0; i < 20; i++)); do
3096 $LFS mirror extend -N $tf ||
3097 error "extending mirror for $tf failed"
3098 check_layout_gen $tf "extend"
3100 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3101 error "split $tf failed"
3102 check_layout_gen $tf "split"
3105 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3108 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3113 local -a old=( $2 $3 $4 )
3116 new=( $(get_times_61 $file) )
3117 ((${old[0]} == ${new[0]})) ||
3118 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3120 ((${old[1]} == ${new[1]})) ||
3121 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3124 test_61a() { # LU-14508
3125 local file=$DIR/$tdir/$tfile
3131 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3132 echo "create $file-2"
3133 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3135 echo XXX > $file || error "write $file failed"
3136 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3138 echo "sleep $nap seconds, then cat $tfile"
3140 cat $file || error "cat $file failed"
3142 echo "sleep $nap seconds, then re-write $tfile"
3144 echo XXXX > $file || error "write $file failed"
3145 cp -p $file $file-2 || error "copy $file-2 failed"
3147 echo "sleep $nap seconds"
3150 tim=( $(get_times_61 $file) )
3152 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3153 $LFS mirror extend -N -f $file-2 $file ||
3154 error "cannot mirror merge $file-2 to $file"
3155 check_times_61 $file "${tim[@]}"
3157 echo "mirror extend $tfile and test timestamps"
3158 $LFS mirror extend -N -c1 -i1 $file ||
3159 error "cannot extend mirror $file"
3160 check_times_61 $file "${tim[@]}"
3162 echo "migrate $tfile and test timestamps"
3163 $LFS migrate -n $file || error "cannot migrate $file"
3164 check_times_61 $file "${tim[@]}"
3166 echo "normal user migrate $tfile and test timestamps"
3167 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3168 check_times_61 $file "${tim[@]}"
3170 run_test 61a "mirror extend and migrate preserve timestamps"
3172 test_61b() { # LU-14508
3173 local file=$DIR/$tdir/$tfile
3179 echo XXX > $file || error "create $file failed"
3180 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3182 echo "sleep $nap seconds, then cat $tfile"
3184 cat $file || error "cat $file failed"
3186 echo "sleep $nap seconds, then re-write $tfile"
3188 echo XXXX > $file || error "write $file failed"
3190 echo "sleep $nap seconds, then test timestamps"
3193 tim=( $(get_times_61 $file) )
3195 echo "mirror extend $tfile and test timestamps"
3196 $LFS mirror extend -N -c1 -i1 $file ||
3197 error "cannot extend mirror $file"
3198 check_times_61 $file "${tim[@]}"
3200 echo "mirror split $tfile and test timestamps"
3201 $LFS mirror split -d --mirror-id=1 $file ||
3202 error "cannot split mirror 1 off $file"
3203 check_times_61 $file "${tim[@]}"
3205 echo "normal user mirror extend $tfile and test timestamps"
3206 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3207 error "cannot extend mirror $file"
3208 check_times_61 $file "${tim[@]}"
3210 run_test 61b "mirror extend and split preserve timestamps"
3212 test_61c() { # LU-14508
3213 local file=$DIR/$tdir/$tfile
3219 echo XXX > $file || error "create $file failed"
3220 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3222 echo "sleep $nap seconds, then cat $tfile"
3224 cat $file || error "cat $file failed"
3226 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3228 $LFS mirror extend -N -c1 -i1 $file ||
3229 error "cannot extend mirror $file"
3230 echo XXXX > $file || error "write $file failed"
3232 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3233 tim=( $(get_times_61 $file) )
3235 $LFS mirror resync $file || error "cannot resync mirror $file"
3236 check_times_61 $file "${tim[@]}"
3238 echo XXXXXX > $file || error "write $tfile failed"
3240 echo "normal user resync $tfile and test timestamps"
3241 tim=( $(get_times_61 $file) )
3242 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3243 check_times_61 $file "${tim[@]}"
3245 run_test 61c "mirror resync preserves timestamps"
3248 local file=$DIR/$tdir/$tfile
3252 echo "create mirror file with unknown magic"
3253 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3254 # mirror 2 in-memory magic is bad
3255 $LCTL set_param fail_loc=0x1426 fail_val=2
3256 $LFS setstripe -N --flags=prefer -N2 $file ||
3257 error "failed to create mirror file $file"
3258 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3259 [[ $magic == 0x0BAD0BD0 ]] ||
3260 error "mirror 2 magic $magic is not bad as expected"
3261 cat /etc/passwd > $file || error "cannot write to $file"
3262 diff /etc/passwd $file || error "read $file error"
3266 echo "create mirror file with unknown pattern"
3267 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3268 # mirror 1 in-memory pattern is bad
3269 $LCTL set_param fail_loc=0x1427 fail_val=1
3270 $LFS setstripe -N -N --flags=prefer $file ||
3271 error "failed to create mirror file $file"
3272 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3273 [[ $pattern == 502 ]] ||
3274 error "mirror 1 pattern $pattern is not bad as expected"
3275 cat /etc/passwd > $file || error "cannot write to $file"
3276 diff /etc/passwd $file || error "read $file error"
3278 run_test 62 "read/write with unknown type of mirror"
3281 local tf=$DIR/$tdir/$tfile
3283 test_mkdir $DIR/$tdir
3284 stack_trap "rm -f $tf"
3288 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3292 echo "mirror create pid $c_pid"
3295 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3298 echo "mirror split pid $s_pid"
3300 echo "mirror create and split race for 60 seconds, should not crash"
3302 kill -9 $c_pid &> /dev/null
3303 kill -9 $s_pid &> /dev/null
3307 run_test 70 "mirror create and split race"
3310 local tf=$DIR/$tdir/$tfile
3312 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3313 skip "Need OST version at least 2.14.51"
3316 test_mkdir $DIR/$tdir
3317 stack_trap "rm -f $tf"
3319 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3320 error "setstripe $tf failed"
3322 FSXNUM=${FSXNUM:-1000}
3323 $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3325 run_test 70a "flr mode fsx test"
3330 local fsize=$(stat --printf=%s $tf)
3332 while [ -f $ctrl_file ]; do
3333 local off=$((RANDOM << 8))
3334 local len=$((RANDOM << 5 + 131072))
3336 [ $((off + len)) -gt $fsize ] && {
3337 fsize=$((off + len))
3338 echo "Extending file size to $fsize .."
3341 flock -s $lock_file -c \
3342 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3344 error "failed writing to $off:$len"; }
3345 sleep 0.$((RANDOM % 2 + 1))
3352 while [ -f $ctrl_file ]; do
3353 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3354 { rm -f $ctrl_file; error "read failed"; }
3355 sleep 0.$((RANDOM % 2 + 1))
3362 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3364 exec 200<>$lock_file
3365 while [ -f $ctrl_file ]; do
3366 local lock_taken=false
3367 local index=$((RANDOM % ${#options[@]}))
3368 local cmd="mirror_io resync ${options[$index]}"
3370 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3372 [ $((RANDOM % 4)) -eq 0 ] && {
3378 echo -n "resync file $tf with '$cmd' .."
3380 if [[ $lock_taken = "true" ]]; then
3382 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3385 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3388 sleep 0.$((RANDOM % 8 + 1))
3392 # this was test_200 before adding "b" and "c" subtests
3394 local tf=$DIR/$tfile
3395 local tf2=$DIR2/$tfile
3396 local tf3=$DIR3/$tfile
3398 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3399 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3400 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3402 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3403 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3404 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3406 $LFS mirror extend -N -f $tf-2 $tf ||
3407 error "merging $tf-2 into $tf failed"
3408 $LFS mirror extend -N -f $tf-3 $tf ||
3409 error "merging $tf-3 into $tf failed"
3411 mkdir -p $MOUNT2 && mount_client $MOUNT2
3413 mkdir -p $MOUNT3 && mount_client $MOUNT3
3415 verify_flr_state $tf3 "ro"
3417 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3418 $LCTL set_param fail_loc=0x1A03
3420 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3421 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3425 write_file_200 $tf &
3431 write_file_200 $tf2 &
3434 read_file_200 $tf2 &
3437 resync_file_200 $tf3 &
3441 [ "$SLOW" = "yes" ] && sleep_time=360
3442 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3449 echo "Waiting ${pids[*]}"
3452 umount_client $MOUNT2
3453 umount_client $MOUNT3
3455 # resync and verify mirrors
3456 $LFS mirror resync $tf || error "final resync failed"
3459 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3461 for id in "${mirror_array[@]:1}"; do
3462 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3463 error "checksum error for mirror $id"
3468 run_test 200a "stress test"
3471 local tf=$DIR/$tfile
3472 local tf2=$DIR2/$tfile
3473 local tf3=$DIR3/$tfile
3475 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3476 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3477 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3479 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3480 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3481 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3483 $LFS mirror extend -N -f $tf-2 $tf ||
3484 error "merging $tf-2 into $tf failed"
3485 $LFS mirror extend -N -f $tf-3 $tf ||
3486 error "merging $tf-3 into $tf failed"
3488 mkdir -p $MOUNT2 && mount_client $MOUNT2
3490 mkdir -p $MOUNT3 && mount_client $MOUNT3
3492 verify_flr_state $tf3 "ro"
3494 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3495 $LCTL set_param fail_loc=0x1423
3499 write_file_200 $tf &
3505 write_file_200 $tf2 &
3508 read_file_200 $tf2 &
3511 resync_file_200 $tf3 &
3515 [ "$SLOW" = "yes" ] && sleep_time=400
3519 echo "Waiting ${pids[@]}"
3522 umount_client $MOUNT2
3523 umount_client $MOUNT3
3525 # resync and verify mirrors
3526 $LFS mirror resync $tf || {
3528 error "final resync failed"
3532 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3533 for id in ${mirror_array[@]:1}; do
3534 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3535 error "checksum error for mirror $id"
3540 run_test 200b "racing IO, mirror extend and resync"
3543 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3544 skip "Need MDS version at least 2.15.53"
3546 local tf=$DIR/$tfile
3547 local tf2=$DIR2/$tfile
3549 mkdir -p $MOUNT2 && mount_client $MOUNT2
3550 stack_trap "umount_client $MOUNT2"
3551 stack_trap "rm -f $tf"
3555 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3557 mdt_idx=$($LFS getstripe -m $tf)
3559 cancel_lru_locks mdc
3560 cancel_lru_locks osc
3562 # start a process modifying file, block it just
3563 # before layout lock acquisition
3564 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3565 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3566 #log "dd to stale replica"
3567 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3573 $LFS mirror extend -N -c -1 $tf2 || {
3575 error "can't mirror"
3577 log "mirror extend done"
3578 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3580 # wait for blocking dd to complete and modify file
3581 wait $PID || error "2nd dd failed"
3584 verify_mirror_count $tf 2
3586 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3589 error "both replicas are still in sync"
3592 $LFS mirror verify -vvv $tf || {
3594 error "corrupted in-sync file"
3597 run_test 200c "layout change racing with open: LOVEA changes"
3599 cleanup_test_201() {
3600 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3602 umount_client $MOUNT2
3606 local delay=${RESYNC_DELAY:-5}
3608 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3609 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3611 stack_trap cleanup_test_201 EXIT
3613 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3614 changelog_register -n)
3616 mkdir -p $MOUNT2 && mount_client $MOUNT2
3620 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3621 [ -z "$log" ] && { sleep 1; continue; }
3623 index=$(echo $log | awk '{print $1}')
3624 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3625 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3626 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3629 [ -z "$file" ] && continue
3631 local now=$(date +%s)
3633 echo "file: $file $fid was modified at $ts, now: $now, " \
3634 "will be resynced at $((ts+delay))"
3636 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3638 $LFS mirror resync $file
3639 echo "$file resync done"
3642 run_test 201 "FLR data mover"
3645 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3647 local tf=$DIR/$tfile
3650 $LFS setstripe -E 1M -S 1M -c 1 $tf
3651 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3652 verify_comp_attr stripe-count $tf ${ids[0]} 1
3654 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3655 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3656 verify_comp_attr stripe-count $tf ${ids[0]} 1
3657 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3659 dd if=/dev/zero of=$tf bs=1M count=2
3660 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3661 verify_comp_attr stripe-count $tf ${ids[0]} 1
3662 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3664 run_test 202 "lfs setstripe --add-component wide striping"
3667 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3668 skip "Need MDS version at least 2.11.55"
3669 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3671 local tf=$DIR/$tfile
3674 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3675 #delete first mirror
3676 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3679 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3680 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3681 error "getstripe count of mirror 2"
3682 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3684 #extend a mirror with 2 OSTs
3685 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3688 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3689 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3690 error "getstripe count of mirror 2"
3691 [[ x$old_id = x$new_id ]] ||
3692 error "mirror 2 changed ID from $old_id to $new_id"
3693 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3695 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3696 error "getstripe count of mirror 3"
3697 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3699 run_test 203 "mirror file preserve mirror ID"
3701 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3703 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3704 skip "skipped for lustre < $SEL_VER"
3706 local comp_file=$DIR/$tdir/$tfile
3710 test_mkdir $DIR/$tdir
3711 stack_trap "rm -f $comp_file"
3713 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3714 # by extension space to -1
3715 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3716 error "Create $comp_file failed"
3718 # Write to first component, extending & staling second mirror
3719 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3720 error "dd to extend + stale failed"
3722 $LFS getstripe $comp_file
3724 flg_opts="--component-flags init,stale"
3725 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3726 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3728 flg_opts="--component-flags extension"
3729 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3730 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3732 # mirror resync should not change the extents
3733 $LFS mirror resync $comp_file
3735 flg_opts="--component-flags init"
3736 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3737 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3739 flg_opts="--component-flags extension"
3740 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3741 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3743 sel_layout_sanity $comp_file 5
3745 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3747 # Simple test of FLR + self-extending layout, SEL in primary mirror
3749 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3750 skip "skipped for lustre < $SEL_VER"
3752 local comp_file=$DIR/$tdir/$tfile
3756 test_mkdir $DIR/$tdir
3757 stack_trap "rm -f $comp_file"
3759 # first mirror is 1M followed by extension space to -1, second mirror
3760 # is 0-10M, then 10M-(-1),
3761 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3762 error "Create $comp_file failed"
3764 # Write to first component, extending first component & staling
3766 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3767 error "dd to extend + stale failed"
3769 $LFS getstripe $comp_file
3771 flg_opts="--component-flags init"
3772 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3773 [ $found -eq 1 ] || error "write: First comp end incorrect"
3775 flg_opts="--component-flags extension"
3776 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3777 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3779 flg_opts="--component-flags init,stale"
3780 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3781 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3783 # This component is staled because it overlaps the extended first
3784 # component of the primary mirror, even though it doesn't overlap
3785 # the actual write - thus not inited.
3786 flg_opts="--component-flags stale"
3787 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3788 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3790 # mirror resync should not change the extents
3791 $LFS mirror resync $comp_file
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 "resync: 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 "resync: Second comp start incorrect"
3803 flg_opts="--component-flags init"
3804 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3805 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3807 flg_opts="--component-flags init"
3808 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3809 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3811 sel_layout_sanity $comp_file 5
3813 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3815 # FLR + SEL failed extension & component removal
3816 # extension space in second mirror
3818 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3819 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3820 skip "skipped for lustre < $SEL_VER"
3822 local comp_file=$DIR/$tdir/$tfile
3825 local ost_name=$(ostname_from_index $ost_idx1)
3827 test_mkdir $DIR/$tdir
3828 stack_trap "rm -f $comp_file"
3830 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3831 # extension space from 1M to 1G, then normal space to -1
3832 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3833 -E -1 $comp_file || error "Create $comp_file failed"
3835 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3838 # write to first comp (0 - 10M) of mirror 1, extending + staling
3839 # first + second comp of mirror 2
3840 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3843 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3846 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3848 $LFS getstripe $comp_file
3850 found=$($LFS find --component-start 0m --component-end 1m \
3851 --comp-flags init,stale $comp_file | wc -l)
3852 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3854 found=$($LFS find --component-start 1m --component-end EOF \
3855 --comp-flags stale,^init $comp_file | wc -l)
3856 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3858 local mirror_id=$($LFS getstripe --component-start=1m \
3859 --component-end=EOF $comp_file | \
3860 grep lcme_mirror_id | awk '{ print $2 }')
3862 [[ $mirror_id -eq 2 ]] ||
3863 error "component not in correct mirror? $mirror_id"
3865 $LFS mirror resync $comp_file
3867 $LFS getstripe $comp_file
3869 # component dimensions should not change from resync
3870 found=$($LFS find --component-start 1m --component-end EOF \
3871 --component-flags init $comp_file | wc -l)
3872 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3874 sel_layout_sanity $comp_file 4
3876 run_test 204c "FLR write/stale/resync test with component removal"
3878 # Successful repeated component in primary mirror
3880 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3881 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3882 skip "skipped for lustre < $SEL_VER"
3884 local comp_file=$DIR/$tdir/$tfile
3887 wait_delete_completed
3889 test_mkdir $DIR/$tdir
3890 stack_trap "rm -f $comp_file"
3892 # first mirror is 64M followed by extension space to -1, second mirror
3893 # is 0-10M, then 10M-(-1)
3894 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3895 error "Create $comp_file failed"
3897 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3898 local ost_name=$(ostname_from_index $ost_idx1)
3899 # degrade OST for first comp so we won't extend there
3900 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3901 obdfilter.$ost_name.degraded=1
3904 # Write beyond first component, causing repeat & stale second mirror
3905 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3908 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3909 obdfilter.$ost_name.degraded=0
3912 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3914 $LFS getstripe $comp_file
3916 found=$($LFS find --component-start 64m --component-end 128m \
3917 --component-flags init $comp_file | wc -l)
3918 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3920 local ost_idx2=$($LFS getstripe --component-start=64m \
3921 --component-end=128m --component-flags=init \
3923 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3924 local mirror_id=$($LFS getstripe --component-start=64m \
3925 --component-end=128m --component-flags=init \
3926 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3927 [[ $mirror_id -eq 1 ]] ||
3928 error "component not in correct mirror: $mirror_id, not 1"
3930 $LFS mirror resync $comp_file
3932 $LFS getstripe $comp_file
3934 # component dimensions should not change from resync
3935 found=$($LFS find --component-start 0m --component-end 64m \
3936 --component-flags init $comp_file | wc -l)
3937 [ $found -eq 1 ] || error "resync: first comp incorrect"
3938 found=$($LFS find --component-start 64m --component-end 128m \
3939 --component-flags init $comp_file | wc -l)
3940 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3942 sel_layout_sanity $comp_file 5
3944 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3946 # Successful repeated component, SEL in non-primary mirror
3948 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3949 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3950 skip "skipped for lustre < $SEL_VER"
3952 local comp_file=$DIR/$tdir/$tfile
3955 wait_delete_completed
3958 test_mkdir $DIR/$tdir
3959 stack_trap "rm -f $comp_file"
3961 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
3962 # space to -1 (-z 64M, so first comp is 0-64M)
3963 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
3964 # will be not enough - one will be degraded, the other is used on
3965 # an overlapping mirror.
3966 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
3967 error "Create $comp_file failed"
3969 local ost_idx1=$($LFS getstripe --component-start=0 \
3970 --component-end=64m -i $comp_file)
3971 local ost_name=$(ostname_from_index $ost_idx1)
3972 # degrade OST for first comp of 2nd mirror so we won't extend there
3973 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3974 obdfilter.$ost_name.degraded=1
3977 $LFS getstripe $comp_file
3979 # Write to first component, stale & instantiate second mirror components
3980 # overlapping with the written component (0-100M);
3981 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3984 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3985 obdfilter.$ost_name.degraded=0
3987 $LFS getstripe $comp_file
3989 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3991 found=$($LFS find --component-start 0m --component-end 64m \
3992 --component-flags init,stale $comp_file | wc -l)
3993 [ $found -eq 1 ] || error "write: first comp incorrect"
3995 # was repeated due to degraded ost
3996 found=$($LFS find --component-start 64m --component-end 128m \
3997 --component-flags init,stale $comp_file | wc -l)
3998 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4000 local ost_idx2=$($LFS getstripe --component-start=64m \
4001 --component-end=128m --component-flags=init \
4003 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4004 local mirror_id=$($LFS getstripe --component-start=0m \
4005 --component-end=64m --component-flags=init \
4006 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4007 [[ $mirror_id -eq 2 ]] ||
4008 error "component not in correct mirror? $mirror_id"
4010 $LFS mirror resync $comp_file
4012 $LFS getstripe $comp_file
4014 # component dimensions should not change from resync
4015 found=$($LFS find --component-start 0m --component-end 64m \
4016 --component-flags init,^stale $comp_file | wc -l)
4017 [ $found -eq 1 ] || error "resync: first comp incorrect"
4018 found=$($LFS find --component-start 64m --component-end 128m \
4019 --component-flags init,^stale $comp_file | wc -l)
4020 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4022 sel_layout_sanity $comp_file 5
4024 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4026 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4028 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4029 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4030 skip "skipped for lustre < $SEL_VER"
4032 local comp_file=$DIR/$tdir/$tfile
4035 wait_delete_completed
4037 test_mkdir $DIR/$tdir
4038 stack_trap "rm -f $comp_file"
4040 pool_add $TESTNAME || error "Pool creation failed"
4041 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4043 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4044 # space to -1 (-z 64M, so first comp is 0-64M)
4045 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4046 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4048 local ost_name0=$(ostname_from_index 0)
4049 local ost_name1=$(ostname_from_index 1)
4051 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4052 # extend original comp
4053 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4054 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4057 # a write to the 1st component, 100M length, which will try to stale
4058 # the first 100M of mirror 2, attempting to extend its 0-64M component
4059 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4062 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4063 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4066 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4068 $LFS getstripe $comp_file
4070 found=$($LFS find --component-start 0m --component-end 128m \
4071 --component-flags init,stale $comp_file | wc -l)
4072 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4074 local mirror_id=$($LFS getstripe --component-start=0m \
4075 --component-end=128m --component-flags=init \
4076 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4078 [[ $mirror_id -eq 2 ]] ||
4079 error "component not in correct mirror? $mirror_id, not 2"
4081 $LFS mirror resync $comp_file
4083 $LFS getstripe $comp_file
4085 # component dimensions should not change from resync
4086 found=$($LFS find --component-start 0m --component-end 128m \
4087 --component-flags init,^stale $comp_file | wc -l)
4088 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4090 sel_layout_sanity $comp_file 4
4092 run_test 204f "FLR write/stale/resync sel w/forced extension"
4094 function test_205() {
4095 local tf=$DIR/$tfile
4098 $LFS setstripe -c1 $tf
4099 $LFS mirror extend -N $tf
4100 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4101 (( $mirrors == 2 )) || error "no new mirror was created?"
4103 $LFS mirror extend -N --flags=prefer $tf
4104 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4105 (( $mirrors == 3 )) || error "no new mirror was created?"
4107 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4108 error "prefer flag was not set on the new mirror"
4110 run_test 205 "lfs mirror extend to set prefer flag"
4112 function test_206() {
4113 # create a new OST pool
4114 local pool_name=$TESTNAME
4116 create_pool $FSNAME.$pool_name ||
4117 error "create OST pool $pool_name failed"
4118 # add OSTs into the pool
4119 pool_add_targets $pool_name 0 1 ||
4120 error "add OSTs into pool $pool_name failed"
4122 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4123 error "can't setstripe"
4124 $LFS mirror extend -N $DIR/$tfile ||
4125 error "can't create replica"
4126 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4127 $LFS getstripe $DIR/$tfile
4128 error "prefer found"
4130 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4131 $LFS getstripe $DIR/$tfile
4132 error "can't setstripe prefer"
4135 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4136 $LFS getstripe $DIR/$tfile
4137 error "no prefer found"
4143 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4146 local file=$DIR/$tfile
4147 local tmpfile=$DIR/$tfile-tt
4149 [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
4150 skip "Need MDS version at least 2.14.50"
4152 stack_trap "rm -f $tmpfile $file"
4154 # generate data for verification
4155 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4156 error "can't generate file with random data"
4158 # create a mirrored file with one stale replica
4159 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4160 error "create mirrored file $file failed"
4161 get_mirror_ids $file
4162 echo "mirror IDs: ${mirror_array[*]}"
4164 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4165 get_mirror_ids $file
4166 echo "mirror IDs: ${mirror_array[*]}"
4169 cmp $tmpfile $file || error "files don't match"
4170 get_mirror_ids $file
4171 echo "mirror IDs: ${mirror_array[*]}"
4173 # mirror creation should work fine
4174 $LFS mirror extend -N -S 8M -c -1 $file ||
4175 error "mirror extend $file failed"
4177 get_mirror_ids $file
4178 echo "mirror IDs: ${mirror_array[*]}"
4181 $LFS mirror verify -v $file || error "verification failed"
4182 cmp $tmpfile $file || error "files don't match"
4184 run_test 207 "create another replica with existing out-of-sync one"
4186 function check_ost_used() {
4195 cancel_lru_locks osc # to drop pages
4196 cancel_lru_locks mdc # to refresh layout
4197 # XXX: cancel_lru_locks mdc doesn't work
4198 # XXX: need a better way to reload the layout
4199 umount_client $MOUNT || error "umount failed"
4200 mount_client $MOUNT || error "mount failed"
4202 # refresh non-rotation status on MDTs
4204 touch $DIR/$tfile-temp
4205 rm -f $DIR/$tfile-temp
4206 # refresh non-rotational status on the client
4210 $LCTL set_param osc.*.stats=clear >/dev/null
4211 if [[ $io == "read" ]]; then
4212 ddarg="if=$file of=/dev/null"
4213 elif [[ $io == "write" ]]; then
4214 ddarg="if=/dev/zero of=$file"
4216 error "unknown type $io"
4218 dd $ddarg bs=8M count=1 || error "can't $io $file"
4219 cancel_lru_locks osc
4221 # check only specified OSTs got reads
4222 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4223 local nr=$($LCTL get_param -n \
4224 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4225 awk "/ost_$io/{print \$2}")
4227 if [[ " $* " =~ $ost ]]; then
4228 (( nr > 0 )) || error "expected reads on $ost"
4230 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4236 local tf=$DIR/$tfile
4237 local osts=$(comma_list $(osts_nodes))
4239 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4240 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4241 skip "Need MDS version at least 2.14.55"
4243 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4245 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4246 stack_trap "restore_lustre_params < $p; rm -f $p"
4248 stack_trap "rm -f $tf"
4249 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4250 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4251 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4252 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4253 $LFS mirror resync $tf || error "can't resync"
4256 log "set OST0000 non-rotational"
4258 $LCTL set_param osd*.*OST*.nonrotational=0
4260 $LCTL set_param osd*.*OST0000*.nonrotational=1
4261 check_ost_used $tf read 0
4263 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4265 $LCTL set_param osd*.*OST*.nonrotational=0
4267 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4268 osd*.*OST0003*.nonrotational=1
4269 check_ost_used $tf read 2 3
4271 log "set mirror 1 on OST0001 preferred"
4272 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4273 error "can't set prefer"
4274 check_ost_used $tf read 1
4276 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4279 local tf=$DIR/$tfile
4280 local osts=$(comma_list $(osts_nodes))
4282 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4283 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4284 skip "Need MDS version at least 2.14.55"
4286 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4288 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4289 stack_trap "restore_lustre_params < $p; rm -f $p"
4291 stack_trap "rm -f $tf"
4292 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4293 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4294 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4295 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4296 $LFS mirror resync $tf || error "can't resync"
4297 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4299 log "set OST0000 non-rotational"
4301 $LCTL set_param osd*.*OST*.nonrotational=0
4303 $LCTL set_param osd*.*OST0000*.nonrotational=1
4304 check_ost_used $tf write 0
4305 $LFS mirror resync $tf || error "can't resync"
4307 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4309 $LCTL set_param osd*.*OST*.nonrotational=0
4311 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4312 osd*.*OST0003*.nonrotational=1
4313 check_ost_used $tf write 2 3
4314 $LFS mirror resync $tf || error "can't resync"
4316 log "set mirror 1 on OST0001 preferred"
4317 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4318 error "can't set prefer"
4319 check_ost_used $tf write 1
4321 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4324 local tf=$DIR/$tfile
4325 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4326 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4327 local osts=$(comma_list $(osts_nodes))
4329 stack_trap "rm -f $tmpfile"
4331 mkdir -p $MOUNT2 && mount_client $MOUNT2
4332 stack_trap "umount_client $MOUNT2"
4334 # to make replica on ost1 preferred for new writes
4335 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4336 stack_trap "restore_lustre_params < $p; rm -f $p"
4338 $LCTL set_param osd*.*OST*.nonrotational=0
4340 $LCTL set_param osd*.*OST0001*.nonrotational=1
4342 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4344 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4345 log "replicated file created"
4347 cancel_lru_locks mdc
4348 cancel_lru_locks osc
4350 log "open(O_RDONLY) and first read from OST"
4351 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4354 log "first read complete"
4356 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4357 error "can't write BBBB"
4358 log "BBBB written which made replica on ost1 stale"
4360 log "fast read from pagecache in the original process"
4364 log "read via $DIR2 new open(2)"
4365 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4367 log "fast read from pagecache after 5s in the original process"
4372 local nr=$(grep "BBBB" $tmpfile | wc -l)
4378 log "read via new open(2)"
4379 $MULTIOP $tf vvoO_RDONLY:r4c
4381 run_test 209a "skip fast reads after layout invalidation"
4383 function sum_ost_reads() {
4384 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4385 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4389 local tf=$DIR/$tfile
4391 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4392 cancel_lru_locks osc
4393 echo "the very first read"
4394 cat $tf >/dev/null || error "can't read"
4396 # cancel layout lock
4397 cancel_lru_locks mdc
4399 # now read again, data must be in the cache, so no ost reads
4400 $LCTL set_param osc.*.stats=clear >/dev/null
4401 echo "read with warm cache"
4402 cat $tf >/dev/null || error "can't read"
4404 (( nr == 0 )) || error "reads with warm cache"
4406 # now verify we can catch reads at all
4407 cancel_lru_locks osc
4408 cat $tf >/dev/null || error "can't read"
4410 (( nr > 0 )) || error "no reads with cold cache"
4412 run_test 209b "pagecache can be used after LL cancellation"
4414 complete_test $SECONDS
4415 check_and_cleanup_lustre