Whamcloud - gitweb
fix handling ost additional.
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2 # requirement:
3 #       add uml1 uml2 uml3 in your /etc/hosts
4
5 # FIXME - there is no reason to use all of these different
6 #   return codes, espcially when most of them are mapped to something
7 #   else anyway.  The combination of test number and return code
8 #   figure out what failed.
9
10 set -e
11
12 ONLY=${ONLY:-"$*"}
13
14 # bug number for skipped test: 13739
15 HEAD_EXCEPT="                  32a 32b"
16
17 # bug number for skipped test:                                 
18 ALWAYS_EXCEPT=" $CONF_SANITY_EXCEPT $HEAD_EXCEPT"
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20
21 SRCDIR=`dirname $0`
22 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
23
24 PTLDEBUG=${PTLDEBUG:--1}
25 SAVE_PWD=$PWD
26 LUSTRE=${LUSTRE:-`dirname $0`/..}
27 RLUSTRE=${RLUSTRE:-$LUSTRE}
28
29 . $LUSTRE/tests/test-framework.sh
30 init_test_env $@
31 # STORED_MDSSIZE is used in test_18
32 if [ -n "$MDSSIZE" ]; then
33     STORED_MDSSIZE=$MDSSIZE
34 fi
35 # use small MDS + OST size to speed formatting time
36 MDSSIZE=40000
37 OSTSIZE=40000
38 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
39
40 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
41 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
42
43 #
44 [ "$SLOW" = "no" ] && EXCEPT_SLOW="0 1 2 3 6 7 15 18 24b 25 30 31 32 33 34a 45"
45
46 assert_DIR
47
48 reformat() {
49         formatall
50 }
51
52 writeconf() {
53     local facet=$SINGLEMDS
54     local dev=${facet}_dev
55     shift
56     stop ${facet} -f
57     rm -f ${facet}active
58     # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
59     do_facet ${facet} "$TUNEFS --writeconf ${!dev}" || echo "tunefs failed, reformatting instead" && reformat
60 }
61
62 gen_config() {
63         reformat
64         # The MGS must be started before the OSTs for a new fs, so start
65         # and stop to generate the startup logs. 
66         start_mds
67         start_ost
68         sleep 5
69         stop_ost
70         stop_mds
71 }
72
73 start_mds() {
74         local facet=$SINGLEMDS
75         # we can not use MDSDEV1 here because SINGLEMDS could be set not to mds1 only
76         local num=$(echo $facet | tr -d "mds")
77         local dev=$(mdsdevname $num)
78         echo "start mds service on `facet_active_host $facet`"
79         start $facet ${dev} $MDS_MOUNT_OPTS || return 94
80 }
81
82 stop_mds() {
83         echo "stop mds service on `facet_active_host $SINGLEMDS`"
84         # These tests all use non-failover stop
85         stop $SINGLEMDS -f  || return 97
86 }
87
88 start_ost() {
89         echo "start ost1 service on `facet_active_host ost1`"
90         start ost1 `ostdevname 1` $OST_MOUNT_OPTS || return 95
91 }
92
93 stop_ost() {
94         echo "stop ost1 service on `facet_active_host ost1`"
95         # These tests all use non-failover stop
96         stop ost1 -f  || return 98
97 }
98
99 start_ost2() {
100         echo "start ost2 service on `facet_active_host ost2`"
101         start ost2 `ostdevname 2` $OST_MOUNT_OPTS || return 92
102 }
103
104 stop_ost2() {
105         echo "stop ost2 service on `facet_active_host ost2`"
106         # These tests all use non-failover stop
107         stop ost2 -f  || return 93
108 }
109
110 mount_client() {
111         local MOUNTPATH=$1
112         echo "mount $FSNAME on ${MOUNTPATH}....."
113         zconf_mount `hostname` $MOUNTPATH  || return 96
114 }
115
116 remount_client() {
117         local SAVEMOUNTOPT=$MOUNTOPT
118         MOUNTOPT="remount,$1"
119         local MOUNTPATH=$2
120         echo "remount '$1' lustre on ${MOUNTPATH}....."
121         zconf_mount `hostname`  $MOUNTPATH  || return 96
122         MOUNTOPT=$SAVEMOUNTOPT
123 }
124
125 umount_client() {
126         local MOUNTPATH=$1
127         echo "umount lustre on ${MOUNTPATH}....."
128         zconf_umount `hostname` $MOUNTPATH || return 97
129 }
130
131 manual_umount_client(){
132         local rc
133         local FORCE=$1
134         echo "manual umount lustre on ${MOUNT}...."
135         do_facet client "umount -d ${FORCE} $MOUNT"
136         rc=$?
137         return $rc
138 }
139
140 setup() {
141         start_ost
142         start_mds
143         mount_client $MOUNT
144 }
145
146 cleanup_nocli() {
147         stop_mds || return 201
148         stop_ost || return 202
149         unload_modules || return 203
150 }
151
152 cleanup() {
153         umount_client $MOUNT || return 200
154         cleanup_nocli || return $?
155 }
156
157 check_mount() {
158         do_facet client "cp /etc/passwd $DIR/a" || return 71
159         do_facet client "rm $DIR/a" || return 72
160         # make sure lustre is actually mounted (touch will block, 
161         # but grep won't, so do it after) 
162         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
163         echo "setup single mount lustre success"
164 }
165
166 check_mount2() {
167         do_facet client "touch $DIR/a" || return 71     
168         do_facet client "rm $DIR/a" || return 72        
169         do_facet client "touch $DIR2/a" || return 73    
170         do_facet client "rm $DIR2/a" || return 74       
171         echo "setup double mount lustre success"
172 }
173
174 build_test_filter
175
176 if [ "$ONLY" == "setup" ]; then
177         setup
178         exit
179 fi
180
181 if [ "$ONLY" == "cleanup" ]; then
182         cleanup
183         exit
184 fi
185
186 init_gss
187
188 #create single point mountpoint
189
190 gen_config
191
192 test_0() {
193         setup
194         check_mount || return 41
195         cleanup || return $?
196 }
197 run_test 0 "single mount setup"
198
199 test_1() {
200         start_ost
201         echo "start ost second time..."
202         setup
203         check_mount || return 42
204         cleanup || return $?
205 }
206 run_test 1 "start up ost twice (should return errors)"
207
208 test_2() {
209         start_ost
210         start_mds
211         echo "start mds second time.."
212         start_mds
213         mount_client $MOUNT
214         check_mount || return 43
215         cleanup || return $?
216 }
217 run_test 2 "start up mds twice (should return err)"
218
219 test_3() {
220         setup
221         #mount.lustre returns an error if already in mtab
222         mount_client $MOUNT && return $?
223         check_mount || return 44
224         cleanup || return $?
225 }
226 run_test 3 "mount client twice (should return err)"
227
228 test_4() {
229         setup
230         touch $DIR/$tfile || return 85
231         stop_ost -f
232         cleanup
233         eno=$?
234         # ok for ost to fail shutdown
235         if [ 202 -ne $eno ]; then
236                 return $eno;
237         fi
238         return 0
239 }
240 run_test 4 "force cleanup ost, then cleanup"
241
242 test_5a() {     # was test_5
243         setup
244         touch $DIR/$tfile || return 1
245         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
246
247         stop_mds -f || return 2
248
249         # cleanup may return an error from the failed
250         # disconnects; for now I'll consider this successful
251         # if all the modules have unloaded.
252         umount -d $MOUNT &
253         UMOUNT_PID=$!
254         sleep 6
255         echo "killing umount"
256         kill -TERM $UMOUNT_PID
257         echo "waiting for umount to finish"
258         wait $UMOUNT_PID
259         if grep " $MOUNT " /proc/mounts; then
260                 echo "test 5: /proc/mounts after failed umount"
261                 umount $MOUNT &
262                 UMOUNT_PID=$!
263                 sleep 2
264                 echo "killing umount"
265                 kill -TERM $UMOUNT_PID
266                 echo "waiting for umount to finish"
267                 wait $UMOUNT_PID
268                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
269         fi
270
271         manual_umount_client
272         # stop_mds is a no-op here, and should not fail
273         cleanup_nocli || return $?
274         # df may have lingering entry
275         manual_umount_client
276         # mtab may have lingering entry
277         local WAIT=0
278         local MAX_WAIT=20
279         local sleep=1
280         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
281                 sleep $sleep
282                 grep -q $MOUNT" " /etc/mtab || break
283                 echo "Waiting /etc/mtab updated ... "
284                 WAIT=$(( WAIT + sleep))
285         done
286         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
287         echo "/etc/mtab updated in $WAIT secs"
288 }
289 run_test 5a "force cleanup mds, then cleanup"
290
291 test_5b() {
292         start_ost
293         [ -d $MOUNT ] || mkdir -p $MOUNT
294         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab before mount" && return 10
295         mount_client $MOUNT && return 1
296         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab after failed mount" && return 11
297         umount_client $MOUNT
298         # stop_mds is a no-op here, and should not fail
299         cleanup_nocli || return $?
300         return 0
301 }
302 run_test 5b "mds down, cleanup after failed mount (bug 2712) (should return errs)"
303
304 test_5c() {
305         start_ost
306         start_mds
307         [ -d $MOUNT ] || mkdir -p $MOUNT
308         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab before mount" && return 10
309         local oldfs="${FSNAME}"
310         FSNAME="wrong.${FSNAME}"
311         mount_client $MOUNT || :
312         FSNAME=${oldfs}
313         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab after failed mount" && return 11
314         umount_client $MOUNT
315         cleanup_nocli  || return $?
316 }
317 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
318
319 test_5d() {
320         start_ost
321         start_mds
322         stop_ost -f
323         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab before mount" && return 10
324         mount_client $MOUNT || return 1
325         cleanup  || return $?
326         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab after unmount" && return 11
327         return 0
328 }
329 run_test 5d "mount with ost down"
330
331 test_5e() {
332         start_ost
333         start_mds
334
335 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
336         do_facet client "lctl set_param fail_loc=0x80000506"
337         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab before mount" && return 10
338         mount_client $MOUNT || echo "mount failed (not fatal)"
339         cleanup  || return $?
340         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab after unmount" && return 11
341         return 0
342 }
343 run_test 5e "delayed connect, don't crash (bug 10268)"
344
345 test_6() {
346         setup
347         manual_umount_client
348         mount_client ${MOUNT} || return 87
349         touch $DIR/a || return 86
350         cleanup  || return $?
351 }
352 run_test 6 "manual umount, then mount again"
353
354 test_7() {
355         setup
356         manual_umount_client
357         cleanup_nocli || return $?
358 }
359 run_test 7 "manual umount, then cleanup"
360
361 test_8() {
362         setup
363         mount_client $MOUNT2
364         check_mount2 || return 45
365         umount_client $MOUNT2
366         cleanup  || return $?
367 }
368 run_test 8 "double mount setup"
369
370 test_9() {
371         start_ost
372
373         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
374         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
375
376         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
377         if [ "$CHECK_PTLDEBUG" ] && { \
378            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
379            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then   
380            echo "lnet.debug success"
381         else
382            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
383            return 1
384         fi
385         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
386         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
387            echo "lnet.subsystem_debug success"
388         else
389            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
390            return 1
391         fi
392         stop_ost || return $?
393 }
394
395 run_test 9 "test ptldebug and subsystem for mkfs"
396
397 # LOGS/PENDING do not exist anymore since CMD3
398 test_16() {
399         local TMPMTPT="${TMP}/conf16"
400         local dev=${SINGLEMDS}_dev
401         local MDSDEV=${!dev}
402         if [ ! -e "$MDSDEV" ]; then
403             log "no $MDSDEV existing, so mount Lustre to create one"
404             setup
405             check_mount || return 41
406             cleanup || return $?
407         fi
408
409         [ -f "$MDSDEV" ] && LOOPOPT="-o loop"
410
411         log "change the mode of $MDSDEV/OBJECTS to 555"
412         do_facet $SINGLEMDS "mkdir -p $TMPMTPT &&
413                       mount $LOOPOPT -t $FSTYPE $MDSDEV $TMPMTPT &&
414                       chmod 555 $TMPMTPT/OBJECTS &&
415                       umount $TMPMTPT" || return $?
416
417         log "mount Lustre to change the mode of OBJECTS, then umount Lustre"
418         setup
419         check_mount || return 41
420         cleanup || return $?
421
422         log "read the mode of OBJECTS and check if they has been changed properly"
423         EXPECTEDOBJECTSMODE=`do_facet $SINGLEMDS "debugfs -R 'stat OBJECTS' $MDSDEV 2> /dev/null" | grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
424
425         if [ "$EXPECTEDOBJECTSMODE" = "0777" ]; then
426                 log "Success:Lustre change the mode of OBJECTS correctly"
427         else
428                 error "Lustre does not change mode of OBJECTS properly"
429         fi
430 }
431 run_test 16 "verify that lustre will correct the mode of OBJECTS"
432
433 test_17() {
434         local dev=${SINGLEMDS}_dev
435         local MDSDEV=${!dev}
436
437         if [ ! -e "$MDSDEV" ]; then
438             echo "no $MDSDEV existing, so mount Lustre to create one"
439             setup
440             check_mount || return 41
441             cleanup || return $?
442         fi
443
444         echo "Remove mds config log"
445         do_facet $SINGLEMDS "debugfs -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MDSDEV || return \$?" || return $?
446
447         start_ost
448         start_mds && return 42
449         gen_config
450 }
451 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
452
453 test_18() {
454         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return
455
456         local dev=${SINGLEMDS}_dev
457         local MDSDEV=${!dev}
458
459         local MIN=2000000
460
461         local OK=
462         # check if current MDSSIZE is large enough
463         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
464                 log "use MDSSIZE=$MDSSIZE"
465
466         # check if the global config has a large enough MDSSIZE
467         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
468                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
469                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
470
471         # check if the block device is large enough
472         [ -z "$OK" -a -b $MDSDEV ] && \
473                 [ "$(dd if=$MDSDEV of=/dev/null bs=1k count=1 skip=$MIN 2>&1 |
474                      awk '($3 == "in") { print $1 }')" = "1+0" ] && OK=1 && \
475                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
476
477         # check if a loopback device has enough space for fs metadata (5%)
478         [ -z "$OK" ] && [ -f $MDSDEV -o ! -e $MDSDEV ] &&
479                 SPACE=$(df -P $(dirname $MDSDEV) |
480                         awk '($1 != "Filesystem") {print $4}') &&
481                 [ $SPACE -gt $((MIN / 20)) ] && OK=1 && myMDSSIZE=$MIN && \
482                         log "use file $MDSDEV with MIN=$MIN"
483
484         [ -z "$OK" ] && skip "$MDSDEV too small for ${MIN}kB MDS" && return
485
486
487         echo "mount mds with large journal..."
488         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
489
490         MDS_MKFS_OPTS="--mgs --mdt --fsname=$FSNAME --device-size=$myMDSSIZE --param sys.timeout=$TIMEOUT $MDSOPT"
491
492         gen_config
493         echo "mount lustre system..."
494         setup
495         check_mount || return 41
496
497         echo "check journal size..."
498         local FOUNDSIZE=`do_facet mds "debugfs -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}'`
499         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
500                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
501         else
502                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
503         fi
504
505         cleanup || return $?
506
507         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
508         gen_config
509 }
510 run_test 18 "check mkfs creates large journals"
511
512 test_19a() {
513         start_mds || return 1
514         stop_mds -f || return 2
515 }
516 run_test 19a "start/stop MDS without OSTs"
517
518 test_19b() {
519         start_ost || return 1
520         stop_ost -f || return 2
521 }
522 run_test 19b "start/stop OSTs without MDS"
523
524 test_20() {
525         # first format the ost/mdt
526         start_ost
527         start_mds
528         mount_client $MOUNT
529         check_mount || return 43
530         rm -f $DIR/$tfile
531         remount_client ro $MOUNT || return 44
532         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
533         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
534         remount_client rw $MOUNT || return 47
535         touch $DIR/$tfile
536         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
537         MCNT=`grep -c $MOUNT /etc/mtab`
538         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
539         umount_client $MOUNT
540         stop_mds
541         stop_ost
542 }
543 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
544
545 test_21a() {
546         start_mds
547         start_ost
548         stop_ost
549         stop_mds
550 }
551 run_test 21a "start mds before ost, stop ost first"
552
553 test_21b() {
554         start_ost
555         start_mds
556         stop_mds
557         stop_ost
558 }
559 run_test 21b "start ost before mds, stop mds first"
560
561 test_21c() {
562         start_ost
563         start_mds
564         start_ost2
565         stop_ost
566         stop_ost2
567         stop_mds
568         #writeconf to remove all ost2 traces for subsequent tests
569         writeconf
570 }
571 run_test 21c "start mds between two osts, stop mds last"
572
573 test_22() {
574         start_mds
575
576         echo Client mount with ost in logs, but none running
577         start_ost
578         stop_ost
579         mount_client $MOUNT
580         # check_mount will block trying to contact ost
581         umount_client $MOUNT
582         pass
583
584         echo Client mount with a running ost
585         start_ost
586         if $GSS; then
587                 # if gss enabled, wait full time to let connection from
588                 # mds to ost be established, due to the mismatch between
589                 # initial connect timeout and gss context negotiation timeout.
590                 # This perhaps could be remove after AT landed.
591                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
592                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
593         fi
594         mount_client $MOUNT
595         check_mount || return 41
596         pass
597
598         cleanup
599 }
600 run_test 22 "start a client before osts (should return errs)"
601
602 test_23a() {    # was test_23
603         setup
604         # fail mds
605         stop $SINGLEMDS   
606         # force down client so that recovering mds waits for reconnect
607         local running=$(grep -c $MOUNT /proc/mounts) || true
608         if [ $running -ne 0 ]; then
609                 echo "Stopping client $MOUNT (opts: -f)"
610                 umount -f $MOUNT
611         fi
612
613         # enter recovery on mds
614         start_mds
615         # try to start a new client
616         mount_client $MOUNT &
617         sleep 5
618         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
619         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
620         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
621         ps --ppid $MOUNT_PID
622         ps --ppid $MOUNT_LUSTRE_PID
623         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
624         kill -TERM $MOUNT_LUSTRE_PID
625         echo "waiting for mount to finish"
626         ps -ef | grep mount
627         # we can not wait $MOUNT_PID because it is not a child of this shell
628         local PID1
629         local PID2
630         local WAIT=0
631         local MAX_WAIT=20
632         local sleep=1
633         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
634                 sleep $sleep
635                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
636                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
637                 echo PID1=$PID1
638                 echo PID2=$PID2
639                 [ -z "$PID1" -a -z "$PID2" ] && break
640                 echo "waiting for mount to finish ... "
641                 WAIT=$(( WAIT + sleep))
642         done
643         [ "$WAIT" -eq "$MAX_WAIT" ] && error "MOUNT_PID $MOUNT_PID and \
644                 MOUNT__LUSTRE_PID $MOUNT__LUSTRE_PID still not killed in $WAIT secs"
645         ps -ef | grep mount
646         stop_mds || error
647         stop_ost || error
648 }
649 run_test 23a "interrupt client during recovery mount delay"
650
651 umount_client $MOUNT
652 cleanup_nocli
653
654 test_23b() {    # was test_23
655         start_ost
656         start_mds
657         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
658         lctl set_param fail_loc=0x80000313
659         mount_client $MOUNT
660         cleanup
661 }
662 run_test 23b "Simulate -EINTR during mount"
663
664 fs2mds_HOST=$mds_HOST
665 fs2ost_HOST=$ost_HOST
666
667 cleanup_24a() {
668         trap 0
669         echo "umount $MOUNT2 ..."
670         umount $MOUNT2 || true
671         echo "stopping fs2mds ..."
672         stop fs2mds -f || true
673         echo "stopping fs2ost ..."
674         stop fs2ost -f || true
675 }
676
677 test_24a() {
678         #set up fs1 
679         gen_config
680         #set up fs2
681         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
682         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
683                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
684                 skip "mixed loopback and real device not working" && return
685         fi
686
687         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
688         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
689
690         # test 8-char fsname as well
691         local FSNAME2=test1234
692         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat $fs2mdsdev || exit 10
693
694         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
695
696         setup
697         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
698         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
699         mkdir -p $MOUNT2
700         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
701         # 1 still works
702         check_mount || return 2
703         # files written on 1 should not show up on 2
704         cp /etc/passwd $DIR/$tfile
705         sleep 10
706         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
707         # 2 should work
708         sleep 5
709         cp /etc/passwd $MOUNT2/b || return 3
710         rm $MOUNT2/b || return 4
711         # 2 is actually mounted
712         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
713         # failover 
714         facet_failover fs2mds
715         facet_failover fs2ost
716         df
717         umount_client $MOUNT 
718         # the MDS must remain up until last MDT
719         stop_mds
720         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
721         [ -z "$MDS" ] && error "No MDT" && return 8
722         cleanup_24a
723         cleanup_nocli || return 6
724 }
725 run_test 24a "Multiple MDTs on a single node"
726
727 test_24b() {
728         if [ -z "$fs2mds_DEV" ]; then
729                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
730                 skip "mixed loopback and real device not working" && return
731         fi
732
733         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
734
735         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat $fs2mdsdev || exit 10 
736         setup
737         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
738         cleanup || return 6
739 }
740 run_test 24b "Multiple MGSs on a single node (should return err)"
741
742 test_25() {
743         setup
744         check_mount || return 2
745         local MODULES=$($LCTL modules | awk '{ print $2 }')
746         rmmod $MODULES 2>/dev/null || true
747         cleanup || return 6
748 }
749 run_test 25 "Verify modules are referenced"
750
751 test_26() {
752     load_modules
753     # we need modules before mount for sysctl, so make sure...
754     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
755 #define OBD_FAIL_MDS_FS_SETUP            0x135
756     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
757     start_mds && echo MDS started && return 1
758     lctl get_param -n devices
759     DEVS=$(lctl get_param -n devices | wc -l)
760     [ $DEVS -gt 0 ] && return 2
761     unload_modules || return 203
762 }
763 run_test 26 "MDT startup failure cleans LOV (should return errs)"
764
765 wait_update () {
766         local node=$1
767         local TEST=$2
768         local FINAL=$3
769
770         local RESULT
771         local MAX=90
772         local WAIT=0
773         local sleep=5
774         while [ $WAIT -lt $MAX ]; do
775             RESULT=$(do_node $node "$TEST") 
776             if [ $RESULT -eq $FINAL ]; then
777                 echo "Updated config after $WAIT sec: wanted $FINAL got $RESULT"
778                 return 0
779             fi
780             WAIT=$((WAIT + sleep))
781             echo "Waiting $((MAX - WAIT)) secs for config update" 
782             sleep $sleep
783         done
784         echo "Config update not seen after $MAX sec: wanted $FINAL got $RESULT"
785         return 3
786 }
787
788 set_and_check() {
789         local myfacet=$1
790         local TEST=$2
791         local PARAM=$3
792         local ORIG=$(do_facet $myfacet "$TEST") 
793         if [ $# -gt 3 ]; then
794             local FINAL=$4
795         else
796             local -i FINAL
797             FINAL=$(($ORIG + 5))
798         fi
799         echo "Setting $PARAM from $ORIG to $FINAL"
800         do_facet $SINGLEMDS "$LCTL conf_param $PARAM=$FINAL" || error conf_param failed
801
802         wait_update $(facet_host $myfacet) "$TEST" $FINAL || error check failed!
803 }
804
805 test_27a() {
806         start_ost || return 1
807         start_mds || return 2
808         echo "Requeue thread should have started: " 
809         ps -e | grep ll_cfg_requeue 
810         set_and_check ost1 "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
811         cleanup_nocli
812 }
813 run_test 27a "Reacquire MGS lock if OST started first"
814
815 test_27b() {
816         # FIXME. ~grev
817         setup
818         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
819
820         facet_failover $SINGLEMDS
821         set_and_check $SINGLEMDS "lctl get_param -n mdt.$device.identity_acquire_expire" "$device.mdt.identity_acquire_expire" || return 3
822         set_and_check client "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight" "$device.mdc.max_rpcs_in_flight" || return 4
823         check_mount
824         cleanup
825 }
826 run_test 27b "Reacquire MGS lock after failover"
827
828 test_28() {
829         setup
830         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
831         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
832         ORIG=$($TEST)
833         FINAL=$(($ORIG + 1))
834         set_and_check client "$TEST" "$PARAM" $FINAL || return 3
835         FINAL=$(($FINAL + 1))
836         set_and_check client "$TEST" "$PARAM" $FINAL || return 4
837         umount_client $MOUNT || return 200
838         mount_client $MOUNT
839         RESULT=$($TEST)
840         if [ $RESULT -ne $FINAL ]; then
841             echo "New config not seen: wanted $FINAL got $RESULT"
842             return 4
843         else
844             echo "New config success: got $RESULT"
845         fi
846         set_and_check client "$TEST" "$PARAM" $ORIG || return 5
847         cleanup
848 }
849 run_test 28 "permanent parameter setting"
850
851 test_29() {
852         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2, skipping" && return
853         setup > /dev/null 2>&1
854         start_ost2
855         sleep 10
856
857         local PARAM="$FSNAME-OST0001.osc.active"
858         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
859         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
860
861         ACTV=$(lctl get_param -n $PROC_ACT)
862         DEAC=$((1 - $ACTV))
863         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
864         # also check ost_server_uuid status
865         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
866         if [ -z "$RESULT" ]; then
867             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
868             return 3
869         else
870             echo "Live client success: got $RESULT"
871         fi
872
873         # check MDT too 
874         local MPROC="osc.$FSNAME-OST0001-osc-[M]*.active"
875         local MAX=30
876         local WAIT=0
877         while [ 1 ]; do
878             sleep 5
879             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
880             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
881             if [ $RESULT -eq $DEAC ]; then
882                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
883                 break
884             fi
885             WAIT=$((WAIT + 5))
886             if [ $WAIT -eq $MAX ]; then
887                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
888                 return 4
889             fi
890             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
891         done
892
893         # test new client starts deactivated
894         umount_client $MOUNT || return 200
895         mount_client $MOUNT
896         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
897         if [ -z "$RESULT" ]; then
898             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
899             return 5
900         else
901             echo "New client success: got $RESULT"
902         fi
903
904         # make sure it reactivates
905         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
906
907         umount_client $MOUNT
908         stop_ost2
909         cleanup_nocli
910         #writeconf to remove all ost2 traces for subsequent tests
911         writeconf
912         start_mds
913         start_ost
914         sleep 5
915         cleanup
916 }
917 run_test 29 "permanently remove an OST"
918
919 test_30() {
920         setup
921
922         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
923         ORIG=$($TEST)
924         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
925         for i in ${LIST[@]}; do
926             set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
927         done
928         # make sure client restart still works 
929         umount_client $MOUNT
930         mount_client $MOUNT || return 4
931         [ "$($TEST)" -ne "$i" ] && return 5   
932         set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $ORIG || return 6
933         cleanup
934 }
935 run_test 30 "Big config llog"
936
937 test_31() { # bug 10734
938         # ipaddr must not exist
939         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
940         cleanup
941 }
942 run_test 31 "Connect to non-existent node (shouldn't crash)"
943
944 # Use these start32/stop32 fn instead of t-f start/stop fn,
945 # for local devices, to skip global facet vars init 
946 stop32 () {
947         local facet=$1
948         shift
949         echo "Stopping local ${MOUNT%/*}/${facet} (opts:$@)"
950         umount -d $@ ${MOUNT%/*}/${facet}
951         losetup -a
952 }
953
954 start32 () {
955         local facet=$1
956         shift
957         local device=$1
958         shift
959         mkdir -p ${MOUNT%/*}/${facet}
960
961         echo "Starting local ${facet}: $@ $device ${MOUNT%/*}/${facet}"
962         mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
963         RC=$?
964         if [ $RC -ne 0 ]; then
965                 echo "mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}"
966                 echo "Start of ${device} of local ${facet} failed ${RC}"
967         fi 
968         losetup -a
969         return $RC
970 }
971
972 cleanup_nocli32 () {
973         stop32 mds -f
974         stop32 ost1 -f
975         wait_exit_ST client
976 }
977
978 cleanup_32() {
979         trap 0
980         echo "Cleanup test_32 umount $MOUNT ..."
981         umount -f $MOUNT || true
982         echo "Cleanup local mds ost1 ..."
983         cleanup_nocli32
984         unload_modules
985 }
986
987 test_32a() {
988         # this test is totally useless on a client-only system
989         [ -n "$CLIENTONLY" -o -n "$CLIENTMODSONLY" ] && skip "client only testing" && return 0
990         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
991         [ -z "$TUNEFS" ] && skip "No tunefs" && return 0
992         local DISK1_8=$LUSTRE/tests/disk1_8.tgz
993         [ ! -r $DISK1_8 ] && skip "Cannot find $DISK1_8" && return 0
994
995         mkdir -p $TMP/$tdir
996         tar xjvf $DISK1_8 -C $TMP/$tdir || \
997                 { skip "Cannot untar $DISK1_8" && return 0; }
998
999         load_modules
1000         lctl set_param debug=$PTLDEBUG
1001
1002         $TUNEFS $tmpdir/mds || error "tunefs failed"
1003
1004         # nids are wrong, so client wont work, but server should start
1005         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1006                 trap cleanup_32 EXIT INT || return 3
1007         
1008         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
1009         echo MDS uuid $UUID
1010         [ "$UUID" == "mdsA_UUID" ] || error "UUID is wrong: $UUID" 
1011
1012         $TUNEFS --mgsnode=`hostname` $tmpdir/ost1 || error "tunefs failed"
1013         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1014         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1015         echo OST uuid $UUID
1016         [ "$UUID" == "ost1_UUID" ] || error "UUID is wrong: $UUID" 
1017
1018         local NID=$($LCTL list_nids | head -1)
1019
1020         echo "OSC changes should return err:" 
1021         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 && return 7
1022         $LCTL conf_param lustre-OST0000.failover.node=$NID && return 8
1023         echo "ok."
1024         echo "MDC changes should succeed:" 
1025         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1026         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1027         echo "ok."
1028
1029         # With a new good MDT failover nid, we should be able to mount a client
1030         # (but it cant talk to OST)
1031         local mountopt="-o exclude=lustre-OST0000"
1032
1033         local device=`h2$NETTYPE $HOSTNAME`:/lustre
1034         echo "Starting local client: $HOSTNAME: $mountopt $device $MOUNT"
1035         mount -t lustre $mountopt $device $MOUNT || return 1
1036
1037         local old=$(lctl get_param -n mdc.*.max_rpcs_in_flight)
1038         local new=$((old + 5))
1039         lctl conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=$new
1040         wait_update $HOSTNAME "lctl get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1041
1042         cleanup_32
1043
1044         # mount a second time to make sure we didnt leave upgrade flag on
1045         load_modules
1046         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1047         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1048                 trap cleanup_32 EXIT INT || return 12
1049
1050         cleanup_32
1051
1052         rm -rf $tmpdir || true  # true is only for TMP on NFS
1053 }
1054 run_test 32a "Upgrade from 1.8 (not live)"
1055
1056 test_32b() {
1057         # this test is totally useless on a client-only system
1058         [ -n "$CLIENTONLY" -o -n "$CLIENTMODSONLY" ] && skip "client only testing" && return 0
1059         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1060         [ -z "$TUNEFS" ] && skip "No tunefs" && return
1061
1062         local DISK1_8=$LUSTRE/tests/disk1_8.tgz
1063         [ ! -r $DISK1_8 ] && skip "Cannot find $DISK1_8" && return 0
1064         local tmpdir=$TMP/$tdir
1065         mkdir -p $tmpdir
1066         tar xjvf $DISK1_8 -C $tmpdir || \
1067                 { skip "Cannot untar $DISK1_8" && return ; }
1068
1069         load_modules
1070         lctl set_param debug=$PTLDEBUG
1071         local NEWNAME=lustre
1072
1073         # writeconf will cause servers to register with their current nids
1074         $TUNEFS --writeconf --fsname=$NEWNAME $tmpdir/mds || error "tunefs failed"
1075         start32 mds1 $tmpdir/mds "-o loop" && \
1076                 trap cleanup_32 EXIT INT || return 3
1077
1078         local UUID=$(lctl get_param -n mdt.${NEWNAME}-MDT0000.uuid)
1079         echo MDS uuid $UUID
1080         [ "$UUID" == "${NEWNAME}-MDT0000_UUID" ] || error "UUID is wrong: $UUID" 
1081
1082         $TUNEFS --mgsnode=`hostname` --writeconf --fsname=$NEWNAME $tmpdir/ost1 || error "tunefs failed"
1083         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1084         UUID=$(lctl get_param -n obdfilter.${NEWNAME}-OST0000.uuid)
1085         echo OST uuid $UUID
1086         [ "$UUID" == "${NEWNAME}-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1087
1088         echo "OSC changes should succeed:" 
1089         $LCTL conf_param ${NEWNAME}-OST0000.osc.max_dirty_mb=15 || return 7
1090         $LCTL conf_param ${NEWNAME}-OST0000.failover.node=$NID || return 8
1091         echo "ok."
1092         echo "MDC changes should succeed:" 
1093         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1094         echo "ok."
1095
1096         # MDT and OST should have registered with new nids, so we should have
1097         # a fully-functioning client
1098         echo "Check client and old fs contents"
1099
1100         local device=`h2$NETTYPE $HOSTNAME`:/$NEWNAME
1101         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1102         mount -t lustre $device $MOUNT || return 1
1103
1104         local old=$(lctl get_param -n mdc.*.max_rpcs_in_flight)
1105         local new=$((old + 5))
1106         lctl conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=$new
1107         wait_update $HOSTNAME "lctl get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1108
1109         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "94306271 1478" ] || return 12
1110         echo "ok."
1111
1112         cleanup_32
1113
1114         rm -rf $tmpdir || true  # true is only for TMP on NFS
1115 }
1116 run_test 32b "Upgrade from 1.8 with writeconf"
1117
1118 test_33a() { # bug 12333, was test_33
1119         local rc=0
1120         local FSNAME2=test-123
1121         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1122
1123         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1124                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1125                 skip "mixed loopback and real device not working" && return
1126         fi
1127
1128         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1129         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1130         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1131         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1132
1133         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1134         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1135         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1136         mkdir -p $MOUNT2
1137         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1138         echo "ok."
1139
1140         cp /etc/hosts $MOUNT2/ || rc=3 
1141         $LFS getstripe $MOUNT2/hosts
1142
1143         umount -d $MOUNT2
1144         stop fs2ost -f
1145         stop fs2mds -f
1146         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1147         cleanup_nocli || rc=6
1148         return $rc
1149 }
1150 run_test 33a "Mount ost with a large index number"
1151
1152 test_33b() {    # was test_34
1153         setup
1154
1155         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1156         # Drop lock cancelation reply during umount
1157         #define OBD_FAIL_LDLM_CANCEL             0x304
1158         do_facet client lctl set_param fail_loc=0x80000304
1159         #lctl set_param debug=-1
1160         umount_client $MOUNT
1161         cleanup
1162 }
1163 run_test 33b "Drop cancel during umount"
1164
1165 test_34a() {
1166         setup
1167         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1168         manual_umount_client
1169         rc=$?
1170         do_facet client killall -USR1 multiop
1171         if [ $rc -eq 0 ]; then
1172                 error "umount not fail!"
1173         fi
1174         sleep 1
1175         cleanup
1176 }
1177 run_test 34a "umount with opened file should be fail"
1178
1179
1180 test_34b() {
1181         setup
1182         touch $DIR/$tfile || return 1
1183         stop_mds --force || return 2
1184
1185         manual_umount_client --force
1186         rc=$?
1187         if [ $rc -ne 0 ]; then
1188                 error "mtab after failed umount - rc $rc"
1189         fi
1190
1191         cleanup
1192         return 0
1193 }
1194 run_test 34b "force umount with failed mds should be normal"
1195
1196 test_34c() {
1197         setup
1198         touch $DIR/$tfile || return 1
1199         stop_ost --force || return 2
1200
1201         manual_umount_client --force
1202         rc=$?
1203         if [ $rc -ne 0 ]; then
1204                 error "mtab after failed umount - rc $rc"
1205         fi
1206
1207         cleanup
1208         return 0
1209 }
1210 run_test 34c "force umount with failed ost should be normal"
1211
1212 test_35() { # bug 12459
1213         setup
1214
1215         DBG_SAVE="`lctl get_param -n debug`"
1216         lctl set_param debug="ha"
1217
1218         log "Set up a fake failnode for the MDS"
1219         FAKENID="127.0.0.2"
1220         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1221         do_facet $SINGLEMDS $LCTL conf_param ${device}.failover.node=$FAKENID || return 4
1222
1223         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1224         sleep 10
1225
1226         MSG="conf-sanity.sh test_35 `date +%F%kh%Mm%Ss`"
1227         $LCTL clear
1228         log "$MSG"
1229         log "Stopping the MDT:"
1230         stop_mds || return 5
1231
1232         df $MOUNT > /dev/null 2>&1 &
1233         DFPID=$!
1234         log "Restarting the MDT:"
1235         start_mds || return 6
1236         log "Wait for df ($DFPID) ... "
1237         wait $DFPID
1238         log "done"
1239         lctl set_param debug="$DBG_SAVE"
1240
1241         # retrieve from the log the first server that the client tried to
1242         # contact after the connection loss
1243         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1244         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1245                        /import_select_connection.$device-mdc.* using connection/ {
1246                                 if (start) {
1247                                         if (\\\$NF ~ /$FAKENID/)
1248                                                 print \\\$NF;
1249                                         else
1250                                                 print 0;
1251                                         exit;
1252                                 }
1253                        }" $TMP/lustre-log-$TESTNAME.log`
1254         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1255         cleanup
1256 }
1257 run_test 35 "Reconnect to the last active server first"
1258
1259 test_36() { # 12743
1260         local rc
1261         local FSNAME2=test1234
1262         local fs3ost_HOST=$ost_HOST
1263
1264         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1265         rc=0
1266
1267         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1268                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1269                 skip "mixed loopback and real device not working" && return
1270         fi
1271         [ $OSTCOUNT -lt 2 ] && skip "skipping test for single OST" && return
1272
1273         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1274                 { skip "remote OST" && return 0; }
1275
1276         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1277         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1278         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1279         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1280         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1281         # other argument
1282         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1283         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1284
1285         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1286         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1287         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1288         mkdir -p $MOUNT2
1289         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1290
1291         sleep 5 # until 11778 fixed
1292
1293         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1294
1295         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1296         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1297         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1298         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1299         DFTOTAL=`echo $STRING | cut -d, -f1`
1300         DFUSED=`echo $STRING  | cut -d, -f2`
1301         DFAVAIL=`echo $STRING | cut -d, -f3`
1302         DFFREE=$(($DFTOTAL - $DFUSED))
1303
1304         ALLOWANCE=$((64 * $OSTCOUNT))
1305
1306         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||  
1307            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1308                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1309                 rc=1
1310         fi
1311         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] || 
1312            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1313                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1314                 rc=2
1315         fi
1316         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] || 
1317            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1318                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1319                 rc=3
1320        fi
1321
1322         umount -d $MOUNT2
1323         stop fs3ost -f || return 200
1324         stop fs2ost -f || return 201
1325         stop fs2mds -f || return 202
1326         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1327         unload_modules || return 203
1328         return $rc
1329 }
1330 run_test 36 "df report consistency on OSTs with different block size"
1331
1332 test_37() {
1333         [ -n "$CLIENTONLY" -o -n "$CLIENTMODSONLY" ] && skip "client only testing" && return 0
1334         LOCAL_MDSDEV="$TMP/mdt.img"
1335         SYM_MDSDEV="$TMP/sym_mdt.img"
1336
1337         echo "MDS :     $LOCAL_MDSDEV"
1338         echo "SYMLINK : $SYM_MDSDEV"
1339         rm -f $LOCAL_MDSDEV
1340
1341         touch $LOCAL_MDSDEV
1342         mkfs.lustre --reformat --fsname=lustre --mdt --mgs --device-size=9000 $LOCAL_MDSDEV ||
1343                 error "mkfs.lustre $LOCAL_MDSDEV failed"
1344         ln -s $LOCAL_MDSDEV $SYM_MDSDEV
1345
1346         echo "mount symlink device - $SYM_MDSDEV"
1347
1348         mount_op=`mount -v -t lustre -o loop $SYM_MDSDEV ${MOUNT%/*}/mds 2>&1 | grep "unable to set tunable"`
1349         umount -d ${MOUNT%/*}/mds
1350         rm -f $LOCAL_MDSDEV $SYM_MDSDEV
1351
1352         if [ -n "$mount_op" ]; then
1353                 error "**** FAIL: set tunables failed for symlink device"
1354         fi
1355         return 0
1356 }
1357 run_test 37 "verify set tunables works for symlink device"
1358
1359 test_38() { # bug 14222
1360         setup
1361         # like runtests
1362         COUNT=10
1363         SRC="/etc /bin"
1364         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1365         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1366         mkdir -p $DIR/$tdir
1367         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1368                 error "copying $SRC to $DIR/$tdir"
1369         sync
1370         umount_client $MOUNT
1371         stop_mds
1372         log "rename lov_objid file on MDS"
1373         rm -f $TMP/lov_objid.orig
1374
1375         local dev=${SINGLEMDS}_dev
1376         local MDSDEV=${!dev}
1377         do_facet $SINGLEMDS "debugfs -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1378         do_facet $SINGLEMDS "debugfs -w -R \\\"rm lov_objid\\\" $MDSDEV"
1379
1380         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
1381         # check create in mds_lov_connect
1382         start_mds
1383         mount_client $MOUNT
1384         for f in $FILES; do
1385                 [ $V ] && log "verifying $DIR/$tdir/$f"
1386                 diff -q $f $DIR/$tdir/$f || ERROR=y
1387         done
1388         do_facet $SINGLEMDS "debugfs -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1389         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
1390         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1391
1392         # check it's updates in sync
1393         umount_client $MOUNT
1394         stop_mds
1395
1396         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1397         do_facet $SINGLEMDS "debugfs -w -R \\\"rm lov_objid\\\" $MDSDEV"
1398         do_facet $SINGLEMDS "debugfs -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1399
1400         start_mds
1401         mount_client $MOUNT
1402         for f in $FILES; do
1403                 [ $V ] && log "verifying $DIR/$tdir/$f"
1404                 diff -q $f $DIR/$tdir/$f || ERROR=y
1405         done
1406         do_facet $SINGLEMDS "debugfs -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1407         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
1408         umount_client $MOUNT
1409         stop_mds
1410         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1411
1412         log "files compared the same"
1413         cleanup
1414 }
1415 run_test 38 "MDS recreates missing lov_objid file from OST data"
1416
1417 test_39() {
1418         PTLDEBUG=+malloc
1419         setup
1420         cleanup
1421         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' && 
1422                 error "memory leak detected" || true
1423 }
1424 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1425
1426 test_40() { # bug 15759
1427         start_ost
1428         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1429         do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000706"
1430         start_mds
1431         cleanup
1432 }
1433 run_test 40 "race during service thread startup"
1434
1435 test_41() { #bug 14134
1436         local rc
1437         local dev=${SINGLEMDS}_dev
1438         local MDSDEV=${!dev}
1439
1440         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1441         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1442         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs
1443         mkdir -p $MOUNT
1444         mount_client $MOUNT || return 1
1445         sleep 5
1446
1447         echo "blah blah" > $MOUNT/$tfile
1448         cat $MOUNT/$tfile
1449
1450         umount_client $MOUNT
1451         stop ost1 -f || return 201
1452         stop_mds -f || return 202
1453         stop_mds -f || return 203
1454         unload_modules || return 204
1455         return $rc
1456 }
1457 run_test 41 "mount mds with --nosvc and --nomgs"
1458
1459 test_42() { #bug 14693
1460         setup
1461         check_mount || return 2
1462         do_facet client lctl conf_param lustre.llite.some_wrong_param=10
1463         umount_client $MOUNT
1464         mount_client $MOUNT || return 1
1465         cleanup
1466         return 0
1467 }
1468 run_test 42 "invalid config param should not prevent client from mounting"
1469
1470 umount_client $MOUNT
1471 cleanup_nocli
1472
1473 test_45() { #17310
1474         setup
1475         check_mount || return 2
1476         stop_mds
1477         df -h $MOUNT &
1478         log "sleep 60 sec"
1479         sleep 60
1480 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1481         do_facet client "lctl set_param fail_loc=0x50f"
1482         log "sleep 10 sec"
1483         sleep 10
1484         manual_umount_client --force || return 3
1485         do_facet client "lctl set_param fail_loc=0x0"
1486         start_mds
1487         mount_client $MOUNT || return 4
1488         cleanup
1489         return 0
1490 }
1491 run_test 45 "long unlink handling in ptlrpcd"
1492
1493 test_46a() {
1494         OSTCOUNT=6
1495         reformat
1496         start_mds || return 1
1497         #first client should see only one ost
1498         start_ost || return 2
1499         #start_client
1500         mount_client $MOUNT || return 3
1501         
1502         start_ost2 || return 4
1503         start ost3 `ostdevname 3` $OST_MOUNT_OPTS || return 5
1504         start ost4 `ostdevname 4` $OST_MOUNT_OPTS || return 6
1505         start ost5 `ostdevname 5` $OST_MOUNT_OPTS || return 7
1506         # wait until ost2-5 is sync
1507         sleep 5
1508         #second client see both ost's
1509
1510         mount_client $MOUNT2 || return 8
1511         $LFS setstripe $MOUNT2 -c -1 || return 9
1512         $LFS getstripe $MOUNT2 || return 10
1513
1514         echo "ok" > $MOUNT2/widestripe
1515         $LFS getstripe $MOUNT2/widestripe || return 11
1516         # fill acl buffer for avoid expand lsm to them
1517         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do  
1518             setfacl -m $acl $MOUNT2/widestripe
1519         done
1520
1521         # will be deadlock
1522         stat $MOUNT/widestripe || return 12
1523
1524         umount_client $MOUNT2 || return 13
1525         umount_client $MOUNT || return 14
1526         stop ost5 -f || return 20
1527         stop ost4 -f || return 21
1528         stop ost3 -f || return 22
1529         stop_ost2 || return 23
1530         stop_ost || return 24
1531         stop_mds || return 25
1532 }
1533 run_test 46a "handle ost additional - wide striped file"
1534
1535 cleanup_gss
1536 equals_msg `basename $0`: test complete
1537 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true