Whamcloud - gitweb
LU-14296 lnet: use an unbound cred in kiblnd_resolve_addr()
[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_11() {
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 11 "Verify component instantiation with write/truncate"
611
612 test_12() {
613         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs"
614
615         local file=$DIR/$tdir/$tfile
616         test_mkdir $DIR/$tdir
617         rm -f $file
618
619         # specify ost list for component
620         $LFS setstripe -E 1M -S 1M -c 2 -o 0,1 -E 2M -c 2 -o 1,2 \
621                 -E 3M -c 2 -o 2,1 -E 4M -c 1 -i 2 -E -1 $file ||
622                 error "Create $file failed"
623
624         # clear lod component cache
625         stop $SINGLEMDS || error "stop MDS"
626         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
627         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
628
629         # instantiate all components
630         $TRUNCATE $file $((1024*1024*4+1))
631
632         #verify object alloc order
633         local o1=$($LFS getstripe -I1 $file |
634                         awk '/l_ost_idx:/ {printf("%d",$5)}')
635         [[ $o1 != "01" ]] && error "$o1 is not 01"
636
637         local o2=$($LFS getstripe -I2 $file |
638                         awk '/l_ost_idx:/ {printf("%d",$5)}')
639         [[ $o2 != "12" ]] && error "$o2 is not 12"
640
641         local o3=$($LFS getstripe -I3 $file |
642                         awk '/l_ost_idx:/ {printf("%d",$5)}')
643         [[ $o3 != "21" ]] && error "$o3 is not 21"
644
645         local o4=$($LFS getstripe -I4 $file |
646                         awk '/l_ost_idx:/ {printf("%d",$5)}')
647         [[ $o4 != "2" ]] && error "$o4 is not 2"
648
649         return 0
650 }
651 run_test 12 "Verify ost list specification"
652
653 test_13() { # LU-9311
654         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs"
655
656         local file=$DIR/$tfile
657         local dd_count=4
658         local dd_size=$(($dd_count * 1024 * 1024))
659         local real_size
660
661         rm -f $file
662         $LFS setstripe -E 1M -S 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
663                 error "Create $file failed"
664         dd if=/dev/zero of=$file bs=1M count=$dd_count
665         real_size=$(stat -c %s $file)
666         [ $real_size -eq $dd_size ] ||
667                 error "dd actually wrote $real_size != $dd_size bytes"
668
669         rm -f $file
670 }
671 run_test 13 "shouldn't reprocess granted resent request"
672
673 test_14() {
674         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
675         local file=$DIR/$tdir/$tfile
676         test_mkdir -p $DIR/$tdir
677         rm -f $file
678
679         $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
680                         -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
681                 error "Create $file failed"
682
683         # check --pool inheritance
684         local pool
685         pool="$($LFS getstripe -I2 --pool $file)"
686         [ x"$pool" != "xpool1" ] && $LFS getstripe -I2 $file &&
687                 error "$file: component 2 doesn't have poolname pool1"
688         pool="$($LFS getstripe -I4 --pool $file)"
689         [ x"$pool" != "xpool2" ] && $LFS getstripe -I4 $file &&
690                 error "$file: component 4 doesn't have poolname pool2"
691
692         #check --stripe-count inheritance
693         local count
694         count="$($LFS getstripe -I2 -c $file)"
695         [ $count -ne 1 ] && $LFS getstripe -I2 $file &&
696                 error "$file: component 2 doesn't have 1 stripe_count"
697         count="$($LFS getstripe -I4 -c $file)"
698         [ $count -ne 2 ] && $LFS getstripe -I4 $file &&
699                 error "$file: component 4 doesn't have 2 stripe_count"
700
701         #check --stripe-size inheritance
702         local size
703         size="$($LFS getstripe -I2 -S $file)"
704         [ $size -ne $((1024*1024)) ] && $LFS getstripe -I2 $file &&
705                 error "$file: component 2 doesn't have 1M stripe_size"
706         size="$($LFS getstripe -I4 -S $file)"
707         [ $size -ne $((1024*1024*2)) ] && $LFS getstripe -I4 $file &&
708                 error "$file: component 4 doesn't have 2M stripe_size"
709
710         return 0
711 }
712 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
713
714 test_15() {
715         local parent=$DIR/$tdir
716
717         rm -fr $parent
718         test_mkdir $parent
719
720         $LFS setstripe -d $parent || error "delete default layout"
721
722         $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1"
723         $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
724         test_mkdir $parent/subdir
725         $LFS setstripe -E 6M -S 1M -c1 -E 30M -c4 -E eof -c -1 $parent/subdir ||
726                 error "setstripe to subdir"
727         $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
728         $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
729
730         # none
731         local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
732         [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
733
734         # f2, f3
735         found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
736         [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
737
738         # subdir
739         found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
740         [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
741
742         local flg_opts="--component-flags init"
743         # none
744         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
745         [ $found -eq 0 ] ||
746                 error "before write: start=1M, end=10M, flag=init, $found != 0"
747
748         dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
749                 error "dd $parent/f1 failed"
750
751         # f1
752         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
753         [ $found -eq 1 ] ||
754                 error "after write: start=1M, end=10M, flag=init, $found != 1"
755
756         local ext_opts="--component-start -1M -E +5M"
757         # parent, subdir, f3, f4
758         found=$($LFS find $ext_opts $parent | wc -l)
759         [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
760
761         local cnt_opts="--component-count +2"
762         # subdir
763         found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
764         [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
765
766         # none
767         found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
768         [ $found -eq 0 ] ||
769                 error "start-1M, end+5M, count+2, flag=init, $found != 0"
770
771         # f3, f4
772         found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
773         [ $found -eq 2 ] ||
774                 error "start-1M, end+5M, !count+2, flag=init, $found != 2"
775
776         # check last component stripe count
777         if [ $OSTCOUNT -gt 1 ]; then
778                 touch $parent/subdir/f5
779                 $TRUNCATE $parent/subdir/f5 $((32*1024*1024))
780                 found=$($LFS find $parent/subdir -c $OSTCOUNT)
781                 [[ "$found" == "$parent/subdir/f5" ]] ||
782                         error "got '$found' with stripe_count=$OSTCOUNT, not f5"
783         fi
784 }
785 run_test 15 "Verify component options for lfs find"
786
787 test_16a() {
788         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
789         large_xattr_enabled || skip_env "ea_inode feature disabled"
790
791         local file=$DIR/$tdir/$tfile
792         local dir=$DIR/$tdir/dir
793         local temp=$DIR/$tdir/template
794         rm -rf $DIR/$tdir
795         test_mkdir $DIR/$tdir
796
797         #####################################################################
798         #                           1. PFL file
799         # set stripe for source file
800         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
801                 $file || error "Create $file failed"
802
803         echo "1. PFL file"
804         verify_yaml_layout $file $file.copy $temp "1. PFL file"
805
806         #####################################################################
807         #                           2. plain file
808         # set stripe for source file
809         rm -f $file
810         $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
811
812         rm -f $file.copy
813         echo "2. plain file"
814         verify_yaml_layout $file $file.copy $temp "2. plain file"
815
816         #####################################################################
817         #                           3. PFL dir
818         # set stripe for source dir
819         test_mkdir $dir
820         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
821                 error "setstripe $dir failed"
822
823         test_mkdir $dir.copy
824         echo "3. PFL dir"
825         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
826
827         #####################################################################
828         #                           4. plain dir
829         # set stripe for source dir
830         $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
831
832         echo "4. plain dir"
833         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
834 }
835 run_test 16a "Verify setstripe/getstripe with YAML config file"
836
837 test_16b() {
838         [[ $($LCTL get_param mdc.*.import |
839                 grep "connect_flags:.*overstriping") ]] ||
840                 skip "server does not support overstriping"
841         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
842         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
843                 skip_env "too many osts, skipping"
844         large_xattr_enabled || skip_env "ea_inode feature disabled"
845
846         local file=$DIR/$tdir/$tfile
847         local dir=$DIR/$tdir/dir
848         local temp=$DIR/$tdir/template
849         # We know OSTCOUNT < (LOV_MAX_STRIPE_COUNT / 2), so this is overstriping
850         local large_count=$((LOV_MAX_STRIPE_COUNT / 2 + 10))
851
852         rm -rf $DIR/$tdir
853         test_mkdir $DIR/$tdir
854
855         #####################################################################
856         #                           1. PFL file, overstriping in first comps
857         # set stripe for source file
858         $LFS setstripe -E1m -S 1M -o0,0 -E2m -o1,1 -E3m -C $large_count -E-1 \
859                 $file || error "Create $file failed"
860
861         echo "1. PFL file"
862         verify_yaml_layout $file $file.copy $temp "1. PFL file"
863
864         #####################################################################
865         #                           2. plain file + overstriping
866         # set stripe for source file
867         rm -f $file
868         $LFS setstripe -C $large_count -i1 $file || error "Create $file failed"
869
870         rm -f $file.copy
871         echo "2. plain file"
872         verify_yaml_layout $file $file.copy $temp "2. plain file"
873
874         #####################################################################
875         #                           3. PFL dir + overstriping
876         # set stripe for source dir
877         test_mkdir $dir
878         $LFS setstripe -E1m -S 1M -o 0,0 -E2m -C $large_count -E-1 $dir ||
879                 error "setstripe $dir failed"
880
881         test_mkdir $dir.copy
882         echo "3. PFL dir"
883         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
884
885         #####################################################################
886         #                           4. plain dir + overstriping
887         # set stripe for source dir
888         $LFS setstripe -C $large_count $dir || error "setstripe $dir failed"
889
890         echo "4. plain dir"
891         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
892 }
893 run_test 16b "Verify setstripe/getstripe with YAML config file + overstriping"
894
895 test_16c() {
896         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
897
898         local file=$DIR/$tdir/$tfile
899         local dir=$DIR/$tdir/dir
900         local temp=$DIR/$tdir/template
901         rm -rf $DIR/$tdir
902         test_mkdir $DIR/$tdir
903
904         #####################################################################
905         #                           1. SEL file
906         # set stripe for source file
907         $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
908                 $file || error "Create $file failed"
909
910         echo "1. SEL file"
911         verify_yaml_layout $file $file.copy $temp "1. PFL file"
912
913         #####################################################################
914         #                           2. SEL dir
915         # set stripe for source dir
916         test_mkdir $dir
917         $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
918                 $dir || error "setstripe $dir failed"
919
920         test_mkdir $dir.copy
921         echo "2. SEL template on dir"
922         verify_yaml_layout $dir $dir.copy $temp.dir "2. PFL dir"
923 }
924 run_test 16c "Verify setstripe/getstripe for SEL layout with YAML config file"
925
926 test_17() {
927         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
928         local file=$DIR/$tdir/$tfile
929         test_mkdir -p $DIR/$tdir
930         rm -f $file
931
932         $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E -1 -c -1 $file ||
933                 error "Create $file failed"
934
935         local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
936         local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
937         local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
938         echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
939
940         # init 2nd component
941         $TRUNCATE $file $((1024*1024+1))
942         local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
943         local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
944         echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
945
946         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
947         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
948
949         # init 3rd component
950         $TRUNCATE $file $((1024*1024*2+1))
951         s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
952         s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
953         local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
954         echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
955
956         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
957         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
958         [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
959 }
960 run_test 17 "Verify LOVEA grows with more component inited"
961
962 check_distribution() {
963         local file=$1
964         local objs
965         local ave
966         local obj_min_one=$((OSTCOUNT - 1))
967
968         objs=$($LFS getstripe $file |
969                 awk '/l_ost_idx:/ { print $5 }' | wc -l)
970         let ave=$((objs / OSTCOUNT))
971
972         # collect objects per OST distribution
973         $LFS getstripe $file | awk '/l_ost_idx:/ { print $5 }' | tr -d "," |
974                 (inuse=( $(for i in $(seq 0 $obj_min_one); do echo 0; done) )
975                 while read O; do
976                         let inuse[$O]=$((1 + ${inuse[$O]}))
977                 done;
978
979                 # verify object distribution varies no more than +-1
980                 for idx in $(seq 0 $obj_min_one); do
981                         let dif=$((${inuse[$idx]} - ave))
982                         let dif=${dif#-}
983                         if [ "$dif" -gt 1 ]; then
984                                 echo "OST${idx}: ${inuse[$idx]} objects"
985                                 error "bad distribution on OST${idx}"
986                         fi
987                 done)
988 }
989
990 test_18() {
991         local file1=$DIR/${tfile}-1
992         local file2=$DIR/${tfile}-2
993         local file3=$DIR/${tfile}-3
994
995         rm -f $file1 $file2 $file3
996
997         $LFS setstripe -E 1m -S 1m $file1 ||
998                 error "Create $file1 failed"
999         $LFS setstripe -E 1m -S 1m $file2 ||
1000                 error "Create $file2 failed"
1001         $LFS setstripe -E 1m -S 1m $file3 ||
1002                 error "Create $file3 failed"
1003
1004         local objs=$((OSTCOUNT+1))
1005         for comp in $(seq 1 $OSTCOUNT); do
1006                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file1 ||
1007                         error "Add component to $file1 failed 2"
1008                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file2 ||
1009                         error "Add component to $file2 failed 2"
1010                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file3 ||
1011                         error "Add component to $file3 failed 2"
1012         done
1013
1014         $LFS setstripe --component-add -E -1 -c -1 $file1 ||
1015                 error "Add component to $file1 failed 3"
1016         $LFS setstripe --component-add -E -1 -c -1 $file2 ||
1017                 error "Add component to $file2 failed 3"
1018         $LFS setstripe --component-add -E -1 -c -1 $file3 ||
1019                 error "Add component to $file3 failed 3"
1020
1021         # Instantiate all components
1022         dd if=/dev/urandom of=$file1 bs=1M count=$((objs+1)) ||
1023                 error "dd failed for $file1"
1024         dd if=/dev/urandom of=$file2 bs=1M count=$((objs+1)) ||
1025                 error "dd failed for $file2"
1026         dd if=/dev/urandom of=$file3 bs=1M count=$((objs+1)) ||
1027                 error "dd failed for $file3"
1028
1029         check_distribution $file1
1030         check_distribution $file2
1031         check_distribution $file3
1032
1033 }
1034 run_test 18 "check component distribution"
1035
1036 test19_io_base() {
1037         local comp_file=$1
1038         local already_created=${2:-0}
1039         local rw_len=$((3 * 1024 * 1024))       # 3M
1040         local flg_opts=""
1041         local found=""
1042
1043         if [ $already_created != 1 ]; then
1044                 test_mkdir -p $DIR/$tdir
1045                 $LFS setstripe --extension-size 64M -c 1 -E -1 $comp_file ||
1046                         error "Create $comp_file failed"
1047         fi
1048
1049         # write past end of first component, so it is extended
1050         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=127 conv=notrunc ||
1051                 error "dd to extend failed"
1052
1053         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1054         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1055
1056         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1057         [ $ost_idx2 -ne "-1" ] && error "second component init $ost_idx2"
1058
1059         flg_opts="--comp-flags init"
1060         found=$($LFS find --comp-start 0 -E 128M $flg_opts $comp_file | wc -l)
1061         [ $found -eq 1 ] || error "Write: Extended first component not found"
1062
1063         flg_opts="--comp-flags extension"
1064         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
1065         [ $found -eq 1 ] || error "Write: second component not found"
1066
1067         found=$($LFS find -z 64M $comp_file | wc -l)
1068         [ $found -eq 1 ] || error "component not found by ext size"
1069
1070         found=$($LFS find --extension-size +63M $comp_file | wc -l)
1071         [ $found -eq 1 ] || error "component not found by +ext size"
1072
1073         found=$($LFS find --ext-size -65M $comp_file | wc -l)
1074         [ $found -eq 1 ] || error "component not found by -ext size"
1075
1076         found=$($LFS find -z 65M $comp_file | wc -l)
1077         [ $found -eq 0 ] || error "component found by wrong ext size"
1078
1079         found=$($LFS find -z +65M $comp_file | wc -l)
1080         [ $found -eq 0 ] || error "component found by wrong +ext size"
1081
1082         found=$($LFS find -z -63M $comp_file | wc -l)
1083         [ $found -eq 0 ] || error "component found by wrong -ext size"
1084
1085         found=$($LFS find ! -z 64M $comp_file | wc -l)
1086         [ $found -eq 0 ] || error "component found by negation of ext size"
1087
1088         found=$($LFS find ! -z +63M $comp_file | wc -l)
1089         [ $found -eq 0 ] || error "component found by negation of +ext size"
1090
1091         found=$($LFS find ! -z -65M $comp_file | wc -l)
1092         [ $found -eq 0 ] || error "component found by negation of -ext size"
1093
1094         found=$($LFS find ! -z 65M $comp_file | wc -l)
1095         [ $found -eq 1 ] ||
1096                 error "component not found by negation of wrong ext size"
1097
1098         found=$($LFS find ! -z +65M $comp_file | wc -l)
1099         [ $found -eq 1 ] ||
1100                 error "component not found by negation of wrong +ext size"
1101
1102         found=$($LFS find ! -z -63M $comp_file | wc -l)
1103         [ $found -eq 1 ] ||
1104                 error "component not found by negation of wrong -ext size"
1105
1106         found=$($LFS find -S +1M $comp_file | wc -l)
1107         [ $found -eq 0 ] || error "component found by wrong +stripe size"
1108
1109         found=$($LFS find -c 1 $comp_file | wc -l)
1110         [ $found -eq 1 ] || error "component not found by stripe count"
1111
1112         small_write $comp_file $rw_len || error "Verify RW failed"
1113
1114         sel_layout_sanity $comp_file 2
1115 }
1116
1117 # Self-extending PFL tests
1118 test_19a() {
1119         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1120         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1121                 skip "skipped for lustre < $SEL_VER"
1122
1123         test19_io_base $DIR/$tdir/$tfile
1124 }
1125 run_test 19a "Simple test of extension behavior"
1126
1127 # Same as 19a, but with default layout set on directory rather than on file
1128 test_19b() {
1129         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1130         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1131                 skip "skipped for lustre < $SEL_VER"
1132
1133         local comp_file=$DIR/$tdir/$tfile
1134         local comp_dir=$DIR/$tdir/$tdir
1135         local flg_opts=""
1136         local found=""
1137
1138         test_mkdir -p $DIR/$tdir
1139         $LFS setstripe --ext-size 64M -c 1 -E -1 $DIR/$tdir ||
1140                 error "Setstripe on $DIR/$tdir failed"
1141
1142         # check inheritance for a sub-dir and a file
1143         test_mkdir $comp_dir
1144         found=$($LFS find --comp-start 0 -E 64M $comp_dir | wc -l)
1145         [ $found -eq 1 ] || error "Dir Inheritance: wrong first component size"
1146
1147         flg_opts="--comp-flags extension"
1148         found=$($LFS find --comp-start 64M -E EOF $flg_opts $comp_dir | wc -l)
1149         [ $found -eq 1 ] || error "Dir Inheritance: Second component not found"
1150
1151         touch $comp_file
1152
1153         flg_opts="--comp-flags init"
1154         found=$($LFS find --comp-start 0 -E 64M $flg_opts $comp_file | wc -l)
1155         [ $found -eq 1 ] || error "File Inheritance: wrong first component size"
1156
1157         flg_opts="--comp-flags extension"
1158         found=$($LFS find --comp-start 64M -E EOF $flg_opts $comp_file | wc -l)
1159         [ $found -eq 1 ] || error "File Inheritance: Second component not found"
1160
1161         test19_io_base $comp_file 1
1162 }
1163 run_test 19b "Simple test of SEL as default layout"
1164
1165 # Test behavior when seeking deep in a file
1166 test_19c() {
1167         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1168         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1169                 skip "skipped for lustre < $SEL_VER"
1170
1171         local comp_file=$DIR/$tdir/$tfile
1172         local flg_opts=""
1173         local found=""
1174
1175         test_mkdir -p $DIR/$tdir
1176
1177         $LFS setstripe -z 128M -E 1G -E -1 $comp_file ||
1178                 error "Create $comp_file failed"
1179
1180         # write past end of first component, so it is extended
1181         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 conv=notrunc ||
1182                 error "dd to extend failed"
1183
1184         flg_opts="--comp-flags init"
1185         found=$($LFS find --comp-start 0M -E 256M $flg_opts $comp_file | wc -l)
1186         [ $found -eq 1 ] || error "Write: first extension component not found"
1187
1188         flg_opts="--comp-flags extension,^init"
1189         found=$($LFS find --comp-start 256M -E 1024M $flg_opts $comp_file |\
1190                 wc -l)
1191         [ $found -eq 1 ] || error "Write: second extension component not found"
1192
1193         local end_1=$($LFS getstripe -I1 -E $comp_file)
1194
1195         # 256 MiB
1196         [ $end_1 -eq 268435456 ] ||
1197                 error "end of first component $end_1 != 268435456"
1198
1199         # Write past end of extension space component, in to normal component
1200         # should exhaust & remove extension component
1201         dd if=/dev/zero bs=1M count=1 seek=1100 of=$comp_file conv=notrunc ||
1202                 error "dd distant seek failed"
1203
1204         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1205         # the last component index is 3
1206         local ost_idx2=$($LFS getstripe -I3 -i $comp_file)
1207
1208         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1209
1210         local start1=$($LFS getstripe -I1 --comp-start $comp_file)
1211         local end1=$($LFS getstripe -I1 -E $comp_file)
1212         local start2=$($LFS getstripe -I3 --comp-start $comp_file)
1213         local end2=$($LFS getstripe -I3 -E $comp_file)
1214
1215         [ $start1 -eq 0 ] || error "start of first component incorrect"
1216         [ $end1 -eq 1073741824 ] || error "end of first component incorrect"
1217         [ $start2 -eq 1073741824  ] ||
1218                 error "start of second component incorrect"
1219         [ "$end2" = "EOF" ] || error "end of second component incorrect"
1220
1221         flg_opts="--comp-flags extension"
1222         found=$($LFS find $flg_opts $comp_file | wc -l)
1223         [ $found -eq 0 ] || error "Seek Write: extension component exists"
1224
1225         sel_layout_sanity $comp_file 2
1226 }
1227 run_test 19c "Test self-extending layout seeking behavior"
1228
1229 test_19d() {
1230         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1231         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1232                 skip "skipped for lustre < $SEL_VER"
1233
1234         local comp_file=$DIR/$tdir/$tfile
1235         local flg_opts=""
1236         local found=""
1237
1238         test_mkdir -p $DIR/$tdir
1239
1240         $LFS setstripe -E 128M -c 1 -z 64M -E -1 $comp_file ||
1241                 error "Create $comp_file failed"
1242
1243         # This will cause component 1 to be extended to 128M, then the
1244         # extension space component will be removed
1245         dd if=/dev/zero of=$comp_file bs=130M count=1 ||
1246                 error "dd to extend failed"
1247
1248         flg_opts="--comp-flags init"
1249         found=$($LFS find --comp-start 0M -E 128M $flg_opts $comp_file | wc -l)
1250         [ $found -eq 1 ] || error "Write: first component not found"
1251
1252         flg_opts="--comp-flags init"
1253         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
1254         [ $found -eq 1 ] || error "Write: second component not found"
1255
1256         sel_layout_sanity $comp_file 2
1257
1258         # always remove large files in case of DO_CLEANUP=false
1259         rm -f $comp_file || error "Delete $comp_file failed"
1260 }
1261 run_test 19d "Test write which completely spans extension space component"
1262
1263 test_19e_check() {
1264         comp_file=$1
1265
1266         local comp2_flags=$($LFS getstripe -I2 --comp-flags $comp_file)
1267         local comp3_flags=$($LFS getstripe -I3 --comp-flags $comp_file)
1268
1269         [ "$comp2_flags" != "init" ] && error "$comp2_flags != init"
1270         [ "$comp3_flags" != "extension" ] && error "$comp3_flags != extension"
1271
1272         local flg_opts=" --comp-start 2M -E 66M --comp-flags init"
1273         local found=$($LFS find $flg_opts $comp_file | wc -l)
1274         [ $found -eq 1 ] || error "Write: extended second component not found"
1275
1276         flg_opts="--comp-start 66M -E EOF --comp-flags extension"
1277         found=$($LFS find $flg_opts $comp_file | wc -l)
1278         [ $found -eq 1 ] || error "Write: third component not found"
1279
1280         sel_layout_sanity $comp_file 3
1281 }
1282
1283 test_19e() {
1284         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1285         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1286                 skip "skipped for lustre < $SEL_VER"
1287
1288         local comp_file=$DIR/$tdir/$tfile
1289         local rw_len=$((3 * 1024 * 1024))       # 3M
1290         local flg_opts=""
1291         local found=""
1292
1293         test_mkdir -p $DIR/$tdir
1294
1295         $LFS setstripe -E 2m -E -1 -z 64M $comp_file ||
1296                 error "Create $comp_file failed"
1297
1298         replay_barrier $SINGLEMDS
1299
1300         #instantiate & extend second component
1301         dd if=/dev/zero of=$comp_file bs=4M count=1 ||
1302                 error "dd to extend failed"
1303
1304         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1305         local ost_idx3=$($LFS getstripe -I3 -i $comp_file)
1306
1307         [ $ost_idx2 -eq $ost_idx3 ] && error "$ost_idx2 == $ost_idx3"
1308         [ $ost_idx3 -ne "-1" ] && error "third component init $ost_idx3"
1309
1310         test_19e_check $comp_file
1311
1312         local f1=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}')
1313         echo "before MDS recovery, the ost fid of 2nd component is $f1"
1314
1315         fail $SINGLEMDS
1316
1317         local f2=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}')
1318         echo "after MDS recovery, the ost fid of 2nd component is $f2"
1319         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
1320
1321         # simply repeat all previous checks, but also verify components are on
1322         # the same OST as before
1323
1324         local ost_idx2_2=$($LFS getstripe -I2 -i $comp_file)
1325         local ost_idx3_2=$($LFS getstripe -I3 -i $comp_file)
1326
1327         [ $ost_idx2_2 -eq $ost_idx3_2 ] && error "$ost_idx2_2 == $ost_idx3_2"
1328         [ $ost_idx3_2 -ne "-1" ] && error "second component init $ost_idx3_2"
1329
1330         # verify OST id is the same after failover
1331         [ $ost_idx2 -ne $ost_idx2_2 ] &&
1332                 error "$ost_idx2 != $ost_idx2_2, changed after failover"
1333
1334         test_19e_check $comp_file
1335 }
1336 run_test 19e "Replay of layout instantiation & extension"
1337
1338 test_19f() {
1339         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1340         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1341                 skip "skipped for lustre < $SEL_VER"
1342
1343         local comp_file=$DIR/$tdir/$tfile
1344         local flg_opts=""
1345         local found=""
1346
1347         test_mkdir -p $DIR/$tdir
1348
1349         $LFS setstripe -E 256M --comp-flags extension -E -1 $comp_file
1350
1351         [ $? != 0 ] || error "should not be able to manually set extension flag"
1352
1353 }
1354 run_test 19f "Rejection of invalid layouts"
1355
1356 test_19g() {
1357         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1358         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1359                 skip "skipped for lustre < $SEL_VER"
1360
1361         local file1=$DIR/${tfile}-1
1362         local file2=$DIR/${tfile}-2
1363
1364         test_mkdir -p $DIR/$tdir
1365         multiop $file1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
1366                 error "create failed $file1"
1367         multiop $file2 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
1368                 error "create failed $file2"
1369
1370         $LFS setstripe --component-add -E 1G -c 1 $file1 ||
1371                 error "comp-add [0,1G] failed $file1"
1372         $LFS setstripe --component-add -E 512M -z 128M $file1 &&
1373                 error "comp-add [1G,1G],SEL[1G,512M] succeded $file1"
1374         $LFS setstripe --component-add -E 10G -z 128M $file1 ||
1375                 error "comp-add [1G,1G],SEL[1G,10G] failed $file1"
1376         $LFS setstripe --component-add -E -1 $file1 ||
1377                 error "comp-add [10G,-1] failed $file1"
1378
1379         $LFS setstripe --component-add -E 1G -z 32M -c 1 $file2 &&
1380                 error "comp-add with smal ext size succeeded $file1"
1381         $LFS setstripe --component-add -E 1G -z 100M -c 1 $file2 &&
1382                 error "comp-add with not aligned ext size succeeded $file1"
1383         $LFS setstripe --component-add -E 1G -z 128M -c 1 $file2 ||
1384                 error "comp-add [0,128M],SEL[128M,1G] failed $file1"
1385         $LFS setstripe --component-add -E 10G $file2 ||
1386                 error "comp-add [1G,10G] failed $file1"
1387         $LFS setstripe --component-add -E -1 -z 128M -c 1 $file2 ||
1388                 error "comp-add [10G,10G],SEL[10G,-1] failed $file1"
1389         $LFS setstripe --component-add -E -1 -z 128M -c 1 $file2 &&
1390                 error "repeated comp-add [10G,10G],SEL[10G,-1] succeeded $file1"
1391
1392         $LFS getstripe $file1
1393         flg_opts="--comp-flags init"
1394         found=$($LFS find --comp-start 0 -E 1G $flg_opts $file1 | wc -l)
1395         [ $found -eq 1 ] || error "First component not found $file1"
1396
1397         flg_opts="--comp-flags ^init"
1398         found=$($LFS find --comp-start 1G -E 1G $flg_opts $file1 | wc -l)
1399         [ $found -eq 1 ] || error "Second component not found $file1"
1400
1401         flg_opts="--comp-flags ^init,extension"
1402         found=$($LFS find --comp-start 1G -E 10G $flg_opts $file1 | wc -l)
1403         [ $found -eq 1 ] || error "Third component not found $file1"
1404
1405         flg_opts="--comp-flags ^init"
1406         found=$($LFS find --comp-start 10G -E EOF $flg_opts $file1 | wc -l)
1407         [ $found -eq 1 ] || error "Fourth component not found $file1"
1408
1409         $LFS getstripe $file2
1410         flg_opts="--comp-flags init"
1411         found=$($LFS find --comp-start 0 -E 128M $flg_opts $file2 | wc -l)
1412         [ $found -eq 1 ] || error "First component not found $file2"
1413
1414         flg_opts="--comp-flags extension"
1415         found=$($LFS find --comp-start 128M -E 1G $flg_opts $file2 | wc -l)
1416         [ $found -eq 1 ] || error "Second component not found $file2"
1417
1418         flg_opts="--comp-flags ^init"
1419         found=$($LFS find --comp-start 1G -E 10G $flg_opts $file2 | wc -l)
1420         [ $found -eq 1 ] || error "Third component not found $file2"
1421
1422         flg_opts="--comp-flags ^init"
1423         found=$($LFS find --comp-start 10G -E 10G $flg_opts $file2 | wc -l)
1424         [ $found -eq 1 ] || error "Fourth component not found $file2"
1425
1426         flg_opts="--comp-flags ^init,extension"
1427         found=$($LFS find --comp-start 10G -E EOF $flg_opts $file2 | wc -l)
1428         [ $found -eq 1 ] || error "Fifth component not found $file2"
1429 }
1430 run_test 19g "component-add behaviour"
1431
1432 # Test out of space behavior
1433 test_20a() {
1434         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1435         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1436                 skip "skipped for lustre < $SEL_VER"
1437
1438         local comp_file=$DIR/$tdir/$tfile
1439         local flg_opts=""
1440         local found=""
1441
1442         test_mkdir -p $DIR/$tdir
1443
1444         # without this, a previous delete can finish after we check free space
1445         wait_delete_completed
1446         wait_mds_ost_sync
1447
1448         # First component is on OST0
1449         $LFS setstripe -E 256M -i 0 -z 64M -E -1 -z 128M $comp_file ||
1450                 error "Create $comp_file failed"
1451
1452         # write past end of first component, so it is extended
1453         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=66 ||
1454                 error "dd to extend failed"
1455
1456         flg_opts="--comp-flags extension"
1457         found=$($LFS find --comp-start 128M -E 256M $flg_opts $comp_file |wc -l)
1458         [ $found -eq 1 ] || error "Write: Second component not found"
1459
1460         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1461         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1462                     grep "watermarks")
1463         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1464
1465         flg_opts="--comp-flags extension"
1466         # Write past current init comp, but we won't extend (because no space)
1467         dd if=/dev/zero of=$comp_file bs=1M count=10 seek=200 ||
1468                 error "dd write past current comp failed"
1469
1470         $LFS getstripe $comp_file
1471
1472         flg_opts="--comp-flags init"
1473         found=$($LFS find --comp-start 128M -E 256M $flg_opts $comp_file | \
1474                 wc -l)
1475         [ $found -eq 1 ] || error "Write: third component not found"
1476
1477         flg_opts="--comp-flags extension"
1478         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file |wc -l)
1479         [ $found -eq 1 ] || error "Write: fourth extension component not found"
1480
1481         sel_layout_sanity $comp_file 3
1482 }
1483 run_test 20a "Test out of space, spillover to defined component"
1484
1485 test_20b() {
1486         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1487         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1488                 skip "skipped for lustre < $SEL_VER"
1489
1490         local comp_file=$DIR/$tdir/$tfile
1491         local flg_opts=""
1492         local found=""
1493
1494         test_mkdir -p $DIR/$tdir
1495
1496         # Pool allows us to force use of only certain OSTs
1497         pool_add $TESTNAME || error "Pool creation failed"
1498         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1499
1500         # normal component to 10M, extendable component to 1G
1501         # further extendable to EOF
1502         $LFS setstripe -E 10M -E 1G -p $TESTNAME -z 64M -E -1 -p "" -z 128M \
1503                 $comp_file || error "Create $comp_file failed"
1504
1505         replay_barrier $SINGLEMDS
1506
1507         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1508         [ $found -eq 1 ] || error "Zero length component not found"
1509
1510         local ost_idx1=0
1511         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1512                     grep "watermarks")
1513         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1514
1515         # write past end of first component
1516         # This should remove the next component, since OST0 is out of space
1517         # and it is striped there (pool contains only OST0)
1518         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=14 ||
1519                 error "dd to extend/remove failed"
1520
1521         $LFS getstripe $comp_file
1522
1523         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1524         [ $found -eq 0 ] || error "Write: zero length component still present"
1525
1526         flg_opts="--comp-flags init"
1527         found=$($LFS find --comp-start 10M -E 138M $flg_opts $comp_file | wc -l)
1528         [ $found -eq 1 ] || error "Write: second component not found"
1529
1530         flg_opts="--comp-flags extension"
1531         found=$($LFS find --comp-start 138M -E EOF $flg_opts $comp_file | wc -l)
1532         [ $found -eq 1 ] || error "Write: third component not found"
1533
1534         fail $SINGLEMDS
1535
1536         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1537         [ $found -eq 0 ] || error "Failover: 0-length component still present"
1538
1539         flg_opts="--comp-flags init"
1540         found=$($LFS find --comp-start 10M -E 138M $flg_opts $comp_file | wc -l)
1541         [ $found -eq 1 ] || error "Failover: second component not found"
1542
1543         flg_opts="--comp-flags extension"
1544         found=$($LFS find --comp-start 138M -E EOF $flg_opts $comp_file | wc -l)
1545         [ $found -eq 1 ] || error "Failover: third component not found"
1546
1547         sel_layout_sanity $comp_file 3
1548 }
1549 run_test 20b "Remove component without instantiation when there is no space"
1550
1551 test_20c() {
1552         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1553         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1554                 skip "skipped for lustre < $SEL_VER"
1555
1556         local comp_file=$DIR/$tdir/$tfile
1557         local flg_opts=""
1558         local found=""
1559
1560         test_mkdir -p $DIR/$tdir
1561
1562         # pool is used to limit available OSTs to 0 and 1, so we can set all
1563         # available OSTs out of space
1564         pool_add $TESTNAME || error "Pool creation failed"
1565         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
1566
1567         # without this, a previous delete can finish after we check free space
1568         wait_delete_completed
1569         wait_mds_ost_sync
1570
1571         $LFS setstripe -E 100M -E -1 -p $TESTNAME -z 64M $comp_file ||
1572                 error "Create $comp_file failed"
1573
1574         local ost_idx1=0
1575         local ost_idx2=1
1576         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1577                     grep "watermarks")
1578         local wms2=$(ost_watermarks_set_enospc $tfile $ost_idx2 |
1579                      grep "watermarks")
1580         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1581         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx2 $wms2" EXIT
1582
1583         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=120 &&
1584                 error "dd should fail with ENOSPC"
1585
1586         flg_opts="--comp-flags init"
1587         found=$($LFS find --comp-start 0M -E 100M $flg_opts $comp_file | wc -l)
1588         [ $found -eq 1 ] || error "Write: First component not found"
1589
1590         flg_opts="--comp-flags ^init"
1591         found=$($LFS find --comp-start 100M -E 100M $flg_opts $comp_file |wc -l)
1592         [ $found -eq 1 ] || error "Write: 0-length component not found"
1593
1594         flg_opts="--comp-flags extension"
1595         found=$($LFS find --comp-start 100M -E EOF $flg_opts $comp_file | wc -l)
1596         [ $found -eq 1 ] || error "Write: third extension component not found"
1597
1598         sel_layout_sanity $comp_file 3
1599 }
1600 run_test 20c "Test inability to stripe new extension component"
1601
1602 test_20d() {
1603         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1604         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1605                 skip "skipped for lustre < $SEL_VER"
1606
1607         local comp_file=$DIR/$tdir/$tfile
1608         test_mkdir -p $DIR/$tdir
1609
1610         wait_delete_completed
1611         wait_mds_ost_sync
1612
1613         pool_add $TESTNAME || error "Pool creation failed"
1614         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1615         $LFS setstripe -E 64m -E -1 -p $TESTNAME -z 64M $comp_file ||
1616                 error "Create $comp_file failed"
1617
1618         replay_barrier $SINGLEMDS
1619
1620         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
1621         dd if=/dev/zero bs=1M count=1 seek=100 of=$comp_file
1622         RC=$?
1623
1624         ost_watermarks_clear_enospc $tfile 0 $wms
1625         [ $RC -eq 0 ] || error "dd failed: $RC"
1626
1627         $LFS getstripe $comp_file
1628         local flg_opts="--comp-start 64M -E 128M --comp-flags init"
1629         local found=$($LFS find $flg_opts $comp_file | wc -l)
1630         [ $found -eq 1 ] || error "Write: component (64M-128M) not found"
1631
1632         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
1633         [ "$ost_idx" != "-1" ] && error "Write: EXT component disappeared"
1634
1635         fail $SINGLEMDS
1636
1637         found=$($LFS find $flg_opts $comp_file | wc -l)
1638         [ $found -eq 1 ] || error "Failover: component (64M-128M) not found"
1639
1640         ost_idx=$($LFS getstripe -I3 -i $comp_file)
1641         [ "$ost_idx" != "-1" ] && error "Failover: EXT component disappeared"
1642
1643         sel_layout_sanity $comp_file 3
1644 }
1645 run_test 20d "Low on space + 0-length comp: force extension"
1646
1647 test_20e() {
1648         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1649         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1650                 skip "skipped for lustre < $SEL_VER"
1651
1652         local comp_file=$DIR/$tdir/$tfile
1653         test_mkdir -p $DIR/$tdir
1654
1655         wait_delete_completed
1656         wait_mds_ost_sync
1657
1658         pool_add $TESTNAME || error "Pool creation failed"
1659         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1660
1661         $LFS setstripe -E 64m -E 640M -z 64M -p $TESTNAME -E -1 $comp_file ||
1662                 error "Create $comp_file failed"
1663
1664         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
1665
1666         dd if=/dev/zero bs=1M count=1 seek=100 of=$comp_file
1667         RC=$?
1668
1669         ost_watermarks_clear_enospc $tfile 0 $wms
1670         [ $RC -eq 0 ] || error "dd failed $RC"
1671
1672         $LFS getstripe $comp_file
1673         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
1674         local found=$($LFS find $flg_opts $comp_file | wc -l)
1675         [ $found -eq 1 ] || error "Write: component (64M-EOF) not found"
1676
1677         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
1678         [ "$ost_idx" != "" ] && error "Write: 0-length component still exists"
1679         ost_idx=$($LFS getstripe -I3 -i $comp_file)
1680         [ "$ost_idx" != "" ] && error "Write: extension component still exists"
1681
1682         sel_layout_sanity $comp_file 2
1683 }
1684 run_test 20e "ENOSPC with next real comp: spillover and backward extension"
1685
1686 # Simple DoM interaction test
1687 test_21a() {
1688         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1689                 skip "skipped for lustre < $SEL_VER"
1690
1691         local comp_file=$DIR/$tdir/$tfile
1692         local flg_opts=""
1693         local found=""
1694
1695         test_mkdir -p $DIR/$tdir
1696
1697         # simple, correct self-extending layout after DoM component
1698         $LFS setstripe -E 1M -L mdt -E -1 -z 64m $comp_file || \
1699                 error "Create $comp_file failed"
1700
1701         # Write to DoM component & to self-extending comp after it
1702         dd if=/dev/zero bs=1M count=12 of=$comp_file ||
1703                 error "dd to extend failed"
1704
1705         flg_opts="--comp-flags init"
1706         found=$($LFS find --comp-start 1M -E 65M $flg_opts $comp_file | wc -l)
1707         [ $found -eq 1 ] || error "Write: extended component not found"
1708
1709         flg_opts="--comp-flags extension"
1710         found=$($LFS find --comp-start 65M $flg_opts $comp_file | wc -l)
1711         [ $found -eq 1 ] || error "Write: extension component not found"
1712
1713         sel_layout_sanity $comp_file 3
1714 }
1715 run_test 21a "Simple DoM interaction tests"
1716
1717 # DoM + extension + removal
1718 test_21b() {
1719         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1720         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1721                 skip "skipped for lustre < $SEL_VER"
1722
1723         local comp_file=$DIR/$tdir/$tfile
1724         local ost_name=$(ostname_from_index 0)
1725         local flg_opts=""
1726         local found=""
1727
1728         test_mkdir -p $DIR/$tdir
1729
1730         # DoM, extendable component, further extendable component
1731         $LFS setstripe -E 1M -L mdt -E 256M -i 0 -z 64M -E -1 -z 128M \
1732                 $comp_file || error "Create $comp_file failed"
1733
1734         found=$($LFS find --comp-start 1M -E 1M $flg_opts $comp_file | wc -l)
1735         [ $found -eq 1 ] || error "Write: Zero length component not found"
1736
1737         # This also demonstrates that we will avoid degraded OSTs
1738         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
1739         # sleep to guarantee we see the degradation
1740         sleep_maxage
1741
1742         # un-degrade on exit
1743         stack_trap "do_facet ost1 $LCTL set_param -n \
1744                 obdfilter.$ost_name.degraded=0; sleep_maxage" EXIT
1745
1746         # This should remove the first component after DoM and spill over to
1747         # the next one
1748         dd if=/dev/zero bs=1M count=2 of=$comp_file ||
1749                 error "dd to remove+spill over failed"
1750
1751         found=$($LFS find --comp-start 1M -E 1M $flg_opts $comp_file | wc -l)
1752         [ $found -eq 0 ] || error "Write: Zero length component still present"
1753
1754         flg_opts="--comp-flags init"
1755         found=$($LFS find --comp-start 1M -E 129M $flg_opts $comp_file | wc -l)
1756         [ $found -eq 1 ] || error "Write: extended component not found"
1757
1758         flg_opts="--comp-flags extension"
1759         found=$($LFS find --comp-start 129M -E EOF $flg_opts $comp_file |wc -l)
1760         [ $found -eq 1 ] || error "Write: extension component not found"
1761
1762         sel_layout_sanity $comp_file 3
1763 }
1764 run_test 21b "DoM followed by extendable component with removal"
1765
1766 # Test of repeat component behavior with OOS/degraded OST
1767 test_22a() {
1768         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1769         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1770                 skip "skipped for lustre < $SEL_VER"
1771
1772         local comp_file=$DIR/$tdir/$tfile
1773         local flg_opts=""
1774         local found=""
1775
1776         test_mkdir -p $DIR/$tdir
1777
1778         $LFS setstripe -E -1 -c 1 -z 128M $comp_file ||
1779                 error "Create $comp_file failed"
1780
1781         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1782         local ost_name=$(ostname_from_index $ost_idx1)
1783
1784         # write past end of first component, so it is extended
1785         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 ||
1786                 error "dd to extend failed"
1787
1788         flg_opts="--comp-flags extension"
1789         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file | wc -l)
1790         [ $found -eq 1 ] || error "Write: second component not found"
1791
1792         # degrade OST for component 1
1793         do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
1794                 obdfilter.$ost_name.degraded=1
1795         # sleep to guarantee we see the degradation
1796         sleep_maxage
1797
1798         # un-degrade on exit
1799         stack_trap "do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
1800                 obdfilter.$ost_name.degraded=0; sleep_maxage" EXIT
1801
1802         replay_barrier $SINGLEMDS
1803
1804         # seek past the end of current comp & write, should cause a new comp
1805         # to be created (ie repeat previous comp)
1806         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 ||
1807                 error "dd to repeat failed"
1808
1809         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1810
1811         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1812
1813         flg_opts="--comp-flags init"
1814         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
1815         [ $found -eq 1 ] || error "Write: second component not found"
1816
1817         flg_opts="--comp-flags extension"
1818         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
1819         [ $found -eq 1 ] || error "Write: extension component not found"
1820
1821         fail $SINGLEMDS
1822
1823         local ost_idx2_2=$($LFS getstripe -I2 -i $comp_file)
1824         [ $ost_idx2_2 -ne $ost_idx2 ] && error "$ost_idx2_2 != $ost_idx2"
1825
1826         flg_opts="--comp-flags init"
1827         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
1828         [ $found -eq 1 ] || error "Failover: second component not found"
1829
1830         flg_opts="--comp-flags extension"
1831         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
1832         [ $found -eq 1 ] || error "Failover: extension component not found"
1833
1834         sel_layout_sanity $comp_file 3
1835 }
1836 run_test 22a "Test repeat component behavior with degraded OST"
1837
1838 # Test repeat behavior with low space
1839 test_22b() {
1840         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1841         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1842                 skip "skipped for lustre < $SEL_VER"
1843
1844         local comp_file=$DIR/$tdir/$tfile
1845         local flg_opts=""
1846         local found=""
1847
1848         test_mkdir -p $DIR/$tdir
1849
1850         # without this, a previous delete can finish after we check free space
1851         wait_delete_completed
1852         wait_mds_ost_sync
1853
1854         $LFS setstripe -E -1 -c 1 -z 128M \
1855                 $comp_file || error "Create $comp_file failed"
1856
1857         # write past end of first component, so it is extended
1858         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 ||
1859                 error "dd to extend failed"
1860
1861         flg_opts="--comp-flags extension"
1862         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file | wc -l)
1863         [ $found -eq 1 ] || error "Write: Second component not found"
1864
1865         # set our OST low on space
1866         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1867         local wms=$(ost_watermarks_set_low_space $ost_idx1 | grep "watermarks")
1868
1869         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1870
1871         # Write past end of current space, fail to extend, causing repeat
1872         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 ||
1873                 error "dd to repeat failed"
1874
1875         $LFS getstripe $comp_file
1876
1877         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1878
1879         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1880
1881         flg_opts="--comp-flags init"
1882         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
1883         [ $found -eq 1 ] || error "Write: Second component not found"
1884
1885         flg_opts="--comp-flags extension"
1886         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
1887         [ $found -eq 1 ] || error "Write: Extension component not found"
1888
1889         sel_layout_sanity $comp_file 3
1890 }
1891 run_test 22b "Test simple 'out of space' condition with repeat"
1892
1893 # This tests both "repeat" and "extend in place when repeat fails" aspects
1894 # of repeating components
1895 test_22c() {
1896         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1897         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1898                 skip "skipped for lustre < $SEL_VER"
1899
1900         local comp_file=$DIR/$tdir/$tfile
1901         local flg_opts=""
1902         local found=""
1903
1904         test_mkdir -p $DIR/$tdir
1905
1906         # pool is used to limit available OSTs to 0 and 1, so we can set all
1907         # available OSTs out of space
1908         pool_add $TESTNAME || error "Pool creation failed"
1909         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
1910
1911         # without this, a previous delete can finish after we check free space
1912         wait_delete_completed
1913         wait_mds_ost_sync
1914
1915         $LFS setstripe -E -1 -z 64M -c 1 -p "$TESTNAME" $comp_file || \
1916                 error "Create $comp_file failed"
1917
1918         # write past end of first component, so it is extended
1919         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=80 conv=notrunc ||
1920                 error "dd to extend failed"
1921
1922         $LFS getstripe $comp_file
1923
1924         flg_opts="--comp-flags extension"
1925         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
1926         [ $found -eq 1 ] || error "Write: second component not found"
1927
1928         # set our OST out of space
1929         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1930         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1931                     grep "watermarks")
1932         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1933
1934         # This should create a repeat component on a new OST
1935         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=180 conv=notrunc ||
1936                 error "dd to repeat failed"
1937
1938         $LFS getstripe $comp_file
1939
1940         local comp_cnt=$($LFS getstripe --component-count $comp_file)
1941         [ $comp_cnt -ne 3 ] && error "component count: $comp_cnt, should be 3"
1942
1943         # New second component should be on a different OST
1944         local ost_idx2=$($LFS getstripe --comp-start=128m \
1945                          --comp-end=192m --comp-flags=init -i $comp_file)
1946
1947         [ $ost_idx1 -eq $ost_idx2 ] && error "2nd comp: same OST $ost_idx1"
1948
1949         local wms2=$(ost_watermarks_set_enospc $tfile $ost_idx2 |
1950                      grep "watermarks")
1951         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx2 $wms2" EXIT
1952
1953         # now that the second OST is out of space (as is the first OST), we
1954         # attempt to extend.  This should result in an extension of the
1955         # existing component, rather than a new component.
1956         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=240 conv=notrunc ||
1957                 error "dd for forced extension failed"
1958
1959         $LFS getstripe $comp_file
1960
1961         # clear out of space on first OST
1962         ost_watermarks_clear_enospc $tfile $ost_idx1 $wms
1963
1964         # finally, now that the first OST has space again, we attempt to
1965         # extend one last time.  This should create a new component on the
1966         # first OST
1967         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 conv=notrunc ||
1968                 error "dd for repeat on first OST failed"
1969
1970         $LFS getstripe $comp_file
1971
1972         flg_opts="--comp-flags init"
1973         found=$($LFS find --comp-start 128M $flg_opts $comp_file | wc -l)
1974         [ $found -eq 1 ] || error "Write: second component not found"
1975
1976         flg_opts="--comp-flags init"
1977         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
1978         [ $found -eq 1 ] || error "Write: third component not found"
1979
1980         flg_opts="--comp-flags extension"
1981         found=$($LFS find --comp-start 320M -E EOF $flg_opts $comp_file | wc -l)
1982         [ $found -eq 1 ] || error "Write: extension component not found"
1983
1984         sel_layout_sanity $comp_file 4
1985 }
1986 run_test 22c "Test repeat with out of space on > 1 OST"
1987
1988 test_22d_post_check() {
1989         local comp_file=$1
1990         local name=$2
1991         local flg_opts="--comp-flags init"
1992         local found=$($LFS find --comp-start 0M -E 128M $flg_opts $comp_file |
1993                       wc -l)
1994         [ $found -eq 1 ] || {
1995                 $LFS getstripe $comp_file
1996                 error "$name: second component not found"
1997         }
1998
1999         flg_opts="--comp-flags extension"
2000         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
2001         [ $found -eq 1 ] || error "$name: third extension component not found"
2002
2003         sel_layout_sanity $comp_file 2
2004 }
2005
2006 test_22d_pre() {
2007         local comp_file=$1
2008         local wms="$2"
2009         local RC
2010
2011         # write past end of first component
2012         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=70
2013         RC=$?
2014
2015         ost_watermarks_clear_enospc $tfile 0 $wms
2016         [ $RC -eq 0 ] || error "dd to force extend failed"
2017
2018         test_22d_post_check $comp_file "Write"
2019 }
2020
2021 test_22d() {
2022         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2023         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2024                 skip "skipped for lustre < $SEL_VER"
2025
2026         local comp_file=$DIR/$tdir/$tfile
2027         local flg_opts=""
2028         local found=""
2029
2030         test_mkdir -p $DIR/$tdir
2031
2032         # without this, a previous delete can finish after we check free space
2033         wait_delete_completed
2034         wait_mds_ost_sync
2035
2036         # Pool allows us to force use of only certain OSTs
2037         pool_add $TESTNAME || error "Pool creation failed"
2038         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2039
2040         # 1. Fail to extend due to OOS, try to repeat within the same pool,
2041         # fail to stripe (again OOS) the 0-length component, remove the
2042         # repeated one, force the extension on the original one.
2043         $LFS setstripe -E -1 -p $TESTNAME -z 64M $comp_file ||
2044                 error "Create $comp_file failed"
2045
2046         replay_barrier $SINGLEMDS
2047
2048         # set our OST out of space
2049         local wms=$(ost_watermarks_set_enospc $tfile 0 | grep "watermarks")
2050
2051         test_22d_pre $comp_file "$wms"
2052         fail $SINGLEMDS
2053         test_22d_post_check $comp_file "Failover"
2054
2055         # 2. repeat with low on space: 0-length repeated component will be
2056         # striped, but still fails to be extended; otherwise the same as (1).
2057         rm -f $comp_file
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 low on space
2064         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2065
2066         test_22d_pre $comp_file "$wms"
2067         fail $SINGLEMDS
2068         test_22d_post_check $comp_file "Failover"
2069 }
2070 run_test 22d "out of/low on space + failed to repeat + forced extension"
2071
2072 test_23a() {
2073         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2074         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2075                 skip "skipped for lustre < $SEL_VER"
2076
2077         local comp_file=$DIR/$tdir/$tfile
2078         test_mkdir -p $DIR/$tdir
2079
2080         $LFS setstripe -z 64M -c 1 -E -1 $comp_file ||
2081                 error "Create $comp_file failed"
2082
2083         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2084                 error "dd append failed"
2085
2086         local flg_opts="--comp-start 0 -E EOF --comp-flags init"
2087         local found=$($LFS find $flg_opts $comp_file | wc -l)
2088         [ $found -eq 1 ] || error "Append: first component (0-EOF) not found"
2089
2090         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
2091         [ "$ost_idx" != "" ] && error "Append: second component still exists"
2092
2093         sel_layout_sanity $comp_file 1
2094 }
2095 run_test 23a "Append: remove EXT comp"
2096
2097 test_23b() {
2098         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2099         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2100                 skip "skipped for lustre < $SEL_VER"
2101
2102         local comp_file=$DIR/$tdir/$tfile
2103         test_mkdir -p $DIR/$tdir
2104
2105         $LFS setstripe -E 64m -E -1 -z 64M $comp_file ||
2106                 error "Create $comp_file failed"
2107
2108         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2109                 error "dd append failed"
2110
2111         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2112         local found=$($LFS find $flg_opts $comp_file | wc -l)
2113         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2114
2115         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
2116         [ "$ost_idx" != "" ] && error "Append: third component still exists"
2117
2118         sel_layout_sanity $comp_file 2
2119 }
2120 run_test 23b "Append with 0-length comp: remove EXT comp"
2121
2122 test_23c() {
2123         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2124         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2125                 skip "skipped for lustre < $SEL_VER"
2126
2127         local comp_file=$DIR/$tdir/$tfile
2128         test_mkdir -p $DIR/$tdir
2129
2130         wait_delete_completed
2131         wait_mds_ost_sync
2132
2133         pool_add $TESTNAME || error "Pool creation failed"
2134         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2135         $LFS setstripe -E 64m -E -1 -p $TESTNAME -z 64M $comp_file ||
2136                 error "Create $comp_file failed"
2137
2138         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2139         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2140         RC=$?
2141
2142         ost_watermarks_clear_enospc $tfile 0 $wms
2143         [ $RC -eq 0 ] || error "dd append failed: $RC"
2144
2145         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2146         local found=$($LFS find $flg_opts $comp_file | wc -l)
2147         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2148
2149         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
2150         [ "$ost_idx" != "" ] && error "Append: EXT component still exists"
2151
2152         sel_layout_sanity $comp_file 2
2153 }
2154 run_test 23c "Append with low on space + 0-length comp: force extension"
2155
2156 test_23d() {
2157         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2158         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2159                 skip "skipped for lustre < $SEL_VER"
2160
2161         local comp_file=$DIR/$tdir/$tfile
2162         test_mkdir -p $DIR/$tdir
2163
2164         $LFS setstripe -E 64m -E 640M -z 64M -E -1 $comp_file ||
2165                 error "Create $comp_file failed"
2166
2167         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2168                 error "dd append failed"
2169
2170         flg_opts="--comp-start 64M -E 640M --comp-flags init"
2171         found=$($LFS find $flg_opts $comp_file | wc -l)
2172         [ $found -eq 1 ] || error "Append: component (64M-640M) not found"
2173
2174         ost_idx=$($LFS getstripe -I3 -i $comp_file)
2175         [ "$ost_idx" != "" ] && error "Append: third component still exists"
2176
2177         sel_layout_sanity $comp_file 3
2178 }
2179 run_test 23d "Append with 0-length comp + next real comp: remove EXT comp"
2180
2181 test_23e() {
2182         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2183         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2184                 skip "skipped for lustre < $SEL_VER"
2185
2186         local comp_file=$DIR/$tdir/$tfile
2187         test_mkdir -p $DIR/$tdir
2188
2189         wait_delete_completed
2190         wait_mds_ost_sync
2191
2192         pool_add $TESTNAME || error "Pool creation failed"
2193         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2194
2195         $LFS setstripe -E 64m -E 640M -z 64M -p $TESTNAME -E -1 $comp_file ||
2196                 error "Create $comp_file failed"
2197
2198         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2199
2200         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2201         RC=$?
2202
2203         ost_watermarks_clear_enospc $tfile 0 $wms
2204         [ $RC -eq 0 ] || error "dd append failed $RC"
2205
2206         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2207         local found=$($LFS find $flg_opts $comp_file | wc -l)
2208         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2209
2210         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
2211         [ "$ost_idx" != "" ] && error "Append: 0-length component still exists"
2212         ost_idx=$($LFS getstripe -I3 -i $comp_file)
2213         [ "$ost_idx" != "" ] && error "Append: extension component still exists"
2214
2215         sel_layout_sanity $comp_file 2
2216 }
2217 run_test 23e "Append with next real comp: spillover and backward extension"
2218
2219 test_23f() {
2220         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2221         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2222                 skip "skipped for lustre < $SEL_VER"
2223
2224         local comp_file=$DIR/$tdir/$tfile
2225         test_mkdir -p $DIR/$tdir
2226
2227         $LFS setstripe -z 64M -c 1 -E -1 $comp_file ||
2228                 error "Create $comp_file failed"
2229
2230         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
2231         local wms=$(ost_watermarks_set_low_space $ost_idx | grep "watermarks")
2232
2233         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2234         RC=$?
2235
2236         ost_watermarks_clear_enospc $tfile $ost_idx $wms
2237         [ $RC -eq 0 ] || error "dd append failed"
2238
2239         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2240         local found=$($LFS find $flg_opts $comp_file | wc -l)
2241         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2242
2243         ost_idx=$($LFS getstripe -I2 -i $comp_file)
2244         [ "$ost_idx" != "" ] && error "Append: extension component still exists"
2245
2246         sel_layout_sanity $comp_file 2
2247 }
2248 run_test 23f "Append with low on space: repeat and remove EXT comp"
2249
2250 OLDIFS="$IFS"
2251 cleanup_24() {
2252         trap 0
2253         IFS="$OLDIFS"
2254 }
2255
2256 test_24a() {
2257         [ "$OSTCOUNT" -lt "3" ] && skip_env "needs >= 3 OSTs"
2258
2259         trap cleanup_24 EXIT RETURN
2260
2261         local file=$DIR/$tfile
2262
2263         $LFS setstripe -E 1m -c1 -o0 -E eof -c2 -o1,2 $file ||
2264                 error "setstripe on $file"
2265
2266         dd if=/dev/zero of=$file bs=1M count=3 || error "dd failed for $file"
2267         sync
2268
2269         filefrag -ves $file || error "filefrag $file failed"
2270         filefrag_op=$(filefrag -ve -k $file |
2271                       sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2272
2273 #Filesystem type is: bd00bd0
2274 #File size of /mnt/lustre/f24a.sanity-pfl is 3145728 (3072 blocks of 1024 bytes)
2275 # ext:     device_logical:        physical_offset: length:  dev: flags:
2276 #   0:        0..    1023:    1572864..   1573887:   1024: 0000: net
2277 #   1:        0..    1023:    1572864..   1573887:   1024: 0002: net
2278 #   2:     1024..    2047:    1573888..   1574911:   1024: 0001: last,net
2279 #/mnt/lustre/f24a.sanity-pfl: 3 extents found
2280
2281         last_lun=$(echo $filefrag_op | cut -d: -f5)
2282
2283         IFS=$'\n'
2284         tot_len=0
2285         num_luns=1
2286         for line in $filefrag_op; do
2287                 frag_lun=$(echo $line | cut -d: -f5)
2288                 ext_len=$(echo $line | cut -d: -f4)
2289                 if [[ "$frag_lun" != "$last_lun" ]]; then
2290                         if (( tot_len != 1024 )); then
2291                                 cleanup_24
2292                                 error "$file: OST$last_lun $tot_len != 1024"
2293                         else
2294                                 (( num_luns += 1 ))
2295                                 tot_len=0
2296                         fi
2297                 fi
2298                 (( tot_len += ext_len ))
2299                 last_lun=$frag_lun
2300         done
2301         if (( num_luns != 3 || tot_len != 1024 )); then
2302                 cleanup_24
2303                 error "$file: $num_luns != 3, $tot_len != 1024 on OST$last_lun"
2304         fi
2305
2306         echo "FIEMAP on $file succeeded"
2307 }
2308 run_test 24a "FIEMAP upon PFL file"
2309
2310 complete $SECONDS
2311 check_and_cleanup_lustre
2312 exit_status