Whamcloud - gitweb
LU-9008 pfl: dynamic layout modification with write/truncate
[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 SRCDIR=$(dirname $0)
8 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
9
10 ONLY=${ONLY:-"$*"}
11 # Bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_PFL_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
16         echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
17
18 TMP=${TMP:-/tmp}
19 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
20
21 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
23 init_test_env $@
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 init_logging
26
27 check_and_setup_lustre
28
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
31 fi
32
33 build_test_filter
34
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
38
39 test_0() {
40         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
41
42         local comp_file=$DIR/$tfile
43         local rw_len=$((3 * 1024 * 1024))       # 3M
44
45         rm -f $comp_file
46
47         $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $comp_file ||
48                 error "Create $comp_file failed"
49
50         #instantiate all components, so that objs are allocted
51         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1k
52
53         local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
54         local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
55
56         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
57
58         small_write $comp_file $rw_len || error "Verify RW failed"
59
60         rm -f $comp_file || error "Delete $comp_file failed"
61 }
62 run_test 0 "Create full components file, no reused OSTs"
63
64 test_1() {
65         local comp_file=$DIR/$tfile
66         local rw_len=$((3 * 1024 * 1024))       # 3M
67
68         rm -f $comp_file
69
70         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
71                 error "Create $comp_file failed"
72
73         #instantiate all components, so that objs are allocted
74         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1k
75
76         local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
77         local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
78
79         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
80
81         small_write $comp_file $rw_len || error "Verify RW failed"
82
83         rm -f $comp_file || error "Delete $comp_file failed"
84 }
85 run_test 1 "Create full components file, reused OSTs"
86
87 test_2() {
88         local comp_file=$DIR/$tfile
89         local rw_len=$((5 * 1024 * 1024))       # 5M
90
91         rm -f $comp_file
92
93         $LFS setstripe -E 1m -S 1m $comp_file ||
94                 error "Create $comp_file failed"
95
96         local comp_cnt=$($LFS getstripe --component-count $comp_file)
97         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
98
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"
103
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"
108
109         $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
110                 error "Add component to $comp_file failed"
111
112         comp_cnt=$($LFS getstripe --component-count $comp_file)
113         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
114
115         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
116                 error "Add last component to $comp_file failed"
117
118         comp_cnt=$($LFS getstripe --component-count $comp_file)
119         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
120
121         small_write $comp_file $rw_len || error "Verify RW failed"
122
123         rm -f $comp_file || error "Delete $comp_file failed"
124 }
125 run_test 2 "Add component to existing file"
126
127 del_comp_and_verify() {
128         local comp_file=$1
129         local id=$2
130         local left=$3
131         local size=$4
132
133         local opt="-I"
134         if [ $id == "init" ]; then
135                 opt="--component-flags"
136         fi
137
138         $LFS setstripe --component-del $opt $id $comp_file ||
139                 error "Delete component $id from $comp_file failed"
140
141         local comp_cnt=$($LFS getstripe --component-count $comp_file)
142         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
143                 comp_cnt=0
144         fi
145         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
146
147         $CHECKSTAT -s $size $comp_file || error "size != $size"
148 }
149
150 test_3() {
151         local comp_file=$DIR/$tfile
152
153         rm -f $comp_file
154
155         $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
156                 error "Create $comp_file failed"
157
158         local comp_cnt=$($LFS getstripe --component-count $comp_file)
159         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
160
161         dd if=/dev/zero of=$comp_file bs=1M count=2
162
163         $LFS setstripe --component-del -I 2 $comp_file &&
164                 error "Component deletion makes hole"
165
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
169
170         rm -f $comp_file || error "Delete $comp_file failed"
171
172         $LFS setstripe -E 1M -E 16M -E -1 $comp_file ||
173                 error "Create second $comp_file failed"
174
175         #instantiate all components, so that objs are allocted
176         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=16k
177
178         del_comp_and_verify $comp_file "init" 0 0
179         rm -f $comp_file || error "Delete second $comp_file failed"
180 }
181 run_test 3 "Delete component from existing file"
182
183 test_4() {
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.
187 }
188 run_test 4 "Modify component flags in existing file"
189
190 test_5() {
191         local parent=$DIR/$tdir
192         local comp_file=$DIR/$tdir/$tfile
193         local subdir=$parent/subdir
194
195         rm -fr $parent
196         mkdir -p $parent || error "Create dir $parent failed"
197
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"
201
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"
206
207         #instantiate all components, so that objs are allocted
208         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=64k
209
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"
213
214         ost_idx=$($LFS getstripe -I 2 -i $comp_file)
215         [ $ost_idx -ne 0 ] &&
216                 error "component 2 ost_idx $ost_idx != 0"
217
218         # create subdir under parent
219         mkdir -p $subdir || error "Create subdir $subdir failed"
220
221         comp_cnt=$($LFS getstripe -d --component-count $subdir)
222         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
223
224         # create file under subdir
225         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
226
227         comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
228         [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
229
230         # delete default layout setting from parent
231         $LFS setstripe -d $parent ||
232                 error "Delete default layout from $parent failed"
233
234         comp_cnt=$($LFS getstripe -d --component-count $parent)
235         [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
236
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"
241 }
242 run_test 5 "Inherit composite layout from parent directory"
243
244 test_6() {
245         local comp_file=$DIR/$tfile
246
247         rm -f $DIR/$tfile
248
249         $LFS setstripe -c 1 -S 128K $comp_file ||
250                 error "Create v1 $comp_file failed"
251
252         local comp_cnt=$($LFS getstripe --component-count $comp_file)
253         [ ! -z "$comp_cnt" ] && error "Wrong component count $comp_cnt"
254
255         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
256                 error "Write to v1 $comp_file failed"
257
258         local old_chksum=$(md5sum $comp_file)
259
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"
263
264         comp_cnt=$($LFS getstripe --component-count $comp_file)
265         [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
266
267         local chksum=$(md5sum $comp_file)
268         [ "$old_chksum" != "$chksum" ] &&
269                 error "(v1 -> compsoite) $old_chksum != $chksum"
270
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"
275
276         comp_cnt=$($LFS getstripe --component-count $comp_file)
277         [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
278
279         chksum=$(md5sum $comp_file)
280         [ "$old_chksum" != "$chksum" ] &&
281                 error "(composite -> compsoite) $old_chksum != $chksum"
282
283         # Migrate composite to v1
284         $LFS migrate -c 2 -S 2M $comp_file ||
285                 error "Migrate(composite -> v1) $comp_file failed"
286
287         comp_cnt=$($LFS getstripe --component-count $comp_file)
288         [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
289
290         chksum=$(md5sum $comp_file)
291         [ "$old_chksum" != "$chksum" ] &&
292                 error "(composite -> v1) $old_chksum != $chksum"
293
294         rm -f $comp_file || "Delete $comp_file failed"
295 }
296 run_test 6 "Migrate composite file"
297
298 test_7() {
299         mkdir -p $DIR/$tdir || error "mkdir failed"
300         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
301
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"
305
306         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
307                 error "Add component to $comp_file failed"
308
309         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
310                 error "Delete component from $comp_file failed"
311
312         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
313                 error "Add last component to $comp_file failed"
314
315         rm $comp_file || "Delete composite failed"
316 }
317 run_test 7 "Add/Delete/Create composite file by non-privileged user"
318
319 test_8() {
320         local parent=$DIR/$tdir
321
322         rm -fr $parent
323         mkdir -p $parent || error "Create dir $parent failed"
324
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"
328
329         sh rundbench -C -D $parent 2 || error "debench failed"
330
331         rm -fr $parent || error "Delete dir $parent failed"
332 }
333 run_test 8 "Run debench over composite files"
334
335 test_9() {
336         local comp_file=$DIR/$tfile
337
338         rm -f $comp_file
339
340         $LFS setstripe -E 1m -S 1m $comp_file ||
341                 error "Create $comp_file failed"
342
343         local comp_cnt=$($LFS getstripe --component-count $comp_file)
344         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
345
346         replay_barrier $SINGLEMDS
347
348         $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
349                 error "Add component to $comp_file failed"
350
351         local f1=$($LFS getstripe -I 2 $comp_file |
352                         awk '/l_fid:/ {print $7}')
353
354         fail $SINGLEMDS
355
356         local f2=$($LFS getstripe -I 2 $comp_file |
357                         awk '/l_fid:/ {print $7}')
358         [ $f1 == $f2 ] || error "$f1 != $f2"
359 }
360 run_test 9 "Replay component add"
361
362 component_dump() {
363         echo $($LFS getstripe $1 |
364                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
365                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
366                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
367 }
368
369 test_10() {
370         local parent=$DIR/$tdir
371
372         rm -rf $parent
373         $LFS setstripe -d $MOUNT || error "clear root layout"
374
375         # set root composite layout
376         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
377                 -E -1 -c 4 -S 4M $MOUNT ||
378                 error "Set root layout failed"
379
380         mkdir -p $parent || error "Create dir $parent failed"
381         # set a different layout for parent
382         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
383                 error "set $parent layout failed"
384         touch $parent/file1
385
386         local f1_entry=$(component_dump $parent/file1)
387
388         # delete parent's layout
389         $LFS setstripe -d $parent || error "Clear $parent layout failed"
390         touch $parent/file2
391
392         local f2_entry=$(component_dump $parent/file2)
393
394         # verify layout inheritance
395         local eof="EOF"
396         local f1_expect="1[0,EOF]"
397         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
398
399         echo "f1 expect=$f1_expect"
400         echo "f1 get   =$f1_entry"
401         echo "f2 expect=$f2_expect"
402         echo "f2 get   =$f2_entry"
403
404         [  x$f1_expect != x$f1_entry ] &&
405                 error "$parent/file1 does not inherite parent layout"
406         [  x$f2_expect != x$f2_entry ] &&
407                 error "$parent/file2 does not inherite root layout"
408         return 0
409 }
410 run_test 10 "Inherit composite template from root"
411
412 complete $SECONDS
413 check_and_cleanup_lustre
414 exit_status