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-11381
18 ALWAYS_EXCEPT+=" 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 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
37 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
38 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
40 check_and_setup_lustre
45 rm -rf $DIR/[Rdfs][0-9]*
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
381 verify_comp_attr pool $tf ${ids[1]} flash
383 # verify component ${ids[2]}
384 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
385 verify_comp_attr stripe-count $tf ${ids[2]} 2
386 verify_comp_attr pool $tf ${ids[2]} flash
388 # verify component ${ids[3]}
389 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
390 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
391 verify_comp_attr pool $tf ${ids[3]} flash
393 # verify component ${ids[4]}
394 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
395 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
396 verify_comp_attr pool $tf ${ids[4]} archive
398 # verify component ${ids[5]}
399 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
400 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
401 verify_comp_attr_with_parent pool $tf ${ids[5]}
403 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
404 # LU-11022 - remove mirror by pool name
405 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
406 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
407 $LFS mirror delete --pool archive $tf || error "delete mirror"
408 cnt=$($LFS getstripe $tf | grep archive | wc -l)
409 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
415 run_test 0b "lfs mirror create plain layout mirrors"
418 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
422 local mirror_cmd="$LFS mirror create"
426 # create a new OST pool
427 local pool_name=$TESTNAME
428 create_pool $FSNAME.$pool_name ||
429 error "create OST pool $pool_name failed"
431 # add OSTs into the pool
432 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
433 error "add OSTs into pool $pool_name failed"
435 # create parent directory
436 mkdir $td || error "mkdir $td failed"
437 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
438 error "$LFS setstripe $td failed"
440 # create a mirrored file with composite layout mirrors
441 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
443 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
444 error "create mirrored file $tf failed"
445 verify_mirror_count $tf 6
446 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
448 # verify components ${ids[0]} and ${ids[2]}
450 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
451 verify_comp_attr stripe-count $tf ${ids[$i]} 2
452 verify_comp_attr stripe-index $tf ${ids[$i]} 1
453 verify_comp_attr pool $tf ${ids[$i]} flash
454 verify_comp_extent $tf ${ids[$i]} 0 4194304
457 # verify components ${ids[1]} and ${ids[3]}
459 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
460 verify_comp_attr stripe-count $tf ${ids[$i]} 2
461 verify_comp_attr pool $tf ${ids[$i]} flash
462 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
465 # verify component ${ids[4]}
466 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
467 verify_comp_attr stripe-count $tf ${ids[4]} 4
468 verify_comp_attr_with_parent pool $tf ${ids[4]}
469 verify_comp_extent $tf ${ids[4]} 0 EOF
471 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
473 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
474 verify_comp_attr stripe-count $tf ${ids[$i]} 4
475 verify_comp_attr pool $tf ${ids[$i]} archive
476 verify_comp_extent $tf ${ids[$i]} 0 536870912
479 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
481 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
482 verify_comp_attr stripe-count $tf ${ids[$i]} -1
483 verify_comp_attr pool $tf ${ids[$i]} archive
484 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
490 run_test 0c "lfs mirror create composite layout mirrors"
495 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
496 local mirror_cmd="$LFS mirror extend"
500 # create parent directory
501 mkdir $td || error "mkdir $td failed"
503 $mirror_cmd $tf &> /dev/null && error "miss -N option"
504 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
506 # create a non-mirrored file, convert it to a mirrored file and extend
507 touch $tf || error "touch $tf failed"
508 $mirror_cmd -N $tf || error "convert and extend $tf failed"
509 verify_mirror_count $tf 2
510 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
511 for ((i = 0; i < 2; i++)); do
512 verify_comp_attrs $tf ${ids[$i]}
513 verify_comp_extent $tf ${ids[$i]} 0 EOF
516 lfsck_verify_pfid $tf || error "PFID is not set"
518 # create a mirrored file and extend it
519 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
520 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
522 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
523 error "setstripe options should not be specified with -f option"
525 $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
526 error "extend mirrored file $tf-1 failed"
527 verify_mirror_count $tf-1 $mirror_count
528 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
529 for ((i = 0; i < $mirror_count; i++)); do
530 verify_comp_attrs $tf-1 ${ids[$i]}
531 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
534 $mirror_cmd -N $tf-1 &> /dev/null &&
535 error "exceeded maximum mirror count $mirror_count" || true
537 run_test 0d "lfs mirror extend with -N option"
540 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
544 local mirror_cmd="$LFS mirror extend"
548 # create parent directory
549 mkdir $td || error "mkdir $td failed"
551 # create a mirrored file with plain layout mirrors
552 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
553 error "create mirrored file $tf failed"
555 # extend the mirrored file with plain layout mirrors
556 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
557 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
558 error "extend mirrored file $tf failed"
559 verify_mirror_count $tf 6
560 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
561 for ((i = 0; i < 6; i++)); do
562 verify_comp_extent $tf ${ids[$i]} 0 EOF
565 # verify component ${ids[0]}
566 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
567 verify_comp_attr stripe-count $tf ${ids[0]} 3
568 verify_comp_attr stripe-index $tf ${ids[0]} 1
569 verify_comp_attr pool $tf ${ids[0]} ssd
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
575 verify_comp_attr pool $tf ${ids[1]} flash
577 # verify component ${ids[2]}
578 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
579 verify_comp_attr stripe-count $tf ${ids[2]} 2
580 verify_comp_attr pool $tf ${ids[2]} flash
582 # verify component ${ids[3]}
583 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
584 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
585 verify_comp_attr pool $tf ${ids[3]} flash
587 # verify component ${ids[4]}
588 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
589 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
590 verify_comp_attr pool $tf ${ids[4]} archive
592 # verify component ${ids[5]}
593 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
594 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
595 verify_comp_attr_with_parent pool $tf ${ids[5]}
597 run_test 0e "lfs mirror extend plain layout mirrors"
600 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
604 local mirror_cmd="$LFS mirror extend"
608 # create parent directory
609 mkdir $td || error "mkdir $td failed"
611 # create a mirrored file with composite layout mirror
612 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
613 error "create mirrored file $tf failed"
615 # extend the mirrored file with composite layout mirrors
616 $mirror_cmd -N -p archive \
617 -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
619 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
620 error "extend mirrored file $tf failed"
621 verify_mirror_count $tf 8
622 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
624 # verify component ${ids[0]}
625 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
626 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
627 verify_comp_attr pool $tf ${ids[0]} ssd
628 verify_comp_extent $tf ${ids[0]} 0 33554432
630 # verify component ${ids[1]}
631 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
632 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
633 verify_comp_attr pool $tf ${ids[1]} ssd
634 verify_comp_extent $tf ${ids[1]} 33554432 EOF
636 # verify component ${ids[2]}
637 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
638 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
639 verify_comp_attr pool $tf ${ids[2]} archive
640 verify_comp_extent $tf ${ids[2]} 0 EOF
642 # verify components ${ids[3]} and ${ids[5]}
644 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
645 verify_comp_attr stripe-count $tf ${ids[$i]} 2
646 verify_comp_attr stripe-index $tf ${ids[$i]} 1
647 verify_comp_attr pool $tf ${ids[$i]} flash
648 verify_comp_extent $tf ${ids[$i]} 0 4194304
651 # verify components ${ids[4]} and ${ids[6]}
653 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
654 verify_comp_attr stripe-count $tf ${ids[$i]} 2
655 verify_comp_attr pool $tf ${ids[$i]} flash
656 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
659 # verify component ${ids[7]}
660 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
661 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
662 verify_comp_attr_with_parent pool $tf ${ids[7]}
663 verify_comp_extent $tf ${ids[7]} 0 EOF
665 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
667 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
668 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
669 verify_comp_attr pool $tf ${ids[$i]} archive
670 verify_comp_extent $tf ${ids[$i]} 0 536870912
673 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
675 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
676 verify_comp_attr stripe-count $tf ${ids[$i]} -1
677 verify_comp_attr pool $tf ${ids[$i]} archive
678 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
681 run_test 0f "lfs mirror extend composite layout mirrors"
686 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
687 -N -o1 $tf || error "create mirrored file $tf failed"
689 verify_comp_attr lcme_flags $tf 0x10001 prefer
690 verify_comp_attr lcme_flags $tf 0x10002 prefer
692 # write to the mirrored file and check primary
693 cp /etc/hosts $tf || error "error writing file '$tf'"
695 verify_comp_attr lcme_flags $tf 0x20003 stale
697 # resync file and check prefer flag
698 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
701 $LCTL set_param osc.*.stats=clear
702 cat $tf &> /dev/null || error "error reading file '$tf'"
704 # verify that the data was provided by OST1 where mirror 1 resides
705 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
706 awk '/ost_read/{print $2}')
707 [ -n "$nr_read" ] || error "read was not provided by OST1"
709 run_test 0g "lfs mirror create flags support"
712 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
713 skip "Need MDS version at least 2.11.57"
720 # create parent directory
721 test_mkdir $td || error "mkdir $td failed"
723 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
724 error "set default mirrored layout on directory $td failed"
726 # verify flags are inherited from the directory
729 verify_comp_attr lcme_flags $tf 0x10001 prefer
730 verify_comp_attr lcme_flags $tf 0x10002 prefer
732 # set flags to the first component
733 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
735 verify_comp_attr lcme_flags $tf 0x10001 stale
736 verify_comp_attr lcme_flags $tf 0x10002 prefer
738 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
739 error "clearing 'stale' should fail"
741 # write and resync file. It can't resync the file directly because the
742 # file state is still 'ro'
743 cp /etc/hosts $tf || error "error writing file '$tf'"
744 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
746 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
747 error "error setting flag prefer"
749 verify_comp_attr lcme_flags $tf 0x20003 prefer
751 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^prefer $tf ||
752 error "error clearing prefer flag from component 0x20003"
754 # MDS disallows setting stale flag on the last non-stale mirror
755 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
757 cp /etc/hosts $tf || error "error writing file '$tf'"
759 verify_comp_attr lcme_flags $tf 0x10002 prefer
760 verify_comp_attr lcme_flags $tf 0x20003 stale
761 verify_comp_attr lcme_flags $tf 0x30004 stale
763 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
765 error "setting stale flag on component 0x10002 should fail"
767 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
769 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
770 error "error setting stale flag on component 0x10001"
771 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
772 error "error setting stale flag on component 0x20003"
774 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
776 error "setting stale flag on component 0x30004 should fail"
778 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
780 run_test 0h "set, clear and test flags for FLR files"
783 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
785 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
786 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
787 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
789 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || "read mirror failed"
790 stack_trap "rm -f $TMP/$tfile"
791 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
792 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || "write failed"
793 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
794 error "set component 1 stale failed"
795 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
796 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
798 run_test 0j "test lfs mirror read/write commands"
802 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
803 local mirror_create_cmd="$LFS mirror create"
804 local stripes[0]=$OSTCOUNT
806 mirror_create_cmd+=" -N -c ${stripes[0]}"
807 for ((i = 1; i < $mirror_count; i++)); do
808 # add mirrors with different stripes to the file
809 stripes[$i]=$((RANDOM % OSTCOUNT))
810 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
812 mirror_create_cmd+=" -N -c ${stripes[$i]}"
815 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
816 verify_mirror_count $tf $mirror_count
818 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
819 $LFS mirror extend -N $tf &&
820 error "Creating the $((mirror_count+1))th mirror succeeded"
822 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
825 # verify the range of components and stripe counts
826 for ((i = 0; i < $mirror_count; i++)); do
827 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
828 verify_comp_extent $tf ${ids[$i]} 0 EOF
831 run_test 1 "create components with setstripe options"
835 local tf2=$DIR/$tfile-2
837 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
838 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
840 $LFS mirror extend -N -f $tf2 $tf ||
841 error "merging $tf2 into $tf failed"
843 verify_mirror_count $tf 2
844 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
846 run_test 2 "create components from existing files"
849 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
851 for ((i = 0; i < 2; i++)); do
852 $LFS mkdir -i $i $DIR/$tdir-$i
853 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
856 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
857 $DIR/$tdir-0/$tfile || error "creating mirrors"
859 # mdt doesn't support to cancel layout lock for remote objects, do
863 # make sure the mirrorted file was created successfully
864 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
865 { $LFS getstripe $DIR/$tdir-0/$tfile;
866 error "expected 2 components"; }
871 run_test 3 "create components from files located on different MDTs"
874 local tf=$DIR/$tdir/$tfile
877 test_mkdir $DIR/$tdir
879 # set mirror with setstripe options to directory
880 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
881 error "set mirror to directory error"
883 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
884 x"mirrored" ] || error "failed to create mirrored dir"
887 verify_mirror_count $tf 2
889 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
890 verify_comp_extent $tf ${ids[0]} 0 1048576
891 verify_comp_extent $tf ${ids[1]} 1048576 EOF
893 # sub directory should inherit mirror setting from parent
894 test_mkdir $DIR/$tdir/td
895 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
896 x"mirrored" ] || error "failed to inherit mirror from parent"
898 # mirror extend won't be applied to directory
899 $LFS mirror extend -N2 $DIR/$tdir &&
900 error "expecting mirror extend failure"
903 run_test 4 "Make sure mirror attributes can be inhertied from directory"
909 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
910 error "failed to create file with non-empty layout"
911 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
913 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
914 verify_mirror_count $tf 3
916 $CHECKSTAT -t file -s 12345 $tf ||
917 error "size error after attaching layout "
919 run_test 5 "Make sure init size work for mirrored layout"
921 # LU=10112: disable dom+flr for phase 1
925 $LFS mirror create -N -E 1M -S 1M -L mdt -E eof -N -E eof $tf &&
926 error "expect failure to create mirrored file with DoM"
928 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf &&
929 error "expect failure to create mirrored file with DoM"
931 $LFS setstripe -E 1M -S 1M -L mdt -E eof $tf
932 $LFS mirror extend -N2 $tf &&
933 error "expect failure to extend mirror with DoM"
935 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2
936 $LFS mirror extend -N -f $tf $tf-2 &&
937 error "expect failure to extend mirrored file with DoM extent"
941 run_test 6 "DoM and FLR won't co-exist for phase 1"
945 local tf2=$DIR/$tfile-2
947 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
949 $LFS setstripe -E EOF -o 0 $tf
950 $LFS setstripe -E EOF -o 1 $tf2
952 local dd_count=$((RANDOM % 20 + 1))
953 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
954 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
956 # for zfs - sync OST dataset so that du below will return
958 [ "$FSTYPE" = "zfs" ] &&
959 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
961 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
964 $LFS mirror extend -N -f $tf2 $tf ||
965 error "merging $tf2 into $tf failed"
970 local new_blocks=$(du -k $tf | awk '{print $1}')
971 [ $new_blocks -eq $blocks ] ||
972 error "i_blocks error expected: $blocks, actual: $new_blocks"
974 run_test 21 "glimpse should report accurate i_blocks"
976 get_osc_lock_count() {
983 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
984 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
985 lock_count=$((lock_count + count))
993 $LFS setstripe -E EOF -o 0 $tf
994 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
996 # add component, two mirrors located on the same OST ;-)
997 $LFS mirror extend -N -o 0 $tf ||
998 error "extending mirrored file $tf failed"
1000 size_blocks=$(stat --format="%b %s" $tf)
1002 cancel_lru_locks mdc
1003 cancel_lru_locks osc
1005 local new_size_blocks=$(stat --format="%b %s" $tf)
1007 # make sure there is no lock cached
1008 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1010 [ "$new_size_blocks" = "$size_blocks" ] ||
1011 echo "size expected: $size_blocks, actual: $new_size_blocks"
1015 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1018 local tf=$DIR/$tfile
1020 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1021 error "creating mirrored file $tf failed"
1023 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
1024 $LCTL set_param fail_loc=0x1A00
1027 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1028 cancel_lru_locks osc
1031 local tmpfile=$(mktemp)
1032 stat --format="%b %s" $tf > $tmpfile &
1036 while [ $cnt -le 5 ]; do
1037 kill -0 $pid > /dev/null 2>&1 || break
1041 kill -0 $pid > /dev/null 2>&1 &&
1042 error "stat process stuck due to unavailable OSTs"
1044 # make sure glimpse request has been sent
1045 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1046 error "OST $ost_idx: no glimpse request was sent"
1051 run_test 31 "make sure glimpse request can be retried"
1054 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1055 rm -f $DIR/$tfile $DIR/$tfile-2
1057 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1058 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1060 local fsize=$(stat -c %s $DIR/$tfile)
1061 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1063 local cksum=$(md5sum $DIR/$tfile)
1065 # create a new mirror in sync mode
1066 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1067 error "extending mirrored file $DIR/$tfile failed"
1069 # make sure the mirrored file was created successfully
1070 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1071 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1076 # check size is correct, glimpse request should go to the 2nd mirror
1077 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1078 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1080 echo "reading file from the 2nd mirror and verify checksum"
1081 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1082 error "checksum error: expected $cksum"
1086 run_test 32 "data should be mirrored to newly created mirror"
1089 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1091 rm -f $DIR/$tfile $DIR/$tfile-2
1093 # create a file with two mirrors
1094 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1097 while [ $count -lt $max_count ]; do
1098 echo "ost1" >> $DIR/$tfile
1099 count=$((count + 1));
1102 # tmp file that will be used as mirror
1103 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1105 while [ $count -lt $max_count ]; do
1106 echo "ost2" >> $DIR/$tfile-2
1107 count=$((count + 1));
1110 # create a mirrored file
1111 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1112 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1113 "with verification should fail"
1114 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1115 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1116 "without verification failed"
1118 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1119 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1120 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1122 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1124 # execpted file size
1125 local fsize=$((5 * max_count))
1126 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1127 error "mirrored file size is not $fsize"
1129 # read file - all OSTs are available
1130 echo "reading file (data can be provided by any ost)... "
1131 local rs=$(cat $DIR/$tfile | head -1)
1132 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1133 error "file content error: expected: \"ost1\" or \"ost2\""
1135 # read file again with ost1 failed
1139 echo "reading file (data should be provided by ost2)..."
1140 local rs=$(cat $DIR/$tfile | head -1)
1141 [[ "$rs" == "ost2" ]] ||
1142 error "file content error: expected: \"ost2\", actual: \"$rs\""
1147 # read file again with ost2 failed
1151 # check size, glimpse should work
1152 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1153 error "mirrored file size is not $fsize"
1155 echo "reading file (data should be provided by ost1)..."
1156 local rs=$(cat $DIR/$tfile | head -1)
1157 [[ "$rs" == "ost1" ]] ||
1158 error "file content error: expected: \"ost1\", actual: \"$rs\""
1162 run_test 33a "read can choose available mirror to read"
1165 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1169 stack_trap "rm -f $DIR/$tfile" EXIT
1171 # create a file with two mirrors on OST0000 and OST0001
1172 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1174 # make sure that $tfile has two mirrors
1175 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1176 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1179 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1180 error "write failed for $DIR/$tfile"
1181 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1182 verify_flr_state $DIR/$tfile "ro"
1187 # read file - all OSTs are available
1188 echo "reading file (data can be provided by any ost)... "
1190 time cat $DIR/$tfile > /dev/null || error "read all"
1194 # read file again with ost1 {OST0000} failed
1197 echo "reading file (data should be provided by ost2)..."
1199 time cat $DIR/$tfile > /dev/null || error "read ost2"
1206 # read file again with ost2 {OST0001} failed
1210 echo "reading file (data should be provided by ost1)..."
1212 time cat $DIR/$tfile > /dev/null || error "read ost1"
1219 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1220 error "read mirror too slow without ost1, from $ra to $r1"
1221 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1222 error "read mirror too slow without ost2, from $ra to $r2"
1224 wait_osc_import_ready client ost2
1226 run_test 33b "avoid reading from unhealthy mirror"
1229 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1233 stack_trap "rm -f $DIR/$tfile" EXIT
1235 # create a file with two mirrors
1236 # mirror1: {OST0000, OST0001}
1237 # mirror2: {OST0001, OST0002}
1238 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1240 # make sure that $tfile has two mirrors
1241 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1242 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1245 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1246 error "write failed for $DIR/$tfile"
1247 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1248 verify_flr_state $DIR/$tfile "ro"
1253 # read file - all OSTs are available
1254 echo "reading file (data can be provided by any ost)... "
1255 time cat $DIR/$tfile > /dev/null || error "read all"
1257 # read file again with ost2 (OST0001) failed
1261 echo "reading file (data should be provided by ost1 and ost3)..."
1262 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1267 wait_osc_import_ready client ost2
1269 run_test 33c "keep reading among unhealthy mirrors"
1272 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1274 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1277 $LFS setstripe -o 0 $DIR/$tfile-ref
1278 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1280 # create a file with two mirrors
1281 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1282 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1284 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1285 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1287 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1288 error "mirrored file size is not 3M"
1290 # merge a mirrored file
1291 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1292 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1294 cancel_lru_locks osc
1296 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1297 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1300 echo "comparing files ... "
1302 # however, read can still return the correct data. It should return
1303 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1304 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1305 $DIR/$tfile-ref || error "file reading error"
1309 run_test 34a "read mirrored file with multiple stripes"
1312 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1314 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1317 $LFS setstripe -o 0 $DIR/$tfile-ref
1318 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1320 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1321 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1323 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1324 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1326 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1327 error "mirrored file size is not 3M"
1329 # merge a mirrored file
1330 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1331 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1333 cancel_lru_locks osc
1335 # stop two OSTs, so the 2nd component of the 1st mirror and
1336 # the 1st component of the 2nd mirror will be inaccessible, ...
1339 echo "comparing files ... "
1341 # however, read can still return the correct data. It should return
1342 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1343 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1344 $DIR/$tfile-ref || error "file reading error"
1348 run_test 34b "read mirrored file with multiple components"
1351 local tf=$DIR/$tfile
1353 $LFS setstripe -E eof $tf
1355 # add an out-of-sync mirror to the file
1356 $LFS mirror extend -N -c 2 $tf ||
1357 error "extending mirrored file $tf failed"
1359 $MULTIOP $tf oO_WRONLY:c ||
1360 error "write open a mirrored file failed"
1362 # truncate file should return error
1363 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1365 run_test 35 "allow to write to mirrored files"
1367 verify_ost_layout_version() {
1370 # get file layout version
1371 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1373 # layout version from OST objects
1374 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1376 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1383 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1384 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1386 $LFS mirror extend -N -f $tf-tmp $tf ||
1387 error "merging $tf-tmp into $tf failed"
1392 local tf=$DIR/$tfile
1394 create_file_36 $tf $tf-2 $tf-3
1396 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1398 # test case 1 - check file write and verify layout version
1399 $MULTIOP $tf oO_WRONLY:c ||
1400 error "write open a mirrored file failed"
1402 # write open file should not return error
1403 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1405 # instantiate components should work
1406 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1408 # verify OST layout version
1409 verify_ost_layout_version $tf
1412 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1415 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1417 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1418 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1420 # write should take at least $fail_loc seconds and succeed
1421 local st=$(date +%s)
1422 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1424 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1425 error "write finished before layout version is transmitted"
1427 # verify OST layout version
1428 verify_ost_layout_version $tf
1430 do_facet $mds_facet $LCTL set_param fail_loc=0
1433 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1435 #define OBD_FAIL_FLR_LV_INC 0x1A02
1436 do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1438 # write open file should return error
1439 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1440 error "write a mirrored file succeeded" || true
1442 do_facet $mds_facet $LCTL set_param fail_loc=0
1444 run_test 36 "write to mirrored files"
1450 echo "create test files with size $fsize .."
1454 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1456 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1457 $TRUNCATE $tf $fsize
1463 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1464 skip "Need MDS version at least 2.11.57"
1466 local tf=$DIR/$tfile
1467 local tf2=$DIR/$tfile-2
1468 local tf3=$DIR/$tfile-3
1469 local tf4=$DIR/$tfile-4
1471 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1475 # assume the mirror id will be 1, 2, and 3
1476 declare -A checksums
1477 checksums[1]=$(cat $tf | md5sum)
1478 checksums[2]=$(cat $tf2 | md5sum)
1479 checksums[3]=$(cat $tf3 | md5sum)
1481 printf '%s\n' "${checksums[@]}"
1483 # merge these files into a mirrored file
1484 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1485 error "merging $tf2 into $tf failed"
1486 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1487 error "merging $tf3 into $tf failed"
1491 # verify mirror read, checksums should equal to the original files'
1492 echo "Verifying mirror read .."
1495 for i in ${mirror_array[@]}; do
1496 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1497 sum=$($LFS mirror read -N $i $tf | md5sum)
1498 [ "$sum" = "${checksums[$i]}" ] ||
1499 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1502 # verify mirror write
1503 echo "Verifying mirror write .."
1504 $LFS mirror write -N2 $tf < $tf4
1506 sum=$($LFS mirror read -N2 $tf | md5sum)
1507 [[ "$sum" = "${checksums[1]}" ]] ||
1508 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1510 # verify mirror copy, write to this mirrored file will invalidate
1511 # the other two mirrors
1512 echo "Verifying mirror copy .."
1514 local osts=$(comma_list $(osts_nodes))
1516 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1517 error "mirror copy error"
1519 # verify copying is successful by checking checksums
1520 remount_client $MOUNT
1521 for i in ${mirror_array[@]}; do
1522 sum=$($LFS mirror read -N $i $tf | md5sum)
1523 [ "$sum" = "${checksums[1]}" ] ||
1524 error "$i: mismatch checksum after copy \'$sum\'"
1529 run_test 37 "mirror I/O API verification"
1532 local tf=$DIR/$tfile
1533 local ref=$DIR/${tfile}-ref
1535 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1536 error "creating $tf failed"
1537 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1538 $tf-2 || error "creating $tf-2 failed"
1539 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1540 error "creating $tf-3 failed"
1542 # instantiate all components
1543 $LFS mirror extend -N -f $tf-2 $tf ||
1544 error "merging $tf-2 into $tf failed"
1545 $LFS mirror extend -N -f $tf-3 $tf ||
1546 error "merging $tf-3 into $tf failed"
1547 $LFS mirror extend -N -c 1 $tf ||
1548 error "extending mirrored file $tf failed"
1550 verify_flr_state $tf "ro"
1552 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1554 local fsize=$((RANDOM << 8 + 1048576))
1555 $TRUNCATE $ref $fsize
1557 local ref_cksum=$(cat $ref | md5sum)
1559 # case 1: verify write to mirrored file & resync work
1560 cp $ref $tf || error "copy from $ref to $f error"
1561 verify_flr_state $tf "wp"
1563 local file_cksum=$(cat $tf | md5sum)
1564 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1567 echo "mirror IDs: ${mirror_array[@]}"
1569 local valid_mirror stale_mirror id mirror_cksum
1570 for id in "${mirror_array[@]}"; do
1571 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1572 [ "$ref_cksum" == "$mirror_cksum" ] &&
1573 { valid_mirror=$id; continue; }
1578 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1579 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1581 mirror_io resync $tf || error "resync failed"
1582 verify_flr_state $tf "ro"
1584 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1585 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1587 # case 2: inject an error to make mirror_io exit after changing
1588 # the file state to sync_pending so that we can start a concurrent
1590 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1591 verify_flr_state $tf "wp"
1593 mirror_io resync -e resync_start $tf && error "resync succeeded"
1594 verify_flr_state $tf "sp"
1596 # from sync_pending to write_pending
1597 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1598 verify_flr_state $tf "wp"
1600 mirror_io resync -e resync_start $tf && error "resync succeeded"
1601 verify_flr_state $tf "sp"
1603 # from sync_pending to read_only
1604 mirror_io resync $tf || error "resync failed"
1605 verify_flr_state $tf "ro"
1607 run_test 38 "resync"
1610 local tf=$DIR/$tfile
1613 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1614 error "create PFL file $tf failed"
1616 verify_mirror_count $tf 2
1617 verify_comp_count $tf 4
1619 rm -f $tf || error "delete $tf failed"
1621 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1624 local tf=$DIR/$tfile
1627 for ops in "conv=notrunc" ""; do
1630 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1631 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1632 error "create PFLR file $tf failed"
1633 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1634 error "write PFLR file $tf failed"
1636 lfs getstripe -vy $tf
1640 # file mirror state should be write_pending
1641 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1643 error "file mirror state $flags"
1644 # the 1st component (in mirror 1) should be inited
1645 verify_comp_attr lcme_flags $tf 0x10001 init
1646 # the 2nd component (in mirror 1) should be inited
1647 verify_comp_attr lcme_flags $tf 0x10002 init
1648 # the 3rd component (in mirror 1) should be uninited
1649 verify_comp_attr lcme_flags $tf 0x10003 prefer
1650 # the 4th component (in mirror 2) should be inited
1651 verify_comp_attr lcme_flags $tf 0x20004 init
1652 # the 5th component (in mirror 2) should be uninited
1653 verify_comp_attr lcme_flags $tf 0x20005 0
1654 # the 6th component (in mirror 2) should be stale
1655 verify_comp_attr lcme_flags $tf 0x20006 stale
1656 # the 7th component (in mirror 2) should be uninited
1657 if [[ x$ops = "xconv=notrunc" ]]; then
1658 verify_comp_attr lcme_flags $tf 0x20007 0
1659 elif [[ x$ops = "x" ]]; then
1660 verify_comp_attr lcme_flags $tf 0x20007 stale
1664 rm -f $tf || error "delete $tf failed"
1666 run_test 40 "PFLR rdonly state instantiation check"
1669 local tf=$DIR/$tfile
1672 echo " **create two FLR files $tf $tf-1"
1673 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1674 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1675 error "create PFLR file $tf failed"
1676 $LFS mirror create -N -E 2M -S 1M -E eof \
1677 -N -E 1M -E eof --flags prefer \
1678 -N -E 4m -E eof $tf-1 ||
1679 error "create PFLR file $tf-1 failed"
1681 # file should be in ro status
1682 echo " **verify files be RDONLY"
1683 verify_flr_state $tf "ro"
1684 verify_flr_state $tf-1 "ro"
1686 # write data in [0, 2M)
1687 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1688 error "writing $tf failed"
1689 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1690 error "writing $tf-1 failed"
1692 local sum0=$(cat $tf-1 | md5sum)
1694 echo " **verify files be WRITE_PENDING"
1695 verify_flr_state $tf "wp"
1696 verify_flr_state $tf-1 "wp"
1698 # file should have stale component
1699 echo " **verify files have stale component"
1700 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1701 error "after writing $tf, it does not contain stale component"
1702 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1703 error "after writing $tf-1, it does not contain stale component"
1705 echo " **full resync"
1706 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1708 echo " **verify $tf-1 data consistency in all mirrors"
1710 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1711 [[ "$sum" = "$sum0" ]] ||
1712 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1715 echo " **verify files be RDONLY"
1716 verify_flr_state $tf "ro"
1717 verify_flr_state $tf-1 "ro"
1719 # file should not have stale component
1720 echo " **verify files do not contain stale component"
1721 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1722 error "after resyncing $tf, it contains stale component"
1723 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1724 error "after resyncing $tf, it contains stale component"
1726 # verify partial resync
1727 echo " **write $tf-1 for partial resync test"
1728 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1729 error "writing $tf-1 failed"
1731 echo " **only resync mirror 2"
1732 verify_flr_state $tf-1 "wp"
1733 $LFS mirror resync --only 2 $tf-1 ||
1734 error "resync mirror 2 of $tf-1 failed"
1735 verify_flr_state $tf "ro"
1737 # resync synced mirror
1738 echo " **resync mirror 2 again"
1739 $LFS mirror resync --only 2 $tf-1 ||
1740 error "resync mirror 2 of $tf-1 failed"
1741 verify_flr_state $tf "ro"
1742 echo " **verify $tf-1 contains stale component"
1743 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1744 error "after writing $tf-1, it does not contain stale component"
1746 echo " **full resync $tf-1"
1747 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1748 verify_flr_state $tf "ro"
1749 echo " **full resync $tf-1 again"
1750 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1751 echo " **verify $tf-1 does not contain stale component"
1752 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1753 error "after resyncing $tf, it contains stale component"
1757 run_test 41 "lfs mirror resync check"
1760 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1764 local mirror_cmd="$LFS mirror verify"
1767 # create parent directory
1768 mkdir $td || error "mkdir $td failed"
1770 $mirror_cmd &> /dev/null && error "no file name given"
1771 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1772 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1774 # create mirrored files
1775 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1776 error "create mirrored file $tf failed"
1777 $LFS mirror create -N -E 2M -S 1M -E EOF \
1778 -N -E 6M -E 8M -E EOF \
1779 -N -E 16M -E EOF $tf-1 ||
1780 error "create mirrored file $tf-1 failed"
1781 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1782 error "create mirrored file $tf-2 failed"
1784 # write data in [0, 10M)
1785 for i in $tf $tf-1 $tf-2; do
1786 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1787 error "write $i failed"
1790 # resync the mirrored files
1791 $LFS mirror resync $tf-1 $tf-2 ||
1792 error "resync $tf-1 $tf-2 failed"
1794 # verify the mirrored files
1795 $mirror_cmd $tf-1 $tf-2 ||
1796 error "verify $tf-1 $tf-2 failed"
1798 get_mirror_ids $tf-1
1799 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1800 error "at least 2 mirror ids needed with '--only' option"
1801 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1803 error "'--only' option cannot be used upon multiple files"
1804 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1805 error "invalid specified mirror ids"
1807 # change the content of $tf and merge it into $tf-1
1809 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1810 error "change $tf with seek=$i failed"
1811 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1812 error "change $tf-1 with seek=$i failed"
1815 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1816 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1817 error "merge $tf into $tf-1 failed"
1819 # verify the mirrored files
1820 echo "Verify $tf-1 without -v option:"
1821 $mirror_cmd $tf-1 &&
1822 error "verify $tf-1 should fail" || echo "PASS"
1824 echo "Verify $tf-1 with -v option:"
1825 $mirror_cmd -v $tf-1 &&
1826 error "verify $tf-1 should fail"
1828 get_mirror_ids $tf-1
1829 echo "Verify $tf-1 with --only option:"
1830 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1831 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1832 "${mirror_array[-1]} should fail"
1834 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1835 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1836 "${mirror_array[1]} should succeed"
1838 # set stale components in $tf-1
1839 for i in 0x40002 0x40003; do
1840 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1841 error "set stale flag on component $i failed"
1844 # verify the mirrored file
1845 echo "Verify $tf-1 with stale components:"
1846 $mirror_cmd -vvv $tf-1 ||
1847 error "verify $tf-1 with stale components should succeed"
1849 echo "Verify $tf-1 with stale components and --only option:"
1850 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1851 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1852 "${mirror_array[-1]} should succeed"
1854 run_test 42 "lfs mirror verify"
1856 # inactivate one OST && write && restore the OST
1860 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1863 wait=$(do_facet $SINGLEMDS \
1864 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1865 wait=${wait%%[^0-9]*}
1867 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1868 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1869 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1870 sleep $(($wait * 2 + 2))
1871 echo " **write $file"
1872 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1873 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1874 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1875 sleep $((wait * 2 + 2))
1877 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1878 [ $flags = wp ] || error "file mirror state $flags != wp"
1882 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1884 local tf=$DIR/$tfile
1888 ## mirror 0 ost (0, 1)
1889 ## mirror 1 ost (1, 2)
1890 ## mirror 2 ost (2, 0)
1891 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1892 -N -Eeof -c2 -o2,0 $tf ||
1893 error "create 3 mirrors file $tf failed"
1895 ################## OST0 ###########################################
1897 echo " **verify components"
1898 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1899 verify_comp_attr lcme_flags $tf 0x20002 init
1900 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1903 echo " **resync $tf"
1904 $LFS mirror resync $tf
1905 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1906 [ $flags = ro ] || error "file mirror state $flags != ro"
1908 ################## OST1 ###########################################
1910 echo " **verify components"
1911 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1912 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1913 verify_comp_attr lcme_flags $tf 0x30003 init
1916 echo " **resync $tf"
1917 $LFS mirror resync $tf
1918 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1919 [ $flags = ro ] || error "file mirror state $flags != ro"
1921 ################## OST2 ###########################################
1923 echo " **verify components"
1924 verify_comp_attr lcme_flags $tf 0x10001 init
1925 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1926 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1928 run_test 43 "mirror pick on write"
1931 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1934 local tf=$DIR/$tdir/$tfile
1935 local tf1=$DIR/$tdir-1/$tfile-1
1937 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1938 error "create directory failed"
1939 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1940 error "create remote directory failed"
1941 rm -f $tf $tf1 $tf.mirror~2
1942 # create file with 4 mirrors
1943 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1944 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
1945 error "create PFLR file $tf failed"
1947 # file should be in ro status
1948 verify_flr_state $tf "ro"
1950 # write data in [0, 3M)
1951 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1952 error "writing $tf failed"
1954 verify_flr_state $tf "wp"
1956 # disallow destroying the last non-stale mirror
1957 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
1958 error "destroying mirror 1 should fail"
1960 # synchronize all mirrors of the file
1961 $LFS mirror resync $tf || error "mirror resync $tf failed"
1963 verify_flr_state $tf "ro"
1966 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1967 error "split to $tf1 failed"
1969 local idx0=$($LFS getstripe -m $tf)
1970 local idx1=$($LFS getstripe -m $tf1)
1972 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1973 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1975 # verify mirror count
1976 verify_mirror_count $tf 3
1977 verify_mirror_count $tf1 1
1979 $LFS mirror split --mirror-id 2 $tf ||
1980 error "split mirror 2 failed"
1982 verify_mirror_count $tf 2
1983 verify_mirror_count $tf.mirror~2 1
1985 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
1986 error "setting stale flag on component 0x30008 failed"
1988 # disallow destroying the last non-stale mirror
1989 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
1990 error "destroying mirror 4 should fail"
1992 $LFS mirror resync $tf || error "resynchronizing $tf failed"
1994 $LFS mirror split --mirror-id 3 -d $tf ||
1995 error "destroying mirror 3 failed"
1996 verify_mirror_count $tf 1
1998 # verify splitted file contains the same content as the orig file does
1999 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2000 diff $tf $tf.mirror~2 ||
2001 error "splited file $tf.mirror~2 diffs from $tf"
2003 run_test 44 "lfs mirror split check"
2006 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2008 local file=$DIR/$tdir/$tfile
2009 local dir=$DIR/$tdir/$dir
2010 local temp=$DIR/$tdir/template
2012 test_mkdir $DIR/$tdir
2014 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2015 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2016 error "Create $file failed"
2018 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2019 rm -f $file $file.copy
2021 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2022 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2023 error "Create $file failed"
2025 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2027 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2034 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2036 local layout1=$(get_layout_param $src)
2037 local layout2=$(get_layout_param $dst)
2038 # compare their layout info
2039 [ "$layout1" == "$layout2" ] ||
2040 error "$msg_prefix $src <=> $dst layouts are not equal"
2044 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2046 local file=$DIR/$tdir/$tfile
2047 test_mkdir $DIR/$tdir
2049 ########################### 1. PFL file #############################
2050 echo " ** 1. PFL file"
2052 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2053 $file || error "1. Create PFL $file failed"
2056 verify_46 $file $file.copy "1. PFL file"
2058 ########################### 2. plain file ###########################
2059 echo " ** 2. plain file"
2061 $LFS setstripe -c2 -o0,1 -i1 $file ||
2062 error "2. Create plain $file failed"
2065 verify_46 $file $file.copy "2. plain file"
2067 ########################### 3. FLR file #############################
2068 echo " ** 3. FLR file"
2070 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2071 $file || error "3. Create FLR $file failed"
2074 verify_46 $file $file.copy "3. FLR file"
2076 local dir=$DIR/$tdir/dir
2077 ########################### 4. PFL dir ##############################
2078 echo " ** 4. PFL dir"
2080 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2081 error "4. setstripe PFL $dir failed"
2083 test_mkdir $dir.copy
2084 verify_46 $dir $dir.copy "4. PFL dir"
2086 ########################### 5. plain dir ############################
2087 echo " ** 5. plain dir"
2088 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2090 verify_46 $dir $dir.copy "5. plain dir"
2092 ########################### 6. FLR dir ##############################
2093 echo " ** 6. FLR dir"
2094 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2095 error "6. setstripe FLR $dir failed"
2097 verify_46 $dir $dir.copy "6. FLR dir"
2099 ########################### 7. SEL file ##############################
2100 echo " ** 7. SEL file"
2102 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2103 $file || error "Create $file failed"
2106 verify_46 $file $file.copy "7. SEL file"
2108 ########################### 8. SEL dir ##############################
2109 echo " ** 8. SEL dir"
2110 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2111 $dir || error "setstripe $dir failed"
2113 verify_46 $dir $dir.copy "8. SEL dir"
2115 ########################### 9. FLR SEL file ##########################
2116 echo " ** 9. FLR SEL file"
2118 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2119 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2122 verify_46 $file $file.copy "9. SEL file"
2124 ########################### 10. FLR SEL dir #########################
2125 echo " ** 10. FLR SEL dir"
2126 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2127 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2129 verify_46 $dir $dir.copy "10. SEL dir"
2131 run_test 46 "Verify setstripe --copy option"
2134 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2136 local file=$DIR/$tdir/$tfile
2141 test_mkdir $DIR/$tdir
2145 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2146 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2147 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2148 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2149 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2151 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2152 $LFS mirror resync $file || error "resync $file failed"
2154 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2155 if [[ x$ost == "x0," ]]; then
2156 $LFS getstripe $file
2157 error "component ${ids[2]} objects allocated on $ost " \
2161 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2162 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2163 $LFS getstripe $file
2164 error "component ${ids[3]} objects allocated on $ost " \
2165 "shouldn't on OST1 or on OST2"
2170 # mirror1: [comp0] [comp1]
2171 # mirror2: [comp2] [comp3]
2172 # mirror3: [comp4] [comp5]
2173 # mirror4: [comp6] [comp7]
2174 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2175 error "create FLR $file failed"
2176 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2178 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2179 $LFS mirror resync $file || error "resync $file failed"
2181 for ((i = 0; i < 6; i++)); do
2182 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2183 awk '/l_ost_idx/{print $5}')
2185 # comp[0],comp[2],comp[4] should use different osts
2186 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2187 ${osts[2]} == ${osts[4]} ]]; then
2188 $LFS getstripe $file
2189 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2190 "allocated on duplicated OSTs"
2192 # comp[1],comp[3],comp[5] should use different osts
2193 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2194 ${osts[3]} == ${osts[5]} ]]; then
2195 $LFS getstripe $file
2196 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2197 "allocated on duplicated OSTs"
2202 run_test 47 "Verify mirror obj alloc"
2205 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2206 skip "Need MDS version at least 2.11.55"
2208 local tf=$DIR/$tfile
2211 echo " ** create 2 mirrors FLR file $tf"
2212 $LFS mirror create -N -E2M -Eeof --flags prefer \
2213 -N -E1M -Eeof $tf ||
2214 error "create FLR file $tf failed"
2217 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2218 verify_flr_state $tf "wp"
2220 local sum0=$(md5sum < $tf)
2222 echo " ** resync the file"
2223 $LFS mirror resync $tf
2225 echo " ** snapshot mirror 2"
2226 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2228 echo " ** write it again"
2229 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2230 echo " ** resync it again"
2231 $LFS mirror resync $tf
2233 verify_flr_state $tf "wp"
2234 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2236 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2237 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2239 echo " ** verify mirror 2 doesn't change"
2240 echo "original checksum: $sum0"
2241 echo "mirror 1 checksum: $sum1"
2242 echo "mirror 2 checksum: $sum2"
2243 [[ $sum0 = $sum2 ]] ||
2244 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2245 echo " ** mirror 2 stripe info"
2246 $LFS getstripe -v --mirror-index=2 $tf
2248 echo " ** resync mirror 2"
2249 $LFS mirror resync --only 2 $tf
2251 verify_flr_state $tf "ro"
2252 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2254 sum1=$($LFS mirror read -N1 $tf | md5sum)
2255 sum2=$($LFS mirror read -N2 $tf | md5sum)
2257 echo " ** verify mirror 2 resync-ed"
2258 echo "original checksum: $sum0"
2259 echo "mirror 1 checksum: $sum1"
2260 echo "mirror 2 checksum: $sum2"
2261 [[ $sum1 = $sum2 ]] ||
2262 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2263 echo " ** mirror 2 stripe info"
2264 $LFS getstripe -v --mirror-index=2 $tf
2266 run_test 48 "Verify snapshot mirror"
2275 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
2277 trap cleanup_49 EXIT RETURN
2279 local file=$DIR/$tfile
2281 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2282 error "setstripe on $file"
2284 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2285 $LFS mirror resync $file
2287 filefrag -ves $file || error "filefrag $file failed"
2288 filefrag_op=$(filefrag -ve -k $file |
2289 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2291 #Filesystem type is: bd00bd0
2292 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2293 # ext: device_logical: physical_offset: length: dev: flags:
2294 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2295 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2296 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2298 last_lun=$(echo $filefrag_op | cut -d: -f5)
2302 for line in $filefrag_op; do
2303 frag_lun=$(echo $line | cut -d: -f5)
2304 ext_len=$(echo $line | cut -d: -f4)
2305 if [[ "$frag_lun" != "$last_lun" ]]; then
2306 if (( tot_len != 1024 )); then
2308 error "$file: OST$last_lun $tot_len != 1024"
2314 (( tot_len += ext_len ))
2317 if (( num_luns != 2 || tot_len != 1024 )); then
2319 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2322 echo "FIEMAP on $file succeeded"
2324 run_test 49a "FIEMAP upon FLR file"
2326 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
2327 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
2332 local fsize=$(stat --printf=%s $tf)
2334 while [ -f $ctrl_file ]; do
2335 local off=$((RANDOM << 8))
2336 local len=$((RANDOM << 5 + 131072))
2338 [ $((off + len)) -gt $fsize ] && {
2339 fsize=$((off + len))
2340 echo "Extending file size to $fsize .."
2343 flock -s $lock_file -c \
2344 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
2346 error "failed writing to $off:$len"; }
2347 sleep 0.$((RANDOM % 2 + 1))
2354 while [ -f $ctrl_file ]; do
2355 flock -s $lock_file -c "cat $tf &> /dev/null" ||
2356 { rm -f $ctrl_file; error "read failed"; }
2357 sleep 0.$((RANDOM % 2 + 1))
2364 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
2366 exec 200<>$lock_file
2367 while [ -f $ctrl_file ]; do
2368 local lock_taken=false
2369 local index=$((RANDOM % ${#options[@]}))
2370 local cmd="mirror_io resync ${options[$index]}"
2372 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
2374 [ $((RANDOM % 4)) -eq 0 ] && {
2380 echo -n "resync file $tf with '$cmd' .."
2382 if [[ $lock_taken = "true" ]]; then
2383 flock -x 200 -c "$cmd $tf &> /dev/null" &&
2384 echo "done" || echo "failed"
2387 $cmd $tf &> /dev/null && echo "done" || echo "failed"
2390 sleep 0.$((RANDOM % 8 + 1))
2395 local tf=$DIR/$tfile
2396 local tf2=$DIR2/$tfile
2397 local tf3=$DIR3/$tfile
2399 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
2400 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
2401 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
2403 $LFS mirror extend -N -f $tf-2 $tf ||
2404 error "merging $tf-2 into $tf failed"
2405 $LFS mirror extend -N -f $tf-3 $tf ||
2406 error "merging $tf-3 into $tf failed"
2408 mkdir -p $MOUNT2 && mount_client $MOUNT2
2410 mkdir -p $MOUNT3 && mount_client $MOUNT3
2412 verify_flr_state $tf3 "ro"
2414 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
2415 $LCTL set_param fail_loc=0x1A03
2417 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
2418 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
2422 write_file_200 $tf &
2428 write_file_200 $tf2 &
2431 read_file_200 $tf2 &
2434 resync_file_200 $tf3 &
2438 [ "$SLOW" = "yes" ] && sleep_time=360
2439 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
2446 echo "Waiting ${pids[@]}"
2449 umount_client $MOUNT2
2450 umount_client $MOUNT3
2454 # resync and verify mirrors
2455 mirror_io resync $tf
2458 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
2459 for id in ${mirror_array[@]:1}; do
2460 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
2461 error "checksum error for mirror $id"
2466 run_test 200 "stress test"
2468 cleanup_test_201() {
2470 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
2472 umount_client $MOUNT2
2476 local delay=${RESYNC_DELAY:-5}
2478 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
2479 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
2481 trap cleanup_test_201 EXIT
2483 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
2484 changelog_register -n)
2486 mkdir -p $MOUNT2 && mount_client $MOUNT2
2490 local log=$($LFS changelog $MDT0 $index | grep FLRW)
2491 [ -z "$log" ] && { sleep 1; continue; }
2493 index=$(echo $log | awk '{print $1}')
2494 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
2495 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
2496 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
2499 [ -z "$file" ] && continue
2501 local now=$(date +%s)
2503 echo "file: $file $fid was modified at $ts, now: $now, " \
2504 "will be resynced at $((ts+delay))"
2506 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
2508 mirror_io resync $file
2509 echo "$file resync done"
2514 run_test 201 "FLR data mover"
2517 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
2519 local tf=$DIR/$tfile
2522 $LFS setstripe -E 1M -S 1M -c 1 $tf
2523 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2524 verify_comp_attr stripe-count $tf ${ids[0]} 1
2526 $LFS setstripe --component-add -E 2M -c -1 $tf
2527 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2528 verify_comp_attr stripe-count $tf ${ids[0]} 1
2529 verify_comp_attr stripe-count $tf ${ids[1]} -1
2531 dd if=/dev/zero of=$tf bs=1M count=2
2532 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2533 verify_comp_attr stripe-count $tf ${ids[0]} 1
2534 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
2536 run_test 202 "lfs setstripe --add-component wide striping"
2539 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2540 skip "Need MDS version at least 2.11.55"
2541 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
2543 local tf=$DIR/$tfile
2546 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
2547 #delete first mirror
2548 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
2551 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
2552 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2553 error "getstripe count of mirror 2"
2554 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2556 #extend a mirror with 2 OSTs
2557 $LFS mirror extend -N -c2 $tf || error "extend mirror"
2560 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
2561 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2562 error "getstripe count of mirror 2"
2563 [[ x$oldid = x$newid ]] ||
2564 error "mirror 2 changed ID from $old_id to $new_id"
2565 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2567 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
2568 error "getstripe count of mirror 3"
2569 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
2571 run_test 203 "mirror file preserve mirror ID"
2573 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
2575 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2576 skip "skipped for lustre < $SEL_VER"
2578 local comp_file=$DIR/$tdir/$tfile
2582 test_mkdir $DIR/$tdir
2584 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
2585 # by extension space to -1
2586 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
2587 error "Create $comp_file failed"
2589 # Write to first component, extending & staling second mirror
2590 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2591 error "dd to extend + stale failed"
2593 $LFS getstripe $comp_file
2595 flg_opts="--component-flags init,stale"
2596 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2597 [ $found -eq 1 ] || error "write: Second comp end incorrect"
2599 flg_opts="--component-flags extension"
2600 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2601 [ $found -eq 1 ] || error "write: Third comp start incorrect"
2603 # mirror resync should not change the extents
2604 $LFS mirror resync $comp_file
2606 flg_opts="--component-flags init"
2607 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2608 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
2610 flg_opts="--component-flags extension"
2611 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2612 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
2614 sel_layout_sanity $comp_file 5
2618 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
2620 # Simple test of FLR + self-extending layout, SEL in primary mirror
2622 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2623 skip "skipped for lustre < $SEL_VER"
2625 local comp_file=$DIR/$tdir/$tfile
2629 test_mkdir $DIR/$tdir
2631 # first mirror is 1M followed by extension space to -1, second mirror
2632 # is 0-10M, then 10M-(-1),
2633 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2634 error "Create $comp_file failed"
2636 # Write to first component, extending first component & staling
2638 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2639 error "dd to extend + stale failed"
2641 $LFS getstripe $comp_file
2643 flg_opts="--component-flags init"
2644 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2645 [ $found -eq 1 ] || error "write: First comp end incorrect"
2647 flg_opts="--component-flags extension"
2648 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2649 [ $found -eq 1 ] || error "write: Second comp start incorrect"
2651 flg_opts="--component-flags init,stale"
2652 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2653 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
2655 # This component is staled because it overlaps the extended first
2656 # component of the primary mirror, even though it doesn't overlap
2657 # the actual write - thus not inited.
2658 flg_opts="--component-flags stale"
2659 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2660 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
2662 # mirror resync should not change the extents
2663 $LFS mirror resync $comp_file
2665 $LFS getstripe $comp_file
2667 flg_opts="--component-flags init"
2668 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2669 [ $found -eq 1 ] || error "resync: First comp end incorrect"
2671 flg_opts="--component-flags extension"
2672 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2673 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
2675 flg_opts="--component-flags init"
2676 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2677 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
2679 flg_opts="--component-flags init"
2680 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2681 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
2683 sel_layout_sanity $comp_file 5
2687 run_test 204b "FLR write/stale/resync tests with self-extending primary"
2689 # FLR + SEL failed extension & component removal
2690 # extension space in second mirror
2692 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2693 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2694 skip "skipped for lustre < $SEL_VER"
2696 local comp_file=$DIR/$tdir/$tfile
2699 local ost_name=$(ostname_from_index $ost_idx1)
2701 test_mkdir $DIR/$tdir
2703 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
2704 # extension space from 1M to 1G, then normal space to -1
2705 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
2706 -E -1 $comp_file || error "Create $comp_file failed"
2708 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
2711 # write to first comp (0 - 10M) of mirror 1, extending + staling
2712 # first + second comp of mirror 2
2713 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2716 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
2719 [ $RC -eq 0 ] || error "dd to extend + stale failed"
2721 $LFS getstripe $comp_file
2723 found=$($LFS find --component-start 0m --component-end 1m \
2724 --comp-flags init,stale $comp_file | wc -l)
2725 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2727 found=$($LFS find --component-start 1m --component-end EOF \
2728 --comp-flags stale,^init $comp_file | wc -l)
2729 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
2731 local mirror_id=$($LFS getstripe --component-start=1m \
2732 --component-end=EOF $comp_file | \
2733 grep lcme_mirror_id | awk '{ print $2 }')
2735 [[ $mirror_id -eq 2 ]] ||
2736 error "component not in correct mirror? $mirror_id"
2738 $LFS mirror resync $comp_file
2740 $LFS getstripe $comp_file
2742 # component dimensions should not change from resync
2743 found=$($LFS find --component-start 1m --component-end EOF \
2744 --component-flags init $comp_file | wc -l)
2745 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
2747 sel_layout_sanity $comp_file 4
2751 run_test 204c "FLR write/stale/resync test with component removal"
2753 # Successful repeated component in primary mirror
2755 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2756 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2757 skip "skipped for lustre < $SEL_VER"
2759 local comp_file=$DIR/$tdir/$tfile
2762 wait_delete_completed
2764 test_mkdir $DIR/$tdir
2766 # first mirror is 64M followed by extension space to -1, second mirror
2767 # is 0-10M, then 10M-(-1)
2768 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2769 error "Create $comp_file failed"
2771 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
2772 local ost_name=$(ostname_from_index $ost_idx1)
2773 # degrade OST for first comp so we won't extend there
2774 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2775 obdfilter.$ost_name.degraded=1
2778 # Write beyond first component, causing repeat & stale second mirror
2779 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
2782 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2783 obdfilter.$ost_name.degraded=0
2786 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2788 $LFS getstripe $comp_file
2790 found=$($LFS find --component-start 64m --component-end 128m \
2791 --component-flags init $comp_file | wc -l)
2792 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
2794 local ost_idx2=$($LFS getstripe --component-start=64m \
2795 --component-end=128m --component-flags=init \
2797 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2798 local mirror_id=$($LFS getstripe --component-start=64m \
2799 --component-end=128m --component-flags=init \
2800 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2801 [[ $mirror_id -eq 1 ]] ||
2802 error "component not in correct mirror: $mirror_id, not 1"
2804 $LFS mirror resync $comp_file
2806 $LFS getstripe $comp_file
2808 # component dimensions should not change from resync
2809 found=$($LFS find --component-start 0m --component-end 64m \
2810 --component-flags init $comp_file | wc -l)
2811 [ $found -eq 1 ] || error "resync: first comp incorrect"
2812 found=$($LFS find --component-start 64m --component-end 128m \
2813 --component-flags init $comp_file | wc -l)
2814 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
2816 sel_layout_sanity $comp_file 5
2820 run_test 204d "FLR write/stale/resync sel test with repeated comp"
2822 # Successful repeated component, SEL in non-primary mirror
2824 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2825 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2826 skip "skipped for lustre < $SEL_VER"
2828 local comp_file=$DIR/$tdir/$tfile
2831 wait_delete_completed
2834 test_mkdir $DIR/$tdir
2836 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2837 # space to -1 (-z 64M, so first comp is 0-64M)
2838 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
2839 # will be not enough - one will be degraded, the other is used on
2840 # an overlapping mirror.
2841 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
2842 error "Create $comp_file failed"
2844 local ost_idx1=$($LFS getstripe --component-start=0 \
2845 --component-end=64m -i $comp_file)
2846 local ost_name=$(ostname_from_index $ost_idx1)
2847 # degrade OST for first comp of 2nd mirror so we won't extend there
2848 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2849 obdfilter.$ost_name.degraded=1
2852 $LFS getstripe $comp_file
2854 # Write to first component, stale & instantiate second mirror components
2855 # overlapping with the written component (0-100M);
2856 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2859 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2860 obdfilter.$ost_name.degraded=0
2862 $LFS getstripe $comp_file
2864 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2866 found=$($LFS find --component-start 0m --component-end 64m \
2867 --component-flags init,stale $comp_file | wc -l)
2868 [ $found -eq 1 ] || error "write: first comp incorrect"
2870 # was repeated due to degraded ost
2871 found=$($LFS find --component-start 64m --component-end 128m \
2872 --component-flags init,stale $comp_file | wc -l)
2873 [ $found -eq 1 ] || error "write: repeated comp incorrect"
2875 local ost_idx2=$($LFS getstripe --component-start=64m \
2876 --component-end=128m --component-flags=init \
2878 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2879 local mirror_id=$($LFS getstripe --component-start=0m \
2880 --component-end=64m --component-flags=init \
2881 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2882 [[ $mirror_id -eq 2 ]] ||
2883 error "component not in correct mirror? $mirror_id"
2885 $LFS mirror resync $comp_file
2887 $LFS getstripe $comp_file
2889 # component dimensions should not change from resync
2890 found=$($LFS find --component-start 0m --component-end 64m \
2891 --component-flags init,^stale $comp_file | wc -l)
2892 [ $found -eq 1 ] || error "resync: first comp incorrect"
2893 found=$($LFS find --component-start 64m --component-end 128m \
2894 --component-flags init,^stale $comp_file | wc -l)
2895 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
2897 sel_layout_sanity $comp_file 5
2901 run_test 204e "FLR write/stale/resync sel test with repeated comp"
2903 # FLR + SEL: failed repeated component, SEL in non-primary mirror
2905 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2906 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2907 skip "skipped for lustre < $SEL_VER"
2909 local comp_file=$DIR/$tdir/$tfile
2912 wait_delete_completed
2914 test_mkdir $DIR/$tdir
2916 pool_add $TESTNAME || error "Pool creation failed"
2917 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
2919 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2920 # space to -1 (-z 64M, so first comp is 0-64M)
2921 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
2922 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
2924 local ost_name0=$(ostname_from_index 0)
2925 local ost_name1=$(ostname_from_index 1)
2927 # degrade both OSTs in pool, so we'll try to repeat, then fail and
2928 # extend original comp
2929 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
2930 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
2933 # a write to the 1st component, 100M length, which will try to stale
2934 # the first 100M of mirror 2, attempting to extend its 0-64M component
2935 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2938 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
2939 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
2942 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
2944 $LFS getstripe $comp_file
2946 found=$($LFS find --component-start 0m --component-end 128m \
2947 --component-flags init,stale $comp_file | wc -l)
2948 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2950 local mirror_id=$($LFS getstripe --component-start=0m \
2951 --component-end=128m --component-flags=init \
2952 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2954 [[ $mirror_id -eq 2 ]] ||
2955 error "component not in correct mirror? $mirror_id, not 2"
2957 $LFS mirror resync $comp_file
2959 $LFS getstripe $comp_file
2961 # component dimensions should not change from resync
2962 found=$($LFS find --component-start 0m --component-end 128m \
2963 --component-flags init,^stale $comp_file | wc -l)
2964 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
2966 sel_layout_sanity $comp_file 4
2970 run_test 204f "FLR write/stale/resync sel w/forced extension"
2972 function test_205() {
2973 local tf=$DIR/$tfile
2976 $LFS setstripe -c1 $tf
2977 $LFS mirror extend -N $tf
2978 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
2979 (( $mirrors == 2 )) || error "no new mirror was created?"
2981 $LFS mirror extend -N --flags=prefer $tf
2982 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
2983 (( $mirrors == 3 )) || error "no new mirror was created?"
2985 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
2986 error "prefer flag was not set on the new mirror"
2988 run_test 205 "lfs mirror extend to set prefer flag"
2991 check_and_cleanup_lustre