Whamcloud - gitweb
land lustre part of b_hd_sec on HEAD.
[fs/lustre-release.git] / lustre / tests / sanity-sec.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 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
11 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
12
13 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
14
15 SRCDIR=`dirname $0`
16 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
17 export SECURITY=${SECURITY:-"null"}
18
19 TMP=${TMP:-/tmp}
20 FSTYPE=${FSTYPE:-ext3}
21
22 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
23 CREATETEST=${CREATETEST:-createtest}
24 LFS=${LFS:-lfs}
25 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
26 LFIND=${LFIND:-"$LFS find"}
27 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
28 LCTL=${LCTL:-lctl}
29 MCREATE=${MCREATE:-mcreate}
30 OPENFILE=${OPENFILE:-openfile}
31 OPENUNLINK=${OPENUNLINK:-openunlink}
32 TOEXCL=${TOEXCL:-toexcl}
33 TRUNCATE=${TRUNCATE:-truncate}
34 MUNLINK=${MUNLINK:-munlink}
35 SOCKETSERVER=${SOCKETSERVER:-socketserver}
36 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
37 IOPENTEST1=${IOPENTEST1:-iopentest1}
38 IOPENTEST2=${IOPENTEST2:-iopentest2}
39
40 . krb5_env.sh
41
42 if [ $UID -ne 0 ]; then
43         RUNAS_ID="$UID"
44         RUNAS=""
45 else
46         RUNAS_ID=${RUNAS_ID:-500}
47         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
48 fi
49
50 if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
51     start_krb5_kdc || exit 1
52     if [ $RUNAS_ID -ne $UID ]; then
53         $RUNAS ./krb5_refresh_cache.sh || exit 2
54     fi
55 fi
56
57 export NAME=${NAME:-local}
58
59 SAVE_PWD=$PWD
60
61 clean() {
62         echo -n "cln.."
63         sh llmountcleanup.sh > /dev/null || exit 20
64         I_MOUNTED=no
65 }
66 CLEAN=${CLEAN:-clean}
67
68 start() {
69         echo -n "mnt.."
70         sh llrmount.sh > /dev/null || exit 10
71         I_MOUNTED=yes
72         echo "done"
73 }
74 START=${START:-start}
75
76 log() {
77         echo "$*"
78         lctl mark "$*" 2> /dev/null || true
79 }
80
81 trace() {
82         log "STARTING: $*"
83         strace -o $TMP/$1.strace -ttt $*
84         RC=$?
85         log "FINISHED: $*: rc $RC"
86         return 1
87 }
88 TRACE=${TRACE:-""}
89
90 check_kernel_version() {
91         VERSION_FILE=/proc/fs/lustre/kernel_version
92         WANT_VER=$1
93         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
94         GOT_VER=`cat $VERSION_FILE`
95         [ $GOT_VER -ge $WANT_VER ] && return 0
96         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
97         return 1
98 }
99
100 run_one() {
101         if ! mount | grep -q $DIR; then
102                 $START
103         fi
104         echo -1 >/proc/sys/portals/debug        
105         log "== test $1: $2"
106         export TESTNAME=test_$1
107         test_$1 || error "test_$1: exit with rc=$?"
108         unset TESTNAME
109         pass
110         cd $SAVE_PWD
111         $CLEAN
112 }
113
114 build_test_filter() {
115         for O in $ONLY; do
116             eval ONLY_${O}=true
117         done
118         for E in $EXCEPT $ALWAYS_EXCEPT; do
119             eval EXCEPT_${E}=true
120         done
121 }
122
123 _basetest() {
124     echo $*
125 }
126
127 basetest() {
128     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
129 }
130
131 run_test() {
132          base=`basetest $1`
133          if [ "$ONLY" ]; then
134                  testname=ONLY_$1
135                  if [ ${!testname}x != x ]; then
136                         run_one $1 "$2"
137                         return $?
138                  fi
139                  testname=ONLY_$base
140                  if [ ${!testname}x != x ]; then
141                          run_one $1 "$2"
142                          return $?
143                  fi
144                  echo -n "."
145                  return 0
146         fi
147         testname=EXCEPT_$1
148         if [ ${!testname}x != x ]; then
149                  echo "skipping excluded test $1"
150                  return 0
151         fi
152         testname=EXCEPT_$base
153         if [ ${!testname}x != x ]; then
154                  echo "skipping excluded test $1 (base $base)"
155                  return 0
156         fi
157         run_one $1 "$2"
158         return $?
159 }
160
161 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
162
163 error() { 
164         log "FAIL: $@"
165         if [ "$SANITYLOG" ]; then
166                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
167         else
168                 exit 1
169         fi
170 }
171
172 pass() { 
173         echo PASS
174 }
175
176 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
177 if [ -z "$MOUNT" ]; then
178         sh llmount.sh
179         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
180         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
181         I_MOUNTED=yes
182 fi
183
184 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
185
186 DIR=${DIR:-$MOUNT}
187 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
188
189 OSTCOUNT=`cat /proc/fs/lustre/llite/fs0/lov/numobd`
190 STRIPECOUNT=`cat /proc/fs/lustre/llite/fs0/lov/stripecount`
191 STRIPESIZE=`cat /proc/fs/lustre/llite/fs0/lov/stripesize`
192
193 build_test_filter
194
195 test_0() {
196         touch $DIR/f
197         $CHECKSTAT -t file $DIR/f || error
198         rm $DIR/f
199         $CHECKSTAT -a $DIR/f || error
200 }
201 run_test 0 "touch .../f ; rm .../f ============================="
202
203 mdsdevice(){
204         lctl << EOF
205         dl
206         quit
207 EOF
208 }
209
210 mynidstr(){
211         lctl << EOF
212         network tcp
213         mynid
214         quit
215 EOF
216 }
217
218 test_1(){
219         mdsnum=`mdsdevice|awk ' $3=="mds" {print $1}'`
220         if [ ! -z "$mdsnum" ];then
221         mynid=`mynidstr|awk '{print $4}'`
222         mkdir $DIR/test_0a_dir1
223         touch $DIR/test_0a_file1
224         ln -s $DIR/test_0a_file1 $DIR/test_0a_filelink1
225         chmod 0777 $DIR
226         lctl << EOF
227         device $mdsnum 
228         root_squash 500:500
229         root_squash
230         quit
231 EOF
232         mkdir $DIR/test_0a_dir2
233         touch $DIR/test_0a_file2
234         ln -s $DIR/test_0a_file2 $DIR/test_0a_filelink2
235         $CHECKSTAT -t dir   -u 500  $DIR/test_0a_dir2 || error
236         $CHECKSTAT -t file  -u 500  $DIR/test_0a_file2 || error
237         $CHECKSTAT -t link  -u 500  $DIR/test_0a_filelink2 || error
238         lctl << EOF
239         device $mdsnum 
240         root_squash 500:500 $mynid
241         root_squash
242         quit
243 EOF
244         mkdir $DIR/test_0a_dir3
245         touch $DIR/test_0a_file3
246         ln -s $DIR/test_0a_file3 $DIR/test_0a_filelink3
247         $CHECKSTAT -t dir -u root  $DIR/test_0a_dir3 || error
248         $CHECKSTAT -t file -u root $DIR/test_0a_file3 || error
249         $CHECKSTAT -t link -u root $DIR/test_0a_filelink3 || error
250         lctl << EOF
251         device $mdsnum 
252         root_squash root:root
253         root_squash
254         quit
255 EOF
256         mkdir $DIR/test_0a_dir4
257         touch $DIR/test_0a_file4
258         ln -s $DIR/test_0a_file4 $DIR/test_0a_filelink4
259         $CHECKSTAT -t dir -u root  $DIR/test_0a_dir4 || error
260         $CHECKSTAT -t file -u root $DIR/test_0a_file4 || error
261         $CHECKSTAT -t link -u root $DIR/test_0a_filelink4 || error
262         rm -rf $DIR/test_0a*
263         chmod 0755 $DIR
264         fi
265 }
266
267 run_test 1 "test root_squash ============================"
268
269 test_2() {
270         touch $DIR/f2
271                                                                                                                              
272         #test set/get xattr
273         setfattr -n trusted.name1 -v value1 $DIR/f2 || error
274         [ "`getfattr -n trusted.name1 $DIR/f2 2> /dev/null | \
275         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
276                                                                                                                              
277         setfattr -n user.author1 -v author1 $DIR/f2 || error
278         [ "`getfattr -n user.author1 $DIR/f2 2> /dev/null | \
279         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
280
281         # test listxattr
282         setfattr -n trusted.name2 -v value2 $DIR/f2 || error
283         setfattr -n trusted.name3 -v value3 $DIR/f2 || error
284         [ `getfattr -d -m "^trusted" $DIR/f2 2> /dev/null | \
285         grep "trusted" | wc -l` -eq 5 ] || error
286
287                                                                                                                              
288         setfattr -n user.author2 -v author2 $DIR/f2 || error
289         setfattr -n user.author3 -v author3 $DIR/f2 || error
290         [ `getfattr -d -m "^user" $DIR/f2 2> /dev/null | \
291         grep "user" | wc -l` -eq 3 ] || error
292         #test removexattr
293         setfattr -x trusted.name1 $DIR/f2 2> /dev/null || error
294         getfattr -d -m trusted $DIR/f2 2> /dev/null | \
295         grep "trusted.name1" && error || true
296
297         setfattr -x user.author1 $DIR/f2 2> /dev/null || error
298         getfattr -d -m user $DIR/f2 2> /dev/null | \
299         grep "user.author1" && error || true
300 }
301 run_test 2 "set/get xattr test (trusted xattr only) ============"
302
303 test_3 () {
304         SAVE_UMASK=`umask`
305         umask 022
306         USER1=rpm
307         USER2=vsx2
308         GROUP1=nobody
309         GROUP2=users
310
311         chmod +x runacltest
312         chmod +x acl_mode
313         cd $DIR
314
315        #sed -e "s/joe/$USER1/g;s/lisa/$USER2/g;s/users/$GROUP1/g;s/toolies/$GROUP2/g" $SAVE_PWD/setfacl.test | runacltest ||
316 #error "$? setfacl tests failed"
317
318         #sed -e "s/joe/$USER1/g;s/lisa/$USER2/g;s/users/$GROUP1/g;s/toolies/$GROUP2/g" $SAVE_PWD/acl_asroot.test | runacltest || error "$? acl_asroot tests failed"
319
320         #sed -e "s/joe/$USER1/g;s/lisa/$USER2/g;s/users/$GROUP1/g;s/toolies/$GROUP2/g" $SAVE_PWD/acl_perm.test | runacltest || error "$? acl_perm tests failed"
321
322         #sed -e "s/joe/$USER1/g;s/lisa/$USER2/g;s/users/$GROUP1/g;s/toolies/$GROUP2/g" $SAVE_PWD/acl_misc.test | runacltest || error "$? acl_misc tests failed"
323
324         sed -e "s/joe/$USER1/g;s/lisa/$USER2/g;s/users/$GROUP1/g;s/toolies/$GROUP2/g" $SAVE_PWD/acl_fileutil.test | runacltest || error "$? acl_fileutil tests failed"
325
326         umask $SAVE_UMASK
327 }
328 run_test 3 "==============acl test ============="
329
330 TMPDIR=$OLDTMPDIR
331 TMP=$OLDTMP
332 HOME=$OLDHOME
333
334 log "cleanup: ======================================================"
335 if [ "`mount | grep ^$NAME`" ]; then
336         rm -rf $DIR/[Rdfs][1-9]*
337         if [ "$I_MOUNTED" = "yes" ]; then
338                 sh llmountcleanup.sh || error
339         fi
340 fi
341
342 echo '=========================== finished ==============================='
343 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true