3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
8 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
11 # Bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_PFL_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
16 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
19 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
21 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 check_and_setup_lustre
29 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.51) ]]; then
30 skip_env "Need MDS version at least 2.9.51" && exit
35 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
36 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
37 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
40 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
42 local comp_file=$DIR/$tfile
43 local rw_len=$((3 * 1024 * 1024)) # 3M
47 $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $comp_file ||
48 error "Create $comp_file failed"
50 #instantiate all components, so that objs are allocted
51 dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1k
53 local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
54 local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
56 [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
58 small_write $comp_file $rw_len || error "Verify RW failed"
60 rm -f $comp_file || error "Delete $comp_file failed"
62 run_test 0 "Create full components file, no reused OSTs"
65 local comp_file=$DIR/$tfile
66 local rw_len=$((3 * 1024 * 1024)) # 3M
70 $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
71 error "Create $comp_file failed"
73 #instantiate all components, so that objs are allocted
74 dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1k
76 local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
77 local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
79 [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
81 small_write $comp_file $rw_len || error "Verify RW failed"
83 rm -f $comp_file || error "Delete $comp_file failed"
85 run_test 1 "Create full components file, reused OSTs"
88 local comp_file=$DIR/$tfile
89 local rw_len=$((5 * 1024 * 1024)) # 5M
93 $LFS setstripe -E 1m -S 1m $comp_file ||
94 error "Create $comp_file failed"
96 local comp_cnt=$($LFS getstripe --component-count $comp_file)
97 [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
99 dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
100 error "Write first component failed"
101 dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
102 error "Read first component failed"
104 dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
105 error "Write beyond component should fail"
106 dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
107 error "Read beyond component should short read, not fail"
109 $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
110 error "Add component to $comp_file failed"
112 comp_cnt=$($LFS getstripe --component-count $comp_file)
113 [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
115 $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
116 error "Add last component to $comp_file failed"
118 comp_cnt=$($LFS getstripe --component-count $comp_file)
119 [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
121 small_write $comp_file $rw_len || error "Verify RW failed"
123 rm -f $comp_file || error "Delete $comp_file failed"
125 run_test 2 "Add component to existing file"
127 del_comp_and_verify() {
134 if [ $id == "init" ]; then
135 opt="--component-flags"
138 $LFS setstripe --component-del $opt $id $comp_file ||
139 error "Delete component $id from $comp_file failed"
141 local comp_cnt=$($LFS getstripe --component-count $comp_file)
142 if grep -q "has no stripe info" <<< "$comp_cnt" ; then
145 [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
147 $CHECKSTAT -s $size $comp_file || error "size != $size"
151 local comp_file=$DIR/$tfile
155 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
156 error "Create $comp_file failed"
158 local comp_cnt=$($LFS getstripe --component-count $comp_file)
159 [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
161 dd if=/dev/zero of=$comp_file bs=1M count=2
163 $LFS setstripe --component-del -I 2 $comp_file &&
164 error "Component deletion makes hole"
166 del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
167 del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
168 del_comp_and_verify $comp_file 1 0 0
170 rm -f $comp_file || error "Delete $comp_file failed"
172 $LFS setstripe -E 1M -E 16M -E -1 $comp_file ||
173 error "Create second $comp_file failed"
175 #instantiate all components, so that objs are allocted
176 dd if=/dev/zero of=$comp_file bs=1k count=1 seek=16k
178 del_comp_and_verify $comp_file "init" 0 0
179 rm -f $comp_file || error "Delete second $comp_file failed"
181 run_test 3 "Delete component from existing file"
184 skip "Not supported in PFL" && return
185 # In PFL project, only LCME_FL_INIT is supported, and it can't
186 # be altered by application.
188 run_test 4 "Modify component flags in existing file"
191 local parent=$DIR/$tdir
192 local comp_file=$DIR/$tdir/$tfile
193 local subdir=$parent/subdir
196 mkdir -p $parent || error "Create dir $parent failed"
198 # set default layout to parent directory
199 $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
200 error "Set default layout to $parent failed"
202 # create file under parent
203 touch $comp_file || error "Create $comp_file failed"
204 local comp_cnt=$($LFS getstripe --component-count $comp_file)
205 [ $comp_cnt -ne 2 ] && error "file $comp_cnt != 2"
207 #instantiate all components, so that objs are allocted
208 dd if=/dev/zero of=$comp_file bs=1k count=1 seek=64k
210 local ost_idx=$($LFS getstripe -I 1 -i $comp_file)
211 [ $ost_idx -ne 0 ] &&
212 error "component 1 ost_idx $ost_idx != 0"
214 ost_idx=$($LFS getstripe -I 2 -i $comp_file)
215 [ $ost_idx -ne 0 ] &&
216 error "component 2 ost_idx $ost_idx != 0"
218 # create subdir under parent
219 mkdir -p $subdir || error "Create subdir $subdir failed"
221 comp_cnt=$($LFS getstripe -d --component-count $subdir)
222 [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
224 # create file under subdir
225 touch $subdir/$tfile || error "Create $subdir/$tfile failed"
227 comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
228 [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
230 # delete default layout setting from parent
231 $LFS setstripe -d $parent ||
232 error "Delete default layout from $parent failed"
234 comp_cnt=$($LFS getstripe -d --component-count $parent)
235 [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
237 rm -f $comp_file || error "Delete $comp_file failed"
238 rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
239 rm -r $subdir || error "Delete subdir $subdir failed"
240 rmdir $parent || error "Delete dir $parent failed"
242 run_test 5 "Inherit composite layout from parent directory"
245 local comp_file=$DIR/$tfile
249 $LFS setstripe -c 1 -S 128K $comp_file ||
250 error "Create v1 $comp_file failed"
252 local comp_cnt=$($LFS getstripe --component-count $comp_file)
253 [ ! -z "$comp_cnt" ] && error "Wrong component count $comp_cnt"
255 dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
256 error "Write to v1 $comp_file failed"
258 local old_chksum=$(md5sum $comp_file)
260 # Migrate v1 to composite
261 $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
262 error "Migrate(v1 -> composite) $comp_file failed"
264 comp_cnt=$($LFS getstripe --component-count $comp_file)
265 [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
267 local chksum=$(md5sum $comp_file)
268 [ "$old_chksum" != "$chksum" ] &&
269 error "(v1 -> compsoite) $old_chksum != $chksum"
271 # Migrate composite to composite
272 $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
273 -E -1 -S 3M -c 3 $comp_file ||
274 error "Migrate(compsoite -> composite) $comp_file failed"
276 comp_cnt=$($LFS getstripe --component-count $comp_file)
277 [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
279 chksum=$(md5sum $comp_file)
280 [ "$old_chksum" != "$chksum" ] &&
281 error "(composite -> compsoite) $old_chksum != $chksum"
283 # Migrate composite to v1
284 $LFS migrate -c 2 -S 2M $comp_file ||
285 error "Migrate(composite -> v1) $comp_file failed"
287 comp_cnt=$($LFS getstripe --component-count $comp_file)
288 [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
290 chksum=$(md5sum $comp_file)
291 [ "$old_chksum" != "$chksum" ] &&
292 error "(composite -> v1) $old_chksum != $chksum"
294 rm -f $comp_file || "Delete $comp_file failed"
296 run_test 6 "Migrate composite file"
299 mkdir -p $DIR/$tdir || error "mkdir failed"
300 chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
302 local comp_file=$DIR/$tdir/$tfile
303 $RUNAS $LFS setstripe -E 1M -c 1 $comp_file ||
304 error "Create composite file $comp_file failed"
306 $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
307 error "Add component to $comp_file failed"
309 $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
310 error "Delete component from $comp_file failed"
312 $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
313 error "Add last component to $comp_file failed"
315 rm $comp_file || "Delete composite failed"
317 run_test 7 "Add/Delete/Create composite file by non-privileged user"
320 local parent=$DIR/$tdir
323 mkdir -p $parent || error "Create dir $parent failed"
325 $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
326 -E -1 -c 4 -S 4M $parent ||
327 error "Set default layout to $parent failed"
329 sh rundbench -C -D $parent 2 || error "debench failed"
331 rm -fr $parent || error "Delete dir $parent failed"
333 run_test 8 "Run debench over composite files"
336 local comp_file=$DIR/$tfile
340 $LFS setstripe -E 1m -S 1m -E 2M -c 1 $comp_file ||
341 error "Create $comp_file failed"
343 local comp_cnt=$($LFS getstripe --component-count $comp_file)
344 [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
346 replay_barrier $SINGLEMDS
348 # instantiate the 2nd component
349 dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1k
351 local f1=$($LFS getstripe -I 2 $comp_file |
352 awk '/l_fid:/ {print $7}')
353 echo "before MDS recovery, the ost fid of 2nd component is $f1"
356 local f2=$($LFS getstripe -I 2 $comp_file |
357 awk '/l_fid:/ {print $7}')
358 echo "after MDS recovery, the ost fid of 2nd component is $f2"
359 [ $f1 == $f2 ] || error "$f1 != $f2"
361 run_test 9 "Replay layout extend object instantiation"
364 echo $($LFS getstripe $1 |
365 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
366 $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
367 $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
371 local parent=$DIR/$tdir
374 $LFS setstripe -d $MOUNT || error "clear root layout"
376 # set root composite layout
377 $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
378 -E -1 -c 4 -S 4M $MOUNT ||
379 error "Set root layout failed"
381 mkdir -p $parent || error "Create dir $parent failed"
382 # set a different layout for parent
383 $LFS setstripe -E -1 -c 1 -S 1M $parent ||
384 error "set $parent layout failed"
387 local f1_entry=$(component_dump $parent/file1)
389 # delete parent's layout
390 $LFS setstripe -d $parent || error "Clear $parent layout failed"
393 local f2_entry=$(component_dump $parent/file2)
395 # verify layout inheritance
397 local f1_expect="1[0,EOF]"
398 local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
400 echo "f1 expect=$f1_expect"
401 echo "f1 get =$f1_entry"
402 echo "f2 expect=$f2_expect"
403 echo "f2 get =$f2_entry"
405 [ x$f1_expect != x$f1_entry ] &&
406 error "$parent/file1 does not inherite parent layout"
407 [ x$f2_expect != x$f2_entry ] &&
408 error "$parent/file2 does not inherite root layout"
411 run_test 10 "Inherit composite template from root"
414 local comp_file=$DIR/$tfile
417 # only 1st component instantiated
418 $LFS setstripe -E 1m -E 2m -E 3m -E -1 $comp_file ||
419 error "Create $comp_file failed"
421 local f1=$($LFS getstripe -I 1 $comp_file | grep "l_fid")
422 [[ -z $f1 ]] && error "1: 1st component uninstantiated"
423 local f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid")
424 [[ -n $f2 ]] && error "1: 2nd component instantiated"
425 local f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid")
426 [[ -n $f3 ]] && error "1: 3rd component instantiated"
427 local f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
428 [[ -n $f4 ]] && error "1: 4th component instantiated"
430 # the first 2 components instantiated
431 $TRUNCATE $comp_file $((1024*1024*1+1))
433 f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid")
434 [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
435 f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid")
436 [[ -n $f3 ]] && error "2: 3rd component instantiated"
437 f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
438 [[ -n $f4 ]] && error "2: 4th component instantiated"
440 # the first 3 components instantiated
441 $TRUNCATE $comp_file $((1024*1024*3))
442 $TRUNCATE $comp_file $((1024*1024*1+1))
444 f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid")
445 [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
446 f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid")
447 [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
448 f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
449 [[ -n $f4 ]] && error "3: 4th component instantiated"
451 # all 4 components instantiated
452 dd if=/dev/zero of=$comp_file bs=1k count=1 seek=3k
454 f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
455 [[ -z $f4 ]] && error "4: 4th component uninstantiated"
459 run_test 11 "Verify component instantiation with write/truncate"
462 [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
464 local file=$DIR/$tfile
467 # specify ost list for component
468 $LFS setstripe -E1m -c2 -o0,1 -E2m -c2 -o1,2 -E3m -c2 -o2,1 \
469 -E4m -c2 -o2,0 -E-1 $file ||
470 error "Create $file failed"
471 # instantiate all components
472 $TRUNCATE $file $((1024*1024*4+1))
474 #verify object alloc order
475 local o1=$($LFS getstripe -I1 $file |
476 awk '/l_ost_idx:/ {printf("%d",$5)}')
477 [[ $o1 != "01" ]] && error "$o1 is not 01"
479 local o2=$($LFS getstripe -I2 $file |
480 awk '/l_ost_idx:/ {printf("%d",$5)}')
481 [[ $o2 != "12" ]] && error "$o2 is not 12"
483 local o3=$($LFS getstripe -I3 $file |
484 awk '/l_ost_idx:/ {printf("%d",$5)}')
485 [[ $o3 != "21" ]] && error "$o3 is not 21"
487 local o4=$($LFS getstripe -I4 $file |
488 awk '/l_ost_idx:/ {printf("%d",$5)}')
489 [[ $o4 != "20" ]] && error "$o4 is not 20"
493 run_test 12 "Verify ost list specification"
496 check_and_cleanup_lustre