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