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
18 ALWAYS_EXCEPT+=" 6 201 "
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
33 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
34 skip "Need MDS version at least 2.10.56"
36 check_and_setup_lustre
39 rm -rf $DIR/[Rdfs][0-9]*
41 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
42 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
47 # global array to store mirror IDs
48 declare -a mirror_array
55 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
56 array[${#array[@]}]=$((id >> 16))
59 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
61 echo ${#mirror_array[@]}
65 echo 3 > /proc/sys/vm/drop_caches
76 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
84 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
85 error "start ost$idx failed"
89 wait_recovery_complete ost$idx
94 # Verify mirror count with an expected value for a given file.
96 verify_mirror_count() {
99 local mirror_count=$($LFS getstripe -N $tf)
101 [[ $mirror_count = $expected ]] || {
102 $LFS getstripe -v $tf
103 error "verify mirror count failed on $tf:" \
104 "$mirror_count != $expected"
109 # Verify component count with an expected value for a given file.
110 # $1 coposited layout file
111 # $2 expected component number
113 verify_comp_count() {
116 local comp_count=$($LFS getstripe --component-count $tf)
118 [[ $comp_count = $expected ]] || {
119 $LFS getstripe -v $tf
120 error "verify component count failed on $tf:" \
121 "$comp_count != $expected"
126 # Verify component attribute with an expected value for a given file
134 local cmd="$LFS getstripe -I$comp_id"
135 local getstripe_cmd="$cmd -v"
139 stripe-size) cmd+=" -S $tf" ;;
140 stripe-count) cmd+=" -c $tf" ;;
141 stripe-index) cmd+=" -i $tf" ;;
142 pool) cmd+=" -p $tf" ;;
143 comp-start) cmd+=" --component-start $tf" ;;
144 comp-end) cmd+=" --component-end $tf" ;;
145 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
146 *) error "invalid attribute $attr";;
151 [ $attr = lcme_flags ] && {
153 local expected_list=$(comma_list $expected)
154 for fl in ${expected_list//,/ }; do
157 [[ ${fl:0:1} = "^" ]] && neg=1
158 [[ $neg = 1 ]] && fl=${fl:1}
160 $(echo $value | grep -q $fl)
162 # 0: matched; 1: not matched
164 if [[ $neg = 0 && $match != 0 ||
165 $neg = 1 && $match = 0 ]]; then
167 [[ $neg = 0 ]] && # expect the flag
168 error "expected flag '$fl' not in $comp_id"
169 [[ $neg = 1 ]] && # not expect the flag
170 error "not expected flag '$fl' in $comp_id"
176 [[ $value = $expected ]] || {
178 error "verify $attr failed on $tf: $value != $expected"
183 # Verify component extent with expected start and end extent values
184 # for a given file and component ID.
186 verify_comp_extent() {
189 local expected_start=$3
190 local expected_end=$4
192 verify_comp_attr comp-start $tf $comp_id $expected_start
193 verify_comp_attr comp-end $tf $comp_id $expected_end
197 # Verify component attribute with parent directory for a given file
200 verify_comp_attr_with_parent() {
204 local td=$(cd $(dirname $tf); echo $PWD)
205 local tf_cmd="$LFS getstripe -I$comp_id"
206 local td_cmd="$LFS getstripe"
212 stripe-size) opt="-S" ;;
213 stripe-count) opt="-c" ;;
215 *) error "invalid attribute $attr";;
218 expected=$($td_cmd $opt $td)
219 [[ $expected = -1 ]] && expected=$OSTCOUNT
221 value=$($tf_cmd $opt $tf)
222 [[ $value = -1 ]] && value=$OSTCOUNT
224 [[ $value = $expected ]] || {
227 error "verify $attr failed with parent on $tf:" \
228 "$value != $expected"
233 # Verify component attribute with filesystem-wide default value for a given file
236 verify_comp_attr_with_default() {
240 local tf_cmd="$LFS getstripe -I$comp_id"
248 expected=$($LCTL get_param -n \
249 lov.$FSNAME-clilov-*.stripesize)
253 expected=$($LCTL get_param -n \
254 lov.$FSNAME-clilov-*.stripecount)
255 [[ $expected = -1 ]] && expected=$OSTCOUNT
257 *) error "invalid attribute $attr";;
260 value=$($tf_cmd $opt $tf)
261 [[ $value = -1 ]] && value=$OSTCOUNT
263 [[ $value = $expected ]] || {
265 error "verify $attr failed with default value on $tf:" \
266 "$value != $expected"
271 # Verify unspecified component attributes for a given file
274 # This will only verify the inherited attributes:
275 # stripe size, stripe count and OST pool name
277 verify_comp_attrs() {
281 verify_comp_attr_with_default stripe-size $tf $comp_id
282 verify_comp_attr_with_default stripe-count $tf $comp_id
283 verify_comp_attr_with_parent pool $tf $comp_id
289 local expected_state=$2
291 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
292 [ $expected_state = $state ] ||
293 error "expected: $expected_state, actual $state"
296 # command line test cases
300 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
301 local mirror_cmd="$LFS mirror create"
306 # create parent directory
307 mkdir $td || error "mkdir $td failed"
309 $mirror_cmd $tf &> /dev/null && error "miss -N option"
311 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
312 verify_mirror_count $tf 1
313 id=$($LFS getstripe -I $tf)
314 verify_comp_attrs $tf $id
315 verify_comp_extent $tf $id 0 EOF
317 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
318 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
319 error "invalid mirror count $((mirror_count + 1))"
321 $mirror_cmd -N$mirror_count $tf-1 ||
322 error "create mirrored file $tf-1 failed"
323 verify_mirror_count $tf-1 $mirror_count
324 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
325 for ((i = 0; i < $mirror_count; i++)); do
326 verify_comp_attrs $tf-1 ${ids[$i]}
327 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
330 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
331 error "create mirrored file $tf-2 failed"
332 verify_mirror_count $tf-2 10
333 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
334 for ((i = 0; i < 10; i++)); do
335 verify_comp_attrs $tf-2 ${ids[$i]}
336 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
339 run_test 0a "lfs mirror create with -N option"
342 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
346 local mirror_cmd="$LFS mirror create"
350 # create a new OST pool
351 local pool_name=$TESTNAME
352 create_pool $FSNAME.$pool_name ||
353 error "create OST pool $pool_name failed"
355 # add OSTs into the pool
356 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
357 error "add OSTs into pool $pool_name failed"
359 # create parent directory
360 mkdir $td || error "mkdir $td failed"
361 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
362 error "$LFS setstripe $td failed"
364 # create a mirrored file with plain layout mirrors
365 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
366 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
367 error "create mirrored file $tf failed"
368 verify_mirror_count $tf 6
369 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
370 for ((i = 0; i < 6; i++)); do
371 verify_comp_extent $tf ${ids[$i]} 0 EOF
374 # verify component ${ids[0]}
375 verify_comp_attrs $tf ${ids[0]}
377 # verify component ${ids[1]}
378 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
379 verify_comp_attr stripe-count $tf ${ids[1]} 2
380 verify_comp_attr stripe-index $tf ${ids[1]} 2
382 # verify component ${ids[2]}
383 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
384 verify_comp_attr stripe-count $tf ${ids[2]} 2
385 verify_comp_attr pool $tf ${ids[2]} flash
387 # verify component ${ids[3]}
388 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
389 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
390 verify_comp_attr pool $tf ${ids[3]} flash
392 # verify component ${ids[4]}
393 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
394 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
395 verify_comp_attr pool $tf ${ids[4]} archive
397 # verify component ${ids[5]}
398 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
399 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
400 verify_comp_attr_with_parent pool $tf ${ids[5]}
402 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
403 # LU-11022 - remove mirror by pool name
404 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
405 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
406 $LFS mirror delete --pool archive $tf || error "delete mirror"
407 cnt=$($LFS getstripe $tf | grep archive | wc -l)
408 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
414 run_test 0b "lfs mirror create plain layout mirrors"
417 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
421 local mirror_cmd="$LFS mirror create"
425 # create a new OST pool
426 local pool_name=$TESTNAME
427 create_pool $FSNAME.$pool_name ||
428 error "create OST pool $pool_name failed"
430 # add OSTs into the pool
431 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
432 error "add OSTs into pool $pool_name failed"
434 # create parent directory
435 mkdir $td || error "mkdir $td failed"
436 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
437 error "$LFS setstripe $td failed"
439 # create a mirrored file with composite layout mirrors
440 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
442 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
443 error "create mirrored file $tf failed"
444 verify_mirror_count $tf 6
445 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
447 # verify components ${ids[0]} and ${ids[2]}
449 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
450 verify_comp_attr stripe-count $tf ${ids[$i]} 2
451 verify_comp_attr stripe-index $tf ${ids[$i]} 1
452 verify_comp_extent $tf ${ids[$i]} 0 4194304
455 # verify components ${ids[1]} and ${ids[3]}
457 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
458 verify_comp_attr stripe-count $tf ${ids[$i]} 2
459 verify_comp_attr pool $tf ${ids[$i]} flash
460 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
463 # verify component ${ids[4]}
464 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
465 verify_comp_attr stripe-count $tf ${ids[4]} 4
466 verify_comp_attr_with_parent pool $tf ${ids[4]}
467 verify_comp_extent $tf ${ids[4]} 0 EOF
469 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
471 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
472 verify_comp_attr stripe-count $tf ${ids[$i]} 4
473 verify_comp_attr pool $tf ${ids[$i]} archive
474 verify_comp_extent $tf ${ids[$i]} 0 536870912
477 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
479 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
480 verify_comp_attr stripe-count $tf ${ids[$i]} -1
481 verify_comp_attr pool $tf ${ids[$i]} archive
482 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
488 run_test 0c "lfs mirror create composite layout mirrors"
493 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
494 local mirror_cmd="$LFS mirror extend"
498 # create parent directory
499 mkdir $td || error "mkdir $td failed"
501 $mirror_cmd $tf &> /dev/null && error "miss -N option"
502 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
504 # create a non-mirrored file, convert it to a mirrored file and extend
505 touch $tf || error "touch $tf failed"
506 $mirror_cmd -N $tf || error "convert and extend $tf failed"
507 verify_mirror_count $tf 2
508 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
509 for ((i = 0; i < 2; i++)); do
510 verify_comp_attrs $tf ${ids[$i]}
511 verify_comp_extent $tf ${ids[$i]} 0 EOF
514 lfsck_verify_pfid $tf || error "PFID is not set"
516 # create a mirrored file and extend it
517 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
518 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
519 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
521 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
522 error "extend mirror with -f failed"
524 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
525 error "extend mirrored file $tf-3 failed"
526 verify_mirror_count $tf-3 $mirror_count
527 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
528 for ((i = 0; i < $mirror_count; i++)); do
529 verify_comp_attrs $tf-3 ${ids[$i]}
530 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
533 $mirror_cmd -N $tf-3 &> /dev/null
536 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
538 run_test 0d "lfs mirror extend with -N option"
541 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
545 local mirror_cmd="$LFS mirror extend"
549 # create parent directory
550 mkdir $td || error "mkdir $td failed"
552 # create a mirrored file with plain layout mirrors
553 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
554 error "create mirrored file $tf failed"
556 # extend the mirrored file with plain layout mirrors
557 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
558 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
559 error "extend mirrored file $tf failed"
560 verify_mirror_count $tf 6
561 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
562 for ((i = 0; i < 6; i++)); do
563 verify_comp_extent $tf ${ids[$i]} 0 EOF
566 # verify component ${ids[0]}
567 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
568 verify_comp_attr stripe-count $tf ${ids[0]} 3
569 verify_comp_attr stripe-index $tf ${ids[0]} 1
571 # verify component ${ids[1]}
572 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
573 verify_comp_attr stripe-count $tf ${ids[1]} 2
574 verify_comp_attr stripe-index $tf ${ids[1]} 2
576 # verify component ${ids[2]}
577 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
578 verify_comp_attr stripe-count $tf ${ids[2]} 2
579 verify_comp_attr pool $tf ${ids[2]} flash
581 # verify component ${ids[3]}
582 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
583 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
584 verify_comp_attr pool $tf ${ids[3]} flash
586 # verify component ${ids[4]}
587 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
588 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
589 verify_comp_attr pool $tf ${ids[4]} archive
591 # verify component ${ids[5]}
592 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
593 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
594 verify_comp_attr_with_parent pool $tf ${ids[5]}
596 run_test 0e "lfs mirror extend plain layout mirrors"
599 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
603 local mirror_cmd="$LFS mirror extend"
607 # create parent directory
608 mkdir $td || error "mkdir $td failed"
610 # create a mirrored file with composite layout mirror
611 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
612 error "create mirrored file $tf failed"
614 # extend the mirrored file with composite layout mirrors
615 $mirror_cmd -N -p archive \
616 -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
618 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
619 error "extend mirrored file $tf failed"
620 verify_mirror_count $tf 8
621 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
623 # verify component ${ids[0]}
624 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
625 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
626 verify_comp_attr pool $tf ${ids[0]} ssd
627 verify_comp_extent $tf ${ids[0]} 0 33554432
629 # verify component ${ids[1]}
630 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
631 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
632 verify_comp_attr pool $tf ${ids[1]} ssd
633 verify_comp_extent $tf ${ids[1]} 33554432 EOF
635 # verify component ${ids[2]}
636 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
637 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
638 verify_comp_attr pool $tf ${ids[2]} archive
639 verify_comp_extent $tf ${ids[2]} 0 EOF
641 # verify components ${ids[3]} and ${ids[5]}
643 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
644 verify_comp_attr stripe-count $tf ${ids[$i]} 2
645 verify_comp_attr stripe-index $tf ${ids[$i]} 1
646 verify_comp_extent $tf ${ids[$i]} 0 4194304
649 # verify components ${ids[4]} and ${ids[6]}
651 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
652 verify_comp_attr stripe-count $tf ${ids[$i]} 2
653 verify_comp_attr pool $tf ${ids[$i]} flash
654 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
657 # verify component ${ids[7]}
658 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
659 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
660 verify_comp_attr_with_parent pool $tf ${ids[7]}
661 verify_comp_extent $tf ${ids[7]} 0 EOF
663 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
665 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
666 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
667 verify_comp_attr pool $tf ${ids[$i]} archive
668 verify_comp_extent $tf ${ids[$i]} 0 536870912
671 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
673 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
674 verify_comp_attr stripe-count $tf ${ids[$i]} -1
675 verify_comp_attr pool $tf ${ids[$i]} archive
676 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
679 run_test 0f "lfs mirror extend composite layout mirrors"
684 ! $LFS mirror create --flags prefer $tf ||
685 error "creating $tf w/ --flags but w/o -N option should fail"
687 ! $LFS mirror create -N --flags foo $tf ||
688 error "creating $tf with '--flags foo' should fail"
690 ! $LFS mirror create -N --flags stale $tf ||
691 error "creating $tf with '--flags stale' should fail"
693 ! $LFS mirror create -N --flags prefer,init $tf ||
694 error "creating $tf with '--flags prefer,init' should fail"
696 ! $LFS mirror create -N --flags ^prefer $tf ||
697 error "creating $tf with '--flags ^prefer' should fail"
699 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
700 -N -o1 $tf || error "create mirrored file $tf failed"
702 verify_comp_attr lcme_flags $tf 0x10001 prefer
703 verify_comp_attr lcme_flags $tf 0x10002 prefer
705 # write to the mirrored file and check primary
706 cp /etc/hosts $tf || error "error writing file '$tf'"
708 verify_comp_attr lcme_flags $tf 0x20003 stale
710 # resync file and check prefer flag
711 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
714 $LCTL set_param osc.*.stats=clear
715 cat $tf &> /dev/null || error "error reading file '$tf'"
717 # verify that the data was provided by OST1 where mirror 1 resides
718 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
719 awk '/ost_read/{print $2}')
720 [ -n "$nr_read" ] || error "read was not provided by OST1"
722 run_test 0g "lfs mirror create flags support"
725 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
726 skip "Need MDS version at least 2.11.57"
733 # create parent directory
734 test_mkdir $td || error "mkdir $td failed"
736 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
737 error "set default mirrored layout on directory $td failed"
739 # verify flags are inherited from the directory
742 verify_comp_attr lcme_flags $tf 0x10001 prefer
743 verify_comp_attr lcme_flags $tf 0x10002 prefer
745 # set flags to the first component
746 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
747 error "setting '^prefer,foo' flags should fail"
749 ! $LFS getstripe --component-flags=prefer,foo $tf ||
750 error "getting component(s) with 'prefer,foo' flags should fail"
752 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
754 verify_comp_attr lcme_flags $tf 0x10001 stale
755 verify_comp_attr lcme_flags $tf 0x10002 prefer
757 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
758 error "clearing 'stale' should fail"
760 # write and resync file. It can't resync the file directly because the
761 # file state is still 'ro'
762 cp /etc/hosts $tf || error "error writing file '$tf'"
763 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
765 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
766 error "error setting flag prefer"
768 verify_comp_attr lcme_flags $tf 0x20003 prefer
770 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^prefer $tf ||
771 error "error clearing prefer flag from component 0x20003"
773 # MDS disallows setting stale flag on the last non-stale mirror
774 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
776 cp /etc/hosts $tf || error "error writing file '$tf'"
778 verify_comp_attr lcme_flags $tf 0x10002 prefer
779 verify_comp_attr lcme_flags $tf 0x20003 stale
780 verify_comp_attr lcme_flags $tf 0x30004 stale
782 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
784 error "setting stale flag on component 0x10002 should fail"
786 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
788 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
789 error "error setting stale flag on component 0x10001"
790 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
791 error "error setting stale flag on component 0x20003"
793 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
795 error "setting stale flag on component 0x30004 should fail"
797 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
799 run_test 0h "set, clear and test flags for FLR files"
802 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
804 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
805 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
806 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
808 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
809 stack_trap "rm -f $TMP/$tfile"
810 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
811 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
812 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
813 error "set component 1 stale failed"
814 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
815 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
817 run_test 0j "test lfs mirror read/write commands"
821 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
822 local mirror_create_cmd="$LFS mirror create"
823 local stripes[0]=$OSTCOUNT
825 mirror_create_cmd+=" -N -c ${stripes[0]}"
826 for ((i = 1; i < $mirror_count; i++)); do
827 # add mirrors with different stripes to the file
828 stripes[$i]=$((RANDOM % OSTCOUNT))
829 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
831 mirror_create_cmd+=" -N -c ${stripes[$i]}"
834 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
835 verify_mirror_count $tf $mirror_count
837 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
838 $LFS mirror extend -N $tf &&
839 error "Creating the $((mirror_count+1))th mirror succeeded"
841 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
844 # verify the range of components and stripe counts
845 for ((i = 0; i < $mirror_count; i++)); do
846 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
847 verify_comp_extent $tf ${ids[$i]} 0 EOF
850 run_test 1 "create components with setstripe options"
854 local tf2=$DIR/$tfile-2
856 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
857 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
859 $LFS mirror extend -N -f $tf2 $tf ||
860 error "merging $tf2 into $tf failed"
862 verify_mirror_count $tf 2
863 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
865 run_test 2 "create components from existing files"
868 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
870 for ((i = 0; i < 2; i++)); do
871 $LFS mkdir -i $i $DIR/$tdir-$i
872 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
875 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
876 $DIR/$tdir-0/$tfile || error "creating mirrors"
878 # mdt doesn't support to cancel layout lock for remote objects, do
882 # make sure the mirrorted file was created successfully
883 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
884 { $LFS getstripe $DIR/$tdir-0/$tfile;
885 error "expected 2 components"; }
890 run_test 3 "create components from files located on different MDTs"
893 local tf=$DIR/$tdir/$tfile
896 test_mkdir $DIR/$tdir
898 # set mirror with setstripe options to directory
899 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
900 error "set mirror to directory error"
902 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
903 x"mirrored" ] || error "failed to create mirrored dir"
906 verify_mirror_count $tf 2
908 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
909 verify_comp_extent $tf ${ids[0]} 0 1048576
910 verify_comp_extent $tf ${ids[1]} 1048576 EOF
912 # sub directory should inherit mirror setting from parent
913 test_mkdir $DIR/$tdir/td
914 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
915 x"mirrored" ] || error "failed to inherit mirror from parent"
917 # mirror extend won't be applied to directory
918 $LFS mirror extend -N2 $DIR/$tdir &&
919 error "expecting mirror extend failure"
922 run_test 4 "Make sure mirror attributes can be inhertied from directory"
928 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
929 error "failed to create file with non-empty layout"
930 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
932 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
933 verify_mirror_count $tf 3
935 $CHECKSTAT -t file -s 12345 $tf ||
936 error "size error after attaching layout "
938 run_test 5 "Make sure init size work for mirrored layout"
941 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
942 skip "MDS version older than 2.12.58"
946 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
947 error "failure to create DoM file with mirror"
949 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
950 error "failure to create mirrored file with DoM"
952 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
953 error "failure to create PFL with DoM file"
954 $LFS mirror extend -N2 $tf ||
955 error "failure to extend mirror with DoM"
957 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
958 error "failure to create PFL with DoM file"
959 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
960 error "failure to create mirrored file"
961 $LFS mirror extend -N -f $tf-1 $tf-2 ||
962 error "failure to extend mirrored file with DoM extent"
964 run_test 6 "DoM and FLR work together"
969 # create DoM with setting stripe_size == component size
970 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
971 error "failure to create DoM with stripe_size == comp size"
972 rm -f $tf || error "delete $tf"
974 # DoM should not inherit previous component stripe_size
975 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
976 error "DoM component shouldn't inherit previous stripe_size"
978 run_test 7 "Create mirror with DoM component"
982 local tf2=$DIR/$tfile-2
984 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
986 stack_trap "rm -f $tf $tf2"
988 $LFS setstripe -E EOF -o 0 $tf
989 $LFS setstripe -E EOF -o 1 $tf2
991 local dd_count=$((RANDOM % 20 + 1))
992 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
993 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
995 # for zfs - sync OST dataset so that du below will return
997 [ "$FSTYPE" = "zfs" ] &&
998 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1000 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1003 $LFS mirror extend -N -f $tf2 $tf ||
1004 error "merging $tf2 into $tf failed"
1006 # cancel layout lock
1007 cancel_lru_locks mdc
1009 local new_blocks=$(du -k $tf | awk '{print $1}')
1010 [ $new_blocks -eq $blocks ] ||
1011 error "i_blocks error expected: $blocks, actual: $new_blocks"
1013 run_test 21 "glimpse should report accurate i_blocks"
1015 get_osc_lock_count() {
1022 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1023 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1024 lock_count=$((lock_count + count))
1030 local tf=$DIR/$tfile
1032 stack_trap "rm -f $tf"
1034 $LFS setstripe -E EOF -o 0 $tf
1035 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1037 # add component, two mirrors located on the same OST ;-)
1038 $LFS mirror extend -N -o 0 $tf ||
1039 error "extending mirrored file $tf failed"
1041 size_blocks=$(stat --format="%b %s" $tf)
1043 cancel_lru_locks mdc
1044 cancel_lru_locks osc
1046 local new_size_blocks=$(stat --format="%b %s" $tf)
1048 # make sure there is no lock cached
1049 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1051 [ "$new_size_blocks" = "$size_blocks" ] ||
1052 echo "size expected: $size_blocks, actual: $new_size_blocks"
1056 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1059 local tf=$DIR/$tfile
1061 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1062 error "creating mirrored file $tf failed"
1064 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
1065 $LCTL set_param fail_loc=0x1A00
1068 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1069 cancel_lru_locks osc
1072 local tmpfile=$(mktemp)
1073 stat --format="%b %s" $tf > $tmpfile &
1077 while [ $cnt -le 5 ]; do
1078 kill -0 $pid > /dev/null 2>&1 || break
1082 kill -0 $pid > /dev/null 2>&1 &&
1083 error "stat process stuck due to unavailable OSTs"
1085 # make sure glimpse request has been sent
1086 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1087 error "OST $ost_idx: no glimpse request was sent"
1092 run_test 31 "make sure glimpse request can be retried"
1095 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1096 rm -f $DIR/$tfile $DIR/$tfile-2
1098 stack_trap "rm -f $DIR/$tfile"
1100 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1101 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1103 local fsize=$(stat -c %s $DIR/$tfile)
1104 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1106 local cksum=$(md5sum $DIR/$tfile)
1108 # create a new mirror in sync mode
1109 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1110 error "extending mirrored file $DIR/$tfile failed"
1112 # make sure the mirrored file was created successfully
1113 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1114 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1119 # check size is correct, glimpse request should go to the 2nd mirror
1120 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1121 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1123 echo "reading file from the 2nd mirror and verify checksum"
1124 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1125 error "checksum error: expected $cksum"
1129 run_test 32 "data should be mirrored to newly created mirror"
1132 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1134 rm -f $DIR/$tfile $DIR/$tfile-2
1136 # create a file with two mirrors
1137 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1140 while [ $count -lt $max_count ]; do
1141 echo "ost1" >> $DIR/$tfile
1142 count=$((count + 1));
1145 # tmp file that will be used as mirror
1146 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1148 while [ $count -lt $max_count ]; do
1149 echo "ost2" >> $DIR/$tfile-2
1150 count=$((count + 1));
1153 # create a mirrored file
1154 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1155 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1156 "with verification should fail"
1157 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1158 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1159 "without verification failed"
1161 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1162 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1163 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1165 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1167 # execpted file size
1168 local fsize=$((5 * max_count))
1169 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1170 error "mirrored file size is not $fsize"
1172 # read file - all OSTs are available
1173 echo "reading file (data can be provided by any ost)... "
1174 local rs=$(cat $DIR/$tfile | head -1)
1175 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1176 error "file content error: expected: \"ost1\" or \"ost2\""
1178 # read file again with ost1 failed
1182 echo "reading file (data should be provided by ost2)..."
1183 local rs=$(cat $DIR/$tfile | head -1)
1184 [[ "$rs" == "ost2" ]] ||
1185 error "file content error: expected: \"ost2\", actual: \"$rs\""
1190 # read file again with ost2 failed
1194 # check size, glimpse should work
1195 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1196 error "mirrored file size is not $fsize"
1198 echo "reading file (data should be provided by ost1)..."
1199 local rs=$(cat $DIR/$tfile | head -1)
1200 [[ "$rs" == "ost1" ]] ||
1201 error "file content error: expected: \"ost1\", actual: \"$rs\""
1205 run_test 33a "read can choose available mirror to read"
1208 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1212 stack_trap "rm -f $DIR/$tfile" EXIT
1214 # create a file with two mirrors on OST0000 and OST0001
1215 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1217 # make sure that $tfile has two mirrors
1218 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1219 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1222 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1223 error "write failed for $DIR/$tfile"
1224 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1225 verify_flr_state $DIR/$tfile "ro"
1230 # read file - all OSTs are available
1231 echo "reading file (data can be provided by any ost)... "
1233 time cat $DIR/$tfile > /dev/null || error "read all"
1237 # read file again with ost1 {OST0000} failed
1240 echo "reading file (data should be provided by ost2)..."
1242 time cat $DIR/$tfile > /dev/null || error "read ost2"
1249 # read file again with ost2 {OST0001} failed
1253 echo "reading file (data should be provided by ost1)..."
1255 time cat $DIR/$tfile > /dev/null || error "read ost1"
1262 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1263 error "read mirror too slow without ost1, from $ra to $r1"
1264 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1265 error "read mirror too slow without ost2, from $ra to $r2"
1267 wait_osc_import_ready client ost2
1269 run_test 33b "avoid reading from unhealthy mirror"
1272 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1276 stack_trap "rm -f $DIR/$tfile" EXIT
1278 # create a file with two mirrors
1279 # mirror1: {OST0000, OST0001}
1280 # mirror2: {OST0001, OST0002}
1281 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1283 # make sure that $tfile has two mirrors
1284 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1285 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1288 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1289 error "write failed for $DIR/$tfile"
1290 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1291 verify_flr_state $DIR/$tfile "ro"
1296 # read file - all OSTs are available
1297 echo "reading file (data can be provided by any ost)... "
1298 time cat $DIR/$tfile > /dev/null || error "read all"
1300 # read file again with ost2 (OST0001) failed
1304 echo "reading file (data should be provided by ost1 and ost3)..."
1305 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1310 wait_osc_import_ready client ost2
1312 run_test 33c "keep reading among unhealthy mirrors"
1315 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1317 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1320 $LFS setstripe -o 0 $DIR/$tfile-ref
1321 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1323 # create a file with two mirrors
1324 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1325 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1327 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1328 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1330 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1331 error "mirrored file size is not 3M"
1333 # merge a mirrored file
1334 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1335 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1337 cancel_lru_locks osc
1339 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1340 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1343 echo "comparing files ... "
1345 # however, read can still return the correct data. It should return
1346 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1347 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1348 $DIR/$tfile-ref || error "file reading error"
1352 run_test 34a "read mirrored file with multiple stripes"
1355 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1357 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1360 $LFS setstripe -o 0 $DIR/$tfile-ref
1361 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1363 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1364 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1366 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1367 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1369 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1370 error "mirrored file size is not 3M"
1372 # merge a mirrored file
1373 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1374 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1376 cancel_lru_locks osc
1378 # stop two OSTs, so the 2nd component of the 1st mirror and
1379 # the 1st component of the 2nd mirror will be inaccessible, ...
1382 echo "comparing files ... "
1384 # however, read can still return the correct data. It should return
1385 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1386 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1387 $DIR/$tfile-ref || error "file reading error"
1391 run_test 34b "read mirrored file with multiple components"
1394 local tf=$DIR/$tfile
1396 $LFS setstripe -E eof $tf
1398 # add an out-of-sync mirror to the file
1399 $LFS mirror extend -N -c 2 $tf ||
1400 error "extending mirrored file $tf failed"
1402 $MULTIOP $tf oO_WRONLY:c ||
1403 error "write open a mirrored file failed"
1405 # truncate file should return error
1406 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1408 run_test 35 "allow to write to mirrored files"
1410 verify_ost_layout_version() {
1413 # get file layout version
1414 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1416 # layout version from OST objects
1417 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1419 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1426 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1427 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1429 $LFS mirror extend -N -f $tf-tmp $tf ||
1430 error "merging $tf-tmp into $tf failed"
1435 local tf=$DIR/$tfile
1437 stack_trap "rm -f $tf $tf-2 $tf-3"
1439 create_file_36 $tf $tf-2 $tf-3
1441 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1443 # test case 1 - check file write and verify layout version
1444 $MULTIOP $tf oO_WRONLY:c ||
1445 error "write open a mirrored file failed"
1447 # write open file should not return error
1448 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1450 # instantiate components should work
1451 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1453 # verify OST layout version
1454 verify_ost_layout_version $tf
1457 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1460 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1462 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1463 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1465 # write should take at least $fail_loc seconds and succeed
1466 local st=$(date +%s)
1467 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1469 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1470 error "write finished before layout version is transmitted"
1472 # verify OST layout version
1473 verify_ost_layout_version $tf
1475 do_facet $mds_facet $LCTL set_param fail_loc=0
1478 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1480 #define OBD_FAIL_FLR_LV_INC 0x1A02
1481 do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1483 # write open file should return error
1484 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1485 error "write a mirrored file succeeded" || true
1487 do_facet $mds_facet $LCTL set_param fail_loc=0
1489 run_test 36 "write to mirrored files"
1495 echo "create test files with size $fsize .."
1499 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1501 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1502 $TRUNCATE $tf $fsize
1508 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1509 skip "Need MDS version at least 2.11.57"
1511 local tf=$DIR/$tfile
1512 local tf2=$DIR/$tfile-2
1513 local tf3=$DIR/$tfile-3
1514 local tf4=$DIR/$tfile-4
1516 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1518 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1522 # assume the mirror id will be 1, 2, and 3
1523 declare -A checksums
1524 checksums[1]=$(cat $tf | md5sum)
1525 checksums[2]=$(cat $tf2 | md5sum)
1526 checksums[3]=$(cat $tf3 | md5sum)
1528 printf '%s\n' "${checksums[@]}"
1530 # merge these files into a mirrored file
1531 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1532 error "merging $tf2 into $tf failed"
1533 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1534 error "merging $tf3 into $tf failed"
1538 # verify mirror read, checksums should equal to the original files'
1539 echo "Verifying mirror read .."
1542 for i in ${mirror_array[@]}; do
1543 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1544 sum=$($LFS mirror read -N $i $tf | md5sum)
1545 [ "$sum" = "${checksums[$i]}" ] ||
1546 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1549 # verify mirror write
1550 echo "Verifying mirror write .."
1551 $LFS mirror write -N2 $tf < $tf4
1553 sum=$($LFS mirror read -N2 $tf | md5sum)
1554 [[ "$sum" = "${checksums[1]}" ]] ||
1555 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1557 # verify mirror copy, write to this mirrored file will invalidate
1558 # the other two mirrors
1559 echo "Verifying mirror copy .."
1561 local osts=$(comma_list $(osts_nodes))
1563 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1564 error "mirror copy error"
1566 # verify copying is successful by checking checksums
1567 remount_client $MOUNT
1568 for i in ${mirror_array[@]}; do
1569 sum=$($LFS mirror read -N $i $tf | md5sum)
1570 [ "$sum" = "${checksums[1]}" ] ||
1571 error "$i: mismatch checksum after copy \'$sum\'"
1576 run_test 37 "mirror I/O API verification"
1579 local tf=$DIR/$tfile
1580 local ref=$DIR/${tfile}-ref
1582 stack_trap "rm -f $tf $ref"
1584 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1585 error "creating $tf failed"
1586 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1587 $tf-2 || error "creating $tf-2 failed"
1588 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1589 error "creating $tf-3 failed"
1591 # instantiate all components
1592 $LFS mirror extend -N -f $tf-2 $tf ||
1593 error "merging $tf-2 into $tf failed"
1594 $LFS mirror extend -N -f $tf-3 $tf ||
1595 error "merging $tf-3 into $tf failed"
1596 $LFS mirror extend -N -c 1 $tf ||
1597 error "extending mirrored file $tf failed"
1599 verify_flr_state $tf "ro"
1601 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1603 local fsize=$((RANDOM << 8 + 1048576))
1604 $TRUNCATE $ref $fsize
1606 local ref_cksum=$(cat $ref | md5sum)
1608 # case 1: verify write to mirrored file & resync work
1609 cp $ref $tf || error "copy from $ref to $f error"
1610 verify_flr_state $tf "wp"
1612 local file_cksum=$(cat $tf | md5sum)
1613 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1616 echo "mirror IDs: ${mirror_array[@]}"
1618 local valid_mirror stale_mirror id mirror_cksum
1619 for id in "${mirror_array[@]}"; do
1620 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1621 [ "$ref_cksum" == "$mirror_cksum" ] &&
1622 { valid_mirror=$id; continue; }
1627 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1628 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1630 $LFS mirror resync $tf || error "resync failed"
1631 verify_flr_state $tf "ro"
1633 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1634 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1636 # case 2: inject an error to make mirror_io exit after changing
1637 # the file state to sync_pending so that we can start a concurrent
1639 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1640 verify_flr_state $tf "wp"
1642 mirror_io resync -e resync_start $tf && error "resync succeeded"
1643 verify_flr_state $tf "sp"
1645 # from sync_pending to write_pending
1646 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1647 verify_flr_state $tf "wp"
1649 mirror_io resync -e resync_start $tf && error "resync succeeded"
1650 verify_flr_state $tf "sp"
1652 # from sync_pending to read_only
1653 $LFS mirror resync $tf || error "resync failed"
1654 verify_flr_state $tf "ro"
1656 run_test 38 "resync"
1659 local tf=$DIR/$tfile
1662 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1663 error "create PFL file $tf failed"
1665 verify_mirror_count $tf 2
1666 verify_comp_count $tf 4
1668 rm -f $tf || error "delete $tf failed"
1670 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1673 local tf=$DIR/$tfile
1676 for ops in "conv=notrunc" ""; do
1679 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1680 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1681 error "create PFLR file $tf failed"
1682 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1683 error "write PFLR file $tf failed"
1685 lfs getstripe -vy $tf
1689 # file mirror state should be write_pending
1690 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1692 error "file mirror state $flags"
1693 # the 1st component (in mirror 1) should be inited
1694 verify_comp_attr lcme_flags $tf 0x10001 init
1695 # the 2nd component (in mirror 1) should be inited
1696 verify_comp_attr lcme_flags $tf 0x10002 init
1697 # the 3rd component (in mirror 1) should be uninited
1698 verify_comp_attr lcme_flags $tf 0x10003 prefer
1699 # the 4th component (in mirror 2) should be inited
1700 verify_comp_attr lcme_flags $tf 0x20004 init
1701 # the 5th component (in mirror 2) should be uninited
1702 verify_comp_attr lcme_flags $tf 0x20005 0
1703 # the 6th component (in mirror 2) should be stale
1704 verify_comp_attr lcme_flags $tf 0x20006 stale
1705 # the 7th component (in mirror 2) should be uninited
1706 if [[ x$ops = "xconv=notrunc" ]]; then
1707 verify_comp_attr lcme_flags $tf 0x20007 0
1708 elif [[ x$ops = "x" ]]; then
1709 verify_comp_attr lcme_flags $tf 0x20007 stale
1713 rm -f $tf || error "delete $tf failed"
1715 run_test 40 "PFLR rdonly state instantiation check"
1718 local tf=$DIR/$tfile
1720 stack_trap "rm -f $tf $tf-1"
1723 echo " **create two FLR files $tf $tf-1"
1724 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1725 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1726 error "create PFLR file $tf failed"
1727 $LFS mirror create -N -E 2M -S 1M -E eof \
1728 -N -E 1M -E eof --flags prefer \
1729 -N -E 4m -E eof $tf-1 ||
1730 error "create PFLR file $tf-1 failed"
1732 # file should be in ro status
1733 echo " **verify files be RDONLY"
1734 verify_flr_state $tf "ro"
1735 verify_flr_state $tf-1 "ro"
1737 # write data in [0, 2M)
1738 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1739 error "writing $tf failed"
1740 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1741 error "writing $tf-1 failed"
1743 local sum0=$(cat $tf-1 | md5sum)
1745 echo " **verify files be WRITE_PENDING"
1746 verify_flr_state $tf "wp"
1747 verify_flr_state $tf-1 "wp"
1749 # file should have stale component
1750 echo " **verify files have stale component"
1751 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1752 error "after writing $tf, it does not contain stale component"
1753 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1754 error "after writing $tf-1, it does not contain stale component"
1756 echo " **full resync"
1757 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1759 echo " **verify $tf-1 data consistency in all mirrors"
1761 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1762 [[ "$sum" = "$sum0" ]] ||
1763 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1766 echo " **verify files be RDONLY"
1767 verify_flr_state $tf "ro"
1768 verify_flr_state $tf-1 "ro"
1770 # file should not have stale component
1771 echo " **verify files do not contain stale component"
1772 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1773 error "after resyncing $tf, it contains stale component"
1774 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1775 error "after resyncing $tf, it contains stale component"
1777 # verify partial resync
1778 echo " **write $tf-1 for partial resync test"
1779 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1780 error "writing $tf-1 failed"
1782 echo " **only resync mirror 2"
1783 verify_flr_state $tf-1 "wp"
1784 $LFS mirror resync --only 2 $tf-1 ||
1785 error "resync mirror 2 of $tf-1 failed"
1786 verify_flr_state $tf "ro"
1788 # resync synced mirror
1789 echo " **resync mirror 2 again"
1790 $LFS mirror resync --only 2 $tf-1 ||
1791 error "resync mirror 2 of $tf-1 failed"
1792 verify_flr_state $tf "ro"
1793 echo " **verify $tf-1 contains stale component"
1794 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1795 error "after writing $tf-1, it does not contain stale component"
1797 echo " **full resync $tf-1"
1798 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1799 verify_flr_state $tf "ro"
1800 echo " **full resync $tf-1 again"
1801 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1802 echo " **verify $tf-1 does not contain stale component"
1803 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1804 error "after resyncing $tf, it contains stale component"
1808 run_test 41 "lfs mirror resync check"
1811 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1815 local mirror_cmd="$LFS mirror verify"
1818 stack_trap "rm -rf $td"
1820 # create parent directory
1821 mkdir $td || error "mkdir $td failed"
1823 $mirror_cmd &> /dev/null && error "no file name given"
1824 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1825 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1827 # create mirrored files
1828 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1829 error "create mirrored file $tf failed"
1830 $LFS mirror create -N -E 2M -S 1M -E EOF \
1831 -N -E 6M -E 8M -E EOF \
1832 -N -E 16M -E EOF $tf-1 ||
1833 error "create mirrored file $tf-1 failed"
1834 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1835 error "create mirrored file $tf-2 failed"
1837 # write data in [0, 10M)
1838 for i in $tf $tf-1 $tf-2; do
1839 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1840 error "write $i failed"
1843 # resync the mirrored files
1844 $LFS mirror resync $tf-1 $tf-2 ||
1845 error "resync $tf-1 $tf-2 failed"
1847 # verify the mirrored files
1848 $mirror_cmd $tf-1 $tf-2 ||
1849 error "verify $tf-1 $tf-2 failed"
1851 get_mirror_ids $tf-1
1852 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1853 error "at least 2 mirror ids needed with '--only' option"
1854 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1856 error "'--only' option cannot be used upon multiple files"
1857 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1858 error "invalid specified mirror ids"
1860 # change the content of $tf and merge it into $tf-1
1862 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1863 error "change $tf with seek=$i failed"
1864 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1865 error "change $tf-1 with seek=$i failed"
1868 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1869 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1870 error "merge $tf into $tf-1 failed"
1872 # verify the mirrored files
1873 echo "Verify $tf-1 without -v option:"
1874 $mirror_cmd $tf-1 &&
1875 error "verify $tf-1 should fail" || echo "PASS"
1877 echo "Verify $tf-1 with -v option:"
1878 $mirror_cmd -v $tf-1 &&
1879 error "verify $tf-1 should fail"
1881 get_mirror_ids $tf-1
1882 echo "Verify $tf-1 with --only option:"
1883 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1884 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1885 "${mirror_array[-1]} should fail"
1887 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1888 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1889 "${mirror_array[1]} should succeed"
1891 # set stale components in $tf-1
1892 for i in 0x40002 0x40003; do
1893 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1894 error "set stale flag on component $i failed"
1897 # verify the mirrored file
1898 echo "Verify $tf-1 with stale components:"
1899 $mirror_cmd -vvv $tf-1 ||
1900 error "verify $tf-1 with stale components should succeed"
1902 echo "Verify $tf-1 with stale components and --only option:"
1903 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1904 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1905 "${mirror_array[-1]} should succeed"
1907 run_test 42 "lfs mirror verify"
1909 # inactivate one OST && write && restore the OST
1913 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1916 wait=$(do_facet $SINGLEMDS \
1917 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1918 wait=${wait%%[^0-9]*}
1920 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1921 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1922 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1923 sleep $(($wait * 2 + 2))
1924 echo " **write $file"
1925 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1926 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1927 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1928 sleep $((wait * 2 + 2))
1930 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1931 [ $flags = wp ] || error "file mirror state $flags != wp"
1935 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1937 local tf=$DIR/$tfile
1941 ## mirror 0 ost (0, 1)
1942 ## mirror 1 ost (1, 2)
1943 ## mirror 2 ost (2, 0)
1944 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1945 -N -Eeof -c2 -o2,0 $tf ||
1946 error "create 3 mirrors file $tf failed"
1948 ################## OST0 ###########################################
1950 echo " **verify components"
1951 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1952 verify_comp_attr lcme_flags $tf 0x20002 init
1953 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1956 echo " **resync $tf"
1957 $LFS mirror resync $tf
1958 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1959 [ $flags = ro ] || error "file mirror state $flags != ro"
1961 ################## OST1 ###########################################
1963 echo " **verify components"
1964 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1965 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1966 verify_comp_attr lcme_flags $tf 0x30003 init
1969 echo " **resync $tf"
1970 $LFS mirror resync $tf
1971 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1972 [ $flags = ro ] || error "file mirror state $flags != ro"
1974 ################## OST2 ###########################################
1976 echo " **verify components"
1977 verify_comp_attr lcme_flags $tf 0x10001 init
1978 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1979 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1981 run_test 43a "mirror pick on write"
1984 local tf=$DIR/$tdir/$tfile
1986 test_mkdir $DIR/$tdir
1988 stack_trap "rm -rf $tf"
1990 # create 3 mirrors FLR file, the first 2 mirrors are preferred
1991 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
1992 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
1993 verify_flr_state $tf "ro"
1995 echo " ** write to $tf"
1996 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
1997 verify_flr_state $tf "wp"
1999 echo " ** resync $tf"
2000 $LFS mirror resync $tf || error "resync $tf failed"
2001 verify_flr_state $tf "ro"
2003 run_test 43b "allow writing to multiple preferred mirror file"
2006 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2009 local tf=$DIR/$tdir/$tfile
2010 local tf1=$DIR/$tdir-1/$tfile-1
2012 stack_trap "rm -rf $tf $tf1"
2014 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2015 error "create directory failed"
2016 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2017 error "create remote directory failed"
2018 rm -f $tf $tf1 $tf.mirror~2
2019 # create file with 4 mirrors
2020 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2021 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2022 error "create PFLR file $tf failed"
2024 # file should be in ro status
2025 verify_flr_state $tf "ro"
2027 # write data in [0, 3M)
2028 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2029 error "writing $tf failed"
2031 verify_flr_state $tf "wp"
2033 # disallow destroying the last non-stale mirror
2034 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2035 error "destroying mirror 1 should fail"
2037 # synchronize all mirrors of the file
2038 $LFS mirror resync $tf || error "mirror resync $tf failed"
2040 verify_flr_state $tf "ro"
2043 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2044 error "split to $tf1 failed"
2046 local idx0=$($LFS getstripe -m $tf)
2047 local idx1=$($LFS getstripe -m $tf1)
2049 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2050 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2052 # verify mirror count
2053 verify_mirror_count $tf 3
2054 verify_mirror_count $tf1 1
2056 $LFS mirror split --mirror-id 2 $tf ||
2057 error "split mirror 2 failed"
2059 verify_mirror_count $tf 2
2060 verify_mirror_count $tf.mirror~2 1
2062 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2063 error "setting stale flag on component 0x30008 failed"
2065 # disallow destroying the last non-stale mirror
2066 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2067 error "destroying mirror 4 should fail"
2069 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2071 $LFS mirror split --mirror-id 3 -d $tf ||
2072 error "destroying mirror 3 failed"
2073 verify_mirror_count $tf 1
2075 # verify splitted file contains the same content as the orig file does
2076 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2077 diff $tf $tf.mirror~2 ||
2078 error "splited file $tf.mirror~2 diffs from $tf"
2080 run_test 44a "lfs mirror split check"
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 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2176 local file=$DIR/$tdir/$tfile
2177 local dir=$DIR/$tdir/$dir
2178 local temp=$DIR/$tdir/template
2180 test_mkdir $DIR/$tdir
2182 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2183 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2184 error "Create $file failed"
2186 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2187 rm -f $file $file.copy
2189 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2190 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2191 error "Create $file failed"
2193 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2195 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2202 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2204 local layout1=$(get_layout_param $src)
2205 local layout2=$(get_layout_param $dst)
2206 # compare their layout info
2207 [ "$layout1" == "$layout2" ] ||
2208 error "$msg_prefix $src <=> $dst layouts are not equal"
2212 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2214 local file=$DIR/$tdir/$tfile
2215 test_mkdir $DIR/$tdir
2217 ########################### 1. PFL file #############################
2218 echo " ** 1. PFL file"
2220 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2221 $file || error "1. Create PFL $file failed"
2224 verify_46 $file $file.copy "1. PFL file"
2226 ########################### 2. plain file ###########################
2227 echo " ** 2. plain file"
2229 $LFS setstripe -c2 -o0,1 -i1 $file ||
2230 error "2. Create plain $file failed"
2233 verify_46 $file $file.copy "2. plain file"
2235 ########################### 3. FLR file #############################
2236 echo " ** 3. FLR file"
2238 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2239 $file || error "3. Create FLR $file failed"
2242 verify_46 $file $file.copy "3. FLR file"
2244 local dir=$DIR/$tdir/dir
2245 ########################### 4. PFL dir ##############################
2246 echo " ** 4. PFL dir"
2248 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2249 error "4. setstripe PFL $dir failed"
2251 test_mkdir $dir.copy
2252 verify_46 $dir $dir.copy "4. PFL dir"
2254 ########################### 5. plain dir ############################
2255 echo " ** 5. plain dir"
2256 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2258 verify_46 $dir $dir.copy "5. plain dir"
2260 ########################### 6. FLR dir ##############################
2261 echo " ** 6. FLR dir"
2262 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2263 error "6. setstripe FLR $dir failed"
2265 verify_46 $dir $dir.copy "6. FLR dir"
2267 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2268 echo "server version $MDS1_VERSION does not support SEL" &&
2271 ########################### 7. SEL file ##############################
2272 echo " ** 7. SEL file"
2274 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2275 $file || error "Create $file failed"
2278 verify_46 $file $file.copy "7. SEL file"
2280 ########################### 8. SEL dir ##############################
2281 echo " ** 8. SEL dir"
2282 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2283 $dir || error "setstripe $dir failed"
2285 verify_46 $dir $dir.copy "8. SEL dir"
2287 ########################### 9. FLR SEL file ##########################
2288 echo " ** 9. FLR SEL file"
2290 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2291 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2294 verify_46 $file $file.copy "9. SEL file"
2296 ########################### 10. FLR SEL dir #########################
2297 echo " ** 10. FLR SEL dir"
2298 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2299 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2301 verify_46 $dir $dir.copy "10. SEL dir"
2303 run_test 46 "Verify setstripe --copy option"
2306 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2308 local file=$DIR/$tdir/$tfile
2313 test_mkdir $DIR/$tdir
2317 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2318 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2319 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2320 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2321 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2323 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2324 $LFS mirror resync $file || error "resync $file failed"
2326 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2327 if [[ x$ost == "x0," ]]; then
2328 $LFS getstripe $file
2329 error "component ${ids[2]} objects allocated on $ost " \
2333 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2334 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2335 $LFS getstripe $file
2336 error "component ${ids[3]} objects allocated on $ost " \
2337 "shouldn't on OST1 or on OST2"
2342 # mirror1: [comp0] [comp1]
2343 # mirror2: [comp2] [comp3]
2344 # mirror3: [comp4] [comp5]
2345 # mirror4: [comp6] [comp7]
2346 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2347 error "create FLR $file failed"
2348 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2350 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2351 $LFS mirror resync $file || error "resync $file failed"
2353 for ((i = 0; i < 6; i++)); do
2354 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2355 awk '/l_ost_idx/{print $5}')
2357 # comp[0],comp[2],comp[4] should use different osts
2358 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2359 ${osts[2]} == ${osts[4]} ]]; then
2360 $LFS getstripe $file
2361 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2362 "allocated on duplicated OSTs"
2364 # comp[1],comp[3],comp[5] should use different osts
2365 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2366 ${osts[3]} == ${osts[5]} ]]; then
2367 $LFS getstripe $file
2368 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2369 "allocated on duplicated OSTs"
2374 run_test 47 "Verify mirror obj alloc"
2377 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2378 skip "Need MDS version at least 2.11.55"
2380 local tf=$DIR/$tfile
2383 echo " ** create 2 mirrors FLR file $tf"
2384 $LFS mirror create -N -E2M -Eeof --flags prefer \
2385 -N -E1M -Eeof $tf ||
2386 error "create FLR file $tf failed"
2389 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2390 verify_flr_state $tf "wp"
2392 local sum0=$(md5sum < $tf)
2394 echo " ** resync the file"
2395 $LFS mirror resync $tf
2397 echo " ** snapshot mirror 2"
2398 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2400 echo " ** write it again"
2401 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2402 echo " ** resync it again"
2403 $LFS mirror resync $tf
2405 verify_flr_state $tf "wp"
2406 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2408 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2409 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2411 echo " ** verify mirror 2 doesn't change"
2412 echo "original checksum: $sum0"
2413 echo "mirror 1 checksum: $sum1"
2414 echo "mirror 2 checksum: $sum2"
2415 [[ $sum0 = $sum2 ]] ||
2416 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2417 echo " ** mirror 2 stripe info"
2418 $LFS getstripe -v --mirror-index=2 $tf
2420 echo " ** resync mirror 2"
2421 $LFS mirror resync --only 2 $tf
2423 verify_flr_state $tf "ro"
2424 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2426 sum1=$($LFS mirror read -N1 $tf | md5sum)
2427 sum2=$($LFS mirror read -N2 $tf | md5sum)
2429 echo " ** verify mirror 2 resync-ed"
2430 echo "original checksum: $sum0"
2431 echo "mirror 1 checksum: $sum1"
2432 echo "mirror 2 checksum: $sum2"
2433 [[ $sum1 = $sum2 ]] ||
2434 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2435 echo " ** mirror 2 stripe info"
2436 $LFS getstripe -v --mirror-index=2 $tf
2438 run_test 48 "Verify snapshot mirror"
2447 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
2449 trap cleanup_49 EXIT RETURN
2451 local file=$DIR/$tfile
2453 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2454 error "setstripe on $file"
2456 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2457 $LFS mirror resync $file
2459 filefrag -ves $file || error "filefrag $file failed"
2460 filefrag_op=$(filefrag -ve -k $file |
2461 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2463 #Filesystem type is: bd00bd0
2464 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2465 # ext: device_logical: physical_offset: length: dev: flags:
2466 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2467 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2468 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2470 last_lun=$(echo $filefrag_op | cut -d: -f5)
2474 for line in $filefrag_op; do
2475 frag_lun=$(echo $line | cut -d: -f5)
2476 ext_len=$(echo $line | cut -d: -f4)
2477 if [[ "$frag_lun" != "$last_lun" ]]; then
2478 if (( tot_len != 1024 )); then
2480 error "$file: OST$last_lun $tot_len != 1024"
2486 (( tot_len += ext_len ))
2489 if (( num_luns != 2 || tot_len != 1024 )); then
2491 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2494 echo "FIEMAP on $file succeeded"
2496 run_test 49a "FIEMAP upon FLR file"
2498 test_50A() { # EX-2179
2501 local file=$DIR/$tdir/$tfile
2503 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2505 $LFS mirror extend -N -c1 -i1 $file ||
2506 error "extending mirror for $file failed"
2508 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2512 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2514 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2516 echo "$file layout generation from $olv to $flv"
2517 (( $flv != ($olv + 1) )) &&
2518 error "split does not increase layout gen from $olv to $flv"
2520 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2522 $LFS getstripe -v $file || error "getstripe $file failed"
2524 run_test 50A "mirror split update layout generation"
2527 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2528 skip "OST does not support SEEK_HOLE"
2530 local file=$DIR/$tdir/$tfile
2538 echo " ** create striped file $file"
2539 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2540 error "cannot create file with PFL layout"
2541 echo " ** write 1st data chunk at 1M boundary"
2542 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2543 error "cannot write data at 1M boundary"
2544 echo " ** write 2nd data chunk at 2M boundary"
2545 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2546 error "cannot write data at 2M boundary"
2547 echo " ** create hole at the file end"
2548 $TRUNCATE $file 3700000 || error "truncate fails"
2550 echo " ** verify sparseness"
2551 offset=$(lseek_test -d 1000 $file)
2552 echo " first data offset: $offset"
2553 [[ $offset == 1000 ]] &&
2554 error "src: data is not expected at offset $offset"
2555 offset=$(lseek_test -l 3500000 $file)
2556 echo " hole at the end: $offset"
2557 [[ $offset == 3500000 ]] ||
2558 error "src: hole is expected at offset $offset"
2560 echo " ** extend the file with new mirror"
2561 # migrate_copy_data() is used
2562 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2563 error "cannot create mirror"
2564 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2565 error "$file still has stale component"
2567 # check migrate_data_copy() was correct
2568 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2569 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2570 [[ $sum_1 == $sum_2 ]] ||
2571 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2573 # stale first mirror
2574 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2575 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2577 echo " ** verify mirror #2 sparseness"
2578 offset=$(lseek_test -d 1000 $file)
2579 echo " first data offset: $offset"
2580 [[ $offset == 1000 ]] &&
2581 error "dst: data is not expected at offset $offset"
2582 offset=$(lseek_test -l 3500000 $file)
2583 echo " hole at the end: $offset"
2584 [[ $offset == 3500000 ]] ||
2585 error "dst: hole is expected at offset $offset"
2587 echo " ** copy mirror #2 to mirror #1"
2588 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2589 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2590 error "$file still has stale component"
2592 # check llapi_mirror_copy_many correctness
2593 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2594 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2595 [[ $sum_1 == $sum_2 ]] ||
2596 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2598 # stale 1st component of mirror #2 before lseek call
2599 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2601 echo " ** verify mirror #1 sparseness again"
2602 offset=$(lseek_test -d 1000 $file)
2603 echo " first data offset: $offset"
2604 [[ $offset == 1000 ]] &&
2605 error "dst: data is not expected at offset $offset"
2606 offset=$(lseek_test -l 3500000 $file)
2607 echo " hole at the end: $offset"
2608 [[ $offset == 3500000 ]] ||
2609 error "dst: hole is expected at offset $offset"
2611 cancel_lru_locks osc
2613 blocks=$(stat -c%b $file)
2614 echo " ** final consumed blocks: $blocks"
2615 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2616 # that file is still sparse
2617 (( blocks < 1000 )) ||
2618 error "Mirrored file consumes $blocks blocks"
2622 run_test 50a "mirror extend/copy preserves sparseness"
2625 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2626 skip "OST does not support SEEK_HOLE"
2628 local file=$DIR/$tdir/$tfile
2636 echo " ** create mirrored file $file"
2637 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2638 -N -E2M -S1M -E eof -S2M $file ||
2639 error "cannot create mirrored file"
2640 echo " ** write data chunk at 1M boundary"
2641 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2642 error "cannot write data at 1M boundary"
2643 echo " ** create hole at the file end"
2644 $TRUNCATE $file 3700000 || error "truncate fails"
2646 echo " ** verify sparseness"
2647 offset=$(lseek_test -d 1000 $file)
2648 echo " first data offset: $offset"
2649 [[ $offset == 1000 ]] &&
2650 error "src: data is not expected at offset $offset"
2651 offset=$(lseek_test -l 3500000 $file)
2652 echo " hole at the end: $offset"
2653 [[ $offset == 3500000 ]] ||
2654 error "src: hole is expected at 3500000"
2656 echo " ** resync mirror #2 to mirror #1"
2657 $LFS mirror resync $file
2659 # check llapi_mirror_copy_many correctness
2660 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2661 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2662 [[ $sum_1 == $sum_2 ]] ||
2663 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2665 cancel_lru_locks osc
2667 blocks=$(stat -c%b $file)
2668 echo " ** consumed blocks: $blocks"
2669 # without full punch() support the first component can be not sparse
2670 # but the last one should be, so file should use far fewer blocks
2671 (( blocks < 5000 )) ||
2672 error "Mirrored file consumes $blocks blocks"
2674 # stale first component in mirror #1
2675 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2676 echo " ** truncate file down"
2678 echo " ** write data chunk at 2M boundary"
2679 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2680 error "cannot write data at 2M boundary"
2681 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2682 $LFS mirror resync $file || error "mirror rsync fails"
2683 # first component is still stale
2684 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2685 error "$file still has no stale component"
2686 echo " ** resync mirror #2 to mirror #1 again"
2687 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2688 $LFS mirror resync $file || error "mirror rsync fails"
2689 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2690 error "$file still has stale component"
2692 # check llapi_mirror_copy_many correctness
2693 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2694 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2695 [[ $sum_1 == $sum_2 ]] ||
2696 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2698 cancel_lru_locks osc
2700 blocks=$(stat -c%b $file)
2701 echo " ** final consumed blocks: $blocks"
2702 # while the first component can lose sparseness, the last one should
2703 # not, so whole file should still use far fewer blocks in total
2704 (( blocks < 3000 )) ||
2705 error "Mirrored file consumes $blocks blocks"
2708 run_test 50b "mirror rsync handles sparseness"
2711 local tf=$DIR/$tdir/$tfile
2713 test_mkdir $DIR/$tdir
2715 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
2716 verify_flr_state $tf "ro"
2718 if [[ "$FSTYPE" == "ldiskfs" ]]; then
2719 # ZFS does not support fallocate for now
2720 fallocate -p -o 1MiB -l 1MiB $tf ||
2721 error "punch hole in $tf failed"
2722 verify_flr_state $tf "wp"
2725 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
2726 $LFS mirror resync $tf || error "mirror resync $tf failed"
2727 verify_flr_state $tf "ro"
2729 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
2730 verify_flr_state $tf "wp"
2732 run_test 50c "punch_hole/mmap_write stale other mirrors"
2735 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2736 skip "OST does not support SEEK_HOLE"
2737 (( $LINUX_VERSION_CODE > $(version_code 3.0.0) )) ||
2738 skip "client kernel does not support SEEK_HOLE"
2740 local file=$DIR/$tdir/$tfile
2747 echo " ** create mirrored file $file"
2748 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2749 -N -E2M -S1M -E eof -S2M $file ||
2750 error "cannot create mirrored file"
2751 echo " ** write data chunk at 1M boundary"
2752 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2753 error "cannot write data at 1M boundary"
2754 echo " ** create hole at the file start"
2755 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
2758 if [[ $rc -eq 0 ]]; then
2759 verify_flr_state $file "wp"
2760 elif [[ ! $prt =~ "unsupported" ]]; then
2761 error "punch hole in $file failed: $prt"
2763 skip "Fallocate punch is not supported"
2766 echo " ** verify sparseness"
2767 offset=$(lseek_test -d 1000 $file)
2768 echo " first data offset: $offset"
2769 (( $offset >= 1024 * 1024 )) ||
2770 error "src: data is not expected at offset $offset"
2772 echo " ** resync mirror #2"
2773 $LFS mirror resync $file
2775 # check llapi_mirror_copy_many correctness
2776 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2777 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2778 [[ $sum_1 == $sum_2 ]] ||
2779 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2781 cancel_lru_locks osc
2783 # stale first component in mirror #1
2784 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2785 echo " ** verify sparseness of mirror #2"
2786 offset=$(lseek_test -d 1000 $file)
2787 echo " first data offset: $offset"
2788 (( $offset >= 1024 * 1024 )) ||
2789 error "src: data is not expected at offset $offset"
2791 run_test 50d "mirror rsync keep holes"
2794 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2795 skip "OST does not support SEEK_HOLE"
2797 local file=$DIR/$tdir/$tfile
2798 local old_size=2147483648 # 2GiB
2802 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
2803 $TRUNCATE $file $old_size
2805 $LFS mirror extend -N -c 1 $file
2806 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
2807 $LFS mirror resync $file
2809 new_size=$(stat --format='%s' $file)
2810 if ((new_size != old_size)); then
2811 error "new_size ($new_size) is not equal to old_size ($old_size)"
2816 run_test 60a "mirror extend sets correct size on sparse file"
2818 get_flr_layout_gen() {
2819 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
2820 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
2823 check_layout_gen() {
2826 local v1=$(get_flr_layout_gen $tf)
2827 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
2829 [[ $v1 -eq $v2 ]] ||
2830 error "$tf in-memory layout gen $v1 != $v2 after $2"
2834 local tf=$DIR/$tdir/$tfile
2836 test_mkdir $DIR/$tdir
2838 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
2840 for ((i = 0; i < 20; i++)); do
2841 $LFS mirror extend -N $tf ||
2842 error "extending mirror for $tf failed"
2843 check_layout_gen $tf "extend"
2845 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
2846 error "split $tf failed"
2847 check_layout_gen $tf "split"
2850 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
2853 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
2858 local -a old=( $2 $3 $4 )
2861 new=( $(get_times_61 $file) )
2862 ((${old[0]} == ${new[0]})) ||
2863 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
2865 ((${old[1]} == ${new[1]})) ||
2866 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
2869 test_61a() { # LU-14508
2870 local file=$DIR/$tdir/$tfile
2876 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
2877 echo "create $file-2"
2878 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
2880 echo XXX > $file || error "write $file failed"
2881 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
2883 echo "sleep $nap seconds, then cat $tfile"
2885 cat $file || error "cat $file failed"
2887 echo "sleep $nap seconds, then re-write $tfile"
2889 echo XXXX > $file || error "write $file failed"
2890 cp -p $file $file-2 || error "copy $file-2 failed"
2892 echo "sleep $nap seconds"
2895 tim=( $(get_times_61 $file) )
2897 echo "mirror merge $tfile-2 to $tfile and test timestamps"
2898 $LFS mirror extend -N -f $file-2 $file ||
2899 error "cannot mirror merge $file-2 to $file"
2900 check_times_61 $file ${tim[@]}
2902 echo "mirror extend $tfile and test timestamps"
2903 $LFS mirror extend -N -c1 -i1 $file ||
2904 error "cannot extend mirror $file"
2905 check_times_61 $file ${tim[@]}
2907 echo "migrate $tfile and test timestamps"
2908 $LFS migrate -n $file || error "cannot migrate $file"
2909 check_times_61 $file ${tim[@]}
2911 echo "normal user migrate $tfile and test timestamps"
2912 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
2913 check_times_61 $file ${tim[@]}
2915 run_test 61a "mirror extend and migrate preserve timestamps"
2917 test_61b() { # LU-14508
2918 local file=$DIR/$tdir/$tfile
2924 echo XXX > $file || error "create $file failed"
2925 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
2927 echo "sleep $nap seconds, then cat $tfile"
2929 cat $file || error "cat $file failed"
2931 echo "sleep $nap seconds, then re-write $tfile"
2933 echo XXXX > $file || error "write $file failed"
2935 echo "sleep $nap seconds, then test timestamps"
2938 tim=( $(get_times_61 $file) )
2940 echo "mirror extend $tfile and test timestamps"
2941 $LFS mirror extend -N -c1 -i1 $file ||
2942 error "cannot extend mirror $file"
2943 check_times_61 $file ${tim[@]}
2945 echo "mirror split $tfile and test timestamps"
2946 $LFS mirror split -d --mirror-id=1 $file ||
2947 error "cannot split mirror 1 off $file"
2948 check_times_61 $file ${tim[@]}
2950 echo "normal user mirror extend $tfile and test timestamps"
2951 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
2952 error "cannot extend mirror $file"
2953 check_times_61 $file ${tim[@]}
2955 run_test 61b "mirror extend and split preserve timestamps"
2957 test_61c() { # LU-14508
2958 local file=$DIR/$tdir/$tfile
2964 echo XXX > $file || error "create $file failed"
2965 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
2967 echo "sleep $nap seconds, then cat $tfile"
2969 cat $file || error "cat $file failed"
2971 echo "sleep $nap seconds, then mirror extend $tfile and write it"
2973 $LFS mirror extend -N -c1 -i1 $file ||
2974 error "cannot extend mirror $file"
2975 echo XXXX > $file || error "write $file failed"
2977 echo "sleep $nap seconds, then resync $tfile and test timestamps"
2978 tim=( $(get_times_61 $file) )
2980 $LFS mirror resync $file || error "cannot resync mirror $file"
2981 check_times_61 $file ${tim[@]}
2983 echo XXXXXX > $file || error "write $tfile failed"
2985 echo "normal user resync $tfile and test timestamps"
2986 tim=( $(get_times_61 $file) )
2987 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
2988 check_times_61 $file ${tim[@]}
2990 run_test 61c "mirror resync preserves timestamps"
2993 local tf=$DIR/$tdir/$tfile
2995 test_mkdir $DIR/$tdir
2999 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3003 echo "mirror create pid $c_pid"
3006 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3009 echo "mirror split pid $s_pid"
3011 echo "mirror create and split race for 60 seconds, should not crash"
3013 kill -9 $c_pid &> /dev/null
3014 kill -9 $s_pid &> /dev/null
3019 run_test 70 "mirror create and split race"
3021 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3022 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3027 local fsize=$(stat --printf=%s $tf)
3029 while [ -f $ctrl_file ]; do
3030 local off=$((RANDOM << 8))
3031 local len=$((RANDOM << 5 + 131072))
3033 [ $((off + len)) -gt $fsize ] && {
3034 fsize=$((off + len))
3035 echo "Extending file size to $fsize .."
3038 flock -s $lock_file -c \
3039 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3041 error "failed writing to $off:$len"; }
3042 sleep 0.$((RANDOM % 2 + 1))
3049 while [ -f $ctrl_file ]; do
3050 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3051 { rm -f $ctrl_file; error "read failed"; }
3052 sleep 0.$((RANDOM % 2 + 1))
3059 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3061 exec 200<>$lock_file
3062 while [ -f $ctrl_file ]; do
3063 local lock_taken=false
3064 local index=$((RANDOM % ${#options[@]}))
3065 local cmd="mirror_io resync ${options[$index]}"
3067 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3069 [ $((RANDOM % 4)) -eq 0 ] && {
3075 echo -n "resync file $tf with '$cmd' .."
3077 if [[ $lock_taken = "true" ]]; then
3079 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3082 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3085 sleep 0.$((RANDOM % 8 + 1))
3090 local tf=$DIR/$tfile
3091 local tf2=$DIR2/$tfile
3092 local tf3=$DIR3/$tfile
3094 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3095 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3096 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3098 $LFS mirror extend -N -f $tf-2 $tf ||
3099 error "merging $tf-2 into $tf failed"
3100 $LFS mirror extend -N -f $tf-3 $tf ||
3101 error "merging $tf-3 into $tf failed"
3103 mkdir -p $MOUNT2 && mount_client $MOUNT2
3105 mkdir -p $MOUNT3 && mount_client $MOUNT3
3107 verify_flr_state $tf3 "ro"
3109 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3110 $LCTL set_param fail_loc=0x1A03
3112 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3113 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3117 write_file_200 $tf &
3123 write_file_200 $tf2 &
3126 read_file_200 $tf2 &
3129 resync_file_200 $tf3 &
3133 [ "$SLOW" = "yes" ] && sleep_time=360
3134 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3141 echo "Waiting ${pids[@]}"
3144 umount_client $MOUNT2
3145 umount_client $MOUNT3
3149 # resync and verify mirrors
3150 $LFS mirror resync $tf || error "final resync failed"
3153 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3154 for id in ${mirror_array[@]:1}; do
3155 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3156 error "checksum error for mirror $id"
3161 run_test 200 "stress test"
3163 cleanup_test_201() {
3165 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3167 umount_client $MOUNT2
3171 local delay=${RESYNC_DELAY:-5}
3173 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3174 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3176 trap cleanup_test_201 EXIT
3178 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3179 changelog_register -n)
3181 mkdir -p $MOUNT2 && mount_client $MOUNT2
3185 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3186 [ -z "$log" ] && { sleep 1; continue; }
3188 index=$(echo $log | awk '{print $1}')
3189 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3190 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3191 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3194 [ -z "$file" ] && continue
3196 local now=$(date +%s)
3198 echo "file: $file $fid was modified at $ts, now: $now, " \
3199 "will be resynced at $((ts+delay))"
3201 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3203 $LFS mirror resync $file
3204 echo "$file resync done"
3209 run_test 201 "FLR data mover"
3212 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3214 local tf=$DIR/$tfile
3217 $LFS setstripe -E 1M -S 1M -c 1 $tf
3218 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3219 verify_comp_attr stripe-count $tf ${ids[0]} 1
3221 $LFS setstripe --component-add -E 2M -c -1 $tf
3222 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3223 verify_comp_attr stripe-count $tf ${ids[0]} 1
3224 verify_comp_attr stripe-count $tf ${ids[1]} -1
3226 dd if=/dev/zero of=$tf bs=1M count=2
3227 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3228 verify_comp_attr stripe-count $tf ${ids[0]} 1
3229 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3231 run_test 202 "lfs setstripe --add-component wide striping"
3234 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3235 skip "Need MDS version at least 2.11.55"
3236 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3238 local tf=$DIR/$tfile
3241 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3242 #delete first mirror
3243 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3246 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3247 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3248 error "getstripe count of mirror 2"
3249 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3251 #extend a mirror with 2 OSTs
3252 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3255 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3256 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3257 error "getstripe count of mirror 2"
3258 [[ x$oldid = x$newid ]] ||
3259 error "mirror 2 changed ID from $old_id to $new_id"
3260 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3262 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3263 error "getstripe count of mirror 3"
3264 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3266 run_test 203 "mirror file preserve mirror ID"
3268 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3270 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3271 skip "skipped for lustre < $SEL_VER"
3273 local comp_file=$DIR/$tdir/$tfile
3277 test_mkdir $DIR/$tdir
3279 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3280 # by extension space to -1
3281 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3282 error "Create $comp_file failed"
3284 # Write to first component, extending & staling second mirror
3285 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3286 error "dd to extend + stale failed"
3288 $LFS getstripe $comp_file
3290 flg_opts="--component-flags init,stale"
3291 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3292 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3294 flg_opts="--component-flags extension"
3295 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3296 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3298 # mirror resync should not change the extents
3299 $LFS mirror resync $comp_file
3301 flg_opts="--component-flags init"
3302 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3303 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3305 flg_opts="--component-flags extension"
3306 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3307 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3309 sel_layout_sanity $comp_file 5
3313 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3315 # Simple test of FLR + self-extending layout, SEL in primary mirror
3317 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3318 skip "skipped for lustre < $SEL_VER"
3320 local comp_file=$DIR/$tdir/$tfile
3324 test_mkdir $DIR/$tdir
3326 # first mirror is 1M followed by extension space to -1, second mirror
3327 # is 0-10M, then 10M-(-1),
3328 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3329 error "Create $comp_file failed"
3331 # Write to first component, extending first component & staling
3333 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3334 error "dd to extend + stale failed"
3336 $LFS getstripe $comp_file
3338 flg_opts="--component-flags init"
3339 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3340 [ $found -eq 1 ] || error "write: First comp end incorrect"
3342 flg_opts="--component-flags extension"
3343 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3344 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3346 flg_opts="--component-flags init,stale"
3347 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3348 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3350 # This component is staled because it overlaps the extended first
3351 # component of the primary mirror, even though it doesn't overlap
3352 # the actual write - thus not inited.
3353 flg_opts="--component-flags stale"
3354 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3355 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3357 # mirror resync should not change the extents
3358 $LFS mirror resync $comp_file
3360 $LFS getstripe $comp_file
3362 flg_opts="--component-flags init"
3363 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3364 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3366 flg_opts="--component-flags extension"
3367 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3368 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3370 flg_opts="--component-flags init"
3371 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3372 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3374 flg_opts="--component-flags init"
3375 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3376 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3378 sel_layout_sanity $comp_file 5
3382 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3384 # FLR + SEL failed extension & component removal
3385 # extension space in second mirror
3387 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3388 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3389 skip "skipped for lustre < $SEL_VER"
3391 local comp_file=$DIR/$tdir/$tfile
3394 local ost_name=$(ostname_from_index $ost_idx1)
3396 test_mkdir $DIR/$tdir
3398 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3399 # extension space from 1M to 1G, then normal space to -1
3400 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3401 -E -1 $comp_file || error "Create $comp_file failed"
3403 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3406 # write to first comp (0 - 10M) of mirror 1, extending + staling
3407 # first + second comp of mirror 2
3408 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3411 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3414 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3416 $LFS getstripe $comp_file
3418 found=$($LFS find --component-start 0m --component-end 1m \
3419 --comp-flags init,stale $comp_file | wc -l)
3420 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3422 found=$($LFS find --component-start 1m --component-end EOF \
3423 --comp-flags stale,^init $comp_file | wc -l)
3424 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3426 local mirror_id=$($LFS getstripe --component-start=1m \
3427 --component-end=EOF $comp_file | \
3428 grep lcme_mirror_id | awk '{ print $2 }')
3430 [[ $mirror_id -eq 2 ]] ||
3431 error "component not in correct mirror? $mirror_id"
3433 $LFS mirror resync $comp_file
3435 $LFS getstripe $comp_file
3437 # component dimensions should not change from resync
3438 found=$($LFS find --component-start 1m --component-end EOF \
3439 --component-flags init $comp_file | wc -l)
3440 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3442 sel_layout_sanity $comp_file 4
3446 run_test 204c "FLR write/stale/resync test with component removal"
3448 # Successful repeated component in primary mirror
3450 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3451 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3452 skip "skipped for lustre < $SEL_VER"
3454 local comp_file=$DIR/$tdir/$tfile
3457 wait_delete_completed
3459 test_mkdir $DIR/$tdir
3461 # first mirror is 64M followed by extension space to -1, second mirror
3462 # is 0-10M, then 10M-(-1)
3463 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3464 error "Create $comp_file failed"
3466 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3467 local ost_name=$(ostname_from_index $ost_idx1)
3468 # degrade OST for first comp so we won't extend there
3469 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3470 obdfilter.$ost_name.degraded=1
3473 # Write beyond first component, causing repeat & stale second mirror
3474 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3477 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3478 obdfilter.$ost_name.degraded=0
3481 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3483 $LFS getstripe $comp_file
3485 found=$($LFS find --component-start 64m --component-end 128m \
3486 --component-flags init $comp_file | wc -l)
3487 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3489 local ost_idx2=$($LFS getstripe --component-start=64m \
3490 --component-end=128m --component-flags=init \
3492 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3493 local mirror_id=$($LFS getstripe --component-start=64m \
3494 --component-end=128m --component-flags=init \
3495 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3496 [[ $mirror_id -eq 1 ]] ||
3497 error "component not in correct mirror: $mirror_id, not 1"
3499 $LFS mirror resync $comp_file
3501 $LFS getstripe $comp_file
3503 # component dimensions should not change from resync
3504 found=$($LFS find --component-start 0m --component-end 64m \
3505 --component-flags init $comp_file | wc -l)
3506 [ $found -eq 1 ] || error "resync: first comp incorrect"
3507 found=$($LFS find --component-start 64m --component-end 128m \
3508 --component-flags init $comp_file | wc -l)
3509 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3511 sel_layout_sanity $comp_file 5
3515 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3517 # Successful repeated component, SEL in non-primary mirror
3519 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3520 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3521 skip "skipped for lustre < $SEL_VER"
3523 local comp_file=$DIR/$tdir/$tfile
3526 wait_delete_completed
3529 test_mkdir $DIR/$tdir
3531 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
3532 # space to -1 (-z 64M, so first comp is 0-64M)
3533 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
3534 # will be not enough - one will be degraded, the other is used on
3535 # an overlapping mirror.
3536 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
3537 error "Create $comp_file failed"
3539 local ost_idx1=$($LFS getstripe --component-start=0 \
3540 --component-end=64m -i $comp_file)
3541 local ost_name=$(ostname_from_index $ost_idx1)
3542 # degrade OST for first comp of 2nd mirror so we won't extend there
3543 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3544 obdfilter.$ost_name.degraded=1
3547 $LFS getstripe $comp_file
3549 # Write to first component, stale & instantiate second mirror components
3550 # overlapping with the written component (0-100M);
3551 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3554 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3555 obdfilter.$ost_name.degraded=0
3557 $LFS getstripe $comp_file
3559 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3561 found=$($LFS find --component-start 0m --component-end 64m \
3562 --component-flags init,stale $comp_file | wc -l)
3563 [ $found -eq 1 ] || error "write: first comp incorrect"
3565 # was repeated due to degraded ost
3566 found=$($LFS find --component-start 64m --component-end 128m \
3567 --component-flags init,stale $comp_file | wc -l)
3568 [ $found -eq 1 ] || error "write: repeated comp incorrect"
3570 local ost_idx2=$($LFS getstripe --component-start=64m \
3571 --component-end=128m --component-flags=init \
3573 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3574 local mirror_id=$($LFS getstripe --component-start=0m \
3575 --component-end=64m --component-flags=init \
3576 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3577 [[ $mirror_id -eq 2 ]] ||
3578 error "component not in correct mirror? $mirror_id"
3580 $LFS mirror resync $comp_file
3582 $LFS getstripe $comp_file
3584 # component dimensions should not change from resync
3585 found=$($LFS find --component-start 0m --component-end 64m \
3586 --component-flags init,^stale $comp_file | wc -l)
3587 [ $found -eq 1 ] || error "resync: first comp incorrect"
3588 found=$($LFS find --component-start 64m --component-end 128m \
3589 --component-flags init,^stale $comp_file | wc -l)
3590 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
3592 sel_layout_sanity $comp_file 5
3596 run_test 204e "FLR write/stale/resync sel test with repeated comp"
3598 # FLR + SEL: failed repeated component, SEL in non-primary mirror
3600 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3601 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3602 skip "skipped for lustre < $SEL_VER"
3604 local comp_file=$DIR/$tdir/$tfile
3607 wait_delete_completed
3609 test_mkdir $DIR/$tdir
3611 pool_add $TESTNAME || error "Pool creation failed"
3612 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
3614 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
3615 # space to -1 (-z 64M, so first comp is 0-64M)
3616 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
3617 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
3619 local ost_name0=$(ostname_from_index 0)
3620 local ost_name1=$(ostname_from_index 1)
3622 # degrade both OSTs in pool, so we'll try to repeat, then fail and
3623 # extend original comp
3624 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
3625 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
3628 # a write to the 1st component, 100M length, which will try to stale
3629 # the first 100M of mirror 2, attempting to extend its 0-64M component
3630 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3633 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
3634 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
3637 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
3639 $LFS getstripe $comp_file
3641 found=$($LFS find --component-start 0m --component-end 128m \
3642 --component-flags init,stale $comp_file | wc -l)
3643 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3645 local mirror_id=$($LFS getstripe --component-start=0m \
3646 --component-end=128m --component-flags=init \
3647 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3649 [[ $mirror_id -eq 2 ]] ||
3650 error "component not in correct mirror? $mirror_id, not 2"
3652 $LFS mirror resync $comp_file
3654 $LFS getstripe $comp_file
3656 # component dimensions should not change from resync
3657 found=$($LFS find --component-start 0m --component-end 128m \
3658 --component-flags init,^stale $comp_file | wc -l)
3659 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
3661 sel_layout_sanity $comp_file 4
3665 run_test 204f "FLR write/stale/resync sel w/forced extension"
3667 function test_205() {
3668 local tf=$DIR/$tfile
3671 $LFS setstripe -c1 $tf
3672 $LFS mirror extend -N $tf
3673 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
3674 (( $mirrors == 2 )) || error "no new mirror was created?"
3676 $LFS mirror extend -N --flags=prefer $tf
3677 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
3678 (( $mirrors == 3 )) || error "no new mirror was created?"
3680 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
3681 error "prefer flag was not set on the new mirror"
3683 run_test 205 "lfs mirror extend to set prefer flag"
3685 function test_206() {
3686 # create a new OST pool
3687 local pool_name=$TESTNAME
3689 create_pool $FSNAME.$pool_name ||
3690 error "create OST pool $pool_name failed"
3691 # add OSTs into the pool
3692 pool_add_targets $pool_name 0 1 ||
3693 error "add OSTs into pool $pool_name failed"
3695 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
3696 error "can't setstripe"
3697 $LFS mirror extend -N $DIR/$tfile ||
3698 error "can't create replica"
3699 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
3700 $LFS getstripe $DIR/$tfile
3701 error "prefer found"
3703 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
3704 $LFS getstripe $DIR/$tfile
3705 error "can't setstripe prefer"
3708 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
3709 $LFS getstripe $DIR/$tfile
3710 error "no prefer found"
3716 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
3719 local file=$DIR/$tfile
3720 local tmpfile=$DIR/$tfile-tt
3722 [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
3723 skip "Need MDS version at least 2.14.50"
3725 stack_trap "rm -f $tmpfile $file"
3727 # generate data for verification
3728 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
3729 error "can't generate file with random data"
3731 # create a mirrored file with one stale replica
3732 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
3733 error "create mirrored file $file failed"
3734 get_mirror_ids $file
3735 echo "mirror IDs: ${mirror_array[@]}"
3737 dd if=$tmpfile of=$file bs=1M || error "can't copy"
3738 get_mirror_ids $file
3739 echo "mirror IDs: ${mirror_array[@]}"
3742 cmp $tmpfile $file || error "files don't match"
3743 get_mirror_ids $file
3744 echo "mirror IDs: ${mirror_array[@]}"
3746 # mirror creation should work fine
3747 $LFS mirror extend -N -S 8M -c -1 $file ||
3748 error "mirror extend $file failed"
3750 get_mirror_ids $file
3751 echo "mirror IDs: ${mirror_array[@]}"
3754 $LFS mirror verify -v $file || error "verification failed"
3755 cmp $tmpfile $file || error "files don't match"
3757 run_test 207 "create another replica with existing out-of-sync one"
3759 function check_ost_used() {
3768 cancel_lru_locks osc # to drop pages
3769 cancel_lru_locks mdc # to refresh layout
3770 # XXX: cancel_lru_locks mdc doesn't work
3771 # XXX: need a better way to reload the layout
3772 umount_client $MOUNT || error "umount failed"
3773 mount_client $MOUNT || error "mount failed"
3775 # refresh non-rotation status on MDTs
3777 touch $DIR/$tfile-temp
3778 rm -f $DIR/$tfile-temp
3779 # refresh non-rotational status on the client
3783 $LCTL set_param osc.*.stats=clear >/dev/null
3784 if [[ $io == "read" ]]; then
3785 ddarg="if=$file of=/dev/null"
3786 elif [[ $io == "write" ]]; then
3787 ddarg="if=/dev/zero of=$file"
3789 error "unknown type $io"
3791 dd $ddarg bs=2M count=1 || error "can't $io $file"
3792 cancel_lru_locks osc
3794 # check only specified OSTs got reads
3795 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
3796 local nr=$($LCTL get_param -n \
3797 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
3798 awk "/ost_$io/{print \$2}")
3800 if [[ " $* " =~ " $ost " ]]; then
3801 (( nr > 0 )) || error "expected reads on $ost"
3803 (( nr == 0 )) || error "unexpected $nr reads on $ost"
3809 local tf=$DIR/$tfile
3810 local osts=$(comma_list $(osts_nodes))
3812 (( $OSTCOUNT >= 4 )) || skip_env "needs >= 4 OSTs"
3814 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
3816 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
3817 stack_trap "restore_lustre_params < $p; rm -f $p"
3819 stack_trap "rm -f $tf"
3820 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
3821 dd if=/dev/zero of=$tf bs=2M count=1 || error "can't dd (1)"
3822 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
3823 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
3824 $LFS mirror resync $tf || error "can't resync"
3827 log "set OST0000 non-rotational"
3829 $LCTL set_param osd*.*OST0000*.nonrotational=1
3830 check_ost_used $tf read 0
3832 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
3834 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
3835 osd*.*OST0003*.nonrotational=1
3836 check_ost_used $tf read 2 3
3838 log "set mirror 1 on OST0001 preferred"
3839 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
3840 error "can't set prefer"
3841 check_ost_used $tf read 1
3843 run_test 208a "mirror selection to prefer non-rotational devices for reads"
3846 local tf=$DIR/$tfile
3847 local osts=$(comma_list $(osts_nodes))
3849 (( $OSTCOUNT >= 4 )) || skip_env "needs >= 4 OSTs"
3851 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
3853 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
3854 stack_trap "restore_lustre_params < $p; rm -f $p"
3856 stack_trap "rm -f $tf"
3857 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
3858 dd if=/dev/zero of=$tf bs=2M count=1 || error "can't dd (1)"
3859 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
3860 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
3861 $LFS mirror resync $tf || error "can't resync"
3862 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
3864 log "set OST0000 non-rotational"
3866 $LCTL set_param osd*.*OST0000*.nonrotational=1
3867 check_ost_used $tf write 0
3868 $LFS mirror resync $tf || error "can't resync"
3870 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
3872 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
3873 osd*.*OST0003*.nonrotational=1
3874 check_ost_used $tf write 2 3
3875 $LFS mirror resync $tf || error "can't resync"
3877 log "set mirror 1 on OST0001 preferred"
3878 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
3879 error "can't set prefer"
3880 check_ost_used $tf write 1
3882 run_test 208b "mirror selection to prefer non-rotational devices for writes"
3885 check_and_cleanup_lustre