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