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 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
23 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
24 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
26 check_and_setup_lustre
32 # global array to store mirror IDs
33 declare -a mirror_array
40 for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
41 array[${#array[@]}]=$((id >> 16))
44 mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
46 echo ${#mirror_array[@]}
50 echo 3 > /proc/sys/vm/drop_caches
61 wait_osc_import_state client ost$idx DISCONN
69 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
70 error "start ost$idx failed"
74 wait_osc_import_state client ost$idx FULL
79 # Verify mirror count with an expected value for a given file.
81 verify_mirror_count() {
84 local mirror_count=$(get_mirror_ids $tf)
86 [[ $mirror_count = $expected ]] || {
88 error "verify mirror count failed on $tf:" \
89 "$mirror_count != $expected"
94 # Verify component count with an expected value for a given file.
95 # $1 coposited layout file
96 # $2 expected component number
101 local comp_count=$($LFS getstripe --component-count $tf)
103 [[ $comp_count = $expected ]] || {
104 $LFS getstripe -v $tf
105 error "verify component count failed on $tf:" \
106 "$comp_count != $expected"
111 # Verify component attribute with an expected value for a given file
119 local cmd="$LFS getstripe -I$comp_id"
120 local getstripe_cmd="$cmd -v"
124 stripe-size) cmd+=" -S $tf" ;;
125 stripe-count) cmd+=" -c $tf" ;;
126 stripe-index) cmd+=" -i $tf" ;;
127 pool) cmd+=" -p $tf" ;;
128 comp-start) cmd+=" --component-start $tf" ;;
129 comp-end) cmd+=" --component-end $tf" ;;
130 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
131 *) error "invalid attribute $attr";;
136 [[ $value = $expected ]] || {
138 error "verify $attr failed on $tf: $value != $expected"
143 # Verify component extent with expected start and end extent values
144 # for a given file and component ID.
146 verify_comp_extent() {
149 local expected_start=$3
150 local expected_end=$4
152 verify_comp_attr comp-start $tf $comp_id $expected_start
153 verify_comp_attr comp-end $tf $comp_id $expected_end
157 # Verify component attribute with parent directory for a given file
160 verify_comp_attr_with_parent() {
164 local td=$(cd $(dirname $tf); echo $PWD)
165 local tf_cmd="$LFS getstripe -I$comp_id"
166 local td_cmd="$LFS getstripe"
172 stripe-size) opt="-S" ;;
173 stripe-count) opt="-c" ;;
175 *) error "invalid attribute $attr";;
178 expected=$($td_cmd $opt $td)
179 [[ $expected = -1 ]] && expected=$OSTCOUNT
181 value=$($tf_cmd $opt $tf)
182 [[ $value = -1 ]] && value=$OSTCOUNT
184 [[ $value = $expected ]] || {
187 error "verify $attr failed with parent on $tf:" \
188 "$value != $expected"
193 # Verify component attributes with parent directory for a given file
196 # This will only verify the inherited attributes:
197 # stripe size, stripe count and OST pool name
199 verify_comp_attrs_with_parent() {
203 verify_comp_attr_with_parent stripe-size $tf $comp_id
204 verify_comp_attr_with_parent stripe-count $tf $comp_id
205 verify_comp_attr_with_parent pool $tf $comp_id
208 # command line test cases
212 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
213 local mirror_cmd="$LFS mirror create"
218 # create parent directory
219 mkdir $td || error "mkdir $td failed"
221 $mirror_cmd $tf &> /dev/null && error "miss -N option"
223 $mirror_cmd -N $tf || error "create mirrored file $tf failed"
224 verify_mirror_count $tf 1
225 id=$($LFS getstripe -I $tf)
226 verify_comp_attrs_with_parent $tf $id
227 verify_comp_extent $tf $id 0 EOF
229 $mirror_cmd -N $tf &> /dev/null &&
230 error "mirrored file $tf already exists"
231 $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
232 $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
233 error "invalid mirror count $((mirror_count + 1))"
235 $mirror_cmd -N$mirror_count $tf-1 ||
236 error "create mirrored file $tf-1 failed"
237 verify_mirror_count $tf-1 $mirror_count
238 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
239 for ((i = 0; i < $mirror_count; i++)); do
240 verify_comp_attrs_with_parent $tf-1 ${ids[$i]}
241 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
244 $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
245 error "create mirrored file $tf-2 failed"
246 verify_mirror_count $tf-2 10
247 ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
248 for ((i = 0; i < 10; i++)); do
249 verify_comp_attrs_with_parent $tf-2 ${ids[$i]}
250 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
253 run_test 0a "lfs mirror create with -N option"
256 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
260 local mirror_cmd="$LFS mirror create"
264 # create parent directory
265 mkdir $td || error "mkdir $td failed"
267 # create a mirrored file with plain layout mirrors
268 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
269 -N -S 16M -N -c -1 -N -p archive -N --parent $tf ||
270 error "create mirrored file $tf failed"
271 verify_mirror_count $tf 5
272 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
273 for ((i = 0; i < 5; i++)); do
274 verify_comp_extent $tf ${ids[$i]} 0 EOF
277 # verify component ${ids[0]}
278 verify_comp_attr stripe-size $tf ${ids[0]} 4194304
279 verify_comp_attr stripe-count $tf ${ids[0]} 2
280 verify_comp_attr stripe-index $tf ${ids[0]} 2
281 verify_comp_attr pool $tf ${ids[0]} flash
283 # verify component ${ids[1]}
284 verify_comp_attr stripe-size $tf ${ids[1]} 16777216
285 verify_comp_attr stripe-count $tf ${ids[1]} 2
286 verify_comp_attr pool $tf ${ids[1]} flash
288 # verify component ${ids[2]}
289 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
290 verify_comp_attr stripe-count $tf ${ids[2]} $OSTCOUNT
291 verify_comp_attr pool $tf ${ids[2]} flash
293 # verify component ${ids[3]}
294 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
295 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
296 verify_comp_attr pool $tf ${ids[3]} archive
298 # verify component ${ids[4]}
299 verify_comp_attrs_with_parent $tf ${ids[4]}
301 run_test 0b "lfs mirror create plain layout mirrors"
304 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
308 local mirror_cmd="$LFS mirror create"
312 # create parent directory
313 mkdir $td || error "mkdir $td failed"
315 # create a mirrored file with composite layout mirrors
316 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
318 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
319 error "create mirrored file $tf failed"
320 verify_mirror_count $tf 6
321 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
323 # verify components ${ids[0]} and ${ids[2]}
325 verify_comp_attr_with_parent stripe-size $tf ${ids[$i]}
326 verify_comp_attr stripe-count $tf ${ids[$i]} 2
327 verify_comp_attr stripe-index $tf ${ids[$i]} 1
328 verify_comp_attr pool $tf ${ids[$i]} flash
329 verify_comp_extent $tf ${ids[$i]} 0 4194304
332 # verify components ${ids[1]} and ${ids[3]}
334 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
335 verify_comp_attr stripe-count $tf ${ids[$i]} 2
336 verify_comp_attr pool $tf ${ids[$i]} flash
337 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
340 # verify component ${ids[4]}
341 verify_comp_attrs_with_parent $tf ${ids[4]}
342 verify_comp_extent $tf ${ids[4]} 0 EOF
344 # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
346 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
347 verify_comp_attr_with_parent stripe-count $tf ${ids[$i]}
348 verify_comp_attr pool $tf ${ids[$i]} archive
349 verify_comp_extent $tf ${ids[$i]} 0 536870912
352 # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
354 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
355 verify_comp_attr stripe-count $tf ${ids[$i]} -1
356 verify_comp_attr pool $tf ${ids[$i]} archive
357 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
360 run_test 0c "lfs mirror create composite layout mirrors"
365 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
366 local mirror_cmd="$LFS mirror extend"
370 # create parent directory
371 mkdir $td || error "mkdir $td failed"
373 $mirror_cmd $tf &> /dev/null && error "miss -N option"
374 $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
376 # create a non-mirrored file, convert it to a mirrored file and extend
378 touch $tf || error "touch $tf failed"
379 $mirror_cmd -N $tf || error "convert and extend $tf failed"
380 verify_mirror_count $tf 2
381 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
382 for ((i = 0; i < 2; i++)); do
383 verify_comp_attrs_with_parent $tf ${ids[$i]}
384 verify_comp_extent $tf ${ids[$i]} 0 EOF
388 # create a mirrored file and extend it
389 $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
390 $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
392 $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
393 error "setstripe options should not be specified with -f option"
395 $mirror_cmd -N -f $tf-2 -N --parent $tf-1 &> /dev/null &&
396 error "--parent option should not be specified with -f option"
398 $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
399 error "extend mirrored file $tf-1 failed"
400 verify_mirror_count $tf-1 $mirror_count
401 ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
402 for ((i = 0; i < $mirror_count; i++)); do
403 verify_comp_attrs_with_parent $tf-1 ${ids[$i]}
404 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
407 $mirror_cmd -N $tf-1 &> /dev/null &&
408 error "exceeded maximum mirror count $mirror_count" || true
410 run_test 0d "lfs mirror extend with -N option"
413 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
417 local mirror_cmd="$LFS mirror extend"
421 # create parent directory
422 mkdir $td || error "mkdir $td failed"
424 # create a mirrored file with plain layout mirrors
425 $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
426 error "create mirrored file $tf failed"
428 # extend the mirrored file with plain layout mirrors
429 $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
430 -N -S 16M -N -c -1 -N -p archive -N --parent $tf ||
431 error "extend mirrored file $tf failed"
432 verify_mirror_count $tf 6
433 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
434 for ((i = 0; i < 6; i++)); do
435 verify_comp_extent $tf ${ids[$i]} 0 EOF
438 # verify component ${ids[0]}
439 verify_comp_attr stripe-size $tf ${ids[0]} 33554432
440 verify_comp_attr stripe-count $tf ${ids[0]} 3
441 verify_comp_attr stripe-index $tf ${ids[0]} 1
442 verify_comp_attr pool $tf ${ids[0]} ssd
444 # verify component ${ids[1]}
445 verify_comp_attr stripe-size $tf ${ids[1]} 4194304
446 verify_comp_attr stripe-count $tf ${ids[1]} 2
447 verify_comp_attr stripe-index $tf ${ids[1]} 2
448 verify_comp_attr pool $tf ${ids[1]} flash
450 # verify component ${ids[2]}
451 verify_comp_attr stripe-size $tf ${ids[2]} 16777216
452 verify_comp_attr stripe-count $tf ${ids[2]} 2
453 verify_comp_attr pool $tf ${ids[2]} flash
455 # verify component ${ids[3]}
456 verify_comp_attr stripe-size $tf ${ids[3]} 16777216
457 verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
458 verify_comp_attr pool $tf ${ids[3]} flash
460 # verify component ${ids[4]}
461 verify_comp_attr stripe-size $tf ${ids[4]} 16777216
462 verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
463 verify_comp_attr pool $tf ${ids[4]} archive
465 # verify component ${ids[5]}
466 verify_comp_attrs_with_parent $tf ${ids[5]}
468 run_test 0e "lfs mirror extend plain layout mirrors"
471 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
475 local mirror_cmd="$LFS mirror extend"
479 # create parent directory
480 mkdir $td || error "mkdir $td failed"
482 # create a mirrored file with composite layout mirror
483 $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
484 error "create mirrored file $tf failed"
486 # extend the mirrored file with composite layout mirrors
487 $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
489 -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
490 error "extend mirrored file $tf failed"
491 verify_mirror_count $tf 7
492 ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
494 # verify component ${ids[0]}
495 verify_comp_attr stripe-size $tf ${ids[0]} 16777216
496 verify_comp_attr_with_parent stripe-count $tf ${ids[0]}
497 verify_comp_attr pool $tf ${ids[0]} ssd
498 verify_comp_extent $tf ${ids[0]} 0 33554432
500 # verify component ${ids[1]}
501 verify_comp_attr stripe-size $tf ${ids[1]} 33554432
502 verify_comp_attr_with_parent stripe-count $tf ${ids[1]}
503 verify_comp_attr pool $tf ${ids[1]} ssd
504 verify_comp_extent $tf ${ids[1]} 33554432 EOF
506 # verify components ${ids[2]} and ${ids[4]}
508 verify_comp_attr_with_parent stripe-size $tf ${ids[$i]}
509 verify_comp_attr stripe-count $tf ${ids[$i]} 2
510 verify_comp_attr stripe-index $tf ${ids[$i]} 1
511 verify_comp_attr pool $tf ${ids[$i]} flash
512 verify_comp_extent $tf ${ids[$i]} 0 4194304
515 # verify components ${ids[3]} and ${ids[5]}
517 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
518 verify_comp_attr stripe-count $tf ${ids[$i]} 2
519 verify_comp_attr pool $tf ${ids[$i]} flash
520 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
523 # verify component ${ids[6]}
524 verify_comp_attrs_with_parent $tf ${ids[6]}
525 verify_comp_extent $tf ${ids[6]} 0 EOF
527 # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
529 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
530 verify_comp_attr_with_parent stripe-count $tf ${ids[$i]}
531 verify_comp_attr pool $tf ${ids[$i]} archive
532 verify_comp_extent $tf ${ids[$i]} 0 536870912
535 # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
537 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
538 verify_comp_attr stripe-count $tf ${ids[$i]} -1
539 verify_comp_attr pool $tf ${ids[$i]} archive
540 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
543 run_test 0f "lfs mirror extend composite layout mirrors"
547 local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
548 local mirror_create_cmd="$LFS mirror create"
549 local stripes[0]=$OSTCOUNT
551 mirror_create_cmd+=" -N -c ${stripes[0]}"
552 for ((i = 1; i < $mirror_count; i++)); do
553 # add mirrors with different stripes to the file
554 stripes[$i]=$((RANDOM % OSTCOUNT))
555 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
557 mirror_create_cmd+=" -N -c ${stripes[$i]}"
560 $mirror_create_cmd $tf || error "create mirrored file $tf failed"
561 verify_mirror_count $tf $mirror_count
563 # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
564 $LFS mirror extend -N $tf &&
565 error "Creating the $((mirror_count+1))th mirror succeeded"
567 local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
570 # verify the range of components and stripe counts
571 for ((i = 0; i < $mirror_count; i++)); do
572 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
573 verify_comp_extent $tf ${ids[$i]} 0 EOF
576 run_test 1 "create components with setstripe options"
580 local tf2=$DIR/$tfile-2
582 $LFS setstripe -E 1M -E EOF -c 1 $tf
583 $LFS setstripe -E 2M -E EOF -c -1 $tf2
585 local layout=$($LFS getstripe $tf2 | grep -A 4 lmm_objects)
587 $LFS mirror extend -N -f $tf2 $tf ||
588 error "merging $tf2 into $tf failed"
590 verify_mirror_count $tf 2
591 [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
593 run_test 2 "create components from existing files"
596 [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
598 for ((i = 0; i < 2; i++)); do
599 $LFS mkdir -i $i $DIR/$tdir-$i
600 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
603 $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
604 $DIR/$tdir-0/$tfile || error "creating mirrors"
606 # mdt doesn't support to cancel layout lock for remote objects, do
610 # make sure the mirrorted file was created successfully
611 [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
612 { $LFS getstripe $DIR/$tdir-0/$tfile;
613 error "expected 2 components"; }
618 run_test 3 "create components from files located on different MDTs"
622 local tf2=$DIR/$tfile-2
624 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
626 $LFS setstripe -E EOF -o 0 $tf
627 $LFS setstripe -E EOF -o 1 $tf2
629 local dd_count=$((RANDOM % 20 + 1))
630 dd if=/dev/zero of=$tf bs=1M count=$dd_count
631 dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1))
634 local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
637 $LFS mirror extend -N -f $tf2 $tf ||
638 error "merging $tf2 into $tf failed"
643 local new_blocks=$(du -k $tf | awk '{print $1}')
644 [ $new_blocks -eq $blocks ] ||
645 error "i_blocks error expected: $blocks, actual: $new_blocks"
647 run_test 21 "glimpse should report accurate i_blocks"
649 get_osc_lock_count() {
656 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'ffff*'
657 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
658 lock_count=$((lock_count + count))
666 $LFS setstripe -E EOF -o 0 $tf
667 dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
669 # add component, two mirrors located on the same OST ;-)
670 $LFS mirror extend -N -o 0 $tf ||
671 error "extending mirrored file $tf failed"
673 size_blocks=$(stat --format="%b %s" $tf)
678 local new_size_blocks=$(stat --format="%b %s" $tf)
680 # make sure there is no lock cached
681 [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
683 [ "$new_size_blocks" = "$size_blocks" ] ||
684 echo "size expected: $size_blocks, actual: $new_size_blocks"
688 run_test 22 "no glimpse to OSTs for READ_ONLY files"
693 $LFS mirror create -N -o 0 -N -o 1 $tf ||
694 error "creating mirrored file $tf failed"
696 #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
697 $LCTL set_param fail_loc=0x1A00
700 for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
704 local tmpfile=$(mktemp)
705 stat --format="%b %s" $tf > $tmpfile &
709 while [ $cnt -le 5 ]; do
710 kill -0 $pid > /dev/null 2>&1 || break
714 kill -0 $pid > /dev/null 2>&1 &&
715 error "stat process stuck due to unavailable OSTs"
717 # make sure glimpse request has been sent
718 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
719 error "OST $ost_idx: no glimpse request was sent"
724 run_test 31 "make sure glimpse request can be retried"
727 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
728 rm -f $DIR/$tfile $DIR/$tfile-2
730 $LFS setstripe -E EOF -o 0 $DIR/$tfile
731 dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
733 local fsize=$(stat -c %s $DIR/$tfile)
734 [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
736 local cksum=$(md5sum $DIR/$tfile)
738 # create a new mirror in sync mode
739 $LFS mirror extend -N -o 1 $DIR/$tfile ||
740 error "extending mirrored file $DIR/$tfile failed"
742 # make sure the mirrored file was created successfully
743 [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
744 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
749 # check size is correct, glimpse request should go to the 2nd mirror
750 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
751 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
753 echo "reading file from the 2nd mirror and verify checksum"
754 [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
755 error "checksum error: expected $cksum"
759 run_test 32 "data should be mirrored to newly created mirror"
762 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
764 rm -f $DIR/$tfile $DIR/$tfile-2
766 # create a file with two mirrors
767 $LFS setstripe -E EOF -o 0 $DIR/$tfile
770 while [ $count -lt $max_count ]; do
771 echo "ost1" >> $DIR/$tfile
772 count=$((count + 1));
775 # tmp file that will be used as mirror
776 $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
778 while [ $count -lt $max_count ]; do
779 echo "ost2" >> $DIR/$tfile-2
780 count=$((count + 1));
783 # create a mirrored file
784 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
785 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
786 "with verification should fail"
787 $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
788 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
789 "without verification failed"
791 # make sure that $tfile has two mirrors and $tfile-2 does not exist
792 [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] ||
793 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
795 [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
798 local fsize=$((5 * max_count))
799 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
800 error "mirrored file size is not $fsize"
802 # read file - all OSTs are available
803 echo "reading file (data should be provided by ost1)... "
804 local rs=$(cat $DIR/$tfile | head -1)
805 [[ "$rs" == "ost1" ]] ||
806 error "file content error: expected: \"ost1\", actual: \"$rs\""
808 # read file again with ost1 failed
812 echo "reading file (data should be provided by ost2)..."
813 local rs=$(cat $DIR/$tfile | head -1)
814 [[ "$rs" == "ost2" ]] ||
815 error "file content error: expected: \"ost2\", actual: \"$rs\""
820 # read file again with ost2 failed
821 $LCTL set_param ldlm.namespaces.lustre-*-osc-ffff*.lru_size=clear
826 # check size, glimpse should work
827 $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
828 error "mirrored file size is not $fsize"
830 echo "reading file (data should be provided by ost1)..."
831 local rs=$(cat $DIR/$tfile | head -1)
832 [[ "$rs" == "ost1" ]] ||
833 error "file content error: expected: \"ost1\", actual: \"$rs\""
835 wait_osc_import_state client ost2 FULL
837 run_test 33 "read can choose available mirror to read"
840 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
842 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
845 $LFS setstripe -o 0 $DIR/$tfile-ref
846 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
848 # create a file with two mirrors
849 $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
850 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
852 $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
853 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
855 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
856 error "mirrored file size is not 3M"
858 # merge a mirrored file
859 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
860 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
864 # stop two OSTs, so the 2nd stripe of the 1st mirror and
865 # the 1st stripe of the 2nd mirror will be inaccessible, ...
868 echo "comparing files ... "
870 # however, read can still return the correct data. It should return
871 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
872 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
873 $DIR/$tfile-ref || error "file reading error"
877 run_test 34a "read mirrored file with multiple stripes"
880 [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
882 rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
885 $LFS setstripe -o 0 $DIR/$tfile-ref
886 dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
888 $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
889 dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
891 $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
892 dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
894 $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
895 error "mirrored file size is not 3M"
897 # merge a mirrored file
898 $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
899 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
903 # stop two OSTs, so the 2nd component of the 1st mirror and
904 # the 1st component of the 2nd mirror will be inaccessible, ...
907 echo "comparing files ... "
909 # however, read can still return the correct data. It should return
910 # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
911 cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
912 $DIR/$tfile-ref || error "file reading error"
916 run_test 34b "read mirrored file with multiple components"
921 $LFS setstripe -E eof $tf
923 # add an out-of-sync mirror to the file
924 $LFS mirror extend -N -c 2 $tf ||
925 error "extending mirrored file $tf failed"
927 $MULTIOP $tf oO_WRONLY:c ||
928 error "write open a mirrored file failed"
930 # truncate file should return error
931 $TRUNCATE $tf 100 || error "error truncating a mirrored file"
933 run_test 35 "allow to write to mirrored files"
935 verify_ost_layout_version() {
938 # get file layout version
939 local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
941 # layout version from OST objects
942 local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
944 [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
951 $LFS setstripe -E 1M -E 2M -E 4M -E eof -c -1 $tf
952 $LFS setstripe -E 3M -E 6M -E eof -c -1 $tf-tmp
954 $LFS mirror extend -N -f $tf-tmp $tf ||
955 error "merging $tf-tmp into $tf failed"
962 create_file_36 $tf $tf-2 $tf-3
964 [ $(get_mirror_ids $tf) -gt 1 ] || error "wrong mirror count"
966 # test case 1 - check file write and verify layout version
967 $MULTIOP $tf oO_WRONLY:c ||
968 error "write open a mirrored file failed"
970 # write open file should not return error
971 $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
973 # instantiate components should work
974 dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
976 # verify OST layout version
977 verify_ost_layout_version $tf
980 local mds_idx=mds$(($($LFS getstripe -M $tf-2) + 1))
983 do_facet $mds_idx $LCTL set_param fail_val=$delay_sec
985 #define OBD_FAIL_FLR_LV_DELAY 0x1A01
986 do_facet $mds_idx $LCTL set_param fail_loc=0x1A01
988 # write should take at least $fail_loc seconds and succeed
990 $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
992 [ $(date +%s) -ge $((st+delay_sec)) ] ||
993 error "write finished before layout version is transmitted"
995 # verify OST layout version
996 verify_ost_layout_version $tf
998 do_facet $mds_idx $LCTL set_param fail_loc=0
1001 mds_idx=mds$(($($LFS getstripe -M $tf-3) + 1))
1003 #define OBD_FAIL_FLR_LV_INC 0x1A02
1004 do_facet $mds_idx $LCTL set_param fail_loc=0x1A02
1006 # write open file should return error
1007 $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1008 error "write a mirrored file succeeded" || true
1010 do_facet $mds_idx $LCTL set_param fail_loc=0
1012 run_test 36 "write to mirrored files"
1018 echo "create test files with size $fsize .."
1022 $LFS setstripe -E 1M -c 1 -E eof -c -1 $tf
1024 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1025 $TRUNCATE $tf $fsize
1031 local tf=$DIR/$tfile
1032 local tf2=$DIR/$tfile-2
1033 local tf3=$DIR/$tfile-3
1035 create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1037 # assume the mirror id will be 1, 2, and 3
1038 declare -A checksums
1039 checksums[1]=$(md5sum $tf | cut -f 1 -d' ')
1040 checksums[2]=$(md5sum $tf2 | cut -f 1 -d' ')
1041 checksums[3]=$(md5sum $tf3 | cut -f 1 -d' ')
1043 printf '%s\n' "${checksums[@]}"
1045 # merge these files into a mirrored file
1046 $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1047 error "merging $tf2 into $tf failed"
1048 $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1049 error "merging $tf3 into $tf failed"
1053 # verify mirror read, checksums should equal to the original files'
1054 echo "Verifying mirror read .."
1057 for i in ${mirror_array[@]}; do
1058 sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
1059 [ "$sum" = "${checksums[$i]}" ] ||
1060 error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1063 # verify mirror copy, write to this mirrored file will invalidate
1064 # the other two mirrors
1065 echo "Verifying mirror copy .."
1067 local osts=$(comma_list $(osts_nodes))
1069 # define OBD_FAIL_OST_SKIP_LV_CHECK 0x241
1070 do_nodes $osts lctl set_param fail_loc=0x241
1072 mirror_io copy -i ${mirror_array[0]} \
1073 -t $(echo ${mirror_array[@]:1} | tr ' ' ',') $tf ||
1074 error "mirror copy error"
1076 do_nodes $osts lctl set_param fail_loc=0
1078 # verify copying is successful by checking checksums
1079 remount_client $MOUNT
1080 for i in ${mirror_array[@]}; do
1081 sum=$(mirror_io dump -i $i $tf | md5sum | cut -f 1 -d' ')
1082 [ "$sum" = "${checksums[1]}" ] ||
1083 error "$i: mismatch checksum after copy"
1088 run_test 37 "mirror I/O API verification"
1093 local expected_state=$2
1095 local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
1096 [ $expected_state = $state ] ||
1097 error "expected: $expected_state, actual $state"
1101 local tf=$DIR/$tfile
1102 local ref=$DIR/${tfile}-ref
1104 $LFS setstripe -E 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf
1105 $LFS setstripe -E 2M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 $tf-2
1106 $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3
1108 # instantiate all components
1109 $LFS mirror extend -N -f $tf-2 $tf ||
1110 error "merging $tf-2 into $tf failed"
1111 $LFS mirror extend -N -f $tf-3 $tf ||
1112 error "merging $tf-3 into $tf failed"
1113 $LFS mirror extend -N -c 1 $tf ||
1114 error "extending mirrored file $tf failed"
1116 verify_flr_state $tf "ro"
1118 dd if=/dev/urandom of=$ref bs=1M count=16 &> /dev/null
1120 local fsize=$((RANDOM << 8 + 1048576))
1121 $TRUNCATE $ref $fsize
1123 local ref_cksum=$(md5sum $ref | cut -f 1 -d' ')
1125 # case 1: verify write to mirrored file & resync work
1126 cp $ref $tf || error "copy from $ref to $f error"
1127 verify_flr_state $tf "wp"
1129 local file_cksum=$(md5sum $tf | cut -f 1 -d' ')
1130 [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1133 echo "mirror IDs: ${mirror_array[@]}"
1135 local valid_mirror stale_mirror id mirror_cksum
1136 for id in "${mirror_array[@]}"; do
1137 mirror_cksum=$(mirror_io dump -i $id $tf |
1138 md5sum | cut -f 1 -d' ')
1139 [ "$ref_cksum" == "$mirror_cksum" ] &&
1140 { valid_mirror=$id; continue; }
1145 [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1146 [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1148 mirror_io resync $tf || error "resync failed"
1149 verify_flr_state $tf "ro"
1151 mirror_cksum=$(mirror_io dump -i $stale_mirror $tf |
1152 md5sum | cut -f 1 -d' ')
1153 [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1155 # case 2: inject an error to make mirror_io exit after changing
1156 # the file state to sync_pending so that we can start a concurrent
1158 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1159 verify_flr_state $tf "wp"
1161 mirror_io resync -e resync_start $tf && error "resync succeeded"
1162 verify_flr_state $tf "sp"
1164 # from sync_pending to write_pending
1165 $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1166 verify_flr_state $tf "wp"
1168 mirror_io resync -e resync_start $tf && error "resync succeeded"
1169 verify_flr_state $tf "sp"
1171 # from sync_pending to read_only
1172 mirror_io resync $tf || error "resync failed"
1173 verify_flr_state $tf "ro"
1175 run_test 38 "resync"
1178 local tf=$DIR/$tfile
1181 $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1182 error "create PFL file $tf failed"
1184 verify_mirror_count $tf 2
1185 verify_comp_count $tf 4
1187 rm -f $tf || error "delete $tf failed"
1189 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1192 local tf=$DIR/$tfile
1195 for ops in "conv=notrunc" ""; do
1198 $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E4m -E-1 \
1199 $tf || error "create PFLR file $tf failed"
1200 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1201 error "write PFLR file $tf failed"
1203 lfs getstripe -vy $tf
1207 # file mirror state should be write_pending
1208 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1210 error "file mirror state $flags"
1211 # the 1st component (in mirror 1) should be inited
1212 verify_comp_attr lcme_flags $tf 0x10001 init
1213 # the 2nd component (in mirror 1) should be inited
1214 verify_comp_attr lcme_flags $tf 0x10002 init
1215 # the 3rd component (in mirror 1) should be uninited
1216 verify_comp_attr lcme_flags $tf 0x10003 0
1217 # the 4th component (in mirror 2) should be inited
1218 verify_comp_attr lcme_flags $tf 0x20004 init
1219 # the 5th component (in mirror 2) should be uninited
1220 verify_comp_attr lcme_flags $tf 0x20005 0
1221 # the 6th component (in mirror 2) should be stale
1222 verify_comp_attr lcme_flags $tf 0x20006 stale
1223 # the 7th component (in mirror 2) should be uninited
1224 if [[ x$ops = "xconv=notrunc" ]]; then
1225 verify_comp_attr lcme_flags $tf 0x20007 0
1226 elif [[ x$ops = "x" ]]; then
1227 verify_comp_attr lcme_flags $tf 0x20007 stale
1231 rm -f $tf || error "delete $tf failed"
1233 run_test 40 "PFLR rdonly state instantiation check"
1236 local tf=$DIR/$tfile
1239 $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 $tf ||
1240 error "create PFLR file $tf failed"
1242 # file should be in ro status
1243 verify_flr_state $tf "ro"
1245 # write data in [0, 2M)
1246 dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1247 error "writing $tf failed"
1249 verify_flr_state $tf "wp"
1251 # file should have stale component
1252 $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1253 error "after writing $tf, it does not contain stale component"
1255 $LFS mirror resync $tf || error "mirror resync $tf failed"
1257 verify_flr_state $tf "ro"
1259 # file should not have stale component
1260 $LFS getstripe $tf | grep lcme_flags | grep stale &&
1261 error "after resyncing $tf, it contains stale component"
1265 run_test 41 "lfs mirror resync check"
1267 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
1268 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
1273 local fsize=$(stat --printf=%s $tf)
1275 while [ -f $ctrl_file ]; do
1276 local off=$((RANDOM << 8))
1277 local len=$((RANDOM << 5 + 131072))
1279 [ $((off + len)) -gt $fsize ] && {
1280 fsize=$((off + len))
1281 echo "Extending file size to $fsize .."
1284 flock -s $lock_file -c \
1285 "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
1287 error "failed writing to $off:$len"; }
1288 sleep 0.$((RANDOM % 2 + 1))
1295 while [ -f $ctrl_file ]; do
1296 flock -s $lock_file -c "cat $tf &> /dev/null" ||
1297 { rm -f $ctrl_file; error "read failed"; }
1298 sleep 0.$((RANDOM % 2 + 1))
1305 options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
1307 exec 200<>$lock_file
1308 while [ -f $ctrl_file ]; do
1309 local lock_taken=false
1310 local index=$((RANDOM % ${#options[@]}))
1311 local cmd="mirror_io resync ${options[$index]}"
1313 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
1315 [ $((RANDOM % 4)) -eq 0 ] && {
1321 echo -n "resync file $tf with '$cmd' .."
1323 $lock_taken && flock -x 200
1324 $cmd $tf &> /dev/null && echo "done" || echo "failed"
1325 $lock_taken && flock -u 200
1327 sleep 0.$((RANDOM % 8 + 1))
1332 local tf=$DIR/$tfile
1333 local tf2=$DIR2/$tfile
1334 local tf3=$DIR3/$tfile
1336 $LFS setstripe -E 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
1337 $LFS setstripe -E 2M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
1338 $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
1340 $LFS mirror extend -N -f $tf-2 $tf ||
1341 error "merging $tf-2 into $tf failed"
1342 $LFS mirror extend -N -f $tf-3 $tf ||
1343 error "merging $tf-3 into $tf failed"
1345 mkdir -p $MOUNT2 && mount_client $MOUNT2
1347 mkdir -p $MOUNT3 && mount_client $MOUNT3
1349 verify_flr_state $tf3 "ro"
1351 #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
1352 $LCTL set_param fail_loc=0x1A03
1354 local mds_idx=mds$(($($LFS getstripe -M $tf) + 1))
1355 do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
1359 write_file_200 $tf &
1365 write_file_200 $tf2 &
1368 read_file_200 $tf2 &
1371 resync_file_200 $tf3 &
1375 [ "$SLOW" = "yes" ] && sleep_time=360
1376 while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
1383 echo "Waiting ${pids[@]}"
1386 umount_client $MOUNT2
1387 umount_client $MOUNT3
1391 # resync and verify mirrors
1392 mirror_io resync $tf
1395 local csum=$(mirror_io dump -i ${mirror_array[0]} $tf | md5sum)
1396 for id in ${mirror_array[@]:1}; do
1397 [ "$(mirror_io dump -i $id $tf | md5sum)" = "$csum" ] ||
1398 error "checksum error for mirror $id"
1403 run_test 200 "stress test"
1405 cleanup_test_201() {
1407 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
1409 umount_client $MOUNT2
1413 local delay=${RESYNC_DELAY:-5}
1415 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
1416 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
1418 trap cleanup_test_201 EXIT
1420 CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
1421 changelog_register -n)
1423 mkdir -p $MOUNT2 && mount_client $MOUNT2
1427 local log=$($LFS changelog $MDT0 $index | grep FLRW)
1428 [ -z "$log" ] && { sleep 1; continue; }
1430 index=$(echo $log | awk '{print $1}')
1431 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
1432 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
1433 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
1436 [ -z "$file" ] && continue
1438 local now=$(date +%s)
1440 echo "file: $file $fid was modified at $ts, now: $now, " \
1441 "will be resynced at $((ts+delay))"
1443 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
1445 mirror_io resync $file
1446 echo "$file resync done"
1451 run_test 201 "FLR data mover"
1454 check_and_cleanup_lustre