3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
16 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT "
17 # Bug number for skipped test: LU-14818 LU-11381 LU-14765
18 ALWAYS_EXCEPT+=" 6 201 44c "
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
21 # skip all tests for PPC until we can get sanity-pfl to pass
22 if [[ $(uname -m) = ppc64 ]]; then
23 skip "Skip FLR testing for PPC clients"
26 if [[ "$ost1_FSTYPE" == "zfs" ]]; then
28 ALWAYS_EXCEPT+=" 49a "
31 if [ -r /etc/redhat-release ]; then
32 rhel_version=$(cat /etc/redhat-release |
33 sed -e 's/^[^0-9.]*//g' | sed -e 's/[ ].*//')
34 if (( $(version_code $rhel_version) >= $(version_code 9.3.0) )); then
35 always_except LU-17675 61a
41 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
42 skip "Need MDS version at least 2.10.56"
44 check_and_setup_lustre
47 rm -rf $DIR/[Rdfs][0-9]*
49 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
50 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
52 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
55 # global array to store mirror IDs
56 declare -a mirror_array
63 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
64 array[${#array[@]}]=$((id >> 16))
67 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
69 echo ${#mirror_array[@]}
73 echo 3 > /proc/sys/vm/drop_caches
84 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
92 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
93 error "start ost$idx failed"
97 wait_recovery_complete ost$idx
102 # Verify mirror count with an expected value for a given file.
104 verify_mirror_count() {
107 local mirror_count=$($LFS getstripe -N $tf)
109 [[ $mirror_count = $expected ]] || {
110 $LFS getstripe -v $tf
111 error "verify mirror count failed on $tf:" \
112 "$mirror_count != $expected"
117 # Verify component count with an expected value for a given file.
118 # $1 coposited layout file
119 # $2 expected component number
121 verify_comp_count() {
124 local comp_count=$($LFS getstripe --component-count $tf)
126 [[ $comp_count = $expected ]] || {
127 $LFS getstripe -v $tf
128 error "verify component count failed on $tf:" \
129 "$comp_count != $expected"
134 # Verify component attribute with an expected value for a given file
142 local cmd="$LFS getstripe -I$comp_id"
143 local getstripe_cmd="$cmd -v"
147 stripe-size) cmd+=" -S $tf" ;;
148 stripe-count) cmd+=" -c $tf" ;;
149 stripe-index) cmd+=" -i $tf" ;;
150 pool) cmd+=" -p $tf" ;;
151 comp-start) cmd+=" --component-start $tf" ;;
152 comp-end) cmd+=" --component-end $tf" ;;
153 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
154 *) error "invalid attribute $attr";;
159 [ $attr = lcme_flags ] && {
161 local expected_list=$(comma_list $expected)
162 for fl in ${expected_list//,/ }; do
165 [[ ${fl:0:1} = "^" ]] && neg=1
166 [[ $neg = 1 ]] && fl=${fl:1}
168 $(echo $value | grep -q $fl)
170 # 0: matched; 1: not matched
172 if [[ $neg = 0 && $match != 0 ||
173 $neg = 1 && $match = 0 ]]; then
175 [[ $neg = 0 ]] && # expect the flag
176 error "expected flag '$fl' not in $comp_id"
177 [[ $neg = 1 ]] && # not expect the flag
178 error "not expected flag '$fl' in $comp_id"
184 [[ $value = $expected ]] ||
185 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
186 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
188 error "verify $attr failed on $tf: $value != $expected"
193 # Verify component extent with expected start and end extent values
194 # for a given file and component ID.
196 verify_comp_extent() {
199 local expected_start=$3
200 local expected_end=$4
202 verify_comp_attr comp-start $tf $comp_id $expected_start
203 verify_comp_attr comp-end $tf $comp_id $expected_end
207 # Verify component attribute with parent directory for a given file
210 verify_comp_attr_with_parent() {
214 local td=$(cd $(dirname $tf); echo $PWD)
215 local tf_cmd="$LFS getstripe -I$comp_id"
216 local td_cmd="$LFS getstripe"
222 stripe-size) opt="-S" ;;
223 stripe-count) opt="-c" ;;
225 *) error "invalid attribute $attr";;
228 expected=$($td_cmd $opt $td)
229 [[ $expected = -1 ]] && expected=$OSTCOUNT
231 value=$($tf_cmd $opt $tf)
232 [[ $value = -1 ]] && value=$OSTCOUNT
234 [[ $value = $expected ]] ||
235 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
236 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
239 error "verify $attr failed with parent on $tf:" \
240 "$value != $expected"
245 # Verify component attribute with filesystem-wide default value for a given file
248 verify_comp_attr_with_default() {
252 local tf_cmd="$LFS getstripe -I$comp_id"
260 expected=$($LCTL get_param -n \
261 lov.$FSNAME-clilov-*.stripesize)
265 expected=$($LCTL get_param -n \
266 lov.$FSNAME-clilov-*.stripecount)
267 [[ $expected = -1 ]] && expected=$OSTCOUNT
269 *) error "invalid attribute $attr";;
272 value=$($tf_cmd $opt $tf)
273 [[ $value = -1 ]] && value=$OSTCOUNT
275 [[ $value = $expected ]] ||
276 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
277 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
279 error "verify $attr failed with default value on $tf:" \
280 "$value != $expected"
285 # Verify unspecified component attributes for a given file
288 # This will only verify the inherited attributes:
289 # stripe size, stripe count and OST pool name
291 verify_comp_attrs() {
295 verify_comp_attr_with_default stripe-size $tf $comp_id
296 verify_comp_attr_with_default stripe-count $tf $comp_id
297 verify_comp_attr_with_parent pool $tf $comp_id
303 local expected_state=$2
305 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
306 [ $expected_state = $state ] ||
307 error "expected: $expected_state, actual $state"
310 # command line test cases
314 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
315 local mirror_cmd="$LFS mirror create"
320 # create parent directory
321 mkdir $td || error "mkdir $td failed"
323 $mirror_cmd $tf &> /dev/null && error "miss -N option"
325 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
326 verify_mirror_count $tf 1
327 id=$($LFS getstripe -I $tf)
328 verify_comp_attrs $tf $id
329 verify_comp_extent $tf $id 0 EOF
331 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
332 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
333 error "invalid mirror count $((mirror_count + 1))"
335 $mirror_cmd -N$mirror_count $tf-1 ||
336 error "create mirrored file $tf-1 failed"
337 verify_mirror_count $tf-1 $mirror_count
338 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
339 for ((i = 0; i < $mirror_count; i++)); do
340 verify_comp_attrs $tf-1 ${ids[$i]}
341 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
344 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
345 error "create mirrored file $tf-2 failed"
346 verify_mirror_count $tf-2 10
347 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
348 for ((i = 0; i < 10; i++)); do
349 verify_comp_attrs $tf-2 ${ids[$i]}
350 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
353 run_test 0a "lfs mirror create with -N option"
356 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
360 local mirror_cmd="$LFS mirror create"
364 # create a new OST pool
365 local pool_name=$TESTNAME
366 create_pool $FSNAME.$pool_name ||
367 error "create OST pool $pool_name failed"
369 # add OSTs into the pool
370 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
371 error "add OSTs into pool $pool_name failed"
373 # create parent directory
374 mkdir $td || error "mkdir $td failed"
375 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
376 error "$LFS setstripe $td failed"
378 create_pool $FSNAME.flash || error "create OST pool flash failed"
379 create_pool $FSNAME.archive || error "create OST pool archive failed"
381 # create a mirrored file with plain layout mirrors
382 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
383 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
384 error "create mirrored file $tf failed"
385 verify_mirror_count $tf 6
386 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
387 for ((i = 0; i < 6; i++)); do
388 verify_comp_extent $tf ${ids[$i]} 0 EOF
391 # verify component ${ids[0]}
392 verify_comp_attrs $tf ${ids[0]}
394 # verify component ${ids[1]}
395 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
396 verify_comp_attr stripe-count $tf ${ids[1]} 2
397 verify_comp_attr stripe-index $tf ${ids[1]} 2
399 # verify component ${ids[2]}
400 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
401 verify_comp_attr stripe-count $tf ${ids[2]} 2
402 verify_comp_attr pool $tf ${ids[2]} flash
404 # verify component ${ids[3]}
405 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
406 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
407 verify_comp_attr pool $tf ${ids[3]} flash
409 # verify component ${ids[4]}
410 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
411 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
412 verify_comp_attr pool $tf ${ids[4]} archive
414 # verify component ${ids[5]}
415 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
416 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
417 verify_comp_attr_with_parent pool $tf ${ids[5]}
419 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
420 # LU-11022 - remove mirror by pool name
421 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
422 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
423 $LFS mirror delete --pool archive $tf || error "delete mirror"
424 cnt=$($LFS getstripe $tf | grep archive | wc -l)
425 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
431 run_test 0b "lfs mirror create plain layout mirrors"
434 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
438 local mirror_cmd="$LFS mirror create"
442 # create a new OST pool
443 local pool_name=$TESTNAME
444 create_pool $FSNAME.$pool_name ||
445 error "create OST pool $pool_name failed"
447 # add OSTs into the pool
448 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
449 error "add OSTs into pool $pool_name failed"
451 # create parent directory
452 mkdir $td || error "mkdir $td failed"
453 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
454 error "$LFS setstripe $td failed"
456 create_pool $FSNAME.flash ||
457 error "create OST pool flash failed"
458 create_pool $FSNAME.archive ||
459 error "create OST pool archive failed"
461 # create a mirrored file with composite layout mirrors
462 $mirror_cmd -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
464 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
465 error "create mirrored file $tf failed"
466 verify_mirror_count $tf 6
467 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
469 # verify components ${ids[0]} and ${ids[2]}
471 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
472 verify_comp_attr stripe-count $tf ${ids[$i]} 2
473 verify_comp_attr stripe-index $tf ${ids[$i]} 1
474 verify_comp_extent $tf ${ids[$i]} 0 8388608
477 # verify components ${ids[1]} and ${ids[3]}
479 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
480 verify_comp_attr stripe-count $tf ${ids[$i]} 2
481 verify_comp_attr pool $tf ${ids[$i]} flash
482 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
485 # verify component ${ids[4]}
486 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
487 verify_comp_attr stripe-count $tf ${ids[4]} 4
488 verify_comp_attr_with_parent pool $tf ${ids[4]}
489 verify_comp_extent $tf ${ids[4]} 0 EOF
491 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
493 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
494 verify_comp_attr stripe-count $tf ${ids[$i]} 4
495 verify_comp_attr pool $tf ${ids[$i]} archive
496 verify_comp_extent $tf ${ids[$i]} 0 536870912
499 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
501 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
502 # ffdf which is -33 and matches LOV_ALL_STRIPES_MIN
503 local decimal_lov_lower_limit=-33
504 #C_opt is -c option which can be -1 to -32
506 local count_exp=$(($decimal_lov_lower_limit + $C_opt + 1))
508 verify_comp_attr stripe-count $tf ${ids[$i]} $count_exp
509 verify_comp_attr pool $tf ${ids[$i]} archive
510 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
516 run_test 0c "lfs mirror create composite layout mirrors"
521 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
522 local mirror_cmd="$LFS mirror extend"
526 # create parent directory
527 mkdir $td || error "mkdir $td failed"
529 $mirror_cmd $tf &> /dev/null && error "miss -N option"
530 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
532 # create a non-mirrored file, convert it to a mirrored file and extend
533 touch $tf || error "touch $tf failed"
534 $mirror_cmd -N $tf || error "convert and extend $tf failed"
535 verify_mirror_count $tf 2
536 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
537 for ((i = 0; i < 2; i++)); do
538 verify_comp_attrs $tf ${ids[$i]}
539 verify_comp_extent $tf ${ids[$i]} 0 EOF
542 lfsck_verify_pfid $tf || error "PFID is not set"
544 # create a mirrored file and extend it
545 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
546 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
547 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
549 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
550 error "extend mirror with -f failed"
552 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
553 error "extend mirrored file $tf-3 failed"
554 verify_mirror_count $tf-3 $mirror_count
555 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
556 for ((i = 0; i < $mirror_count; i++)); do
557 verify_comp_attrs $tf-3 ${ids[$i]}
558 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
561 $mirror_cmd -N $tf-3 &> /dev/null
563 (( $rc == 34 || $MDS1_VERSION < $(version_code v2_14_57-72-gf468093cb6) )) ||
564 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
566 run_test 0d "lfs mirror extend with -N option"
569 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
573 local mirror_cmd="$LFS mirror extend"
577 # create parent directory
578 mkdir $td || error "mkdir $td failed"
580 create_pool $FSNAME.ssd ||
581 error "create OST pool ssd failed"
583 # create a mirrored file with plain layout mirrors
584 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
585 error "create mirrored file $tf failed"
587 create_pool $FSNAME.flash ||
588 error "create OST pool flash failed"
589 create_pool $FSNAME.archive ||
590 error "create OST pool archive failed"
592 # extend the mirrored file with plain layout mirrors
593 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
594 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
595 error "extend mirrored file $tf failed"
596 verify_mirror_count $tf 6
597 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
598 for ((i = 0; i < 6; i++)); do
599 verify_comp_extent $tf ${ids[$i]} 0 EOF
602 # verify component ${ids[0]}
603 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
604 verify_comp_attr stripe-count $tf ${ids[0]} 3
605 verify_comp_attr stripe-index $tf ${ids[0]} 1
607 # verify component ${ids[1]}
608 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
609 verify_comp_attr stripe-count $tf ${ids[1]} 2
610 verify_comp_attr stripe-index $tf ${ids[1]} 2
612 # verify component ${ids[2]}
613 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
614 verify_comp_attr stripe-count $tf ${ids[2]} 2
615 verify_comp_attr pool $tf ${ids[2]} flash
617 # verify component ${ids[3]}
618 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
619 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
620 verify_comp_attr pool $tf ${ids[3]} flash
622 # verify component ${ids[4]}
623 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
624 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
625 verify_comp_attr pool $tf ${ids[4]} archive
627 # verify component ${ids[5]}
628 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
629 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
630 verify_comp_attr_with_parent pool $tf ${ids[5]}
632 run_test 0e "lfs mirror extend plain layout mirrors"
635 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
639 local mirror_cmd="$LFS mirror extend"
643 # create parent directory
644 mkdir $td || error "mkdir $td failed"
646 create_pool $FSNAME.ssd ||
647 error "create OST pool ssd failed"
649 # create a mirrored file with composite layout mirror
650 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
651 error "create mirrored file $tf failed"
653 create_pool $FSNAME.flash ||
654 error "create OST pool flash failed"
655 create_pool $FSNAME.archive ||
656 error "create OST pool archive failed"
658 # extend the mirrored file with composite layout mirrors
659 $mirror_cmd -N -p archive \
660 -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
662 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
663 error "extend mirrored file $tf failed"
664 verify_mirror_count $tf 8
665 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
667 # verify component ${ids[0]}
668 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
669 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
670 verify_comp_attr pool $tf ${ids[0]} ssd
671 verify_comp_extent $tf ${ids[0]} 0 33554432
673 # verify component ${ids[1]}
674 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
675 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
676 verify_comp_attr pool $tf ${ids[1]} ssd
677 verify_comp_extent $tf ${ids[1]} 33554432 EOF
679 # verify component ${ids[2]}
680 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
681 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
682 verify_comp_attr pool $tf ${ids[2]} archive
683 verify_comp_extent $tf ${ids[2]} 0 EOF
685 # verify components ${ids[3]} and ${ids[5]}
687 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
688 verify_comp_attr stripe-count $tf ${ids[$i]} 2
689 verify_comp_attr stripe-index $tf ${ids[$i]} 1
690 verify_comp_extent $tf ${ids[$i]} 0 8388608
693 # verify components ${ids[4]} and ${ids[6]}
695 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
696 verify_comp_attr stripe-count $tf ${ids[$i]} 2
697 verify_comp_attr pool $tf ${ids[$i]} flash
698 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
701 # verify component ${ids[7]}
702 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
703 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
704 verify_comp_attr_with_parent pool $tf ${ids[7]}
705 verify_comp_extent $tf ${ids[7]} 0 EOF
707 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
709 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
710 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
711 verify_comp_attr pool $tf ${ids[$i]} archive
712 verify_comp_extent $tf ${ids[$i]} 0 536870912
715 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
717 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
718 # ffdf which is -33 and matches LOV_ALL_STRIPES_MIN
719 local decimal_lov_lower_limit=-33
720 #C_opt is -c option which can be -1 to -32
722 local count_exp=$(($decimal_lov_lower_limit + $C_opt + 1))
724 verify_comp_attr stripe-count $tf ${ids[$i]} $count_exp
725 verify_comp_attr pool $tf ${ids[$i]} archive
726 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
729 run_test 0f "lfs mirror extend composite layout mirrors"
734 ! $LFS mirror create --flags prefer $tf ||
735 error "creating $tf w/ --flags but w/o -N option should fail"
737 ! $LFS mirror create -N --flags foo $tf ||
738 error "creating $tf with '--flags foo' should fail"
740 ! $LFS mirror create -N --flags stale $tf ||
741 error "creating $tf with '--flags stale' should fail"
743 ! $LFS mirror create -N --flags prefer,init $tf ||
744 error "creating $tf with '--flags prefer,init' should fail"
746 ! $LFS mirror create -N --flags ^prefer $tf ||
747 error "creating $tf with '--flags ^prefer' should fail"
749 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
750 -N -o1 $tf || error "create mirrored file $tf failed"
752 verify_comp_attr lcme_flags $tf 0x10001 prefer
753 verify_comp_attr lcme_flags $tf 0x10002 prefer
755 # write to the mirrored file and check primary
756 cp /etc/hosts $tf || error "error writing file '$tf'"
758 verify_comp_attr lcme_flags $tf 0x20003 stale
760 # resync file and check prefer flag
761 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
764 $LCTL set_param osc.*.stats=clear
765 cat $tf &> /dev/null || error "error reading file '$tf'"
767 # verify that the data was provided by OST1 where mirror 1 resides
768 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
769 awk '/ost_read/{print $2}')
770 [ -n "$nr_read" ] || error "read was not provided by OST1"
772 run_test 0g "lfs mirror create flags support"
775 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
776 skip "Need MDS version at least 2.11.57"
784 # create parent directory
785 test_mkdir $td || error "mkdir $td failed"
787 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
788 error "set default mirrored layout on directory $td failed"
790 # verify flags are inherited from the directory
793 verify_comp_attr lcme_flags $tf 0x10001 prefer
794 verify_comp_attr lcme_flags $tf 0x10002 prefer
796 # set flags to the first component
797 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
798 error "setting '^prefer,foo' flags should fail"
800 ! $LFS getstripe --component-flags=prefer,foo $tf ||
801 error "getting component(s) with 'prefer,foo' flags should fail"
803 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
805 verify_comp_attr lcme_flags $tf 0x10001 stale
806 verify_comp_attr lcme_flags $tf 0x10002 prefer
808 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
809 error "clearing 'stale' should fail"
811 # write and resync file. It can't resync the file directly because the
812 # file state is still 'ro'
813 cp /etc/hosts $tf || error "error writing file '$tf'"
814 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
816 for flag in prefer prefrd prefwr; do
817 $LFS setstripe --comp-set -I 0x20003 --comp-flags=$flag $tf ||
818 error "error setting flag $flag"
820 verify_comp_attr lcme_flags $tf 0x20003 $flag
822 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^$flag $tf ||
823 error "error clearing $flag flag from component 0x20003"
826 # MDS disallows setting stale flag on the last non-stale mirror
827 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
829 cp /etc/hosts $tf || error "error writing file '$tf'"
831 verify_comp_attr lcme_flags $tf 0x10002 prefer
832 verify_comp_attr lcme_flags $tf 0x20003 stale
833 verify_comp_attr lcme_flags $tf 0x30004 stale
835 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
837 error "setting stale flag on component 0x10002 should fail"
839 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
841 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
842 error "error setting stale flag on component 0x10001"
843 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
844 error "error setting stale flag on component 0x20003"
846 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
848 error "setting stale flag on component 0x30004 should fail"
850 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
852 run_test 0h "set, clear and test flags for FLR files"
855 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
857 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
858 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
859 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
861 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
862 stack_trap "rm -f $TMP/$tfile"
863 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
864 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
865 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
866 error "set component 1 stale failed"
867 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
868 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
870 run_test 0j "test lfs mirror read/write commands"
873 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
876 # default FLR with 2 mirrors
877 $LFS setstripe -N -c1 -i0 -N -c1 -i1 $DIR/$tdir ||
878 error "set default layout failed"
880 # plain file extension under default FLR dir
881 echo $tfile >> $DIR/$tdir/$tfile.append || error "create $tfile.append failed"
882 echo -n " before extend $tfile.append, mirror count = "
883 $LFS getstripe -N $DIR/$tdir/$tfile.append
885 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile.append ||
886 error "mirror extend failed"
887 echo -n " after extend $tfile.append, mirror count = "
888 $LFS getstripe -N $DIR/$tdir/$tfile.append
890 # normal file extension under default FLR dir
891 touch $DIR/$tdir/$tfile || error "create $tfile failed"
892 echo -n " before extend $tfile, mirror count = "
893 $LFS getstripe -N $DIR/$tdir/$tfile
895 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile ||
896 error "mirror extend $tfile failed"
897 echo -n " after extend $tfile, mirror count = "
898 $LFS getstripe -N $DIR/$tdir/$tfile
900 run_test 0k "mirroring a file in directory with default FLR layout"
904 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
905 local mirror_create_cmd="$LFS mirror create"
906 local stripes[0]=$OSTCOUNT
908 mirror_create_cmd+=" -N -c ${stripes[0]}"
909 for ((i = 1; i < $mirror_count; i++)); do
910 # add mirrors with different stripes to the file
911 stripes[$i]=$((RANDOM % OSTCOUNT))
912 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
914 mirror_create_cmd+=" -N -c ${stripes[$i]}"
917 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
918 verify_mirror_count $tf $mirror_count
920 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
921 $LFS mirror extend -N $tf &&
922 error "Creating the $((mirror_count+1))th mirror succeeded"
924 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
927 # verify the range of components and stripe counts
928 for ((i = 0; i < $mirror_count; i++)); do
929 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
930 verify_comp_extent $tf ${ids[$i]} 0 EOF
933 run_test 1 "create components with setstripe options"
937 local tf2=$DIR/$tfile-2
939 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
940 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
942 $LFS mirror extend -N -f $tf2 $tf ||
943 error "merging $tf2 into $tf failed"
945 verify_mirror_count $tf 2
946 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
948 run_test 2 "create components from existing files"
951 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
953 for ((i = 0; i < 2; i++)); do
954 $LFS mkdir -i $i $DIR/$tdir-$i
955 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
958 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
959 $DIR/$tdir-0/$tfile || error "creating mirrors"
961 # mdt doesn't support to cancel layout lock for remote objects, do
965 # make sure the mirrorted file was created successfully
966 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
967 { $LFS getstripe $DIR/$tdir-0/$tfile;
968 error "expected 2 components"; }
973 run_test 3 "create components from files located on different MDTs"
976 local tf=$DIR/$tdir/$tfile
979 test_mkdir $DIR/$tdir
981 # set mirror with setstripe options to directory
982 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
983 error "set mirror to directory error"
985 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
986 x"mirrored" ] || error "failed to create mirrored dir"
989 verify_mirror_count $tf 2
991 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
992 verify_comp_extent $tf ${ids[0]} 0 1048576
993 verify_comp_extent $tf ${ids[1]} 1048576 EOF
995 # sub directory should inherit mirror setting from parent
996 test_mkdir $DIR/$tdir/td
997 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
998 x"mirrored" ] || error "failed to inherit mirror from parent"
1000 # mirror extend won't be applied to directory
1001 $LFS mirror extend -N2 $DIR/$tdir &&
1002 error "expecting mirror extend failure"
1005 run_test 4 "Make sure mirror attributes can be inhertied from directory"
1008 local tf=$DIR/$tfile
1011 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
1012 error "failed to create file with non-empty layout"
1013 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
1015 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
1016 verify_mirror_count $tf 3
1018 $CHECKSTAT -t file -s 12345 $tf ||
1019 error "size error after attaching layout "
1021 run_test 5 "Make sure init size work for mirrored layout"
1024 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
1025 skip "MDS version older than 2.12.58"
1027 local tf=$DIR/$tfile
1029 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
1030 error "failure to create DoM file with mirror"
1032 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
1033 error "failure to create mirrored file with DoM"
1035 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
1036 error "failure to create PFL with DoM file"
1037 $LFS mirror extend -N2 $tf ||
1038 error "failure to extend mirror with DoM"
1040 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
1041 error "failure to create PFL with DoM file"
1042 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
1043 error "failure to create mirrored file"
1044 $LFS mirror extend -N -f $tf-1 $tf-2 ||
1045 error "failure to extend mirrored file with DoM extent"
1047 run_test 6a "DoM and FLR work together"
1050 (( $MDS1_VERSION >= $(version_code 2.15.58.1) )) ||
1051 skip "MDS version older than 2.15.58.1"
1053 local tf=$DIR/$tfile
1055 $LFS setstripe -E64K -L mdt -Eeof $tf ||
1056 error "failure to create PFL with DoM file"
1057 $LFS mirror extend -N -E1M -L mdt -Eeof $tf &&
1058 error "should not extend mirror with different DoM size"
1062 run_test 6b "extend mirror with different DoM size"
1065 local tf=$DIR/$tfile
1067 # create DoM with setting stripe_size == component size
1068 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
1069 error "failure to create DoM with stripe_size == comp size"
1070 rm -f $tf || error "delete $tf"
1072 # DoM should not inherit previous component stripe_size
1073 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
1074 error "DoM component shouldn't inherit previous stripe_size"
1076 run_test 7 "Create mirror with DoM component"
1079 local tf=$DIR/$tfile
1080 local tf2=$DIR/$tfile-2
1082 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1084 stack_trap "rm -f $tf $tf2"
1086 $LFS setstripe -E EOF -o 0 $tf
1087 $LFS setstripe -E EOF -o 1 $tf2
1089 local dd_count=$((RANDOM % 20 + 1))
1090 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
1091 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
1093 # for zfs - sync OST dataset so that du below will return
1095 [ "$FSTYPE" = "zfs" ] &&
1096 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1098 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1101 $LFS mirror extend -N -f $tf2 $tf ||
1102 error "merging $tf2 into $tf failed"
1104 # cancel layout lock
1105 cancel_lru_locks mdc
1107 local new_blocks=$(du -k $tf | awk '{print $1}')
1108 [ $new_blocks -eq $blocks ] ||
1109 error "i_blocks error expected: $blocks, actual: $new_blocks"
1111 run_test 21 "glimpse should report accurate i_blocks"
1113 get_osc_lock_count() {
1120 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1121 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1122 lock_count=$((lock_count + count))
1128 local tf=$DIR/$tfile
1130 stack_trap "rm -f $tf"
1132 $LFS setstripe -E EOF -o 0 $tf
1133 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1135 # add component, two mirrors located on the same OST ;-)
1136 $LFS mirror extend -N -o 0 $tf ||
1137 error "extending mirrored file $tf failed"
1139 size_blocks=$(stat --format="%b %s" $tf)
1141 cancel_lru_locks mdc
1142 cancel_lru_locks osc
1144 local new_size_blocks=$(stat --format="%b %s" $tf)
1146 # make sure there is no lock cached
1147 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1149 [ "$new_size_blocks" = "$size_blocks" ] ||
1150 echo "size expected: $size_blocks, actual: $new_size_blocks"
1154 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1157 local tf=$DIR/$tfile
1159 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1160 error "creating mirrored file $tf failed"
1163 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1164 cancel_lru_locks osc
1167 local tmpfile=$(mktemp)
1168 stat --format="%b %s" $tf > $tmpfile &
1172 while [ $cnt -le 5 ]; do
1173 kill -0 $pid > /dev/null 2>&1 || break
1177 kill -0 $pid > /dev/null 2>&1 &&
1178 error "stat process stuck due to unavailable OSTs"
1180 # make sure glimpse request has been sent
1181 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1182 error "OST $ost_idx: no glimpse request was sent"
1187 run_test 31 "make sure glimpse request can be retried"
1190 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1191 rm -f $DIR/$tfile $DIR/$tfile-2
1193 stack_trap "rm -f $DIR/$tfile"
1195 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1196 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1198 local fsize=$(stat -c %s $DIR/$tfile)
1199 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1201 local cksum=$(md5sum $DIR/$tfile)
1203 # create a new mirror in sync mode
1204 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1205 error "extending mirrored file $DIR/$tfile failed"
1207 # make sure the mirrored file was created successfully
1208 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1209 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1214 # check size is correct, glimpse request should go to the 2nd mirror
1215 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1216 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1218 echo "reading file from the 2nd mirror and verify checksum"
1219 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1220 error "checksum error: expected $cksum"
1224 run_test 32 "data should be mirrored to newly created mirror"
1227 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1229 rm -f $DIR/$tfile $DIR/$tfile-2
1231 # create a file with two mirrors
1232 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1235 while [ $count -lt $max_count ]; do
1236 echo "ost1" >> $DIR/$tfile
1237 count=$((count + 1));
1240 # tmp file that will be used as mirror
1241 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1243 while [ $count -lt $max_count ]; do
1244 echo "ost2" >> $DIR/$tfile-2
1245 count=$((count + 1));
1248 # create a mirrored file
1249 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1250 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1251 "with verification should fail"
1252 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1253 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1254 "without verification failed"
1256 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1257 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1258 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1260 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1262 # execpted file size
1263 local fsize=$((5 * max_count))
1264 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1265 error "mirrored file size is not $fsize"
1267 # read file - all OSTs are available
1268 echo "reading file (data can be provided by any ost)... "
1269 local rs=$(cat $DIR/$tfile | head -1)
1270 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1271 error "file content error: expected: \"ost1\" or \"ost2\""
1273 # read file again with ost1 failed
1277 echo "reading file (data should be provided by ost2)..."
1278 local rs=$(cat $DIR/$tfile | head -1)
1279 [[ "$rs" == "ost2" ]] ||
1280 error "file content error: expected: \"ost2\", actual: \"$rs\""
1285 # read file again with ost2 failed
1289 # check size, glimpse should work
1290 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1291 error "mirrored file size is not $fsize"
1293 echo "reading file (data should be provided by ost1)..."
1294 local rs=$(cat $DIR/$tfile | head -1)
1295 [[ "$rs" == "ost1" ]] ||
1296 error "file content error: expected: \"ost1\", actual: \"$rs\""
1300 run_test 33a "read can choose available mirror to read"
1303 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1307 stack_trap "rm -f $DIR/$tfile" EXIT
1309 # create a file with two mirrors on OST0000 and OST0001
1310 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1312 # make sure that $tfile has two mirrors
1313 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1314 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1317 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1318 error "write failed for $DIR/$tfile"
1319 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1320 verify_flr_state $DIR/$tfile "ro"
1325 # read file - all OSTs are available
1326 echo "reading file (data can be provided by any ost)... "
1328 time cat $DIR/$tfile > /dev/null || error "read all"
1332 # read file again with ost1 {OST0000} failed
1335 echo "reading file (data should be provided by ost2)..."
1337 time cat $DIR/$tfile > /dev/null || error "read ost2"
1344 # read file again with ost2 {OST0001} failed
1348 echo "reading file (data should be provided by ost1)..."
1350 time cat $DIR/$tfile > /dev/null || error "read ost1"
1357 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1358 error "read mirror too slow without ost1, from $ra to $r1"
1359 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1360 error "read mirror too slow without ost2, from $ra to $r2"
1362 wait_osc_import_ready client ost2
1364 run_test 33b "avoid reading from unhealthy mirror"
1367 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1371 stack_trap "rm -f $DIR/$tfile" EXIT
1373 # create a file with two mirrors
1374 # mirror1: {OST0000, OST0001}
1375 # mirror2: {OST0001, OST0002}
1376 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1378 # make sure that $tfile has two mirrors
1379 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1380 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1383 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1384 error "write failed for $DIR/$tfile"
1385 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1386 verify_flr_state $DIR/$tfile "ro"
1391 # read file - all OSTs are available
1392 echo "reading file (data can be provided by any ost)... "
1393 time cat $DIR/$tfile > /dev/null || error "read all"
1395 # read file again with ost2 (OST0001) failed
1399 echo "reading file (data should be provided by ost1 and ost3)..."
1400 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1405 wait_osc_import_ready client ost2
1407 run_test 33c "keep reading among unhealthy mirrors"
1410 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1412 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1415 $LFS setstripe -o 0 $DIR/$tfile-ref
1416 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1418 # create a file with two mirrors
1419 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1420 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1422 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1423 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1425 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1426 error "mirrored file size is not 3M"
1428 # merge a mirrored file
1429 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1430 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1432 cancel_lru_locks osc
1434 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1435 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1438 echo "comparing files ... "
1440 # however, read can still return the correct data. It should return
1441 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1442 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1443 $DIR/$tfile-ref || error "file reading error"
1447 run_test 34a "read mirrored file with multiple stripes"
1450 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1452 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1455 $LFS setstripe -o 0 $DIR/$tfile-ref
1456 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1458 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1459 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1461 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1462 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1464 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1465 error "mirrored file size is not 3M"
1467 # merge a mirrored file
1468 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1469 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1471 cancel_lru_locks osc
1473 # stop two OSTs, so the 2nd component of the 1st mirror and
1474 # the 1st component of the 2nd mirror will be inaccessible, ...
1477 echo "comparing files ... "
1479 # however, read can still return the correct data. It should return
1480 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1481 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1482 $DIR/$tfile-ref || error "file reading error"
1486 run_test 34b "read mirrored file with multiple components"
1489 local tf=$DIR/$tfile
1491 $LFS setstripe -E eof $tf
1493 # add an out-of-sync mirror to the file
1494 $LFS mirror extend -N -c 2 $tf ||
1495 error "extending mirrored file $tf failed"
1497 $MULTIOP $tf oO_WRONLY:c ||
1498 error "write open a mirrored file failed"
1500 # truncate file should return error
1501 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1503 run_test 35 "allow to write to mirrored files"
1505 get_file_layout_version() {
1506 $LFS getstripe $1 | awk '/lcm_layout_gen/{print $2}'
1509 get_ost_layout_version() {
1510 $MULTIOP $1 oXc | awk '/ostlayoutversion/{print $2}'
1513 verify_ost_layout_version() {
1516 # get file layout version
1517 local flv=$(get_file_layout_version $tf)
1519 # layout version from OST objects
1520 local olv=$(get_ost_layout_version $tf)
1522 (( flv >= olv )) || error "layout version mismatch: $flv vs. $olv"
1529 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1530 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1532 $LFS mirror extend -N -f $tf-tmp $tf ||
1533 error "merging $tf-tmp into $tf failed"
1538 local tf=$DIR/$tfile
1540 stack_trap "rm -f $tf $tf-2 $tf-3"
1542 create_file_36 $tf $tf-2 $tf-3
1544 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1546 # test case 1 - check file write and verify layout version
1547 $MULTIOP $tf oO_WRONLY:c ||
1548 error "write open a mirrored file failed"
1550 # write open file should not return error
1551 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1553 # instantiate components should work
1554 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1556 # verify OST layout version
1557 verify_ost_layout_version $tf
1560 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1563 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1565 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1566 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1568 # write should take at least $fail_loc seconds and succeed
1569 local st=$(date +%s)
1570 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1572 # verify OST layout version
1573 verify_ost_layout_version $tf
1575 do_facet $mds_facet $LCTL set_param fail_loc=0
1577 run_test 36a "write to mirrored files"
1580 local tf=$DIR/$tfile
1582 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1583 skip "Need OST version at least 2.15.50"
1585 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1587 # create 2 mirrors using different OSTs
1588 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1589 error "create mirrored file"
1591 # write 1M data to one mirror
1592 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1595 # set prefer mirror to another mirror
1596 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1597 error "clear prefer mirror error"
1598 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1599 error "set prefer mirror error"
1601 # the second write should not hung
1602 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1604 run_test 36b "write should not hung when prefered mirror is stale"
1607 local tf=$DIR/$tfile
1609 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1610 skip "Need OST version at least 2.15.50"
1612 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1614 # create 2 mirrors using different OSTs
1615 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1616 error "create mirrored file"
1617 stack_trap "rm -f $tf"
1619 # write it in the background
1620 $MULTIOP $tf Ow4096_w4096c &
1625 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1626 error "clear prefer mirror error"
1627 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1628 error "set prefer mirror error"
1633 run_test 36c "change prefer mirror during write shouldn't hung"
1636 local tf=$DIR/$tfile
1638 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1639 skip "Need OST version at least 2.15.50"
1641 echo " ** create $tf"
1642 $LFS mirror create -N $tf || error "create $tf failed"
1645 echo " ** mirror extend $tf ($i/2)"
1646 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1647 flv=$(get_file_layout_version $tf)
1648 olv=$(get_ost_layout_version $tf)
1649 echo " flv=$flv olv=$olv"
1653 echo " ** write $tf ($i/2)"
1654 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1655 flv=$(get_file_layout_version $tf)
1656 olv=$(get_ost_layout_version $tf)
1657 echo " flv=$flv olv=$olv"
1659 error "write update OST layout failed $flv/$olv"
1662 echo " ** resync $tf"
1663 $LFS mirror resync $tf || error "mirror resync $tf failed"
1664 flv=$(get_file_layout_version $tf)
1665 olv=$(get_ost_layout_version $tf)
1666 echo " flv=$flv olv=$olv"
1669 echo " ** truncate $tf ($i/2)"
1670 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1671 flv=$(get_file_layout_version $tf)
1672 olv=$(get_ost_layout_version $tf)
1673 echo " flv=$flv olv=$olv"
1674 (( flv == olv || flv == olv + 1 )) ||
1675 error "truncate update OST layout failed $flv/$olv"
1678 echo " ** resync $tf"
1679 $LFS mirror resync $tf || error "mirror resync $tf failed"
1680 flv=$(get_file_layout_version $tf)
1681 olv=$(get_ost_layout_version $tf)
1682 echo " flv=$flv olv=$olv"
1685 echo " ** write $tf ($i/2)"
1686 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1687 flv=$(get_file_layout_version $tf)
1688 olv=$(get_ost_layout_version $tf)
1689 echo " flv=$flv olv=$olv"
1691 error "write update OST layout failed $flv/$olv"
1694 run_test 36d "write/punch FLR file update OST layout version"
1700 echo "create test files with size $fsize .."
1704 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1706 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1707 $TRUNCATE $tf $fsize
1713 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1714 skip "Need MDS version at least 2.11.57"
1716 local tf=$DIR/$tfile
1717 local tf2=$DIR/$tfile-2
1718 local tf3=$DIR/$tfile-3
1719 local tf4=$DIR/$tfile-4
1721 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1723 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1726 # assume the mirror id will be 1, 2, and 3
1727 declare -A checksums
1728 checksums[1]=$(cat $tf | md5sum)
1729 checksums[2]=$(cat $tf2 | md5sum)
1730 checksums[3]=$(cat $tf3 | md5sum)
1732 printf '%s\n' "${checksums[@]}"
1734 # merge these files into a mirrored file
1735 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1736 error "merging $tf2 into $tf failed"
1737 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1738 error "merging $tf3 into $tf failed"
1742 # verify mirror read, checksums should equal to the original files'
1743 echo "Verifying mirror read .."
1746 for i in "${mirror_array[@]}"; do
1747 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1748 sum=$($LFS mirror read -N $i $tf | md5sum)
1749 [ "$sum" = "${checksums[$i]}" ] ||
1750 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1753 # verify mirror write
1754 echo "Verifying mirror write .."
1755 $LFS mirror write -N2 $tf < $tf4
1757 sum=$($LFS mirror read -N2 $tf | md5sum)
1758 [[ "$sum" = "${checksums[1]}" ]] ||
1759 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1761 # verify mirror copy, write to this mirrored file will invalidate
1762 # the other two mirrors
1763 echo "Verifying mirror copy .."
1765 local osts=$(comma_list $(osts_nodes))
1767 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1768 error "mirror copy error"
1770 # verify copying is successful by checking checksums
1771 remount_client $MOUNT
1772 for i in "${mirror_array[@]}"; do
1773 sum=$($LFS mirror read -N $i $tf | md5sum)
1774 [ "$sum" = "${checksums[1]}" ] ||
1775 error "$i: mismatch checksum after copy \'$sum\'"
1780 run_test 37 "mirror I/O API verification"
1783 local tf=$DIR/$tfile
1784 local ref=$DIR/${tfile}-ref
1786 stack_trap "rm -f $tf $ref"
1788 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1789 error "creating $tf failed"
1790 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1791 $tf-2 || error "creating $tf-2 failed"
1792 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1793 error "creating $tf-3 failed"
1795 # instantiate all components
1796 $LFS mirror extend -N -f $tf-2 $tf ||
1797 error "merging $tf-2 into $tf failed"
1798 $LFS mirror extend -N -f $tf-3 $tf ||
1799 error "merging $tf-3 into $tf failed"
1800 $LFS mirror extend -N -c 1 $tf ||
1801 error "extending mirrored file $tf failed"
1803 verify_flr_state $tf "ro"
1805 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1807 local fsize=$((RANDOM << 8 + 1048576))
1808 $TRUNCATE $ref $fsize
1810 local ref_cksum=$(cat $ref | md5sum)
1812 # case 1: verify write to mirrored file & resync work
1813 cp $ref $tf || error "copy from $ref to $f error"
1814 verify_flr_state $tf "wp"
1816 local file_cksum=$(cat $tf | md5sum)
1817 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1820 echo "mirror IDs: ${mirror_array[*]}"
1822 local valid_mirror stale_mirror id mirror_cksum
1823 for id in "${mirror_array[@]}"; do
1824 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1825 [ "$ref_cksum" == "$mirror_cksum" ] &&
1826 { valid_mirror=$id; continue; }
1831 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1832 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1834 $LFS mirror resync $tf || error "resync failed"
1835 verify_flr_state $tf "ro"
1837 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1838 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1840 # case 2: inject an error to make mirror_io exit after changing
1841 # the file state to sync_pending so that we can start a concurrent
1843 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1844 verify_flr_state $tf "wp"
1846 mirror_io resync -e resync_start $tf && error "resync succeeded"
1847 verify_flr_state $tf "sp"
1849 # from sync_pending to write_pending
1850 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1851 verify_flr_state $tf "wp"
1853 mirror_io resync -e resync_start $tf && error "resync succeeded"
1854 verify_flr_state $tf "sp"
1856 # from sync_pending to read_only
1857 $LFS mirror resync $tf || error "resync failed"
1858 verify_flr_state $tf "ro"
1860 run_test 38 "resync"
1863 local tf=$DIR/$tfile
1866 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1867 error "create PFL file $tf failed"
1869 verify_mirror_count $tf 2
1870 verify_comp_count $tf 4
1872 rm -f $tf || error "delete $tf failed"
1874 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1877 local tf=$DIR/$tfile
1880 for ops in "conv=notrunc" ""; do
1883 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1884 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1885 error "create PFLR file $tf failed"
1886 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1887 error "write PFLR file $tf failed"
1889 lfs getstripe -vy $tf
1893 # file mirror state should be write_pending
1894 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1896 error "file mirror state $flags"
1897 # the 1st component (in mirror 1) should be inited
1898 verify_comp_attr lcme_flags $tf 0x10001 init
1899 # the 2nd component (in mirror 1) should be inited
1900 verify_comp_attr lcme_flags $tf 0x10002 init
1901 # the 3rd component (in mirror 1) should be uninited
1902 verify_comp_attr lcme_flags $tf 0x10003 prefer
1903 # the 4th component (in mirror 2) should be inited
1904 verify_comp_attr lcme_flags $tf 0x20004 init
1905 # the 5th component (in mirror 2) should be uninited
1906 verify_comp_attr lcme_flags $tf 0x20005 0
1907 # the 6th component (in mirror 2) should be stale
1908 verify_comp_attr lcme_flags $tf 0x20006 stale
1909 # the 7th component (in mirror 2) should be uninited
1910 if [[ x$ops = "xconv=notrunc" ]]; then
1911 verify_comp_attr lcme_flags $tf 0x20007 0
1912 elif [[ x$ops = "x" ]]; then
1913 verify_comp_attr lcme_flags $tf 0x20007 stale
1917 rm -f $tf || error "delete $tf failed"
1919 run_test 40 "PFLR rdonly state instantiation check"
1922 local tf=$DIR/$tfile
1924 stack_trap "rm -f $tf $tf-1"
1927 echo " **create two FLR files $tf $tf-1"
1928 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1929 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1930 error "create PFLR file $tf failed"
1931 $LFS mirror create -N -E 2M -S 1M -E eof \
1932 -N -E 1M -E eof --flags prefer \
1933 -N -E 4m -E eof $tf-1 ||
1934 error "create PFLR file $tf-1 failed"
1936 # file should be in ro status
1937 echo " **verify files be RDONLY"
1938 verify_flr_state $tf "ro"
1939 verify_flr_state $tf-1 "ro"
1941 # write data in [0, 2M)
1942 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1943 error "writing $tf failed"
1944 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1945 error "writing $tf-1 failed"
1947 local sum0=$(cat $tf-1 | md5sum)
1949 echo " **verify files be WRITE_PENDING"
1950 verify_flr_state $tf "wp"
1951 verify_flr_state $tf-1 "wp"
1953 # file should have stale component
1954 echo " **verify files have stale component"
1955 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1956 error "after writing $tf, it does not contain stale component"
1957 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1958 error "after writing $tf-1, it does not contain stale component"
1960 echo " **full resync"
1961 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1963 echo " **verify $tf-1 data consistency in all mirrors"
1965 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1966 [[ "$sum" = "$sum0" ]] ||
1967 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1970 echo " **verify files be RDONLY"
1971 verify_flr_state $tf "ro"
1972 verify_flr_state $tf-1 "ro"
1974 # file should not have stale component
1975 echo " **verify files do not contain stale component"
1976 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1977 error "after resyncing $tf, it contains stale component"
1978 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1979 error "after resyncing $tf, it contains stale component"
1981 # verify partial resync
1982 echo " **write $tf-1 for partial resync test"
1983 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1984 error "writing $tf-1 failed"
1986 echo " **only resync mirror 2"
1987 verify_flr_state $tf-1 "wp"
1988 $LFS mirror resync --only 2 $tf-1 ||
1989 error "resync mirror 2 of $tf-1 failed"
1990 verify_flr_state $tf "ro"
1992 # resync synced mirror
1993 echo " **resync mirror 2 again"
1994 $LFS mirror resync --only 2 $tf-1 ||
1995 error "resync mirror 2 of $tf-1 failed"
1996 verify_flr_state $tf "ro"
1997 echo " **verify $tf-1 contains stale component"
1998 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1999 error "after writing $tf-1, it does not contain stale component"
2001 echo " **full resync $tf-1"
2002 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
2003 verify_flr_state $tf "ro"
2004 echo " **full resync $tf-1 again"
2005 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
2006 echo " **verify $tf-1 does not contain stale component"
2007 $LFS getstripe $tf | grep lcme_flags | grep stale &&
2008 error "after resyncing $tf, it contains stale component"
2012 run_test 41 "lfs mirror resync check"
2015 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
2019 local mirror_cmd="$LFS mirror verify"
2022 stack_trap "rm -rf $td"
2024 # create parent directory
2025 mkdir $td || error "mkdir $td failed"
2027 $mirror_cmd &> /dev/null && error "no file name given"
2028 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
2029 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
2031 # create mirrored files
2032 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
2033 error "create mirrored file $tf failed"
2034 $LFS mirror create -N -E 2M -S 1M -E EOF \
2035 -N -E 6M -E 8M -E EOF \
2036 -N -E 16M -E EOF $tf-1 ||
2037 error "create mirrored file $tf-1 failed"
2038 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
2039 error "create mirrored file $tf-2 failed"
2041 # write data in [0, 10M)
2042 for i in $tf $tf-1 $tf-2; do
2043 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
2044 error "write $i failed"
2047 # resync the mirrored files
2048 $LFS mirror resync $tf-1 $tf-2 ||
2049 error "resync $tf-1 $tf-2 failed"
2051 # verify the mirrored files
2052 $mirror_cmd $tf-1 $tf-2 ||
2053 error "verify $tf-1 $tf-2 failed"
2055 get_mirror_ids $tf-1
2056 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2057 error "at least 2 mirror ids needed with '--only' option"
2058 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2060 error "'--only' option cannot be used upon multiple files"
2061 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2062 error "invalid specified mirror ids"
2064 # change the content of $tf and merge it into $tf-1
2066 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2067 error "change $tf with seek=$i failed"
2068 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2069 error "change $tf-1 with seek=$i failed"
2072 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2073 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2074 error "merge $tf into $tf-1 failed"
2076 # verify the mirrored files
2077 echo "Verify $tf-1 without -v option:"
2078 $mirror_cmd $tf-1 &&
2079 error "verify $tf-1 should fail" || echo "PASS"
2081 echo "Verify $tf-1 with -v option:"
2082 $mirror_cmd -v $tf-1 &&
2083 error "verify $tf-1 should fail"
2085 get_mirror_ids $tf-1
2086 echo "Verify $tf-1 with --only option:"
2087 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2088 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2089 "${mirror_array[-1]} should fail"
2091 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2092 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2093 "${mirror_array[1]} should succeed"
2095 # set stale components in $tf-1
2096 for i in 0x40002 0x40003; do
2097 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2098 error "set stale flag on component $i failed"
2101 # verify the mirrored file
2102 echo "Verify $tf-1 with stale components:"
2103 $mirror_cmd -vvv $tf-1 ||
2104 error "verify $tf-1 with stale components should succeed"
2106 echo "Verify $tf-1 with stale components and --only option:"
2107 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2108 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2109 "${mirror_array[-1]} should succeed"
2111 run_test 42 "lfs mirror verify"
2113 # inactivate one OST && write && restore the OST
2117 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2120 wait=$(do_facet $SINGLEMDS \
2121 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2122 wait=${wait%%[^0-9]*}
2124 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2125 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2126 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2127 sleep $(($wait * 2 + 2))
2128 echo " **write $file"
2129 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2130 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2131 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2132 sleep $((wait * 2 + 2))
2134 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2135 [ $flags = wp ] || error "file mirror state $flags != wp"
2139 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2141 local tf=$DIR/$tfile
2144 stack_trap "rm -f $tf"
2146 ## mirror 0 ost (0, 1)
2147 ## mirror 1 ost (1, 2)
2148 ## mirror 2 ost (2, 0)
2149 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2150 -N -Eeof -c2 -o2,0 $tf ||
2151 error "create 3 mirrors file $tf failed"
2153 ################## OST0 ###########################################
2155 echo " **verify components"
2156 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2157 verify_comp_attr lcme_flags $tf 0x20002 init
2158 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2161 echo " **resync $tf"
2162 $LFS mirror resync $tf
2163 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2164 [ $flags = ro ] || error "file mirror state $flags != ro"
2166 ################## OST1 ###########################################
2168 echo " **verify components"
2169 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2170 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2171 verify_comp_attr lcme_flags $tf 0x30003 init
2174 echo " **resync $tf"
2175 $LFS mirror resync $tf
2176 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2177 [ $flags = ro ] || error "file mirror state $flags != ro"
2179 ################## OST2 ###########################################
2181 echo " **verify components"
2182 verify_comp_attr lcme_flags $tf 0x10001 init
2183 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2184 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2186 run_test 43a "mirror pick on write"
2189 local tf=$DIR/$tdir/$tfile
2191 test_mkdir $DIR/$tdir
2193 stack_trap "rm -rf $tf"
2195 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2196 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2197 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2198 verify_flr_state $tf "ro"
2200 echo " ** write to $tf"
2201 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2202 verify_flr_state $tf "wp"
2204 echo " ** resync $tf"
2205 $LFS mirror resync $tf || error "resync $tf failed"
2206 verify_flr_state $tf "ro"
2208 run_test 43b "allow writing to multiple preferred mirror file"
2211 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2214 local tf=$DIR/$tdir/$tfile
2215 local tf1=$DIR/$tdir-1/$tfile-1
2217 stack_trap "rm -rf $tf $tf1"
2219 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2220 error "create directory failed"
2221 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2222 error "create remote directory failed"
2223 rm -f $tf $tf1 $tf.mirror~2
2224 # create file with 4 mirrors
2225 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2226 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2227 error "create PFLR file $tf failed"
2229 # file should be in ro status
2230 verify_flr_state $tf "ro"
2232 # write data in [0, 3M)
2233 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2234 error "writing $tf failed"
2236 verify_flr_state $tf "wp"
2238 # disallow destroying the last non-stale mirror
2239 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2240 error "destroying mirror 1 should fail"
2242 # synchronize all mirrors of the file
2243 $LFS mirror resync $tf || error "mirror resync $tf failed"
2245 verify_flr_state $tf "ro"
2248 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2249 error "split to $tf1 failed"
2251 local idx0=$($LFS getstripe -m $tf)
2252 local idx1=$($LFS getstripe -m $tf1)
2254 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2255 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2257 # verify mirror count
2258 verify_mirror_count $tf 3
2259 verify_mirror_count $tf1 1
2261 $LFS mirror split --mirror-id 2 $tf ||
2262 error "split mirror 2 failed"
2264 verify_mirror_count $tf 2
2265 verify_mirror_count $tf.mirror~2 1
2267 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2268 error "setting stale flag on component 0x30008 failed"
2270 # disallow destroying the last non-stale mirror
2271 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2272 error "destroying mirror 4 should fail"
2274 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2276 $LFS mirror split --mirror-id 3 -d $tf ||
2277 error "destroying mirror 3 failed"
2278 verify_mirror_count $tf 1
2280 # verify splitted file contains the same content as the orig file does
2281 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2282 diff $tf $tf.mirror~2 ||
2283 error "splited file $tf.mirror~2 diffs from $tf"
2285 run_test 44a "lfs mirror split check"
2288 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2289 skip "Need MDS version at least 2.14.56"
2292 local tf=$DIR/$tdir/$tfile
2294 mkdir -p $DIR/$tdir || error "create directory failed"
2298 # create 2 mirrors file
2299 $LFS mirror extend -N -c1 $tf
2303 verify_flr_state $tf "wp"
2305 local str=$(cat $tf)
2307 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2309 # get the non-stale mirror id
2310 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2312 local mirror_ids=($($LFS getstripe $tf |
2313 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2314 for ((i = 0; i < 2; i++)); do
2315 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2316 grep stale > /dev/null || break
2319 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2323 # split the updated mirror, should fail
2324 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2325 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2326 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2329 # split the stale mirror
2330 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2331 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2332 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2334 echo "make sure there's no stale comp in the file"
2335 # make sure there's no stale comp in the file
2336 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2337 ( $LFS getstripe $tf; error "stale mirror file" )
2340 [[ $str == "YYY" ]] ||
2341 ( cat $tf; error "$tf content is not YYY after split" )
2343 run_test 44b "mirror split does not create stale file"
2346 local tf=$DIR/$tdir/$tfile
2348 stack_trap "rm -f $tf"
2350 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2351 skip "Need MDS version at least 2.14.52"
2353 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2355 mkdir -p $DIR/$tdir || error "create directroy failed"
2357 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2359 block1=$(( $(stat -c "%b*%B" $tf) ))
2360 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2362 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2364 block2=$(( $(stat -c "%b*%B" $tf) ))
2365 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2367 $LFS mirror split -d --mirror-id=2 $tf ||
2368 error "mirror split $tfile failed"
2369 $LFS mirror split -d --mirror-id=3 $tf ||
2370 error "mirror split $tfile failed"
2373 block3=$(( $(stat -c "%b*%B" $tf) ))
2374 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2376 [[ $block1 -eq $block3 ]] ||
2377 error "mirror split does not reduce block# $block3 != $block1"
2379 run_test 44c "lfs mirror split reduces block size of a file"
2382 local tf=$DIR/$tdir/$tfile
2388 stack_trap "rm -f $tf"
2390 mkdir -p $DIR/$tdir || error "create directroy failed"
2392 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2394 size1=$(stat -c "%s" $tf)
2395 echo " ** before mirror ops, file size=$size1"
2397 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2399 size2=$(stat -c "%s" $tf)
2400 echo " ** after mirror extend, file size=$size2"
2402 (($size1 == $size2)) ||
2403 error "mirror extend should not change size, before: $size1, after $size2"
2405 $LFS mirror split -d --mirror-id=2 $tf ||
2406 error "mirror split $tfile failed"
2408 size2=$(stat -c "%s" $tf)
2409 echo " ** after mirror split, file size=$size2"
2410 (($size1 == $size2)) ||
2411 error "mirror split should not change size, before: $size1, after $size2"
2413 # Remount client to clear cached size information
2414 remount_client $MOUNT
2415 size2=$(stat -c "%s" $tf)
2416 echo " ** after mirror split & remount, file size=$size2"
2417 (($size1 == $size2)) ||
2418 error "mirror extend should not change size, before: $size1, after $size2"
2421 run_test 44d "lfs mirror split does not break size"
2424 local tf=$DIR/$tdir/$tfile
2425 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2429 test_mkdir $DIR/$tdir
2430 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2431 skip "Need MDS version at least 2.14.52"
2433 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2435 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2436 $LCTL set_param llite.*.xattr_cache=0
2437 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2438 stack_trap "rm -rf $tf"
2440 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2442 size1=$(stat -c "%s" $tf)
2443 echo " ** before mirror resync, file size=$size1"
2445 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2446 size1=$(stat -c "%s" $tf)
2447 size2=$($LFS getsom -s $tf)
2451 ((size1 == size2)) ||
2452 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2454 # Remount client to clear cached size information
2455 remount_client $MOUNT
2457 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2458 stack_trap "restore_lustre_params < $p; rm -f $p"
2459 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2461 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2463 size2=$(stat -c "%s" $tf)
2464 # 'getsom' here is just for debugging
2467 ((size2 == size1)) ||
2468 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2470 run_test 44e "basic FLR SOM tests + disable SOM"
2473 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2475 local file=$DIR/$tdir/$tfile
2476 local dir=$DIR/$tdir/$dir
2477 local temp=$DIR/$tdir/template
2479 test_mkdir $DIR/$tdir
2481 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2482 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2483 error "Create $file failed"
2485 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2486 rm -f $file $file.copy
2488 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2489 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2490 error "Create $file failed"
2492 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2494 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2501 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2503 local layout1=$(get_layout_param $src)
2504 local layout2=$(get_layout_param $dst)
2505 # compare their layout info
2506 [ "$layout1" == "$layout2" ] ||
2507 error "$msg_prefix $src <=> $dst layouts are not equal"
2511 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2513 local file=$DIR/$tdir/$tfile
2514 test_mkdir $DIR/$tdir
2516 ########################### 1. PFL file #############################
2517 echo " ** 1. PFL file"
2519 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2520 $file || error "1. Create PFL $file failed"
2523 verify_46 $file $file.copy "1. PFL file"
2525 ########################### 2. plain file ###########################
2526 echo " ** 2. plain file"
2528 $LFS setstripe -c2 -o0,1 -i1 $file ||
2529 error "2. Create plain $file failed"
2532 verify_46 $file $file.copy "2. plain file"
2534 ########################### 3. FLR file #############################
2535 echo " ** 3. FLR file"
2537 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2538 $file || error "3. Create FLR $file failed"
2541 verify_46 $file $file.copy "3. FLR file"
2543 local dir=$DIR/$tdir/dir
2544 ########################### 4. PFL dir ##############################
2545 echo " ** 4. PFL dir"
2547 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2548 error "4. setstripe PFL $dir failed"
2550 test_mkdir $dir.copy
2551 verify_46 $dir $dir.copy "4. PFL dir"
2553 ########################### 5. plain dir ############################
2554 echo " ** 5. plain dir"
2555 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2557 verify_46 $dir $dir.copy "5. plain dir"
2559 ########################### 6. FLR dir ##############################
2560 echo " ** 6. FLR dir"
2561 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2562 error "6. setstripe FLR $dir failed"
2564 verify_46 $dir $dir.copy "6. FLR dir"
2566 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2567 echo "server version $MDS1_VERSION does not support SEL" &&
2570 ########################### 7. SEL file ##############################
2571 echo " ** 7. SEL file"
2573 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2574 $file || error "Create $file failed"
2577 verify_46 $file $file.copy "7. SEL file"
2579 ########################### 8. SEL dir ##############################
2580 echo " ** 8. SEL dir"
2581 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2582 $dir || error "setstripe $dir failed"
2584 verify_46 $dir $dir.copy "8. SEL dir"
2586 ########################### 9. FLR SEL file ##########################
2587 echo " ** 9. FLR SEL file"
2589 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2590 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2593 verify_46 $file $file.copy "9. SEL file"
2595 ########################### 10. FLR SEL dir #########################
2596 echo " ** 10. FLR SEL dir"
2597 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2598 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2600 verify_46 $dir $dir.copy "10. SEL dir"
2602 run_test 46 "Verify setstripe --copy option"
2605 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2607 local file=$DIR/$tdir/$tfile
2612 test_mkdir $DIR/$tdir
2613 stack_trap "rm -f $file"
2617 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2618 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2619 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2620 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2621 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2623 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2624 $LFS mirror resync $file || error "resync $file failed"
2626 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2627 if [[ x$ost == "x0," ]]; then
2628 $LFS getstripe $file
2629 error "component ${ids[2]} objects allocated on $ost " \
2633 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2634 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2635 $LFS getstripe $file
2636 error "component ${ids[3]} objects allocated on $ost " \
2637 "shouldn't on OST1 or on OST2"
2642 # mirror1: [comp0] [comp1]
2643 # mirror2: [comp2] [comp3]
2644 # mirror3: [comp4] [comp5]
2645 # mirror4: [comp6] [comp7]
2646 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2647 error "create FLR $file failed"
2648 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2650 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2651 $LFS mirror resync $file || error "resync $file failed"
2653 for ((i = 0; i < 6; i++)); do
2654 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2655 awk '/l_ost_idx/{print $5}')
2657 # comp[0],comp[2],comp[4] should use different osts
2658 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2659 ${osts[2]} == ${osts[4]} ]]; then
2660 $LFS getstripe $file
2661 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2662 "allocated on duplicated OSTs"
2664 # comp[1],comp[3],comp[5] should use different osts
2665 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2666 ${osts[3]} == ${osts[5]} ]]; then
2667 $LFS getstripe $file
2668 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2669 "allocated on duplicated OSTs"
2674 run_test 47 "Verify mirror obj alloc"
2677 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2678 skip "Need MDS version at least 2.11.55"
2680 local tf=$DIR/$tfile
2682 stack_trap "rm -f $tf"
2684 echo " ** create 2 mirrors FLR file $tf"
2685 $LFS mirror create -N -E2M -Eeof --flags prefer \
2686 -N -E1M -Eeof $tf ||
2687 error "create FLR file $tf failed"
2690 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2691 verify_flr_state $tf "wp"
2693 local sum0=$(md5sum < $tf)
2695 echo " ** resync the file"
2696 $LFS mirror resync $tf
2698 echo " ** snapshot mirror 2"
2699 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2701 echo " ** write it again"
2702 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2703 echo " ** resync it again"
2704 $LFS mirror resync $tf
2706 verify_flr_state $tf "wp"
2707 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2709 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2710 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2712 echo " ** verify mirror 2 doesn't change"
2713 echo "original checksum: $sum0"
2714 echo "mirror 1 checksum: $sum1"
2715 echo "mirror 2 checksum: $sum2"
2716 [[ $sum0 = $sum2 ]] ||
2717 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2718 echo " ** mirror 2 stripe info"
2719 $LFS getstripe -v --mirror-index=2 $tf
2721 echo " ** resync mirror 2"
2722 $LFS mirror resync --only 2 $tf
2724 verify_flr_state $tf "ro"
2725 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2727 sum1=$($LFS mirror read -N1 $tf | md5sum)
2728 sum2=$($LFS mirror read -N2 $tf | md5sum)
2730 echo " ** verify mirror 2 resync-ed"
2731 echo "original checksum: $sum0"
2732 echo "mirror 1 checksum: $sum1"
2733 echo "mirror 2 checksum: $sum2"
2734 [[ $sum1 = $sum2 ]] ||
2735 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2736 echo " ** mirror 2 stripe info"
2737 $LFS getstripe -v --mirror-index=2 $tf
2739 run_test 48 "Verify snapshot mirror"
2748 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2749 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2750 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2751 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2752 skip "LU-1941: FIEMAP unimplemented on ZFS"
2754 trap cleanup_49 EXIT RETURN
2756 local file=$DIR/$tfile
2758 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2759 error "setstripe on $file"
2760 stack_trap "rm -f $file"
2762 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2763 $LFS mirror resync $file
2765 filefrag -ves $file || error "filefrag $file failed"
2766 filefrag_op=$(filefrag -ve -k $file |
2767 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2769 #Filesystem type is: bd00bd0
2770 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2771 # ext: device_logical: physical_offset: length: dev: flags:
2772 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2773 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2774 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2776 last_lun=$(echo $filefrag_op | cut -d: -f5)
2780 for line in $filefrag_op; do
2781 frag_lun=$(echo $line | cut -d: -f5)
2782 ext_len=$(echo $line | cut -d: -f4)
2783 if [[ "$frag_lun" != "$last_lun" ]]; then
2784 if (( tot_len != 1024 )); then
2786 error "$file: OST$last_lun $tot_len != 1024"
2792 (( tot_len += ext_len ))
2795 if (( num_luns != 2 || tot_len != 1024 )); then
2797 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2800 echo "FIEMAP on $file succeeded"
2802 run_test 49a "FIEMAP upon FLR file"
2804 test_50A() { # EX-2179
2807 local file=$DIR/$tdir/$tfile
2809 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2811 $LFS mirror extend -N -c1 -i1 $file ||
2812 error "extending mirror for $file failed"
2814 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2818 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2820 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2822 echo "$file layout generation from $olv to $flv"
2823 (( $flv != ($olv + 1) )) &&
2824 error "split does not increase layout gen from $olv to $flv"
2826 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2828 $LFS getstripe -v $file || error "getstripe $file failed"
2830 run_test 50A "mirror split update layout generation"
2833 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2834 skip "OST does not support SEEK_HOLE"
2835 [ "$FSTYPE" != "zfs" ] ||
2836 skip "lseek for ZFS is not accurate if obj is not committed"
2838 local file=$DIR/$tdir/$tfile
2846 echo " ** create striped file $file"
2847 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2848 error "cannot create file with PFL layout"
2849 echo " ** write 1st data chunk at 1M boundary"
2850 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2851 error "cannot write data at 1M boundary"
2852 echo " ** write 2nd data chunk at 2M boundary"
2853 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2854 error "cannot write data at 2M boundary"
2855 echo " ** create hole at the file end"
2856 $TRUNCATE $file 3700000 || error "truncate fails"
2858 echo " ** verify sparseness"
2859 offset=$(lseek_test -d 1000 $file)
2860 echo " first data offset: $offset"
2861 [[ $offset == 1000 ]] &&
2862 error "src: data is not expected at offset $offset"
2863 offset=$(lseek_test -l 3500000 $file)
2864 echo " hole at the end: $offset"
2865 [[ $offset == 3500000 ]] ||
2866 error "src: hole is expected at offset $offset"
2868 echo " ** extend the file with new mirror"
2869 # migrate_copy_data() is used
2870 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2871 error "cannot create mirror"
2872 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2873 error "$file still has stale component"
2875 # check migrate_data_copy() was correct
2876 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2877 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2878 [[ $sum_1 == $sum_2 ]] ||
2879 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2881 # stale first mirror
2882 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2883 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2885 echo " ** verify mirror #2 sparseness"
2886 offset=$(lseek_test -d 1000 $file)
2887 echo " first data offset: $offset"
2888 [[ $offset == 1000 ]] &&
2889 error "dst: data is not expected at offset $offset"
2890 offset=$(lseek_test -l 3500000 $file)
2891 echo " hole at the end: $offset"
2892 [[ $offset == 3500000 ]] ||
2893 error "dst: hole is expected at offset $offset"
2895 echo " ** copy mirror #2 to mirror #1"
2896 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2897 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2898 error "$file still has stale component"
2900 # check llapi_mirror_copy_many correctness
2901 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2902 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2903 [[ $sum_1 == $sum_2 ]] ||
2904 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2906 # stale 1st component of mirror #2 before lseek call
2907 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2909 echo " ** verify mirror #1 sparseness again"
2910 offset=$(lseek_test -d 1000 $file)
2911 echo " first data offset: $offset"
2912 [[ $offset == 1000 ]] &&
2913 error "dst: data is not expected at offset $offset"
2914 offset=$(lseek_test -l 3500000 $file)
2915 echo " hole at the end: $offset"
2916 [[ $offset == 3500000 ]] ||
2917 error "dst: hole is expected at offset $offset"
2919 cancel_lru_locks osc
2921 blocks=$(stat -c%b $file)
2922 echo " ** final consumed blocks: $blocks"
2923 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2924 # that file is still sparse
2925 (( blocks < 1000 )) ||
2926 error "Mirrored file consumes $blocks blocks"
2928 run_test 50a "mirror extend/copy preserves sparseness"
2931 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2932 skip "OST does not support SEEK_HOLE"
2933 [ "$FSTYPE" != "zfs" ] ||
2934 skip "lseek for ZFS is not accurate if obj is not committed"
2936 local file=$DIR/$tdir/$tfile
2943 stack_trap "rm -f $file"
2945 echo " ** create mirrored file $file"
2946 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2947 -N -E2M -S1M -E eof -S2M $file ||
2948 error "cannot create mirrored file"
2949 echo " ** write data chunk at 1M boundary"
2950 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2951 error "cannot write data at 1M boundary"
2952 echo " ** create hole at the file end"
2953 $TRUNCATE $file 3700000 || error "truncate fails"
2955 echo " ** verify sparseness"
2956 offset=$(lseek_test -d 1000 $file)
2957 echo " first data offset: $offset"
2958 [[ $offset == 1000 ]] &&
2959 error "src: data is not expected at offset $offset"
2960 offset=$(lseek_test -l 3500000 $file)
2961 echo " hole at the end: $offset"
2962 [[ $offset == 3500000 ]] ||
2963 error "src: hole is expected at 3500000"
2965 echo " ** resync mirror #2 to mirror #1"
2966 $LFS mirror resync $file
2968 # check llapi_mirror_copy_many correctness
2969 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2970 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2971 [[ $sum_1 == $sum_2 ]] ||
2972 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2974 cancel_lru_locks osc
2976 blocks=$(stat -c%b $file)
2977 echo " ** consumed blocks: $blocks"
2978 # without full punch() support the first component can be not sparse
2979 # but the last one should be, so file should use far fewer blocks
2980 (( blocks < 5000 )) ||
2981 error "Mirrored file consumes $blocks blocks"
2983 # stale first component in mirror #1
2984 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2985 echo " ** truncate file down"
2987 echo " ** write data chunk at 2M boundary"
2988 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2989 error "cannot write data at 2M boundary"
2990 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2991 $LFS mirror resync $file || error "mirror rsync fails"
2992 # first component is still stale
2993 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2994 error "$file still has no stale component"
2995 echo " ** resync mirror #2 to mirror #1 again"
2996 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2997 $LFS mirror resync $file || error "mirror rsync fails"
2998 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2999 error "$file still has stale component"
3001 # check llapi_mirror_copy_many correctness
3002 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3003 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3004 [[ $sum_1 == $sum_2 ]] ||
3005 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3007 cancel_lru_locks osc
3009 blocks=$(stat -c%b $file)
3010 echo " ** final consumed blocks: $blocks"
3011 # while the first component can lose sparseness, the last one should
3012 # not, so whole file should still use far fewer blocks in total
3013 (( blocks < 3000 )) ||
3014 error "Mirrored file consumes $blocks blocks"
3016 run_test 50b "mirror rsync handles sparseness"
3019 local tf=$DIR/$tdir/$tfile
3021 test_mkdir $DIR/$tdir
3023 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
3024 verify_flr_state $tf "ro"
3026 if [[ "$FSTYPE" == "ldiskfs" ]]; then
3027 # ZFS does not support fallocate for now
3028 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
3029 skip_eopnotsupp "$out|punch hole in $tf failed"
3030 verify_flr_state $tf "wp"
3033 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
3034 $LFS mirror resync $tf || error "mirror resync $tf failed"
3035 verify_flr_state $tf "ro"
3037 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
3038 verify_flr_state $tf "wp"
3040 run_test 50c "punch_hole/mmap_write stale other mirrors"
3043 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3044 skip "OST does not support SEEK_HOLE"
3045 [ "$FSTYPE" != "zfs" ] ||
3046 skip "lseek for ZFS is not accurate if obj is not committed"
3048 local file=$DIR/$tdir/$tfile
3055 echo " ** create mirrored file $file"
3056 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3057 -N -E2M -S1M -E eof -S2M $file ||
3058 error "cannot create mirrored file"
3059 echo " ** write data chunk at 1M boundary"
3060 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3061 error "cannot write data at 1M boundary"
3062 echo " ** create hole at the file start"
3063 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3066 if [[ $rc -eq 0 ]]; then
3067 verify_flr_state $file "wp"
3068 elif [[ ! $prt =~ unsupported ]]; then
3069 error "punch hole in $file failed: $prt"
3071 skip "Fallocate punch is not supported: $prt"
3074 echo " ** verify sparseness"
3075 offset=$(lseek_test -d 1000 $file)
3076 echo " first data offset: $offset"
3077 (( $offset >= 1024 * 1024 )) ||
3078 error "src: data is not expected at offset $offset"
3080 echo " ** resync mirror #2"
3081 $LFS mirror resync $file
3083 # check llapi_mirror_copy_many correctness
3084 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3085 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3086 [[ $sum_1 == $sum_2 ]] ||
3087 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3089 cancel_lru_locks osc
3091 # stale first component in mirror #1
3092 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3093 echo " ** verify sparseness of mirror #2"
3094 offset=$(lseek_test -d 1000 $file)
3095 echo " first data offset: $offset"
3096 (( $offset >= 1024 * 1024 )) ||
3097 error "src: data is not expected at offset $offset"
3099 run_test 50d "mirror rsync keep holes"
3102 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3103 skip "OST does not support SEEK_HOLE"
3105 local file=$DIR/$tdir/$tfile
3106 local old_size=2147483648 # 2GiB
3110 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3111 $TRUNCATE $file $old_size
3113 $LFS mirror extend -N -c 1 $file
3114 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3115 $LFS mirror resync $file
3117 new_size=$(stat --format='%s' $file)
3118 if ((new_size != old_size)); then
3119 error "new_size ($new_size) is not equal to old_size ($old_size)"
3122 run_test 60a "mirror extend sets correct size on sparse file"
3124 get_flr_layout_gen() {
3125 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3126 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3129 check_layout_gen() {
3132 local v1=$(get_flr_layout_gen $tf)
3133 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3135 [[ $v1 -eq $v2 ]] ||
3136 error "$tf in-memory layout gen $v1 != $v2 after $2"
3140 local tf=$DIR/$tdir/$tfile
3142 test_mkdir $DIR/$tdir
3144 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3146 for ((i = 0; i < 20; i++)); do
3147 $LFS mirror extend -N $tf ||
3148 error "extending mirror for $tf failed"
3149 check_layout_gen $tf "extend"
3151 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3152 error "split $tf failed"
3153 check_layout_gen $tf "split"
3156 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3159 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3164 local -a old=( $2 $3 $4 )
3167 new=( $(get_times_61 $file) )
3168 ((${old[0]} == ${new[0]})) ||
3169 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3171 ((${old[1]} == ${new[1]})) ||
3172 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3175 test_61a() { # LU-14508
3176 local file=$DIR/$tdir/$tfile
3177 local old_diff=($(do_facet mds1 "$LCTL get_param -n mdd.*.atime_diff"))
3178 local mdts=$(comma_list $(mdts_nodes))
3182 do_nodes $mdts "$LCTL set_param mdd.*.atime_diff=1"
3183 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.atime_diff=$old_diff"
3187 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3188 echo "create $file-2"
3189 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3191 echo XXX > $file || error "write $file failed"
3192 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3194 echo "sleep $nap seconds, then cat $tfile"
3196 cat $file || error "cat $file failed"
3198 echo "sleep $nap seconds, then re-write $tfile"
3200 echo XXXX > $file || error "write $file failed"
3201 cp -p $file $file-2 || error "copy $file-2 failed"
3203 echo "sleep $nap seconds"
3206 tim=( $(get_times_61 $file) )
3208 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3209 $LFS mirror extend -N -f $file-2 $file ||
3210 error "cannot mirror merge $file-2 to $file"
3211 check_times_61 $file "${tim[@]}"
3213 echo "mirror extend $tfile and test timestamps"
3214 $LFS mirror extend -N -c1 -i1 $file ||
3215 error "cannot extend mirror $file"
3216 check_times_61 $file "${tim[@]}"
3218 echo "migrate $tfile and test timestamps"
3219 $LFS migrate -n $file || error "cannot migrate $file"
3220 check_times_61 $file "${tim[@]}"
3222 echo "normal user migrate $tfile and test timestamps"
3223 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3224 check_times_61 $file "${tim[@]}"
3226 run_test 61a "mirror extend and migrate preserve timestamps"
3228 test_61b() { # LU-14508
3229 local file=$DIR/$tdir/$tfile
3235 echo XXX > $file || error "create $file failed"
3236 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3238 echo "sleep $nap seconds, then cat $tfile"
3240 cat $file || error "cat $file failed"
3242 echo "sleep $nap seconds, then re-write $tfile"
3244 echo XXXX > $file || error "write $file failed"
3246 echo "sleep $nap seconds, then test timestamps"
3249 tim=( $(get_times_61 $file) )
3251 echo "mirror extend $tfile and test timestamps"
3252 $LFS mirror extend -N -c1 -i1 $file ||
3253 error "cannot extend mirror $file"
3254 check_times_61 $file "${tim[@]}"
3256 echo "mirror split $tfile and test timestamps"
3257 $LFS mirror split -d --mirror-id=1 $file ||
3258 error "cannot split mirror 1 off $file"
3259 check_times_61 $file "${tim[@]}"
3261 echo "normal user mirror extend $tfile and test timestamps"
3262 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3263 error "cannot extend mirror $file"
3264 check_times_61 $file "${tim[@]}"
3266 run_test 61b "mirror extend and split preserve timestamps"
3268 test_61c() { # LU-14508
3269 local file=$DIR/$tdir/$tfile
3275 echo XXX > $file || error "create $file failed"
3276 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3278 echo "sleep $nap seconds, then cat $tfile"
3280 cat $file || error "cat $file failed"
3282 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3284 $LFS mirror extend -N -c1 -i1 $file ||
3285 error "cannot extend mirror $file"
3286 echo XXXX > $file || error "write $file failed"
3288 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3289 tim=( $(get_times_61 $file) )
3291 $LFS mirror resync $file || error "cannot resync mirror $file"
3292 check_times_61 $file "${tim[@]}"
3294 echo XXXXXX > $file || error "write $tfile failed"
3296 echo "normal user resync $tfile and test timestamps"
3297 tim=( $(get_times_61 $file) )
3298 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3299 check_times_61 $file "${tim[@]}"
3301 run_test 61c "mirror resync preserves timestamps"
3304 local file=$DIR/$tdir/$tfile
3308 echo "create mirror file with unknown magic"
3309 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3310 # mirror 2 in-memory magic is bad
3311 $LCTL set_param fail_loc=0x1426 fail_val=2
3312 $LFS setstripe -N --flags=prefer -N2 $file ||
3313 error "failed to create mirror file $file"
3314 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3315 [[ $magic == 0x0BAD0BD0 ]] ||
3316 error "mirror 2 magic $magic is not bad as expected"
3317 cat /etc/passwd > $file || error "cannot write to $file"
3318 diff /etc/passwd $file || error "read $file error"
3322 echo "create mirror file with unknown pattern"
3323 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3324 # mirror 1 in-memory pattern is bad
3325 $LCTL set_param fail_loc=0x1427 fail_val=1
3326 $LFS setstripe -N -N --flags=prefer $file ||
3327 error "failed to create mirror file $file"
3328 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3329 [[ $pattern == 502 ]] ||
3330 error "mirror 1 pattern $pattern is not bad as expected"
3331 cat /etc/passwd > $file || error "cannot write to $file"
3332 diff /etc/passwd $file || error "read $file error"
3334 run_test 62 "read/write with unknown type of mirror"
3337 local tf=$DIR/$tdir/$tfile
3339 test_mkdir $DIR/$tdir
3340 stack_trap "rm -f $tf"
3344 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3348 echo "mirror create pid $c_pid"
3351 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3354 echo "mirror split pid $s_pid"
3356 echo "mirror create and split race for 60 seconds, should not crash"
3358 kill -9 $c_pid &> /dev/null
3359 kill -9 $s_pid &> /dev/null
3363 run_test 70 "mirror create and split race"
3366 local tf=$DIR/$tdir/$tfile
3368 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3369 skip "Need OST version at least 2.14.51"
3372 test_mkdir $DIR/$tdir
3373 stack_trap "rm -f $tf"
3375 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3376 error "setstripe $tf failed"
3378 FSXNUM=${FSXNUM:-1000}
3379 $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3381 run_test 70a "flr mode fsx test"
3386 local fsize=$(stat --printf=%s $tf)
3388 while [ -f $ctrl_file ]; do
3389 local off=$((RANDOM << 8))
3390 local len=$((RANDOM << 5 + 131072))
3392 [ $((off + len)) -gt $fsize ] && {
3393 fsize=$((off + len))
3394 echo "Extending file size to $fsize .."
3397 flock -s $lock_file -c \
3398 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3400 error "failed writing to $off:$len"; }
3401 sleep 0.$((RANDOM % 2 + 1))
3408 while [ -f $ctrl_file ]; do
3409 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3410 { rm -f $ctrl_file; error "read failed"; }
3411 sleep 0.$((RANDOM % 2 + 1))
3418 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3420 exec 200<>$lock_file
3421 while [ -f $ctrl_file ]; do
3422 local lock_taken=false
3423 local index=$((RANDOM % ${#options[@]}))
3424 local cmd="mirror_io resync ${options[$index]}"
3426 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3428 [ $((RANDOM % 4)) -eq 0 ] && {
3434 echo -n "resync file $tf with '$cmd' .."
3436 if [[ $lock_taken = "true" ]]; then
3438 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3441 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3444 sleep 0.$((RANDOM % 8 + 1))
3448 # this was test_200 before adding "b" and "c" subtests
3450 local tf=$DIR/$tfile
3451 local tf2=$DIR2/$tfile
3452 local tf3=$DIR3/$tfile
3454 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3455 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3456 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3458 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3459 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3460 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3462 $LFS mirror extend -N -f $tf-2 $tf ||
3463 error "merging $tf-2 into $tf failed"
3464 $LFS mirror extend -N -f $tf-3 $tf ||
3465 error "merging $tf-3 into $tf failed"
3467 mkdir -p $MOUNT2 && mount_client $MOUNT2
3469 mkdir -p $MOUNT3 && mount_client $MOUNT3
3471 verify_flr_state $tf3 "ro"
3473 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3474 $LCTL set_param fail_loc=0x1A03
3476 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3477 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3481 write_file_200 $tf &
3487 write_file_200 $tf2 &
3490 read_file_200 $tf2 &
3493 resync_file_200 $tf3 &
3497 [ "$SLOW" = "yes" ] && sleep_time=360
3498 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3505 echo "Waiting ${pids[*]}"
3508 umount_client $MOUNT2
3509 umount_client $MOUNT3
3511 # resync and verify mirrors
3512 $LFS mirror resync $tf || error "final resync failed"
3515 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3517 for id in "${mirror_array[@]:1}"; do
3518 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3519 error "checksum error for mirror $id"
3524 run_test 200a "stress test"
3527 local tf=$DIR/$tfile
3528 local tf2=$DIR2/$tfile
3529 local tf3=$DIR3/$tfile
3531 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3532 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3533 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3535 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3536 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3537 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3539 $LFS mirror extend -N -f $tf-2 $tf ||
3540 error "merging $tf-2 into $tf failed"
3541 $LFS mirror extend -N -f $tf-3 $tf ||
3542 error "merging $tf-3 into $tf failed"
3544 mkdir -p $MOUNT2 && mount_client $MOUNT2
3546 mkdir -p $MOUNT3 && mount_client $MOUNT3
3548 verify_flr_state $tf3 "ro"
3550 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3551 $LCTL set_param fail_loc=0x1423
3555 write_file_200 $tf &
3561 write_file_200 $tf2 &
3564 read_file_200 $tf2 &
3567 resync_file_200 $tf3 &
3571 [ "$SLOW" = "yes" ] && sleep_time=400
3575 echo "Waiting ${pids[@]}"
3578 umount_client $MOUNT2
3579 umount_client $MOUNT3
3581 # resync and verify mirrors
3582 $LFS mirror resync $tf || {
3584 error "final resync failed"
3588 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3589 for id in ${mirror_array[@]:1}; do
3590 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3591 error "checksum error for mirror $id"
3596 run_test 200b "racing IO, mirror extend and resync"
3599 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3600 skip "Need MDS version at least 2.15.53"
3602 local tf=$DIR/$tfile
3603 local tf2=$DIR2/$tfile
3605 mkdir -p $MOUNT2 && mount_client $MOUNT2
3606 stack_trap "umount_client $MOUNT2"
3607 stack_trap "rm -f $tf"
3611 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3613 mdt_idx=$($LFS getstripe -m $tf)
3615 cancel_lru_locks mdc
3616 cancel_lru_locks osc
3618 # start a process modifying file, block it just
3619 # before layout lock acquisition
3620 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3621 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3622 #log "dd to stale replica"
3623 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3629 $LFS mirror extend -N -c -1 $tf2 || {
3631 error "can't mirror"
3633 log "mirror extend done"
3634 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3636 # wait for blocking dd to complete and modify file
3637 wait $PID || error "2nd dd failed"
3640 verify_mirror_count $tf 2
3642 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3645 error "both replicas are still in sync"
3648 $LFS mirror verify -vvv $tf || {
3650 error "corrupted in-sync file"
3653 run_test 200c "layout change racing with open: LOVEA changes"
3655 cleanup_test_201() {
3656 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3658 umount_client $MOUNT2
3662 local delay=${RESYNC_DELAY:-5}
3664 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3665 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3667 stack_trap cleanup_test_201 EXIT
3669 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3670 changelog_register -n)
3672 mkdir -p $MOUNT2 && mount_client $MOUNT2
3676 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3677 [ -z "$log" ] && { sleep 1; continue; }
3679 index=$(echo $log | awk '{print $1}')
3680 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3681 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3682 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3685 [ -z "$file" ] && continue
3687 local now=$(date +%s)
3689 echo "file: $file $fid was modified at $ts, now: $now, " \
3690 "will be resynced at $((ts+delay))"
3692 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3694 $LFS mirror resync $file
3695 echo "$file resync done"
3698 run_test 201 "FLR data mover"
3701 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3703 local tf=$DIR/$tfile
3706 $LFS setstripe -E 1M -S 1M -c 1 $tf
3707 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3708 verify_comp_attr stripe-count $tf ${ids[0]} 1
3710 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3711 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3712 verify_comp_attr stripe-count $tf ${ids[0]} 1
3713 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3715 dd if=/dev/zero of=$tf bs=1M count=2
3716 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3717 verify_comp_attr stripe-count $tf ${ids[0]} 1
3718 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3720 run_test 202 "lfs setstripe --add-component wide striping"
3723 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3724 skip "Need MDS version at least 2.11.55"
3725 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3727 local tf=$DIR/$tfile
3730 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3731 #delete first mirror
3732 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3735 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3736 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3737 error "getstripe count of mirror 2"
3738 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3740 #extend a mirror with 2 OSTs
3741 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3744 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3745 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3746 error "getstripe count of mirror 2"
3747 [[ x$old_id = x$new_id ]] ||
3748 error "mirror 2 changed ID from $old_id to $new_id"
3749 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3751 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3752 error "getstripe count of mirror 3"
3753 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3755 run_test 203 "mirror file preserve mirror ID"
3757 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3759 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3760 skip "skipped for lustre < $SEL_VER"
3762 local comp_file=$DIR/$tdir/$tfile
3766 test_mkdir $DIR/$tdir
3767 stack_trap "rm -f $comp_file"
3769 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3770 # by extension space to -1
3771 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3772 error "Create $comp_file failed"
3774 # Write to first component, extending & staling second mirror
3775 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3776 error "dd to extend + stale failed"
3778 $LFS getstripe $comp_file
3780 flg_opts="--component-flags init,stale"
3781 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3782 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3784 flg_opts="--component-flags extension"
3785 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3786 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3788 # mirror resync should not change the extents
3789 $LFS mirror resync $comp_file
3791 flg_opts="--component-flags init"
3792 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3793 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3795 flg_opts="--component-flags extension"
3796 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3797 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3799 sel_layout_sanity $comp_file 5
3801 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3803 # Simple test of FLR + self-extending layout, SEL in primary mirror
3805 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3806 skip "skipped for lustre < $SEL_VER"
3808 local comp_file=$DIR/$tdir/$tfile
3812 test_mkdir $DIR/$tdir
3813 stack_trap "rm -f $comp_file"
3815 # first mirror is 1M followed by extension space to -1, second mirror
3816 # is 0-10M, then 10M-(-1),
3817 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3818 error "Create $comp_file failed"
3820 # Write to first component, extending first component & staling
3822 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3823 error "dd to extend + stale failed"
3825 $LFS getstripe $comp_file
3827 flg_opts="--component-flags init"
3828 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3829 [ $found -eq 1 ] || error "write: First comp end incorrect"
3831 flg_opts="--component-flags extension"
3832 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3833 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3835 flg_opts="--component-flags init,stale"
3836 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3837 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3839 # This component is staled because it overlaps the extended first
3840 # component of the primary mirror, even though it doesn't overlap
3841 # the actual write - thus not inited.
3842 flg_opts="--component-flags stale"
3843 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3844 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3846 # mirror resync should not change the extents
3847 $LFS mirror resync $comp_file
3849 $LFS getstripe $comp_file
3851 flg_opts="--component-flags init"
3852 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3853 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3855 flg_opts="--component-flags extension"
3856 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3857 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3859 flg_opts="--component-flags init"
3860 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3861 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3863 flg_opts="--component-flags init"
3864 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3865 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3867 sel_layout_sanity $comp_file 5
3869 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3871 # FLR + SEL failed extension & component removal
3872 # extension space in second mirror
3874 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3875 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3876 skip "skipped for lustre < $SEL_VER"
3878 local comp_file=$DIR/$tdir/$tfile
3881 local ost_name=$(ostname_from_index $ost_idx1)
3883 test_mkdir $DIR/$tdir
3884 stack_trap "rm -f $comp_file"
3886 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3887 # extension space from 1M to 1G, then normal space to -1
3888 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3889 -E -1 $comp_file || error "Create $comp_file failed"
3891 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3894 # write to first comp (0 - 10M) of mirror 1, extending + staling
3895 # first + second comp of mirror 2
3896 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3899 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3902 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3904 $LFS getstripe $comp_file
3906 found=$($LFS find --component-start 0m --component-end 1m \
3907 --comp-flags init,stale $comp_file | wc -l)
3908 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3910 found=$($LFS find --component-start 1m --component-end EOF \
3911 --comp-flags stale,^init $comp_file | wc -l)
3912 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3914 local mirror_id=$($LFS getstripe --component-start=1m \
3915 --component-end=EOF $comp_file | \
3916 grep lcme_mirror_id | awk '{ print $2 }')
3918 [[ $mirror_id -eq 2 ]] ||
3919 error "component not in correct mirror? $mirror_id"
3921 $LFS mirror resync $comp_file
3923 $LFS getstripe $comp_file
3925 # component dimensions should not change from resync
3926 found=$($LFS find --component-start 1m --component-end EOF \
3927 --component-flags init $comp_file | wc -l)
3928 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3930 sel_layout_sanity $comp_file 4
3932 run_test 204c "FLR write/stale/resync test with component removal"
3934 # Successful repeated component in primary mirror
3936 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3937 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3938 skip "skipped for lustre < $SEL_VER"
3940 local comp_file=$DIR/$tdir/$tfile
3943 wait_delete_completed
3945 test_mkdir $DIR/$tdir
3946 stack_trap "rm -f $comp_file"
3948 # first mirror is 64M followed by extension space to -1, second mirror
3949 # is 0-10M, then 10M-(-1)
3950 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3951 error "Create $comp_file failed"
3953 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3954 local ost_name=$(ostname_from_index $ost_idx1)
3955 # degrade OST for first comp so we won't extend there
3956 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3957 obdfilter.$ost_name.degraded=1
3960 # Write beyond first component, causing repeat & stale second mirror
3961 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3964 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3965 obdfilter.$ost_name.degraded=0
3968 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3970 $LFS getstripe $comp_file
3972 found=$($LFS find --component-start 64m --component-end 128m \
3973 --component-flags init $comp_file | wc -l)
3974 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3976 local ost_idx2=$($LFS getstripe --component-start=64m \
3977 --component-end=128m --component-flags=init \
3979 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3980 local mirror_id=$($LFS getstripe --component-start=64m \
3981 --component-end=128m --component-flags=init \
3982 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3983 [[ $mirror_id -eq 1 ]] ||
3984 error "component not in correct mirror: $mirror_id, not 1"
3986 $LFS mirror resync $comp_file
3988 $LFS getstripe $comp_file
3990 # component dimensions should not change from resync
3991 found=$($LFS find --component-start 0m --component-end 64m \
3992 --component-flags init $comp_file | wc -l)
3993 [ $found -eq 1 ] || error "resync: first comp incorrect"
3994 found=$($LFS find --component-start 64m --component-end 128m \
3995 --component-flags init $comp_file | wc -l)
3996 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3998 sel_layout_sanity $comp_file 5
4000 run_test 204d "FLR write/stale/resync sel test with repeated comp"
4002 # Successful repeated component, SEL in non-primary mirror
4004 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4005 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4006 skip "skipped for lustre < $SEL_VER"
4008 local comp_file=$DIR/$tdir/$tfile
4011 wait_delete_completed
4014 test_mkdir $DIR/$tdir
4015 stack_trap "rm -f $comp_file"
4017 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4018 # space to -1 (-z 64M, so first comp is 0-64M)
4019 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
4020 # will be not enough - one will be degraded, the other is used on
4021 # an overlapping mirror.
4022 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
4023 error "Create $comp_file failed"
4025 local ost_idx1=$($LFS getstripe --component-start=0 \
4026 --component-end=64m -i $comp_file)
4027 local ost_name=$(ostname_from_index $ost_idx1)
4028 # degrade OST for first comp of 2nd mirror so we won't extend there
4029 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4030 obdfilter.$ost_name.degraded=1
4033 $LFS getstripe $comp_file
4035 # Write to first component, stale & instantiate second mirror components
4036 # overlapping with the written component (0-100M);
4037 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4040 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4041 obdfilter.$ost_name.degraded=0
4043 $LFS getstripe $comp_file
4045 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
4047 found=$($LFS find --component-start 0m --component-end 64m \
4048 --component-flags init,stale $comp_file | wc -l)
4049 [ $found -eq 1 ] || error "write: first comp incorrect"
4051 # was repeated due to degraded ost
4052 found=$($LFS find --component-start 64m --component-end 128m \
4053 --component-flags init,stale $comp_file | wc -l)
4054 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4056 local ost_idx2=$($LFS getstripe --component-start=64m \
4057 --component-end=128m --component-flags=init \
4059 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4060 local mirror_id=$($LFS getstripe --component-start=0m \
4061 --component-end=64m --component-flags=init \
4062 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4063 [[ $mirror_id -eq 2 ]] ||
4064 error "component not in correct mirror? $mirror_id"
4066 $LFS mirror resync $comp_file
4068 $LFS getstripe $comp_file
4070 # component dimensions should not change from resync
4071 found=$($LFS find --component-start 0m --component-end 64m \
4072 --component-flags init,^stale $comp_file | wc -l)
4073 [ $found -eq 1 ] || error "resync: first comp incorrect"
4074 found=$($LFS find --component-start 64m --component-end 128m \
4075 --component-flags init,^stale $comp_file | wc -l)
4076 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4078 sel_layout_sanity $comp_file 5
4080 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4082 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4084 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4085 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4086 skip "skipped for lustre < $SEL_VER"
4088 local comp_file=$DIR/$tdir/$tfile
4091 wait_delete_completed
4093 test_mkdir $DIR/$tdir
4094 stack_trap "rm -f $comp_file"
4096 pool_add $TESTNAME || error "Pool creation failed"
4097 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4099 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4100 # space to -1 (-z 64M, so first comp is 0-64M)
4101 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4102 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4104 local ost_name0=$(ostname_from_index 0)
4105 local ost_name1=$(ostname_from_index 1)
4107 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4108 # extend original comp
4109 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4110 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4113 # a write to the 1st component, 100M length, which will try to stale
4114 # the first 100M of mirror 2, attempting to extend its 0-64M component
4115 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4118 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4119 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4122 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4124 $LFS getstripe $comp_file
4126 found=$($LFS find --component-start 0m --component-end 128m \
4127 --component-flags init,stale $comp_file | wc -l)
4128 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4130 local mirror_id=$($LFS getstripe --component-start=0m \
4131 --component-end=128m --component-flags=init \
4132 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4134 [[ $mirror_id -eq 2 ]] ||
4135 error "component not in correct mirror? $mirror_id, not 2"
4137 $LFS mirror resync $comp_file
4139 $LFS getstripe $comp_file
4141 # component dimensions should not change from resync
4142 found=$($LFS find --component-start 0m --component-end 128m \
4143 --component-flags init,^stale $comp_file | wc -l)
4144 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4146 sel_layout_sanity $comp_file 4
4148 run_test 204f "FLR write/stale/resync sel w/forced extension"
4150 function test_205() {
4151 local tf=$DIR/$tfile
4154 $LFS setstripe -c1 $tf
4155 $LFS mirror extend -N $tf
4156 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4157 (( $mirrors == 2 )) || error "no new mirror was created?"
4159 $LFS mirror extend -N --flags=prefer $tf
4160 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4161 (( $mirrors == 3 )) || error "no new mirror with prefer flag was created?"
4163 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4164 error "prefer flag was not set on the new mirror"
4166 $LFS mirror extend -N --flags=nocompr $tf
4167 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4168 (( $mirrors == 4 )) || error "no new mirror with nocompr flag was created?"
4170 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q nocompr) ||
4171 error "nocompr flag was not set on the new mirror"
4173 $LFS mirror extend -N --flags=prefer,nocompr $tf
4174 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4175 (( $mirrors == 5 )) || error "no new mirror with prefer,nocompr flags was created?"
4177 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q "prefer,nocompr") ||
4178 error "prefer,nocompr flags were not set on the new mirror"
4180 run_test 205 "lfs mirror extend to set prefer and nocompr flags"
4182 function test_206() {
4183 # create a new OST pool
4184 local pool_name=$TESTNAME
4186 create_pool $FSNAME.$pool_name ||
4187 error "create OST pool $pool_name failed"
4188 # add OSTs into the pool
4189 pool_add_targets $pool_name 0 1 ||
4190 error "add OSTs into pool $pool_name failed"
4192 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4193 error "can't setstripe"
4194 $LFS mirror extend -N $DIR/$tfile ||
4195 error "can't create replica"
4196 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4197 $LFS getstripe $DIR/$tfile
4198 error "prefer found"
4200 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4201 $LFS getstripe $DIR/$tfile
4202 error "can't setstripe prefer"
4205 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4206 $LFS getstripe $DIR/$tfile
4207 error "no prefer found"
4213 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4216 local file=$DIR/$tfile
4217 local tmpfile=$DIR/$tfile-tt
4219 (( $MDS1_VERSION >= $(version_code v2_14_50-161-g571f3cf111) )) ||
4220 skip "Need MDS >= 2.14.50.161 for stale components fix"
4222 stack_trap "rm -f $tmpfile $file"
4224 # generate data for verification
4225 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4226 error "can't generate file with random data"
4228 # create a mirrored file with one stale replica
4229 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4230 error "create mirrored file $file failed"
4231 get_mirror_ids $file
4232 echo "mirror IDs: ${mirror_array[*]}"
4234 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4235 get_mirror_ids $file
4236 echo "mirror IDs: ${mirror_array[*]}"
4239 cmp $tmpfile $file || error "files don't match"
4240 get_mirror_ids $file
4241 echo "mirror IDs: ${mirror_array[*]}"
4243 # mirror creation should work fine
4244 $LFS mirror extend -N -S 8M -c -1 $file ||
4245 error "mirror extend $file failed"
4247 get_mirror_ids $file
4248 echo "mirror IDs: ${mirror_array[*]}"
4251 $LFS mirror verify -v $file || error "verification failed"
4252 cmp $tmpfile $file || error "files don't match"
4254 run_test 207 "create another replica with existing out-of-sync one"
4256 function check_ost_used() {
4265 cancel_lru_locks osc # to drop pages
4266 cancel_lru_locks mdc # to refresh layout
4267 # XXX: cancel_lru_locks mdc doesn't work
4268 # XXX: need a better way to reload the layout
4269 umount_client $MOUNT || error "umount failed"
4270 mount_client $MOUNT || error "mount failed"
4272 # refresh non-rotation status on MDTs
4274 touch $DIR/$tfile-temp
4275 rm -f $DIR/$tfile-temp
4276 # refresh non-rotational status on the client
4280 $LCTL set_param osc.*.stats=clear >/dev/null
4281 if [[ $io == "read" ]]; then
4282 ddarg="if=$file of=/dev/null"
4283 elif [[ $io == "write" ]]; then
4284 ddarg="if=/dev/zero of=$file"
4286 error "unknown type $io"
4288 dd $ddarg bs=8M count=1 || error "can't $io $file"
4289 cancel_lru_locks osc
4291 # check only specified OSTs got reads
4292 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4293 local nr=$($LCTL get_param -n \
4294 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4295 awk "/ost_$io/{print \$2}")
4297 if [[ " $* " =~ $ost ]]; then
4298 (( nr > 0 )) || error "expected reads on $ost"
4300 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4306 local tf=$DIR/$tfile
4307 local osts=$(comma_list $(osts_nodes))
4309 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4310 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4311 skip "Need MDS version at least 2.14.55"
4313 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4315 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4316 stack_trap "restore_lustre_params < $p; rm -f $p"
4318 stack_trap "rm -f $tf"
4319 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4320 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4321 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4322 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4323 $LFS mirror resync $tf || error "can't resync"
4326 log "set OST0000 non-rotational"
4328 $LCTL set_param osd*.*OST*.nonrotational=0
4330 $LCTL set_param osd*.*OST0000*.nonrotational=1
4331 check_ost_used $tf read 0
4333 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4335 $LCTL set_param osd*.*OST*.nonrotational=0
4337 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4338 osd*.*OST0003*.nonrotational=1
4339 check_ost_used $tf read 2 3
4341 log "set mirror 1 on OST0001 preferred"
4342 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4343 error "can't set prefer"
4344 check_ost_used $tf read 1
4346 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4349 local tf=$DIR/$tfile
4350 local osts=$(comma_list $(osts_nodes))
4352 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4353 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4354 skip "Need MDS version at least 2.14.55"
4356 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4358 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4359 stack_trap "restore_lustre_params < $p; rm -f $p"
4361 stack_trap "rm -f $tf"
4362 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4363 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4364 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4365 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4366 $LFS mirror resync $tf || error "can't resync"
4367 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4369 log "set OST0000 non-rotational"
4371 $LCTL set_param osd*.*OST*.nonrotational=0
4373 $LCTL set_param osd*.*OST0000*.nonrotational=1
4374 check_ost_used $tf write 0
4375 $LFS mirror resync $tf || error "can't resync"
4377 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4379 $LCTL set_param osd*.*OST*.nonrotational=0
4381 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4382 osd*.*OST0003*.nonrotational=1
4383 check_ost_used $tf write 2 3
4384 $LFS mirror resync $tf || error "can't resync"
4386 log "set mirror 1 on OST0001 preferred"
4387 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4388 error "can't set prefer"
4389 check_ost_used $tf write 1
4391 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4394 local tf=$DIR/$tfile
4395 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4396 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4397 local osts=$(comma_list $(osts_nodes))
4399 stack_trap "rm -f $tmpfile"
4401 mkdir -p $MOUNT2 && mount_client $MOUNT2
4402 stack_trap "umount_client $MOUNT2"
4404 # to make replica on ost1 preferred for new writes
4405 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4406 stack_trap "restore_lustre_params < $p; rm -f $p"
4408 $LCTL set_param osd*.*OST*.nonrotational=0
4410 $LCTL set_param osd*.*OST0001*.nonrotational=1
4412 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4414 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4415 log "replicated file created"
4417 cancel_lru_locks mdc
4418 cancel_lru_locks osc
4420 log "open(O_RDONLY) and first read from OST"
4421 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4424 log "first read complete"
4426 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4427 error "can't write BBBB"
4428 log "BBBB written which made replica on ost1 stale"
4430 log "fast read from pagecache in the original process"
4434 log "read via $DIR2 new open(2)"
4435 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4437 log "fast read from pagecache after 5s in the original process"
4442 local nr=$(grep "BBBB" $tmpfile | wc -l)
4448 log "read via new open(2)"
4449 $MULTIOP $tf vvoO_RDONLY:r4c
4451 run_test 209a "skip fast reads after layout invalidation"
4453 function sum_ost_reads() {
4454 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4455 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4459 local tf=$DIR/$tfile
4461 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4462 cancel_lru_locks osc
4463 echo "the very first read"
4464 cat $tf >/dev/null || error "can't read"
4466 # cancel layout lock
4467 cancel_lru_locks mdc
4469 # now read again, data must be in the cache, so no ost reads
4470 $LCTL set_param osc.*.stats=clear >/dev/null
4471 echo "read with warm cache"
4472 cat $tf >/dev/null || error "can't read"
4474 (( nr == 0 )) || error "reads with warm cache"
4476 # now verify we can catch reads at all
4477 cancel_lru_locks osc
4478 cat $tf >/dev/null || error "can't read"
4480 (( nr > 0 )) || error "no reads with cold cache"
4482 run_test 209b "pagecache can be used after LL cancellation"
4485 local tf=$DIR/$tfile
4487 stack_trap "rm -f $tf"
4488 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4489 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4490 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4491 $LFS mirror extend -N $tf || error "can't mirror"
4492 $LFS getstripe -v $tf
4493 stat $tf || error "can't stat"
4495 run_test 210a "handle broken mirrored lovea"
4498 local tf=$DIR/$tfile
4500 [ "$FSTYPE" != "zfs" ] || skip "ZFS file number is not accurate"
4502 $LFS setstripe -i0 -c1 $tf || error "can't create file"
4503 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4505 local ostdev=$(ostdevname 1)
4506 local fid=($($LFS getstripe $DIR/$tfile | grep 0x))
4507 local seq=${fid[3]#0x}
4510 if [ $seq == 0 ]; then
4513 oid_hex=${fid[2]#0x}
4515 local objpath="O/$seq/d$(($oid % 32))/$oid_hex"
4516 local cmd="$DEBUGFS -c -R \\\"stat $objpath\\\" $ostdev"
4518 local ino=$(do_facet ost1 $cmd | grep Inode:)
4519 [[ -n $ino ]] || error "can't access obj object: $objpath"
4521 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4522 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4523 $LFS mirror extend -N $tf || error "can't mirror"
4525 # now remove the file with bogus ostidx in the striping info
4526 rm $tf || error "can't remove"
4527 [[ -f $tf ]] && error "rm failed"
4528 wait_delete_completed
4530 local ino=$(do_facet ost1 $cmd | grep Inode:)
4531 [[ -z $ino ]] || error "still CAN access obj object: $objpath"
4533 run_test 210b "handle broken mirrored lovea (unlink)"
4535 complete_test $SECONDS
4536 check_and_cleanup_lustre