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:
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
35 # global array to store mirror IDs
36 declare -a mirror_array
43 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
44 array[${#array[@]}]=$((id >> 16))
47 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
49 echo ${#mirror_array[@]}
53 echo 3 > /proc/sys/vm/drop_caches
64 wait_osc_import_state client ost$idx DISCONN
72 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
73 error "start ost$idx failed"
77 wait_osc_import_state client ost$idx FULL
82 # Verify mirror count with an expected value for a given file.
84 verify_mirror_count() {
87 local mirror_count=$(get_mirror_ids $tf)
89 [[ $mirror_count = $expected ]] || {
91 error "verify mirror count failed on $tf:" \
92 "$mirror_count != $expected"
97 # Verify component count with an expected value for a given file.
98 # $1 coposited layout file
99 # $2 expected component number
101 verify_comp_count() {
104 local comp_count=$($LFS getstripe --component-count $tf)
106 [[ $comp_count = $expected ]] || {
107 $LFS getstripe -v $tf
108 error "verify component count failed on $tf:" \
109 "$comp_count != $expected"
114 # Verify component attribute with an expected value for a given file
122 local cmd="$LFS getstripe -I$comp_id"
123 local getstripe_cmd="$cmd -v"
127 stripe-size) cmd+=" -S $tf" ;;
128 stripe-count) cmd+=" -c $tf" ;;
129 stripe-index) cmd+=" -i $tf" ;;
130 pool) cmd+=" -p $tf" ;;
131 comp-start) cmd+=" --component-start $tf" ;;
132 comp-end) cmd+=" --component-end $tf" ;;
133 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
134 *) error "invalid attribute $attr";;
139 [ $attr = lcme_flags ] && {
141 local expected_list=$(comma_list $expected)
142 for fl in ${expected_list//,/ }; do
143 echo $value | grep -q $fl || {
145 error "expected flag $fl existing on $comp_id"
151 [[ $value = $expected ]] || {
153 error "verify $attr failed on $tf: $value != $expected"
158 # Verify component extent with expected start and end extent values
159 # for a given file and component ID.
161 verify_comp_extent() {
164 local expected_start=$3
165 local expected_end=$4
167 verify_comp_attr comp-start $tf $comp_id $expected_start
168 verify_comp_attr comp-end $tf $comp_id $expected_end
172 # Verify component attribute with parent directory for a given file
175 verify_comp_attr_with_parent() {
179 local td=$(cd $(dirname $tf); echo $PWD)
180 local tf_cmd="$LFS getstripe -I$comp_id"
181 local td_cmd="$LFS getstripe"
187 stripe-size) opt="-S" ;;
188 stripe-count) opt="-c" ;;
190 *) error "invalid attribute $attr";;
193 expected=$($td_cmd $opt $td)
194 [[ $expected = -1 ]] && expected=$OSTCOUNT
196 value=$($tf_cmd $opt $tf)
197 [[ $value = -1 ]] && value=$OSTCOUNT
199 [[ $value = $expected ]] || {
202 error "verify $attr failed with parent on $tf:" \
203 "$value != $expected"
208 # Verify component attributes with parent directory for a given file
211 # This will only verify the inherited attributes:
212 # stripe size, stripe count and OST pool name
214 verify_comp_attrs_with_parent() {
218 verify_comp_attr_with_parent stripe-size $tf $comp_id
219 verify_comp_attr_with_parent stripe-count $tf $comp_id
220 verify_comp_attr_with_parent pool $tf $comp_id
223 # command line test cases
227 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
228 local mirror_cmd="$LFS mirror create"
233 # create parent directory
234 mkdir $td || error "mkdir $td failed"
236 $mirror_cmd $tf &> /dev/null && error "miss -N option"
238 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
239 verify_mirror_count $tf 1
240 id=$($LFS getstripe -I $tf)
241 verify_comp_attrs_with_parent $tf $id
242 verify_comp_extent $tf $id 0 EOF
244 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
245 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
246 error "invalid mirror count $((mirror_count + 1))"
248 $mirror_cmd -N$mirror_count $tf-1 ||
249 error "create mirrored file $tf-1 failed"
250 verify_mirror_count $tf-1 $mirror_count
251 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
252 for ((i = 0; i < $mirror_count; i++)); do
253 verify_comp_attrs_with_parent $tf-1 ${ids[$i]}
254 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
257 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
258 error "create mirrored file $tf-2 failed"
259 verify_mirror_count $tf-2 10
260 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
261 for ((i = 0; i < 10; i++)); do
262 verify_comp_attrs_with_parent $tf-2 ${ids[$i]}
263 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
266 run_test 0a "lfs mirror create with -N option"
269 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
273 local mirror_cmd="$LFS mirror create"
277 # create parent directory
278 mkdir $td || error "mkdir $td failed"
280 # create a mirrored file with plain layout mirrors
281 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
282 -N -S 16M -N -c -1 -N -p archive -N --parent $tf ||
283 error "create mirrored file $tf failed"
284 verify_mirror_count $tf 5
285 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
286 for ((i = 0; i < 5; i++)); do
287 verify_comp_extent $tf ${ids[$i]} 0 EOF
290 # verify component ${ids[0]}
291 verify_comp_attr stripe-size $tf ${ids[0]} 4194304
292 verify_comp_attr stripe-count $tf ${ids[0]} 2
293 verify_comp_attr stripe-index $tf ${ids[0]} 2
294 verify_comp_attr pool $tf ${ids[0]} flash
296 # verify component ${ids[1]}
297 verify_comp_attr stripe-size $tf ${ids[1]} 16777216
298 verify_comp_attr stripe-count $tf ${ids[1]} 2
299 verify_comp_attr pool $tf ${ids[1]} flash
301 # verify component ${ids[2]}
302 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
303 verify_comp_attr stripe-count $tf ${ids[2]} $OSTCOUNT
304 verify_comp_attr pool $tf ${ids[2]} flash
306 # verify component ${ids[3]}
307 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
308 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
309 verify_comp_attr pool $tf ${ids[3]} archive
311 # verify component ${ids[4]}
312 verify_comp_attrs_with_parent $tf ${ids[4]}
314 run_test 0b "lfs mirror create plain layout mirrors"
317 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
321 local mirror_cmd="$LFS mirror create"
325 # create parent directory
326 mkdir $td || error "mkdir $td failed"
328 # create a mirrored file with composite layout mirrors
329 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
331 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
332 error "create mirrored file $tf failed"
333 verify_mirror_count $tf 6
334 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
336 # verify components ${ids[0]} and ${ids[2]}
338 verify_comp_attr_with_parent stripe-size $tf ${ids[$i]}
339 verify_comp_attr stripe-count $tf ${ids[$i]} 2
340 verify_comp_attr stripe-index $tf ${ids[$i]} 1
341 verify_comp_attr pool $tf ${ids[$i]} flash
342 verify_comp_extent $tf ${ids[$i]} 0 4194304
345 # verify components ${ids[1]} and ${ids[3]}
347 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
348 verify_comp_attr stripe-count $tf ${ids[$i]} 2
349 verify_comp_attr pool $tf ${ids[$i]} flash
350 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
353 # verify component ${ids[4]}
354 verify_comp_attrs_with_parent $tf ${ids[4]}
355 verify_comp_extent $tf ${ids[4]} 0 EOF
357 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
359 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
360 verify_comp_attr_with_parent stripe-count $tf ${ids[$i]}
361 verify_comp_attr pool $tf ${ids[$i]} archive
362 verify_comp_extent $tf ${ids[$i]} 0 536870912
365 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
367 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
368 verify_comp_attr stripe-count $tf ${ids[$i]} -1
369 verify_comp_attr pool $tf ${ids[$i]} archive
370 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
373 run_test 0c "lfs mirror create composite layout mirrors"
378 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
379 local mirror_cmd="$LFS mirror extend"
383 # create parent directory
384 mkdir $td || error "mkdir $td failed"
386 $mirror_cmd $tf &> /dev/null && error "miss -N option"
387 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
389 # create a non-mirrored file, convert it to a mirrored file and extend
390 touch $tf || error "touch $tf failed"
391 $mirror_cmd -N $tf || error "convert and extend $tf failed"
392 verify_mirror_count $tf 2
393 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
394 for ((i = 0; i < 2; i++)); do
395 verify_comp_attrs_with_parent $tf ${ids[$i]}
396 verify_comp_extent $tf ${ids[$i]} 0 EOF
399 lfsck_verify_pfid $tf || error "PFID is not set"
401 # create a mirrored file and extend it
402 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
403 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
405 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
406 error "setstripe options should not be specified with -f option"
408 $mirror_cmd -N -f $tf-2 -N --parent $tf-1 &> /dev/null &&
409 error "--parent option should not be specified with -f option"
411 $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
412 error "extend mirrored file $tf-1 failed"
413 verify_mirror_count $tf-1 $mirror_count
414 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
415 for ((i = 0; i < $mirror_count; i++)); do
416 verify_comp_attrs_with_parent $tf-1 ${ids[$i]}
417 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
420 $mirror_cmd -N $tf-1 &> /dev/null &&
421 error "exceeded maximum mirror count $mirror_count" || true
423 run_test 0d "lfs mirror extend with -N option"
426 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
430 local mirror_cmd="$LFS mirror extend"
434 # create parent directory
435 mkdir $td || error "mkdir $td failed"
437 # create a mirrored file with plain layout mirrors
438 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
439 error "create mirrored file $tf failed"
441 # extend the mirrored file with plain layout mirrors
442 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
443 -N -S 16M -N -c -1 -N -p archive -N --parent $tf ||
444 error "extend mirrored file $tf failed"
445 verify_mirror_count $tf 6
446 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
447 for ((i = 0; i < 6; i++)); do
448 verify_comp_extent $tf ${ids[$i]} 0 EOF
451 # verify component ${ids[0]}
452 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
453 verify_comp_attr stripe-count $tf ${ids[0]} 3
454 verify_comp_attr stripe-index $tf ${ids[0]} 1
455 verify_comp_attr pool $tf ${ids[0]} ssd
457 # verify component ${ids[1]}
458 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
459 verify_comp_attr stripe-count $tf ${ids[1]} 2
460 verify_comp_attr stripe-index $tf ${ids[1]} 2
461 verify_comp_attr pool $tf ${ids[1]} flash
463 # verify component ${ids[2]}
464 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
465 verify_comp_attr stripe-count $tf ${ids[2]} 2
466 verify_comp_attr pool $tf ${ids[2]} flash
468 # verify component ${ids[3]}
469 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
470 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
471 verify_comp_attr pool $tf ${ids[3]} flash
473 # verify component ${ids[4]}
474 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
475 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
476 verify_comp_attr pool $tf ${ids[4]} archive
478 # verify component ${ids[5]}
479 verify_comp_attrs_with_parent $tf ${ids[5]}
481 run_test 0e "lfs mirror extend plain layout mirrors"
484 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
488 local mirror_cmd="$LFS mirror extend"
492 # create parent directory
493 mkdir $td || error "mkdir $td failed"
495 # create a mirrored file with composite layout mirror
496 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
497 error "create mirrored file $tf failed"
499 # extend the mirrored file with composite layout mirrors
500 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
502 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
503 error "extend mirrored file $tf failed"
504 verify_mirror_count $tf 7
505 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
507 # verify component ${ids[0]}
508 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
509 verify_comp_attr_with_parent stripe-count $tf ${ids[0]}
510 verify_comp_attr pool $tf ${ids[0]} ssd
511 verify_comp_extent $tf ${ids[0]} 0 33554432
513 # verify component ${ids[1]}
514 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
515 verify_comp_attr_with_parent stripe-count $tf ${ids[1]}
516 verify_comp_attr pool $tf ${ids[1]} ssd
517 verify_comp_extent $tf ${ids[1]} 33554432 EOF
519 # verify components ${ids[2]} and ${ids[4]}
521 verify_comp_attr_with_parent stripe-size $tf ${ids[$i]}
522 verify_comp_attr stripe-count $tf ${ids[$i]} 2
523 verify_comp_attr stripe-index $tf ${ids[$i]} 1
524 verify_comp_attr pool $tf ${ids[$i]} flash
525 verify_comp_extent $tf ${ids[$i]} 0 4194304
528 # verify components ${ids[3]} and ${ids[5]}
530 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
531 verify_comp_attr stripe-count $tf ${ids[$i]} 2
532 verify_comp_attr pool $tf ${ids[$i]} flash
533 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
536 # verify component ${ids[6]}
537 verify_comp_attrs_with_parent $tf ${ids[6]}
538 verify_comp_extent $tf ${ids[6]} 0 EOF
540 # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
542 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
543 verify_comp_attr_with_parent stripe-count $tf ${ids[$i]}
544 verify_comp_attr pool $tf ${ids[$i]} archive
545 verify_comp_extent $tf ${ids[$i]} 0 536870912
548 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
550 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
551 verify_comp_attr stripe-count $tf ${ids[$i]} -1
552 verify_comp_attr pool $tf ${ids[$i]} archive
553 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
556 run_test 0f "lfs mirror extend composite layout mirrors"
561 $LFS mirror create -N -E 1M -o0 --flags=prefer -E eof -o1 -N -o1 $tf ||
562 error "create mirrored file $tf failed"
564 verify_comp_attr lcme_flags $tf 0x10001 prefer
565 verify_comp_attr lcme_flags $tf 0x10002 prefer
567 # write to the mirrored file and check primary
568 cp /etc/hosts $tf || error "error writing file '$tf'"
570 verify_comp_attr lcme_flags $tf 0x20003 stale
572 # resync file and check prefer flag
573 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
576 $LCTL set_param osc.*.stats=clear
577 cat $tf &> /dev/null || error "error reading file '$tf'"
579 # verify that the data was provided by OST1 where mirror 1 resides
580 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-ffff*.stats |
581 awk '/ost_read/{print $2}')
582 [ -n "$nr_read" ] || error "read was not provided by OST1"
584 run_test 0g "lfs mirror create flags support"
589 $LFS mirror create -N -E 1M --flags=prefer -E eof -N2 $tf ||
590 error "create mirrored file $tf failed"
592 verify_comp_attr lcme_flags $tf 0x10001 prefer
593 verify_comp_attr lcme_flags $tf 0x10002 prefer
595 # set flags to the first component
596 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
598 verify_comp_attr lcme_flags $tf 0x10001 stale
599 verify_comp_attr lcme_flags $tf 0x10002 prefer
601 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
602 error "clearing 'stale' should fail"
604 # write and resync file. It can't resync the file directly because the
605 # file state is still 'ro'
606 cp /etc/hosts $tf || error "error writing file '$tf'"
607 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
609 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
610 error "error setting flag prefer"
612 verify_comp_attr lcme_flags $tf 0x20003 prefer
614 run_test 0h "set, clear and test flags for FLR files"
618 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
619 local mirror_create_cmd="$LFS mirror create"
620 local stripes[0]=$OSTCOUNT
622 mirror_create_cmd+=" -N -c ${stripes[0]}"
623 for ((i = 1; i < $mirror_count; i++)); do
624 # add mirrors with different stripes to the file
625 stripes[$i]=$((RANDOM % OSTCOUNT))
626 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
628 mirror_create_cmd+=" -N -c ${stripes[$i]}"
631 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
632 verify_mirror_count $tf $mirror_count
634 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
635 $LFS mirror extend -N $tf &&
636 error "Creating the $((mirror_count+1))th mirror succeeded"
638 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
641 # verify the range of components and stripe counts
642 for ((i = 0; i < $mirror_count; i++)); do
643 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
644 verify_comp_extent $tf ${ids[$i]} 0 EOF
647 run_test 1 "create components with setstripe options"
651 local tf2=$DIR/$tfile-2
653 $LFS setstripe -E 1M -E EOF -c 1 $tf
654 $LFS setstripe -E 2M -E EOF -c -1 $tf2
656 local layout=$($LFS getstripe $tf2 | grep -A 4 lmm_objects)
658 $LFS mirror extend -N -f $tf2 $tf ||
659 error "merging $tf2 into $tf failed"
661 verify_mirror_count $tf 2
662 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
664 run_test 2 "create components from existing files"
667 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
669 for ((i = 0; i < 2; i++)); do
670 $LFS mkdir -i $i $DIR/$tdir-$i
671 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
674 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
675 $DIR/$tdir-0/$tfile || error "creating mirrors"
677 # mdt doesn't support to cancel layout lock for remote objects, do
681 # make sure the mirrorted file was created successfully
682 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
683 { $LFS getstripe $DIR/$tdir-0/$tfile;
684 error "expected 2 components"; }
689 run_test 3 "create components from files located on different MDTs"
692 local tf=$DIR/$tdir/$tfile
695 test_mkdir $DIR/$tdir
697 # set mirror with setstripe options to directory
698 $LFS mirror create -N2 -E 1M -E eof $DIR/$tdir ||
699 error "set mirror to directory error"
701 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
702 x"mirrored" ] || error "failed to create mirrored dir"
705 verify_mirror_count $tf 2
707 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
708 verify_comp_extent $tf ${ids[0]} 0 1048576
709 verify_comp_extent $tf ${ids[1]} 1048576 EOF
711 # sub directory should inherit mirror setting from parent
712 test_mkdir $DIR/$tdir/td
713 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
714 x"mirrored" ] || error "failed to inherit mirror from parent"
716 # mirror extend won't be applied to directory
717 $LFS mirror extend -N2 $DIR/$tdir &&
718 error "expecting mirror extend failure"
721 run_test 4 "Make sure mirror attributes can be inhertied from directory"
727 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
728 error "failed to create file with non-empty layout"
729 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
731 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
732 verify_mirror_count $tf 3
734 $CHECKSTAT -t file -s 12345 $tf ||
735 error "size error after attaching layout "
737 run_test 5 "Make sure init size work for mirrored layout"
739 # LU=10112: disable dom+flr for phase 1
743 $LFS mirror create -N -E 1M -L mdt -E eof -N -E eof $tf &&
744 error "expect failure to create mirrored file with DoM"
746 $LFS mirror create -N -E 1M -E eof -N -E 1M -L mdt -E eof $tf &&
747 error "expect failure to create mirrored file with DoM"
749 $LFS setstripe -E 1M -L mdt -E eof $tf
750 $LFS mirror extend -N2 $tf &&
751 error "expect failure to extend mirror with DoM"
753 $LFS mirror create -N2 -E 1M -E eof $tf-2
754 $LFS mirror extend -N -f $tf $tf-2 &&
755 error "expect failure to extend mirrored file with DoM extent"
759 run_test 6 "DoM and FLR won't co-exist for phase 1"
763 local tf2=$DIR/$tfile-2
765 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
767 $LFS setstripe -E EOF -o 0 $tf
768 $LFS setstripe -E EOF -o 1 $tf2
770 local dd_count=$((RANDOM % 20 + 1))
771 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
772 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
774 # for zfs - sync OST dataset so that du below will return
776 [ "$FSTYPE" = "zfs" ] &&
777 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
779 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
782 $LFS mirror extend -N -f $tf2 $tf ||
783 error "merging $tf2 into $tf failed"
788 local new_blocks=$(du -k $tf | awk '{print $1}')
789 [ $new_blocks -eq $blocks ] ||
790 error "i_blocks error expected: $blocks, actual: $new_blocks"
792 run_test 21 "glimpse should report accurate i_blocks"
794 get_osc_lock_count() {
801 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'ffff*'
802 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
803 lock_count=$((lock_count + count))
811 $LFS setstripe -E EOF -o 0 $tf
812 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
814 # add component, two mirrors located on the same OST ;-)
815 $LFS mirror extend -N -o 0 $tf ||
816 error "extending mirrored file $tf failed"
818 size_blocks=$(stat --format="%b %s" $tf)
823 local new_size_blocks=$(stat --format="%b %s" $tf)
825 # make sure there is no lock cached
826 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
828 [ "$new_size_blocks" = "$size_blocks" ] ||
829 echo "size expected: $size_blocks, actual: $new_size_blocks"
833 run_test 22 "no glimpse to OSTs for READ_ONLY files"
838 $LFS mirror create -N -o 0 -N -o 1 $tf ||
839 error "creating mirrored file $tf failed"
841 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
842 $LCTL set_param fail_loc=0x1A00
845 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
849 local tmpfile=$(mktemp)
850 stat --format="%b %s" $tf > $tmpfile &
854 while [ $cnt -le 5 ]; do
855 kill -0 $pid > /dev/null 2>&1 || break
859 kill -0 $pid > /dev/null 2>&1 &&
860 error "stat process stuck due to unavailable OSTs"
862 # make sure glimpse request has been sent
863 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
864 error "OST $ost_idx: no glimpse request was sent"
869 run_test 31 "make sure glimpse request can be retried"
872 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
873 rm -f $DIR/$tfile $DIR/$tfile-2
875 $LFS setstripe -E EOF -o 0 $DIR/$tfile
876 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
878 local fsize=$(stat -c %s $DIR/$tfile)
879 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
881 local cksum=$(md5sum $DIR/$tfile)
883 # create a new mirror in sync mode
884 $LFS mirror extend -N -o 1 $DIR/$tfile ||
885 error "extending mirrored file $DIR/$tfile failed"
887 # make sure the mirrored file was created successfully
888 [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
889 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
894 # check size is correct, glimpse request should go to the 2nd mirror
895 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
896 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
898 echo "reading file from the 2nd mirror and verify checksum"
899 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
900 error "checksum error: expected $cksum"
904 run_test 32 "data should be mirrored to newly created mirror"
907 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
909 rm -f $DIR/$tfile $DIR/$tfile-2
911 # create a file with two mirrors
912 $LFS setstripe -E EOF -o 0 $DIR/$tfile
915 while [ $count -lt $max_count ]; do
916 echo "ost1" >> $DIR/$tfile
917 count=$((count + 1));
920 # tmp file that will be used as mirror
921 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
923 while [ $count -lt $max_count ]; do
924 echo "ost2" >> $DIR/$tfile-2
925 count=$((count + 1));
928 # create a mirrored file
929 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
930 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
931 "with verification should fail"
932 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
933 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
934 "without verification failed"
936 # make sure that $tfile has two mirrors and $tfile-2 does not exist
937 [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
938 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
940 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
943 local fsize=$((5 * max_count))
944 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
945 error "mirrored file size is not $fsize"
947 # read file - all OSTs are available
948 echo "reading file (data can be provided by any ost)... "
949 local rs=$(cat $DIR/$tfile | head -1)
950 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
951 error "file content error: expected: \"ost1\" or \"ost2\""
953 # read file again with ost1 failed
957 echo "reading file (data should be provided by ost2)..."
958 local rs=$(cat $DIR/$tfile | head -1)
959 [[ "$rs" == "ost2" ]] ||
960 error "file content error: expected: \"ost2\", actual: \"$rs\""
965 # read file again with ost2 failed
966 $LCTL set_param ldlm.namespaces.lustre-*-osc-ffff*.lru_size=clear
971 # check size, glimpse should work
972 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
973 error "mirrored file size is not $fsize"
975 echo "reading file (data should be provided by ost1)..."
976 local rs=$(cat $DIR/$tfile | head -1)
977 [[ "$rs" == "ost1" ]] ||
978 error "file content error: expected: \"ost1\", actual: \"$rs\""
980 wait_osc_import_state client ost2 FULL
982 run_test 33 "read can choose available mirror to read"
985 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
987 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
990 $LFS setstripe -o 0 $DIR/$tfile-ref
991 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
993 # create a file with two mirrors
994 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
995 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
997 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
998 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1000 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1001 error "mirrored file size is not 3M"
1003 # merge a mirrored file
1004 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1005 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1007 cancel_lru_locks osc
1009 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1010 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1013 echo "comparing files ... "
1015 # however, read can still return the correct data. It should return
1016 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1017 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1018 $DIR/$tfile-ref || error "file reading error"
1022 run_test 34a "read mirrored file with multiple stripes"
1025 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1027 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1030 $LFS setstripe -o 0 $DIR/$tfile-ref
1031 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1033 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1034 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1036 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1037 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1039 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1040 error "mirrored file size is not 3M"
1042 # merge a mirrored file
1043 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1044 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1046 cancel_lru_locks osc
1048 # stop two OSTs, so the 2nd component of the 1st mirror and
1049 # the 1st component of the 2nd mirror will be inaccessible, ...
1052 echo "comparing files ... "
1054 # however, read can still return the correct data. It should return
1055 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1056 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1057 $DIR/$tfile-ref || error "file reading error"
1061 run_test 34b "read mirrored file with multiple components"
1064 local tf=$DIR/$tfile
1066 $LFS setstripe -E eof $tf
1068 # add an out-of-sync mirror to the file
1069 $LFS mirror extend -N -c 2 $tf ||
1070 error "extending mirrored file $tf failed"
1072 $MULTIOP $tf oO_WRONLY:c ||
1073 error "write open a mirrored file failed"
1075 # truncate file should return error
1076 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1078 run_test 35 "allow to write to mirrored files"
1080 verify_ost_layout_version() {
1083 # get file layout version
1084 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1086 # layout version from OST objects
1087 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1089 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1096 $LFS setstripe -E 1M -E 2M -E 4M -E eof -c -1 $tf
1097 $LFS setstripe -E 3M -E 6M -E eof -c -1 $tf-tmp
1099 $LFS mirror extend -N -f $tf-tmp $tf ||
1100 error "merging $tf-tmp into $tf failed"
1105 local tf=$DIR/$tfile
1107 create_file_36 $tf $tf-2 $tf-3
1109 [ $(get_mirror_ids $tf) -gt 1 ] || error "wrong mirror count"
1111 # test case 1 - check file write and verify layout version
1112 $MULTIOP $tf oO_WRONLY:c ||
1113 error "write open a mirrored file failed"
1115 # write open file should not return error
1116 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1118 # instantiate components should work
1119 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1121 # verify OST layout version
1122 verify_ost_layout_version $tf
1125 local mds_idx=mds$(($($LFS getstripe -M $tf-2) + 1))
1128 do_facet $mds_idx $LCTL set_param fail_val=$delay_sec
1130 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1131 do_facet $mds_idx $LCTL set_param fail_loc=0x1A01
1133 # write should take at least $fail_loc seconds and succeed
1134 local st=$(date +%s)
1135 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1137 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1138 error "write finished before layout version is transmitted"
1140 # verify OST layout version
1141 verify_ost_layout_version $tf
1143 do_facet $mds_idx $LCTL set_param fail_loc=0
1146 mds_idx=mds$(($($LFS getstripe -M $tf-3) + 1))
1148 #define OBD_FAIL_FLR_LV_INC 0x1A02
1149 do_facet $mds_idx $LCTL set_param fail_loc=0x1A02
1151 # write open file should return error
1152 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1153 error "write a mirrored file succeeded" || true
1155 do_facet $mds_idx $LCTL set_param fail_loc=0
1157 run_test 36 "write to mirrored files"
1163 echo "create test files with size $fsize .."
1167 $LFS setstripe -E 1M -c 1 -E eof -c -1 $tf
1169 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1170 $TRUNCATE $tf $fsize
1176 local tf=$DIR/$tfile
1177 local tf2=$DIR/$tfile-2
1178 local tf3=$DIR/$tfile-3
1180 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1182 # assume the mirror id will be 1, 2, and 3
1183 declare -A checksums
1184 checksums[1]=$(md5sum $tf | cut -f 1 -d' ')
1185 checksums[2]=$(md5sum $tf2 | cut -f 1 -d' ')
1186 checksums[3]=$(md5sum $tf3 | cut -f 1 -d' ')
1188 printf '%s\n' "${checksums[@]}"
1190 # merge these files into a mirrored file
1191 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1192 error "merging $tf2 into $tf failed"
1193 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1194 error "merging $tf3 into $tf failed"
1198 # verify mirror read, checksums should equal to the original files'
1199 echo "Verifying mirror read .."
1202 for i in ${mirror_array[@]}; do
1203 sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
1204 [ "$sum" = "${checksums[$i]}" ] ||
1205 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1208 # verify mirror copy, write to this mirrored file will invalidate
1209 # the other two mirrors
1210 echo "Verifying mirror copy .."
1212 local osts=$(comma_list $(osts_nodes))
1214 # define OBD_FAIL_OST_SKIP_LV_CHECK 0x241
1215 do_nodes $osts lctl set_param fail_loc=0x241
1217 mirror_io copy -i ${mirror_array[0]} \
1218 -t $(echo ${mirror_array[@]:1} | tr ' ' ',') $tf ||
1219 error "mirror copy error"
1221 do_nodes $osts lctl set_param fail_loc=0
1223 # verify copying is successful by checking checksums
1224 remount_client $MOUNT
1225 for i in ${mirror_array[@]}; do
1226 sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
1227 [ "$sum" = "${checksums[1]}" ] ||
1228 error "$i: mismatch checksum after copy"
1233 run_test 37 "mirror I/O API verification"
1238 local expected_state=$2
1240 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
1241 [ $expected_state = $state ] ||
1242 error "expected: $expected_state, actual $state"
1246 local tf=$DIR/$tfile
1247 local ref=$DIR/${tfile}-ref
1249 $LFS setstripe -E 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf
1250 $LFS setstripe -E 2M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 $tf-2
1251 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3
1253 # instantiate all components
1254 $LFS mirror extend -N -f $tf-2 $tf ||
1255 error "merging $tf-2 into $tf failed"
1256 $LFS mirror extend -N -f $tf-3 $tf ||
1257 error "merging $tf-3 into $tf failed"
1258 $LFS mirror extend -N -c 1 $tf ||
1259 error "extending mirrored file $tf failed"
1261 verify_flr_state $tf "ro"
1263 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1265 local fsize=$((RANDOM << 8 + 1048576))
1266 $TRUNCATE $ref $fsize
1268 local ref_cksum=$(md5sum $ref | cut -f 1 -d' ')
1270 # case 1: verify write to mirrored file & resync work
1271 cp $ref $tf || error "copy from $ref to $f error"
1272 verify_flr_state $tf "wp"
1274 local file_cksum=$(md5sum $tf | cut -f 1 -d' ')
1275 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1278 echo "mirror IDs: ${mirror_array[@]}"
1280 local valid_mirror stale_mirror id mirror_cksum
1281 for id in "${mirror_array[@]}"; do
1282 mirror_cksum=$(mirror_io dump -i $id $tf |
1283 md5sum | cut -f 1 -d' ')
1284 [ "$ref_cksum" == "$mirror_cksum" ] &&
1285 { valid_mirror=$id; continue; }
1290 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1291 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1293 mirror_io resync $tf || error "resync failed"
1294 verify_flr_state $tf "ro"
1296 mirror_cksum=$(mirror_io dump -i $stale_mirror $tf |
1297 md5sum | cut -f 1 -d' ')
1298 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1300 # case 2: inject an error to make mirror_io exit after changing
1301 # the file state to sync_pending so that we can start a concurrent
1303 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1304 verify_flr_state $tf "wp"
1306 mirror_io resync -e resync_start $tf && error "resync succeeded"
1307 verify_flr_state $tf "sp"
1309 # from sync_pending to write_pending
1310 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1311 verify_flr_state $tf "wp"
1313 mirror_io resync -e resync_start $tf && error "resync succeeded"
1314 verify_flr_state $tf "sp"
1316 # from sync_pending to read_only
1317 mirror_io resync $tf || error "resync failed"
1318 verify_flr_state $tf "ro"
1320 run_test 38 "resync"
1323 local tf=$DIR/$tfile
1326 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1327 error "create PFL file $tf failed"
1329 verify_mirror_count $tf 2
1330 verify_comp_count $tf 4
1332 rm -f $tf || error "delete $tf failed"
1334 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1337 local tf=$DIR/$tfile
1340 for ops in "conv=notrunc" ""; do
1343 $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E4m -E-1 \
1344 $tf || error "create PFLR file $tf failed"
1345 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1346 error "write PFLR file $tf failed"
1348 lfs getstripe -vy $tf
1352 # file mirror state should be write_pending
1353 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1355 error "file mirror state $flags"
1356 # the 1st component (in mirror 1) should be inited
1357 verify_comp_attr lcme_flags $tf 0x10001 init
1358 # the 2nd component (in mirror 1) should be inited
1359 verify_comp_attr lcme_flags $tf 0x10002 init
1360 # the 3rd component (in mirror 1) should be uninited
1361 verify_comp_attr lcme_flags $tf 0x10003 0
1362 # the 4th component (in mirror 2) should be inited
1363 verify_comp_attr lcme_flags $tf 0x20004 init
1364 # the 5th component (in mirror 2) should be uninited
1365 verify_comp_attr lcme_flags $tf 0x20005 0
1366 # the 6th component (in mirror 2) should be stale
1367 verify_comp_attr lcme_flags $tf 0x20006 stale
1368 # the 7th component (in mirror 2) should be uninited
1369 if [[ x$ops = "xconv=notrunc" ]]; then
1370 verify_comp_attr lcme_flags $tf 0x20007 0
1371 elif [[ x$ops = "x" ]]; then
1372 verify_comp_attr lcme_flags $tf 0x20007 stale
1376 rm -f $tf || error "delete $tf failed"
1378 run_test 40 "PFLR rdonly state instantiation check"
1381 local tf=$DIR/$tfile
1384 $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 $tf ||
1385 error "create PFLR file $tf failed"
1386 $LFS mirror create -N -E4m -E-1 -N -E2m -E3m -E-1 $tf-1 ||
1387 error "create PFLR file $tf-1 failed"
1389 # file should be in ro status
1390 verify_flr_state $tf "ro"
1391 verify_flr_state $tf-1 "ro"
1393 # write data in [0, 2M)
1394 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1395 error "writing $tf failed"
1396 dd if=/dev/zero of=$tf-1 bs=1M count=4 conv=notrunc ||
1397 error "writing $tf-1 failed"
1399 verify_flr_state $tf "wp"
1400 verify_flr_state $tf-1 "wp"
1402 # file should have stale component
1403 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1404 error "after writing $tf, it does not contain stale component"
1405 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1406 error "after writing $tf-1, it does not contain stale component"
1408 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1410 verify_flr_state $tf "ro"
1411 verify_flr_state $tf-1 "ro"
1413 # file should not have stale component
1414 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1415 error "after resyncing $tf, it contains stale component"
1416 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1417 error "after resyncing $tf, it contains stale component"
1421 run_test 41 "lfs mirror resync check"
1423 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
1424 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
1429 local fsize=$(stat --printf=%s $tf)
1431 while [ -f $ctrl_file ]; do
1432 local off=$((RANDOM << 8))
1433 local len=$((RANDOM << 5 + 131072))
1435 [ $((off + len)) -gt $fsize ] && {
1436 fsize=$((off + len))
1437 echo "Extending file size to $fsize .."
1440 flock -s $lock_file -c \
1441 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
1443 error "failed writing to $off:$len"; }
1444 sleep 0.$((RANDOM % 2 + 1))
1451 while [ -f $ctrl_file ]; do
1452 flock -s $lock_file -c "cat $tf &> /dev/null" ||
1453 { rm -f $ctrl_file; error "read failed"; }
1454 sleep 0.$((RANDOM % 2 + 1))
1461 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
1463 exec 200<>$lock_file
1464 while [ -f $ctrl_file ]; do
1465 local lock_taken=false
1466 local index=$((RANDOM % ${#options[@]}))
1467 local cmd="mirror_io resync ${options[$index]}"
1469 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
1471 [ $((RANDOM % 4)) -eq 0 ] && {
1477 echo -n "resync file $tf with '$cmd' .."
1479 $lock_taken && flock -x 200
1480 $cmd $tf &> /dev/null && echo "done" || echo "failed"
1481 $lock_taken && flock -u 200
1483 sleep 0.$((RANDOM % 8 + 1))
1488 local tf=$DIR/$tfile
1489 local tf2=$DIR2/$tfile
1490 local tf3=$DIR3/$tfile
1492 $LFS setstripe -E 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
1493 $LFS setstripe -E 2M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
1494 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
1496 $LFS mirror extend -N -f $tf-2 $tf ||
1497 error "merging $tf-2 into $tf failed"
1498 $LFS mirror extend -N -f $tf-3 $tf ||
1499 error "merging $tf-3 into $tf failed"
1501 mkdir -p $MOUNT2 && mount_client $MOUNT2
1503 mkdir -p $MOUNT3 && mount_client $MOUNT3
1505 verify_flr_state $tf3 "ro"
1507 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
1508 $LCTL set_param fail_loc=0x1A03
1510 local mds_idx=mds$(($($LFS getstripe -M $tf) + 1))
1511 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
1515 write_file_200 $tf &
1521 write_file_200 $tf2 &
1524 read_file_200 $tf2 &
1527 resync_file_200 $tf3 &
1531 [ "$SLOW" = "yes" ] && sleep_time=360
1532 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
1539 echo "Waiting ${pids[@]}"
1542 umount_client $MOUNT2
1543 umount_client $MOUNT3
1547 # resync and verify mirrors
1548 mirror_io resync $tf
1551 local csum=$(mirror_io dump -i ${mirror_array[0]} $tf | md5sum)
1552 for id in ${mirror_array[@]:1}; do
1553 [ "$(mirror_io dump -i $id $tf | md5sum)" = "$csum" ] ||
1554 error "checksum error for mirror $id"
1559 run_test 200 "stress test"
1561 cleanup_test_201() {
1563 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
1565 umount_client $MOUNT2
1569 local delay=${RESYNC_DELAY:-5}
1571 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
1572 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
1574 trap cleanup_test_201 EXIT
1576 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
1577 changelog_register -n)
1579 mkdir -p $MOUNT2 && mount_client $MOUNT2
1583 local log=$($LFS changelog $MDT0 $index | grep FLRW)
1584 [ -z "$log" ] && { sleep 1; continue; }
1586 index=$(echo $log | awk '{print $1}')
1587 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
1588 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
1589 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
1592 [ -z "$file" ] && continue
1594 local now=$(date +%s)
1596 echo "file: $file $fid was modified at $ts, now: $now, " \
1597 "will be resynced at $((ts+delay))"
1599 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
1601 mirror_io resync $file
1602 echo "$file resync done"
1607 run_test 201 "FLR data mover"
1610 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1612 local tf=$DIR/$tfile
1615 $LFS setstripe -E 1M -c 1 $tf
1616 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1617 verify_comp_attr stripe-count $tf ${ids[0]} 1
1619 $LFS setstripe --component-add -E 2M -c -1 $tf
1620 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1621 verify_comp_attr stripe-count $tf ${ids[0]} 1
1622 verify_comp_attr stripe-count $tf ${ids[1]} -1
1624 dd if=/dev/zero of=$tf bs=1M count=2
1625 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1626 verify_comp_attr stripe-count $tf ${ids[0]} 1
1627 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
1629 run_test 202 "lfs setstripe --add-component wide striping"
1633 check_and_cleanup_lustre