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 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
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 --flags prefer $tf ||
687 error "creating $tf w/ --flags but w/o -N option should fail"
689 ! $LFS mirror create -N --flags foo $tf ||
690 error "creating $tf with '--flags foo' should fail"
692 ! $LFS mirror create -N --flags stale $tf ||
693 error "creating $tf with '--flags stale' should fail"
695 ! $LFS mirror create -N --flags prefer,init $tf ||
696 error "creating $tf with '--flags prefer,init' should fail"
698 ! $LFS mirror create -N --flags ^prefer $tf ||
699 error "creating $tf with '--flags ^prefer' should fail"
701 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
702 -N -o1 $tf || error "create mirrored file $tf failed"
704 verify_comp_attr lcme_flags $tf 0x10001 prefer
705 verify_comp_attr lcme_flags $tf 0x10002 prefer
707 # write to the mirrored file and check primary
708 cp /etc/hosts $tf || error "error writing file '$tf'"
710 verify_comp_attr lcme_flags $tf 0x20003 stale
712 # resync file and check prefer flag
713 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
716 $LCTL set_param osc.*.stats=clear
717 cat $tf &> /dev/null || error "error reading file '$tf'"
719 # verify that the data was provided by OST1 where mirror 1 resides
720 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
721 awk '/ost_read/{print $2}')
722 [ -n "$nr_read" ] || error "read was not provided by OST1"
724 run_test 0g "lfs mirror create flags support"
727 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
728 skip "Need MDS version at least 2.11.57"
735 # create parent directory
736 test_mkdir $td || error "mkdir $td failed"
738 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
739 error "set default mirrored layout on directory $td failed"
741 # verify flags are inherited from the directory
744 verify_comp_attr lcme_flags $tf 0x10001 prefer
745 verify_comp_attr lcme_flags $tf 0x10002 prefer
747 # set flags to the first component
748 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
749 error "setting '^prefer,foo' flags should fail"
751 ! $LFS getstripe --component-flags=prefer,foo $tf ||
752 error "getting component(s) with 'prefer,foo' flags should fail"
754 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
756 verify_comp_attr lcme_flags $tf 0x10001 stale
757 verify_comp_attr lcme_flags $tf 0x10002 prefer
759 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
760 error "clearing 'stale' should fail"
762 # write and resync file. It can't resync the file directly because the
763 # file state is still 'ro'
764 cp /etc/hosts $tf || error "error writing file '$tf'"
765 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
767 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
768 error "error setting flag prefer"
770 verify_comp_attr lcme_flags $tf 0x20003 prefer
772 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^prefer $tf ||
773 error "error clearing prefer flag from component 0x20003"
775 # MDS disallows setting stale flag on the last non-stale mirror
776 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
778 cp /etc/hosts $tf || error "error writing file '$tf'"
780 verify_comp_attr lcme_flags $tf 0x10002 prefer
781 verify_comp_attr lcme_flags $tf 0x20003 stale
782 verify_comp_attr lcme_flags $tf 0x30004 stale
784 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
786 error "setting stale flag on component 0x10002 should fail"
788 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
790 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
791 error "error setting stale flag on component 0x10001"
792 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
793 error "error setting stale flag on component 0x20003"
795 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
797 error "setting stale flag on component 0x30004 should fail"
799 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
801 run_test 0h "set, clear and test flags for FLR files"
804 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
806 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
807 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
808 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
810 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || "read mirror failed"
811 stack_trap "rm -f $TMP/$tfile"
812 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
813 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || "write failed"
814 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
815 error "set component 1 stale failed"
816 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
817 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
819 run_test 0j "test lfs mirror read/write commands"
823 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
824 local mirror_create_cmd="$LFS mirror create"
825 local stripes[0]=$OSTCOUNT
827 mirror_create_cmd+=" -N -c ${stripes[0]}"
828 for ((i = 1; i < $mirror_count; i++)); do
829 # add mirrors with different stripes to the file
830 stripes[$i]=$((RANDOM % OSTCOUNT))
831 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
833 mirror_create_cmd+=" -N -c ${stripes[$i]}"
836 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
837 verify_mirror_count $tf $mirror_count
839 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
840 $LFS mirror extend -N $tf &&
841 error "Creating the $((mirror_count+1))th mirror succeeded"
843 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
846 # verify the range of components and stripe counts
847 for ((i = 0; i < $mirror_count; i++)); do
848 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
849 verify_comp_extent $tf ${ids[$i]} 0 EOF
852 run_test 1 "create components with setstripe options"
856 local tf2=$DIR/$tfile-2
858 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
859 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
861 $LFS mirror extend -N -f $tf2 $tf ||
862 error "merging $tf2 into $tf failed"
864 verify_mirror_count $tf 2
865 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
867 run_test 2 "create components from existing files"
870 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
872 for ((i = 0; i < 2; i++)); do
873 $LFS mkdir -i $i $DIR/$tdir-$i
874 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
877 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
878 $DIR/$tdir-0/$tfile || error "creating mirrors"
880 # mdt doesn't support to cancel layout lock for remote objects, do
884 # make sure the mirrorted file was created successfully
885 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
886 { $LFS getstripe $DIR/$tdir-0/$tfile;
887 error "expected 2 components"; }
892 run_test 3 "create components from files located on different MDTs"
895 local tf=$DIR/$tdir/$tfile
898 test_mkdir $DIR/$tdir
900 # set mirror with setstripe options to directory
901 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
902 error "set mirror to directory error"
904 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
905 x"mirrored" ] || error "failed to create mirrored dir"
908 verify_mirror_count $tf 2
910 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
911 verify_comp_extent $tf ${ids[0]} 0 1048576
912 verify_comp_extent $tf ${ids[1]} 1048576 EOF
914 # sub directory should inherit mirror setting from parent
915 test_mkdir $DIR/$tdir/td
916 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
917 x"mirrored" ] || error "failed to inherit mirror from parent"
919 # mirror extend won't be applied to directory
920 $LFS mirror extend -N2 $DIR/$tdir &&
921 error "expecting mirror extend failure"
924 run_test 4 "Make sure mirror attributes can be inhertied from directory"
930 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
931 error "failed to create file with non-empty layout"
932 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
934 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
935 verify_mirror_count $tf 3
937 $CHECKSTAT -t file -s 12345 $tf ||
938 error "size error after attaching layout "
940 run_test 5 "Make sure init size work for mirrored layout"
942 # LU=10112: disable dom+flr for phase 1
946 $LFS mirror create -N -E 1M -S 1M -L mdt -E eof -N -E eof $tf &&
947 error "expect failure to create mirrored file with DoM"
949 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf &&
950 error "expect failure to create mirrored file with DoM"
952 $LFS setstripe -E 1M -S 1M -L mdt -E eof $tf
953 $LFS mirror extend -N2 $tf &&
954 error "expect failure to extend mirror with DoM"
956 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2
957 $LFS mirror extend -N -f $tf $tf-2 &&
958 error "expect failure to extend mirrored file with DoM extent"
962 run_test 6 "DoM and FLR won't co-exist for phase 1"
966 local tf2=$DIR/$tfile-2
968 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
970 $LFS setstripe -E EOF -o 0 $tf
971 $LFS setstripe -E EOF -o 1 $tf2
973 local dd_count=$((RANDOM % 20 + 1))
974 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
975 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
977 # for zfs - sync OST dataset so that du below will return
979 [ "$FSTYPE" = "zfs" ] &&
980 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
982 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
985 $LFS mirror extend -N -f $tf2 $tf ||
986 error "merging $tf2 into $tf failed"
991 local new_blocks=$(du -k $tf | awk '{print $1}')
992 [ $new_blocks -eq $blocks ] ||
993 error "i_blocks error expected: $blocks, actual: $new_blocks"
995 run_test 21 "glimpse should report accurate i_blocks"
997 get_osc_lock_count() {
1004 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1005 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1006 lock_count=$((lock_count + count))
1012 local tf=$DIR/$tfile
1014 $LFS setstripe -E EOF -o 0 $tf
1015 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1017 # add component, two mirrors located on the same OST ;-)
1018 $LFS mirror extend -N -o 0 $tf ||
1019 error "extending mirrored file $tf failed"
1021 size_blocks=$(stat --format="%b %s" $tf)
1023 cancel_lru_locks mdc
1024 cancel_lru_locks osc
1026 local new_size_blocks=$(stat --format="%b %s" $tf)
1028 # make sure there is no lock cached
1029 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1031 [ "$new_size_blocks" = "$size_blocks" ] ||
1032 echo "size expected: $size_blocks, actual: $new_size_blocks"
1036 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1039 local tf=$DIR/$tfile
1041 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1042 error "creating mirrored file $tf failed"
1044 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
1045 $LCTL set_param fail_loc=0x1A00
1048 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1049 cancel_lru_locks osc
1052 local tmpfile=$(mktemp)
1053 stat --format="%b %s" $tf > $tmpfile &
1057 while [ $cnt -le 5 ]; do
1058 kill -0 $pid > /dev/null 2>&1 || break
1062 kill -0 $pid > /dev/null 2>&1 &&
1063 error "stat process stuck due to unavailable OSTs"
1065 # make sure glimpse request has been sent
1066 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1067 error "OST $ost_idx: no glimpse request was sent"
1072 run_test 31 "make sure glimpse request can be retried"
1075 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1076 rm -f $DIR/$tfile $DIR/$tfile-2
1078 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1079 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1081 local fsize=$(stat -c %s $DIR/$tfile)
1082 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1084 local cksum=$(md5sum $DIR/$tfile)
1086 # create a new mirror in sync mode
1087 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1088 error "extending mirrored file $DIR/$tfile failed"
1090 # make sure the mirrored file was created successfully
1091 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1092 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1097 # check size is correct, glimpse request should go to the 2nd mirror
1098 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1099 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1101 echo "reading file from the 2nd mirror and verify checksum"
1102 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1103 error "checksum error: expected $cksum"
1107 run_test 32 "data should be mirrored to newly created mirror"
1110 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1112 rm -f $DIR/$tfile $DIR/$tfile-2
1114 # create a file with two mirrors
1115 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1118 while [ $count -lt $max_count ]; do
1119 echo "ost1" >> $DIR/$tfile
1120 count=$((count + 1));
1123 # tmp file that will be used as mirror
1124 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1126 while [ $count -lt $max_count ]; do
1127 echo "ost2" >> $DIR/$tfile-2
1128 count=$((count + 1));
1131 # create a mirrored file
1132 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1133 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1134 "with verification should fail"
1135 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1136 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1137 "without verification failed"
1139 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1140 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1141 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1143 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1145 # execpted file size
1146 local fsize=$((5 * max_count))
1147 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1148 error "mirrored file size is not $fsize"
1150 # read file - all OSTs are available
1151 echo "reading file (data can be provided by any ost)... "
1152 local rs=$(cat $DIR/$tfile | head -1)
1153 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1154 error "file content error: expected: \"ost1\" or \"ost2\""
1156 # read file again with ost1 failed
1160 echo "reading file (data should be provided by ost2)..."
1161 local rs=$(cat $DIR/$tfile | head -1)
1162 [[ "$rs" == "ost2" ]] ||
1163 error "file content error: expected: \"ost2\", actual: \"$rs\""
1168 # read file again with ost2 failed
1172 # check size, glimpse should work
1173 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1174 error "mirrored file size is not $fsize"
1176 echo "reading file (data should be provided by ost1)..."
1177 local rs=$(cat $DIR/$tfile | head -1)
1178 [[ "$rs" == "ost1" ]] ||
1179 error "file content error: expected: \"ost1\", actual: \"$rs\""
1183 run_test 33a "read can choose available mirror to read"
1186 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1190 stack_trap "rm -f $DIR/$tfile" EXIT
1192 # create a file with two mirrors on OST0000 and OST0001
1193 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1195 # make sure that $tfile has two mirrors
1196 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1197 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1200 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1201 error "write failed for $DIR/$tfile"
1202 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1203 verify_flr_state $DIR/$tfile "ro"
1208 # read file - all OSTs are available
1209 echo "reading file (data can be provided by any ost)... "
1211 time cat $DIR/$tfile > /dev/null || error "read all"
1215 # read file again with ost1 {OST0000} failed
1218 echo "reading file (data should be provided by ost2)..."
1220 time cat $DIR/$tfile > /dev/null || error "read ost2"
1227 # read file again with ost2 {OST0001} failed
1231 echo "reading file (data should be provided by ost1)..."
1233 time cat $DIR/$tfile > /dev/null || error "read ost1"
1240 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1241 error "read mirror too slow without ost1, from $ra to $r1"
1242 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1243 error "read mirror too slow without ost2, from $ra to $r2"
1245 wait_osc_import_ready client ost2
1247 run_test 33b "avoid reading from unhealthy mirror"
1250 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1254 stack_trap "rm -f $DIR/$tfile" EXIT
1256 # create a file with two mirrors
1257 # mirror1: {OST0000, OST0001}
1258 # mirror2: {OST0001, OST0002}
1259 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1261 # make sure that $tfile has two mirrors
1262 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1263 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1266 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1267 error "write failed for $DIR/$tfile"
1268 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1269 verify_flr_state $DIR/$tfile "ro"
1274 # read file - all OSTs are available
1275 echo "reading file (data can be provided by any ost)... "
1276 time cat $DIR/$tfile > /dev/null || error "read all"
1278 # read file again with ost2 (OST0001) failed
1282 echo "reading file (data should be provided by ost1 and ost3)..."
1283 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1288 wait_osc_import_ready client ost2
1290 run_test 33c "keep reading among unhealthy mirrors"
1293 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1295 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1298 $LFS setstripe -o 0 $DIR/$tfile-ref
1299 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1301 # create a file with two mirrors
1302 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1303 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1305 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1306 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1308 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1309 error "mirrored file size is not 3M"
1311 # merge a mirrored file
1312 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1313 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1315 cancel_lru_locks osc
1317 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1318 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1321 echo "comparing files ... "
1323 # however, read can still return the correct data. It should return
1324 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1325 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1326 $DIR/$tfile-ref || error "file reading error"
1330 run_test 34a "read mirrored file with multiple stripes"
1333 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1335 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1338 $LFS setstripe -o 0 $DIR/$tfile-ref
1339 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1341 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1342 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1344 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1345 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1347 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1348 error "mirrored file size is not 3M"
1350 # merge a mirrored file
1351 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1352 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1354 cancel_lru_locks osc
1356 # stop two OSTs, so the 2nd component of the 1st mirror and
1357 # the 1st component of the 2nd mirror will be inaccessible, ...
1360 echo "comparing files ... "
1362 # however, read can still return the correct data. It should return
1363 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1364 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1365 $DIR/$tfile-ref || error "file reading error"
1369 run_test 34b "read mirrored file with multiple components"
1372 local tf=$DIR/$tfile
1374 $LFS setstripe -E eof $tf
1376 # add an out-of-sync mirror to the file
1377 $LFS mirror extend -N -c 2 $tf ||
1378 error "extending mirrored file $tf failed"
1380 $MULTIOP $tf oO_WRONLY:c ||
1381 error "write open a mirrored file failed"
1383 # truncate file should return error
1384 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1386 run_test 35 "allow to write to mirrored files"
1388 verify_ost_layout_version() {
1391 # get file layout version
1392 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1394 # layout version from OST objects
1395 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1397 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1404 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1405 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1407 $LFS mirror extend -N -f $tf-tmp $tf ||
1408 error "merging $tf-tmp into $tf failed"
1413 local tf=$DIR/$tfile
1415 create_file_36 $tf $tf-2 $tf-3
1417 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1419 # test case 1 - check file write and verify layout version
1420 $MULTIOP $tf oO_WRONLY:c ||
1421 error "write open a mirrored file failed"
1423 # write open file should not return error
1424 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1426 # instantiate components should work
1427 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1429 # verify OST layout version
1430 verify_ost_layout_version $tf
1433 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1436 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1438 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1439 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1441 # write should take at least $fail_loc seconds and succeed
1442 local st=$(date +%s)
1443 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1445 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1446 error "write finished before layout version is transmitted"
1448 # verify OST layout version
1449 verify_ost_layout_version $tf
1451 do_facet $mds_facet $LCTL set_param fail_loc=0
1454 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1456 #define OBD_FAIL_FLR_LV_INC 0x1A02
1457 do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1459 # write open file should return error
1460 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1461 error "write a mirrored file succeeded" || true
1463 do_facet $mds_facet $LCTL set_param fail_loc=0
1465 run_test 36 "write to mirrored files"
1471 echo "create test files with size $fsize .."
1475 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1477 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1478 $TRUNCATE $tf $fsize
1484 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1485 skip "Need MDS version at least 2.11.57"
1487 local tf=$DIR/$tfile
1488 local tf2=$DIR/$tfile-2
1489 local tf3=$DIR/$tfile-3
1490 local tf4=$DIR/$tfile-4
1492 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1496 # assume the mirror id will be 1, 2, and 3
1497 declare -A checksums
1498 checksums[1]=$(cat $tf | md5sum)
1499 checksums[2]=$(cat $tf2 | md5sum)
1500 checksums[3]=$(cat $tf3 | md5sum)
1502 printf '%s\n' "${checksums[@]}"
1504 # merge these files into a mirrored file
1505 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1506 error "merging $tf2 into $tf failed"
1507 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1508 error "merging $tf3 into $tf failed"
1512 # verify mirror read, checksums should equal to the original files'
1513 echo "Verifying mirror read .."
1516 for i in ${mirror_array[@]}; do
1517 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1518 sum=$($LFS mirror read -N $i $tf | md5sum)
1519 [ "$sum" = "${checksums[$i]}" ] ||
1520 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1523 # verify mirror write
1524 echo "Verifying mirror write .."
1525 $LFS mirror write -N2 $tf < $tf4
1527 sum=$($LFS mirror read -N2 $tf | md5sum)
1528 [[ "$sum" = "${checksums[1]}" ]] ||
1529 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1531 # verify mirror copy, write to this mirrored file will invalidate
1532 # the other two mirrors
1533 echo "Verifying mirror copy .."
1535 local osts=$(comma_list $(osts_nodes))
1537 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1538 error "mirror copy error"
1540 # verify copying is successful by checking checksums
1541 remount_client $MOUNT
1542 for i in ${mirror_array[@]}; do
1543 sum=$($LFS mirror read -N $i $tf | md5sum)
1544 [ "$sum" = "${checksums[1]}" ] ||
1545 error "$i: mismatch checksum after copy \'$sum\'"
1550 run_test 37 "mirror I/O API verification"
1553 local tf=$DIR/$tfile
1554 local ref=$DIR/${tfile}-ref
1556 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1557 error "creating $tf failed"
1558 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1559 $tf-2 || error "creating $tf-2 failed"
1560 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1561 error "creating $tf-3 failed"
1563 # instantiate all components
1564 $LFS mirror extend -N -f $tf-2 $tf ||
1565 error "merging $tf-2 into $tf failed"
1566 $LFS mirror extend -N -f $tf-3 $tf ||
1567 error "merging $tf-3 into $tf failed"
1568 $LFS mirror extend -N -c 1 $tf ||
1569 error "extending mirrored file $tf failed"
1571 verify_flr_state $tf "ro"
1573 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1575 local fsize=$((RANDOM << 8 + 1048576))
1576 $TRUNCATE $ref $fsize
1578 local ref_cksum=$(cat $ref | md5sum)
1580 # case 1: verify write to mirrored file & resync work
1581 cp $ref $tf || error "copy from $ref to $f error"
1582 verify_flr_state $tf "wp"
1584 local file_cksum=$(cat $tf | md5sum)
1585 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1588 echo "mirror IDs: ${mirror_array[@]}"
1590 local valid_mirror stale_mirror id mirror_cksum
1591 for id in "${mirror_array[@]}"; do
1592 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1593 [ "$ref_cksum" == "$mirror_cksum" ] &&
1594 { valid_mirror=$id; continue; }
1599 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1600 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1602 mirror_io resync $tf || error "resync failed"
1603 verify_flr_state $tf "ro"
1605 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1606 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1608 # case 2: inject an error to make mirror_io exit after changing
1609 # the file state to sync_pending so that we can start a concurrent
1611 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1612 verify_flr_state $tf "wp"
1614 mirror_io resync -e resync_start $tf && error "resync succeeded"
1615 verify_flr_state $tf "sp"
1617 # from sync_pending to write_pending
1618 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1619 verify_flr_state $tf "wp"
1621 mirror_io resync -e resync_start $tf && error "resync succeeded"
1622 verify_flr_state $tf "sp"
1624 # from sync_pending to read_only
1625 mirror_io resync $tf || error "resync failed"
1626 verify_flr_state $tf "ro"
1628 run_test 38 "resync"
1631 local tf=$DIR/$tfile
1634 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1635 error "create PFL file $tf failed"
1637 verify_mirror_count $tf 2
1638 verify_comp_count $tf 4
1640 rm -f $tf || error "delete $tf failed"
1642 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1645 local tf=$DIR/$tfile
1648 for ops in "conv=notrunc" ""; do
1651 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1652 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1653 error "create PFLR file $tf failed"
1654 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1655 error "write PFLR file $tf failed"
1657 lfs getstripe -vy $tf
1661 # file mirror state should be write_pending
1662 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1664 error "file mirror state $flags"
1665 # the 1st component (in mirror 1) should be inited
1666 verify_comp_attr lcme_flags $tf 0x10001 init
1667 # the 2nd component (in mirror 1) should be inited
1668 verify_comp_attr lcme_flags $tf 0x10002 init
1669 # the 3rd component (in mirror 1) should be uninited
1670 verify_comp_attr lcme_flags $tf 0x10003 prefer
1671 # the 4th component (in mirror 2) should be inited
1672 verify_comp_attr lcme_flags $tf 0x20004 init
1673 # the 5th component (in mirror 2) should be uninited
1674 verify_comp_attr lcme_flags $tf 0x20005 0
1675 # the 6th component (in mirror 2) should be stale
1676 verify_comp_attr lcme_flags $tf 0x20006 stale
1677 # the 7th component (in mirror 2) should be uninited
1678 if [[ x$ops = "xconv=notrunc" ]]; then
1679 verify_comp_attr lcme_flags $tf 0x20007 0
1680 elif [[ x$ops = "x" ]]; then
1681 verify_comp_attr lcme_flags $tf 0x20007 stale
1685 rm -f $tf || error "delete $tf failed"
1687 run_test 40 "PFLR rdonly state instantiation check"
1690 local tf=$DIR/$tfile
1693 echo " **create two FLR files $tf $tf-1"
1694 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1695 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1696 error "create PFLR file $tf failed"
1697 $LFS mirror create -N -E 2M -S 1M -E eof \
1698 -N -E 1M -E eof --flags prefer \
1699 -N -E 4m -E eof $tf-1 ||
1700 error "create PFLR file $tf-1 failed"
1702 # file should be in ro status
1703 echo " **verify files be RDONLY"
1704 verify_flr_state $tf "ro"
1705 verify_flr_state $tf-1 "ro"
1707 # write data in [0, 2M)
1708 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1709 error "writing $tf failed"
1710 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1711 error "writing $tf-1 failed"
1713 local sum0=$(cat $tf-1 | md5sum)
1715 echo " **verify files be WRITE_PENDING"
1716 verify_flr_state $tf "wp"
1717 verify_flr_state $tf-1 "wp"
1719 # file should have stale component
1720 echo " **verify files have stale component"
1721 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1722 error "after writing $tf, it does not contain stale component"
1723 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1724 error "after writing $tf-1, it does not contain stale component"
1726 echo " **full resync"
1727 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1729 echo " **verify $tf-1 data consistency in all mirrors"
1731 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1732 [[ "$sum" = "$sum0" ]] ||
1733 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1736 echo " **verify files be RDONLY"
1737 verify_flr_state $tf "ro"
1738 verify_flr_state $tf-1 "ro"
1740 # file should not have stale component
1741 echo " **verify files do not contain stale component"
1742 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1743 error "after resyncing $tf, it contains stale component"
1744 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1745 error "after resyncing $tf, it contains stale component"
1747 # verify partial resync
1748 echo " **write $tf-1 for partial resync test"
1749 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1750 error "writing $tf-1 failed"
1752 echo " **only resync mirror 2"
1753 verify_flr_state $tf-1 "wp"
1754 $LFS mirror resync --only 2 $tf-1 ||
1755 error "resync mirror 2 of $tf-1 failed"
1756 verify_flr_state $tf "ro"
1758 # resync synced mirror
1759 echo " **resync mirror 2 again"
1760 $LFS mirror resync --only 2 $tf-1 ||
1761 error "resync mirror 2 of $tf-1 failed"
1762 verify_flr_state $tf "ro"
1763 echo " **verify $tf-1 contains stale component"
1764 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1765 error "after writing $tf-1, it does not contain stale component"
1767 echo " **full resync $tf-1"
1768 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1769 verify_flr_state $tf "ro"
1770 echo " **full resync $tf-1 again"
1771 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1772 echo " **verify $tf-1 does not contain stale component"
1773 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1774 error "after resyncing $tf, it contains stale component"
1778 run_test 41 "lfs mirror resync check"
1781 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1785 local mirror_cmd="$LFS mirror verify"
1788 # create parent directory
1789 mkdir $td || error "mkdir $td failed"
1791 $mirror_cmd &> /dev/null && error "no file name given"
1792 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1793 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1795 # create mirrored files
1796 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1797 error "create mirrored file $tf failed"
1798 $LFS mirror create -N -E 2M -S 1M -E EOF \
1799 -N -E 6M -E 8M -E EOF \
1800 -N -E 16M -E EOF $tf-1 ||
1801 error "create mirrored file $tf-1 failed"
1802 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1803 error "create mirrored file $tf-2 failed"
1805 # write data in [0, 10M)
1806 for i in $tf $tf-1 $tf-2; do
1807 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1808 error "write $i failed"
1811 # resync the mirrored files
1812 $LFS mirror resync $tf-1 $tf-2 ||
1813 error "resync $tf-1 $tf-2 failed"
1815 # verify the mirrored files
1816 $mirror_cmd $tf-1 $tf-2 ||
1817 error "verify $tf-1 $tf-2 failed"
1819 get_mirror_ids $tf-1
1820 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1821 error "at least 2 mirror ids needed with '--only' option"
1822 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1824 error "'--only' option cannot be used upon multiple files"
1825 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1826 error "invalid specified mirror ids"
1828 # change the content of $tf and merge it into $tf-1
1830 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1831 error "change $tf with seek=$i failed"
1832 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1833 error "change $tf-1 with seek=$i failed"
1836 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1837 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1838 error "merge $tf into $tf-1 failed"
1840 # verify the mirrored files
1841 echo "Verify $tf-1 without -v option:"
1842 $mirror_cmd $tf-1 &&
1843 error "verify $tf-1 should fail" || echo "PASS"
1845 echo "Verify $tf-1 with -v option:"
1846 $mirror_cmd -v $tf-1 &&
1847 error "verify $tf-1 should fail"
1849 get_mirror_ids $tf-1
1850 echo "Verify $tf-1 with --only option:"
1851 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1852 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1853 "${mirror_array[-1]} should fail"
1855 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1856 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1857 "${mirror_array[1]} should succeed"
1859 # set stale components in $tf-1
1860 for i in 0x40002 0x40003; do
1861 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1862 error "set stale flag on component $i failed"
1865 # verify the mirrored file
1866 echo "Verify $tf-1 with stale components:"
1867 $mirror_cmd -vvv $tf-1 ||
1868 error "verify $tf-1 with stale components should succeed"
1870 echo "Verify $tf-1 with stale components and --only option:"
1871 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1872 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1873 "${mirror_array[-1]} should succeed"
1875 run_test 42 "lfs mirror verify"
1877 # inactivate one OST && write && restore the OST
1881 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1884 wait=$(do_facet $SINGLEMDS \
1885 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1886 wait=${wait%%[^0-9]*}
1888 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1889 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1890 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1891 sleep $(($wait * 2 + 2))
1892 echo " **write $file"
1893 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1894 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1895 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1896 sleep $((wait * 2 + 2))
1898 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1899 [ $flags = wp ] || error "file mirror state $flags != wp"
1903 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1905 local tf=$DIR/$tfile
1909 ## mirror 0 ost (0, 1)
1910 ## mirror 1 ost (1, 2)
1911 ## mirror 2 ost (2, 0)
1912 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1913 -N -Eeof -c2 -o2,0 $tf ||
1914 error "create 3 mirrors file $tf failed"
1916 ################## OST0 ###########################################
1918 echo " **verify components"
1919 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1920 verify_comp_attr lcme_flags $tf 0x20002 init
1921 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1924 echo " **resync $tf"
1925 $LFS mirror resync $tf
1926 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1927 [ $flags = ro ] || error "file mirror state $flags != ro"
1929 ################## OST1 ###########################################
1931 echo " **verify components"
1932 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1933 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1934 verify_comp_attr lcme_flags $tf 0x30003 init
1937 echo " **resync $tf"
1938 $LFS mirror resync $tf
1939 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1940 [ $flags = ro ] || error "file mirror state $flags != ro"
1942 ################## OST2 ###########################################
1944 echo " **verify components"
1945 verify_comp_attr lcme_flags $tf 0x10001 init
1946 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1947 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1949 run_test 43 "mirror pick on write"
1952 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1955 local tf=$DIR/$tdir/$tfile
1956 local tf1=$DIR/$tdir-1/$tfile-1
1958 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1959 error "create directory failed"
1960 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1961 error "create remote directory failed"
1962 rm -f $tf $tf1 $tf.mirror~2
1963 # create file with 4 mirrors
1964 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1965 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
1966 error "create PFLR file $tf failed"
1968 # file should be in ro status
1969 verify_flr_state $tf "ro"
1971 # write data in [0, 3M)
1972 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1973 error "writing $tf failed"
1975 verify_flr_state $tf "wp"
1977 # disallow destroying the last non-stale mirror
1978 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
1979 error "destroying mirror 1 should fail"
1981 # synchronize all mirrors of the file
1982 $LFS mirror resync $tf || error "mirror resync $tf failed"
1984 verify_flr_state $tf "ro"
1987 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1988 error "split to $tf1 failed"
1990 local idx0=$($LFS getstripe -m $tf)
1991 local idx1=$($LFS getstripe -m $tf1)
1993 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1994 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1996 # verify mirror count
1997 verify_mirror_count $tf 3
1998 verify_mirror_count $tf1 1
2000 $LFS mirror split --mirror-id 2 $tf ||
2001 error "split mirror 2 failed"
2003 verify_mirror_count $tf 2
2004 verify_mirror_count $tf.mirror~2 1
2006 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2007 error "setting stale flag on component 0x30008 failed"
2009 # disallow destroying the last non-stale mirror
2010 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2011 error "destroying mirror 4 should fail"
2013 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2015 $LFS mirror split --mirror-id 3 -d $tf ||
2016 error "destroying mirror 3 failed"
2017 verify_mirror_count $tf 1
2019 # verify splitted file contains the same content as the orig file does
2020 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2021 diff $tf $tf.mirror~2 ||
2022 error "splited file $tf.mirror~2 diffs from $tf"
2024 run_test 44 "lfs mirror split check"
2027 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2029 local file=$DIR/$tdir/$tfile
2030 local dir=$DIR/$tdir/$dir
2031 local temp=$DIR/$tdir/template
2033 test_mkdir $DIR/$tdir
2035 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2036 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2037 error "Create $file failed"
2039 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2040 rm -f $file $file.copy
2042 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2043 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2044 error "Create $file failed"
2046 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2048 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2055 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2057 local layout1=$(get_layout_param $src)
2058 local layout2=$(get_layout_param $dst)
2059 # compare their layout info
2060 [ "$layout1" == "$layout2" ] ||
2061 error "$msg_prefix $src <=> $dst layouts are not equal"
2065 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2067 local file=$DIR/$tdir/$tfile
2068 test_mkdir $DIR/$tdir
2070 ########################### 1. PFL file #############################
2071 echo " ** 1. PFL file"
2073 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2074 $file || error "1. Create PFL $file failed"
2077 verify_46 $file $file.copy "1. PFL file"
2079 ########################### 2. plain file ###########################
2080 echo " ** 2. plain file"
2082 $LFS setstripe -c2 -o0,1 -i1 $file ||
2083 error "2. Create plain $file failed"
2086 verify_46 $file $file.copy "2. plain file"
2088 ########################### 3. FLR file #############################
2089 echo " ** 3. FLR file"
2091 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2092 $file || error "3. Create FLR $file failed"
2095 verify_46 $file $file.copy "3. FLR file"
2097 local dir=$DIR/$tdir/dir
2098 ########################### 4. PFL dir ##############################
2099 echo " ** 4. PFL dir"
2101 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2102 error "4. setstripe PFL $dir failed"
2104 test_mkdir $dir.copy
2105 verify_46 $dir $dir.copy "4. PFL dir"
2107 ########################### 5. plain dir ############################
2108 echo " ** 5. plain dir"
2109 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2111 verify_46 $dir $dir.copy "5. plain dir"
2113 ########################### 6. FLR dir ##############################
2114 echo " ** 6. FLR dir"
2115 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2116 error "6. setstripe FLR $dir failed"
2118 verify_46 $dir $dir.copy "6. FLR dir"
2120 ########################### 7. SEL file ##############################
2121 echo " ** 7. SEL file"
2123 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2124 $file || error "Create $file failed"
2127 verify_46 $file $file.copy "7. SEL file"
2129 ########################### 8. SEL dir ##############################
2130 echo " ** 8. SEL dir"
2131 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2132 $dir || error "setstripe $dir failed"
2134 verify_46 $dir $dir.copy "8. SEL dir"
2136 ########################### 9. FLR SEL file ##########################
2137 echo " ** 9. FLR SEL file"
2139 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2140 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2143 verify_46 $file $file.copy "9. SEL file"
2145 ########################### 10. FLR SEL dir #########################
2146 echo " ** 10. FLR SEL dir"
2147 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2148 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2150 verify_46 $dir $dir.copy "10. SEL dir"
2152 run_test 46 "Verify setstripe --copy option"
2155 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2157 local file=$DIR/$tdir/$tfile
2162 test_mkdir $DIR/$tdir
2166 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2167 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2168 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2169 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2170 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2172 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2173 $LFS mirror resync $file || error "resync $file failed"
2175 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2176 if [[ x$ost == "x0," ]]; then
2177 $LFS getstripe $file
2178 error "component ${ids[2]} objects allocated on $ost " \
2182 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2183 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2184 $LFS getstripe $file
2185 error "component ${ids[3]} objects allocated on $ost " \
2186 "shouldn't on OST1 or on OST2"
2191 # mirror1: [comp0] [comp1]
2192 # mirror2: [comp2] [comp3]
2193 # mirror3: [comp4] [comp5]
2194 # mirror4: [comp6] [comp7]
2195 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2196 error "create FLR $file failed"
2197 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2199 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2200 $LFS mirror resync $file || error "resync $file failed"
2202 for ((i = 0; i < 6; i++)); do
2203 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2204 awk '/l_ost_idx/{print $5}')
2206 # comp[0],comp[2],comp[4] should use different osts
2207 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2208 ${osts[2]} == ${osts[4]} ]]; then
2209 $LFS getstripe $file
2210 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2211 "allocated on duplicated OSTs"
2213 # comp[1],comp[3],comp[5] should use different osts
2214 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2215 ${osts[3]} == ${osts[5]} ]]; then
2216 $LFS getstripe $file
2217 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2218 "allocated on duplicated OSTs"
2223 run_test 47 "Verify mirror obj alloc"
2226 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2227 skip "Need MDS version at least 2.11.55"
2229 local tf=$DIR/$tfile
2232 echo " ** create 2 mirrors FLR file $tf"
2233 $LFS mirror create -N -E2M -Eeof --flags prefer \
2234 -N -E1M -Eeof $tf ||
2235 error "create FLR file $tf failed"
2238 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2239 verify_flr_state $tf "wp"
2241 local sum0=$(md5sum < $tf)
2243 echo " ** resync the file"
2244 $LFS mirror resync $tf
2246 echo " ** snapshot mirror 2"
2247 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2249 echo " ** write it again"
2250 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2251 echo " ** resync it again"
2252 $LFS mirror resync $tf
2254 verify_flr_state $tf "wp"
2255 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2257 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2258 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2260 echo " ** verify mirror 2 doesn't change"
2261 echo "original checksum: $sum0"
2262 echo "mirror 1 checksum: $sum1"
2263 echo "mirror 2 checksum: $sum2"
2264 [[ $sum0 = $sum2 ]] ||
2265 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2266 echo " ** mirror 2 stripe info"
2267 $LFS getstripe -v --mirror-index=2 $tf
2269 echo " ** resync mirror 2"
2270 $LFS mirror resync --only 2 $tf
2272 verify_flr_state $tf "ro"
2273 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2275 sum1=$($LFS mirror read -N1 $tf | md5sum)
2276 sum2=$($LFS mirror read -N2 $tf | md5sum)
2278 echo " ** verify mirror 2 resync-ed"
2279 echo "original checksum: $sum0"
2280 echo "mirror 1 checksum: $sum1"
2281 echo "mirror 2 checksum: $sum2"
2282 [[ $sum1 = $sum2 ]] ||
2283 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2284 echo " ** mirror 2 stripe info"
2285 $LFS getstripe -v --mirror-index=2 $tf
2287 run_test 48 "Verify snapshot mirror"
2296 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
2298 trap cleanup_49 EXIT RETURN
2300 local file=$DIR/$tfile
2302 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2303 error "setstripe on $file"
2305 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2306 $LFS mirror resync $file
2308 filefrag -ves $file || error "filefrag $file failed"
2309 filefrag_op=$(filefrag -ve -k $file |
2310 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2312 #Filesystem type is: bd00bd0
2313 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2314 # ext: device_logical: physical_offset: length: dev: flags:
2315 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2316 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2317 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2319 last_lun=$(echo $filefrag_op | cut -d: -f5)
2323 for line in $filefrag_op; do
2324 frag_lun=$(echo $line | cut -d: -f5)
2325 ext_len=$(echo $line | cut -d: -f4)
2326 if [[ "$frag_lun" != "$last_lun" ]]; then
2327 if (( tot_len != 1024 )); then
2329 error "$file: OST$last_lun $tot_len != 1024"
2335 (( tot_len += ext_len ))
2338 if (( num_luns != 2 || tot_len != 1024 )); then
2340 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2343 echo "FIEMAP on $file succeeded"
2345 run_test 49a "FIEMAP upon FLR file"
2347 test_50() { # EX-2179
2350 local file=$DIR/$tdir/$tfile
2352 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2354 $LFS mirror extend -N -c1 -i1 $file ||
2355 error "extending mirror for $file failed"
2357 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2361 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2363 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2365 echo "$file layout generation from $olv to $flv"
2366 (( $flv != ($olv + 1) )) &&
2367 error "split does not increase layout gen from $olv to $flv"
2369 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2371 $LFS getstripe -v $file || error "getstripe $file failed"
2373 run_test 50 "mirror split update layout generation"
2375 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
2376 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
2381 local fsize=$(stat --printf=%s $tf)
2383 while [ -f $ctrl_file ]; do
2384 local off=$((RANDOM << 8))
2385 local len=$((RANDOM << 5 + 131072))
2387 [ $((off + len)) -gt $fsize ] && {
2388 fsize=$((off + len))
2389 echo "Extending file size to $fsize .."
2392 flock -s $lock_file -c \
2393 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
2395 error "failed writing to $off:$len"; }
2396 sleep 0.$((RANDOM % 2 + 1))
2403 while [ -f $ctrl_file ]; do
2404 flock -s $lock_file -c "cat $tf &> /dev/null" ||
2405 { rm -f $ctrl_file; error "read failed"; }
2406 sleep 0.$((RANDOM % 2 + 1))
2413 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
2415 exec 200<>$lock_file
2416 while [ -f $ctrl_file ]; do
2417 local lock_taken=false
2418 local index=$((RANDOM % ${#options[@]}))
2419 local cmd="mirror_io resync ${options[$index]}"
2421 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
2423 [ $((RANDOM % 4)) -eq 0 ] && {
2429 echo -n "resync file $tf with '$cmd' .."
2431 if [[ $lock_taken = "true" ]]; then
2432 flock -x 200 -c "$cmd $tf &> /dev/null" &&
2433 echo "done" || echo "failed"
2436 $cmd $tf &> /dev/null && echo "done" || echo "failed"
2439 sleep 0.$((RANDOM % 8 + 1))
2444 local tf=$DIR/$tfile
2445 local tf2=$DIR2/$tfile
2446 local tf3=$DIR3/$tfile
2448 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
2449 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
2450 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
2452 $LFS mirror extend -N -f $tf-2 $tf ||
2453 error "merging $tf-2 into $tf failed"
2454 $LFS mirror extend -N -f $tf-3 $tf ||
2455 error "merging $tf-3 into $tf failed"
2457 mkdir -p $MOUNT2 && mount_client $MOUNT2
2459 mkdir -p $MOUNT3 && mount_client $MOUNT3
2461 verify_flr_state $tf3 "ro"
2463 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
2464 $LCTL set_param fail_loc=0x1A03
2466 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
2467 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
2471 write_file_200 $tf &
2477 write_file_200 $tf2 &
2480 read_file_200 $tf2 &
2483 resync_file_200 $tf3 &
2487 [ "$SLOW" = "yes" ] && sleep_time=360
2488 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
2495 echo "Waiting ${pids[@]}"
2498 umount_client $MOUNT2
2499 umount_client $MOUNT3
2503 # resync and verify mirrors
2504 mirror_io resync $tf
2507 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
2508 for id in ${mirror_array[@]:1}; do
2509 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
2510 error "checksum error for mirror $id"
2515 run_test 200 "stress test"
2517 cleanup_test_201() {
2519 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
2521 umount_client $MOUNT2
2525 local delay=${RESYNC_DELAY:-5}
2527 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
2528 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
2530 trap cleanup_test_201 EXIT
2532 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
2533 changelog_register -n)
2535 mkdir -p $MOUNT2 && mount_client $MOUNT2
2539 local log=$($LFS changelog $MDT0 $index | grep FLRW)
2540 [ -z "$log" ] && { sleep 1; continue; }
2542 index=$(echo $log | awk '{print $1}')
2543 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
2544 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
2545 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
2548 [ -z "$file" ] && continue
2550 local now=$(date +%s)
2552 echo "file: $file $fid was modified at $ts, now: $now, " \
2553 "will be resynced at $((ts+delay))"
2555 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
2557 mirror_io resync $file
2558 echo "$file resync done"
2563 run_test 201 "FLR data mover"
2566 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
2568 local tf=$DIR/$tfile
2571 $LFS setstripe -E 1M -S 1M -c 1 $tf
2572 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2573 verify_comp_attr stripe-count $tf ${ids[0]} 1
2575 $LFS setstripe --component-add -E 2M -c -1 $tf
2576 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2577 verify_comp_attr stripe-count $tf ${ids[0]} 1
2578 verify_comp_attr stripe-count $tf ${ids[1]} -1
2580 dd if=/dev/zero of=$tf bs=1M count=2
2581 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2582 verify_comp_attr stripe-count $tf ${ids[0]} 1
2583 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
2585 run_test 202 "lfs setstripe --add-component wide striping"
2588 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2589 skip "Need MDS version at least 2.11.55"
2590 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
2592 local tf=$DIR/$tfile
2595 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
2596 #delete first mirror
2597 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
2600 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
2601 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2602 error "getstripe count of mirror 2"
2603 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2605 #extend a mirror with 2 OSTs
2606 $LFS mirror extend -N -c2 $tf || error "extend mirror"
2609 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
2610 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2611 error "getstripe count of mirror 2"
2612 [[ x$oldid = x$newid ]] ||
2613 error "mirror 2 changed ID from $old_id to $new_id"
2614 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2616 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
2617 error "getstripe count of mirror 3"
2618 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
2620 run_test 203 "mirror file preserve mirror ID"
2622 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
2624 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2625 skip "skipped for lustre < $SEL_VER"
2627 local comp_file=$DIR/$tdir/$tfile
2631 test_mkdir $DIR/$tdir
2633 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
2634 # by extension space to -1
2635 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
2636 error "Create $comp_file failed"
2638 # Write to first component, extending & staling second mirror
2639 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2640 error "dd to extend + stale failed"
2642 $LFS getstripe $comp_file
2644 flg_opts="--component-flags init,stale"
2645 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2646 [ $found -eq 1 ] || error "write: Second comp end incorrect"
2648 flg_opts="--component-flags extension"
2649 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2650 [ $found -eq 1 ] || error "write: Third comp start incorrect"
2652 # mirror resync should not change the extents
2653 $LFS mirror resync $comp_file
2655 flg_opts="--component-flags init"
2656 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2657 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
2659 flg_opts="--component-flags extension"
2660 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2661 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
2663 sel_layout_sanity $comp_file 5
2667 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
2669 # Simple test of FLR + self-extending layout, SEL in primary mirror
2671 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2672 skip "skipped for lustre < $SEL_VER"
2674 local comp_file=$DIR/$tdir/$tfile
2678 test_mkdir $DIR/$tdir
2680 # first mirror is 1M followed by extension space to -1, second mirror
2681 # is 0-10M, then 10M-(-1),
2682 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2683 error "Create $comp_file failed"
2685 # Write to first component, extending first component & staling
2687 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2688 error "dd to extend + stale failed"
2690 $LFS getstripe $comp_file
2692 flg_opts="--component-flags init"
2693 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2694 [ $found -eq 1 ] || error "write: First comp end incorrect"
2696 flg_opts="--component-flags extension"
2697 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2698 [ $found -eq 1 ] || error "write: Second comp start incorrect"
2700 flg_opts="--component-flags init,stale"
2701 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2702 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
2704 # This component is staled because it overlaps the extended first
2705 # component of the primary mirror, even though it doesn't overlap
2706 # the actual write - thus not inited.
2707 flg_opts="--component-flags stale"
2708 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2709 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
2711 # mirror resync should not change the extents
2712 $LFS mirror resync $comp_file
2714 $LFS getstripe $comp_file
2716 flg_opts="--component-flags init"
2717 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2718 [ $found -eq 1 ] || error "resync: First comp end incorrect"
2720 flg_opts="--component-flags extension"
2721 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2722 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
2724 flg_opts="--component-flags init"
2725 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2726 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
2728 flg_opts="--component-flags init"
2729 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2730 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
2732 sel_layout_sanity $comp_file 5
2736 run_test 204b "FLR write/stale/resync tests with self-extending primary"
2738 # FLR + SEL failed extension & component removal
2739 # extension space in second mirror
2741 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2742 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2743 skip "skipped for lustre < $SEL_VER"
2745 local comp_file=$DIR/$tdir/$tfile
2748 local ost_name=$(ostname_from_index $ost_idx1)
2750 test_mkdir $DIR/$tdir
2752 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
2753 # extension space from 1M to 1G, then normal space to -1
2754 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
2755 -E -1 $comp_file || error "Create $comp_file failed"
2757 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
2760 # write to first comp (0 - 10M) of mirror 1, extending + staling
2761 # first + second comp of mirror 2
2762 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2765 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
2768 [ $RC -eq 0 ] || error "dd to extend + stale failed"
2770 $LFS getstripe $comp_file
2772 found=$($LFS find --component-start 0m --component-end 1m \
2773 --comp-flags init,stale $comp_file | wc -l)
2774 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2776 found=$($LFS find --component-start 1m --component-end EOF \
2777 --comp-flags stale,^init $comp_file | wc -l)
2778 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
2780 local mirror_id=$($LFS getstripe --component-start=1m \
2781 --component-end=EOF $comp_file | \
2782 grep lcme_mirror_id | awk '{ print $2 }')
2784 [[ $mirror_id -eq 2 ]] ||
2785 error "component not in correct mirror? $mirror_id"
2787 $LFS mirror resync $comp_file
2789 $LFS getstripe $comp_file
2791 # component dimensions should not change from resync
2792 found=$($LFS find --component-start 1m --component-end EOF \
2793 --component-flags init $comp_file | wc -l)
2794 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
2796 sel_layout_sanity $comp_file 4
2800 run_test 204c "FLR write/stale/resync test with component removal"
2802 # Successful repeated component in primary mirror
2804 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2805 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2806 skip "skipped for lustre < $SEL_VER"
2808 local comp_file=$DIR/$tdir/$tfile
2811 wait_delete_completed
2813 test_mkdir $DIR/$tdir
2815 # first mirror is 64M followed by extension space to -1, second mirror
2816 # is 0-10M, then 10M-(-1)
2817 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2818 error "Create $comp_file failed"
2820 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
2821 local ost_name=$(ostname_from_index $ost_idx1)
2822 # degrade OST for first comp so we won't extend there
2823 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2824 obdfilter.$ost_name.degraded=1
2827 # Write beyond first component, causing repeat & stale second mirror
2828 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
2831 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2832 obdfilter.$ost_name.degraded=0
2835 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2837 $LFS getstripe $comp_file
2839 found=$($LFS find --component-start 64m --component-end 128m \
2840 --component-flags init $comp_file | wc -l)
2841 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
2843 local ost_idx2=$($LFS getstripe --component-start=64m \
2844 --component-end=128m --component-flags=init \
2846 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2847 local mirror_id=$($LFS getstripe --component-start=64m \
2848 --component-end=128m --component-flags=init \
2849 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2850 [[ $mirror_id -eq 1 ]] ||
2851 error "component not in correct mirror: $mirror_id, not 1"
2853 $LFS mirror resync $comp_file
2855 $LFS getstripe $comp_file
2857 # component dimensions should not change from resync
2858 found=$($LFS find --component-start 0m --component-end 64m \
2859 --component-flags init $comp_file | wc -l)
2860 [ $found -eq 1 ] || error "resync: first comp incorrect"
2861 found=$($LFS find --component-start 64m --component-end 128m \
2862 --component-flags init $comp_file | wc -l)
2863 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
2865 sel_layout_sanity $comp_file 5
2869 run_test 204d "FLR write/stale/resync sel test with repeated comp"
2871 # Successful repeated component, SEL in non-primary mirror
2873 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2874 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2875 skip "skipped for lustre < $SEL_VER"
2877 local comp_file=$DIR/$tdir/$tfile
2880 wait_delete_completed
2883 test_mkdir $DIR/$tdir
2885 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2886 # space to -1 (-z 64M, so first comp is 0-64M)
2887 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
2888 # will be not enough - one will be degraded, the other is used on
2889 # an overlapping mirror.
2890 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
2891 error "Create $comp_file failed"
2893 local ost_idx1=$($LFS getstripe --component-start=0 \
2894 --component-end=64m -i $comp_file)
2895 local ost_name=$(ostname_from_index $ost_idx1)
2896 # degrade OST for first comp of 2nd mirror so we won't extend there
2897 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2898 obdfilter.$ost_name.degraded=1
2901 $LFS getstripe $comp_file
2903 # Write to first component, stale & instantiate second mirror components
2904 # overlapping with the written component (0-100M);
2905 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2908 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2909 obdfilter.$ost_name.degraded=0
2911 $LFS getstripe $comp_file
2913 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2915 found=$($LFS find --component-start 0m --component-end 64m \
2916 --component-flags init,stale $comp_file | wc -l)
2917 [ $found -eq 1 ] || error "write: first comp incorrect"
2919 # was repeated due to degraded ost
2920 found=$($LFS find --component-start 64m --component-end 128m \
2921 --component-flags init,stale $comp_file | wc -l)
2922 [ $found -eq 1 ] || error "write: repeated comp incorrect"
2924 local ost_idx2=$($LFS getstripe --component-start=64m \
2925 --component-end=128m --component-flags=init \
2927 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2928 local mirror_id=$($LFS getstripe --component-start=0m \
2929 --component-end=64m --component-flags=init \
2930 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2931 [[ $mirror_id -eq 2 ]] ||
2932 error "component not in correct mirror? $mirror_id"
2934 $LFS mirror resync $comp_file
2936 $LFS getstripe $comp_file
2938 # component dimensions should not change from resync
2939 found=$($LFS find --component-start 0m --component-end 64m \
2940 --component-flags init,^stale $comp_file | wc -l)
2941 [ $found -eq 1 ] || error "resync: first comp incorrect"
2942 found=$($LFS find --component-start 64m --component-end 128m \
2943 --component-flags init,^stale $comp_file | wc -l)
2944 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
2946 sel_layout_sanity $comp_file 5
2950 run_test 204e "FLR write/stale/resync sel test with repeated comp"
2952 # FLR + SEL: failed repeated component, SEL in non-primary mirror
2954 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2955 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2956 skip "skipped for lustre < $SEL_VER"
2958 local comp_file=$DIR/$tdir/$tfile
2961 wait_delete_completed
2963 test_mkdir $DIR/$tdir
2965 pool_add $TESTNAME || error "Pool creation failed"
2966 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
2968 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2969 # space to -1 (-z 64M, so first comp is 0-64M)
2970 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
2971 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
2973 local ost_name0=$(ostname_from_index 0)
2974 local ost_name1=$(ostname_from_index 1)
2976 # degrade both OSTs in pool, so we'll try to repeat, then fail and
2977 # extend original comp
2978 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
2979 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
2982 # a write to the 1st component, 100M length, which will try to stale
2983 # the first 100M of mirror 2, attempting to extend its 0-64M component
2984 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2987 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
2988 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
2991 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
2993 $LFS getstripe $comp_file
2995 found=$($LFS find --component-start 0m --component-end 128m \
2996 --component-flags init,stale $comp_file | wc -l)
2997 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2999 local mirror_id=$($LFS getstripe --component-start=0m \
3000 --component-end=128m --component-flags=init \
3001 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3003 [[ $mirror_id -eq 2 ]] ||
3004 error "component not in correct mirror? $mirror_id, not 2"
3006 $LFS mirror resync $comp_file
3008 $LFS getstripe $comp_file
3010 # component dimensions should not change from resync
3011 found=$($LFS find --component-start 0m --component-end 128m \
3012 --component-flags init,^stale $comp_file | wc -l)
3013 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
3015 sel_layout_sanity $comp_file 4
3019 run_test 204f "FLR write/stale/resync sel w/forced extension"
3021 function test_205() {
3022 local tf=$DIR/$tfile
3025 $LFS setstripe -c1 $tf
3026 $LFS mirror extend -N $tf
3027 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
3028 (( $mirrors == 2 )) || error "no new mirror was created?"
3030 $LFS mirror extend -N --flags=prefer $tf
3031 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
3032 (( $mirrors == 3 )) || error "no new mirror was created?"
3034 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
3035 error "prefer flag was not set on the new mirror"
3037 run_test 205 "lfs mirror extend to set prefer flag"
3039 function test_206() {
3040 # create a new OST pool
3041 local pool_name=$TESTNAME
3043 create_pool $FSNAME.$pool_name ||
3044 error "create OST pool $pool_name failed"
3045 # add OSTs into the pool
3046 pool_add_targets $pool_name 0 1 ||
3047 error "add OSTs into pool $pool_name failed"
3049 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
3050 error "can't setstripe"
3051 $LFS mirror extend -N $DIR/$tfile ||
3052 error "can't create replica"
3053 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
3054 $LFS getstripe $DIR/$tfile
3055 error "prefer found"
3057 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
3058 $LFS getstripe $DIR/$tfile
3059 error "can't setstripe prefer"
3062 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
3063 $LFS getstripe $DIR/$tfile
3064 error "no prefer found"
3070 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
3073 local file=$DIR/$tfile
3074 local tmpfile=$DIR/$tfile-tt
3076 [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
3077 skip "Need MDS version at least 2.14.50"
3079 stack_trap "rm -f $tmpfile $file"
3081 # generate data for verification
3082 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
3083 error "can't generate file with random data"
3085 # create a mirrored file with one stale replica
3086 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
3087 error "create mirrored file $file failed"
3088 get_mirror_ids $file
3089 echo "mirror IDs: ${mirror_array[@]}"
3091 dd if=$tmpfile of=$file bs=1M || error "can't copy"
3092 get_mirror_ids $file
3093 echo "mirror IDs: ${mirror_array[@]}"
3096 cmp $tmpfile $file || error "files don't match"
3097 get_mirror_ids $file
3098 echo "mirror IDs: ${mirror_array[@]}"
3100 # mirror creation should work fine
3101 $LFS mirror extend -N -S 8M -c -1 $file ||
3102 error "mirror extend $file failed"
3104 get_mirror_ids $file
3105 echo "mirror IDs: ${mirror_array[@]}"
3108 $LFS mirror verify -v $file || error "verification failed"
3109 cmp $tmpfile $file || error "files don't match"
3111 run_test 207 "create another replica with existing out-of-sync one"
3114 check_and_cleanup_lustre