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 verify_comp_attr stripe-count $tf ${ids[$i]} -1
503 verify_comp_attr pool $tf ${ids[$i]} archive
504 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
510 run_test 0c "lfs mirror create composite layout mirrors"
515 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
516 local mirror_cmd="$LFS mirror extend"
520 # create parent directory
521 mkdir $td || error "mkdir $td failed"
523 $mirror_cmd $tf &> /dev/null && error "miss -N option"
524 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
526 # create a non-mirrored file, convert it to a mirrored file and extend
527 touch $tf || error "touch $tf failed"
528 $mirror_cmd -N $tf || error "convert and extend $tf failed"
529 verify_mirror_count $tf 2
530 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
531 for ((i = 0; i < 2; i++)); do
532 verify_comp_attrs $tf ${ids[$i]}
533 verify_comp_extent $tf ${ids[$i]} 0 EOF
536 lfsck_verify_pfid $tf || error "PFID is not set"
538 # create a mirrored file and extend it
539 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
540 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
541 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
543 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
544 error "extend mirror with -f failed"
546 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
547 error "extend mirrored file $tf-3 failed"
548 verify_mirror_count $tf-3 $mirror_count
549 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
550 for ((i = 0; i < $mirror_count; i++)); do
551 verify_comp_attrs $tf-3 ${ids[$i]}
552 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
555 $mirror_cmd -N $tf-3 &> /dev/null
557 (( $rc == 34 || $MDS1_VERSION < $(version_code v2_14_57-72-gf468093cb6) )) ||
558 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
560 run_test 0d "lfs mirror extend with -N option"
563 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
567 local mirror_cmd="$LFS mirror extend"
571 # create parent directory
572 mkdir $td || error "mkdir $td failed"
574 create_pool $FSNAME.ssd ||
575 error "create OST pool ssd failed"
577 # create a mirrored file with plain layout mirrors
578 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
579 error "create mirrored file $tf failed"
581 create_pool $FSNAME.flash ||
582 error "create OST pool flash failed"
583 create_pool $FSNAME.archive ||
584 error "create OST pool archive failed"
586 # extend the mirrored file with plain layout mirrors
587 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
588 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
589 error "extend mirrored file $tf failed"
590 verify_mirror_count $tf 6
591 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
592 for ((i = 0; i < 6; i++)); do
593 verify_comp_extent $tf ${ids[$i]} 0 EOF
596 # verify component ${ids[0]}
597 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
598 verify_comp_attr stripe-count $tf ${ids[0]} 3
599 verify_comp_attr stripe-index $tf ${ids[0]} 1
601 # verify component ${ids[1]}
602 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
603 verify_comp_attr stripe-count $tf ${ids[1]} 2
604 verify_comp_attr stripe-index $tf ${ids[1]} 2
606 # verify component ${ids[2]}
607 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
608 verify_comp_attr stripe-count $tf ${ids[2]} 2
609 verify_comp_attr pool $tf ${ids[2]} flash
611 # verify component ${ids[3]}
612 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
613 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
614 verify_comp_attr pool $tf ${ids[3]} flash
616 # verify component ${ids[4]}
617 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
618 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
619 verify_comp_attr pool $tf ${ids[4]} archive
621 # verify component ${ids[5]}
622 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
623 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
624 verify_comp_attr_with_parent pool $tf ${ids[5]}
626 run_test 0e "lfs mirror extend plain layout mirrors"
629 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
633 local mirror_cmd="$LFS mirror extend"
637 # create parent directory
638 mkdir $td || error "mkdir $td failed"
640 create_pool $FSNAME.ssd ||
641 error "create OST pool ssd failed"
643 # create a mirrored file with composite layout mirror
644 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
645 error "create mirrored file $tf failed"
647 create_pool $FSNAME.flash ||
648 error "create OST pool flash failed"
649 create_pool $FSNAME.archive ||
650 error "create OST pool archive failed"
652 # extend the mirrored file with composite layout mirrors
653 $mirror_cmd -N -p archive \
654 -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
656 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
657 error "extend mirrored file $tf failed"
658 verify_mirror_count $tf 8
659 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
661 # verify component ${ids[0]}
662 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
663 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
664 verify_comp_attr pool $tf ${ids[0]} ssd
665 verify_comp_extent $tf ${ids[0]} 0 33554432
667 # verify component ${ids[1]}
668 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
669 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
670 verify_comp_attr pool $tf ${ids[1]} ssd
671 verify_comp_extent $tf ${ids[1]} 33554432 EOF
673 # verify component ${ids[2]}
674 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
675 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
676 verify_comp_attr pool $tf ${ids[2]} archive
677 verify_comp_extent $tf ${ids[2]} 0 EOF
679 # verify components ${ids[3]} and ${ids[5]}
681 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
682 verify_comp_attr stripe-count $tf ${ids[$i]} 2
683 verify_comp_attr stripe-index $tf ${ids[$i]} 1
684 verify_comp_extent $tf ${ids[$i]} 0 8388608
687 # verify components ${ids[4]} and ${ids[6]}
689 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
690 verify_comp_attr stripe-count $tf ${ids[$i]} 2
691 verify_comp_attr pool $tf ${ids[$i]} flash
692 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
695 # verify component ${ids[7]}
696 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
697 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
698 verify_comp_attr_with_parent pool $tf ${ids[7]}
699 verify_comp_extent $tf ${ids[7]} 0 EOF
701 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
703 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
704 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
705 verify_comp_attr pool $tf ${ids[$i]} archive
706 verify_comp_extent $tf ${ids[$i]} 0 536870912
709 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
711 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
712 verify_comp_attr stripe-count $tf ${ids[$i]} -1
713 verify_comp_attr pool $tf ${ids[$i]} archive
714 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
717 run_test 0f "lfs mirror extend composite layout mirrors"
722 ! $LFS mirror create --flags prefer $tf ||
723 error "creating $tf w/ --flags but w/o -N option should fail"
725 ! $LFS mirror create -N --flags foo $tf ||
726 error "creating $tf with '--flags foo' should fail"
728 ! $LFS mirror create -N --flags stale $tf ||
729 error "creating $tf with '--flags stale' should fail"
731 ! $LFS mirror create -N --flags prefer,init $tf ||
732 error "creating $tf with '--flags prefer,init' should fail"
734 ! $LFS mirror create -N --flags ^prefer $tf ||
735 error "creating $tf with '--flags ^prefer' should fail"
737 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
738 -N -o1 $tf || error "create mirrored file $tf failed"
740 verify_comp_attr lcme_flags $tf 0x10001 prefer
741 verify_comp_attr lcme_flags $tf 0x10002 prefer
743 # write to the mirrored file and check primary
744 cp /etc/hosts $tf || error "error writing file '$tf'"
746 verify_comp_attr lcme_flags $tf 0x20003 stale
748 # resync file and check prefer flag
749 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
752 $LCTL set_param osc.*.stats=clear
753 cat $tf &> /dev/null || error "error reading file '$tf'"
755 # verify that the data was provided by OST1 where mirror 1 resides
756 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
757 awk '/ost_read/{print $2}')
758 [ -n "$nr_read" ] || error "read was not provided by OST1"
760 run_test 0g "lfs mirror create flags support"
763 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
764 skip "Need MDS version at least 2.11.57"
772 # create parent directory
773 test_mkdir $td || error "mkdir $td failed"
775 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
776 error "set default mirrored layout on directory $td failed"
778 # verify flags are inherited from the directory
781 verify_comp_attr lcme_flags $tf 0x10001 prefer
782 verify_comp_attr lcme_flags $tf 0x10002 prefer
784 # set flags to the first component
785 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
786 error "setting '^prefer,foo' flags should fail"
788 ! $LFS getstripe --component-flags=prefer,foo $tf ||
789 error "getting component(s) with 'prefer,foo' flags should fail"
791 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
793 verify_comp_attr lcme_flags $tf 0x10001 stale
794 verify_comp_attr lcme_flags $tf 0x10002 prefer
796 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
797 error "clearing 'stale' should fail"
799 # write and resync file. It can't resync the file directly because the
800 # file state is still 'ro'
801 cp /etc/hosts $tf || error "error writing file '$tf'"
802 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
804 for flag in prefer prefrd prefwr; do
805 $LFS setstripe --comp-set -I 0x20003 --comp-flags=$flag $tf ||
806 error "error setting flag $flag"
808 verify_comp_attr lcme_flags $tf 0x20003 $flag
810 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^$flag $tf ||
811 error "error clearing $flag flag from component 0x20003"
814 # MDS disallows setting stale flag on the last non-stale mirror
815 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
817 cp /etc/hosts $tf || error "error writing file '$tf'"
819 verify_comp_attr lcme_flags $tf 0x10002 prefer
820 verify_comp_attr lcme_flags $tf 0x20003 stale
821 verify_comp_attr lcme_flags $tf 0x30004 stale
823 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
825 error "setting stale flag on component 0x10002 should fail"
827 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
829 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
830 error "error setting stale flag on component 0x10001"
831 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
832 error "error setting stale flag on component 0x20003"
834 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
836 error "setting stale flag on component 0x30004 should fail"
838 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
840 run_test 0h "set, clear and test flags for FLR files"
843 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
845 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
846 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
847 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
849 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
850 stack_trap "rm -f $TMP/$tfile"
851 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
852 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
853 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
854 error "set component 1 stale failed"
855 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
856 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
858 run_test 0j "test lfs mirror read/write commands"
861 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
864 # default FLR with 2 mirrors
865 $LFS setstripe -N -c1 -i0 -N -c1 -i1 $DIR/$tdir ||
866 error "set default layout failed"
868 # plain file extension under default FLR dir
869 echo $tfile >> $DIR/$tdir/$tfile.append || error "create $tfile.append failed"
870 echo -n " before extend $tfile.append, mirror count = "
871 $LFS getstripe -N $DIR/$tdir/$tfile.append
873 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile.append ||
874 error "mirror extend failed"
875 echo -n " after extend $tfile.append, mirror count = "
876 $LFS getstripe -N $DIR/$tdir/$tfile.append
878 # normal file extension under default FLR dir
879 touch $DIR/$tdir/$tfile || error "create $tfile failed"
880 echo -n " before extend $tfile, mirror count = "
881 $LFS getstripe -N $DIR/$tdir/$tfile
883 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile ||
884 error "mirror extend $tfile failed"
885 echo -n " after extend $tfile, mirror count = "
886 $LFS getstripe -N $DIR/$tdir/$tfile
888 run_test 0k "mirroring a file in directory with default FLR layout"
892 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
893 local mirror_create_cmd="$LFS mirror create"
894 local stripes[0]=$OSTCOUNT
896 mirror_create_cmd+=" -N -c ${stripes[0]}"
897 for ((i = 1; i < $mirror_count; i++)); do
898 # add mirrors with different stripes to the file
899 stripes[$i]=$((RANDOM % OSTCOUNT))
900 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
902 mirror_create_cmd+=" -N -c ${stripes[$i]}"
905 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
906 verify_mirror_count $tf $mirror_count
908 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
909 $LFS mirror extend -N $tf &&
910 error "Creating the $((mirror_count+1))th mirror succeeded"
912 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
915 # verify the range of components and stripe counts
916 for ((i = 0; i < $mirror_count; i++)); do
917 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
918 verify_comp_extent $tf ${ids[$i]} 0 EOF
921 run_test 1 "create components with setstripe options"
925 local tf2=$DIR/$tfile-2
927 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
928 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
930 $LFS mirror extend -N -f $tf2 $tf ||
931 error "merging $tf2 into $tf failed"
933 verify_mirror_count $tf 2
934 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
936 run_test 2 "create components from existing files"
939 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
941 for ((i = 0; i < 2; i++)); do
942 $LFS mkdir -i $i $DIR/$tdir-$i
943 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
946 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
947 $DIR/$tdir-0/$tfile || error "creating mirrors"
949 # mdt doesn't support to cancel layout lock for remote objects, do
953 # make sure the mirrorted file was created successfully
954 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
955 { $LFS getstripe $DIR/$tdir-0/$tfile;
956 error "expected 2 components"; }
961 run_test 3 "create components from files located on different MDTs"
964 local tf=$DIR/$tdir/$tfile
967 test_mkdir $DIR/$tdir
969 # set mirror with setstripe options to directory
970 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
971 error "set mirror to directory error"
973 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
974 x"mirrored" ] || error "failed to create mirrored dir"
977 verify_mirror_count $tf 2
979 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
980 verify_comp_extent $tf ${ids[0]} 0 1048576
981 verify_comp_extent $tf ${ids[1]} 1048576 EOF
983 # sub directory should inherit mirror setting from parent
984 test_mkdir $DIR/$tdir/td
985 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
986 x"mirrored" ] || error "failed to inherit mirror from parent"
988 # mirror extend won't be applied to directory
989 $LFS mirror extend -N2 $DIR/$tdir &&
990 error "expecting mirror extend failure"
993 run_test 4 "Make sure mirror attributes can be inhertied from directory"
999 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
1000 error "failed to create file with non-empty layout"
1001 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
1003 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
1004 verify_mirror_count $tf 3
1006 $CHECKSTAT -t file -s 12345 $tf ||
1007 error "size error after attaching layout "
1009 run_test 5 "Make sure init size work for mirrored layout"
1012 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
1013 skip "MDS version older than 2.12.58"
1015 local tf=$DIR/$tfile
1017 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
1018 error "failure to create DoM file with mirror"
1020 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
1021 error "failure to create mirrored file with DoM"
1023 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
1024 error "failure to create PFL with DoM file"
1025 $LFS mirror extend -N2 $tf ||
1026 error "failure to extend mirror with DoM"
1028 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
1029 error "failure to create PFL with DoM file"
1030 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
1031 error "failure to create mirrored file"
1032 $LFS mirror extend -N -f $tf-1 $tf-2 ||
1033 error "failure to extend mirrored file with DoM extent"
1035 run_test 6a "DoM and FLR work together"
1038 (( $MDS1_VERSION >= $(version_code 2.15.58.1) )) ||
1039 skip "MDS version older than 2.15.58.1"
1041 local tf=$DIR/$tfile
1043 $LFS setstripe -E64K -L mdt -Eeof $tf ||
1044 error "failure to create PFL with DoM file"
1045 $LFS mirror extend -N -E1M -L mdt -Eeof $tf &&
1046 error "should not extend mirror with different DoM size"
1050 run_test 6b "extend mirror with different DoM size"
1053 local tf=$DIR/$tfile
1055 # create DoM with setting stripe_size == component size
1056 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
1057 error "failure to create DoM with stripe_size == comp size"
1058 rm -f $tf || error "delete $tf"
1060 # DoM should not inherit previous component stripe_size
1061 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
1062 error "DoM component shouldn't inherit previous stripe_size"
1064 run_test 7 "Create mirror with DoM component"
1067 local tf=$DIR/$tfile
1068 local tf2=$DIR/$tfile-2
1070 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1072 stack_trap "rm -f $tf $tf2"
1074 $LFS setstripe -E EOF -o 0 $tf
1075 $LFS setstripe -E EOF -o 1 $tf2
1077 local dd_count=$((RANDOM % 20 + 1))
1078 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
1079 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
1081 # for zfs - sync OST dataset so that du below will return
1083 [ "$FSTYPE" = "zfs" ] &&
1084 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1086 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1089 $LFS mirror extend -N -f $tf2 $tf ||
1090 error "merging $tf2 into $tf failed"
1092 # cancel layout lock
1093 cancel_lru_locks mdc
1095 local new_blocks=$(du -k $tf | awk '{print $1}')
1096 [ $new_blocks -eq $blocks ] ||
1097 error "i_blocks error expected: $blocks, actual: $new_blocks"
1099 run_test 21 "glimpse should report accurate i_blocks"
1101 get_osc_lock_count() {
1108 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1109 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1110 lock_count=$((lock_count + count))
1116 local tf=$DIR/$tfile
1118 stack_trap "rm -f $tf"
1120 $LFS setstripe -E EOF -o 0 $tf
1121 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1123 # add component, two mirrors located on the same OST ;-)
1124 $LFS mirror extend -N -o 0 $tf ||
1125 error "extending mirrored file $tf failed"
1127 size_blocks=$(stat --format="%b %s" $tf)
1129 cancel_lru_locks mdc
1130 cancel_lru_locks osc
1132 local new_size_blocks=$(stat --format="%b %s" $tf)
1134 # make sure there is no lock cached
1135 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1137 [ "$new_size_blocks" = "$size_blocks" ] ||
1138 echo "size expected: $size_blocks, actual: $new_size_blocks"
1142 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1145 local tf=$DIR/$tfile
1147 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1148 error "creating mirrored file $tf failed"
1151 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1152 cancel_lru_locks osc
1155 local tmpfile=$(mktemp)
1156 stat --format="%b %s" $tf > $tmpfile &
1160 while [ $cnt -le 5 ]; do
1161 kill -0 $pid > /dev/null 2>&1 || break
1165 kill -0 $pid > /dev/null 2>&1 &&
1166 error "stat process stuck due to unavailable OSTs"
1168 # make sure glimpse request has been sent
1169 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1170 error "OST $ost_idx: no glimpse request was sent"
1175 run_test 31 "make sure glimpse request can be retried"
1178 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1179 rm -f $DIR/$tfile $DIR/$tfile-2
1181 stack_trap "rm -f $DIR/$tfile"
1183 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1184 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1186 local fsize=$(stat -c %s $DIR/$tfile)
1187 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1189 local cksum=$(md5sum $DIR/$tfile)
1191 # create a new mirror in sync mode
1192 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1193 error "extending mirrored file $DIR/$tfile failed"
1195 # make sure the mirrored file was created successfully
1196 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1197 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1202 # check size is correct, glimpse request should go to the 2nd mirror
1203 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1204 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1206 echo "reading file from the 2nd mirror and verify checksum"
1207 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1208 error "checksum error: expected $cksum"
1212 run_test 32 "data should be mirrored to newly created mirror"
1215 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1217 rm -f $DIR/$tfile $DIR/$tfile-2
1219 # create a file with two mirrors
1220 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1223 while [ $count -lt $max_count ]; do
1224 echo "ost1" >> $DIR/$tfile
1225 count=$((count + 1));
1228 # tmp file that will be used as mirror
1229 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1231 while [ $count -lt $max_count ]; do
1232 echo "ost2" >> $DIR/$tfile-2
1233 count=$((count + 1));
1236 # create a mirrored file
1237 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1238 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1239 "with verification should fail"
1240 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1241 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1242 "without verification failed"
1244 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1245 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1246 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1248 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1250 # execpted file size
1251 local fsize=$((5 * max_count))
1252 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1253 error "mirrored file size is not $fsize"
1255 # read file - all OSTs are available
1256 echo "reading file (data can be provided by any ost)... "
1257 local rs=$(cat $DIR/$tfile | head -1)
1258 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1259 error "file content error: expected: \"ost1\" or \"ost2\""
1261 # read file again with ost1 failed
1265 echo "reading file (data should be provided by ost2)..."
1266 local rs=$(cat $DIR/$tfile | head -1)
1267 [[ "$rs" == "ost2" ]] ||
1268 error "file content error: expected: \"ost2\", actual: \"$rs\""
1273 # read file again with ost2 failed
1277 # check size, glimpse should work
1278 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1279 error "mirrored file size is not $fsize"
1281 echo "reading file (data should be provided by ost1)..."
1282 local rs=$(cat $DIR/$tfile | head -1)
1283 [[ "$rs" == "ost1" ]] ||
1284 error "file content error: expected: \"ost1\", actual: \"$rs\""
1288 run_test 33a "read can choose available mirror to read"
1291 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1295 stack_trap "rm -f $DIR/$tfile" EXIT
1297 # create a file with two mirrors on OST0000 and OST0001
1298 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1300 # make sure that $tfile has two mirrors
1301 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1302 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1305 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1306 error "write failed for $DIR/$tfile"
1307 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1308 verify_flr_state $DIR/$tfile "ro"
1313 # read file - all OSTs are available
1314 echo "reading file (data can be provided by any ost)... "
1316 time cat $DIR/$tfile > /dev/null || error "read all"
1320 # read file again with ost1 {OST0000} failed
1323 echo "reading file (data should be provided by ost2)..."
1325 time cat $DIR/$tfile > /dev/null || error "read ost2"
1332 # read file again with ost2 {OST0001} failed
1336 echo "reading file (data should be provided by ost1)..."
1338 time cat $DIR/$tfile > /dev/null || error "read ost1"
1345 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1346 error "read mirror too slow without ost1, from $ra to $r1"
1347 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1348 error "read mirror too slow without ost2, from $ra to $r2"
1350 wait_osc_import_ready client ost2
1352 run_test 33b "avoid reading from unhealthy mirror"
1355 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1359 stack_trap "rm -f $DIR/$tfile" EXIT
1361 # create a file with two mirrors
1362 # mirror1: {OST0000, OST0001}
1363 # mirror2: {OST0001, OST0002}
1364 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1366 # make sure that $tfile has two mirrors
1367 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1368 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1371 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1372 error "write failed for $DIR/$tfile"
1373 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1374 verify_flr_state $DIR/$tfile "ro"
1379 # read file - all OSTs are available
1380 echo "reading file (data can be provided by any ost)... "
1381 time cat $DIR/$tfile > /dev/null || error "read all"
1383 # read file again with ost2 (OST0001) failed
1387 echo "reading file (data should be provided by ost1 and ost3)..."
1388 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1393 wait_osc_import_ready client ost2
1395 run_test 33c "keep reading among unhealthy mirrors"
1398 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1400 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1403 $LFS setstripe -o 0 $DIR/$tfile-ref
1404 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1406 # create a file with two mirrors
1407 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1408 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1410 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1411 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1413 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1414 error "mirrored file size is not 3M"
1416 # merge a mirrored file
1417 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1418 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1420 cancel_lru_locks osc
1422 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1423 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1426 echo "comparing files ... "
1428 # however, read can still return the correct data. It should return
1429 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1430 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1431 $DIR/$tfile-ref || error "file reading error"
1435 run_test 34a "read mirrored file with multiple stripes"
1438 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1440 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1443 $LFS setstripe -o 0 $DIR/$tfile-ref
1444 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1446 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1447 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1449 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1450 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1452 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1453 error "mirrored file size is not 3M"
1455 # merge a mirrored file
1456 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1457 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1459 cancel_lru_locks osc
1461 # stop two OSTs, so the 2nd component of the 1st mirror and
1462 # the 1st component of the 2nd mirror will be inaccessible, ...
1465 echo "comparing files ... "
1467 # however, read can still return the correct data. It should return
1468 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1469 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1470 $DIR/$tfile-ref || error "file reading error"
1474 run_test 34b "read mirrored file with multiple components"
1477 local tf=$DIR/$tfile
1479 $LFS setstripe -E eof $tf
1481 # add an out-of-sync mirror to the file
1482 $LFS mirror extend -N -c 2 $tf ||
1483 error "extending mirrored file $tf failed"
1485 $MULTIOP $tf oO_WRONLY:c ||
1486 error "write open a mirrored file failed"
1488 # truncate file should return error
1489 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1491 run_test 35 "allow to write to mirrored files"
1493 get_file_layout_version() {
1494 $LFS getstripe $1 | awk '/lcm_layout_gen/{print $2}'
1497 get_ost_layout_version() {
1498 $MULTIOP $1 oXc | awk '/ostlayoutversion/{print $2}'
1501 verify_ost_layout_version() {
1504 # get file layout version
1505 local flv=$(get_file_layout_version $tf)
1507 # layout version from OST objects
1508 local olv=$(get_ost_layout_version $tf)
1510 (( flv >= olv )) || error "layout version mismatch: $flv vs. $olv"
1517 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1518 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1520 $LFS mirror extend -N -f $tf-tmp $tf ||
1521 error "merging $tf-tmp into $tf failed"
1526 local tf=$DIR/$tfile
1528 stack_trap "rm -f $tf $tf-2 $tf-3"
1530 create_file_36 $tf $tf-2 $tf-3
1532 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1534 # test case 1 - check file write and verify layout version
1535 $MULTIOP $tf oO_WRONLY:c ||
1536 error "write open a mirrored file failed"
1538 # write open file should not return error
1539 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1541 # instantiate components should work
1542 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1544 # verify OST layout version
1545 verify_ost_layout_version $tf
1548 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1551 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1553 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1554 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1556 # write should take at least $fail_loc seconds and succeed
1557 local st=$(date +%s)
1558 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1560 # verify OST layout version
1561 verify_ost_layout_version $tf
1563 do_facet $mds_facet $LCTL set_param fail_loc=0
1565 run_test 36a "write to mirrored files"
1568 local tf=$DIR/$tfile
1570 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1571 skip "Need OST version at least 2.15.50"
1573 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1575 # create 2 mirrors using different OSTs
1576 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1577 error "create mirrored file"
1579 # write 1M data to one mirror
1580 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1583 # set prefer mirror to another mirror
1584 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1585 error "clear prefer mirror error"
1586 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1587 error "set prefer mirror error"
1589 # the second write should not hung
1590 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1592 run_test 36b "write should not hung when prefered mirror is stale"
1595 local tf=$DIR/$tfile
1597 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1598 skip "Need OST version at least 2.15.50"
1600 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1602 # create 2 mirrors using different OSTs
1603 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1604 error "create mirrored file"
1605 stack_trap "rm -f $tf"
1607 # write it in the background
1608 $MULTIOP $tf Ow4096_w4096c &
1613 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1614 error "clear prefer mirror error"
1615 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1616 error "set prefer mirror error"
1621 run_test 36c "change prefer mirror during write shouldn't hung"
1624 local tf=$DIR/$tfile
1626 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1627 skip "Need OST version at least 2.15.50"
1629 echo " ** create $tf"
1630 $LFS mirror create -N $tf || error "create $tf failed"
1633 echo " ** mirror extend $tf ($i/2)"
1634 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1635 flv=$(get_file_layout_version $tf)
1636 olv=$(get_ost_layout_version $tf)
1637 echo " flv=$flv olv=$olv"
1641 echo " ** write $tf ($i/2)"
1642 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1643 flv=$(get_file_layout_version $tf)
1644 olv=$(get_ost_layout_version $tf)
1645 echo " flv=$flv olv=$olv"
1647 error "write update OST layout failed $flv/$olv"
1650 echo " ** resync $tf"
1651 $LFS mirror resync $tf || error "mirror resync $tf failed"
1652 flv=$(get_file_layout_version $tf)
1653 olv=$(get_ost_layout_version $tf)
1654 echo " flv=$flv olv=$olv"
1657 echo " ** truncate $tf ($i/2)"
1658 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1659 flv=$(get_file_layout_version $tf)
1660 olv=$(get_ost_layout_version $tf)
1661 echo " flv=$flv olv=$olv"
1662 (( flv == olv || flv == olv + 1 )) ||
1663 error "truncate update OST layout failed $flv/$olv"
1666 echo " ** resync $tf"
1667 $LFS mirror resync $tf || error "mirror resync $tf failed"
1668 flv=$(get_file_layout_version $tf)
1669 olv=$(get_ost_layout_version $tf)
1670 echo " flv=$flv olv=$olv"
1673 echo " ** write $tf ($i/2)"
1674 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1675 flv=$(get_file_layout_version $tf)
1676 olv=$(get_ost_layout_version $tf)
1677 echo " flv=$flv olv=$olv"
1679 error "write update OST layout failed $flv/$olv"
1682 run_test 36d "write/punch FLR file update OST layout version"
1688 echo "create test files with size $fsize .."
1692 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1694 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1695 $TRUNCATE $tf $fsize
1701 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1702 skip "Need MDS version at least 2.11.57"
1704 local tf=$DIR/$tfile
1705 local tf2=$DIR/$tfile-2
1706 local tf3=$DIR/$tfile-3
1707 local tf4=$DIR/$tfile-4
1709 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1711 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1714 # assume the mirror id will be 1, 2, and 3
1715 declare -A checksums
1716 checksums[1]=$(cat $tf | md5sum)
1717 checksums[2]=$(cat $tf2 | md5sum)
1718 checksums[3]=$(cat $tf3 | md5sum)
1720 printf '%s\n' "${checksums[@]}"
1722 # merge these files into a mirrored file
1723 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1724 error "merging $tf2 into $tf failed"
1725 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1726 error "merging $tf3 into $tf failed"
1730 # verify mirror read, checksums should equal to the original files'
1731 echo "Verifying mirror read .."
1734 for i in "${mirror_array[@]}"; do
1735 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1736 sum=$($LFS mirror read -N $i $tf | md5sum)
1737 [ "$sum" = "${checksums[$i]}" ] ||
1738 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1741 # verify mirror write
1742 echo "Verifying mirror write .."
1743 $LFS mirror write -N2 $tf < $tf4
1745 sum=$($LFS mirror read -N2 $tf | md5sum)
1746 [[ "$sum" = "${checksums[1]}" ]] ||
1747 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1749 # verify mirror copy, write to this mirrored file will invalidate
1750 # the other two mirrors
1751 echo "Verifying mirror copy .."
1753 local osts=$(comma_list $(osts_nodes))
1755 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1756 error "mirror copy error"
1758 # verify copying is successful by checking checksums
1759 remount_client $MOUNT
1760 for i in "${mirror_array[@]}"; do
1761 sum=$($LFS mirror read -N $i $tf | md5sum)
1762 [ "$sum" = "${checksums[1]}" ] ||
1763 error "$i: mismatch checksum after copy \'$sum\'"
1768 run_test 37 "mirror I/O API verification"
1771 local tf=$DIR/$tfile
1772 local ref=$DIR/${tfile}-ref
1774 stack_trap "rm -f $tf $ref"
1776 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1777 error "creating $tf failed"
1778 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1779 $tf-2 || error "creating $tf-2 failed"
1780 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1781 error "creating $tf-3 failed"
1783 # instantiate all components
1784 $LFS mirror extend -N -f $tf-2 $tf ||
1785 error "merging $tf-2 into $tf failed"
1786 $LFS mirror extend -N -f $tf-3 $tf ||
1787 error "merging $tf-3 into $tf failed"
1788 $LFS mirror extend -N -c 1 $tf ||
1789 error "extending mirrored file $tf failed"
1791 verify_flr_state $tf "ro"
1793 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1795 local fsize=$((RANDOM << 8 + 1048576))
1796 $TRUNCATE $ref $fsize
1798 local ref_cksum=$(cat $ref | md5sum)
1800 # case 1: verify write to mirrored file & resync work
1801 cp $ref $tf || error "copy from $ref to $f error"
1802 verify_flr_state $tf "wp"
1804 local file_cksum=$(cat $tf | md5sum)
1805 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1808 echo "mirror IDs: ${mirror_array[*]}"
1810 local valid_mirror stale_mirror id mirror_cksum
1811 for id in "${mirror_array[@]}"; do
1812 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1813 [ "$ref_cksum" == "$mirror_cksum" ] &&
1814 { valid_mirror=$id; continue; }
1819 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1820 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1822 $LFS mirror resync $tf || error "resync failed"
1823 verify_flr_state $tf "ro"
1825 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1826 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1828 # case 2: inject an error to make mirror_io exit after changing
1829 # the file state to sync_pending so that we can start a concurrent
1831 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1832 verify_flr_state $tf "wp"
1834 mirror_io resync -e resync_start $tf && error "resync succeeded"
1835 verify_flr_state $tf "sp"
1837 # from sync_pending to write_pending
1838 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1839 verify_flr_state $tf "wp"
1841 mirror_io resync -e resync_start $tf && error "resync succeeded"
1842 verify_flr_state $tf "sp"
1844 # from sync_pending to read_only
1845 $LFS mirror resync $tf || error "resync failed"
1846 verify_flr_state $tf "ro"
1848 run_test 38 "resync"
1851 local tf=$DIR/$tfile
1854 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1855 error "create PFL file $tf failed"
1857 verify_mirror_count $tf 2
1858 verify_comp_count $tf 4
1860 rm -f $tf || error "delete $tf failed"
1862 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1865 local tf=$DIR/$tfile
1868 for ops in "conv=notrunc" ""; do
1871 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1872 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1873 error "create PFLR file $tf failed"
1874 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1875 error "write PFLR file $tf failed"
1877 lfs getstripe -vy $tf
1881 # file mirror state should be write_pending
1882 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1884 error "file mirror state $flags"
1885 # the 1st component (in mirror 1) should be inited
1886 verify_comp_attr lcme_flags $tf 0x10001 init
1887 # the 2nd component (in mirror 1) should be inited
1888 verify_comp_attr lcme_flags $tf 0x10002 init
1889 # the 3rd component (in mirror 1) should be uninited
1890 verify_comp_attr lcme_flags $tf 0x10003 prefer
1891 # the 4th component (in mirror 2) should be inited
1892 verify_comp_attr lcme_flags $tf 0x20004 init
1893 # the 5th component (in mirror 2) should be uninited
1894 verify_comp_attr lcme_flags $tf 0x20005 0
1895 # the 6th component (in mirror 2) should be stale
1896 verify_comp_attr lcme_flags $tf 0x20006 stale
1897 # the 7th component (in mirror 2) should be uninited
1898 if [[ x$ops = "xconv=notrunc" ]]; then
1899 verify_comp_attr lcme_flags $tf 0x20007 0
1900 elif [[ x$ops = "x" ]]; then
1901 verify_comp_attr lcme_flags $tf 0x20007 stale
1905 rm -f $tf || error "delete $tf failed"
1907 run_test 40 "PFLR rdonly state instantiation check"
1910 local tf=$DIR/$tfile
1912 stack_trap "rm -f $tf $tf-1"
1915 echo " **create two FLR files $tf $tf-1"
1916 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1917 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1918 error "create PFLR file $tf failed"
1919 $LFS mirror create -N -E 2M -S 1M -E eof \
1920 -N -E 1M -E eof --flags prefer \
1921 -N -E 4m -E eof $tf-1 ||
1922 error "create PFLR file $tf-1 failed"
1924 # file should be in ro status
1925 echo " **verify files be RDONLY"
1926 verify_flr_state $tf "ro"
1927 verify_flr_state $tf-1 "ro"
1929 # write data in [0, 2M)
1930 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1931 error "writing $tf failed"
1932 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1933 error "writing $tf-1 failed"
1935 local sum0=$(cat $tf-1 | md5sum)
1937 echo " **verify files be WRITE_PENDING"
1938 verify_flr_state $tf "wp"
1939 verify_flr_state $tf-1 "wp"
1941 # file should have stale component
1942 echo " **verify files have stale component"
1943 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1944 error "after writing $tf, it does not contain stale component"
1945 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1946 error "after writing $tf-1, it does not contain stale component"
1948 echo " **full resync"
1949 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1951 echo " **verify $tf-1 data consistency in all mirrors"
1953 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1954 [[ "$sum" = "$sum0" ]] ||
1955 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1958 echo " **verify files be RDONLY"
1959 verify_flr_state $tf "ro"
1960 verify_flr_state $tf-1 "ro"
1962 # file should not have stale component
1963 echo " **verify files do not contain stale component"
1964 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1965 error "after resyncing $tf, it contains stale component"
1966 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1967 error "after resyncing $tf, it contains stale component"
1969 # verify partial resync
1970 echo " **write $tf-1 for partial resync test"
1971 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1972 error "writing $tf-1 failed"
1974 echo " **only resync mirror 2"
1975 verify_flr_state $tf-1 "wp"
1976 $LFS mirror resync --only 2 $tf-1 ||
1977 error "resync mirror 2 of $tf-1 failed"
1978 verify_flr_state $tf "ro"
1980 # resync synced mirror
1981 echo " **resync mirror 2 again"
1982 $LFS mirror resync --only 2 $tf-1 ||
1983 error "resync mirror 2 of $tf-1 failed"
1984 verify_flr_state $tf "ro"
1985 echo " **verify $tf-1 contains stale component"
1986 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1987 error "after writing $tf-1, it does not contain stale component"
1989 echo " **full resync $tf-1"
1990 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1991 verify_flr_state $tf "ro"
1992 echo " **full resync $tf-1 again"
1993 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1994 echo " **verify $tf-1 does not contain stale component"
1995 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1996 error "after resyncing $tf, it contains stale component"
2000 run_test 41 "lfs mirror resync check"
2003 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
2007 local mirror_cmd="$LFS mirror verify"
2010 stack_trap "rm -rf $td"
2012 # create parent directory
2013 mkdir $td || error "mkdir $td failed"
2015 $mirror_cmd &> /dev/null && error "no file name given"
2016 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
2017 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
2019 # create mirrored files
2020 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
2021 error "create mirrored file $tf failed"
2022 $LFS mirror create -N -E 2M -S 1M -E EOF \
2023 -N -E 6M -E 8M -E EOF \
2024 -N -E 16M -E EOF $tf-1 ||
2025 error "create mirrored file $tf-1 failed"
2026 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
2027 error "create mirrored file $tf-2 failed"
2029 # write data in [0, 10M)
2030 for i in $tf $tf-1 $tf-2; do
2031 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
2032 error "write $i failed"
2035 # resync the mirrored files
2036 $LFS mirror resync $tf-1 $tf-2 ||
2037 error "resync $tf-1 $tf-2 failed"
2039 # verify the mirrored files
2040 $mirror_cmd $tf-1 $tf-2 ||
2041 error "verify $tf-1 $tf-2 failed"
2043 get_mirror_ids $tf-1
2044 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2045 error "at least 2 mirror ids needed with '--only' option"
2046 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2048 error "'--only' option cannot be used upon multiple files"
2049 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2050 error "invalid specified mirror ids"
2052 # change the content of $tf and merge it into $tf-1
2054 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2055 error "change $tf with seek=$i failed"
2056 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2057 error "change $tf-1 with seek=$i failed"
2060 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2061 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2062 error "merge $tf into $tf-1 failed"
2064 # verify the mirrored files
2065 echo "Verify $tf-1 without -v option:"
2066 $mirror_cmd $tf-1 &&
2067 error "verify $tf-1 should fail" || echo "PASS"
2069 echo "Verify $tf-1 with -v option:"
2070 $mirror_cmd -v $tf-1 &&
2071 error "verify $tf-1 should fail"
2073 get_mirror_ids $tf-1
2074 echo "Verify $tf-1 with --only option:"
2075 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2076 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2077 "${mirror_array[-1]} should fail"
2079 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2080 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2081 "${mirror_array[1]} should succeed"
2083 # set stale components in $tf-1
2084 for i in 0x40002 0x40003; do
2085 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2086 error "set stale flag on component $i failed"
2089 # verify the mirrored file
2090 echo "Verify $tf-1 with stale components:"
2091 $mirror_cmd -vvv $tf-1 ||
2092 error "verify $tf-1 with stale components should succeed"
2094 echo "Verify $tf-1 with stale components and --only option:"
2095 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2096 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2097 "${mirror_array[-1]} should succeed"
2099 run_test 42 "lfs mirror verify"
2101 # inactivate one OST && write && restore the OST
2105 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2108 wait=$(do_facet $SINGLEMDS \
2109 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2110 wait=${wait%%[^0-9]*}
2112 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2113 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2114 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2115 sleep $(($wait * 2 + 2))
2116 echo " **write $file"
2117 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2118 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2119 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2120 sleep $((wait * 2 + 2))
2122 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2123 [ $flags = wp ] || error "file mirror state $flags != wp"
2127 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2129 local tf=$DIR/$tfile
2132 stack_trap "rm -f $tf"
2134 ## mirror 0 ost (0, 1)
2135 ## mirror 1 ost (1, 2)
2136 ## mirror 2 ost (2, 0)
2137 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2138 -N -Eeof -c2 -o2,0 $tf ||
2139 error "create 3 mirrors file $tf failed"
2141 ################## OST0 ###########################################
2143 echo " **verify components"
2144 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2145 verify_comp_attr lcme_flags $tf 0x20002 init
2146 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2149 echo " **resync $tf"
2150 $LFS mirror resync $tf
2151 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2152 [ $flags = ro ] || error "file mirror state $flags != ro"
2154 ################## OST1 ###########################################
2156 echo " **verify components"
2157 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2158 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2159 verify_comp_attr lcme_flags $tf 0x30003 init
2162 echo " **resync $tf"
2163 $LFS mirror resync $tf
2164 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2165 [ $flags = ro ] || error "file mirror state $flags != ro"
2167 ################## OST2 ###########################################
2169 echo " **verify components"
2170 verify_comp_attr lcme_flags $tf 0x10001 init
2171 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2172 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2174 run_test 43a "mirror pick on write"
2177 local tf=$DIR/$tdir/$tfile
2179 test_mkdir $DIR/$tdir
2181 stack_trap "rm -rf $tf"
2183 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2184 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2185 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2186 verify_flr_state $tf "ro"
2188 echo " ** write to $tf"
2189 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2190 verify_flr_state $tf "wp"
2192 echo " ** resync $tf"
2193 $LFS mirror resync $tf || error "resync $tf failed"
2194 verify_flr_state $tf "ro"
2196 run_test 43b "allow writing to multiple preferred mirror file"
2199 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2202 local tf=$DIR/$tdir/$tfile
2203 local tf1=$DIR/$tdir-1/$tfile-1
2205 stack_trap "rm -rf $tf $tf1"
2207 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2208 error "create directory failed"
2209 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2210 error "create remote directory failed"
2211 rm -f $tf $tf1 $tf.mirror~2
2212 # create file with 4 mirrors
2213 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2214 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2215 error "create PFLR file $tf failed"
2217 # file should be in ro status
2218 verify_flr_state $tf "ro"
2220 # write data in [0, 3M)
2221 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2222 error "writing $tf failed"
2224 verify_flr_state $tf "wp"
2226 # disallow destroying the last non-stale mirror
2227 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2228 error "destroying mirror 1 should fail"
2230 # synchronize all mirrors of the file
2231 $LFS mirror resync $tf || error "mirror resync $tf failed"
2233 verify_flr_state $tf "ro"
2236 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2237 error "split to $tf1 failed"
2239 local idx0=$($LFS getstripe -m $tf)
2240 local idx1=$($LFS getstripe -m $tf1)
2242 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2243 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2245 # verify mirror count
2246 verify_mirror_count $tf 3
2247 verify_mirror_count $tf1 1
2249 $LFS mirror split --mirror-id 2 $tf ||
2250 error "split mirror 2 failed"
2252 verify_mirror_count $tf 2
2253 verify_mirror_count $tf.mirror~2 1
2255 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2256 error "setting stale flag on component 0x30008 failed"
2258 # disallow destroying the last non-stale mirror
2259 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2260 error "destroying mirror 4 should fail"
2262 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2264 $LFS mirror split --mirror-id 3 -d $tf ||
2265 error "destroying mirror 3 failed"
2266 verify_mirror_count $tf 1
2268 # verify splitted file contains the same content as the orig file does
2269 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2270 diff $tf $tf.mirror~2 ||
2271 error "splited file $tf.mirror~2 diffs from $tf"
2273 run_test 44a "lfs mirror split check"
2276 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2277 skip "Need MDS version at least 2.14.56"
2280 local tf=$DIR/$tdir/$tfile
2282 mkdir -p $DIR/$tdir || error "create directory failed"
2286 # create 2 mirrors file
2287 $LFS mirror extend -N -c1 $tf
2291 verify_flr_state $tf "wp"
2293 local str=$(cat $tf)
2295 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2297 # get the non-stale mirror id
2298 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2300 local mirror_ids=($($LFS getstripe $tf |
2301 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2302 for ((i = 0; i < 2; i++)); do
2303 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2304 grep stale > /dev/null || break
2307 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2311 # split the updated mirror, should fail
2312 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2313 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2314 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2317 # split the stale mirror
2318 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2319 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2320 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2322 echo "make sure there's no stale comp in the file"
2323 # make sure there's no stale comp in the file
2324 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2325 ( $LFS getstripe $tf; error "stale mirror file" )
2328 [[ $str == "YYY" ]] ||
2329 ( cat $tf; error "$tf content is not YYY after split" )
2331 run_test 44b "mirror split does not create stale file"
2334 local tf=$DIR/$tdir/$tfile
2336 stack_trap "rm -f $tf"
2338 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2339 skip "Need MDS version at least 2.14.52"
2341 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2343 mkdir -p $DIR/$tdir || error "create directroy failed"
2345 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2347 block1=$(( $(stat -c "%b*%B" $tf) ))
2348 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2350 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2352 block2=$(( $(stat -c "%b*%B" $tf) ))
2353 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2355 $LFS mirror split -d --mirror-id=2 $tf ||
2356 error "mirror split $tfile failed"
2357 $LFS mirror split -d --mirror-id=3 $tf ||
2358 error "mirror split $tfile failed"
2361 block3=$(( $(stat -c "%b*%B" $tf) ))
2362 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2364 [[ $block1 -eq $block3 ]] ||
2365 error "mirror split does not reduce block# $block3 != $block1"
2367 run_test 44c "lfs mirror split reduces block size of a file"
2370 local tf=$DIR/$tdir/$tfile
2376 stack_trap "rm -f $tf"
2378 mkdir -p $DIR/$tdir || error "create directroy failed"
2380 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2382 size1=$(stat -c "%s" $tf)
2383 echo " ** before mirror ops, file size=$size1"
2385 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2387 size2=$(stat -c "%s" $tf)
2388 echo " ** after mirror extend, file size=$size2"
2390 (($size1 == $size2)) ||
2391 error "mirror extend should not change size, before: $size1, after $size2"
2393 $LFS mirror split -d --mirror-id=2 $tf ||
2394 error "mirror split $tfile failed"
2396 size2=$(stat -c "%s" $tf)
2397 echo " ** after mirror split, file size=$size2"
2398 (($size1 == $size2)) ||
2399 error "mirror split should not change size, before: $size1, after $size2"
2401 # Remount client to clear cached size information
2402 remount_client $MOUNT
2403 size2=$(stat -c "%s" $tf)
2404 echo " ** after mirror split & remount, file size=$size2"
2405 (($size1 == $size2)) ||
2406 error "mirror extend should not change size, before: $size1, after $size2"
2409 run_test 44d "lfs mirror split does not break size"
2412 local tf=$DIR/$tdir/$tfile
2413 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2417 test_mkdir $DIR/$tdir
2418 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2419 skip "Need MDS version at least 2.14.52"
2421 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2423 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2424 $LCTL set_param llite.*.xattr_cache=0
2425 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2426 stack_trap "rm -rf $tf"
2428 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2430 size1=$(stat -c "%s" $tf)
2431 echo " ** before mirror resync, file size=$size1"
2433 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2434 size1=$(stat -c "%s" $tf)
2435 size2=$($LFS getsom -s $tf)
2439 ((size1 == size2)) ||
2440 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2442 # Remount client to clear cached size information
2443 remount_client $MOUNT
2445 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2446 stack_trap "restore_lustre_params < $p; rm -f $p"
2447 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2449 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2451 size2=$(stat -c "%s" $tf)
2452 # 'getsom' here is just for debugging
2455 ((size2 == size1)) ||
2456 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2458 run_test 44e "basic FLR SOM tests + disable SOM"
2461 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2463 local file=$DIR/$tdir/$tfile
2464 local dir=$DIR/$tdir/$dir
2465 local temp=$DIR/$tdir/template
2467 test_mkdir $DIR/$tdir
2469 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2470 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2471 error "Create $file failed"
2473 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2474 rm -f $file $file.copy
2476 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2477 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2478 error "Create $file failed"
2480 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2482 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2489 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2491 local layout1=$(get_layout_param $src)
2492 local layout2=$(get_layout_param $dst)
2493 # compare their layout info
2494 [ "$layout1" == "$layout2" ] ||
2495 error "$msg_prefix $src <=> $dst layouts are not equal"
2499 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2501 local file=$DIR/$tdir/$tfile
2502 test_mkdir $DIR/$tdir
2504 ########################### 1. PFL file #############################
2505 echo " ** 1. PFL file"
2507 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2508 $file || error "1. Create PFL $file failed"
2511 verify_46 $file $file.copy "1. PFL file"
2513 ########################### 2. plain file ###########################
2514 echo " ** 2. plain file"
2516 $LFS setstripe -c2 -o0,1 -i1 $file ||
2517 error "2. Create plain $file failed"
2520 verify_46 $file $file.copy "2. plain file"
2522 ########################### 3. FLR file #############################
2523 echo " ** 3. FLR file"
2525 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2526 $file || error "3. Create FLR $file failed"
2529 verify_46 $file $file.copy "3. FLR file"
2531 local dir=$DIR/$tdir/dir
2532 ########################### 4. PFL dir ##############################
2533 echo " ** 4. PFL dir"
2535 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2536 error "4. setstripe PFL $dir failed"
2538 test_mkdir $dir.copy
2539 verify_46 $dir $dir.copy "4. PFL dir"
2541 ########################### 5. plain dir ############################
2542 echo " ** 5. plain dir"
2543 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2545 verify_46 $dir $dir.copy "5. plain dir"
2547 ########################### 6. FLR dir ##############################
2548 echo " ** 6. FLR dir"
2549 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2550 error "6. setstripe FLR $dir failed"
2552 verify_46 $dir $dir.copy "6. FLR dir"
2554 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2555 echo "server version $MDS1_VERSION does not support SEL" &&
2558 ########################### 7. SEL file ##############################
2559 echo " ** 7. SEL file"
2561 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2562 $file || error "Create $file failed"
2565 verify_46 $file $file.copy "7. SEL file"
2567 ########################### 8. SEL dir ##############################
2568 echo " ** 8. SEL dir"
2569 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2570 $dir || error "setstripe $dir failed"
2572 verify_46 $dir $dir.copy "8. SEL dir"
2574 ########################### 9. FLR SEL file ##########################
2575 echo " ** 9. FLR SEL file"
2577 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2578 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2581 verify_46 $file $file.copy "9. SEL file"
2583 ########################### 10. FLR SEL dir #########################
2584 echo " ** 10. FLR SEL dir"
2585 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2586 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2588 verify_46 $dir $dir.copy "10. SEL dir"
2590 run_test 46 "Verify setstripe --copy option"
2593 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2595 local file=$DIR/$tdir/$tfile
2600 test_mkdir $DIR/$tdir
2601 stack_trap "rm -f $file"
2605 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2606 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2607 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2608 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2609 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2611 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2612 $LFS mirror resync $file || error "resync $file failed"
2614 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2615 if [[ x$ost == "x0," ]]; then
2616 $LFS getstripe $file
2617 error "component ${ids[2]} objects allocated on $ost " \
2621 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2622 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2623 $LFS getstripe $file
2624 error "component ${ids[3]} objects allocated on $ost " \
2625 "shouldn't on OST1 or on OST2"
2630 # mirror1: [comp0] [comp1]
2631 # mirror2: [comp2] [comp3]
2632 # mirror3: [comp4] [comp5]
2633 # mirror4: [comp6] [comp7]
2634 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2635 error "create FLR $file failed"
2636 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2638 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2639 $LFS mirror resync $file || error "resync $file failed"
2641 for ((i = 0; i < 6; i++)); do
2642 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2643 awk '/l_ost_idx/{print $5}')
2645 # comp[0],comp[2],comp[4] should use different osts
2646 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2647 ${osts[2]} == ${osts[4]} ]]; then
2648 $LFS getstripe $file
2649 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2650 "allocated on duplicated OSTs"
2652 # comp[1],comp[3],comp[5] should use different osts
2653 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2654 ${osts[3]} == ${osts[5]} ]]; then
2655 $LFS getstripe $file
2656 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2657 "allocated on duplicated OSTs"
2662 run_test 47 "Verify mirror obj alloc"
2665 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2666 skip "Need MDS version at least 2.11.55"
2668 local tf=$DIR/$tfile
2670 stack_trap "rm -f $tf"
2672 echo " ** create 2 mirrors FLR file $tf"
2673 $LFS mirror create -N -E2M -Eeof --flags prefer \
2674 -N -E1M -Eeof $tf ||
2675 error "create FLR file $tf failed"
2678 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2679 verify_flr_state $tf "wp"
2681 local sum0=$(md5sum < $tf)
2683 echo " ** resync the file"
2684 $LFS mirror resync $tf
2686 echo " ** snapshot mirror 2"
2687 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2689 echo " ** write it again"
2690 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2691 echo " ** resync it again"
2692 $LFS mirror resync $tf
2694 verify_flr_state $tf "wp"
2695 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2697 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2698 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2700 echo " ** verify mirror 2 doesn't change"
2701 echo "original checksum: $sum0"
2702 echo "mirror 1 checksum: $sum1"
2703 echo "mirror 2 checksum: $sum2"
2704 [[ $sum0 = $sum2 ]] ||
2705 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2706 echo " ** mirror 2 stripe info"
2707 $LFS getstripe -v --mirror-index=2 $tf
2709 echo " ** resync mirror 2"
2710 $LFS mirror resync --only 2 $tf
2712 verify_flr_state $tf "ro"
2713 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2715 sum1=$($LFS mirror read -N1 $tf | md5sum)
2716 sum2=$($LFS mirror read -N2 $tf | md5sum)
2718 echo " ** verify mirror 2 resync-ed"
2719 echo "original checksum: $sum0"
2720 echo "mirror 1 checksum: $sum1"
2721 echo "mirror 2 checksum: $sum2"
2722 [[ $sum1 = $sum2 ]] ||
2723 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2724 echo " ** mirror 2 stripe info"
2725 $LFS getstripe -v --mirror-index=2 $tf
2727 run_test 48 "Verify snapshot mirror"
2736 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2737 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2738 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2739 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2740 skip "LU-1941: FIEMAP unimplemented on ZFS"
2742 trap cleanup_49 EXIT RETURN
2744 local file=$DIR/$tfile
2746 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2747 error "setstripe on $file"
2748 stack_trap "rm -f $file"
2750 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2751 $LFS mirror resync $file
2753 filefrag -ves $file || error "filefrag $file failed"
2754 filefrag_op=$(filefrag -ve -k $file |
2755 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2757 #Filesystem type is: bd00bd0
2758 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2759 # ext: device_logical: physical_offset: length: dev: flags:
2760 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2761 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2762 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2764 last_lun=$(echo $filefrag_op | cut -d: -f5)
2768 for line in $filefrag_op; do
2769 frag_lun=$(echo $line | cut -d: -f5)
2770 ext_len=$(echo $line | cut -d: -f4)
2771 if [[ "$frag_lun" != "$last_lun" ]]; then
2772 if (( tot_len != 1024 )); then
2774 error "$file: OST$last_lun $tot_len != 1024"
2780 (( tot_len += ext_len ))
2783 if (( num_luns != 2 || tot_len != 1024 )); then
2785 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2788 echo "FIEMAP on $file succeeded"
2790 run_test 49a "FIEMAP upon FLR file"
2792 test_50A() { # EX-2179
2795 local file=$DIR/$tdir/$tfile
2797 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2799 $LFS mirror extend -N -c1 -i1 $file ||
2800 error "extending mirror for $file failed"
2802 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2806 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2808 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2810 echo "$file layout generation from $olv to $flv"
2811 (( $flv != ($olv + 1) )) &&
2812 error "split does not increase layout gen from $olv to $flv"
2814 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2816 $LFS getstripe -v $file || error "getstripe $file failed"
2818 run_test 50A "mirror split update layout generation"
2821 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2822 skip "OST does not support SEEK_HOLE"
2823 [ "$FSTYPE" != "zfs" ] ||
2824 skip "lseek for ZFS is not accurate if obj is not committed"
2826 local file=$DIR/$tdir/$tfile
2834 echo " ** create striped file $file"
2835 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2836 error "cannot create file with PFL layout"
2837 echo " ** write 1st data chunk at 1M boundary"
2838 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2839 error "cannot write data at 1M boundary"
2840 echo " ** write 2nd data chunk at 2M boundary"
2841 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2842 error "cannot write data at 2M boundary"
2843 echo " ** create hole at the file end"
2844 $TRUNCATE $file 3700000 || error "truncate fails"
2846 echo " ** verify sparseness"
2847 offset=$(lseek_test -d 1000 $file)
2848 echo " first data offset: $offset"
2849 [[ $offset == 1000 ]] &&
2850 error "src: data is not expected at offset $offset"
2851 offset=$(lseek_test -l 3500000 $file)
2852 echo " hole at the end: $offset"
2853 [[ $offset == 3500000 ]] ||
2854 error "src: hole is expected at offset $offset"
2856 echo " ** extend the file with new mirror"
2857 # migrate_copy_data() is used
2858 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2859 error "cannot create mirror"
2860 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2861 error "$file still has stale component"
2863 # check migrate_data_copy() was correct
2864 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2865 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2866 [[ $sum_1 == $sum_2 ]] ||
2867 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2869 # stale first mirror
2870 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2871 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2873 echo " ** verify mirror #2 sparseness"
2874 offset=$(lseek_test -d 1000 $file)
2875 echo " first data offset: $offset"
2876 [[ $offset == 1000 ]] &&
2877 error "dst: data is not expected at offset $offset"
2878 offset=$(lseek_test -l 3500000 $file)
2879 echo " hole at the end: $offset"
2880 [[ $offset == 3500000 ]] ||
2881 error "dst: hole is expected at offset $offset"
2883 echo " ** copy mirror #2 to mirror #1"
2884 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2885 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2886 error "$file still has stale component"
2888 # check llapi_mirror_copy_many correctness
2889 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2890 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2891 [[ $sum_1 == $sum_2 ]] ||
2892 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2894 # stale 1st component of mirror #2 before lseek call
2895 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2897 echo " ** verify mirror #1 sparseness again"
2898 offset=$(lseek_test -d 1000 $file)
2899 echo " first data offset: $offset"
2900 [[ $offset == 1000 ]] &&
2901 error "dst: data is not expected at offset $offset"
2902 offset=$(lseek_test -l 3500000 $file)
2903 echo " hole at the end: $offset"
2904 [[ $offset == 3500000 ]] ||
2905 error "dst: hole is expected at offset $offset"
2907 cancel_lru_locks osc
2909 blocks=$(stat -c%b $file)
2910 echo " ** final consumed blocks: $blocks"
2911 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2912 # that file is still sparse
2913 (( blocks < 1000 )) ||
2914 error "Mirrored file consumes $blocks blocks"
2916 run_test 50a "mirror extend/copy preserves sparseness"
2919 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2920 skip "OST does not support SEEK_HOLE"
2921 [ "$FSTYPE" != "zfs" ] ||
2922 skip "lseek for ZFS is not accurate if obj is not committed"
2924 local file=$DIR/$tdir/$tfile
2931 stack_trap "rm -f $file"
2933 echo " ** create mirrored file $file"
2934 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2935 -N -E2M -S1M -E eof -S2M $file ||
2936 error "cannot create mirrored file"
2937 echo " ** write data chunk at 1M boundary"
2938 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2939 error "cannot write data at 1M boundary"
2940 echo " ** create hole at the file end"
2941 $TRUNCATE $file 3700000 || error "truncate fails"
2943 echo " ** verify sparseness"
2944 offset=$(lseek_test -d 1000 $file)
2945 echo " first data offset: $offset"
2946 [[ $offset == 1000 ]] &&
2947 error "src: data is not expected at offset $offset"
2948 offset=$(lseek_test -l 3500000 $file)
2949 echo " hole at the end: $offset"
2950 [[ $offset == 3500000 ]] ||
2951 error "src: hole is expected at 3500000"
2953 echo " ** resync mirror #2 to mirror #1"
2954 $LFS mirror resync $file
2956 # check llapi_mirror_copy_many correctness
2957 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2958 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2959 [[ $sum_1 == $sum_2 ]] ||
2960 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2962 cancel_lru_locks osc
2964 blocks=$(stat -c%b $file)
2965 echo " ** consumed blocks: $blocks"
2966 # without full punch() support the first component can be not sparse
2967 # but the last one should be, so file should use far fewer blocks
2968 (( blocks < 5000 )) ||
2969 error "Mirrored file consumes $blocks blocks"
2971 # stale first component in mirror #1
2972 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2973 echo " ** truncate file down"
2975 echo " ** write data chunk at 2M boundary"
2976 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2977 error "cannot write data at 2M boundary"
2978 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2979 $LFS mirror resync $file || error "mirror rsync fails"
2980 # first component is still stale
2981 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2982 error "$file still has no stale component"
2983 echo " ** resync mirror #2 to mirror #1 again"
2984 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2985 $LFS mirror resync $file || error "mirror rsync fails"
2986 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2987 error "$file still has stale component"
2989 # check llapi_mirror_copy_many correctness
2990 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2991 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2992 [[ $sum_1 == $sum_2 ]] ||
2993 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2995 cancel_lru_locks osc
2997 blocks=$(stat -c%b $file)
2998 echo " ** final consumed blocks: $blocks"
2999 # while the first component can lose sparseness, the last one should
3000 # not, so whole file should still use far fewer blocks in total
3001 (( blocks < 3000 )) ||
3002 error "Mirrored file consumes $blocks blocks"
3004 run_test 50b "mirror rsync handles sparseness"
3007 local tf=$DIR/$tdir/$tfile
3009 test_mkdir $DIR/$tdir
3011 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
3012 verify_flr_state $tf "ro"
3014 if [[ "$FSTYPE" == "ldiskfs" ]]; then
3015 # ZFS does not support fallocate for now
3016 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
3017 skip_eopnotsupp "$out|punch hole in $tf failed"
3018 verify_flr_state $tf "wp"
3021 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
3022 $LFS mirror resync $tf || error "mirror resync $tf failed"
3023 verify_flr_state $tf "ro"
3025 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
3026 verify_flr_state $tf "wp"
3028 run_test 50c "punch_hole/mmap_write stale other mirrors"
3031 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3032 skip "OST does not support SEEK_HOLE"
3033 [ "$FSTYPE" != "zfs" ] ||
3034 skip "lseek for ZFS is not accurate if obj is not committed"
3036 local file=$DIR/$tdir/$tfile
3043 echo " ** create mirrored file $file"
3044 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3045 -N -E2M -S1M -E eof -S2M $file ||
3046 error "cannot create mirrored file"
3047 echo " ** write data chunk at 1M boundary"
3048 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3049 error "cannot write data at 1M boundary"
3050 echo " ** create hole at the file start"
3051 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3054 if [[ $rc -eq 0 ]]; then
3055 verify_flr_state $file "wp"
3056 elif [[ ! $prt =~ unsupported ]]; then
3057 error "punch hole in $file failed: $prt"
3059 skip "Fallocate punch is not supported: $prt"
3062 echo " ** verify sparseness"
3063 offset=$(lseek_test -d 1000 $file)
3064 echo " first data offset: $offset"
3065 (( $offset >= 1024 * 1024 )) ||
3066 error "src: data is not expected at offset $offset"
3068 echo " ** resync mirror #2"
3069 $LFS mirror resync $file
3071 # check llapi_mirror_copy_many correctness
3072 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3073 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3074 [[ $sum_1 == $sum_2 ]] ||
3075 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3077 cancel_lru_locks osc
3079 # stale first component in mirror #1
3080 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3081 echo " ** verify sparseness of mirror #2"
3082 offset=$(lseek_test -d 1000 $file)
3083 echo " first data offset: $offset"
3084 (( $offset >= 1024 * 1024 )) ||
3085 error "src: data is not expected at offset $offset"
3087 run_test 50d "mirror rsync keep holes"
3090 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3091 skip "OST does not support SEEK_HOLE"
3093 local file=$DIR/$tdir/$tfile
3094 local old_size=2147483648 # 2GiB
3098 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3099 $TRUNCATE $file $old_size
3101 $LFS mirror extend -N -c 1 $file
3102 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3103 $LFS mirror resync $file
3105 new_size=$(stat --format='%s' $file)
3106 if ((new_size != old_size)); then
3107 error "new_size ($new_size) is not equal to old_size ($old_size)"
3110 run_test 60a "mirror extend sets correct size on sparse file"
3112 get_flr_layout_gen() {
3113 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3114 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3117 check_layout_gen() {
3120 local v1=$(get_flr_layout_gen $tf)
3121 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3123 [[ $v1 -eq $v2 ]] ||
3124 error "$tf in-memory layout gen $v1 != $v2 after $2"
3128 local tf=$DIR/$tdir/$tfile
3130 test_mkdir $DIR/$tdir
3132 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3134 for ((i = 0; i < 20; i++)); do
3135 $LFS mirror extend -N $tf ||
3136 error "extending mirror for $tf failed"
3137 check_layout_gen $tf "extend"
3139 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3140 error "split $tf failed"
3141 check_layout_gen $tf "split"
3144 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3147 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3152 local -a old=( $2 $3 $4 )
3155 new=( $(get_times_61 $file) )
3156 ((${old[0]} == ${new[0]})) ||
3157 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3159 ((${old[1]} == ${new[1]})) ||
3160 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3163 test_61a() { # LU-14508
3164 local file=$DIR/$tdir/$tfile
3165 local old_diff=($(do_facet mds1 "$LCTL get_param -n mdd.*.atime_diff"))
3166 local mdts=$(comma_list $(mdts_nodes))
3170 do_nodes $mdts "$LCTL set_param mdd.*.atime_diff=1"
3171 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.atime_diff=$old_diff"
3175 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3176 echo "create $file-2"
3177 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3179 echo XXX > $file || error "write $file failed"
3180 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3182 echo "sleep $nap seconds, then cat $tfile"
3184 cat $file || error "cat $file failed"
3186 echo "sleep $nap seconds, then re-write $tfile"
3188 echo XXXX > $file || error "write $file failed"
3189 cp -p $file $file-2 || error "copy $file-2 failed"
3191 echo "sleep $nap seconds"
3194 tim=( $(get_times_61 $file) )
3196 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3197 $LFS mirror extend -N -f $file-2 $file ||
3198 error "cannot mirror merge $file-2 to $file"
3199 check_times_61 $file "${tim[@]}"
3201 echo "mirror extend $tfile and test timestamps"
3202 $LFS mirror extend -N -c1 -i1 $file ||
3203 error "cannot extend mirror $file"
3204 check_times_61 $file "${tim[@]}"
3206 echo "migrate $tfile and test timestamps"
3207 $LFS migrate -n $file || error "cannot migrate $file"
3208 check_times_61 $file "${tim[@]}"
3210 echo "normal user migrate $tfile and test timestamps"
3211 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3212 check_times_61 $file "${tim[@]}"
3214 run_test 61a "mirror extend and migrate preserve timestamps"
3216 test_61b() { # LU-14508
3217 local file=$DIR/$tdir/$tfile
3223 echo XXX > $file || error "create $file failed"
3224 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3226 echo "sleep $nap seconds, then cat $tfile"
3228 cat $file || error "cat $file failed"
3230 echo "sleep $nap seconds, then re-write $tfile"
3232 echo XXXX > $file || error "write $file failed"
3234 echo "sleep $nap seconds, then test timestamps"
3237 tim=( $(get_times_61 $file) )
3239 echo "mirror extend $tfile and test timestamps"
3240 $LFS mirror extend -N -c1 -i1 $file ||
3241 error "cannot extend mirror $file"
3242 check_times_61 $file "${tim[@]}"
3244 echo "mirror split $tfile and test timestamps"
3245 $LFS mirror split -d --mirror-id=1 $file ||
3246 error "cannot split mirror 1 off $file"
3247 check_times_61 $file "${tim[@]}"
3249 echo "normal user mirror extend $tfile and test timestamps"
3250 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3251 error "cannot extend mirror $file"
3252 check_times_61 $file "${tim[@]}"
3254 run_test 61b "mirror extend and split preserve timestamps"
3256 test_61c() { # LU-14508
3257 local file=$DIR/$tdir/$tfile
3263 echo XXX > $file || error "create $file failed"
3264 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3266 echo "sleep $nap seconds, then cat $tfile"
3268 cat $file || error "cat $file failed"
3270 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3272 $LFS mirror extend -N -c1 -i1 $file ||
3273 error "cannot extend mirror $file"
3274 echo XXXX > $file || error "write $file failed"
3276 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3277 tim=( $(get_times_61 $file) )
3279 $LFS mirror resync $file || error "cannot resync mirror $file"
3280 check_times_61 $file "${tim[@]}"
3282 echo XXXXXX > $file || error "write $tfile failed"
3284 echo "normal user resync $tfile and test timestamps"
3285 tim=( $(get_times_61 $file) )
3286 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3287 check_times_61 $file "${tim[@]}"
3289 run_test 61c "mirror resync preserves timestamps"
3292 local file=$DIR/$tdir/$tfile
3296 echo "create mirror file with unknown magic"
3297 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3298 # mirror 2 in-memory magic is bad
3299 $LCTL set_param fail_loc=0x1426 fail_val=2
3300 $LFS setstripe -N --flags=prefer -N2 $file ||
3301 error "failed to create mirror file $file"
3302 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3303 [[ $magic == 0x0BAD0BD0 ]] ||
3304 error "mirror 2 magic $magic is not bad as expected"
3305 cat /etc/passwd > $file || error "cannot write to $file"
3306 diff /etc/passwd $file || error "read $file error"
3310 echo "create mirror file with unknown pattern"
3311 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3312 # mirror 1 in-memory pattern is bad
3313 $LCTL set_param fail_loc=0x1427 fail_val=1
3314 $LFS setstripe -N -N --flags=prefer $file ||
3315 error "failed to create mirror file $file"
3316 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3317 [[ $pattern == 502 ]] ||
3318 error "mirror 1 pattern $pattern is not bad as expected"
3319 cat /etc/passwd > $file || error "cannot write to $file"
3320 diff /etc/passwd $file || error "read $file error"
3322 run_test 62 "read/write with unknown type of mirror"
3325 local tf=$DIR/$tdir/$tfile
3327 test_mkdir $DIR/$tdir
3328 stack_trap "rm -f $tf"
3332 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3336 echo "mirror create pid $c_pid"
3339 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3342 echo "mirror split pid $s_pid"
3344 echo "mirror create and split race for 60 seconds, should not crash"
3346 kill -9 $c_pid &> /dev/null
3347 kill -9 $s_pid &> /dev/null
3351 run_test 70 "mirror create and split race"
3354 local tf=$DIR/$tdir/$tfile
3356 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3357 skip "Need OST version at least 2.14.51"
3360 test_mkdir $DIR/$tdir
3361 stack_trap "rm -f $tf"
3363 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3364 error "setstripe $tf failed"
3366 FSXNUM=${FSXNUM:-1000}
3367 $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3369 run_test 70a "flr mode fsx test"
3374 local fsize=$(stat --printf=%s $tf)
3376 while [ -f $ctrl_file ]; do
3377 local off=$((RANDOM << 8))
3378 local len=$((RANDOM << 5 + 131072))
3380 [ $((off + len)) -gt $fsize ] && {
3381 fsize=$((off + len))
3382 echo "Extending file size to $fsize .."
3385 flock -s $lock_file -c \
3386 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3388 error "failed writing to $off:$len"; }
3389 sleep 0.$((RANDOM % 2 + 1))
3396 while [ -f $ctrl_file ]; do
3397 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3398 { rm -f $ctrl_file; error "read failed"; }
3399 sleep 0.$((RANDOM % 2 + 1))
3406 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3408 exec 200<>$lock_file
3409 while [ -f $ctrl_file ]; do
3410 local lock_taken=false
3411 local index=$((RANDOM % ${#options[@]}))
3412 local cmd="mirror_io resync ${options[$index]}"
3414 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3416 [ $((RANDOM % 4)) -eq 0 ] && {
3422 echo -n "resync file $tf with '$cmd' .."
3424 if [[ $lock_taken = "true" ]]; then
3426 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3429 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3432 sleep 0.$((RANDOM % 8 + 1))
3436 # this was test_200 before adding "b" and "c" subtests
3438 local tf=$DIR/$tfile
3439 local tf2=$DIR2/$tfile
3440 local tf3=$DIR3/$tfile
3442 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3443 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3444 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3446 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3447 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3448 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3450 $LFS mirror extend -N -f $tf-2 $tf ||
3451 error "merging $tf-2 into $tf failed"
3452 $LFS mirror extend -N -f $tf-3 $tf ||
3453 error "merging $tf-3 into $tf failed"
3455 mkdir -p $MOUNT2 && mount_client $MOUNT2
3457 mkdir -p $MOUNT3 && mount_client $MOUNT3
3459 verify_flr_state $tf3 "ro"
3461 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3462 $LCTL set_param fail_loc=0x1A03
3464 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3465 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3469 write_file_200 $tf &
3475 write_file_200 $tf2 &
3478 read_file_200 $tf2 &
3481 resync_file_200 $tf3 &
3485 [ "$SLOW" = "yes" ] && sleep_time=360
3486 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3493 echo "Waiting ${pids[*]}"
3496 umount_client $MOUNT2
3497 umount_client $MOUNT3
3499 # resync and verify mirrors
3500 $LFS mirror resync $tf || error "final resync failed"
3503 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3505 for id in "${mirror_array[@]:1}"; do
3506 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3507 error "checksum error for mirror $id"
3512 run_test 200a "stress test"
3515 local tf=$DIR/$tfile
3516 local tf2=$DIR2/$tfile
3517 local tf3=$DIR3/$tfile
3519 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3520 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3521 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3523 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3524 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3525 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3527 $LFS mirror extend -N -f $tf-2 $tf ||
3528 error "merging $tf-2 into $tf failed"
3529 $LFS mirror extend -N -f $tf-3 $tf ||
3530 error "merging $tf-3 into $tf failed"
3532 mkdir -p $MOUNT2 && mount_client $MOUNT2
3534 mkdir -p $MOUNT3 && mount_client $MOUNT3
3536 verify_flr_state $tf3 "ro"
3538 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3539 $LCTL set_param fail_loc=0x1423
3543 write_file_200 $tf &
3549 write_file_200 $tf2 &
3552 read_file_200 $tf2 &
3555 resync_file_200 $tf3 &
3559 [ "$SLOW" = "yes" ] && sleep_time=400
3563 echo "Waiting ${pids[@]}"
3566 umount_client $MOUNT2
3567 umount_client $MOUNT3
3569 # resync and verify mirrors
3570 $LFS mirror resync $tf || {
3572 error "final resync failed"
3576 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3577 for id in ${mirror_array[@]:1}; do
3578 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3579 error "checksum error for mirror $id"
3584 run_test 200b "racing IO, mirror extend and resync"
3587 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3588 skip "Need MDS version at least 2.15.53"
3590 local tf=$DIR/$tfile
3591 local tf2=$DIR2/$tfile
3593 mkdir -p $MOUNT2 && mount_client $MOUNT2
3594 stack_trap "umount_client $MOUNT2"
3595 stack_trap "rm -f $tf"
3599 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3601 mdt_idx=$($LFS getstripe -m $tf)
3603 cancel_lru_locks mdc
3604 cancel_lru_locks osc
3606 # start a process modifying file, block it just
3607 # before layout lock acquisition
3608 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3609 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3610 #log "dd to stale replica"
3611 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3617 $LFS mirror extend -N -c -1 $tf2 || {
3619 error "can't mirror"
3621 log "mirror extend done"
3622 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3624 # wait for blocking dd to complete and modify file
3625 wait $PID || error "2nd dd failed"
3628 verify_mirror_count $tf 2
3630 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3633 error "both replicas are still in sync"
3636 $LFS mirror verify -vvv $tf || {
3638 error "corrupted in-sync file"
3641 run_test 200c "layout change racing with open: LOVEA changes"
3643 cleanup_test_201() {
3644 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3646 umount_client $MOUNT2
3650 local delay=${RESYNC_DELAY:-5}
3652 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3653 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3655 stack_trap cleanup_test_201 EXIT
3657 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3658 changelog_register -n)
3660 mkdir -p $MOUNT2 && mount_client $MOUNT2
3664 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3665 [ -z "$log" ] && { sleep 1; continue; }
3667 index=$(echo $log | awk '{print $1}')
3668 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3669 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3670 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3673 [ -z "$file" ] && continue
3675 local now=$(date +%s)
3677 echo "file: $file $fid was modified at $ts, now: $now, " \
3678 "will be resynced at $((ts+delay))"
3680 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3682 $LFS mirror resync $file
3683 echo "$file resync done"
3686 run_test 201 "FLR data mover"
3689 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3691 local tf=$DIR/$tfile
3694 $LFS setstripe -E 1M -S 1M -c 1 $tf
3695 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3696 verify_comp_attr stripe-count $tf ${ids[0]} 1
3698 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3699 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3700 verify_comp_attr stripe-count $tf ${ids[0]} 1
3701 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3703 dd if=/dev/zero of=$tf bs=1M count=2
3704 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3705 verify_comp_attr stripe-count $tf ${ids[0]} 1
3706 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3708 run_test 202 "lfs setstripe --add-component wide striping"
3711 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3712 skip "Need MDS version at least 2.11.55"
3713 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3715 local tf=$DIR/$tfile
3718 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3719 #delete first mirror
3720 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3723 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3724 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3725 error "getstripe count of mirror 2"
3726 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3728 #extend a mirror with 2 OSTs
3729 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3732 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3733 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3734 error "getstripe count of mirror 2"
3735 [[ x$old_id = x$new_id ]] ||
3736 error "mirror 2 changed ID from $old_id to $new_id"
3737 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3739 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3740 error "getstripe count of mirror 3"
3741 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3743 run_test 203 "mirror file preserve mirror ID"
3745 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3747 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3748 skip "skipped for lustre < $SEL_VER"
3750 local comp_file=$DIR/$tdir/$tfile
3754 test_mkdir $DIR/$tdir
3755 stack_trap "rm -f $comp_file"
3757 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3758 # by extension space to -1
3759 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3760 error "Create $comp_file failed"
3762 # Write to first component, extending & staling second mirror
3763 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3764 error "dd to extend + stale failed"
3766 $LFS getstripe $comp_file
3768 flg_opts="--component-flags init,stale"
3769 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3770 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3772 flg_opts="--component-flags extension"
3773 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3774 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3776 # mirror resync should not change the extents
3777 $LFS mirror resync $comp_file
3779 flg_opts="--component-flags init"
3780 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3781 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3783 flg_opts="--component-flags extension"
3784 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3785 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3787 sel_layout_sanity $comp_file 5
3789 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3791 # Simple test of FLR + self-extending layout, SEL in primary mirror
3793 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3794 skip "skipped for lustre < $SEL_VER"
3796 local comp_file=$DIR/$tdir/$tfile
3800 test_mkdir $DIR/$tdir
3801 stack_trap "rm -f $comp_file"
3803 # first mirror is 1M followed by extension space to -1, second mirror
3804 # is 0-10M, then 10M-(-1),
3805 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3806 error "Create $comp_file failed"
3808 # Write to first component, extending first component & staling
3810 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3811 error "dd to extend + stale failed"
3813 $LFS getstripe $comp_file
3815 flg_opts="--component-flags init"
3816 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3817 [ $found -eq 1 ] || error "write: First comp end incorrect"
3819 flg_opts="--component-flags extension"
3820 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3821 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3823 flg_opts="--component-flags init,stale"
3824 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3825 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3827 # This component is staled because it overlaps the extended first
3828 # component of the primary mirror, even though it doesn't overlap
3829 # the actual write - thus not inited.
3830 flg_opts="--component-flags stale"
3831 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3832 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3834 # mirror resync should not change the extents
3835 $LFS mirror resync $comp_file
3837 $LFS getstripe $comp_file
3839 flg_opts="--component-flags init"
3840 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3841 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3843 flg_opts="--component-flags extension"
3844 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3845 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3847 flg_opts="--component-flags init"
3848 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3849 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3851 flg_opts="--component-flags init"
3852 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3853 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3855 sel_layout_sanity $comp_file 5
3857 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3859 # FLR + SEL failed extension & component removal
3860 # extension space in second mirror
3862 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3863 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3864 skip "skipped for lustre < $SEL_VER"
3866 local comp_file=$DIR/$tdir/$tfile
3869 local ost_name=$(ostname_from_index $ost_idx1)
3871 test_mkdir $DIR/$tdir
3872 stack_trap "rm -f $comp_file"
3874 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3875 # extension space from 1M to 1G, then normal space to -1
3876 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3877 -E -1 $comp_file || error "Create $comp_file failed"
3879 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3882 # write to first comp (0 - 10M) of mirror 1, extending + staling
3883 # first + second comp of mirror 2
3884 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3887 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3890 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3892 $LFS getstripe $comp_file
3894 found=$($LFS find --component-start 0m --component-end 1m \
3895 --comp-flags init,stale $comp_file | wc -l)
3896 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3898 found=$($LFS find --component-start 1m --component-end EOF \
3899 --comp-flags stale,^init $comp_file | wc -l)
3900 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3902 local mirror_id=$($LFS getstripe --component-start=1m \
3903 --component-end=EOF $comp_file | \
3904 grep lcme_mirror_id | awk '{ print $2 }')
3906 [[ $mirror_id -eq 2 ]] ||
3907 error "component not in correct mirror? $mirror_id"
3909 $LFS mirror resync $comp_file
3911 $LFS getstripe $comp_file
3913 # component dimensions should not change from resync
3914 found=$($LFS find --component-start 1m --component-end EOF \
3915 --component-flags init $comp_file | wc -l)
3916 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3918 sel_layout_sanity $comp_file 4
3920 run_test 204c "FLR write/stale/resync test with component removal"
3922 # Successful repeated component in primary mirror
3924 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3925 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3926 skip "skipped for lustre < $SEL_VER"
3928 local comp_file=$DIR/$tdir/$tfile
3931 wait_delete_completed
3933 test_mkdir $DIR/$tdir
3934 stack_trap "rm -f $comp_file"
3936 # first mirror is 64M followed by extension space to -1, second mirror
3937 # is 0-10M, then 10M-(-1)
3938 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3939 error "Create $comp_file failed"
3941 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3942 local ost_name=$(ostname_from_index $ost_idx1)
3943 # degrade OST for first comp so we won't extend there
3944 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3945 obdfilter.$ost_name.degraded=1
3948 # Write beyond first component, causing repeat & stale second mirror
3949 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3952 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3953 obdfilter.$ost_name.degraded=0
3956 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3958 $LFS getstripe $comp_file
3960 found=$($LFS find --component-start 64m --component-end 128m \
3961 --component-flags init $comp_file | wc -l)
3962 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3964 local ost_idx2=$($LFS getstripe --component-start=64m \
3965 --component-end=128m --component-flags=init \
3967 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3968 local mirror_id=$($LFS getstripe --component-start=64m \
3969 --component-end=128m --component-flags=init \
3970 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3971 [[ $mirror_id -eq 1 ]] ||
3972 error "component not in correct mirror: $mirror_id, not 1"
3974 $LFS mirror resync $comp_file
3976 $LFS getstripe $comp_file
3978 # component dimensions should not change from resync
3979 found=$($LFS find --component-start 0m --component-end 64m \
3980 --component-flags init $comp_file | wc -l)
3981 [ $found -eq 1 ] || error "resync: first comp incorrect"
3982 found=$($LFS find --component-start 64m --component-end 128m \
3983 --component-flags init $comp_file | wc -l)
3984 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3986 sel_layout_sanity $comp_file 5
3988 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3990 # Successful repeated component, SEL in non-primary mirror
3992 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3993 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3994 skip "skipped for lustre < $SEL_VER"
3996 local comp_file=$DIR/$tdir/$tfile
3999 wait_delete_completed
4002 test_mkdir $DIR/$tdir
4003 stack_trap "rm -f $comp_file"
4005 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4006 # space to -1 (-z 64M, so first comp is 0-64M)
4007 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
4008 # will be not enough - one will be degraded, the other is used on
4009 # an overlapping mirror.
4010 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
4011 error "Create $comp_file failed"
4013 local ost_idx1=$($LFS getstripe --component-start=0 \
4014 --component-end=64m -i $comp_file)
4015 local ost_name=$(ostname_from_index $ost_idx1)
4016 # degrade OST for first comp of 2nd mirror so we won't extend there
4017 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4018 obdfilter.$ost_name.degraded=1
4021 $LFS getstripe $comp_file
4023 # Write to first component, stale & instantiate second mirror components
4024 # overlapping with the written component (0-100M);
4025 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4028 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4029 obdfilter.$ost_name.degraded=0
4031 $LFS getstripe $comp_file
4033 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
4035 found=$($LFS find --component-start 0m --component-end 64m \
4036 --component-flags init,stale $comp_file | wc -l)
4037 [ $found -eq 1 ] || error "write: first comp incorrect"
4039 # was repeated due to degraded ost
4040 found=$($LFS find --component-start 64m --component-end 128m \
4041 --component-flags init,stale $comp_file | wc -l)
4042 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4044 local ost_idx2=$($LFS getstripe --component-start=64m \
4045 --component-end=128m --component-flags=init \
4047 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4048 local mirror_id=$($LFS getstripe --component-start=0m \
4049 --component-end=64m --component-flags=init \
4050 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4051 [[ $mirror_id -eq 2 ]] ||
4052 error "component not in correct mirror? $mirror_id"
4054 $LFS mirror resync $comp_file
4056 $LFS getstripe $comp_file
4058 # component dimensions should not change from resync
4059 found=$($LFS find --component-start 0m --component-end 64m \
4060 --component-flags init,^stale $comp_file | wc -l)
4061 [ $found -eq 1 ] || error "resync: first comp incorrect"
4062 found=$($LFS find --component-start 64m --component-end 128m \
4063 --component-flags init,^stale $comp_file | wc -l)
4064 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4066 sel_layout_sanity $comp_file 5
4068 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4070 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4072 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4073 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4074 skip "skipped for lustre < $SEL_VER"
4076 local comp_file=$DIR/$tdir/$tfile
4079 wait_delete_completed
4081 test_mkdir $DIR/$tdir
4082 stack_trap "rm -f $comp_file"
4084 pool_add $TESTNAME || error "Pool creation failed"
4085 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4087 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4088 # space to -1 (-z 64M, so first comp is 0-64M)
4089 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4090 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4092 local ost_name0=$(ostname_from_index 0)
4093 local ost_name1=$(ostname_from_index 1)
4095 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4096 # extend original comp
4097 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4098 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4101 # a write to the 1st component, 100M length, which will try to stale
4102 # the first 100M of mirror 2, attempting to extend its 0-64M component
4103 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4106 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4107 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4110 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4112 $LFS getstripe $comp_file
4114 found=$($LFS find --component-start 0m --component-end 128m \
4115 --component-flags init,stale $comp_file | wc -l)
4116 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4118 local mirror_id=$($LFS getstripe --component-start=0m \
4119 --component-end=128m --component-flags=init \
4120 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4122 [[ $mirror_id -eq 2 ]] ||
4123 error "component not in correct mirror? $mirror_id, not 2"
4125 $LFS mirror resync $comp_file
4127 $LFS getstripe $comp_file
4129 # component dimensions should not change from resync
4130 found=$($LFS find --component-start 0m --component-end 128m \
4131 --component-flags init,^stale $comp_file | wc -l)
4132 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4134 sel_layout_sanity $comp_file 4
4136 run_test 204f "FLR write/stale/resync sel w/forced extension"
4138 function test_205() {
4139 local tf=$DIR/$tfile
4142 $LFS setstripe -c1 $tf
4143 $LFS mirror extend -N $tf
4144 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4145 (( $mirrors == 2 )) || error "no new mirror was created?"
4147 $LFS mirror extend -N --flags=prefer $tf
4148 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4149 (( $mirrors == 3 )) || error "no new mirror with prefer flag was created?"
4151 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4152 error "prefer flag was not set on the new mirror"
4154 $LFS mirror extend -N --flags=nocompr $tf
4155 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4156 (( $mirrors == 4 )) || error "no new mirror with nocompr flag was created?"
4158 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q nocompr) ||
4159 error "nocompr flag was not set on the new mirror"
4161 $LFS mirror extend -N --flags=prefer,nocompr $tf
4162 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4163 (( $mirrors == 5 )) || error "no new mirror with prefer,nocompr flags was created?"
4165 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q "prefer,nocompr") ||
4166 error "prefer,nocompr flags were not set on the new mirror"
4168 run_test 205 "lfs mirror extend to set prefer and nocompr flags"
4170 function test_206() {
4171 # create a new OST pool
4172 local pool_name=$TESTNAME
4174 create_pool $FSNAME.$pool_name ||
4175 error "create OST pool $pool_name failed"
4176 # add OSTs into the pool
4177 pool_add_targets $pool_name 0 1 ||
4178 error "add OSTs into pool $pool_name failed"
4180 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4181 error "can't setstripe"
4182 $LFS mirror extend -N $DIR/$tfile ||
4183 error "can't create replica"
4184 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4185 $LFS getstripe $DIR/$tfile
4186 error "prefer found"
4188 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4189 $LFS getstripe $DIR/$tfile
4190 error "can't setstripe prefer"
4193 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4194 $LFS getstripe $DIR/$tfile
4195 error "no prefer found"
4201 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4204 local file=$DIR/$tfile
4205 local tmpfile=$DIR/$tfile-tt
4207 (( $MDS1_VERSION >= $(version_code v2_14_50-161-g571f3cf111) )) ||
4208 skip "Need MDS >= 2.14.50.161 for stale components fix"
4210 stack_trap "rm -f $tmpfile $file"
4212 # generate data for verification
4213 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4214 error "can't generate file with random data"
4216 # create a mirrored file with one stale replica
4217 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4218 error "create mirrored file $file failed"
4219 get_mirror_ids $file
4220 echo "mirror IDs: ${mirror_array[*]}"
4222 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4223 get_mirror_ids $file
4224 echo "mirror IDs: ${mirror_array[*]}"
4227 cmp $tmpfile $file || error "files don't match"
4228 get_mirror_ids $file
4229 echo "mirror IDs: ${mirror_array[*]}"
4231 # mirror creation should work fine
4232 $LFS mirror extend -N -S 8M -c -1 $file ||
4233 error "mirror extend $file failed"
4235 get_mirror_ids $file
4236 echo "mirror IDs: ${mirror_array[*]}"
4239 $LFS mirror verify -v $file || error "verification failed"
4240 cmp $tmpfile $file || error "files don't match"
4242 run_test 207 "create another replica with existing out-of-sync one"
4244 function check_ost_used() {
4253 cancel_lru_locks osc # to drop pages
4254 cancel_lru_locks mdc # to refresh layout
4255 # XXX: cancel_lru_locks mdc doesn't work
4256 # XXX: need a better way to reload the layout
4257 umount_client $MOUNT || error "umount failed"
4258 mount_client $MOUNT || error "mount failed"
4260 # refresh non-rotation status on MDTs
4262 touch $DIR/$tfile-temp
4263 rm -f $DIR/$tfile-temp
4264 # refresh non-rotational status on the client
4268 $LCTL set_param osc.*.stats=clear >/dev/null
4269 if [[ $io == "read" ]]; then
4270 ddarg="if=$file of=/dev/null"
4271 elif [[ $io == "write" ]]; then
4272 ddarg="if=/dev/zero of=$file"
4274 error "unknown type $io"
4276 dd $ddarg bs=8M count=1 || error "can't $io $file"
4277 cancel_lru_locks osc
4279 # check only specified OSTs got reads
4280 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4281 local nr=$($LCTL get_param -n \
4282 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4283 awk "/ost_$io/{print \$2}")
4285 if [[ " $* " =~ $ost ]]; then
4286 (( nr > 0 )) || error "expected reads on $ost"
4288 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4294 local tf=$DIR/$tfile
4295 local osts=$(comma_list $(osts_nodes))
4297 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4298 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4299 skip "Need MDS version at least 2.14.55"
4301 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4303 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4304 stack_trap "restore_lustre_params < $p; rm -f $p"
4306 stack_trap "rm -f $tf"
4307 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4308 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4309 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4310 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4311 $LFS mirror resync $tf || error "can't resync"
4314 log "set OST0000 non-rotational"
4316 $LCTL set_param osd*.*OST*.nonrotational=0
4318 $LCTL set_param osd*.*OST0000*.nonrotational=1
4319 check_ost_used $tf read 0
4321 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4323 $LCTL set_param osd*.*OST*.nonrotational=0
4325 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4326 osd*.*OST0003*.nonrotational=1
4327 check_ost_used $tf read 2 3
4329 log "set mirror 1 on OST0001 preferred"
4330 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4331 error "can't set prefer"
4332 check_ost_used $tf read 1
4334 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4337 local tf=$DIR/$tfile
4338 local osts=$(comma_list $(osts_nodes))
4340 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4341 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4342 skip "Need MDS version at least 2.14.55"
4344 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4346 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4347 stack_trap "restore_lustre_params < $p; rm -f $p"
4349 stack_trap "rm -f $tf"
4350 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4351 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4352 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4353 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4354 $LFS mirror resync $tf || error "can't resync"
4355 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4357 log "set OST0000 non-rotational"
4359 $LCTL set_param osd*.*OST*.nonrotational=0
4361 $LCTL set_param osd*.*OST0000*.nonrotational=1
4362 check_ost_used $tf write 0
4363 $LFS mirror resync $tf || error "can't resync"
4365 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4367 $LCTL set_param osd*.*OST*.nonrotational=0
4369 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4370 osd*.*OST0003*.nonrotational=1
4371 check_ost_used $tf write 2 3
4372 $LFS mirror resync $tf || error "can't resync"
4374 log "set mirror 1 on OST0001 preferred"
4375 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4376 error "can't set prefer"
4377 check_ost_used $tf write 1
4379 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4382 local tf=$DIR/$tfile
4383 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4384 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4385 local osts=$(comma_list $(osts_nodes))
4387 stack_trap "rm -f $tmpfile"
4389 mkdir -p $MOUNT2 && mount_client $MOUNT2
4390 stack_trap "umount_client $MOUNT2"
4392 # to make replica on ost1 preferred for new writes
4393 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4394 stack_trap "restore_lustre_params < $p; rm -f $p"
4396 $LCTL set_param osd*.*OST*.nonrotational=0
4398 $LCTL set_param osd*.*OST0001*.nonrotational=1
4400 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4402 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4403 log "replicated file created"
4405 cancel_lru_locks mdc
4406 cancel_lru_locks osc
4408 log "open(O_RDONLY) and first read from OST"
4409 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4412 log "first read complete"
4414 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4415 error "can't write BBBB"
4416 log "BBBB written which made replica on ost1 stale"
4418 log "fast read from pagecache in the original process"
4422 log "read via $DIR2 new open(2)"
4423 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4425 log "fast read from pagecache after 5s in the original process"
4430 local nr=$(grep "BBBB" $tmpfile | wc -l)
4436 log "read via new open(2)"
4437 $MULTIOP $tf vvoO_RDONLY:r4c
4439 run_test 209a "skip fast reads after layout invalidation"
4441 function sum_ost_reads() {
4442 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4443 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4447 local tf=$DIR/$tfile
4449 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4450 cancel_lru_locks osc
4451 echo "the very first read"
4452 cat $tf >/dev/null || error "can't read"
4454 # cancel layout lock
4455 cancel_lru_locks mdc
4457 # now read again, data must be in the cache, so no ost reads
4458 $LCTL set_param osc.*.stats=clear >/dev/null
4459 echo "read with warm cache"
4460 cat $tf >/dev/null || error "can't read"
4462 (( nr == 0 )) || error "reads with warm cache"
4464 # now verify we can catch reads at all
4465 cancel_lru_locks osc
4466 cat $tf >/dev/null || error "can't read"
4468 (( nr > 0 )) || error "no reads with cold cache"
4470 run_test 209b "pagecache can be used after LL cancellation"
4473 local tf=$DIR/$tfile
4475 stack_trap "rm -f $tf"
4476 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4477 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4478 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4479 $LFS mirror extend -N $tf || error "can't mirror"
4480 $LFS getstripe -v $tf
4481 stat $tf || error "can't stat"
4483 run_test 210a "handle broken mirrored lovea"
4486 local tf=$DIR/$tfile
4488 [ "$FSTYPE" != "zfs" ] || skip "ZFS file number is not accurate"
4490 $LFS setstripe -i0 -c1 $tf || error "can't create file"
4491 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4493 local ostdev=$(ostdevname 1)
4494 local fid=($($LFS getstripe $DIR/$tfile | grep 0x))
4495 local seq=${fid[3]#0x}
4498 if [ $seq == 0 ]; then
4501 oid_hex=${fid[2]#0x}
4503 local objpath="O/$seq/d$(($oid % 32))/$oid_hex"
4504 local cmd="$DEBUGFS -c -R \\\"stat $objpath\\\" $ostdev"
4506 local ino=$(do_facet ost1 $cmd | grep Inode:)
4507 [[ -n $ino ]] || error "can't access obj object: $objpath"
4509 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4510 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4511 $LFS mirror extend -N $tf || error "can't mirror"
4513 # now remove the file with bogus ostidx in the striping info
4514 rm $tf || error "can't remove"
4515 [[ -f $tf ]] && error "rm failed"
4516 wait_delete_completed
4518 local ino=$(do_facet ost1 $cmd | grep Inode:)
4519 [[ -z $ino ]] || error "still CAN access obj object: $objpath"
4521 run_test 210b "handle broken mirrored lovea (unlink)"
4523 complete_test $SECONDS
4524 check_and_cleanup_lustre