Whamcloud - gitweb
LU-17038 tests: remove mlink utility
[fs/lustre-release.git] / lustre / tests / sanity-pfl.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
7 ONLY=${ONLY:-"$*"}
8
9 LUSTRE=${LUSTRE:-$(dirname $0)/..}
10 . $LUSTRE/tests/test-framework.sh
11 init_test_env "$@"
12 init_logging
13
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_PFL_EXCEPT "
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 # Skip tests for PPC that fail frequently
19 if [[ $(uname -m) = ppc64 ]]; then
20         # bug number:    LU-13186 LU-13205 LU-13207 LU-13186
21         ALWAYS_EXCEPT+=" 14       16a      16b      17"
22 fi
23
24 if [[ "$ost1_FSTYPE" == "zfs" ]]; then
25         # bug #:        LU-1941
26         ALWAYS_EXCEPT+="24a"
27 fi
28 build_test_filter
29
30 check_and_setup_lustre
31
32 if [[ "$MDS1_VERSION" -lt $(version_code 2.9.51) ]]; then
33         skip_env "Need MDS version at least 2.9.51"
34 fi
35
36 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
37         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
38 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
39
40 assert_DIR
41 rm -rf $DIR/[Rdfs][0-9]*
42
43 force_new_seq mds1
44
45 test_0a() {
46         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
47
48         local comp_file=$DIR/$tdir/$tfile
49         local rw_len=$((3 * 1024 * 1024))       # 3M
50
51         test_mkdir $DIR/$tdir
52         rm -f $comp_file
53
54         $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $comp_file ||
55                 error "Create $comp_file failed"
56
57         #instantiate all components, so that objs are allocted
58         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
59
60         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
61         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
62
63         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
64
65         small_write $comp_file $rw_len || error "Verify RW failed"
66
67         rm -f $comp_file || error "Delete $comp_file failed"
68 }
69 run_test 0a "Create full components file, no reused OSTs"
70
71 test_0b() {
72         [[ $($LCTL get_param mdc.*.import |
73                 grep "connect_flags:.*overstriping") ]] ||
74                 skip "server does not support overstriping"
75         large_xattr_enabled || skip_env "no large xattr support"
76
77         force_new_seq_all
78
79         local comp_file=$DIR/$tdir/$tfile
80
81         test_mkdir $DIR/$tdir
82
83         $LFS setstripe -E -1 -C $LOV_MAX_STRIPE_COUNT $comp_file ||
84                 error "Create $comp_file failed"
85
86         local count=$($LFS getstripe -I1 -c $comp_file)
87         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
88                 error "stripe count of first component is shrinked to $count"
89
90         rm -f $comp_file || error "Delete $comp_file failed"
91
92         # Create file with 1.1*LOV_MAX_STRIPE_COUNT stripes should succeed
93         $LFS setstripe -E 1m -C $((LOV_MAX_STRIPE_COUNT / 10)) -E -1 \
94                 -C $LOV_MAX_STRIPE_COUNT $comp_file ||
95                 error "Create $comp_file failed"
96
97         local count=$($LFS getstripe -I2 -c $comp_file)
98         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
99                 error "stripe count of second component is shrinked to $count"
100
101         rm -f $comp_file || error "Delete $comp_file failed"
102
103         # Create file with 3*LOV_MAX_STRIPE_COUNT stripes should fail
104         $LFS setstripe -E 200G -C $LOV_MAX_STRIPE_COUNT \
105                 -E 500G -C $LOV_MAX_STRIPE_COUNT \
106                 -E -1 -C $LOV_MAX_STRIPE_COUNT $comp_file &&
107                 error "Create $comp_file succeeded"
108
109         rm -f $comp_file || error "Delete $comp_file failed"
110 }
111 run_test 0b "Verify comp stripe count limits"
112
113 test_0c() {
114         [[ $($LCTL get_param mdc.*.import |
115                 grep "connect_flags:.*overstriping") ]] ||
116                 skip "server does not support overstriping"
117         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
118                 skip "skipped for lustre < $SEL_VER"
119
120         large_xattr_enabled || skip_env "no large xattr support"
121
122         force_new_seq_all
123
124         local comp_file=$DIR/$tdir/$tfile
125
126         test_mkdir $DIR/$tdir
127
128         # extension size aligned to 64M and limit to 1G
129         $LFS setstripe -E-1 -S64K -C $LOV_MAX_STRIPE_COUNT \
130                 -z $((64*1024*((LOV_MAX_STRIPE_COUNT+1023)>>10<<10))) \
131                 $comp_file || error "Create $comp_file failed"
132
133         local count=$($LFS getstripe -I1 -c $comp_file)
134         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
135                 error "stripe count is shrinked to $count"
136 }
137 run_test 0c "Verify SEL comp stripe count limits"
138
139 test_0d() {
140         (( $MDS1_VERSION > $(version_code 2.14.50.115) )) ||
141                 skip_env "Need MDS version at least 2.14.50.115"
142
143         local td=$DIR/$tdir
144         local tf=$td/$tfile
145         local comp_end
146         local stripe_size
147
148         # Create parent directory
149         test_mkdir $td
150
151         # Component end must be a multiple of stripe size
152         # and a multiple of 64KiB to align with the minimum
153         # stripe size value.
154         # Values below 4096 are assumed to be in KiB units.
155         $LFS setstripe -E 127 $tf-1 > /dev/null 2>&1 &&
156                 error "creating $tf-1 with '-E 127' should fail"
157
158         $LFS setstripe -E 128 -S 512 $tf-1 > /dev/null 2>&1 &&
159                 error "creating $tf-1 with '-E 128 -S 512' should fail"
160
161         $LFS setstripe -E 128 $tf-1 ||
162                 error "creating $tf-1 failed"
163
164         yes | dd bs=1K count=129 iflag=fullblock of=$tf-1 &&
165                 error "writing to $tf-1 should fail"
166
167         yes | dd bs=1K count=128 iflag=fullblock of=$tf-1 ||
168                 error "writing to $tf-1 failed"
169
170         comp_end=$($LFS getstripe -I1 -E $tf-1)
171         stripe_size=$($LFS getstripe -I1 -S $tf-1)
172
173         [[ $comp_end == $((128 * 1024)) ]] ||
174                 error "incorrect component end '$comp_end' for $tf-1"
175
176         [[ $stripe_size == $((128 * 1024)) ]] ||
177                 error "incorrect stripe size '$stripe_size' for $tf-1"
178
179         rm $tf-1 || error "removing $tf-1 failed"
180
181         # The stripe size must be a multiple of 64KiB.
182         # Values below 4096 are assumed to be in KiB units.
183         $LFS setstripe -E -1 -S 2047 $tf-2 > /dev/null 2>&1 &&
184                 error "creating $tf-2 with '-S 2047' should fail"
185
186         $LFS setstripe -E -1 -S 2048 $tf-2 ||
187                 error "creating $tf-2 failed"
188
189         stripe_size=$($LFS getstripe -I1 -S $tf-2)
190         [[ $stripe_size == $((2048 * 1024)) ]] ||
191                 error "incorrect stripe size '$stripe_size' for $tf-2"
192
193         rm $tf-2 || error "removing $tf-2 failed"
194 }
195 run_test 0d "Verify comp end and stripe size"
196
197 test_0e() {
198         (( $MDS1_VERSION >= $(version_code 2.15.56.112) )) ||
199                 skip "Need MDS version at least 2.15.56.112"
200
201         (( OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
202
203         local td=$DIR/$tdir
204         local tf=$td/$tfile
205
206         test_mkdir $td
207
208         # component size 1M can only utilize 1 stripe
209         $LFS setstripe -E1M -S1M -c2 -Eeof -S1M -c2 $tf ||
210                 error "failed to setstripe $tf"
211
212         local sc=$($LFS getstripe -I1 -c $tf)
213         (( sc == 1 )) || {
214                 $LFS getstripe $tf
215                 error "expect 1 stripe count instread of $sc"
216         }
217         sc=$($LFS getstripe -I2 -c $tf)
218         (( sc == 2 )) || {
219                 $LFS getstripe $tf
220                 error "expect 2 stripe count instread of $sc"
221         }
222
223         (( OSTCOUNT >= 3 )) || skip "needs >= 3 OSTs"
224
225         rm -f $tf
226         # component size 2M can only utilize 2 stripes
227         $LFS setstripe -E2M -S1M -c3 -Eeof -S1M -c3 $tf ||
228                 error "failed to setstripe $tf"
229         sc=$($LFS getstripe -I1 -c $tf)
230         (( sc == 2 )) || {
231                 $LFS getstripe $tf
232                 error "expect 2 stripe count instread of $sc"
233         }
234         sc=$($LFS getstripe -I2 -c $tf)
235         (( sc == 3 )) || {
236                 $LFS getstripe $tf
237                 error "expect 3 stripe count instread of $sc"
238         }
239
240         rm -f $tf
241         # 2nd component size 11M and stripe_size 4M should cross 3 stripes
242         $LFS setstripe -E1M -S1M -c3 -E12M -S4M -c3 $tf ||
243                 error "failed to setstripe $tf"
244         sc=$($LFS getstripe -I1 -c $tf)
245         (( sc == 1 )) || {
246                 $LFS getstripe $tf
247                 error "expect 1 stripe count instread of $sc"
248         }
249         sc=$($LFS getstripe -I2 -c $tf)
250         (( sc == 3 )) || {
251                 $LFS getstripe $tf
252                 error "expect 3 stripe count instread of $sc"
253         }
254 }
255 run_test 0e "lfs setstripe should limite stripe count for component size"
256
257 test_1a() {
258         local comp_file=$DIR/$tdir/$tfile
259         local rw_len=$((3 * 1024 * 1024))       # 3M
260
261         test_mkdir $DIR/$tdir
262         rm -f $comp_file
263
264         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
265                 error "Create $comp_file failed"
266
267         #instantiate all components, so that objs are allocted
268         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
269
270         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
271         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
272
273         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
274
275         small_write $comp_file $rw_len || error "Verify RW failed"
276
277         rm -f $comp_file || error "Delete $comp_file failed"
278 }
279 run_test 1a "Create full components file, reused OSTs"
280
281 # test overstriping (>1 stripe/OST within a component)
282 test_1b() {
283         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
284         [[ $($LCTL get_param mdc.*.import |
285                 grep "connect_flags:.*overstriping") ]] ||
286                 skip "server does not support overstriping"
287
288         local comp_file=$DIR/$tdir/$tfile
289         local rw_len=$((3 * 1024 * 1024))       # 3M
290
291         test_mkdir $DIR/$tdir
292
293         $LFS setstripe -E 2m -S 1m -o 0,0 -E -1 -o 1,1,0,0 $comp_file ||
294                 error "Create $comp_file failed"
295
296         #instantiate all components, so that objs are allocted
297         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1M
298
299         $LFS getstripe $comp_file
300         local OSTS_1=$($LFS getstripe -I1 $comp_file | grep -o 'l_ost_idx.*' |
301                       awk -e '{print $2}' | tr "\n" "\0")
302         local OSTS_2=$($LFS getstripe -I2 $comp_file | grep -o 'l_ost_idx.*' |
303                       awk -e '{print $2}' | tr "\n" "\0")
304
305         echo ":"$OSTS_1":"
306         echo ":"$OSTS_2":"
307         [ "$OSTS_1" = "0,0," ] || error "incorrect OSTs($OSTS_1) in component 1"
308         [ "$OSTS_2" = "1,1,0,0," ] ||
309                 error "incorrect OSTs($OSTS_2) in component 2"
310
311         small_write $comp_file $rw_len || error "Verify RW failed"
312
313         rm -f $comp_file || error "Delete $comp_file failed"
314 }
315 run_test 1b "Create full components file, overstriping in components"
316
317 # test overstriping with max stripe count
318 test_1c() {
319         [[ $($LCTL get_param mdc.*.import |
320                 grep "connect_flags:.*overstriping") ]] ||
321                 skip "server does not support overstriping"
322         large_xattr_enabled || skip_env "no large xattr support"
323
324         force_new_seq_all
325
326         local comp_file=$DIR/$tdir/$tfile
327         local rw_len=$((3 * 1024 * 1024))       # 3M
328
329         test_mkdir $DIR/$tdir
330
331         $LFS setstripe -E 10m -C 10 -E 110M -C 100 -E -1 \
332             -C $LOV_MAX_STRIPE_COUNT $comp_file ||
333                 error "Create $comp_file failed"
334
335         # Seek & write in to last component so all objects are allocated
336         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=20000
337
338         local count=$($LFS getstripe -c -I1 $DIR/$tdir/$tfile)
339         [ $count -eq 10 ] || error "comp1 stripe count $count, should be 10"
340         count=$($LFS getstripe -c -I2 $DIR/$tdir/$tfile)
341         [ $count -eq 100 ] || error "comp2 stripe count $count, should be 100"
342         count=$($LFS getstripe -c -I3 $DIR/$tdir/$tfile)
343         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
344                 error "comp4 stripe count $count != $LOV_MAX_STRIPE_COUNT"
345
346         small_write $comp_file $rw_len || error "Verify RW failed"
347
348         rm -f $comp_file || error "Delete $comp_file failed"
349 }
350 run_test 1c "Test overstriping w/max stripe count"
351
352 base_test_2() {
353         local comp_file=$DIR/$tdir/$tfile
354         local rw_len=$((5 * 1024 * 1024))       # 5M
355         local params=$1
356
357         test_mkdir $DIR/$tdir
358         rm -f $comp_file
359
360         multiop $comp_file oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
361                 error "create failed $comp_file"
362
363         $LFS setstripe --component-add $params $comp_file ||
364                 error "Add component to $comp_file failed"
365
366         check_component_count $comp_file 1
367
368         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
369                 error "Write first component failed"
370         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
371                 error "Read first component failed"
372
373         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
374                 error "Write beyond component should fail"
375         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
376                 error "Read beyond component should short read, not fail"
377
378         $LFS setstripe --component-add -E 2M -S 1M -c 1 $comp_file ||
379                 error "Add component to $comp_file failed"
380
381         check_component_count $comp_file 2
382
383         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
384                 error "Add last component to $comp_file failed"
385
386         check_component_count $comp_file 3
387
388         small_write $comp_file $rw_len || error "Verify RW failed"
389
390         rm -f $comp_file || error "Delete $comp_file failed"
391 }
392
393 test_2a() {
394         base_test_2 "-E 1m -S 1m"
395 }
396 run_test 2a "Add components to existing file"
397
398 test_2b () {
399         base_test_2 "-E 1m -L mdt"
400 }
401 run_test 2b "Add components w/DOM to existing file"
402
403 del_comp_and_verify() {
404         local comp_file=$1
405         local id=$2
406         local left=$3
407         local size=$4
408
409         local opt="-I "
410         if [ $id == "init" -o $id == "^init" ]; then
411                 opt="--component-flags="
412         fi
413
414         $LFS setstripe --component-del $opt$id $comp_file ||
415                 error "Delete component $id from $comp_file failed"
416
417         local comp_cnt=$($LFS getstripe --component-count $comp_file)
418         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
419                 comp_cnt=0
420         fi
421         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
422
423         $CHECKSTAT -s $size $comp_file || error "size != $size"
424 }
425
426 base_test_3() {
427         local comp_file=$DIR/$tdir/$tfile
428         local params=$1
429
430         test_mkdir $DIR/$tdir
431         rm -f $comp_file
432
433         $LFS setstripe $params $comp_file || error "Create $comp_file failed"
434
435         check_component_count $comp_file 3
436
437         dd if=/dev/zero of=$comp_file bs=1M count=2
438
439         $LFS setstripe --component-del -I 2 $comp_file &&
440                 error "Component deletion makes hole"
441
442         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
443         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
444         del_comp_and_verify $comp_file 1 0 0
445
446         rm -f $comp_file || error "Delete $comp_file failed"
447
448         $LFS setstripe -E 1M -S 1M -E 16M -E -1 $comp_file ||
449                 error "Create second $comp_file failed"
450
451         del_comp_and_verify $comp_file "^init" 1 0
452         del_comp_and_verify $comp_file "init" 0 0
453         rm -f $comp_file || error "Delete second $comp_file failed"
454 }
455
456 test_3a() {
457         base_test_3 "-E 1M -S 1M -E 64M -c 2 -E -1 -c 3"
458 }
459 run_test 3a "Delete components from existing file"
460
461 test_3b() {
462         base_test_3 "-E 1M -L mdt -E 64M -S 1M -c 2 -E -1 -c 3"
463 }
464 run_test 3b "Delete components w/DOM from existing file"
465
466 test_4() {
467         skip "Not supported in PFL"
468         # In PFL project, only LCME_FL_INIT is supported, and it can't
469         # be altered by application.
470 }
471 run_test 4 "Modify component flags in existing file"
472
473 test_5() {
474         local parent=$DIR/$tdir
475         local comp_file=$DIR/$tdir/$tfile
476         local subdir=$parent/subdir
477
478         rm -fr $parent
479         test_mkdir $parent
480
481         # set default layout to parent directory
482         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
483                 error "Set default layout to $parent failed"
484
485         # create file under parent
486         touch $comp_file || error "Create $comp_file failed"
487         check_component_count $comp_file 2
488
489         #instantiate all components, so that objs are allocted
490         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k
491
492         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
493         [ $ost_idx -ne 0 ] &&
494                 error "component 1 ost_idx $ost_idx != 0"
495
496         ost_idx=$($LFS getstripe -I2 -i $comp_file)
497         [ $ost_idx -ne 0 ] &&
498                 error "component 2 ost_idx $ost_idx != 0"
499
500         # create subdir under parent
501         mkdir -p $subdir || error "Create subdir $subdir failed"
502
503         comp_cnt=$($LFS getstripe -d --component-count $subdir)
504         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
505
506         # create file under subdir
507         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
508
509         check_component_count $subdir/$tfile 2
510
511         # delete default layout setting from parent
512         $LFS setstripe -d $parent ||
513                 error "Delete default layout from $parent failed"
514
515         comp_cnt=$($LFS getstripe -d --component-count $parent)
516         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
517
518         rm -f $comp_file || error "Delete $comp_file failed"
519         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
520         rm -r $subdir || error "Delete subdir $subdir failed"
521         rmdir $parent || error "Delete dir $parent failed"
522 }
523 run_test 5 "Inherit composite layout from parent directory"
524
525 test_6() {
526         local comp_file=$DIR/$tdir/$tfile
527
528         test_mkdir $DIR/$tdir
529         rm -f $DIR/$tfile
530
531         $LFS setstripe -c 1 -S 128K $comp_file ||
532                 error "Create v1 $comp_file failed"
533
534         check_component_count $comp_file 0
535
536         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
537                 error "Write to v1 $comp_file failed"
538
539         local old_chksum=$(md5sum $comp_file)
540
541         # Migrate v1 to composite
542         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
543                 error "Migrate(v1 -> composite) $comp_file failed"
544
545         check_component_count $comp_file 2
546
547         local chksum=$(md5sum $comp_file)
548         [ "$old_chksum" != "$chksum" ] &&
549                 error "(v1 -> compsoite) $old_chksum != $chksum"
550
551         # Migrate composite to composite
552         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
553                 -E -1 -S 3M -c 3 $comp_file ||
554                 error "Migrate(compsoite -> composite) $comp_file failed"
555
556         check_component_count $comp_file 3
557
558         chksum=$(md5sum $comp_file)
559         [ "$old_chksum" != "$chksum" ] &&
560                 error "(composite -> compsoite) $old_chksum != $chksum"
561
562         # Migrate composite to v1
563         $LFS migrate -c 2 -S 2M $comp_file ||
564                 error "Migrate(composite -> v1) $comp_file failed"
565
566         check_component_count $comp_file 0
567
568         chksum=$(md5sum $comp_file)
569         [ "$old_chksum" != "$chksum" ] &&
570                 error "(composite -> v1) $old_chksum != $chksum"
571
572         rm -f $comp_file || error "Delete $comp_file failed"
573 }
574 run_test 6 "Migrate composite file"
575
576 test_7() {
577         test_mkdir $DIR/$tdir
578         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
579
580         local comp_file=$DIR/$tdir/$tfile
581         $RUNAS $LFS setstripe -E 1M -S 1M -c 1 $comp_file ||
582                 error "Create composite file $comp_file failed"
583
584         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
585                 error "Add component to $comp_file failed"
586
587         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
588                 error "Delete component from $comp_file failed"
589
590         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
591                 error "Add last component to $comp_file failed"
592
593         rm $comp_file || error "Delete composite failed"
594 }
595 run_test 7 "Add/Delete/Create composite file by non-privileged user"
596
597 test_8() {
598         local parent=$DIR/$tdir
599
600         rm -fr $parent
601         mkdir_on_mdt0 $parent
602
603         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
604                 -E -1 -c 4 -S 4M $parent ||
605                 error "Set default layout to $parent failed"
606
607         bash rundbench -C -D $parent 2 || error "dbench failed"
608
609         rm -fr $parent || error "Delete dir $parent failed"
610 }
611 run_test 8 "Run dbench over composite files"
612
613 test_9() {
614         local comp_file=$DIR/$tdir/$tfile
615
616         test_mkdir $DIR/$tdir
617         rm -f $comp_file
618
619         $LFS setstripe -E 1M -S 1M -E -1 -c 1 $comp_file ||
620                 error "Create $comp_file failed"
621
622         check_component_count $comp_file 2
623
624         replay_barrier $SINGLEMDS
625
626         # instantiate the 2nd component
627         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
628
629         local f1=$($LFS getstripe -I2 $comp_file |
630                         awk '/l_fid:/ {print $7}')
631         echo "before MDS recovery, the ost fid of 2nd component is $f1"
632         fail $SINGLEMDS
633
634         local f2=$($LFS getstripe -I2 $comp_file |
635                         awk '/l_fid:/ {print $7}')
636         echo "after MDS recovery, the ost fid of 2nd component is $f2"
637         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
638 }
639 run_test 9 "Replay layout extend object instantiation"
640
641 component_dump() {
642         echo $($LFS getstripe $1 |
643                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
644                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
645                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
646 }
647
648 test_10() {
649         local parent=$DIR/$tdir
650         local root=$MOUNT
651
652         save_layout_restore_at_exit $MOUNT
653
654         rm -rf $parent
655
656         # mount root on $MOUNT2 if FILESET is set
657         if [ -n "$FILESET" ]; then
658                 FILESET="" mount_client $MOUNT2 ||
659                         error "mount $MOUNT2 fail"
660                 root=$MOUNT2
661         fi
662
663         $LFS setstripe -d $root || error "clear root layout"
664
665         # set root composite layout
666         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
667                 -E -1 -c 4 -S 4M $root ||
668                 error "Set root layout failed"
669
670         if [ "$root" == "$MOUNT2" ]; then
671                 umount_client $MOUNT2 ||
672                         error "umount $MOUNT2 fail"
673         fi
674
675         test_mkdir $parent
676         # set a different layout for parent
677         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
678                 error "set $parent layout failed"
679         touch $parent/file1
680
681         local f1_entry=$(component_dump $parent/file1)
682
683         # delete parent's layout
684         $LFS setstripe -d $parent || error "Clear $parent layout failed"
685         touch $parent/file2
686
687         local f2_entry=$(component_dump $parent/file2)
688
689         # verify layout inheritance
690         local eof="EOF"
691         local f1_expect="1[0,EOF]"
692         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
693
694         echo "f1 expect=$f1_expect"
695         echo "f1 get   =$f1_entry"
696         echo "f2 expect=$f2_expect"
697         echo "f2 get   =$f2_entry"
698
699         [  x$f1_expect != x$f1_entry ] &&
700                 error "$parent/file1 does not inherite parent layout"
701         [  x$f2_expect != x$f2_entry ] &&
702                 error "$parent/file2 does not inherite root layout"
703
704         return 0
705 }
706 run_test 10 "Inherit composite template from root"
707
708 test_11a() {
709         local comp_file=$DIR/$tdir/$tfile
710         test_mkdir $DIR/$tdir
711         rm -f $comp_file
712
713         # only 1st component instantiated
714         $LFS setstripe -E 1M -S 1M -E 2M -E 3M -E -1 $comp_file ||
715                 error "Create $comp_file failed"
716
717         local f1=$($LFS getstripe -I1 $comp_file | grep "l_fid")
718         [[ -z $f1 ]] && error "1: 1st component uninstantiated"
719         local f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
720         [[ -n $f2 ]] && error "1: 2nd component instantiated"
721         local f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
722         [[ -n $f3 ]] && error "1: 3rd component instantiated"
723         local f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
724         [[ -n $f4 ]] && error "1: 4th component instantiated"
725
726         # the first 2 components instantiated
727         # Truncate to exact start of new component - LU-12586
728         $TRUNCATE $comp_file $((1024*1024*1))
729
730         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
731         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
732         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
733         [[ -n $f3 ]] && error "2: 3rd component instantiated"
734         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
735         [[ -n $f4 ]] && error "2: 4th component instantiated"
736
737         # the first 3 components instantiated
738         $TRUNCATE $comp_file $((1024*1024*3 - 1))
739         $TRUNCATE $comp_file $((1024*1024*1+1))
740
741         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
742         [[ -z $f2 ]] && error "3: 2nd component uninstantiated"
743         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
744         [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
745         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
746         [[ -n $f4 ]] && error "3: 4th component instantiated"
747
748         # all 4 components instantiated, using append write
749         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
750         ls -l $comp_file
751         rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1
752         ls -l $comp_file
753
754         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
755         [[ -z $f4 ]] && error "4: 4th component uninstantiated"
756
757         return 0
758 }
759 run_test 11a "Verify component instantiation with write/truncate"
760
761 test_11b() {
762         [ $OSTCOUNT -lt 4 ] && skip "needs >= 4 OSTs"
763
764         local file=$DIR/$tdir/$tfile
765
766         test_mkdir $DIR/$tdir
767         rm -f $file
768
769         $LFS setstripe -E 1m -E 1g -c 4 -E eof $DIR/$tdir ||
770                 error "setstripe dir $DIR/$tdir failed"
771         expand_truncate_test $file ||
772                 error "expand_truncate_test failed on $file"
773 }
774 run_test 11b "truncate file set file size correctly"
775
776 test_12() {
777         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs"
778
779         local file=$DIR/$tdir/$tfile
780         test_mkdir $DIR/$tdir
781         rm -f $file
782
783         # specify ost list for component
784         $LFS setstripe -E 2M -S 1M -c 2 -o 0,1 -E 4M -c 2 -o 1,2 \
785                 -E 6M -c 2 -o 2,1 -E 8M -c 1 -i 2 -E -1 $file ||
786                 error "Create $file failed"
787
788         # clear lod component cache
789         stop $SINGLEMDS || error "stop MDS"
790         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
791         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
792
793         # instantiate all components
794         $TRUNCATE $file $((1024*1024*8+1))
795
796         #verify object alloc order
797         local o1=$($LFS getstripe -I1 $file |
798                         awk '/l_ost_idx:/ {printf("%d",$5)}')
799         [[ $o1 != "01" ]] && error "$o1 is not 01"
800
801         local o2=$($LFS getstripe -I2 $file |
802                         awk '/l_ost_idx:/ {printf("%d",$5)}')
803         [[ $o2 != "12" ]] && error "$o2 is not 12"
804
805         local o3=$($LFS getstripe -I3 $file |
806                         awk '/l_ost_idx:/ {printf("%d",$5)}')
807         [[ $o3 != "21" ]] && error "$o3 is not 21"
808
809         local o4=$($LFS getstripe -I4 $file |
810                         awk '/l_ost_idx:/ {printf("%d",$5)}')
811         [[ $o4 != "2" ]] && error "$o4 is not 2"
812
813         return 0
814 }
815 run_test 12 "Verify ost list specification"
816
817 test_13() { # LU-9311
818         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs"
819
820         local file=$DIR/$tfile
821         local dd_count=4
822         local dd_size=$(($dd_count * 1024 * 1024))
823         local real_size
824
825         rm -f $file
826         $LFS setstripe -E 1M -S 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
827                 error "Create $file failed"
828         dd if=/dev/zero of=$file bs=1M count=$dd_count
829         real_size=$(stat -c %s $file)
830         [ $real_size -eq $dd_size ] ||
831                 error "dd actually wrote $real_size != $dd_size bytes"
832
833         rm -f $file
834 }
835 run_test 13 "shouldn't reprocess granted resent request"
836
837 test_14() {
838         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
839         local file=$DIR/$tdir/$tfile
840         test_mkdir -p $DIR/$tdir
841         rm -f $file
842
843         $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
844                         -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
845                 error "Create $file failed"
846
847         # check --pool inheritance
848         local pool
849         pool="$($LFS getstripe -I2 --pool $file)"
850         [ x"$pool" != "xpool1" ] && $LFS getstripe -I2 $file &&
851                 error "$file: component 2 doesn't have poolname pool1"
852         pool="$($LFS getstripe -I4 --pool $file)"
853         [ x"$pool" != "xpool2" ] && $LFS getstripe -I4 $file &&
854                 error "$file: component 4 doesn't have poolname pool2"
855
856         #check --stripe-count inheritance
857         local count
858         count="$($LFS getstripe -I2 -c $file)"
859         [ $count -ne 1 ] && $LFS getstripe -I2 $file &&
860                 error "$file: component 2 doesn't have 1 stripe_count"
861         count="$($LFS getstripe -I4 -c $file)"
862         [ $count -ne 2 ] && $LFS getstripe -I4 $file &&
863                 error "$file: component 4 doesn't have 2 stripe_count"
864
865         #check --stripe-size inheritance
866         local size
867         size="$($LFS getstripe -I2 -S $file)"
868         [ $size -ne $((1024*1024)) ] && $LFS getstripe -I2 $file &&
869                 error "$file: component 2 doesn't have 1M stripe_size"
870         size="$($LFS getstripe -I4 -S $file)"
871         [ $size -ne $((1024*1024*2)) ] && $LFS getstripe -I4 $file &&
872                 error "$file: component 4 doesn't have 2M stripe_size"
873
874         return 0
875 }
876 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
877
878 test_15() {
879         local parent=$DIR/$tdir
880
881         rm -fr $parent
882         test_mkdir $parent
883
884         $LFS setstripe -d $parent || error "delete default layout"
885
886         $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1"
887         $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
888         test_mkdir $parent/subdir
889         $LFS setstripe -E 6M -S 1M -c1 -E 30M -c4 -E eof -c $OSTCOUNT \
890                 $parent/subdir || error "setstripe to subdir"
891         $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
892         $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
893
894         # none
895         local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
896         [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
897
898         # f2, f3
899         found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
900         [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
901
902         # subdir
903         found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
904         [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
905
906         local flg_opts="--component-flags init"
907         # none
908         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
909         [ $found -eq 0 ] ||
910                 error "before write: start=1M, end=10M, flag=init, $found != 0"
911
912         dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
913                 error "dd $parent/f1 failed"
914
915         # f1
916         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
917         [ $found -eq 1 ] ||
918                 error "after write: start=1M, end=10M, flag=init, $found != 1"
919
920         local ext_opts="--component-start -1M -E +5M"
921         # parent, subdir, f3, f4
922         found=$($LFS find $ext_opts $parent | wc -l)
923         [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
924
925         local cnt_opts="--component-count +2"
926         # subdir
927         found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
928         [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
929
930         # none
931         found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
932         [ $found -eq 0 ] ||
933                 error "start-1M, end+5M, count+2, flag=init, $found != 0"
934
935         # f3, f4
936         found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
937         [ $found -eq 2 ] ||
938                 error "start-1M, end+5M, !count+2, flag=init, $found != 2"
939
940         # check last component stripe count
941         if [ $OSTCOUNT -gt 1 ]; then
942                 touch $parent/subdir/f5
943                 $TRUNCATE $parent/subdir/f5 $((32*1024*1024))
944                 found=$($LFS find $parent/subdir -c $OSTCOUNT)
945                 [[ "$found" == "$parent/subdir/f5" ]] ||
946                         error "got '$found' with stripe_count=$OSTCOUNT, not f5"
947         fi
948 }
949 run_test 15 "Verify component options for lfs find"
950
951 test_16a() {
952         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
953         large_xattr_enabled || skip_env "ea_inode feature disabled"
954
955         local file=$DIR/$tdir/$tfile
956         local dir=$DIR/$tdir/dir
957         local temp=$DIR/$tdir/template
958         rm -rf $DIR/$tdir
959         test_mkdir $DIR/$tdir
960
961         #####################################################################
962         #                           1. PFL file
963         # set stripe for source file
964         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
965                 $file || error "Create $file failed"
966
967         echo "1. PFL file"
968         verify_yaml_layout $file $file.copy $temp "1. PFL file"
969
970         #####################################################################
971         #                           2. plain file
972         # set stripe for source file
973         rm -f $file
974         $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
975
976         rm -f $file.copy
977         echo "2. plain file"
978         verify_yaml_layout $file $file.copy $temp "2. plain file"
979
980         #####################################################################
981         #                           3. PFL dir
982         # set stripe for source dir
983         test_mkdir $dir
984         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
985                 error "setstripe $dir failed"
986
987         test_mkdir $dir.copy
988         echo "3. PFL dir"
989         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
990
991         #####################################################################
992         #                           4. plain dir
993         # set stripe for source dir
994         $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
995
996         echo "4. plain dir"
997         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
998 }
999 run_test 16a "Verify setstripe/getstripe with YAML config file"
1000
1001 test_16b() {
1002         [[ $($LCTL get_param mdc.*.import |
1003                 grep "connect_flags:.*overstriping") ]] ||
1004                 skip "server does not support overstriping"
1005         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1006         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
1007                 skip_env "too many osts, skipping"
1008         large_xattr_enabled || skip_env "ea_inode feature disabled"
1009
1010         force_new_seq_all
1011
1012         local file=$DIR/$tdir/$tfile
1013         local dir=$DIR/$tdir/dir
1014         local temp=$DIR/$tdir/template
1015         # We know OSTCOUNT < (LOV_MAX_STRIPE_COUNT / 2), so this is overstriping
1016         local large_count=$((LOV_MAX_STRIPE_COUNT / 2 + 10))
1017
1018         rm -rf $DIR/$tdir
1019         test_mkdir $DIR/$tdir
1020
1021         #####################################################################
1022         #                           1. PFL file, overstriping in first comps
1023         # set stripe for source file
1024         $LFS setstripe -E1m -S 1M -o0,0 -E2m -o1,1 -E3m -C $large_count -E-1 \
1025                 $file || error "Create $file failed"
1026
1027         echo "1. PFL file"
1028         verify_yaml_layout $file $file.copy $temp "1. PFL file"
1029
1030         #####################################################################
1031         #                           2. plain file + overstriping
1032         # set stripe for source file
1033         rm -f $file
1034         $LFS setstripe -C $large_count -i1 $file || error "Create $file failed"
1035
1036         rm -f $file.copy
1037         echo "2. plain file"
1038         verify_yaml_layout $file $file.copy $temp "2. plain file"
1039
1040         #####################################################################
1041         #                           3. PFL dir + overstriping
1042         # set stripe for source dir
1043         test_mkdir $dir
1044         $LFS setstripe -E1m -S 1M -o 0,0 -E2m -C $large_count -E-1 $dir ||
1045                 error "setstripe $dir failed"
1046
1047         test_mkdir $dir.copy
1048         echo "3. PFL dir"
1049         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
1050
1051         #####################################################################
1052         #                           4. plain dir + overstriping
1053         # set stripe for source dir
1054         $LFS setstripe -C $large_count $dir || error "setstripe $dir failed"
1055
1056         echo "4. plain dir"
1057         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
1058 }
1059 run_test 16b "Verify setstripe/getstripe with YAML config file + overstriping"
1060
1061 test_16c() {
1062         (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
1063                 skip "need MDS version at least 2.13.53.205"
1064
1065         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1066
1067         local file=$DIR/$tdir/$tfile
1068         local dir=$DIR/$tdir/dir
1069         local temp=$DIR/$tdir/template
1070         rm -rf $DIR/$tdir
1071         test_mkdir $DIR/$tdir
1072
1073         #####################################################################
1074         #                           1. SEL file
1075         # set stripe for source file
1076         $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
1077                 $file || error "Create $file failed"
1078
1079         echo "1. SEL file"
1080         verify_yaml_layout $file $file.copy $temp "1. PFL file"
1081
1082         #####################################################################
1083         #                           2. SEL dir
1084         # set stripe for source dir
1085         test_mkdir $dir
1086         $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
1087                 $dir || error "setstripe $dir failed"
1088
1089         test_mkdir $dir.copy
1090         echo "2. SEL template on dir"
1091         verify_yaml_layout $dir $dir.copy $temp.dir "2. PFL dir"
1092 }
1093 run_test 16c "Verify setstripe/getstripe for SEL layout with YAML config file"
1094
1095 test_16d() {
1096         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1097
1098         local file=$DIR/$tdir/$tfile
1099         local dir=$DIR/$tdir/dir
1100         local temp=$DIR/$tdir/template
1101         rm -rf $DIR/$tdir
1102         test_mkdir $DIR/$tdir
1103
1104         #####################################################################
1105         #                           1. DOM file
1106         # set stripe for source file
1107         $LFS setstripe -E1m -L mdt -E-1 -o1,0 $file ||
1108                 error "Create $file failed"
1109
1110         echo "1. DOM file"
1111         verify_yaml_layout $file $file.copy $temp "1. DOM file"
1112
1113         #####################################################################
1114         #                           2. DOM dir
1115         # set stripe for source dir
1116         test_mkdir $dir
1117         $LFS setstripe -E1m -L mdt -E-1 -o1,0 $dir || error "Create $dir failed"
1118
1119         test_mkdir $dir.copy
1120         echo "2. DOM dir"
1121         verify_yaml_layout $dir $dir.copy $temp.dir "2. DOM dir"
1122 }
1123 run_test 16d "Verify setstripe/getstripe for DOM layout with YAML config file"
1124
1125
1126 test_17() {
1127         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1128         local file=$DIR/$tdir/$tfile
1129         test_mkdir -p $DIR/$tdir
1130         rm -f $file
1131
1132         $LFS setstripe -E 1M -S 1M -E 3M -c 2 -E -1 -c -1 $file ||
1133                 error "Create $file failed"
1134
1135         local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
1136         local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
1137         local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
1138         echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
1139
1140         # init 2nd component
1141         $TRUNCATE $file $((1024*1024+1))
1142         local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
1143         local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
1144         echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
1145
1146         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
1147         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
1148
1149         # init 3rd component
1150         $TRUNCATE $file $((1024*1024*3+1))
1151         s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
1152         s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
1153         local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
1154         echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
1155
1156         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
1157         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
1158         [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
1159 }
1160 run_test 17 "Verify LOVEA grows with more component inited"
1161
1162 check_distribution() {
1163         local file=$1
1164         local objs
1165         local ave
1166         local obj_min_one=$((OSTCOUNT - 1))
1167
1168         objs=$($LFS getstripe $file |
1169                 awk '/l_ost_idx:/ { print $5 }' | wc -l)
1170         let ave=$((objs / OSTCOUNT))
1171
1172         # collect objects per OST distribution
1173         $LFS getstripe $file | awk '/l_ost_idx:/ { print $5 }' | tr -d "," |
1174                 (inuse=( $(for i in $(seq 0 $obj_min_one); do echo 0; done) )
1175                 while read O; do
1176                         let inuse[$O]=$((1 + ${inuse[$O]}))
1177                 done;
1178
1179                 # verify object distribution varies no more than +-1
1180                 for idx in $(seq 0 $obj_min_one); do
1181                         let dif=$((${inuse[$idx]} - ave))
1182                         let dif=${dif#-}
1183                         if [ "$dif" -gt 1 ]; then
1184                                 echo "OST${idx}: ${inuse[$idx]} objects"
1185                                 error "bad distribution on OST${idx}"
1186                         fi
1187                 done)
1188 }
1189
1190 test_18() {
1191         local file1=$DIR/${tfile}-1
1192         local file2=$DIR/${tfile}-2
1193         local file3=$DIR/${tfile}-3
1194
1195         rm -f $file1 $file2 $file3
1196
1197         $LFS setstripe -E 1m -S 1m $file1 ||
1198                 error "Create $file1 failed"
1199         $LFS setstripe -E 1m -S 1m $file2 ||
1200                 error "Create $file2 failed"
1201         $LFS setstripe -E 1m -S 1m $file3 ||
1202                 error "Create $file3 failed"
1203
1204         local objs=$((OSTCOUNT+1))
1205         for comp in $(seq 1 $OSTCOUNT); do
1206                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file1 ||
1207                         error "Add component to $file1 failed 2"
1208                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file2 ||
1209                         error "Add component to $file2 failed 2"
1210                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file3 ||
1211                         error "Add component to $file3 failed 2"
1212         done
1213
1214         $LFS setstripe --component-add -E -1 -c -1 $file1 ||
1215                 error "Add component to $file1 failed 3"
1216         $LFS setstripe --component-add -E -1 -c -1 $file2 ||
1217                 error "Add component to $file2 failed 3"
1218         $LFS setstripe --component-add -E -1 -c -1 $file3 ||
1219                 error "Add component to $file3 failed 3"
1220
1221         # Instantiate all components
1222         dd if=/dev/urandom of=$file1 bs=1M count=$((objs+1)) ||
1223                 error "dd failed for $file1"
1224         dd if=/dev/urandom of=$file2 bs=1M count=$((objs+1)) ||
1225                 error "dd failed for $file2"
1226         dd if=/dev/urandom of=$file3 bs=1M count=$((objs+1)) ||
1227                 error "dd failed for $file3"
1228
1229         check_distribution $file1
1230         check_distribution $file2
1231         check_distribution $file3
1232
1233 }
1234 run_test 18 "check component distribution"
1235
1236 test19_io_base() {
1237         local comp_file=$1
1238         local already_created=${2:-0}
1239         local rw_len=$((3 * 1024 * 1024))       # 3M
1240         local flg_opts=""
1241         local found=""
1242
1243         if [ $already_created != 1 ]; then
1244                 test_mkdir -p $DIR/$tdir
1245                 $LFS setstripe --extension-size 64M -c 1 -E -1 $comp_file ||
1246                         error "Create $comp_file failed"
1247         fi
1248
1249         # write past end of first component, so it is extended
1250         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=127 conv=notrunc ||
1251                 error "dd to extend failed"
1252
1253         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1254         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1255
1256         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1257         [ $ost_idx2 -ne "-1" ] && error "second component init $ost_idx2"
1258
1259         flg_opts="--comp-flags init"
1260         found=$($LFS find --comp-start 0 -E 128M $flg_opts $comp_file | wc -l)
1261         [ $found -eq 1 ] || error "Write: Extended first component not found"
1262
1263         flg_opts="--comp-flags extension"
1264         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
1265         [ $found -eq 1 ] || error "Write: second component not found"
1266
1267         found=$($LFS find -z 64M $comp_file | wc -l)
1268         [ $found -eq 1 ] || error "component not found by ext size"
1269
1270         found=$($LFS find --extension-size +63M $comp_file | wc -l)
1271         [ $found -eq 1 ] || error "component not found by +ext size"
1272
1273         found=$($LFS find --ext-size -65M $comp_file | wc -l)
1274         [ $found -eq 1 ] || error "component not found by -ext size"
1275
1276         found=$($LFS find -z 65M $comp_file | wc -l)
1277         [ $found -eq 0 ] || error "component found by wrong ext size"
1278
1279         found=$($LFS find -z +65M $comp_file | wc -l)
1280         [ $found -eq 0 ] || error "component found by wrong +ext size"
1281
1282         found=$($LFS find -z -63M $comp_file | wc -l)
1283         [ $found -eq 0 ] || error "component found by wrong -ext size"
1284
1285         found=$($LFS find ! -z 64M $comp_file | wc -l)
1286         [ $found -eq 0 ] || error "component found by negation of ext size"
1287
1288         found=$($LFS find ! -z +63M $comp_file | wc -l)
1289         [ $found -eq 0 ] || error "component found by negation of +ext size"
1290
1291         found=$($LFS find ! -z -65M $comp_file | wc -l)
1292         [ $found -eq 0 ] || error "component found by negation of -ext size"
1293
1294         found=$($LFS find ! -z 65M $comp_file | wc -l)
1295         [ $found -eq 1 ] ||
1296                 error "component not found by negation of wrong ext size"
1297
1298         found=$($LFS find ! -z +65M $comp_file | wc -l)
1299         [ $found -eq 1 ] ||
1300                 error "component not found by negation of wrong +ext size"
1301
1302         found=$($LFS find ! -z -63M $comp_file | wc -l)
1303         [ $found -eq 1 ] ||
1304                 error "component not found by negation of wrong -ext size"
1305
1306         found=$($LFS find -S +1M $comp_file | wc -l)
1307         [ $found -eq 0 ] || error "component found by wrong +stripe size"
1308
1309         found=$($LFS find -c 1 $comp_file | wc -l)
1310         [ $found -eq 1 ] || error "component not found by stripe count"
1311
1312         small_write $comp_file $rw_len || error "Verify RW failed"
1313
1314         sel_layout_sanity $comp_file 2
1315 }
1316
1317 # Self-extending PFL tests
1318 test_19a() {
1319         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1320         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1321                 skip "skipped for lustre < $SEL_VER"
1322
1323         test19_io_base $DIR/$tdir/$tfile
1324 }
1325 run_test 19a "Simple test of extension behavior"
1326
1327 # Same as 19a, but with default layout set on directory rather than on file
1328 test_19b() {
1329         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1330         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1331                 skip "skipped for lustre < $SEL_VER"
1332
1333         local comp_file=$DIR/$tdir/$tfile
1334         local comp_dir=$DIR/$tdir/$tdir
1335         local flg_opts=""
1336         local found=""
1337
1338         test_mkdir -p $DIR/$tdir
1339         $LFS setstripe --ext-size 64M -c 1 -E -1 $DIR/$tdir ||
1340                 error "Setstripe on $DIR/$tdir failed"
1341
1342         # check inheritance for a sub-dir and a file
1343         test_mkdir $comp_dir
1344         found=$($LFS find --comp-start 0 -E 64M $comp_dir | wc -l)
1345         [ $found -eq 1 ] || error "Dir Inheritance: wrong first component size"
1346
1347         flg_opts="--comp-flags extension"
1348         found=$($LFS find --comp-start 64M -E EOF $flg_opts $comp_dir | wc -l)
1349         [ $found -eq 1 ] || error "Dir Inheritance: Second component not found"
1350
1351         touch $comp_file
1352
1353         flg_opts="--comp-flags init"
1354         found=$($LFS find --comp-start 0 -E 64M $flg_opts $comp_file | wc -l)
1355         [ $found -eq 1 ] || error "File Inheritance: wrong first component size"
1356
1357         flg_opts="--comp-flags extension"
1358         found=$($LFS find --comp-start 64M -E EOF $flg_opts $comp_file | wc -l)
1359         [ $found -eq 1 ] || error "File Inheritance: Second component not found"
1360
1361         test19_io_base $comp_file 1
1362 }
1363 run_test 19b "Simple test of SEL as default layout"
1364
1365 # Test behavior when seeking deep in a file
1366 test_19c() {
1367         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1368         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1369                 skip "skipped for lustre < $SEL_VER"
1370
1371         local comp_file=$DIR/$tdir/$tfile
1372         local flg_opts=""
1373         local found=""
1374
1375         test_mkdir -p $DIR/$tdir
1376
1377         $LFS setstripe -z 128M -E 1G -E -1 $comp_file ||
1378                 error "Create $comp_file failed"
1379
1380         # write past end of first component, so it is extended
1381         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 conv=notrunc ||
1382                 error "dd to extend failed"
1383
1384         flg_opts="--comp-flags init"
1385         found=$($LFS find --comp-start 0M -E 256M $flg_opts $comp_file | wc -l)
1386         [ $found -eq 1 ] || error "Write: first extension component not found"
1387
1388         flg_opts="--comp-flags extension,^init"
1389         found=$($LFS find --comp-start 256M -E 1024M $flg_opts $comp_file |\
1390                 wc -l)
1391         [ $found -eq 1 ] || error "Write: second extension component not found"
1392
1393         local end_1=$($LFS getstripe -I1 -E $comp_file)
1394
1395         # 256 MiB
1396         [ $end_1 -eq 268435456 ] ||
1397                 error "end of first component $end_1 != 268435456"
1398
1399         # Write past end of extension space component, in to normal component
1400         # should exhaust & remove extension component
1401         dd if=/dev/zero bs=1M count=1 seek=1100 of=$comp_file conv=notrunc ||
1402                 error "dd distant seek failed"
1403
1404         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1405         # the last component index is 3
1406         local ost_idx2=$($LFS getstripe -I3 -i $comp_file)
1407
1408         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1409
1410         local start1=$($LFS getstripe -I1 --comp-start $comp_file)
1411         local end1=$($LFS getstripe -I1 -E $comp_file)
1412         local start2=$($LFS getstripe -I3 --comp-start $comp_file)
1413         local end2=$($LFS getstripe -I3 -E $comp_file)
1414
1415         [ $start1 -eq 0 ] || error "start of first component incorrect"
1416         [ $end1 -eq 1073741824 ] || error "end of first component incorrect"
1417         [ $start2 -eq 1073741824  ] ||
1418                 error "start of second component incorrect"
1419         [ "$end2" = "EOF" ] || error "end of second component incorrect"
1420
1421         flg_opts="--comp-flags extension"
1422         found=$($LFS find $flg_opts $comp_file | wc -l)
1423         [ $found -eq 0 ] || error "Seek Write: extension component exists"
1424
1425         sel_layout_sanity $comp_file 2
1426 }
1427 run_test 19c "Test self-extending layout seeking behavior"
1428
1429 test_19d() {
1430         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1431         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1432                 skip "skipped for lustre < $SEL_VER"
1433
1434         local comp_file=$DIR/$tdir/$tfile
1435         local flg_opts=""
1436         local found=""
1437
1438         test_mkdir -p $DIR/$tdir
1439
1440         $LFS setstripe -E 128M -c 1 -z 64M -E -1 $comp_file ||
1441                 error "Create $comp_file failed"
1442
1443         # This will cause component 1 to be extended to 128M, then the
1444         # extension space component will be removed
1445         dd if=/dev/zero of=$comp_file bs=130M count=1 ||
1446                 error "dd to extend failed"
1447
1448         flg_opts="--comp-flags init"
1449         found=$($LFS find --comp-start 0M -E 128M $flg_opts $comp_file | wc -l)
1450         [ $found -eq 1 ] || error "Write: first component not found"
1451
1452         flg_opts="--comp-flags init"
1453         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
1454         [ $found -eq 1 ] || error "Write: second component not found"
1455
1456         sel_layout_sanity $comp_file 2
1457
1458         # always remove large files in case of DO_CLEANUP=false
1459         rm -f $comp_file || error "Delete $comp_file failed"
1460 }
1461 run_test 19d "Test write which completely spans extension space component"
1462
1463 test_19e_check() {
1464         comp_file=$1
1465
1466         local comp2_flags=$($LFS getstripe -I2 --comp-flags $comp_file)
1467         local comp3_flags=$($LFS getstripe -I3 --comp-flags $comp_file)
1468
1469         [ "$comp2_flags" != "init" ] && error "$comp2_flags != init"
1470         [ "$comp3_flags" != "extension" ] && error "$comp3_flags != extension"
1471
1472         local flg_opts=" --comp-start 2M -E 66M --comp-flags init"
1473         local found=$($LFS find $flg_opts $comp_file | wc -l)
1474         [ $found -eq 1 ] || error "Write: extended second component not found"
1475
1476         flg_opts="--comp-start 66M -E EOF --comp-flags extension"
1477         found=$($LFS find $flg_opts $comp_file | wc -l)
1478         [ $found -eq 1 ] || error "Write: third component not found"
1479
1480         sel_layout_sanity $comp_file 3
1481 }
1482
1483 test_19e() {
1484         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1485         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1486                 skip "skipped for lustre < $SEL_VER"
1487
1488         local comp_file=$DIR/$tdir/$tfile
1489         local rw_len=$((3 * 1024 * 1024))       # 3M
1490         local flg_opts=""
1491         local found=""
1492
1493         test_mkdir -p $DIR/$tdir
1494
1495         $LFS setstripe -E 2m -E -1 -z 64M $comp_file ||
1496                 error "Create $comp_file failed"
1497
1498         replay_barrier $SINGLEMDS
1499
1500         #instantiate & extend second component
1501         dd if=/dev/zero of=$comp_file bs=4M count=1 ||
1502                 error "dd to extend failed"
1503
1504         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1505         local ost_idx3=$($LFS getstripe -I3 -i $comp_file)
1506
1507         [ $ost_idx2 -eq $ost_idx3 ] && error "$ost_idx2 == $ost_idx3"
1508         [ $ost_idx3 -ne "-1" ] && error "third component init $ost_idx3"
1509
1510         test_19e_check $comp_file
1511
1512         local f1=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}')
1513         echo "before MDS recovery, the ost fid of 2nd component is $f1"
1514
1515         fail $SINGLEMDS
1516
1517         local f2=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}')
1518         echo "after MDS recovery, the ost fid of 2nd component is $f2"
1519         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
1520
1521         # simply repeat all previous checks, but also verify components are on
1522         # the same OST as before
1523
1524         local ost_idx2_2=$($LFS getstripe -I2 -i $comp_file)
1525         local ost_idx3_2=$($LFS getstripe -I3 -i $comp_file)
1526
1527         [ $ost_idx2_2 -eq $ost_idx3_2 ] && error "$ost_idx2_2 == $ost_idx3_2"
1528         [ $ost_idx3_2 -ne "-1" ] && error "second component init $ost_idx3_2"
1529
1530         # verify OST id is the same after failover
1531         [ $ost_idx2 -ne $ost_idx2_2 ] &&
1532                 error "$ost_idx2 != $ost_idx2_2, changed after failover"
1533
1534         test_19e_check $comp_file
1535 }
1536 run_test 19e "Replay of layout instantiation & extension"
1537
1538 test_19f() {
1539         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1540         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1541                 skip "skipped for lustre < $SEL_VER"
1542
1543         local comp_file=$DIR/$tdir/$tfile
1544         local flg_opts=""
1545         local found=""
1546
1547         test_mkdir -p $DIR/$tdir
1548
1549         $LFS setstripe -E 256M --comp-flags extension -E -1 $comp_file
1550
1551         [ $? != 0 ] || error "should not be able to manually set extension flag"
1552
1553 }
1554 run_test 19f "Rejection of invalid layouts"
1555
1556 test_19g() {
1557         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1558         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1559                 skip "skipped for lustre < $SEL_VER"
1560
1561         local file1=$DIR/${tfile}-1
1562         local file2=$DIR/${tfile}-2
1563
1564         test_mkdir -p $DIR/$tdir
1565         multiop $file1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
1566                 error "create failed $file1"
1567         multiop $file2 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
1568                 error "create failed $file2"
1569
1570         $LFS setstripe --component-add -E 1G -c 1 $file1 ||
1571                 error "comp-add [0,1G] failed $file1"
1572         $LFS setstripe --component-add -E 512M -z 128M $file1 &&
1573                 error "comp-add [1G,1G],SEL[1G,512M] succeded $file1"
1574         $LFS setstripe --component-add -E 10G -z 128M $file1 ||
1575                 error "comp-add [1G,1G],SEL[1G,10G] failed $file1"
1576         $LFS setstripe --component-add -E -1 $file1 ||
1577                 error "comp-add [10G,-1] failed $file1"
1578
1579         $LFS setstripe --component-add -E 1G -z 32M -c 1 $file2 &&
1580                 error "comp-add with smal ext size succeeded $file1"
1581         $LFS setstripe --component-add -E 1G -z 100M -c 1 $file2 &&
1582                 error "comp-add with not aligned ext size succeeded $file1"
1583         $LFS setstripe --component-add -E 1G -z 128M -c 1 $file2 ||
1584                 error "comp-add [0,128M],SEL[128M,1G] failed $file1"
1585         $LFS setstripe --component-add -E 10G $file2 ||
1586                 error "comp-add [1G,10G] failed $file1"
1587         $LFS setstripe --component-add -E -1 -z 128M -c 1 $file2 ||
1588                 error "comp-add [10G,10G],SEL[10G,-1] failed $file1"
1589         $LFS setstripe --component-add -E -1 -z 128M -c 1 $file2 &&
1590                 error "repeated comp-add [10G,10G],SEL[10G,-1] succeeded $file1"
1591
1592         $LFS getstripe $file1
1593         flg_opts="--comp-flags init"
1594         found=$($LFS find --comp-start 0 -E 1G $flg_opts $file1 | wc -l)
1595         [ $found -eq 1 ] || error "First component not found $file1"
1596
1597         flg_opts="--comp-flags ^init"
1598         found=$($LFS find --comp-start 1G -E 1G $flg_opts $file1 | wc -l)
1599         [ $found -eq 1 ] || error "Second component not found $file1"
1600
1601         flg_opts="--comp-flags ^init,extension"
1602         found=$($LFS find --comp-start 1G -E 10G $flg_opts $file1 | wc -l)
1603         [ $found -eq 1 ] || error "Third component not found $file1"
1604
1605         flg_opts="--comp-flags ^init"
1606         found=$($LFS find --comp-start 10G -E EOF $flg_opts $file1 | wc -l)
1607         [ $found -eq 1 ] || error "Fourth component not found $file1"
1608
1609         $LFS getstripe $file2
1610         flg_opts="--comp-flags init"
1611         found=$($LFS find --comp-start 0 -E 128M $flg_opts $file2 | wc -l)
1612         [ $found -eq 1 ] || error "First component not found $file2"
1613
1614         flg_opts="--comp-flags extension"
1615         found=$($LFS find --comp-start 128M -E 1G $flg_opts $file2 | wc -l)
1616         [ $found -eq 1 ] || error "Second component not found $file2"
1617
1618         flg_opts="--comp-flags ^init"
1619         found=$($LFS find --comp-start 1G -E 10G $flg_opts $file2 | wc -l)
1620         [ $found -eq 1 ] || error "Third component not found $file2"
1621
1622         flg_opts="--comp-flags ^init"
1623         found=$($LFS find --comp-start 10G -E 10G $flg_opts $file2 | wc -l)
1624         [ $found -eq 1 ] || error "Fourth component not found $file2"
1625
1626         flg_opts="--comp-flags ^init,extension"
1627         found=$($LFS find --comp-start 10G -E EOF $flg_opts $file2 | wc -l)
1628         [ $found -eq 1 ] || error "Fifth component not found $file2"
1629 }
1630 run_test 19g "component-add behaviour"
1631
1632 # Test out of space behavior
1633 test_20a() {
1634         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1635         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1636                 skip "skipped for lustre < $SEL_VER"
1637
1638         local comp_file=$DIR/$tdir/$tfile
1639         local flg_opts=""
1640         local found=""
1641
1642         test_mkdir -p $DIR/$tdir
1643
1644         # without this, a previous delete can finish after we check free space
1645         wait_delete_completed
1646         wait_mds_ost_sync
1647
1648         # First component is on OST0
1649         $LFS setstripe -E 256M -i 0 -z 64M -E -1 -z 128M $comp_file ||
1650                 error "Create $comp_file failed"
1651
1652         # write past end of first component, so it is extended
1653         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=66 ||
1654                 error "dd to extend failed"
1655
1656         flg_opts="--comp-flags extension"
1657         found=$($LFS find --comp-start 128M -E 256M $flg_opts $comp_file |wc -l)
1658         [ $found -eq 1 ] || error "Write: Second component not found"
1659
1660         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1661         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1662                     grep "watermarks")
1663         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1664
1665         flg_opts="--comp-flags extension"
1666         # Write past current init comp, but we won't extend (because no space)
1667         dd if=/dev/zero of=$comp_file bs=1M count=10 seek=200 ||
1668                 error "dd write past current comp failed"
1669
1670         $LFS getstripe $comp_file
1671
1672         flg_opts="--comp-flags init"
1673         found=$($LFS find --comp-start 128M -E 256M $flg_opts $comp_file | \
1674                 wc -l)
1675         [ $found -eq 1 ] || error "Write: third component not found"
1676
1677         flg_opts="--comp-flags extension"
1678         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file |wc -l)
1679         [ $found -eq 1 ] || error "Write: fourth extension component not found"
1680
1681         sel_layout_sanity $comp_file 3
1682 }
1683 run_test 20a "Test out of space, spillover to defined component"
1684
1685 test_20b() {
1686         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1687         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1688                 skip "skipped for lustre < $SEL_VER"
1689
1690         local comp_file=$DIR/$tdir/$tfile
1691         local flg_opts=""
1692         local found=""
1693
1694         test_mkdir -p $DIR/$tdir
1695
1696         # Pool allows us to force use of only certain OSTs
1697         pool_add $TESTNAME || error "Pool creation failed"
1698         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1699
1700         # normal component to 10M, extendable component to 1G
1701         # further extendable to EOF
1702         $LFS setstripe -E 10M -E 1G -p $TESTNAME -z 64M -E -1 -p "" -z 128M \
1703                 $comp_file || error "Create $comp_file failed"
1704
1705         replay_barrier $SINGLEMDS
1706
1707         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1708         [ $found -eq 1 ] || error "Zero length component not found"
1709
1710         local ost_idx1=0
1711         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1712                     grep "watermarks")
1713         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1714
1715         # write past end of first component
1716         # This should remove the next component, since OST0 is out of space
1717         # and it is striped there (pool contains only OST0)
1718         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=14 ||
1719                 error "dd to extend/remove failed"
1720
1721         $LFS getstripe $comp_file
1722
1723         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1724         [ $found -eq 0 ] || error "Write: zero length component still present"
1725
1726         flg_opts="--comp-flags init"
1727         found=$($LFS find --comp-start 10M -E 138M $flg_opts $comp_file | wc -l)
1728         [ $found -eq 1 ] || error "Write: second component not found"
1729
1730         flg_opts="--comp-flags extension"
1731         found=$($LFS find --comp-start 138M -E EOF $flg_opts $comp_file | wc -l)
1732         [ $found -eq 1 ] || error "Write: third component not found"
1733
1734         fail $SINGLEMDS
1735
1736         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1737         [ $found -eq 0 ] || error "Failover: 0-length component still present"
1738
1739         flg_opts="--comp-flags init"
1740         found=$($LFS find --comp-start 10M -E 138M $flg_opts $comp_file | wc -l)
1741         [ $found -eq 1 ] || error "Failover: second component not found"
1742
1743         flg_opts="--comp-flags extension"
1744         found=$($LFS find --comp-start 138M -E EOF $flg_opts $comp_file | wc -l)
1745         [ $found -eq 1 ] || error "Failover: third component not found"
1746
1747         sel_layout_sanity $comp_file 3
1748 }
1749 run_test 20b "Remove component without instantiation when there is no space"
1750
1751 test_20c() {
1752         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1753         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1754                 skip "skipped for lustre < $SEL_VER"
1755
1756         local comp_file=$DIR/$tdir/$tfile
1757         local flg_opts=""
1758         local found=""
1759
1760         test_mkdir -p $DIR/$tdir
1761
1762         # pool is used to limit available OSTs to 0 and 1, so we can set all
1763         # available OSTs out of space
1764         pool_add $TESTNAME || error "Pool creation failed"
1765         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
1766
1767         # without this, a previous delete can finish after we check free space
1768         wait_delete_completed
1769         wait_mds_ost_sync
1770
1771         $LFS setstripe -E 100M -E -1 -p $TESTNAME -z 64M $comp_file ||
1772                 error "Create $comp_file failed"
1773
1774         local ost_idx1=0
1775         local ost_idx2=1
1776         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1777                     grep "watermarks")
1778         local wms2=$(ost_watermarks_set_enospc $tfile $ost_idx2 |
1779                      grep "watermarks")
1780         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1781         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx2 $wms2" EXIT
1782
1783         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=120 &&
1784                 error "dd should fail with ENOSPC"
1785
1786         flg_opts="--comp-flags init"
1787         found=$($LFS find --comp-start 0M -E 100M $flg_opts $comp_file | wc -l)
1788         [ $found -eq 1 ] || error "Write: First component not found"
1789
1790         flg_opts="--comp-flags ^init"
1791         found=$($LFS find --comp-start 100M -E 100M $flg_opts $comp_file |wc -l)
1792         [ $found -eq 1 ] || error "Write: 0-length component not found"
1793
1794         flg_opts="--comp-flags extension"
1795         found=$($LFS find --comp-start 100M -E EOF $flg_opts $comp_file | wc -l)
1796         [ $found -eq 1 ] || error "Write: third extension component not found"
1797
1798         sel_layout_sanity $comp_file 3
1799 }
1800 run_test 20c "Test inability to stripe new extension component"
1801
1802 test_20d() {
1803         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1804         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1805                 skip "skipped for lustre < $SEL_VER"
1806
1807         local comp_file=$DIR/$tdir/$tfile
1808         test_mkdir -p $DIR/$tdir
1809
1810         wait_delete_completed
1811         wait_mds_ost_sync
1812
1813         pool_add $TESTNAME || error "Pool creation failed"
1814         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1815         $LFS setstripe -E 64m -E -1 -p $TESTNAME -z 64M $comp_file ||
1816                 error "Create $comp_file failed"
1817
1818         replay_barrier $SINGLEMDS
1819
1820         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
1821         dd if=/dev/zero bs=1M count=1 seek=100 of=$comp_file
1822         RC=$?
1823
1824         ost_watermarks_clear_enospc $tfile 0 $wms
1825         [ $RC -eq 0 ] || error "dd failed: $RC"
1826
1827         $LFS getstripe $comp_file
1828         local flg_opts="--comp-start 64M -E 128M --comp-flags init"
1829         local found=$($LFS find $flg_opts $comp_file | wc -l)
1830         [ $found -eq 1 ] || error "Write: component (64M-128M) not found"
1831
1832         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
1833         [ "$ost_idx" != "-1" ] && error "Write: EXT component disappeared"
1834
1835         fail $SINGLEMDS
1836
1837         found=$($LFS find $flg_opts $comp_file | wc -l)
1838         [ $found -eq 1 ] || error "Failover: component (64M-128M) not found"
1839
1840         ost_idx=$($LFS getstripe -I3 -i $comp_file)
1841         [ "$ost_idx" != "-1" ] && error "Failover: EXT component disappeared"
1842
1843         sel_layout_sanity $comp_file 3
1844 }
1845 run_test 20d "Low on space + 0-length comp: force extension"
1846
1847 test_20e() {
1848         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1849         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1850                 skip "skipped for lustre < $SEL_VER"
1851
1852         local comp_file=$DIR/$tdir/$tfile
1853         test_mkdir -p $DIR/$tdir
1854
1855         wait_delete_completed
1856         wait_mds_ost_sync
1857
1858         pool_add $TESTNAME || error "Pool creation failed"
1859         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1860
1861         $LFS setstripe -E 64m -E 640M -z 64M -p $TESTNAME -E -1 $comp_file ||
1862                 error "Create $comp_file failed"
1863
1864         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
1865
1866         dd if=/dev/zero bs=1M count=1 seek=100 of=$comp_file
1867         RC=$?
1868
1869         ost_watermarks_clear_enospc $tfile 0 $wms
1870         [ $RC -eq 0 ] || error "dd failed $RC"
1871
1872         $LFS getstripe $comp_file
1873         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
1874         local found=$($LFS find $flg_opts $comp_file | wc -l)
1875         [ $found -eq 1 ] || error "Write: component (64M-EOF) not found"
1876
1877         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
1878         [ "$ost_idx" != "" ] && error "Write: 0-length component still exists"
1879         ost_idx=$($LFS getstripe -I3 -i $comp_file)
1880         [ "$ost_idx" != "" ] && error "Write: extension component still exists"
1881
1882         sel_layout_sanity $comp_file 2
1883 }
1884 run_test 20e "ENOSPC with next real comp: spillover and backward extension"
1885
1886 # Simple DoM interaction test
1887 test_21a() {
1888         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1889                 skip "skipped for lustre < $SEL_VER"
1890
1891         local comp_file=$DIR/$tdir/$tfile
1892         local flg_opts=""
1893         local found=""
1894
1895         test_mkdir -p $DIR/$tdir
1896
1897         # simple, correct self-extending layout after DoM component
1898         $LFS setstripe -E 1M -L mdt -E -1 -z 64m $comp_file || \
1899                 error "Create $comp_file failed"
1900
1901         # Write to DoM component & to self-extending comp after it
1902         dd if=/dev/zero bs=1M count=12 of=$comp_file ||
1903                 error "dd to extend failed"
1904
1905         flg_opts="--comp-flags init"
1906         found=$($LFS find --comp-start 1M -E 65M $flg_opts $comp_file | wc -l)
1907         [ $found -eq 1 ] || error "Write: extended component not found"
1908
1909         flg_opts="--comp-flags extension"
1910         found=$($LFS find --comp-start 65M $flg_opts $comp_file | wc -l)
1911         [ $found -eq 1 ] || error "Write: extension component not found"
1912
1913         sel_layout_sanity $comp_file 3
1914 }
1915 run_test 21a "Simple DoM interaction tests"
1916
1917 # DoM + extension + removal
1918 test_21b() {
1919         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1920         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1921                 skip "skipped for lustre < $SEL_VER"
1922
1923         local comp_file=$DIR/$tdir/$tfile
1924         local ost_name=$(ostname_from_index 0)
1925         local flg_opts=""
1926         local found=""
1927
1928         test_mkdir -p $DIR/$tdir
1929
1930         # DoM, extendable component, further extendable component
1931         $LFS setstripe -E 1M -L mdt -E 256M -i 0 -z 64M -E -1 -z 128M \
1932                 $comp_file || error "Create $comp_file failed"
1933
1934         found=$($LFS find --comp-start 1M -E 1M $flg_opts $comp_file | wc -l)
1935         [ $found -eq 1 ] || error "Write: Zero length component not found"
1936
1937         # This also demonstrates that we will avoid degraded OSTs
1938         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
1939         # sleep to guarantee we see the degradation
1940         sleep_maxage
1941
1942         # un-degrade on exit
1943         stack_trap "do_facet ost1 $LCTL set_param -n \
1944                 obdfilter.$ost_name.degraded=0; sleep_maxage" EXIT
1945
1946         # This should remove the first component after DoM and spill over to
1947         # the next one
1948         dd if=/dev/zero bs=1M count=2 of=$comp_file ||
1949                 error "dd to remove+spill over failed"
1950
1951         found=$($LFS find --comp-start 1M -E 1M $flg_opts $comp_file | wc -l)
1952         [ $found -eq 0 ] || error "Write: Zero length component still present"
1953
1954         flg_opts="--comp-flags init"
1955         found=$($LFS find --comp-start 1M -E 129M $flg_opts $comp_file | wc -l)
1956         [ $found -eq 1 ] || error "Write: extended component not found"
1957
1958         flg_opts="--comp-flags extension"
1959         found=$($LFS find --comp-start 129M -E EOF $flg_opts $comp_file |wc -l)
1960         [ $found -eq 1 ] || error "Write: extension component not found"
1961
1962         sel_layout_sanity $comp_file 3
1963 }
1964 run_test 21b "DoM followed by extendable component with removal"
1965
1966 # Test of repeat component behavior with OOS/degraded OST
1967 test_22a() {
1968         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1969         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1970                 skip "skipped for lustre < $SEL_VER"
1971
1972         local comp_file=$DIR/$tdir/$tfile
1973         local flg_opts=""
1974         local found=""
1975
1976         test_mkdir -p $DIR/$tdir
1977
1978         $LFS setstripe -E -1 -c 1 -z 128M $comp_file ||
1979                 error "Create $comp_file failed"
1980
1981         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1982         local ost_name=$(ostname_from_index $ost_idx1)
1983
1984         # write past end of first component, so it is extended
1985         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 ||
1986                 error "dd to extend failed"
1987
1988         flg_opts="--comp-flags extension"
1989         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file | wc -l)
1990         [ $found -eq 1 ] || error "Write: second component not found"
1991
1992         # degrade OST for component 1
1993         do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
1994                 obdfilter.$ost_name.degraded=1
1995         # sleep to guarantee we see the degradation
1996         sleep_maxage
1997
1998         # un-degrade on exit
1999         stack_trap "do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
2000                 obdfilter.$ost_name.degraded=0; sleep_maxage" EXIT
2001
2002         replay_barrier $SINGLEMDS
2003
2004         # seek past the end of current comp & write, should cause a new comp
2005         # to be created (ie repeat previous comp)
2006         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 ||
2007                 error "dd to repeat failed"
2008
2009         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
2010
2011         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
2012
2013         flg_opts="--comp-flags init"
2014         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2015         [ $found -eq 1 ] || error "Write: second component not found"
2016
2017         flg_opts="--comp-flags extension"
2018         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
2019         [ $found -eq 1 ] || error "Write: extension component not found"
2020
2021         fail $SINGLEMDS
2022
2023         local ost_idx2_2=$($LFS getstripe -I2 -i $comp_file)
2024         [ $ost_idx2_2 -ne $ost_idx2 ] && error "$ost_idx2_2 != $ost_idx2"
2025
2026         flg_opts="--comp-flags init"
2027         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2028         [ $found -eq 1 ] || error "Failover: second component not found"
2029
2030         flg_opts="--comp-flags extension"
2031         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
2032         [ $found -eq 1 ] || error "Failover: extension component not found"
2033
2034         sel_layout_sanity $comp_file 3
2035 }
2036 run_test 22a "Test repeat component behavior with degraded OST"
2037
2038 # Test repeat behavior with low space
2039 test_22b() {
2040         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2041         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2042                 skip "skipped for lustre < $SEL_VER"
2043
2044         local comp_file=$DIR/$tdir/$tfile
2045         local flg_opts=""
2046         local found=""
2047
2048         test_mkdir -p $DIR/$tdir
2049
2050         # without this, a previous delete can finish after we check free space
2051         wait_delete_completed
2052         wait_mds_ost_sync
2053
2054         $LFS setstripe -E -1 -c 1 -z 128M \
2055                 $comp_file || error "Create $comp_file failed"
2056
2057         # write past end of first component, so it is extended
2058         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 ||
2059                 error "dd to extend failed"
2060
2061         flg_opts="--comp-flags extension"
2062         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file | wc -l)
2063         [ $found -eq 1 ] || error "Write: Second component not found"
2064
2065         # set our OST low on space
2066         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
2067         local wms=$(ost_watermarks_set_low_space $ost_idx1 | grep "watermarks")
2068
2069         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
2070
2071         # Write past end of current space, fail to extend, causing repeat
2072         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 ||
2073                 error "dd to repeat failed"
2074
2075         $LFS getstripe $comp_file
2076
2077         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
2078
2079         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
2080
2081         flg_opts="--comp-flags init"
2082         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2083         [ $found -eq 1 ] || error "Write: Second component not found"
2084
2085         flg_opts="--comp-flags extension"
2086         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
2087         [ $found -eq 1 ] || error "Write: Extension component not found"
2088
2089         sel_layout_sanity $comp_file 3
2090 }
2091 run_test 22b "Test simple 'out of space' condition with repeat"
2092
2093 # This tests both "repeat" and "extend in place when repeat fails" aspects
2094 # of repeating components
2095 test_22c() {
2096         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2097         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2098                 skip "skipped for lustre < $SEL_VER"
2099
2100         local comp_file=$DIR/$tdir/$tfile
2101         local flg_opts=""
2102         local found=""
2103
2104         test_mkdir -p $DIR/$tdir
2105
2106         # pool is used to limit available OSTs to 0 and 1, so we can set all
2107         # available OSTs out of space
2108         pool_add $TESTNAME || error "Pool creation failed"
2109         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
2110
2111         # without this, a previous delete can finish after we check free space
2112         wait_delete_completed
2113         wait_mds_ost_sync
2114
2115         $LFS setstripe -E -1 -z 64M -c 1 -p "$TESTNAME" $comp_file || \
2116                 error "Create $comp_file failed"
2117
2118         # write past end of first component, so it is extended
2119         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=80 conv=notrunc ||
2120                 error "dd to extend failed"
2121
2122         $LFS getstripe $comp_file
2123
2124         flg_opts="--comp-flags extension"
2125         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
2126         [ $found -eq 1 ] || error "Write: second component not found"
2127
2128         # set our OST out of space
2129         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
2130         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
2131                     grep "watermarks")
2132         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
2133
2134         # This should create a repeat component on a new OST
2135         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=180 conv=notrunc ||
2136                 error "dd to repeat failed"
2137
2138         $LFS getstripe $comp_file
2139
2140         local comp_cnt=$($LFS getstripe --component-count $comp_file)
2141         [ $comp_cnt -ne 3 ] && error "component count: $comp_cnt, should be 3"
2142
2143         # New second component should be on a different OST
2144         local ost_idx2=$($LFS getstripe --comp-start=128m \
2145                          --comp-end=192m --comp-flags=init -i $comp_file)
2146
2147         [ $ost_idx1 -eq $ost_idx2 ] && error "2nd comp: same OST $ost_idx1"
2148
2149         local wms2=$(ost_watermarks_set_enospc $tfile $ost_idx2 |
2150                      grep "watermarks")
2151         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx2 $wms2" EXIT
2152
2153         # now that the second OST is out of space (as is the first OST), we
2154         # attempt to extend.  This should result in an extension of the
2155         # existing component, rather than a new component.
2156         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=240 conv=notrunc ||
2157                 error "dd for forced extension failed"
2158
2159         $LFS getstripe $comp_file
2160
2161         # clear out of space on first OST
2162         ost_watermarks_clear_enospc $tfile $ost_idx1 $wms
2163
2164         # finally, now that the first OST has space again, we attempt to
2165         # extend one last time.  This should create a new component on the
2166         # first OST
2167         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 conv=notrunc ||
2168                 error "dd for repeat on first OST failed"
2169
2170         $LFS getstripe $comp_file
2171
2172         flg_opts="--comp-flags init"
2173         found=$($LFS find --comp-start 128M $flg_opts $comp_file | wc -l)
2174         [ $found -eq 1 ] || error "Write: second component not found"
2175
2176         flg_opts="--comp-flags init"
2177         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2178         [ $found -eq 1 ] || error "Write: third component not found"
2179
2180         flg_opts="--comp-flags extension"
2181         found=$($LFS find --comp-start 320M -E EOF $flg_opts $comp_file | wc -l)
2182         [ $found -eq 1 ] || error "Write: extension component not found"
2183
2184         sel_layout_sanity $comp_file 4
2185 }
2186 run_test 22c "Test repeat with out of space on > 1 OST"
2187
2188 test_22d_post_check() {
2189         local comp_file=$1
2190         local name=$2
2191         local flg_opts="--comp-flags init"
2192         local found=$($LFS find --comp-start 0M -E 128M $flg_opts $comp_file |
2193                       wc -l)
2194         [ $found -eq 1 ] || {
2195                 $LFS getstripe $comp_file
2196                 error "$name: second component not found"
2197         }
2198
2199         flg_opts="--comp-flags extension"
2200         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
2201         [ $found -eq 1 ] || error "$name: third extension component not found"
2202
2203         sel_layout_sanity $comp_file 2
2204 }
2205
2206 test_22d_pre() {
2207         local comp_file=$1
2208         local wms="$2"
2209         local RC
2210
2211         # write past end of first component
2212         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=70
2213         RC=$?
2214
2215         ost_watermarks_clear_enospc $tfile 0 $wms
2216         [ $RC -eq 0 ] || error "dd to force extend failed"
2217
2218         test_22d_post_check $comp_file "Write"
2219 }
2220
2221 test_22d() {
2222         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2223         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2224                 skip "skipped for lustre < $SEL_VER"
2225
2226         local comp_file=$DIR/$tdir/$tfile
2227         local flg_opts=""
2228         local found=""
2229
2230         test_mkdir -p $DIR/$tdir
2231
2232         # without this, a previous delete can finish after we check free space
2233         wait_delete_completed
2234         wait_mds_ost_sync
2235
2236         # Pool allows us to force use of only certain OSTs
2237         pool_add $TESTNAME || error "Pool creation failed"
2238         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2239
2240         # 1. Fail to extend due to OOS, try to repeat within the same pool,
2241         # fail to stripe (again OOS) the 0-length component, remove the
2242         # repeated one, force the extension on the original one.
2243         $LFS setstripe -E -1 -p $TESTNAME -z 64M $comp_file ||
2244                 error "Create $comp_file failed"
2245
2246         replay_barrier $SINGLEMDS
2247
2248         # set our OST out of space
2249         local wms=$(ost_watermarks_set_enospc $tfile 0 | grep "watermarks")
2250
2251         test_22d_pre $comp_file "$wms"
2252         fail $SINGLEMDS
2253         test_22d_post_check $comp_file "Failover"
2254
2255         # 2. repeat with low on space: 0-length repeated component will be
2256         # striped, but still fails to be extended; otherwise the same as (1).
2257         rm -f $comp_file
2258         $LFS setstripe -E -1 -p $TESTNAME -z 64M $comp_file ||
2259                 error "Create $comp_file failed"
2260
2261         replay_barrier $SINGLEMDS
2262
2263         # set our OST low on space
2264         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2265
2266         test_22d_pre $comp_file "$wms"
2267         fail $SINGLEMDS
2268         test_22d_post_check $comp_file "Failover"
2269 }
2270 run_test 22d "out of/low on space + failed to repeat + forced extension"
2271
2272 test_23a() {
2273         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2274         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2275                 skip "skipped for lustre < $SEL_VER"
2276
2277         local comp_file=$DIR/$tdir/$tfile
2278         test_mkdir -p $DIR/$tdir
2279
2280         $LFS setstripe -z 64M -c 1 -E -1 $comp_file ||
2281                 error "Create $comp_file failed"
2282
2283         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2284                 error "dd append failed"
2285
2286         local flg_opts="--comp-start 0 -E EOF --comp-flags init"
2287         local found=$($LFS find $flg_opts $comp_file | wc -l)
2288         [ $found -eq 1 ] || error "Append: first component (0-EOF) not found"
2289
2290         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
2291         [ "$ost_idx" != "" ] && error "Append: second component still exists"
2292
2293         sel_layout_sanity $comp_file 1
2294 }
2295 run_test 23a "Append: remove EXT comp"
2296
2297 test_23b() {
2298         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2299         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2300                 skip "skipped for lustre < $SEL_VER"
2301
2302         local comp_file=$DIR/$tdir/$tfile
2303         test_mkdir -p $DIR/$tdir
2304
2305         $LFS setstripe -E 64m -E -1 -z 64M $comp_file ||
2306                 error "Create $comp_file failed"
2307
2308         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2309                 error "dd append failed"
2310
2311         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2312         local found=$($LFS find $flg_opts $comp_file | wc -l)
2313         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2314
2315         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
2316         [ "$ost_idx" != "" ] && error "Append: third component still exists"
2317
2318         sel_layout_sanity $comp_file 2
2319 }
2320 run_test 23b "Append with 0-length comp: remove EXT comp"
2321
2322 test_23c() {
2323         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2324         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2325                 skip "skipped for lustre < $SEL_VER"
2326
2327         local comp_file=$DIR/$tdir/$tfile
2328         test_mkdir -p $DIR/$tdir
2329
2330         wait_delete_completed
2331         wait_mds_ost_sync
2332
2333         pool_add $TESTNAME || error "Pool creation failed"
2334         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2335         $LFS setstripe -E 64m -E -1 -p $TESTNAME -z 64M $comp_file ||
2336                 error "Create $comp_file failed"
2337
2338         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2339         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2340         RC=$?
2341
2342         ost_watermarks_clear_enospc $tfile 0 $wms
2343         [ $RC -eq 0 ] || error "dd append failed: $RC"
2344
2345         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2346         local found=$($LFS find $flg_opts $comp_file | wc -l)
2347         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2348
2349         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
2350         [ "$ost_idx" != "" ] && error "Append: EXT component still exists"
2351
2352         sel_layout_sanity $comp_file 2
2353 }
2354 run_test 23c "Append with low on space + 0-length comp: force extension"
2355
2356 test_23d() {
2357         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2358         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2359                 skip "skipped for lustre < $SEL_VER"
2360
2361         local comp_file=$DIR/$tdir/$tfile
2362         test_mkdir -p $DIR/$tdir
2363
2364         $LFS setstripe -E 64m -E 640M -z 64M -E -1 $comp_file ||
2365                 error "Create $comp_file failed"
2366
2367         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2368                 error "dd append failed"
2369
2370         flg_opts="--comp-start 64M -E 640M --comp-flags init"
2371         found=$($LFS find $flg_opts $comp_file | wc -l)
2372         [ $found -eq 1 ] || error "Append: component (64M-640M) not found"
2373
2374         ost_idx=$($LFS getstripe -I3 -i $comp_file)
2375         [ "$ost_idx" != "" ] && error "Append: third component still exists"
2376
2377         sel_layout_sanity $comp_file 3
2378 }
2379 run_test 23d "Append with 0-length comp + next real comp: remove EXT comp"
2380
2381 test_23e() {
2382         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2383         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2384                 skip "skipped for lustre < $SEL_VER"
2385
2386         local comp_file=$DIR/$tdir/$tfile
2387         test_mkdir -p $DIR/$tdir
2388
2389         wait_delete_completed
2390         wait_mds_ost_sync
2391
2392         pool_add $TESTNAME || error "Pool creation failed"
2393         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2394
2395         $LFS setstripe -E 64m -E 640M -z 64M -p $TESTNAME -E -1 $comp_file ||
2396                 error "Create $comp_file failed"
2397
2398         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2399
2400         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2401         RC=$?
2402
2403         ost_watermarks_clear_enospc $tfile 0 $wms
2404         [ $RC -eq 0 ] || error "dd append failed $RC"
2405
2406         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2407         local found=$($LFS find $flg_opts $comp_file | wc -l)
2408         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2409
2410         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
2411         [ "$ost_idx" != "" ] && error "Append: 0-length component still exists"
2412         ost_idx=$($LFS getstripe -I3 -i $comp_file)
2413         [ "$ost_idx" != "" ] && error "Append: extension component still exists"
2414
2415         sel_layout_sanity $comp_file 2
2416 }
2417 run_test 23e "Append with next real comp: spillover and backward extension"
2418
2419 test_23f() {
2420         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2421         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2422                 skip "skipped for lustre < $SEL_VER"
2423
2424         local comp_file=$DIR/$tdir/$tfile
2425         test_mkdir -p $DIR/$tdir
2426
2427         $LFS setstripe -z 64M -c 1 -E -1 $comp_file ||
2428                 error "Create $comp_file failed"
2429
2430         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
2431         local wms=$(ost_watermarks_set_low_space $ost_idx | grep "watermarks")
2432
2433         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2434         RC=$?
2435
2436         ost_watermarks_clear_enospc $tfile $ost_idx $wms
2437         [ $RC -eq 0 ] || error "dd append failed"
2438
2439         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2440         local found=$($LFS find $flg_opts $comp_file | wc -l)
2441         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2442
2443         ost_idx=$($LFS getstripe -I2 -i $comp_file)
2444         [ "$ost_idx" != "" ] && error "Append: extension component still exists"
2445
2446         sel_layout_sanity $comp_file 2
2447 }
2448 run_test 23f "Append with low on space: repeat and remove EXT comp"
2449
2450 OLDIFS="$IFS"
2451 cleanup_24() {
2452         trap 0
2453         IFS="$OLDIFS"
2454 }
2455
2456 test_24a() {
2457         [ "$OSTCOUNT" -lt "3" ] && skip_env "needs >= 3 OSTs"
2458
2459         trap cleanup_24 EXIT RETURN
2460
2461         local file=$DIR/$tfile
2462
2463         $LFS setstripe -E 1m -c1 -o0 -E eof -c2 -o1,2 $file ||
2464                 error "setstripe on $file"
2465
2466         dd if=/dev/zero of=$file bs=1M count=3 || error "dd failed for $file"
2467         sync
2468
2469         filefrag -ves $file || error "filefrag $file failed"
2470         filefrag_op=$(filefrag -ve -k $file |
2471                       sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2472
2473 #Filesystem type is: bd00bd0
2474 #File size of /mnt/lustre/f24a.sanity-pfl is 3145728 (3072 blocks of 1024 bytes)
2475 # ext:     device_logical:        physical_offset: length:  dev: flags:
2476 #   0:        0..    1023:    1572864..   1573887:   1024: 0000: net
2477 #   1:        0..    1023:    1572864..   1573887:   1024: 0002: net
2478 #   2:     1024..    2047:    1573888..   1574911:   1024: 0001: last,net
2479 #/mnt/lustre/f24a.sanity-pfl: 3 extents found
2480
2481         last_lun=$(echo $filefrag_op | cut -d: -f5)
2482
2483         IFS=$'\n'
2484         tot_len=0
2485         num_luns=1
2486         for line in $filefrag_op; do
2487                 frag_lun=$(echo $line | cut -d: -f5)
2488                 ext_len=$(echo $line | cut -d: -f4)
2489                 if [[ "$frag_lun" != "$last_lun" ]]; then
2490                         if (( tot_len != 1024 )); then
2491                                 cleanup_24
2492                                 error "$file: OST$last_lun $tot_len != 1024"
2493                         else
2494                                 (( num_luns += 1 ))
2495                                 tot_len=0
2496                         fi
2497                 fi
2498                 (( tot_len += ext_len ))
2499                 last_lun=$frag_lun
2500         done
2501         if (( num_luns != 3 || tot_len != 1024 )); then
2502                 cleanup_24
2503                 error "$file: $num_luns != 3, $tot_len != 1024 on OST$last_lun"
2504         fi
2505
2506         echo "FIEMAP on $file succeeded"
2507 }
2508 run_test 24a "FIEMAP upon PFL file"
2509
2510 test_25() {
2511         local pfl_f=$DIR/$tdir/"$tfile"_pfl
2512         local dom_f=$DIR/$tdir/"$tfile"_dom
2513         local common_f=$DIR/$tdir/"$tfile"_common
2514         local stripe_count
2515         local stripe_size
2516
2517         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2518         $LFS setstripe -E 10M -S 64k -c -1 -E 20M -S 1M -E -1 -S 2M -c 1 \
2519                 $pfl_f || error "setstripe $pfl_f failed"
2520         $LFS setstripe -E 256k -L mdt -E -1 -S 1M $dom_f ||
2521                 error "setstripe $dom_f failed"
2522         $LFS setstripe -S 512K -c -1 $common_f ||
2523                 error "setstripe $common_f failed"
2524
2525         #verify lov_getstripe_old with PFL file
2526         stripe_count=$(lov_getstripe_old $pfl_f |
2527                         awk '/stripe_count/ { print $2 }')
2528         stripe_size=$(lov_getstripe_old $pfl_f |
2529                         awk '/stripe_size/ { print $2 }')
2530         [ $stripe_count -eq 1 ] ||
2531                 error "stripe_count $stripe_count !=1 for $pfl_f"
2532         [ $stripe_size -eq 2097152 ] ||
2533                 error "stripe_size $stripe_size != 2097152 for $pfl_f"
2534
2535         #verify lov_getstripe_old with DoM file
2536         stripe_count=$(lov_getstripe_old $dom_f |
2537                         awk '/stripe_count/ { print $2 }')
2538         stripe_size=$(lov_getstripe_old $dom_f |
2539                         awk '/stripe_size/ { print $2 }')
2540         [ $stripe_count -eq 1 ] ||
2541                 error "stripe_count $stripe_count !=1 for $dom_f"
2542         [ $stripe_size -eq 1048576 ] ||
2543                 error "stripe_size $stripe_size != 1048576 for $dom_f"
2544
2545         #verify lov_getstripe_old with common file
2546         stripe_count=$(lov_getstripe_old $common_f |
2547                         awk '/stripe_count/ { print $2 }')
2548         stripe_size=$(lov_getstripe_old $common_f |
2549                         awk '/stripe_size/ { print $2 }')
2550         [ $stripe_count -eq $OSTCOUNT ] ||
2551                 error "stripe_count $stripe_count !=$OSTCOUNT for $common_f"
2552         [ $stripe_size -eq 524288 ] ||
2553                 error "stripe_size $stripe_size != 524288 for $common_f"
2554 }
2555 run_test 25 "Verify old lov stripe API with PFL files"
2556
2557 test_26a() {
2558         $LFS setstripe -E 1m -S 1M -c 1 $DIR/$tfile
2559         dd if=/dev/urandom bs=1M count=10 >> $DIR/$tfile
2560         [ $? != 0 ] || error "append must return an error"
2561 }
2562 run_test 26a "Append to not-existent component"
2563
2564 test_26b() {
2565         $LFS setstripe -E 1m -S 1M -c 1 $DIR/$tfile
2566         dd if=/dev/urandom bs=1M count=1 > $DIR/$tfile
2567         dd if=/dev/urandom bs=1M count=1 >> $DIR/$tfile
2568         [ $? != 0 ] || error "append must return an error"
2569 }
2570 run_test 26b "Append to not-existend component, file size is unknown"
2571
2572 test_26c() {
2573         $LFS setstripe -E 1m -S 1M -c 1 $DIR/$tfile
2574         dd if=/dev/urandom bs=2M count=1 >> $DIR/$tfile
2575         [ $? != 0 ] || error "append must return an error"
2576 }
2577 run_test 26c "Append to not-existend component, crossing the component border"
2578
2579 test_27() {
2580         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2581                 skip "server does not support overstriping"
2582         (( $MDS1_VERSION >= $(version_code 2.15.55.102) )) ||
2583                 skip "need MDS >= 2.12.55.102 for mdt_dump_lmm fix"
2584
2585         stack_trap "rm -f $DIR/$tfile"
2586         # start_full_debug_logging
2587         $LFS setstripe -S 64K -C -1 $DIR/$tfile || error "create $tfile failed"
2588         $LFS getstripe -c $DIR/$tfile || error "getstripe $tfile failed"
2589         cancel_lru_locks
2590         $LFS getstripe -c $DIR/$tfile || error "getstripe failed after clear"
2591
2592         test_mkdir $DIR/$tdir
2593         stack_trap "rm -rf $DIR/$tdir/$tfile"
2594         $LFS setstripe -S 64K -C -1 $DIR/$tdir || error "mkdir $tdir failed"
2595         $LFS getstripe -y $DIR/$tdir || error "getstripe $tdir failed"
2596         touch $DIR/$tdir/$tfile || error "create $tdir/$tfile failed"
2597         cancel_lru_locks
2598         $LFS getstripe -c $DIR/$tdir/$tfile ||
2599                 error "getstripe $tdir/$tfile failed"
2600         #stop_full_debug_logging
2601 }
2602 run_test 27 "overstriping with -C -1 in mdt_dump_lmm"
2603
2604 complete_test $SECONDS
2605 check_and_cleanup_lustre
2606 exit_status