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"
1065 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1066 cancel_lru_locks osc
1069 local tmpfile=$(mktemp)
1070 stat --format="%b %s" $tf > $tmpfile &
1074 while [ $cnt -le 5 ]; do
1075 kill -0 $pid > /dev/null 2>&1 || break
1079 kill -0 $pid > /dev/null 2>&1 &&
1080 error "stat process stuck due to unavailable OSTs"
1082 # make sure glimpse request has been sent
1083 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1084 error "OST $ost_idx: no glimpse request was sent"
1089 run_test 31 "make sure glimpse request can be retried"
1092 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1093 rm -f $DIR/$tfile $DIR/$tfile-2
1095 stack_trap "rm -f $DIR/$tfile"
1097 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1098 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1100 local fsize=$(stat -c %s $DIR/$tfile)
1101 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1103 local cksum=$(md5sum $DIR/$tfile)
1105 # create a new mirror in sync mode
1106 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1107 error "extending mirrored file $DIR/$tfile failed"
1109 # make sure the mirrored file was created successfully
1110 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1111 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1116 # check size is correct, glimpse request should go to the 2nd mirror
1117 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1118 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1120 echo "reading file from the 2nd mirror and verify checksum"
1121 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1122 error "checksum error: expected $cksum"
1126 run_test 32 "data should be mirrored to newly created mirror"
1129 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1131 rm -f $DIR/$tfile $DIR/$tfile-2
1133 # create a file with two mirrors
1134 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1137 while [ $count -lt $max_count ]; do
1138 echo "ost1" >> $DIR/$tfile
1139 count=$((count + 1));
1142 # tmp file that will be used as mirror
1143 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1145 while [ $count -lt $max_count ]; do
1146 echo "ost2" >> $DIR/$tfile-2
1147 count=$((count + 1));
1150 # create a mirrored file
1151 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1152 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1153 "with verification should fail"
1154 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1155 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1156 "without verification failed"
1158 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1159 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1160 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1162 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1164 # execpted file size
1165 local fsize=$((5 * max_count))
1166 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1167 error "mirrored file size is not $fsize"
1169 # read file - all OSTs are available
1170 echo "reading file (data can be provided by any ost)... "
1171 local rs=$(cat $DIR/$tfile | head -1)
1172 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1173 error "file content error: expected: \"ost1\" or \"ost2\""
1175 # read file again with ost1 failed
1179 echo "reading file (data should be provided by ost2)..."
1180 local rs=$(cat $DIR/$tfile | head -1)
1181 [[ "$rs" == "ost2" ]] ||
1182 error "file content error: expected: \"ost2\", actual: \"$rs\""
1187 # read file again with ost2 failed
1191 # check size, glimpse should work
1192 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1193 error "mirrored file size is not $fsize"
1195 echo "reading file (data should be provided by ost1)..."
1196 local rs=$(cat $DIR/$tfile | head -1)
1197 [[ "$rs" == "ost1" ]] ||
1198 error "file content error: expected: \"ost1\", actual: \"$rs\""
1202 run_test 33a "read can choose available mirror to read"
1205 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1209 stack_trap "rm -f $DIR/$tfile" EXIT
1211 # create a file with two mirrors on OST0000 and OST0001
1212 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1214 # make sure that $tfile has two mirrors
1215 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1216 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1219 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1220 error "write failed for $DIR/$tfile"
1221 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1222 verify_flr_state $DIR/$tfile "ro"
1227 # read file - all OSTs are available
1228 echo "reading file (data can be provided by any ost)... "
1230 time cat $DIR/$tfile > /dev/null || error "read all"
1234 # read file again with ost1 {OST0000} failed
1237 echo "reading file (data should be provided by ost2)..."
1239 time cat $DIR/$tfile > /dev/null || error "read ost2"
1246 # read file again with ost2 {OST0001} failed
1250 echo "reading file (data should be provided by ost1)..."
1252 time cat $DIR/$tfile > /dev/null || error "read ost1"
1259 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1260 error "read mirror too slow without ost1, from $ra to $r1"
1261 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1262 error "read mirror too slow without ost2, from $ra to $r2"
1264 wait_osc_import_ready client ost2
1266 run_test 33b "avoid reading from unhealthy mirror"
1269 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1273 stack_trap "rm -f $DIR/$tfile" EXIT
1275 # create a file with two mirrors
1276 # mirror1: {OST0000, OST0001}
1277 # mirror2: {OST0001, OST0002}
1278 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1280 # make sure that $tfile has two mirrors
1281 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1282 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1285 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1286 error "write failed for $DIR/$tfile"
1287 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1288 verify_flr_state $DIR/$tfile "ro"
1293 # read file - all OSTs are available
1294 echo "reading file (data can be provided by any ost)... "
1295 time cat $DIR/$tfile > /dev/null || error "read all"
1297 # read file again with ost2 (OST0001) failed
1301 echo "reading file (data should be provided by ost1 and ost3)..."
1302 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1307 wait_osc_import_ready client ost2
1309 run_test 33c "keep reading among unhealthy mirrors"
1312 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1314 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1317 $LFS setstripe -o 0 $DIR/$tfile-ref
1318 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1320 # create a file with two mirrors
1321 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1322 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1324 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1325 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1327 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1328 error "mirrored file size is not 3M"
1330 # merge a mirrored file
1331 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1332 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1334 cancel_lru_locks osc
1336 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1337 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1340 echo "comparing files ... "
1342 # however, read can still return the correct data. It should return
1343 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1344 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1345 $DIR/$tfile-ref || error "file reading error"
1349 run_test 34a "read mirrored file with multiple stripes"
1352 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1354 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1357 $LFS setstripe -o 0 $DIR/$tfile-ref
1358 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1360 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1361 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1363 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1364 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1366 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1367 error "mirrored file size is not 3M"
1369 # merge a mirrored file
1370 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1371 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1373 cancel_lru_locks osc
1375 # stop two OSTs, so the 2nd component of the 1st mirror and
1376 # the 1st component of the 2nd mirror will be inaccessible, ...
1379 echo "comparing files ... "
1381 # however, read can still return the correct data. It should return
1382 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1383 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1384 $DIR/$tfile-ref || error "file reading error"
1388 run_test 34b "read mirrored file with multiple components"
1391 local tf=$DIR/$tfile
1393 $LFS setstripe -E eof $tf
1395 # add an out-of-sync mirror to the file
1396 $LFS mirror extend -N -c 2 $tf ||
1397 error "extending mirrored file $tf failed"
1399 $MULTIOP $tf oO_WRONLY:c ||
1400 error "write open a mirrored file failed"
1402 # truncate file should return error
1403 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1405 run_test 35 "allow to write to mirrored files"
1407 verify_ost_layout_version() {
1410 # get file layout version
1411 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1413 # layout version from OST objects
1414 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1416 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1423 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1424 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1426 $LFS mirror extend -N -f $tf-tmp $tf ||
1427 error "merging $tf-tmp into $tf failed"
1432 local tf=$DIR/$tfile
1434 stack_trap "rm -f $tf $tf-2 $tf-3"
1436 create_file_36 $tf $tf-2 $tf-3
1438 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1440 # test case 1 - check file write and verify layout version
1441 $MULTIOP $tf oO_WRONLY:c ||
1442 error "write open a mirrored file failed"
1444 # write open file should not return error
1445 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1447 # instantiate components should work
1448 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1450 # verify OST layout version
1451 verify_ost_layout_version $tf
1454 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1457 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1459 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1460 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1462 # write should take at least $fail_loc seconds and succeed
1463 local st=$(date +%s)
1464 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1466 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1467 error "write finished before layout version is transmitted"
1469 # verify OST layout version
1470 verify_ost_layout_version $tf
1472 do_facet $mds_facet $LCTL set_param fail_loc=0
1475 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1477 #define OBD_FAIL_FLR_LV_INC 0x1A02
1478 do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1480 # write open file should return error
1481 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1482 error "write a mirrored file succeeded" || true
1484 do_facet $mds_facet $LCTL set_param fail_loc=0
1486 run_test 36 "write to mirrored files"
1492 echo "create test files with size $fsize .."
1496 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1498 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1499 $TRUNCATE $tf $fsize
1505 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1506 skip "Need MDS version at least 2.11.57"
1508 local tf=$DIR/$tfile
1509 local tf2=$DIR/$tfile-2
1510 local tf3=$DIR/$tfile-3
1511 local tf4=$DIR/$tfile-4
1513 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1515 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1519 # assume the mirror id will be 1, 2, and 3
1520 declare -A checksums
1521 checksums[1]=$(cat $tf | md5sum)
1522 checksums[2]=$(cat $tf2 | md5sum)
1523 checksums[3]=$(cat $tf3 | md5sum)
1525 printf '%s\n' "${checksums[@]}"
1527 # merge these files into a mirrored file
1528 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1529 error "merging $tf2 into $tf failed"
1530 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1531 error "merging $tf3 into $tf failed"
1535 # verify mirror read, checksums should equal to the original files'
1536 echo "Verifying mirror read .."
1539 for i in "${mirror_array[@]}"; do
1540 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1541 sum=$($LFS mirror read -N $i $tf | md5sum)
1542 [ "$sum" = "${checksums[$i]}" ] ||
1543 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1546 # verify mirror write
1547 echo "Verifying mirror write .."
1548 $LFS mirror write -N2 $tf < $tf4
1550 sum=$($LFS mirror read -N2 $tf | md5sum)
1551 [[ "$sum" = "${checksums[1]}" ]] ||
1552 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1554 # verify mirror copy, write to this mirrored file will invalidate
1555 # the other two mirrors
1556 echo "Verifying mirror copy .."
1558 local osts=$(comma_list $(osts_nodes))
1560 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1561 error "mirror copy error"
1563 # verify copying is successful by checking checksums
1564 remount_client $MOUNT
1565 for i in "${mirror_array[@]}"; do
1566 sum=$($LFS mirror read -N $i $tf | md5sum)
1567 [ "$sum" = "${checksums[1]}" ] ||
1568 error "$i: mismatch checksum after copy \'$sum\'"
1573 run_test 37 "mirror I/O API verification"
1576 local tf=$DIR/$tfile
1577 local ref=$DIR/${tfile}-ref
1579 stack_trap "rm -f $tf $ref"
1581 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1582 error "creating $tf failed"
1583 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1584 $tf-2 || error "creating $tf-2 failed"
1585 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1586 error "creating $tf-3 failed"
1588 # instantiate all components
1589 $LFS mirror extend -N -f $tf-2 $tf ||
1590 error "merging $tf-2 into $tf failed"
1591 $LFS mirror extend -N -f $tf-3 $tf ||
1592 error "merging $tf-3 into $tf failed"
1593 $LFS mirror extend -N -c 1 $tf ||
1594 error "extending mirrored file $tf failed"
1596 verify_flr_state $tf "ro"
1598 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1600 local fsize=$((RANDOM << 8 + 1048576))
1601 $TRUNCATE $ref $fsize
1603 local ref_cksum=$(cat $ref | md5sum)
1605 # case 1: verify write to mirrored file & resync work
1606 cp $ref $tf || error "copy from $ref to $f error"
1607 verify_flr_state $tf "wp"
1609 local file_cksum=$(cat $tf | md5sum)
1610 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1613 echo "mirror IDs: ${mirror_array[*]}"
1615 local valid_mirror stale_mirror id mirror_cksum
1616 for id in "${mirror_array[@]}"; do
1617 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1618 [ "$ref_cksum" == "$mirror_cksum" ] &&
1619 { valid_mirror=$id; continue; }
1624 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1625 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1627 $LFS mirror resync $tf || error "resync failed"
1628 verify_flr_state $tf "ro"
1630 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1631 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1633 # case 2: inject an error to make mirror_io exit after changing
1634 # the file state to sync_pending so that we can start a concurrent
1636 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1637 verify_flr_state $tf "wp"
1639 mirror_io resync -e resync_start $tf && error "resync succeeded"
1640 verify_flr_state $tf "sp"
1642 # from sync_pending to write_pending
1643 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1644 verify_flr_state $tf "wp"
1646 mirror_io resync -e resync_start $tf && error "resync succeeded"
1647 verify_flr_state $tf "sp"
1649 # from sync_pending to read_only
1650 $LFS mirror resync $tf || error "resync failed"
1651 verify_flr_state $tf "ro"
1653 run_test 38 "resync"
1656 local tf=$DIR/$tfile
1659 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1660 error "create PFL file $tf failed"
1662 verify_mirror_count $tf 2
1663 verify_comp_count $tf 4
1665 rm -f $tf || error "delete $tf failed"
1667 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1670 local tf=$DIR/$tfile
1673 for ops in "conv=notrunc" ""; do
1676 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1677 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1678 error "create PFLR file $tf failed"
1679 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1680 error "write PFLR file $tf failed"
1682 lfs getstripe -vy $tf
1686 # file mirror state should be write_pending
1687 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1689 error "file mirror state $flags"
1690 # the 1st component (in mirror 1) should be inited
1691 verify_comp_attr lcme_flags $tf 0x10001 init
1692 # the 2nd component (in mirror 1) should be inited
1693 verify_comp_attr lcme_flags $tf 0x10002 init
1694 # the 3rd component (in mirror 1) should be uninited
1695 verify_comp_attr lcme_flags $tf 0x10003 prefer
1696 # the 4th component (in mirror 2) should be inited
1697 verify_comp_attr lcme_flags $tf 0x20004 init
1698 # the 5th component (in mirror 2) should be uninited
1699 verify_comp_attr lcme_flags $tf 0x20005 0
1700 # the 6th component (in mirror 2) should be stale
1701 verify_comp_attr lcme_flags $tf 0x20006 stale
1702 # the 7th component (in mirror 2) should be uninited
1703 if [[ x$ops = "xconv=notrunc" ]]; then
1704 verify_comp_attr lcme_flags $tf 0x20007 0
1705 elif [[ x$ops = "x" ]]; then
1706 verify_comp_attr lcme_flags $tf 0x20007 stale
1710 rm -f $tf || error "delete $tf failed"
1712 run_test 40 "PFLR rdonly state instantiation check"
1715 local tf=$DIR/$tfile
1717 stack_trap "rm -f $tf $tf-1"
1720 echo " **create two FLR files $tf $tf-1"
1721 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1722 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1723 error "create PFLR file $tf failed"
1724 $LFS mirror create -N -E 2M -S 1M -E eof \
1725 -N -E 1M -E eof --flags prefer \
1726 -N -E 4m -E eof $tf-1 ||
1727 error "create PFLR file $tf-1 failed"
1729 # file should be in ro status
1730 echo " **verify files be RDONLY"
1731 verify_flr_state $tf "ro"
1732 verify_flr_state $tf-1 "ro"
1734 # write data in [0, 2M)
1735 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1736 error "writing $tf failed"
1737 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1738 error "writing $tf-1 failed"
1740 local sum0=$(cat $tf-1 | md5sum)
1742 echo " **verify files be WRITE_PENDING"
1743 verify_flr_state $tf "wp"
1744 verify_flr_state $tf-1 "wp"
1746 # file should have stale component
1747 echo " **verify files have stale component"
1748 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1749 error "after writing $tf, it does not contain stale component"
1750 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1751 error "after writing $tf-1, it does not contain stale component"
1753 echo " **full resync"
1754 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1756 echo " **verify $tf-1 data consistency in all mirrors"
1758 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1759 [[ "$sum" = "$sum0" ]] ||
1760 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1763 echo " **verify files be RDONLY"
1764 verify_flr_state $tf "ro"
1765 verify_flr_state $tf-1 "ro"
1767 # file should not have stale component
1768 echo " **verify files do not contain stale component"
1769 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1770 error "after resyncing $tf, it contains stale component"
1771 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1772 error "after resyncing $tf, it contains stale component"
1774 # verify partial resync
1775 echo " **write $tf-1 for partial resync test"
1776 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1777 error "writing $tf-1 failed"
1779 echo " **only resync mirror 2"
1780 verify_flr_state $tf-1 "wp"
1781 $LFS mirror resync --only 2 $tf-1 ||
1782 error "resync mirror 2 of $tf-1 failed"
1783 verify_flr_state $tf "ro"
1785 # resync synced mirror
1786 echo " **resync mirror 2 again"
1787 $LFS mirror resync --only 2 $tf-1 ||
1788 error "resync mirror 2 of $tf-1 failed"
1789 verify_flr_state $tf "ro"
1790 echo " **verify $tf-1 contains stale component"
1791 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1792 error "after writing $tf-1, it does not contain stale component"
1794 echo " **full resync $tf-1"
1795 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1796 verify_flr_state $tf "ro"
1797 echo " **full resync $tf-1 again"
1798 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1799 echo " **verify $tf-1 does not contain stale component"
1800 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1801 error "after resyncing $tf, it contains stale component"
1805 run_test 41 "lfs mirror resync check"
1808 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1812 local mirror_cmd="$LFS mirror verify"
1815 stack_trap "rm -rf $td"
1817 # create parent directory
1818 mkdir $td || error "mkdir $td failed"
1820 $mirror_cmd &> /dev/null && error "no file name given"
1821 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1822 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1824 # create mirrored files
1825 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1826 error "create mirrored file $tf failed"
1827 $LFS mirror create -N -E 2M -S 1M -E EOF \
1828 -N -E 6M -E 8M -E EOF \
1829 -N -E 16M -E EOF $tf-1 ||
1830 error "create mirrored file $tf-1 failed"
1831 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1832 error "create mirrored file $tf-2 failed"
1834 # write data in [0, 10M)
1835 for i in $tf $tf-1 $tf-2; do
1836 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1837 error "write $i failed"
1840 # resync the mirrored files
1841 $LFS mirror resync $tf-1 $tf-2 ||
1842 error "resync $tf-1 $tf-2 failed"
1844 # verify the mirrored files
1845 $mirror_cmd $tf-1 $tf-2 ||
1846 error "verify $tf-1 $tf-2 failed"
1848 get_mirror_ids $tf-1
1849 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1850 error "at least 2 mirror ids needed with '--only' option"
1851 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1853 error "'--only' option cannot be used upon multiple files"
1854 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1855 error "invalid specified mirror ids"
1857 # change the content of $tf and merge it into $tf-1
1859 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1860 error "change $tf with seek=$i failed"
1861 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1862 error "change $tf-1 with seek=$i failed"
1865 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1866 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1867 error "merge $tf into $tf-1 failed"
1869 # verify the mirrored files
1870 echo "Verify $tf-1 without -v option:"
1871 $mirror_cmd $tf-1 &&
1872 error "verify $tf-1 should fail" || echo "PASS"
1874 echo "Verify $tf-1 with -v option:"
1875 $mirror_cmd -v $tf-1 &&
1876 error "verify $tf-1 should fail"
1878 get_mirror_ids $tf-1
1879 echo "Verify $tf-1 with --only option:"
1880 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1881 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1882 "${mirror_array[-1]} should fail"
1884 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1885 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1886 "${mirror_array[1]} should succeed"
1888 # set stale components in $tf-1
1889 for i in 0x40002 0x40003; do
1890 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1891 error "set stale flag on component $i failed"
1894 # verify the mirrored file
1895 echo "Verify $tf-1 with stale components:"
1896 $mirror_cmd -vvv $tf-1 ||
1897 error "verify $tf-1 with stale components should succeed"
1899 echo "Verify $tf-1 with stale components and --only option:"
1900 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1901 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1902 "${mirror_array[-1]} should succeed"
1904 run_test 42 "lfs mirror verify"
1906 # inactivate one OST && write && restore the OST
1910 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1913 wait=$(do_facet $SINGLEMDS \
1914 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1915 wait=${wait%%[^0-9]*}
1917 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1918 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1919 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1920 sleep $(($wait * 2 + 2))
1921 echo " **write $file"
1922 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1923 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1924 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1925 sleep $((wait * 2 + 2))
1927 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1928 [ $flags = wp ] || error "file mirror state $flags != wp"
1932 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1934 local tf=$DIR/$tfile
1938 ## mirror 0 ost (0, 1)
1939 ## mirror 1 ost (1, 2)
1940 ## mirror 2 ost (2, 0)
1941 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1942 -N -Eeof -c2 -o2,0 $tf ||
1943 error "create 3 mirrors file $tf failed"
1945 ################## OST0 ###########################################
1947 echo " **verify components"
1948 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1949 verify_comp_attr lcme_flags $tf 0x20002 init
1950 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1953 echo " **resync $tf"
1954 $LFS mirror resync $tf
1955 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1956 [ $flags = ro ] || error "file mirror state $flags != ro"
1958 ################## OST1 ###########################################
1960 echo " **verify components"
1961 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1962 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1963 verify_comp_attr lcme_flags $tf 0x30003 init
1966 echo " **resync $tf"
1967 $LFS mirror resync $tf
1968 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1969 [ $flags = ro ] || error "file mirror state $flags != ro"
1971 ################## OST2 ###########################################
1973 echo " **verify components"
1974 verify_comp_attr lcme_flags $tf 0x10001 init
1975 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1976 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1978 run_test 43a "mirror pick on write"
1981 local tf=$DIR/$tdir/$tfile
1983 test_mkdir $DIR/$tdir
1985 stack_trap "rm -rf $tf"
1987 # create 3 mirrors FLR file, the first 2 mirrors are preferred
1988 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
1989 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
1990 verify_flr_state $tf "ro"
1992 echo " ** write to $tf"
1993 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
1994 verify_flr_state $tf "wp"
1996 echo " ** resync $tf"
1997 $LFS mirror resync $tf || error "resync $tf failed"
1998 verify_flr_state $tf "ro"
2000 run_test 43b "allow writing to multiple preferred mirror file"
2003 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2006 local tf=$DIR/$tdir/$tfile
2007 local tf1=$DIR/$tdir-1/$tfile-1
2009 stack_trap "rm -rf $tf $tf1"
2011 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2012 error "create directory failed"
2013 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2014 error "create remote directory failed"
2015 rm -f $tf $tf1 $tf.mirror~2
2016 # create file with 4 mirrors
2017 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2018 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2019 error "create PFLR file $tf failed"
2021 # file should be in ro status
2022 verify_flr_state $tf "ro"
2024 # write data in [0, 3M)
2025 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2026 error "writing $tf failed"
2028 verify_flr_state $tf "wp"
2030 # disallow destroying the last non-stale mirror
2031 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2032 error "destroying mirror 1 should fail"
2034 # synchronize all mirrors of the file
2035 $LFS mirror resync $tf || error "mirror resync $tf failed"
2037 verify_flr_state $tf "ro"
2040 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2041 error "split to $tf1 failed"
2043 local idx0=$($LFS getstripe -m $tf)
2044 local idx1=$($LFS getstripe -m $tf1)
2046 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2047 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2049 # verify mirror count
2050 verify_mirror_count $tf 3
2051 verify_mirror_count $tf1 1
2053 $LFS mirror split --mirror-id 2 $tf ||
2054 error "split mirror 2 failed"
2056 verify_mirror_count $tf 2
2057 verify_mirror_count $tf.mirror~2 1
2059 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2060 error "setting stale flag on component 0x30008 failed"
2062 # disallow destroying the last non-stale mirror
2063 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2064 error "destroying mirror 4 should fail"
2066 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2068 $LFS mirror split --mirror-id 3 -d $tf ||
2069 error "destroying mirror 3 failed"
2070 verify_mirror_count $tf 1
2072 # verify splitted file contains the same content as the orig file does
2073 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2074 diff $tf $tf.mirror~2 ||
2075 error "splited file $tf.mirror~2 diffs from $tf"
2077 run_test 44a "lfs mirror split check"
2080 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2081 skip "Need MDS version at least 2.14.56"
2084 local tf=$DIR/$tdir/$tfile
2086 mkdir -p $DIR/$tdir || error "create directory failed"
2090 # create 2 mirrors file
2091 $LFS mirror extend -N -c1 $tf
2095 verify_flr_state $tf "wp"
2097 local str=$(cat $tf)
2099 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2101 # get the non-stale mirror id
2102 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2104 local mirror_ids=($($LFS getstripe $tf |
2105 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2106 for ((i = 0; i < 2; i++)); do
2107 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2108 grep stale > /dev/null || break
2111 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2115 # split the updated mirror, should fail
2116 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2117 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2118 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2121 # split the stale mirror
2122 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2123 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2124 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2126 echo "make sure there's no stale comp in the file"
2127 # make sure there's no stale comp in the file
2128 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2129 ( $LFS getstripe $tf; error "stale mirror file" )
2132 [[ $str == "YYY" ]] ||
2133 ( cat $tf; error "$tf content is not YYY after split" )
2135 run_test 44b "mirror split does not create stale file"
2138 local tf=$DIR/$tdir/$tfile
2140 stack_trap "rm -f $tf"
2142 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2143 skip "Need MDS version at least 2.14.52"
2145 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2147 mkdir -p $DIR/$tdir || error "create directroy failed"
2149 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2151 block1=$(( $(stat -c "%b*%B" $tf) ))
2152 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2154 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2156 block2=$(( $(stat -c "%b*%B" $tf) ))
2157 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2159 $LFS mirror split -d --mirror-id=2 $tf ||
2160 error "mirror split $tfile failed"
2161 $LFS mirror split -d --mirror-id=3 $tf ||
2162 error "mirror split $tfile failed"
2165 block3=$(( $(stat -c "%b*%B" $tf) ))
2166 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2168 [[ $block1 -eq $block3 ]] ||
2169 error "mirror split does not reduce block# $block3 != $block1"
2171 run_test 44c "lfs mirror split reduces block size of a file"
2174 local tf=$DIR/$tdir/$tfile
2180 stack_trap "rm -f $tf"
2182 mkdir -p $DIR/$tdir || error "create directroy failed"
2184 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2186 size1=$(stat -c "%s" $tf)
2187 echo " ** before mirror ops, file size=$size1"
2189 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2191 size2=$(stat -c "%s" $tf)
2192 echo " ** after mirror extend, file size=$size2"
2194 (($size1 == $size2)) ||
2195 error "mirror extend should not change size, before: $size1, after $size2"
2197 $LFS mirror split -d --mirror-id=2 $tf ||
2198 error "mirror split $tfile failed"
2200 size2=$(stat -c "%s" $tf)
2201 echo " ** after mirror split, file size=$size2"
2202 (($size1 == $size2)) ||
2203 error "mirror split should not change size, before: $size1, after $size2"
2205 # Remount client to clear cached size information
2206 remount_client $MOUNT
2207 size2=$(stat -c "%s" $tf)
2208 echo " ** after mirror split & remount, file size=$size2"
2209 (($size1 == $size2)) ||
2210 error "mirror extend should not change size, before: $size1, after $size2"
2213 run_test 44d "lfs mirror split does not break size"
2216 local tf=$DIR/$tdir/$tfile
2217 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2221 test_mkdir $DIR/$tdir
2222 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2223 skip "Need MDS version at least 2.14.52"
2225 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2227 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2228 $LCTL set_param llite.*.xattr_cache=0
2229 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2231 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2233 size1=$(stat -c "%s" $tf)
2234 echo " ** before mirror resync, file size=$size1"
2236 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2237 size1=$(stat -c "%s" $tf)
2238 size2=$($LFS getsom -s $tf)
2242 ((size1 == size2)) ||
2243 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2245 # Remount client to clear cached size information
2246 remount_client $MOUNT
2248 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2249 stack_trap "restore_lustre_params < $p; rm -f $p"
2250 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2252 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2254 size2=$(stat -c "%s" $tf)
2255 # 'getsom' here is just for debugging
2258 ((size2 == size1)) ||
2259 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2261 run_test 44e "basic FLR SOM tests + disable SOM"
2264 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2266 local file=$DIR/$tdir/$tfile
2267 local dir=$DIR/$tdir/$dir
2268 local temp=$DIR/$tdir/template
2270 test_mkdir $DIR/$tdir
2272 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2273 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2274 error "Create $file failed"
2276 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2277 rm -f $file $file.copy
2279 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2280 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2281 error "Create $file failed"
2283 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2285 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2292 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2294 local layout1=$(get_layout_param $src)
2295 local layout2=$(get_layout_param $dst)
2296 # compare their layout info
2297 [ "$layout1" == "$layout2" ] ||
2298 error "$msg_prefix $src <=> $dst layouts are not equal"
2302 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2304 local file=$DIR/$tdir/$tfile
2305 test_mkdir $DIR/$tdir
2307 ########################### 1. PFL file #############################
2308 echo " ** 1. PFL file"
2310 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2311 $file || error "1. Create PFL $file failed"
2314 verify_46 $file $file.copy "1. PFL file"
2316 ########################### 2. plain file ###########################
2317 echo " ** 2. plain file"
2319 $LFS setstripe -c2 -o0,1 -i1 $file ||
2320 error "2. Create plain $file failed"
2323 verify_46 $file $file.copy "2. plain file"
2325 ########################### 3. FLR file #############################
2326 echo " ** 3. FLR file"
2328 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2329 $file || error "3. Create FLR $file failed"
2332 verify_46 $file $file.copy "3. FLR file"
2334 local dir=$DIR/$tdir/dir
2335 ########################### 4. PFL dir ##############################
2336 echo " ** 4. PFL dir"
2338 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2339 error "4. setstripe PFL $dir failed"
2341 test_mkdir $dir.copy
2342 verify_46 $dir $dir.copy "4. PFL dir"
2344 ########################### 5. plain dir ############################
2345 echo " ** 5. plain dir"
2346 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2348 verify_46 $dir $dir.copy "5. plain dir"
2350 ########################### 6. FLR dir ##############################
2351 echo " ** 6. FLR dir"
2352 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2353 error "6. setstripe FLR $dir failed"
2355 verify_46 $dir $dir.copy "6. FLR dir"
2357 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2358 echo "server version $MDS1_VERSION does not support SEL" &&
2361 ########################### 7. SEL file ##############################
2362 echo " ** 7. SEL file"
2364 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2365 $file || error "Create $file failed"
2368 verify_46 $file $file.copy "7. SEL file"
2370 ########################### 8. SEL dir ##############################
2371 echo " ** 8. SEL dir"
2372 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2373 $dir || error "setstripe $dir failed"
2375 verify_46 $dir $dir.copy "8. SEL dir"
2377 ########################### 9. FLR SEL file ##########################
2378 echo " ** 9. FLR SEL file"
2380 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2381 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2384 verify_46 $file $file.copy "9. SEL file"
2386 ########################### 10. FLR SEL dir #########################
2387 echo " ** 10. FLR SEL dir"
2388 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2389 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2391 verify_46 $dir $dir.copy "10. SEL dir"
2393 run_test 46 "Verify setstripe --copy option"
2396 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2398 local file=$DIR/$tdir/$tfile
2403 test_mkdir $DIR/$tdir
2407 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2408 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2409 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2410 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2411 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2413 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2414 $LFS mirror resync $file || error "resync $file failed"
2416 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2417 if [[ x$ost == "x0," ]]; then
2418 $LFS getstripe $file
2419 error "component ${ids[2]} objects allocated on $ost " \
2423 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2424 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2425 $LFS getstripe $file
2426 error "component ${ids[3]} objects allocated on $ost " \
2427 "shouldn't on OST1 or on OST2"
2432 # mirror1: [comp0] [comp1]
2433 # mirror2: [comp2] [comp3]
2434 # mirror3: [comp4] [comp5]
2435 # mirror4: [comp6] [comp7]
2436 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2437 error "create FLR $file failed"
2438 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2440 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2441 $LFS mirror resync $file || error "resync $file failed"
2443 for ((i = 0; i < 6; i++)); do
2444 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2445 awk '/l_ost_idx/{print $5}')
2447 # comp[0],comp[2],comp[4] should use different osts
2448 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2449 ${osts[2]} == ${osts[4]} ]]; then
2450 $LFS getstripe $file
2451 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2452 "allocated on duplicated OSTs"
2454 # comp[1],comp[3],comp[5] should use different osts
2455 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2456 ${osts[3]} == ${osts[5]} ]]; then
2457 $LFS getstripe $file
2458 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2459 "allocated on duplicated OSTs"
2464 run_test 47 "Verify mirror obj alloc"
2467 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2468 skip "Need MDS version at least 2.11.55"
2470 local tf=$DIR/$tfile
2473 echo " ** create 2 mirrors FLR file $tf"
2474 $LFS mirror create -N -E2M -Eeof --flags prefer \
2475 -N -E1M -Eeof $tf ||
2476 error "create FLR file $tf failed"
2479 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2480 verify_flr_state $tf "wp"
2482 local sum0=$(md5sum < $tf)
2484 echo " ** resync the file"
2485 $LFS mirror resync $tf
2487 echo " ** snapshot mirror 2"
2488 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2490 echo " ** write it again"
2491 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2492 echo " ** resync it again"
2493 $LFS mirror resync $tf
2495 verify_flr_state $tf "wp"
2496 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2498 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2499 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2501 echo " ** verify mirror 2 doesn't change"
2502 echo "original checksum: $sum0"
2503 echo "mirror 1 checksum: $sum1"
2504 echo "mirror 2 checksum: $sum2"
2505 [[ $sum0 = $sum2 ]] ||
2506 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2507 echo " ** mirror 2 stripe info"
2508 $LFS getstripe -v --mirror-index=2 $tf
2510 echo " ** resync mirror 2"
2511 $LFS mirror resync --only 2 $tf
2513 verify_flr_state $tf "ro"
2514 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2516 sum1=$($LFS mirror read -N1 $tf | md5sum)
2517 sum2=$($LFS mirror read -N2 $tf | md5sum)
2519 echo " ** verify mirror 2 resync-ed"
2520 echo "original checksum: $sum0"
2521 echo "mirror 1 checksum: $sum1"
2522 echo "mirror 2 checksum: $sum2"
2523 [[ $sum1 = $sum2 ]] ||
2524 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2525 echo " ** mirror 2 stripe info"
2526 $LFS getstripe -v --mirror-index=2 $tf
2528 run_test 48 "Verify snapshot mirror"
2537 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
2539 trap cleanup_49 EXIT RETURN
2541 local file=$DIR/$tfile
2543 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2544 error "setstripe on $file"
2546 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2547 $LFS mirror resync $file
2549 filefrag -ves $file || error "filefrag $file failed"
2550 filefrag_op=$(filefrag -ve -k $file |
2551 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2553 #Filesystem type is: bd00bd0
2554 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2555 # ext: device_logical: physical_offset: length: dev: flags:
2556 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2557 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2558 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2560 last_lun=$(echo $filefrag_op | cut -d: -f5)
2564 for line in $filefrag_op; do
2565 frag_lun=$(echo $line | cut -d: -f5)
2566 ext_len=$(echo $line | cut -d: -f4)
2567 if [[ "$frag_lun" != "$last_lun" ]]; then
2568 if (( tot_len != 1024 )); then
2570 error "$file: OST$last_lun $tot_len != 1024"
2576 (( tot_len += ext_len ))
2579 if (( num_luns != 2 || tot_len != 1024 )); then
2581 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2584 echo "FIEMAP on $file succeeded"
2586 run_test 49a "FIEMAP upon FLR file"
2588 test_50A() { # EX-2179
2591 local file=$DIR/$tdir/$tfile
2593 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2595 $LFS mirror extend -N -c1 -i1 $file ||
2596 error "extending mirror for $file failed"
2598 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2602 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2604 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2606 echo "$file layout generation from $olv to $flv"
2607 (( $flv != ($olv + 1) )) &&
2608 error "split does not increase layout gen from $olv to $flv"
2610 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2612 $LFS getstripe -v $file || error "getstripe $file failed"
2614 run_test 50A "mirror split update layout generation"
2617 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2618 skip "OST does not support SEEK_HOLE"
2620 local file=$DIR/$tdir/$tfile
2628 echo " ** create striped file $file"
2629 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2630 error "cannot create file with PFL layout"
2631 echo " ** write 1st data chunk at 1M boundary"
2632 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2633 error "cannot write data at 1M boundary"
2634 echo " ** write 2nd data chunk at 2M boundary"
2635 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2636 error "cannot write data at 2M boundary"
2637 echo " ** create hole at the file end"
2638 $TRUNCATE $file 3700000 || error "truncate fails"
2640 echo " ** verify sparseness"
2641 offset=$(lseek_test -d 1000 $file)
2642 echo " first data offset: $offset"
2643 [[ $offset == 1000 ]] &&
2644 error "src: data is not expected at offset $offset"
2645 offset=$(lseek_test -l 3500000 $file)
2646 echo " hole at the end: $offset"
2647 [[ $offset == 3500000 ]] ||
2648 error "src: hole is expected at offset $offset"
2650 echo " ** extend the file with new mirror"
2651 # migrate_copy_data() is used
2652 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2653 error "cannot create mirror"
2654 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2655 error "$file still has stale component"
2657 # check migrate_data_copy() was correct
2658 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2659 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2660 [[ $sum_1 == $sum_2 ]] ||
2661 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2663 # stale first mirror
2664 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2665 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2667 echo " ** verify mirror #2 sparseness"
2668 offset=$(lseek_test -d 1000 $file)
2669 echo " first data offset: $offset"
2670 [[ $offset == 1000 ]] &&
2671 error "dst: data is not expected at offset $offset"
2672 offset=$(lseek_test -l 3500000 $file)
2673 echo " hole at the end: $offset"
2674 [[ $offset == 3500000 ]] ||
2675 error "dst: hole is expected at offset $offset"
2677 echo " ** copy mirror #2 to mirror #1"
2678 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2679 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2680 error "$file still has stale component"
2682 # check llapi_mirror_copy_many correctness
2683 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2684 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2685 [[ $sum_1 == $sum_2 ]] ||
2686 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2688 # stale 1st component of mirror #2 before lseek call
2689 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2691 echo " ** verify mirror #1 sparseness again"
2692 offset=$(lseek_test -d 1000 $file)
2693 echo " first data offset: $offset"
2694 [[ $offset == 1000 ]] &&
2695 error "dst: data is not expected at offset $offset"
2696 offset=$(lseek_test -l 3500000 $file)
2697 echo " hole at the end: $offset"
2698 [[ $offset == 3500000 ]] ||
2699 error "dst: hole is expected at offset $offset"
2701 cancel_lru_locks osc
2703 blocks=$(stat -c%b $file)
2704 echo " ** final consumed blocks: $blocks"
2705 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2706 # that file is still sparse
2707 (( blocks < 1000 )) ||
2708 error "Mirrored file consumes $blocks blocks"
2712 run_test 50a "mirror extend/copy preserves sparseness"
2715 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2716 skip "OST does not support SEEK_HOLE"
2718 local file=$DIR/$tdir/$tfile
2726 echo " ** create mirrored file $file"
2727 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2728 -N -E2M -S1M -E eof -S2M $file ||
2729 error "cannot create mirrored file"
2730 echo " ** write data chunk at 1M boundary"
2731 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2732 error "cannot write data at 1M boundary"
2733 echo " ** create hole at the file end"
2734 $TRUNCATE $file 3700000 || error "truncate fails"
2736 echo " ** verify sparseness"
2737 offset=$(lseek_test -d 1000 $file)
2738 echo " first data offset: $offset"
2739 [[ $offset == 1000 ]] &&
2740 error "src: data is not expected at offset $offset"
2741 offset=$(lseek_test -l 3500000 $file)
2742 echo " hole at the end: $offset"
2743 [[ $offset == 3500000 ]] ||
2744 error "src: hole is expected at 3500000"
2746 echo " ** resync mirror #2 to mirror #1"
2747 $LFS mirror resync $file
2749 # check llapi_mirror_copy_many correctness
2750 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2751 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2752 [[ $sum_1 == $sum_2 ]] ||
2753 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2755 cancel_lru_locks osc
2757 blocks=$(stat -c%b $file)
2758 echo " ** consumed blocks: $blocks"
2759 # without full punch() support the first component can be not sparse
2760 # but the last one should be, so file should use far fewer blocks
2761 (( blocks < 5000 )) ||
2762 error "Mirrored file consumes $blocks blocks"
2764 # stale first component in mirror #1
2765 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2766 echo " ** truncate file down"
2768 echo " ** write data chunk at 2M boundary"
2769 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2770 error "cannot write data at 2M boundary"
2771 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2772 $LFS mirror resync $file || error "mirror rsync fails"
2773 # first component is still stale
2774 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2775 error "$file still has no stale component"
2776 echo " ** resync mirror #2 to mirror #1 again"
2777 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2778 $LFS mirror resync $file || error "mirror rsync fails"
2779 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2780 error "$file still has stale component"
2782 # check llapi_mirror_copy_many correctness
2783 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2784 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2785 [[ $sum_1 == $sum_2 ]] ||
2786 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2788 cancel_lru_locks osc
2790 blocks=$(stat -c%b $file)
2791 echo " ** final consumed blocks: $blocks"
2792 # while the first component can lose sparseness, the last one should
2793 # not, so whole file should still use far fewer blocks in total
2794 (( blocks < 3000 )) ||
2795 error "Mirrored file consumes $blocks blocks"
2798 run_test 50b "mirror rsync handles sparseness"
2801 local tf=$DIR/$tdir/$tfile
2803 test_mkdir $DIR/$tdir
2805 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
2806 verify_flr_state $tf "ro"
2808 if [[ "$FSTYPE" == "ldiskfs" ]]; then
2809 # ZFS does not support fallocate for now
2810 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
2811 skip_eopnotsupp "$out|punch hole in $tf failed"
2812 verify_flr_state $tf "wp"
2815 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
2816 $LFS mirror resync $tf || error "mirror resync $tf failed"
2817 verify_flr_state $tf "ro"
2819 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
2820 verify_flr_state $tf "wp"
2822 run_test 50c "punch_hole/mmap_write stale other mirrors"
2825 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2826 skip "OST does not support SEEK_HOLE"
2827 (( $LINUX_VERSION_CODE > $(version_code 3.0.0) )) ||
2828 skip "client kernel does not support SEEK_HOLE"
2830 local file=$DIR/$tdir/$tfile
2837 echo " ** create mirrored file $file"
2838 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2839 -N -E2M -S1M -E eof -S2M $file ||
2840 error "cannot create mirrored file"
2841 echo " ** write data chunk at 1M boundary"
2842 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2843 error "cannot write data at 1M boundary"
2844 echo " ** create hole at the file start"
2845 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
2848 if [[ $rc -eq 0 ]]; then
2849 verify_flr_state $file "wp"
2850 elif [[ ! $prt =~ unsupported ]]; then
2851 error "punch hole in $file failed: $prt"
2853 skip "Fallocate punch is not supported: $prt"
2856 echo " ** verify sparseness"
2857 offset=$(lseek_test -d 1000 $file)
2858 echo " first data offset: $offset"
2859 (( $offset >= 1024 * 1024 )) ||
2860 error "src: data is not expected at offset $offset"
2862 echo " ** resync mirror #2"
2863 $LFS mirror resync $file
2865 # check llapi_mirror_copy_many correctness
2866 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2867 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2868 [[ $sum_1 == $sum_2 ]] ||
2869 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2871 cancel_lru_locks osc
2873 # stale first component in mirror #1
2874 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2875 echo " ** verify sparseness of mirror #2"
2876 offset=$(lseek_test -d 1000 $file)
2877 echo " first data offset: $offset"
2878 (( $offset >= 1024 * 1024 )) ||
2879 error "src: data is not expected at offset $offset"
2881 run_test 50d "mirror rsync keep holes"
2884 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2885 skip "OST does not support SEEK_HOLE"
2887 local file=$DIR/$tdir/$tfile
2888 local old_size=2147483648 # 2GiB
2892 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
2893 $TRUNCATE $file $old_size
2895 $LFS mirror extend -N -c 1 $file
2896 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
2897 $LFS mirror resync $file
2899 new_size=$(stat --format='%s' $file)
2900 if ((new_size != old_size)); then
2901 error "new_size ($new_size) is not equal to old_size ($old_size)"
2906 run_test 60a "mirror extend sets correct size on sparse file"
2908 get_flr_layout_gen() {
2909 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
2910 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
2913 check_layout_gen() {
2916 local v1=$(get_flr_layout_gen $tf)
2917 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
2919 [[ $v1 -eq $v2 ]] ||
2920 error "$tf in-memory layout gen $v1 != $v2 after $2"
2924 local tf=$DIR/$tdir/$tfile
2926 test_mkdir $DIR/$tdir
2928 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
2930 for ((i = 0; i < 20; i++)); do
2931 $LFS mirror extend -N $tf ||
2932 error "extending mirror for $tf failed"
2933 check_layout_gen $tf "extend"
2935 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
2936 error "split $tf failed"
2937 check_layout_gen $tf "split"
2940 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
2943 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
2948 local -a old=( $2 $3 $4 )
2951 new=( $(get_times_61 $file) )
2952 ((${old[0]} == ${new[0]})) ||
2953 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
2955 ((${old[1]} == ${new[1]})) ||
2956 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
2959 test_61a() { # LU-14508
2960 local file=$DIR/$tdir/$tfile
2966 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
2967 echo "create $file-2"
2968 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
2970 echo XXX > $file || error "write $file failed"
2971 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
2973 echo "sleep $nap seconds, then cat $tfile"
2975 cat $file || error "cat $file failed"
2977 echo "sleep $nap seconds, then re-write $tfile"
2979 echo XXXX > $file || error "write $file failed"
2980 cp -p $file $file-2 || error "copy $file-2 failed"
2982 echo "sleep $nap seconds"
2985 tim=( $(get_times_61 $file) )
2987 echo "mirror merge $tfile-2 to $tfile and test timestamps"
2988 $LFS mirror extend -N -f $file-2 $file ||
2989 error "cannot mirror merge $file-2 to $file"
2990 check_times_61 $file "${tim[@]}"
2992 echo "mirror extend $tfile and test timestamps"
2993 $LFS mirror extend -N -c1 -i1 $file ||
2994 error "cannot extend mirror $file"
2995 check_times_61 $file "${tim[@]}"
2997 echo "migrate $tfile and test timestamps"
2998 $LFS migrate -n $file || error "cannot migrate $file"
2999 check_times_61 $file "${tim[@]}"
3001 echo "normal user migrate $tfile and test timestamps"
3002 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3003 check_times_61 $file "${tim[@]}"
3005 run_test 61a "mirror extend and migrate preserve timestamps"
3007 test_61b() { # LU-14508
3008 local file=$DIR/$tdir/$tfile
3014 echo XXX > $file || error "create $file failed"
3015 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3017 echo "sleep $nap seconds, then cat $tfile"
3019 cat $file || error "cat $file failed"
3021 echo "sleep $nap seconds, then re-write $tfile"
3023 echo XXXX > $file || error "write $file failed"
3025 echo "sleep $nap seconds, then test timestamps"
3028 tim=( $(get_times_61 $file) )
3030 echo "mirror extend $tfile and test timestamps"
3031 $LFS mirror extend -N -c1 -i1 $file ||
3032 error "cannot extend mirror $file"
3033 check_times_61 $file "${tim[@]}"
3035 echo "mirror split $tfile and test timestamps"
3036 $LFS mirror split -d --mirror-id=1 $file ||
3037 error "cannot split mirror 1 off $file"
3038 check_times_61 $file "${tim[@]}"
3040 echo "normal user mirror extend $tfile and test timestamps"
3041 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3042 error "cannot extend mirror $file"
3043 check_times_61 $file "${tim[@]}"
3045 run_test 61b "mirror extend and split preserve timestamps"
3047 test_61c() { # LU-14508
3048 local file=$DIR/$tdir/$tfile
3054 echo XXX > $file || error "create $file failed"
3055 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3057 echo "sleep $nap seconds, then cat $tfile"
3059 cat $file || error "cat $file failed"
3061 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3063 $LFS mirror extend -N -c1 -i1 $file ||
3064 error "cannot extend mirror $file"
3065 echo XXXX > $file || error "write $file failed"
3067 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3068 tim=( $(get_times_61 $file) )
3070 $LFS mirror resync $file || error "cannot resync mirror $file"
3071 check_times_61 $file "${tim[@]}"
3073 echo XXXXXX > $file || error "write $tfile failed"
3075 echo "normal user resync $tfile and test timestamps"
3076 tim=( $(get_times_61 $file) )
3077 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3078 check_times_61 $file "${tim[@]}"
3080 run_test 61c "mirror resync preserves timestamps"
3083 local tf=$DIR/$tdir/$tfile
3085 test_mkdir $DIR/$tdir
3089 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3093 echo "mirror create pid $c_pid"
3096 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3099 echo "mirror split pid $s_pid"
3101 echo "mirror create and split race for 60 seconds, should not crash"
3103 kill -9 $c_pid &> /dev/null
3104 kill -9 $s_pid &> /dev/null
3109 run_test 70 "mirror create and split race"
3112 local tf=$DIR/$tdir/$tfile
3114 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3115 skip "Need OST version at least 2.14.51"
3118 test_mkdir $DIR/$tdir
3120 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3121 error "setstripe $tf failed"
3123 FSXNUM=${FSXNUM:-1000}
3124 $FSX -p 5 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3126 run_test 100 "flr mode fsx test"
3128 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3129 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3134 local fsize=$(stat --printf=%s $tf)
3136 while [ -f $ctrl_file ]; do
3137 local off=$((RANDOM << 8))
3138 local len=$((RANDOM << 5 + 131072))
3140 [ $((off + len)) -gt $fsize ] && {
3141 fsize=$((off + len))
3142 echo "Extending file size to $fsize .."
3145 flock -s $lock_file -c \
3146 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3148 error "failed writing to $off:$len"; }
3149 sleep 0.$((RANDOM % 2 + 1))
3156 while [ -f $ctrl_file ]; do
3157 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3158 { rm -f $ctrl_file; error "read failed"; }
3159 sleep 0.$((RANDOM % 2 + 1))
3166 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3168 exec 200<>$lock_file
3169 while [ -f $ctrl_file ]; do
3170 local lock_taken=false
3171 local index=$((RANDOM % ${#options[@]}))
3172 local cmd="mirror_io resync ${options[$index]}"
3174 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3176 [ $((RANDOM % 4)) -eq 0 ] && {
3182 echo -n "resync file $tf with '$cmd' .."
3184 if [[ $lock_taken = "true" ]]; then
3186 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3189 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3192 sleep 0.$((RANDOM % 8 + 1))
3197 local tf=$DIR/$tfile
3198 local tf2=$DIR2/$tfile
3199 local tf3=$DIR3/$tfile
3201 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3202 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3203 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3205 $LFS mirror extend -N -f $tf-2 $tf ||
3206 error "merging $tf-2 into $tf failed"
3207 $LFS mirror extend -N -f $tf-3 $tf ||
3208 error "merging $tf-3 into $tf failed"
3210 mkdir -p $MOUNT2 && mount_client $MOUNT2
3212 mkdir -p $MOUNT3 && mount_client $MOUNT3
3214 verify_flr_state $tf3 "ro"
3216 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3217 $LCTL set_param fail_loc=0x1A03
3219 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3220 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3224 write_file_200 $tf &
3230 write_file_200 $tf2 &
3233 read_file_200 $tf2 &
3236 resync_file_200 $tf3 &
3240 [ "$SLOW" = "yes" ] && sleep_time=360
3241 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3248 echo "Waiting ${pids[*]}"
3251 umount_client $MOUNT2
3252 umount_client $MOUNT3
3256 # resync and verify mirrors
3257 $LFS mirror resync $tf || error "final resync failed"
3260 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3262 for id in "${mirror_array[@]:1}"; do
3263 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3264 error "checksum error for mirror $id"
3269 run_test 200 "stress test"
3271 cleanup_test_201() {
3273 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3275 umount_client $MOUNT2
3279 local delay=${RESYNC_DELAY:-5}
3281 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3282 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3284 trap cleanup_test_201 EXIT
3286 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3287 changelog_register -n)
3289 mkdir -p $MOUNT2 && mount_client $MOUNT2
3293 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3294 [ -z "$log" ] && { sleep 1; continue; }
3296 index=$(echo $log | awk '{print $1}')
3297 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3298 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3299 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3302 [ -z "$file" ] && continue
3304 local now=$(date +%s)
3306 echo "file: $file $fid was modified at $ts, now: $now, " \
3307 "will be resynced at $((ts+delay))"
3309 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3311 $LFS mirror resync $file
3312 echo "$file resync done"
3317 run_test 201 "FLR data mover"
3320 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3322 local tf=$DIR/$tfile