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