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