Whamcloud - gitweb
LU-10448 lod: pick primary mirror for write
[fs/lustre-release.git] / lustre / tests / sanity-flr.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 set -e
6 set +o posix
7
8 SRCDIR=$(dirname $0)
9 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
10
11 ONLY=${ONLY:-"$*"}
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!
15
16 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
17 . $LUSTRE/tests/test-framework.sh
18 init_test_env $@
19 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
20 init_logging
21
22 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
23         { skip "Need MDS version at least 2.10.56"; exit 0; }
24
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
28
29 check_and_setup_lustre
30 DIR=${DIR:-$MOUNT}
31 assert_DIR
32
33 build_test_filter
34
35 # global array to store mirror IDs
36 declare -a mirror_array
37 get_mirror_ids() {
38         local tf=$1
39         local id
40         local array
41
42         array=()
43         for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
44                 array[${#array[@]}]=$((id >> 16))
45         done
46
47         mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
48
49         echo ${#mirror_array[@]}
50 }
51
52 drop_client_cache() {
53         echo 3 > /proc/sys/vm/drop_caches
54 }
55
56 stop_osts() {
57         local idx
58
59         for idx in "$@"; do
60                 stop ost$idx
61         done
62
63         for idx in "$@"; do
64                 wait_osc_import_state client ost$idx DISCONN
65         done
66 }
67
68 start_osts() {
69         local idx
70
71         for idx in "$@"; do
72                 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
73                         error "start ost$idx failed"
74         done
75
76         for idx in "$@"; do
77                 wait_osc_import_state client ost$idx FULL
78         done
79 }
80
81 #
82 # Verify mirror count with an expected value for a given file.
83 #
84 verify_mirror_count() {
85         local tf=$1
86         local expected=$2
87         local mirror_count=$(get_mirror_ids $tf)
88
89         [[ $mirror_count = $expected ]] || {
90                 $LFS getstripe -v $tf
91                 error "verify mirror count failed on $tf:" \
92                       "$mirror_count != $expected"
93         }
94 }
95
96 #
97 # Verify component count with an expected value for a given file.
98 #       $1 coposited layout file
99 #       $2 expected component number
100 #
101 verify_comp_count() {
102         local tf=$1
103         local expected=$2
104         local comp_count=$($LFS getstripe --component-count $tf)
105
106         [[ $comp_count = $expected ]] || {
107                 $LFS getstripe -v $tf
108                 error "verify component count failed on $tf:" \
109                       "$comp_count != $expected"
110         }
111 }
112
113 #
114 # Verify component attribute with an expected value for a given file
115 # and component ID.
116 #
117 verify_comp_attr() {
118         local attr=$1
119         local tf=$2
120         local comp_id=$3
121         local expected=$4
122         local cmd="$LFS getstripe -I$comp_id"
123         local getstripe_cmd="$cmd -v"
124         local value
125
126         case $attr in
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";;
135         esac
136
137         value=$(eval $cmd)
138
139         [ $attr = lcme_flags ] && {
140                 local fl
141                 local expected_list=$(comma_list $expected)
142                 for fl in ${expected_list//,/ }; do
143                         echo $value | grep -q $fl || {
144                                 $getstripe_cmd $tf
145                                 error "expected flag $fl existing on $comp_id"
146                         }
147                 done
148                 return
149         }
150
151         [[ $value = $expected ]] || {
152                 $getstripe_cmd $tf
153                 error "verify $attr failed on $tf: $value != $expected"
154         }
155 }
156
157 #
158 # Verify component extent with expected start and end extent values
159 # for a given file and component ID.
160 #
161 verify_comp_extent() {
162         local tf=$1
163         local comp_id=$2
164         local expected_start=$3
165         local expected_end=$4
166
167         verify_comp_attr comp-start $tf $comp_id $expected_start
168         verify_comp_attr comp-end $tf $comp_id $expected_end
169 }
170
171 #
172 # Verify component attribute with parent directory for a given file
173 # and component ID.
174 #
175 verify_comp_attr_with_parent() {
176         local attr=$1
177         local tf=$2
178         local comp_id=$3
179         local td=$(cd $(dirname $tf); echo $PWD)
180         local tf_cmd="$LFS getstripe -I$comp_id"
181         local td_cmd="$LFS getstripe"
182         local opt
183         local expected
184         local value
185
186         case $attr in
187                 stripe-size) opt="-S" ;;
188                 stripe-count) opt="-c" ;;
189                 pool) opt="-p" ;;
190                 *) error "invalid attribute $attr";;
191         esac
192
193         expected=$($td_cmd $opt $td)
194         [[ $expected = -1 ]] && expected=$OSTCOUNT
195
196         value=$($tf_cmd $opt $tf)
197         [[ $value = -1 ]] && value=$OSTCOUNT
198
199         [[ $value = $expected ]] || {
200                 $td_cmd -d $td
201                 $tf_cmd -v $tf
202                 error "verify $attr failed with parent on $tf:" \
203                       "$value != $expected"
204         }
205 }
206
207 #
208 # Verify component attributes with parent directory for a given file
209 # and component ID.
210 #
211 # This will only verify the inherited attributes:
212 # stripe size, stripe count and OST pool name
213 #
214 verify_comp_attrs_with_parent() {
215         local tf=$1
216         local comp_id=$2
217
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
221 }
222
223 # command line test cases
224 test_0a() {
225         local td=$DIR/$tdir
226         local tf=$td/$tfile
227         local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
228         local mirror_cmd="$LFS mirror create"
229         local id
230         local ids
231         local i
232
233         # create parent directory
234         mkdir $td || error "mkdir $td failed"
235
236         $mirror_cmd $tf &> /dev/null && error "miss -N option"
237
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
243
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))"
247
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
255         done
256
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
264         done
265 }
266 run_test 0a "lfs mirror create with -N option"
267
268 test_0b() {
269         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
270
271         local td=$DIR/$tdir
272         local tf=$td/$tfile
273         local mirror_cmd="$LFS mirror create"
274         local ids
275         local i
276
277         # create parent directory
278         mkdir $td || error "mkdir $td failed"
279
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
288         done
289
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
295
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
300
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
305
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
310
311         # verify component ${ids[4]}
312         verify_comp_attrs_with_parent $tf ${ids[4]}
313 }
314 run_test 0b "lfs mirror create plain layout mirrors"
315
316 test_0c() {
317         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
318
319         local td=$DIR/$tdir
320         local tf=$td/$tfile
321         local mirror_cmd="$LFS mirror create"
322         local ids
323         local i
324
325         # create parent directory
326         mkdir $td || error "mkdir $td failed"
327
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 \
330                     -N --parent \
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' ' '))
335
336         # verify components ${ids[0]} and ${ids[2]}
337         for i in 0 2; do
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
343         done
344
345         # verify components ${ids[1]} and ${ids[3]}
346         for i in 1 3; do
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
351         done
352
353         # verify component ${ids[4]}
354         verify_comp_attrs_with_parent $tf ${ids[4]}
355         verify_comp_extent $tf ${ids[4]} 0 EOF
356
357         # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
358         for i in 5 7 9; do
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
363         done
364
365         # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
366         for i in 6 8 10; do
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
371         done
372 }
373 run_test 0c "lfs mirror create composite layout mirrors"
374
375 test_0d() {
376         local td=$DIR/$tdir
377         local tf=$td/$tfile
378         local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
379         local mirror_cmd="$LFS mirror extend"
380         local ids
381         local i
382
383         # create parent directory
384         mkdir $td || error "mkdir $td failed"
385
386         $mirror_cmd $tf &> /dev/null && error "miss -N option"
387         $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
388
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
397         done
398
399         lfsck_verify_pfid $tf || error "PFID is not set"
400
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"
404
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"
407
408         $mirror_cmd -N -f $tf-2 -N --parent $tf-1 &> /dev/null &&
409                 error "--parent option should not be specified with -f option"
410
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
418         done
419
420         $mirror_cmd -N $tf-1 &> /dev/null &&
421                 error "exceeded maximum mirror count $mirror_count" || true
422 }
423 run_test 0d "lfs mirror extend with -N option"
424
425 test_0e() {
426         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
427
428         local td=$DIR/$tdir
429         local tf=$td/$tfile
430         local mirror_cmd="$LFS mirror extend"
431         local ids
432         local i
433
434         # create parent directory
435         mkdir $td || error "mkdir $td failed"
436
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"
440
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
449         done
450
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
456
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
462
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
467
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
472
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
477
478         # verify component ${ids[5]}
479         verify_comp_attrs_with_parent $tf ${ids[5]}
480 }
481 run_test 0e "lfs mirror extend plain layout mirrors"
482
483 test_0f() {
484         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
485
486         local td=$DIR/$tdir
487         local tf=$td/$tfile
488         local mirror_cmd="$LFS mirror extend"
489         local ids
490         local i
491
492         # create parent directory
493         mkdir $td || error "mkdir $td failed"
494
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"
498
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 \
501                     -N --parent \
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' ' '))
506
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
512
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
518
519         # verify components ${ids[2]} and ${ids[4]}
520         for i in 2 4; do
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
526         done
527
528         # verify components ${ids[3]} and ${ids[5]}
529         for i in 3 5; do
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
534         done
535
536         # verify component ${ids[6]}
537         verify_comp_attrs_with_parent $tf ${ids[6]}
538         verify_comp_extent $tf ${ids[6]} 0 EOF
539
540         # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
541         for i in 7 9 11; do
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
546         done
547
548         # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
549         for i in 8 10 12; do
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
554         done
555 }
556 run_test 0f "lfs mirror extend composite layout mirrors"
557
558 test_0g() {
559         local tf=$DIR/$tfile
560
561         $LFS mirror create -N -E 1M -o0 --flags=prefer -E eof -o1 -N -o1 $tf ||
562                 error "create mirrored file $tf failed"
563
564         verify_comp_attr lcme_flags $tf 0x10001 prefer
565         verify_comp_attr lcme_flags $tf 0x10002 prefer
566
567         # write to the mirrored file and check primary
568         cp /etc/hosts $tf || error "error writing file '$tf'"
569
570         verify_comp_attr lcme_flags $tf 0x20003 stale
571
572         # resync file and check prefer flag
573         $LFS mirror resync $tf || error "error resync-ing file '$tf'"
574
575         cancel_lru_locks osc
576         $LCTL set_param osc.*.stats=clear
577         cat $tf &> /dev/null || error "error reading file '$tf'"
578
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"
583 }
584 run_test 0g "lfs mirror create flags support"
585
586 test_0h() {
587         local tf=$DIR/$tfile
588
589         $LFS mirror create -N -E 1M --flags=prefer -E eof -N2 $tf ||
590                 error "create mirrored file $tf failed"
591
592         verify_comp_attr lcme_flags $tf 0x10001 prefer
593         verify_comp_attr lcme_flags $tf 0x10002 prefer
594
595         # set flags to the first component
596         $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
597
598         verify_comp_attr lcme_flags $tf 0x10001 stale
599         verify_comp_attr lcme_flags $tf 0x10002 prefer
600
601         $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
602                 error "clearing 'stale' should fail"
603
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'"
608
609         $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
610                 error "error setting flag prefer"
611
612         verify_comp_attr lcme_flags $tf 0x20003 prefer
613 }
614 run_test 0h "set, clear and test flags for FLR files"
615
616 test_1() {
617         local tf=$DIR/$tfile
618         local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
619         local mirror_create_cmd="$LFS mirror create"
620         local stripes[0]=$OSTCOUNT
621
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
627
628                 mirror_create_cmd+=" -N -c ${stripes[$i]}"
629         done
630
631         $mirror_create_cmd $tf || error "create mirrored file $tf failed"
632         verify_mirror_count $tf $mirror_count
633
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"
637
638         local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
639                         tr '\n' ' '))
640
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
645         done
646 }
647 run_test 1 "create components with setstripe options"
648
649 test_2() {
650         local tf=$DIR/$tfile
651         local tf2=$DIR/$tfile-2
652
653         $LFS setstripe -E 1M -E EOF -c 1 $tf
654         $LFS setstripe -E 2M -E EOF -c -1 $tf2
655
656         local layout=$($LFS getstripe $tf2 | grep -A 4 lmm_objects)
657
658         $LFS mirror extend -N -f $tf2 $tf ||
659                 error "merging $tf2 into $tf failed"
660
661         verify_mirror_count $tf 2
662         [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
663 }
664 run_test 2 "create components from existing files"
665
666 test_3() {
667         [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
668
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
672         done
673
674         $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
675                 $DIR/$tdir-0/$tfile || error "creating mirrors"
676
677         # mdt doesn't support to cancel layout lock for remote objects, do
678         # it here manually.
679         cancel_lru_locks mdc
680
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"; }
685
686         # cleanup
687         rm -rf $DIR/$tdir-*
688 }
689 run_test 3 "create components from files located on different MDTs"
690
691 test_4() {
692         local tf=$DIR/$tdir/$tfile
693         local ids=()
694
695         test_mkdir $DIR/$tdir
696
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"
700
701         [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
702                 x"mirrored" ] || error "failed to create mirrored dir"
703
704         touch $tf
705         verify_mirror_count $tf 2
706
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
710
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"
715
716         # mirror extend won't be applied to directory
717         $LFS mirror extend -N2 $DIR/$tdir &&
718                 error "expecting mirror extend failure"
719         true
720 }
721 run_test 4 "Make sure mirror attributes can be inhertied from directory"
722
723 test_5() {
724         local tf=$DIR/$tfile
725         local ids=()
726
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"
730
731         $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
732         verify_mirror_count $tf 3
733
734         $CHECKSTAT -t file -s 12345 $tf ||
735                 error "size error after attaching layout "
736 }
737 run_test 5 "Make sure init size work for mirrored layout"
738
739 # LU=10112: disable dom+flr for phase 1
740 test_6() {
741         local tf=$DIR/$tfile
742
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"
745
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"
748
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"
752
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"
756
757         true
758 }
759 run_test 6 "DoM and FLR won't co-exist for phase 1"
760
761 test_21() {
762         local tf=$DIR/$tfile
763         local tf2=$DIR/$tfile-2
764
765         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
766
767         $LFS setstripe -E EOF -o 0 $tf
768         $LFS setstripe -E EOF -o 1 $tf2
769
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
773
774         # for zfs - sync OST dataset so that du below will return
775         # accurate results
776         [ "$FSTYPE" = "zfs" ] &&
777                 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
778
779         local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
780
781         # add component
782         $LFS mirror extend -N -f $tf2 $tf ||
783                 error "merging $tf2 into $tf failed"
784
785         # cancel layout lock
786         cancel_lru_locks mdc
787
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"
791 }
792 run_test 21 "glimpse should report accurate i_blocks"
793
794 get_osc_lock_count() {
795         local lock_count=0
796
797         for idx in "$@"; do
798                 local osc_name
799                 local count
800
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))
804         done
805         echo $lock_count
806 }
807
808 test_22() {
809         local tf=$DIR/$tfile
810
811         $LFS setstripe -E EOF -o 0 $tf
812         dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
813
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"
817
818         size_blocks=$(stat --format="%b %s" $tf)
819
820         cancel_lru_locks mdc
821         cancel_lru_locks osc
822
823         local new_size_blocks=$(stat --format="%b %s" $tf)
824
825         # make sure there is no lock cached
826         [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
827
828         [ "$new_size_blocks" = "$size_blocks" ] ||
829                 echo "size expected: $size_blocks, actual: $new_size_blocks"
830
831         rm -f $tmpfile
832 }
833 run_test 22 "no glimpse to OSTs for READ_ONLY files"
834
835 test_31() {
836         local tf=$DIR/$tfile
837
838         $LFS mirror create -N -o 0 -N -o 1 $tf ||
839                 error "creating mirrored file $tf failed"
840
841         #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
842         $LCTL set_param fail_loc=0x1A00
843
844         local ost_idx
845         for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
846                 cancel_lru_locks osc
847                 stop_osts $ost_idx
848
849                 local tmpfile=$(mktemp)
850                 stat --format="%b %s" $tf > $tmpfile  &
851                 local pid=$!
852
853                 local cnt=0
854                 while [ $cnt -le 5 ]; do
855                         kill -0 $pid > /dev/null 2>&1 || break
856                         sleep 1
857                         ((cnt += 1))
858                 done
859                 kill -0 $pid > /dev/null 2>&1 &&
860                         error "stat process stuck due to unavailable OSTs"
861
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"
865
866                 start_osts $ost_idx
867         done
868 }
869 run_test 31 "make sure glimpse request can be retried"
870
871 test_32() {
872         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
873         rm -f $DIR/$tfile $DIR/$tfile-2
874
875         $LFS setstripe -E EOF -o 0 $DIR/$tfile
876         dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
877
878         local fsize=$(stat -c %s $DIR/$tfile)
879         [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
880
881         local cksum=$(md5sum $DIR/$tfile)
882
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"
886
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"; }
890
891         drop_client_cache
892         stop_osts 1
893
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)"
897
898         echo "reading file from the 2nd mirror and verify checksum"
899         [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
900                 error "checksum error: expected $cksum"
901
902         start_osts 1
903 }
904 run_test 32 "data should be mirrored to newly created mirror"
905
906 test_33() {
907         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
908
909         rm -f $DIR/$tfile $DIR/$tfile-2
910
911         # create a file with two mirrors
912         $LFS setstripe -E EOF -o 0 $DIR/$tfile
913         local max_count=100
914         local count=0
915         while [ $count -lt $max_count ]; do
916                 echo "ost1" >> $DIR/$tfile
917                 count=$((count + 1));
918         done
919
920         # tmp file that will be used as mirror
921         $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
922         count=0
923         while [ $count -lt $max_count ]; do
924                 echo "ost2" >> $DIR/$tfile-2
925                 count=$((count + 1));
926         done
927
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"
935
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"; }
939
940         [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
941
942         # execpted file size
943         local fsize=$((5 * max_count))
944         $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
945                 error "mirrored file size is not $fsize"
946
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\""
952
953         # read file again with ost1 failed
954         stop_osts 1
955         drop_client_cache
956
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\""
961
962         # remount ost1
963         start_osts 1
964
965         # read file again with ost2 failed
966         $LCTL set_param ldlm.namespaces.lustre-*-osc-ffff*.lru_size=clear
967
968         fail ost2 &
969         sleep 1
970
971         # check size, glimpse should work
972         $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
973                 error "mirrored file size is not $fsize"
974
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\""
979
980         wait_osc_import_state client ost2 FULL
981 }
982 run_test 33 "read can choose available mirror to read"
983
984 test_34a() {
985         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
986
987         rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
988
989         # reference file
990         $LFS setstripe -o 0 $DIR/$tfile-ref
991         dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
992
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
996
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
999
1000         $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1001                 error "mirrored file size is not 3M"
1002
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"
1006
1007         cancel_lru_locks osc
1008
1009         # stop two OSTs, so the 2nd stripe of the 1st mirror and
1010         # the 1st stripe of the 2nd mirror will be inaccessible, ...
1011         stop_osts 2 3
1012
1013         echo "comparing files ... "
1014
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"
1019
1020         start_osts 2 3
1021 }
1022 run_test 34a "read mirrored file with multiple stripes"
1023
1024 test_34b() {
1025         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1026
1027         rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1028
1029         # reference file
1030         $LFS setstripe -o 0 $DIR/$tfile-ref
1031         dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1032
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
1035
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
1038
1039         $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1040                 error "mirrored file size is not 3M"
1041
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"
1045
1046         cancel_lru_locks osc
1047
1048         # stop two OSTs, so the 2nd component of the 1st mirror and
1049         # the 1st component of the 2nd mirror will be inaccessible, ...
1050         stop_osts 2 3
1051
1052         echo "comparing files ... "
1053
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"
1058
1059         start_osts 2 3
1060 }
1061 run_test 34b "read mirrored file with multiple components"
1062
1063 test_35() {
1064         local tf=$DIR/$tfile
1065
1066         $LFS setstripe -E eof $tf
1067
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"
1071
1072         $MULTIOP $tf oO_WRONLY:c ||
1073                 error "write open a mirrored file failed"
1074
1075         # truncate file should return error
1076         $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1077 }
1078 run_test 35 "allow to write to mirrored files"
1079
1080 verify_ost_layout_version() {
1081         local tf=$1
1082
1083         # get file layout version
1084         local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1085
1086         # layout version from OST objects
1087         local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1088
1089         [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1090 }
1091
1092 create_file_36() {
1093         local tf
1094
1095         for tf in "$@"; do
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
1098
1099                 $LFS mirror extend -N -f $tf-tmp $tf ||
1100                         error "merging $tf-tmp into $tf failed"
1101         done
1102 }
1103
1104 test_36() {
1105         local tf=$DIR/$tfile
1106
1107         create_file_36 $tf $tf-2 $tf-3
1108
1109         [ $(get_mirror_ids $tf) -gt 1 ] || error "wrong mirror count"
1110
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"
1114
1115         # write open file should not return error
1116         $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1117
1118         # instantiate components should work
1119         dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1120
1121         # verify OST layout version
1122         verify_ost_layout_version $tf
1123
1124         # test case 2
1125         local mds_idx=mds$(($($LFS getstripe -M $tf-2) + 1))
1126
1127         local delay_sec=10
1128         do_facet $mds_idx $LCTL set_param fail_val=$delay_sec
1129
1130         #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1131         do_facet $mds_idx $LCTL set_param fail_loc=0x1A01
1132
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"
1136
1137         [ $(date +%s) -ge $((st+delay_sec)) ] ||
1138                 error "write finished before layout version is transmitted"
1139
1140         # verify OST layout version
1141         verify_ost_layout_version $tf
1142
1143         do_facet $mds_idx $LCTL set_param fail_loc=0
1144
1145         # test case 3
1146         mds_idx=mds$(($($LFS getstripe -M $tf-3) + 1))
1147
1148         #define OBD_FAIL_FLR_LV_INC 0x1A02
1149         do_facet $mds_idx $LCTL set_param fail_loc=0x1A02
1150
1151         # write open file should return error
1152         $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1153                 error "write a mirrored file succeeded" || true
1154
1155         do_facet $mds_idx $LCTL set_param fail_loc=0
1156 }
1157 run_test 36 "write to mirrored files"
1158
1159 create_files_37() {
1160         local tf
1161         local fsize=$1
1162
1163         echo "create test files with size $fsize .."
1164
1165         shift
1166         for tf in "$@"; do
1167                 $LFS setstripe -E 1M -c 1 -E eof -c -1 $tf
1168
1169                 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1170                 $TRUNCATE $tf $fsize
1171         done
1172 }
1173
1174 test_37()
1175 {
1176         local tf=$DIR/$tfile
1177         local tf2=$DIR/$tfile-2
1178         local tf3=$DIR/$tfile-3
1179
1180         create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1181
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' ')
1187
1188         printf '%s\n' "${checksums[@]}"
1189
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"
1195
1196         get_mirror_ids $tf
1197
1198         # verify mirror read, checksums should equal to the original files'
1199         echo "Verifying mirror read .."
1200
1201         local sum
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\'"
1206         done
1207
1208         # verify mirror copy, write to this mirrored file will invalidate
1209         # the other two mirrors
1210         echo "Verifying mirror copy .."
1211
1212         local osts=$(comma_list $(osts_nodes))
1213
1214         # define OBD_FAIL_OST_SKIP_LV_CHECK     0x241
1215         do_nodes $osts lctl set_param fail_loc=0x241
1216
1217         mirror_io copy -i ${mirror_array[0]} \
1218                 -t $(echo ${mirror_array[@]:1} | tr ' ' ',') $tf ||
1219                         error "mirror copy error"
1220
1221         do_nodes $osts lctl set_param fail_loc=0
1222
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"
1229         done
1230
1231         rm -f $tf
1232 }
1233 run_test 37 "mirror I/O API verification"
1234
1235 verify_flr_state()
1236 {
1237         local tf=$1
1238         local expected_state=$2
1239
1240         local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
1241         [ $expected_state = $state ] ||
1242                 error "expected: $expected_state, actual $state"
1243 }
1244
1245 test_38() {
1246         local tf=$DIR/$tfile
1247         local ref=$DIR/${tfile}-ref
1248
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
1252
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"
1260
1261         verify_flr_state $tf "ro"
1262
1263         dd if=/dev/urandom of=$ref  bs=1M count=16 &> /dev/null
1264
1265         local fsize=$((RANDOM << 8 + 1048576))
1266         $TRUNCATE $ref $fsize
1267
1268         local ref_cksum=$(md5sum $ref | cut -f 1 -d' ')
1269
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"
1273
1274         local file_cksum=$(md5sum $tf | cut -f 1 -d' ')
1275         [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1276
1277         get_mirror_ids $tf
1278         echo "mirror IDs: ${mirror_array[@]}"
1279
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; }
1286
1287                 stale_mirror=$id
1288         done
1289
1290         [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1291         [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1292
1293         mirror_io resync $tf || error "resync failed"
1294         verify_flr_state $tf "ro"
1295
1296         mirror_cksum=$(mirror_io dump -i $stale_mirror $tf |
1297                         md5sum | cut -f 1 -d' ')
1298         [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1299
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
1302         # write.
1303         $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1304         verify_flr_state $tf "wp"
1305
1306         mirror_io resync -e resync_start $tf && error "resync succeeded"
1307         verify_flr_state $tf "sp"
1308
1309         # from sync_pending to write_pending
1310         $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1311         verify_flr_state $tf "wp"
1312
1313         mirror_io resync -e resync_start $tf && error "resync succeeded"
1314         verify_flr_state $tf "sp"
1315
1316         # from sync_pending to read_only
1317         mirror_io resync $tf || error "resync failed"
1318         verify_flr_state $tf "ro"
1319 }
1320 run_test 38 "resync"
1321
1322 test_39() {
1323         local tf=$DIR/$tfile
1324
1325         rm -f $tf
1326         $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1327         error "create PFL file $tf failed"
1328
1329         verify_mirror_count $tf 2
1330         verify_comp_count $tf 4
1331
1332         rm -f $tf || error "delete $tf failed"
1333 }
1334 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1335
1336 test_40() {
1337         local tf=$DIR/$tfile
1338         local ops
1339
1340         for ops in "conv=notrunc" ""; do
1341                 rm -f $tf
1342
1343                 $LFS mirror create -N -E2m -E4m -E-1  --flags=prefer \
1344                                 -N -E1m -E2m -E4m -E-1 $tf ||
1345                         error "create PFLR file $tf failed"
1346                 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1347                         error "write PFLR file $tf failed"
1348
1349                 lfs getstripe -vy $tf
1350
1351                 local flags
1352
1353                 # file mirror state should be write_pending
1354                 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1355                 [ $flags = wp ] ||
1356                 error "file mirror state $flags"
1357                 # the 1st component (in mirror 1) should be inited
1358                 verify_comp_attr lcme_flags $tf 0x10001 init
1359                 # the 2nd component (in mirror 1) should be inited
1360                 verify_comp_attr lcme_flags $tf 0x10002 init
1361                 # the 3rd component (in mirror 1) should be uninited
1362                 verify_comp_attr lcme_flags $tf 0x10003 prefer
1363                 # the 4th component (in mirror 2) should be inited
1364                 verify_comp_attr lcme_flags $tf 0x20004 init
1365                 # the 5th component (in mirror 2) should be uninited
1366                 verify_comp_attr lcme_flags $tf 0x20005 0
1367                 # the 6th component (in mirror 2) should be stale
1368                 verify_comp_attr lcme_flags $tf 0x20006 stale
1369                 # the 7th component (in mirror 2) should be uninited
1370                 if [[ x$ops = "xconv=notrunc" ]]; then
1371                         verify_comp_attr lcme_flags $tf 0x20007 0
1372                 elif [[ x$ops = "x" ]]; then
1373                         verify_comp_attr lcme_flags $tf 0x20007 stale
1374                 fi
1375         done
1376
1377         rm -f $tf || error "delete $tf failed"
1378 }
1379 run_test 40 "PFLR rdonly state instantiation check"
1380
1381 test_41() {
1382         local tf=$DIR/$tfile
1383
1384         rm -f $tf $tf-1
1385         $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 $tf ||
1386                 error "create PFLR file $tf failed"
1387         $LFS mirror create -N -E4m -E-1 -N -E2m -E3m -E-1 $tf-1 ||
1388                 error "create PFLR file $tf-1 failed"
1389
1390         # file should be in ro status
1391         verify_flr_state $tf "ro"
1392         verify_flr_state $tf-1 "ro"
1393
1394         # write data in [0, 2M)
1395         dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1396                 error "writing $tf failed"
1397         dd if=/dev/zero of=$tf-1 bs=1M count=4 conv=notrunc ||
1398                 error "writing $tf-1 failed"
1399
1400         verify_flr_state $tf "wp"
1401         verify_flr_state $tf-1 "wp"
1402
1403         # file should have stale component
1404         $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1405                 error "after writing $tf, it does not contain stale component"
1406         $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1407                 error "after writing $tf-1, it does not contain stale component"
1408
1409         $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1410
1411         verify_flr_state $tf "ro"
1412         verify_flr_state $tf-1 "ro"
1413
1414         # file should not have stale component
1415         $LFS getstripe $tf | grep lcme_flags | grep stale &&
1416                 error "after resyncing $tf, it contains stale component"
1417         $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1418                 error "after resyncing $tf, it contains stale component"
1419
1420         return 0
1421 }
1422 run_test 41 "lfs mirror resync check"
1423
1424 test_42() {
1425         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1426
1427         local td=$DIR/$tdir
1428         local tf=$td/$tfile
1429         local mirror_cmd="$LFS mirror verify"
1430         local i
1431
1432         # create parent directory
1433         mkdir $td || error "mkdir $td failed"
1434
1435         $mirror_cmd &> /dev/null && error "no file name given"
1436         $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1437         $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1438
1439         # create mirrored files
1440         $LFS mirror create -N -E 4M -E 10M -E EOF $tf ||
1441                 error "create mirrored file $tf failed"
1442         $LFS mirror create -N -E 2M -E EOF \
1443                            -N -E 6M -E 8M -E EOF \
1444                            -N -E 16M -E EOF $tf-1 ||
1445                 error "create mirrored file $tf-1 failed"
1446         $LFS mirror create -N -c 2 -o 1,3 -N -S 4M -c -1 $tf-2 ||
1447                 error "create mirrored file $tf-2 failed"
1448
1449         # write data in [0, 10M)
1450         for i in $tf $tf-1 $tf-2; do
1451                 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1452                         error "write $i failed"
1453         done
1454
1455         # resync the mirrored files
1456         $LFS mirror resync $tf-1 $tf-2 ||
1457                 error "resync $tf-1 $tf-2 failed"
1458
1459         # verify the mirrored files
1460         $mirror_cmd $tf-1 $tf-2 ||
1461                 error "verify $tf-1 $tf-2 failed"
1462
1463         get_mirror_ids $tf-1
1464         $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1465                 error "at least 2 mirror ids needed with '--only' option"
1466         $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1467                 &> /dev/null &&
1468                 error "'--only' option cannot be used upon multiple files"
1469         $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1470                 error "invalid specified mirror ids"
1471
1472         # change the content of $tf and merge it into $tf-1
1473         for i in 6 10; do
1474                 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1475                         error "change $tf with seek=$i failed"
1476                 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1477                         error "change $tf-1 with seek=$i failed"
1478         done
1479
1480         $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1481         $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1482                 error "merge $tf into $tf-1 failed"
1483
1484         # verify the mirrored files
1485         echo "Verify $tf-1 without -v option:"
1486         $mirror_cmd $tf-1 &&
1487                 error "verify $tf-1 should fail" || echo "PASS"
1488
1489         echo "Verify $tf-1 with -v option:"
1490         $mirror_cmd -v $tf-1 &&
1491                 error "verify $tf-1 should fail"
1492
1493         get_mirror_ids $tf-1
1494         echo "Verify $tf-1 with --only option:"
1495         $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1496                 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1497                       "${mirror_array[-1]} should fail"
1498
1499         $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1500                 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1501                       "${mirror_array[1]} should succeed"
1502
1503         # set stale components in $tf-1
1504         for i in 0x40002 0x40003; do
1505                 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1506                         error "set stale flag on component $i failed"
1507         done
1508
1509         # verify the mirrored file
1510         echo "Verify $tf-1 with stale components:"
1511         $mirror_cmd -vvv $tf-1 ||
1512                 error "verify $tf-1 with stale components should succeed"
1513
1514         echo "Verify $tf-1 with stale components and --only option:"
1515         $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1516                 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1517                       "${mirror_array[-1]} should succeed"
1518 }
1519 run_test 42 "lfs mirror verify"
1520
1521 # inactivate one OST && write && restore the OST
1522 write_file_43() {
1523         local file=$1
1524         local ost=$2
1525         local PARAM="osc.${FSNAME}-OST000${ost}-osc-M*.active"
1526         local wait
1527
1528         wait=$(do_facet $SINGLEMDS \
1529                 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1530         wait=${wait%%[^0-9]*}
1531
1532         echo "deactivate OST$ost, waiting for $((wait*2)) seconds"
1533         $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1534         # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1535         sleep $(($wait * 2))
1536         echo "write $file"
1537         dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1538         echo "restore activating OST$ost, waiting for $((wait*2)) seconds"
1539         $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1540         sleep $((wait * 2))
1541
1542         local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1543         [ $flags = wp ] || error "file mirror state $flags != wp"
1544 }
1545
1546 test_43() {
1547         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1548
1549         local tf=$DIR/$tfile
1550         local flags
1551
1552         rm -f $tf
1553         ##   mirror 0  ost (0, 1)
1554         ##   mirror 1  ost (1, 2)
1555         ##   mirror 2  ost (2, 0)
1556         $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1557                 -N -Eeof -c2 -o2,0 $tf ||
1558                 error "create 3 mirrors file $tf failed"
1559
1560         ################## OST0 ###########################################
1561         write_file_43 $tf 0
1562         verify_comp_attr lcme_flags $tf 0x10001 init,stale
1563         verify_comp_attr lcme_flags $tf 0x20002 init
1564         verify_comp_attr lcme_flags $tf 0x30003 init,stale
1565
1566         # resync
1567         echo "resync $tf"
1568         $LFS mirror resync $tf
1569         flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1570         [ $flags = ro ] || error "file mirror state $flags != ro"
1571
1572         ################## OST1 ###########################################
1573         write_file_43 $tf 1
1574         verify_comp_attr lcme_flags $tf 0x10001 init,stale
1575         verify_comp_attr lcme_flags $tf 0x20002 init,stale
1576         verify_comp_attr lcme_flags $tf 0x30003 init
1577
1578         # resync
1579         echo "resync $tf"
1580         $LFS mirror resync $tf
1581         flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1582         [ $flags = ro ] || error "file mirror state $flags != ro"
1583
1584         ################## OST2 ###########################################
1585         write_file_43 $tf 2
1586         verify_comp_attr lcme_flags $tf 0x10001 init
1587         verify_comp_attr lcme_flags $tf 0x20002 init,stale
1588         verify_comp_attr lcme_flags $tf 0x30003 init,stale
1589 }
1590 run_test 43 "mirror pick on write"
1591
1592 test_44() {
1593         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1594         rm -rf $DIR/$tdir
1595         rm -rf $DIR/$tdir-1
1596         local tf=$DIR/$tdir/$tfile
1597         local tf1=$DIR/$tdir-1/$tfile-1
1598
1599         $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1600                 error "create directory failed"
1601         $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1602                 error "create remote directory failed"
1603         rm -f $tf $tf1 $tf.mirror~2
1604         # create file with 4 mirrors
1605         $LFS mirror create -N -E2m -E4m -E-1 -N -E1m -E2m -E3m -E-1 -N2 $tf ||
1606                 error "create PFLR file $tf failed"
1607
1608         # file should be in ro status
1609         verify_flr_state $tf "ro"
1610
1611         # write data in [0, 3M)
1612         dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1613                 error "writing $tf failed"
1614
1615         verify_flr_state $tf "wp"
1616
1617         # synchronize all mirrors of the file
1618         $LFS mirror resync $tf || error "mirror resync $tf failed"
1619
1620         verify_flr_state $tf "ro"
1621
1622         # split mirror 1
1623         $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1624                 error "split to $tf1 failed"
1625
1626         local idx0=$($LFS getstripe -m $tf)
1627         local idx1=$($LFS getstripe -m $tf1)
1628
1629         [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1630         [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1631
1632         # verify mirror count
1633         verify_mirror_count $tf 3
1634         verify_mirror_count $tf1 1
1635
1636         $LFS mirror split --mirror-id 2 $tf ||
1637                 error "split mirror 2 failed"
1638
1639         verify_mirror_count $tf 2
1640         verify_mirror_count $tf.mirror~2 1
1641
1642         $LFS mirror split --mirror-id 3 -d $tf ||
1643                 error "split and delte mirror 3 failed"
1644         verify_mirror_count $tf 1
1645
1646         # verify splitted file contains the same content as the orig file does
1647         diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
1648         diff $tf $tf.mirror~2 ||
1649                 error "splited file $tf.mirror~2 diffs from $tf"
1650 }
1651 run_test 44 "lfs mirror split check"
1652
1653 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
1654 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
1655
1656 write_file_200() {
1657         local tf=$1
1658
1659         local fsize=$(stat --printf=%s $tf)
1660
1661         while [ -f $ctrl_file ]; do
1662                 local off=$((RANDOM << 8))
1663                 local len=$((RANDOM << 5 + 131072))
1664
1665                 [ $((off + len)) -gt $fsize ] && {
1666                         fsize=$((off + len))
1667                         echo "Extending file size to $fsize .."
1668                 }
1669
1670                 flock -s $lock_file -c \
1671                         "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
1672                                 { rm -f $ctrl_file;
1673                                   error "failed writing to $off:$len"; }
1674                 sleep 0.$((RANDOM % 2 + 1))
1675         done
1676 }
1677
1678 read_file_200() {
1679         local tf=$1
1680
1681         while [ -f $ctrl_file ]; do
1682                 flock -s $lock_file -c "cat $tf &> /dev/null" ||
1683                         { rm -f $ctrl_file; error "read failed"; }
1684                 sleep 0.$((RANDOM % 2 + 1))
1685         done
1686 }
1687
1688 resync_file_200() {
1689         local tf=$1
1690
1691         options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
1692
1693         exec 200<>$lock_file
1694         while [ -f $ctrl_file ]; do
1695                 local lock_taken=false
1696                 local index=$((RANDOM % ${#options[@]}))
1697                 local cmd="mirror_io resync ${options[$index]}"
1698
1699                 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
1700
1701                 [ $((RANDOM % 4)) -eq 0 ] && {
1702                         index=0
1703                         lock_taken=true
1704                         echo -n "lock to "
1705                 }
1706
1707                 echo -n "resync file $tf with '$cmd' .."
1708
1709                 $lock_taken && flock -x 200
1710                 $cmd $tf &> /dev/null && echo "done" || echo "failed"
1711                 $lock_taken && flock -u 200
1712
1713                 sleep 0.$((RANDOM % 8 + 1))
1714         done
1715 }
1716
1717 test_200() {
1718         local tf=$DIR/$tfile
1719         local tf2=$DIR2/$tfile
1720         local tf3=$DIR3/$tfile
1721
1722         $LFS setstripe -E 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
1723         $LFS setstripe -E 2M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
1724         $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
1725
1726         $LFS mirror extend -N -f $tf-2 $tf ||
1727                 error "merging $tf-2 into $tf failed"
1728         $LFS mirror extend -N -f $tf-3 $tf ||
1729                 error "merging $tf-3 into $tf failed"
1730
1731         mkdir -p $MOUNT2 && mount_client $MOUNT2
1732
1733         mkdir -p $MOUNT3 && mount_client $MOUNT3
1734
1735         verify_flr_state $tf3 "ro"
1736
1737         #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
1738         $LCTL set_param fail_loc=0x1A03
1739
1740         local mds_idx=mds$(($($LFS getstripe -M $tf) + 1))
1741         do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
1742
1743         declare -a pids
1744
1745         write_file_200 $tf &
1746         pids+=($!)
1747
1748         read_file_200 $tf &
1749         pids+=($!)
1750
1751         write_file_200 $tf2 &
1752         pids+=($!)
1753
1754         read_file_200 $tf2 &
1755         pids+=($!)
1756
1757         resync_file_200 $tf3 &
1758         pids+=($!)
1759
1760         local sleep_time=60
1761         [ "$SLOW" = "yes" ] && sleep_time=360
1762         while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
1763                 sleep 1
1764                 ((--sleep_time))
1765         done
1766
1767         rm -f $ctrl_file
1768
1769         echo "Waiting ${pids[@]}"
1770         wait ${pids[@]}
1771
1772         umount_client $MOUNT2
1773         umount_client $MOUNT3
1774
1775         rm -f $lock_file
1776
1777         # resync and verify mirrors
1778         mirror_io resync $tf
1779         get_mirror_ids $tf
1780
1781         local csum=$(mirror_io dump -i ${mirror_array[0]} $tf | md5sum)
1782         for id in ${mirror_array[@]:1}; do
1783                 [ "$(mirror_io dump -i $id $tf | md5sum)" = "$csum" ] ||
1784                         error "checksum error for mirror $id"
1785         done
1786
1787         true
1788 }
1789 run_test 200 "stress test"
1790
1791 cleanup_test_201() {
1792         trap 0
1793         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
1794
1795         umount_client $MOUNT2
1796 }
1797
1798 test_201() {
1799         local delay=${RESYNC_DELAY:-5}
1800
1801         MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
1802                awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
1803
1804         trap cleanup_test_201 EXIT
1805
1806         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
1807                         changelog_register -n)
1808
1809         mkdir -p $MOUNT2 && mount_client $MOUNT2
1810
1811         local index=0
1812         while :; do
1813                 local log=$($LFS changelog $MDT0 $index | grep FLRW)
1814                 [ -z "$log" ] && { sleep 1; continue; }
1815
1816                 index=$(echo $log | awk '{print $1}')
1817                 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
1818                 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
1819                 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
1820
1821                 ((++index))
1822                 [ -z "$file" ] && continue
1823
1824                 local now=$(date +%s)
1825
1826                 echo "file: $file $fid was modified at $ts, now: $now, " \
1827                      "will be resynced at $((ts+delay))"
1828
1829                 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
1830
1831                 mirror_io resync $file
1832                 echo "$file resync done"
1833         done
1834
1835         cleanup_test_201
1836 }
1837 run_test 201 "FLR data mover"
1838
1839 test_202() {
1840         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1841
1842         local tf=$DIR/$tfile
1843         local ids
1844
1845         $LFS setstripe -E 1M -c 1 $tf
1846         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1847         verify_comp_attr stripe-count $tf ${ids[0]} 1
1848
1849         $LFS setstripe --component-add -E 2M -c -1 $tf
1850         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1851         verify_comp_attr stripe-count $tf ${ids[0]} 1
1852         verify_comp_attr stripe-count $tf ${ids[1]} -1
1853
1854         dd if=/dev/zero of=$tf bs=1M count=2
1855         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1856         verify_comp_attr stripe-count $tf ${ids[0]} 1
1857         verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
1858 }
1859 run_test 202 "lfs setstripe --add-component wide striping"
1860
1861
1862 complete $SECONDS
1863 check_and_cleanup_lustre
1864 exit_status