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