Whamcloud - gitweb
LU-5710 all: second batch of corrected typos and grammar errors
[fs/lustre-release.git] / lustre / tests / sanity-gss.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 # bug number for skipped test:
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"$SANITY_GSS_EXCEPT"}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 SRCDIR=`dirname $0`
15
16 export MULTIOP=${MULTIOP:-multiop}
17
18 LUSTRE=${LUSTRE:-`dirname $0`/..}
19 . $LUSTRE/tests/test-framework.sh
20 init_test_env $@
21 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 init_logging
23
24 require_dsh_mds || exit 0
25
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
27
28 # $RUNAS_ID may get set incorrectly somewhere else
29 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
30
31 # remove $SEC, we'd like to control everything by ourselves
32 unset SEC
33
34 #
35 # global variables of this sanity
36 #
37 DBENCH_PID=0
38
39 # set manually
40 GSS=true
41
42 # we want double mount
43 MOUNT_2=${MOUNT_2:-"yes"}
44 check_and_setup_lustre
45
46 rm -rf $DIR/[df][0-9]*
47
48 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
49
50 build_test_filter
51
52 start_dbench()
53 {
54     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
55     [ $NPROC -gt 2 ] && NPROC=2
56     sh rundbench $NPROC 1>/dev/null &
57     DBENCH_PID=$!
58     sleep 2
59
60     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
61     if [ $num -ne 1 ]; then
62         error "failed to start dbench $NPROC"
63     else
64         echo "started dbench with $NPROC processes at background"
65     fi
66
67     return 0
68 }
69
70 check_dbench()
71 {
72     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
73     if [ $num -eq 0 ]; then
74         echo "dbench $DBENCH_PID already finished"
75         wait $DBENCH_PID || error "dbench $PID exit with error"
76         start_dbench
77     elif [ $num -ne 1 ]; then
78         killall -9 dbench
79         error "found $num instance of pid $DBENCH_PID ???"
80     fi
81
82     return 0
83 }
84
85 stop_dbench()
86 {
87     for ((;;)); do
88         killall dbench 2>/dev/null
89         num=`ps --no-headers -p $DBENCH_PID | wc -l`
90         if [ $num -eq 0 ]; then
91             echo "dbench finished"
92             break
93         fi
94         echo "dbench $DBENCH_PID is still running, waiting 2s..."
95         sleep 2
96     done
97
98     wait $DBENCH_PID || true
99     sync || true
100 }
101
102 calc_connection_cnt
103 umask 077
104
105 set_flavor_all gssnull
106
107 test_1() {
108         local file=$DIR/$tfile
109
110         chmod 0777 $DIR || error "chmod $DIR failed"
111         # access w/o context
112         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
113         $RUNAS touch $DIR
114         $RUNAS touch $file || error "should not fail"
115         [ -f $file ] || error "$file not found"
116 }
117 run_test 1 "create file"
118
119 test_2() {
120     local file1=$DIR/$tfile-1
121     local file2=$DIR/$tfile-2
122
123     chmod 0777 $DIR || error "chmod $DIR failed"
124     # current access should be ok
125     $RUNAS touch $file1 || error "can't touch $file1"
126     [ -f $file1 ] || error "$file1 not found"
127
128         # cleanup all cred/ctx and touch
129         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
130         $RUNAS touch $file2 && error "unexpected success"
131 }
132 run_test 2 "lfs flushctx"
133
134 test_3() {
135     local file=$DIR/$tfile
136
137     # create file
138     echo "aaaaaaaaaaaaaaaaa" > $file
139     chmod 0666 $file
140     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
141     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
142     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
143
144     # start multiop
145     $RUNAS $MULTIOP $file o_r &
146     OPPID=$!
147     # wait multiop finish its open()
148     sleep 1
149
150     # cleanup all cred/ctx and check
151     # metadata check should fail, but file data check should success
152     # because we always use root credential to OSTs
153     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
154     echo "destroied credentials/contexs for $RUNAS_ID"
155     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
156     kill -s 10 $OPPID
157     wait $OPPID || error "read file data failed"
158     echo "read file data OK"
159 }
160 run_test 3 "local cache under DLM lock"
161
162 test_6() {
163     local nfile=10
164
165     mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
166     for ((i=0; i<$nfile; i++)); do
167         dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 || error "dd file$i failed"
168     done
169     ls -l $DIR/d6/* > /dev/null || error "ls failed"
170     rm -rf $DIR2/d6/* || error "rm failed"
171     rmdir $DIR2/d6/ || error "rmdir failed"
172 }
173 run_test 6 "test basic DLM callback works"
174
175 test_7() {
176         local tdir=$DIR/d7
177         local num_osts
178
179         # for open(), client only reserve space for default stripe count lovea,
180         # and server may return larger lovea in reply (because of larger stripe
181         # count), client need call enlarge_reqbuf() and save the replied lovea
182         # in request for future possible replay.
183         #
184         # Note: current script does NOT guarantee enlarge_reqbuf() will be in
185         # the path, however it does work in local test which has 2 OSTs and
186         # default stripe count is 1.
187         num_osts=$($LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l)
188         echo "found $num_osts active OSTs"
189         [ $num_osts -lt 2 ] &&
190                 echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
191
192         mkdir $tdir || error "mkdir $tdir failed"
193         $LFS setstripe -c $num_osts $tdir || error "setstripe -c $num_osts"
194
195         echo "creating..."
196         for ((i = 0; i < 20; i++)); do
197                 dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
198         done
199         echo "reading..."
200         for ((i = 0; i < 20; i++)); do
201                 dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
202         done
203         rm -rf $tdir
204 }
205 run_test 7 "exercise enlarge_reqbuf()"
206
207 test_8()
208 {
209     local ATHISTORY=$(do_facet $SINGLEMDS "find /sys/ -name at_history")
210     local ATOLDBASE=$(do_facet $SINGLEMDS "cat $ATHISTORY")
211     local REQ_DELAY
212     do_facet $SINGLEMDS "echo 8 >> $ATHISTORY"
213
214     mkdir -p $DIR/d8
215     chmod a+w $DIR/d8
216
217     $LCTL dk > /dev/null
218     debugsave
219     sysctl -w lnet.debug="+other"
220
221     # wait for the at estimation come down, this is faster
222     while [ true ]; do
223         REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
224                    awk '/portal 12/ {print $5}' | tail -1`
225         [ $REQ_DELAY -le 5 ] && break
226         echo "current AT estimation is $REQ_DELAY, wait a little bit"
227         sleep 8
228     done
229     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
230
231     # sleep sometime in ctx handle
232     do_facet $SINGLEMDS lctl set_param fail_val=$REQ_DELAY
233 #define OBD_FAIL_SEC_CTX_HDL_PAUSE       0x1204
234     do_facet $SINGLEMDS lctl set_param fail_loc=0x1204
235
236     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
237
238     $RUNAS touch $DIR/d8/f &
239     TOUCHPID=$!
240     echo "waiting for touch (pid $TOUCHPID) to finish..."
241     sleep 2 # give it a chance to really trigger context init rpc
242     do_facet $SINGLEMDS $LCTL set_param fail_loc=0
243     wait $TOUCHPID || error "touch should have succeeded"
244
245     $LCTL dk | grep "Early reply #" || error "No early reply"
246
247     debugrestore
248     do_facet $SINGLEMDS "echo $ATOLDBASE >> $ATHISTORY" || true
249 }
250 run_test 8 "Early reply sent for slow gss context negotiation"
251
252 #
253 # following tests will manipulate flavors and may end with any flavor set,
254 # so each test should not assume any start flavor.
255 #
256
257 test_90() {
258     if [ "$SLOW" = "no" ]; then
259         total=10
260     else
261         total=60
262     fi
263
264     restore_to_default_flavor
265         set_rule $FSNAME any any gssnull
266         wait_flavor all2all gssnull
267
268     start_dbench
269
270     for ((n=0;n<$total;n++)); do
271         sleep 2
272         check_dbench
273         echo "flush ctx ($n/$total) ..."
274         $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
275     done
276     check_dbench
277     #sleep to let ctxs be re-established
278     sleep 10
279     stop_dbench
280 }
281 run_test 90 "recoverable from losing contexts under load"
282
283 test_99() {
284     local nrule_old=0
285     local nrule_new=0
286     local max=64
287
288     #
289     # general rules
290     #
291     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
292                | grep "$FSNAME.srpc.flavor." | wc -l`
293     echo "original general rules: $nrule_old"
294
295     for ((i = $nrule_old; i < $max; i++)); do
296         set_rule $FSNAME elan$i any gssnull || error "set rule $i"
297     done
298     for ((i = $nrule_old; i < $max; i++)); do
299         set_rule $FSNAME elan$i any || error "remove rule $i"
300     done
301
302     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
303                | grep "$FSNAME.srpc.flavor." | wc -l`
304     if [ $nrule_new != $nrule_old ]; then
305         error "general rule: $nrule_new != $nrule_old"
306     fi
307 }
308 run_test 99 "set large number of sptlrpc rules"
309
310 error_dbench()
311 {
312     local err_str=$1
313
314     killall -9 dbench
315     sleep 1
316
317     error $err_str
318 }
319
320 test_100() {
321         # started from default flavors
322         restore_to_default_flavor
323
324         # running dbench background
325         start_dbench
326
327         #
328         # all: null -> gssnull -> plain
329         #
330         set_rule $FSNAME any any gssnull
331         wait_flavor all2all gssnull || error_dbench "1"
332         check_dbench
333
334         set_rule $FSNAME any any plain
335         wait_flavor all2all plain || error_dbench "2"
336         check_dbench
337
338         #
339         # M - M: gssnull
340         # C - M: gssnull
341         # M - O: gssnull
342         # C - O: gssnull
343         #
344         set_rule $FSNAME any mdt2mdt gssnull
345         wait_flavor mdt2mdt gssnull || error_dbench "3"
346         check_dbench
347
348         set_rule $FSNAME any cli2mdt gssnull
349         wait_flavor cli2mdt gssnull || error_dbench "4"
350         check_dbench
351
352         set_rule $FSNAME any mdt2ost gssnull
353         wait_flavor mdt2ost gssnull || error_dbench "5"
354         check_dbench
355
356         set_rule $FSNAME any cli2ost gssnull
357         wait_flavor cli2ost gssnull || error_dbench "6"
358         check_dbench
359
360         #
361         # * - MDT0: plain
362         # * - OST0: plain
363         #
364         # nothing should be changed because they are override by above dir rules
365         #
366         set_rule $FSNAME-MDT0000 any any plain
367         set_rule $FSNAME-OST0000 any any plain
368         wait_flavor mdt2mdt gssnull || error_dbench "7"
369         wait_flavor cli2mdt gssnull || error_dbench "8"
370         check_dbench
371         wait_flavor mdt2ost gssnull || error_dbench "9"
372         wait_flavor cli2ost gssnull || error_dbench "10"
373
374         #
375         # delete all dir-specific rules
376         #
377         set_rule $FSNAME any mdt2mdt
378         set_rule $FSNAME any cli2mdt
379         set_rule $FSNAME any mdt2ost
380         set_rule $FSNAME any cli2ost
381         wait_flavor mdt2mdt gssnull $((MDSCOUNT - 1)) || error_dbench "11"
382         wait_flavor cli2mdt gssnull $(get_clients_mount_count) ||
383                 error_dbench "12"
384         check_dbench
385         wait_flavor mdt2ost gssnull $MDSCOUNT || error_dbench "13"
386         wait_flavor cli2ost gssnull $(get_clients_mount_count) ||
387                 error_dbench "14"
388         check_dbench
389
390         #
391         # remove:
392         #  * - MDT0: gssnull
393         #  * - OST0: gssnull
394         #
395         set_rule $FSNAME-MDT0000 any any
396         set_rule $FSNAME-OST0000 any any || error_dbench "15"
397         wait_flavor all2all plain || error_dbench "16"
398         check_dbench
399
400         stop_dbench
401 }
402 run_test 100 "change security flavor on the fly under load"
403
404 switch_sec_test()
405 {
406     local flavor0=$1
407     local flavor1=$2
408     local filename=$DIR/$tfile
409     local multiop_pid
410     local num
411
412     #
413     # after set to flavor0, start multop which use flavor0 rpc, and let
414     # server drop the reply; then switch to flavor1, the resend should be
415     # completed using flavor1. To exercise the code of switching ctx/sec
416     # for a resend request.
417     #
418     log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
419
420     set_rule $FSNAME any cli2mdt $flavor0
421     wait_flavor cli2mdt $flavor0
422     rm -f $filename || error "remove old $filename failed"
423
424 #MDS_REINT = 36
425 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC     0x513
426     do_facet $SINGLEMDS lctl set_param fail_val=36
427     do_facet $SINGLEMDS lctl set_param fail_loc=0x513
428     log "starting multiop"
429     $MULTIOP $filename m &
430     multiop_pid=$!
431     echo "multiop pid=$multiop_pid"
432     sleep 1
433
434     set_rule $FSNAME any cli2mdt $flavor1
435     wait_flavor cli2mdt $flavor1
436
437     num=`ps --no-headers -p $multiop_pid 2>/dev/null | wc -l`
438     [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
439     echo "process $multiop_pid is still hanging there... OK"
440
441     do_facet $SINGLEMDS lctl set_param fail_loc=0
442     log "waiting for multiop ($multiop_pid) to finish"
443     wait $multiop_pid || error "multiop returned error"
444 }
445
446 test_101()
447 {
448         # started from default flavors
449         restore_to_default_flavor
450
451         switch_sec_test null    plain
452         switch_sec_test plain   gssnull
453         switch_sec_test gssnull null
454         switch_sec_test null    gssnull
455         switch_sec_test gssnull plain
456         switch_sec_test plain   gssnull
457 }
458 run_test 101 "switch ctx/sec for resending request"
459
460 error_102()
461 {
462     local err_str=$1
463
464     killall -9 dbench
465     sleep 1
466
467     error $err_str
468 }
469
470 test_102() {
471     # started from default flavors
472     restore_to_default_flavor
473
474     # run dbench background
475     start_dbench
476
477         echo "Testing null->gssnull->plain->null"
478         set_rule $FSNAME any any gssnull
479         set_rule $FSNAME any any plain
480         set_rule $FSNAME any any null
481
482     check_dbench
483     wait_flavor all2all null || error_dbench "1"
484     check_dbench
485
486     echo "waiting for 15s and check again"
487     sleep 15
488     check_dbench
489
490         echo "Testing null->gssnull->null->gssnull->null..."
491         for ((i=0; i<10; i++)); do
492                 set_rule $FSNAME any any gssnull
493                 set_rule $FSNAME any any null
494         done
495         set_rule $FSNAME any any gssnull
496
497         check_dbench
498         wait_flavor all2all gssnull || error_dbench "2"
499         check_dbench
500
501     echo "waiting for 15s and check again"
502     sleep 15
503     check_dbench
504
505     stop_dbench
506 }
507 run_test 102 "survive from insanely fast flavor switch"
508
509 test_150() {
510     local mount_opts
511     local count
512     local clients=$CLIENTS
513
514     [ -z $clients ] && clients=$HOSTNAME
515
516     # started from default flavors
517     restore_to_default_flavor
518
519     # at this time no rules has been set on mgs; mgc use null
520     # flavor connect to mgs.
521     count=`flvr_cnt_mgc2mgs null`
522     [ $count -eq 1 ] || error "$count mgc connection use null flavor"
523
524     zconf_umount_clients $clients $MOUNT || return 1
525
526     # mount client with conflict flavor - should fail
527     mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=gssnull"
528     zconf_mount_clients $clients $MOUNT $mount_opts &&
529         error "mount with conflict flavor should have failed"
530
531     # mount client with same flavor - should succeed
532     mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=null"
533     zconf_mount_clients $clients $MOUNT $mount_opts ||
534         error "mount with same flavor should have succeeded"
535     zconf_umount_clients $clients $MOUNT || return 2
536
537     # mount client with default flavor - should succeed
538     zconf_mount_clients $clients $MOUNT || \
539         error "mount with default flavor should have succeeded"
540 }
541 run_test 150 "secure mgs connection: client flavor setting"
542
543 test_151() {
544         local save_opts
545
546         # set mgs only accept gssnull
547         set_rule _mgs any any gssnull
548
549     # umount everything, modules still loaded
550     stopall
551
552     # mount mgs with default flavor, in current framework it means mgs+mdt1.
553     # the connection of mgc of mdt1 to mgs is expected fail.
554     DEVNAME=$(mdsdevname 1)
555     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with default flavor should have failed"
556
557     # mount with unauthorized flavor should fail
558     save_opts=$MDS_MOUNT_OPTS
559     MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=null"
560     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with unauthorized flavor should have failed"
561     MDS_MOUNT_OPTS=$save_opts
562
563     # mount with designated flavor should succeed
564     save_opts=$MDS_MOUNT_OPTS
565         MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=gssnull"
566         start mds1 $DEVNAME $MDS_MOUNT_OPTS ||
567                 error "mount with designated flavor should have succeeded"
568         MDS_MOUNT_OPTS=$save_opts
569
570         stop mds1 -f
571 }
572 run_test 151 "secure mgs connection: server flavor control"
573
574 complete $SECONDS
575 check_and_cleanup_lustre
576 exit_status