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