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 "
33 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
34 skip "Need MDS version at least 2.10.56"
36 check_and_setup_lustre
39 rm -rf $DIR/[Rdfs][0-9]*
41 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
42 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
47 # global array to store mirror IDs
48 declare -a mirror_array
55 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
56 array[${#array[@]}]=$((id >> 16))
59 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
61 echo ${#mirror_array[@]}
65 echo 3 > /proc/sys/vm/drop_caches
76 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
84 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
85 error "start ost$idx failed"
89 wait_recovery_complete ost$idx
94 # Verify mirror count with an expected value for a given file.
96 verify_mirror_count() {
99 local mirror_count=$($LFS getstripe -N $tf)
101 [[ $mirror_count = $expected ]] || {
102 $LFS getstripe -v $tf
103 error "verify mirror count failed on $tf:" \
104 "$mirror_count != $expected"
109 # Verify component count with an expected value for a given file.
110 # $1 coposited layout file
111 # $2 expected component number
113 verify_comp_count() {
116 local comp_count=$($LFS getstripe --component-count $tf)
118 [[ $comp_count = $expected ]] || {
119 $LFS getstripe -v $tf
120 error "verify component count failed on $tf:" \
121 "$comp_count != $expected"
126 # Verify component attribute with an expected value for a given file
134 local cmd="$LFS getstripe -I$comp_id"
135 local getstripe_cmd="$cmd -v"
139 stripe-size) cmd+=" -S $tf" ;;
140 stripe-count) cmd+=" -c $tf" ;;
141 stripe-index) cmd+=" -i $tf" ;;
142 pool) cmd+=" -p $tf" ;;
143 comp-start) cmd+=" --component-start $tf" ;;
144 comp-end) cmd+=" --component-end $tf" ;;
145 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
146 *) error "invalid attribute $attr";;
151 [ $attr = lcme_flags ] && {
153 local expected_list=$(comma_list $expected)
154 for fl in ${expected_list//,/ }; do
157 [[ ${fl:0:1} = "^" ]] && neg=1
158 [[ $neg = 1 ]] && fl=${fl:1}
160 $(echo $value | grep -q $fl)
162 # 0: matched; 1: not matched
164 if [[ $neg = 0 && $match != 0 ||
165 $neg = 1 && $match = 0 ]]; then
167 [[ $neg = 0 ]] && # expect the flag
168 error "expected flag '$fl' not in $comp_id"
169 [[ $neg = 1 ]] && # not expect the flag
170 error "not expected flag '$fl' in $comp_id"
176 [[ $value = $expected ]] ||
177 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
178 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
180 error "verify $attr failed on $tf: $value != $expected"
185 # Verify component extent with expected start and end extent values
186 # for a given file and component ID.
188 verify_comp_extent() {
191 local expected_start=$3
192 local expected_end=$4
194 verify_comp_attr comp-start $tf $comp_id $expected_start
195 verify_comp_attr comp-end $tf $comp_id $expected_end
199 # Verify component attribute with parent directory for a given file
202 verify_comp_attr_with_parent() {
206 local td=$(cd $(dirname $tf); echo $PWD)
207 local tf_cmd="$LFS getstripe -I$comp_id"
208 local td_cmd="$LFS getstripe"
214 stripe-size) opt="-S" ;;
215 stripe-count) opt="-c" ;;
217 *) error "invalid attribute $attr";;
220 expected=$($td_cmd $opt $td)
221 [[ $expected = -1 ]] && expected=$OSTCOUNT
223 value=$($tf_cmd $opt $tf)
224 [[ $value = -1 ]] && value=$OSTCOUNT
226 [[ $value = $expected ]] ||
227 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
228 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
231 error "verify $attr failed with parent on $tf:" \
232 "$value != $expected"
237 # Verify component attribute with filesystem-wide default value for a given file
240 verify_comp_attr_with_default() {
244 local tf_cmd="$LFS getstripe -I$comp_id"
252 expected=$($LCTL get_param -n \
253 lov.$FSNAME-clilov-*.stripesize)
257 expected=$($LCTL get_param -n \
258 lov.$FSNAME-clilov-*.stripecount)
259 [[ $expected = -1 ]] && expected=$OSTCOUNT
261 *) error "invalid attribute $attr";;
264 value=$($tf_cmd $opt $tf)
265 [[ $value = -1 ]] && value=$OSTCOUNT
267 [[ $value = $expected ]] ||
268 # file sometimes one stripe short if MDS-OST didn't precreate, LU-16623
269 [[ $attr == "stripe-count" && $value == $((OSTCOUNT - 1)) ]] || {
271 error "verify $attr failed with default value on $tf:" \
272 "$value != $expected"
277 # Verify unspecified component attributes for a given file
280 # This will only verify the inherited attributes:
281 # stripe size, stripe count and OST pool name
283 verify_comp_attrs() {
287 verify_comp_attr_with_default stripe-size $tf $comp_id
288 verify_comp_attr_with_default stripe-count $tf $comp_id
289 verify_comp_attr_with_parent pool $tf $comp_id
295 local expected_state=$2
297 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
298 [ $expected_state = $state ] ||
299 error "expected: $expected_state, actual $state"
302 # command line test cases
306 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
307 local mirror_cmd="$LFS mirror create"
312 # create parent directory
313 mkdir $td || error "mkdir $td failed"
315 $mirror_cmd $tf &> /dev/null && error "miss -N option"
317 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
318 verify_mirror_count $tf 1
319 id=$($LFS getstripe -I $tf)
320 verify_comp_attrs $tf $id
321 verify_comp_extent $tf $id 0 EOF
323 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
324 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
325 error "invalid mirror count $((mirror_count + 1))"
327 $mirror_cmd -N$mirror_count $tf-1 ||
328 error "create mirrored file $tf-1 failed"
329 verify_mirror_count $tf-1 $mirror_count
330 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
331 for ((i = 0; i < $mirror_count; i++)); do
332 verify_comp_attrs $tf-1 ${ids[$i]}
333 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
336 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
337 error "create mirrored file $tf-2 failed"
338 verify_mirror_count $tf-2 10
339 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
340 for ((i = 0; i < 10; i++)); do
341 verify_comp_attrs $tf-2 ${ids[$i]}
342 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
345 run_test 0a "lfs mirror create with -N option"
348 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
352 local mirror_cmd="$LFS mirror create"
356 # create a new OST pool
357 local pool_name=$TESTNAME
358 create_pool $FSNAME.$pool_name ||
359 error "create OST pool $pool_name failed"
361 # add OSTs into the pool
362 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
363 error "add OSTs into pool $pool_name failed"
365 # create parent directory
366 mkdir $td || error "mkdir $td failed"
367 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
368 error "$LFS setstripe $td failed"
370 create_pool $FSNAME.flash || error "create OST pool flash failed"
371 create_pool $FSNAME.archive || error "create OST pool archive failed"
373 # create a mirrored file with plain layout mirrors
374 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
375 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
376 error "create mirrored file $tf failed"
377 verify_mirror_count $tf 6
378 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
379 for ((i = 0; i < 6; i++)); do
380 verify_comp_extent $tf ${ids[$i]} 0 EOF
383 # verify component ${ids[0]}
384 verify_comp_attrs $tf ${ids[0]}
386 # verify component ${ids[1]}
387 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
388 verify_comp_attr stripe-count $tf ${ids[1]} 2
389 verify_comp_attr stripe-index $tf ${ids[1]} 2
391 # verify component ${ids[2]}
392 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
393 verify_comp_attr stripe-count $tf ${ids[2]} 2
394 verify_comp_attr pool $tf ${ids[2]} flash
396 # verify component ${ids[3]}
397 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
398 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
399 verify_comp_attr pool $tf ${ids[3]} flash
401 # verify component ${ids[4]}
402 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
403 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
404 verify_comp_attr pool $tf ${ids[4]} archive
406 # verify component ${ids[5]}
407 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
408 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
409 verify_comp_attr_with_parent pool $tf ${ids[5]}
411 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
412 # LU-11022 - remove mirror by pool name
413 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
414 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
415 $LFS mirror delete --pool archive $tf || error "delete mirror"
416 cnt=$($LFS getstripe $tf | grep archive | wc -l)
417 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
423 run_test 0b "lfs mirror create plain layout mirrors"
426 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
430 local mirror_cmd="$LFS mirror create"
434 # create a new OST pool
435 local pool_name=$TESTNAME
436 create_pool $FSNAME.$pool_name ||
437 error "create OST pool $pool_name failed"
439 # add OSTs into the pool
440 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
441 error "add OSTs into pool $pool_name failed"
443 # create parent directory
444 mkdir $td || error "mkdir $td failed"
445 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
446 error "$LFS setstripe $td failed"
448 create_pool $FSNAME.flash ||
449 error "create OST pool flash failed"
450 create_pool $FSNAME.archive ||
451 error "create OST pool archive failed"
453 # create a mirrored file with composite layout mirrors
454 $mirror_cmd -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
456 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
457 error "create mirrored file $tf failed"
458 verify_mirror_count $tf 6
459 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
461 # verify components ${ids[0]} and ${ids[2]}
463 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
464 verify_comp_attr stripe-count $tf ${ids[$i]} 2
465 verify_comp_attr stripe-index $tf ${ids[$i]} 1
466 verify_comp_extent $tf ${ids[$i]} 0 8388608
469 # verify components ${ids[1]} and ${ids[3]}
471 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
472 verify_comp_attr stripe-count $tf ${ids[$i]} 2
473 verify_comp_attr pool $tf ${ids[$i]} flash
474 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
477 # verify component ${ids[4]}
478 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
479 verify_comp_attr stripe-count $tf ${ids[4]} 4
480 verify_comp_attr_with_parent pool $tf ${ids[4]}
481 verify_comp_extent $tf ${ids[4]} 0 EOF
483 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
485 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
486 verify_comp_attr stripe-count $tf ${ids[$i]} 4
487 verify_comp_attr pool $tf ${ids[$i]} archive
488 verify_comp_extent $tf ${ids[$i]} 0 536870912
491 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
493 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
494 # ffdf which is -33 and matches LOV_ALL_STRIPES_MIN
495 local decimal_lov_lower_limit=-33
496 #C_opt is -c option which can be -1 to -32
498 local count_exp=$(($decimal_lov_lower_limit + $C_opt + 1))
500 verify_comp_attr stripe-count $tf ${ids[$i]} $count_exp
501 verify_comp_attr pool $tf ${ids[$i]} archive
502 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
508 run_test 0c "lfs mirror create composite layout mirrors"
513 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
514 local mirror_cmd="$LFS mirror extend"
518 # create parent directory
519 mkdir $td || error "mkdir $td failed"
521 $mirror_cmd $tf &> /dev/null && error "miss -N option"
522 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
524 # create a non-mirrored file, convert it to a mirrored file and extend
525 touch $tf || error "touch $tf failed"
526 $mirror_cmd -N $tf || error "convert and extend $tf failed"
527 verify_mirror_count $tf 2
528 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
529 for ((i = 0; i < 2; i++)); do
530 verify_comp_attrs $tf ${ids[$i]}
531 verify_comp_extent $tf ${ids[$i]} 0 EOF
534 lfsck_verify_pfid $tf || error "PFID is not set"
536 # create a mirrored file and extend it
537 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
538 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
539 $LFS mirror create -N $tf-3 || error "create mirrored file $tf-3 failed"
541 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 ||
542 error "extend mirror with -f failed"
544 $mirror_cmd -N$((mirror_count - 1)) $tf-3 ||
545 error "extend mirrored file $tf-3 failed"
546 verify_mirror_count $tf-3 $mirror_count
547 ids=($($LFS getstripe $tf-3 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
548 for ((i = 0; i < $mirror_count; i++)); do
549 verify_comp_attrs $tf-3 ${ids[$i]}
550 verify_comp_extent $tf-3 ${ids[$i]} 0 EOF
553 $mirror_cmd -N $tf-3 &> /dev/null
555 (( $rc == 34 || $MDS1_VERSION < $(version_code v2_14_57-72-gf468093cb6) )) ||
556 error "exceeded maximum mirror count returns $rc not ERANGE(34)"
558 run_test 0d "lfs mirror extend with -N option"
561 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
565 local mirror_cmd="$LFS mirror extend"
569 # create parent directory
570 mkdir $td || error "mkdir $td failed"
572 create_pool $FSNAME.ssd ||
573 error "create OST pool ssd failed"
575 # create a mirrored file with plain layout mirrors
576 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
577 error "create mirrored file $tf failed"
579 create_pool $FSNAME.flash ||
580 error "create OST pool flash failed"
581 create_pool $FSNAME.archive ||
582 error "create OST pool archive failed"
584 # extend the mirrored file with plain layout mirrors
585 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
586 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
587 error "extend mirrored file $tf failed"
588 verify_mirror_count $tf 6
589 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
590 for ((i = 0; i < 6; i++)); do
591 verify_comp_extent $tf ${ids[$i]} 0 EOF
594 # verify component ${ids[0]}
595 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
596 verify_comp_attr stripe-count $tf ${ids[0]} 3
597 verify_comp_attr stripe-index $tf ${ids[0]} 1
599 # verify component ${ids[1]}
600 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
601 verify_comp_attr stripe-count $tf ${ids[1]} 2
602 verify_comp_attr stripe-index $tf ${ids[1]} 2
604 # verify component ${ids[2]}
605 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
606 verify_comp_attr stripe-count $tf ${ids[2]} 2
607 verify_comp_attr pool $tf ${ids[2]} flash
609 # verify component ${ids[3]}
610 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
611 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
612 verify_comp_attr pool $tf ${ids[3]} flash
614 # verify component ${ids[4]}
615 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
616 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
617 verify_comp_attr pool $tf ${ids[4]} archive
619 # verify component ${ids[5]}
620 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
621 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
622 verify_comp_attr_with_parent pool $tf ${ids[5]}
624 run_test 0e "lfs mirror extend plain layout mirrors"
627 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
631 local mirror_cmd="$LFS mirror extend"
635 # create parent directory
636 mkdir $td || error "mkdir $td failed"
638 create_pool $FSNAME.ssd ||
639 error "create OST pool ssd failed"
641 # create a mirrored file with composite layout mirror
642 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
643 error "create mirrored file $tf failed"
645 create_pool $FSNAME.flash ||
646 error "create OST pool flash failed"
647 create_pool $FSNAME.archive ||
648 error "create OST pool archive failed"
650 # extend the mirrored file with composite layout mirrors
651 $mirror_cmd -N -p archive \
652 -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
654 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
655 error "extend mirrored file $tf failed"
656 verify_mirror_count $tf 8
657 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
659 # verify component ${ids[0]}
660 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
661 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
662 verify_comp_attr pool $tf ${ids[0]} ssd
663 verify_comp_extent $tf ${ids[0]} 0 33554432
665 # verify component ${ids[1]}
666 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
667 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
668 verify_comp_attr pool $tf ${ids[1]} ssd
669 verify_comp_extent $tf ${ids[1]} 33554432 EOF
671 # verify component ${ids[2]}
672 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
673 verify_comp_attr_with_default stripe-count $tf ${ids[2]}
674 verify_comp_attr pool $tf ${ids[2]} archive
675 verify_comp_extent $tf ${ids[2]} 0 EOF
677 # verify components ${ids[3]} and ${ids[5]}
679 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
680 verify_comp_attr stripe-count $tf ${ids[$i]} 2
681 verify_comp_attr stripe-index $tf ${ids[$i]} 1
682 verify_comp_extent $tf ${ids[$i]} 0 8388608
685 # verify components ${ids[4]} and ${ids[6]}
687 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
688 verify_comp_attr stripe-count $tf ${ids[$i]} 2
689 verify_comp_attr pool $tf ${ids[$i]} flash
690 verify_comp_extent $tf ${ids[$i]} 8388608 EOF
693 # verify component ${ids[7]}
694 verify_comp_attr stripe-size $tf ${ids[7]} 4194304
695 verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
696 verify_comp_attr_with_parent pool $tf ${ids[7]}
697 verify_comp_extent $tf ${ids[7]} 0 EOF
699 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
701 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
702 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
703 verify_comp_attr pool $tf ${ids[$i]} archive
704 verify_comp_extent $tf ${ids[$i]} 0 536870912
707 # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
709 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
710 # ffdf which is -33 and matches LOV_ALL_STRIPES_MIN
711 local decimal_lov_lower_limit=-33
712 #C_opt is -c option which can be -1 to -32
714 local count_exp=$(($decimal_lov_lower_limit + $C_opt + 1))
716 verify_comp_attr stripe-count $tf ${ids[$i]} $count_exp
717 verify_comp_attr pool $tf ${ids[$i]} archive
718 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
721 run_test 0f "lfs mirror extend composite layout mirrors"
726 ! $LFS mirror create --flags prefer $tf ||
727 error "creating $tf w/ --flags but w/o -N option should fail"
729 ! $LFS mirror create -N --flags foo $tf ||
730 error "creating $tf with '--flags foo' should fail"
732 ! $LFS mirror create -N --flags stale $tf ||
733 error "creating $tf with '--flags stale' should fail"
735 ! $LFS mirror create -N --flags prefer,init $tf ||
736 error "creating $tf with '--flags prefer,init' should fail"
738 ! $LFS mirror create -N --flags ^prefer $tf ||
739 error "creating $tf with '--flags ^prefer' should fail"
741 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
742 -N -o1 $tf || error "create mirrored file $tf failed"
744 verify_comp_attr lcme_flags $tf 0x10001 prefer
745 verify_comp_attr lcme_flags $tf 0x10002 prefer
747 # write to the mirrored file and check primary
748 cp /etc/hosts $tf || error "error writing file '$tf'"
750 verify_comp_attr lcme_flags $tf 0x20003 stale
752 # resync file and check prefer flag
753 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
756 $LCTL set_param osc.*.stats=clear
757 cat $tf &> /dev/null || error "error reading file '$tf'"
759 # verify that the data was provided by OST1 where mirror 1 resides
760 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
761 awk '/ost_read/{print $2}')
762 [ -n "$nr_read" ] || error "read was not provided by OST1"
764 run_test 0g "lfs mirror create flags support"
767 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
768 skip "Need MDS version at least 2.11.57"
776 # create parent directory
777 test_mkdir $td || error "mkdir $td failed"
779 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
780 error "set default mirrored layout on directory $td failed"
782 # verify flags are inherited from the directory
785 verify_comp_attr lcme_flags $tf 0x10001 prefer
786 verify_comp_attr lcme_flags $tf 0x10002 prefer
788 # set flags to the first component
789 ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
790 error "setting '^prefer,foo' flags should fail"
792 ! $LFS getstripe --component-flags=prefer,foo $tf ||
793 error "getting component(s) with 'prefer,foo' flags should fail"
795 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
797 verify_comp_attr lcme_flags $tf 0x10001 stale
798 verify_comp_attr lcme_flags $tf 0x10002 prefer
800 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
801 error "clearing 'stale' should fail"
803 # write and resync file. It can't resync the file directly because the
804 # file state is still 'ro'
805 cp /etc/hosts $tf || error "error writing file '$tf'"
806 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
808 for flag in prefer prefrd prefwr; do
809 $LFS setstripe --comp-set -I 0x20003 --comp-flags=$flag $tf ||
810 error "error setting flag $flag"
812 verify_comp_attr lcme_flags $tf 0x20003 $flag
814 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^$flag $tf ||
815 error "error clearing $flag flag from component 0x20003"
818 # MDS disallows setting stale flag on the last non-stale mirror
819 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
821 cp /etc/hosts $tf || error "error writing file '$tf'"
823 verify_comp_attr lcme_flags $tf 0x10002 prefer
824 verify_comp_attr lcme_flags $tf 0x20003 stale
825 verify_comp_attr lcme_flags $tf 0x30004 stale
827 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
829 error "setting stale flag on component 0x10002 should fail"
831 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
833 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
834 error "error setting stale flag on component 0x10001"
835 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
836 error "error setting stale flag on component 0x20003"
838 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
840 error "setting stale flag on component 0x30004 should fail"
842 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
844 run_test 0h "set, clear and test flags for FLR files"
847 $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
849 cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
850 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
851 cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
853 $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || error "read mirror failed"
854 stack_trap "rm -f $TMP/$tfile"
855 cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
856 $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || error "write failed"
857 $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
858 error "set component 1 stale failed"
859 $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
860 cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
862 run_test 0j "test lfs mirror read/write commands"
865 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
868 # default FLR with 2 mirrors
869 $LFS setstripe -N -c1 -i0 -N -c1 -i1 $DIR/$tdir ||
870 error "set default layout failed"
872 # plain file extension under default FLR dir
873 echo $tfile >> $DIR/$tdir/$tfile.append || error "create $tfile.append failed"
874 echo -n " before extend $tfile.append, mirror count = "
875 $LFS getstripe -N $DIR/$tdir/$tfile.append
877 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile.append ||
878 error "mirror extend failed"
879 echo -n " after extend $tfile.append, mirror count = "
880 $LFS getstripe -N $DIR/$tdir/$tfile.append
882 # normal file extension under default FLR dir
883 touch $DIR/$tdir/$tfile || error "create $tfile failed"
884 echo -n " before extend $tfile, mirror count = "
885 $LFS getstripe -N $DIR/$tdir/$tfile
887 $LFS mirror extend -N -c1 -i2 $DIR/$tdir/$tfile ||
888 error "mirror extend $tfile failed"
889 echo -n " after extend $tfile, mirror count = "
890 $LFS getstripe -N $DIR/$tdir/$tfile
892 run_test 0k "mirroring a file in directory with default FLR layout"
896 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
897 local mirror_create_cmd="$LFS mirror create"
898 local stripes[0]=$OSTCOUNT
900 mirror_create_cmd+=" -N -c ${stripes[0]}"
901 for ((i = 1; i < $mirror_count; i++)); do
902 # add mirrors with different stripes to the file
903 stripes[$i]=$((RANDOM % OSTCOUNT))
904 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
906 mirror_create_cmd+=" -N -c ${stripes[$i]}"
909 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
910 verify_mirror_count $tf $mirror_count
912 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
913 $LFS mirror extend -N $tf &&
914 error "Creating the $((mirror_count+1))th mirror succeeded"
916 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
919 # verify the range of components and stripe counts
920 for ((i = 0; i < $mirror_count; i++)); do
921 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
922 verify_comp_extent $tf ${ids[$i]} 0 EOF
925 run_test 1 "create components with setstripe options"
929 local tf2=$DIR/$tfile-2
931 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
932 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
934 $LFS mirror extend -N -f $tf2 $tf ||
935 error "merging $tf2 into $tf failed"
937 verify_mirror_count $tf 2
938 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
940 run_test 2 "create components from existing files"
943 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
945 for ((i = 0; i < 2; i++)); do
946 $LFS mkdir -i $i $DIR/$tdir-$i
947 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
950 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
951 $DIR/$tdir-0/$tfile || error "creating mirrors"
953 # mdt doesn't support to cancel layout lock for remote objects, do
957 # make sure the mirrorted file was created successfully
958 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
959 { $LFS getstripe $DIR/$tdir-0/$tfile;
960 error "expected 2 components"; }
965 run_test 3 "create components from files located on different MDTs"
968 local tf=$DIR/$tdir/$tfile
971 test_mkdir $DIR/$tdir
973 # set mirror with setstripe options to directory
974 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
975 error "set mirror to directory error"
977 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
978 x"mirrored" ] || error "failed to create mirrored dir"
981 verify_mirror_count $tf 2
983 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
984 verify_comp_extent $tf ${ids[0]} 0 1048576
985 verify_comp_extent $tf ${ids[1]} 1048576 EOF
987 # sub directory should inherit mirror setting from parent
988 test_mkdir $DIR/$tdir/td
989 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
990 x"mirrored" ] || error "failed to inherit mirror from parent"
992 # mirror extend won't be applied to directory
993 $LFS mirror extend -N2 $DIR/$tdir &&
994 error "expecting mirror extend failure"
997 run_test 4 "Make sure mirror attributes can be inhertied from directory"
1000 local tf=$DIR/$tfile
1003 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
1004 error "failed to create file with non-empty layout"
1005 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
1007 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
1008 verify_mirror_count $tf 3
1010 $CHECKSTAT -t file -s 12345 $tf ||
1011 error "size error after attaching layout "
1013 run_test 5 "Make sure init size work for mirrored layout"
1016 (( $MDS1_VERSION >= $(version_code 2.12.58) )) ||
1017 skip "MDS version older than 2.12.58"
1019 local tf=$DIR/$tfile
1021 $LFS mirror create -N -E 1M -L mdt -E eof -S 1M -N -E eof $tf ||
1022 error "failure to create DoM file with mirror"
1024 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf ||
1025 error "failure to create mirrored file with DoM"
1027 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf ||
1028 error "failure to create PFL with DoM file"
1029 $LFS mirror extend -N2 $tf ||
1030 error "failure to extend mirror with DoM"
1032 $LFS setstripe -E 1M -L mdt -E eof -S 1M $tf-1 ||
1033 error "failure to create PFL with DoM file"
1034 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2 ||
1035 error "failure to create mirrored file"
1036 $LFS mirror extend -N -f $tf-1 $tf-2 ||
1037 error "failure to extend mirrored file with DoM extent"
1039 run_test 6a "DoM and FLR work together"
1042 (( $MDS1_VERSION >= $(version_code 2.15.58.1) )) ||
1043 skip "MDS version older than 2.15.58.1"
1045 local tf=$DIR/$tfile
1047 $LFS setstripe -E64K -L mdt -Eeof $tf ||
1048 error "failure to create PFL with DoM file"
1049 $LFS mirror extend -N -E1M -L mdt -Eeof $tf &&
1050 error "should not extend mirror with different DoM size"
1054 run_test 6b "extend mirror with different DoM size"
1057 local tf=$DIR/$tfile
1059 # create DoM with setting stripe_size == component size
1060 $LFS mirror create -N -E1M -S1M -L mdt -Eeof $tf ||
1061 error "failure to create DoM with stripe_size == comp size"
1062 rm -f $tf || error "delete $tf"
1064 # DoM should not inherit previous component stripe_size
1065 $LFS mirror create -N -E4M -S2M -Eeof -N -E1M -L mdt -Eeof $tf ||
1066 error "DoM component shouldn't inherit previous stripe_size"
1068 run_test 7 "Create mirror with DoM component"
1071 local tf=$DIR/$tfile
1072 local tf2=$DIR/$tfile-2
1074 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1076 stack_trap "rm -f $tf $tf2"
1078 $LFS setstripe -E EOF -o 0 $tf
1079 $LFS setstripe -E EOF -o 1 $tf2
1081 local dd_count=$((RANDOM % 20 + 1))
1082 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
1083 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
1085 # for zfs - sync OST dataset so that du below will return
1087 [ "$FSTYPE" = "zfs" ] &&
1088 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
1090 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
1093 $LFS mirror extend -N -f $tf2 $tf ||
1094 error "merging $tf2 into $tf failed"
1096 # cancel layout lock
1097 cancel_lru_locks mdc
1099 local new_blocks=$(du -k $tf | awk '{print $1}')
1100 [ $new_blocks -eq $blocks ] ||
1101 error "i_blocks error expected: $blocks, actual: $new_blocks"
1103 run_test 21 "glimpse should report accurate i_blocks"
1105 get_osc_lock_count() {
1112 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
1113 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
1114 lock_count=$((lock_count + count))
1120 local tf=$DIR/$tfile
1122 stack_trap "rm -f $tf"
1124 $LFS setstripe -E EOF -o 0 $tf
1125 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
1127 # add component, two mirrors located on the same OST ;-)
1128 $LFS mirror extend -N -o 0 $tf ||
1129 error "extending mirrored file $tf failed"
1131 size_blocks=$(stat --format="%b %s" $tf)
1133 cancel_lru_locks mdc
1134 cancel_lru_locks osc
1136 local new_size_blocks=$(stat --format="%b %s" $tf)
1138 # make sure there is no lock cached
1139 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
1141 [ "$new_size_blocks" = "$size_blocks" ] ||
1142 echo "size expected: $size_blocks, actual: $new_size_blocks"
1146 run_test 22 "no glimpse to OSTs for READ_ONLY files"
1149 local tf=$DIR/$tfile
1151 $LFS mirror create -N -o 0 -N -o 1 $tf ||
1152 error "creating mirrored file $tf failed"
1155 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
1156 cancel_lru_locks osc
1159 local tmpfile=$(mktemp)
1160 stat --format="%b %s" $tf > $tmpfile &
1164 while [ $cnt -le 5 ]; do
1165 kill -0 $pid > /dev/null 2>&1 || break
1169 kill -0 $pid > /dev/null 2>&1 &&
1170 error "stat process stuck due to unavailable OSTs"
1172 # make sure glimpse request has been sent
1173 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1174 error "OST $ost_idx: no glimpse request was sent"
1179 run_test 31 "make sure glimpse request can be retried"
1182 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1183 rm -f $DIR/$tfile $DIR/$tfile-2
1185 stack_trap "rm -f $DIR/$tfile"
1187 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1188 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1190 local fsize=$(stat -c %s $DIR/$tfile)
1191 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1193 local cksum=$(md5sum $DIR/$tfile)
1195 # create a new mirror in sync mode
1196 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1197 error "extending mirrored file $DIR/$tfile failed"
1199 # make sure the mirrored file was created successfully
1200 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1201 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1206 # check size is correct, glimpse request should go to the 2nd mirror
1207 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1208 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1210 echo "reading file from the 2nd mirror and verify checksum"
1211 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1212 error "checksum error: expected $cksum"
1216 run_test 32 "data should be mirrored to newly created mirror"
1219 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1221 rm -f $DIR/$tfile $DIR/$tfile-2
1223 # create a file with two mirrors
1224 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1227 while [ $count -lt $max_count ]; do
1228 echo "ost1" >> $DIR/$tfile
1229 count=$((count + 1));
1232 # tmp file that will be used as mirror
1233 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1235 while [ $count -lt $max_count ]; do
1236 echo "ost2" >> $DIR/$tfile-2
1237 count=$((count + 1));
1240 # create a mirrored file
1241 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1242 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1243 "with verification should fail"
1244 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1245 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1246 "without verification failed"
1248 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1249 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1250 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1252 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1254 # execpted file size
1255 local fsize=$((5 * max_count))
1256 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1257 error "mirrored file size is not $fsize"
1259 # read file - all OSTs are available
1260 echo "reading file (data can be provided by any ost)... "
1261 local rs=$(cat $DIR/$tfile | head -1)
1262 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1263 error "file content error: expected: \"ost1\" or \"ost2\""
1265 # read file again with ost1 failed
1269 echo "reading file (data should be provided by ost2)..."
1270 local rs=$(cat $DIR/$tfile | head -1)
1271 [[ "$rs" == "ost2" ]] ||
1272 error "file content error: expected: \"ost2\", actual: \"$rs\""
1277 # read file again with ost2 failed
1281 # check size, glimpse should work
1282 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1283 error "mirrored file size is not $fsize"
1285 echo "reading file (data should be provided by ost1)..."
1286 local rs=$(cat $DIR/$tfile | head -1)
1287 [[ "$rs" == "ost1" ]] ||
1288 error "file content error: expected: \"ost1\", actual: \"$rs\""
1292 run_test 33a "read can choose available mirror to read"
1295 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1299 stack_trap "rm -f $DIR/$tfile" EXIT
1301 # create a file with two mirrors on OST0000 and OST0001
1302 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1304 # make sure that $tfile has two mirrors
1305 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1306 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1309 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1310 error "write failed for $DIR/$tfile"
1311 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1312 verify_flr_state $DIR/$tfile "ro"
1317 # read file - all OSTs are available
1318 echo "reading file (data can be provided by any ost)... "
1320 time cat $DIR/$tfile > /dev/null || error "read all"
1324 # read file again with ost1 {OST0000} failed
1327 echo "reading file (data should be provided by ost2)..."
1329 time cat $DIR/$tfile > /dev/null || error "read ost2"
1336 # read file again with ost2 {OST0001} failed
1340 echo "reading file (data should be provided by ost1)..."
1342 time cat $DIR/$tfile > /dev/null || error "read ost1"
1349 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1350 error "read mirror too slow without ost1, from $ra to $r1"
1351 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1352 error "read mirror too slow without ost2, from $ra to $r2"
1354 wait_osc_import_ready client ost2
1356 run_test 33b "avoid reading from unhealthy mirror"
1359 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1363 stack_trap "rm -f $DIR/$tfile" EXIT
1365 # create a file with two mirrors
1366 # mirror1: {OST0000, OST0001}
1367 # mirror2: {OST0001, OST0002}
1368 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1370 # make sure that $tfile has two mirrors
1371 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1372 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1375 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1376 error "write failed for $DIR/$tfile"
1377 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1378 verify_flr_state $DIR/$tfile "ro"
1383 # read file - all OSTs are available
1384 echo "reading file (data can be provided by any ost)... "
1385 time cat $DIR/$tfile > /dev/null || error "read all"
1387 # read file again with ost2 (OST0001) failed
1391 echo "reading file (data should be provided by ost1 and ost3)..."
1392 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1397 wait_osc_import_ready client ost2
1399 run_test 33c "keep reading among unhealthy mirrors"
1402 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1404 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1407 $LFS setstripe -o 0 $DIR/$tfile-ref
1408 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1410 # create a file with two mirrors
1411 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1412 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1414 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1415 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1417 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1418 error "mirrored file size is not 3M"
1420 # merge a mirrored file
1421 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1422 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1424 cancel_lru_locks osc
1426 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1427 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1430 echo "comparing files ... "
1432 # however, read can still return the correct data. It should return
1433 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1434 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1435 $DIR/$tfile-ref || error "file reading error"
1439 run_test 34a "read mirrored file with multiple stripes"
1442 (( $OSTCOUNT >= 4 )) || skip "need >= 4 OSTs"
1444 stack_trap "rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref"
1447 $LFS setstripe -o 0 $DIR/$tfile-ref
1448 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1450 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1451 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1453 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1454 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1456 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1457 error "mirrored file size is not 3M"
1459 # merge a mirrored file
1460 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1461 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1463 cancel_lru_locks osc
1465 # stop two OSTs, so the 2nd component of the 1st mirror and
1466 # the 1st component of the 2nd mirror will be inaccessible, ...
1469 echo "comparing files ... "
1471 # however, read can still return the correct data. It should return
1472 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1473 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1474 $DIR/$tfile-ref || error "file reading error"
1478 run_test 34b "read mirrored file with multiple components"
1481 local tf=$DIR/$tfile
1483 $LFS setstripe -E eof $tf
1485 # add an out-of-sync mirror to the file
1486 $LFS mirror extend -N -c 2 $tf ||
1487 error "extending mirrored file $tf failed"
1489 $MULTIOP $tf oO_WRONLY:c ||
1490 error "write open a mirrored file failed"
1492 # truncate file should return error
1493 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1495 run_test 35 "allow to write to mirrored files"
1497 get_file_layout_version() {
1498 $LFS getstripe $1 | awk '/lcm_layout_gen/{print $2}'
1501 get_ost_layout_version() {
1502 $MULTIOP $1 oXc | awk '/ostlayoutversion/{print $2}'
1505 verify_ost_layout_version() {
1508 # get file layout version
1509 local flv=$(get_file_layout_version $tf)
1511 # layout version from OST objects
1512 local olv=$(get_ost_layout_version $tf)
1514 (( flv >= olv )) || error "layout version mismatch: $flv vs. $olv"
1521 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1522 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1524 $LFS mirror extend -N -f $tf-tmp $tf ||
1525 error "merging $tf-tmp into $tf failed"
1530 local tf=$DIR/$tfile
1532 stack_trap "rm -f $tf $tf-2 $tf-3"
1534 create_file_36 $tf $tf-2 $tf-3
1536 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1538 # test case 1 - check file write and verify layout version
1539 $MULTIOP $tf oO_WRONLY:c ||
1540 error "write open a mirrored file failed"
1542 # write open file should not return error
1543 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1545 # instantiate components should work
1546 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1548 # verify OST layout version
1549 verify_ost_layout_version $tf
1552 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1555 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1557 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1558 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1560 # write should take at least $fail_loc seconds and succeed
1561 local st=$(date +%s)
1562 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1564 # verify OST layout version
1565 verify_ost_layout_version $tf
1567 do_facet $mds_facet $LCTL set_param fail_loc=0
1569 run_test 36a "write to mirrored files"
1572 local tf=$DIR/$tfile
1574 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1575 skip "Need OST version at least 2.15.50"
1577 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1579 # create 2 mirrors using different OSTs
1580 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1581 error "create mirrored file"
1583 # write 1M data to one mirror
1584 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1587 # set prefer mirror to another mirror
1588 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1589 error "clear prefer mirror error"
1590 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1591 error "set prefer mirror error"
1593 # the second write should not hung
1594 dd if=/dev/zero of=$tf bs=1M count=1 || error "write file error"
1596 run_test 36b "write should not hung when prefered mirror is stale"
1599 local tf=$DIR/$tfile
1601 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1602 skip "Need OST version at least 2.15.50"
1604 (( OSTCOUNT >= 2 )) || skip "need >= 2 OSTs"
1606 # create 2 mirrors using different OSTs
1607 $LFS setstripe -N -c1 -i0 --flags=prefer -N -c1 -i1 $tf ||
1608 error "create mirrored file"
1609 stack_trap "rm -f $tf"
1611 # write it in the background
1612 $MULTIOP $tf Ow4096_w4096c &
1617 $LFS setstripe --comp-set -I0x10001 --comp-flags=^prefer $tf ||
1618 error "clear prefer mirror error"
1619 $LFS setstripe --comp-set -I0x20002 --comp-flags=prefer $tf ||
1620 error "set prefer mirror error"
1625 run_test 36c "change prefer mirror during write shouldn't hung"
1628 local tf=$DIR/$tfile
1630 (( OST1_VERSION >= $(version_code 2.15.50) )) ||
1631 skip "Need OST version at least 2.15.50"
1633 echo " ** create $tf"
1634 $LFS mirror create -N $tf || error "create $tf failed"
1637 echo " ** mirror extend $tf ($i/2)"
1638 $LFS mirror extend -N $tf || error "mirror extend $tf failed"
1639 flv=$(get_file_layout_version $tf)
1640 olv=$(get_ost_layout_version $tf)
1641 echo " flv=$flv olv=$olv"
1645 echo " ** write $tf ($i/2)"
1646 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1647 flv=$(get_file_layout_version $tf)
1648 olv=$(get_ost_layout_version $tf)
1649 echo " flv=$flv olv=$olv"
1651 error "write update OST layout failed $flv/$olv"
1654 echo " ** resync $tf"
1655 $LFS mirror resync $tf || error "mirror resync $tf failed"
1656 flv=$(get_file_layout_version $tf)
1657 olv=$(get_ost_layout_version $tf)
1658 echo " flv=$flv olv=$olv"
1661 echo " ** truncate $tf ($i/2)"
1662 $TRUNCATE $tf $((1024 * 1024)) || error "truncate $tf fails"
1663 flv=$(get_file_layout_version $tf)
1664 olv=$(get_ost_layout_version $tf)
1665 echo " flv=$flv olv=$olv"
1666 (( flv == olv || flv == olv + 1 )) ||
1667 error "truncate update OST layout failed $flv/$olv"
1670 echo " ** resync $tf"
1671 $LFS mirror resync $tf || error "mirror resync $tf failed"
1672 flv=$(get_file_layout_version $tf)
1673 olv=$(get_ost_layout_version $tf)
1674 echo " flv=$flv olv=$olv"
1677 echo " ** write $tf ($i/2)"
1678 dd if=/dev/zero of=$tf bs=1k count=1 || error "write $tf failed"
1679 flv=$(get_file_layout_version $tf)
1680 olv=$(get_ost_layout_version $tf)
1681 echo " flv=$flv olv=$olv"
1683 error "write update OST layout failed $flv/$olv"
1686 run_test 36d "write/punch FLR file update OST layout version"
1692 echo "create test files with size $fsize .."
1696 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1698 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1699 $TRUNCATE $tf $fsize
1705 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1706 skip "Need MDS version at least 2.11.57"
1708 local tf=$DIR/$tfile
1709 local tf2=$DIR/$tfile-2
1710 local tf3=$DIR/$tfile-3
1711 local tf4=$DIR/$tfile-4
1713 stack_trap "rm -f $tf $tf2 $tf3 $tf4"
1715 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1718 # assume the mirror id will be 1, 2, and 3
1719 declare -A checksums
1720 checksums[1]=$(cat $tf | md5sum)
1721 checksums[2]=$(cat $tf2 | md5sum)
1722 checksums[3]=$(cat $tf3 | md5sum)
1724 printf '%s\n' "${checksums[@]}"
1726 # merge these files into a mirrored file
1727 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1728 error "merging $tf2 into $tf failed"
1729 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1730 error "merging $tf3 into $tf failed"
1734 # verify mirror read, checksums should equal to the original files'
1735 echo "Verifying mirror read .."
1738 for i in "${mirror_array[@]}"; do
1739 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1740 sum=$($LFS mirror read -N $i $tf | md5sum)
1741 [ "$sum" = "${checksums[$i]}" ] ||
1742 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1745 # verify mirror write
1746 echo "Verifying mirror write .."
1747 $LFS mirror write -N2 $tf < $tf4
1749 sum=$($LFS mirror read -N2 $tf | md5sum)
1750 [[ "$sum" = "${checksums[1]}" ]] ||
1751 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1753 # verify mirror copy, write to this mirrored file will invalidate
1754 # the other two mirrors
1755 echo "Verifying mirror copy .."
1757 local osts=$(comma_list $(osts_nodes))
1759 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1760 error "mirror copy error"
1762 # verify copying is successful by checking checksums
1763 remount_client $MOUNT
1764 for i in "${mirror_array[@]}"; do
1765 sum=$($LFS mirror read -N $i $tf | md5sum)
1766 [ "$sum" = "${checksums[1]}" ] ||
1767 error "$i: mismatch checksum after copy \'$sum\'"
1772 run_test 37 "mirror I/O API verification"
1775 local tf=$DIR/$tfile
1776 local ref=$DIR/${tfile}-ref
1778 stack_trap "rm -f $tf $ref"
1780 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1781 error "creating $tf failed"
1782 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1783 $tf-2 || error "creating $tf-2 failed"
1784 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1785 error "creating $tf-3 failed"
1787 # instantiate all components
1788 $LFS mirror extend -N -f $tf-2 $tf ||
1789 error "merging $tf-2 into $tf failed"
1790 $LFS mirror extend -N -f $tf-3 $tf ||
1791 error "merging $tf-3 into $tf failed"
1792 $LFS mirror extend -N -c 1 $tf ||
1793 error "extending mirrored file $tf failed"
1795 verify_flr_state $tf "ro"
1797 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1799 local fsize=$((RANDOM << 8 + 1048576))
1800 $TRUNCATE $ref $fsize
1802 local ref_cksum=$(cat $ref | md5sum)
1804 # case 1: verify write to mirrored file & resync work
1805 cp $ref $tf || error "copy from $ref to $f error"
1806 verify_flr_state $tf "wp"
1808 local file_cksum=$(cat $tf | md5sum)
1809 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1812 echo "mirror IDs: ${mirror_array[*]}"
1814 local valid_mirror stale_mirror id mirror_cksum
1815 for id in "${mirror_array[@]}"; do
1816 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1817 [ "$ref_cksum" == "$mirror_cksum" ] &&
1818 { valid_mirror=$id; continue; }
1823 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1824 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1826 $LFS mirror resync $tf || error "resync failed"
1827 verify_flr_state $tf "ro"
1829 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1830 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1832 # case 2: inject an error to make mirror_io exit after changing
1833 # the file state to sync_pending so that we can start a concurrent
1835 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1836 verify_flr_state $tf "wp"
1838 mirror_io resync -e resync_start $tf && error "resync succeeded"
1839 verify_flr_state $tf "sp"
1841 # from sync_pending to write_pending
1842 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1843 verify_flr_state $tf "wp"
1845 mirror_io resync -e resync_start $tf && error "resync succeeded"
1846 verify_flr_state $tf "sp"
1848 # from sync_pending to read_only
1849 $LFS mirror resync $tf || error "resync failed"
1850 verify_flr_state $tf "ro"
1852 run_test 38 "resync"
1855 local tf=$DIR/$tfile
1858 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1859 error "create PFL file $tf failed"
1861 verify_mirror_count $tf 2
1862 verify_comp_count $tf 4
1864 rm -f $tf || error "delete $tf failed"
1866 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1869 local tf=$DIR/$tfile
1872 for ops in "conv=notrunc" ""; do
1875 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1876 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1877 error "create PFLR file $tf failed"
1878 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1879 error "write PFLR file $tf failed"
1881 lfs getstripe -vy $tf
1885 # file mirror state should be write_pending
1886 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1888 error "file mirror state $flags"
1889 # the 1st component (in mirror 1) should be inited
1890 verify_comp_attr lcme_flags $tf 0x10001 init
1891 # the 2nd component (in mirror 1) should be inited
1892 verify_comp_attr lcme_flags $tf 0x10002 init
1893 # the 3rd component (in mirror 1) should be uninited
1894 verify_comp_attr lcme_flags $tf 0x10003 prefer
1895 # the 4th component (in mirror 2) should be inited
1896 verify_comp_attr lcme_flags $tf 0x20004 init
1897 # the 5th component (in mirror 2) should be uninited
1898 verify_comp_attr lcme_flags $tf 0x20005 0
1899 # the 6th component (in mirror 2) should be stale
1900 verify_comp_attr lcme_flags $tf 0x20006 stale
1901 # the 7th component (in mirror 2) should be uninited
1902 if [[ x$ops = "xconv=notrunc" ]]; then
1903 verify_comp_attr lcme_flags $tf 0x20007 0
1904 elif [[ x$ops = "x" ]]; then
1905 verify_comp_attr lcme_flags $tf 0x20007 stale
1909 rm -f $tf || error "delete $tf failed"
1911 run_test 40 "PFLR rdonly state instantiation check"
1914 local tf=$DIR/$tfile
1916 stack_trap "rm -f $tf $tf-1"
1919 echo " **create two FLR files $tf $tf-1"
1920 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1921 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1922 error "create PFLR file $tf failed"
1923 $LFS mirror create -N -E 2M -S 1M -E eof \
1924 -N -E 1M -E eof --flags prefer \
1925 -N -E 4m -E eof $tf-1 ||
1926 error "create PFLR file $tf-1 failed"
1928 # file should be in ro status
1929 echo " **verify files be RDONLY"
1930 verify_flr_state $tf "ro"
1931 verify_flr_state $tf-1 "ro"
1933 # write data in [0, 2M)
1934 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1935 error "writing $tf failed"
1936 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1937 error "writing $tf-1 failed"
1939 local sum0=$(cat $tf-1 | md5sum)
1941 echo " **verify files be WRITE_PENDING"
1942 verify_flr_state $tf "wp"
1943 verify_flr_state $tf-1 "wp"
1945 # file should have stale component
1946 echo " **verify files have stale component"
1947 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1948 error "after writing $tf, it does not contain stale component"
1949 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1950 error "after writing $tf-1, it does not contain stale component"
1952 echo " **full resync"
1953 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1955 echo " **verify $tf-1 data consistency in all mirrors"
1957 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1958 [[ "$sum" = "$sum0" ]] ||
1959 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1962 echo " **verify files be RDONLY"
1963 verify_flr_state $tf "ro"
1964 verify_flr_state $tf-1 "ro"
1966 # file should not have stale component
1967 echo " **verify files do not contain stale component"
1968 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1969 error "after resyncing $tf, it contains stale component"
1970 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1971 error "after resyncing $tf, it contains stale component"
1973 # verify partial resync
1974 echo " **write $tf-1 for partial resync test"
1975 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1976 error "writing $tf-1 failed"
1978 echo " **only resync mirror 2"
1979 verify_flr_state $tf-1 "wp"
1980 $LFS mirror resync --only 2 $tf-1 ||
1981 error "resync mirror 2 of $tf-1 failed"
1982 verify_flr_state $tf "ro"
1984 # resync synced mirror
1985 echo " **resync mirror 2 again"
1986 $LFS mirror resync --only 2 $tf-1 ||
1987 error "resync mirror 2 of $tf-1 failed"
1988 verify_flr_state $tf "ro"
1989 echo " **verify $tf-1 contains stale component"
1990 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1991 error "after writing $tf-1, it does not contain stale component"
1993 echo " **full resync $tf-1"
1994 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1995 verify_flr_state $tf "ro"
1996 echo " **full resync $tf-1 again"
1997 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1998 echo " **verify $tf-1 does not contain stale component"
1999 $LFS getstripe $tf | grep lcme_flags | grep stale &&
2000 error "after resyncing $tf, it contains stale component"
2004 run_test 41 "lfs mirror resync check"
2007 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
2011 local mirror_cmd="$LFS mirror verify"
2014 stack_trap "rm -rf $td"
2016 # create parent directory
2017 mkdir $td || error "mkdir $td failed"
2019 $mirror_cmd &> /dev/null && error "no file name given"
2020 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
2021 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
2023 # create mirrored files
2024 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
2025 error "create mirrored file $tf failed"
2026 $LFS mirror create -N -E 2M -S 1M -E EOF \
2027 -N -E 6M -E 8M -E EOF \
2028 -N -E 16M -E EOF $tf-1 ||
2029 error "create mirrored file $tf-1 failed"
2030 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
2031 error "create mirrored file $tf-2 failed"
2033 # write data in [0, 10M)
2034 for i in $tf $tf-1 $tf-2; do
2035 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
2036 error "write $i failed"
2039 # resync the mirrored files
2040 $LFS mirror resync $tf-1 $tf-2 ||
2041 error "resync $tf-1 $tf-2 failed"
2043 # verify the mirrored files
2044 $mirror_cmd $tf-1 $tf-2 ||
2045 error "verify $tf-1 $tf-2 failed"
2047 get_mirror_ids $tf-1
2048 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
2049 error "at least 2 mirror ids needed with '--only' option"
2050 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
2052 error "'--only' option cannot be used upon multiple files"
2053 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
2054 error "invalid specified mirror ids"
2056 # change the content of $tf and merge it into $tf-1
2058 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
2059 error "change $tf with seek=$i failed"
2060 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
2061 error "change $tf-1 with seek=$i failed"
2064 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
2065 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
2066 error "merge $tf into $tf-1 failed"
2068 # verify the mirrored files
2069 echo "Verify $tf-1 without -v option:"
2070 $mirror_cmd $tf-1 &&
2071 error "verify $tf-1 should fail" || echo "PASS"
2073 echo "Verify $tf-1 with -v option:"
2074 $mirror_cmd -v $tf-1 &&
2075 error "verify $tf-1 should fail"
2077 get_mirror_ids $tf-1
2078 echo "Verify $tf-1 with --only option:"
2079 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
2080 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2081 "${mirror_array[-1]} should fail"
2083 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
2084 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
2085 "${mirror_array[1]} should succeed"
2087 # set stale components in $tf-1
2088 for i in 0x40002 0x40003; do
2089 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
2090 error "set stale flag on component $i failed"
2093 # verify the mirrored file
2094 echo "Verify $tf-1 with stale components:"
2095 $mirror_cmd -vvv $tf-1 ||
2096 error "verify $tf-1 with stale components should succeed"
2098 echo "Verify $tf-1 with stale components and --only option:"
2099 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
2100 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
2101 "${mirror_array[-1]} should succeed"
2103 run_test 42 "lfs mirror verify"
2105 # inactivate one OST && write && restore the OST
2109 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
2112 wait=$(do_facet $SINGLEMDS \
2113 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
2114 wait=${wait%%[^0-9]*}
2116 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
2117 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
2118 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
2119 sleep $(($wait * 2 + 2))
2120 echo " **write $file"
2121 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2122 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
2123 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
2124 sleep $((wait * 2 + 2))
2126 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
2127 [ $flags = wp ] || error "file mirror state $flags != wp"
2131 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2133 local tf=$DIR/$tfile
2136 stack_trap "rm -f $tf"
2138 ## mirror 0 ost (0, 1)
2139 ## mirror 1 ost (1, 2)
2140 ## mirror 2 ost (2, 0)
2141 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
2142 -N -Eeof -c2 -o2,0 $tf ||
2143 error "create 3 mirrors file $tf failed"
2145 ################## OST0 ###########################################
2147 echo " **verify components"
2148 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2149 verify_comp_attr lcme_flags $tf 0x20002 init
2150 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2153 echo " **resync $tf"
2154 $LFS mirror resync $tf
2155 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2156 [ $flags = ro ] || error "file mirror state $flags != ro"
2158 ################## OST1 ###########################################
2160 echo " **verify components"
2161 verify_comp_attr lcme_flags $tf 0x10001 init,stale
2162 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2163 verify_comp_attr lcme_flags $tf 0x30003 init
2166 echo " **resync $tf"
2167 $LFS mirror resync $tf
2168 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
2169 [ $flags = ro ] || error "file mirror state $flags != ro"
2171 ################## OST2 ###########################################
2173 echo " **verify components"
2174 verify_comp_attr lcme_flags $tf 0x10001 init
2175 verify_comp_attr lcme_flags $tf 0x20002 init,stale
2176 verify_comp_attr lcme_flags $tf 0x30003 init,stale
2178 run_test 43a "mirror pick on write"
2181 local tf=$DIR/$tdir/$tfile
2183 test_mkdir $DIR/$tdir
2185 stack_trap "rm -rf $tf"
2187 # create 3 mirrors FLR file, the first 2 mirrors are preferred
2188 $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \
2189 -N -Eeof $tf || error "create 3 mirrors file $tf failed"
2190 verify_flr_state $tf "ro"
2192 echo " ** write to $tf"
2193 dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed"
2194 verify_flr_state $tf "wp"
2196 echo " ** resync $tf"
2197 $LFS mirror resync $tf || error "resync $tf failed"
2198 verify_flr_state $tf "ro"
2200 run_test 43b "allow writing to multiple preferred mirror file"
2203 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2206 local tf=$DIR/$tdir/$tfile
2207 local tf1=$DIR/$tdir-1/$tfile-1
2209 stack_trap "rm -rf $tf $tf1"
2211 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
2212 error "create directory failed"
2213 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
2214 error "create remote directory failed"
2215 rm -f $tf $tf1 $tf.mirror~2
2216 # create file with 4 mirrors
2217 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
2218 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
2219 error "create PFLR file $tf failed"
2221 # file should be in ro status
2222 verify_flr_state $tf "ro"
2224 # write data in [0, 3M)
2225 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
2226 error "writing $tf failed"
2228 verify_flr_state $tf "wp"
2230 # disallow destroying the last non-stale mirror
2231 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
2232 error "destroying mirror 1 should fail"
2234 # synchronize all mirrors of the file
2235 $LFS mirror resync $tf || error "mirror resync $tf failed"
2237 verify_flr_state $tf "ro"
2240 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
2241 error "split to $tf1 failed"
2243 local idx0=$($LFS getstripe -m $tf)
2244 local idx1=$($LFS getstripe -m $tf1)
2246 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
2247 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
2249 # verify mirror count
2250 verify_mirror_count $tf 3
2251 verify_mirror_count $tf1 1
2253 $LFS mirror split --mirror-id 2 $tf ||
2254 error "split mirror 2 failed"
2256 verify_mirror_count $tf 2
2257 verify_mirror_count $tf.mirror~2 1
2259 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
2260 error "setting stale flag on component 0x30008 failed"
2262 # disallow destroying the last non-stale mirror
2263 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
2264 error "destroying mirror 4 should fail"
2266 $LFS mirror resync $tf || error "resynchronizing $tf failed"
2268 $LFS mirror split --mirror-id 3 -d $tf ||
2269 error "destroying mirror 3 failed"
2270 verify_mirror_count $tf 1
2272 # verify splitted file contains the same content as the orig file does
2273 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
2274 diff $tf $tf.mirror~2 ||
2275 error "splited file $tf.mirror~2 diffs from $tf"
2277 run_test 44a "lfs mirror split check"
2280 (( $MDS1_VERSION >= $(version_code 2.14.56) )) ||
2281 skip "Need MDS version at least 2.14.56"
2284 local tf=$DIR/$tdir/$tfile
2286 mkdir -p $DIR/$tdir || error "create directory failed"
2290 # create 2 mirrors file
2291 $LFS mirror extend -N -c1 $tf
2295 verify_flr_state $tf "wp"
2297 local str=$(cat $tf)
2299 [[ $str == "YYY" ]] || error "$tf content is not YYY"
2301 # get the non-stale mirror id
2302 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
2304 local mirror_ids=($($LFS getstripe $tf |
2305 awk '/lcme_mirror_id/{print $2}' | tr '\n' ' '))
2306 for ((i = 0; i < 2; i++)); do
2307 $LFS getstripe -I${ids[$i]} --component-flags $tf |
2308 grep stale > /dev/null || break
2311 [[ $i -ge 2 ]] && ( $LFS getstripe $tf; error "no stale mirror" )
2315 # split the updated mirror, should fail
2316 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}, should fail"
2317 $LFS mirror split --mirror-id=${mirror_ids[$i]} $tf &> /dev/null &&
2318 error "split --mirror-id=${mirror_ids[$i]} $tf should fail"
2321 # split the stale mirror
2322 echo "split mirror_id ${mirror_ids[$i]} id ${ids[$i]}"
2323 $LFS mirror split --mirror-id=${mirror_ids[$i]} -d $tf ||
2324 error "mirror split --mirror-id=${mirror_ids[$i]} $tf failed"
2326 echo "make sure there's no stale comp in the file"
2327 # make sure there's no stale comp in the file
2328 $LFS getstripe $tf | awk '/lcme_flags/{print $2}' | grep stale &&
2329 ( $LFS getstripe $tf; error "stale mirror file" )
2332 [[ $str == "YYY" ]] ||
2333 ( cat $tf; error "$tf content is not YYY after split" )
2335 run_test 44b "mirror split does not create stale file"
2338 local tf=$DIR/$tdir/$tfile
2340 stack_trap "rm -f $tf"
2342 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2343 skip "Need MDS version at least 2.14.52"
2345 [ "$FSTYPE" != "zfs" ] || skip "ZFS file's block number is not accurate"
2347 mkdir -p $DIR/$tdir || error "create directroy failed"
2349 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2351 block1=$(( $(stat -c "%b*%B" $tf) ))
2352 echo " ** before mirror ops, file blocks=$((block1/1024)) KiB"
2354 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2356 block2=$(( $(stat -c "%b*%B" $tf) ))
2357 echo " ** after mirror extend, file blocks=$((block2/1024)) KiB"
2359 $LFS mirror split -d --mirror-id=2 $tf ||
2360 error "mirror split $tfile failed"
2361 $LFS mirror split -d --mirror-id=3 $tf ||
2362 error "mirror split $tfile failed"
2365 block3=$(( $(stat -c "%b*%B" $tf) ))
2366 echo " ** after mirror split, file blocks=$((block3/1024)) KiB"
2368 [[ $block1 -eq $block3 ]] ||
2369 error "mirror split does not reduce block# $block3 != $block1"
2371 run_test 44c "lfs mirror split reduces block size of a file"
2374 local tf=$DIR/$tdir/$tfile
2380 stack_trap "rm -f $tf"
2382 mkdir -p $DIR/$tdir || error "create directroy failed"
2384 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2386 size1=$(stat -c "%s" $tf)
2387 echo " ** before mirror ops, file size=$size1"
2389 $LFS mirror extend -N2 -c1 $tf || error "mirror extend $tfile failed"
2391 size2=$(stat -c "%s" $tf)
2392 echo " ** after mirror extend, file size=$size2"
2394 (($size1 == $size2)) ||
2395 error "mirror extend should not change size, before: $size1, after $size2"
2397 $LFS mirror split -d --mirror-id=2 $tf ||
2398 error "mirror split $tfile failed"
2400 size2=$(stat -c "%s" $tf)
2401 echo " ** after mirror split, file size=$size2"
2402 (($size1 == $size2)) ||
2403 error "mirror split should not change size, before: $size1, after $size2"
2405 # Remount client to clear cached size information
2406 remount_client $MOUNT
2407 size2=$(stat -c "%s" $tf)
2408 echo " ** after mirror split & remount, file size=$size2"
2409 (($size1 == $size2)) ||
2410 error "mirror extend should not change size, before: $size1, after $size2"
2413 run_test 44d "lfs mirror split does not break size"
2416 local tf=$DIR/$tdir/$tfile
2417 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2421 test_mkdir $DIR/$tdir
2422 [ $MDS1_VERSION -ge $(version_code 2.14.52) ] ||
2423 skip "Need MDS version at least 2.14.52"
2425 $LFS mirror create -N2 $tf || error "create mirrored file $tf failed"
2427 # Disable xattr caching so we can repeatedly check SOM with lfs getsom
2428 $LCTL set_param llite.*.xattr_cache=0
2429 stack_trap "$LCTL set_param llite.*.xattr_cache=1"
2430 stack_trap "rm -rf $tf"
2432 dd if=/dev/zero of=$tf bs=1M count=10 || error "dd write $tfile failed"
2434 size1=$(stat -c "%s" $tf)
2435 echo " ** before mirror resync, file size=$size1"
2437 $LFS mirror resync $tf || error "mirror resync file $tf failed"
2438 size1=$(stat -c "%s" $tf)
2439 size2=$($LFS getsom -s $tf)
2443 ((size1 == size2)) ||
2444 error "mirrored file with strict SOM $size1 != disabled SOM $size2"
2446 # Remount client to clear cached size information
2447 remount_client $MOUNT
2449 save_lustre_params $(get_facets MDS) mdt.*MDT*.enable_strict_som > $p
2450 stack_trap "restore_lustre_params < $p; rm -f $p"
2451 local mds_facet=mds$(($($LFS getstripe -m $tf) + 1))
2453 do_facet $mds_facet $LCTL set_param mdt.*MDT*.enable_strict_som=0
2455 size2=$(stat -c "%s" $tf)
2456 # 'getsom' here is just for debugging
2459 ((size2 == size1)) ||
2460 error "mirrored file in sync with som disabled, size with som disabled ($size2) and without som disabled ($size1) should agree"
2462 run_test 44e "basic FLR SOM tests + disable SOM"
2465 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2467 local file=$DIR/$tdir/$tfile
2468 local dir=$DIR/$tdir/$dir
2469 local temp=$DIR/$tdir/template
2471 test_mkdir $DIR/$tdir
2473 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2474 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
2475 error "Create $file failed"
2477 verify_yaml_layout $file $file.copy $temp "1. FLR file"
2478 rm -f $file $file.copy
2480 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
2481 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
2482 error "Create $file failed"
2484 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
2486 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
2493 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2495 local layout1=$(get_layout_param $src)
2496 local layout2=$(get_layout_param $dst)
2497 # compare their layout info
2498 [ "$layout1" == "$layout2" ] ||
2499 error "$msg_prefix $src <=> $dst layouts are not equal"
2503 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2505 local file=$DIR/$tdir/$tfile
2506 test_mkdir $DIR/$tdir
2508 ########################### 1. PFL file #############################
2509 echo " ** 1. PFL file"
2511 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2512 $file || error "1. Create PFL $file failed"
2515 verify_46 $file $file.copy "1. PFL file"
2517 ########################### 2. plain file ###########################
2518 echo " ** 2. plain file"
2520 $LFS setstripe -c2 -o0,1 -i1 $file ||
2521 error "2. Create plain $file failed"
2524 verify_46 $file $file.copy "2. plain file"
2526 ########################### 3. FLR file #############################
2527 echo " ** 3. FLR file"
2529 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2530 $file || error "3. Create FLR $file failed"
2533 verify_46 $file $file.copy "3. FLR file"
2535 local dir=$DIR/$tdir/dir
2536 ########################### 4. PFL dir ##############################
2537 echo " ** 4. PFL dir"
2539 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2540 error "4. setstripe PFL $dir failed"
2542 test_mkdir $dir.copy
2543 verify_46 $dir $dir.copy "4. PFL dir"
2545 ########################### 5. plain dir ############################
2546 echo " ** 5. plain dir"
2547 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2549 verify_46 $dir $dir.copy "5. plain dir"
2551 ########################### 6. FLR dir ##############################
2552 echo " ** 6. FLR dir"
2553 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2554 error "6. setstripe FLR $dir failed"
2556 verify_46 $dir $dir.copy "6. FLR dir"
2558 (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
2559 echo "server version $MDS1_VERSION does not support SEL" &&
2562 ########################### 7. SEL file ##############################
2563 echo " ** 7. SEL file"
2565 $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
2566 $file || error "Create $file failed"
2569 verify_46 $file $file.copy "7. SEL file"
2571 ########################### 8. SEL dir ##############################
2572 echo " ** 8. SEL dir"
2573 $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
2574 $dir || error "setstripe $dir failed"
2576 verify_46 $dir $dir.copy "8. SEL dir"
2578 ########################### 9. FLR SEL file ##########################
2579 echo " ** 9. FLR SEL file"
2581 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2582 -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
2585 verify_46 $file $file.copy "9. SEL file"
2587 ########################### 10. FLR SEL dir #########################
2588 echo " ** 10. FLR SEL dir"
2589 $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
2590 -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
2592 verify_46 $dir $dir.copy "10. SEL dir"
2594 run_test 46 "Verify setstripe --copy option"
2597 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2599 local file=$DIR/$tdir/$tfile
2604 test_mkdir $DIR/$tdir
2605 stack_trap "rm -f $file"
2609 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2610 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2611 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2612 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2613 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2615 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2616 $LFS mirror resync $file || error "resync $file failed"
2618 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2619 if [[ x$ost == "x0," ]]; then
2620 $LFS getstripe $file
2621 error "component ${ids[2]} objects allocated on $ost " \
2625 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2626 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2627 $LFS getstripe $file
2628 error "component ${ids[3]} objects allocated on $ost " \
2629 "shouldn't on OST1 or on OST2"
2634 # mirror1: [comp0] [comp1]
2635 # mirror2: [comp2] [comp3]
2636 # mirror3: [comp4] [comp5]
2637 # mirror4: [comp6] [comp7]
2638 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2639 error "create FLR $file failed"
2640 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2642 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2643 $LFS mirror resync $file || error "resync $file failed"
2645 for ((i = 0; i < 6; i++)); do
2646 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2647 awk '/l_ost_idx/{print $5}')
2649 # comp[0],comp[2],comp[4] should use different osts
2650 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2651 ${osts[2]} == ${osts[4]} ]]; then
2652 $LFS getstripe $file
2653 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2654 "allocated on duplicated OSTs"
2656 # comp[1],comp[3],comp[5] should use different osts
2657 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2658 ${osts[3]} == ${osts[5]} ]]; then
2659 $LFS getstripe $file
2660 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2661 "allocated on duplicated OSTs"
2666 run_test 47 "Verify mirror obj alloc"
2669 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2670 skip "Need MDS version at least 2.11.55"
2672 local tf=$DIR/$tfile
2674 stack_trap "rm -f $tf"
2676 echo " ** create 2 mirrors FLR file $tf"
2677 $LFS mirror create -N -E2M -Eeof --flags prefer \
2678 -N -E1M -Eeof $tf ||
2679 error "create FLR file $tf failed"
2682 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2683 verify_flr_state $tf "wp"
2685 local sum0=$(md5sum < $tf)
2687 echo " ** resync the file"
2688 $LFS mirror resync $tf
2690 echo " ** snapshot mirror 2"
2691 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2693 echo " ** write it again"
2694 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2695 echo " ** resync it again"
2696 $LFS mirror resync $tf
2698 verify_flr_state $tf "wp"
2699 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2701 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2702 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2704 echo " ** verify mirror 2 doesn't change"
2705 echo "original checksum: $sum0"
2706 echo "mirror 1 checksum: $sum1"
2707 echo "mirror 2 checksum: $sum2"
2708 [[ $sum0 = $sum2 ]] ||
2709 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2710 echo " ** mirror 2 stripe info"
2711 $LFS getstripe -v --mirror-index=2 $tf
2713 echo " ** resync mirror 2"
2714 $LFS mirror resync --only 2 $tf
2716 verify_flr_state $tf "ro"
2717 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2719 sum1=$($LFS mirror read -N1 $tf | md5sum)
2720 sum2=$($LFS mirror read -N2 $tf | md5sum)
2722 echo " ** verify mirror 2 resync-ed"
2723 echo "original checksum: $sum0"
2724 echo "mirror 1 checksum: $sum1"
2725 echo "mirror 2 checksum: $sum2"
2726 [[ $sum1 = $sum2 ]] ||
2727 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2728 echo " ** mirror 2 stripe info"
2729 $LFS getstripe -v --mirror-index=2 $tf
2731 run_test 48 "Verify snapshot mirror"
2740 (( "$OSTCOUNT" >= "2" )) || skip "needs >= 2 OSTs"
2741 local filefrag_op=$(filefrag -l 2>&1 | grep "invalid option")
2742 [[ -z "$filefrag_op" ]] || skip_env "filefrag missing logical ordering"
2743 [[ "$ost1_FSTYPE" != "zfs" ]] ||
2744 skip "LU-1941: FIEMAP unimplemented on ZFS"
2746 trap cleanup_49 EXIT RETURN
2748 local file=$DIR/$tfile
2750 $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
2751 error "setstripe on $file"
2752 stack_trap "rm -f $file"
2754 dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
2755 $LFS mirror resync $file
2757 filefrag -ves $file || error "filefrag $file failed"
2758 filefrag_op=$(filefrag -ve -k $file |
2759 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2761 #Filesystem type is: bd00bd0
2762 #File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
2763 # ext: device_logical: physical_offset: length: dev: flags:
2764 # 0: 0.. 1023: 1572864.. 1573887: 1024: 0001: net,eof
2765 # 1: 0.. 1023: 1572864.. 1573887: 1024: 0000: last,net,eof
2766 #/mnt/lustre/f49a.sanity-flr: 2 extents found
2768 last_lun=$(echo $filefrag_op | cut -d: -f5)
2772 for line in $filefrag_op; do
2773 frag_lun=$(echo $line | cut -d: -f5)
2774 ext_len=$(echo $line | cut -d: -f4)
2775 if [[ "$frag_lun" != "$last_lun" ]]; then
2776 if (( tot_len != 1024 )); then
2778 error "$file: OST$last_lun $tot_len != 1024"
2784 (( tot_len += ext_len ))
2787 if (( num_luns != 2 || tot_len != 1024 )); then
2789 error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
2792 echo "FIEMAP on $file succeeded"
2794 run_test 49a "FIEMAP upon FLR file"
2796 test_50A() { # EX-2179
2799 local file=$DIR/$tdir/$tfile
2801 $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
2803 $LFS mirror extend -N -c1 -i1 $file ||
2804 error "extending mirror for $file failed"
2806 local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2810 $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
2812 local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
2814 echo "$file layout generation from $olv to $flv"
2815 (( $flv != ($olv + 1) )) &&
2816 error "split does not increase layout gen from $olv to $flv"
2818 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
2820 $LFS getstripe -v $file || error "getstripe $file failed"
2822 run_test 50A "mirror split update layout generation"
2825 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2826 skip "OST does not support SEEK_HOLE"
2827 [ "$FSTYPE" != "zfs" ] ||
2828 skip "lseek for ZFS is not accurate if obj is not committed"
2830 local file=$DIR/$tdir/$tfile
2838 echo " ** create striped file $file"
2839 $LFS setstripe -E 1M -c1 -S 1M -E eof -c2 -S1M $file ||
2840 error "cannot create file with PFL layout"
2841 echo " ** write 1st data chunk at 1M boundary"
2842 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2843 error "cannot write data at 1M boundary"
2844 echo " ** write 2nd data chunk at 2M boundary"
2845 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 ||
2846 error "cannot write data at 2M boundary"
2847 echo " ** create hole at the file end"
2848 $TRUNCATE $file 3700000 || error "truncate fails"
2850 echo " ** verify sparseness"
2851 offset=$(lseek_test -d 1000 $file)
2852 echo " first data offset: $offset"
2853 [[ $offset == 1000 ]] &&
2854 error "src: data is not expected at offset $offset"
2855 offset=$(lseek_test -l 3500000 $file)
2856 echo " hole at the end: $offset"
2857 [[ $offset == 3500000 ]] ||
2858 error "src: hole is expected at offset $offset"
2860 echo " ** extend the file with new mirror"
2861 # migrate_copy_data() is used
2862 $LFS mirror extend -N -E 2M -S 1M -E 1G -S 2M -E eof $file ||
2863 error "cannot create mirror"
2864 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2865 error "$file still has stale component"
2867 # check migrate_data_copy() was correct
2868 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2869 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2870 [[ $sum_1 == $sum_2 ]] ||
2871 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2873 # stale first mirror
2874 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale $file
2875 $LFS setstripe --comp-set -I0x10002 --comp-flags=stale $file
2877 echo " ** verify mirror #2 sparseness"
2878 offset=$(lseek_test -d 1000 $file)
2879 echo " first data offset: $offset"
2880 [[ $offset == 1000 ]] &&
2881 error "dst: data is not expected at offset $offset"
2882 offset=$(lseek_test -l 3500000 $file)
2883 echo " hole at the end: $offset"
2884 [[ $offset == 3500000 ]] ||
2885 error "dst: hole is expected at offset $offset"
2887 echo " ** copy mirror #2 to mirror #1"
2888 $LFS mirror copy -i 2 -o 1 $file || error "mirror copy fails"
2889 $LFS getstripe $file | grep lcme_flags | grep stale > /dev/null &&
2890 error "$file still has stale component"
2892 # check llapi_mirror_copy_many correctness
2893 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2894 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2895 [[ $sum_1 == $sum_2 ]] ||
2896 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2898 # stale 1st component of mirror #2 before lseek call
2899 $LFS setstripe --comp-set -I0x20001 --comp-flags=stale $file
2901 echo " ** verify mirror #1 sparseness again"
2902 offset=$(lseek_test -d 1000 $file)
2903 echo " first data offset: $offset"
2904 [[ $offset == 1000 ]] &&
2905 error "dst: data is not expected at offset $offset"
2906 offset=$(lseek_test -l 3500000 $file)
2907 echo " hole at the end: $offset"
2908 [[ $offset == 3500000 ]] ||
2909 error "dst: hole is expected at offset $offset"
2911 cancel_lru_locks osc
2913 blocks=$(stat -c%b $file)
2914 echo " ** final consumed blocks: $blocks"
2915 # for 3.5Mb file consumes ~6000 blocks, use 1000 to check
2916 # that file is still sparse
2917 (( blocks < 1000 )) ||
2918 error "Mirrored file consumes $blocks blocks"
2920 run_test 50a "mirror extend/copy preserves sparseness"
2923 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
2924 skip "OST does not support SEEK_HOLE"
2925 [ "$FSTYPE" != "zfs" ] ||
2926 skip "lseek for ZFS is not accurate if obj is not committed"
2928 local file=$DIR/$tdir/$tfile
2935 stack_trap "rm -f $file"
2937 echo " ** create mirrored file $file"
2938 $LFS mirror create -N -E1M -c1 -S1M -E eof \
2939 -N -E2M -S1M -E eof -S2M $file ||
2940 error "cannot create mirrored file"
2941 echo " ** write data chunk at 1M boundary"
2942 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
2943 error "cannot write data at 1M boundary"
2944 echo " ** create hole at the file end"
2945 $TRUNCATE $file 3700000 || error "truncate fails"
2947 echo " ** verify sparseness"
2948 offset=$(lseek_test -d 1000 $file)
2949 echo " first data offset: $offset"
2950 [[ $offset == 1000 ]] &&
2951 error "src: data is not expected at offset $offset"
2952 offset=$(lseek_test -l 3500000 $file)
2953 echo " hole at the end: $offset"
2954 [[ $offset == 3500000 ]] ||
2955 error "src: hole is expected at 3500000"
2957 echo " ** resync mirror #2 to mirror #1"
2958 $LFS mirror resync $file
2960 # check llapi_mirror_copy_many correctness
2961 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2962 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2963 [[ $sum_1 == $sum_2 ]] ||
2964 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2966 cancel_lru_locks osc
2968 blocks=$(stat -c%b $file)
2969 echo " ** consumed blocks: $blocks"
2970 # without full punch() support the first component can be not sparse
2971 # but the last one should be, so file should use far fewer blocks
2972 (( blocks < 5000 )) ||
2973 error "Mirrored file consumes $blocks blocks"
2975 # stale first component in mirror #1
2976 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
2977 echo " ** truncate file down"
2979 echo " ** write data chunk at 2M boundary"
2980 dd if=/dev/urandom of=$file bs=1k count=20 seek=2041 conv=notrunc ||
2981 error "cannot write data at 2M boundary"
2982 echo " ** resync mirror #2 to mirror #1 with nosync 1st component"
2983 $LFS mirror resync $file || error "mirror rsync fails"
2984 # first component is still stale
2985 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null ||
2986 error "$file still has no stale component"
2987 echo " ** resync mirror #2 to mirror #1 again"
2988 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,^nosync $file
2989 $LFS mirror resync $file || error "mirror rsync fails"
2990 $LFS getstripe $file | grep 'lcme_flags:.*stale' > /dev/null &&
2991 error "$file still has stale component"
2993 # check llapi_mirror_copy_many correctness
2994 sum_1=$($LFS mirror read -N 1 $file | md5sum)
2995 sum_2=$($LFS mirror read -N 2 $file | md5sum)
2996 [[ $sum_1 == $sum_2 ]] ||
2997 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
2999 cancel_lru_locks osc
3001 blocks=$(stat -c%b $file)
3002 echo " ** final consumed blocks: $blocks"
3003 # while the first component can lose sparseness, the last one should
3004 # not, so whole file should still use far fewer blocks in total
3005 (( blocks < 3000 )) ||
3006 error "Mirrored file consumes $blocks blocks"
3008 run_test 50b "mirror rsync handles sparseness"
3011 local tf=$DIR/$tdir/$tfile
3013 test_mkdir $DIR/$tdir
3015 $LFS setstripe -N2 -c-1 $tf || error "create FLR $tf failed"
3016 verify_flr_state $tf "ro"
3018 if [[ "$FSTYPE" == "ldiskfs" ]]; then
3019 # ZFS does not support fallocate for now
3020 out=$(fallocate -p -o 1MiB -l 1MiB $tf 2>&1) ||
3021 skip_eopnotsupp "$out|punch hole in $tf failed"
3022 verify_flr_state $tf "wp"
3025 dd if=/dev/zero of=$tf bs=4096 count=4 || error "write $tf failed"
3026 $LFS mirror resync $tf || error "mirror resync $tf failed"
3027 verify_flr_state $tf "ro"
3029 $MULTIOP $tf OSMWUc || error "$MULTIOP $tf failed"
3030 verify_flr_state $tf "wp"
3032 run_test 50c "punch_hole/mmap_write stale other mirrors"
3035 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3036 skip "OST does not support SEEK_HOLE"
3037 [ "$FSTYPE" != "zfs" ] ||
3038 skip "lseek for ZFS is not accurate if obj is not committed"
3040 local file=$DIR/$tdir/$tfile
3047 echo " ** create mirrored file $file"
3048 $LFS mirror create -N -E1M -c1 -S1M -E eof \
3049 -N -E2M -S1M -E eof -S2M $file ||
3050 error "cannot create mirrored file"
3051 echo " ** write data chunk at 1M boundary"
3052 dd if=/dev/urandom of=$file bs=1k count=20 seek=1021 ||
3053 error "cannot write data at 1M boundary"
3054 echo " ** create hole at the file start"
3055 prt=$(fallocate -p -o 0 -l 1M $file 2>&1)
3058 if [[ $rc -eq 0 ]]; then
3059 verify_flr_state $file "wp"
3060 elif [[ ! $prt =~ unsupported ]]; then
3061 error "punch hole in $file failed: $prt"
3063 skip "Fallocate punch is not supported: $prt"
3066 echo " ** verify sparseness"
3067 offset=$(lseek_test -d 1000 $file)
3068 echo " first data offset: $offset"
3069 (( $offset >= 1024 * 1024 )) ||
3070 error "src: data is not expected at offset $offset"
3072 echo " ** resync mirror #2"
3073 $LFS mirror resync $file
3075 # check llapi_mirror_copy_many correctness
3076 sum_1=$($LFS mirror read -N 1 $file | md5sum)
3077 sum_2=$($LFS mirror read -N 2 $file | md5sum)
3078 [[ $sum_1 == $sum_2 ]] ||
3079 error "data mismatch: \'$sum_1\' vs. \'$sum_2\'"
3081 cancel_lru_locks osc
3083 # stale first component in mirror #1
3084 $LFS setstripe --comp-set -I0x10001 --comp-flags=stale,nosync $file
3085 echo " ** verify sparseness of mirror #2"
3086 offset=$(lseek_test -d 1000 $file)
3087 echo " first data offset: $offset"
3088 (( $offset >= 1024 * 1024 )) ||
3089 error "src: data is not expected at offset $offset"
3091 run_test 50d "mirror rsync keep holes"
3094 $LCTL get_param osc.*.import | grep -q 'connect_flags:.*seek' ||
3095 skip "OST does not support SEEK_HOLE"
3097 local file=$DIR/$tdir/$tfile
3098 local old_size=2147483648 # 2GiB
3102 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096))
3103 $TRUNCATE $file $old_size
3105 $LFS mirror extend -N -c 1 $file
3106 dd if=/dev/urandom of=$file bs=4096 count=1 seek=$((134217728 / 4096)) conv=notrunc
3107 $LFS mirror resync $file
3109 new_size=$(stat --format='%s' $file)
3110 if ((new_size != old_size)); then
3111 error "new_size ($new_size) is not equal to old_size ($old_size)"
3114 run_test 60a "mirror extend sets correct size on sparse file"
3116 get_flr_layout_gen() {
3117 getfattr -n lustre.lov --only-values $tf 2>/dev/null |
3118 od -tx4 | awk '/000000/ { print "0x"$4; exit; }'
3121 check_layout_gen() {
3124 local v1=$(get_flr_layout_gen $tf)
3125 local v2=$($LFS getstripe -v $tf | awk '/lcm_layout_gen/ { print $2 }')
3127 [[ $v1 -eq $v2 ]] ||
3128 error "$tf in-memory layout gen $v1 != $v2 after $2"
3132 local tf=$DIR/$tdir/$tfile
3134 test_mkdir $DIR/$tdir
3136 $LFS setstripe -Eeof $tf || error "setstripe $tf failed"
3138 for ((i = 0; i < 20; i++)); do
3139 $LFS mirror extend -N $tf ||
3140 error "extending mirror for $tf failed"
3141 check_layout_gen $tf "extend"
3143 $LFS mirror split -d --mirror-id=$((i+1)) $tf ||
3144 error "split $tf failed"
3145 check_layout_gen $tf "split"
3148 run_test 60b "mirror merge/split cancel client's in-memory layout gen"
3151 stat --format='%X %Y %Z' $file || error "$file: cannot get times"
3156 local -a old=( $2 $3 $4 )
3159 new=( $(get_times_61 $file) )
3160 ((${old[0]} == ${new[0]})) ||
3161 error "$file: atime: old '${old[0]}' != new '${new[0]}'"
3163 ((${old[1]} == ${new[1]})) ||
3164 error "$file: mtime: old '${old[1]}' != new '${new[1]}'"
3167 test_61a() { # LU-14508
3168 local file=$DIR/$tdir/$tfile
3169 local old_diff=($(do_facet mds1 "$LCTL get_param -n mdd.*.atime_diff"))
3170 local mdts=$(comma_list $(mdts_nodes))
3174 do_nodes $mdts "$LCTL set_param mdd.*.atime_diff=1"
3175 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.atime_diff=$old_diff"
3179 $LFS setstripe -E1M -Eeof $file || error "setstripe $file failed"
3180 echo "create $file-2"
3181 $LFS setstripe -E2M -Eeof $file-2 || error "setstripe $file-2 failed"
3183 echo XXX > $file || error "write $file failed"
3184 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3186 echo "sleep $nap seconds, then cat $tfile"
3188 cat $file || error "cat $file failed"
3190 echo "sleep $nap seconds, then re-write $tfile"
3192 echo XXXX > $file || error "write $file failed"
3193 cp -p $file $file-2 || error "copy $file-2 failed"
3195 # flush opencache to update atime with close rpc
3196 cancel_lru_locks mdc
3198 echo "sleep $nap seconds"
3201 tim=( $(get_times_61 $file) )
3203 echo "mirror merge $tfile-2 to $tfile and test timestamps"
3204 $LFS mirror extend -N -f $file-2 $file ||
3205 error "cannot mirror merge $file-2 to $file"
3206 check_times_61 $file "${tim[@]}"
3208 echo "mirror extend $tfile and test timestamps"
3209 $LFS mirror extend -N -c1 -i1 $file ||
3210 error "cannot extend mirror $file"
3211 check_times_61 $file "${tim[@]}"
3213 echo "migrate $tfile and test timestamps"
3214 $LFS migrate -n $file || error "cannot migrate $file"
3215 check_times_61 $file "${tim[@]}"
3217 echo "normal user migrate $tfile and test timestamps"
3218 $RUNAS $LFS migrate -n $file || error "cannot migrate $file"
3219 check_times_61 $file "${tim[@]}"
3221 run_test 61a "mirror extend and migrate preserve timestamps"
3223 test_61b() { # LU-14508
3224 local file=$DIR/$tdir/$tfile
3230 echo XXX > $file || error "create $file failed"
3231 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3233 echo "sleep $nap seconds, then cat $tfile"
3235 cat $file || error "cat $file failed"
3237 echo "sleep $nap seconds, then re-write $tfile"
3239 echo XXXX > $file || error "write $file failed"
3241 echo "sleep $nap seconds, then test timestamps"
3244 tim=( $(get_times_61 $file) )
3246 echo "mirror extend $tfile and test timestamps"
3247 $LFS mirror extend -N -c1 -i1 $file ||
3248 error "cannot extend mirror $file"
3249 check_times_61 $file "${tim[@]}"
3251 echo "mirror split $tfile and test timestamps"
3252 $LFS mirror split -d --mirror-id=1 $file ||
3253 error "cannot split mirror 1 off $file"
3254 check_times_61 $file "${tim[@]}"
3256 echo "normal user mirror extend $tfile and test timestamps"
3257 $RUNAS $LFS mirror extend -N -c1 -i1 $file ||
3258 error "cannot extend mirror $file"
3259 check_times_61 $file "${tim[@]}"
3261 run_test 61b "mirror extend and split preserve timestamps"
3263 test_61c() { # LU-14508
3264 local file=$DIR/$tdir/$tfile
3270 echo XXX > $file || error "create $file failed"
3271 chown $RUNAS_ID $DIR/$tdir $file || error "chown $file failed"
3273 echo "sleep $nap seconds, then cat $tfile"
3275 cat $file || error "cat $file failed"
3277 echo "sleep $nap seconds, then mirror extend $tfile and write it"
3279 $LFS mirror extend -N -c1 -i1 $file ||
3280 error "cannot extend mirror $file"
3281 echo XXXX > $file || error "write $file failed"
3283 echo "sleep $nap seconds, then resync $tfile and test timestamps"
3284 tim=( $(get_times_61 $file) )
3286 $LFS mirror resync $file || error "cannot resync mirror $file"
3287 check_times_61 $file "${tim[@]}"
3289 echo XXXXXX > $file || error "write $tfile failed"
3291 echo "normal user resync $tfile and test timestamps"
3292 tim=( $(get_times_61 $file) )
3293 $RUNAS $LFS mirror resync $file || error "cannot resync mirror $file"
3294 check_times_61 $file "${tim[@]}"
3296 run_test 61c "mirror resync preserves timestamps"
3299 local file=$DIR/$tdir/$tfile
3303 echo "create mirror file with unknown magic"
3304 #define OBD_FAIL_LOV_COMP_MAGIC 0x1426
3305 # mirror 2 in-memory magic is bad
3306 $LCTL set_param fail_loc=0x1426 fail_val=2
3307 $LFS setstripe -N --flags=prefer -N2 $file ||
3308 error "failed to create mirror file $file"
3309 magic=$($LFS getstripe -v -I131074 $file | awk '/lmm_magic/{print $2}')
3310 [[ $magic == 0x0BAD0BD0 ]] ||
3311 error "mirror 2 magic $magic is not bad as expected"
3312 cat /etc/passwd > $file || error "cannot write to $file"
3313 diff /etc/passwd $file || error "read $file error"
3317 echo "create mirror file with unknown pattern"
3318 #define OBD_FAIL_LOV_COMP_PATTERN 0x1427
3319 # mirror 1 in-memory pattern is bad
3320 $LCTL set_param fail_loc=0x1427 fail_val=1
3321 $LFS setstripe -N -N --flags=prefer $file ||
3322 error "failed to create mirror file $file"
3323 pattern=$($LFS getstripe -I65537 $file | awk '/lmm_pattern/{print $2}')
3324 [[ $pattern == 502 ]] ||
3325 error "mirror 1 pattern $pattern is not bad as expected"
3326 cat /etc/passwd > $file || error "cannot write to $file"
3327 diff /etc/passwd $file || error "read $file error"
3329 run_test 62 "read/write with unknown type of mirror"
3332 local tf=$DIR/$tdir/$tfile
3334 test_mkdir $DIR/$tdir
3335 stack_trap "rm -f $tf"
3339 $LFS mirror create -N -E 1M -c -1 -E eof -N $tf
3343 echo "mirror create pid $c_pid"
3346 $LFS mirror split -d --mirror-id=1 $tf &> /dev/null
3349 echo "mirror split pid $s_pid"
3351 echo "mirror create and split race for 60 seconds, should not crash"
3353 kill -9 $c_pid &> /dev/null
3354 kill -9 $s_pid &> /dev/null
3358 run_test 70 "mirror create and split race"
3361 local tf=$DIR/$tdir/$tfile
3363 (( $OST1_VERSION >= $(version_code 2.14.51) )) ||
3364 skip "Need OST version at least 2.14.51"
3367 test_mkdir $DIR/$tdir
3368 stack_trap "rm -f $tf"
3370 $LFS setstripe -N -E1M -c-1 -Eeof -c-1 $tf ||
3371 error "setstripe $tf failed"
3373 FSXNUM=${FSXNUM:-1000}
3374 $FSX -p 1 -N $FSXNUM -S 0 -M $tf || error "fsx FLR file $tf failed"
3376 run_test 70a "flr mode fsx test"
3381 local fsize=$(stat --printf=%s $tf)
3383 while [ -f $ctrl_file ]; do
3384 local off=$((RANDOM << 8))
3385 local len=$((RANDOM << 5 + 131072))
3387 [ $((off + len)) -gt $fsize ] && {
3388 fsize=$((off + len))
3389 echo "Extending file size to $fsize .."
3392 flock -s $lock_file -c \
3393 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
3395 error "failed writing to $off:$len"; }
3396 sleep 0.$((RANDOM % 2 + 1))
3403 while [ -f $ctrl_file ]; do
3404 flock -s $lock_file -c "cat $tf &> /dev/null" ||
3405 { rm -f $ctrl_file; error "read failed"; }
3406 sleep 0.$((RANDOM % 2 + 1))
3413 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
3415 exec 200<>$lock_file
3416 while [ -f $ctrl_file ]; do
3417 local lock_taken=false
3418 local index=$((RANDOM % ${#options[@]}))
3419 local cmd="mirror_io resync ${options[$index]}"
3421 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
3423 [ $((RANDOM % 4)) -eq 0 ] && {
3429 echo -n "resync file $tf with '$cmd' .."
3431 if [[ $lock_taken = "true" ]]; then
3433 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3436 $cmd $tf &> /dev/null && echo "done" || echo "failed"
3439 sleep 0.$((RANDOM % 8 + 1))
3443 # this was test_200 before adding "b" and "c" subtests
3445 local tf=$DIR/$tfile
3446 local tf2=$DIR2/$tfile
3447 local tf3=$DIR3/$tfile
3449 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3450 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3451 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3453 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3454 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3455 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3457 $LFS mirror extend -N -f $tf-2 $tf ||
3458 error "merging $tf-2 into $tf failed"
3459 $LFS mirror extend -N -f $tf-3 $tf ||
3460 error "merging $tf-3 into $tf failed"
3462 mkdir -p $MOUNT2 && mount_client $MOUNT2
3464 mkdir -p $MOUNT3 && mount_client $MOUNT3
3466 verify_flr_state $tf3 "ro"
3468 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
3469 $LCTL set_param fail_loc=0x1A03
3471 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
3472 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
3476 write_file_200 $tf &
3482 write_file_200 $tf2 &
3485 read_file_200 $tf2 &
3488 resync_file_200 $tf3 &
3492 [ "$SLOW" = "yes" ] && sleep_time=360
3493 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
3500 echo "Waiting ${pids[*]}"
3503 umount_client $MOUNT2
3504 umount_client $MOUNT3
3506 # resync and verify mirrors
3507 $LFS mirror resync $tf || error "final resync failed"
3510 local csum=$($LFS mirror read -N "${mirror_array[0]}" $tf | md5sum)
3512 for id in "${mirror_array[@]:1}"; do
3513 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3514 error "checksum error for mirror $id"
3519 run_test 200a "stress test"
3522 local tf=$DIR/$tfile
3523 local tf2=$DIR2/$tfile
3524 local tf3=$DIR3/$tfile
3526 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
3527 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
3528 stack_trap "rm -f $ctrl_file $lock_file $tf $tf-2 $tf-3"
3530 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
3531 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
3532 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
3534 $LFS mirror extend -N -f $tf-2 $tf ||
3535 error "merging $tf-2 into $tf failed"
3536 $LFS mirror extend -N -f $tf-3 $tf ||
3537 error "merging $tf-3 into $tf failed"
3539 mkdir -p $MOUNT2 && mount_client $MOUNT2
3541 mkdir -p $MOUNT3 && mount_client $MOUNT3
3543 verify_flr_state $tf3 "ro"
3545 #define OBD_FAIL_LLITE_PANIC_ON_ESTALE 0x1423
3546 $LCTL set_param fail_loc=0x1423
3550 write_file_200 $tf &
3556 write_file_200 $tf2 &
3559 read_file_200 $tf2 &
3562 resync_file_200 $tf3 &
3566 [ "$SLOW" = "yes" ] && sleep_time=400
3570 echo "Waiting ${pids[@]}"
3573 umount_client $MOUNT2
3574 umount_client $MOUNT3
3576 # resync and verify mirrors
3577 $LFS mirror resync $tf || {
3579 error "final resync failed"
3583 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
3584 for id in ${mirror_array[@]:1}; do
3585 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
3586 error "checksum error for mirror $id"
3591 run_test 200b "racing IO, mirror extend and resync"
3594 (( MDS1_VERSION >= $(version_code 2.15.53) )) ||
3595 skip "Need MDS version at least 2.15.53"
3597 local tf=$DIR/$tfile
3598 local tf2=$DIR2/$tfile
3600 mkdir -p $MOUNT2 && mount_client $MOUNT2
3601 stack_trap "umount_client $MOUNT2"
3602 stack_trap "rm -f $tf"
3606 dd if=/dev/urandom of=$tf bs=1M count=2 || error "can't write"
3608 mdt_idx=$($LFS getstripe -m $tf)
3610 cancel_lru_locks mdc
3611 cancel_lru_locks osc
3613 # start a process modifying file, block it just
3614 # before layout lock acquisition
3615 #define OBD_FAIL_MDS_DELAY_OPEN 0x175
3616 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0x80000175 fail_val=10
3617 #log "dd to stale replica"
3618 dd if=/dev/urandom of=$tf bs=1M count=2 oflag=direct conv=notrunc &
3624 $LFS mirror extend -N -c -1 $tf2 || {
3626 error "can't mirror"
3628 log "mirror extend done"
3629 do_facet mds$((mdt_idx+1)) $LCTL set_param fail_loc=0 fail_val=0
3631 # wait for blocking dd to complete and modify file
3632 wait $PID || error "2nd dd failed"
3635 verify_mirror_count $tf 2
3637 $LFS getstripe $tf | grep -q lcme_flags.*stale || {
3640 error "both replicas are still in sync"
3643 $LFS mirror verify -vvv $tf || {
3645 error "corrupted in-sync file"
3648 run_test 200c "layout change racing with open: LOVEA changes"
3650 cleanup_test_201() {
3651 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
3653 umount_client $MOUNT2
3657 local delay=${RESYNC_DELAY:-5}
3659 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
3660 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
3662 stack_trap cleanup_test_201 EXIT
3664 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
3665 changelog_register -n)
3667 mkdir -p $MOUNT2 && mount_client $MOUNT2
3671 local log=$($LFS changelog $MDT0 $index | grep FLRW)
3672 [ -z "$log" ] && { sleep 1; continue; }
3674 index=$(echo $log | awk '{print $1}')
3675 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
3676 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
3677 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
3680 [ -z "$file" ] && continue
3682 local now=$(date +%s)
3684 echo "file: $file $fid was modified at $ts, now: $now, " \
3685 "will be resynced at $((ts+delay))"
3687 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
3689 $LFS mirror resync $file
3690 echo "$file resync done"
3693 run_test 201 "FLR data mover"
3696 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
3698 local tf=$DIR/$tfile
3701 $LFS setstripe -E 1M -S 1M -c 1 $tf
3702 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3703 verify_comp_attr stripe-count $tf ${ids[0]} 1
3705 $LFS setstripe --component-add -E 2M -c $OSTCOUNT $tf
3706 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3707 verify_comp_attr stripe-count $tf ${ids[0]} 1
3708 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3710 dd if=/dev/zero of=$tf bs=1M count=2
3711 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
3712 verify_comp_attr stripe-count $tf ${ids[0]} 1
3713 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
3715 run_test 202 "lfs setstripe --add-component wide striping"
3718 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
3719 skip "Need MDS version at least 2.11.55"
3720 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
3722 local tf=$DIR/$tfile
3725 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
3726 #delete first mirror
3727 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
3730 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
3731 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3732 error "getstripe count of mirror 2"
3733 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3735 #extend a mirror with 2 OSTs
3736 $LFS mirror extend -N -c2 $tf || error "extend mirror"
3739 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
3740 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
3741 error "getstripe count of mirror 2"
3742 [[ x$old_id = x$new_id ]] ||
3743 error "mirror 2 changed ID from $old_id to $new_id"
3744 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
3746 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
3747 error "getstripe count of mirror 3"
3748 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
3750 run_test 203 "mirror file preserve mirror ID"
3752 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
3754 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3755 skip "skipped for lustre < $SEL_VER"
3757 local comp_file=$DIR/$tdir/$tfile
3761 test_mkdir $DIR/$tdir
3762 stack_trap "rm -f $comp_file"
3764 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
3765 # by extension space to -1
3766 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
3767 error "Create $comp_file failed"
3769 # Write to first component, extending & staling second mirror
3770 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3771 error "dd to extend + stale failed"
3773 $LFS getstripe $comp_file
3775 flg_opts="--component-flags init,stale"
3776 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3777 [ $found -eq 1 ] || error "write: Second comp end incorrect"
3779 flg_opts="--component-flags extension"
3780 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3781 [ $found -eq 1 ] || error "write: Third comp start incorrect"
3783 # mirror resync should not change the extents
3784 $LFS mirror resync $comp_file
3786 flg_opts="--component-flags init"
3787 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3788 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
3790 flg_opts="--component-flags extension"
3791 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3792 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
3794 sel_layout_sanity $comp_file 5
3796 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
3798 # Simple test of FLR + self-extending layout, SEL in primary mirror
3800 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3801 skip "skipped for lustre < $SEL_VER"
3803 local comp_file=$DIR/$tdir/$tfile
3807 test_mkdir $DIR/$tdir
3808 stack_trap "rm -f $comp_file"
3810 # first mirror is 1M followed by extension space to -1, second mirror
3811 # is 0-10M, then 10M-(-1),
3812 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3813 error "Create $comp_file failed"
3815 # Write to first component, extending first component & staling
3817 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
3818 error "dd to extend + stale failed"
3820 $LFS getstripe $comp_file
3822 flg_opts="--component-flags init"
3823 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3824 [ $found -eq 1 ] || error "write: First comp end incorrect"
3826 flg_opts="--component-flags extension"
3827 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3828 [ $found -eq 1 ] || error "write: Second comp start incorrect"
3830 flg_opts="--component-flags init,stale"
3831 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3832 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
3834 # This component is staled because it overlaps the extended first
3835 # component of the primary mirror, even though it doesn't overlap
3836 # the actual write - thus not inited.
3837 flg_opts="--component-flags stale"
3838 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3839 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
3841 # mirror resync should not change the extents
3842 $LFS mirror resync $comp_file
3844 $LFS getstripe $comp_file
3846 flg_opts="--component-flags init"
3847 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
3848 [ $found -eq 1 ] || error "resync: First comp end incorrect"
3850 flg_opts="--component-flags extension"
3851 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
3852 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
3854 flg_opts="--component-flags init"
3855 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
3856 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
3858 flg_opts="--component-flags init"
3859 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
3860 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
3862 sel_layout_sanity $comp_file 5
3864 run_test 204b "FLR write/stale/resync tests with self-extending primary"
3866 # FLR + SEL failed extension & component removal
3867 # extension space in second mirror
3869 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3870 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3871 skip "skipped for lustre < $SEL_VER"
3873 local comp_file=$DIR/$tdir/$tfile
3876 local ost_name=$(ostname_from_index $ost_idx1)
3878 test_mkdir $DIR/$tdir
3879 stack_trap "rm -f $comp_file"
3881 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
3882 # extension space from 1M to 1G, then normal space to -1
3883 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
3884 -E -1 $comp_file || error "Create $comp_file failed"
3886 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
3889 # write to first comp (0 - 10M) of mirror 1, extending + staling
3890 # first + second comp of mirror 2
3891 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
3894 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
3897 [ $RC -eq 0 ] || error "dd to extend + stale failed"
3899 $LFS getstripe $comp_file
3901 found=$($LFS find --component-start 0m --component-end 1m \
3902 --comp-flags init,stale $comp_file | wc -l)
3903 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
3905 found=$($LFS find --component-start 1m --component-end EOF \
3906 --comp-flags stale,^init $comp_file | wc -l)
3907 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
3909 local mirror_id=$($LFS getstripe --component-start=1m \
3910 --component-end=EOF $comp_file | \
3911 grep lcme_mirror_id | awk '{ print $2 }')
3913 [[ $mirror_id -eq 2 ]] ||
3914 error "component not in correct mirror? $mirror_id"
3916 $LFS mirror resync $comp_file
3918 $LFS getstripe $comp_file
3920 # component dimensions should not change from resync
3921 found=$($LFS find --component-start 1m --component-end EOF \
3922 --component-flags init $comp_file | wc -l)
3923 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
3925 sel_layout_sanity $comp_file 4
3927 run_test 204c "FLR write/stale/resync test with component removal"
3929 # Successful repeated component in primary mirror
3931 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
3932 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
3933 skip "skipped for lustre < $SEL_VER"
3935 local comp_file=$DIR/$tdir/$tfile
3938 wait_delete_completed
3940 test_mkdir $DIR/$tdir
3941 stack_trap "rm -f $comp_file"
3943 # first mirror is 64M followed by extension space to -1, second mirror
3944 # is 0-10M, then 10M-(-1)
3945 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
3946 error "Create $comp_file failed"
3948 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
3949 local ost_name=$(ostname_from_index $ost_idx1)
3950 # degrade OST for first comp so we won't extend there
3951 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3952 obdfilter.$ost_name.degraded=1
3955 # Write beyond first component, causing repeat & stale second mirror
3956 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
3959 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
3960 obdfilter.$ost_name.degraded=0
3963 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
3965 $LFS getstripe $comp_file
3967 found=$($LFS find --component-start 64m --component-end 128m \
3968 --component-flags init $comp_file | wc -l)
3969 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
3971 local ost_idx2=$($LFS getstripe --component-start=64m \
3972 --component-end=128m --component-flags=init \
3974 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
3975 local mirror_id=$($LFS getstripe --component-start=64m \
3976 --component-end=128m --component-flags=init \
3977 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
3978 [[ $mirror_id -eq 1 ]] ||
3979 error "component not in correct mirror: $mirror_id, not 1"
3981 $LFS mirror resync $comp_file
3983 $LFS getstripe $comp_file
3985 # component dimensions should not change from resync
3986 found=$($LFS find --component-start 0m --component-end 64m \
3987 --component-flags init $comp_file | wc -l)
3988 [ $found -eq 1 ] || error "resync: first comp incorrect"
3989 found=$($LFS find --component-start 64m --component-end 128m \
3990 --component-flags init $comp_file | wc -l)
3991 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
3993 sel_layout_sanity $comp_file 5
3995 run_test 204d "FLR write/stale/resync sel test with repeated comp"
3997 # Successful repeated component, SEL in non-primary mirror
3999 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4000 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4001 skip "skipped for lustre < $SEL_VER"
4003 local comp_file=$DIR/$tdir/$tfile
4006 wait_delete_completed
4009 test_mkdir $DIR/$tdir
4010 stack_trap "rm -f $comp_file"
4012 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4013 # space to -1 (-z 64M, so first comp is 0-64M)
4014 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
4015 # will be not enough - one will be degraded, the other is used on
4016 # an overlapping mirror.
4017 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
4018 error "Create $comp_file failed"
4020 local ost_idx1=$($LFS getstripe --component-start=0 \
4021 --component-end=64m -i $comp_file)
4022 local ost_name=$(ostname_from_index $ost_idx1)
4023 # degrade OST for first comp of 2nd mirror so we won't extend there
4024 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4025 obdfilter.$ost_name.degraded=1
4028 $LFS getstripe $comp_file
4030 # Write to first component, stale & instantiate second mirror components
4031 # overlapping with the written component (0-100M);
4032 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4035 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
4036 obdfilter.$ost_name.degraded=0
4038 $LFS getstripe $comp_file
4040 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
4042 found=$($LFS find --component-start 0m --component-end 64m \
4043 --component-flags init,stale $comp_file | wc -l)
4044 [ $found -eq 1 ] || error "write: first comp incorrect"
4046 # was repeated due to degraded ost
4047 found=$($LFS find --component-start 64m --component-end 128m \
4048 --component-flags init,stale $comp_file | wc -l)
4049 [ $found -eq 1 ] || error "write: repeated comp incorrect"
4051 local ost_idx2=$($LFS getstripe --component-start=64m \
4052 --component-end=128m --component-flags=init \
4054 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
4055 local mirror_id=$($LFS getstripe --component-start=0m \
4056 --component-end=64m --component-flags=init \
4057 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4058 [[ $mirror_id -eq 2 ]] ||
4059 error "component not in correct mirror? $mirror_id"
4061 $LFS mirror resync $comp_file
4063 $LFS getstripe $comp_file
4065 # component dimensions should not change from resync
4066 found=$($LFS find --component-start 0m --component-end 64m \
4067 --component-flags init,^stale $comp_file | wc -l)
4068 [ $found -eq 1 ] || error "resync: first comp incorrect"
4069 found=$($LFS find --component-start 64m --component-end 128m \
4070 --component-flags init,^stale $comp_file | wc -l)
4071 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
4073 sel_layout_sanity $comp_file 5
4075 run_test 204e "FLR write/stale/resync sel test with repeated comp"
4077 # FLR + SEL: failed repeated component, SEL in non-primary mirror
4079 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
4080 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
4081 skip "skipped for lustre < $SEL_VER"
4083 local comp_file=$DIR/$tdir/$tfile
4086 wait_delete_completed
4088 test_mkdir $DIR/$tdir
4089 stack_trap "rm -f $comp_file"
4091 pool_add $TESTNAME || error "Pool creation failed"
4092 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
4094 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
4095 # space to -1 (-z 64M, so first comp is 0-64M)
4096 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
4097 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
4099 local ost_name0=$(ostname_from_index 0)
4100 local ost_name1=$(ostname_from_index 1)
4102 # degrade both OSTs in pool, so we'll try to repeat, then fail and
4103 # extend original comp
4104 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
4105 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
4108 # a write to the 1st component, 100M length, which will try to stale
4109 # the first 100M of mirror 2, attempting to extend its 0-64M component
4110 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
4113 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
4114 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
4117 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
4119 $LFS getstripe $comp_file
4121 found=$($LFS find --component-start 0m --component-end 128m \
4122 --component-flags init,stale $comp_file | wc -l)
4123 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
4125 local mirror_id=$($LFS getstripe --component-start=0m \
4126 --component-end=128m --component-flags=init \
4127 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
4129 [[ $mirror_id -eq 2 ]] ||
4130 error "component not in correct mirror? $mirror_id, not 2"
4132 $LFS mirror resync $comp_file
4134 $LFS getstripe $comp_file
4136 # component dimensions should not change from resync
4137 found=$($LFS find --component-start 0m --component-end 128m \
4138 --component-flags init,^stale $comp_file | wc -l)
4139 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
4141 sel_layout_sanity $comp_file 4
4143 run_test 204f "FLR write/stale/resync sel w/forced extension"
4145 function test_205() {
4146 local tf=$DIR/$tfile
4149 $LFS setstripe -c1 $tf
4150 $LFS mirror extend -N $tf
4151 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4152 (( $mirrors == 2 )) || error "no new mirror was created?"
4154 $LFS mirror extend -N --flags=prefer $tf
4155 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4156 (( $mirrors == 3 )) || error "no new mirror with prefer flag was created?"
4158 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
4159 error "prefer flag was not set on the new mirror"
4161 $LFS mirror extend -N --flags=nocompr $tf
4162 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4163 (( $mirrors == 4 )) || error "no new mirror with nocompr flag was created?"
4165 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q nocompr) ||
4166 error "nocompr flag was not set on the new mirror"
4168 $LFS mirror extend -N --flags=prefer,nocompr $tf
4169 mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
4170 (( $mirrors == 5 )) || error "no new mirror with prefer,nocompr flags was created?"
4172 $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q "prefer,nocompr") ||
4173 error "prefer,nocompr flags were not set on the new mirror"
4175 run_test 205 "lfs mirror extend to set prefer and nocompr flags"
4177 function test_206() {
4178 # create a new OST pool
4179 local pool_name=$TESTNAME
4181 create_pool $FSNAME.$pool_name ||
4182 error "create OST pool $pool_name failed"
4183 # add OSTs into the pool
4184 pool_add_targets $pool_name 0 1 ||
4185 error "add OSTs into pool $pool_name failed"
4187 $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile ||
4188 error "can't setstripe"
4189 $LFS mirror extend -N $DIR/$tfile ||
4190 error "can't create replica"
4191 if $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4192 $LFS getstripe $DIR/$tfile
4193 error "prefer found"
4195 $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || {
4196 $LFS getstripe $DIR/$tfile
4197 error "can't setstripe prefer"
4200 if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then
4201 $LFS getstripe $DIR/$tfile
4202 error "no prefer found"
4208 run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
4211 local file=$DIR/$tfile
4212 local tmpfile=$DIR/$tfile-tt
4214 (( $MDS1_VERSION >= $(version_code v2_14_50-161-g571f3cf111) )) ||
4215 skip "Need MDS >= 2.14.50.161 for stale components fix"
4217 stack_trap "rm -f $tmpfile $file"
4219 # generate data for verification
4220 dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
4221 error "can't generate file with random data"
4223 # create a mirrored file with one stale replica
4224 $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
4225 error "create mirrored file $file failed"
4226 get_mirror_ids $file
4227 echo "mirror IDs: ${mirror_array[*]}"
4229 dd if=$tmpfile of=$file bs=1M || error "can't copy"
4230 get_mirror_ids $file
4231 echo "mirror IDs: ${mirror_array[*]}"
4234 cmp $tmpfile $file || error "files don't match"
4235 get_mirror_ids $file
4236 echo "mirror IDs: ${mirror_array[*]}"
4238 # mirror creation should work fine
4239 $LFS mirror extend -N -S 8M -c -1 $file ||
4240 error "mirror extend $file failed"
4242 get_mirror_ids $file
4243 echo "mirror IDs: ${mirror_array[*]}"
4246 $LFS mirror verify -v $file || error "verification failed"
4247 cmp $tmpfile $file || error "files don't match"
4249 run_test 207 "create another replica with existing out-of-sync one"
4251 function check_ost_used() {
4260 cancel_lru_locks osc # to drop pages
4261 cancel_lru_locks mdc # to refresh layout
4262 # XXX: cancel_lru_locks mdc doesn't work
4263 # XXX: need a better way to reload the layout
4264 umount_client $MOUNT || error "umount failed"
4265 mount_client $MOUNT || error "mount failed"
4267 # refresh non-rotation status on MDTs
4269 touch $DIR/$tfile-temp
4270 rm -f $DIR/$tfile-temp
4271 # refresh non-rotational status on the client
4275 $LCTL set_param osc.*.stats=clear >/dev/null
4276 if [[ $io == "read" ]]; then
4277 ddarg="if=$file of=/dev/null"
4278 elif [[ $io == "write" ]]; then
4279 ddarg="if=/dev/zero of=$file"
4281 error "unknown type $io"
4283 dd $ddarg bs=8M count=1 || error "can't $io $file"
4284 cancel_lru_locks osc
4286 # check only specified OSTs got reads
4287 for ((ost = 0; ost < $OSTCOUNT; ost++)); do
4288 local nr=$($LCTL get_param -n \
4289 osc.$FSNAME-OST000$ost-osc-[-0-9a-f]*.stats |
4290 awk "/ost_$io/{print \$2}")
4292 if [[ " $* " =~ $ost ]]; then
4293 (( nr > 0 )) || error "expected reads on $ost"
4295 (( nr == 0 )) || error "unexpected $nr reads on $ost"
4301 local tf=$DIR/$tfile
4302 local osts=$(comma_list $(osts_nodes))
4304 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4305 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4306 skip "Need MDS version at least 2.14.55"
4308 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4310 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4311 stack_trap "restore_lustre_params < $p; rm -f $p"
4313 stack_trap "rm -f $tf"
4314 $LFS setstripe -i0 -c1 $tf || error "can't setstripe"
4315 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4316 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4317 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4318 $LFS mirror resync $tf || error "can't resync"
4321 log "set OST0000 non-rotational"
4323 $LCTL set_param osd*.*OST*.nonrotational=0
4325 $LCTL set_param osd*.*OST0000*.nonrotational=1
4326 check_ost_used $tf read 0
4328 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4330 $LCTL set_param osd*.*OST*.nonrotational=0
4332 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4333 osd*.*OST0003*.nonrotational=1
4334 check_ost_used $tf read 2 3
4336 log "set mirror 1 on OST0001 preferred"
4337 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4338 error "can't set prefer"
4339 check_ost_used $tf read 1
4341 run_test 208a "mirror selection to prefer non-rotational devices for reads"
4344 local tf=$DIR/$tfile
4345 local osts=$(comma_list $(osts_nodes))
4347 (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
4348 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
4349 skip "Need MDS version at least 2.14.55"
4351 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4353 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4354 stack_trap "restore_lustre_params < $p; rm -f $p"
4356 stack_trap "rm -f $tf"
4357 $LFS setstripe -i0 -c1 -S1M $tf || error "can't setstripe"
4358 dd if=/dev/zero of=$tf bs=8M count=1 || error "can't dd (1)"
4359 $LFS mirror extend -N -c1 -o1 $tf || error "can't create mirror"
4360 $LFS mirror extend -N -c2 -o 2,3 $tf || error "can't create mirror"
4361 $LFS mirror resync $tf || error "can't resync"
4362 $LFS getstripe $tf | grep -q flags.*stale && error "still stale"
4364 log "set OST0000 non-rotational"
4366 $LCTL set_param osd*.*OST*.nonrotational=0
4368 $LCTL set_param osd*.*OST0000*.nonrotational=1
4369 check_ost_used $tf write 0
4370 $LFS mirror resync $tf || error "can't resync"
4372 log "set OST0002 and OST0003 non-rotational, two fast OSTs is better"
4374 $LCTL set_param osd*.*OST*.nonrotational=0
4376 $LCTL set_param osd*.*OST0002*.nonrotational=1 \
4377 osd*.*OST0003*.nonrotational=1
4378 check_ost_used $tf write 2 3
4379 $LFS mirror resync $tf || error "can't resync"
4381 log "set mirror 1 on OST0001 preferred"
4382 $LFS setstripe --comp-set -I 0x20001 --comp-flags=prefer $tf ||
4383 error "can't set prefer"
4384 check_ost_used $tf write 1
4386 run_test 208b "mirror selection to prefer non-rotational devices for writes"
4389 local tf=$DIR/$tfile
4390 local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
4391 local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
4392 local osts=$(comma_list $(osts_nodes))
4394 stack_trap "rm -f $tmpfile"
4396 mkdir -p $MOUNT2 && mount_client $MOUNT2
4397 stack_trap "umount_client $MOUNT2"
4399 # to make replica on ost1 preferred for new writes
4400 save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
4401 stack_trap "restore_lustre_params < $p; rm -f $p"
4403 $LCTL set_param osd*.*OST*.nonrotational=0
4405 $LCTL set_param osd*.*OST0001*.nonrotational=1
4407 $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
4409 $LFS mirror extend -N -o1 $tf || error "can't make replica"
4410 log "replicated file created"
4412 cancel_lru_locks mdc
4413 cancel_lru_locks osc
4415 log "open(O_RDONLY) and first read from OST"
4416 $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
4419 log "first read complete"
4421 echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
4422 error "can't write BBBB"
4423 log "BBBB written which made replica on ost1 stale"
4425 log "fast read from pagecache in the original process"
4429 log "read via $DIR2 new open(2)"
4430 $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
4432 log "fast read from pagecache after 5s in the original process"
4437 local nr=$(grep "BBBB" $tmpfile | wc -l)
4443 log "read via new open(2)"
4444 $MULTIOP $tf vvoO_RDONLY:r4c
4446 run_test 209a "skip fast reads after layout invalidation"
4448 function sum_ost_reads() {
4449 $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
4450 awk '/^ost_read/{sum=sum+$2}END{print sum}'
4454 local tf=$DIR/$tfile
4456 dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
4457 cancel_lru_locks osc
4458 echo "the very first read"
4459 cat $tf >/dev/null || error "can't read"
4461 # cancel layout lock
4462 cancel_lru_locks mdc
4464 # now read again, data must be in the cache, so no ost reads
4465 $LCTL set_param osc.*.stats=clear >/dev/null
4466 echo "read with warm cache"
4467 cat $tf >/dev/null || error "can't read"
4469 (( nr == 0 )) || error "reads with warm cache"
4471 # now verify we can catch reads at all
4472 cancel_lru_locks osc
4473 cat $tf >/dev/null || error "can't read"
4475 (( nr > 0 )) || error "no reads with cold cache"
4477 run_test 209b "pagecache can be used after LL cancellation"
4480 local tf=$DIR/$tfile
4482 stack_trap "rm -f $tf"
4483 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4484 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4485 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4486 $LFS mirror extend -N $tf || error "can't mirror"
4487 $LFS getstripe -v $tf
4488 stat $tf || error "can't stat"
4490 run_test 210a "handle broken mirrored lovea"
4493 local tf=$DIR/$tfile
4495 [ "$FSTYPE" != "zfs" ] || skip "ZFS file number is not accurate"
4497 $LFS setstripe -i0 -c1 $tf || error "can't create file"
4498 dd if=/dev/zero of=$tf bs=1M count=1 || error "can't dd"
4500 local ostdev=$(ostdevname 1)
4501 local fid=($($LFS getstripe $DIR/$tfile | grep 0x))
4502 local seq=${fid[3]#0x}
4505 if [ $seq == 0 ]; then
4508 oid_hex=${fid[2]#0x}
4510 local objpath="O/$seq/d$(($oid % 32))/$oid_hex"
4511 local cmd="$DEBUGFS -c -R \\\"stat $objpath\\\" $ostdev"
4513 local ino=$(do_facet ost1 $cmd | grep Inode:)
4514 [[ -n $ino ]] || error "can't access obj object: $objpath"
4516 #define OBD_FAIL_LOV_INVALID_OSTIDX 0x1428
4517 do_facet mds1 "$LCTL set_param fail_loc=0x1428"
4518 $LFS mirror extend -N $tf || error "can't mirror"
4520 # now remove the file with bogus ostidx in the striping info
4521 rm $tf || error "can't remove"
4522 [[ -f $tf ]] && error "rm failed"
4523 wait_delete_completed
4525 local ino=$(do_facet ost1 $cmd | grep Inode:)
4526 [[ -z $ino ]] || error "still CAN access obj object: $objpath"
4528 run_test 210b "handle broken mirrored lovea (unlink)"
4530 complete_test $SECONDS
4531 check_and_cleanup_lustre