3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
9 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
12 # Bug number for skipped test: LU-11381
13 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT 201"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
17 . $LUSTRE/tests/test-framework.sh
19 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
23 { skip "Need MDS version at least 2.10.56"; exit 0; }
25 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
26 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
27 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
29 check_and_setup_lustre
36 rm -rf $DIR/[Rdfs][0-9]*
38 # global array to store mirror IDs
39 declare -a mirror_array
46 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
47 array[${#array[@]}]=$((id >> 16))
50 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
52 echo ${#mirror_array[@]}
56 echo 3 > /proc/sys/vm/drop_caches
67 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
75 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
76 error "start ost$idx failed"
80 wait_recovery_complete ost$idx
85 # Verify mirror count with an expected value for a given file.
87 verify_mirror_count() {
90 local mirror_count=$($LFS getstripe -N $tf)
92 [[ $mirror_count = $expected ]] || {
94 error "verify mirror count failed on $tf:" \
95 "$mirror_count != $expected"
100 # Verify component count with an expected value for a given file.
101 # $1 coposited layout file
102 # $2 expected component number
104 verify_comp_count() {
107 local comp_count=$($LFS getstripe --component-count $tf)
109 [[ $comp_count = $expected ]] || {
110 $LFS getstripe -v $tf
111 error "verify component count failed on $tf:" \
112 "$comp_count != $expected"
117 # Verify component attribute with an expected value for a given file
125 local cmd="$LFS getstripe -I$comp_id"
126 local getstripe_cmd="$cmd -v"
130 stripe-size) cmd+=" -S $tf" ;;
131 stripe-count) cmd+=" -c $tf" ;;
132 stripe-index) cmd+=" -i $tf" ;;
133 pool) cmd+=" -p $tf" ;;
134 comp-start) cmd+=" --component-start $tf" ;;
135 comp-end) cmd+=" --component-end $tf" ;;
136 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
137 *) error "invalid attribute $attr";;
142 [ $attr = lcme_flags ] && {
144 local expected_list=$(comma_list $expected)
145 for fl in ${expected_list//,/ }; do
148 [[ ${fl:0:1} = "^" ]] && neg=1
149 [[ $neg = 1 ]] && fl=${fl:1}
151 $(echo $value | grep -q $fl)
153 # 0: matched; 1: not matched
155 if [[ $neg = 0 && $match != 0 ||
156 $neg = 1 && $match = 0 ]]; then
158 [[ $neg = 0 ]] && # expect the flag
159 error "expected flag '$fl' not in $comp_id"
160 [[ $neg = 1 ]] && # not expect the flag
161 error "not expected flag '$fl' in $comp_id"
167 [[ $value = $expected ]] || {
169 error "verify $attr failed on $tf: $value != $expected"
174 # Verify component extent with expected start and end extent values
175 # for a given file and component ID.
177 verify_comp_extent() {
180 local expected_start=$3
181 local expected_end=$4
183 verify_comp_attr comp-start $tf $comp_id $expected_start
184 verify_comp_attr comp-end $tf $comp_id $expected_end
188 # Verify component attribute with parent directory for a given file
191 verify_comp_attr_with_parent() {
195 local td=$(cd $(dirname $tf); echo $PWD)
196 local tf_cmd="$LFS getstripe -I$comp_id"
197 local td_cmd="$LFS getstripe"
203 stripe-size) opt="-S" ;;
204 stripe-count) opt="-c" ;;
206 *) error "invalid attribute $attr";;
209 expected=$($td_cmd $opt $td)
210 [[ $expected = -1 ]] && expected=$OSTCOUNT
212 value=$($tf_cmd $opt $tf)
213 [[ $value = -1 ]] && value=$OSTCOUNT
215 [[ $value = $expected ]] || {
218 error "verify $attr failed with parent on $tf:" \
219 "$value != $expected"
224 # Verify component attribute with filesystem-wide default value for a given file
227 verify_comp_attr_with_default() {
231 local tf_cmd="$LFS getstripe -I$comp_id"
239 expected=$($LCTL get_param -n \
240 lov.$FSNAME-clilov-*.stripesize)
244 expected=$($LCTL get_param -n \
245 lov.$FSNAME-clilov-*.stripecount)
246 [[ $expected = -1 ]] && expected=$OSTCOUNT
248 *) error "invalid attribute $attr";;
251 value=$($tf_cmd $opt $tf)
252 [[ $value = -1 ]] && value=$OSTCOUNT
254 [[ $value = $expected ]] || {
256 error "verify $attr failed with default value on $tf:" \
257 "$value != $expected"
262 # Verify unspecified component attributes for a given file
265 # This will only verify the inherited attributes:
266 # stripe size, stripe count and OST pool name
268 verify_comp_attrs() {
272 verify_comp_attr_with_default stripe-size $tf $comp_id
273 verify_comp_attr_with_default stripe-count $tf $comp_id
274 verify_comp_attr_with_parent pool $tf $comp_id
277 # command line test cases
281 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
282 local mirror_cmd="$LFS mirror create"
287 # create parent directory
288 mkdir $td || error "mkdir $td failed"
290 $mirror_cmd $tf &> /dev/null && error "miss -N option"
292 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
293 verify_mirror_count $tf 1
294 id=$($LFS getstripe -I $tf)
295 verify_comp_attrs $tf $id
296 verify_comp_extent $tf $id 0 EOF
298 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
299 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
300 error "invalid mirror count $((mirror_count + 1))"
302 $mirror_cmd -N$mirror_count $tf-1 ||
303 error "create mirrored file $tf-1 failed"
304 verify_mirror_count $tf-1 $mirror_count
305 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
306 for ((i = 0; i < $mirror_count; i++)); do
307 verify_comp_attrs $tf-1 ${ids[$i]}
308 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
311 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
312 error "create mirrored file $tf-2 failed"
313 verify_mirror_count $tf-2 10
314 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
315 for ((i = 0; i < 10; i++)); do
316 verify_comp_attrs $tf-2 ${ids[$i]}
317 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
320 run_test 0a "lfs mirror create with -N option"
323 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
327 local mirror_cmd="$LFS mirror create"
331 # create a new OST pool
332 local pool_name=$TESTNAME
333 create_pool $FSNAME.$pool_name ||
334 error "create OST pool $pool_name failed"
336 # add OSTs into the pool
337 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
338 error "add OSTs into pool $pool_name failed"
340 # create parent directory
341 mkdir $td || error "mkdir $td failed"
342 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
343 error "$LFS setstripe $td failed"
345 # create a mirrored file with plain layout mirrors
346 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
347 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
348 error "create mirrored file $tf failed"
349 verify_mirror_count $tf 6
350 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
351 for ((i = 0; i < 6; i++)); do
352 verify_comp_extent $tf ${ids[$i]} 0 EOF
355 # verify component ${ids[0]}
356 verify_comp_attrs $tf ${ids[0]}
358 # verify component ${ids[1]}
359 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
360 verify_comp_attr stripe-count $tf ${ids[1]} 2
361 verify_comp_attr stripe-index $tf ${ids[1]} 2
362 verify_comp_attr pool $tf ${ids[1]} flash
364 # verify component ${ids[2]}
365 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
366 verify_comp_attr stripe-count $tf ${ids[2]} 2
367 verify_comp_attr pool $tf ${ids[2]} flash
369 # verify component ${ids[3]}
370 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
371 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
372 verify_comp_attr pool $tf ${ids[3]} flash
374 # verify component ${ids[4]}
375 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
376 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
377 verify_comp_attr pool $tf ${ids[4]} archive
379 # verify component ${ids[5]}
380 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
381 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
382 verify_comp_attr_with_parent pool $tf ${ids[5]}
387 run_test 0b "lfs mirror create plain layout mirrors"
390 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
394 local mirror_cmd="$LFS mirror create"
398 # create a new OST pool
399 local pool_name=$TESTNAME
400 create_pool $FSNAME.$pool_name ||
401 error "create OST pool $pool_name failed"
403 # add OSTs into the pool
404 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
405 error "add OSTs into pool $pool_name failed"
407 # create parent directory
408 mkdir $td || error "mkdir $td failed"
409 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
410 error "$LFS setstripe $td failed"
412 # create a mirrored file with composite layout mirrors
413 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
415 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
416 error "create mirrored file $tf failed"
417 verify_mirror_count $tf 6
418 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
420 # verify components ${ids[0]} and ${ids[2]}
422 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
423 verify_comp_attr stripe-count $tf ${ids[$i]} 2
424 verify_comp_attr stripe-index $tf ${ids[$i]} 1
425 verify_comp_attr pool $tf ${ids[$i]} flash
426 verify_comp_extent $tf ${ids[$i]} 0 4194304
429 # verify components ${ids[1]} and ${ids[3]}
431 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
432 verify_comp_attr stripe-count $tf ${ids[$i]} 2
433 verify_comp_attr pool $tf ${ids[$i]} flash
434 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
437 # verify component ${ids[4]}
438 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
439 verify_comp_attr stripe-count $tf ${ids[4]} 4
440 verify_comp_attr_with_parent pool $tf ${ids[4]}
441 verify_comp_extent $tf ${ids[4]} 0 EOF
443 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
445 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
446 verify_comp_attr stripe-count $tf ${ids[$i]} 4
447 verify_comp_attr pool $tf ${ids[$i]} archive
448 verify_comp_extent $tf ${ids[$i]} 0 536870912
451 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
453 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
454 verify_comp_attr stripe-count $tf ${ids[$i]} -1
455 verify_comp_attr pool $tf ${ids[$i]} archive
456 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
462 run_test 0c "lfs mirror create composite layout mirrors"
467 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
468 local mirror_cmd="$LFS mirror extend"
472 # create parent directory
473 mkdir $td || error "mkdir $td failed"
475 $mirror_cmd $tf &> /dev/null && error "miss -N option"
476 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
478 # create a non-mirrored file, convert it to a mirrored file and extend
479 touch $tf || error "touch $tf failed"
480 $mirror_cmd -N $tf || error "convert and extend $tf failed"
481 verify_mirror_count $tf 2
482 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
483 for ((i = 0; i < 2; i++)); do
484 verify_comp_attrs $tf ${ids[$i]}
485 verify_comp_extent $tf ${ids[$i]} 0 EOF
488 lfsck_verify_pfid $tf || error "PFID is not set"
490 # create a mirrored file and extend it
491 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
492 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
494 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
495 error "setstripe options should not be specified with -f option"
497 $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
498 error "extend mirrored file $tf-1 failed"
499 verify_mirror_count $tf-1 $mirror_count
500 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
501 for ((i = 0; i < $mirror_count; i++)); do
502 verify_comp_attrs $tf-1 ${ids[$i]}
503 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
506 $mirror_cmd -N $tf-1 &> /dev/null &&
507 error "exceeded maximum mirror count $mirror_count" || true
509 run_test 0d "lfs mirror extend with -N option"
512 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
516 local mirror_cmd="$LFS mirror extend"
520 # create parent directory
521 mkdir $td || error "mkdir $td failed"
523 # create a mirrored file with plain layout mirrors
524 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
525 error "create mirrored file $tf failed"
527 # extend the mirrored file with plain layout mirrors
528 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
529 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
530 error "extend mirrored file $tf failed"
531 verify_mirror_count $tf 6
532 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
533 for ((i = 0; i < 6; i++)); do
534 verify_comp_extent $tf ${ids[$i]} 0 EOF
537 # verify component ${ids[0]}
538 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
539 verify_comp_attr stripe-count $tf ${ids[0]} 3
540 verify_comp_attr stripe-index $tf ${ids[0]} 1
541 verify_comp_attr pool $tf ${ids[0]} ssd
543 # verify component ${ids[1]}
544 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
545 verify_comp_attr stripe-count $tf ${ids[1]} 2
546 verify_comp_attr stripe-index $tf ${ids[1]} 2
547 verify_comp_attr pool $tf ${ids[1]} flash
549 # verify component ${ids[2]}
550 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
551 verify_comp_attr stripe-count $tf ${ids[2]} 2
552 verify_comp_attr pool $tf ${ids[2]} flash
554 # verify component ${ids[3]}
555 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
556 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
557 verify_comp_attr pool $tf ${ids[3]} flash
559 # verify component ${ids[4]}
560 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
561 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
562 verify_comp_attr pool $tf ${ids[4]} archive
564 # verify component ${ids[5]}
565 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
566 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
567 verify_comp_attr_with_parent pool $tf ${ids[5]}
569 run_test 0e "lfs mirror extend plain layout mirrors"
572 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
576 local mirror_cmd="$LFS mirror extend"
580 # create parent directory
581 mkdir $td || error "mkdir $td failed"
583 # create a mirrored file with composite layout mirror
584 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
585 error "create mirrored file $tf failed"
587 # extend the mirrored file with composite layout mirrors
588 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
590 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
591 error "extend mirrored file $tf failed"
592 verify_mirror_count $tf 7
593 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
595 # verify component ${ids[0]}
596 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
597 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
598 verify_comp_attr pool $tf ${ids[0]} ssd
599 verify_comp_extent $tf ${ids[0]} 0 33554432
601 # verify component ${ids[1]}
602 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
603 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
604 verify_comp_attr pool $tf ${ids[1]} ssd
605 verify_comp_extent $tf ${ids[1]} 33554432 EOF
607 # verify components ${ids[2]} and ${ids[4]}
609 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
610 verify_comp_attr stripe-count $tf ${ids[$i]} 2
611 verify_comp_attr stripe-index $tf ${ids[$i]} 1
612 verify_comp_attr pool $tf ${ids[$i]} flash
613 verify_comp_extent $tf ${ids[$i]} 0 4194304
616 # verify components ${ids[3]} and ${ids[5]}
618 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
619 verify_comp_attr stripe-count $tf ${ids[$i]} 2
620 verify_comp_attr pool $tf ${ids[$i]} flash
621 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
624 # verify component ${ids[6]}
625 verify_comp_attr stripe-size $tf ${ids[6]} 4194304
626 verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
627 verify_comp_attr_with_parent pool $tf ${ids[6]}
628 verify_comp_extent $tf ${ids[6]} 0 EOF
630 # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
632 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
633 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
634 verify_comp_attr pool $tf ${ids[$i]} archive
635 verify_comp_extent $tf ${ids[$i]} 0 536870912
638 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
640 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
641 verify_comp_attr stripe-count $tf ${ids[$i]} -1
642 verify_comp_attr pool $tf ${ids[$i]} archive
643 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
646 run_test 0f "lfs mirror extend composite layout mirrors"
651 $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
652 -N -o1 $tf || error "create mirrored file $tf failed"
654 verify_comp_attr lcme_flags $tf 0x10001 prefer
655 verify_comp_attr lcme_flags $tf 0x10002 prefer
657 # write to the mirrored file and check primary
658 cp /etc/hosts $tf || error "error writing file '$tf'"
660 verify_comp_attr lcme_flags $tf 0x20003 stale
662 # resync file and check prefer flag
663 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
666 $LCTL set_param osc.*.stats=clear
667 cat $tf &> /dev/null || error "error reading file '$tf'"
669 # verify that the data was provided by OST1 where mirror 1 resides
670 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-ffff*.stats |
671 awk '/ost_read/{print $2}')
672 [ -n "$nr_read" ] || error "read was not provided by OST1"
674 run_test 0g "lfs mirror create flags support"
682 # create parent directory
683 test_mkdir $td || error "mkdir $td failed"
685 $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
686 error "set default mirrored layout on directory $td failed"
688 # verify flags are inherited from the directory
691 verify_comp_attr lcme_flags $tf 0x10001 prefer
692 verify_comp_attr lcme_flags $tf 0x10002 prefer
694 # set flags to the first component
695 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
697 verify_comp_attr lcme_flags $tf 0x10001 stale
698 verify_comp_attr lcme_flags $tf 0x10002 prefer
700 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
701 error "clearing 'stale' should fail"
703 # write and resync file. It can't resync the file directly because the
704 # file state is still 'ro'
705 cp /etc/hosts $tf || error "error writing file '$tf'"
706 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
708 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
709 error "error setting flag prefer"
711 verify_comp_attr lcme_flags $tf 0x20003 prefer
713 run_test 0h "set, clear and test flags for FLR files"
717 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
718 local mirror_create_cmd="$LFS mirror create"
719 local stripes[0]=$OSTCOUNT
721 mirror_create_cmd+=" -N -c ${stripes[0]}"
722 for ((i = 1; i < $mirror_count; i++)); do
723 # add mirrors with different stripes to the file
724 stripes[$i]=$((RANDOM % OSTCOUNT))
725 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
727 mirror_create_cmd+=" -N -c ${stripes[$i]}"
730 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
731 verify_mirror_count $tf $mirror_count
733 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
734 $LFS mirror extend -N $tf &&
735 error "Creating the $((mirror_count+1))th mirror succeeded"
737 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
740 # verify the range of components and stripe counts
741 for ((i = 0; i < $mirror_count; i++)); do
742 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
743 verify_comp_extent $tf ${ids[$i]} 0 EOF
746 run_test 1 "create components with setstripe options"
750 local tf2=$DIR/$tfile-2
752 $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
753 $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
755 $LFS mirror extend -N -f $tf2 $tf ||
756 error "merging $tf2 into $tf failed"
758 verify_mirror_count $tf 2
759 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
761 run_test 2 "create components from existing files"
764 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
766 for ((i = 0; i < 2; i++)); do
767 $LFS mkdir -i $i $DIR/$tdir-$i
768 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
771 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
772 $DIR/$tdir-0/$tfile || error "creating mirrors"
774 # mdt doesn't support to cancel layout lock for remote objects, do
778 # make sure the mirrorted file was created successfully
779 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
780 { $LFS getstripe $DIR/$tdir-0/$tfile;
781 error "expected 2 components"; }
786 run_test 3 "create components from files located on different MDTs"
789 local tf=$DIR/$tdir/$tfile
792 test_mkdir $DIR/$tdir
794 # set mirror with setstripe options to directory
795 $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
796 error "set mirror to directory error"
798 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
799 x"mirrored" ] || error "failed to create mirrored dir"
802 verify_mirror_count $tf 2
804 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
805 verify_comp_extent $tf ${ids[0]} 0 1048576
806 verify_comp_extent $tf ${ids[1]} 1048576 EOF
808 # sub directory should inherit mirror setting from parent
809 test_mkdir $DIR/$tdir/td
810 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
811 x"mirrored" ] || error "failed to inherit mirror from parent"
813 # mirror extend won't be applied to directory
814 $LFS mirror extend -N2 $DIR/$tdir &&
815 error "expecting mirror extend failure"
818 run_test 4 "Make sure mirror attributes can be inhertied from directory"
824 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
825 error "failed to create file with non-empty layout"
826 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
828 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
829 verify_mirror_count $tf 3
831 $CHECKSTAT -t file -s 12345 $tf ||
832 error "size error after attaching layout "
834 run_test 5 "Make sure init size work for mirrored layout"
836 # LU=10112: disable dom+flr for phase 1
840 $LFS mirror create -N -E 1M -S 1M -L mdt -E eof -N -E eof $tf &&
841 error "expect failure to create mirrored file with DoM"
843 $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf &&
844 error "expect failure to create mirrored file with DoM"
846 $LFS setstripe -E 1M -S 1M -L mdt -E eof $tf
847 $LFS mirror extend -N2 $tf &&
848 error "expect failure to extend mirror with DoM"
850 $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2
851 $LFS mirror extend -N -f $tf $tf-2 &&
852 error "expect failure to extend mirrored file with DoM extent"
856 run_test 6 "DoM and FLR won't co-exist for phase 1"
860 local tf2=$DIR/$tfile-2
862 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
864 $LFS setstripe -E EOF -o 0 $tf
865 $LFS setstripe -E EOF -o 1 $tf2
867 local dd_count=$((RANDOM % 20 + 1))
868 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
869 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
871 # for zfs - sync OST dataset so that du below will return
873 [ "$FSTYPE" = "zfs" ] &&
874 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
876 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
879 $LFS mirror extend -N -f $tf2 $tf ||
880 error "merging $tf2 into $tf failed"
885 local new_blocks=$(du -k $tf | awk '{print $1}')
886 [ $new_blocks -eq $blocks ] ||
887 error "i_blocks error expected: $blocks, actual: $new_blocks"
889 run_test 21 "glimpse should report accurate i_blocks"
891 get_osc_lock_count() {
898 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'ffff*'
899 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
900 lock_count=$((lock_count + count))
908 $LFS setstripe -E EOF -o 0 $tf
909 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
911 # add component, two mirrors located on the same OST ;-)
912 $LFS mirror extend -N -o 0 $tf ||
913 error "extending mirrored file $tf failed"
915 size_blocks=$(stat --format="%b %s" $tf)
920 local new_size_blocks=$(stat --format="%b %s" $tf)
922 # make sure there is no lock cached
923 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
925 [ "$new_size_blocks" = "$size_blocks" ] ||
926 echo "size expected: $size_blocks, actual: $new_size_blocks"
930 run_test 22 "no glimpse to OSTs for READ_ONLY files"
935 $LFS mirror create -N -o 0 -N -o 1 $tf ||
936 error "creating mirrored file $tf failed"
938 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
939 $LCTL set_param fail_loc=0x1A00
942 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
946 local tmpfile=$(mktemp)
947 stat --format="%b %s" $tf > $tmpfile &
951 while [ $cnt -le 5 ]; do
952 kill -0 $pid > /dev/null 2>&1 || break
956 kill -0 $pid > /dev/null 2>&1 &&
957 error "stat process stuck due to unavailable OSTs"
959 # make sure glimpse request has been sent
960 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
961 error "OST $ost_idx: no glimpse request was sent"
966 run_test 31 "make sure glimpse request can be retried"
969 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
970 rm -f $DIR/$tfile $DIR/$tfile-2
972 $LFS setstripe -E EOF -o 0 $DIR/$tfile
973 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
975 local fsize=$(stat -c %s $DIR/$tfile)
976 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
978 local cksum=$(md5sum $DIR/$tfile)
980 # create a new mirror in sync mode
981 $LFS mirror extend -N -o 1 $DIR/$tfile ||
982 error "extending mirrored file $DIR/$tfile failed"
984 # make sure the mirrored file was created successfully
985 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
986 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
991 # check size is correct, glimpse request should go to the 2nd mirror
992 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
993 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
995 echo "reading file from the 2nd mirror and verify checksum"
996 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
997 error "checksum error: expected $cksum"
1001 run_test 32 "data should be mirrored to newly created mirror"
1004 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1006 rm -f $DIR/$tfile $DIR/$tfile-2
1008 # create a file with two mirrors
1009 $LFS setstripe -E EOF -o 0 $DIR/$tfile
1012 while [ $count -lt $max_count ]; do
1013 echo "ost1" >> $DIR/$tfile
1014 count=$((count + 1));
1017 # tmp file that will be used as mirror
1018 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1020 while [ $count -lt $max_count ]; do
1021 echo "ost2" >> $DIR/$tfile-2
1022 count=$((count + 1));
1025 # create a mirrored file
1026 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1027 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1028 "with verification should fail"
1029 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1030 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1031 "without verification failed"
1033 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1034 [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1035 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1037 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1039 # execpted file size
1040 local fsize=$((5 * max_count))
1041 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1042 error "mirrored file size is not $fsize"
1044 # read file - all OSTs are available
1045 echo "reading file (data can be provided by any ost)... "
1046 local rs=$(cat $DIR/$tfile | head -1)
1047 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1048 error "file content error: expected: \"ost1\" or \"ost2\""
1050 # read file again with ost1 failed
1054 echo "reading file (data should be provided by ost2)..."
1055 local rs=$(cat $DIR/$tfile | head -1)
1056 [[ "$rs" == "ost2" ]] ||
1057 error "file content error: expected: \"ost2\", actual: \"$rs\""
1062 # read file again with ost2 failed
1063 $LCTL set_param ldlm.namespaces.lustre-*-osc-ffff*.lru_size=clear
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\""
1077 wait_osc_import_state client ost2 FULL
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 local tf=$DIR/$tfile
1274 local tf2=$DIR/$tfile-2
1275 local tf3=$DIR/$tfile-3
1277 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1279 # assume the mirror id will be 1, 2, and 3
1280 declare -A checksums
1281 checksums[1]=$(cat $tf | md5sum)
1282 checksums[2]=$(cat $tf2 | md5sum)
1283 checksums[3]=$(cat $tf3 | md5sum)
1285 printf '%s\n' "${checksums[@]}"
1287 # merge these files into a mirrored file
1288 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1289 error "merging $tf2 into $tf failed"
1290 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1291 error "merging $tf3 into $tf failed"
1295 # verify mirror read, checksums should equal to the original files'
1296 echo "Verifying mirror read .."
1299 for i in ${mirror_array[@]}; do
1300 sum=$($LFS mirror dump -N $i $tf | md5sum)
1301 [ "$sum" = "${checksums[$i]}" ] ||
1302 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1305 # verify mirror copy, write to this mirrored file will invalidate
1306 # the other two mirrors
1307 echo "Verifying mirror copy .."
1309 local osts=$(comma_list $(osts_nodes))
1311 # define OBD_FAIL_OST_SKIP_LV_CHECK 0x241
1312 do_nodes $osts lctl set_param fail_loc=0x241
1314 mirror_io copy -i ${mirror_array[0]} \
1315 -t $(echo ${mirror_array[@]:1} | tr ' ' ',') $tf ||
1316 error "mirror copy error"
1318 do_nodes $osts lctl set_param fail_loc=0
1320 # verify copying is successful by checking checksums
1321 remount_client $MOUNT
1322 for i in ${mirror_array[@]}; do
1323 sum=$($LFS mirror dump -N $i $tf | md5sum)
1324 [ "$sum" = "${checksums[1]}" ] ||
1325 error "$i: mismatch checksum after copy"
1330 run_test 37 "mirror I/O API verification"
1335 local expected_state=$2
1337 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
1338 [ $expected_state = $state ] ||
1339 error "expected: $expected_state, actual $state"
1343 local tf=$DIR/$tfile
1344 local ref=$DIR/${tfile}-ref
1346 $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1347 error "creating $tf failed"
1348 $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1349 $tf-2 || error "creating $tf-2 failed"
1350 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1351 error "creating $tf-3 failed"
1353 # instantiate all components
1354 $LFS mirror extend -N -f $tf-2 $tf ||
1355 error "merging $tf-2 into $tf failed"
1356 $LFS mirror extend -N -f $tf-3 $tf ||
1357 error "merging $tf-3 into $tf failed"
1358 $LFS mirror extend -N -c 1 $tf ||
1359 error "extending mirrored file $tf failed"
1361 verify_flr_state $tf "ro"
1363 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1365 local fsize=$((RANDOM << 8 + 1048576))
1366 $TRUNCATE $ref $fsize
1368 local ref_cksum=$(cat $ref | md5sum)
1370 # case 1: verify write to mirrored file & resync work
1371 cp $ref $tf || error "copy from $ref to $f error"
1372 verify_flr_state $tf "wp"
1374 local file_cksum=$(cat $tf | md5sum)
1375 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1378 echo "mirror IDs: ${mirror_array[@]}"
1380 local valid_mirror stale_mirror id mirror_cksum
1381 for id in "${mirror_array[@]}"; do
1382 mirror_cksum=$($LFS mirror dump -N $id $tf | md5sum)
1383 [ "$ref_cksum" == "$mirror_cksum" ] &&
1384 { valid_mirror=$id; continue; }
1389 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1390 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1392 mirror_io resync $tf || error "resync failed"
1393 verify_flr_state $tf "ro"
1395 mirror_cksum=$($LFS mirror dump -N $stale_mirror $tf | md5sum)
1396 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1398 # case 2: inject an error to make mirror_io exit after changing
1399 # the file state to sync_pending so that we can start a concurrent
1401 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1402 verify_flr_state $tf "wp"
1404 mirror_io resync -e resync_start $tf && error "resync succeeded"
1405 verify_flr_state $tf "sp"
1407 # from sync_pending to write_pending
1408 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1409 verify_flr_state $tf "wp"
1411 mirror_io resync -e resync_start $tf && error "resync succeeded"
1412 verify_flr_state $tf "sp"
1414 # from sync_pending to read_only
1415 mirror_io resync $tf || error "resync failed"
1416 verify_flr_state $tf "ro"
1418 run_test 38 "resync"
1421 local tf=$DIR/$tfile
1424 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1425 error "create PFL file $tf failed"
1427 verify_mirror_count $tf 2
1428 verify_comp_count $tf 4
1430 rm -f $tf || error "delete $tf failed"
1432 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1435 local tf=$DIR/$tfile
1438 for ops in "conv=notrunc" ""; do
1441 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1442 -N -E 1M -E 2M -E 4M -E -1 $tf ||
1443 error "create PFLR file $tf failed"
1444 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1445 error "write PFLR file $tf failed"
1447 lfs getstripe -vy $tf
1451 # file mirror state should be write_pending
1452 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1454 error "file mirror state $flags"
1455 # the 1st component (in mirror 1) should be inited
1456 verify_comp_attr lcme_flags $tf 0x10001 init
1457 # the 2nd component (in mirror 1) should be inited
1458 verify_comp_attr lcme_flags $tf 0x10002 init
1459 # the 3rd component (in mirror 1) should be uninited
1460 verify_comp_attr lcme_flags $tf 0x10003 prefer
1461 # the 4th component (in mirror 2) should be inited
1462 verify_comp_attr lcme_flags $tf 0x20004 init
1463 # the 5th component (in mirror 2) should be uninited
1464 verify_comp_attr lcme_flags $tf 0x20005 0
1465 # the 6th component (in mirror 2) should be stale
1466 verify_comp_attr lcme_flags $tf 0x20006 stale
1467 # the 7th component (in mirror 2) should be uninited
1468 if [[ x$ops = "xconv=notrunc" ]]; then
1469 verify_comp_attr lcme_flags $tf 0x20007 0
1470 elif [[ x$ops = "x" ]]; then
1471 verify_comp_attr lcme_flags $tf 0x20007 stale
1475 rm -f $tf || error "delete $tf failed"
1477 run_test 40 "PFLR rdonly state instantiation check"
1480 local tf=$DIR/$tfile
1483 echo " **create two FLR files $tf $tf-1"
1484 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1485 -N -E 1M -E 2M -E 3M -E -1 $tf ||
1486 error "create PFLR file $tf failed"
1487 $LFS mirror create -N -E 2M -S 1M -E eof \
1488 -N -E 1M -E eof --flags prefer \
1489 -N -E 4m -E eof $tf-1 ||
1490 error "create PFLR file $tf-1 failed"
1492 # file should be in ro status
1493 echo " **verify files be RDONLY"
1494 verify_flr_state $tf "ro"
1495 verify_flr_state $tf-1 "ro"
1497 # write data in [0, 2M)
1498 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1499 error "writing $tf failed"
1500 dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1501 error "writing $tf-1 failed"
1503 local sum0=$(cat $tf-1 | md5sum)
1505 echo " **verify files be WRITE_PENDING"
1506 verify_flr_state $tf "wp"
1507 verify_flr_state $tf-1 "wp"
1509 # file should have stale component
1510 echo " **verify files have stale component"
1511 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1512 error "after writing $tf, it does not contain stale component"
1513 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1514 error "after writing $tf-1, it does not contain stale component"
1516 echo " **full resync"
1517 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1519 echo " **verify $tf-1 data consistency in all mirrors"
1521 local sum=$($LFS mirror dump -N$i $tf-1 | md5sum)
1522 [[ "$sum" = "$sum0" ]] ||
1523 error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1526 echo " **verify files be RDONLY"
1527 verify_flr_state $tf "ro"
1528 verify_flr_state $tf-1 "ro"
1530 # file should not have stale component
1531 echo " **verify files do not contain stale component"
1532 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1533 error "after resyncing $tf, it contains stale component"
1534 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1535 error "after resyncing $tf, it contains stale component"
1537 # verify partial resync
1538 echo " **write $tf-1 for partial resync test"
1539 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1540 error "writing $tf-1 failed"
1542 echo " **only resync mirror 2"
1543 verify_flr_state $tf-1 "wp"
1544 $LFS mirror resync --only 2 $tf-1 ||
1545 error "resync mirror 2 of $tf-1 failed"
1546 verify_flr_state $tf "ro"
1548 # resync synced mirror
1549 echo " **resync mirror 2 again"
1550 $LFS mirror resync --only 2 $tf-1 ||
1551 error "resync mirror 2 of $tf-1 failed"
1552 verify_flr_state $tf "ro"
1553 echo " **verify $tf-1 contains stale component"
1554 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1555 error "after writing $tf-1, it does not contain stale component"
1557 echo " **full resync $tf-1"
1558 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1559 verify_flr_state $tf "ro"
1560 echo " **full resync $tf-1 again"
1561 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1562 echo " **verify $tf-1 does not contain stale component"
1563 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1564 error "after resyncing $tf, it contains stale component"
1568 run_test 41 "lfs mirror resync check"
1571 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1575 local mirror_cmd="$LFS mirror verify"
1578 # create parent directory
1579 mkdir $td || error "mkdir $td failed"
1581 $mirror_cmd &> /dev/null && error "no file name given"
1582 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1583 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1585 # create mirrored files
1586 $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1587 error "create mirrored file $tf failed"
1588 $LFS mirror create -N -E 2M -S 1M -E EOF \
1589 -N -E 6M -E 8M -E EOF \
1590 -N -E 16M -E EOF $tf-1 ||
1591 error "create mirrored file $tf-1 failed"
1592 $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1593 error "create mirrored file $tf-2 failed"
1595 # write data in [0, 10M)
1596 for i in $tf $tf-1 $tf-2; do
1597 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1598 error "write $i failed"
1601 # resync the mirrored files
1602 $LFS mirror resync $tf-1 $tf-2 ||
1603 error "resync $tf-1 $tf-2 failed"
1605 # verify the mirrored files
1606 $mirror_cmd $tf-1 $tf-2 ||
1607 error "verify $tf-1 $tf-2 failed"
1609 get_mirror_ids $tf-1
1610 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1611 error "at least 2 mirror ids needed with '--only' option"
1612 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1614 error "'--only' option cannot be used upon multiple files"
1615 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1616 error "invalid specified mirror ids"
1618 # change the content of $tf and merge it into $tf-1
1620 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1621 error "change $tf with seek=$i failed"
1622 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1623 error "change $tf-1 with seek=$i failed"
1626 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1627 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1628 error "merge $tf into $tf-1 failed"
1630 # verify the mirrored files
1631 echo "Verify $tf-1 without -v option:"
1632 $mirror_cmd $tf-1 &&
1633 error "verify $tf-1 should fail" || echo "PASS"
1635 echo "Verify $tf-1 with -v option:"
1636 $mirror_cmd -v $tf-1 &&
1637 error "verify $tf-1 should fail"
1639 get_mirror_ids $tf-1
1640 echo "Verify $tf-1 with --only option:"
1641 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1642 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1643 "${mirror_array[-1]} should fail"
1645 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1646 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1647 "${mirror_array[1]} should succeed"
1649 # set stale components in $tf-1
1650 for i in 0x40002 0x40003; do
1651 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1652 error "set stale flag on component $i failed"
1655 # verify the mirrored file
1656 echo "Verify $tf-1 with stale components:"
1657 $mirror_cmd -vvv $tf-1 ||
1658 error "verify $tf-1 with stale components should succeed"
1660 echo "Verify $tf-1 with stale components and --only option:"
1661 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1662 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1663 "${mirror_array[-1]} should succeed"
1665 run_test 42 "lfs mirror verify"
1667 # inactivate one OST && write && restore the OST
1671 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1674 wait=$(do_facet $SINGLEMDS \
1675 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1676 wait=${wait%%[^0-9]*}
1678 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1679 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1680 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1681 sleep $(($wait * 2 + 2))
1682 echo " **write $file"
1683 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1684 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1685 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1686 sleep $((wait * 2 + 2))
1688 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1689 [ $flags = wp ] || error "file mirror state $flags != wp"
1693 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1695 local tf=$DIR/$tfile
1699 ## mirror 0 ost (0, 1)
1700 ## mirror 1 ost (1, 2)
1701 ## mirror 2 ost (2, 0)
1702 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1703 -N -Eeof -c2 -o2,0 $tf ||
1704 error "create 3 mirrors file $tf failed"
1706 ################## OST0 ###########################################
1708 echo " **verify components"
1709 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1710 verify_comp_attr lcme_flags $tf 0x20002 init
1711 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1714 echo " **resync $tf"
1715 $LFS mirror resync $tf
1716 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1717 [ $flags = ro ] || error "file mirror state $flags != ro"
1719 ################## OST1 ###########################################
1721 echo " **verify components"
1722 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1723 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1724 verify_comp_attr lcme_flags $tf 0x30003 init
1727 echo " **resync $tf"
1728 $LFS mirror resync $tf
1729 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1730 [ $flags = ro ] || error "file mirror state $flags != ro"
1732 ################## OST2 ###########################################
1734 echo " **verify components"
1735 verify_comp_attr lcme_flags $tf 0x10001 init
1736 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1737 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1739 run_test 43 "mirror pick on write"
1742 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1745 local tf=$DIR/$tdir/$tfile
1746 local tf1=$DIR/$tdir-1/$tfile-1
1748 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1749 error "create directory failed"
1750 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1751 error "create remote directory failed"
1752 rm -f $tf $tf1 $tf.mirror~2
1753 # create file with 4 mirrors
1754 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1755 -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
1756 error "create PFLR file $tf failed"
1758 # file should be in ro status
1759 verify_flr_state $tf "ro"
1761 # write data in [0, 3M)
1762 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1763 error "writing $tf failed"
1765 verify_flr_state $tf "wp"
1767 # synchronize all mirrors of the file
1768 $LFS mirror resync $tf || error "mirror resync $tf failed"
1770 verify_flr_state $tf "ro"
1773 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1774 error "split to $tf1 failed"
1776 local idx0=$($LFS getstripe -m $tf)
1777 local idx1=$($LFS getstripe -m $tf1)
1779 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1780 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1782 # verify mirror count
1783 verify_mirror_count $tf 3
1784 verify_mirror_count $tf1 1
1786 $LFS mirror split --mirror-id 2 $tf ||
1787 error "split mirror 2 failed"
1789 verify_mirror_count $tf 2
1790 verify_mirror_count $tf.mirror~2 1
1792 $LFS mirror split --mirror-id 3 -d $tf ||
1793 error "split and delte mirror 3 failed"
1794 verify_mirror_count $tf 1
1796 # verify splitted file contains the same content as the orig file does
1797 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
1798 diff $tf $tf.mirror~2 ||
1799 error "splited file $tf.mirror~2 diffs from $tf"
1801 run_test 44 "lfs mirror split check"
1804 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1806 local file=$DIR/$tdir/$tfile
1807 local dir=$DIR/$tdir/$dir
1808 local temp=$DIR/$tdir/template
1810 test_mkdir $DIR/$tdir
1812 $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1813 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
1814 error "Create $file failed"
1816 echo "getstripe --yaml $file"
1817 $LFS getstripe --yaml $file > $temp || error "getstripe $file failed"
1818 echo "setstripe --yaml=$temp $file.2"
1819 $LFS setstripe --yaml=$temp $file.2 || error "setstripe $file.2 failed"
1821 echo "compare layout"
1822 local layout1=$(get_layout_param $file)
1823 local layout2=$(get_layout_param $file.2)
1824 [ "$layout1" == "$layout2" ] ||
1825 error "FLR file $file/$file.2 layouts are not equal"
1827 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
1834 $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
1836 local layout1=$(get_layout_param $src)
1837 local layout2=$(get_layout_param $dst)
1838 # compare their layout info
1839 [ "$layout1" == "$layout2" ] ||
1840 error "$msg_prefix $src <=> $dst layouts are not equal"
1844 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1846 local file=$DIR/$tdir/$tfile
1847 test_mkdir $DIR/$tdir
1849 ########################### 1. PFL file #############################
1850 echo " ** 1. PFL file"
1852 $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
1853 $file || error "1. Create PFL $file failed"
1856 verify_46 $file $file.copy "1. PFL file"
1858 ########################### 2. plain file ###########################
1859 echo " ** 2. plain file"
1861 $LFS setstripe -c2 -o0,1 -i1 $file ||
1862 error "2. Create plain $file failed"
1865 verify_46 $file $file.copy "2. plain file"
1867 ########################### 3. FLR file #############################
1868 echo " ** 3. FLR file"
1869 $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
1870 $file || error "3. Create FLR $file failed"
1873 verify_46 $file $file.copy "3. FLR file"
1875 local dir=$DIR/$tdir/dir
1876 ########################### 4. PFL dir ##############################
1877 echo " ** 4. PFL dir"
1879 $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
1880 error "4. setstripe PFL $dir failed"
1882 test_mkdir $dir.copy
1883 verify_46 $dir $dir.copy "4. PFL dir"
1885 ########################### 5. plain dir ############################
1886 echo " ** 5. plain dir"
1887 $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
1889 verify_46 $dir $dir.copy "5. plain dir"
1891 ########################### 6. FLR dir ##############################
1892 echo " ** 6. FLR dir"
1893 $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
1894 error "6. setstripe FLR $dir failed"
1896 verify_46 $dir $dir.copy "6. FLR dir"
1898 run_test 46 "Verify setstripe --copy option"
1901 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1903 local file=$DIR/$tdir/$tfile
1908 test_mkdir $DIR/$tdir
1912 # mirror1: [comp0]ost0, [comp1]ost1 and ost2
1913 # mirror2: [comp2] , [comp3] should not use ost1 or ost2
1914 $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
1915 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
1916 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1918 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
1919 $LFS mirror resync $file || error "resync $file failed"
1921 ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
1922 if [[ x$ost == "x0," ]]; then
1923 $LFS getstripe $file
1924 error "component ${ids[2]} objects allocated on $ost " \
1928 ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
1929 if [[ x$ost == "x1," || x$ost == "x2," ]]; then
1930 $LFS getstripe $file
1931 error "component ${ids[3]} objects allocated on $ost " \
1932 "shouldn't on OST1 or on OST2"
1937 # mirror1: [comp0] [comp1]
1938 # mirror2: [comp2] [comp3]
1939 # mirror3: [comp4] [comp5]
1940 # mirror4: [comp6] [comp7]
1941 $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
1942 error "create FLR $file failed"
1943 ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1945 dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
1946 $LFS mirror resync $file || error "resync $file failed"
1948 for ((i = 0; i < 6; i++)); do
1949 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
1950 awk '/l_ost_idx/{print $5}')
1952 # comp[0],comp[2],comp[4] should use different osts
1953 if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
1954 ${osts[2]} == ${osts[4]} ]]; then
1955 $LFS getstripe $file
1956 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
1957 "allocated on duplicated OSTs"
1959 # comp[1],comp[3],comp[5] should use different osts
1960 if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
1961 ${osts[3]} == ${osts[5]} ]]; then
1962 $LFS getstripe $file
1963 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
1964 "allocated on duplicated OSTs"
1969 run_test 47 "Verify mirror obj alloc"
1972 local tf=$DIR/$tfile
1975 echo " ** create 2 mirrors FLR file $tf"
1976 $LFS mirror create -N -E2M -Eeof --flags prefer \
1977 -N -E1M -Eeof $tf ||
1978 error "create FLR file $tf failed"
1981 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
1982 verify_flr_state $tf "wp"
1984 local sum0=$(md5sum < $tf)
1986 echo " ** resync the file"
1987 $LFS mirror resync $tf
1989 echo " ** snapshot mirror 2"
1990 $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
1992 echo " ** write it again"
1993 dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
1994 echo " ** resync it again"
1995 $LFS mirror resync $tf
1997 verify_flr_state $tf "wp"
1998 verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2000 local sum1=$($LFS mirror dump -N1 $tf | md5sum)
2001 local sum2=$($LFS mirror dump -N2 $tf | md5sum)
2003 echo " ** verify mirror 2 doesn't change"
2004 echo "original checksum: $sum0"
2005 echo "mirror 1 checksum: $sum1"
2006 echo "mirror 2 checksum: $sum2"
2007 [[ $sum0 = $sum2 ]] ||
2008 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2009 echo " ** mirror 2 stripe info"
2010 $LFS getstripe -v --mirror-index=2 $tf
2012 echo " ** resync mirror 2"
2013 $LFS mirror resync --only 2 $tf
2015 verify_flr_state $tf "ro"
2016 verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2018 sum1=$($LFS mirror dump -N1 $tf | md5sum)
2019 sum2=$($LFS mirror dump -N2 $tf | md5sum)
2021 echo " ** verify mirror 2 resync-ed"
2022 echo "original checksum: $sum0"
2023 echo "mirror 1 checksum: $sum1"
2024 echo "mirror 2 checksum: $sum2"
2025 [[ $sum1 = $sum2 ]] ||
2026 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2027 echo " ** mirror 2 stripe info"
2028 $LFS getstripe -v --mirror-index=2 $tf
2030 run_test 48 "Verify snapshot mirror"
2032 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
2033 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
2038 local fsize=$(stat --printf=%s $tf)
2040 while [ -f $ctrl_file ]; do
2041 local off=$((RANDOM << 8))
2042 local len=$((RANDOM << 5 + 131072))
2044 [ $((off + len)) -gt $fsize ] && {
2045 fsize=$((off + len))
2046 echo "Extending file size to $fsize .."
2049 flock -s $lock_file -c \
2050 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
2052 error "failed writing to $off:$len"; }
2053 sleep 0.$((RANDOM % 2 + 1))
2060 while [ -f $ctrl_file ]; do
2061 flock -s $lock_file -c "cat $tf &> /dev/null" ||
2062 { rm -f $ctrl_file; error "read failed"; }
2063 sleep 0.$((RANDOM % 2 + 1))
2070 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
2072 exec 200<>$lock_file
2073 while [ -f $ctrl_file ]; do
2074 local lock_taken=false
2075 local index=$((RANDOM % ${#options[@]}))
2076 local cmd="mirror_io resync ${options[$index]}"
2078 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
2080 [ $((RANDOM % 4)) -eq 0 ] && {
2086 echo -n "resync file $tf with '$cmd' .."
2088 if [[ $lock_taken = "true" ]]; then
2089 flock -x 200 -c "$cmd $tf &> /dev/null" &&
2090 echo "done" || echo "failed"
2093 $cmd $tf &> /dev/null && echo "done" || echo "failed"
2096 sleep 0.$((RANDOM % 8 + 1))
2101 local tf=$DIR/$tfile
2102 local tf2=$DIR2/$tfile
2103 local tf3=$DIR3/$tfile
2105 $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
2106 $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
2107 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
2109 $LFS mirror extend -N -f $tf-2 $tf ||
2110 error "merging $tf-2 into $tf failed"
2111 $LFS mirror extend -N -f $tf-3 $tf ||
2112 error "merging $tf-3 into $tf failed"
2114 mkdir -p $MOUNT2 && mount_client $MOUNT2
2116 mkdir -p $MOUNT3 && mount_client $MOUNT3
2118 verify_flr_state $tf3 "ro"
2120 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
2121 $LCTL set_param fail_loc=0x1A03
2123 local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
2124 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
2128 write_file_200 $tf &
2134 write_file_200 $tf2 &
2137 read_file_200 $tf2 &
2140 resync_file_200 $tf3 &
2144 [ "$SLOW" = "yes" ] && sleep_time=360
2145 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
2152 echo "Waiting ${pids[@]}"
2155 umount_client $MOUNT2
2156 umount_client $MOUNT3
2160 # resync and verify mirrors
2161 mirror_io resync $tf
2164 local csum=$($LFS mirror dump -N ${mirror_array[0]} $tf | md5sum)
2165 for id in ${mirror_array[@]:1}; do
2166 [ "$($LFS mirror dump -N $id $tf | md5sum)" = "$csum" ] ||
2167 error "checksum error for mirror $id"
2172 run_test 200 "stress test"
2174 cleanup_test_201() {
2176 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
2178 umount_client $MOUNT2
2182 local delay=${RESYNC_DELAY:-5}
2184 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
2185 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
2187 trap cleanup_test_201 EXIT
2189 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
2190 changelog_register -n)
2192 mkdir -p $MOUNT2 && mount_client $MOUNT2
2196 local log=$($LFS changelog $MDT0 $index | grep FLRW)
2197 [ -z "$log" ] && { sleep 1; continue; }
2199 index=$(echo $log | awk '{print $1}')
2200 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
2201 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
2202 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
2205 [ -z "$file" ] && continue
2207 local now=$(date +%s)
2209 echo "file: $file $fid was modified at $ts, now: $now, " \
2210 "will be resynced at $((ts+delay))"
2212 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
2214 mirror_io resync $file
2215 echo "$file resync done"
2220 run_test 201 "FLR data mover"
2223 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
2225 local tf=$DIR/$tfile
2228 $LFS setstripe -E 1M -S 1M -c 1 $tf
2229 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2230 verify_comp_attr stripe-count $tf ${ids[0]} 1
2232 $LFS setstripe --component-add -E 2M -c -1 $tf
2233 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2234 verify_comp_attr stripe-count $tf ${ids[0]} 1
2235 verify_comp_attr stripe-count $tf ${ids[1]} -1
2237 dd if=/dev/zero of=$tf bs=1M count=2
2238 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2239 verify_comp_attr stripe-count $tf ${ids[0]} 1
2240 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
2242 run_test 202 "lfs setstripe --add-component wide striping"
2245 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
2247 local tf=$DIR/$tfile
2250 $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
2251 #delete first mirror
2252 $LFS mirror split --mirror-id=1 -d $tf || error "delete first mirror"
2255 local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
2256 local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2257 error "getstripe count of mirror 2"
2258 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2260 #extend a mirror with 2 OSTs
2261 $LFS mirror extend -N -c2 $tf || error "extend mirror"
2264 local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
2265 count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2266 error "getstripe count of mirror 2"
2267 [[ x$oldid = x$newid ]] ||
2268 error "mirror 2 changed ID from $old_id to $new_id"
2269 [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2271 count=$($LFS getstripe --mirror-id=3 -c $tf) ||
2272 error "getstripe count of mirror 3"
2273 [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
2275 run_test 203 "mirror file preserve mirror ID"
2278 check_and_cleanup_lustre