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`"
28 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
29 . $LUSTRE/tests/test-framework.sh
31 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
37 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
38 check_and_setup_lustre
40 if [ $MDSCOUNT -ge 2 ]; then
41 skip_env "Only run with single MDT for now" && exit
44 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.61) ]; then
45 skip_env "Need MDS version at least 2.3.61" && exit
57 TESTFILE=$DIR/$tdir/file
58 $RUNAS touch $TESTFILE
61 local state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
62 [[ $state == "(0x00000000)" ]] ||
63 error "wrong initial hsm state $state"
65 $RUNAS $LFS hsm_set --norelease $TESTFILE ||
66 error "user could not change hsm flags"
67 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
68 [[ $state == "(0x00000010)" ]] ||
69 error "wrong hsm state $state, should be: --norelease"
71 $RUNAS $LFS hsm_clear --norelease $TESTFILE ||
72 error "user could not clear hsm flags"
73 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
74 [[ $state == "(0x00000000)" ]] ||
75 error "wrong hsm state $state, should be empty"
77 # User could not change those flags...
78 $RUNAS $LFS hsm_set --exists $TESTFILE &&
79 error "user should not set this flag"
80 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
81 [[ $state == "(0x00000000)" ]] ||
82 error "wrong hsm state $state, should be empty"
85 $LFS hsm_set --exists $TESTFILE ||
86 error "root could not change hsm flags"
87 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
88 [[ $state == "(0x00000001)" ]] ||
89 error "wrong hsm state $state, should be: --exists"
91 $LFS hsm_clear --exists $TESTFILE ||
92 error "root could not clear hsm state"
93 state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
94 [[ $state == "(0x00000000)" ]] ||
95 error "wrong hsm state $state, should be empty"
97 run_test 1 "lfs hsm flags root/non-root access"
101 TESTFILE=$DIR/$tdir/file
104 # New files are not dirty
105 local state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
106 [[ $state == "(0x00000000)" ]] ||
107 error "wrong hsm state $state, should be empty"
109 # For test, we simulate an archived file.
110 $LFS hsm_set --exists $TESTFILE || error "user could not change hsm flags"
111 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
112 [[ $state == "(0x00000001)" ]] ||
113 error "wrong hsm state $state, should be: --exists"
115 # chmod do not put the file dirty
116 chmod 600 $TESTFILE || error "could not chmod test file"
117 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
118 [[ $state == "(0x00000001)" ]] ||
119 error "wrong hsm state $state, should be: --exists"
121 # chown do not put the file dirty
122 chown $RUNAS_ID $TESTFILE || error "could not chown test file"
123 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
124 [[ $state == "(0x00000001)" ]] ||
125 error "wrong hsm state $state, should be: --exists"
127 # truncate put the file dirty
128 $TRUNCATE $TESTFILE 1 || error "could not truncate test file"
129 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
130 [[ $state == "(0x00000003)" ]] ||
131 error "wrong hsm state $state, should be 0x00000003"
133 $LFS hsm_clear --dirty $TESTFILE || error "could not clear hsm flags"
134 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
135 [[ $state == "(0x00000001)" ]] ||
136 error "wrong hsm state $state, should be: --exists"
138 run_test 2 "Check file dirtyness when doing setattr"
142 TESTFILE=$DIR/$tdir/file
144 # New files are not dirty
145 cp -p /etc/passwd $TESTFILE
146 local state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
147 [[ $state == "(0x00000000)" ]] ||
148 error "wrong hsm state $state, should be empty"
150 # For test, we simulate an archived file.
151 $LFS hsm_set --exists $TESTFILE ||
152 error "user could not change hsm flags"
153 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
154 [[ $state == "(0x00000001)" ]] ||
155 error "wrong hsm state $state, should be: --exists"
157 # Reading a file, does not set dirty
158 cat $TESTFILE > /dev/null || error "could not read file"
159 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
160 [[ $state == "(0x00000001)" ]] ||
161 error "wrong hsm state $state, should be: --exists"
163 # Open for write without modifying data, does not set dirty
164 openfile -f O_WRONLY $TESTFILE || error "could not open test file"
165 state=$($LFS hsm_state $TESTFILE | cut -f 2 -d" ")
166 [[ $state == "(0x00000001)" ]] ||
167 error "wrong hsm state $state, should be: --exists"
169 # Append to a file sets it dirty
170 cp -p /etc/passwd $TESTFILE.append || error "could not create file"
171 $LFS hsm_set --exists $TESTFILE.append ||
172 error "user could not change hsm flags"
173 dd if=/etc/passwd of=$TESTFILE.append bs=1 count=3 \
174 conv=notrunc oflag=append status=noxfer ||
175 error "could not append to test file"
176 state=$($LFS hsm_state $TESTFILE.append | cut -f 2 -d" ")
177 [[ $state == "(0x00000003)" ]] ||
178 error "wrong hsm state $state, should be 0x00000003"
180 # Modify a file sets it dirty
181 cp -p /etc/passwd $TESTFILE.modify || error "could not create file"
182 $LFS hsm_set --exists $TESTFILE.modify ||
183 error "user could not change hsm flags"
184 dd if=/dev/zero of=$TESTFILE.modify bs=1 count=3 \
185 conv=notrunc status=noxfer ||
186 error "could not modify test file"
187 state=$($LFS hsm_state $TESTFILE.modify | cut -f 2 -d" ")
188 [[ $state == "(0x00000003)" ]] ||
189 error "wrong hsm state $state, should be 0x00000003"
191 # Open O_TRUNC sets dirty
192 cp -p /etc/passwd $TESTFILE.trunc || error "could not create file"
193 $LFS hsm_set --exists $TESTFILE.trunc ||
194 error "user could not change hsm flags"
195 cp /etc/group $TESTFILE.trunc || error "could not override a file"
196 state=$($LFS hsm_state $TESTFILE.trunc | cut -f 2 -d" ")
197 [[ $state == "(0x00000003)" ]] ||
198 error "wrong hsm state $state, should be 0x00000003"
200 # Mmapped a file sets dirty
201 cp -p /etc/passwd $TESTFILE.mmap || error "could not create file"
202 $LFS hsm_set --exists $TESTFILE.mmap ||
203 error "user could not change hsm flags"
204 multiop $TESTFILE.mmap OSMWUc || error "could not mmap a file"
205 state=$($LFS hsm_state $TESTFILE.mmap | cut -f 2 -d" ")
206 [[ $state == "(0x00000003)" ]] ||
207 error "wrong hsm state $state, should be 0x00000003"
209 run_test 3 "Check file dirtyness when opening for write"
211 log "cleanup: ======================================================"
213 check_and_cleanup_lustre
214 echo '=========================== finished ==============================='
215 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 ||