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