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