3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
16 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT "
17 # Bug number for skipped test: LU-11381
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
23 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
24 skip "Need MDS version at least 2.10.56"
26 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
27 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
28 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
30 check_and_setup_lustre
35 rm -rf $DIR/[Rdfs][0-9]*
37 # global array to store mirror IDs
38 declare -a mirror_array
45 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
46 array[${#array[@]}]=$((id >> 16))
49 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
51 echo ${#mirror_array[@]}
55 echo 3 > /proc/sys/vm/drop_caches
66 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
74 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
75 error "start ost$idx failed"
79 wait_recovery_complete ost$idx
84 # Verify mirror count with an expected value for a given file.
86 verify_mirror_count() {
89 local mirror_count=$($LFS getstripe -N $tf)
91 [[ $mirror_count = $expected ]] || {
93 error "verify mirror count failed on $tf:" \
94 "$mirror_count != $expected"
99 # Verify component count with an expected value for a given file.
100 # $1 coposited layout file
101 # $2 expected component number
103 verify_comp_count() {
106 local comp_count=$($LFS getstripe --component-count $tf)
108 [[ $comp_count = $expected ]] || {
109 $LFS getstripe -v $tf
110 error "verify component count failed on $tf:" \
111 "$comp_count != $expected"
116 # Verify component attribute with an expected value for a given file
124 local cmd="$LFS getstripe -I$comp_id"
125 local getstripe_cmd="$cmd -v"
129 stripe-size) cmd+=" -S $tf" ;;
130 stripe-count) cmd+=" -c $tf" ;;
131 stripe-index) cmd+=" -i $tf" ;;
132 pool) cmd+=" -p $tf" ;;
133 comp-start) cmd+=" --component-start $tf" ;;
134 comp-end) cmd+=" --component-end $tf" ;;
135 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
136 *) error "invalid attribute $attr";;
141 [ $attr = lcme_flags ] && {
143 local expected_list=$(comma_list $expected)
144 for fl in ${expected_list//,/ }; do
147 [[ ${fl:0:1} = "^" ]] && neg=1
148 [[ $neg = 1 ]] && fl=${fl:1}
150 $(echo $value | grep -q $fl)
152 # 0: matched; 1: not matched
154 if [[ $neg = 0 && $match != 0 ||
155 $neg = 1 && $match = 0 ]]; then
157 [[ $neg = 0 ]] && # expect the flag
158 error "expected flag '$fl' not in $comp_id"
159 [[ $neg = 1 ]] && # not expect the flag
160 error "not expected flag '$fl' in $comp_id"
166 [[ $value = $expected ]] || {
168 error "verify $attr failed on $tf: $value != $expected"
173 # Verify component extent with expected start and end extent values
174 # for a given file and component ID.
176 verify_comp_extent() {
179 local expected_start=$3
180 local expected_end=$4
182 verify_comp_attr comp-start $tf $comp_id $expected_start
183 verify_comp_attr comp-end $tf $comp_id $expected_end
187 # Verify component attribute with parent directory for a given file
190 verify_comp_attr_with_parent() {
194 local td=$(cd $(dirname $tf); echo $PWD)
195 local tf_cmd="$LFS getstripe -I$comp_id"
196 local td_cmd="$LFS getstripe"
202 stripe-size) opt="-S" ;;
203 stripe-count) opt="-c" ;;
205 *) error "invalid attribute $attr";;
208 expected=$($td_cmd $opt $td)
209 [[ $expected = -1 ]] && expected=$OSTCOUNT
211 value=$($tf_cmd $opt $tf)
212 [[ $value = -1 ]] && value=$OSTCOUNT
214 [[ $value = $expected ]] || {
217 error "verify $attr failed with parent on $tf:" \
218 "$value != $expected"
223 # Verify component attribute with filesystem-wide default value for a given file
226 verify_comp_attr_with_default() {
230 local tf_cmd="$LFS getstripe -I$comp_id"
238 expected=$($LCTL get_param -n \
239 lov.$FSNAME-clilov-*.stripesize)
243 expected=$($LCTL get_param -n \
244 lov.$FSNAME-clilov-*.stripecount)
245 [[ $expected = -1 ]] && expected=$OSTCOUNT
247 *) error "invalid attribute $attr";;
250 value=$($tf_cmd $opt $tf)
251 [[ $value = -1 ]] && value=$OSTCOUNT
253 [[ $value = $expected ]] || {
255 error "verify $attr failed with default value on $tf:" \
256 "$value != $expected"
261 # Verify unspecified component attributes for a given file
264 # This will only verify the inherited attributes:
265 # stripe size, stripe count and OST pool name
267 verify_comp_attrs() {
271 verify_comp_attr_with_default stripe-size $tf $comp_id
272 verify_comp_attr_with_default stripe-count $tf $comp_id
273 verify_comp_attr_with_parent pool $tf $comp_id
279 local expected_state=$2
281 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
282 [ $expected_state = $state ] ||
283 error "expected: $expected_state, actual $state"
286 # command line test cases
290 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
291 local mirror_cmd="$LFS mirror create"
296 # create parent directory
297 mkdir $td || error "mkdir $td failed"
299 $mirror_cmd $tf &> /dev/null && error "miss -N option"
301 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
302 verify_mirror_count $tf 1
303 id=$($LFS getstripe -I $tf)
304 verify_comp_attrs $tf $id
305 verify_comp_extent $tf $id 0 EOF
307 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
308 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
309 error "invalid mirror count $((mirror_count + 1))"
311 $mirror_cmd -N$mirror_count $tf-1 ||
312 error "create mirrored file $tf-1 failed"
313 verify_mirror_count $tf-1 $mirror_count
314 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
315 for ((i = 0; i < $mirror_count; i++)); do
316 verify_comp_attrs $tf-1 ${ids[$i]}
317 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
320 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
321 error "create mirrored file $tf-2 failed"
322 verify_mirror_count $tf-2 10
323 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
324 for ((i = 0; i < 10; i++)); do
325 verify_comp_attrs $tf-2 ${ids[$i]}
326 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
329 run_test 0a "lfs mirror create with -N option"
332 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
336 local mirror_cmd="$LFS mirror create"
340 # create a new OST pool
341 local pool_name=$TESTNAME
342 create_pool $FSNAME.$pool_name ||
343 error "create OST pool $pool_name failed"
345 # add OSTs into the pool
346 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
347 error "add OSTs into pool $pool_name failed"
349 # create parent directory
350 mkdir $td || error "mkdir $td failed"
351 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
352 error "$LFS setstripe $td failed"
354 # create a mirrored file with plain layout mirrors
355 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
356 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
357 error "create mirrored file $tf failed"
358 verify_mirror_count $tf 6
359 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
360 for ((i = 0; i < 6; i++)); do
361 verify_comp_extent $tf ${ids[$i]} 0 EOF
364 # verify component ${ids[0]}
365 verify_comp_attrs $tf ${ids[0]}
367 # verify component ${ids[1]}
368 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
369 verify_comp_attr stripe-count $tf ${ids[1]} 2
370 verify_comp_attr stripe-index $tf ${ids[1]} 2
371 verify_comp_attr pool $tf ${ids[1]} flash
373 # verify component ${ids[2]}
374 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
375 verify_comp_attr stripe-count $tf ${ids[2]} 2
376 verify_comp_attr pool $tf ${ids[2]} flash
378 # verify component ${ids[3]}
379 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
380 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
381 verify_comp_attr pool $tf ${ids[3]} flash
383 # verify component ${ids[4]}
384 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
385 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
386 verify_comp_attr pool $tf ${ids[4]} archive
388 # verify component ${ids[5]}
389 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
390 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
391 verify_comp_attr_with_parent pool $tf ${ids[5]}
393 if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then
394 # LU-11022 - remove mirror by pool name
395 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
396 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
397 $LFS mirror delete --pool archive $tf || error "delete mirror"
398 cnt=$($LFS getstripe $tf | grep archive | wc -l)
399 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
405 run_test 0b "lfs mirror create plain layout mirrors"
408 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
412 local mirror_cmd="$LFS mirror create"
416 # create a new OST pool
417 local pool_name=$TESTNAME
418 create_pool $FSNAME.$pool_name ||
419 error "create OST pool $pool_name failed"
421 # add OSTs into the pool
422 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
423 error "add OSTs into pool $pool_name failed"
425 # create parent directory
426 mkdir $td || error "mkdir $td failed"
427 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
428 error "$LFS setstripe $td failed"
430 # create a mirrored file with composite layout mirrors
431 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
433 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
434 error "create mirrored file $tf failed"
435 verify_mirror_count $tf 6
436 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
438 # verify components ${ids[0]} and ${ids[2]}
440 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
441 verify_comp_attr stripe-count $tf ${ids[$i]} 2
442 verify_comp_attr stripe-index $tf ${ids[$i]} 1
443 verify_comp_attr pool $tf ${ids[$i]} flash
444 verify_comp_extent $tf ${ids[$i]} 0 4194304
447 # verify components ${ids[1]} and ${ids[3]}
449 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
450 verify_comp_attr stripe-count $tf ${ids[$i]} 2
451 verify_comp_attr pool $tf ${ids[$i]} flash
452 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
455 # verify component ${ids[4]}
456 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
457 verify_comp_attr stripe-count $tf ${ids[4]} 4
458 verify_comp_attr_with_parent pool $tf ${ids[4]}
459 verify_comp_extent $tf ${ids[4]} 0 EOF
461 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
463 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
464 verify_comp_attr stripe-count $tf ${ids[$i]} 4
465 verify_comp_attr pool $tf ${ids[$i]} archive
466 verify_comp_extent $tf ${ids[$i]} 0 536870912
469 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
471 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
472 verify_comp_attr stripe-count $tf ${ids[$i]} -1
473 verify_comp_attr pool $tf ${ids[$i]} archive
474 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
480 run_test 0c "lfs mirror create composite layout mirrors"
485 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
486 local mirror_cmd="$LFS mirror extend"
490 # create parent directory
491 mkdir $td || error "mkdir $td failed"
493 $mirror_cmd $tf &> /dev/null && error "miss -N option"
494 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
496 # create a non-mirrored file, convert it to a mirrored file and extend
497 touch $tf || error "touch $tf failed"
498 $mirror_cmd -N $tf || error "convert and extend $tf failed"
499 verify_mirror_count $tf 2
500 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
501 for ((i = 0; i < 2; i++)); do
502 verify_comp_attrs $tf ${ids[$i]}
503 verify_comp_extent $tf ${ids[$i]} 0 EOF
506 lfsck_verify_pfid $tf || error "PFID is not set"
508 # create a mirrored file and extend it
509 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
510 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
512 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
513 error "setstripe options should not be specified with -f option"
515 $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
516 error "extend mirrored file $tf-1 failed"
517 verify_mirror_count $tf-1 $mirror_count
518 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
519 for ((i = 0; i < $mirror_count; i++)); do
520 verify_comp_attrs $tf-1 ${ids[$i]}
521 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
524 $mirror_cmd -N $tf-1 &> /dev/null &&
525 error "exceeded maximum mirror count $mirror_count" || true
527 run_test 0d "lfs mirror extend with -N option"
530 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
534 local mirror_cmd="$LFS mirror extend"
538 # create parent directory
539 mkdir $td || error "mkdir $td failed"
541 # create a mirrored file with plain layout mirrors
542 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
543 error "create mirrored file $tf failed"
545 # extend the mirrored file with plain layout mirrors
546 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
547 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
548 error "extend mirrored file $tf failed"
549 verify_mirror_count $tf 6
550 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
551 for ((i = 0; i < 6; i++)); do
552 verify_comp_extent $tf ${ids[$i]} 0 EOF
555 # verify component ${ids[0]}
556 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
557 verify_comp_attr stripe-count $tf ${ids[0]} 3
558 verify_comp_attr stripe-index $tf ${ids[0]} 1
559 verify_comp_attr pool $tf ${ids[0]} ssd
561 # verify component ${ids[1]}
562 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
563 verify_comp_attr stripe-count $tf ${ids[1]} 2
564 verify_comp_attr stripe-index $tf ${ids[1]} 2
565 verify_comp_attr pool $tf ${ids[1]} flash
567 # verify component ${ids[2]}
568 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
569 verify_comp_attr stripe-count $tf ${ids[2]} 2
570 verify_comp_attr pool $tf ${ids[2]} flash
572 # verify component ${ids[3]}
573 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
574 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
575 verify_comp_attr pool $tf ${ids[3]} flash
577 # verify component ${ids[4]}
578 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
579 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
580 verify_comp_attr pool $tf ${ids[4]} archive
582 # verify component ${ids[5]}
583 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
584 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
585 verify_comp_attr_with_parent pool $tf ${ids[5]}
587 run_test 0e "lfs mirror extend plain layout mirrors"
590 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
594 local mirror_cmd="$LFS mirror extend"
598 # create parent directory
599 mkdir $td || error "mkdir $td failed"
601 # create a mirrored file with composite layout mirror
602 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
603 error "create mirrored file $tf failed"
605 # extend the mirrored file with composite layout mirrors
606 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
608 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
609 error "extend mirrored file $tf failed"
610 verify_mirror_count $tf 7
611 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
613 # verify component ${ids[0]}
614 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
615 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
616 verify_comp_attr pool $tf ${ids[0]} ssd
617 verify_comp_extent $tf ${ids[0]} 0 33554432
619 # verify component ${ids[1]}
620 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
621 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
622 verify_comp_attr pool $tf ${ids[1]} ssd
623 verify_comp_extent $tf ${ids[1]} 33554432 EOF
625 # verify components ${ids[2]} and ${ids[4]}
627 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
628 verify_comp_attr stripe-count $tf ${ids[$i]} 2
629 verify_comp_attr stripe-index $tf ${ids[$i]} 1
630 verify_comp_attr pool $tf ${ids[$i]} flash
631 verify_comp_extent $tf ${ids[$i]} 0 4194304
634 # verify components ${ids[3]} and ${ids[5]}
636 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
637 verify_comp_attr stripe-count $tf ${ids[$i]} 2
638 verify_comp_attr pool $tf ${ids[$i]} flash
639 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
642 # verify component ${ids[6]}
643 verify_comp_attr stripe-size $tf ${ids[6]} 4194304
644 verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
645 verify_comp_attr_with_parent pool $tf ${ids[6]}
646 verify_comp_extent $tf ${ids[6]} 0 EOF
648 # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
650 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
651 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
652 verify_comp_attr pool $tf ${ids[$i]} archive
653 verify_comp_extent $tf ${ids[$i]} 0 536870912
656 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
658 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
659 verify_comp_attr stripe-count $tf ${ids[$i]} -1
660 verify_comp_attr pool $tf ${ids[$i]} archive
661 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
664 run_test 0f "lfs mirror extend composite layout mirrors"
669 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
670 -N -o1 $tf || error "create mirrored file $tf failed"
672 verify_comp_attr lcme_flags $tf 0x10001 prefer
673 verify_comp_attr lcme_flags $tf 0x10002 prefer
675 # write to the mirrored file and check primary
676 cp /etc/hosts $tf || error "error writing file '$tf'"
678 verify_comp_attr lcme_flags $tf 0x20003 stale
680 # resync file and check prefer flag
681 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
684 $LCTL set_param osc.*.stats=clear
685 cat $tf &> /dev/null || error "error reading file '$tf'"
687 # verify that the data was provided by OST1 where mirror 1 resides
688 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
689 awk '/ost_read/{print $2}')
690 [ -n "$nr_read" ] || error "read was not provided by OST1"
692 run_test 0g "lfs mirror create flags support"
695 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
696 skip "Need MDS version at least 2.11.57"
703 # create parent directory
704 test_mkdir $td || error "mkdir $td failed"
706 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
707 error "set default mirrored layout on directory $td failed"
709 # verify flags are inherited from the directory
712 verify_comp_attr lcme_flags $tf 0x10001 prefer
713 verify_comp_attr lcme_flags $tf 0x10002 prefer
715 # set flags to the first component
716 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
718 verify_comp_attr lcme_flags $tf 0x10001 stale
719 verify_comp_attr lcme_flags $tf 0x10002 prefer
721 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
722 error "clearing 'stale' should fail"
724 # write and resync file. It can't resync the file directly because the
725 # file state is still 'ro'
726 cp /etc/hosts $tf || error "error writing file '$tf'"
727 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
729 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
730 error "error setting flag prefer"
732 verify_comp_attr lcme_flags $tf 0x20003 prefer
734 $LFS setstripe --comp-set -I 0x20003 --comp-flags=^prefer $tf ||
735 error "error clearing prefer flag from component 0x20003"
737 # MDS disallows setting stale flag on the last non-stale mirror
738 [[ "$MDS1_VERSION" -ge $(version_code 2.12.57) ]] || return 0
740 cp /etc/hosts $tf || error "error writing file '$tf'"
742 verify_comp_attr lcme_flags $tf 0x10002 prefer
743 verify_comp_attr lcme_flags $tf 0x20003 stale
744 verify_comp_attr lcme_flags $tf 0x30004 stale
746 ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
748 error "setting stale flag on component 0x10002 should fail"
750 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
752 $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
753 error "error setting stale flag on component 0x10001"
754 $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
755 error "error setting stale flag on component 0x20003"
757 ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
759 error "setting stale flag on component 0x30004 should fail"
761 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
763 run_test 0h "set, clear and test flags for FLR files"
767 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
768 local mirror_create_cmd="$LFS mirror create"
769 local stripes[0]=$OSTCOUNT
771 mirror_create_cmd+=" -N -c ${stripes[0]}"
772 for ((i = 1; i < $mirror_count; i++)); do
773 # add mirrors with different stripes to the file
774 stripes[$i]=$((RANDOM % OSTCOUNT))
775 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
777 mirror_create_cmd+=" -N -c ${stripes[$i]}"
780 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
781 verify_mirror_count $tf $mirror_count
783 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
784 $LFS mirror extend -N $tf &&
785 error "Creating the $((mirror_count+1))th mirror succeeded"
787 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
790 # verify the range of components and stripe counts
791 for ((i = 0; i < $mirror_count; i++)); do
792 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
793 verify_comp_extent $tf ${ids[$i]} 0 EOF
796 run_test 1 "create components with setstripe options"
800 local tf2=$DIR/$tfile-2
802 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
803 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
805 $LFS mirror extend -N -f $tf2 $tf ||
806 error "merging $tf2 into $tf failed"
808 verify_mirror_count $tf 2
809 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
811 run_test 2 "create components from existing files"
814 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
816 for ((i = 0; i < 2; i++)); do
817 $LFS mkdir -i $i $DIR/$tdir-$i
818 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
821 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
822 $DIR/$tdir-0/$tfile || error "creating mirrors"
824 # mdt doesn't support to cancel layout lock for remote objects, do
828 # make sure the mirrorted file was created successfully
829 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
830 { $LFS getstripe $DIR/$tdir-0/$tfile;
831 error "expected 2 components"; }
836 run_test 3 "create components from files located on different MDTs"
839 local tf=$DIR/$tdir/$tfile
842 test_mkdir $DIR/$tdir
844 # set mirror with setstripe options to directory
845 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
846 error "set mirror to directory error"
848 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
849 x"mirrored" ] || error "failed to create mirrored dir"
852 verify_mirror_count $tf 2
854 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
855 verify_comp_extent $tf ${ids[0]} 0 1048576
856 verify_comp_extent $tf ${ids[1]} 1048576 EOF
858 # sub directory should inherit mirror setting from parent
859 test_mkdir $DIR/$tdir/td
860 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
861 x"mirrored" ] || error "failed to inherit mirror from parent"
863 # mirror extend won't be applied to directory
864 $LFS mirror extend -N2 $DIR/$tdir &&
865 error "expecting mirror extend failure"
868 run_test 4 "Make sure mirror attributes can be inhertied from directory"
874 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
875 error "failed to create file with non-empty layout"
876 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
878 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
879 verify_mirror_count $tf 3
881 $CHECKSTAT -t file -s 12345 $tf ||
882 error "size error after attaching layout "
884 run_test 5 "Make sure init size work for mirrored layout"
886 # LU=10112: disable dom+flr for phase 1
890 $LFS mirror create -N -E 1M -S 1M -L mdt -E eof -N -E eof $tf &&
891 error "expect failure to create mirrored file with DoM"
893 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf &&
894 error "expect failure to create mirrored file with DoM"
896 $LFS setstripe -E 1M -S 1M -L mdt -E eof $tf
897 $LFS mirror extend -N2 $tf &&
898 error "expect failure to extend mirror with DoM"
900 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2
901 $LFS mirror extend -N -f $tf $tf-2 &&
902 error "expect failure to extend mirrored file with DoM extent"
906 run_test 6 "DoM and FLR won't co-exist for phase 1"
910 local tf2=$DIR/$tfile-2
912 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
914 $LFS setstripe -E EOF -o 0 $tf
915 $LFS setstripe -E EOF -o 1 $tf2
917 local dd_count=$((RANDOM % 20 + 1))
918 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
919 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
921 # for zfs - sync OST dataset so that du below will return
923 [ "$FSTYPE" = "zfs" ] &&
924 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
926 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
929 $LFS mirror extend -N -f $tf2 $tf ||
930 error "merging $tf2 into $tf failed"
935 local new_blocks=$(du -k $tf | awk '{print $1}')
936 [ $new_blocks -eq $blocks ] ||
937 error "i_blocks error expected: $blocks, actual: $new_blocks"
939 run_test 21 "glimpse should report accurate i_blocks"
941 get_osc_lock_count() {
948 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
949 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
950 lock_count=$((lock_count + count))
958 $LFS setstripe -E EOF -o 0 $tf
959 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
961 # add component, two mirrors located on the same OST ;-)
962 $LFS mirror extend -N -o 0 $tf ||
963 error "extending mirrored file $tf failed"
965 size_blocks=$(stat --format="%b %s" $tf)
970 local new_size_blocks=$(stat --format="%b %s" $tf)
972 # make sure there is no lock cached
973 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
975 [ "$new_size_blocks" = "$size_blocks" ] ||
976 echo "size expected: $size_blocks, actual: $new_size_blocks"
980 run_test 22 "no glimpse to OSTs for READ_ONLY files"
985 $LFS mirror create -N -o 0 -N -o 1 $tf ||
986 error "creating mirrored file $tf failed"
988 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
989 $LCTL set_param fail_loc=0x1A00
992 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
996 local tmpfile=$(mktemp)
997 stat --format="%b %s" $tf > $tmpfile &
1001 while [ $cnt -le 5 ]; do
1002 kill -0 $pid > /dev/null 2>&1 || break
1006 kill -0 $pid > /dev/null 2>&1 &&
1007 error "stat process stuck due to unavailable OSTs"
1009 # make sure glimpse request has been sent
1010 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1011 error "OST $ost_idx: no glimpse request was sent"
1016 run_test 31 "make sure glimpse request can be retried"
1019 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1020 rm -f $DIR/$tfile $DIR/$tfile-2
1022 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1023 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1025 local fsize=$(stat -c %s $DIR/$tfile)
1026 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1028 local cksum=$(md5sum $DIR/$tfile)
1030 # create a new mirror in sync mode
1031 $LFS mirror extend -N -o 1 $DIR/$tfile ||
1032 error "extending mirrored file $DIR/$tfile failed"
1034 # make sure the mirrored file was created successfully
1035 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1036 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1041 # check size is correct, glimpse request should go to the 2nd mirror
1042 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1043 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1045 echo "reading file from the 2nd mirror and verify checksum"
1046 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1047 error "checksum error: expected $cksum"
1051 run_test 32 "data should be mirrored to newly created mirror"
1054 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1056 rm -f $DIR/$tfile $DIR/$tfile-2
1058 # create a file with two mirrors
1059 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1062 while [ $count -lt $max_count ]; do
1063 echo "ost1" >> $DIR/$tfile
1064 count=$((count + 1));
1067 # tmp file that will be used as mirror
1068 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1070 while [ $count -lt $max_count ]; do
1071 echo "ost2" >> $DIR/$tfile-2
1072 count=$((count + 1));
1075 # create a mirrored file
1076 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1077 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1078 "with verification should fail"
1079 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1080 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1081 "without verification failed"
1083 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1084 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1085 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1087 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1089 # execpted file size
1090 local fsize=$((5 * max_count))
1091 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1092 error "mirrored file size is not $fsize"
1094 # read file - all OSTs are available
1095 echo "reading file (data can be provided by any ost)... "
1096 local rs=$(cat $DIR/$tfile | head -1)
1097 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1098 error "file content error: expected: \"ost1\" or \"ost2\""
1100 # read file again with ost1 failed
1104 echo "reading file (data should be provided by ost2)..."
1105 local rs=$(cat $DIR/$tfile | head -1)
1106 [[ "$rs" == "ost2" ]] ||
1107 error "file content error: expected: \"ost2\", actual: \"$rs\""
1112 # read file again with ost2 failed
1116 # check size, glimpse should work
1117 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1118 error "mirrored file size is not $fsize"
1120 echo "reading file (data should be provided by ost1)..."
1121 local rs=$(cat $DIR/$tfile | head -1)
1122 [[ "$rs" == "ost1" ]] ||
1123 error "file content error: expected: \"ost1\", actual: \"$rs\""
1127 run_test 33a "read can choose available mirror to read"
1130 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1134 stack_trap "rm -f $DIR/$tfile" EXIT
1136 # create a file with two mirrors on OST0000 and OST0001
1137 $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
1139 # make sure that $tfile has two mirrors
1140 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1141 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1144 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1145 error "write failed for $DIR/$tfile"
1146 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1147 verify_flr_state $DIR/$tfile "ro"
1152 # read file - all OSTs are available
1153 echo "reading file (data can be provided by any ost)... "
1155 time cat $DIR/$tfile > /dev/null || error "read all"
1159 # read file again with ost1 {OST0000} failed
1162 echo "reading file (data should be provided by ost2)..."
1164 time cat $DIR/$tfile > /dev/null || error "read ost2"
1171 # read file again with ost2 {OST0001} failed
1175 echo "reading file (data should be provided by ost1)..."
1177 time cat $DIR/$tfile > /dev/null || error "read ost1"
1184 [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
1185 error "read mirror too slow without ost1, from $ra to $r1"
1186 [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
1187 error "read mirror too slow without ost2, from $ra to $r2"
1189 wait_osc_import_ready client ost2
1191 run_test 33b "avoid reading from unhealthy mirror"
1194 [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
1198 stack_trap "rm -f $DIR/$tfile" EXIT
1200 # create a file with two mirrors
1201 # mirror1: {OST0000, OST0001}
1202 # mirror2: {OST0001, OST0002}
1203 $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
1205 # make sure that $tfile has two mirrors
1206 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1207 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1210 dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
1211 error "write failed for $DIR/$tfile"
1212 $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
1213 verify_flr_state $DIR/$tfile "ro"
1218 # read file - all OSTs are available
1219 echo "reading file (data can be provided by any ost)... "
1220 time cat $DIR/$tfile > /dev/null || error "read all"
1222 # read file again with ost2 (OST0001) failed
1226 echo "reading file (data should be provided by ost1 and ost3)..."
1227 time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
1232 wait_osc_import_ready client ost2
1234 run_test 33c "keep reading among unhealthy mirrors"
1237 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1239 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1242 $LFS setstripe -o 0 $DIR/$tfile-ref
1243 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1245 # create a file with two mirrors
1246 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1247 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1249 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1250 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1252 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1253 error "mirrored file size is not 3M"
1255 # merge a mirrored file
1256 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1257 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1259 cancel_lru_locks osc
1261 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1262 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1265 echo "comparing files ... "
1267 # however, read can still return the correct data. It should return
1268 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1269 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1270 $DIR/$tfile-ref || error "file reading error"
1274 run_test 34a "read mirrored file with multiple stripes"
1277 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1279 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1282 $LFS setstripe -o 0 $DIR/$tfile-ref
1283 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1285 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1286 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1288 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1289 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1291 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1292 error "mirrored file size is not 3M"
1294 # merge a mirrored file
1295 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1296 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1298 cancel_lru_locks osc
1300 # stop two OSTs, so the 2nd component of the 1st mirror and
1301 # the 1st component of the 2nd mirror will be inaccessible, ...
1304 echo "comparing files ... "
1306 # however, read can still return the correct data. It should return
1307 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1308 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1309 $DIR/$tfile-ref || error "file reading error"
1313 run_test 34b "read mirrored file with multiple components"
1316 local tf=$DIR/$tfile
1318 $LFS setstripe -E eof $tf
1320 # add an out-of-sync mirror to the file
1321 $LFS mirror extend -N -c 2 $tf ||
1322 error "extending mirrored file $tf failed"
1324 $MULTIOP $tf oO_WRONLY:c ||
1325 error "write open a mirrored file failed"
1327 # truncate file should return error
1328 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1330 run_test 35 "allow to write to mirrored files"
1332 verify_ost_layout_version() {
1335 # get file layout version
1336 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1338 # layout version from OST objects
1339 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1341 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1348 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1349 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1351 $LFS mirror extend -N -f $tf-tmp $tf ||
1352 error "merging $tf-tmp into $tf failed"
1357 local tf=$DIR/$tfile
1359 create_file_36 $tf $tf-2 $tf-3
1361 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1363 # test case 1 - check file write and verify layout version
1364 $MULTIOP $tf oO_WRONLY:c ||
1365 error "write open a mirrored file failed"
1367 # write open file should not return error
1368 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1370 # instantiate components should work
1371 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1373 # verify OST layout version
1374 verify_ost_layout_version $tf
1377 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1380 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1382 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1383 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1385 # write should take at least $fail_loc seconds and succeed
1386 local st=$(date +%s)
1387 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1389 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1390 error "write finished before layout version is transmitted"
1392 # verify OST layout version
1393 verify_ost_layout_version $tf
1395 do_facet $mds_facet $LCTL set_param fail_loc=0
1398 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1400 #define OBD_FAIL_FLR_LV_INC 0x1A02
1401 do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1403 # write open file should return error
1404 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1405 error "write a mirrored file succeeded" || true
1407 do_facet $mds_facet $LCTL set_param fail_loc=0
1409 run_test 36 "write to mirrored files"
1415 echo "create test files with size $fsize .."
1419 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1421 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1422 $TRUNCATE $tf $fsize
1428 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1429 skip "Need MDS version at least 2.11.57"
1431 local tf=$DIR/$tfile
1432 local tf2=$DIR/$tfile-2
1433 local tf3=$DIR/$tfile-3
1434 local tf4=$DIR/$tfile-4
1436 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1440 # assume the mirror id will be 1, 2, and 3
1441 declare -A checksums
1442 checksums[1]=$(cat $tf | md5sum)
1443 checksums[2]=$(cat $tf2 | md5sum)
1444 checksums[3]=$(cat $tf3 | md5sum)
1446 printf '%s\n' "${checksums[@]}"
1448 # merge these files into a mirrored file
1449 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1450 error "merging $tf2 into $tf failed"
1451 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1452 error "merging $tf3 into $tf failed"
1456 # verify mirror read, checksums should equal to the original files'
1457 echo "Verifying mirror read .."
1460 for i in ${mirror_array[@]}; do
1461 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1462 sum=$($LFS mirror read -N $i $tf | md5sum)
1463 [ "$sum" = "${checksums[$i]}" ] ||
1464 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1467 # verify mirror write
1468 echo "Verifying mirror write .."
1469 $LFS mirror write -N2 $tf < $tf4
1471 sum=$($LFS mirror read -N2 $tf | md5sum)
1472 [[ "$sum" = "${checksums[1]}" ]] ||
1473 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1475 # verify mirror copy, write to this mirrored file will invalidate
1476 # the other two mirrors
1477 echo "Verifying mirror copy .."
1479 local osts=$(comma_list $(osts_nodes))
1481 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1482 error "mirror copy error"
1484 # verify copying is successful by checking checksums
1485 remount_client $MOUNT
1486 for i in ${mirror_array[@]}; do
1487 sum=$($LFS mirror read -N $i $tf | md5sum)
1488 [ "$sum" = "${checksums[1]}" ] ||
1489 error "$i: mismatch checksum after copy \'$sum\'"
1494 run_test 37 "mirror I/O API verification"
1497 local tf=$DIR/$tfile
1498 local ref=$DIR/${tfile}-ref
1500 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1501 error "creating $tf failed"
1502 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1503 $tf-2 || error "creating $tf-2 failed"
1504 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1505 error "creating $tf-3 failed"
1507 # instantiate all components
1508 $LFS mirror extend -N -f $tf-2 $tf ||
1509 error "merging $tf-2 into $tf failed"
1510 $LFS mirror extend -N -f $tf-3 $tf ||
1511 error "merging $tf-3 into $tf failed"
1512 $LFS mirror extend -N -c 1 $tf ||
1513 error "extending mirrored file $tf failed"
1515 verify_flr_state $tf "ro"
1517 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1519 local fsize=$((RANDOM << 8 + 1048576))
1520 $TRUNCATE $ref $fsize
1522 local ref_cksum=$(cat $ref | md5sum)
1524 # case 1: verify write to mirrored file & resync work
1525 cp $ref $tf || error "copy from $ref to $f error"
1526 verify_flr_state $tf "wp"
1528 local file_cksum=$(cat $tf | md5sum)
1529 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1532 echo "mirror IDs: ${mirror_array[@]}"
1534 local valid_mirror stale_mirror id mirror_cksum
1535 for id in "${mirror_array[@]}"; do
1536 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1537 [ "$ref_cksum" == "$mirror_cksum" ] &&
1538 { valid_mirror=$id; continue; }
1543 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1544 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1546 mirror_io resync $tf || error "resync failed"
1547 verify_flr_state $tf "ro"
1549 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1550 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1552 # case 2: inject an error to make mirror_io exit after changing
1553 # the file state to sync_pending so that we can start a concurrent
1555 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1556 verify_flr_state $tf "wp"
1558 mirror_io resync -e resync_start $tf && error "resync succeeded"
1559 verify_flr_state $tf "sp"
1561 # from sync_pending to write_pending
1562 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1563 verify_flr_state $tf "wp"
1565 mirror_io resync -e resync_start $tf && error "resync succeeded"
1566 verify_flr_state $tf "sp"
1568 # from sync_pending to read_only
1569 mirror_io resync $tf || error "resync failed"
1570 verify_flr_state $tf "ro"
1572 run_test 38 "resync"
1575 local tf=$DIR/$tfile
1578 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1579 error "create PFL file $tf failed"
1581 verify_mirror_count $tf 2
1582 verify_comp_count $tf 4
1584 rm -f $tf || error "delete $tf failed"
1586 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1589 local tf=$DIR/$tfile
1592 for ops in "conv=notrunc" ""; do
1595 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1596 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1597 error "create PFLR file $tf failed"
1598 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1599 error "write PFLR file $tf failed"
1601 lfs getstripe -vy $tf
1605 # file mirror state should be write_pending
1606 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1608 error "file mirror state $flags"
1609 # the 1st component (in mirror 1) should be inited
1610 verify_comp_attr lcme_flags $tf 0x10001 init
1611 # the 2nd component (in mirror 1) should be inited
1612 verify_comp_attr lcme_flags $tf 0x10002 init
1613 # the 3rd component (in mirror 1) should be uninited
1614 verify_comp_attr lcme_flags $tf 0x10003 prefer
1615 # the 4th component (in mirror 2) should be inited
1616 verify_comp_attr lcme_flags $tf 0x20004 init
1617 # the 5th component (in mirror 2) should be uninited
1618 verify_comp_attr lcme_flags $tf 0x20005 0
1619 # the 6th component (in mirror 2) should be stale
1620 verify_comp_attr lcme_flags $tf 0x20006 stale
1621 # the 7th component (in mirror 2) should be uninited
1622 if [[ x$ops = "xconv=notrunc" ]]; then
1623 verify_comp_attr lcme_flags $tf 0x20007 0
1624 elif [[ x$ops = "x" ]]; then
1625 verify_comp_attr lcme_flags $tf 0x20007 stale
1629 rm -f $tf || error "delete $tf failed"
1631 run_test 40 "PFLR rdonly state instantiation check"
1634 local tf=$DIR/$tfile
1637 echo " **create two FLR files $tf $tf-1"
1638 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1639 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1640 error "create PFLR file $tf failed"
1641 $LFS mirror create -N -E 2M -S 1M -E eof \
1642 -N -E 1M -E eof --flags prefer \
1643 -N -E 4m -E eof $tf-1 ||
1644 error "create PFLR file $tf-1 failed"
1646 # file should be in ro status
1647 echo " **verify files be RDONLY"
1648 verify_flr_state $tf "ro"
1649 verify_flr_state $tf-1 "ro"
1651 # write data in [0, 2M)
1652 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1653 error "writing $tf failed"
1654 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1655 error "writing $tf-1 failed"
1657 local sum0=$(cat $tf-1 | md5sum)
1659 echo " **verify files be WRITE_PENDING"
1660 verify_flr_state $tf "wp"
1661 verify_flr_state $tf-1 "wp"
1663 # file should have stale component
1664 echo " **verify files have stale component"
1665 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1666 error "after writing $tf, it does not contain stale component"
1667 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1668 error "after writing $tf-1, it does not contain stale component"
1670 echo " **full resync"
1671 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1673 echo " **verify $tf-1 data consistency in all mirrors"
1675 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1676 [[ "$sum" = "$sum0" ]] ||
1677 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1680 echo " **verify files be RDONLY"
1681 verify_flr_state $tf "ro"
1682 verify_flr_state $tf-1 "ro"
1684 # file should not have stale component
1685 echo " **verify files do not contain stale component"
1686 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1687 error "after resyncing $tf, it contains stale component"
1688 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1689 error "after resyncing $tf, it contains stale component"
1691 # verify partial resync
1692 echo " **write $tf-1 for partial resync test"
1693 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1694 error "writing $tf-1 failed"
1696 echo " **only resync mirror 2"
1697 verify_flr_state $tf-1 "wp"
1698 $LFS mirror resync --only 2 $tf-1 ||
1699 error "resync mirror 2 of $tf-1 failed"
1700 verify_flr_state $tf "ro"
1702 # resync synced mirror
1703 echo " **resync mirror 2 again"
1704 $LFS mirror resync --only 2 $tf-1 ||
1705 error "resync mirror 2 of $tf-1 failed"
1706 verify_flr_state $tf "ro"
1707 echo " **verify $tf-1 contains stale component"
1708 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1709 error "after writing $tf-1, it does not contain stale component"
1711 echo " **full resync $tf-1"
1712 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1713 verify_flr_state $tf "ro"
1714 echo " **full resync $tf-1 again"
1715 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1716 echo " **verify $tf-1 does not contain stale component"
1717 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1718 error "after resyncing $tf, it contains stale component"
1722 run_test 41 "lfs mirror resync check"
1725 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1729 local mirror_cmd="$LFS mirror verify"
1732 # create parent directory
1733 mkdir $td || error "mkdir $td failed"
1735 $mirror_cmd &> /dev/null && error "no file name given"
1736 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1737 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1739 # create mirrored files
1740 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1741 error "create mirrored file $tf failed"
1742 $LFS mirror create -N -E 2M -S 1M -E EOF \
1743 -N -E 6M -E 8M -E EOF \
1744 -N -E 16M -E EOF $tf-1 ||
1745 error "create mirrored file $tf-1 failed"
1746 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1747 error "create mirrored file $tf-2 failed"
1749 # write data in [0, 10M)
1750 for i in $tf $tf-1 $tf-2; do
1751 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1752 error "write $i failed"
1755 # resync the mirrored files
1756 $LFS mirror resync $tf-1 $tf-2 ||
1757 error "resync $tf-1 $tf-2 failed"
1759 # verify the mirrored files
1760 $mirror_cmd $tf-1 $tf-2 ||
1761 error "verify $tf-1 $tf-2 failed"
1763 get_mirror_ids $tf-1
1764 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1765 error "at least 2 mirror ids needed with '--only' option"
1766 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1768 error "'--only' option cannot be used upon multiple files"
1769 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1770 error "invalid specified mirror ids"
1772 # change the content of $tf and merge it into $tf-1
1774 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1775 error "change $tf with seek=$i failed"
1776 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1777 error "change $tf-1 with seek=$i failed"
1780 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1781 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1782 error "merge $tf into $tf-1 failed"
1784 # verify the mirrored files
1785 echo "Verify $tf-1 without -v option:"
1786 $mirror_cmd $tf-1 &&
1787 error "verify $tf-1 should fail" || echo "PASS"
1789 echo "Verify $tf-1 with -v option:"
1790 $mirror_cmd -v $tf-1 &&
1791 error "verify $tf-1 should fail"
1793 get_mirror_ids $tf-1
1794 echo "Verify $tf-1 with --only option:"
1795 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1796 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1797 "${mirror_array[-1]} should fail"
1799 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1800 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1801 "${mirror_array[1]} should succeed"
1803 # set stale components in $tf-1
1804 for i in 0x40002 0x40003; do
1805 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1806 error "set stale flag on component $i failed"
1809 # verify the mirrored file
1810 echo "Verify $tf-1 with stale components:"
1811 $mirror_cmd -vvv $tf-1 ||
1812 error "verify $tf-1 with stale components should succeed"
1814 echo "Verify $tf-1 with stale components and --only option:"
1815 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1816 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1817 "${mirror_array[-1]} should succeed"
1819 run_test 42 "lfs mirror verify"
1821 # inactivate one OST && write && restore the OST
1825 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1828 wait=$(do_facet $SINGLEMDS \
1829 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1830 wait=${wait%%[^0-9]*}
1832 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1833 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1834 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1835 sleep $(($wait * 2 + 2))
1836 echo " **write $file"
1837 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1838 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1839 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1840 sleep $((wait * 2 + 2))
1842 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1843 [ $flags = wp ] || error "file mirror state $flags != wp"
1847 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1849 local tf=$DIR/$tfile
1853 ## mirror 0 ost (0, 1)
1854 ## mirror 1 ost (1, 2)
1855 ## mirror 2 ost (2, 0)
1856 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1857 -N -Eeof -c2 -o2,0 $tf ||
1858 error "create 3 mirrors file $tf failed"
1860 ################## OST0 ###########################################
1862 echo " **verify components"
1863 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1864 verify_comp_attr lcme_flags $tf 0x20002 init
1865 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1868 echo " **resync $tf"
1869 $LFS mirror resync $tf
1870 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1871 [ $flags = ro ] || error "file mirror state $flags != ro"
1873 ################## OST1 ###########################################
1875 echo " **verify components"
1876 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1877 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1878 verify_comp_attr lcme_flags $tf 0x30003 init
1881 echo " **resync $tf"
1882 $LFS mirror resync $tf
1883 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1884 [ $flags = ro ] || error "file mirror state $flags != ro"
1886 ################## OST2 ###########################################
1888 echo " **verify components"
1889 verify_comp_attr lcme_flags $tf 0x10001 init
1890 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1891 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1893 run_test 43 "mirror pick on write"
1896 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1899 local tf=$DIR/$tdir/$tfile
1900 local tf1=$DIR/$tdir-1/$tfile-1
1902 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1903 error "create directory failed"
1904 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1905 error "create remote directory failed"
1906 rm -f $tf $tf1 $tf.mirror~2
1907 # create file with 4 mirrors
1908 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1909 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
1910 error "create PFLR file $tf failed"
1912 # file should be in ro status
1913 verify_flr_state $tf "ro"
1915 # write data in [0, 3M)
1916 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1917 error "writing $tf failed"
1919 verify_flr_state $tf "wp"
1921 # disallow destroying the last non-stale mirror
1922 ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
1923 error "destroying mirror 1 should fail"
1925 # synchronize all mirrors of the file
1926 $LFS mirror resync $tf || error "mirror resync $tf failed"
1928 verify_flr_state $tf "ro"
1931 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1932 error "split to $tf1 failed"
1934 local idx0=$($LFS getstripe -m $tf)
1935 local idx1=$($LFS getstripe -m $tf1)
1937 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1938 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1940 # verify mirror count
1941 verify_mirror_count $tf 3
1942 verify_mirror_count $tf1 1
1944 $LFS mirror split --mirror-id 2 $tf ||
1945 error "split mirror 2 failed"
1947 verify_mirror_count $tf 2
1948 verify_mirror_count $tf.mirror~2 1
1950 $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
1951 error "setting stale flag on component 0x30008 failed"
1953 # disallow destroying the last non-stale mirror
1954 ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
1955 error "destroying mirror 4 should fail"
1957 $LFS mirror resync $tf || error "resynchronizing $tf failed"
1959 $LFS mirror split --mirror-id 3 -d $tf ||
1960 error "destroying mirror 3 failed"
1961 verify_mirror_count $tf 1
1963 # verify splitted file contains the same content as the orig file does
1964 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
1965 diff $tf $tf.mirror~2 ||
1966 error "splited file $tf.mirror~2 diffs from $tf"
1968 run_test 44 "lfs mirror split check"
1971 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1973 local file=$DIR/$tdir/$tfile
1974 local dir=$DIR/$tdir/$dir
1975 local temp=$DIR/$tdir/template
1977 test_mkdir $DIR/$tdir
1979 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1980 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
1981 error "Create $file failed"
1983 verify_yaml_layout $file $file.copy $temp "1. FLR file"
1984 rm -f $file $file.copy
1986 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1987 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
1988 error "Create $file failed"
1990 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
1992 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
1999 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
2001 local layout1=$(get_layout_param $src)
2002 local layout2=$(get_layout_param $dst)
2003 # compare their layout info
2004 [ "$layout1" == "$layout2" ] ||
2005 error "$msg_prefix $src <=> $dst layouts are not equal"
2009 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2011 local file=$DIR/$tdir/$tfile
2012 test_mkdir $DIR/$tdir
2014 ########################### 1. PFL file #############################
2015 echo " ** 1. PFL file"
2017 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
2018 $file || error "1. Create PFL $file failed"
2021 verify_46 $file $file.copy "1. PFL file"
2023 ########################### 2. plain file ###########################
2024 echo " ** 2. plain file"
2026 $LFS setstripe -c2 -o0,1 -i1 $file ||
2027 error "2. Create plain $file failed"
2030 verify_46 $file $file.copy "2. plain file"
2032 ########################### 3. FLR file #############################
2033 echo " ** 3. FLR file"
2034 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
2035 $file || error "3. Create FLR $file failed"
2038 verify_46 $file $file.copy "3. FLR file"
2040 local dir=$DIR/$tdir/dir
2041 ########################### 4. PFL dir ##############################
2042 echo " ** 4. PFL dir"
2044 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
2045 error "4. setstripe PFL $dir failed"
2047 test_mkdir $dir.copy
2048 verify_46 $dir $dir.copy "4. PFL dir"
2050 ########################### 5. plain dir ############################
2051 echo " ** 5. plain dir"
2052 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
2054 verify_46 $dir $dir.copy "5. plain dir"
2056 ########################### 6. FLR dir ##############################
2057 echo " ** 6. FLR dir"
2058 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
2059 error "6. setstripe FLR $dir failed"
2061 verify_46 $dir $dir.copy "6. FLR dir"
2063 run_test 46 "Verify setstripe --copy option"
2066 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
2068 local file=$DIR/$tdir/$tfile
2073 test_mkdir $DIR/$tdir
2077 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
2078 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
2079 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
2080 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
2081 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2083 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2084 $LFS mirror resync $file || error "resync $file failed"
2086 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
2087 if [[ x$ost == "x0," ]]; then
2088 $LFS getstripe $file
2089 error "component ${ids[2]} objects allocated on $ost " \
2093 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2094 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2095 $LFS getstripe $file
2096 error "component ${ids[3]} objects allocated on $ost " \
2097 "shouldn't on OST1 or on OST2"
2102 # mirror1: [comp0] [comp1]
2103 # mirror2: [comp2] [comp3]
2104 # mirror3: [comp4] [comp5]
2105 # mirror4: [comp6] [comp7]
2106 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2107 error "create FLR $file failed"
2108 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2110 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2111 $LFS mirror resync $file || error "resync $file failed"
2113 for ((i = 0; i < 6; i++)); do
2114 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2115 awk '/l_ost_idx/{print $5}')
2117 # comp[0],comp[2],comp[4] should use different osts
2118 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2119 ${osts[2]} == ${osts[4]} ]]; then
2120 $LFS getstripe $file
2121 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2122 "allocated on duplicated OSTs"
2124 # comp[1],comp[3],comp[5] should use different osts
2125 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2126 ${osts[3]} == ${osts[5]} ]]; then
2127 $LFS getstripe $file
2128 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2129 "allocated on duplicated OSTs"
2134 run_test 47 "Verify mirror obj alloc"
2137 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2138 skip "Need MDS version at least 2.11.55"
2140 local tf=$DIR/$tfile
2143 echo " ** create 2 mirrors FLR file $tf"
2144 $LFS mirror create -N -E2M -Eeof --flags prefer \
2145 -N -E1M -Eeof $tf ||
2146 error "create FLR file $tf failed"
2149 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2150 verify_flr_state $tf "wp"
2152 local sum0=$(md5sum < $tf)
2154 echo " ** resync the file"
2155 $LFS mirror resync $tf
2157 echo " ** snapshot mirror 2"
2158 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2160 echo " ** write it again"
2161 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2162 echo " ** resync it again"
2163 $LFS mirror resync $tf
2165 verify_flr_state $tf "wp"
2166 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2168 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2169 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2171 echo " ** verify mirror 2 doesn't change"
2172 echo "original checksum: $sum0"
2173 echo "mirror 1 checksum: $sum1"
2174 echo "mirror 2 checksum: $sum2"
2175 [[ $sum0 = $sum2 ]] ||
2176 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2177 echo " ** mirror 2 stripe info"
2178 $LFS getstripe -v --mirror-index=2 $tf
2180 echo " ** resync mirror 2"
2181 $LFS mirror resync --only 2 $tf
2183 verify_flr_state $tf "ro"
2184 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2186 sum1=$($LFS mirror read -N1 $tf | md5sum)
2187 sum2=$($LFS mirror read -N2 $tf | md5sum)
2189 echo " ** verify mirror 2 resync-ed"
2190 echo "original checksum: $sum0"
2191 echo "mirror 1 checksum: $sum1"
2192 echo "mirror 2 checksum: $sum2"
2193 [[ $sum1 = $sum2 ]] ||
2194 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2195 echo " ** mirror 2 stripe info"
2196 $LFS getstripe -v --mirror-index=2 $tf
2198 run_test 48 "Verify snapshot mirror"
2200 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
2201 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
2206 local fsize=$(stat --printf=%s $tf)
2208 while [ -f $ctrl_file ]; do
2209 local off=$((RANDOM << 8))
2210 local len=$((RANDOM << 5 + 131072))
2212 [ $((off + len)) -gt $fsize ] && {
2213 fsize=$((off + len))
2214 echo "Extending file size to $fsize .."
2217 flock -s $lock_file -c \
2218 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
2220 error "failed writing to $off:$len"; }
2221 sleep 0.$((RANDOM % 2 + 1))
2228 while [ -f $ctrl_file ]; do
2229 flock -s $lock_file -c "cat $tf &> /dev/null" ||
2230 { rm -f $ctrl_file; error "read failed"; }
2231 sleep 0.$((RANDOM % 2 + 1))
2238 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
2240 exec 200<>$lock_file
2241 while [ -f $ctrl_file ]; do
2242 local lock_taken=false
2243 local index=$((RANDOM % ${#options[@]}))
2244 local cmd="mirror_io resync ${options[$index]}"
2246 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
2248 [ $((RANDOM % 4)) -eq 0 ] && {
2254 echo -n "resync file $tf with '$cmd' .."
2256 if [[ $lock_taken = "true" ]]; then
2257 flock -x 200 -c "$cmd $tf &> /dev/null" &&
2258 echo "done" || echo "failed"
2261 $cmd $tf &> /dev/null && echo "done" || echo "failed"
2264 sleep 0.$((RANDOM % 8 + 1))
2269 local tf=$DIR/$tfile
2270 local tf2=$DIR2/$tfile
2271 local tf3=$DIR3/$tfile
2273 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
2274 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
2275 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
2277 $LFS mirror extend -N -f $tf-2 $tf ||
2278 error "merging $tf-2 into $tf failed"
2279 $LFS mirror extend -N -f $tf-3 $tf ||
2280 error "merging $tf-3 into $tf failed"
2282 mkdir -p $MOUNT2 && mount_client $MOUNT2
2284 mkdir -p $MOUNT3 && mount_client $MOUNT3
2286 verify_flr_state $tf3 "ro"
2288 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
2289 $LCTL set_param fail_loc=0x1A03
2291 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
2292 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
2296 write_file_200 $tf &
2302 write_file_200 $tf2 &
2305 read_file_200 $tf2 &
2308 resync_file_200 $tf3 &
2312 [ "$SLOW" = "yes" ] && sleep_time=360
2313 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
2320 echo "Waiting ${pids[@]}"
2323 umount_client $MOUNT2
2324 umount_client $MOUNT3
2328 # resync and verify mirrors
2329 mirror_io resync $tf
2332 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
2333 for id in ${mirror_array[@]:1}; do
2334 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
2335 error "checksum error for mirror $id"
2340 run_test 200 "stress test"
2342 cleanup_test_201() {
2344 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
2346 umount_client $MOUNT2
2350 local delay=${RESYNC_DELAY:-5}
2352 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
2353 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
2355 trap cleanup_test_201 EXIT
2357 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
2358 changelog_register -n)
2360 mkdir -p $MOUNT2 && mount_client $MOUNT2
2364 local log=$($LFS changelog $MDT0 $index | grep FLRW)
2365 [ -z "$log" ] && { sleep 1; continue; }
2367 index=$(echo $log | awk '{print $1}')
2368 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
2369 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
2370 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
2373 [ -z "$file" ] && continue
2375 local now=$(date +%s)
2377 echo "file: $file $fid was modified at $ts, now: $now, " \
2378 "will be resynced at $((ts+delay))"
2380 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
2382 mirror_io resync $file
2383 echo "$file resync done"
2388 run_test 201 "FLR data mover"
2391 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
2393 local tf=$DIR/$tfile
2396 $LFS setstripe -E 1M -S 1M -c 1 $tf
2397 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2398 verify_comp_attr stripe-count $tf ${ids[0]} 1
2400 $LFS setstripe --component-add -E 2M -c -1 $tf
2401 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2402 verify_comp_attr stripe-count $tf ${ids[0]} 1
2403 verify_comp_attr stripe-count $tf ${ids[1]} -1
2405 dd if=/dev/zero of=$tf bs=1M count=2
2406 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2407 verify_comp_attr stripe-count $tf ${ids[0]} 1
2408 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
2410 run_test 202 "lfs setstripe --add-component wide striping"
2413 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2414 skip "Need MDS version at least 2.11.55"
2415 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
2417 local tf=$DIR/$tfile
2420 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
2421 #delete first mirror
2422 $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror"
2425 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
2426 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2427 error "getstripe count of mirror 2"
2428 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2430 #extend a mirror with 2 OSTs
2431 $LFS mirror extend -N -c2 $tf || error "extend mirror"
2434 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
2435 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2436 error "getstripe count of mirror 2"
2437 [[ x$oldid = x$newid ]] ||
2438 error "mirror 2 changed ID from $old_id to $new_id"
2439 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2441 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
2442 error "getstripe count of mirror 3"
2443 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
2445 run_test 203 "mirror file preserve mirror ID"
2447 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
2449 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2450 skip "skipped for lustre < $SEL_VER"
2452 local comp_file=$DIR/$tdir/$tfile
2456 test_mkdir $DIR/$tdir
2458 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
2459 # by extension space to -1
2460 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
2461 error "Create $comp_file failed"
2463 # Write to first component, extending & staling second mirror
2464 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2465 error "dd to extend + stale failed"
2467 $LFS getstripe $comp_file
2469 flg_opts="--component-flags init,stale"
2470 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2471 [ $found -eq 1 ] || error "write: Second comp end incorrect"
2473 flg_opts="--component-flags extension"
2474 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2475 [ $found -eq 1 ] || error "write: Third comp start incorrect"
2477 # mirror resync should not change the extents
2478 $LFS mirror resync $comp_file
2480 flg_opts="--component-flags init"
2481 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2482 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
2484 flg_opts="--component-flags extension"
2485 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2486 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
2488 sel_layout_sanity $comp_file 5
2492 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
2494 # Simple test of FLR + self-extending layout, SEL in primary mirror
2496 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2497 skip "skipped for lustre < $SEL_VER"
2499 local comp_file=$DIR/$tdir/$tfile
2503 test_mkdir $DIR/$tdir
2505 # first mirror is 1M followed by extension space to -1, second mirror
2506 # is 0-10M, then 10M-(-1),
2507 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2508 error "Create $comp_file failed"
2510 # Write to first component, extending first component & staling
2512 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2513 error "dd to extend + stale failed"
2515 $LFS getstripe $comp_file
2517 flg_opts="--component-flags init"
2518 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2519 [ $found -eq 1 ] || error "write: First comp end incorrect"
2521 flg_opts="--component-flags extension"
2522 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2523 [ $found -eq 1 ] || error "write: Second comp start incorrect"
2525 flg_opts="--component-flags init,stale"
2526 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2527 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
2529 # This component is staled because it overlaps the extended first
2530 # component of the primary mirror, even though it doesn't overlap
2531 # the actual write - thus not inited.
2532 flg_opts="--component-flags stale"
2533 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2534 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
2536 # mirror resync should not change the extents
2537 $LFS mirror resync $comp_file
2539 $LFS getstripe $comp_file
2541 flg_opts="--component-flags init"
2542 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2543 [ $found -eq 1 ] || error "resync: First comp end incorrect"
2545 flg_opts="--component-flags extension"
2546 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2547 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
2549 flg_opts="--component-flags init"
2550 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2551 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
2553 flg_opts="--component-flags init"
2554 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2555 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
2557 sel_layout_sanity $comp_file 5
2561 run_test 204b "FLR write/stale/resync tests with self-extending primary"
2563 # FLR + SEL failed extension & component removal
2564 # extension space in second mirror
2566 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2567 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2568 skip "skipped for lustre < $SEL_VER"
2570 local comp_file=$DIR/$tdir/$tfile
2573 local ost_name=$(ostname_from_index $ost_idx1)
2575 test_mkdir $DIR/$tdir
2577 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
2578 # extension space from 1M to 1G, then normal space to -1
2579 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
2580 -E -1 $comp_file || error "Create $comp_file failed"
2582 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
2585 # write to first comp (0 - 10M) of mirror 1, extending + staling
2586 # first + second comp of mirror 2
2587 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2590 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
2593 [ $RC -eq 0 ] || error "dd to extend + stale failed"
2595 $LFS getstripe $comp_file
2597 found=$($LFS find --component-start 0m --component-end 1m \
2598 --comp-flags init,stale $comp_file | wc -l)
2599 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2601 found=$($LFS find --component-start 1m --component-end EOF \
2602 --comp-flags stale,^init $comp_file | wc -l)
2603 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
2605 local mirror_id=$($LFS getstripe --component-start=1m \
2606 --component-end=EOF $comp_file | \
2607 grep lcme_mirror_id | awk '{ print $2 }')
2609 [[ $mirror_id -eq 2 ]] ||
2610 error "component not in correct mirror? $mirror_id"
2612 $LFS mirror resync $comp_file
2614 $LFS getstripe $comp_file
2616 # component dimensions should not change from resync
2617 found=$($LFS find --component-start 1m --component-end EOF \
2618 --component-flags init $comp_file | wc -l)
2619 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
2621 sel_layout_sanity $comp_file 4
2625 run_test 204c "FLR write/stale/resync test with component removal"
2627 # Successful repeated component in primary mirror
2629 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2630 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2631 skip "skipped for lustre < $SEL_VER"
2633 local comp_file=$DIR/$tdir/$tfile
2636 wait_delete_completed
2638 test_mkdir $DIR/$tdir
2640 # first mirror is 64M followed by extension space to -1, second mirror
2641 # is 0-10M, then 10M-(-1)
2642 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2643 error "Create $comp_file failed"
2645 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
2646 local ost_name=$(ostname_from_index $ost_idx1)
2647 # degrade OST for first comp so we won't extend there
2648 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2649 obdfilter.$ost_name.degraded=1
2652 # Write beyond first component, causing repeat & stale second mirror
2653 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
2656 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2657 obdfilter.$ost_name.degraded=0
2660 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2662 $LFS getstripe $comp_file
2664 found=$($LFS find --component-start 64m --component-end 128m \
2665 --component-flags init $comp_file | wc -l)
2666 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
2668 local ost_idx2=$($LFS getstripe --component-start=64m \
2669 --component-end=128m --component-flags=init \
2671 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2672 local mirror_id=$($LFS getstripe --component-start=64m \
2673 --component-end=128m --component-flags=init \
2674 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2675 [[ $mirror_id -eq 1 ]] ||
2676 error "component not in correct mirror: $mirror_id, not 1"
2678 $LFS mirror resync $comp_file
2680 $LFS getstripe $comp_file
2682 # component dimensions should not change from resync
2683 found=$($LFS find --component-start 0m --component-end 64m \
2684 --component-flags init $comp_file | wc -l)
2685 [ $found -eq 1 ] || error "resync: first comp incorrect"
2686 found=$($LFS find --component-start 64m --component-end 128m \
2687 --component-flags init $comp_file | wc -l)
2688 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
2690 sel_layout_sanity $comp_file 5
2694 run_test 204d "FLR write/stale/resync sel test with repeated comp"
2696 # Successful repeated component, SEL in non-primary mirror
2698 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2699 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2700 skip "skipped for lustre < $SEL_VER"
2702 local comp_file=$DIR/$tdir/$tfile
2705 wait_delete_completed
2708 test_mkdir $DIR/$tdir
2710 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2711 # space to -1 (-z 64M, so first comp is 0-64M)
2712 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
2713 # will be not enough - one will be degraded, the other is used on
2714 # an overlapping mirror.
2715 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
2716 error "Create $comp_file failed"
2718 local ost_idx1=$($LFS getstripe --component-start=0 \
2719 --component-end=64m -i $comp_file)
2720 local ost_name=$(ostname_from_index $ost_idx1)
2721 # degrade OST for first comp of 2nd mirror so we won't extend there
2722 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2723 obdfilter.$ost_name.degraded=1
2726 $LFS getstripe $comp_file
2728 # Write to first component, stale & instantiate second mirror components
2729 # overlapping with the written component (0-100M);
2730 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2733 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2734 obdfilter.$ost_name.degraded=0
2736 $LFS getstripe $comp_file
2738 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2740 found=$($LFS find --component-start 0m --component-end 64m \
2741 --component-flags init,stale $comp_file | wc -l)
2742 [ $found -eq 1 ] || error "write: first comp incorrect"
2744 # was repeated due to degraded ost
2745 found=$($LFS find --component-start 64m --component-end 128m \
2746 --component-flags init,stale $comp_file | wc -l)
2747 [ $found -eq 1 ] || error "write: repeated comp incorrect"
2749 local ost_idx2=$($LFS getstripe --component-start=64m \
2750 --component-end=128m --component-flags=init \
2752 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2753 local mirror_id=$($LFS getstripe --component-start=0m \
2754 --component-end=64m --component-flags=init \
2755 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2756 [[ $mirror_id -eq 2 ]] ||
2757 error "component not in correct mirror? $mirror_id"
2759 $LFS mirror resync $comp_file
2761 $LFS getstripe $comp_file
2763 # component dimensions should not change from resync
2764 found=$($LFS find --component-start 0m --component-end 64m \
2765 --component-flags init,^stale $comp_file | wc -l)
2766 [ $found -eq 1 ] || error "resync: first comp incorrect"
2767 found=$($LFS find --component-start 64m --component-end 128m \
2768 --component-flags init,^stale $comp_file | wc -l)
2769 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
2771 sel_layout_sanity $comp_file 5
2775 run_test 204e "FLR write/stale/resync sel test with repeated comp"
2777 # FLR + SEL: failed repeated component, SEL in non-primary mirror
2779 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2780 [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2781 skip "skipped for lustre < $SEL_VER"
2783 local comp_file=$DIR/$tdir/$tfile
2786 wait_delete_completed
2788 test_mkdir $DIR/$tdir
2790 pool_add $TESTNAME || error "Pool creation failed"
2791 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
2793 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2794 # space to -1 (-z 64M, so first comp is 0-64M)
2795 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
2796 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
2798 local ost_name0=$(ostname_from_index 0)
2799 local ost_name1=$(ostname_from_index 1)
2801 # degrade both OSTs in pool, so we'll try to repeat, then fail and
2802 # extend original comp
2803 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
2804 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
2807 # a write to the 1st component, 100M length, which will try to stale
2808 # the first 100M of mirror 2, attempting to extend its 0-64M component
2809 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2812 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
2813 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
2816 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
2818 $LFS getstripe $comp_file
2820 found=$($LFS find --component-start 0m --component-end 128m \
2821 --component-flags init,stale $comp_file | wc -l)
2822 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2824 local mirror_id=$($LFS getstripe --component-start=0m \
2825 --component-end=128m --component-flags=init \
2826 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2828 [[ $mirror_id -eq 2 ]] ||
2829 error "component not in correct mirror? $mirror_id, not 2"
2831 $LFS mirror resync $comp_file
2833 $LFS getstripe $comp_file
2835 # component dimensions should not change from resync
2836 found=$($LFS find --component-start 0m --component-end 128m \
2837 --component-flags init,^stale $comp_file | wc -l)
2838 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
2840 sel_layout_sanity $comp_file 4
2844 run_test 204f "FLR write/stale/resync sel w/forced extension"
2847 check_and_cleanup_lustre