Whamcloud - gitweb
b21434cbd70c0fdee3d823d72c1b33f4a7f51fef
[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 check_component_count() {
178         local comp_cnt=$($LFS getstripe --component-count $1)
179         [ $comp_cnt -ne $2 ] && error "$1, component count $comp_cnt != $2"
180 }
181
182 test_2() {
183         local comp_file=$DIR/$tdir/$tfile
184         local rw_len=$((5 * 1024 * 1024))       # 5M
185
186         test_mkdir $DIR/$tdir
187         rm -f $comp_file
188
189         $LFS setstripe -E 1m -S 1m $comp_file ||
190                 error "Create $comp_file failed"
191
192         check_component_count $comp_file 1
193
194         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
195                 error "Write first component failed"
196         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
197                 error "Read first component failed"
198
199         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
200                 error "Write beyond component should fail"
201         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
202                 error "Read beyond component should short read, not fail"
203
204         $LFS setstripe --component-add -E 2M -S 1M -c 1 $comp_file ||
205                 error "Add component to $comp_file failed"
206
207         check_component_count $comp_file 2
208
209         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
210                 error "Add last component to $comp_file failed"
211
212         check_component_count $comp_file 3
213
214         small_write $comp_file $rw_len || error "Verify RW failed"
215
216         rm -f $comp_file || error "Delete $comp_file failed"
217 }
218 run_test 2 "Add component to existing file"
219
220 del_comp_and_verify() {
221         local comp_file=$1
222         local id=$2
223         local left=$3
224         local size=$4
225
226         local opt="-I "
227         if [ $id == "init" -o $id == "^init" ]; then
228                 opt="--component-flags="
229         fi
230
231         $LFS setstripe --component-del $opt$id $comp_file ||
232                 error "Delete component $id from $comp_file failed"
233
234         local comp_cnt=$($LFS getstripe --component-count $comp_file)
235         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
236                 comp_cnt=0
237         fi
238         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
239
240         $CHECKSTAT -s $size $comp_file || error "size != $size"
241 }
242
243 test_3() {
244         local comp_file=$DIR/$tdir/$tfile
245
246         test_mkdir $DIR/$tdir
247         rm -f $comp_file
248
249         $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
250                 error "Create $comp_file failed"
251
252         check_component_count $comp_file 3
253
254         dd if=/dev/zero of=$comp_file bs=1M count=2
255
256         $LFS setstripe --component-del -I 2 $comp_file &&
257                 error "Component deletion makes hole"
258
259         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
260         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
261         del_comp_and_verify $comp_file 1 0 0
262
263         rm -f $comp_file || error "Delete $comp_file failed"
264
265         $LFS setstripe -E 1M -S 1M -E 16M -E -1 $comp_file ||
266                 error "Create second $comp_file failed"
267
268         del_comp_and_verify $comp_file "^init" 1 0
269         del_comp_and_verify $comp_file "init" 0 0
270         rm -f $comp_file || error "Delete second $comp_file failed"
271
272 }
273 run_test 3 "Delete component from existing file"
274
275 test_4() {
276         skip "Not supported in PFL"
277         # In PFL project, only LCME_FL_INIT is supported, and it can't
278         # be altered by application.
279 }
280 run_test 4 "Modify component flags in existing file"
281
282 test_5() {
283         local parent=$DIR/$tdir
284         local comp_file=$DIR/$tdir/$tfile
285         local subdir=$parent/subdir
286
287         rm -fr $parent
288         test_mkdir $parent
289
290         # set default layout to parent directory
291         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
292                 error "Set default layout to $parent failed"
293
294         # create file under parent
295         touch $comp_file || error "Create $comp_file failed"
296         check_component_count $comp_file 2
297
298         #instantiate all components, so that objs are allocted
299         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k
300
301         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
302         [ $ost_idx -ne 0 ] &&
303                 error "component 1 ost_idx $ost_idx != 0"
304
305         ost_idx=$($LFS getstripe -I2 -i $comp_file)
306         [ $ost_idx -ne 0 ] &&
307                 error "component 2 ost_idx $ost_idx != 0"
308
309         # create subdir under parent
310         mkdir -p $subdir || error "Create subdir $subdir failed"
311
312         comp_cnt=$($LFS getstripe -d --component-count $subdir)
313         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
314
315         # create file under subdir
316         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
317
318         check_component_count $subdir/$tfile 2
319
320         # delete default layout setting from parent
321         $LFS setstripe -d $parent ||
322                 error "Delete default layout from $parent failed"
323
324         comp_cnt=$($LFS getstripe -d --component-count $parent)
325         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
326
327         rm -f $comp_file || error "Delete $comp_file failed"
328         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
329         rm -r $subdir || error "Delete subdir $subdir failed"
330         rmdir $parent || error "Delete dir $parent failed"
331 }
332 run_test 5 "Inherit composite layout from parent directory"
333
334 test_6() {
335         local comp_file=$DIR/$tdir/$tfile
336
337         test_mkdir $DIR/$tdir
338         rm -f $DIR/$tfile
339
340         $LFS setstripe -c 1 -S 128K $comp_file ||
341                 error "Create v1 $comp_file failed"
342
343         check_component_count $comp_file 0
344
345         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
346                 error "Write to v1 $comp_file failed"
347
348         local old_chksum=$(md5sum $comp_file)
349
350         # Migrate v1 to composite
351         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
352                 error "Migrate(v1 -> composite) $comp_file failed"
353
354         check_component_count $comp_file 2
355
356         local chksum=$(md5sum $comp_file)
357         [ "$old_chksum" != "$chksum" ] &&
358                 error "(v1 -> compsoite) $old_chksum != $chksum"
359
360         # Migrate composite to composite
361         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
362                 -E -1 -S 3M -c 3 $comp_file ||
363                 error "Migrate(compsoite -> composite) $comp_file failed"
364
365         check_component_count $comp_file 3
366
367         chksum=$(md5sum $comp_file)
368         [ "$old_chksum" != "$chksum" ] &&
369                 error "(composite -> compsoite) $old_chksum != $chksum"
370
371         # Migrate composite to v1
372         $LFS migrate -c 2 -S 2M $comp_file ||
373                 error "Migrate(composite -> v1) $comp_file failed"
374
375         check_component_count $comp_file 0
376
377         chksum=$(md5sum $comp_file)
378         [ "$old_chksum" != "$chksum" ] &&
379                 error "(composite -> v1) $old_chksum != $chksum"
380
381         rm -f $comp_file || "Delete $comp_file failed"
382 }
383 run_test 6 "Migrate composite file"
384
385 test_7() {
386         test_mkdir $DIR/$tdir
387         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
388
389         local comp_file=$DIR/$tdir/$tfile
390         $RUNAS $LFS setstripe -E 1M -S 1M -c 1 $comp_file ||
391                 error "Create composite file $comp_file failed"
392
393         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
394                 error "Add component to $comp_file failed"
395
396         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
397                 error "Delete component from $comp_file failed"
398
399         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
400                 error "Add last component to $comp_file failed"
401
402         rm $comp_file || "Delete composite failed"
403 }
404 run_test 7 "Add/Delete/Create composite file by non-privileged user"
405
406 test_8() {
407         local parent=$DIR/$tdir
408
409         rm -fr $parent
410         test_mkdir $parent
411
412         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
413                 -E -1 -c 4 -S 4M $parent ||
414                 error "Set default layout to $parent failed"
415
416         sh rundbench -C -D $parent 2 || error "dbench failed"
417
418         rm -fr $parent || error "Delete dir $parent failed"
419 }
420 run_test 8 "Run dbench over composite files"
421
422 test_9() {
423         local comp_file=$DIR/$tdir/$tfile
424
425         test_mkdir $DIR/$tdir
426         rm -f $comp_file
427
428         $LFS setstripe -E 1M -S 1M -E -1 -c 1 $comp_file ||
429                 error "Create $comp_file failed"
430
431         check_component_count $comp_file 2
432
433         replay_barrier $SINGLEMDS
434
435         # instantiate the 2nd component
436         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
437
438         local f1=$($LFS getstripe -I2 $comp_file |
439                         awk '/l_fid:/ {print $7}')
440         echo "before MDS recovery, the ost fid of 2nd component is $f1"
441         fail $SINGLEMDS
442
443         local f2=$($LFS getstripe -I2 $comp_file |
444                         awk '/l_fid:/ {print $7}')
445         echo "after MDS recovery, the ost fid of 2nd component is $f2"
446         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
447 }
448 run_test 9 "Replay layout extend object instantiation"
449
450 component_dump() {
451         echo $($LFS getstripe $1 |
452                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
453                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
454                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
455 }
456
457 test_10() {
458         local parent=$DIR/$tdir
459         local root=$MOUNT
460
461         save_layout_restore_at_exit $MOUNT
462
463         rm -rf $parent
464
465         # mount root on $MOUNT2 if FILESET is set
466         if [ -n "$FILESET" ]; then
467                 FILESET="" mount_client $MOUNT2 ||
468                         error "mount $MOUNT2 fail"
469                 root=$MOUNT2
470         fi
471
472         $LFS setstripe -d $root || error "clear root layout"
473
474         # set root composite layout
475         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
476                 -E -1 -c 4 -S 4M $root ||
477                 error "Set root layout failed"
478
479         if [ "$root" == "$MOUNT2" ]; then
480                 umount_client $MOUNT2 ||
481                         error "umount $MOUNT2 fail"
482         fi
483
484         test_mkdir $parent
485         # set a different layout for parent
486         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
487                 error "set $parent layout failed"
488         touch $parent/file1
489
490         local f1_entry=$(component_dump $parent/file1)
491
492         # delete parent's layout
493         $LFS setstripe -d $parent || error "Clear $parent layout failed"
494         touch $parent/file2
495
496         local f2_entry=$(component_dump $parent/file2)
497
498         # verify layout inheritance
499         local eof="EOF"
500         local f1_expect="1[0,EOF]"
501         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
502
503         echo "f1 expect=$f1_expect"
504         echo "f1 get   =$f1_entry"
505         echo "f2 expect=$f2_expect"
506         echo "f2 get   =$f2_entry"
507
508         [  x$f1_expect != x$f1_entry ] &&
509                 error "$parent/file1 does not inherite parent layout"
510         [  x$f2_expect != x$f2_entry ] &&
511                 error "$parent/file2 does not inherite root layout"
512
513         return 0
514 }
515 run_test 10 "Inherit composite template from root"
516
517 test_11() {
518         local comp_file=$DIR/$tdir/$tfile
519         test_mkdir $DIR/$tdir
520         rm -f $comp_file
521
522         # only 1st component instantiated
523         $LFS setstripe -E 1M -S 1M -E 2M -E 3M -E -1 $comp_file ||
524                 error "Create $comp_file failed"
525
526         local f1=$($LFS getstripe -I1 $comp_file | grep "l_fid")
527         [[ -z $f1 ]] && error "1: 1st component uninstantiated"
528         local f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
529         [[ -n $f2 ]] && error "1: 2nd component instantiated"
530         local f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
531         [[ -n $f3 ]] && error "1: 3rd component instantiated"
532         local f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
533         [[ -n $f4 ]] && error "1: 4th component instantiated"
534
535         # the first 2 components instantiated
536         $TRUNCATE $comp_file $((1024*1024*1+1))
537
538         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
539         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
540         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
541         [[ -n $f3 ]] && error "2: 3rd component instantiated"
542         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
543         [[ -n $f4 ]] && error "2: 4th component instantiated"
544
545         # the first 3 components instantiated
546         $TRUNCATE $comp_file $((1024*1024*3))
547         $TRUNCATE $comp_file $((1024*1024*1+1))
548
549         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
550         [[ -z $f2 ]] && error "3: 2nd component uninstantiated"
551         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
552         [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
553         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
554         [[ -n $f4 ]] && error "3: 4th component instantiated"
555
556         # all 4 components instantiated, using append write
557         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
558         ls -l $comp_file
559         rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1
560         ls -l $comp_file
561
562         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
563         [[ -z $f4 ]] && error "4: 4th component uninstantiated"
564
565         return 0
566 }
567 run_test 11 "Verify component instantiation with write/truncate"
568
569 test_12() {
570         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs"
571
572         local file=$DIR/$tdir/$tfile
573         test_mkdir $DIR/$tdir
574         rm -f $file
575
576         # specify ost list for component
577         $LFS setstripe -E 1M -S 1M -c 2 -o 0,1 -E 2M -c 2 -o 1,2 \
578                 -E 3M -c 2 -o 2,1 -E 4M -c 1 -i 2 -E -1 $file ||
579                 error "Create $file failed"
580
581         # clear lod component cache
582         stop $SINGLEMDS || error "stop MDS"
583         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
584         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
585
586         # instantiate all components
587         $TRUNCATE $file $((1024*1024*4+1))
588
589         #verify object alloc order
590         local o1=$($LFS getstripe -I1 $file |
591                         awk '/l_ost_idx:/ {printf("%d",$5)}')
592         [[ $o1 != "01" ]] && error "$o1 is not 01"
593
594         local o2=$($LFS getstripe -I2 $file |
595                         awk '/l_ost_idx:/ {printf("%d",$5)}')
596         [[ $o2 != "12" ]] && error "$o2 is not 12"
597
598         local o3=$($LFS getstripe -I3 $file |
599                         awk '/l_ost_idx:/ {printf("%d",$5)}')
600         [[ $o3 != "21" ]] && error "$o3 is not 21"
601
602         local o4=$($LFS getstripe -I4 $file |
603                         awk '/l_ost_idx:/ {printf("%d",$5)}')
604         [[ $o4 != "2" ]] && error "$o4 is not 2"
605
606         return 0
607 }
608 run_test 12 "Verify ost list specification"
609
610 test_13() { # LU-9311
611         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs"
612
613         local file=$DIR/$tfile
614         local dd_count=4
615         local dd_size=$(($dd_count * 1024 * 1024))
616         local real_size
617
618         rm -f $file
619         $LFS setstripe -E 1M -S 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
620                 error "Create $file failed"
621         dd if=/dev/zero of=$file bs=1M count=$dd_count
622         real_size=$(stat -c %s $file)
623         [ $real_size -eq $dd_size ] ||
624                 error "dd actually wrote $real_size != $dd_size bytes"
625
626         rm -f $file
627 }
628 run_test 13 "shouldn't reprocess granted resent request"
629
630 test_14() {
631         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
632         local file=$DIR/$tdir/$tfile
633         test_mkdir -p $DIR/$tdir
634         rm -f $file
635
636         $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
637                         -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
638                 error "Create $file failed"
639
640         # check --pool inheritance
641         local pool
642         pool="$($LFS getstripe -I2 --pool $file)"
643         [ x"$pool" != "xpool1" ] && $LFS getstripe -I2 $file &&
644                 error "$file: component 2 doesn't have poolname pool1"
645         pool="$($LFS getstripe -I4 --pool $file)"
646         [ x"$pool" != "xpool2" ] && $LFS getstripe -I4 $file &&
647                 error "$file: component 4 doesn't have poolname pool2"
648
649         #check --stripe-count inheritance
650         local count
651         count="$($LFS getstripe -I2 -c $file)"
652         [ $count -ne 1 ] && $LFS getstripe -I2 $file &&
653                 error "$file: component 2 doesn't have 1 stripe_count"
654         count="$($LFS getstripe -I4 -c $file)"
655         [ $count -ne 2 ] && $LFS getstripe -I4 $file &&
656                 error "$file: component 4 doesn't have 2 stripe_count"
657
658         #check --stripe-size inheritance
659         local size
660         size="$($LFS getstripe -I2 -S $file)"
661         [ $size -ne $((1024*1024)) ] && $LFS getstripe -I2 $file &&
662                 error "$file: component 2 doesn't have 1M stripe_size"
663         size="$($LFS getstripe -I4 -S $file)"
664         [ $size -ne $((1024*1024*2)) ] && $LFS getstripe -I4 $file &&
665                 error "$file: component 4 doesn't have 2M stripe_size"
666
667         return 0
668 }
669 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
670
671 test_15() {
672         local parent=$DIR/$tdir
673
674         rm -fr $parent
675         test_mkdir $parent
676
677         $LFS setstripe -d $parent || error "delete default layout"
678
679         $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1"
680         $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
681         test_mkdir $parent/subdir
682         $LFS setstripe -E 6M -S 1M -E 30M -E eof $parent/subdir ||
683                 error "setstripe to subdir"
684         $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
685         $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
686
687         # none
688         local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
689         [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
690
691         # f2, f3
692         found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
693         [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
694
695         # subdir
696         found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
697         [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
698
699         local flg_opts="--component-flags init"
700         # none
701         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
702         [ $found -eq 0 ] ||
703                 error "before write: start=1M, end=10M, flag=init, $found != 0"
704
705         dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
706                 error "dd $parent/f1 failed"
707
708         # f1
709         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
710         [ $found -eq 1 ] ||
711                 error "after write: start=1M, end=10M, flag=init, $found != 1"
712
713         local ext_opts="--component-start -1M -E +5M"
714         # parent, subdir, f3, f4
715         found=$($LFS find $ext_opts $parent | wc -l)
716         [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
717
718         local cnt_opts="--component-count +2"
719         # subdir
720         found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
721         [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
722
723         # none
724         found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
725         [ $found -eq 0 ] ||
726                 error "start-1M, end+5M, count+2, flag=init, $found != 0"
727
728         # f3, f4
729         found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
730         [ $found -eq 2 ] ||
731                 error "start-1M, end+5M, !count+2, flag=init, $found != 2"
732 }
733 run_test 15 "Verify component options for lfs find"
734
735 test_16a() {
736         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
737         large_xattr_enabled || skip_env "ea_inode feature disabled"
738
739         local file=$DIR/$tdir/$tfile
740         local dir=$DIR/$tdir/dir
741         local temp=$DIR/$tdir/template
742         rm -rf $DIR/$tdir
743         test_mkdir $DIR/$tdir
744
745         #####################################################################
746         #                           1. PFL file
747         # set stripe for source file
748         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
749                 $file || error "Create $file failed"
750
751         echo "1. PFL file"
752         verify_yaml_layout $file $file.copy $temp "1. PFL file"
753
754         #####################################################################
755         #                           2. plain file
756         # set stripe for source file
757         rm -f $file
758         $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
759
760         rm -f $file.copy
761         echo "2. plain file"
762         verify_yaml_layout $file $file.copy $temp "2. plain file"
763
764         #####################################################################
765         #                           3. PFL dir
766         # set stripe for source dir
767         test_mkdir $dir
768         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
769                 error "setstripe $dir failed"
770
771         test_mkdir $dir.copy
772         echo "3. PFL dir"
773         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
774
775         #####################################################################
776         #                           4. plain dir
777         # set stripe for source dir
778         $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
779
780         echo "4. plain dir"
781         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
782 }
783 run_test 16a "Verify setstripe/getstripe with YAML config file"
784
785 test_16b() {
786         [[ $($LCTL get_param mdc.*.import |
787                 grep "connect_flags:.*overstriping") ]] ||
788                 skip "server does not support overstriping"
789         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
790         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
791                 skip_env "too many osts, skipping"
792         large_xattr_enabled || skip_env "ea_inode feature disabled"
793
794         local file=$DIR/$tdir/$tfile
795         local dir=$DIR/$tdir/dir
796         local temp=$DIR/$tdir/template
797         # We know OSTCOUNT < (LOV_MAX_STRIPE_COUNT / 2), so this is overstriping
798         local large_count=$((LOV_MAX_STRIPE_COUNT / 2 + 10))
799
800         rm -rf $DIR/$tdir
801         test_mkdir $DIR/$tdir
802
803         #####################################################################
804         #                           1. PFL file, overstriping in first comps
805         # set stripe for source file
806         $LFS setstripe -E1m -S 1M -o0,0 -E2m -o1,1 -E3m -C $large_count -E-1 \
807                 $file || error "Create $file failed"
808
809         echo "1. PFL file"
810         verify_yaml_layout $file $file.copy $temp "1. PFL file"
811
812         #####################################################################
813         #                           2. plain file + overstriping
814         # set stripe for source file
815         rm -f $file
816         $LFS setstripe -C $large_count -i1 $file || error "Create $file failed"
817
818         rm -f $file.copy
819         echo "2. plain file"
820         verify_yaml_layout $file $file.copy $temp "2. plain file"
821
822         #####################################################################
823         #                           3. PFL dir + overstriping
824         # set stripe for source dir
825         test_mkdir $dir
826         $LFS setstripe -E1m -S 1M -o 0,0 -E2m -C $large_count -E-1 $dir ||
827                 error "setstripe $dir failed"
828
829         test_mkdir $dir.copy
830         echo "3. PFL dir"
831         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
832
833         #####################################################################
834         #                           4. plain dir + overstriping
835         # set stripe for source dir
836         $LFS setstripe -C $large_count $dir || error "setstripe $dir failed"
837
838         echo "4. plain dir"
839         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
840 }
841 run_test 16b "Verify setstripe/getstripe with YAML config file + overstriping"
842
843 test_17() {
844         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
845         local file=$DIR/$tdir/$tfile
846         test_mkdir -p $DIR/$tdir
847         rm -f $file
848
849         $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E -1 -c -1 $file ||
850                 error "Create $file failed"
851
852         local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
853         local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
854         local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
855         echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
856
857         # init 2nd component
858         $TRUNCATE $file $((1024*1024+1))
859         local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
860         local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
861         echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
862
863         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
864         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
865
866         # init 3rd component
867         $TRUNCATE $file $((1024*1024*2+1))
868         s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
869         s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
870         local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
871         echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
872
873         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
874         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
875         [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
876 }
877 run_test 17 "Verify LOVEA grows with more component inited"
878
879 check_distribution() {
880         local file=$1
881         local objs
882         local ave
883         local obj_min_one=$((OSTCOUNT - 1))
884
885         objs=$($LFS getstripe $file |
886                 awk '/l_ost_idx:/ { print $5 }' | wc -l)
887         let ave=$((objs / OSTCOUNT))
888
889         # collect objects per OST distribution
890         $LFS getstripe $file | awk '/l_ost_idx:/ { print $5 }' | tr -d "," |
891                 (inuse=( $(for i in $(seq 0 $obj_min_one); do echo 0; done) )
892                 while read O; do
893                         let inuse[$O]=$((1 + ${inuse[$O]}))
894                 done;
895
896                 # verify object distribution varies no more than +-1
897                 for idx in $(seq 0 $obj_min_one); do
898                         let dif=$((${inuse[$idx]} - ave))
899                         let dif=${dif#-}
900                         if [ "$dif" -gt 1 ]; then
901                                 echo "OST${idx}: ${inuse[$idx]} objects"
902                                 error "bad distribution on OST${idx}"
903                         fi
904                 done)
905 }
906
907 test_18() {
908         local file1=$DIR/${tfile}-1
909         local file2=$DIR/${tfile}-2
910         local file3=$DIR/${tfile}-3
911
912         rm -f $file1 $file2 $file3
913
914         $LFS setstripe -E 1m -S 1m $file1 ||
915                 error "Create $file1 failed"
916         $LFS setstripe -E 1m -S 1m $file2 ||
917                 error "Create $file2 failed"
918         $LFS setstripe -E 1m -S 1m $file3 ||
919                 error "Create $file3 failed"
920
921         local objs=$((OSTCOUNT+1))
922         for comp in $(seq 1 $OSTCOUNT); do
923                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file1 ||
924                         error "Add component to $file1 failed 2"
925                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file2 ||
926                         error "Add component to $file2 failed 2"
927                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file3 ||
928                         error "Add component to $file3 failed 2"
929         done
930
931         $LFS setstripe --component-add -E -1 -c -1 $file1 ||
932                 error "Add component to $file1 failed 3"
933         $LFS setstripe --component-add -E -1 -c -1 $file2 ||
934                 error "Add component to $file2 failed 3"
935         $LFS setstripe --component-add -E -1 -c -1 $file3 ||
936                 error "Add component to $file3 failed 3"
937
938         # Instantiate all components
939         dd if=/dev/urandom of=$file1 bs=1M count=$((objs+1)) ||
940                 error "dd failed for $file1"
941         dd if=/dev/urandom of=$file2 bs=1M count=$((objs+1)) ||
942                 error "dd failed for $file2"
943         dd if=/dev/urandom of=$file3 bs=1M count=$((objs+1)) ||
944                 error "dd failed for $file3"
945
946         check_distribution $file1
947         check_distribution $file2
948         check_distribution $file3
949
950 }
951 run_test 18 "check component distribution"
952
953 complete $SECONDS
954 check_and_cleanup_lustre
955 exit_status