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