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