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 4M -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 4194304
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]} 4194304 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 4M -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 4194304
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]} 4194304 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"
733 # create parent directory
734 test_mkdir $td || error "mkdir $td failed"
736 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
737 error "set default mirrored layout on directory $td failed"
739 # verify flags are inherited from the directory
742 verify_comp_attr lcme_flags $tf 0x10001 prefer
743 verify_comp_attr lcme_flags $tf 0x10002 prefer
745 # set flags to the first component
746 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
747 error "setting '^prefer,foo' flags should fail"
749 ! $LFS getstripe --component-flags=prefer,foo $tf ||
750 error "getting component(s) with 'prefer,foo' flags should fail"
752 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
754 verify_comp_attr lcme_flags $tf 0x10001 stale
755 verify_comp_attr lcme_flags $tf 0x10002 prefer
757 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
758 error "clearing 'stale' should fail"
760 # write and resync file. It can't resync the file directly because the
761 # file state is still 'ro'
762 cp /etc/hosts $tf || error "error writing file '$tf'"
763 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
765 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
766 error "error setting flag prefer"
768 verify_comp_attr lcme_flags $tf 0x20003 prefer
770 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^prefer $tf ||
771 error "error clearing prefer flag from component 0x20003"
773 # MDS disallows setting stale flag on the last non-stale mirror
774 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
776 cp /etc/hosts $tf || error "error writing file '$tf'"
778 verify_comp_attr lcme_flags $tf 0x10002 prefer
779 verify_comp_attr lcme_flags $tf 0x20003 stale
780 verify_comp_attr lcme_flags $tf 0x30004 stale
782 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
784 error "setting stale flag on component 0x10002 should fail"
786 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
788 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
789 error "error setting stale flag on component 0x10001"
790 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
791 error "error setting stale flag on component 0x20003"
793 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
795 error "setting stale flag on component 0x30004 should fail"
797 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
799 run_test 0h "set, clear and test flags for FLR files"
802 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
804 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
805 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
806 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
808 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
809 stack_trap "rm -f $TMP/$tfile"
810 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
811 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
812 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
813 error "set component 1 stale failed"
814 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
815 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
817 run_test 0j "test lfs mirror read/write commands"
821 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
822 local mirror_create_cmd="$LFS mirror create"
823 local stripes[0]=$OSTCOUNT
825 mirror_create_cmd+=" -N -c ${stripes[0]}"
826 for ((i = 1; i < $mirror_count; i++)); do
827 # add mirrors with different stripes to the file
828 stripes[$i]=$((RANDOM % OSTCOUNT))
829 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
831 mirror_create_cmd+=" -N -c ${stripes[$i]}"
834 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
835 verify_mirror_count $tf $mirror_count
837 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
838 $LFS mirror extend -N $tf &&
839 error "Creating the $((mirror_count+1))th mirror succeeded"
841 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
844 # verify the range of components and stripe counts
845 for ((i = 0; i < $mirror_count; i++)); do
846 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
847 verify_comp_extent $tf ${ids[$i]} 0 EOF
850 run_test 1 "create components with setstripe options"
854 local tf2=$DIR/$tfile-2
856 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
857 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
859 $LFS mirror extend -N -f $tf2 $tf ||
860 error "merging $tf2 into $tf failed"
862 verify_mirror_count $tf 2
863 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
865 run_test 2 "create components from existing files"
868 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
870 for ((i = 0; i < 2; i++)); do
871 $LFS mkdir -i $i $DIR/$tdir-$i
872 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
875 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
876 $DIR/$tdir-0/$tfile || error "creating mirrors"
878 # mdt doesn't support to cancel layout lock for remote objects, do
882 # make sure the mirrorted file was created successfully
883 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
884 { $LFS getstripe $DIR/$tdir-0/$tfile;
885 error "expected 2 components"; }
890 run_test 3 "create components from files located on different MDTs"
893 local tf=$DIR/$tdir/$tfile
896 test_mkdir $DIR/$tdir
898 # set mirror with setstripe options to directory
899 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
900 error "set mirror to directory error"
902 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
903 x"mirrored" ] || error "failed to create mirrored dir"
906 verify_mirror_count $tf 2
908 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
909 verify_comp_extent $tf ${ids[0]} 0 1048576
910 verify_comp_extent $tf ${ids[1]} 1048576 EOF
912 # sub directory should inherit mirror setting from parent
913 test_mkdir $DIR/$tdir/td
914 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
915 x"mirrored" ] || error "failed to inherit mirror from parent"
917 # mirror extend won't be applied to directory
918 $LFS mirror extend -N2 $DIR/$tdir &&
919 error "expecting mirror extend failure"
922 run_test 4 "Make sure mirror attributes can be inhertied from directory"
928 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
929 error "failed to create file with non-empty layout"
930 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
932 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
933 verify_mirror_count $tf 3
935 $CHECKSTAT -t file -s 12345 $tf ||
936 error "size error after attaching layout "
938 run_test 5 "Make sure init size work for mirrored layout"
941 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
942 skip "MDS version older than 2.12.58"
946 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
947 error "failure to create DoM file with mirror"
949 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
950 error "failure to create mirrored file with DoM"
952 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
953 error "failure to create PFL with DoM file"
954 $LFS mirror extend -N2 $tf ||
955 error "failure to extend mirror with DoM"
957 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
958 error "failure to create PFL with DoM file"
959 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
960 error "failure to create mirrored file"
961 $LFS mirror extend -N -f $tf-1 $tf-2 ||
962 error "failure to extend mirrored file with DoM extent"
964 run_test 6 "DoM and FLR work together"
969 # create DoM with setting stripe_size == component size
970 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
971 error "failure to create DoM with stripe_size == comp size"
972 rm -f $tf || error "delete $tf"
974 # DoM should not inherit previous component stripe_size
975 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
976 error "DoM component shouldn't inherit previous stripe_size"
978 run_test 7 "Create mirror with DoM component"
982 local tf2=$DIR/$tfile-2
984 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
986 stack_trap "rm -f $tf $tf2"
988 $LFS setstripe -E EOF -o 0 $tf
989 $LFS setstripe -E EOF -o 1 $tf2
991 local dd_count=$((RANDOM % 20 + 1))
992 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
993 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
995 # for zfs - sync OST dataset so that du below will return
997 [ "$FSTYPE" = "zfs" ] &&
998 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1000 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1003 $LFS mirror extend -N -f $tf2 $tf ||
1004 error "merging $tf2 into $tf failed"
1006 # cancel layout lock
1007 cancel_lru_locks mdc
1009 local new_blocks=$(du -k $tf | awk '{print $1}')
1010 [ $new_blocks -eq $blocks ] ||
1011 error "i_blocks error expected: $blocks, actual: $new_blocks"
1013 run_test 21 "glimpse should report accurate i_blocks"
1015 get_osc_lock_count() {
1022 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1023 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1024 lock_count=$((lock_count + count))
1030 local tf=$DIR/$tfile
1032 stack_trap "rm -f $tf"
1034 $LFS setstripe -E EOF -o 0 $tf
1035 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1037 # add component, two mirrors located on the same OST ;-)
1038 $LFS mirror extend -N -o 0 $tf ||
1039 error "extending mirrored file $tf failed"
1041 size_blocks=$(stat --format="%b %s" $tf)
1043 cancel_lru_locks mdc
1044 cancel_lru_locks osc
1046 local new_size_blocks=$(stat --format="%b %s" $tf)
1048 # make sure there is no lock cached
1049 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1051 [ "$new_size_blocks" = "$size_blocks" ] ||
1052 echo "size expected: $size_blocks, actual: $new_size_blocks"
1056 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1059 local tf=$DIR/$tfile
1061 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1062 error "creating mirrored file $tf failed"
1064 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
1065 $LCTL set_param fail_loc=0x1A00
1068 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1069 cancel_lru_locks osc
1072 local tmpfile=$(mktemp)
1073 stat --format="%b %s" $tf > $tmpfile &
1077 while [ $cnt -le 5 ]; do
1078 kill -0 $pid > /dev/null 2>&1 || break
1082 kill -0 $pid > /dev/null 2>&1 &&
1083 error "stat process stuck due to unavailable OSTs"
1085 # make sure glimpse request has been sent
1086 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1087 error "OST $ost_idx: no glimpse request was sent"
1092 run_test 31 "make sure glimpse request can be retried"
1095 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1096 rm -f $DIR/$tfile $DIR/$tfile-2
1098 stack_trap "rm -f $DIR/$tfile"
1100 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1101 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1103 local fsize=$(stat -c %s $DIR/$tfile)
1104 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1106 local cksum=$(md5sum $DIR/$tfile)
1108 # create a new mirror in sync mode
1109 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1110 error "extending mirrored file $DIR/$tfile failed"
1112 # make sure the mirrored file was created successfully
1113 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1114 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1119 # check size is correct, glimpse request should go to the 2nd mirror
1120 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1121 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1123 echo "reading file from the 2nd mirror and verify checksum"
1124 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1125 error "checksum error: expected $cksum"
1129 run_test 32 "data should be mirrored to newly created mirror"
1132 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1134 rm -f $DIR/$tfile $DIR/$tfile-2
1136 # create a file with two mirrors
1137 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1140 while [ $count -lt $max_count ]; do
1141 echo "ost1" >> $DIR/$tfile
1142 count=$((count + 1));
1145 # tmp file that will be used as mirror
1146 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1148 while [ $count -lt $max_count ]; do
1149 echo "ost2" >> $DIR/$tfile-2
1150 count=$((count + 1));
1153 # create a mirrored file
1154 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1155 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1156 "with verification should fail"
1157 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1158 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1159 "without verification failed"
1161 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1162 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1163 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1165 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1167 # execpted file size
1168 local fsize=$((5 * max_count))
1169 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1170 error "mirrored file size is not $fsize"
1172 # read file - all OSTs are available
1173 echo "reading file (data can be provided by any ost)... "
1174 local rs=$(cat $DIR/$tfile | head -1)
1175 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1176 error "file content error: expected: \"ost1\" or \"ost2\""
1178 # read file again with ost1 failed
1182 echo "reading file (data should be provided by ost2)..."
1183 local rs=$(cat $DIR/$tfile | head -1)
1184 [[ "$rs" == "ost2" ]] ||
1185 error "file content error: expected: \"ost2\", actual: \"$rs\""
1190 # read file again with ost2 failed
1194 # check size, glimpse should work
1195 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1196 error "mirrored file size is not $fsize"
1198 echo "reading file (data should be provided by ost1)..."
1199 local rs=$(cat $DIR/$tfile | head -1)
1200 [[ "$rs" == "ost1" ]] ||
1201 error "file content error: expected: \"ost1\", actual: \"$rs\""
1205 run_test 33a "read can choose available mirror to read"
1208 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1212 stack_trap "rm -f $DIR/$tfile" EXIT
1214 # create a file with two mirrors on OST0000 and OST0001
1215 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1217 # make sure that $tfile has two mirrors
1218 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1219 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1222 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1223 error "write failed for $DIR/$tfile"
1224 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1225 verify_flr_state $DIR/$tfile "ro"
1230 # read file - all OSTs are available
1231 echo "reading file (data can be provided by any ost)... "
1233 time cat $DIR/$tfile > /dev/null || error "read all"
1237 # read file again with ost1 {OST0000} failed
1240 echo "reading file (data should be provided by ost2)..."
1242 time cat $DIR/$tfile > /dev/null || error "read ost2"
1249 # read file again with ost2 {OST0001} failed
1253 echo "reading file (data should be provided by ost1)..."
1255 time cat $DIR/$tfile > /dev/null || error "read ost1"
1262 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1263 error "read mirror too slow without ost1, from $ra to $r1"
1264 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1265 error "read mirror too slow without ost2, from $ra to $r2"
1267 wait_osc_import_ready client ost2
1269 run_test 33b "avoid reading from unhealthy mirror"
1272 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1276 stack_trap "rm -f $DIR/$tfile" EXIT
1278 # create a file with two mirrors
1279 # mirror1: {OST0000, OST0001}
1280 # mirror2: {OST0001, OST0002}
1281 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1283 # make sure that $tfile has two mirrors
1284 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1285 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1288 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1289 error "write failed for $DIR/$tfile"
1290 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1291 verify_flr_state $DIR/$tfile "ro"
1296 # read file - all OSTs are available
1297 echo "reading file (data can be provided by any ost)... "
1298 time cat $DIR/$tfile > /dev/null || error "read all"
1300 # read file again with ost2 (OST0001) failed
1304 echo "reading file (data should be provided by ost1 and ost3)..."
1305 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1310 wait_osc_import_ready client ost2
1312 run_test 33c "keep reading among unhealthy mirrors"
1315 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1317 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1320 $LFS setstripe -o 0 $DIR/$tfile-ref
1321 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1323 # create a file with two mirrors
1324 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1325 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1327 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1328 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1330 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1331 error "mirrored file size is not 3M"
1333 # merge a mirrored file
1334 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1335 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1337 cancel_lru_locks osc
1339 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1340 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1343 echo "comparing files ... "
1345 # however, read can still return the correct data. It should return
1346 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1347 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1348 $DIR/$tfile-ref || error "file reading error"
1352 run_test 34a "read mirrored file with multiple stripes"
1355 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1357 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1360 $LFS setstripe -o 0 $DIR/$tfile-ref
1361 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1363 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1364 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1366 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1367 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1369 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1370 error "mirrored file size is not 3M"
1372 # merge a mirrored file
1373 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1374 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1376 cancel_lru_locks osc
1378 # stop two OSTs, so the 2nd component of the 1st mirror and
1379 # the 1st component of the 2nd mirror will be inaccessible, ...
1382 echo "comparing files ... "
1384 # however, read can still return the correct data. It should return
1385 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1386 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1387 $DIR/$tfile-ref || error "file reading error"
1391 run_test 34b "read mirrored file with multiple components"
1394 local tf=$DIR/$tfile
1396 $LFS setstripe -E eof $tf
1398 # add an out-of-sync mirror to the file
1399 $LFS mirror extend -N -c 2 $tf ||
1400 error "extending mirrored file $tf failed"
1402 $MULTIOP $tf oO_WRONLY:c ||
1403 error "write open a mirrored file failed"
1405 # truncate file should return error
1406 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1408 run_test 35 "allow to write to mirrored files"
1410 verify_ost_layout_version() {
1413 # get file layout version
1414 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1416 # layout version from OST objects
1417 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1419 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1426 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1427 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1429 $LFS mirror extend -N -f $tf-tmp $tf ||
1430 error "merging $tf-tmp into $tf failed"
1435 local tf=$DIR/$tfile
1437 stack_trap "rm -f $tf $tf-2 $tf-3"
1439 create_file_36 $tf $tf-2 $tf-3
1441 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1443 # test case 1 - check file write and verify layout version
1444 $MULTIOP $tf oO_WRONLY:c ||
1445 error "write open a mirrored file failed"
1447 # write open file should not return error
1448 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1450 # instantiate components should work
1451 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1453 # verify OST layout version
1454 verify_ost_layout_version $tf
1457 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1460 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1462 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1463 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1465 # write should take at least $fail_loc seconds and succeed
1466 local st=$(date +%s)
1467 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1469 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1470 error "write finished before layout version is transmitted"
1472 # verify OST layout version
1473 verify_ost_layout_version $tf
1475 do_facet $mds_facet $LCTL set_param fail_loc=0
1478 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1480 #define OBD_FAIL_FLR_LV_INC 0x1A02
1481 do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1483 # write open file should return error
1484 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1485 error "write a mirrored file succeeded" || true
1487 do_facet $mds_facet $LCTL set_param fail_loc=0
1489 run_test 36 "write to mirrored files"
1495 echo "create test files with size $fsize .."
1499 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1501 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1502 $TRUNCATE $tf $fsize
1508 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1509 skip "Need MDS version at least 2.11.57"
1511 local tf=$DIR/$tfile
1512 local tf2=$DIR/$tfile-2
1513 local tf3=$DIR/$tfile-3
1514 local tf4=$DIR/$tfile-4
1516 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1518 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1522 # assume the mirror id will be 1, 2, and 3
1523 declare -A checksums
1524 checksums[1]=$(cat $tf | md5sum)
1525 checksums[2]=$(cat $tf2 | md5sum)
1526 checksums[3]=$(cat $tf3 | md5sum)
1528 printf '%s\n' "${checksums[@]}"
1530 # merge these files into a mirrored file
1531 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1532 error "merging $tf2 into $tf failed"
1533 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1534 error "merging $tf3 into $tf failed"
1538 # verify mirror read, checksums should equal to the original files'
1539 echo "Verifying mirror read .."
1542 for i in "${mirror_array[@]}"; do
1543 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1544 sum=$($LFS mirror read -N $i $tf | md5sum)
1545 [ "$sum" = "${checksums[$i]}" ] ||
1546 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1549 # verify mirror write
1550 echo "Verifying mirror write .."
1551 $LFS mirror write -N2 $tf < $tf4
1553 sum=$($LFS mirror read -N2 $tf | md5sum)
1554 [[ "$sum" = "${checksums[1]}" ]] ||
1555 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1557 # verify mirror copy, write to this mirrored file will invalidate
1558 # the other two mirrors
1559 echo "Verifying mirror copy .."
1561 local osts=$(comma_list $(osts_nodes))
1563 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1564 error "mirror copy error"
1566 # verify copying is successful by checking checksums
1567 remount_client $MOUNT
1568 for i in "${mirror_array[@]}"; do
1569 sum=$($LFS mirror read -N $i $tf | md5sum)
1570 [ "$sum" = "${checksums[1]}" ] ||
1571 error "$i: mismatch checksum after copy \'$sum\'"
1576 run_test 37 "mirror I/O API verification"
1579 local tf=$DIR/$tfile
1580 local ref=$DIR/${tfile}-ref
1582 stack_trap "rm -f $tf $ref"
1584 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1585 error "creating $tf failed"
1586 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1587 $tf-2 || error "creating $tf-2 failed"
1588 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1589 error "creating $tf-3 failed"
1591 # instantiate all components
1592 $LFS mirror extend -N -f $tf-2 $tf ||
1593 error "merging $tf-2 into $tf failed"
1594 $LFS mirror extend -N -f $tf-3 $tf ||
1595 error "merging $tf-3 into $tf failed"
1596 $LFS mirror extend -N -c 1 $tf ||
1597 error "extending mirrored file $tf failed"
1599 verify_flr_state $tf "ro"
1601 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1603 local fsize=$((RANDOM << 8 + 1048576))
1604 $TRUNCATE $ref $fsize
1606 local ref_cksum=$(cat $ref | md5sum)
1608 # case 1: verify write to mirrored file & resync work
1609 cp $ref $tf || error "copy from $ref to $f error"
1610 verify_flr_state $tf "wp"
1612 local file_cksum=$(cat $tf | md5sum)
1613 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1616 echo "mirror IDs: ${mirror_array[*]}"
1618 local valid_mirror stale_mirror id mirror_cksum
1619 for id in "${mirror_array[@]}"; do
1620 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1621 [ "$ref_cksum" == "$mirror_cksum" ] &&
1622 { valid_mirror=$id; continue; }
1627 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1628 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1630 $LFS mirror resync $tf || error "resync failed"
1631 verify_flr_state $tf "ro"
1633 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1634 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1636 # case 2: inject an error to make mirror_io exit after changing
1637 # the file state to sync_pending so that we can start a concurrent
1639 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1640 verify_flr_state $tf "wp"
1642 mirror_io resync -e resync_start $tf && error "resync succeeded"
1643 verify_flr_state $tf "sp"
1645 # from sync_pending to write_pending
1646 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1647 verify_flr_state $tf "wp"
1649 mirror_io resync -e resync_start $tf && error "resync succeeded"
1650 verify_flr_state $tf "sp"
1652 # from sync_pending to read_only
1653 $LFS mirror resync $tf || error "resync failed"
1654 verify_flr_state $tf "ro"
1656 run_test 38 "resync"
1659 local tf=$DIR/$tfile
1662 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1663 error "create PFL file $tf failed"
1665 verify_mirror_count $tf 2
1666 verify_comp_count $tf 4
1668 rm -f $tf || error "delete $tf failed"
1670 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1673 local tf=$DIR/$tfile
1676 for ops in "conv=notrunc" ""; do
1679 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1680 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1681 error "create PFLR file $tf failed"
1682 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1683 error "write PFLR file $tf failed"
1685 lfs getstripe -vy $tf
1689 # file mirror state should be write_pending
1690 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1692 error "file mirror state $flags"
1693 # the 1st component (in mirror 1) should be inited
1694 verify_comp_attr lcme_flags $tf 0x10001 init
1695 # the 2nd component (in mirror 1) should be inited
1696 verify_comp_attr lcme_flags $tf 0x10002 init
1697 # the 3rd component (in mirror 1) should be uninited
1698 verify_comp_attr lcme_flags $tf 0x10003 prefer
1699 # the 4th component (in mirror 2) should be inited
1700 verify_comp_attr lcme_flags $tf 0x20004 init
1701 # the 5th component (in mirror 2) should be uninited
1702 verify_comp_attr lcme_flags $tf 0x20005 0
1703 # the 6th component (in mirror 2) should be stale
1704 verify_comp_attr lcme_flags $tf 0x20006 stale
1705 # the 7th component (in mirror 2) should be uninited
1706 if [[ x$ops = "xconv=notrunc" ]]; then
1707 verify_comp_attr lcme_flags $tf 0x20007 0
1708 elif [[ x$ops = "x" ]]; then
1709 verify_comp_attr lcme_flags $tf 0x20007 stale
1713 rm -f $tf || error "delete $tf failed"
1715 run_test 40 "PFLR rdonly state instantiation check"
1718 local tf=$DIR/$tfile
1720 stack_trap "rm -f $tf $tf-1"
1723 echo " **create two FLR files $tf $tf-1"
1724 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1725 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1726 error "create PFLR file $tf failed"
1727 $LFS mirror create -N -E 2M -S 1M -E eof \
1728 -N -E 1M -E eof --flags prefer \
1729 -N -E 4m -E eof $tf-1 ||
1730 error "create PFLR file $tf-1 failed"
1732 # file should be in ro status
1733 echo " **verify files be RDONLY"
1734 verify_flr_state $tf "ro"
1735 verify_flr_state $tf-1 "ro"
1737 # write data in [0, 2M)
1738 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1739 error "writing $tf failed"
1740 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1741 error "writing $tf-1 failed"
1743 local sum0=$(cat $tf-1 | md5sum)
1745 echo " **verify files be WRITE_PENDING"
1746 verify_flr_state $tf "wp"
1747 verify_flr_state $tf-1 "wp"
1749 # file should have stale component
1750 echo " **verify files have stale component"
1751 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1752 error "after writing $tf, it does not contain stale component"
1753 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1754 error "after writing $tf-1, it does not contain stale component"
1756 echo " **full resync"
1757 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1759 echo " **verify $tf-1 data consistency in all mirrors"
1761 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1762 [[ "$sum" = "$sum0" ]] ||
1763 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1766 echo " **verify files be RDONLY"
1767 verify_flr_state $tf "ro"
1768 verify_flr_state $tf-1 "ro"
1770 # file should not have stale component
1771 echo " **verify files do not contain stale component"
1772 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1773 error "after resyncing $tf, it contains stale component"
1774 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1775 error "after resyncing $tf, it contains stale component"
1777 # verify partial resync
1778 echo " **write $tf-1 for partial resync test"
1779 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1780 error "writing $tf-1 failed"
1782 echo " **only resync mirror 2"
1783 verify_flr_state $tf-1 "wp"
1784 $LFS mirror resync --only 2 $tf-1 ||
1785 error "resync mirror 2 of $tf-1 failed"
1786 verify_flr_state $tf "ro"
1788 # resync synced mirror
1789 echo " **resync mirror 2 again"
1790 $LFS mirror resync --only 2 $tf-1 ||
1791 error "resync mirror 2 of $tf-1 failed"
1792 verify_flr_state $tf "ro"
1793 echo " **verify $tf-1 contains stale component"
1794 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1795 error "after writing $tf-1, it does not contain stale component"
1797 echo " **full resync $tf-1"
1798 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1799 verify_flr_state $tf "ro"
1800 echo " **full resync $tf-1 again"
1801 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1802 echo " **verify $tf-1 does not contain stale component"
1803 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1804 error "after resyncing $tf, it contains stale component"
1808 run_test 41 "lfs mirror resync check"
1811 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1815 local mirror_cmd="$LFS mirror verify"
1818 stack_trap "rm -rf $td"
1820 # create parent directory
1821 mkdir $td || error "mkdir $td failed"
1823 $mirror_cmd &> /dev/null && error "no file name given"
1824 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1825 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1827 # create mirrored files
1828 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1829 error "create mirrored file $tf failed"
1830 $LFS mirror create -N -E 2M -S 1M -E EOF \
1831 -N -E 6M -E 8M -E EOF \
1832 -N -E 16M -E EOF $tf-1 ||
1833 error "create mirrored file $tf-1 failed"
1834 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1835 error "create mirrored file $tf-2 failed"
1837 # write data in [0, 10M)
1838 for i in $tf $tf-1 $tf-2; do
1839 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1840 error "write $i failed"
1843 # resync the mirrored files
1844 $LFS mirror resync $tf-1 $tf-2 ||
1845 error "resync $tf-1 $tf-2 failed"
1847 # verify the mirrored files
1848 $mirror_cmd $tf-1 $tf-2 ||
1849 error "verify $tf-1 $tf-2 failed"
1851 get_mirror_ids $tf-1
1852 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1853 error "at least 2 mirror ids needed with '--only' option"
1854 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1856 error "'--only' option cannot be used upon multiple files"
1857 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1858 error "invalid specified mirror ids"
1860 # change the content of $tf and merge it into $tf-1
1862 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1863 error "change $tf with seek=$i failed"
1864 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1865 error "change $tf-1 with seek=$i failed"
1868 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1869 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1870 error "merge $tf into $tf-1 failed"
1872 # verify the mirrored files
1873 echo "Verify $tf-1 without -v option:"
1874 $mirror_cmd $tf-1 &&
1875 error "verify $tf-1 should fail" || echo "PASS"
1877 echo "Verify $tf-1 with -v option:"
1878 $mirror_cmd -v $tf-1 &&
1879 error "verify $tf-1 should fail"
1881 get_mirror_ids $tf-1
1882 echo "Verify $tf-1 with --only option:"
1883 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1884 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1885 "${mirror_array[-1]} should fail"
1887 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1888 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1889 "${mirror_array[1]} should succeed"
1891 # set stale components in $tf-1
1892 for i in 0x40002 0x40003; do
1893 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1894 error "set stale flag on component $i failed"
1897 # verify the mirrored file
1898 echo "Verify $tf-1 with stale components:"
1899 $mirror_cmd -vvv $tf-1 ||
1900 error "verify $tf-1 with stale components should succeed"
1902 echo "Verify $tf-1 with stale components and --only option:"
1903 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1904 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1905 "${mirror_array[-1]} should succeed"
1907 run_test 42 "lfs mirror verify"
1909 # inactivate one OST && write && restore the OST
1913 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1916 wait=$(do_facet $SINGLEMDS \
1917 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1918 wait=${wait%%[^0-9]*}
1920 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1921 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1922 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1923 sleep $(($wait * 2 + 2))
1924 echo " **write $file"
1925 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1926 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1927 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1928 sleep $((wait * 2 + 2))
1930 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1931 [ $flags = wp ] || error "file mirror state $flags != wp"
1935 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1937 local tf=$DIR/$tfile
1941 ## mirror 0 ost (0, 1)
1942 ## mirror 1 ost (1, 2)
1943 ## mirror 2 ost (2, 0)
1944 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1945 -N -Eeof -c2 -o2,0 $tf ||
1946 error "create 3 mirrors file $tf failed"
1948 ################## OST0 ###########################################
1950 echo " **verify components"
1951 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1952 verify_comp_attr lcme_flags $tf 0x20002 init
1953 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1956 echo " **resync $tf"
1957 $LFS mirror resync $tf
1958 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1959 [ $flags = ro ] || error "file mirror state $flags != ro"
1961 ################## OST1 ###########################################
1963 echo " **verify components"
1964 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1965 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1966 verify_comp_attr lcme_flags $tf 0x30003 init
1969 echo " **resync $tf"
1970 $LFS mirror resync $tf
1971 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1972 [ $flags = ro ] || error "file mirror state $flags != ro"
1974 ################## OST2 ###########################################
1976 echo " **verify components"
1977 verify_comp_attr lcme_flags $tf 0x10001 init
1978 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1979 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1981 run_test 43a "mirror pick on write"
1984 local tf=$DIR/$tdir/$tfile
1986 test_mkdir $DIR/$tdir
1988 stack_trap "rm -rf $tf"
1990 # create 3 mirrors FLR file, the first 2 mirrors are preferred
1991 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
1992 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
1993 verify_flr_state $tf "ro"
1995 echo " ** write to $tf"
1996 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
1997 verify_flr_state $tf "wp"
1999 echo " ** resync $tf"
2000 $LFS mirror resync $tf || error "resync $tf failed"
2001 verify_flr_state $tf "ro"
2003 run_test 43b "allow writing to multiple preferred mirror file"
2006 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2009 local tf=$DIR/$tdir/$tfile
2010 local tf1=$DIR/$tdir-1/$tfile-1
2012 stack_trap "rm -rf $tf $tf1"
2014 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2015 error "create directory failed"
2016 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2017 error "create remote directory failed"
2018 rm -f $tf $tf1 $tf.mirror~2
2019 # create file with 4 mirrors
2020 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2021 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2022 error "create PFLR file $tf failed"
2024 # file should be in ro status
2025 verify_flr_state $tf "ro"
2027 # write data in [0, 3M)
2028 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2029 error "writing $tf failed"
2031 verify_flr_state $tf "wp"
2033 # disallow destroying the last non-stale mirror
2034 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2035 error "destroying mirror 1 should fail"
2037 # synchronize all mirrors of the file
2038 $LFS mirror resync $tf || error "mirror resync $tf failed"
2040 verify_flr_state $tf "ro"
2043 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2044 error "split to $tf1 failed"
2046 local idx0=$($LFS getstripe -m $tf)
2047 local idx1=$($LFS getstripe -m $tf1)
2049 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2050 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2052 # verify mirror count
2053 verify_mirror_count $tf 3
2054 verify_mirror_count $tf1 1
2056 $LFS mirror split --mirror-id 2 $tf ||
2057 error "split mirror 2 failed"
2059 verify_mirror_count $tf 2
2060 verify_mirror_count $tf.mirror~2 1
2062 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2063 error "setting stale flag on component 0x30008 failed"
2065 # disallow destroying the last non-stale mirror
2066 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2067 error "destroying mirror 4 should fail"
2069 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2071 $LFS mirror split --mirror-id 3 -d $tf ||
2072 error "destroying mirror 3 failed"
2073 verify_mirror_count $tf 1
2075 # verify splitted file contains the same content as the orig file does
2076 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2077 diff $tf $tf.mirror~2 ||
2078 error "splited file $tf.mirror~2 diffs from $tf"
2080 run_test 44a "lfs mirror split check"
2083 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2084 skip "Need MDS version at least 2.14.56"
2087 local tf=$DIR/$tdir/$tfile
2089 mkdir -p $DIR/$tdir || error "create directory failed"
2093 # create 2 mirrors file
2094 $LFS mirror extend -N -c1 $tf
2098 verify_flr_state $tf "wp"
2100 local str=$(cat $tf)
2102 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2104 # get the non-stale mirror id
2105 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2107 local mirror_ids=($($LFS getstripe $tf |
2108 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2109 for ((i = 0; i < 2; i++)); do
2110 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2111 grep stale > /dev/null || break
2114 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2118 # split the updated mirror, should fail
2119 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2120 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2121 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2124 # split the stale mirror
2125 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2126 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2127 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2129 echo "make sure there's no stale comp in the file"
2130 # make sure there's no stale comp in the file
2131 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2132 ( $LFS getstripe $tf; error "stale mirror file" )
2135 [[ $str == "YYY" ]] ||
2136 ( cat $tf; error "$tf content is not YYY after split" )
2138 run_test 44b "mirror split does not create stale file"
2141 local tf=$DIR/$tdir/$tfile
2143 stack_trap "rm -f $tf"
2145 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2146 skip "Need MDS version at least 2.14.52"
2148 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2150 mkdir -p $DIR/$tdir || error "create directroy failed"
2152 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2154 block1=$(( $(stat -c "%b*%B" $tf) ))
2155 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2157 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2159 block2=$(( $(stat -c "%b*%B" $tf) ))
2160 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2162 $LFS mirror split -d --mirror-id=2 $tf ||
2163 error "mirror split $tfile failed"
2164 $LFS mirror split -d --mirror-id=3 $tf ||
2165 error "mirror split $tfile failed"
2168 block3=$(( $(stat -c "%b*%B" $tf) ))
2169 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2171 [[ $block1 -eq $block3 ]] ||
2172 error "mirror split does not reduce block# $block3 != $block1"
2174 run_test 44c "lfs mirror split reduces block size of a file"
2177 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2179 local file=$DIR/$tdir/$tfile
2180 local dir=$DIR/$tdir/$dir
2181 local temp=$DIR/$tdir/template
2183 test_mkdir $DIR/$tdir
2185 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2186 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2187 error "Create $file failed"
2189 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2190 rm -f $file $file.copy
2192 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2193 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2194 error "Create $file failed"
2196 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2198 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2205 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2207 local layout1=$(get_layout_param $src)
2208 local layout2=$(get_layout_param $dst)
2209 # compare their layout info
2210 [ "$layout1" == "$layout2" ] ||
2211 error "$msg_prefix $src <=> $dst layouts are not equal"
2215 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2217 local file=$DIR/$tdir/$tfile
2218 test_mkdir $DIR/$tdir
2220 ########################### 1. PFL file #############################
2221 echo " ** 1. PFL file"
2223 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2224 $file || error "1. Create PFL $file failed"
2227 verify_46 $file $file.copy "1. PFL file"
2229 ########################### 2. plain file ###########################
2230 echo " ** 2. plain file"
2232 $LFS setstripe -c2 -o0,1 -i1 $file ||
2233 error "2. Create plain $file failed"
2236 verify_46 $file $file.copy "2. plain file"
2238 ########################### 3. FLR file #############################
2239 echo " ** 3. FLR file"
2241 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2242 $file || error "3. Create FLR $file failed"
2245 verify_46 $file $file.copy "3. FLR file"
2247 local dir=$DIR/$tdir/dir
2248 ########################### 4. PFL dir ##############################
2249 echo " ** 4. PFL dir"
2251 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2252 error "4. setstripe PFL $dir failed"
2254 test_mkdir $dir.copy
2255 verify_46 $dir $dir.copy "4. PFL dir"
2257 ########################### 5. plain dir ############################
2258 echo " ** 5. plain dir"
2259 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2261 verify_46 $dir $dir.copy "5. plain dir"
2263 ########################### 6. FLR dir ##############################
2264 echo " ** 6. FLR dir"
2265 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2266 error "6. setstripe FLR $dir failed"
2268 verify_46 $dir $dir.copy "6. FLR dir"
2270 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2271 echo "server version $MDS1_VERSION does not support SEL" &&
2274 ########################### 7. SEL file ##############################
2275 echo " ** 7. SEL file"
2277 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2278 $file || error "Create $file failed"
2281 verify_46 $file $file.copy "7. SEL file"
2283 ########################### 8. SEL dir ##############################
2284 echo " ** 8. SEL dir"
2285 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2286 $dir || error "setstripe $dir failed"
2288 verify_46 $dir $dir.copy "8. SEL dir"
2290 ########################### 9. FLR SEL file ##########################
2291 echo " ** 9. FLR SEL file"
2293 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2294 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2297 verify_46 $file $file.copy "9. SEL file"
2299 ########################### 10. FLR SEL dir #########################
2300 echo " ** 10. FLR SEL dir"
2301 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2302 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2304 verify_46 $dir $dir.copy "10. SEL dir"
2306 run_test 46 "Verify setstripe --copy option"
2309 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2311 local file=$DIR/$tdir/$tfile
2316 test_mkdir $DIR/$tdir
2320 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2321 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2322 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2323 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2324 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2326 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2327 $LFS mirror resync $file || error "resync $file failed"
2329 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2330 if [[ x$ost == "x0," ]]; then
2331 $LFS getstripe $file
2332 error "component ${ids[2]} objects allocated on $ost " \
2336 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2337 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2338 $LFS getstripe $file
2339 error "component ${ids[3]} objects allocated on $ost " \
2340 "shouldn't on OST1 or on OST2"
2345 # mirror1: [comp0] [comp1]
2346 # mirror2: [comp2] [comp3]
2347 # mirror3: [comp4] [comp5]
2348 # mirror4: [comp6] [comp7]
2349 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2350 error "create FLR $file failed"
2351 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2353 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2354 $LFS mirror resync $file || error "resync $file failed"
2356 for ((i = 0; i < 6; i++)); do
2357 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2358 awk '/l_ost_idx/{print $5}')
2360 # comp[0],comp[2],comp[4] should use different osts
2361 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2362 ${osts[2]} == ${osts[4]} ]]; then
2363 $LFS getstripe $file
2364 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2365 "allocated on duplicated OSTs"
2367 # comp[1],comp[3],comp[5] should use different osts
2368 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2369 ${osts[3]} == ${osts[5]} ]]; then
2370 $LFS getstripe $file
2371 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2372 "allocated on duplicated OSTs"
2377 run_test 47 "Verify mirror obj alloc"
2380 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2381 skip "Need MDS version at least 2.11.55"
2383 local tf=$DIR/$tfile
2386 echo " ** create 2 mirrors FLR file $tf"
2387 $LFS mirror create -N -E2M -Eeof --flags prefer \
2388 -N -E1M -Eeof $tf ||
2389 error "create FLR file $tf failed"
2392 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2393 verify_flr_state $tf "wp"
2395 local sum0=$(md5sum < $tf)
2397 echo " ** resync the file"
2398 $LFS mirror resync $tf
2400 echo " ** snapshot mirror 2"
2401 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2403 echo " ** write it again"
2404 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2405 echo " ** resync it again"
2406 $LFS mirror resync $tf
2408 verify_flr_state $tf "wp"
2409 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2411 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2412 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2414 echo " ** verify mirror 2 doesn't change"
2415 echo "original checksum: $sum0"
2416 echo "mirror 1 checksum: $sum1"
2417 echo "mirror 2 checksum: $sum2"
2418 [[ $sum0 = $sum2 ]] ||
2419 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2420 echo " ** mirror 2 stripe info"
2421 $LFS getstripe -v --mirror-index=2 $tf
2423 echo " ** resync mirror 2"
2424 $LFS mirror resync --only 2 $tf
2426 verify_flr_state $tf "ro"
2427 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2429 sum1=$($LFS mirror read -N1 $tf | md5sum)
2430 sum2=$($LFS mirror read -N2 $tf | md5sum)
2432 echo " ** verify mirror 2 resync-ed"
2433 echo "original checksum: $sum0"
2434 echo "mirror 1 checksum: $sum1"
2435 echo "mirror 2 checksum: $sum2"
2436 [[ $sum1 = $sum2 ]] ||
2437 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2438 echo " ** mirror 2 stripe info"
2439 $LFS getstripe -v --mirror-index=2 $tf
2441 run_test 48 "Verify snapshot mirror"
2450 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
2452 trap cleanup_49 EXIT RETURN
2454 local file=$DIR/$tfile
2456 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2457 error "setstripe on $file"
2459 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2460 $LFS mirror resync $file
2462 filefrag -ves $file || error "filefrag $file failed"
2463 filefrag_op=$(filefrag -ve -k $file |
2464 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2466 #Filesystem type is: bd00bd0
2467 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2468 # ext: device_logical: physical_offset: length: dev: flags:
2469 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2470 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2471 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2473 last_lun=$(echo $filefrag_op | cut -d: -f5)
2477 for line in $filefrag_op; do
2478 frag_lun=$(echo $line | cut -d: -f5)
2479 ext_len=$(echo $line | cut -d: -f4)
2480 if [[ "$frag_lun" != "$last_lun" ]]; then
2481 if (( tot_len != 1024 )); then
2483 error "$file: OST$last_lun $tot_len != 1024"
2489 (( tot_len += ext_len ))
2492 if (( num_luns != 2 || tot_len != 1024 )); then
2494 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2497 echo "FIEMAP on $file succeeded"
2499 run_test 49a "FIEMAP upon FLR file"
2501 test_50A() { # EX-2179
2504 local file=$DIR/$tdir/$tfile
2506 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2508 $LFS mirror extend -N -c1 -i1 $file ||
2509 error "extending mirror for $file failed"
2511 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2515 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2517 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2519 echo "$file layout generation from $olv to $flv"
2520 (( $flv != ($olv + 1) )) &&
2521 error "split does not increase layout gen from $olv to $flv"
2523 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2525 $LFS getstripe -v $file || error "getstripe $file failed"
2527 run_test 50A "mirror split update layout generation"
2530 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2531 skip "OST does not support SEEK_HOLE"
2533 local file=$DIR/$tdir/$tfile
2541 echo " ** create striped file $file"
2542 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2543 error "cannot create file with PFL layout"
2544 echo " ** write 1st data chunk at 1M boundary"
2545 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2546 error "cannot write data at 1M boundary"
2547 echo " ** write 2nd data chunk at 2M boundary"
2548 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2549 error "cannot write data at 2M boundary"
2550 echo " ** create hole at the file end"
2551 $TRUNCATE $file 3700000 || error "truncate fails"
2553 echo " ** verify sparseness"
2554 offset=$(lseek_test -d 1000 $file)
2555 echo " first data offset: $offset"
2556 [[ $offset == 1000 ]] &&
2557 error "src: data is not expected at offset $offset"
2558 offset=$(lseek_test -l 3500000 $file)
2559 echo " hole at the end: $offset"
2560 [[ $offset == 3500000 ]] ||
2561 error "src: hole is expected at offset $offset"
2563 echo " ** extend the file with new mirror"
2564 # migrate_copy_data() is used
2565 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2566 error "cannot create mirror"
2567 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2568 error "$file still has stale component"
2570 # check migrate_data_copy() was correct
2571 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2572 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2573 [[ $sum_1 == $sum_2 ]] ||
2574 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2576 # stale first mirror
2577 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2578 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2580 echo " ** verify mirror #2 sparseness"
2581 offset=$(lseek_test -d 1000 $file)
2582 echo " first data offset: $offset"
2583 [[ $offset == 1000 ]] &&
2584 error "dst: data is not expected at offset $offset"
2585 offset=$(lseek_test -l 3500000 $file)
2586 echo " hole at the end: $offset"
2587 [[ $offset == 3500000 ]] ||
2588 error "dst: hole is expected at offset $offset"
2590 echo " ** copy mirror #2 to mirror #1"
2591 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2592 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2593 error "$file still has stale component"
2595 # check llapi_mirror_copy_many correctness
2596 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2597 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2598 [[ $sum_1 == $sum_2 ]] ||
2599 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2601 # stale 1st component of mirror #2 before lseek call
2602 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2604 echo " ** verify mirror #1 sparseness again"
2605 offset=$(lseek_test -d 1000 $file)
2606 echo " first data offset: $offset"
2607 [[ $offset == 1000 ]] &&
2608 error "dst: data is not expected at offset $offset"
2609 offset=$(lseek_test -l 3500000 $file)
2610 echo " hole at the end: $offset"
2611 [[ $offset == 3500000 ]] ||
2612 error "dst: hole is expected at offset $offset"
2614 cancel_lru_locks osc
2616 blocks=$(stat -c%b $file)
2617 echo " ** final consumed blocks: $blocks"
2618 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2619 # that file is still sparse
2620 (( blocks < 1000 )) ||
2621 error "Mirrored file consumes $blocks blocks"
2625 run_test 50a "mirror extend/copy preserves sparseness"
2628 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2629 skip "OST does not support SEEK_HOLE"
2631 local file=$DIR/$tdir/$tfile
2639 echo " ** create mirrored file $file"
2640 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2641 -N -E2M -S1M -E eof -S2M $file ||
2642 error "cannot create mirrored file"
2643 echo " ** write data chunk at 1M boundary"
2644 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2645 error "cannot write data at 1M boundary"
2646 echo " ** create hole at the file end"
2647 $TRUNCATE $file 3700000 || error "truncate fails"
2649 echo " ** verify sparseness"
2650 offset=$(lseek_test -d 1000 $file)
2651 echo " first data offset: $offset"
2652 [[ $offset == 1000 ]] &&
2653 error "src: data is not expected at offset $offset"
2654 offset=$(lseek_test -l 3500000 $file)
2655 echo " hole at the end: $offset"
2656 [[ $offset == 3500000 ]] ||
2657 error "src: hole is expected at 3500000"
2659 echo " ** resync mirror #2 to mirror #1"
2660 $LFS mirror resync $file
2662 # check llapi_mirror_copy_many correctness
2663 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2664 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2665 [[ $sum_1 == $sum_2 ]] ||
2666 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2668 cancel_lru_locks osc
2670 blocks=$(stat -c%b $file)
2671 echo " ** consumed blocks: $blocks"
2672 # without full punch() support the first component can be not sparse
2673 # but the last one should be, so file should use far fewer blocks
2674 (( blocks < 5000 )) ||
2675 error "Mirrored file consumes $blocks blocks"
2677 # stale first component in mirror #1
2678 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2679 echo " ** truncate file down"
2681 echo " ** write data chunk at 2M boundary"
2682 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2683 error "cannot write data at 2M boundary"
2684 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2685 $LFS mirror resync $file || error "mirror rsync fails"
2686 # first component is still stale
2687 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2688 error "$file still has no stale component"
2689 echo " ** resync mirror #2 to mirror #1 again"
2690 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2691 $LFS mirror resync $file || error "mirror rsync fails"
2692 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2693 error "$file still has stale component"
2695 # check llapi_mirror_copy_many correctness
2696 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2697 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2698 [[ $sum_1 == $sum_2 ]] ||
2699 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2701 cancel_lru_locks osc
2703 blocks=$(stat -c%b $file)
2704 echo " ** final consumed blocks: $blocks"
2705 # while the first component can lose sparseness, the last one should
2706 # not, so whole file should still use far fewer blocks in total
2707 (( blocks < 3000 )) ||
2708 error "Mirrored file consumes $blocks blocks"
2711 run_test 50b "mirror rsync handles sparseness"
2714 local tf=$DIR/$tdir/$tfile
2716 test_mkdir $DIR/$tdir
2718 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
2719 verify_flr_state $tf "ro"
2721 if [[ "$FSTYPE" == "ldiskfs" ]]; then
2722 # ZFS does not support fallocate for now
2723 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
2724 skip_eopnotsupp "$out|punch hole in $tf failed"
2725 verify_flr_state $tf "wp"
2728 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
2729 $LFS mirror resync $tf || error "mirror resync $tf failed"
2730 verify_flr_state $tf "ro"
2732 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
2733 verify_flr_state $tf "wp"
2735 run_test 50c "punch_hole/mmap_write stale other mirrors"
2738 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2739 skip "OST does not support SEEK_HOLE"
2740 (( $LINUX_VERSION_CODE > $(version_code 3.0.0) )) ||
2741 skip "client kernel does not support SEEK_HOLE"
2743 local file=$DIR/$tdir/$tfile
2750 echo " ** create mirrored file $file"
2751 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2752 -N -E2M -S1M -E eof -S2M $file ||
2753 error "cannot create mirrored file"
2754 echo " ** write data chunk at 1M boundary"
2755 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2756 error "cannot write data at 1M boundary"
2757 echo " ** create hole at the file start"
2758 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
2761 if [[ $rc -eq 0 ]]; then
2762 verify_flr_state $file "wp"
2763 elif [[ ! $prt =~ unsupported ]]; then
2764 error "punch hole in $file failed: $prt"
2766 skip "Fallocate punch is not supported: $prt"
2769 echo " ** verify sparseness"
2770 offset=$(lseek_test -d 1000 $file)
2771 echo " first data offset: $offset"
2772 (( $offset >= 1024 * 1024 )) ||
2773 error "src: data is not expected at offset $offset"
2775 echo " ** resync mirror #2"
2776 $LFS mirror resync $file
2778 # check llapi_mirror_copy_many correctness
2779 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2780 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2781 [[ $sum_1 == $sum_2 ]] ||
2782 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2784 cancel_lru_locks osc
2786 # stale first component in mirror #1
2787 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2788 echo " ** verify sparseness of mirror #2"
2789 offset=$(lseek_test -d 1000 $file)
2790 echo " first data offset: $offset"
2791 (( $offset >= 1024 * 1024 )) ||
2792 error "src: data is not expected at offset $offset"
2794 run_test 50d "mirror rsync keep holes"
2797 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2798 skip "OST does not support SEEK_HOLE"
2800 local file=$DIR/$tdir/$tfile
2801 local old_size=2147483648 # 2GiB
2805 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
2806 $TRUNCATE $file $old_size
2808 $LFS mirror extend -N -c 1 $file
2809 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
2810 $LFS mirror resync $file
2812 new_size=$(stat --format='%s' $file)
2813 if ((new_size != old_size)); then
2814 error "new_size ($new_size) is not equal to old_size ($old_size)"
2819 run_test 60a "mirror extend sets correct size on sparse file"
2821 get_flr_layout_gen() {
2822 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
2823 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
2826 check_layout_gen() {
2829 local v1=$(get_flr_layout_gen $tf)
2830 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
2832 [[ $v1 -eq $v2 ]] ||
2833 error "$tf in-memory layout gen $v1 != $v2 after $2"
2837 local tf=$DIR/$tdir/$tfile
2839 test_mkdir $DIR/$tdir
2841 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
2843 for ((i = 0; i < 20; i++)); do
2844 $LFS mirror extend -N $tf ||
2845 error "extending mirror for $tf failed"
2846 check_layout_gen $tf "extend"
2848 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
2849 error "split $tf failed"
2850 check_layout_gen $tf "split"
2853 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
2856 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
2861 local -a old=( $2 $3 $4 )
2864 new=( $(get_times_61 $file) )
2865 ((${old[0]} == ${new[0]})) ||
2866 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
2868 ((${old[1]} == ${new[1]})) ||
2869 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
2872 test_61a() { # LU-14508
2873 local file=$DIR/$tdir/$tfile
2879 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
2880 echo "create $file-2"
2881 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
2883 echo XXX > $file || error "write $file failed"
2884 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
2886 echo "sleep $nap seconds, then cat $tfile"
2888 cat $file || error "cat $file failed"
2890 echo "sleep $nap seconds, then re-write $tfile"
2892 echo XXXX > $file || error "write $file failed"
2893 cp -p $file $file-2 || error "copy $file-2 failed"
2895 echo "sleep $nap seconds"
2898 tim=( $(get_times_61 $file) )
2900 echo "mirror merge $tfile-2 to $tfile and test timestamps"
2901 $LFS mirror extend -N -f $file-2 $file ||
2902 error "cannot mirror merge $file-2 to $file"
2903 check_times_61 $file "${tim[@]}"
2905 echo "mirror extend $tfile and test timestamps"
2906 $LFS mirror extend -N -c1 -i1 $file ||
2907 error "cannot extend mirror $file"
2908 check_times_61 $file "${tim[@]}"
2910 echo "migrate $tfile and test timestamps"
2911 $LFS migrate -n $file || error "cannot migrate $file"
2912 check_times_61 $file "${tim[@]}"
2914 echo "normal user migrate $tfile and test timestamps"
2915 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
2916 check_times_61 $file "${tim[@]}"
2918 run_test 61a "mirror extend and migrate preserve timestamps"
2920 test_61b() { # LU-14508
2921 local file=$DIR/$tdir/$tfile
2927 echo XXX > $file || error "create $file failed"
2928 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
2930 echo "sleep $nap seconds, then cat $tfile"
2932 cat $file || error "cat $file failed"
2934 echo "sleep $nap seconds, then re-write $tfile"
2936 echo XXXX > $file || error "write $file failed"
2938 echo "sleep $nap seconds, then test timestamps"
2941 tim=( $(get_times_61 $file) )
2943 echo "mirror extend $tfile and test timestamps"
2944 $LFS mirror extend -N -c1 -i1 $file ||
2945 error "cannot extend mirror $file"
2946 check_times_61 $file "${tim[@]}"
2948 echo "mirror split $tfile and test timestamps"
2949 $LFS mirror split -d --mirror-id=1 $file ||
2950 error "cannot split mirror 1 off $file"
2951 check_times_61 $file "${tim[@]}"
2953 echo "normal user mirror extend $tfile and test timestamps"
2954 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
2955 error "cannot extend mirror $file"
2956 check_times_61 $file "${tim[@]}"
2958 run_test 61b "mirror extend and split preserve timestamps"
2960 test_61c() { # LU-14508
2961 local file=$DIR/$tdir/$tfile
2967 echo XXX > $file || error "create $file failed"
2968 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
2970 echo "sleep $nap seconds, then cat $tfile"
2972 cat $file || error "cat $file failed"
2974 echo "sleep $nap seconds, then mirror extend $tfile and write it"
2976 $LFS mirror extend -N -c1 -i1 $file ||
2977 error "cannot extend mirror $file"
2978 echo XXXX > $file || error "write $file failed"
2980 echo "sleep $nap seconds, then resync $tfile and test timestamps"
2981 tim=( $(get_times_61 $file) )
2983 $LFS mirror resync $file || error "cannot resync mirror $file"
2984 check_times_61 $file "${tim[@]}"
2986 echo XXXXXX > $file || error "write $tfile failed"
2988 echo "normal user resync $tfile and test timestamps"
2989 tim=( $(get_times_61 $file) )
2990 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
2991 check_times_61 $file "${tim[@]}"
2993 run_test 61c "mirror resync preserves timestamps"
2996 local tf=$DIR/$tdir/$tfile
2998 test_mkdir $DIR/$tdir
3002 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3006 echo "mirror create pid $c_pid"
3009 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3012 echo "mirror split pid $s_pid"
3014 echo "mirror create and split race for 60 seconds, should not crash"
3016 kill -9 $c_pid &> /dev/null
3017 kill -9 $s_pid &> /dev/null
3022 run_test 70 "mirror create and split race"
3024 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3025 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3030 local fsize=$(stat --printf=%s $tf)
3032 while [ -f $ctrl_file ]; do
3033 local off=$((RANDOM << 8))
3034 local len=$((RANDOM << 5 + 131072))
3036 [ $((off + len)) -gt $fsize ] && {
3037 fsize=$((off + len))
3038 echo "Extending file size to $fsize .."
3041 flock -s $lock_file -c \
3042 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3044 error "failed writing to $off:$len"; }
3045 sleep 0.$((RANDOM % 2 + 1))
3052 while [ -f $ctrl_file ]; do
3053 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3054 { rm -f $ctrl_file; error "read failed"; }
3055 sleep 0.$((RANDOM % 2 + 1))
3062 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3064 exec 200<>$lock_file
3065 while [ -f $ctrl_file ]; do
3066 local lock_taken=false
3067 local index=$((RANDOM % ${#options[@]}))
3068 local cmd="mirror_io resync ${options[$index]}"
3070 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3072 [ $((RANDOM % 4)) -eq 0 ] && {
3078 echo -n "resync file $tf with '$cmd' .."
3080 if [[ $lock_taken = "true" ]]; then
3082 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3085 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3088 sleep 0.$((RANDOM % 8 + 1))
3093 local tf=$DIR/$tfile
3094 local tf2=$DIR2/$tfile
3095 local tf3=$DIR3/$tfile
3097 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3098 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3099 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3101 $LFS mirror extend -N -f $tf-2 $tf ||
3102 error "merging $tf-2 into $tf failed"
3103 $LFS mirror extend -N -f $tf-3 $tf ||
3104 error "merging $tf-3 into $tf failed"
3106 mkdir -p $MOUNT2 && mount_client $MOUNT2
3108 mkdir -p $MOUNT3 && mount_client $MOUNT3
3110 verify_flr_state $tf3 "ro"
3112 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3113 $LCTL set_param fail_loc=0x1A03
3115 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3116 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3120 write_file_200 $tf &
3126 write_file_200 $tf2 &
3129 read_file_200 $tf2 &
3132 resync_file_200 $tf3 &
3136 [ "$SLOW" = "yes" ] && sleep_time=360
3137 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3144 echo "Waiting ${pids[*]}"
3147 umount_client $MOUNT2
3148 umount_client $MOUNT3
3152 # resync and verify mirrors
3153 $LFS mirror resync $tf || error "final resync failed"
3156 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3158 for id in "${mirror_array[@]:1}"; do
3159 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3160 error "checksum error for mirror $id"
3165 run_test 200 "stress test"
3167 cleanup_test_201() {
3169 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3171 umount_client $MOUNT2
3175 local delay=${RESYNC_DELAY:-5}
3177 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3178 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3180 trap cleanup_test_201 EXIT
3182 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3183 changelog_register -n)
3185 mkdir -p $MOUNT2 && mount_client $MOUNT2
3189 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3190 [ -z "$log" ] && { sleep 1; continue; }
3192 index=$(echo $log | awk '{print $1}')
3193 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3194 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3195 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3198 [ -z "$file" ] && continue
3200 local now=$(date +%s)
3202 echo "file: $file $fid was modified at $ts, now: $now, " \
3203 "will be resynced at $((ts+delay))"
3205 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3207 $LFS mirror resync $file
3208 echo "$file resync done"
3213 run_test 201 "FLR data mover"
3216 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3218 local tf=$DIR/$tfile
3221 $LFS setstripe -E 1M -S 1M -c 1 $tf
3222 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3223 verify_comp_attr stripe-count $tf ${ids[0]} 1
3225 $LFS setstripe --component-add -E 2M -c -1 $tf
3226 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3227 verify_comp_attr stripe-count $tf ${ids[0]} 1
3228 verify_comp_attr stripe-count $tf ${ids[1]} -1
3230 dd if=/dev/zero of=$tf bs=1M count=2
3231 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3232 verify_comp_attr stripe-count $tf ${ids[0]} 1
3233 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3235 run_test 202 "lfs setstripe --add-component wide striping"
3238 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3239 skip "Need MDS version at least 2.11.55"
3240 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3242 local tf=$DIR/$tfile
3245 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3246 #delete first mirror
3247 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3250 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3251 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3252 error "getstripe count of mirror 2"
3253 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3255 #extend a mirror with 2 OSTs
3256 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3259 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3260 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3261 error "getstripe count of mirror 2"
3262 [[ x$old_id = x$new_id ]] ||
3263 error "mirror 2 changed ID from $old_id to $new_id"
3264 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3266 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3267 error "getstripe count of mirror 3"
3268 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3270 run_test 203 "mirror file preserve mirror ID"
3272 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3274 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3275 skip "skipped for lustre < $SEL_VER"
3277 local comp_file=$DIR/$tdir/$tfile
3281 test_mkdir $DIR/$tdir
3283 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3284 # by extension space to -1
3285 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3286 error "Create $comp_file failed"
3288 # Write to first component, extending & staling second mirror
3289 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3290 error "dd to extend + stale failed"
3292 $LFS getstripe $comp_file
3294 flg_opts="--component-flags init,stale"
3295 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3296 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3298 flg_opts="--component-flags extension"
3299 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3300 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3302 # mirror resync should not change the extents
3303 $LFS mirror resync $comp_file
3305 flg_opts="--component-flags init"
3306 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3307 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3309 flg_opts="--component-flags extension"
3310 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3311 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3313 sel_layout_sanity $comp_file 5
3317 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3319 # Simple test of FLR + self-extending layout, SEL in primary mirror
3321 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3322 skip "skipped for lustre < $SEL_VER"
3324 local comp_file=$DIR/$tdir/$tfile
3328 test_mkdir $DIR/$tdir
3330 # first mirror is 1M followed by extension space to -1, second mirror
3331 # is 0-10M, then 10M-(-1),
3332 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3333 error "Create $comp_file failed"
3335 # Write to first component, extending first component & staling
3337 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3338 error "dd to extend + stale failed"
3340 $LFS getstripe $comp_file
3342 flg_opts="--component-flags init"
3343 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3344 [ $found -eq 1 ] || error "write: First comp end incorrect"
3346 flg_opts="--component-flags extension"
3347 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3348 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3350 flg_opts="--component-flags init,stale"
3351 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3352 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3354 # This component is staled because it overlaps the extended first
3355 # component of the primary mirror, even though it doesn't overlap
3356 # the actual write - thus not inited.
3357 flg_opts="--component-flags stale"
3358 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3359 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3361 # mirror resync should not change the extents
3362 $LFS mirror resync $comp_file
3364 $LFS getstripe $comp_file
3366 flg_opts="--component-flags init"
3367 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3368 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3370 flg_opts="--component-flags extension"
3371 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3372 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3374 flg_opts="--component-flags init"
3375 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3376 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3378 flg_opts="--component-flags init"
3379 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3380 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3382 sel_layout_sanity $comp_file 5
3386 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3388 # FLR + SEL failed extension & component removal
3389 # extension space in second mirror
3391 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3392 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3393 skip "skipped for lustre < $SEL_VER"
3395 local comp_file=$DIR/$tdir/$tfile
3398 local ost_name=$(ostname_from_index $ost_idx1)
3400 test_mkdir $DIR/$tdir
3402 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3403 # extension space from 1M to 1G, then normal space to -1
3404 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3405 -E -1 $comp_file || error "Create $comp_file failed"
3407 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3410 # write to first comp (0 - 10M) of mirror 1, extending + staling
3411 # first + second comp of mirror 2
3412 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3415 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3418 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3420 $LFS getstripe $comp_file
3422 found=$($LFS find --component-start 0m --component-end 1m \
3423 --comp-flags init,stale $comp_file | wc -l)
3424 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3426 found=$($LFS find --component-start 1m --component-end EOF \
3427 --comp-flags stale,^init $comp_file | wc -l)
3428 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3430 local mirror_id=$($LFS getstripe --component-start=1m \
3431 --component-end=EOF $comp_file | \
3432 grep lcme_mirror_id | awk '{ print $2 }')
3434 [[ $mirror_id -eq 2 ]] ||
3435 error "component not in correct mirror? $mirror_id"
3437 $LFS mirror resync $comp_file
3439 $LFS getstripe $comp_file
3441 # component dimensions should not change from resync
3442 found=$($LFS find --component-start 1m --component-end EOF \
3443 --component-flags init $comp_file | wc -l)
3444 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3446 sel_layout_sanity $comp_file 4
3450 run_test 204c "FLR write/stale/resync test with component removal"
3452 # Successful repeated component in primary mirror
3454 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3455 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3456 skip "skipped for lustre < $SEL_VER"
3458 local comp_file=$DIR/$tdir/$tfile
3461 wait_delete_completed
3463 test_mkdir $DIR/$tdir
3465 # first mirror is 64M followed by extension space to -1, second mirror
3466 # is 0-10M, then 10M-(-1)
3467 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3468 error "Create $comp_file failed"
3470 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3471 local ost_name=$(ostname_from_index $ost_idx1)
3472 # degrade OST for first comp so we won't extend there
3473 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3474 obdfilter.$ost_name.degraded=1
3477 # Write beyond first component, causing repeat & stale second mirror
3478 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3481 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3482 obdfilter.$ost_name.degraded=0
3485 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3487 $LFS getstripe $comp_file
3489 found=$($LFS find --component-start 64m --component-end 128m \
3490 --component-flags init $comp_file | wc -l)
3491 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3493 local ost_idx2=$($LFS getstripe --component-start=64m \
3494 --component-end=128m --component-flags=init \
3496 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3497 local mirror_id=$($LFS getstripe --component-start=64m \
3498 --component-end=128m --component-flags=init \
3499 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3500 [[ $mirror_id -eq 1 ]] ||
3501 error "component not in correct mirror: $mirror_id, not 1"
3503 $LFS mirror resync $comp_file
3505 $LFS getstripe $comp_file
3507 # component dimensions should not change from resync
3508 found=$($LFS find --component-start 0m --component-end 64m \
3509 --component-flags init $comp_file | wc -l)
3510 [ $found -eq 1 ] || error "resync: first comp incorrect"
3511 found=$($LFS find --component-start 64m --component-end 128m \
3512 --component-flags init $comp_file | wc -l)
3513 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3515 sel_layout_sanity $comp_file 5
3519 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3521 # Successful repeated component, SEL in non-primary mirror
3523 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3524 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3525 skip "skipped for lustre < $SEL_VER"
3527 local comp_file=$DIR/$tdir/$tfile
3530 wait_delete_completed
3533 test_mkdir $DIR/$tdir
3535 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
3536 # space to -1 (-z 64M, so first comp is 0-64M)
3537 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
3538 # will be not enough - one will be degraded, the other is used on
3539 # an overlapping mirror.
3540 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
3541 error "Create $comp_file failed"
3543 local ost_idx1=$($LFS getstripe --component-start=0 \
3544 --component-end=64m -i $comp_file)
3545 local ost_name=$(ostname_from_index $ost_idx1)
3546 # degrade OST for first comp of 2nd mirror so we won't extend there
3547 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3548 obdfilter.$ost_name.degraded=1
3551 $LFS getstripe $comp_file
3553 # Write to first component, stale & instantiate second mirror components
3554 # overlapping with the written component (0-100M);
3555 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3558 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3559 obdfilter.$ost_name.degraded=0
3561 $LFS getstripe $comp_file
3563 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3565 found=$($LFS find --component-start 0m --component-end 64m \
3566 --component-flags init,stale $comp_file | wc -l)
3567 [ $found -eq 1 ] || error "write: first comp incorrect"
3569 # was repeated due to degraded ost
3570 found=$($LFS find --component-start 64m --component-end 128m \
3571 --component-flags init,stale $comp_file | wc -l)
3572 [ $found -eq 1 ] || error "write: repeated comp incorrect"
3574 local ost_idx2=$($LFS getstripe --component-start=64m \
3575 --component-end=128m --component-flags=init \
3577 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3578 local mirror_id=$($LFS getstripe --component-start=0m \
3579 --component-end=64m --component-flags=init \
3580 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3581 [[ $mirror_id -eq 2 ]] ||
3582 error "component not in correct mirror? $mirror_id"
3584 $LFS mirror resync $comp_file
3586 $LFS getstripe $comp_file
3588 # component dimensions should not change from resync
3589 found=$($LFS find --component-start 0m --component-end 64m \
3590 --component-flags init,^stale $comp_file | wc -l)
3591 [ $found -eq 1 ] || error "resync: first comp incorrect"
3592 found=$($LFS find --component-start 64m --component-end 128m \
3593 --component-flags init,^stale $comp_file | wc -l)
3594 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
3596 sel_layout_sanity $comp_file 5
3600 run_test 204e "FLR write/stale/resync sel test with repeated comp"
3602 # FLR + SEL: failed repeated component, SEL in non-primary mirror
3604 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3605 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3606 skip "skipped for lustre < $SEL_VER"
3608 local comp_file=$DIR/$tdir/$tfile
3611 wait_delete_completed
3613 test_mkdir $DIR/$tdir
3615 pool_add $TESTNAME || error "Pool creation failed"
3616 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
3618 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
3619 # space to -1 (-z 64M, so first comp is 0-64M)
3620 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
3621 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
3623 local ost_name0=$(ostname_from_index 0)
3624 local ost_name1=$(ostname_from_index 1)
3626 # degrade both OSTs in pool, so we'll try to repeat, then fail and
3627 # extend original comp
3628 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
3629 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
3632 # a write to the 1st component, 100M length, which will try to stale
3633 # the first 100M of mirror 2, attempting to extend its 0-64M component
3634 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3637 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
3638 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
3641 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
3643 $LFS getstripe $comp_file
3645 found=$($LFS find --component-start 0m --component-end 128m \
3646 --component-flags init,stale $comp_file | wc -l)
3647 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3649 local mirror_id=$($LFS getstripe --component-start=0m \
3650 --component-end=128m --component-flags=init \
3651 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3653 [[ $mirror_id -eq 2 ]] ||
3654 error "component not in correct mirror? $mirror_id, not 2"
3656 $LFS mirror resync $comp_file
3658 $LFS getstripe $comp_file
3660 # component dimensions should not change from resync
3661 found=$($LFS find --component-start 0m --component-end 128m \
3662 --component-flags init,^stale $comp_file | wc -l)
3663 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
3665 sel_layout_sanity $comp_file 4
3669 run_test 204f "FLR write/stale/resync sel w/forced extension"
3671 function test_205() {
3672 local tf=$DIR/$tfile
3675 $LFS setstripe -c1 $tf
3676 $LFS mirror extend -N $tf
3677 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
3678 (( $mirrors == 2 )) || error "no new mirror was created?"
3680 $LFS mirror extend -N --flags=prefer $tf
3681 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
3682 (( $mirrors == 3 )) || error "no new mirror was created?"
3684 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
3685 error "prefer flag was not set on the new mirror"
3687 run_test 205 "lfs mirror extend to set prefer flag"
3689 function test_206() {
3690 # create a new OST pool
3691 local pool_name=$TESTNAME
3693 create_pool $FSNAME.$pool_name ||
3694 error "create OST pool $pool_name failed"
3695 # add OSTs into the pool
3696 pool_add_targets $pool_name 0 1 ||
3697 error "add OSTs into pool $pool_name failed"
3699 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
3700 error "can't setstripe"
3701 $LFS mirror extend -N $DIR/$tfile ||
3702 error "can't create replica"
3703 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
3704 $LFS getstripe $DIR/$tfile
3705 error "prefer found"
3707 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
3708 $LFS getstripe $DIR/$tfile
3709 error "can't setstripe prefer"
3712 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
3713 $LFS getstripe $DIR/$tfile
3714 error "no prefer found"
3720 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
3723 local file=$DIR/$tfile
3724 local tmpfile=$DIR/$tfile-tt
3726 [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
3727 skip "Need MDS version at least 2.14.50"
3729 stack_trap "rm -f $tmpfile $file"
3731 # generate data for verification
3732 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
3733 error "can't generate file with random data"
3735 # create a mirrored file with one stale replica
3736 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
3737 error "create mirrored file $file failed"
3738 get_mirror_ids $file
3739 echo "mirror IDs: ${mirror_array[*]}"
3741 dd if=$tmpfile of=$file bs=1M || error "can't copy"
3742 get_mirror_ids $file
3743 echo "mirror IDs: ${mirror_array[*]}"
3746 cmp $tmpfile $file || error "files don't match"
3747 get_mirror_ids $file
3748 echo "mirror IDs: ${mirror_array[*]}"
3750 # mirror creation should work fine
3751 $LFS mirror extend -N -S 8M -c -1 $file ||
3752 error "mirror extend $file failed"
3754 get_mirror_ids $file
3755 echo "mirror IDs: ${mirror_array[*]}"
3758 $LFS mirror verify -v $file || error "verification failed"
3759 cmp $tmpfile $file || error "files don't match"
3761 run_test 207 "create another replica with existing out-of-sync one"
3763 function check_ost_used() {
3772 cancel_lru_locks osc # to drop pages
3773 cancel_lru_locks mdc # to refresh layout
3774 # XXX: cancel_lru_locks mdc doesn't work
3775 # XXX: need a better way to reload the layout
3776 umount_client $MOUNT || error "umount failed"
3777 mount_client $MOUNT || error "mount failed"
3779 # refresh non-rotation status on MDTs
3781 touch $DIR/$tfile-temp
3782 rm -f $DIR/$tfile-temp
3783 # refresh non-rotational status on the client
3787 $LCTL set_param osc.*.stats=clear >/dev/null
3788 if [[ $io == "read" ]]; then
3789 ddarg="if=$file of=/dev/null"
3790 elif [[ $io == "write" ]]; then
3791 ddarg="if=/dev/zero of=$file"
3793 error "unknown type $io"
3795 dd $ddarg bs=2M count=1 || error "can't $io $file"
3796 cancel_lru_locks osc
3798 # check only specified OSTs got reads
3799 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
3800 local nr=$($LCTL get_param -n \
3801 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
3802 awk "/ost_$io/{print \$2}")
3804 if [[ " $* " =~ $ost ]]; then
3805 (( nr > 0 )) || error "expected reads on $ost"
3807 (( nr == 0 )) || error "unexpected $nr reads on $ost"
3813 local tf=$DIR/$tfile
3814 local osts=$(comma_list $(osts_nodes))
3816 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
3817 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
3818 skip "Need MDS version at least 2.14.55"
3820 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
3822 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
3823 stack_trap "restore_lustre_params < $p; rm -f $p"
3825 stack_trap "rm -f $tf"
3826 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
3827 dd if=/dev/zero of=$tf bs=2M count=1 || error "can't dd (1)"
3828 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
3829 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
3830 $LFS mirror resync $tf || error "can't resync"
3833 log "set OST0000 non-rotational"
3835 $LCTL set_param osd*.*OST0000*.nonrotational=1
3836 check_ost_used $tf read 0
3838 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
3840 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
3841 osd*.*OST0003*.nonrotational=1
3842 check_ost_used $tf read 2 3
3844 log "set mirror 1 on OST0001 preferred"
3845 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
3846 error "can't set prefer"
3847 check_ost_used $tf read 1
3849 run_test 208a "mirror selection to prefer non-rotational devices for reads"
3852 local tf=$DIR/$tfile
3853 local osts=$(comma_list $(osts_nodes))
3855 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
3856 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
3857 skip "Need MDS version at least 2.14.55"
3859 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
3861 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
3862 stack_trap "restore_lustre_params < $p; rm -f $p"
3864 stack_trap "rm -f $tf"
3865 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
3866 dd if=/dev/zero of=$tf bs=2M count=1 || error "can't dd (1)"
3867 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
3868 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
3869 $LFS mirror resync $tf || error "can't resync"
3870 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
3872 log "set OST0000 non-rotational"
3874 $LCTL set_param osd*.*OST0000*.nonrotational=1
3875 check_ost_used $tf write 0
3876 $LFS mirror resync $tf || error "can't resync"
3878 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
3880 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
3881 osd*.*OST0003*.nonrotational=1
3882 check_ost_used $tf write 2 3
3883 $LFS mirror resync $tf || error "can't resync"
3885 log "set mirror 1 on OST0001 preferred"
3886 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
3887 error "can't set prefer"
3888 check_ost_used $tf write 1
3890 run_test 208b "mirror selection to prefer non-rotational devices for writes"
3893 check_and_cleanup_lustre