Whamcloud - gitweb
LU-11367 som: integrate LSOM with lfs find
[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:    LU-11381
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 get_lustre_env
21 init_logging
22
23 [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
24         { skip "Need MDS version at least 2.10.56"; exit 0; }
25
26 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
27         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
28 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
29
30 check_and_setup_lustre
31 DIR=${DIR:-$MOUNT}
32 assert_DIR
33
34 build_test_filter
35
36 assert_DIR
37 rm -rf $DIR/[Rdfs][0-9]*
38
39 # global array to store mirror IDs
40 declare -a mirror_array
41 get_mirror_ids() {
42         local tf=$1
43         local id
44         local array
45
46         array=()
47         for id in $($LFS getstripe $tf | awk '/lcme_id/{print $2}'); do
48                 array[${#array[@]}]=$((id >> 16))
49         done
50
51         mirror_array=($(printf "%s\n" "${array[@]}" | sort -u))
52
53         echo ${#mirror_array[@]}
54 }
55
56 drop_client_cache() {
57         echo 3 > /proc/sys/vm/drop_caches
58 }
59
60 stop_osts() {
61         local idx
62
63         for idx in "$@"; do
64                 stop ost$idx
65         done
66
67         for idx in "$@"; do
68                 wait_osc_import_state client ost$idx "\(DISCONN\|IDLE\)"
69         done
70 }
71
72 start_osts() {
73         local idx
74
75         for idx in "$@"; do
76                 start ost$idx $(ostdevname $idx) $OST_MOUNT_OPTS ||
77                         error "start ost$idx failed"
78         done
79
80         for idx in "$@"; do
81                 wait_recovery_complete ost$idx
82         done
83 }
84
85 #
86 # Verify mirror count with an expected value for a given file.
87 #
88 verify_mirror_count() {
89         local tf=$1
90         local expected=$2
91         local mirror_count=$($LFS getstripe -N $tf)
92
93         [[ $mirror_count = $expected ]] || {
94                 $LFS getstripe -v $tf
95                 error "verify mirror count failed on $tf:" \
96                       "$mirror_count != $expected"
97         }
98 }
99
100 #
101 # Verify component count with an expected value for a given file.
102 #       $1 coposited layout file
103 #       $2 expected component number
104 #
105 verify_comp_count() {
106         local tf=$1
107         local expected=$2
108         local comp_count=$($LFS getstripe --component-count $tf)
109
110         [[ $comp_count = $expected ]] || {
111                 $LFS getstripe -v $tf
112                 error "verify component count failed on $tf:" \
113                       "$comp_count != $expected"
114         }
115 }
116
117 #
118 # Verify component attribute with an expected value for a given file
119 # and component ID.
120 #
121 verify_comp_attr() {
122         local attr=$1
123         local tf=$2
124         local comp_id=$3
125         local expected=$4
126         local cmd="$LFS getstripe -I$comp_id"
127         local getstripe_cmd="$cmd -v"
128         local value
129
130         case $attr in
131                 stripe-size) cmd+=" -S $tf" ;;
132                 stripe-count) cmd+=" -c $tf" ;;
133                 stripe-index) cmd+=" -i $tf" ;;
134                 pool) cmd+=" -p $tf" ;;
135                 comp-start) cmd+=" --component-start $tf" ;;
136                 comp-end) cmd+=" --component-end $tf" ;;
137                 lcme_flags) cmd+=" $tf | awk '/lcme_flags:/ { print \$2 }'" ;;
138                 *) error "invalid attribute $attr";;
139         esac
140
141         value=$(eval $cmd)
142
143         [ $attr = lcme_flags ] && {
144                 local fl
145                 local expected_list=$(comma_list $expected)
146                 for fl in ${expected_list//,/ }; do
147                         local neg=0
148
149                         [[ ${fl:0:1} = "^" ]] && neg=1
150                         [[ $neg = 1 ]] && fl=${fl:1}
151
152                         $(echo $value | grep -q $fl)
153                         local match=$?
154                         # 0: matched; 1: not matched
155
156                         if  [[ $neg = 0 && $match != 0 ||
157                                $neg = 1 && $match = 0 ]]; then
158                                 $getstripe_cmd $tf
159                                 [[ $neg = 0 ]] && # expect the flag
160                                     error "expected flag '$fl' not in $comp_id"
161                                 [[ $neg = 1 ]] && # not expect the flag
162                                     error "not expected flag '$fl' in $comp_id"
163                         fi
164                 done
165                 return
166         }
167
168         [[ $value = $expected ]] || {
169                 $getstripe_cmd $tf
170                 error "verify $attr failed on $tf: $value != $expected"
171         }
172 }
173
174 #
175 # Verify component extent with expected start and end extent values
176 # for a given file and component ID.
177 #
178 verify_comp_extent() {
179         local tf=$1
180         local comp_id=$2
181         local expected_start=$3
182         local expected_end=$4
183
184         verify_comp_attr comp-start $tf $comp_id $expected_start
185         verify_comp_attr comp-end $tf $comp_id $expected_end
186 }
187
188 #
189 # Verify component attribute with parent directory for a given file
190 # and component ID.
191 #
192 verify_comp_attr_with_parent() {
193         local attr=$1
194         local tf=$2
195         local comp_id=$3
196         local td=$(cd $(dirname $tf); echo $PWD)
197         local tf_cmd="$LFS getstripe -I$comp_id"
198         local td_cmd="$LFS getstripe"
199         local opt
200         local expected
201         local value
202
203         case $attr in
204                 stripe-size) opt="-S" ;;
205                 stripe-count) opt="-c" ;;
206                 pool) opt="-p" ;;
207                 *) error "invalid attribute $attr";;
208         esac
209
210         expected=$($td_cmd $opt $td)
211         [[ $expected = -1 ]] && expected=$OSTCOUNT
212
213         value=$($tf_cmd $opt $tf)
214         [[ $value = -1 ]] && value=$OSTCOUNT
215
216         [[ $value = $expected ]] || {
217                 $td_cmd -d $td
218                 $tf_cmd -v $tf
219                 error "verify $attr failed with parent on $tf:" \
220                       "$value != $expected"
221         }
222 }
223
224 #
225 # Verify component attribute with filesystem-wide default value for a given file
226 # and component ID.
227 #
228 verify_comp_attr_with_default() {
229         local attr=$1
230         local tf=$2
231         local comp_id=$3
232         local tf_cmd="$LFS getstripe -I$comp_id"
233         local opt
234         local expected
235         local value
236
237         case $attr in
238                 stripe-size)
239                         opt="-S"
240                         expected=$($LCTL get_param -n \
241                                    lov.$FSNAME-clilov-*.stripesize)
242                         ;;
243                 stripe-count)
244                         opt="-c"
245                         expected=$($LCTL get_param -n \
246                                    lov.$FSNAME-clilov-*.stripecount)
247                         [[ $expected = -1 ]] && expected=$OSTCOUNT
248                         ;;
249                 *) error "invalid attribute $attr";;
250         esac
251
252         value=$($tf_cmd $opt $tf)
253         [[ $value = -1 ]] && value=$OSTCOUNT
254
255         [[ $value = $expected ]] || {
256                 $tf_cmd -v $tf
257                 error "verify $attr failed with default value on $tf:" \
258                       "$value != $expected"
259         }
260 }
261
262 #
263 # Verify unspecified component attributes for a given file
264 # and component ID.
265 #
266 # This will only verify the inherited attributes:
267 # stripe size, stripe count and OST pool name
268 #
269 verify_comp_attrs() {
270         local tf=$1
271         local comp_id=$2
272
273         verify_comp_attr_with_default stripe-size $tf $comp_id
274         verify_comp_attr_with_default stripe-count $tf $comp_id
275         verify_comp_attr_with_parent pool $tf $comp_id
276 }
277
278 # command line test cases
279 test_0a() {
280         local td=$DIR/$tdir
281         local tf=$td/$tfile
282         local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
283         local mirror_cmd="$LFS mirror create"
284         local id
285         local ids
286         local i
287
288         # create parent directory
289         mkdir $td || error "mkdir $td failed"
290
291         $mirror_cmd $tf &> /dev/null && error "miss -N option"
292
293         $mirror_cmd -N $tf || error "create mirrored file $tf failed"
294         verify_mirror_count $tf 1
295         id=$($LFS getstripe -I $tf)
296         verify_comp_attrs $tf $id
297         verify_comp_extent $tf $id 0 EOF
298
299         $mirror_cmd -N0 $tf-1 &> /dev/null && error "invalid mirror count 0"
300         $mirror_cmd -N$((mirror_count + 1)) $tf-1 &> /dev/null &&
301                 error "invalid mirror count $((mirror_count + 1))"
302
303         $mirror_cmd -N$mirror_count $tf-1 ||
304                 error "create mirrored file $tf-1 failed"
305         verify_mirror_count $tf-1 $mirror_count
306         ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
307         for ((i = 0; i < $mirror_count; i++)); do
308                 verify_comp_attrs $tf-1 ${ids[$i]}
309                 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
310         done
311
312         $mirror_cmd -N -N2 -N3 -N4 $tf-2 ||
313                 error "create mirrored file $tf-2 failed"
314         verify_mirror_count $tf-2 10
315         ids=($($LFS getstripe $tf-2 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
316         for ((i = 0; i < 10; i++)); do
317                 verify_comp_attrs $tf-2 ${ids[$i]}
318                 verify_comp_extent $tf-2 ${ids[$i]} 0 EOF
319         done
320 }
321 run_test 0a "lfs mirror create with -N option"
322
323 test_0b() {
324         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
325
326         local td=$DIR/$tdir
327         local tf=$td/$tfile
328         local mirror_cmd="$LFS mirror create"
329         local ids
330         local i
331
332         # create a new OST pool
333         local pool_name=$TESTNAME
334         create_pool $FSNAME.$pool_name ||
335                 error "create OST pool $pool_name failed"
336
337         # add OSTs into the pool
338         pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
339                 error "add OSTs into pool $pool_name failed"
340
341         # create parent directory
342         mkdir $td || error "mkdir $td failed"
343         $LFS setstripe -S 8M -c -1 -p $pool_name $td ||
344                 error "$LFS setstripe $td failed"
345
346         # create a mirrored file with plain layout mirrors
347         $mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
348                     -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
349                 error "create mirrored file $tf failed"
350         verify_mirror_count $tf 6
351         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
352         for ((i = 0; i < 6; i++)); do
353                 verify_comp_extent $tf ${ids[$i]} 0 EOF
354         done
355
356         # verify component ${ids[0]}
357         verify_comp_attrs $tf ${ids[0]}
358
359         # verify component ${ids[1]}
360         verify_comp_attr stripe-size $tf ${ids[1]} 4194304
361         verify_comp_attr stripe-count $tf ${ids[1]} 2
362         verify_comp_attr stripe-index $tf ${ids[1]} 2
363         verify_comp_attr pool $tf ${ids[1]} flash
364
365         # verify component ${ids[2]}
366         verify_comp_attr stripe-size $tf ${ids[2]} 16777216
367         verify_comp_attr stripe-count $tf ${ids[2]} 2
368         verify_comp_attr pool $tf ${ids[2]} flash
369
370         # verify component ${ids[3]}
371         verify_comp_attr stripe-size $tf ${ids[3]} 16777216
372         verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
373         verify_comp_attr pool $tf ${ids[3]} flash
374
375         # verify component ${ids[4]}
376         verify_comp_attr stripe-size $tf ${ids[4]} 16777216
377         verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
378         verify_comp_attr pool $tf ${ids[4]} archive
379
380         # verify component ${ids[5]}
381         verify_comp_attr stripe-size $tf ${ids[5]} 16777216
382         verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
383         verify_comp_attr_with_parent pool $tf ${ids[5]}
384
385         if [[ $MDS1_VERSION -ge $(version_code 2.12.56) ]] ||
386            [[ $MDS1_VERSION -ge $(version_code 2.12.2) &&
387               $MDS1_VERSION -lt $(version_code 2.12.50) ]]; then
388                 # LU-11022 - remove mirror by pool name
389                 local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
390                 [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
391                 $LFS mirror split --pool archive -d $tf || error "delete mirror"
392                 cnt=$($LFS getstripe $tf | grep archive | wc -l)
393                 [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
394         fi
395
396         # destroy OST pool
397         destroy_test_pools
398 }
399 run_test 0b "lfs mirror create plain layout mirrors"
400
401 test_0c() {
402         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
403
404         local td=$DIR/$tdir
405         local tf=$td/$tfile
406         local mirror_cmd="$LFS mirror create"
407         local ids
408         local i
409
410         # create a new OST pool
411         local pool_name=$TESTNAME
412         create_pool $FSNAME.$pool_name ||
413                 error "create OST pool $pool_name failed"
414
415         # add OSTs into the pool
416         pool_add_targets $pool_name 0 $((OSTCOUNT - 1)) ||
417                 error "add OSTs into pool $pool_name failed"
418
419         # create parent directory
420         mkdir $td || error "mkdir $td failed"
421         $LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
422                 error "$LFS setstripe $td failed"
423
424         # create a mirrored file with composite layout mirrors
425         $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
426                     -N -c 4 -p none \
427                     -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
428                 error "create mirrored file $tf failed"
429         verify_mirror_count $tf 6
430         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
431
432         # verify components ${ids[0]} and ${ids[2]}
433         for i in 0 2; do
434                 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
435                 verify_comp_attr stripe-count $tf ${ids[$i]} 2
436                 verify_comp_attr stripe-index $tf ${ids[$i]} 1
437                 verify_comp_attr pool $tf ${ids[$i]} flash
438                 verify_comp_extent $tf ${ids[$i]} 0 4194304
439         done
440
441         # verify components ${ids[1]} and ${ids[3]}
442         for i in 1 3; do
443                 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
444                 verify_comp_attr stripe-count $tf ${ids[$i]} 2
445                 verify_comp_attr pool $tf ${ids[$i]} flash
446                 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
447         done
448
449         # verify component ${ids[4]}
450         verify_comp_attr stripe-size $tf ${ids[4]} 4194304
451         verify_comp_attr stripe-count $tf ${ids[4]} 4
452         verify_comp_attr_with_parent pool $tf ${ids[4]}
453         verify_comp_extent $tf ${ids[4]} 0 EOF
454
455         # verify components ${ids[5]}, ${ids[7]} and ${ids[9]}
456         for i in 5 7 9; do
457                 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
458                 verify_comp_attr stripe-count $tf ${ids[$i]} 4
459                 verify_comp_attr pool $tf ${ids[$i]} archive
460                 verify_comp_extent $tf ${ids[$i]} 0 536870912
461         done
462
463         # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
464         for i in 6 8 10; do
465                 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
466                 verify_comp_attr stripe-count $tf ${ids[$i]} -1
467                 verify_comp_attr pool $tf ${ids[$i]} archive
468                 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
469         done
470
471         # destroy OST pool
472         destroy_test_pools
473 }
474 run_test 0c "lfs mirror create composite layout mirrors"
475
476 test_0d() {
477         local td=$DIR/$tdir
478         local tf=$td/$tfile
479         local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
480         local mirror_cmd="$LFS mirror extend"
481         local ids
482         local i
483
484         # create parent directory
485         mkdir $td || error "mkdir $td failed"
486
487         $mirror_cmd $tf &> /dev/null && error "miss -N option"
488         $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
489
490         # create a non-mirrored file, convert it to a mirrored file and extend
491         touch $tf || error "touch $tf failed"
492         $mirror_cmd -N $tf || error "convert and extend $tf failed"
493         verify_mirror_count $tf 2
494         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
495         for ((i = 0; i < 2; i++)); do
496                 verify_comp_attrs $tf ${ids[$i]}
497                 verify_comp_extent $tf ${ids[$i]} 0 EOF
498         done
499
500         lfsck_verify_pfid $tf || error "PFID is not set"
501
502         # create a mirrored file and extend it
503         $LFS mirror create -N $tf-1 || error "create mirrored file $tf-1 failed"
504         $LFS mirror create -N $tf-2 || error "create mirrored file $tf-2 failed"
505
506         $mirror_cmd -N -S 4M -N -f $tf-2 $tf-1 &> /dev/null &&
507                 error "setstripe options should not be specified with -f option"
508
509         $mirror_cmd -N$((mirror_count - 1)) $tf-1 ||
510                 error "extend mirrored file $tf-1 failed"
511         verify_mirror_count $tf-1 $mirror_count
512         ids=($($LFS getstripe $tf-1 | awk '/lcme_id/{print $2}' | tr '\n' ' '))
513         for ((i = 0; i < $mirror_count; i++)); do
514                 verify_comp_attrs $tf-1 ${ids[$i]}
515                 verify_comp_extent $tf-1 ${ids[$i]} 0 EOF
516         done
517
518         $mirror_cmd -N $tf-1 &> /dev/null &&
519                 error "exceeded maximum mirror count $mirror_count" || true
520 }
521 run_test 0d "lfs mirror extend with -N option"
522
523 test_0e() {
524         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
525
526         local td=$DIR/$tdir
527         local tf=$td/$tfile
528         local mirror_cmd="$LFS mirror extend"
529         local ids
530         local i
531
532         # create parent directory
533         mkdir $td || error "mkdir $td failed"
534
535         # create a mirrored file with plain layout mirrors
536         $LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
537                 error "create mirrored file $tf failed"
538
539         # extend the mirrored file with plain layout mirrors
540         $mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
541                     -N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
542                 error "extend mirrored file $tf failed"
543         verify_mirror_count $tf 6
544         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
545         for ((i = 0; i < 6; i++)); do
546                 verify_comp_extent $tf ${ids[$i]} 0 EOF
547         done
548
549         # verify component ${ids[0]}
550         verify_comp_attr stripe-size $tf ${ids[0]} 33554432
551         verify_comp_attr stripe-count $tf ${ids[0]} 3
552         verify_comp_attr stripe-index $tf ${ids[0]} 1
553         verify_comp_attr pool $tf ${ids[0]} ssd
554
555         # verify component ${ids[1]}
556         verify_comp_attr stripe-size $tf ${ids[1]} 4194304
557         verify_comp_attr stripe-count $tf ${ids[1]} 2
558         verify_comp_attr stripe-index $tf ${ids[1]} 2
559         verify_comp_attr pool $tf ${ids[1]} flash
560
561         # verify component ${ids[2]}
562         verify_comp_attr stripe-size $tf ${ids[2]} 16777216
563         verify_comp_attr stripe-count $tf ${ids[2]} 2
564         verify_comp_attr pool $tf ${ids[2]} flash
565
566         # verify component ${ids[3]}
567         verify_comp_attr stripe-size $tf ${ids[3]} 16777216
568         verify_comp_attr stripe-count $tf ${ids[3]} $OSTCOUNT
569         verify_comp_attr pool $tf ${ids[3]} flash
570
571         # verify component ${ids[4]}
572         verify_comp_attr stripe-size $tf ${ids[4]} 16777216
573         verify_comp_attr stripe-count $tf ${ids[4]} $OSTCOUNT
574         verify_comp_attr pool $tf ${ids[4]} archive
575
576         # verify component ${ids[5]}
577         verify_comp_attr stripe-size $tf ${ids[5]} 16777216
578         verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT
579         verify_comp_attr_with_parent pool $tf ${ids[5]}
580 }
581 run_test 0e "lfs mirror extend plain layout mirrors"
582
583 test_0f() {
584         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
585
586         local td=$DIR/$tdir
587         local tf=$td/$tfile
588         local mirror_cmd="$LFS mirror extend"
589         local ids
590         local i
591
592         # create parent directory
593         mkdir $td || error "mkdir $td failed"
594
595         # create a mirrored file with composite layout mirror
596         $LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
597                 error "create mirrored file $tf failed"
598
599         # extend the mirrored file with composite layout mirrors
600         $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
601                     -N -c -1 -p none \
602                     -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
603                 error "extend mirrored file $tf failed"
604         verify_mirror_count $tf 7
605         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
606
607         # verify component ${ids[0]}
608         verify_comp_attr stripe-size $tf ${ids[0]} 16777216
609         verify_comp_attr_with_default stripe-count $tf ${ids[0]}
610         verify_comp_attr pool $tf ${ids[0]} ssd
611         verify_comp_extent $tf ${ids[0]} 0 33554432
612
613         # verify component ${ids[1]}
614         verify_comp_attr stripe-size $tf ${ids[1]} 33554432
615         verify_comp_attr_with_default stripe-count $tf ${ids[1]}
616         verify_comp_attr pool $tf ${ids[1]} ssd
617         verify_comp_extent $tf ${ids[1]} 33554432 EOF
618
619         # verify components ${ids[2]} and ${ids[4]}
620         for i in 2 4; do
621                 verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
622                 verify_comp_attr stripe-count $tf ${ids[$i]} 2
623                 verify_comp_attr stripe-index $tf ${ids[$i]} 1
624                 verify_comp_attr pool $tf ${ids[$i]} flash
625                 verify_comp_extent $tf ${ids[$i]} 0 4194304
626         done
627
628         # verify components ${ids[3]} and ${ids[5]}
629         for i in 3 5; do
630                 verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
631                 verify_comp_attr stripe-count $tf ${ids[$i]} 2
632                 verify_comp_attr pool $tf ${ids[$i]} flash
633                 verify_comp_extent $tf ${ids[$i]} 4194304 EOF
634         done
635
636         # verify component ${ids[6]}
637         verify_comp_attr stripe-size $tf ${ids[6]} 4194304
638         verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
639         verify_comp_attr_with_parent pool $tf ${ids[6]}
640         verify_comp_extent $tf ${ids[6]} 0 EOF
641
642         # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
643         for i in 7 9 11; do
644                 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
645                 verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
646                 verify_comp_attr pool $tf ${ids[$i]} archive
647                 verify_comp_extent $tf ${ids[$i]} 0 536870912
648         done
649
650         # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
651         for i in 8 10 12; do
652                 verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
653                 verify_comp_attr stripe-count $tf ${ids[$i]} -1
654                 verify_comp_attr pool $tf ${ids[$i]} archive
655                 verify_comp_extent $tf ${ids[$i]} 536870912 EOF
656         done
657 }
658 run_test 0f "lfs mirror extend composite layout mirrors"
659
660 test_0g() {
661         local tf=$DIR/$tfile
662
663         $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
664                            -N -o1 $tf || error "create mirrored file $tf failed"
665
666         verify_comp_attr lcme_flags $tf 0x10001 prefer
667         verify_comp_attr lcme_flags $tf 0x10002 prefer
668
669         # write to the mirrored file and check primary
670         cp /etc/hosts $tf || error "error writing file '$tf'"
671
672         verify_comp_attr lcme_flags $tf 0x20003 stale
673
674         # resync file and check prefer flag
675         $LFS mirror resync $tf || error "error resync-ing file '$tf'"
676
677         cancel_lru_locks osc
678         $LCTL set_param osc.*.stats=clear
679         cat $tf &> /dev/null || error "error reading file '$tf'"
680
681         # verify that the data was provided by OST1 where mirror 1 resides
682         local nr_read=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[-0-9a-f]*.stats |
683                         awk '/ost_read/{print $2}')
684         [ -n "$nr_read" ] || error "read was not provided by OST1"
685 }
686 run_test 0g "lfs mirror create flags support"
687
688 test_0h() {
689         [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
690                 skip "Need MDS version at least 2.11.57"
691
692         local td=$DIR/$tdir
693         local tf=$td/$tfile
694         local ids
695         local i
696
697         # create parent directory
698         test_mkdir $td || error "mkdir $td failed"
699
700         $LFS setstripe -N -E 1M -S 1M --flags=prefer -E eof -N2 $td ||
701                 error "set default mirrored layout on directory $td failed"
702
703         # verify flags are inherited from the directory
704         touch $tf
705
706         verify_comp_attr lcme_flags $tf 0x10001 prefer
707         verify_comp_attr lcme_flags $tf 0x10002 prefer
708
709         # set flags to the first component
710         $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
711
712         verify_comp_attr lcme_flags $tf 0x10001 stale
713         verify_comp_attr lcme_flags $tf 0x10002 prefer
714
715         $LFS setstripe --comp-set -I0x10001 --comp-flags=^stale $tf &&
716                 error "clearing 'stale' should fail"
717
718         # write and resync file. It can't resync the file directly because the
719         # file state is still 'ro'
720         cp /etc/hosts $tf || error "error writing file '$tf'"
721         $LFS mirror resync $tf || error "error resync-ing file '$tf'"
722
723         $LFS setstripe --comp-set -I 0x20003 --comp-flags=prefer $tf ||
724                 error "error setting flag prefer"
725
726         verify_comp_attr lcme_flags $tf 0x20003 prefer
727
728         $LFS setstripe --comp-set -I 0x20003 --comp-flags=^prefer $tf ||
729                 error "error clearing prefer flag from component 0x20003"
730
731         # MDS disallows setting stale flag on the last non-stale mirror
732         [[ $MDS1_VERSION -ge $(version_code 2.12.57) ]] ||
733         [[ $MDS1_VERSION -ge $(version_code 2.12.2) &&
734            $MDS1_VERSION -lt $(version_code 2.12.50) ]] || return 0
735
736         cp /etc/hosts $tf || error "error writing file '$tf'"
737
738         verify_comp_attr lcme_flags $tf 0x10002 prefer
739         verify_comp_attr lcme_flags $tf 0x20003 stale
740         verify_comp_attr lcme_flags $tf 0x30004 stale
741
742         ! $LFS setstripe --comp-set -I 0x10002 --comp-flags=^prefer,stale $tf \
743                 > /dev/null 2>&1 ||
744                 error "setting stale flag on component 0x10002 should fail"
745
746         $LFS mirror resync $tf || error "error resync-ing file '$tf'"
747
748         $LFS setstripe --comp-set -I 0x10001 --comp-flags=stale $tf ||
749                 error "error setting stale flag on component 0x10001"
750         $LFS setstripe --comp-set -I 0x20003 --comp-flags=stale $tf ||
751                 error "error setting stale flag on component 0x20003"
752
753         ! $LFS setstripe --comp-set -I 0x30004 --comp-flags=stale $tf \
754                 > /dev/null 2>&1 ||
755                 error "setting stale flag on component 0x30004 should fail"
756
757         $LFS mirror resync $tf || error "error resync-ing file '$tf'"
758 }
759 run_test 0h "set, clear and test flags for FLR files"
760
761 test_1() {
762         local tf=$DIR/$tfile
763         local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
764         local mirror_create_cmd="$LFS mirror create"
765         local stripes[0]=$OSTCOUNT
766
767         mirror_create_cmd+=" -N -c ${stripes[0]}"
768         for ((i = 1; i < $mirror_count; i++)); do
769                 # add mirrors with different stripes to the file
770                 stripes[$i]=$((RANDOM % OSTCOUNT))
771                 [ ${stripes[$i]} -eq 0 ] && stripes[$i]=1
772
773                 mirror_create_cmd+=" -N -c ${stripes[$i]}"
774         done
775
776         $mirror_create_cmd $tf || error "create mirrored file $tf failed"
777         verify_mirror_count $tf $mirror_count
778
779         # can't create mirrors exceeding LUSTRE_MIRROR_COUNT_MAX
780         $LFS mirror extend -N $tf &&
781                 error "Creating the $((mirror_count+1))th mirror succeeded"
782
783         local ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' |
784                         tr '\n' ' '))
785
786         # verify the range of components and stripe counts
787         for ((i = 0; i < $mirror_count; i++)); do
788                 verify_comp_attr stripe-count $tf ${ids[$i]} ${stripes[$i]}
789                 verify_comp_extent $tf ${ids[$i]} 0 EOF
790         done
791 }
792 run_test 1 "create components with setstripe options"
793
794 test_2() {
795         local tf=$DIR/$tfile
796         local tf2=$DIR/$tfile-2
797
798         $LFS setstripe -E 1M -S 1M -E EOF -c 1 $tf
799         $LFS setstripe -E 2M -S 1M -E EOF -c -1 $tf2
800
801         $LFS mirror extend -N -f $tf2 $tf ||
802                 error "merging $tf2 into $tf failed"
803
804         verify_mirror_count $tf 2
805         [[ ! -e $tf2 ]] || error "$tf2 was not unlinked"
806 }
807 run_test 2 "create components from existing files"
808
809 test_3() {
810         [[ $MDSCOUNT -lt 2 ]] && skip "need >= 2 MDTs" && return
811
812         for ((i = 0; i < 2; i++)); do
813                 $LFS mkdir -i $i $DIR/$tdir-$i
814                 $LFS setstripe -E -1 $DIR/$tdir-$i/$tfile
815         done
816
817         $LFS mirror extend -N -f $DIR/$tdir-1/$tfile \
818                 $DIR/$tdir-0/$tfile || error "creating mirrors"
819
820         # mdt doesn't support to cancel layout lock for remote objects, do
821         # it here manually.
822         cancel_lru_locks mdc
823
824         # make sure the mirrorted file was created successfully
825         [[ $($LFS getstripe --component-count $DIR/$tdir-0/$tfile) -eq 2 ]] ||
826                 { $LFS getstripe $DIR/$tdir-0/$tfile;
827                         error "expected 2 components"; }
828
829         # cleanup
830         rm -rf $DIR/$tdir-*
831 }
832 run_test 3 "create components from files located on different MDTs"
833
834 test_4() {
835         local tf=$DIR/$tdir/$tfile
836         local ids=()
837
838         test_mkdir $DIR/$tdir
839
840         # set mirror with setstripe options to directory
841         $LFS mirror create -N2 -E 1M -S 1M -E eof $DIR/$tdir ||
842                 error "set mirror to directory error"
843
844         [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \
845                 x"mirrored" ] || error "failed to create mirrored dir"
846
847         touch $tf
848         verify_mirror_count $tf 2
849
850         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
851         verify_comp_extent $tf ${ids[0]} 0 1048576
852         verify_comp_extent $tf ${ids[1]} 1048576 EOF
853
854         # sub directory should inherit mirror setting from parent
855         test_mkdir $DIR/$tdir/td
856         [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \
857                 x"mirrored" ] || error "failed to inherit mirror from parent"
858
859         # mirror extend won't be applied to directory
860         $LFS mirror extend -N2 $DIR/$tdir &&
861                 error "expecting mirror extend failure"
862         true
863 }
864 run_test 4 "Make sure mirror attributes can be inhertied from directory"
865
866 test_5() {
867         local tf=$DIR/$tfile
868         local ids=()
869
870         $MULTIOP $tf oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T12345c ||
871                 error "failed to create file with non-empty layout"
872         $CHECKSTAT -t file -s 12345 $tf || error "size error: expecting 12345"
873
874         $LFS mirror create -N3 $tf || error "failed to attach mirror layout"
875         verify_mirror_count $tf 3
876
877         $CHECKSTAT -t file -s 12345 $tf ||
878                 error "size error after attaching layout "
879 }
880 run_test 5 "Make sure init size work for mirrored layout"
881
882 # LU=10112: disable dom+flr for phase 1
883 test_6() {
884         local tf=$DIR/$tfile
885
886         $LFS mirror create -N -E 1M -S 1M -L mdt -E eof -N -E eof $tf &&
887                 error "expect failure to create mirrored file with DoM"
888
889         $LFS mirror create -N -E 1M -S 1M -E eof -N -E 1M -L mdt -E eof $tf &&
890                 error "expect failure to create mirrored file with DoM"
891
892         $LFS setstripe -E 1M -S 1M -L mdt -E eof $tf
893         $LFS mirror extend -N2 $tf &&
894                 error "expect failure to extend mirror with DoM"
895
896         $LFS mirror create -N2 -E 1M -S 1M -E eof $tf-2
897         $LFS mirror extend -N -f $tf $tf-2 &&
898                 error "expect failure to extend mirrored file with DoM extent"
899
900         true
901 }
902 run_test 6 "DoM and FLR won't co-exist for phase 1"
903
904 test_21() {
905         local tf=$DIR/$tfile
906         local tf2=$DIR/$tfile-2
907
908         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
909
910         $LFS setstripe -E EOF -o 0 $tf
911         $LFS setstripe -E EOF -o 1 $tf2
912
913         local dd_count=$((RANDOM % 20 + 1))
914         dd if=/dev/zero of=$tf bs=1M count=$dd_count oflag=sync
915         dd if=/dev/zero of=$tf2 bs=1M count=1 seek=$((dd_count - 1)) oflag=sync
916
917         # for zfs - sync OST dataset so that du below will return
918         # accurate results
919         [ "$FSTYPE" = "zfs" ] &&
920                 do_nodes $(comma_list $(osts_nodes)) "$ZPOOL sync"
921
922         local blocks=$(du -kc $tf $tf2 | awk '/total/{print $1}')
923
924         # add component
925         $LFS mirror extend -N -f $tf2 $tf ||
926                 error "merging $tf2 into $tf failed"
927
928         # cancel layout lock
929         cancel_lru_locks mdc
930
931         local new_blocks=$(du -k $tf | awk '{print $1}')
932         [ $new_blocks -eq $blocks ] ||
933         error "i_blocks error expected: $blocks, actual: $new_blocks"
934 }
935 run_test 21 "glimpse should report accurate i_blocks"
936
937 get_osc_lock_count() {
938         local lock_count=0
939
940         for idx in "$@"; do
941                 local osc_name
942                 local count
943
944                 osc_name=${FSNAME}-OST$(printf "%04x" $((idx-1)))-osc-'[-0-9a-f]*'
945                 count=$($LCTL get_param -n ldlm.namespaces.$osc_name.lock_count)
946                 lock_count=$((lock_count + count))
947         done
948         echo $lock_count
949 }
950
951 test_22() {
952         local tf=$DIR/$tfile
953
954         $LFS setstripe -E EOF -o 0 $tf
955         dd if=/dev/zero of=$tf bs=1M count=$((RANDOM % 20 + 1))
956
957         # add component, two mirrors located on the same OST ;-)
958         $LFS mirror extend -N -o 0 $tf ||
959                 error "extending mirrored file $tf failed"
960
961         size_blocks=$(stat --format="%b %s" $tf)
962
963         cancel_lru_locks mdc
964         cancel_lru_locks osc
965
966         local new_size_blocks=$(stat --format="%b %s" $tf)
967
968         # make sure there is no lock cached
969         [ $(get_osc_lock_count 1) -eq 0 ] || error "glimpse requests were sent"
970
971         [ "$new_size_blocks" = "$size_blocks" ] ||
972                 echo "size expected: $size_blocks, actual: $new_size_blocks"
973
974         rm -f $tmpfile
975 }
976 run_test 22 "no glimpse to OSTs for READ_ONLY files"
977
978 test_31() {
979         local tf=$DIR/$tfile
980
981         $LFS mirror create -N -o 0 -N -o 1 $tf ||
982                 error "creating mirrored file $tf failed"
983
984         #define OBD_FAIL_GLIMPSE_IMMUTABLE 0x1A00
985         $LCTL set_param fail_loc=0x1A00
986
987         local ost_idx
988         for ((ost_idx = 1; ost_idx <= 2; ost_idx++)); do
989                 cancel_lru_locks osc
990                 stop_osts $ost_idx
991
992                 local tmpfile=$(mktemp)
993                 stat --format="%b %s" $tf > $tmpfile  &
994                 local pid=$!
995
996                 local cnt=0
997                 while [ $cnt -le 5 ]; do
998                         kill -0 $pid > /dev/null 2>&1 || break
999                         sleep 1
1000                         ((cnt += 1))
1001                 done
1002                 kill -0 $pid > /dev/null 2>&1 &&
1003                         error "stat process stuck due to unavailable OSTs"
1004
1005                 # make sure glimpse request has been sent
1006                 [ $(get_osc_lock_count 1 2) -ne 0 ] ||
1007                         error "OST $ost_idx: no glimpse request was sent"
1008
1009                 start_osts $ost_idx
1010         done
1011 }
1012 run_test 31 "make sure glimpse request can be retried"
1013
1014 test_32() {
1015         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1016         rm -f $DIR/$tfile $DIR/$tfile-2
1017
1018         $LFS setstripe -E EOF -o 0 $DIR/$tfile
1019         dd if=/dev/urandom of=$DIR/$tfile bs=1M count=$((RANDOM % 10 + 2))
1020
1021         local fsize=$(stat -c %s $DIR/$tfile)
1022         [[ $fsize -ne 0 ]] || error "file size is (wrongly) zero"
1023
1024         local cksum=$(md5sum $DIR/$tfile)
1025
1026         # create a new mirror in sync mode
1027         $LFS mirror extend -N -o 1 $DIR/$tfile ||
1028                 error "extending mirrored file $DIR/$tfile failed"
1029
1030         # make sure the mirrored file was created successfully
1031         [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1032                 { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; }
1033
1034         drop_client_cache
1035         stop_osts 1
1036
1037         # check size is correct, glimpse request should go to the 2nd mirror
1038         $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1039                 error "file size error $fsize vs. $(stat -c %s $DIR/$tfile)"
1040
1041         echo "reading file from the 2nd mirror and verify checksum"
1042         [[ "$cksum" == "$(md5sum $DIR/$tfile)" ]] ||
1043                 error "checksum error: expected $cksum"
1044
1045         start_osts 1
1046 }
1047 run_test 32 "data should be mirrored to newly created mirror"
1048
1049 test_33() {
1050         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
1051
1052         rm -f $DIR/$tfile $DIR/$tfile-2
1053
1054         # create a file with two mirrors
1055         $LFS setstripe -E EOF -o 0 $DIR/$tfile
1056         local max_count=100
1057         local count=0
1058         while [ $count -lt $max_count ]; do
1059                 echo "ost1" >> $DIR/$tfile
1060                 count=$((count + 1));
1061         done
1062
1063         # tmp file that will be used as mirror
1064         $LFS setstripe -E EOF -o 1 $DIR/$tfile-2
1065         count=0
1066         while [ $count -lt $max_count ]; do
1067                 echo "ost2" >> $DIR/$tfile-2
1068                 count=$((count + 1));
1069         done
1070
1071         # create a mirrored file
1072         $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile &&
1073                 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1074                       "with verification should fail"
1075         $LFS mirror extend --no-verify -N -f $DIR/$tfile-2 $DIR/$tfile ||
1076                 error "merging $DIR/$tfile-2 into $DIR/$tfile" \
1077                       "without verification failed"
1078
1079         # make sure that $tfile has two mirrors and $tfile-2 does not exist
1080         [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
1081                 { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
1082
1083         [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked"
1084
1085         # execpted file size
1086         local fsize=$((5 * max_count))
1087         $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1088                 error "mirrored file size is not $fsize"
1089
1090         # read file - all OSTs are available
1091         echo "reading file (data can be provided by any ost)... "
1092         local rs=$(cat $DIR/$tfile | head -1)
1093         [[ "$rs" == "ost1" || "$rs" == "ost2" ]] ||
1094                 error "file content error: expected: \"ost1\" or \"ost2\""
1095
1096         # read file again with ost1 failed
1097         stop_osts 1
1098         drop_client_cache
1099
1100         echo "reading file (data should be provided by ost2)..."
1101         local rs=$(cat $DIR/$tfile | head -1)
1102         [[ "$rs" == "ost2" ]] ||
1103                 error "file content error: expected: \"ost2\", actual: \"$rs\""
1104
1105         # remount ost1
1106         start_osts 1
1107
1108         # read file again with ost2 failed
1109         stop_osts 2
1110         drop_client_cache
1111
1112         # check size, glimpse should work
1113         $CHECKSTAT -t file -s $fsize $DIR/$tfile ||
1114                 error "mirrored file size is not $fsize"
1115
1116         echo "reading file (data should be provided by ost1)..."
1117         local rs=$(cat $DIR/$tfile | head -1)
1118         [[ "$rs" == "ost1" ]] ||
1119                 error "file content error: expected: \"ost1\", actual: \"$rs\""
1120
1121         start_osts 2
1122 }
1123 run_test 33 "read can choose available mirror to read"
1124
1125 test_34a() {
1126         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1127
1128         rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1129
1130         # reference file
1131         $LFS setstripe -o 0 $DIR/$tfile-ref
1132         dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1133
1134         # create a file with two mirrors
1135         $LFS setstripe -E -1 -o 0,1 -S 1M $DIR/$tfile
1136         dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1137
1138         $LFS setstripe -E -1 -o 2,3 -S 1M $DIR/$tfile-2
1139         dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1140
1141         $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1142                 error "mirrored file size is not 3M"
1143
1144         # merge a mirrored file
1145         $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1146                 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1147
1148         cancel_lru_locks osc
1149
1150         # stop two OSTs, so the 2nd stripe of the 1st mirror and
1151         # the 1st stripe of the 2nd mirror will be inaccessible, ...
1152         stop_osts 2 3
1153
1154         echo "comparing files ... "
1155
1156         # however, read can still return the correct data. It should return
1157         # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1158         cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1159                 $DIR/$tfile-ref || error "file reading error"
1160
1161         start_osts 2 3
1162 }
1163 run_test 34a "read mirrored file with multiple stripes"
1164
1165 test_34b() {
1166         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1167
1168         rm -f $DIR/$tfile $DIR/$tfile-2 $DIR/$tfile-ref
1169
1170         # reference file
1171         $LFS setstripe -o 0 $DIR/$tfile-ref
1172         dd if=/dev/urandom of=$DIR/$tfile-ref bs=1M count=3
1173
1174         $LFS setstripe -E 1M -S 1M -o 0 -E eof -o 1 $DIR/$tfile
1175         dd if=$DIR/$tfile-ref of=$DIR/$tfile bs=1M
1176
1177         $LFS setstripe -E 1M -S 1M -o 2 -E eof -o 3 $DIR/$tfile-2
1178         dd if=$DIR/$tfile-ref of=$DIR/$tfile-2 bs=1M
1179
1180         $CHECKSTAT -t file -s $((3 * 1024 * 1024)) $DIR/$tfile ||
1181                 error "mirrored file size is not 3M"
1182
1183         # merge a mirrored file
1184         $LFS mirror extend -N -f $DIR/$tfile-2 $DIR/$tfile ||
1185                 error "merging $DIR/$tfile-2 into $DIR/$tfile failed"
1186
1187         cancel_lru_locks osc
1188
1189         # stop two OSTs, so the 2nd component of the 1st mirror and
1190         # the 1st component of the 2nd mirror will be inaccessible, ...
1191         stop_osts 2 3
1192
1193         echo "comparing files ... "
1194
1195         # however, read can still return the correct data. It should return
1196         # the 1st stripe from mirror 1 and 2st stripe from mirror 2.
1197         cmp -n 2097152 <(rwv -f $DIR/$tfile -r -o -n 1 2097152) \
1198                 $DIR/$tfile-ref || error "file reading error"
1199
1200         start_osts 2 3
1201 }
1202 run_test 34b "read mirrored file with multiple components"
1203
1204 test_35() {
1205         local tf=$DIR/$tfile
1206
1207         $LFS setstripe -E eof $tf
1208
1209         # add an out-of-sync mirror to the file
1210         $LFS mirror extend -N -c 2 $tf ||
1211                 error "extending mirrored file $tf failed"
1212
1213         $MULTIOP $tf oO_WRONLY:c ||
1214                 error "write open a mirrored file failed"
1215
1216         # truncate file should return error
1217         $TRUNCATE $tf 100 || error "error truncating a mirrored file"
1218 }
1219 run_test 35 "allow to write to mirrored files"
1220
1221 verify_ost_layout_version() {
1222         local tf=$1
1223
1224         # get file layout version
1225         local flv=$($LFS getstripe $tf | awk '/lcm_layout_gen/{print $2}')
1226
1227         # layout version from OST objects
1228         local olv=$($MULTIOP $tf oXc | awk '/ostlayoutversion/{print $2}')
1229
1230         [ $flv -eq $olv ] || error "layout version mismatch: $flv vs. $olv"
1231 }
1232
1233 create_file_36() {
1234         local tf
1235
1236         for tf in "$@"; do
1237                 $LFS setstripe -E 1M -S 1M -E 2M -E 4M -E eof -c -1 $tf
1238                 $LFS setstripe -E 3M -S 1M -E 6M -E eof -c -1 $tf-tmp
1239
1240                 $LFS mirror extend -N -f $tf-tmp $tf ||
1241                         error "merging $tf-tmp into $tf failed"
1242         done
1243 }
1244
1245 test_36() {
1246         local tf=$DIR/$tfile
1247
1248         create_file_36 $tf $tf-2 $tf-3
1249
1250         [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count"
1251
1252         # test case 1 - check file write and verify layout version
1253         $MULTIOP $tf oO_WRONLY:c ||
1254                 error "write open a mirrored file failed"
1255
1256         # write open file should not return error
1257         $MULTIOP $tf oO_WRONLY:w1024Yc || error "write mirrored file error"
1258
1259         # instantiate components should work
1260         dd if=/dev/zero of=$tf bs=1M count=12 || error "write file error"
1261
1262         # verify OST layout version
1263         verify_ost_layout_version $tf
1264
1265         # test case 2
1266         local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1))
1267
1268         local delay_sec=10
1269         do_facet $mds_facet $LCTL set_param fail_val=$delay_sec
1270
1271         #define OBD_FAIL_FLR_LV_DELAY 0x1A01
1272         do_facet $mds_facet $LCTL set_param fail_loc=0x1A01
1273
1274         # write should take at least $fail_loc seconds and succeed
1275         local st=$(date +%s)
1276         $MULTIOP $tf-2 oO_WRONLY:w1024Yc || error "write mirrored file error"
1277
1278         [ $(date +%s) -ge $((st+delay_sec)) ] ||
1279                 error "write finished before layout version is transmitted"
1280
1281         # verify OST layout version
1282         verify_ost_layout_version $tf
1283
1284         do_facet $mds_facet $LCTL set_param fail_loc=0
1285
1286         # test case 3
1287         mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1))
1288
1289         #define OBD_FAIL_FLR_LV_INC 0x1A02
1290         do_facet $mds_facet $LCTL set_param fail_loc=0x1A02
1291
1292         # write open file should return error
1293         $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c &&
1294                 error "write a mirrored file succeeded" || true
1295
1296         do_facet $mds_facet $LCTL set_param fail_loc=0
1297 }
1298 run_test 36 "write to mirrored files"
1299
1300 create_files_37() {
1301         local tf
1302         local fsize=$1
1303
1304         echo "create test files with size $fsize .."
1305
1306         shift
1307         for tf in "$@"; do
1308                 $LFS setstripe -E 1M -S 1M -c 1 -E eof -c -1 $tf
1309
1310                 dd if=/dev/urandom of=$tf bs=1M count=16 &> /dev/null
1311                 $TRUNCATE $tf $fsize
1312         done
1313 }
1314
1315 test_37()
1316 {
1317         [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
1318                 skip "Need MDS version at least 2.11.57"
1319
1320         local tf=$DIR/$tfile
1321         local tf2=$DIR/$tfile-2
1322         local tf3=$DIR/$tfile-3
1323         local tf4=$DIR/$tfile-4
1324
1325         create_files_37 $((RANDOM + 15 * 1048576)) $tf $tf2 $tf3
1326         rm -f $tf4
1327         cp $tf $tf4
1328
1329         # assume the mirror id will be 1, 2, and 3
1330         declare -A checksums
1331         checksums[1]=$(cat $tf | md5sum)
1332         checksums[2]=$(cat $tf2 | md5sum)
1333         checksums[3]=$(cat $tf3 | md5sum)
1334
1335         printf '%s\n' "${checksums[@]}"
1336
1337         # merge these files into a mirrored file
1338         $LFS mirror extend --no-verify -N -f $tf2 $tf ||
1339                 error "merging $tf2 into $tf failed"
1340         $LFS mirror extend --no-verify -N -f $tf3 $tf ||
1341                 error "merging $tf3 into $tf failed"
1342
1343         get_mirror_ids $tf
1344
1345         # verify mirror read, checksums should equal to the original files'
1346         echo "Verifying mirror read .."
1347
1348         local sum
1349         for i in ${mirror_array[@]}; do
1350                 $LCTL set_param ldlm.namespaces.*.lru_size=clear > /dev/null
1351                 sum=$($LFS mirror read -N $i $tf | md5sum)
1352                 [ "$sum" = "${checksums[$i]}" ] ||
1353                         error "$i: mismatch: \'${checksums[$i]}\' vs. \'$sum\'"
1354         done
1355
1356         # verify mirror write
1357         echo "Verifying mirror write .."
1358         $LFS mirror write -N2 $tf < $tf4
1359
1360         sum=$($LFS mirror read -N2 $tf | md5sum)
1361         [[ "$sum" = "${checksums[1]}" ]] ||
1362                 error "2: mismatch \'${checksums[1]}\' vs. \'$sum\'"
1363
1364         # verify mirror copy, write to this mirrored file will invalidate
1365         # the other two mirrors
1366         echo "Verifying mirror copy .."
1367
1368         local osts=$(comma_list $(osts_nodes))
1369
1370         if [[ $MDS1_VERSION -lt $(version_code 2.12.3) ]]; then
1371                 # define OBD_FAIL_OST_SKIP_LV_CHECK     0x241
1372                 do_nodes $osts lctl set_param fail_loc=0x241
1373
1374                 mirror_io copy -i ${mirror_array[0]} \
1375                         -t $(echo ${mirror_array[@]:1} | tr ' ' ',') $tf ||
1376                                 error "mirror copy error"
1377
1378                 do_nodes $osts lctl set_param fail_loc=0
1379         elif [[ $MDS1_VERSION -lt $(version_code 2.12.50) ||
1380                 $MDS1_VERSION -gt $(version_code 2.12.52) ]]; then
1381                 $LFS mirror copy -i ${mirror_array[0]} -o-1 $tf ||
1382                         error "mirror copy error"
1383         fi
1384
1385         # verify copying is successful by checking checksums
1386         remount_client $MOUNT
1387         for i in ${mirror_array[@]}; do
1388                 sum=$($LFS mirror read -N $i $tf | md5sum)
1389                 [ "$sum" = "${checksums[1]}" ] ||
1390                         error "$i: mismatch checksum after copy \'$sum\'"
1391         done
1392
1393         rm -f $tf
1394 }
1395 run_test 37 "mirror I/O API verification"
1396
1397 verify_flr_state()
1398 {
1399         local tf=$1
1400         local expected_state=$2
1401
1402         local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
1403         [ $expected_state = $state ] ||
1404                 error "expected: $expected_state, actual $state"
1405 }
1406
1407 test_38() {
1408         local tf=$DIR/$tfile
1409         local ref=$DIR/${tfile}-ref
1410
1411         $LFS setstripe -E 1M -S 1M -c 1 -E 4M -c 2 -E eof -c -1 $tf ||
1412                 error "creating $tf failed"
1413         $LFS setstripe -E 2M -S 1M -c 1 -E 6M -c 2 -E 8M -c -1 -E eof -c -1 \
1414                 $tf-2 || error "creating $tf-2 failed"
1415         $LFS setstripe -E 4M -c 1 -E 8M -c 2 -E eof -c -1 $tf-3 ||
1416                 error "creating $tf-3 failed"
1417
1418         # instantiate all components
1419         $LFS mirror extend -N -f $tf-2 $tf ||
1420                 error "merging $tf-2 into $tf failed"
1421         $LFS mirror extend -N -f $tf-3 $tf ||
1422                 error "merging $tf-3 into $tf failed"
1423         $LFS mirror extend -N -c 1 $tf ||
1424                 error "extending mirrored file $tf failed"
1425
1426         verify_flr_state $tf "ro"
1427
1428         dd if=/dev/urandom of=$ref  bs=1M count=16 &> /dev/null
1429
1430         local fsize=$((RANDOM << 8 + 1048576))
1431         $TRUNCATE $ref $fsize
1432
1433         local ref_cksum=$(cat $ref | md5sum)
1434
1435         # case 1: verify write to mirrored file & resync work
1436         cp $ref $tf || error "copy from $ref to $f error"
1437         verify_flr_state $tf "wp"
1438
1439         local file_cksum=$(cat $tf | md5sum)
1440         [ "$file_cksum" = "$ref_cksum" ] || error "write failed, cksum mismatch"
1441
1442         get_mirror_ids $tf
1443         echo "mirror IDs: ${mirror_array[@]}"
1444
1445         local valid_mirror stale_mirror id mirror_cksum
1446         for id in "${mirror_array[@]}"; do
1447                 mirror_cksum=$($LFS mirror read -N $id $tf | md5sum)
1448                 [ "$ref_cksum" == "$mirror_cksum" ] &&
1449                         { valid_mirror=$id; continue; }
1450
1451                 stale_mirror=$id
1452         done
1453
1454         [ -z "$stale_mirror" ] && error "stale mirror doesn't exist"
1455         [ -z "$valid_mirror" ] && error "valid mirror doesn't exist"
1456
1457         mirror_io resync $tf || error "resync failed"
1458         verify_flr_state $tf "ro"
1459
1460         mirror_cksum=$($LFS mirror read -N $stale_mirror $tf | md5sum)
1461         [ "$file_cksum" = "$ref_cksum" ] || error "resync failed"
1462
1463         # case 2: inject an error to make mirror_io exit after changing
1464         # the file state to sync_pending so that we can start a concurrent
1465         # write.
1466         $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1467         verify_flr_state $tf "wp"
1468
1469         mirror_io resync -e resync_start $tf && error "resync succeeded"
1470         verify_flr_state $tf "sp"
1471
1472         # from sync_pending to write_pending
1473         $MULTIOP $tf oO_WRONLY:w$((RANDOM % 1048576 + 1024))c
1474         verify_flr_state $tf "wp"
1475
1476         mirror_io resync -e resync_start $tf && error "resync succeeded"
1477         verify_flr_state $tf "sp"
1478
1479         # from sync_pending to read_only
1480         mirror_io resync $tf || error "resync failed"
1481         verify_flr_state $tf "ro"
1482 }
1483 run_test 38 "resync"
1484
1485 test_39() {
1486         local tf=$DIR/$tfile
1487
1488         rm -f $tf
1489         $LFS mirror create -N2 -E1m -c1 -S1M -E-1 $tf ||
1490         error "create PFL file $tf failed"
1491
1492         verify_mirror_count $tf 2
1493         verify_comp_count $tf 4
1494
1495         rm -f $tf || error "delete $tf failed"
1496 }
1497 run_test 39 "check FLR+PFL (a.k.a. PFLR) creation"
1498
1499 test_40() {
1500         local tf=$DIR/$tfile
1501         local ops
1502
1503         for ops in "conv=notrunc" ""; do
1504                 rm -f $tf
1505
1506                 $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 --flags=prefer \
1507                                    -N -E 1M -E 2M -E 4M -E -1 $tf ||
1508                         error "create PFLR file $tf failed"
1509                 dd if=/dev/zero of=$tf $ops bs=1M seek=2 count=1 ||
1510                         error "write PFLR file $tf failed"
1511
1512                 lfs getstripe -vy $tf
1513
1514                 local flags
1515
1516                 # file mirror state should be write_pending
1517                 flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1518                 [ $flags = wp ] ||
1519                 error "file mirror state $flags"
1520                 # the 1st component (in mirror 1) should be inited
1521                 verify_comp_attr lcme_flags $tf 0x10001 init
1522                 # the 2nd component (in mirror 1) should be inited
1523                 verify_comp_attr lcme_flags $tf 0x10002 init
1524                 # the 3rd component (in mirror 1) should be uninited
1525                 verify_comp_attr lcme_flags $tf 0x10003 prefer
1526                 # the 4th component (in mirror 2) should be inited
1527                 verify_comp_attr lcme_flags $tf 0x20004 init
1528                 # the 5th component (in mirror 2) should be uninited
1529                 verify_comp_attr lcme_flags $tf 0x20005 0
1530                 # the 6th component (in mirror 2) should be stale
1531                 verify_comp_attr lcme_flags $tf 0x20006 stale
1532                 # the 7th component (in mirror 2) should be uninited
1533                 if [[ x$ops = "xconv=notrunc" ]]; then
1534                         verify_comp_attr lcme_flags $tf 0x20007 0
1535                 elif [[ x$ops = "x" ]]; then
1536                         verify_comp_attr lcme_flags $tf 0x20007 stale
1537                 fi
1538         done
1539
1540         rm -f $tf || error "delete $tf failed"
1541 }
1542 run_test 40 "PFLR rdonly state instantiation check"
1543
1544 test_41() {
1545         local tf=$DIR/$tfile
1546
1547         rm -f $tf $tf-1
1548         echo " **create two FLR files $tf $tf-1"
1549         $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1550                            -N -E 1M -E 2M -E 3M -E -1 $tf ||
1551                 error "create PFLR file $tf failed"
1552         $LFS mirror create -N -E 2M -S 1M -E eof \
1553                            -N -E 1M -E eof --flags prefer \
1554                            -N -E 4m -E eof $tf-1 ||
1555                 error "create PFLR file $tf-1 failed"
1556
1557         # file should be in ro status
1558         echo " **verify files be RDONLY"
1559         verify_flr_state $tf "ro"
1560         verify_flr_state $tf-1 "ro"
1561
1562         # write data in [0, 2M)
1563         dd if=/dev/zero of=$tf bs=1M count=2 conv=notrunc ||
1564                 error "writing $tf failed"
1565         dd if=/dev/urandom of=$tf-1 bs=1M count=4 conv=notrunc ||
1566                 error "writing $tf-1 failed"
1567
1568         local sum0=$(cat $tf-1 | md5sum)
1569
1570         echo " **verify files be WRITE_PENDING"
1571         verify_flr_state $tf "wp"
1572         verify_flr_state $tf-1 "wp"
1573
1574         # file should have stale component
1575         echo " **verify files have stale component"
1576         $LFS getstripe $tf | grep lcme_flags | grep stale > /dev/null ||
1577                 error "after writing $tf, it does not contain stale component"
1578         $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1579                 error "after writing $tf-1, it does not contain stale component"
1580
1581         echo " **full resync"
1582         $LFS mirror resync $tf $tf-1 || error "mirror resync $tf $tf-1 failed"
1583
1584         echo " **verify $tf-1 data consistency in all mirrors"
1585         for i in 1 2 3; do
1586                 local sum=$($LFS mirror read -N$i $tf-1 | md5sum)
1587                 [[ "$sum" = "$sum0" ]] ||
1588                         error "$tf-1.$i: checksum mismatch: $sum != $sum0"
1589         done
1590
1591         echo " **verify files be RDONLY"
1592         verify_flr_state $tf "ro"
1593         verify_flr_state $tf-1 "ro"
1594
1595         # file should not have stale component
1596         echo " **verify files do not contain stale component"
1597         $LFS getstripe $tf | grep lcme_flags | grep stale &&
1598                 error "after resyncing $tf, it contains stale component"
1599         $LFS getstripe $tf-1 | grep lcme_flags | grep stale &&
1600                 error "after resyncing $tf, it contains stale component"
1601
1602         # verify partial resync
1603         echo " **write $tf-1 for partial resync test"
1604         dd if=/dev/zero of=$tf-1 bs=1M count=2 conv=notrunc ||
1605                 error "writing $tf-1 failed"
1606
1607         echo " **only resync mirror 2"
1608         verify_flr_state $tf-1 "wp"
1609         $LFS mirror resync --only 2 $tf-1 ||
1610                 error "resync mirror 2 of $tf-1 failed"
1611         verify_flr_state $tf "ro"
1612
1613         # resync synced mirror
1614         echo " **resync mirror 2 again"
1615         $LFS mirror resync --only 2 $tf-1 ||
1616                 error "resync mirror 2 of $tf-1 failed"
1617         verify_flr_state $tf "ro"
1618         echo " **verify $tf-1 contains stale component"
1619         $LFS getstripe $tf-1 | grep lcme_flags | grep stale > /dev/null ||
1620                 error "after writing $tf-1, it does not contain stale component"
1621
1622         echo " **full resync $tf-1"
1623         $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1624         verify_flr_state $tf "ro"
1625         echo " **full resync $tf-1 again"
1626         $LFS mirror resync $tf-1 || error "resync of $tf-1 failed"
1627         echo " **verify $tf-1 does not contain stale component"
1628         $LFS getstripe $tf | grep lcme_flags | grep stale &&
1629                 error "after resyncing $tf, it contains stale component"
1630
1631         return 0
1632 }
1633 run_test 41 "lfs mirror resync check"
1634
1635 test_42() {
1636         [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
1637
1638         local td=$DIR/$tdir
1639         local tf=$td/$tfile
1640         local mirror_cmd="$LFS mirror verify"
1641         local i
1642
1643         # create parent directory
1644         mkdir $td || error "mkdir $td failed"
1645
1646         $mirror_cmd &> /dev/null && error "no file name given"
1647         $mirror_cmd $tf &> /dev/null && error "cannot stat file $tf"
1648         $mirror_cmd $td &> /dev/null && error "$td is not a regular file"
1649
1650         # create mirrored files
1651         $LFS mirror create -N -E 4M -S 1M -E 10M -E EOF $tf ||
1652                 error "create mirrored file $tf failed"
1653         $LFS mirror create -N -E 2M -S 1M -E EOF \
1654                            -N -E 6M -E 8M -E EOF \
1655                            -N -E 16M -E EOF $tf-1 ||
1656                 error "create mirrored file $tf-1 failed"
1657         $LFS mirror create -N -c 2 -o 1,3 -N -S 2M -c -1 $tf-2 ||
1658                 error "create mirrored file $tf-2 failed"
1659
1660         # write data in [0, 10M)
1661         for i in $tf $tf-1 $tf-2; do
1662                 yes | dd of=$i bs=1M count=10 iflag=fullblock conv=notrunc ||
1663                         error "write $i failed"
1664         done
1665
1666         # resync the mirrored files
1667         $LFS mirror resync $tf-1 $tf-2 ||
1668                 error "resync $tf-1 $tf-2 failed"
1669
1670         # verify the mirrored files
1671         $mirror_cmd $tf-1 $tf-2 ||
1672                 error "verify $tf-1 $tf-2 failed"
1673
1674         get_mirror_ids $tf-1
1675         $mirror_cmd --only ${mirror_array[0]} $tf-1 &> /dev/null &&
1676                 error "at least 2 mirror ids needed with '--only' option"
1677         $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 $tf-2 \
1678                 &> /dev/null &&
1679                 error "'--only' option cannot be used upon multiple files"
1680         $mirror_cmd --only 65534,${mirror_array[0]},65535 $tf-1 &&
1681                 error "invalid specified mirror ids"
1682
1683         # change the content of $tf and merge it into $tf-1
1684         for i in 6 10; do
1685                 echo a | dd of=$tf bs=1M seek=$i conv=notrunc ||
1686                         error "change $tf with seek=$i failed"
1687                 echo b | dd of=$tf-1 bs=1M seek=$i conv=notrunc ||
1688                         error "change $tf-1 with seek=$i failed"
1689         done
1690
1691         $LFS mirror resync $tf-1 || error "resync $tf-1 failed"
1692         $LFS mirror extend --no-verify -N -f $tf $tf-1 ||
1693                 error "merge $tf into $tf-1 failed"
1694
1695         # verify the mirrored files
1696         echo "Verify $tf-1 without -v option:"
1697         $mirror_cmd $tf-1 &&
1698                 error "verify $tf-1 should fail" || echo "PASS"
1699
1700         echo "Verify $tf-1 with -v option:"
1701         $mirror_cmd -v $tf-1 &&
1702                 error "verify $tf-1 should fail"
1703
1704         get_mirror_ids $tf-1
1705         echo "Verify $tf-1 with --only option:"
1706         $mirror_cmd -v --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 &&
1707                 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1708                       "${mirror_array[-1]} should fail"
1709
1710         $mirror_cmd --only ${mirror_array[0]},${mirror_array[1]} $tf-1 ||
1711                 error "verify $tf-1 with mirror ${mirror_array[0]} and" \
1712                       "${mirror_array[1]} should succeed"
1713
1714         # set stale components in $tf-1
1715         for i in 0x40002 0x40003; do
1716                 $LFS setstripe --comp-set -I$i --comp-flags=stale $tf-1 ||
1717                         error "set stale flag on component $i failed"
1718         done
1719
1720         # verify the mirrored file
1721         echo "Verify $tf-1 with stale components:"
1722         $mirror_cmd -vvv $tf-1 ||
1723                 error "verify $tf-1 with stale components should succeed"
1724
1725         echo "Verify $tf-1 with stale components and --only option:"
1726         $mirror_cmd -vvv --only ${mirror_array[1]},${mirror_array[-1]} $tf-1 ||
1727                 error "verify $tf-1 with mirror ${mirror_array[1]} and" \
1728                       "${mirror_array[-1]} should succeed"
1729 }
1730 run_test 42 "lfs mirror verify"
1731
1732 # inactivate one OST && write && restore the OST
1733 write_file_43() {
1734         local file=$1
1735         local ost=$2
1736         local PARAM="osp.${FSNAME}-OST000${ost}-osc-M*.active"
1737         local wait
1738
1739         wait=$(do_facet $SINGLEMDS \
1740                 "$LCTL get_param -n lod.*MDT0000-*.qos_maxage")
1741         wait=${wait%%[^0-9]*}
1742
1743         echo "  **deactivate OST$ost, waiting for $((wait*2+2)) seconds"
1744         $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 0")
1745         # lod_qos_statfs_update needs 2*$wait seconds to refresh targets statfs
1746         sleep $(($wait * 2 + 2))
1747         echo "  **write $file"
1748         dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
1749         echo "  **restore activating OST$ost, waiting for $((wait*2+2)) seconds"
1750         $(do_facet $SINGLEMDS "$LCTL set_param -n $PARAM 1")
1751         sleep $((wait * 2 + 2))
1752
1753         local flags=$($LFS getstripe -v $file | awk '/lcm_flags:/ { print $2 }')
1754         [ $flags = wp ] || error "file mirror state $flags != wp"
1755 }
1756
1757 test_43() {
1758         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1759
1760         local tf=$DIR/$tfile
1761         local flags
1762
1763         rm -f $tf
1764         ##   mirror 0  ost (0, 1)
1765         ##   mirror 1  ost (1, 2)
1766         ##   mirror 2  ost (2, 0)
1767         $LFS mirror create -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 \
1768                 -N -Eeof -c2 -o2,0 $tf ||
1769                 error "create 3 mirrors file $tf failed"
1770
1771         ################## OST0 ###########################################
1772         write_file_43 $tf 0
1773         echo "  **verify components"
1774         verify_comp_attr lcme_flags $tf 0x10001 init,stale
1775         verify_comp_attr lcme_flags $tf 0x20002 init
1776         verify_comp_attr lcme_flags $tf 0x30003 init,stale
1777
1778         # resync
1779         echo "  **resync $tf"
1780         $LFS mirror resync $tf
1781         flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1782         [ $flags = ro ] || error "file mirror state $flags != ro"
1783
1784         ################## OST1 ###########################################
1785         write_file_43 $tf 1
1786         echo "  **verify components"
1787         verify_comp_attr lcme_flags $tf 0x10001 init,stale
1788         verify_comp_attr lcme_flags $tf 0x20002 init,stale
1789         verify_comp_attr lcme_flags $tf 0x30003 init
1790
1791         # resync
1792         echo "  **resync $tf"
1793         $LFS mirror resync $tf
1794         flags=$($LFS getstripe -v $tf | awk '/lcm_flags:/ { print $2 }')
1795         [ $flags = ro ] || error "file mirror state $flags != ro"
1796
1797         ################## OST2 ###########################################
1798         write_file_43 $tf 2
1799         echo "  **verify components"
1800         verify_comp_attr lcme_flags $tf 0x10001 init
1801         verify_comp_attr lcme_flags $tf 0x20002 init,stale
1802         verify_comp_attr lcme_flags $tf 0x30003 init,stale
1803 }
1804 run_test 43 "mirror pick on write"
1805
1806 test_44() {
1807         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1808         rm -rf $DIR/$tdir
1809         rm -rf $DIR/$tdir-1
1810         local tf=$DIR/$tdir/$tfile
1811         local tf1=$DIR/$tdir-1/$tfile-1
1812
1813         $LFS setdirstripe -i 0 -c 1 $DIR/$tdir ||
1814                 error "create directory failed"
1815         $LFS setdirstripe -i 1 -c 1 $DIR/$tdir-1 ||
1816                 error "create remote directory failed"
1817         rm -f $tf $tf1 $tf.mirror~2
1818         # create file with 4 mirrors
1819         $LFS mirror create -N -E 2M -S 1M -E 4M -E -1 \
1820                            -N -E 1M -E 2M -E 3M -E -1 -N2 $tf ||
1821                 error "create PFLR file $tf failed"
1822
1823         # file should be in ro status
1824         verify_flr_state $tf "ro"
1825
1826         # write data in [0, 3M)
1827         dd if=/dev/urandom of=$tf bs=1M count=3 conv=notrunc ||
1828                 error "writing $tf failed"
1829
1830         verify_flr_state $tf "wp"
1831
1832         # disallow destroying the last non-stale mirror
1833         ! $LFS mirror split --mirror-id 1 -d $tf > /dev/null 2>&1 ||
1834                 error "destroying mirror 1 should fail"
1835
1836         # synchronize all mirrors of the file
1837         $LFS mirror resync $tf || error "mirror resync $tf failed"
1838
1839         verify_flr_state $tf "ro"
1840
1841         # split mirror 1
1842         $LFS mirror split --mirror-id 1 -f $tf1 $tf ||
1843                 error "split to $tf1 failed"
1844
1845         local idx0=$($LFS getstripe -m $tf)
1846         local idx1=$($LFS getstripe -m $tf1)
1847
1848         [[ x$idx0 == x0 ]] || error "$tf is not on MDT0"
1849         [[ x$idx1 == x1 ]] || error "$tf1 is not on MDT1"
1850
1851         # verify mirror count
1852         verify_mirror_count $tf 3
1853         verify_mirror_count $tf1 1
1854
1855         $LFS mirror split --mirror-id 2 $tf ||
1856                 error "split mirror 2 failed"
1857
1858         verify_mirror_count $tf 2
1859         verify_mirror_count $tf.mirror~2 1
1860
1861         $LFS setstripe --comp-set -I 0x30008 --comp-flags=stale $tf ||
1862                 error "setting stale flag on component 0x30008 failed"
1863
1864         # disallow destroying the last non-stale mirror
1865         ! $LFS mirror split --mirror-id 4 -d $tf > /dev/null 2>&1 ||
1866                 error "destroying mirror 4 should fail"
1867
1868         $LFS mirror resync $tf || error "resynchronizing $tf failed"
1869
1870         $LFS mirror split --mirror-id 3 -d $tf ||
1871                 error "destroying mirror 3 failed"
1872         verify_mirror_count $tf 1
1873
1874         # verify splitted file contains the same content as the orig file does
1875         diff $tf $tf1 || error "splited file $tf1 diffs from $tf"
1876         diff $tf $tf.mirror~2 ||
1877                 error "splited file $tf.mirror~2 diffs from $tf"
1878 }
1879 run_test 44 "lfs mirror split check"
1880
1881 test_45() {
1882         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1883
1884         local file=$DIR/$tdir/$tfile
1885         local dir=$DIR/$tdir/$dir
1886         local temp=$DIR/$tdir/template
1887         rm -rf $DIR/$tdir
1888         test_mkdir $DIR/$tdir
1889
1890         $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1891                 -N -E3m -S1m -Eeof -N -E8m -Eeof $file ||
1892                         error "Create $file failed"
1893
1894         verify_yaml_layout $file $file.copy $temp "1. FLR file"
1895         rm -f $file $file.copy
1896
1897         $LFS setstripe -N -E1m -S1m -c2 -o0,1 -E2m -Eeof -N -E4m -Eeof \
1898                 -N -E3m -S1m -Eeof -N -E8m --flags=prefer -Eeof $file ||
1899                         error "Create $file failed"
1900
1901         verify_yaml_layout $file $file.copy $temp "2. FLR file with flags"
1902 }
1903 run_test 45 "Verify setstripe/getstripe with YAML with FLR file"
1904
1905 verify_46() {
1906         local src=$1
1907         local dst=$2
1908         local msg_prefix=$3
1909
1910         $LFS setstripe --copy=$src $dst || error "setstripe $dst failed"
1911
1912         local layout1=$(get_layout_param $src)
1913         local layout2=$(get_layout_param $dst)
1914         # compare their layout info
1915         [ "$layout1" == "$layout2" ] ||
1916                 error "$msg_prefix $src <=> $dst layouts are not equal"
1917 }
1918
1919 test_46() {
1920         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1921
1922         local file=$DIR/$tdir/$tfile
1923         test_mkdir $DIR/$tdir
1924
1925         ########################### 1. PFL file #############################
1926         echo "  ** 1. PFL file"
1927         rm -f $file
1928         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
1929                 $file || error "1. Create PFL $file failed"
1930
1931         rm -f $file.copy
1932         verify_46 $file $file.copy "1. PFL file"
1933
1934         ########################### 2. plain file ###########################
1935         echo "  ** 2. plain file"
1936         rm -f $file
1937         $LFS setstripe -c2 -o0,1 -i1 $file ||
1938                 error "2. Create plain $file failed"
1939
1940         rm -f $file.copy
1941         verify_46 $file $file.copy "2. plain file"
1942
1943         ########################### 3. FLR file #############################
1944         echo "  ** 3. FLR file"
1945         $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
1946                 $file || error "3. Create FLR $file failed"
1947
1948         rm -f $file.copy
1949         verify_46 $file $file.copy "3. FLR file"
1950
1951         local dir=$DIR/$tdir/dir
1952         ########################### 4. PFL dir ##############################
1953         echo "  ** 4. PFL dir"
1954         test_mkdir $dir
1955         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
1956                 error "4. setstripe PFL $dir failed"
1957
1958         test_mkdir $dir.copy
1959         verify_46 $dir $dir.copy "4. PFL dir"
1960
1961         ########################### 5. plain dir ############################
1962         echo "  ** 5. plain dir"
1963         $LFS setstripe -c2 -i-1 $dir || error "5. setstripe plain $dir failed"
1964
1965         verify_46 $dir $dir.copy "5. plain dir"
1966
1967         ########################### 6. FLR dir ##############################
1968         echo "  ** 6. FLR dir"
1969         $LFS setstripe -N -E1m -S 1M -c2 -E2m -c1 -Eeof -N -E4m -Eeof $dir ||
1970                 error "6. setstripe FLR $dir failed"
1971
1972         verify_46 $dir $dir.copy "6. FLR dir"
1973 }
1974 run_test 46 "Verify setstripe --copy option"
1975
1976 test_47() {
1977         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
1978
1979         local file=$DIR/$tdir/$tfile
1980         local ids
1981         local ost
1982         local osts
1983
1984         test_mkdir $DIR/$tdir
1985
1986         # test case 1:
1987         rm -f $file
1988         # mirror1: [comp0]ost0,    [comp1]ost1 and ost2
1989         # mirror2: [comp2]    ,    [comp3] should not use ost1 or ost2
1990         $LFS mirror create -N -E2m -c1 -o0 --flags=prefer -Eeof -c2 -o1,2 \
1991                 -N -E2m -c1 -Eeof -c1 $file || error "create FLR $file failed"
1992         ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
1993
1994         dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
1995         $LFS mirror resync $file || error "resync $file failed"
1996
1997         ost=$($LFS getstripe -I${ids[2]} $file | awk '/l_ost_idx/{print $5}')
1998         if [[ x$ost == "x0," ]]; then
1999                 $LFS getstripe $file
2000                 error "component ${ids[2]} objects allocated on $ost " \
2001                       "shouldn't on OST0"
2002         fi
2003
2004         ost=$($LFS getstripe -I${ids[3]} $file | awk '/l_ost_idx/{print $5}')
2005         if [[ x$ost == "x1," || x$ost == "x2," ]]; then
2006                 $LFS getstripe $file
2007                 error "component ${ids[3]} objects allocated on $ost " \
2008                       "shouldn't on OST1 or on OST2"
2009         fi
2010
2011         ## test case 2:
2012         rm -f $file
2013         # mirror1: [comp0]    [comp1]
2014         # mirror2: [comp2]    [comp3]
2015         # mirror3: [comp4]    [comp5]
2016         # mirror4: [comp6]    [comp7]
2017         $LFS mirror create -N4 -E1m -c1 -Eeof -c1 $file ||
2018                 error "create FLR $file failed"
2019         ids=($($LFS getstripe $file | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2020
2021         dd if=/dev/zero of=$file bs=1M count=3 || error "dd $file failed"
2022         $LFS mirror resync $file || error "resync $file failed"
2023
2024         for ((i = 0; i < 6; i++)); do
2025                 osts[$i]=$($LFS getstripe -I${ids[$i]} $file |
2026                         awk '/l_ost_idx/{print $5}')
2027         done
2028         # comp[0],comp[2],comp[4] should use different osts
2029         if [[ ${osts[0]} == ${osts[2]} || ${osts[0]} == ${osts[4]} ||
2030               ${osts[2]} == ${osts[4]} ]]; then
2031                 $LFS getstripe $file
2032                 error "component ${ids[0]}, ${ids[2]}, ${ids[4]} have objects "\
2033                       "allocated on duplicated OSTs"
2034         fi
2035         # comp[1],comp[3],comp[5] should use different osts
2036         if [[ ${osts[1]} == ${osts[3]} || ${osts[1]} == ${osts[5]} ||
2037               ${osts[3]} == ${osts[5]} ]]; then
2038                 $LFS getstripe $file
2039                 error "component ${ids[1]}, ${ids[3]}, ${ids[5]} have objects "\
2040                       "allocated on duplicated OSTs"
2041         fi
2042
2043         return 0
2044 }
2045 run_test 47 "Verify mirror obj alloc"
2046
2047 test_48() {
2048         [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2049                 skip "Need MDS version at least 2.11.55"
2050
2051         local tf=$DIR/$tfile
2052
2053         rm -f $tf
2054         echo " ** create 2 mirrors FLR file $tf"
2055         $LFS mirror create -N -E2M -Eeof --flags prefer \
2056                            -N -E1M -Eeof $tf ||
2057                 error "create FLR file $tf failed"
2058
2059         echo " ** write it"
2060         dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2061         verify_flr_state $tf "wp"
2062
2063         local sum0=$(md5sum < $tf)
2064
2065         echo " ** resync the file"
2066         $LFS mirror resync $tf
2067
2068         echo " ** snapshot mirror 2"
2069         $LFS setstripe --comp-set -I 0x20003 --comp-flags=nosync $tf
2070
2071         echo " ** write it again"
2072         dd if=/dev/urandom of=$tf bs=1M count=3 || error "write $tf failed"
2073         echo " ** resync it again"
2074         $LFS mirror resync $tf
2075
2076         verify_flr_state $tf "wp"
2077         verify_comp_attr lcme_flags $tf 0x20003 nosync,stale
2078
2079         local sum1=$($LFS mirror read -N1 $tf | md5sum)
2080         local sum2=$($LFS mirror read -N2 $tf | md5sum)
2081
2082         echo " ** verify mirror 2 doesn't change"
2083         echo "original checksum: $sum0"
2084         echo "mirror 1 checksum: $sum1"
2085         echo "mirror 2 checksum: $sum2"
2086         [[ $sum0 = $sum2 ]] ||
2087                 error "original checksum: $sum0, mirror 2 checksum: $sum2"
2088         echo " ** mirror 2 stripe info"
2089         $LFS getstripe -v --mirror-index=2 $tf
2090
2091         echo " ** resync mirror 2"
2092         $LFS mirror resync --only 2 $tf
2093
2094         verify_flr_state $tf "ro"
2095         verify_comp_attr lcme_flags $tf 0x20003 nosync,^stale
2096
2097         sum1=$($LFS mirror read -N1 $tf | md5sum)
2098         sum2=$($LFS mirror read -N2 $tf | md5sum)
2099
2100         echo " ** verify mirror 2 resync-ed"
2101         echo "original checksum: $sum0"
2102         echo "mirror 1 checksum: $sum1"
2103         echo "mirror 2 checksum: $sum2"
2104         [[ $sum1 = $sum2 ]] ||
2105                 error "mirror 1 checksum: $sum1, mirror 2 checksum: $sum2"
2106         echo " ** mirror 2 stripe info"
2107         $LFS getstripe -v --mirror-index=2 $tf
2108 }
2109 run_test 48 "Verify snapshot mirror"
2110
2111 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
2112 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
2113
2114 write_file_200() {
2115         local tf=$1
2116
2117         local fsize=$(stat --printf=%s $tf)
2118
2119         while [ -f $ctrl_file ]; do
2120                 local off=$((RANDOM << 8))
2121                 local len=$((RANDOM << 5 + 131072))
2122
2123                 [ $((off + len)) -gt $fsize ] && {
2124                         fsize=$((off + len))
2125                         echo "Extending file size to $fsize .."
2126                 }
2127
2128                 flock -s $lock_file -c \
2129                         "$MULTIOP $tf oO_WRONLY:z${off}w${len}c" ||
2130                                 { rm -f $ctrl_file;
2131                                   error "failed writing to $off:$len"; }
2132                 sleep 0.$((RANDOM % 2 + 1))
2133         done
2134 }
2135
2136 read_file_200() {
2137         local tf=$1
2138
2139         while [ -f $ctrl_file ]; do
2140                 flock -s $lock_file -c "cat $tf &> /dev/null" ||
2141                         { rm -f $ctrl_file; error "read failed"; }
2142                 sleep 0.$((RANDOM % 2 + 1))
2143         done
2144 }
2145
2146 resync_file_200() {
2147         local tf=$1
2148
2149         options=("" "-e resync_start" "-e delay_before_copy -d 1" "" "")
2150
2151         exec 200<>$lock_file
2152         while [ -f $ctrl_file ]; do
2153                 local lock_taken=false
2154                 local index=$((RANDOM % ${#options[@]}))
2155                 local cmd="mirror_io resync ${options[$index]}"
2156
2157                 [ "${options[$index]}" = "" ] && cmd="$LFS mirror resync"
2158
2159                 [ $((RANDOM % 4)) -eq 0 ] && {
2160                         index=0
2161                         lock_taken=true
2162                         echo -n "lock to "
2163                 }
2164
2165                 echo -n "resync file $tf with '$cmd' .."
2166
2167                 if [[ $lock_taken = "true" ]]; then
2168                         flock -x 200 -c "$cmd $tf &> /dev/null" &&
2169                                 echo "done" || echo "failed"
2170                         flock -u 200
2171                 else
2172                         $cmd $tf &> /dev/null && echo "done" || echo "failed"
2173                 fi
2174
2175                 sleep 0.$((RANDOM % 8 + 1))
2176         done
2177 }
2178
2179 test_200() {
2180         local tf=$DIR/$tfile
2181         local tf2=$DIR2/$tfile
2182         local tf3=$DIR3/$tfile
2183
2184         $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E 4M -E 16M -E eof $tf
2185         $LFS setstripe -E 2M -S 1M -E 6M -c 2 -E 8M -E 32M -E eof $tf-2
2186         $LFS setstripe -E 4M -c 2 -E 8M -E 64M -E eof $tf-3
2187
2188         $LFS mirror extend -N -f $tf-2 $tf ||
2189                 error "merging $tf-2 into $tf failed"
2190         $LFS mirror extend -N -f $tf-3 $tf ||
2191                 error "merging $tf-3 into $tf failed"
2192
2193         mkdir -p $MOUNT2 && mount_client $MOUNT2
2194
2195         mkdir -p $MOUNT3 && mount_client $MOUNT3
2196
2197         verify_flr_state $tf3 "ro"
2198
2199         #define OBD_FAIL_FLR_RANDOM_PICK_MIRROR 0x1A03
2200         $LCTL set_param fail_loc=0x1A03
2201
2202         local mds_idx=mds$(($($LFS getstripe -m $tf) + 1))
2203         do_facet $mds_idx $LCTL set_param fail_loc=0x1A03
2204
2205         declare -a pids
2206
2207         write_file_200 $tf &
2208         pids+=($!)
2209
2210         read_file_200 $tf &
2211         pids+=($!)
2212
2213         write_file_200 $tf2 &
2214         pids+=($!)
2215
2216         read_file_200 $tf2 &
2217         pids+=($!)
2218
2219         resync_file_200 $tf3 &
2220         pids+=($!)
2221
2222         local sleep_time=60
2223         [ "$SLOW" = "yes" ] && sleep_time=360
2224         while [ $sleep_time -gt 0 -a -f $ctrl_file ]; do
2225                 sleep 1
2226                 ((--sleep_time))
2227         done
2228
2229         rm -f $ctrl_file
2230
2231         echo "Waiting ${pids[@]}"
2232         wait ${pids[@]}
2233
2234         umount_client $MOUNT2
2235         umount_client $MOUNT3
2236
2237         rm -f $lock_file
2238
2239         # resync and verify mirrors
2240         mirror_io resync $tf
2241         get_mirror_ids $tf
2242
2243         local csum=$($LFS mirror read -N ${mirror_array[0]} $tf | md5sum)
2244         for id in ${mirror_array[@]:1}; do
2245                 [ "$($LFS mirror read -N $id $tf | md5sum)" = "$csum" ] ||
2246                         error "checksum error for mirror $id"
2247         done
2248
2249         true
2250 }
2251 run_test 200 "stress test"
2252
2253 cleanup_test_201() {
2254         trap 0
2255         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
2256
2257         umount_client $MOUNT2
2258 }
2259
2260 test_201() {
2261         local delay=${RESYNC_DELAY:-5}
2262
2263         MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
2264                awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
2265
2266         trap cleanup_test_201 EXIT
2267
2268         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
2269                         changelog_register -n)
2270
2271         mkdir -p $MOUNT2 && mount_client $MOUNT2
2272
2273         local index=0
2274         while :; do
2275                 local log=$($LFS changelog $MDT0 $index | grep FLRW)
2276                 [ -z "$log" ] && { sleep 1; continue; }
2277
2278                 index=$(echo $log | awk '{print $1}')
2279                 local ts=$(date -d "$(echo $log | awk '{print $3}')" "+%s" -u)
2280                 local fid=$(echo $log | awk '{print $6}' | sed -e 's/t=//')
2281                 local file=$($LFS fid2path $MOUNT2 $fid 2> /dev/null)
2282
2283                 ((++index))
2284                 [ -z "$file" ] && continue
2285
2286                 local now=$(date +%s)
2287
2288                 echo "file: $file $fid was modified at $ts, now: $now, " \
2289                      "will be resynced at $((ts+delay))"
2290
2291                 [ $now -lt $((ts + delay)) ] && sleep $((ts + delay - now))
2292
2293                 mirror_io resync $file
2294                 echo "$file resync done"
2295         done
2296
2297         cleanup_test_201
2298 }
2299 run_test 201 "FLR data mover"
2300
2301 test_202() {
2302         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
2303
2304         local tf=$DIR/$tfile
2305         local ids
2306
2307         $LFS setstripe -E 1M -S 1M -c 1 $tf
2308         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2309         verify_comp_attr stripe-count $tf ${ids[0]} 1
2310
2311         $LFS setstripe --component-add -E 2M -c -1 $tf
2312         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2313         verify_comp_attr stripe-count $tf ${ids[0]} 1
2314         verify_comp_attr stripe-count $tf ${ids[1]} -1
2315
2316         dd if=/dev/zero of=$tf bs=1M count=2
2317         ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
2318         verify_comp_attr stripe-count $tf ${ids[0]} 1
2319         verify_comp_attr stripe-count $tf ${ids[1]} $OSTCOUNT
2320 }
2321 run_test 202 "lfs setstripe --add-component wide striping"
2322
2323 test_203() {
2324         [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
2325                 skip "Need MDS version at least 2.11.55"
2326         [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
2327
2328         local tf=$DIR/$tfile
2329
2330         #create 2 mirrors
2331         $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
2332         #delete first mirror
2333         $LFS mirror split --mirror-id=1 -d $tf || error "delete first mirror"
2334
2335         $LFS getstripe $tf
2336         local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
2337         local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2338                 error "getstripe count of mirror 2"
2339         [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2340
2341         #extend a mirror with 2 OSTs
2342         $LFS mirror extend -N -c2 $tf || error "extend mirror"
2343         $LFS getstripe $tf
2344
2345         local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
2346         count=$($LFS getstripe --mirror-id=2 -c $tf) ||
2347                 error "getstripe count of mirror 2"
2348         [[ x$oldid = x$newid ]] ||
2349                 error "mirror 2 changed ID from $old_id to $new_id"
2350         [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
2351
2352         count=$($LFS getstripe --mirror-id=3 -c $tf) ||
2353                 error "getstripe count of mirror 3"
2354         [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
2355 }
2356 run_test 203 "mirror file preserve mirror ID"
2357
2358 complete $SECONDS
2359 check_and_cleanup_lustre
2360 exit_status