3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
13 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin/
16 SANITY_HSM_EXCEPT=${SANITY_HSM_EXCEPT:-""}
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
18 # bug number for skipped test:
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
21 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
22 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
27 MCREATE=${MCREATE:-mcreate}
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/test-framework.sh
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
36 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
39 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
40 check_and_setup_lustre
42 if [ $MDSCOUNT -ge 2 ]; then
43 skip_env "Only run with single MDT for now" && exit
46 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.61) ]; then
47 skip_env "Need MDS version at least 2.3.61" && exit
55 # $RUNAS_ID may get set incorrectly somewhere else
56 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
57 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
59 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
62 # TODO: add copytool cleanup code here!
76 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
77 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
78 HSM_ARCHIVE=${HSM_ARCHIVE:-$TMP/arc}
82 $LFS path2fid $1 | tr -d '[]'
86 local file2=${1/$DIR/$DIR}
87 dd if=/dev/urandom of=$file2 count=2 bs=1M
95 TESTFILE=$DIR/$tdir/file
96 $RUNAS touch $TESTFILE
99 local state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
100 [[ $state == "(0x00000000)" ]] ||
101 error "wrong initial hsm state $state"
103 $RUNAS $LFS hsm_set --norelease $TESTFILE ||
104 error "user could not change hsm flags"
105 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
106 [[ $state == "(0x00000010)" ]] ||
107 error "wrong hsm state $state, should be: --norelease"
109 $RUNAS $LFS hsm_clear --norelease $TESTFILE ||
110 error "user could not clear hsm flags"
111 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
112 [[ $state == "(0x00000000)" ]] ||
113 error "wrong hsm state $state, should be empty"
115 # User could not change those flags...
116 $RUNAS $LFS hsm_set --exists $TESTFILE &&
117 error "user should not set this flag"
118 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
119 [[ $state == "(0x00000000)" ]] ||
120 error "wrong hsm state $state, should be empty"
123 $LFS hsm_set --exists $TESTFILE ||
124 error "root could not change hsm flags"
125 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
126 [[ $state == "(0x00000001)" ]] ||
127 error "wrong hsm state $state, should be: --exists"
129 $LFS hsm_clear --exists $TESTFILE ||
130 error "root could not clear hsm state"
131 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
132 [[ $state == "(0x00000000)" ]] ||
133 error "wrong hsm state $state, should be empty"
135 run_test 1 "lfs hsm flags root/non-root access"
139 TESTFILE=$DIR/$tdir/file
142 # New files are not dirty
143 local state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
144 [[ $state == "(0x00000000)" ]] ||
145 error "wrong hsm state $state, should be empty"
147 # For test, we simulate an archived file.
148 $LFS hsm_set --exists $TESTFILE || error "user could not change hsm flags"
149 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
150 [[ $state == "(0x00000001)" ]] ||
151 error "wrong hsm state $state, should be: --exists"
153 # chmod do not put the file dirty
154 chmod 600 $TESTFILE || error "could not chmod test file"
155 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
156 [[ $state == "(0x00000001)" ]] ||
157 error "wrong hsm state $state, should be: --exists"
159 # chown do not put the file dirty
160 chown $RUNAS_ID $TESTFILE || error "could not chown test file"
161 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
162 [[ $state == "(0x00000001)" ]] ||
163 error "wrong hsm state $state, should be: --exists"
165 # truncate put the file dirty
166 $TRUNCATE $TESTFILE 1 || error "could not truncate test file"
167 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
168 [[ $state == "(0x00000003)" ]] ||
169 error "wrong hsm state $state, should be 0x00000003"
171 $LFS hsm_clear --dirty $TESTFILE || error "could not clear hsm flags"
172 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
173 [[ $state == "(0x00000001)" ]] ||
174 error "wrong hsm state $state, should be: --exists"
176 run_test 2 "Check file dirtyness when doing setattr"
180 TESTFILE=$DIR/$tdir/file
182 # New files are not dirty
183 cp -p /etc/passwd $TESTFILE
184 local state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
185 [[ $state == "(0x00000000)" ]] ||
186 error "wrong hsm state $state, should be empty"
188 # For test, we simulate an archived file.
189 $LFS hsm_set --exists $TESTFILE ||
190 error "user could not change hsm flags"
191 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
192 [[ $state == "(0x00000001)" ]] ||
193 error "wrong hsm state $state, should be: --exists"
195 # Reading a file, does not set dirty
196 cat $TESTFILE > /dev/null || error "could not read file"
197 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
198 [[ $state == "(0x00000001)" ]] ||
199 error "wrong hsm state $state, should be: --exists"
201 # Open for write without modifying data, does not set dirty
202 openfile -f O_WRONLY $TESTFILE || error "could not open test file"
203 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
204 [[ $state == "(0x00000001)" ]] ||
205 error "wrong hsm state $state, should be: --exists"
207 # Append to a file sets it dirty
208 cp -p /etc/passwd $TESTFILE.append || error "could not create file"
209 $LFS hsm_set --exists $TESTFILE.append ||
210 error "user could not change hsm flags"
211 dd if=/etc/passwd of=$TESTFILE.append bs=1 count=3 \
212 conv=notrunc oflag=append status=noxfer ||
213 error "could not append to test file"
214 state=$($LFS hsm_state $TESTFILE.append | cut -f 2 -d" ")
215 [[ $state == "(0x00000003)" ]] ||
216 error "wrong hsm state $state, should be 0x00000003"
218 # Modify a file sets it dirty
219 cp -p /etc/passwd $TESTFILE.modify || error "could not create file"
220 $LFS hsm_set --exists $TESTFILE.modify ||
221 error "user could not change hsm flags"
222 dd if=/dev/zero of=$TESTFILE.modify bs=1 count=3 \
223 conv=notrunc status=noxfer ||
224 error "could not modify test file"
225 state=$($LFS hsm_state $TESTFILE.modify | cut -f 2 -d" ")
226 [[ $state == "(0x00000003)" ]] ||
227 error "wrong hsm state $state, should be 0x00000003"
229 # Open O_TRUNC sets dirty
230 cp -p /etc/passwd $TESTFILE.trunc || error "could not create file"
231 $LFS hsm_set --exists $TESTFILE.trunc ||
232 error "user could not change hsm flags"
233 cp /etc/group $TESTFILE.trunc || error "could not override a file"
234 state=$($LFS hsm_state $TESTFILE.trunc | cut -f 2 -d" ")
235 [[ $state == "(0x00000003)" ]] ||
236 error "wrong hsm state $state, should be 0x00000003"
238 # Mmapped a file sets dirty
239 cp -p /etc/passwd $TESTFILE.mmap || error "could not create file"
240 $LFS hsm_set --exists $TESTFILE.mmap ||
241 error "user could not change hsm flags"
242 multiop $TESTFILE.mmap OSMWUc || error "could not mmap a file"
243 state=$($LFS hsm_state $TESTFILE.mmap | cut -f 2 -d" ")
244 [[ $state == "(0x00000003)" ]] ||
245 error "wrong hsm state $state, should be 0x00000003"
247 run_test 3 "Check file dirtyness when opening for write"
250 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
251 cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
252 local f=$DIR/$tdir/$tfile
253 $HSMTOOL $HSMTOOL_VERBOSE --archive $HSM_ARCHIVE_NUMBER \
254 --hsm_root $HSM_ARCHIVE --import $tdir/$tfile $f $MOUNT ||
255 error "import failed"
256 echo -n "Verifying released state: "
258 $LFS hsm_state $f | grep -q "released exists archived" ||
259 error "flags not set"
260 local LSZ=$(stat -c "%s" $f)
261 local ASZ=$(stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
262 echo "Verifying imported size $LSZ=$ASZ"
263 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
264 echo -n "Verifying released pattern: "
265 local PTRN=$($GETSTRIPE -L $f)
267 [[ $PTRN == 80000001 ]] || error "Is not released"
268 local fid=$(path2fid $f)
269 echo "Verifying new fid $fid in archive"
270 local AFILE=$(ls $HSM_ARCHIVE/*/*/*/*/*/*/$fid) || \
271 error "fid $fid not in archive $HSM_ARCHIVE"
273 run_test 11 "Import a file"
278 local f=$DIR/$tdir/sample
281 # Could not release a non-archived file
282 $LFS hsm_release $f && error "release should not succeed"
284 # For following tests, we must test them with HS_ARCHIVED set
285 $LFS hsm_set --exists --archived $f || error "could not add flag"
287 # Could not release a file if no-release is set
288 $LFS hsm_set --norelease $f || error "could not add flag"
289 $LFS hsm_release $f && error "release should not succeed"
290 $LFS hsm_clear --norelease $f || error "could not remove flag"
292 # Could not release a file if lost
293 $LFS hsm_set --lost $f || error "could not add flag"
294 $LFS hsm_release $f && error "release should not succeed"
295 $LFS hsm_clear --lost $f || error "could not remove flag"
297 # Could not release a file if dirty
298 $LFS hsm_set --dirty $f || error "could not add flag"
299 $LFS hsm_release $f && error "release should not succeed"
300 $LFS hsm_clear --dirty $f || error "could not remove flag"
303 run_test 20 "Release is not permitted"
306 # test needs a running copytool
310 local f=$DIR/$tdir/test_release
312 # Create a file and check its states
313 local fid=$(make_small $f)
314 $LFS hsm_state $f | grep -q " (0x00000000)" ||
315 fail "wrong clean hsm state"
317 # $LFS hsm_archive $f || fail "could not archive file"
318 # wait_request_state $fid ARCHIVE SUCCEED
319 $LFS hsm_set --archived --exist $f || fail "could not archive file"
321 [ $(stat -c "%b" $f) -ne "0" ] || fail "wrong block number"
322 local sz=$(stat -c "%s" $f)
323 [ $sz -ne "0" ] || fail "file size should not be zero"
325 # Release and check states
326 $LFS hsm_release $f || fail "could not release file"
327 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
328 fail "wrong released hsm state"
329 [ $(stat -c "%b" $f) -eq "0" ] || fail "wrong block number"
330 [ $(stat -c "%s" $f) -eq $sz ] || fail "wrong file size"
332 # Check we can release an file without stripe info
336 $LFS hsm_state $f | grep -q " (0x00000000)" ||
337 fail "wrong clean hsm state"
339 # $LFS hsm_archive $f || fail "could not archive file"
340 # wait_request_state $fid ARCHIVE SUCCEED
341 $LFS hsm_set --archived --exist $f || fail "could not archive file"
343 # Release and check states
344 $LFS hsm_release $f || fail "could not release file"
345 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
346 fail "wrong released hsm state"
348 # Release again a file that is already released is OK
349 $LFS hsm_release $f || fail "second release should succeed"
350 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
351 fail "wrong released hsm state"
355 run_test 21 "Simple release tests"
358 # test needs a running copytool
363 local f=$DIR/$tdir/test_release
364 local swap=$DIR/$tdir/test_swap
366 # Create a file and check its states
367 local fid=$(make_small $f)
368 $LFS hsm_state $f | grep -q " (0x00000000)" ||
369 fail "wrong clean hsm state"
371 # $LFS hsm_archive $f || fail "could not archive file"
372 # wait_request_state $fid ARCHIVE SUCCEED
373 $LFS hsm_set --archived --exist $f || fail "could not archive file"
375 # Release and check states
376 $LFS hsm_release $f || fail "could not release file"
377 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
378 fail "wrong released hsm state"
380 make_small $swap || fail "could not create $swap"
381 $LFS swap_layouts $swap $f && fail "swap_layouts should failed"
386 run_test 22 "Could not swap a release file"
390 # test needs a running copytool
395 local f=$DIR/$tdir/test_mtime
397 # Create a file and check its states
398 local fid=$(make_small $f)
399 $LFS hsm_state $f | grep -q " (0x00000000)" ||
400 fail "wrong clean hsm state"
402 # $LFS hsm_archive $f || fail "could not archive file"
403 # wait_request_state $fid ARCHIVE SUCCEED
404 $LFS hsm_set --archived --exist $f || fail "could not archive file"
406 # Set modification time in the past
407 touch -m -a -d @978261179 $f
409 # Release and check states
410 $LFS hsm_release $f || fail "could not release file"
411 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
412 fail "wrong released hsm state"
413 local MTIME=$(stat -c "%Y" $f)
414 local ATIME=$(stat -c "%X" $f)
415 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
416 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
420 run_test 23 "Release does not change a/mtime (utime)"
423 # test needs a running copytool
428 local f=$DIR/$tdir/test_mtime
430 # Create a file and check its states
431 local fid=$(make_small $f)
432 $LFS hsm_state $f | grep -q " (0x00000000)" ||
433 fail "wrong clean hsm state"
435 # ensure mtime is different
438 local MTIME=$(stat -c "%Y" $f)
439 local ATIME=$(stat -c "%X" $f)
441 # $LFS hsm_archive $f || fail "could not archive file"
442 # wait_request_state $fid ARCHIVE SUCCEED
443 $LFS hsm_set --archived --exist $f || fail "could not archive file"
445 # Release and check states
446 $LFS hsm_release $f || fail "could not release file"
447 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
448 fail "wrong released hsm state"
450 [ "$(stat -c "%Y" $f)" -eq "$MTIME" ] ||
451 fail "mtime should be $MTIME"
453 # [ "$(stat -c "%X" $f)" -eq "$ATIME" ] ||
454 # fail "atime should be $ATIME"
458 run_test 24 "Release does not change a/mtime (i/o)"
460 log "cleanup: ======================================================"
462 check_and_cleanup_lustre
463 echo '=========================== finished ==============================='
464 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 ||