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