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