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 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
24 { skip "Need MDS version at least 2.10.56"; exit 0; }
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
276 # command line test cases
280 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
281 local mirror_cmd="$LFS mirror create"
286 # create parent directory
287 mkdir $td || error "mkdir $td failed"
289 $mirror_cmd $tf &> /dev/null && error "miss -N option"
291 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
292 verify_mirror_count $tf 1
293 id=$($LFS getstripe -I $tf)
294 verify_comp_attrs $tf $id
295 verify_comp_extent $tf $id 0 EOF
297 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
298 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
299 error "invalid mirror count $((mirror_count + 1))"
301 $mirror_cmd -N$mirror_count $tf-1 ||
302 error "create mirrored file $tf-1 failed"
303 verify_mirror_count $tf-1 $mirror_count
304 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
305 for ((i = 0; i < $mirror_count; i++)); do
306 verify_comp_attrs $tf-1 ${ids[$i]}
307 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
310 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
311 error "create mirrored file $tf-2 failed"
312 verify_mirror_count $tf-2 10
313 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
314 for ((i = 0; i < 10; i++)); do
315 verify_comp_attrs $tf-2 ${ids[$i]}
316 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
319 run_test 0a "lfs mirror create with -N option"
322 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
326 local mirror_cmd="$LFS mirror create"
330 # create a new OST pool
331 local pool_name=$TESTNAME
332 create_pool $FSNAME.$pool_name ||
333 error "create OST pool $pool_name failed"
335 # add OSTs into the pool
336 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
337 error "add OSTs into pool $pool_name failed"
339 # create parent directory
340 mkdir $td || error "mkdir $td failed"
341 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
342 error "$LFS setstripe $td failed"
344 # create a mirrored file with plain layout mirrors
345 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
346 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
347 error "create mirrored file $tf failed"
348 verify_mirror_count $tf 6
349 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
350 for ((i = 0; i < 6; i++)); do
351 verify_comp_extent $tf ${ids[$i]} 0 EOF
354 # verify component ${ids[0]}
355 verify_comp_attrs $tf ${ids[0]}
357 # verify component ${ids[1]}
358 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
359 verify_comp_attr stripe-count $tf ${ids[1]} 2
360 verify_comp_attr stripe-index $tf ${ids[1]} 2
361 verify_comp_attr pool $tf ${ids[1]} flash
363 # verify component ${ids[2]}
364 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
365 verify_comp_attr stripe-count $tf ${ids[2]} 2
366 verify_comp_attr pool $tf ${ids[2]} flash
368 # verify component ${ids[3]}
369 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
370 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
371 verify_comp_attr pool $tf ${ids[3]} flash
373 # verify component ${ids[4]}
374 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
375 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
376 verify_comp_attr pool $tf ${ids[4]} archive
378 # verify component ${ids[5]}
379 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
380 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
381 verify_comp_attr_with_parent pool $tf ${ids[5]}
386 run_test 0b "lfs mirror create plain layout mirrors"
389 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
393 local mirror_cmd="$LFS mirror create"
397 # create a new OST pool
398 local pool_name=$TESTNAME
399 create_pool $FSNAME.$pool_name ||
400 error "create OST pool $pool_name failed"
402 # add OSTs into the pool
403 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
404 error "add OSTs into pool $pool_name failed"
406 # create parent directory
407 mkdir $td || error "mkdir $td failed"
408 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
409 error "$LFS setstripe $td failed"
411 # create a mirrored file with composite layout mirrors
412 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
414 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
415 error "create mirrored file $tf failed"
416 verify_mirror_count $tf 6
417 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
419 # verify components ${ids[0]} and ${ids[2]}
421 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
422 verify_comp_attr stripe-count $tf ${ids[$i]} 2
423 verify_comp_attr stripe-index $tf ${ids[$i]} 1
424 verify_comp_attr pool $tf ${ids[$i]} flash
425 verify_comp_extent $tf ${ids[$i]} 0 4194304
428 # verify components ${ids[1]} and ${ids[3]}
430 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
431 verify_comp_attr stripe-count $tf ${ids[$i]} 2
432 verify_comp_attr pool $tf ${ids[$i]} flash
433 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
436 # verify component ${ids[4]}
437 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
438 verify_comp_attr stripe-count $tf ${ids[4]} 4
439 verify_comp_attr_with_parent pool $tf ${ids[4]}
440 verify_comp_extent $tf ${ids[4]} 0 EOF
442 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
444 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
445 verify_comp_attr stripe-count $tf ${ids[$i]} 4
446 verify_comp_attr pool $tf ${ids[$i]} archive
447 verify_comp_extent $tf ${ids[$i]} 0 536870912
450 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
452 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
453 verify_comp_attr stripe-count $tf ${ids[$i]} -1
454 verify_comp_attr pool $tf ${ids[$i]} archive
455 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
461 run_test 0c "lfs mirror create composite layout mirrors"
466 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
467 local mirror_cmd="$LFS mirror extend"
471 # create parent directory
472 mkdir $td || error "mkdir $td failed"
474 $mirror_cmd $tf &> /dev/null && error "miss -N option"
475 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
477 # create a non-mirrored file, convert it to a mirrored file and extend
478 touch $tf || error "touch $tf failed"
479 $mirror_cmd -N $tf || error "convert and extend $tf failed"
480 verify_mirror_count $tf 2
481 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
482 for ((i = 0; i < 2; i++)); do
483 verify_comp_attrs $tf ${ids[$i]}
484 verify_comp_extent $tf ${ids[$i]} 0 EOF
487 lfsck_verify_pfid $tf || error "PFID is not set"
489 # create a mirrored file and extend it
490 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
491 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
493 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
494 error "setstripe options should not be specified with -f option"
496 $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
497 error "extend mirrored file $tf-1 failed"
498 verify_mirror_count $tf-1 $mirror_count
499 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
500 for ((i = 0; i < $mirror_count; i++)); do
501 verify_comp_attrs $tf-1 ${ids[$i]}
502 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
505 $mirror_cmd -N $tf-1 &> /dev/null &&
506 error "exceeded maximum mirror count $mirror_count" || true
508 run_test 0d "lfs mirror extend with -N option"
511 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
515 local mirror_cmd="$LFS mirror extend"
519 # create parent directory
520 mkdir $td || error "mkdir $td failed"
522 # create a mirrored file with plain layout mirrors
523 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
524 error "create mirrored file $tf failed"
526 # extend the mirrored file with plain layout mirrors
527 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
528 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
529 error "extend mirrored file $tf failed"
530 verify_mirror_count $tf 6
531 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
532 for ((i = 0; i < 6; i++)); do
533 verify_comp_extent $tf ${ids[$i]} 0 EOF
536 # verify component ${ids[0]}
537 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
538 verify_comp_attr stripe-count $tf ${ids[0]} 3
539 verify_comp_attr stripe-index $tf ${ids[0]} 1
540 verify_comp_attr pool $tf ${ids[0]} ssd
542 # verify component ${ids[1]}
543 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
544 verify_comp_attr stripe-count $tf ${ids[1]} 2
545 verify_comp_attr stripe-index $tf ${ids[1]} 2
546 verify_comp_attr pool $tf ${ids[1]} flash
548 # verify component ${ids[2]}
549 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
550 verify_comp_attr stripe-count $tf ${ids[2]} 2
551 verify_comp_attr pool $tf ${ids[2]} flash
553 # verify component ${ids[3]}
554 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
555 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
556 verify_comp_attr pool $tf ${ids[3]} flash
558 # verify component ${ids[4]}
559 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
560 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
561 verify_comp_attr pool $tf ${ids[4]} archive
563 # verify component ${ids[5]}
564 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
565 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
566 verify_comp_attr_with_parent pool $tf ${ids[5]}
568 run_test 0e "lfs mirror extend plain layout mirrors"
571 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
575 local mirror_cmd="$LFS mirror extend"
579 # create parent directory
580 mkdir $td || error "mkdir $td failed"
582 # create a mirrored file with composite layout mirror
583 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
584 error "create mirrored file $tf failed"
586 # extend the mirrored file with composite layout mirrors
587 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
589 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
590 error "extend mirrored file $tf failed"
591 verify_mirror_count $tf 7
592 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
594 # verify component ${ids[0]}
595 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
596 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
597 verify_comp_attr pool $tf ${ids[0]} ssd
598 verify_comp_extent $tf ${ids[0]} 0 33554432
600 # verify component ${ids[1]}
601 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
602 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
603 verify_comp_attr pool $tf ${ids[1]} ssd
604 verify_comp_extent $tf ${ids[1]} 33554432 EOF
606 # verify components ${ids[2]} and ${ids[4]}
608 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
609 verify_comp_attr stripe-count $tf ${ids[$i]} 2
610 verify_comp_attr stripe-index $tf ${ids[$i]} 1
611 verify_comp_attr pool $tf ${ids[$i]} flash
612 verify_comp_extent $tf ${ids[$i]} 0 4194304
615 # verify components ${ids[3]} and ${ids[5]}
617 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
618 verify_comp_attr stripe-count $tf ${ids[$i]} 2
619 verify_comp_attr pool $tf ${ids[$i]} flash
620 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
623 # verify component ${ids[6]}
624 verify_comp_attr stripe-size $tf ${ids[6]} 4194304
625 verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
626 verify_comp_attr_with_parent pool $tf ${ids[6]}
627 verify_comp_extent $tf ${ids[6]} 0 EOF
629 # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
631 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
632 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
633 verify_comp_attr pool $tf ${ids[$i]} archive
634 verify_comp_extent $tf ${ids[$i]} 0 536870912
637 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
639 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
640 verify_comp_attr stripe-count $tf ${ids[$i]} -1
641 verify_comp_attr pool $tf ${ids[$i]} archive
642 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
645 run_test 0f "lfs mirror extend composite layout mirrors"
650 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
651 -N -o1 $tf || error "create mirrored file $tf failed"
653 verify_comp_attr lcme_flags $tf 0x10001 prefer
654 verify_comp_attr lcme_flags $tf 0x10002 prefer
656 # write to the mirrored file and check primary
657 cp /etc/hosts $tf || error "error writing file '$tf'"
659 verify_comp_attr lcme_flags $tf 0x20003 stale
661 # resync file and check prefer flag
662 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
665 $LCTL set_param osc.*.stats=clear
666 cat $tf &> /dev/null || error "error reading file '$tf'"
668 # verify that the data was provided by OST1 where mirror 1 resides
669 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
670 awk '/ost_read/{print $2}')
671 [ -n "$nr_read" ] || error "read was not provided by OST1"
673 run_test 0g "lfs mirror create flags support"
676 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
677 skip "Need MDS version at least 2.11.57"
684 # create parent directory
685 test_mkdir $td || error "mkdir $td failed"
687 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
688 error "set default mirrored layout on directory $td failed"
690 # verify flags are inherited from the directory
693 verify_comp_attr lcme_flags $tf 0x10001 prefer
694 verify_comp_attr lcme_flags $tf 0x10002 prefer
696 # set flags to the first component
697 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
699 verify_comp_attr lcme_flags $tf 0x10001 stale
700 verify_comp_attr lcme_flags $tf 0x10002 prefer
702 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
703 error "clearing 'stale' should fail"
705 # write and resync file. It can't resync the file directly because the
706 # file state is still 'ro'
707 cp /etc/hosts $tf || error "error writing file '$tf'"
708 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
710 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
711 error "error setting flag prefer"
713 verify_comp_attr lcme_flags $tf 0x20003 prefer
715 run_test 0h "set, clear and test flags for FLR files"
719 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
720 local mirror_create_cmd="$LFS mirror create"
721 local stripes[0]=$OSTCOUNT
723 mirror_create_cmd+=" -N -c ${stripes[0]}"
724 for ((i = 1; i < $mirror_count; i++)); do
725 # add mirrors with different stripes to the file
726 stripes[$i]=$((RANDOM % OSTCOUNT))
727 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
729 mirror_create_cmd+=" -N -c ${stripes[$i]}"
732 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
733 verify_mirror_count $tf $mirror_count
735 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
736 $LFS mirror extend -N $tf &&
737 error "Creating the $((mirror_count+1))th mirror succeeded"
739 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
742 # verify the range of components and stripe counts
743 for ((i = 0; i < $mirror_count; i++)); do
744 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
745 verify_comp_extent $tf ${ids[$i]} 0 EOF
748 run_test 1 "create components with setstripe options"
752 local tf2=$DIR/$tfile-2
754 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
755 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
757 $LFS mirror extend -N -f $tf2 $tf ||
758 error "merging $tf2 into $tf failed"
760 verify_mirror_count $tf 2
761 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
763 run_test 2 "create components from existing files"
766 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
768 for ((i = 0; i < 2; i++)); do
769 $LFS mkdir -i $i $DIR/$tdir-$i
770 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
773 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
774 $DIR/$tdir-0/$tfile || error "creating mirrors"
776 # mdt doesn't support to cancel layout lock for remote objects, do
780 # make sure the mirrorted file was created successfully
781 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
782 { $LFS getstripe $DIR/$tdir-0/$tfile;
783 error "expected 2 components"; }
788 run_test 3 "create components from files located on different MDTs"
791 local tf=$DIR/$tdir/$tfile
794 test_mkdir $DIR/$tdir
796 # set mirror with setstripe options to directory
797 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
798 error "set mirror to directory error"
800 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
801 x"mirrored" ] || error "failed to create mirrored dir"
804 verify_mirror_count $tf 2
806 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
807 verify_comp_extent $tf ${ids[0]} 0 1048576
808 verify_comp_extent $tf ${ids[1]} 1048576 EOF
810 # sub directory should inherit mirror setting from parent
811 test_mkdir $DIR/$tdir/td
812 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
813 x"mirrored" ] || error "failed to inherit mirror from parent"
815 # mirror extend won't be applied to directory
816 $LFS mirror extend -N2 $DIR/$tdir &&
817 error "expecting mirror extend failure"
820 run_test 4 "Make sure mirror attributes can be inhertied from directory"
826 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
827 error "failed to create file with non-empty layout"
828 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
830 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
831 verify_mirror_count $tf 3
833 $CHECKSTAT -t file -s 12345 $tf ||
834 error "size error after attaching layout "
836 run_test 5 "Make sure init size work for mirrored layout"
838 # LU=10112: disable dom+flr for phase 1
842 $LFS mirror create -N -E 1M -S 1M -L mdt -E eof -N -E eof $tf &&
843 error "expect failure to create mirrored file with DoM"
845 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf &&
846 error "expect failure to create mirrored file with DoM"
848 $LFS setstripe -E 1M -S 1M -L mdt -E eof $tf
849 $LFS mirror extend -N2 $tf &&
850 error "expect failure to extend mirror with DoM"
852 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2
853 $LFS mirror extend -N -f $tf $tf-2 &&
854 error "expect failure to extend mirrored file with DoM extent"
858 run_test 6 "DoM and FLR won't co-exist for phase 1"
862 local tf2=$DIR/$tfile-2
864 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
866 $LFS setstripe -E EOF -o 0 $tf
867 $LFS setstripe -E EOF -o 1 $tf2
869 local dd_count=$((RANDOM % 20 + 1))
870 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
871 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
873 # for zfs - sync OST dataset so that du below will return
875 [ "$FSTYPE" = "zfs" ] &&
876 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
878 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
881 $LFS mirror extend -N -f $tf2 $tf ||
882 error "merging $tf2 into $tf failed"
887 local new_blocks=$(du -k $tf | awk '{print $1}')
888 [ $new_blocks -eq $blocks ] ||
889 error "i_blocks error expected: $blocks, actual: $new_blocks"
891 run_test 21 "glimpse should report accurate i_blocks"
893 get_osc_lock_count() {
900 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
901 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
902 lock_count=$((lock_count + count))
910 $LFS setstripe -E EOF -o 0 $tf
911 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
913 # add component, two mirrors located on the same OST ;-)
914 $LFS mirror extend -N -o 0 $tf ||
915 error "extending mirrored file $tf failed"
917 size_blocks=$(stat --format="%b %s" $tf)
922 local new_size_blocks=$(stat --format="%b %s" $tf)
924 # make sure there is no lock cached
925 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
927 [ "$new_size_blocks" = "$size_blocks" ] ||
928 echo "size expected: $size_blocks, actual: $new_size_blocks"
932 run_test 22 "no glimpse to OSTs for READ_ONLY files"
937 $LFS mirror create -N -o 0 -N -o 1 $tf ||
938 error "creating mirrored file $tf failed"
940 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
941 $LCTL set_param fail_loc=0x1A00
944 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
948 local tmpfile=$(mktemp)
949 stat --format="%b %s" $tf > $tmpfile &
953 while [ $cnt -le 5 ]; do
954 kill -0 $pid > /dev/null 2>&1 || break
958 kill -0 $pid > /dev/null 2>&1 &&
959 error "stat process stuck due to unavailable OSTs"
961 # make sure glimpse request has been sent
962 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
963 error "OST $ost_idx: no glimpse request was sent"
968 run_test 31 "make sure glimpse request can be retried"
971 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
972 rm -f $DIR/$tfile $DIR/$tfile-2
974 $LFS setstripe -E EOF -o 0 $DIR/$tfile
975 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
977 local fsize=$(stat -c %s $DIR/$tfile)
978 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
980 local cksum=$(md5sum $DIR/$tfile)
982 # create a new mirror in sync mode
983 $LFS mirror extend -N -o 1 $DIR/$tfile ||
984 error "extending mirrored file $DIR/$tfile failed"
986 # make sure the mirrored file was created successfully
987 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
988 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
993 # check size is correct, glimpse request should go to the 2nd mirror
994 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
995 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
997 echo "reading file from the 2nd mirror and verify checksum"
998 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
999 error "checksum error: expected $cksum"
1003 run_test 32 "data should be mirrored to newly created mirror"
1006 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1008 rm -f $DIR/$tfile $DIR/$tfile-2
1010 # create a file with two mirrors
1011 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1014 while [ $count -lt $max_count ]; do
1015 echo "ost1" >> $DIR/$tfile
1016 count=$((count + 1));
1019 # tmp file that will be used as mirror
1020 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1022 while [ $count -lt $max_count ]; do
1023 echo "ost2" >> $DIR/$tfile-2
1024 count=$((count + 1));
1027 # create a mirrored file
1028 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1029 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1030 "with verification should fail"
1031 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1032 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1033 "without verification failed"
1035 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1036 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1037 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1039 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1041 # execpted file size
1042 local fsize=$((5 * max_count))
1043 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1044 error "mirrored file size is not $fsize"
1046 # read file - all OSTs are available
1047 echo "reading file (data can be provided by any ost)... "
1048 local rs=$(cat $DIR/$tfile | head -1)
1049 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1050 error "file content error: expected: \"ost1\" or \"ost2\""
1052 # read file again with ost1 failed
1056 echo "reading file (data should be provided by ost2)..."
1057 local rs=$(cat $DIR/$tfile | head -1)
1058 [[ "$rs" == "ost2" ]] ||
1059 error "file content error: expected: \"ost2\", actual: \"$rs\""
1064 # read file again with ost2 failed
1068 # check size, glimpse should work
1069 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1070 error "mirrored file size is not $fsize"
1072 echo "reading file (data should be provided by ost1)..."
1073 local rs=$(cat $DIR/$tfile | head -1)
1074 [[ "$rs" == "ost1" ]] ||
1075 error "file content error: expected: \"ost1\", actual: \"$rs\""
1079 run_test 33 "read can choose available mirror to read"
1082 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1084 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1087 $LFS setstripe -o 0 $DIR/$tfile-ref
1088 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1090 # create a file with two mirrors
1091 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1092 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1094 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1095 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1097 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1098 error "mirrored file size is not 3M"
1100 # merge a mirrored file
1101 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1102 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1104 cancel_lru_locks osc
1106 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1107 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1110 echo "comparing files ... "
1112 # however, read can still return the correct data. It should return
1113 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1114 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1115 $DIR/$tfile-ref || error "file reading error"
1119 run_test 34a "read mirrored file with multiple stripes"
1122 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1124 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1127 $LFS setstripe -o 0 $DIR/$tfile-ref
1128 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1130 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1131 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1133 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1134 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1136 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1137 error "mirrored file size is not 3M"
1139 # merge a mirrored file
1140 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1141 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1143 cancel_lru_locks osc
1145 # stop two OSTs, so the 2nd component of the 1st mirror and
1146 # the 1st component of the 2nd mirror will be inaccessible, ...
1149 echo "comparing files ... "
1151 # however, read can still return the correct data. It should return
1152 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1153 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1154 $DIR/$tfile-ref || error "file reading error"
1158 run_test 34b "read mirrored file with multiple components"
1161 local tf=$DIR/$tfile
1163 $LFS setstripe -E eof $tf
1165 # add an out-of-sync mirror to the file
1166 $LFS mirror extend -N -c 2 $tf ||
1167 error "extending mirrored file $tf failed"
1169 $MULTIOP $tf oO_WRONLY:c ||
1170 error "write open a mirrored file failed"
1172 # truncate file should return error
1173 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1175 run_test 35 "allow to write to mirrored files"
1177 verify_ost_layout_version() {
1180 # get file layout version
1181 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1183 # layout version from OST objects
1184 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1186 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1193 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1194 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1196 $LFS mirror extend -N -f $tf-tmp $tf ||
1197 error "merging $tf-tmp into $tf failed"
1202 local tf=$DIR/$tfile
1204 create_file_36 $tf $tf-2 $tf-3
1206 [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1208 # test case 1 - check file write and verify layout version
1209 $MULTIOP $tf oO_WRONLY:c ||
1210 error "write open a mirrored file failed"
1212 # write open file should not return error
1213 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1215 # instantiate components should work
1216 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1218 # verify OST layout version
1219 verify_ost_layout_version $tf
1222 local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1225 do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1227 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1228 do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1230 # write should take at least $fail_loc seconds and succeed
1231 local st=$(date +%s)
1232 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1234 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1235 error "write finished before layout version is transmitted"
1237 # verify OST layout version
1238 verify_ost_layout_version $tf
1240 do_facet $mds_facet $LCTL set_param fail_loc=0
1243 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1245 #define OBD_FAIL_FLR_LV_INC 0x1A02
1246 do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1248 # write open file should return error
1249 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1250 error "write a mirrored file succeeded" || true
1252 do_facet $mds_facet $LCTL set_param fail_loc=0
1254 run_test 36 "write to mirrored files"
1260 echo "create test files with size $fsize .."
1264 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1266 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1267 $TRUNCATE $tf $fsize
1273 [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1274 skip "Need MDS version at least 2.11.57"
1276 local tf=$DIR/$tfile
1277 local tf2=$DIR/$tfile-2
1278 local tf3=$DIR/$tfile-3
1279 local tf4=$DIR/$tfile-4
1281 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1285 # assume the mirror id will be 1, 2, and 3
1286 declare -A checksums
1287 checksums[1]=$(cat $tf | md5sum)
1288 checksums[2]=$(cat $tf2 | md5sum)
1289 checksums[3]=$(cat $tf3 | md5sum)
1291 printf '%s\n' "${checksums[@]}"
1293 # merge these files into a mirrored file
1294 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1295 error "merging $tf2 into $tf failed"
1296 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1297 error "merging $tf3 into $tf failed"
1301 # verify mirror read, checksums should equal to the original files'
1302 echo "Verifying mirror read .."
1305 for i in ${mirror_array[@]}; do
1306 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1307 sum=$($LFS mirror read -N $i $tf | md5sum)
1308 [ "$sum" = "${checksums[$i]}" ] ||
1309 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1312 # verify mirror write
1313 echo "Verifying mirror write .."
1314 $LFS mirror write -N2 $tf < $tf4
1316 sum=$($LFS mirror read -N2 $tf | md5sum)
1317 [[ "$sum" = "${checksums[1]}" ]] ||
1318 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1320 # verify mirror copy, write to this mirrored file will invalidate
1321 # the other two mirrors
1322 echo "Verifying mirror copy .."
1324 local osts=$(comma_list $(osts_nodes))
1326 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1327 error "mirror copy error"
1329 # verify copying is successful by checking checksums
1330 remount_client $MOUNT
1331 for i in ${mirror_array[@]}; do
1332 sum=$($LFS mirror read -N $i $tf | md5sum)
1333 [ "$sum" = "${checksums[1]}" ] ||
1334 error "$i: mismatch checksum after copy \'$sum\'"
1339 run_test 37 "mirror I/O API verification"
1344 local expected_state=$2
1346 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
1347 [ $expected_state = $state ] ||
1348 error "expected: $expected_state, actual $state"
1352 local tf=$DIR/$tfile
1353 local ref=$DIR/${tfile}-ref
1355 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1356 error "creating $tf failed"
1357 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1358 $tf-2 || error "creating $tf-2 failed"
1359 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1360 error "creating $tf-3 failed"
1362 # instantiate all components
1363 $LFS mirror extend -N -f $tf-2 $tf ||
1364 error "merging $tf-2 into $tf failed"
1365 $LFS mirror extend -N -f $tf-3 $tf ||
1366 error "merging $tf-3 into $tf failed"
1367 $LFS mirror extend -N -c 1 $tf ||
1368 error "extending mirrored file $tf failed"
1370 verify_flr_state $tf "ro"
1372 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1374 local fsize=$((RANDOM << 8 + 1048576))
1375 $TRUNCATE $ref $fsize
1377 local ref_cksum=$(cat $ref | md5sum)
1379 # case 1: verify write to mirrored file & resync work
1380 cp $ref $tf || error "copy from $ref to $f error"
1381 verify_flr_state $tf "wp"
1383 local file_cksum=$(cat $tf | md5sum)
1384 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1387 echo "mirror IDs: ${mirror_array[@]}"
1389 local valid_mirror stale_mirror id mirror_cksum
1390 for id in "${mirror_array[@]}"; do
1391 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1392 [ "$ref_cksum" == "$mirror_cksum" ] &&
1393 { valid_mirror=$id; continue; }
1398 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1399 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1401 mirror_io resync $tf || error "resync failed"
1402 verify_flr_state $tf "ro"
1404 mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1405 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1407 # case 2: inject an error to make mirror_io exit after changing
1408 # the file state to sync_pending so that we can start a concurrent
1410 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1411 verify_flr_state $tf "wp"
1413 mirror_io resync -e resync_start $tf && error "resync succeeded"
1414 verify_flr_state $tf "sp"
1416 # from sync_pending to write_pending
1417 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1418 verify_flr_state $tf "wp"
1420 mirror_io resync -e resync_start $tf && error "resync succeeded"
1421 verify_flr_state $tf "sp"
1423 # from sync_pending to read_only
1424 mirror_io resync $tf || error "resync failed"
1425 verify_flr_state $tf "ro"
1427 run_test 38 "resync"
1430 local tf=$DIR/$tfile
1433 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1434 error "create PFL file $tf failed"
1436 verify_mirror_count $tf 2
1437 verify_comp_count $tf 4
1439 rm -f $tf || error "delete $tf failed"
1441 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1444 local tf=$DIR/$tfile
1447 for ops in "conv=notrunc" ""; do
1450 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1451 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1452 error "create PFLR file $tf failed"
1453 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1454 error "write PFLR file $tf failed"
1456 lfs getstripe -vy $tf
1460 # file mirror state should be write_pending
1461 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1463 error "file mirror state $flags"
1464 # the 1st component (in mirror 1) should be inited
1465 verify_comp_attr lcme_flags $tf 0x10001 init
1466 # the 2nd component (in mirror 1) should be inited
1467 verify_comp_attr lcme_flags $tf 0x10002 init
1468 # the 3rd component (in mirror 1) should be uninited
1469 verify_comp_attr lcme_flags $tf 0x10003 prefer
1470 # the 4th component (in mirror 2) should be inited
1471 verify_comp_attr lcme_flags $tf 0x20004 init
1472 # the 5th component (in mirror 2) should be uninited
1473 verify_comp_attr lcme_flags $tf 0x20005 0
1474 # the 6th component (in mirror 2) should be stale
1475 verify_comp_attr lcme_flags $tf 0x20006 stale
1476 # the 7th component (in mirror 2) should be uninited
1477 if [[ x$ops = "xconv=notrunc" ]]; then
1478 verify_comp_attr lcme_flags $tf 0x20007 0
1479 elif [[ x$ops = "x" ]]; then
1480 verify_comp_attr lcme_flags $tf 0x20007 stale
1484 rm -f $tf || error "delete $tf failed"
1486 run_test 40 "PFLR rdonly state instantiation check"
1489 local tf=$DIR/$tfile
1492 echo " **create two FLR files $tf $tf-1"
1493 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1494 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1495 error "create PFLR file $tf failed"
1496 $LFS mirror create -N -E 2M -S 1M -E eof \
1497 -N -E 1M -E eof --flags prefer \
1498 -N -E 4m -E eof $tf-1 ||
1499 error "create PFLR file $tf-1 failed"
1501 # file should be in ro status
1502 echo " **verify files be RDONLY"
1503 verify_flr_state $tf "ro"
1504 verify_flr_state $tf-1 "ro"
1506 # write data in [0, 2M)
1507 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1508 error "writing $tf failed"
1509 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1510 error "writing $tf-1 failed"
1512 local sum0=$(cat $tf-1 | md5sum)
1514 echo " **verify files be WRITE_PENDING"
1515 verify_flr_state $tf "wp"
1516 verify_flr_state $tf-1 "wp"
1518 # file should have stale component
1519 echo " **verify files have stale component"
1520 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1521 error "after writing $tf, it does not contain stale component"
1522 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1523 error "after writing $tf-1, it does not contain stale component"
1525 echo " **full resync"
1526 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1528 echo " **verify $tf-1 data consistency in all mirrors"
1530 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1531 [[ "$sum" = "$sum0" ]] ||
1532 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1535 echo " **verify files be RDONLY"
1536 verify_flr_state $tf "ro"
1537 verify_flr_state $tf-1 "ro"
1539 # file should not have stale component
1540 echo " **verify files do not contain stale component"
1541 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1542 error "after resyncing $tf, it contains stale component"
1543 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1544 error "after resyncing $tf, it contains stale component"
1546 # verify partial resync
1547 echo " **write $tf-1 for partial resync test"
1548 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1549 error "writing $tf-1 failed"
1551 echo " **only resync mirror 2"
1552 verify_flr_state $tf-1 "wp"
1553 $LFS mirror resync --only 2 $tf-1 ||
1554 error "resync mirror 2 of $tf-1 failed"
1555 verify_flr_state $tf "ro"
1557 # resync synced mirror
1558 echo " **resync mirror 2 again"
1559 $LFS mirror resync --only 2 $tf-1 ||
1560 error "resync mirror 2 of $tf-1 failed"
1561 verify_flr_state $tf "ro"
1562 echo " **verify $tf-1 contains stale component"
1563 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1564 error "after writing $tf-1, it does not contain stale component"
1566 echo " **full resync $tf-1"
1567 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1568 verify_flr_state $tf "ro"
1569 echo " **full resync $tf-1 again"
1570 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1571 echo " **verify $tf-1 does not contain stale component"
1572 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1573 error "after resyncing $tf, it contains stale component"
1577 run_test 41 "lfs mirror resync check"
1580 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1584 local mirror_cmd="$LFS mirror verify"
1587 # create parent directory
1588 mkdir $td || error "mkdir $td failed"
1590 $mirror_cmd &> /dev/null && error "no file name given"
1591 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1592 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1594 # create mirrored files
1595 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1596 error "create mirrored file $tf failed"
1597 $LFS mirror create -N -E 2M -S 1M -E EOF \
1598 -N -E 6M -E 8M -E EOF \
1599 -N -E 16M -E EOF $tf-1 ||
1600 error "create mirrored file $tf-1 failed"
1601 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1602 error "create mirrored file $tf-2 failed"
1604 # write data in [0, 10M)
1605 for i in $tf $tf-1 $tf-2; do
1606 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1607 error "write $i failed"
1610 # resync the mirrored files
1611 $LFS mirror resync $tf-1 $tf-2 ||
1612 error "resync $tf-1 $tf-2 failed"
1614 # verify the mirrored files
1615 $mirror_cmd $tf-1 $tf-2 ||
1616 error "verify $tf-1 $tf-2 failed"
1618 get_mirror_ids $tf-1
1619 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1620 error "at least 2 mirror ids needed with '--only' option"
1621 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1623 error "'--only' option cannot be used upon multiple files"
1624 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1625 error "invalid specified mirror ids"
1627 # change the content of $tf and merge it into $tf-1
1629 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1630 error "change $tf with seek=$i failed"
1631 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1632 error "change $tf-1 with seek=$i failed"
1635 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1636 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1637 error "merge $tf into $tf-1 failed"
1639 # verify the mirrored files
1640 echo "Verify $tf-1 without -v option:"
1641 $mirror_cmd $tf-1 &&
1642 error "verify $tf-1 should fail" || echo "PASS"
1644 echo "Verify $tf-1 with -v option:"
1645 $mirror_cmd -v $tf-1 &&
1646 error "verify $tf-1 should fail"
1648 get_mirror_ids $tf-1
1649 echo "Verify $tf-1 with --only option:"
1650 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1651 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1652 "${mirror_array[-1]} should fail"
1654 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1655 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1656 "${mirror_array[1]} should succeed"
1658 # set stale components in $tf-1
1659 for i in 0x40002 0x40003; do
1660 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1661 error "set stale flag on component $i failed"
1664 # verify the mirrored file
1665 echo "Verify $tf-1 with stale components:"
1666 $mirror_cmd -vvv $tf-1 ||
1667 error "verify $tf-1 with stale components should succeed"
1669 echo "Verify $tf-1 with stale components and --only option:"
1670 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1671 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1672 "${mirror_array[-1]} should succeed"
1674 run_test 42 "lfs mirror verify"
1676 # inactivate one OST && write && restore the OST
1680 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1683 wait=$(do_facet $SINGLEMDS \
1684 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1685 wait=${wait%%[^0-9]*}
1687 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1688 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1689 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1690 sleep $(($wait * 2 + 2))
1691 echo " **write $file"
1692 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1693 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1694 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1695 sleep $((wait * 2 + 2))
1697 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1698 [ $flags = wp ] || error "file mirror state $flags != wp"
1702 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1704 local tf=$DIR/$tfile
1708 ## mirror 0 ost (0, 1)
1709 ## mirror 1 ost (1, 2)
1710 ## mirror 2 ost (2, 0)
1711 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1712 -N -Eeof -c2 -o2,0 $tf ||
1713 error "create 3 mirrors file $tf failed"
1715 ################## OST0 ###########################################
1717 echo " **verify components"
1718 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1719 verify_comp_attr lcme_flags $tf 0x20002 init
1720 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1723 echo " **resync $tf"
1724 $LFS mirror resync $tf
1725 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1726 [ $flags = ro ] || error "file mirror state $flags != ro"
1728 ################## OST1 ###########################################
1730 echo " **verify components"
1731 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1732 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1733 verify_comp_attr lcme_flags $tf 0x30003 init
1736 echo " **resync $tf"
1737 $LFS mirror resync $tf
1738 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1739 [ $flags = ro ] || error "file mirror state $flags != ro"
1741 ################## OST2 ###########################################
1743 echo " **verify components"
1744 verify_comp_attr lcme_flags $tf 0x10001 init
1745 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1746 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1748 run_test 43 "mirror pick on write"
1751 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1754 local tf=$DIR/$tdir/$tfile
1755 local tf1=$DIR/$tdir-1/$tfile-1
1757 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1758 error "create directory failed"
1759 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1760 error "create remote directory failed"
1761 rm -f $tf $tf1 $tf.mirror~2
1762 # create file with 4 mirrors
1763 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1764 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
1765 error "create PFLR file $tf failed"
1767 # file should be in ro status
1768 verify_flr_state $tf "ro"
1770 # write data in [0, 3M)
1771 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1772 error "writing $tf failed"
1774 verify_flr_state $tf "wp"
1776 # synchronize all mirrors of the file
1777 $LFS mirror resync $tf || error "mirror resync $tf failed"
1779 verify_flr_state $tf "ro"
1782 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1783 error "split to $tf1 failed"
1785 local idx0=$($LFS getstripe -m $tf)
1786 local idx1=$($LFS getstripe -m $tf1)
1788 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1789 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1791 # verify mirror count
1792 verify_mirror_count $tf 3
1793 verify_mirror_count $tf1 1
1795 $LFS mirror split --mirror-id 2 $tf ||
1796 error "split mirror 2 failed"
1798 verify_mirror_count $tf 2
1799 verify_mirror_count $tf.mirror~2 1
1801 $LFS mirror split --mirror-id 3 -d $tf ||
1802 error "split and delte mirror 3 failed"
1803 verify_mirror_count $tf 1
1805 # verify splitted file contains the same content as the orig file does
1806 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
1807 diff $tf $tf.mirror~2 ||
1808 error "splited file $tf.mirror~2 diffs from $tf"
1810 run_test 44 "lfs mirror split check"
1813 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1815 local file=$DIR/$tdir/$tfile
1816 local dir=$DIR/$tdir/$dir
1817 local temp=$DIR/$tdir/template
1819 test_mkdir $DIR/$tdir
1821 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1822 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
1823 error "Create $file failed"
1825 verify_yaml_layout $file $file.copy $temp "1. FLR file"
1826 rm -f $file $file.copy
1828 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1829 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
1830 error "Create $file failed"
1832 verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
1834 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
1841 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
1843 local layout1=$(get_layout_param $src)
1844 local layout2=$(get_layout_param $dst)
1845 # compare their layout info
1846 [ "$layout1" == "$layout2" ] ||
1847 error "$msg_prefix $src <=> $dst layouts are not equal"
1851 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1853 local file=$DIR/$tdir/$tfile
1854 test_mkdir $DIR/$tdir
1856 ########################### 1. PFL file #############################
1857 echo " ** 1. PFL file"
1859 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
1860 $file || error "1. Create PFL $file failed"
1863 verify_46 $file $file.copy "1. PFL file"
1865 ########################### 2. plain file ###########################
1866 echo " ** 2. plain file"
1868 $LFS setstripe -c2 -o0,1 -i1 $file ||
1869 error "2. Create plain $file failed"
1872 verify_46 $file $file.copy "2. plain file"
1874 ########################### 3. FLR file #############################
1875 echo " ** 3. FLR file"
1876 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
1877 $file || error "3. Create FLR $file failed"
1880 verify_46 $file $file.copy "3. FLR file"
1882 local dir=$DIR/$tdir/dir
1883 ########################### 4. PFL dir ##############################
1884 echo " ** 4. PFL dir"
1886 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
1887 error "4. setstripe PFL $dir failed"
1889 test_mkdir $dir.copy
1890 verify_46 $dir $dir.copy "4. PFL dir"
1892 ########################### 5. plain dir ############################
1893 echo " ** 5. plain dir"
1894 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
1896 verify_46 $dir $dir.copy "5. plain dir"
1898 ########################### 6. FLR dir ##############################
1899 echo " ** 6. FLR dir"
1900 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
1901 error "6. setstripe FLR $dir failed"
1903 verify_46 $dir $dir.copy "6. FLR dir"
1905 run_test 46 "Verify setstripe --copy option"
1908 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1910 local file=$DIR/$tdir/$tfile
1915 test_mkdir $DIR/$tdir
1919 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
1920 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
1921 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
1922 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
1923 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1925 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
1926 $LFS mirror resync $file || error "resync $file failed"
1928 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
1929 if [[ x$ost == "x0," ]]; then
1930 $LFS getstripe $file
1931 error "component ${ids[2]} objects allocated on $ost " \
1935 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
1936 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
1937 $LFS getstripe $file
1938 error "component ${ids[3]} objects allocated on $ost " \
1939 "shouldn't on OST1 or on OST2"
1944 # mirror1: [comp0] [comp1]
1945 # mirror2: [comp2] [comp3]
1946 # mirror3: [comp4] [comp5]
1947 # mirror4: [comp6] [comp7]
1948 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
1949 error "create FLR $file failed"
1950 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1952 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
1953 $LFS mirror resync $file || error "resync $file failed"
1955 for ((i = 0; i < 6; i++)); do
1956 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
1957 awk '/l_ost_idx/{print $5}')
1959 # comp[0],comp[2],comp[4] should use different osts
1960 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
1961 ${osts[2]} == ${osts[4]} ]]; then
1962 $LFS getstripe $file
1963 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
1964 "allocated on duplicated OSTs"
1966 # comp[1],comp[3],comp[5] should use different osts
1967 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
1968 ${osts[3]} == ${osts[5]} ]]; then
1969 $LFS getstripe $file
1970 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
1971 "allocated on duplicated OSTs"
1976 run_test 47 "Verify mirror obj alloc"
1979 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
1980 skip "Need MDS version at least 2.11.55"
1982 local tf=$DIR/$tfile
1985 echo " ** create 2 mirrors FLR file $tf"
1986 $LFS mirror create -N -E2M -Eeof --flags prefer \
1987 -N -E1M -Eeof $tf ||
1988 error "create FLR file $tf failed"
1991 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
1992 verify_flr_state $tf "wp"
1994 local sum0=$(md5sum < $tf)
1996 echo " ** resync the file"
1997 $LFS mirror resync $tf
1999 echo " ** snapshot mirror 2"
2000 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2002 echo " ** write it again"
2003 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2004 echo " ** resync it again"
2005 $LFS mirror resync $tf
2007 verify_flr_state $tf "wp"
2008 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2010 local sum1=$($LFS mirror read -N1 $tf | md5sum)
2011 local sum2=$($LFS mirror read -N2 $tf | md5sum)
2013 echo " ** verify mirror 2 doesn't change"
2014 echo "original checksum: $sum0"
2015 echo "mirror 1 checksum: $sum1"
2016 echo "mirror 2 checksum: $sum2"
2017 [[ $sum0 = $sum2 ]] ||
2018 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2019 echo " ** mirror 2 stripe info"
2020 $LFS getstripe -v --mirror-index=2 $tf
2022 echo " ** resync mirror 2"
2023 $LFS mirror resync --only 2 $tf
2025 verify_flr_state $tf "ro"
2026 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2028 sum1=$($LFS mirror read -N1 $tf | md5sum)
2029 sum2=$($LFS mirror read -N2 $tf | md5sum)
2031 echo " ** verify mirror 2 resync-ed"
2032 echo "original checksum: $sum0"
2033 echo "mirror 1 checksum: $sum1"
2034 echo "mirror 2 checksum: $sum2"
2035 [[ $sum1 = $sum2 ]] ||
2036 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2037 echo " ** mirror 2 stripe info"
2038 $LFS getstripe -v --mirror-index=2 $tf
2040 run_test 48 "Verify snapshot mirror"
2042 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
2043 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
2048 local fsize=$(stat --printf=%s $tf)
2050 while [ -f $ctrl_file ]; do
2051 local off=$((RANDOM << 8))
2052 local len=$((RANDOM << 5 + 131072))
2054 [ $((off + len)) -gt $fsize ] && {
2055 fsize=$((off + len))
2056 echo "Extending file size to $fsize .."
2059 flock -s $lock_file -c \
2060 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
2062 error "failed writing to $off:$len"; }
2063 sleep 0.$((RANDOM % 2 + 1))
2070 while [ -f $ctrl_file ]; do
2071 flock -s $lock_file -c "cat $tf &> /dev/null" ||
2072 { rm -f $ctrl_file; error "read failed"; }
2073 sleep 0.$((RANDOM % 2 + 1))
2080 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
2082 exec 200<>$lock_file
2083 while [ -f $ctrl_file ]; do
2084 local lock_taken=false
2085 local index=$((RANDOM % ${#options[@]}))
2086 local cmd="mirror_io resync ${options[$index]}"
2088 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
2090 [ $((RANDOM % 4)) -eq 0 ] && {
2096 echo -n "resync file $tf with '$cmd' .."
2098 if [[ $lock_taken = "true" ]]; then
2099 flock -x 200 -c "$cmd $tf &> /dev/null" &&
2100 echo "done" || echo "failed"
2103 $cmd $tf &> /dev/null && echo "done" || echo "failed"
2106 sleep 0.$((RANDOM % 8 + 1))
2111 local tf=$DIR/$tfile
2112 local tf2=$DIR2/$tfile
2113 local tf3=$DIR3/$tfile
2115 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
2116 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
2117 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
2119 $LFS mirror extend -N -f $tf-2 $tf ||
2120 error "merging $tf-2 into $tf failed"
2121 $LFS mirror extend -N -f $tf-3 $tf ||
2122 error "merging $tf-3 into $tf failed"
2124 mkdir -p $MOUNT2 && mount_client $MOUNT2
2126 mkdir -p $MOUNT3 && mount_client $MOUNT3
2128 verify_flr_state $tf3 "ro"
2130 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
2131 $LCTL set_param fail_loc=0x1A03
2133 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
2134 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
2138 write_file_200 $tf &
2144 write_file_200 $tf2 &
2147 read_file_200 $tf2 &
2150 resync_file_200 $tf3 &
2154 [ "$SLOW" = "yes" ] && sleep_time=360
2155 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
2162 echo "Waiting ${pids[@]}"
2165 umount_client $MOUNT2
2166 umount_client $MOUNT3
2170 # resync and verify mirrors
2171 mirror_io resync $tf
2174 local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
2175 for id in ${mirror_array[@]:1}; do
2176 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
2177 error "checksum error for mirror $id"
2182 run_test 200 "stress test"
2184 cleanup_test_201() {
2186 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
2188 umount_client $MOUNT2
2192 local delay=${RESYNC_DELAY:-5}
2194 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
2195 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
2197 trap cleanup_test_201 EXIT
2199 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
2200 changelog_register -n)
2202 mkdir -p $MOUNT2 && mount_client $MOUNT2
2206 local log=$($LFS changelog $MDT0 $index | grep FLRW)
2207 [ -z "$log" ] && { sleep 1; continue; }
2209 index=$(echo $log | awk '{print $1}')
2210 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
2211 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
2212 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
2215 [ -z "$file" ] && continue
2217 local now=$(date +%s)
2219 echo "file: $file $fid was modified at $ts, now: $now, " \
2220 "will be resynced at $((ts+delay))"
2222 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
2224 mirror_io resync $file
2225 echo "$file resync done"
2230 run_test 201 "FLR data mover"
2233 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
2235 local tf=$DIR/$tfile
2238 $LFS setstripe -E 1M -S 1M -c 1 $tf
2239 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2240 verify_comp_attr stripe-count $tf ${ids[0]} 1
2242 $LFS setstripe --component-add -E 2M -c -1 $tf
2243 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2244 verify_comp_attr stripe-count $tf ${ids[0]} 1
2245 verify_comp_attr stripe-count $tf ${ids[1]} -1
2247 dd if=/dev/zero of=$tf bs=1M count=2
2248 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2249 verify_comp_attr stripe-count $tf ${ids[0]} 1
2250 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
2252 run_test 202 "lfs setstripe --add-component wide striping"
2255 [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2256 skip "Need MDS version at least 2.11.55"
2257 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
2259 local tf=$DIR/$tfile
2262 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
2263 #delete first mirror
2264 $LFS mirror split --mirror-id=1 -d $tf || error "delete first mirror"
2267 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
2268 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2269 error "getstripe count of mirror 2"
2270 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2272 #extend a mirror with 2 OSTs
2273 $LFS mirror extend -N -c2 $tf || error "extend mirror"
2276 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
2277 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2278 error "getstripe count of mirror 2"
2279 [[ x$oldid = x$newid ]] ||
2280 error "mirror 2 changed ID from $old_id to $new_id"
2281 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2283 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
2284 error "getstripe count of mirror 3"
2285 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
2287 run_test 203 "mirror file preserve mirror ID"
2289 # Simple test of FLR + self-extending layout, SEL in non-primary mirror
2291 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
2292 skip "skipped for lustre < $SEL_VER"
2294 local comp_file=$DIR/$tdir/$tfile
2298 test_mkdir $DIR/$tdir
2300 # first mirror is 0-10M, then 10M-(-1), second mirror is 1M followed
2301 # by extension space to -1
2302 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E-1 -z64M $comp_file ||
2303 error "Create $comp_file failed"
2305 # Write to first component, extending & staling second mirror
2306 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2307 error "dd to extend + stale failed"
2309 $LFS getstripe $comp_file
2311 flg_opts="--component-flags init,stale"
2312 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2313 [ $found -eq 1 ] || error "write: Second comp end incorrect"
2315 flg_opts="--component-flags extension"
2316 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2317 [ $found -eq 1 ] || error "write: Third comp start incorrect"
2319 # mirror resync should not change the extents
2320 $LFS mirror resync $comp_file
2322 flg_opts="--component-flags init"
2323 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2324 [ $found -eq 1 ] || error "resync: Second comp end incorrect"
2326 flg_opts="--component-flags extension"
2327 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2328 [ $found -eq 1 ] || error "resync: Third comp start incorrect"
2330 sel_layout_sanity $comp_file 5
2334 run_test 204a "FLR write/stale/resync tests with self-extending mirror"
2336 # Simple test of FLR + self-extending layout, SEL in primary mirror
2338 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
2339 skip "skipped for lustre < $SEL_VER"
2341 local comp_file=$DIR/$tdir/$tfile
2345 test_mkdir $DIR/$tdir
2347 # first mirror is 1M followed by extension space to -1, second mirror
2348 # is 0-10M, then 10M-(-1),
2349 $LFS setstripe -N -E 1M -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2350 error "Create $comp_file failed"
2352 # Write to first component, extending first component & staling
2354 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc ||
2355 error "dd to extend + stale failed"
2357 $LFS getstripe $comp_file
2359 flg_opts="--component-flags init"
2360 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2361 [ $found -eq 1 ] || error "write: First comp end incorrect"
2363 flg_opts="--component-flags extension"
2364 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2365 [ $found -eq 1 ] || error "write: Second comp start incorrect"
2367 flg_opts="--component-flags init,stale"
2368 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2369 [ $found -eq 1 ] || error "write: First mirror comp flags incorrect"
2371 # This component is staled because it overlaps the extended first
2372 # component of the primary mirror, even though it doesn't overlap
2373 # the actual write - thus not inited.
2374 flg_opts="--component-flags stale"
2375 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2376 [ $found -eq 1 ] || error "write: Second mirror comp flags incorrect"
2378 # mirror resync should not change the extents
2379 $LFS mirror resync $comp_file
2381 $LFS getstripe $comp_file
2383 flg_opts="--component-flags init"
2384 found=$($LFS find --component-end 65M $flg_opts $comp_file | wc -l)
2385 [ $found -eq 1 ] || error "resync: First comp end incorrect"
2387 flg_opts="--component-flags extension"
2388 found=$($LFS find --component-start 65M $flg_opts $comp_file | wc -l)
2389 [ $found -eq 1 ] || error "resync: Second comp start incorrect"
2391 flg_opts="--component-flags init"
2392 found=$($LFS find --component-end 10M $flg_opts $comp_file | wc -l)
2393 [ $found -eq 1 ] || error "resync: First mirror comp flags incorrect"
2395 flg_opts="--component-flags init"
2396 found=$($LFS find --component-start 10M $flg_opts $comp_file | wc -l)
2397 [ $found -eq 1 ] || error "resync: Second mirror comp flags incorrect"
2399 sel_layout_sanity $comp_file 5
2403 run_test 204b "FLR write/stale/resync tests with self-extending primary"
2405 # FLR + SEL failed extension & component removal
2406 # extension space in second mirror
2408 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2409 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
2410 skip "skipped for lustre < $SEL_VER"
2412 local comp_file=$DIR/$tdir/$tfile
2415 local ost_name=$(ostname_from_index $ost_idx1)
2417 test_mkdir $DIR/$tdir
2419 # first mirror is is 0-10M, then 10M-(-1), second mirror is 0-1M, then
2420 # extension space from 1M to 1G, then normal space to -1
2421 $LFS setstripe -N -E 10M -E-1 -N -E 1M -E 1G -i $ost_idx1 -z 64M \
2422 -E -1 $comp_file || error "Create $comp_file failed"
2424 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
2427 # write to first comp (0 - 10M) of mirror 1, extending + staling
2428 # first + second comp of mirror 2
2429 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2432 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
2435 [ $RC -eq 0 ] || error "dd to extend + stale failed"
2437 $LFS getstripe $comp_file
2439 found=$($LFS find --component-start 0m --component-end 1m \
2440 --comp-flags init,stale $comp_file | wc -l)
2441 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2443 found=$($LFS find --component-start 1m --component-end EOF \
2444 --comp-flags stale,^init $comp_file | wc -l)
2445 [ $found -eq 1 ] || error "write: Second mirror comp incorrect"
2447 local mirror_id=$($LFS getstripe --component-start=1m \
2448 --component-end=EOF $comp_file | \
2449 grep lcme_mirror_id | awk '{ print $2 }')
2451 [[ $mirror_id -eq 2 ]] ||
2452 error "component not in correct mirror? $mirror_id"
2454 $LFS mirror resync $comp_file
2456 $LFS getstripe $comp_file
2458 # component dimensions should not change from resync
2459 found=$($LFS find --component-start 1m --component-end EOF \
2460 --component-flags init $comp_file | wc -l)
2461 [ $found -eq 1 ] || error "resync: Second mirror comp incorrect"
2463 sel_layout_sanity $comp_file 4
2467 run_test 204c "FLR write/stale/resync test with component removal"
2469 # Successful repeated component in primary mirror
2471 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2472 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
2473 skip "skipped for lustre < $SEL_VERSION"
2475 local comp_file=$DIR/$tdir/$tfile
2478 wait_delete_completed
2480 test_mkdir $DIR/$tdir
2482 # first mirror is 64M followed by extension space to -1, second mirror
2483 # is 0-10M, then 10M-(-1)
2484 $LFS setstripe -N -E-1 -z64M -N -E 10M -E-1 $comp_file ||
2485 error "Create $comp_file failed"
2487 local ost_idx1=$($LFS getstripe -I65537 -i $comp_file)
2488 local ost_name=$(ostname_from_index $ost_idx1)
2489 # degrade OST for first comp so we won't extend there
2490 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2491 obdfilter.$ost_name.degraded=1
2494 # Write beyond first component, causing repeat & stale second mirror
2495 dd if=/dev/zero bs=1M count=1 seek=66 of=$comp_file conv=notrunc
2498 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2499 obdfilter.$ost_name.degraded=0
2502 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2504 $LFS getstripe $comp_file
2506 found=$($LFS find --component-start 64m --component-end 128m \
2507 --component-flags init $comp_file | wc -l)
2508 [ $found -eq 1 ] || error "write: Repeat comp incorrect"
2510 local ost_idx2=$($LFS getstripe --component-start=64m \
2511 --component-end=128m --component-flags=init \
2513 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2514 local mirror_id=$($LFS getstripe --component-start=64m \
2515 --component-end=128m --component-flags=init \
2516 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2517 [[ $mirror_id -eq 1 ]] ||
2518 error "component not in correct mirror: $mirror_id, not 1"
2520 $LFS mirror resync $comp_file
2522 $LFS getstripe $comp_file
2524 # component dimensions should not change from resync
2525 found=$($LFS find --component-start 0m --component-end 64m \
2526 --component-flags init $comp_file | wc -l)
2527 [ $found -eq 1 ] || error "resync: first comp incorrect"
2528 found=$($LFS find --component-start 64m --component-end 128m \
2529 --component-flags init $comp_file | wc -l)
2530 [ $found -eq 1 ] || error "resync: repeat comp incorrect"
2532 sel_layout_sanity $comp_file 5
2536 run_test 204d "FLR write/stale/resync sel test with repeated comp"
2538 # Successful repeated component, SEL in non-primary mirror
2540 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2541 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
2542 skip "skipped for lustre < $SEL_VERSION"
2544 local comp_file=$DIR/$tdir/$tfile
2547 wait_delete_completed
2550 test_mkdir $DIR/$tdir
2552 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2553 # space to -1 (-z 64M, so first comp is 0-64M)
2554 # Note: we have to place both 1st components on OST0, otherwise 2 OSTs
2555 # will be not enough - one will be degraded, the other is used on
2556 # an overlapping mirror.
2557 $LFS setstripe -N -E 100M -i 0 -E-1 -N -E-1 -i 0 -z 64M $comp_file ||
2558 error "Create $comp_file failed"
2560 local ost_idx1=$($LFS getstripe --component-start=0 \
2561 --component-end=64m -i $comp_file)
2562 local ost_name=$(ostname_from_index $ost_idx1)
2563 # degrade OST for first comp of 2nd mirror so we won't extend there
2564 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2565 obdfilter.$ost_name.degraded=1
2568 $LFS getstripe $comp_file
2570 # Write to first component, stale & instantiate second mirror components
2571 # overlapping with the written component (0-100M);
2572 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2575 do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2576 obdfilter.$ost_name.degraded=0
2578 $LFS getstripe $comp_file
2580 [ $RC -eq 0 ] || error "dd to repeat & stale failed"
2582 found=$($LFS find --component-start 0m --component-end 64m \
2583 --component-flags init,stale $comp_file | wc -l)
2584 [ $found -eq 1 ] || error "write: first comp incorrect"
2586 # was repeated due to degraded ost
2587 found=$($LFS find --component-start 64m --component-end 128m \
2588 --component-flags init,stale $comp_file | wc -l)
2589 [ $found -eq 1 ] || error "write: repeated comp incorrect"
2591 local ost_idx2=$($LFS getstripe --component-start=64m \
2592 --component-end=128m --component-flags=init \
2594 [[ $ost_idx1 -eq $ost_idx2 ]] && error "$ost_idx1 == $ost_idx2"
2595 local mirror_id=$($LFS getstripe --component-start=0m \
2596 --component-end=64m --component-flags=init \
2597 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2598 [[ $mirror_id -eq 2 ]] ||
2599 error "component not in correct mirror? $mirror_id"
2601 $LFS mirror resync $comp_file
2603 $LFS getstripe $comp_file
2605 # component dimensions should not change from resync
2606 found=$($LFS find --component-start 0m --component-end 64m \
2607 --component-flags init,^stale $comp_file | wc -l)
2608 [ $found -eq 1 ] || error "resync: first comp incorrect"
2609 found=$($LFS find --component-start 64m --component-end 128m \
2610 --component-flags init,^stale $comp_file | wc -l)
2611 [ $found -eq 1 ] || error "resync: repeated comp incorrect"
2613 sel_layout_sanity $comp_file 5
2617 run_test 204e "FLR write/stale/resync sel test with repeated comp"
2619 # FLR + SEL: failed repeated component, SEL in non-primary mirror
2621 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2622 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
2623 skip "skipped for lustre < $SEL_VERSION"
2625 local comp_file=$DIR/$tdir/$tfile
2628 wait_delete_completed
2630 test_mkdir $DIR/$tdir
2632 pool_add $TESTNAME || error "Pool creation failed"
2633 pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
2635 # first mirror is is 0-100M, then 100M-(-1), second mirror is extension
2636 # space to -1 (-z 64M, so first comp is 0-64M)
2637 $LFS setstripe -N -E 100M -E-1 -N --pool="$TESTNAME" \
2638 -E-1 -c 1 -z 64M $comp_file || error "Create $comp_file failed"
2640 local ost_name0=$(ostname_from_index 0)
2641 local ost_name1=$(ostname_from_index 1)
2643 # degrade both OSTs in pool, so we'll try to repeat, then fail and
2644 # extend original comp
2645 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=1
2646 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=1
2649 # a write to the 1st component, 100M length, which will try to stale
2650 # the first 100M of mirror 2, attempting to extend its 0-64M component
2651 dd if=/dev/zero bs=2M count=1 of=$comp_file conv=notrunc
2654 do_facet ost1 $LCTL set_param -n obdfilter.$ost_name0.degraded=0
2655 do_facet ost2 $LCTL set_param -n obdfilter.$ost_name1.degraded=0
2658 [ $RC -eq 0 ] || error "dd to extend mirror comp failed"
2660 $LFS getstripe $comp_file
2662 found=$($LFS find --component-start 0m --component-end 128m \
2663 --component-flags init,stale $comp_file | wc -l)
2664 [ $found -eq 1 ] || error "write: First mirror comp incorrect"
2666 local mirror_id=$($LFS getstripe --component-start=0m \
2667 --component-end=128m --component-flags=init \
2668 $comp_file | grep lcme_mirror_id | awk '{ print $2 }')
2670 [[ $mirror_id -eq 2 ]] ||
2671 error "component not in correct mirror? $mirror_id, not 2"
2673 $LFS mirror resync $comp_file
2675 $LFS getstripe $comp_file
2677 # component dimensions should not change from resync
2678 found=$($LFS find --component-start 0m --component-end 128m \
2679 --component-flags init,^stale $comp_file | wc -l)
2680 [ $found -eq 1 ] || error "resync: First mirror comp incorrect"
2682 sel_layout_sanity $comp_file 4
2686 run_test 204f "FLR write/stale/resync sel w/forced extension"
2689 check_and_cleanup_lustre