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 attribute with filesystem-wide default value for a given file
211 verify_comp_attr_with_default() {
215 local tf_cmd="$LFS getstripe -I$comp_id"
223 expected=$($LCTL get_param -n \
224 lov.$FSNAME-clilov-*.stripesize)
228 expected=$($LCTL get_param -n \
229 lov.$FSNAME-clilov-*.stripecount)
230 [[ $expected = -1 ]] && expected=$OSTCOUNT
232 *) error "invalid attribute $attr";;
235 value=$($tf_cmd $opt $tf)
236 [[ $value = -1 ]] && value=$OSTCOUNT
238 [[ $value = $expected ]] || {
240 error "verify $attr failed with default value on $tf:" \
241 "$value != $expected"
246 # Verify unspecified component attributes for a given file
249 # This will only verify the inherited attributes:
250 # stripe size, stripe count and OST pool name
252 verify_comp_attrs() {
256 verify_comp_attr_with_default stripe-size $tf $comp_id
257 verify_comp_attr_with_default stripe-count $tf $comp_id
258 verify_comp_attr_with_parent pool $tf $comp_id
261 # command line test cases
265 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
266 local mirror_cmd="$LFS mirror create"
271 # create parent directory
272 mkdir $td || error "mkdir $td failed"
274 $mirror_cmd $tf &> /dev/null && error "miss -N option"
276 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
277 verify_mirror_count $tf 1
278 id=$($LFS getstripe -I $tf)
279 verify_comp_attrs $tf $id
280 verify_comp_extent $tf $id 0 EOF
282 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
283 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
284 error "invalid mirror count $((mirror_count + 1))"
286 $mirror_cmd -N$mirror_count $tf-1 ||
287 error "create mirrored file $tf-1 failed"
288 verify_mirror_count $tf-1 $mirror_count
289 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
290 for ((i = 0; i < $mirror_count; i++)); do
291 verify_comp_attrs $tf-1 ${ids[$i]}
292 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
295 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
296 error "create mirrored file $tf-2 failed"
297 verify_mirror_count $tf-2 10
298 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
299 for ((i = 0; i < 10; i++)); do
300 verify_comp_attrs $tf-2 ${ids[$i]}
301 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
304 run_test 0a "lfs mirror create with -N option"
307 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
311 local mirror_cmd="$LFS mirror create"
315 # create a new OST pool
316 local pool_name=$TESTNAME
317 create_pool $FSNAME.$pool_name ||
318 error "create OST pool $pool_name failed"
320 # add OSTs into the pool
321 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
322 error "add OSTs into pool $pool_name failed"
324 # create parent directory
325 mkdir $td || error "mkdir $td failed"
326 $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
327 error "$LFS setstripe $td failed"
329 # create a mirrored file with plain layout mirrors
330 $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
331 -N -S 16M -N -c -1 -N -p archive -N -p none $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' ' '))
335 for ((i = 0; i < 6; i++)); do
336 verify_comp_extent $tf ${ids[$i]} 0 EOF
339 # verify component ${ids[0]}
340 verify_comp_attrs $tf ${ids[0]}
342 # verify component ${ids[1]}
343 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
344 verify_comp_attr stripe-count $tf ${ids[1]} 2
345 verify_comp_attr stripe-index $tf ${ids[1]} 2
346 verify_comp_attr pool $tf ${ids[1]} flash
348 # verify component ${ids[2]}
349 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
350 verify_comp_attr stripe-count $tf ${ids[2]} 2
351 verify_comp_attr pool $tf ${ids[2]} flash
353 # verify component ${ids[3]}
354 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
355 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
356 verify_comp_attr pool $tf ${ids[3]} flash
358 # verify component ${ids[4]}
359 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
360 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
361 verify_comp_attr pool $tf ${ids[4]} archive
363 # verify component ${ids[5]}
364 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
365 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
366 verify_comp_attr_with_parent pool $tf ${ids[5]}
371 run_test 0b "lfs mirror create plain layout mirrors"
374 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
378 local mirror_cmd="$LFS mirror create"
382 # create a new OST pool
383 local pool_name=$TESTNAME
384 create_pool $FSNAME.$pool_name ||
385 error "create OST pool $pool_name failed"
387 # add OSTs into the pool
388 pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
389 error "add OSTs into pool $pool_name failed"
391 # create parent directory
392 mkdir $td || error "mkdir $td failed"
393 $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
394 error "$LFS setstripe $td failed"
396 # create a mirrored file with composite layout mirrors
397 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
399 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
400 error "create mirrored file $tf failed"
401 verify_mirror_count $tf 6
402 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
404 # verify components ${ids[0]} and ${ids[2]}
406 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
407 verify_comp_attr stripe-count $tf ${ids[$i]} 2
408 verify_comp_attr stripe-index $tf ${ids[$i]} 1
409 verify_comp_attr pool $tf ${ids[$i]} flash
410 verify_comp_extent $tf ${ids[$i]} 0 4194304
413 # verify components ${ids[1]} and ${ids[3]}
415 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
416 verify_comp_attr stripe-count $tf ${ids[$i]} 2
417 verify_comp_attr pool $tf ${ids[$i]} flash
418 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
421 # verify component ${ids[4]}
422 verify_comp_attr stripe-size $tf ${ids[4]} 4194304
423 verify_comp_attr stripe-count $tf ${ids[4]} 4
424 verify_comp_attr_with_parent pool $tf ${ids[4]}
425 verify_comp_extent $tf ${ids[4]} 0 EOF
427 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
429 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
430 verify_comp_attr stripe-count $tf ${ids[$i]} 4
431 verify_comp_attr pool $tf ${ids[$i]} archive
432 verify_comp_extent $tf ${ids[$i]} 0 536870912
435 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
437 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
438 verify_comp_attr stripe-count $tf ${ids[$i]} -1
439 verify_comp_attr pool $tf ${ids[$i]} archive
440 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
446 run_test 0c "lfs mirror create composite layout mirrors"
451 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
452 local mirror_cmd="$LFS mirror extend"
456 # create parent directory
457 mkdir $td || error "mkdir $td failed"
459 $mirror_cmd $tf &> /dev/null && error "miss -N option"
460 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
462 # create a non-mirrored file, convert it to a mirrored file and extend
463 touch $tf || error "touch $tf failed"
464 $mirror_cmd -N $tf || error "convert and extend $tf failed"
465 verify_mirror_count $tf 2
466 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
467 for ((i = 0; i < 2; i++)); do
468 verify_comp_attrs $tf ${ids[$i]}
469 verify_comp_extent $tf ${ids[$i]} 0 EOF
472 lfsck_verify_pfid $tf || error "PFID is not set"
474 # create a mirrored file and extend it
475 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
476 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
478 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
479 error "setstripe options should not be specified with -f option"
481 $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
482 error "extend mirrored file $tf-1 failed"
483 verify_mirror_count $tf-1 $mirror_count
484 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
485 for ((i = 0; i < $mirror_count; i++)); do
486 verify_comp_attrs $tf-1 ${ids[$i]}
487 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
490 $mirror_cmd -N $tf-1 &> /dev/null &&
491 error "exceeded maximum mirror count $mirror_count" || true
493 run_test 0d "lfs mirror extend with -N option"
496 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
500 local mirror_cmd="$LFS mirror extend"
504 # create parent directory
505 mkdir $td || error "mkdir $td failed"
507 # create a mirrored file with plain layout mirrors
508 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
509 error "create mirrored file $tf failed"
511 # extend the mirrored file with plain layout mirrors
512 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
513 -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
514 error "extend mirrored file $tf failed"
515 verify_mirror_count $tf 6
516 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
517 for ((i = 0; i < 6; i++)); do
518 verify_comp_extent $tf ${ids[$i]} 0 EOF
521 # verify component ${ids[0]}
522 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
523 verify_comp_attr stripe-count $tf ${ids[0]} 3
524 verify_comp_attr stripe-index $tf ${ids[0]} 1
525 verify_comp_attr pool $tf ${ids[0]} ssd
527 # verify component ${ids[1]}
528 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
529 verify_comp_attr stripe-count $tf ${ids[1]} 2
530 verify_comp_attr stripe-index $tf ${ids[1]} 2
531 verify_comp_attr pool $tf ${ids[1]} flash
533 # verify component ${ids[2]}
534 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
535 verify_comp_attr stripe-count $tf ${ids[2]} 2
536 verify_comp_attr pool $tf ${ids[2]} flash
538 # verify component ${ids[3]}
539 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
540 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
541 verify_comp_attr pool $tf ${ids[3]} flash
543 # verify component ${ids[4]}
544 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
545 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
546 verify_comp_attr pool $tf ${ids[4]} archive
548 # verify component ${ids[5]}
549 verify_comp_attr stripe-size $tf ${ids[5]} 16777216
550 verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
551 verify_comp_attr_with_parent pool $tf ${ids[5]}
553 run_test 0e "lfs mirror extend plain layout mirrors"
556 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
560 local mirror_cmd="$LFS mirror extend"
564 # create parent directory
565 mkdir $td || error "mkdir $td failed"
567 # create a mirrored file with composite layout mirror
568 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
569 error "create mirrored file $tf failed"
571 # extend the mirrored file with composite layout mirrors
572 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
574 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
575 error "extend mirrored file $tf failed"
576 verify_mirror_count $tf 7
577 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
579 # verify component ${ids[0]}
580 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
581 verify_comp_attr_with_default stripe-count $tf ${ids[0]}
582 verify_comp_attr pool $tf ${ids[0]} ssd
583 verify_comp_extent $tf ${ids[0]} 0 33554432
585 # verify component ${ids[1]}
586 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
587 verify_comp_attr_with_default stripe-count $tf ${ids[1]}
588 verify_comp_attr pool $tf ${ids[1]} ssd
589 verify_comp_extent $tf ${ids[1]} 33554432 EOF
591 # verify components ${ids[2]} and ${ids[4]}
593 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
594 verify_comp_attr stripe-count $tf ${ids[$i]} 2
595 verify_comp_attr stripe-index $tf ${ids[$i]} 1
596 verify_comp_attr pool $tf ${ids[$i]} flash
597 verify_comp_extent $tf ${ids[$i]} 0 4194304
600 # verify components ${ids[3]} and ${ids[5]}
602 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
603 verify_comp_attr stripe-count $tf ${ids[$i]} 2
604 verify_comp_attr pool $tf ${ids[$i]} flash
605 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
608 # verify component ${ids[6]}
609 verify_comp_attr stripe-size $tf ${ids[6]} 4194304
610 verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
611 verify_comp_attr_with_parent pool $tf ${ids[6]}
612 verify_comp_extent $tf ${ids[6]} 0 EOF
614 # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
616 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
617 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
618 verify_comp_attr pool $tf ${ids[$i]} archive
619 verify_comp_extent $tf ${ids[$i]} 0 536870912
622 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
624 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
625 verify_comp_attr stripe-count $tf ${ids[$i]} -1
626 verify_comp_attr pool $tf ${ids[$i]} archive
627 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
630 run_test 0f "lfs mirror extend composite layout mirrors"
635 $LFS mirror create -N -E 1M -o0 --flags=prefer -E eof -o1 -N -o1 $tf ||
636 error "create mirrored file $tf failed"
638 verify_comp_attr lcme_flags $tf 0x10001 prefer
639 verify_comp_attr lcme_flags $tf 0x10002 prefer
641 # write to the mirrored file and check primary
642 cp /etc/hosts $tf || error "error writing file '$tf'"
644 verify_comp_attr lcme_flags $tf 0x20003 stale
646 # resync file and check prefer flag
647 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
650 $LCTL set_param osc.*.stats=clear
651 cat $tf &> /dev/null || error "error reading file '$tf'"
653 # verify that the data was provided by OST1 where mirror 1 resides
654 local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-ffff*.stats |
655 awk '/ost_read/{print $2}')
656 [ -n "$nr_read" ] || error "read was not provided by OST1"
658 run_test 0g "lfs mirror create flags support"
663 $LFS mirror create -N -E 1M --flags=prefer -E eof -N2 $tf ||
664 error "create mirrored file $tf failed"
666 verify_comp_attr lcme_flags $tf 0x10001 prefer
667 verify_comp_attr lcme_flags $tf 0x10002 prefer
669 # set flags to the first component
670 $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
672 verify_comp_attr lcme_flags $tf 0x10001 stale
673 verify_comp_attr lcme_flags $tf 0x10002 prefer
675 $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
676 error "clearing 'stale' should fail"
678 # write and resync file. It can't resync the file directly because the
679 # file state is still 'ro'
680 cp /etc/hosts $tf || error "error writing file '$tf'"
681 $LFS mirror resync $tf || error "error resync-ing file '$tf'"
683 $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
684 error "error setting flag prefer"
686 verify_comp_attr lcme_flags $tf 0x20003 prefer
688 run_test 0h "set, clear and test flags for FLR files"
692 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
693 local mirror_create_cmd="$LFS mirror create"
694 local stripes[0]=$OSTCOUNT
696 mirror_create_cmd+=" -N -c ${stripes[0]}"
697 for ((i = 1; i < $mirror_count; i++)); do
698 # add mirrors with different stripes to the file
699 stripes[$i]=$((RANDOM % OSTCOUNT))
700 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
702 mirror_create_cmd+=" -N -c ${stripes[$i]}"
705 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
706 verify_mirror_count $tf $mirror_count
708 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
709 $LFS mirror extend -N $tf &&
710 error "Creating the $((mirror_count+1))th mirror succeeded"
712 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
715 # verify the range of components and stripe counts
716 for ((i = 0; i < $mirror_count; i++)); do
717 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
718 verify_comp_extent $tf ${ids[$i]} 0 EOF
721 run_test 1 "create components with setstripe options"
725 local tf2=$DIR/$tfile-2
727 $LFS setstripe -E 1M -E EOF -c 1 $tf
728 $LFS setstripe -E 2M -E EOF -c -1 $tf2
730 local layout=$($LFS getstripe $tf2 | grep -A 4 lmm_objects)
732 $LFS mirror extend -N -f $tf2 $tf ||
733 error "merging $tf2 into $tf failed"
735 verify_mirror_count $tf 2
736 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
738 run_test 2 "create components from existing files"
741 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
743 for ((i = 0; i < 2; i++)); do
744 $LFS mkdir -i $i $DIR/$tdir-$i
745 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
748 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
749 $DIR/$tdir-0/$tfile || error "creating mirrors"
751 # mdt doesn't support to cancel layout lock for remote objects, do
755 # make sure the mirrorted file was created successfully
756 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
757 { $LFS getstripe $DIR/$tdir-0/$tfile;
758 error "expected 2 components"; }
763 run_test 3 "create components from files located on different MDTs"
766 local tf=$DIR/$tdir/$tfile
769 test_mkdir $DIR/$tdir
771 # set mirror with setstripe options to directory
772 $LFS mirror create -N2 -E 1M -E eof $DIR/$tdir ||
773 error "set mirror to directory error"
775 [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
776 x"mirrored" ] || error "failed to create mirrored dir"
779 verify_mirror_count $tf 2
781 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
782 verify_comp_extent $tf ${ids[0]} 0 1048576
783 verify_comp_extent $tf ${ids[1]} 1048576 EOF
785 # sub directory should inherit mirror setting from parent
786 test_mkdir $DIR/$tdir/td
787 [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
788 x"mirrored" ] || error "failed to inherit mirror from parent"
790 # mirror extend won't be applied to directory
791 $LFS mirror extend -N2 $DIR/$tdir &&
792 error "expecting mirror extend failure"
795 run_test 4 "Make sure mirror attributes can be inhertied from directory"
801 $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
802 error "failed to create file with non-empty layout"
803 $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
805 $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
806 verify_mirror_count $tf 3
808 $CHECKSTAT -t file -s 12345 $tf ||
809 error "size error after attaching layout "
811 run_test 5 "Make sure init size work for mirrored layout"
813 # LU=10112: disable dom+flr for phase 1
817 $LFS mirror create -N -E 1M -L mdt -E eof -N -E eof $tf &&
818 error "expect failure to create mirrored file with DoM"
820 $LFS mirror create -N -E 1M -E eof -N -E 1M -L mdt -E eof $tf &&
821 error "expect failure to create mirrored file with DoM"
823 $LFS setstripe -E 1M -L mdt -E eof $tf
824 $LFS mirror extend -N2 $tf &&
825 error "expect failure to extend mirror with DoM"
827 $LFS mirror create -N2 -E 1M -E eof $tf-2
828 $LFS mirror extend -N -f $tf $tf-2 &&
829 error "expect failure to extend mirrored file with DoM extent"
833 run_test 6 "DoM and FLR won't co-exist for phase 1"
837 local tf2=$DIR/$tfile-2
839 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
841 $LFS setstripe -E EOF -o 0 $tf
842 $LFS setstripe -E EOF -o 1 $tf2
844 local dd_count=$((RANDOM % 20 + 1))
845 dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
846 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
848 # for zfs - sync OST dataset so that du below will return
850 [ "$FSTYPE" = "zfs" ] &&
851 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
853 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
856 $LFS mirror extend -N -f $tf2 $tf ||
857 error "merging $tf2 into $tf failed"
862 local new_blocks=$(du -k $tf | awk '{print $1}')
863 [ $new_blocks -eq $blocks ] ||
864 error "i_blocks error expected: $blocks, actual: $new_blocks"
866 run_test 21 "glimpse should report accurate i_blocks"
868 get_osc_lock_count() {
875 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'ffff*'
876 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
877 lock_count=$((lock_count + count))
885 $LFS setstripe -E EOF -o 0 $tf
886 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
888 # add component, two mirrors located on the same OST ;-)
889 $LFS mirror extend -N -o 0 $tf ||
890 error "extending mirrored file $tf failed"
892 size_blocks=$(stat --format="%b %s" $tf)
897 local new_size_blocks=$(stat --format="%b %s" $tf)
899 # make sure there is no lock cached
900 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
902 [ "$new_size_blocks" = "$size_blocks" ] ||
903 echo "size expected: $size_blocks, actual: $new_size_blocks"
907 run_test 22 "no glimpse to OSTs for READ_ONLY files"
912 $LFS mirror create -N -o 0 -N -o 1 $tf ||
913 error "creating mirrored file $tf failed"
915 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
916 $LCTL set_param fail_loc=0x1A00
919 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
923 local tmpfile=$(mktemp)
924 stat --format="%b %s" $tf > $tmpfile &
928 while [ $cnt -le 5 ]; do
929 kill -0 $pid > /dev/null 2>&1 || break
933 kill -0 $pid > /dev/null 2>&1 &&
934 error "stat process stuck due to unavailable OSTs"
936 # make sure glimpse request has been sent
937 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
938 error "OST $ost_idx: no glimpse request was sent"
943 run_test 31 "make sure glimpse request can be retried"
946 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
947 rm -f $DIR/$tfile $DIR/$tfile-2
949 $LFS setstripe -E EOF -o 0 $DIR/$tfile
950 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
952 local fsize=$(stat -c %s $DIR/$tfile)
953 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
955 local cksum=$(md5sum $DIR/$tfile)
957 # create a new mirror in sync mode
958 $LFS mirror extend -N -o 1 $DIR/$tfile ||
959 error "extending mirrored file $DIR/$tfile failed"
961 # make sure the mirrored file was created successfully
962 [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
963 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
968 # check size is correct, glimpse request should go to the 2nd mirror
969 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
970 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
972 echo "reading file from the 2nd mirror and verify checksum"
973 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
974 error "checksum error: expected $cksum"
978 run_test 32 "data should be mirrored to newly created mirror"
981 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
983 rm -f $DIR/$tfile $DIR/$tfile-2
985 # create a file with two mirrors
986 $LFS setstripe -E EOF -o 0 $DIR/$tfile
989 while [ $count -lt $max_count ]; do
990 echo "ost1" >> $DIR/$tfile
991 count=$((count + 1));
994 # tmp file that will be used as mirror
995 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
997 while [ $count -lt $max_count ]; do
998 echo "ost2" >> $DIR/$tfile-2
999 count=$((count + 1));
1002 # create a mirrored file
1003 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1004 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1005 "with verification should fail"
1006 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1007 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1008 "without verification failed"
1010 # make sure that $tfile has two mirrors and $tfile-2 does not exist
1011 [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
1012 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1014 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1016 # execpted file size
1017 local fsize=$((5 * max_count))
1018 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1019 error "mirrored file size is not $fsize"
1021 # read file - all OSTs are available
1022 echo "reading file (data can be provided by any ost)... "
1023 local rs=$(cat $DIR/$tfile | head -1)
1024 [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1025 error "file content error: expected: \"ost1\" or \"ost2\""
1027 # read file again with ost1 failed
1031 echo "reading file (data should be provided by ost2)..."
1032 local rs=$(cat $DIR/$tfile | head -1)
1033 [[ "$rs" == "ost2" ]] ||
1034 error "file content error: expected: \"ost2\", actual: \"$rs\""
1039 # read file again with ost2 failed
1040 $LCTL set_param ldlm.namespaces.lustre-*-osc-ffff*.lru_size=clear
1045 # check size, glimpse should work
1046 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1047 error "mirrored file size is not $fsize"
1049 echo "reading file (data should be provided by ost1)..."
1050 local rs=$(cat $DIR/$tfile | head -1)
1051 [[ "$rs" == "ost1" ]] ||
1052 error "file content error: expected: \"ost1\", actual: \"$rs\""
1054 wait_osc_import_state client ost2 FULL
1056 run_test 33 "read can choose available mirror to read"
1059 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1061 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1064 $LFS setstripe -o 0 $DIR/$tfile-ref
1065 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1067 # create a file with two mirrors
1068 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1069 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1071 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1072 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1074 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1075 error "mirrored file size is not 3M"
1077 # merge a mirrored file
1078 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1079 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1081 cancel_lru_locks osc
1083 # stop two OSTs, so the 2nd stripe of the 1st mirror and
1084 # the 1st stripe of the 2nd mirror will be inaccessible, ...
1087 echo "comparing files ... "
1089 # however, read can still return the correct data. It should return
1090 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1091 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1092 $DIR/$tfile-ref || error "file reading error"
1096 run_test 34a "read mirrored file with multiple stripes"
1099 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1101 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1104 $LFS setstripe -o 0 $DIR/$tfile-ref
1105 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1107 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1108 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1110 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1111 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1113 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1114 error "mirrored file size is not 3M"
1116 # merge a mirrored file
1117 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1118 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1120 cancel_lru_locks osc
1122 # stop two OSTs, so the 2nd component of the 1st mirror and
1123 # the 1st component of the 2nd mirror will be inaccessible, ...
1126 echo "comparing files ... "
1128 # however, read can still return the correct data. It should return
1129 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1130 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1131 $DIR/$tfile-ref || error "file reading error"
1135 run_test 34b "read mirrored file with multiple components"
1138 local tf=$DIR/$tfile
1140 $LFS setstripe -E eof $tf
1142 # add an out-of-sync mirror to the file
1143 $LFS mirror extend -N -c 2 $tf ||
1144 error "extending mirrored file $tf failed"
1146 $MULTIOP $tf oO_WRONLY:c ||
1147 error "write open a mirrored file failed"
1149 # truncate file should return error
1150 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1152 run_test 35 "allow to write to mirrored files"
1154 verify_ost_layout_version() {
1157 # get file layout version
1158 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1160 # layout version from OST objects
1161 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1163 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1170 $LFS setstripe -E 1M -E 2M -E 4M -E eof -c -1 $tf
1171 $LFS setstripe -E 3M -E 6M -E eof -c -1 $tf-tmp
1173 $LFS mirror extend -N -f $tf-tmp $tf ||
1174 error "merging $tf-tmp into $tf failed"
1179 local tf=$DIR/$tfile
1181 create_file_36 $tf $tf-2 $tf-3
1183 [ $(get_mirror_ids $tf) -gt 1 ] || error "wrong mirror count"
1185 # test case 1 - check file write and verify layout version
1186 $MULTIOP $tf oO_WRONLY:c ||
1187 error "write open a mirrored file failed"
1189 # write open file should not return error
1190 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1192 # instantiate components should work
1193 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1195 # verify OST layout version
1196 verify_ost_layout_version $tf
1199 local mds_idx=mds$(($($LFS getstripe -M $tf-2) + 1))
1202 do_facet $mds_idx $LCTL set_param fail_val=$delay_sec
1204 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1205 do_facet $mds_idx $LCTL set_param fail_loc=0x1A01
1207 # write should take at least $fail_loc seconds and succeed
1208 local st=$(date +%s)
1209 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1211 [ $(date +%s) -ge $((st+delay_sec)) ] ||
1212 error "write finished before layout version is transmitted"
1214 # verify OST layout version
1215 verify_ost_layout_version $tf
1217 do_facet $mds_idx $LCTL set_param fail_loc=0
1220 mds_idx=mds$(($($LFS getstripe -M $tf-3) + 1))
1222 #define OBD_FAIL_FLR_LV_INC 0x1A02
1223 do_facet $mds_idx $LCTL set_param fail_loc=0x1A02
1225 # write open file should return error
1226 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1227 error "write a mirrored file succeeded" || true
1229 do_facet $mds_idx $LCTL set_param fail_loc=0
1231 run_test 36 "write to mirrored files"
1237 echo "create test files with size $fsize .."
1241 $LFS setstripe -E 1M -c 1 -E eof -c -1 $tf
1243 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1244 $TRUNCATE $tf $fsize
1250 local tf=$DIR/$tfile
1251 local tf2=$DIR/$tfile-2
1252 local tf3=$DIR/$tfile-3
1254 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1256 # assume the mirror id will be 1, 2, and 3
1257 declare -A checksums
1258 checksums[1]=$(md5sum $tf | cut -f 1 -d' ')
1259 checksums[2]=$(md5sum $tf2 | cut -f 1 -d' ')
1260 checksums[3]=$(md5sum $tf3 | cut -f 1 -d' ')
1262 printf '%s\n' "${checksums[@]}"
1264 # merge these files into a mirrored file
1265 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1266 error "merging $tf2 into $tf failed"
1267 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1268 error "merging $tf3 into $tf failed"
1272 # verify mirror read, checksums should equal to the original files'
1273 echo "Verifying mirror read .."
1276 for i in ${mirror_array[@]}; do
1277 sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
1278 [ "$sum" = "${checksums[$i]}" ] ||
1279 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1282 # verify mirror copy, write to this mirrored file will invalidate
1283 # the other two mirrors
1284 echo "Verifying mirror copy .."
1286 local osts=$(comma_list $(osts_nodes))
1288 # define OBD_FAIL_OST_SKIP_LV_CHECK 0x241
1289 do_nodes $osts lctl set_param fail_loc=0x241
1291 mirror_io copy -i ${mirror_array[0]} \
1292 -t $(echo ${mirror_array[@]:1} | tr ' ' ',') $tf ||
1293 error "mirror copy error"
1295 do_nodes $osts lctl set_param fail_loc=0
1297 # verify copying is successful by checking checksums
1298 remount_client $MOUNT
1299 for i in ${mirror_array[@]}; do
1300 sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
1301 [ "$sum" = "${checksums[1]}" ] ||
1302 error "$i: mismatch checksum after copy"
1307 run_test 37 "mirror I/O API verification"
1312 local expected_state=$2
1314 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
1315 [ $expected_state = $state ] ||
1316 error "expected: $expected_state, actual $state"
1320 local tf=$DIR/$tfile
1321 local ref=$DIR/${tfile}-ref
1323 $LFS setstripe -E 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf
1324 $LFS setstripe -E 2M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 $tf-2
1325 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3
1327 # instantiate all components
1328 $LFS mirror extend -N -f $tf-2 $tf ||
1329 error "merging $tf-2 into $tf failed"
1330 $LFS mirror extend -N -f $tf-3 $tf ||
1331 error "merging $tf-3 into $tf failed"
1332 $LFS mirror extend -N -c 1 $tf ||
1333 error "extending mirrored file $tf failed"
1335 verify_flr_state $tf "ro"
1337 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1339 local fsize=$((RANDOM << 8 + 1048576))
1340 $TRUNCATE $ref $fsize
1342 local ref_cksum=$(md5sum $ref | cut -f 1 -d' ')
1344 # case 1: verify write to mirrored file & resync work
1345 cp $ref $tf || error "copy from $ref to $f error"
1346 verify_flr_state $tf "wp"
1348 local file_cksum=$(md5sum $tf | cut -f 1 -d' ')
1349 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1352 echo "mirror IDs: ${mirror_array[@]}"
1354 local valid_mirror stale_mirror id mirror_cksum
1355 for id in "${mirror_array[@]}"; do
1356 mirror_cksum=$(mirror_io dump -i $id $tf |
1357 md5sum | cut -f 1 -d' ')
1358 [ "$ref_cksum" == "$mirror_cksum" ] &&
1359 { valid_mirror=$id; continue; }
1364 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1365 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1367 mirror_io resync $tf || error "resync failed"
1368 verify_flr_state $tf "ro"
1370 mirror_cksum=$(mirror_io dump -i $stale_mirror $tf |
1371 md5sum | cut -f 1 -d' ')
1372 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1374 # case 2: inject an error to make mirror_io exit after changing
1375 # the file state to sync_pending so that we can start a concurrent
1377 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1378 verify_flr_state $tf "wp"
1380 mirror_io resync -e resync_start $tf && error "resync succeeded"
1381 verify_flr_state $tf "sp"
1383 # from sync_pending to write_pending
1384 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1385 verify_flr_state $tf "wp"
1387 mirror_io resync -e resync_start $tf && error "resync succeeded"
1388 verify_flr_state $tf "sp"
1390 # from sync_pending to read_only
1391 mirror_io resync $tf || error "resync failed"
1392 verify_flr_state $tf "ro"
1394 run_test 38 "resync"
1397 local tf=$DIR/$tfile
1400 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1401 error "create PFL file $tf failed"
1403 verify_mirror_count $tf 2
1404 verify_comp_count $tf 4
1406 rm -f $tf || error "delete $tf failed"
1408 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1411 local tf=$DIR/$tfile
1414 for ops in "conv=notrunc" ""; do
1417 $LFS mirror create -N -E2m -E4m -E-1 --flags=prefer \
1418 -N -E1m -E2m -E4m -E-1 $tf ||
1419 error "create PFLR file $tf failed"
1420 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1421 error "write PFLR file $tf failed"
1423 lfs getstripe -vy $tf
1427 # file mirror state should be write_pending
1428 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1430 error "file mirror state $flags"
1431 # the 1st component (in mirror 1) should be inited
1432 verify_comp_attr lcme_flags $tf 0x10001 init
1433 # the 2nd component (in mirror 1) should be inited
1434 verify_comp_attr lcme_flags $tf 0x10002 init
1435 # the 3rd component (in mirror 1) should be uninited
1436 verify_comp_attr lcme_flags $tf 0x10003 prefer
1437 # the 4th component (in mirror 2) should be inited
1438 verify_comp_attr lcme_flags $tf 0x20004 init
1439 # the 5th component (in mirror 2) should be uninited
1440 verify_comp_attr lcme_flags $tf 0x20005 0
1441 # the 6th component (in mirror 2) should be stale
1442 verify_comp_attr lcme_flags $tf 0x20006 stale
1443 # the 7th component (in mirror 2) should be uninited
1444 if [[ x$ops = "xconv=notrunc" ]]; then
1445 verify_comp_attr lcme_flags $tf 0x20007 0
1446 elif [[ x$ops = "x" ]]; then
1447 verify_comp_attr lcme_flags $tf 0x20007 stale
1451 rm -f $tf || error "delete $tf failed"
1453 run_test 40 "PFLR rdonly state instantiation check"
1456 local tf=$DIR/$tfile
1459 echo " **create two FLR files $tf $tf-1"
1460 $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 $tf ||
1461 error "create PFLR file $tf failed"
1462 $LFS mirror create -N -E2m -Eeof -N -E1m -Eeof --flags prefer \
1463 -N -E4m -Eeof $tf-1 || error "create PFLR file $tf-1 failed"
1465 # file should be in ro status
1466 echo " **verify files be RDONLY"
1467 verify_flr_state $tf "ro"
1468 verify_flr_state $tf-1 "ro"
1470 # write data in [0, 2M)
1471 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1472 error "writing $tf failed"
1473 dd if=/dev/zero of=$tf-1 bs=1M count=4 conv=notrunc ||
1474 error "writing $tf-1 failed"
1476 echo " **verify files be WRITE_PENDING"
1477 verify_flr_state $tf "wp"
1478 verify_flr_state $tf-1 "wp"
1480 # file should have stale component
1481 echo " **verify files have stale component"
1482 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1483 error "after writing $tf, it does not contain stale component"
1484 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1485 error "after writing $tf-1, it does not contain stale component"
1487 echo " **full resync"
1488 $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1490 echo " **verify files be RDONLY"
1491 verify_flr_state $tf "ro"
1492 verify_flr_state $tf-1 "ro"
1494 # file should not have stale component
1495 echo " **verify files do not contain stale component"
1496 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1497 error "after resyncing $tf, it contains stale component"
1498 $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1499 error "after resyncing $tf, it contains stale component"
1501 # verify partial resync
1502 echo " **write $tf-1 for partial resync test"
1503 dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1504 error "writing $tf-1 failed"
1506 echo " **only resync mirror 2"
1507 verify_flr_state $tf-1 "wp"
1508 $LFS mirror resync --only 2 $tf-1 ||
1509 error "resync mirror 2 of $tf-1 failed"
1510 verify_flr_state $tf "ro"
1512 # resync synced mirror
1513 echo " **resync mirror 2 again"
1514 $LFS mirror resync --only 2 $tf-1 ||
1515 error "resync mirror 2 of $tf-1 failed"
1516 verify_flr_state $tf "ro"
1517 echo " **verify $tf-1 contains stale component"
1518 $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1519 error "after writing $tf-1, it does not contain stale component"
1521 echo " **full resync $tf-1"
1522 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1523 verify_flr_state $tf "ro"
1524 echo " **full resync $tf-1 again"
1525 $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1526 echo " **verify $tf-1 does not contain stale component"
1527 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1528 error "after resyncing $tf, it contains stale component"
1532 run_test 41 "lfs mirror resync check"
1535 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1539 local mirror_cmd="$LFS mirror verify"
1542 # create parent directory
1543 mkdir $td || error "mkdir $td failed"
1545 $mirror_cmd &> /dev/null && error "no file name given"
1546 $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1547 $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1549 # create mirrored files
1550 $LFS mirror create -N -E 4M -E 10M -E EOF $tf ||
1551 error "create mirrored file $tf failed"
1552 $LFS mirror create -N -E 2M -E EOF \
1553 -N -E 6M -E 8M -E EOF \
1554 -N -E 16M -E EOF $tf-1 ||
1555 error "create mirrored file $tf-1 failed"
1556 $LFS mirror create -N -c 2 -o 1,3 -N -S 4M -c -1 $tf-2 ||
1557 error "create mirrored file $tf-2 failed"
1559 # write data in [0, 10M)
1560 for i in $tf $tf-1 $tf-2; do
1561 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1562 error "write $i failed"
1565 # resync the mirrored files
1566 $LFS mirror resync $tf-1 $tf-2 ||
1567 error "resync $tf-1 $tf-2 failed"
1569 # verify the mirrored files
1570 $mirror_cmd $tf-1 $tf-2 ||
1571 error "verify $tf-1 $tf-2 failed"
1573 get_mirror_ids $tf-1
1574 $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1575 error "at least 2 mirror ids needed with '--only' option"
1576 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1578 error "'--only' option cannot be used upon multiple files"
1579 $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1580 error "invalid specified mirror ids"
1582 # change the content of $tf and merge it into $tf-1
1584 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1585 error "change $tf with seek=$i failed"
1586 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1587 error "change $tf-1 with seek=$i failed"
1590 $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1591 $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1592 error "merge $tf into $tf-1 failed"
1594 # verify the mirrored files
1595 echo "Verify $tf-1 without -v option:"
1596 $mirror_cmd $tf-1 &&
1597 error "verify $tf-1 should fail" || echo "PASS"
1599 echo "Verify $tf-1 with -v option:"
1600 $mirror_cmd -v $tf-1 &&
1601 error "verify $tf-1 should fail"
1603 get_mirror_ids $tf-1
1604 echo "Verify $tf-1 with --only option:"
1605 $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1606 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1607 "${mirror_array[-1]} should fail"
1609 $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1610 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1611 "${mirror_array[1]} should succeed"
1613 # set stale components in $tf-1
1614 for i in 0x40002 0x40003; do
1615 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1616 error "set stale flag on component $i failed"
1619 # verify the mirrored file
1620 echo "Verify $tf-1 with stale components:"
1621 $mirror_cmd -vvv $tf-1 ||
1622 error "verify $tf-1 with stale components should succeed"
1624 echo "Verify $tf-1 with stale components and --only option:"
1625 $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1626 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1627 "${mirror_array[-1]} should succeed"
1629 run_test 42 "lfs mirror verify"
1631 # inactivate one OST && write && restore the OST
1635 local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1638 wait=$(do_facet $SINGLEMDS \
1639 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1640 wait=${wait%%[^0-9]*}
1642 echo " **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1643 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1644 # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1645 sleep $(($wait * 2 + 2))
1646 echo " **write $file"
1647 dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1648 echo " **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1649 $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1650 sleep $((wait * 2 + 2))
1652 local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1653 [ $flags = wp ] || error "file mirror state $flags != wp"
1657 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1659 local tf=$DIR/$tfile
1663 ## mirror 0 ost (0, 1)
1664 ## mirror 1 ost (1, 2)
1665 ## mirror 2 ost (2, 0)
1666 $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1667 -N -Eeof -c2 -o2,0 $tf ||
1668 error "create 3 mirrors file $tf failed"
1670 ################## OST0 ###########################################
1672 echo " **verify components"
1673 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1674 verify_comp_attr lcme_flags $tf 0x20002 init
1675 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1678 echo " **resync $tf"
1679 $LFS mirror resync $tf
1680 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1681 [ $flags = ro ] || error "file mirror state $flags != ro"
1683 ################## OST1 ###########################################
1685 echo " **verify components"
1686 verify_comp_attr lcme_flags $tf 0x10001 init,stale
1687 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1688 verify_comp_attr lcme_flags $tf 0x30003 init
1691 echo " **resync $tf"
1692 $LFS mirror resync $tf
1693 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1694 [ $flags = ro ] || error "file mirror state $flags != ro"
1696 ################## OST2 ###########################################
1698 echo " **verify components"
1699 verify_comp_attr lcme_flags $tf 0x10001 init
1700 verify_comp_attr lcme_flags $tf 0x20002 init,stale
1701 verify_comp_attr lcme_flags $tf 0x30003 init,stale
1703 run_test 43 "mirror pick on write"
1706 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1709 local tf=$DIR/$tdir/$tfile
1710 local tf1=$DIR/$tdir-1/$tfile-1
1712 $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1713 error "create directory failed"
1714 $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1715 error "create remote directory failed"
1716 rm -f $tf $tf1 $tf.mirror~2
1717 # create file with 4 mirrors
1718 $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 -N2 $tf ||
1719 error "create PFLR file $tf failed"
1721 # file should be in ro status
1722 verify_flr_state $tf "ro"
1724 # write data in [0, 3M)
1725 dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1726 error "writing $tf failed"
1728 verify_flr_state $tf "wp"
1730 # synchronize all mirrors of the file
1731 $LFS mirror resync $tf || error "mirror resync $tf failed"
1733 verify_flr_state $tf "ro"
1736 $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1737 error "split to $tf1 failed"
1739 local idx0=$($LFS getstripe -m $tf)
1740 local idx1=$($LFS getstripe -m $tf1)
1742 [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1743 [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1745 # verify mirror count
1746 verify_mirror_count $tf 3
1747 verify_mirror_count $tf1 1
1749 $LFS mirror split --mirror-id 2 $tf ||
1750 error "split mirror 2 failed"
1752 verify_mirror_count $tf 2
1753 verify_mirror_count $tf.mirror~2 1
1755 $LFS mirror split --mirror-id 3 -d $tf ||
1756 error "split and delte mirror 3 failed"
1757 verify_mirror_count $tf 1
1759 # verify splitted file contains the same content as the orig file does
1760 diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
1761 diff $tf $tf.mirror~2 ||
1762 error "splited file $tf.mirror~2 diffs from $tf"
1764 run_test 44 "lfs mirror split check"
1767 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1769 local file=$DIR/$tdir/$tfile
1770 local dir=$DIR/$tdir/$dir
1771 local temp=$DIR/$tdir/template
1773 test_mkdir $DIR/$tdir
1775 $LFS setstripe -N -E1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1776 -N -E3m -Eeof -N -E8m -Eeof $file || error "Create $file failed"
1778 echo "getstripe --yaml $file"
1779 $LFS getstripe --yaml $file > $temp || error "getstripe $file failed"
1780 echo "setstripe --yaml=$temp $file.2"
1781 $LFS setstripe --yaml=$temp $file.2 || error "setstripe $file.2 failed"
1783 echo "compare layout"
1784 local layout1=$(get_layout_param $file)
1785 local layout2=$(get_layout_param $file.2)
1786 [ "$layout1" == "$layout2" ] ||
1787 error "FLR file $file/$file.2 layouts are not equal"
1789 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
1791 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
1792 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
1797 local fsize=$(stat --printf=%s $tf)
1799 while [ -f $ctrl_file ]; do
1800 local off=$((RANDOM << 8))
1801 local len=$((RANDOM << 5 + 131072))
1803 [ $((off + len)) -gt $fsize ] && {
1804 fsize=$((off + len))
1805 echo "Extending file size to $fsize .."
1808 flock -s $lock_file -c \
1809 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
1811 error "failed writing to $off:$len"; }
1812 sleep 0.$((RANDOM % 2 + 1))
1819 while [ -f $ctrl_file ]; do
1820 flock -s $lock_file -c "cat $tf &> /dev/null" ||
1821 { rm -f $ctrl_file; error "read failed"; }
1822 sleep 0.$((RANDOM % 2 + 1))
1829 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
1831 exec 200<>$lock_file
1832 while [ -f $ctrl_file ]; do
1833 local lock_taken=false
1834 local index=$((RANDOM % ${#options[@]}))
1835 local cmd="mirror_io resync ${options[$index]}"
1837 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
1839 [ $((RANDOM % 4)) -eq 0 ] && {
1845 echo -n "resync file $tf with '$cmd' .."
1847 $lock_taken && flock -x 200
1848 $cmd $tf &> /dev/null && echo "done" || echo "failed"
1849 $lock_taken && flock -u 200
1851 sleep 0.$((RANDOM % 8 + 1))
1856 local tf=$DIR/$tfile
1857 local tf2=$DIR2/$tfile
1858 local tf3=$DIR3/$tfile
1860 $LFS setstripe -E 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
1861 $LFS setstripe -E 2M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
1862 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
1864 $LFS mirror extend -N -f $tf-2 $tf ||
1865 error "merging $tf-2 into $tf failed"
1866 $LFS mirror extend -N -f $tf-3 $tf ||
1867 error "merging $tf-3 into $tf failed"
1869 mkdir -p $MOUNT2 && mount_client $MOUNT2
1871 mkdir -p $MOUNT3 && mount_client $MOUNT3
1873 verify_flr_state $tf3 "ro"
1875 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
1876 $LCTL set_param fail_loc=0x1A03
1878 local mds_idx=mds$(($($LFS getstripe -M $tf) + 1))
1879 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
1883 write_file_200 $tf &
1889 write_file_200 $tf2 &
1892 read_file_200 $tf2 &
1895 resync_file_200 $tf3 &
1899 [ "$SLOW" = "yes" ] && sleep_time=360
1900 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
1907 echo "Waiting ${pids[@]}"
1910 umount_client $MOUNT2
1911 umount_client $MOUNT3
1915 # resync and verify mirrors
1916 mirror_io resync $tf
1919 local csum=$(mirror_io dump -i ${mirror_array[0]} $tf | md5sum)
1920 for id in ${mirror_array[@]:1}; do
1921 [ "$(mirror_io dump -i $id $tf | md5sum)" = "$csum" ] ||
1922 error "checksum error for mirror $id"
1927 run_test 200 "stress test"
1929 cleanup_test_201() {
1931 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
1933 umount_client $MOUNT2
1937 local delay=${RESYNC_DELAY:-5}
1939 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
1940 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
1942 trap cleanup_test_201 EXIT
1944 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
1945 changelog_register -n)
1947 mkdir -p $MOUNT2 && mount_client $MOUNT2
1951 local log=$($LFS changelog $MDT0 $index | grep FLRW)
1952 [ -z "$log" ] && { sleep 1; continue; }
1954 index=$(echo $log | awk '{print $1}')
1955 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
1956 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
1957 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
1960 [ -z "$file" ] && continue
1962 local now=$(date +%s)
1964 echo "file: $file $fid was modified at $ts, now: $now, " \
1965 "will be resynced at $((ts+delay))"
1967 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
1969 mirror_io resync $file
1970 echo "$file resync done"
1975 run_test 201 "FLR data mover"
1978 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1980 local tf=$DIR/$tfile
1983 $LFS setstripe -E 1M -c 1 $tf
1984 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1985 verify_comp_attr stripe-count $tf ${ids[0]} 1
1987 $LFS setstripe --component-add -E 2M -c -1 $tf
1988 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1989 verify_comp_attr stripe-count $tf ${ids[0]} 1
1990 verify_comp_attr stripe-count $tf ${ids[1]} -1
1992 dd if=/dev/zero of=$tf bs=1M count=2
1993 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1994 verify_comp_attr stripe-count $tf ${ids[0]} 1
1995 verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
1997 run_test 202 "lfs setstripe --add-component wide striping"
2001 check_and_cleanup_lustre