Whamcloud - gitweb
0cf33552a00011736d5e9f0b302dd0cf5b6e515f
[fs/lustre-release.git] / lustre / tests / sanity-hsm.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 #
6 # Run test by setting NOSETUP=true when ltest has setup env for us
7 #
8 # exit on error
9 set -e
10 set +o monitor
11
12 SRCDIR=`dirname $0`
13 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin
14
15 ONLY=${ONLY:-"$*"}
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!
20
21 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
22         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
23
24 TMP=${TMP:-/tmp}
25
26 ORIG_PWD=${PWD}
27
28 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
29 . $LUSTRE/tests/test-framework.sh
30 init_test_env $@
31 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
32 init_logging
33
34 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
35 FAIL_ON_ERROR=false
36
37 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
38 check_and_setup_lustre
39
40 if [ $MDSCOUNT -ge 2 ]; then
41         skip_env "Only run with single MDT for now" && exit
42 fi
43
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
46 fi
47
48 DIR=${DIR:-$MOUNT}
49 assert_DIR
50
51 build_test_filter
52
53 test_1() {
54         mkdir -p $DIR/$tdir
55         chmod 777 $DIR/$tdir
56
57         TESTFILE=$DIR/$tdir/file
58         $RUNAS touch $TESTFILE
59
60         # User flags
61         local state=$($RUNAS $LFS hsm_state $TESTFILE | cut -f 2 -d" ")
62         [[ $state == "(0x00000000)" ]] ||
63                 error "wrong initial hsm state $state"
64
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"
70
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"
76
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"
83
84         # ...but root can
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"
90
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"
96 }
97 run_test 1 "lfs hsm flags root/non-root access"
98
99 test_2() {
100         mkdir -p $DIR/$tdir
101         TESTFILE=$DIR/$tdir/file
102         touch $TESTFILE
103
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"
108
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"
114
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"
120
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"
126
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"
132
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"
137 }
138 run_test 2 "Check file dirtyness when doing setattr"
139
140 test_3() {
141         mkdir -p $DIR/$tdir
142         TESTFILE=$DIR/$tdir/file
143
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"
149
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"
156
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"
162
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"
168
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"
179
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"
190
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"
199
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"
208 }
209 run_test 3 "Check file dirtyness when opening for write"
210
211 log "cleanup: ======================================================"
212 cd $ORIG_PWD
213 check_and_cleanup_lustre
214 echo '=========================== finished ==============================='
215 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 ||
216         true
217 echo "$0: completed"