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