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 local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
51 local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
53 [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
55 small_write $comp_file $rw_len || error "Verify RW failed"
57 rm -f $comp_file || error "Delete $comp_file failed"
59 run_test 0 "Create full components file, no reused OSTs"
62 local comp_file=$DIR/$tfile
63 local rw_len=$((3 * 1024 * 1024)) # 3M
67 $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
68 error "Create $comp_file failed"
70 local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
71 local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
73 [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
75 small_write $comp_file $rw_len || error "Verify RW failed"
77 rm -f $comp_file || error "Delete $comp_file failed"
79 run_test 1 "Create full components file, reused OSTs"
82 local comp_file=$DIR/$tfile
83 local rw_len=$((5 * 1024 * 1024)) # 5M
87 $LFS setstripe -E 1m -S 1m $comp_file ||
88 error "Create $comp_file failed"
90 local comp_cnt=$($LFS getstripe --component-count $comp_file)
91 [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
93 dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
94 error "Write first component failed"
95 dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
96 error "Read first component failed"
98 dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
99 error "Write beyond component should fail"
100 dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 &&
101 error "Read beyond component should fail"
103 $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
104 error "Add component to $comp_file failed"
106 comp_cnt=$($LFS getstripe --component-count $comp_file)
107 [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
109 $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
110 error "Add last component to $comp_file failed"
112 comp_cnt=$($LFS getstripe --component-count $comp_file)
113 [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
115 small_write $comp_file $rw_len || error "Verify RW failed"
117 rm -f $comp_file || error "Delete $comp_file failed"
119 run_test 2 "Add component to existing file"
121 del_comp_and_verify() {
128 if [ $id == "init" ]; then
129 opt="--component-flags"
132 $LFS setstripe --component-del $opt $id $comp_file ||
133 error "Delete component $id from $comp_file failed"
135 local comp_cnt=$($LFS getstripe --component-count $comp_file)
136 if grep -q "has no stripe info" <<< "$comp_cnt" ; then
139 [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
141 $CHECKSTAT -s $size $comp_file || error "size != $size"
145 local comp_file=$DIR/$tfile
149 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
150 error "Create $comp_file failed"
152 local comp_cnt=$($LFS getstripe --component-count $comp_file)
153 [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
155 dd if=/dev/zero of=$comp_file bs=1M count=2
157 $LFS setstripe --component-del -I 2 $comp_file &&
158 error "Component deletion makes hole"
160 del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
161 del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
162 del_comp_and_verify $comp_file 1 0 0
164 rm -f $comp_file || error "Delete $comp_file failed"
166 $LFS setstripe -E 1M -E 16M -E -1 $comp_file ||
167 error "Create second $comp_file failed"
169 del_comp_and_verify $comp_file "init" 0 0
170 rm -f $comp_file || error "Delete second $comp_file failed"
172 run_test 3 "Delete component from existing file"
175 skip "Not supported in PFL" && return
176 # In PFL project, only LCME_FL_INIT is supported, and it can't
177 # be altered by application.
179 run_test 4 "Modify component flags in existing file"
182 local parent=$DIR/$tdir
183 local comp_file=$DIR/$tdir/$tfile
184 local subdir=$parent/subdir
187 mkdir -p $parent || error "Create dir $parent failed"
189 # set default layout to parent directory
190 $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
191 error "Set default layout to $parent failed"
193 # create file under parent
194 touch $comp_file || error "Create $comp_file failed"
195 local comp_cnt=$($LFS getstripe --component-count $comp_file)
196 [ $comp_cnt -ne 2 ] && error "file $comp_cnt != 2"
198 local ost_idx=$($LFS getstripe -I 1 -i $comp_file)
199 [ $ost_idx -ne 0 ] &&
200 error "component 1 ost_idx $ost_idx != 0"
202 ost_idx=$($LFS getstripe -I 2 -i $comp_file)
203 [ $ost_idx -ne 0 ] &&
204 error "component 2 ost_idx $ost_idx != 0"
206 # create subdir under parent
207 mkdir -p $subdir || error "Create subdir $subdir failed"
209 comp_cnt=$($LFS getstripe -d --component-count $subdir)
210 [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
212 # create file under subdir
213 touch $subdir/$tfile || error "Create $subdir/$tfile failed"
215 comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
216 [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
218 # delete default layout setting from parent
219 $LFS setstripe -d $parent ||
220 error "Delete default layout from $parent failed"
222 comp_cnt=$($LFS getstripe -d --component-count $parent)
223 [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
225 rm -f $comp_file || error "Delete $comp_file failed"
226 rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
227 rm -r $subdir || error "Delete subdir $subdir failed"
228 rmdir $parent || error "Delete dir $parent failed"
230 run_test 5 "Inherit composite layout from parent directory"
233 local comp_file=$DIR/$tfile
237 $LFS setstripe -c 1 -S 128K $comp_file ||
238 error "Create v1 $comp_file failed"
240 local comp_cnt=$($LFS getstripe --component-count $comp_file)
241 [ ! -z "$comp_cnt" ] && error "Wrong component count $comp_cnt"
243 dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
244 error "Write to v1 $comp_file failed"
246 local old_chksum=$(md5sum $comp_file)
248 # Migrate v1 to composite
249 $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
250 error "Migrate(v1 -> composite) $comp_file failed"
252 comp_cnt=$($LFS getstripe --component-count $comp_file)
253 [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
255 local chksum=$(md5sum $comp_file)
256 [ "$old_chksum" != "$chksum" ] &&
257 error "(v1 -> compsoite) $old_chksum != $chksum"
259 # Migrate composite to composite
260 $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
261 -E -1 -S 3M -c 3 $comp_file ||
262 error "Migrate(compsoite -> composite) $comp_file failed"
264 comp_cnt=$($LFS getstripe --component-count $comp_file)
265 [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
267 chksum=$(md5sum $comp_file)
268 [ "$old_chksum" != "$chksum" ] &&
269 error "(composite -> compsoite) $old_chksum != $chksum"
271 # Migrate composite to v1
272 $LFS migrate -c 2 -S 2M $comp_file ||
273 error "Migrate(composite -> v1) $comp_file failed"
275 comp_cnt=$($LFS getstripe --component-count $comp_file)
276 [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
278 chksum=$(md5sum $comp_file)
279 [ "$old_chksum" != "$chksum" ] &&
280 error "(composite -> v1) $old_chksum != $chksum"
282 rm -f $comp_file || "Delete $comp_file failed"
284 run_test 6 "Migrate composite file"
287 mkdir -p $DIR/$tdir || error "mkdir failed"
288 chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
290 local comp_file=$DIR/$tdir/$tfile
291 $RUNAS $LFS setstripe -E 1M -c 1 $comp_file ||
292 error "Create composite file $comp_file failed"
294 $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
295 error "Add component to $comp_file failed"
297 $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
298 error "Delete component from $comp_file failed"
300 $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
301 error "Add last component to $comp_file failed"
303 rm $comp_file || "Delete composite failed"
305 run_test 7 "Add/Delete/Create composite file by non-privileged user"
308 local parent=$DIR/$tdir
311 mkdir -p $parent || error "Create dir $parent failed"
313 $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
314 -E -1 -c 4 -S 4M $parent ||
315 error "Set default layout to $parent failed"
317 sh rundbench -C -D $parent 2 || error "debench failed"
319 rm -fr $parent || error "Delete dir $parent failed"
321 run_test 8 "Run debench over composite files"
324 local comp_file=$DIR/$tfile
328 $LFS setstripe -E 1m -S 1m $comp_file ||
329 error "Create $comp_file failed"
331 local comp_cnt=$($LFS getstripe --component-count $comp_file)
332 [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
334 replay_barrier $SINGLEMDS
336 $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
337 error "Add component to $comp_file failed"
339 local f1=$($LFS getstripe -I 2 $comp_file |
340 awk '/l_fid:/ {print $7}')
344 local f2=$($LFS getstripe -I 2 $comp_file |
345 awk '/l_fid:/ {print $7}')
346 [ $f1 == $f2 ] || error "$f1 != $f2"
348 run_test 9 "Replay component add"
351 echo $($LFS getstripe $1 |
352 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
353 $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
354 $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
358 local parent=$DIR/$tdir
361 $LFS setstripe -d $MOUNT || error "clear root layout"
363 # set root composite layout
364 $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
365 -E -1 -c 4 -S 4M $MOUNT ||
366 error "Set root layout failed"
368 mkdir -p $parent || error "Create dir $parent failed"
369 # set a different layout for parent
370 $LFS setstripe -E -1 -c 1 -S 1M $parent ||
371 error "set $parent layout failed"
374 local f1_entry=$(component_dump $parent/file1)
376 # delete parent's layout
377 $LFS setstripe -d $parent || error "Clear $parent layout failed"
380 local f2_entry=$(component_dump $parent/file2)
382 # verify layout inheritance
384 local f1_expect="1[0,EOF]"
385 local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
387 echo "f1 expect=$f1_expect"
388 echo "f1 get =$f1_entry"
389 echo "f2 expect=$f2_expect"
390 echo "f2 get =$f2_entry"
392 [ x$f1_expect != x$f1_entry ] &&
393 error "$parent/file1 does not inherite parent layout"
394 [ x$f2_expect != x$f2_entry ] &&
395 error "$parent/file2 does not inherite root layout"
398 run_test 10 "Inherit composite template from root"
401 check_and_cleanup_lustre