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
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)}
30 . $LUSTRE/tests/test-framework.sh
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
35 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
38 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
39 check_and_setup_lustre
41 if [ $MDSCOUNT -ge 2 ]; then
42 skip_env "Only run with single MDT for now" && exit
45 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.61) ]; then
46 skip_env "Need MDS version at least 2.3.61" && exit
54 # $RUNAS_ID may get set incorrectly somewhere else
55 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
56 error "\$RUNAS_ID set to 0, but \$UID is also 0!"
58 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
61 # TODO: add copytool cleanup code here!
66 # TODO: add copytool setup code here!
76 $LFS path2fid $1 | tr -d '[]'
80 local file2=${1/$DIR/$DIR}
81 dd if=/dev/urandom of=$file2 count=2 bs=1M
89 TESTFILE=$DIR/$tdir/file
90 $RUNAS touch $TESTFILE
93 local state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
94 [[ $state == "(0x00000000)" ]] ||
95 error "wrong initial hsm state $state"
97 $RUNAS $LFS hsm_set --norelease $TESTFILE ||
98 error "user could not change hsm flags"
99 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
100 [[ $state == "(0x00000010)" ]] ||
101 error "wrong hsm state $state, should be: --norelease"
103 $RUNAS $LFS hsm_clear --norelease $TESTFILE ||
104 error "user could not clear hsm flags"
105 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
106 [[ $state == "(0x00000000)" ]] ||
107 error "wrong hsm state $state, should be empty"
109 # User could not change those flags...
110 $RUNAS $LFS hsm_set --exists $TESTFILE &&
111 error "user should not set this flag"
112 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
113 [[ $state == "(0x00000000)" ]] ||
114 error "wrong hsm state $state, should be empty"
117 $LFS hsm_set --exists $TESTFILE ||
118 error "root could not change hsm flags"
119 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
120 [[ $state == "(0x00000001)" ]] ||
121 error "wrong hsm state $state, should be: --exists"
123 $LFS hsm_clear --exists $TESTFILE ||
124 error "root could not clear hsm state"
125 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
126 [[ $state == "(0x00000000)" ]] ||
127 error "wrong hsm state $state, should be empty"
129 run_test 1 "lfs hsm flags root/non-root access"
133 TESTFILE=$DIR/$tdir/file
136 # New files are not dirty
137 local state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
138 [[ $state == "(0x00000000)" ]] ||
139 error "wrong hsm state $state, should be empty"
141 # For test, we simulate an archived file.
142 $LFS hsm_set --exists $TESTFILE || error "user could not change hsm flags"
143 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
144 [[ $state == "(0x00000001)" ]] ||
145 error "wrong hsm state $state, should be: --exists"
147 # chmod do not put the file dirty
148 chmod 600 $TESTFILE || error "could not chmod test file"
149 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
150 [[ $state == "(0x00000001)" ]] ||
151 error "wrong hsm state $state, should be: --exists"
153 # chown do not put the file dirty
154 chown $RUNAS_ID $TESTFILE || error "could not chown 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 # truncate put the file dirty
160 $TRUNCATE $TESTFILE 1 || error "could not truncate test file"
161 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
162 [[ $state == "(0x00000003)" ]] ||
163 error "wrong hsm state $state, should be 0x00000003"
165 $LFS hsm_clear --dirty $TESTFILE || error "could not clear hsm flags"
166 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
167 [[ $state == "(0x00000001)" ]] ||
168 error "wrong hsm state $state, should be: --exists"
170 run_test 2 "Check file dirtyness when doing setattr"
174 TESTFILE=$DIR/$tdir/file
176 # New files are not dirty
177 cp -p /etc/passwd $TESTFILE
178 local state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
179 [[ $state == "(0x00000000)" ]] ||
180 error "wrong hsm state $state, should be empty"
182 # For test, we simulate an archived file.
183 $LFS hsm_set --exists $TESTFILE ||
184 error "user could not change hsm flags"
185 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
186 [[ $state == "(0x00000001)" ]] ||
187 error "wrong hsm state $state, should be: --exists"
189 # Reading a file, does not set dirty
190 cat $TESTFILE > /dev/null || error "could not read file"
191 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
192 [[ $state == "(0x00000001)" ]] ||
193 error "wrong hsm state $state, should be: --exists"
195 # Open for write without modifying data, does not set dirty
196 openfile -f O_WRONLY $TESTFILE || error "could not open test file"
197 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
198 [[ $state == "(0x00000001)" ]] ||
199 error "wrong hsm state $state, should be: --exists"
201 # Append to a file sets it dirty
202 cp -p /etc/passwd $TESTFILE.append || error "could not create file"
203 $LFS hsm_set --exists $TESTFILE.append ||
204 error "user could not change hsm flags"
205 dd if=/etc/passwd of=$TESTFILE.append bs=1 count=3 \
206 conv=notrunc oflag=append status=noxfer ||
207 error "could not append to test file"
208 state=$($LFS hsm_state $TESTFILE.append | cut -f 2 -d" ")
209 [[ $state == "(0x00000003)" ]] ||
210 error "wrong hsm state $state, should be 0x00000003"
212 # Modify a file sets it dirty
213 cp -p /etc/passwd $TESTFILE.modify || error "could not create file"
214 $LFS hsm_set --exists $TESTFILE.modify ||
215 error "user could not change hsm flags"
216 dd if=/dev/zero of=$TESTFILE.modify bs=1 count=3 \
217 conv=notrunc status=noxfer ||
218 error "could not modify test file"
219 state=$($LFS hsm_state $TESTFILE.modify | cut -f 2 -d" ")
220 [[ $state == "(0x00000003)" ]] ||
221 error "wrong hsm state $state, should be 0x00000003"
223 # Open O_TRUNC sets dirty
224 cp -p /etc/passwd $TESTFILE.trunc || error "could not create file"
225 $LFS hsm_set --exists $TESTFILE.trunc ||
226 error "user could not change hsm flags"
227 cp /etc/group $TESTFILE.trunc || error "could not override a file"
228 state=$($LFS hsm_state $TESTFILE.trunc | cut -f 2 -d" ")
229 [[ $state == "(0x00000003)" ]] ||
230 error "wrong hsm state $state, should be 0x00000003"
232 # Mmapped a file sets dirty
233 cp -p /etc/passwd $TESTFILE.mmap || error "could not create file"
234 $LFS hsm_set --exists $TESTFILE.mmap ||
235 error "user could not change hsm flags"
236 multiop $TESTFILE.mmap OSMWUc || error "could not mmap a file"
237 state=$($LFS hsm_state $TESTFILE.mmap | cut -f 2 -d" ")
238 [[ $state == "(0x00000003)" ]] ||
239 error "wrong hsm state $state, should be 0x00000003"
241 run_test 3 "Check file dirtyness when opening for write"
246 local f=$DIR/$tdir/sample
249 # Could not release a non-archived file
250 $LFS hsm_release $f && error "release should not succeed"
252 # For following tests, we must test them with HS_ARCHIVED set
253 $LFS hsm_set --exists --archived $f || error "could not add flag"
255 # Could not release a file if no-release is set
256 $LFS hsm_set --norelease $f || error "could not add flag"
257 $LFS hsm_release $f && error "release should not succeed"
258 $LFS hsm_clear --norelease $f || error "could not remove flag"
260 # Could not release a file if lost
261 $LFS hsm_set --lost $f || error "could not add flag"
262 $LFS hsm_release $f && error "release should not succeed"
263 $LFS hsm_clear --lost $f || error "could not remove flag"
265 # Could not release a file if dirty
266 $LFS hsm_set --dirty $f || error "could not add flag"
267 $LFS hsm_release $f && error "release should not succeed"
268 $LFS hsm_clear --dirty $f || error "could not remove flag"
271 run_test 20 "Release is not permitted"
274 # test needs a running copytool
278 local f=$DIR/$tdir/test_release
280 # Create a file and check its states
281 local fid=$(make_small $f)
282 $LFS hsm_state $f | grep -q " (0x00000000)" ||
283 fail "wrong clean hsm state"
285 # $LFS hsm_archive $f || fail "could not archive file"
286 # wait_request_state $fid ARCHIVE SUCCEED
287 $LFS hsm_set --archived --exist $f || fail "could not archive file"
289 [ $(stat -c "%b" $f) -ne "0" ] || fail "wrong block number"
290 local sz=$(stat -c "%s" $f)
291 [ $sz -ne "0" ] || fail "file size should not be zero"
293 # Release and check states
294 $LFS hsm_release $f || fail "could not release file"
295 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
296 fail "wrong released hsm state"
297 [ $(stat -c "%b" $f) -eq "0" ] || fail "wrong block number"
298 [ $(stat -c "%s" $f) -eq $sz ] || fail "wrong file size"
300 # Check we can release an file without stripe info
304 $LFS hsm_state $f | grep -q " (0x00000000)" ||
305 fail "wrong clean hsm state"
307 # $LFS hsm_archive $f || fail "could not archive file"
308 # wait_request_state $fid ARCHIVE SUCCEED
309 $LFS hsm_set --archived --exist $f || fail "could not archive file"
311 # Release and check states
312 $LFS hsm_release $f || fail "could not release file"
313 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
314 fail "wrong released hsm state"
316 # Release again a file that is already released is OK
317 $LFS hsm_release $f || fail "second release should succeed"
318 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
319 fail "wrong released hsm state"
323 run_test 21 "Simple release tests"
326 # test needs a running copytool
331 local f=$DIR/$tdir/test_release
332 local swap=$DIR/$tdir/test_swap
334 # Create a file and check its states
335 local fid=$(make_small $f)
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 make_small $swap || fail "could not create $swap"
349 $LFS swap_layouts $swap $f && fail "swap_layouts should failed"
354 run_test 22 "Could not swap a release file"
358 # test needs a running copytool
363 local f=$DIR/$tdir/test_mtime
365 # Create a file and check its states
366 local fid=$(make_small $f)
367 $LFS hsm_state $f | grep -q " (0x00000000)" ||
368 fail "wrong clean hsm state"
370 # $LFS hsm_archive $f || fail "could not archive file"
371 # wait_request_state $fid ARCHIVE SUCCEED
372 $LFS hsm_set --archived --exist $f || fail "could not archive file"
374 # Set modification time in the past
375 touch -m -a -d @978261179 $f
377 # Release and check states
378 $LFS hsm_release $f || fail "could not release file"
379 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
380 fail "wrong released hsm state"
381 local MTIME=$(stat -c "%Y" $f)
382 local ATIME=$(stat -c "%X" $f)
383 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
384 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
388 run_test 23 "Release does not change a/mtime (utime)"
391 # test needs a running copytool
396 local f=$DIR/$tdir/test_mtime
398 # Create a file and check its states
399 local fid=$(make_small $f)
400 $LFS hsm_state $f | grep -q " (0x00000000)" ||
401 fail "wrong clean hsm state"
403 # ensure mtime is different
406 local MTIME=$(stat -c "%Y" $f)
407 local ATIME=$(stat -c "%X" $f)
409 # $LFS hsm_archive $f || fail "could not archive file"
410 # wait_request_state $fid ARCHIVE SUCCEED
411 $LFS hsm_set --archived --exist $f || fail "could not archive file"
413 # Release and check states
414 $LFS hsm_release $f || fail "could not release file"
415 $LFS hsm_state $f | grep -q " (0x0000000d)" ||
416 fail "wrong released hsm state"
418 [ "$(stat -c "%Y" $f)" -eq "$MTIME" ] ||
419 fail "mtime should be $MTIME"
421 # [ "$(stat -c "%X" $f)" -eq "$ATIME" ] ||
422 # fail "atime should be $ATIME"
426 run_test 24 "Release does not change a/mtime (i/o)"
428 log "cleanup: ======================================================"
430 check_and_cleanup_lustre
431 echo '=========================== finished ==============================='
432 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 ||