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