Whamcloud - gitweb
Land b_head_interop_disk on HEAD (20081119_1314)
[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 #create single point mountpoint
187
188 gen_config
189
190 init_gss
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 }
569 run_test 21c "start mds between two osts, stop mds last"
570
571 test_22() {
572         #reformat to remove all logs
573         reformat
574         start_mds
575         echo Client mount before any osts are in the logs
576         mount_client $MOUNT
577         check_mount && return 41
578         pass
579
580         echo Client mount with ost in logs, but none running
581         start_ost
582         stop_ost
583         mount_client $MOUNT
584         # check_mount will block trying to contact ost
585         umount_client $MOUNT
586         pass
587
588         echo Client mount with a running ost
589         start_ost
590         if $GSS; then
591                 # if gss enabled, wait full time to let connection from
592                 # mds to ost be established, due to the mismatch between
593                 # initial connect timeout and gss context negotiation timeout.
594                 # This perhaps could be remove after AT landed.
595                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
596                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
597         fi
598         mount_client $MOUNT
599         check_mount || return 41
600         pass
601
602         cleanup
603 }
604 run_test 22 "start a client before osts (should return errs)"
605
606 test_23a() {    # was test_23
607         setup
608         # fail mds
609         stop $SINGLEMDS   
610         # force down client so that recovering mds waits for reconnect
611         local running=$(grep -c $MOUNT /proc/mounts) || true
612         if [ $running -ne 0 ]; then
613                 echo "Stopping client $MOUNT (opts: -f)"
614                 umount -f $MOUNT
615         fi
616
617         # enter recovery on mds
618         start_mds
619         # try to start a new client
620         mount_client $MOUNT &
621         sleep 5
622         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
623         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
624         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
625         ps --ppid $MOUNT_PID
626         ps --ppid $MOUNT_LUSTRE_PID
627         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
628         kill -TERM $MOUNT_LUSTRE_PID
629         echo "waiting for mount to finish"
630         ps -ef | grep mount
631         # we can not wait $MOUNT_PID because it is not a child of this shell
632         local PID1
633         local PID2
634         local WAIT=0
635         local MAX_WAIT=20
636         local sleep=1
637         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
638                 sleep $sleep
639                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
640                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
641                 echo PID1=$PID1
642                 echo PID2=$PID2
643                 [ -z "$PID1" -a -z "$PID2" ] && break
644                 echo "waiting for mount to finish ... "
645                 WAIT=$(( WAIT + sleep))
646         done
647         [ "$WAIT" -eq "$MAX_WAIT" ] && error "MOUNT_PID $MOUNT_PID and \
648                 MOUNT__LUSTRE_PID $MOUNT__LUSTRE_PID still not killed in $WAIT secs"
649         ps -ef | grep mount
650         stop_mds || error
651         stop_ost || error
652 }
653 run_test 23a "interrupt client during recovery mount delay"
654
655 umount_client $MOUNT
656 cleanup_nocli
657
658 test_23b() {    # was test_23
659         start_ost
660         start_mds
661         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
662         lctl set_param fail_loc=0x80000313
663         mount_client $MOUNT
664         cleanup
665 }
666 run_test 23b "Simulate -EINTR during mount"
667
668 fs2mds_HOST=$mds_HOST
669 fs2ost_HOST=$ost_HOST
670
671 cleanup_24a() {
672         trap 0
673         echo "umount $MOUNT2 ..."
674         umount $MOUNT2 || true
675         echo "stopping fs2mds ..."
676         stop fs2mds -f || true
677         echo "stopping fs2ost ..."
678         stop fs2ost -f || true
679 }
680
681 test_24a() {
682         #set up fs1 
683         gen_config
684         #set up fs2
685         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
686         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
687                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
688                 skip "mixed loopback and real device not working" && return
689         fi
690
691         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
692         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
693
694         # test 8-char fsname as well
695         local FSNAME2=test1234
696         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat $fs2mdsdev || exit 10
697
698         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
699
700         setup
701         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
702         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
703         mkdir -p $MOUNT2
704         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
705         # 1 still works
706         check_mount || return 2
707         # files written on 1 should not show up on 2
708         cp /etc/passwd $DIR/$tfile
709         sleep 10
710         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
711         # 2 should work
712         sleep 5
713         cp /etc/passwd $MOUNT2/b || return 3
714         rm $MOUNT2/b || return 4
715         # 2 is actually mounted
716         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
717         # failover 
718         facet_failover fs2mds
719         facet_failover fs2ost
720         df
721         umount_client $MOUNT 
722         # the MDS must remain up until last MDT
723         stop_mds
724         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
725         [ -z "$MDS" ] && error "No MDT" && return 8
726         cleanup_24a
727         cleanup_nocli || return 6
728 }
729 run_test 24a "Multiple MDTs on a single node"
730
731 test_24b() {
732         if [ -z "$fs2mds_DEV" ]; then
733                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
734                 skip "mixed loopback and real device not working" && return
735         fi
736
737         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
738
739         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat $fs2mdsdev || exit 10 
740         setup
741         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
742         cleanup || return 6
743 }
744 run_test 24b "Multiple MGSs on a single node (should return err)"
745
746 test_25() {
747         setup
748         check_mount || return 2
749         local MODULES=$($LCTL modules | awk '{ print $2 }')
750         rmmod $MODULES 2>/dev/null || true
751         cleanup || return 6
752 }
753 run_test 25 "Verify modules are referenced"
754
755 test_26() {
756     load_modules
757     # we need modules before mount for sysctl, so make sure...
758     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
759 #define OBD_FAIL_MDS_FS_SETUP            0x135
760     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
761     start_mds && echo MDS started && return 1
762     lctl get_param -n devices
763     DEVS=$(lctl get_param -n devices | wc -l)
764     [ $DEVS -gt 0 ] && return 2
765     unload_modules || return 203
766 }
767 run_test 26 "MDT startup failure cleans LOV (should return errs)"
768
769 set_and_check() {
770         local myfacet=$1
771         local TEST=$2
772         local PARAM=$3
773         local ORIG=$(do_facet $myfacet "$TEST") 
774         if [ $# -gt 3 ]; then
775             local FINAL=$4
776         else
777             local -i FINAL
778             FINAL=$(($ORIG + 5))
779         fi
780         echo "Setting $PARAM from $ORIG to $FINAL"
781         do_facet $SINGLEMDS "$LCTL conf_param $PARAM=$FINAL" || error conf_param failed
782         local RESULT
783         local MAX=90
784         local WAIT=0
785         while [ 1 ]; do
786             sleep 5
787             RESULT=$(do_facet $myfacet "$TEST") 
788             if [ $RESULT -eq $FINAL ]; then
789                 echo "Updated config after $WAIT sec (got $RESULT)"
790                 break
791             fi
792             WAIT=$((WAIT + 5))
793             if [ $WAIT -eq $MAX ]; then
794                 echo "Config update not seen: wanted $FINAL got $RESULT"
795                 return 3
796             fi
797             echo "Waiting $(($MAX - $WAIT)) secs for config update" 
798         done
799 }
800
801 test_27a() {
802         start_ost || return 1
803         start_mds || return 2
804         echo "Requeue thread should have started: " 
805         ps -e | grep ll_cfg_requeue 
806         set_and_check ost1 "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
807         cleanup_nocli
808 }
809 run_test 27a "Reacquire MGS lock if OST started first"
810
811 test_27b() {
812         # FIXME. ~grev
813         setup
814         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
815
816         facet_failover $SINGLEMDS
817         set_and_check $SINGLEMDS "lctl get_param -n mdt.$device.identity_acquire_expire" "$device.mdt.identity_acquire_expire" || return 3
818         set_and_check client "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight" "$device.mdc.max_rpcs_in_flight" || return 4
819         check_mount
820         cleanup
821 }
822 run_test 27b "Reacquire MGS lock after failover"
823
824 test_28() {
825         setup
826         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
827         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
828         ORIG=$($TEST)
829         FINAL=$(($ORIG + 1))
830         set_and_check client "$TEST" "$PARAM" $FINAL || return 3
831         FINAL=$(($FINAL + 1))
832         set_and_check client "$TEST" "$PARAM" $FINAL || return 4
833         umount_client $MOUNT || return 200
834         mount_client $MOUNT
835         RESULT=$($TEST)
836         if [ $RESULT -ne $FINAL ]; then
837             echo "New config not seen: wanted $FINAL got $RESULT"
838             return 4
839         else
840             echo "New config success: got $RESULT"
841         fi
842         set_and_check client "$TEST" "$PARAM" $ORIG || return 5
843         cleanup
844 }
845 run_test 28 "permanent parameter setting"
846
847 test_29() {
848         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2, skipping" && return
849         setup > /dev/null 2>&1
850         start_ost2
851         sleep 10
852
853         local PARAM="$FSNAME-OST0001.osc.active"
854         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
855         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
856
857         ACTV=$(lctl get_param -n $PROC_ACT)
858         DEAC=$((1 - $ACTV))
859         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
860         # also check ost_server_uuid status
861         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
862         if [ -z "$RESULT" ]; then
863             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
864             return 3
865         else
866             echo "Live client success: got $RESULT"
867         fi
868
869         # check MDT too 
870         local MPROC="osc.$FSNAME-OST0001-osc-[M]*.active"
871         local MAX=30
872         local WAIT=0
873         while [ 1 ]; do
874             sleep 5
875             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
876             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
877             if [ $RESULT -eq $DEAC ]; then
878                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
879                 break
880             fi
881             WAIT=$((WAIT + 5))
882             if [ $WAIT -eq $MAX ]; then
883                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
884                 return 4
885             fi
886             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
887         done
888
889         # test new client starts deactivated
890         umount_client $MOUNT || return 200
891         mount_client $MOUNT
892         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
893         if [ -z "$RESULT" ]; then
894             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
895             return 5
896         else
897             echo "New client success: got $RESULT"
898         fi
899
900         # make sure it reactivates
901         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
902
903         umount_client $MOUNT
904         stop_ost2
905         cleanup_nocli
906         #writeconf to remove all ost2 traces for subsequent tests
907         writeconf
908         start_mds
909         start_ost
910         cleanup
911 }
912 run_test 29 "permanently remove an OST"
913
914 test_30() {
915         setup
916
917         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
918         ORIG=$($TEST)
919         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
920         for i in ${LIST[@]}; do
921             set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
922         done
923         # make sure client restart still works 
924         umount_client $MOUNT
925         mount_client $MOUNT || return 4
926         [ "$($TEST)" -ne "$i" ] && return 5   
927         set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $ORIG || return 6
928         cleanup
929 }
930 run_test 30 "Big config llog"
931
932 test_31() { # bug 10734
933         # ipaddr must not exist
934         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
935         cleanup
936 }
937 run_test 31 "Connect to non-existent node (shouldn't crash)"
938
939 test_32a() {
940         # XXX - make this test verify 1.8 -> 2.0 upgrade is working
941         # XXX - make this run on client-only systems with real hardware on
942         #       the OST and MDT
943         #       there appears to be a lot of assumption here about loopback
944         #       devices
945         # or maybe this test is just totally useless on a client-only system
946         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
947         [ "$mds_HOST" = "`hostname`" ] || { skip "remote MDS" && return 0; }
948         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
949                 { skip "remote OST" && return 0; }
950
951         [ -z "$TUNEFS" ] && skip "No tunefs" && return
952         local DISK1_8=$LUSTRE/tests/disk1_8.tgz
953         [ ! -r $DISK1_8 ] && skip "Cannot find $DISK1_8" && return 0
954
955         mkdir -p $TMP/$tdir
956         tar xjvf $DISK1_8 -C $TMP/$tdir || \
957                 { skip "Cannot untar $DISK1_8" && return 0; }
958
959         load_modules
960         lctl set_param debug=$PTLDEBUG
961
962         $TUNEFS $tmpdir/mds || error "tunefs failed"
963         # nids are wrong, so client wont work, but server should start
964         start mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" || return 3
965         local UUID=$(lctl get_param -n mdt.lustre-MDT0000.uuid)
966         echo MDS uuid $UUID
967         [ "$UUID" == "mdsA_UUID" ] || error "UUID is wrong: $UUID" 
968
969         $TUNEFS --mgsnode=`hostname` $tmpdir/ost1 || error "tunefs failed"
970         start ost1 $tmpdir/ost1 "-o loop" || return 5
971         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
972         echo OST uuid $UUID
973         [ "$UUID" == "ost1_UUID" ] || error "UUID is wrong: $UUID" 
974
975         local NID=$($LCTL list_nids | head -1)
976
977         echo "OSC changes should return err:" 
978         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 && return 7
979         $LCTL conf_param lustre-OST0000.failover.node=$NID && return 8
980         echo "ok."
981         echo "MDC changes should succeed:" 
982         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
983         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
984         echo "ok."
985
986         # With a new good MDT failover nid, we should be able to mount a client
987         # (but it cant talk to OST)
988         local OLDMOUNTOPT=$MOUNTOPT
989         MOUNTOPT="exclude=lustre-OST0000"
990         mount_client $MOUNT
991         MOUNTOPT=$OLDMOUNTOPT
992         set_and_check client "lctl get_param -n mdc.*.max_rpcs_in_flight" "lustre-MDT0000.mdc.max_rpcs_in_flight" ||
993                 return 11
994
995         zconf_umount `hostname` $MOUNT -f
996         cleanup_nocli
997         load_modules
998
999         # mount a second time to make sure we didnt leave upgrade flag on
1000         load_modules
1001         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1002         load_modules
1003         start mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" || return 12
1004         cleanup_nocli
1005
1006         rm -rf $tmpdir || true  # true is only for TMP on NFS
1007 }
1008 run_test 32a "Upgrade from 1.8 (not live)"
1009
1010 test_32b() {
1011         # XXX - make this test verify 1.8 -> 2.0 upgrade is working
1012         # XXX - make this run on client-only systems with real hardware on
1013         #       the OST and MDT
1014         #       there appears to be a lot of assumption here about loopback
1015         #       devices
1016         # or maybe this test is just totally useless on a client-only system
1017         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1018         [ "$mds_HOST" = "`hostname`" ] || { skip "remote MDS" && return 0; }
1019         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1020                 { skip "remote OST" && return 0; }
1021
1022         [ -z "$TUNEFS" ] && skip "No tunefs" && return
1023         local DISK1_8=$LUSTRE/tests/disk1_8.tgz
1024         [ ! -r $DISK1_8 ] && skip "Cannot find $DISK1_8" && return 0
1025         local tmpdir=$TMP/$tdir
1026         mkdir -p $tmpdir
1027         tar xjvf $DISK1_8 -C $tmpdir || \
1028                 { skip "Cannot untar $DISK1_8" && return ; }
1029
1030         load_modules
1031         lctl set_param debug=$PTLDEBUG
1032         NEWNAME=lustre
1033
1034         # writeconf will cause servers to register with their current nids
1035         $TUNEFS --writeconf --fsname=$NEWNAME $tmpdir/mds || error "tunefs failed"
1036         start mds1 $tmpdir/mds "-o loop" || return 3
1037         local UUID=$(lctl get_param -n mdt.${NEWNAME}-MDT0000.uuid)
1038         echo MDS uuid $UUID
1039         [ "$UUID" == "${NEWNAME}-MDT0000_UUID" ] || error "UUID is wrong: $UUID" 
1040
1041         $TUNEFS --mgsnode=`hostname` --writeconf --fsname=$NEWNAME $tmpdir/ost1 || error "tunefs failed"
1042         start ost1 $tmpdir/ost1 "-o loop" || return 5
1043         UUID=$(lctl get_param -n obdfilter.${NEWNAME}-OST0000.uuid)
1044         echo OST uuid $UUID
1045         [ "$UUID" == "${NEWNAME}-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1046
1047         echo "OSC changes should succeed:" 
1048         $LCTL conf_param ${NEWNAME}-OST0000.osc.max_dirty_mb=15 || return 7
1049         $LCTL conf_param ${NEWNAME}-OST0000.failover.node=$NID || return 8
1050         echo "ok."
1051         echo "MDC changes should succeed:" 
1052         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1053         echo "ok."
1054
1055         # MDT and OST should have registered with new nids, so we should have
1056         # a fully-functioning client
1057         echo "Check client and old fs contents"
1058         OLDFS=$FSNAME
1059         FSNAME=$NEWNAME
1060         mount_client $MOUNT
1061         FSNAME=$OLDFS
1062         set_and_check client "lctl get_param -n mdc.*.max_rpcs_in_flight" "${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight" || return 11
1063         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "94306271 1478" ] || return 12
1064         echo "ok."
1065
1066         cleanup
1067         rm -rf $tmpdir || true  # true is only for TMP on NFS
1068 }
1069 run_test 32b "Upgrade from 1.8 with writeconf"
1070
1071 test_33a() { # bug 12333, was test_33
1072         local rc=0
1073         local FSNAME2=test-123
1074         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1075
1076         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1077                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1078                 skip "mixed loopback and real device not working" && return
1079         fi
1080
1081         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1082         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1083         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1084         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1085
1086         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1087         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1088         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1089         mkdir -p $MOUNT2
1090         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1091         echo "ok."
1092
1093         cp /etc/hosts $MOUNT2/ || rc=3 
1094         $LFS getstripe $MOUNT2/hosts
1095
1096         umount -d $MOUNT2
1097         stop fs2ost -f
1098         stop fs2mds -f
1099         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1100         cleanup_nocli || rc=6
1101         return $rc
1102 }
1103 run_test 33a "Mount ost with a large index number"
1104
1105 test_33b() {    # was test_34
1106         setup
1107
1108         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1109         # Drop lock cancelation reply during umount
1110         #define OBD_FAIL_LDLM_CANCEL             0x304
1111         do_facet client lctl set_param fail_loc=0x80000304
1112         #lctl set_param debug=-1
1113         umount_client $MOUNT
1114         cleanup
1115 }
1116 run_test 33b "Drop cancel during umount"
1117
1118 test_34a() {
1119         setup
1120         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1121         manual_umount_client
1122         rc=$?
1123         do_facet client killall -USR1 multiop
1124         if [ $rc -eq 0 ]; then
1125                 error "umount not fail!"
1126         fi
1127         sleep 1
1128         cleanup
1129 }
1130 run_test 34a "umount with opened file should be fail"
1131
1132
1133 test_34b() {
1134         setup
1135         touch $DIR/$tfile || return 1
1136         stop_mds --force || return 2
1137
1138         manual_umount_client --force
1139         rc=$?
1140         if [ $rc -ne 0 ]; then
1141                 error "mtab after failed umount - rc $rc"
1142         fi
1143
1144         cleanup
1145         return 0
1146 }
1147 run_test 34b "force umount with failed mds should be normal"
1148
1149 test_34c() {
1150         setup
1151         touch $DIR/$tfile || return 1
1152         stop_ost --force || return 2
1153
1154         manual_umount_client --force
1155         rc=$?
1156         if [ $rc -ne 0 ]; then
1157                 error "mtab after failed umount - rc $rc"
1158         fi
1159
1160         cleanup
1161         return 0
1162 }
1163 run_test 34c "force umount with failed ost should be normal"
1164
1165 test_35() { # bug 12459
1166         setup
1167
1168         DBG_SAVE="`lctl get_param -n debug`"
1169         lctl set_param debug="ha"
1170
1171         log "Set up a fake failnode for the MDS"
1172         FAKENID="127.0.0.2"
1173         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1174         do_facet $SINGLEMDS $LCTL conf_param ${device}.failover.node=$FAKENID || return 4
1175
1176         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1177         sleep 10
1178
1179         MSG="conf-sanity.sh test_35 `date +%F%kh%Mm%Ss`"
1180         $LCTL clear
1181         log "$MSG"
1182         log "Stopping the MDT:"
1183         stop_mds || return 5
1184
1185         df $MOUNT > /dev/null 2>&1 &
1186         DFPID=$!
1187         log "Restarting the MDT:"
1188         start_mds || return 6
1189         log "Wait for df ($DFPID) ... "
1190         wait $DFPID
1191         log "done"
1192         lctl set_param debug="$DBG_SAVE"
1193
1194         # retrieve from the log the first server that the client tried to
1195         # contact after the connection loss
1196         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1197         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1198                        /import_select_connection.$device-mdc.* using connection/ {
1199                                 if (start) {
1200                                         if (\\\$NF ~ /$FAKENID/)
1201                                                 print \\\$NF;
1202                                         else
1203                                                 print 0;
1204                                         exit;
1205                                 }
1206                        }" $TMP/lustre-log-$TESTNAME.log`
1207         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1208         cleanup
1209 }
1210 run_test 35 "Reconnect to the last active server first"
1211
1212 test_36() { # 12743
1213         local rc
1214         local FSNAME2=test1234
1215         local fs3ost_HOST=$ost_HOST
1216
1217         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1218         rc=0
1219
1220         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1221                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1222                 skip "mixed loopback and real device not working" && return
1223         fi
1224         [ $OSTCOUNT -lt 2 ] && skip "skipping test for single OST" && return
1225
1226         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1227                 { skip "remote OST" && return 0; }
1228
1229         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1230         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1231         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1232         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1233         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1234         # other argument
1235         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1236         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1237
1238         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1239         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1240         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1241         mkdir -p $MOUNT2
1242         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1243
1244         sleep 5 # until 11778 fixed
1245
1246         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1247
1248         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1249         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1250         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1251         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1252         DFTOTAL=`echo $STRING | cut -d, -f1`
1253         DFUSED=`echo $STRING  | cut -d, -f2`
1254         DFAVAIL=`echo $STRING | cut -d, -f3`
1255         DFFREE=$(($DFTOTAL - $DFUSED))
1256
1257         ALLOWANCE=$((64 * $OSTCOUNT))
1258
1259         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||  
1260            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1261                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1262                 rc=1
1263         fi
1264         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] || 
1265            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1266                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1267                 rc=2
1268         fi
1269         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] || 
1270            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1271                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1272                 rc=3
1273        fi
1274
1275         umount -d $MOUNT2
1276         stop fs3ost -f || return 200
1277         stop fs2ost -f || return 201
1278         stop fs2mds -f || return 202
1279         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1280         unload_modules || return 203
1281         return $rc
1282 }
1283 run_test 36 "df report consistency on OSTs with different block size"
1284
1285 test_37() {
1286         [ -n "$CLIENTONLY" -o -n "$CLIENTMODSONLY" ] && skip "client only testing" && return 0
1287         LOCAL_MDSDEV="$TMP/mdt.img"
1288         SYM_MDSDEV="$TMP/sym_mdt.img"
1289
1290         echo "MDS :     $LOCAL_MDSDEV"
1291         echo "SYMLINK : $SYM_MDSDEV"
1292         rm -f $LOCAL_MDSDEV
1293
1294         touch $LOCAL_MDSDEV
1295         mkfs.lustre --reformat --fsname=lustre --mdt --mgs --device-size=9000 $LOCAL_MDSDEV ||
1296                 error "mkfs.lustre $LOCAL_MDSDEV failed"
1297         ln -s $LOCAL_MDSDEV $SYM_MDSDEV
1298
1299         echo "mount symlink device - $SYM_MDSDEV"
1300
1301         mount_op=`mount -v -t lustre -o loop $SYM_MDSDEV ${MOUNT%/*}/mds 2>&1 | grep "unable to set tunable"`
1302         umount -d ${MOUNT%/*}/mds
1303         rm -f $LOCAL_MDSDEV $SYM_MDSDEV
1304
1305         if [ -n "$mount_op" ]; then
1306                 error "**** FAIL: set tunables failed for symlink device"
1307         fi
1308         return 0
1309 }
1310 run_test 37 "verify set tunables works for symlink device"
1311
1312 test_38() { # bug 14222
1313         setup
1314         # like runtests
1315         COUNT=10
1316         SRC="/etc /bin"
1317         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1318         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1319         mkdir -p $DIR/$tdir
1320         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1321                 error "copying $SRC to $DIR/$tdir"
1322         sync
1323         umount_client $MOUNT
1324         stop_mds
1325         log "rename lov_objid file on MDS"
1326         rm -f $TMP/lov_objid.orig
1327
1328         local dev=${SINGLEMDS}_dev
1329         local MDSDEV=${!dev}
1330         do_facet $SINGLEMDS "debugfs -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1331         do_facet $SINGLEMDS "debugfs -w -R \\\"rm lov_objid\\\" $MDSDEV"
1332
1333         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
1334         # check create in mds_lov_connect
1335         start_mds
1336         mount_client $MOUNT
1337         for f in $FILES; do
1338                 [ $V ] && log "verifying $DIR/$tdir/$f"
1339                 diff -q $f $DIR/$tdir/$f || ERROR=y
1340         done
1341         do_facet $SINGLEMDS "debugfs -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1342         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
1343         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1344
1345         # check it's updates in sync
1346         umount_client $MOUNT
1347         stop_mds
1348
1349         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1350         do_facet $SINGLEMDS "debugfs -w -R \\\"rm lov_objid\\\" $MDSDEV"
1351         do_facet $SINGLEMDS "debugfs -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1352
1353         start_mds
1354         mount_client $MOUNT
1355         for f in $FILES; do
1356                 [ $V ] && log "verifying $DIR/$tdir/$f"
1357                 diff -q $f $DIR/$tdir/$f || ERROR=y
1358         done
1359         do_facet $SINGLEMDS "debugfs -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1360         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
1361         umount_client $MOUNT
1362         stop_mds
1363         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1364
1365         log "files compared the same"
1366         cleanup
1367 }
1368 run_test 38 "MDS recreates missing lov_objid file from OST data"
1369
1370 test_39() {
1371         PTLDEBUG=+malloc
1372         setup
1373         cleanup
1374         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' && 
1375                 error "memory leak detected" || true
1376 }
1377 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1378
1379 test_40() { # bug 15759
1380         start_ost
1381         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1382         do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000706"
1383         start_mds
1384         cleanup
1385 }
1386 run_test 40 "race during service thread startup"
1387
1388 test_41() { #bug 14134
1389         local rc
1390         local dev=${SINGLEMDS}_dev
1391         local MDSDEV=${!dev}
1392
1393         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1394         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1395         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs
1396         mkdir -p $MOUNT
1397         mount_client $MOUNT || return 1
1398         sleep 5
1399
1400         echo "blah blah" > $MOUNT/$tfile
1401         cat $MOUNT/$tfile
1402
1403         umount_client $MOUNT
1404         stop ost1 -f || return 201
1405         stop_mds -f || return 202
1406         stop_mds -f || return 203
1407         unload_modules || return 204
1408         return $rc
1409 }
1410 run_test 41 "mount mds with --nosvc and --nomgs"
1411
1412 test_42() { #bug 14693
1413         setup
1414         check_mount || return 2
1415         do_facet client lctl conf_param lustre.llite.some_wrong_param=10
1416         umount_client $MOUNT
1417         mount_client $MOUNT || return 1
1418         cleanup
1419         return 0
1420 }
1421 run_test 42 "invalid config param should not prevent client from mounting"
1422
1423 umount_client $MOUNT
1424 cleanup_nocli
1425 cleanup_gss
1426
1427 test_45() { #17310
1428         setup
1429         check_mount || return 2
1430         stop_mds
1431         df -h $MOUNT &
1432         log "sleep 60 sec"
1433         sleep 60
1434 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1435         do_facet client "lctl set_param fail_loc=0x50f"
1436         log "sleep 10 sec"
1437         sleep 10
1438         manual_umount_client --force || return 3
1439         do_facet client "lctl set_param fail_loc=0x0"
1440         start_mds
1441         mount_client $MOUNT || return 4
1442         cleanup
1443         return 0
1444 }
1445 run_test 45 "long unlink handling in ptlrpcd"
1446
1447
1448 equals_msg `basename $0`: test complete
1449 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true