Whamcloud - gitweb
LU-3196 tests: several test fixes about DNE tests
[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         $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
62            error "wrong initial hsm state"
63         $RUNAS $LFS hsm_set --norelease $TESTFILE ||
64            error "user could not change hsm flags"
65         $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000010)" ||
66            error "wrong hsm state, should be: --norelease"
67         $RUNAS $LFS hsm_clear --norelease $TESTFILE ||
68            error "user could not clear hsm flags"
69         $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
70            error "wrong hsm state, should be empty"
71
72         # User could not change those flags...
73         $RUNAS $LFS hsm_set --exists $TESTFILE &&
74            error "user should not set this flag"
75         $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
76            error "wrong hsm state, should be empty"
77
78         # ...but root can
79         $LFS hsm_set --exists $TESTFILE ||
80            error "root could not change hsm flags"
81         $LFS hsm_state $TESTFILE | grep -q "(0x00000001)" ||
82             error "wrong hsm state, should be: --exists"
83         $LFS hsm_clear --exists $TESTFILE ||
84             error "root could not clear hsm state"
85         $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
86             error "wrong hsm state, should be empty"
87 }
88 run_test 1 "lfs hsm flags root/non-root access"
89
90 test_2() {
91         mkdir -p $DIR/$tdir
92         TESTFILE=$DIR/$tdir/file
93         touch $TESTFILE
94
95         # New files are not dirty
96         $LFS hsm_state $TESTFILE | grep -q " (0x00000000)" ||
97                 error "wrong hsm state: !0x0"
98
99         # For test, we simulate an archived file.
100         $LFS hsm_set --exists $TESTFILE || error "user could not change hsm flags"
101         $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
102                 error "wrong hsm state: !0x1"
103
104         # chmod do not put the file dirty
105         chmod 600 $TESTFILE || error "could not chmod test file"
106         $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
107                 error "wrong hsm state: !0x1"
108
109         # chown do not put the file dirty
110         chown $RUNAS_ID $TESTFILE || error "could not chown test file"
111         $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
112                 error "wrong hsm state: !0x1"
113
114         # truncate put the file dirty
115         ./truncate $TESTFILE 1 || error "could not truncate test file"
116         $LFS hsm_state $TESTFILE | grep -q " (0x00000003)" ||
117                 error "wrong hsm state: !0x3"
118         $LFS hsm_clear --dirty $TESTFILE || error "could not clear hsm flags"
119         $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
120                 error "wrong hsm state: !0x1"
121 }
122 run_test 2 "Check file dirtyness when doing setattr"
123
124 test_3() {
125         mkdir -p $DIR/$tdir
126         TESTFILE=$DIR/$tdir/file
127
128         # New files are not dirty
129         cp -p /etc/passwd $TESTFILE
130         $LFS hsm_state $TESTFILE | grep -q " (0x00000000)" ||
131                 error "wrong hsm state: !0x0"
132
133         # For test, we simulate an archived file.
134         $LFS hsm_set --exists $TESTFILE ||
135                 error "user could not change hsm flags"
136         $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
137                 error "wrong hsm state: !0x1"
138
139         # Reading a file, does not set dirty
140         cat $TESTFILE > /dev/null || error "could not read file"
141         $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
142                 error "wrong hsm state: !0x1"
143
144         # Open for write without modifying data, does not set dirty
145         openfile -f O_WRONLY $TESTFILE || error "could not open test file"
146         $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
147                 error "wrong hsm state: !0x1"
148
149         # Append to a file sets it dirty
150         cp -p /etc/passwd $TESTFILE.append || error "could not create file"
151         $LFS hsm_set --exists $TESTFILE.append ||
152                 error "user could not change hsm flags"
153         dd if=/etc/passwd of=$TESTFILE.append bs=1 count=3 \
154            conv=notrunc oflag=append status=noxfer ||
155                 error "could not append to test file"
156         $LFS hsm_state $TESTFILE.append | grep -q " (0x00000003)" ||
157                 error "wrong hsm state: !0x3"
158
159         # Modify a file sets it dirty
160         cp -p /etc/passwd $TESTFILE.modify || error "could not create file"
161         $LFS hsm_set --exists $TESTFILE.modify ||
162                 error "user could not change hsm flags"
163         dd if=/dev/zero of=$TESTFILE.modify bs=1 count=3 \
164            conv=notrunc status=noxfer ||
165                 error "could not modify test file"
166         $LFS hsm_state $TESTFILE.modify | grep -q " (0x00000003)" ||
167                 error "wrong hsm state: !0x3"
168
169         # Open O_TRUNC sets dirty
170         cp -p /etc/passwd $TESTFILE.trunc || error "could not create file"
171         $LFS hsm_set --exists $TESTFILE.trunc ||
172                 error "user could not change hsm flags"
173         cp /etc/group $TESTFILE.trunc || error "could not override a file"
174         $LFS hsm_state $TESTFILE.trunc | grep -q " (0x00000003)" ||
175                 error "wrong hsm state: !0x3"
176
177         # Mmapped a file sets dirty
178         cp -p /etc/passwd $TESTFILE.mmap || error "could not create file"
179         $LFS hsm_set --exists $TESTFILE.mmap ||
180                 error "user could not change hsm flags"
181         multiop $TESTFILE.mmap OSMWUc || error "could not mmap a file"
182         $LFS hsm_state $TESTFILE.mmap | grep -q " (0x00000003)" ||
183                 error "wrong hsm state: !0x3"
184 }
185 run_test 3 "Check file dirtyness when opening for write"
186
187 log "cleanup: ======================================================"
188 cd $ORIG_PWD
189 check_and_cleanup_lustre
190 echo '=========================== finished ==============================='
191 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 ||
192         true
193 echo "$0: completed"