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