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