Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / tests / sanity-gss.sh
1 #!/bin/bash
2 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test:
12 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 [ "$SLOW" = "no" ] && EXCEPT="$EXCEPT"
16
17 # Tests that fail on uml, maybe elsewhere, FIXME
18 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
19 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT"
20
21 case `uname -r` in
22 2.6*) FSTYPE=${FSTYPE:-ldiskfs}; ALWAYS_EXCEPT="$ALWAYS_EXCEPT " ;;
23 *) error "unsupported kernel (gss only works with 2.6.x)" ;;
24 esac
25
26 SRCDIR=`dirname $0`
27 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$SRCDIR/../utils/gss:$PATH:/sbin
28
29 TMP=${TMP:-/tmp}
30
31 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
32 CREATETEST=${CREATETEST:-createtest}
33 LFS=${LFS:-lfs}
34 LCTL=${LCTL:-lctl}
35 MEMHOG=${MEMHOG:-memhog}
36 DIRECTIO=${DIRECTIO:-directio}
37 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
38 UMOUNT=${UMOUNT:-"umount -d"}
39
40 if [ $UID -ne 0 ]; then
41     echo "Warning: running as non-root uid $UID"
42     RUNAS_ID="$UID"
43     RUNAS=""
44 else
45     RUNAS_ID=${RUNAS_ID:-500}
46     RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
47
48     # $RUNAS_ID may get set incorrectly somewhere else
49     if [ $RUNAS_ID -eq 0 ]; then
50         echo "Error: \$RUNAS_ID set to 0, but \$UID is also 0!"
51         exit 1
52     fi
53 fi
54
55 SANITYLOG=${SANITYLOG:-/tmp/sanity-gss.log}
56
57 export NAME=${NAME:-local}
58
59 SAVE_PWD=$PWD
60
61 #
62 # check pre-set $SEC
63 #
64 if [ ! -z $SEC ]; then
65     if [ "$SEC" != "krb5i" -a "$SEC" != "krb5p" ]; then
66         echo "SEC=$SEC is invalid, this script only run in gss mode (krb5i/krb5p)"
67         exit 1
68     fi
69 fi
70
71 export SEC=${SEC:-krb5p}
72 export KRB5_CCACHE_DIR=/tmp
73 export KRB5_CRED=$KRB5_CCACHE_DIR/krb5cc_$RUNAS_ID
74 export KRB5_CRED_SAVE=$KRB5_CCACHE_DIR/krb5cc.sanity.save
75
76 echo "Using security flavor $SEC"
77
78 LUSTRE=${LUSTRE:-`dirname $0`/..}
79 . $LUSTRE/tests/test-framework.sh
80 init_test_env $@
81 . ${CONFIG:=$LUSTRE/tests/cfg/local.sh}
82
83 prepare_krb5_creds() {
84     rm -f $CRED_SAVE
85     $RUNAS krb5_login.sh || exit 1
86     [ -f $KRB5_CRED ] || exit 2
87     cp $KRB5_CRED $KRB5_CRED_SAVE
88 }
89
90 cleanup() {
91     echo -n "cln.."
92     cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
93 }
94 CLEANUP=${CLEANUP:-:}
95
96 setup() {
97     echo -n "mnt.."
98     load_modules
99     setupall || exit 10
100     echo "done"
101 }
102 SETUP=${SETUP:-:}
103
104 trace() {
105     log "STARTING: $*"
106     strace -o $TMP/$1.strace -ttt $*
107     RC=$?
108     log "FINISHED: $*: rc $RC"
109     return 1
110 }
111 TRACE=${TRACE:-""}
112
113 check_kernel_version() {
114     VERSION_FILE=$LPROC/kernel_version
115     WANT_VER=$1
116     [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
117     GOT_VER=`cat $VERSION_FILE`
118     [ $GOT_VER -ge $WANT_VER ] && return 0
119     log "test needs at least kernel version $WANT_VER, running $GOT_VER"
120     return 1
121 }
122
123 _basetest() {
124     echo $*
125 }
126
127 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
128
129
130 prepare_krb5_creds
131 build_test_filter
132 umask 077
133
134 # setup filesystem
135 formatall
136 setupall
137 chmod a+rwx $MOUNT
138
139 restore_krb5_cred() {
140     cp $KRB5_CRED_SAVE $KRB5_CRED
141     chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
142     chmod 0600 $KRB5_CRED
143 }
144
145 test_1() {
146     # access w/o cred
147     $RUNAS kdestroy
148     $RUNAS touch $MOUNT/f1 && error "unexpected success"
149
150     # access w/ cred
151     restore_krb5_cred
152     $RUNAS touch $MOUNT/f1 || error "should not fail"
153     [ -f $MOUNT/f1 ] || error "$MOUNT/f1 not found"
154 }
155 run_test 1 "access with or without krb5 credential"
156
157 test_2() {
158     # current access should be ok
159     $RUNAS touch $MOUNT/f2_1 || error "can't touch $MOUNT/f2_1"
160     [ -f $MOUNT/f2_1 ] || error "$MOUNT/f2_1 not found"
161
162     # cleanup all cred/ctx and touch
163     $RUNAS kdestroy
164     $RUNAS $LFS flushctx
165     $RUNAS touch $MOUNT/f2_2 && error "unexpected success"
166
167     # restore and touch
168     restore_krb5_cred
169     $RUNAS touch $MOUNT/f2_2 || error "should not fail"
170     [ -f $MOUNT/f2_2 ] || error "$MOUNT/f2_2 not found"
171 }
172 run_test 2 "lfs flushctx"
173
174 test_3() {
175     local file=$MOUNT/f3
176
177     # create file
178     echo "aaaaaaaaaaaaaaaaa" > $file
179     chmod 0666 $file
180     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
181     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
182     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
183
184     # start multiop
185     $RUNAS multiop $file o_r &
186     OPPID=$!
187     # wait multiop finish its open()
188     sleep 1
189
190     # cleanup all cred/ctx and check
191     # metadata check should fail, but file data check should success
192     # because we always use root credential to OSTs
193     $RUNAS kdestroy
194     $RUNAS $LFS flushctx
195     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
196     kill -s 10 $OPPID
197     wait $OPPID || error "read file data failed"
198     echo "read file data OK"
199
200     # restore and check again
201     restore_krb5_cred
202     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
203     $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
204     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
205 }
206 run_test 3 "local cache under DLM lock"
207
208 test_4() {
209     local file1=$MOUNT/f4_1
210     local file2=$MOUNT/f4_2
211
212     # current access should be ok
213     $RUNAS touch $file1 || error "can't touch $file1"
214     [ -f $file1 ] || error "$file1 not found"
215
216     # stop lgssd
217     send_sigint client lgssd
218     sleep 5
219     check_gss_daemon_facet client lgssd && error "lgssd still running"
220
221     # flush context, and touch
222     $RUNAS $LFS flushctx
223     $RUNAS touch $file2 &
224     TOUCHPID=$!
225     echo "waiting touch pid $TOUCHPID"
226     wait $TOUCHPID && error "touch should fail"
227
228     # restart lgssd
229     do_facet client "$LGSSD -v"
230     sleep 5
231     check_gss_daemon_facet client lgssd
232
233     # touch new should succeed
234     $RUNAS touch $file2 || error "can't touch $file2"
235     [ -f $file2 ] || error "$file2 not found"
236 }
237 run_test 4 "lgssd dead, operations should wait timeout and fail"
238
239 test_5() {
240     local file1=$MOUNT/f5_1
241     local file2=$MOUNT/f5_2
242     local wait_time=120
243
244     # current access should be ok
245     $RUNAS touch $file1 || error "can't touch $file1"
246     [ -f $file1 ] || error "$file1 not found"
247
248     # stop lsvcgssd
249     send_sigint mds lsvcgssd
250     sleep 5
251     check_gss_daemon_facet mds lsvcgssd && error "lsvcgssd still running"
252
253     # flush context, and touch
254     $RUNAS $LFS flushctx
255     $RUNAS touch $file2 &
256     TOUCHPID=$!
257
258     # wait certain time
259     echo "waiting $wait_time seconds for touch pid $TOUCHPID"
260     sleep $wait_time
261     num=`ps --no-headers -p $TOUCHPID | wc -l`
262     [ $num -eq 1 ] || error "touch already ended ($num)"
263     echo "process $TOUCHPID still hanging there... OK"
264
265     # restart lsvcgssd, expect touch suceed
266     echo "restart lsvcgssd and recovering"
267     do_facet mds "$LSVCGSSD -v"
268     sleep 5
269     check_gss_daemon_facet mds lsvcgssd
270     wait $TOUCHPID || error "touch fail"
271     [ -f $file2 ] || error "$file2 not found"
272 }
273 run_test 5 "lsvcgssd dead, operations lead to recovery"
274
275 test_6() {
276     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
277     [ $NPROC -ne 0 ] || NPROC=2
278
279     echo "starting dbench $NPROC"
280     sh rundbench $NPROC &
281     RUNPID=$!
282
283     for ((n=0;;n++)); do
284         sleep 2
285         num=`ps --no-headers -p $RUNPID | wc -l`
286         [ $num -ne 0 ] || break
287         echo "flush ctx ..."
288         $LFS flushctx
289     done
290     wait $RUNPID || error "dbench detect error"
291 }
292 run_test 6 "recoverable from losing context"
293
294 test_7() {
295     local tdir=$MOUNT/dir7
296     local num_osts
297
298     #
299     # for open(), client only reserve space for default stripe count lovea,
300     # and server may return larger lovea in reply (because of larger stripe
301     # count), client need call enlarge_reqbuf() and save the replied lovea
302     # in request for future possible replay.
303     #
304     # Note: current script does NOT guarantee enlarge_reqbuf() will be in
305     # the path, however it does work in local test which has 2 OSTs and
306     # default stripe count is 1.
307     #
308     num_osts=`$LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l`
309     echo "found $num_osts active OSTs"
310     [ $num_osts -lt 2 ] && echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
311
312     mkdir $tdir || error
313     $LFS setstripe $tdir 0 -1 -1 || error
314
315     echo "creating..."
316     for ((i=0;i<20;i++)); do
317         dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
318     done
319     echo "reading..."
320     for ((i=0;i<20;i++)); do
321         dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
322     done
323     rm -rf $tdir
324 }
325 run_test 7 "exercise enlarge_reqbuf()"
326
327 check_multiple_gss_daemons() {
328     local facet=$1
329
330     for ((i=0;i<10;i++)); do
331         do_facet $facet "$LSVCGSSD -v &"
332     done
333     for ((i=0;i<10;i++)); do
334         do_facet $facet "$LGSSD -v &"
335     done
336
337     # wait daemons entering "stable" status
338     sleep 5
339
340     numc=`do_facet $facet ps -o cmd -C lgssd | grep lgssd | wc -l`
341     nums=`do_facet $facet ps -o cmd -C lgssd | grep lgssd | wc -l`
342     echo "$numc lgssd and $nums lsvcgssd are running"
343
344     if [ $numc -ne 1 -o $nums -ne 1 ]; then
345         error "lgssd/lsvcgssd not unique"
346     fi
347 }
348
349 test_100() {
350     local facet=mds
351
352     # cleanup everything at first
353     cleanupall
354
355     echo "bring up gss daemons..."
356     start_gss_daemons
357
358     echo "check with someone already running..."
359     check_multiple_gss_daemons $facet
360
361     echo "check with someone run & finished..."
362     do_facet $facet killall -q -2 lgssd lsvcgssd || true
363     sleep 5 # wait fully exit
364     check_multiple_gss_daemons $facet
365
366     echo "check refresh..."
367     do_facet $facet killall -q -2 lgssd lsvcgssd || true
368     sleep 5 # wait fully exit
369     do_facet $facet ipcrm -S 0x3b92d473
370     do_facet $facet ipcrm -S 0x3a92d473
371     check_multiple_gss_daemons $facet
372
373     stop_gss_daemons
374 }
375 run_test 100 "start more multiple gss daemons"
376
377 TMPDIR=$OLDTMPDIR
378 TMP=$OLDTMP
379 HOME=$OLDHOME
380
381 log "cleanup: ======================================================"
382 if [ "`mount | grep ^$NAME`" ]; then
383     rm -rf $DIR/[Rdfs][1-9]*
384 fi
385
386 cleanupall -f || error "cleanup failed"
387
388
389 echo '=========================== finished ==============================='
390 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true