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