Whamcloud - gitweb
b=12942
[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 FIXME
16 MOUNTCONFSKIP="10  11  12  13  13b 14  15   18"
17
18 # bug number for skipped test:
19 ALWAYS_EXCEPT=" $CONF_SANITY_EXCEPT $MOUNTCONFSKIP"
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 LUSTRE=${LUSTRE:-`dirname $0`/..}
26 RLUSTRE=${RLUSTRE:-$LUSTRE}
27 HOSTNAME=`hostname`
28
29 . $LUSTRE/tests/test-framework.sh
30 init_test_env $@
31 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
32
33 reformat() {
34         formatall
35 }
36
37 writeconf() {
38     local facet=mds
39     shift
40     stop ${facet} -f
41     rm -f ${facet}active
42     # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
43     do_facet ${facet} "$TUNEFS --writeconf $MDSDEV" || echo "tunefs failed, reformatting instead" && reformat
44 }
45
46 gen_config() {
47         reformat
48         # The MGS must be started before the OSTs for a new fs, so start
49         # and stop to generate the startup logs. 
50         start_mds
51         start_ost
52         sleep 5
53         stop_ost
54         stop_mds
55 }
56
57 start_mds() {
58         echo "start mds service on `facet_active_host mds`"
59         start mds $MDSDEV $MDS_MOUNT_OPTS || return 94
60 }
61
62 stop_mds() {
63         echo "stop mds service on `facet_active_host mds`"
64         # These tests all use non-failover stop
65         stop mds -f  || return 97
66 }
67
68 start_ost() {
69         echo "start ost1 service on `facet_active_host ost1`"
70         start ost1 `ostdevname 1` $OST_MOUNT_OPTS || return 95
71 }
72
73 stop_ost() {
74         echo "stop ost1 service on `facet_active_host ost1`"
75         # These tests all use non-failover stop
76         stop ost1 -f  || return 98
77 }
78
79 start_ost2() {
80         echo "start ost2 service on `facet_active_host ost2`"
81         start ost2 `ostdevname 2` $OST_MOUNT_OPTS || return 92
82 }
83
84 stop_ost2() {
85         echo "stop ost2 service on `facet_active_host ost2`"
86         # These tests all use non-failover stop
87         stop ost2 -f  || return 93
88 }
89
90 mount_client() {
91         local MOUNTPATH=$1
92         echo "mount $FSNAME on ${MOUNTPATH}....."
93         zconf_mount `hostname` $MOUNTPATH  || return 96
94 }
95
96 remount_client() {
97         local SAVEMOUNTOPT=$MOUNTOPT
98         MOUNTOPT="remount,$1"
99         local MOUNTPATH=$2
100         echo "remount '$1' lustre on ${MOUNTPATH}....."
101         zconf_mount `hostname`  $MOUNTPATH  || return 96
102         MOUNTOPT=$SAVEMOUNTOPT
103 }
104
105 umount_client() {
106         local MOUNTPATH=$1
107         echo "umount lustre on ${MOUNTPATH}....."
108         zconf_umount `hostname` $MOUNTPATH || return 97
109 }
110
111 manual_umount_client(){
112         echo "manual umount lustre on ${MOUNT}...."
113         do_facet client "umount -d $MOUNT"
114 }
115
116 setup() {
117         start_ost
118         start_mds
119         mount_client $MOUNT
120 }
121
122 cleanup_nocli() {
123         stop_mds || return 201
124         stop_ost || return 202
125         unload_modules || return 203
126 }
127
128 cleanup() {
129         umount_client $MOUNT || return 200
130         cleanup_nocli || return $?
131 }
132
133 check_mount() {
134         do_facet client "cp /etc/passwd $DIR/a" || return 71
135         do_facet client "rm $DIR/a" || return 72
136         # make sure lustre is actually mounted (touch will block, 
137         # but grep won't, so do it after) 
138         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
139         echo "setup single mount lustre success"
140 }
141
142 check_mount2() {
143         do_facet client "touch $DIR/a" || return 71     
144         do_facet client "rm $DIR/a" || return 72        
145         do_facet client "touch $DIR2/a" || return 73    
146         do_facet client "rm $DIR2/a" || return 74       
147         echo "setup double mount lustre success"
148 }
149
150 build_test_filter
151
152 if [ "$ONLY" == "setup" ]; then
153         setup
154         exit
155 fi
156
157 if [ "$ONLY" == "cleanup" ]; then
158         cleanup
159         exit
160 fi
161
162 #create single point mountpoint
163
164 gen_config
165
166
167 test_0() {
168         setup
169         check_mount || return 41
170         cleanup || return $?
171 }
172 run_test 0 "single mount setup"
173
174 test_1() {
175         start_ost
176         echo "start ost second time..."
177         setup
178         check_mount || return 42
179         cleanup || return $?
180 }
181 run_test 1 "start up ost twice (should return errors)"
182
183 test_2() {
184         start_ost
185         start_mds       
186         echo "start mds second time.."
187         start_mds
188         mount_client $MOUNT
189         check_mount || return 43
190         cleanup || return $?
191 }
192 run_test 2 "start up mds twice (should return err)"
193
194 test_3() {
195         setup
196         #mount.lustre returns an error if already in mtab
197         mount_client $MOUNT && return $?
198         check_mount || return 44
199         cleanup || return $?
200 }
201 run_test 3 "mount client twice (should return err)"
202
203 test_4() {
204         setup
205         touch $DIR/$tfile || return 85
206         stop_ost -f
207         cleanup
208         eno=$?
209         # ok for ost to fail shutdown
210         if [ 202 -ne $eno ]; then
211                 return $eno;
212         fi
213         return 0
214 }
215 run_test 4 "force cleanup ost, then cleanup"
216
217 test_5() {
218         setup
219         touch $DIR/$tfile || return 1
220         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
221
222         stop_mds -f || return 2
223
224         # cleanup may return an error from the failed
225         # disconnects; for now I'll consider this successful
226         # if all the modules have unloaded.
227         umount -d $MOUNT &
228         UMOUNT_PID=$!
229         sleep 6
230         echo "killing umount"
231         kill -TERM $UMOUNT_PID
232         echo "waiting for umount to finish"
233         wait $UMOUNT_PID
234         if grep " $MOUNT " /proc/mounts; then
235                 echo "test 5: /proc/mounts after failed umount"
236                 umount $MOUNT &
237                 UMOUNT_PID=$!
238                 sleep 2
239                 echo "killing umount"
240                 kill -TERM $UMOUNT_PID
241                 echo "waiting for umount to finish"
242                 wait $UMOUNT_PID
243                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
244         fi
245
246         manual_umount_client
247         # stop_mds is a no-op here, and should not fail
248         cleanup_nocli || return $?
249         # df may have lingering entry
250         manual_umount_client
251         # mtab may have lingering entry
252         grep -v $MOUNT" " /etc/mtab > $TMP/mtabtemp
253         mv $TMP/mtabtemp /etc/mtab
254 }
255 run_test 5 "force cleanup mds, then cleanup"
256
257 test_5b() {
258         start_ost
259         [ -d $MOUNT ] || mkdir -p $MOUNT
260         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab before mount" && return 10
261         mount_client $MOUNT && return 1
262         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab after failed mount" && return 11
263         umount_client $MOUNT    
264         # stop_mds is a no-op here, and should not fail
265         cleanup_nocli || return $?
266         return 0
267 }
268 run_test 5b "mds down, cleanup after failed mount (bug 2712) (should return errs)"
269
270 test_5c() {
271         start_ost
272         start_mds
273         [ -d $MOUNT ] || mkdir -p $MOUNT
274         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab before mount" && return 10
275         mount -t lustre $MGSNID:/wrong.$FSNAME $MOUNT || :
276         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab after failed mount" && return 11
277         umount_client $MOUNT
278         cleanup_nocli  || return $?
279 }
280 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
281
282 test_5d() {
283         start_ost
284         start_mds
285         stop_ost -f
286         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab before mount" && return 10
287         mount_client $MOUNT || return 1
288         cleanup  || return $?
289         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab after unmount" && return 11
290         return 0
291 }
292 run_test 5d "mount with ost down"
293
294 test_5e() {
295         start_ost
296         start_mds
297
298 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
299         do_facet client "sysctl -w lustre.fail_loc=0x80000506"
300         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab before mount" && return 10
301         mount_client $MOUNT || echo "mount failed (not fatal)"
302         cleanup  || return $?
303         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab after unmount" && return 11
304         return 0
305 }
306 run_test 5e "delayed connect, don't crash (bug 10268)"
307
308 test_6() {
309         setup
310         manual_umount_client
311         mount_client ${MOUNT} || return 87
312         touch $DIR/a || return 86
313         cleanup  || return $?
314 }
315 run_test 6 "manual umount, then mount again"
316
317 test_7() {
318         setup
319         manual_umount_client
320         cleanup_nocli || return $?
321 }
322 run_test 7 "manual umount, then cleanup"
323
324 test_8() {
325         setup
326         mount_client $MOUNT2
327         check_mount2 || return 45
328         umount_client $MOUNT2
329         cleanup  || return $?
330 }
331 run_test 8 "double mount setup"
332
333 test_9() {
334         start_ost
335
336         do_facet ost1 sysctl lnet.debug=\'inode trace\' || return 1
337         do_facet ost1 sysctl lnet.subsystem_debug=\'mds ost\' || return 1
338
339         CHECK_PTLDEBUG="`do_facet ost1 sysctl -n lnet.debug`"
340         if [ "$CHECK_PTLDEBUG" ] && [ "$CHECK_PTLDEBUG" = "trace inode" ];then
341            echo "lnet.debug success"
342         else
343            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
344            return 1
345         fi
346         CHECK_SUBSYS="`do_facet ost1 sysctl -n lnet.subsystem_debug`"
347         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
348            echo "lnet.subsystem_debug success"
349         else
350            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
351            return 1
352         fi
353         stop_ost || return $?
354 }
355
356 run_test 9 "test ptldebug and subsystem for mkfs"
357
358 test_10() {
359         echo "generate configuration with the same name for node and mds"
360         OLDXMLCONFIG=$XMLCONFIG
361         XMLCONFIG="broken.xml"
362         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
363         facet="mds"
364         rm -f ${facet}active
365         add_facet $facet
366         echo "the name for node and mds is the same"
367         do_lmc --add mds --node ${facet}_facet --mds ${facet}_facet \
368             --dev $MDSDEV --size $MDSSIZE || return $?
369         do_lmc --add lov --mds ${facet}_facet --lov lov1 --stripe_sz \
370             $STRIPE_BYTES --stripe_cnt $STRIPES_PER_OBJ \
371             --stripe_pattern 0 || return $?
372         add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE
373         facet="client"
374         add_facet $facet --lustre_upcall $UPCALL
375         do_lmc --add mtpt --node ${facet}_facet --mds mds_facet \
376             --lov lov1 --path $MOUNT
377
378         echo "mount lustre"
379         start_ost
380         start_mds
381         mount_client $MOUNT
382         check_mount || return 41
383         cleanup || return $?
384
385         echo "Success!"
386         XMLCONFIG=$OLDXMLCONFIG
387 }
388 run_test 10 "mount lustre with the same name for node and mds"
389
390 test_11() {
391         OLDXMLCONFIG=$XMLCONFIG
392         XMLCONFIG="conf11.xml"
393
394         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
395         add_mds mds --dev $MDSDEV --size $MDSSIZE
396         add_ost ost --dev $OSTDEV --size $OSTSIZE
397         add_client client mds --path $MOUNT --ost ost_svc || return $?
398         echo "Default lov config success!"
399
400         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
401         add_mds mds --dev $MDSDEV --size $MDSSIZE
402         add_ost ost --dev $OSTDEV --size $OSTSIZE
403         add_client client mds --path $MOUNT && return $?
404         echo "--add mtpt with neither --lov nor --ost will return error"
405
406         echo ""
407         echo "Success!"
408         XMLCONFIG=$OLDXMLCONFIG
409 }
410 run_test 11 "use default lov configuration (should return error)"
411
412 test_12() {
413         OLDXMLCONFIG=$XMLCONFIG
414         XMLCONFIG="batch.xml"
415         BATCHFILE="batchfile"
416
417         # test double quote
418         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
419         [ -f "$BATCHFILE" ] && rm -f $BATCHFILE
420         echo "--add net --node $HOSTNAME --nid $HOSTNAME --nettype tcp" > $BATCHFILE
421         echo "--add mds --node $HOSTNAME --mds mds1 --mkfsoptions \"-I 128\"" >> $BATCHFILE
422         # --mkfsoptions "-I 128"
423         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
424         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
425                 echo "matched double quote success"
426         else
427                 echo "matched double quote fail"
428                 return 1
429         fi
430         rm -f $XMLCONFIG
431         rm -f $BATCHFILE
432         echo "--add net --node $HOSTNAME --nid $HOSTNAME --nettype tcp" > $BATCHFILE
433         echo "--add mds --node $HOSTNAME --mds mds1 --mkfsoptions \"-I 128" >> $BATCHFILE
434         # --mkfsoptions "-I 128
435         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
436         echo "unmatched double quote should return error"
437
438         # test single quote
439         rm -f $BATCHFILE
440         echo "--add net --node $HOSTNAME --nid $HOSTNAME --nettype tcp" > $BATCHFILE
441         echo "--add mds --node $HOSTNAME --mds mds1 --mkfsoptions '-I 128'" >> $BATCHFILE
442         # --mkfsoptions '-I 128'
443         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
444         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
445                 echo "matched single quote success"
446         else
447                 echo "matched single quote fail"
448                 return 1
449         fi
450         rm -f $XMLCONFIG
451         rm -f $BATCHFILE
452         echo "--add net --node $HOSTNAME --nid $HOSTNAME --nettype tcp" > $BATCHFILE
453         echo "--add mds --node $HOSTNAME --mds mds1 --mkfsoptions '-I 128" >> $BATCHFILE
454         # --mkfsoptions '-I 128
455         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
456         echo "unmatched single quote should return error"
457
458         # test backslash
459         rm -f $BATCHFILE
460         echo "--add net --node $HOSTNAME --nid $HOSTNAME --nettype tcp" > $BATCHFILE
461         echo "--add mds --node $HOSTNAME --mds mds1 --mkfsoptions \-\I\ \128" >> $BATCHFILE
462         # --mkfsoptions \-\I\ \128
463         do_lmc -m $XMLCONFIG --batch $BATCHFILE || return $?
464         if [ `sed -n '/>-I 128</p' $XMLCONFIG | wc -l` -eq 1 ]; then
465                 echo "backslash followed by a whitespace/letter success"
466         else
467                 echo "backslash followed by a whitespace/letter fail"
468                 return 1
469         fi
470         rm -f $XMLCONFIG
471         rm -f $BATCHFILE
472         echo "--add net --node $HOSTNAME --nid $HOSTNAME --nettype tcp" > $BATCHFILE
473         echo "--add mds --node $HOSTNAME --mds mds1 --mkfsoptions -I\ 128\\" >> $BATCHFILE
474         # --mkfsoptions -I\ 128\
475         do_lmc -m $XMLCONFIG --batch $BATCHFILE && return $?
476         echo "backslash followed by nothing should return error"
477
478         rm -f $BATCHFILE
479         XMLCONFIG=$OLDXMLCONFIG
480 }
481 run_test 12 "lmc --batch, with single/double quote, backslash in batchfile"
482
483 test_13() {
484         OLDXMLCONFIG=$XMLCONFIG
485         XMLCONFIG="conf13-1.xml"
486
487         # check long uuid will be truncated properly and uniquely
488         echo "To generate XML configuration file(with long ost name): $XMLCONFIG"
489         [ -f "$XMLCONFIG" ] && rm -f $XMLCONFIG
490         do_lmc --add net --node $HOSTNAME --nid $HOSTNAME --nettype tcp
491         do_lmc --add mds --node $HOSTNAME --mds mds1_name_longer_than_31characters
492         do_lmc --add mds --node $HOSTNAME --mds mds2_name_longer_than_31characters
493         if [ ! -f "$XMLCONFIG" ]; then
494                 echo "Error:no file $XMLCONFIG created!"
495                 return 1
496         fi
497         EXPECTEDMDS1UUID="e_longer_than_31characters_UUID"
498         EXPECTEDMDS2UUID="longer_than_31characters_UUID_2"
499         FOUNDMDS1UUID=`awk -F"'" '/<mds .*uuid=/' $XMLCONFIG | sed -n '1p' \
500                        | sed "s/ /\n\r/g" | awk -F"'" '/uuid=/{print $2}'`
501         FOUNDMDS2UUID=`awk -F"'" '/<mds .*uuid=/' $XMLCONFIG | sed -n '2p' \
502                        | sed "s/ /\n\r/g" | awk -F"'" '/uuid=/{print $2}'`
503         [ -z "$FOUNDMDS1UUID" ] && echo "MDS1 UUID empty" && return 1
504         [ -z "$FOUNDMDS2UUID" ] && echo "MDS2 UUID empty" && return 1
505         if ([ $EXPECTEDMDS1UUID = $FOUNDMDS1UUID ] && [ $EXPECTEDMDS2UUID = $FOUNDMDS2UUID ]) || \
506            ([ $EXPECTEDMDS1UUID = $FOUNDMDS2UUID ] && [ $EXPECTEDMDS2UUID = $FOUNDMDS1UUID ]); then
507                 echo "Success:long uuid truncated successfully and being unique."
508         else
509                 echo "Error:expected uuid for mds1 and mds2: $EXPECTEDMDS1UUID; $EXPECTEDMDS2UUID"
510                 echo "but:     found uuid for mds1 and mds2: $FOUNDMDS1UUID; $FOUNDMDS2UUID"
511                 return 1
512         fi
513         rm -f $XMLCONFIG
514         XMLCONFIG=$OLDXMLCONFIG
515 }
516 run_test 13 "check new_uuid of lmc operating correctly"
517
518 test_13b() {
519         OLDXMLCONFIG=$XMLCONFIG
520         XMLCONFIG="conf13-1.xml"
521         SECONDXMLCONFIG="conf13-2.xml"
522         # check multiple invocations for lmc generate same XML configuration file
523         rm -f $XMLCONFIG
524         echo "Generate the first XML configuration file"
525         gen_config
526         echo "mv $XMLCONFIG to $SECONDXMLCONFIG"
527         sed -e "s/mtime[^ ]*//" $XMLCONFIG > $SECONDXMLCONFIG || return $?
528         echo "Generate the second XML configuration file"
529         gen_config
530         # don't compare .xml mtime, it will always be different
531         if [ `sed -e "s/mtime[^ ]*//" $XMLCONFIG | diff - $SECONDXMLCONFIG | wc -l` -eq 0 ]; then
532                 echo "Success:multiple invocations for lmc generate same XML file"
533         else
534                 echo "Error: multiple invocations for lmc generate different XML file"
535                 return 1
536         fi
537
538         rm -f $XMLCONFIG $SECONDXMLCONFIG
539         XMLCONFIG=$OLDXMLCONFIG
540 }
541 run_test 13b "check lmc generates consistent .xml file"
542
543 test_14() {
544         rm -f $XMLCONFIG
545
546         # create xml file with --mkfsoptions for ost
547         echo "create xml file with --mkfsoptions for ost"
548         add_mds mds --dev $MDSDEV --size $MDSSIZE
549         add_lov lov1 mds --stripe_sz $STRIPE_BYTES\
550             --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
551         add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE \
552             --mkfsoptions "-Llabel_conf_14"
553         add_client client mds --lov lov1 --path $MOUNT
554
555         FOUNDSTRING=`awk -F"<" '/<mkfsoptions>/{print $2}' $XMLCONFIG`
556         EXPECTEDSTRING="mkfsoptions>-Llabel_conf_14"
557         if [ "$EXPECTEDSTRING" != "$FOUNDSTRING" ]; then
558                 echo "Error: expected: $EXPECTEDSTRING; found: $FOUNDSTRING"
559                 return 1
560         fi
561         echo "Success:mkfsoptions for ost written to xml file correctly."
562
563         # mount lustre to test lconf mkfsoptions-parsing
564         echo "mount lustre"
565         start_ost
566         start_mds
567         mount_client $MOUNT || return $?
568         if [ -z "`do_facet ost1 dumpe2fs -h $OSTDEV | grep label_conf_14`" ]; then
569                 echo "Error: the mkoptions not applied to mke2fs of ost."
570                 return 1
571         fi
572         cleanup
573         echo "lconf mkfsoptions for ost success"
574
575         gen_config
576 }
577 run_test 14 "test mkfsoptions of ost for lmc and lconf"
578
579 cleanup_15() {
580         trap 0
581         [ -f $MOUNTLUSTRE ] && echo "remove $MOUNTLUSTRE" && rm -f $MOUNTLUSTRE
582         if [ -f $MOUNTLUSTRE.sav ]; then
583                 echo "return original $MOUNTLUSTRE.sav to $MOUNTLUSTRE"
584                 mv $MOUNTLUSTRE.sav $MOUNTLUSTRE
585         fi
586 }
587
588 # this only tests the kernel mount command, not anything about lustre.
589 test_15() {
590         MOUNTLUSTRE=${MOUNTLUSTRE:-/sbin/mount.lustre}
591         start_ost
592         start_mds
593
594         echo "mount lustre on ${MOUNT} without $MOUNTLUSTRE....."
595         if [ -f "$MOUNTLUSTRE" ]; then
596                 echo "save $MOUNTLUSTRE to $MOUNTLUSTRE.sav"
597                 mv $MOUNTLUSTRE $MOUNTLUSTRE.sav && trap cleanup_15 EXIT INT
598                 if [ -f $MOUNTLUSTRE ]; then
599                         echo "$MOUNTLUSTRE cannot be moved, skipping test"
600                         return 0
601                 fi
602         fi
603
604         mount_client $MOUNT && error "mount succeeded" && return 1
605         echo "mount lustre on $MOUNT without $MOUNTLUSTRE failed as expected"
606         cleanup_15
607         cleanup || return $?
608 }
609 run_test 15 "zconf-mount without /sbin/mount.lustre (should return error)"
610
611 test_16() {
612         TMPMTPT="${MOUNT%/*}/conf16"
613
614         if [ ! -f "$MDSDEV" ]; then
615             echo "no $MDSDEV existing, so mount Lustre to create one"
616             setup
617             check_mount || return 41
618             cleanup || return $?
619         fi
620
621         echo "change the mode of $MDSDEV/OBJECTS,LOGS,PENDING to 555"
622         do_facet mds "mkdir -p $TMPMTPT &&
623                       mount -o loop -t ext3 $MDSDEV $TMPMTPT &&
624                       chmod 555 $TMPMTPT/{OBJECTS,LOGS,PENDING} &&
625                       umount $TMPMTPT" || return $?
626
627         echo "mount Lustre to change the mode of OBJECTS/LOGS/PENDING, then umount Lustre"
628         setup
629         check_mount || return 41
630         cleanup || return $?
631
632         echo "read the mode of OBJECTS/LOGS/PENDING and check if they has been changed properly"
633         EXPECTEDOBJECTSMODE=`do_facet mds "debugfs -R 'stat OBJECTS' $MDSDEV 2> /dev/null" | grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
634         EXPECTEDLOGSMODE=`do_facet mds "debugfs -R 'stat LOGS' $MDSDEV 2> /dev/null" | grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
635         EXPECTEDPENDINGMODE=`do_facet mds "debugfs -R 'stat PENDING' $MDSDEV 2> /dev/null" | grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
636
637         if [ "$EXPECTEDOBJECTSMODE" = "0777" ]; then
638                 echo "Success:Lustre change the mode of OBJECTS correctly"
639         else
640                 echo "Error: Lustre does not change mode of OBJECTS properly"
641                 return 1
642         fi
643
644         if [ "$EXPECTEDLOGSMODE" = "0777" ]; then
645                 echo "Success:Lustre change the mode of LOGS correctly"
646         else
647                 echo "Error: Lustre does not change mode of LOGS properly"
648                 return 1
649         fi
650
651         if [ "$EXPECTEDPENDINGMODE" = "0777" ]; then
652                 echo "Success:Lustre change the mode of PENDING correctly"
653         else
654                 echo "Error: Lustre does not change mode of PENDING properly"
655                 return 1
656         fi
657 }
658 run_test 16 "verify that lustre will correct the mode of OBJECTS/LOGS/PENDING"
659
660 test_17() {
661         if [ ! -f "$MDSDEV" ]; then
662             echo "no $MDSDEV existing, so mount Lustre to create one"
663             setup
664             check_mount || return 41
665             cleanup || return $?
666         fi
667
668         echo "Remove mds config log"
669         do_facet mds "debugfs -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MDSDEV || return \$?" || return $?
670
671         start_ost
672         start_mds && return 42
673         gen_config
674 }
675 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
676
677 test_18() {
678         [ -f $MDSDEV ] && echo "remove $MDSDEV" && rm -f $MDSDEV
679         echo "mount mds with large journal..."
680         OLDMDSSIZE=$MDSSIZE
681         MDSSIZE=2000000
682         #FIXME have to change MDS_MKFS_OPTS
683         gen_config
684
685         echo "mount lustre system..."
686         setup
687         check_mount || return 41
688
689         echo "check journal size..."
690         FOUNDJOURNALSIZE=`do_facet mds "debugfs -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}'`
691         if [ "$FOUNDJOURNALSIZE" = "79691776" ]; then
692                 echo "Success:lconf creates large journals"
693         else
694                 echo "Error:lconf not create large journals correctly"
695                 echo "expected journal size: 79691776(76M), found journal size: $FOUNDJOURNALSIZE"
696                 return 1
697         fi
698
699         cleanup || return $?
700
701         MDSSIZE=$OLDMDSSIZE
702         gen_config
703 }
704 run_test 18 "check lconf creates large journals"
705
706 test_19a() {
707         start_mds || return 1
708         stop_mds -f || return 2
709 }
710 run_test 19a "start/stop MDS without OSTs"
711
712 test_19b() {
713         start_ost || return 1
714         stop_ost -f || return 2
715 }
716 run_test 19b "start/stop OSTs without MDS"
717
718 test_20() {
719         # first format the ost/mdt
720         start_ost
721         start_mds
722         mount_client $MOUNT
723         check_mount || return 43
724         rm -f $DIR/$tfile
725         remount_client ro $MOUNT || return 44
726         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
727         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
728         remount_client rw $MOUNT || return 47
729         touch $DIR/$tfile
730         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
731         MCNT=`grep -c $MOUNT /etc/mtab`
732         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
733         umount_client $MOUNT
734         stop_mds
735         stop_ost
736 }
737 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
738
739 test_21a() {
740         start_mds
741         start_ost
742         stop_ost
743         stop_mds
744 }
745 run_test 21a "start mds before ost, stop ost first"
746
747 test_21b() {
748         start_ost
749         start_mds
750         stop_mds
751         stop_ost
752 }
753 run_test 21b "start ost before mds, stop mds first"
754
755 test_21c() {
756         start_ost
757         start_mds
758         start_ost2
759         stop_ost
760         stop_ost2
761         stop_mds
762 }
763 run_test 21c "start mds between two osts, stop mds last"
764
765 test_22() {
766         #reformat to remove all logs
767         reformat
768         start_mds
769
770         echo Client mount with a running ost
771         start_ost
772         mount_client $MOUNT
773         check_mount || return 41
774         umount_client $MOUNT
775         pass
776
777         echo Client mount with ost in logs, but none running
778         stop_ost
779         mount_client $MOUNT
780         # check_mount will block trying to contact ost
781         umount_client $MOUNT
782         pass
783
784         cleanup
785 }
786 run_test 22 "start a client before osts (should return errs)"
787
788 test_23() {
789         setup
790         # fail mds
791         stop mds   
792         # force down client so that recovering mds waits for reconnect
793         zconf_umount `hostname` $MOUNT -f
794         # enter recovery on mds
795         start_mds
796         # try to start a new client
797         mount_client $MOUNT &
798         MOUNT_PID=$!
799         sleep 5
800         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
801         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
802         ps --ppid $MOUNT_PID
803         ps --ppid $MOUNT_LUSTRE_PID
804         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
805         kill -TERM $MOUNT_PID
806         echo "waiting for mount to finish"
807         ps -ef | grep mount
808         wait $MOUNT_PID
809
810         stop_mds
811         stop_ost
812 }
813 #this test isn't working yet
814 #run_test 23 "interrupt client during recovery mount delay"
815
816 test_24a() {
817         local fs2mds_HOST=$mds_HOST
818         # test 8-char fsname as well
819         local FSNAME2=test1234
820         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat ${MDSDEV}_2 || exit 10
821
822         local fs2ost_HOST=$ost_HOST
823         local fs2ostdev=$(ostdevname 1)_2
824         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
825
826         setup
827         start fs2mds ${MDSDEV}_2 $MDS_MOUNT_OPTS
828         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
829         mkdir -p $MOUNT2
830         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
831         # 1 still works
832         check_mount || return 2
833         # files written on 1 should not show up on 2
834         cp /etc/passwd $DIR/$tfile
835         sleep 10
836         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
837         # 2 should work
838         cp /etc/passwd $MOUNT2/b || return 3
839         rm $MOUNT2/b || return 4
840         # 2 is actually mounted
841         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
842         # failover 
843         facet_failover fs2mds
844         facet_failover fs2ost
845         df
846         umount_client $MOUNT 
847         # the MDS must remain up until last MDT
848         stop_mds
849         MDS=$(awk '($3 ~ "mdt" && $4 ~ "MDS") { print $4 }' $LPROC/devices)
850         [ -z "$MDS" ] && error "No MDS" && return 8
851         umount $MOUNT2
852         stop fs2mds -f
853         stop fs2ost -f
854         cleanup_nocli || return 6
855 }
856 run_test 24a "Multiple MDTs on a single node"
857
858 test_24b() {
859         local fs2mds_HOST=$mds_HOST
860         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat ${MDSDEV}_2 || exit 10
861         setup
862         start fs2mds ${MDSDEV}_2 $MDS_MOUNT_OPTS && return 2
863         cleanup || return 6
864 }
865 run_test 24b "Multiple MGSs on a single node (should return err)"
866
867 test_25() {
868         setup
869         check_mount || return 2
870         local MODULES=$($LCTL modules | awk '{ print $2 }')
871         rmmod $MODULES 2>/dev/null || true
872         cleanup || return 6
873 }
874 run_test 25 "Verify modules are referenced"
875
876 test_26() {
877     load_modules
878     # we need modules before mount for sysctl, so make sure...
879     [ -z "$(lsmod | grep lustre)" ] && modprobe lustre 
880 #define OBD_FAIL_MDS_FS_SETUP            0x135
881     do_facet mds "sysctl -w lustre.fail_loc=0x80000135"
882     start_mds && echo MDS started && return 1
883     cat $LPROC/devices
884     DEVS=$(cat $LPROC/devices | wc -l)
885     [ $DEVS -gt 0 ] && return 2
886     unload_modules || return 203
887 }
888 run_test 26 "MDT startup failure cleans LOV (should return errs)"
889
890 set_and_check() {
891         local TEST=$1
892         local PARAM=$2
893         local ORIG=$($TEST) 
894         if [ $# -gt 2 ]; then
895             local FINAL=$3
896         else
897             local -i FINAL
898             FINAL=$(($ORIG + 5))
899         fi
900         echo "Setting $PARAM from $ORIG to $FINAL"
901         $LCTL conf_param $PARAM=$FINAL
902         local RESULT
903         local MAX=30
904         local WAIT=0
905         while [ 1 ]; do
906             sleep 5
907             RESULT=$($TEST) 
908             if [ $RESULT -eq $FINAL ]; then
909                 echo "Updated config after $WAIT sec (got $RESULT)"
910                 break
911             fi
912             WAIT=$((WAIT + 5))
913             if [ $WAIT -eq $MAX ]; then
914                 echo "Config update not seen: wanted $FINAL got $RESULT"
915                 return 3
916             fi
917             echo "Waiting $(($MAX - $WAIT)) secs for config update" 
918         done
919 }
920
921 test_27a() {
922         start_ost || return 1
923         start_mds || return 2
924         echo "Requeue thread should have started: " 
925         ps -e | grep ll_cfg_requeue 
926         set_and_check "cat $LPROC/obdfilter/$FSNAME-OST0000/client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3 
927         cleanup_nocli
928 }
929 run_test 27a "Reacquire MGS lock if OST started first"
930
931 test_27b() {
932         setup
933         facet_failover mds
934         set_and_check "cat $LPROC/mds/$FSNAME-MDT0000/group_acquire_expire" "$FSNAME-MDT0000.mdt.group_acquire_expire" || return 3 
935         set_and_check "cat $LPROC/mdc/$FSNAME-MDT0000-mdc-*/max_rpcs_in_flight" "$FSNAME-MDT0000.mdc.max_rpcs_in_flight" || return 4 
936         cleanup
937 }
938 run_test 27b "Reacquire MGS lock after failover"
939
940 test_28() {
941         setup
942         TEST="cat $LPROC/llite/$FSNAME-*/max_read_ahead_whole_mb"
943         ORIG=$($TEST) 
944         declare -i FINAL
945         FINAL=$(($ORIG + 10))
946         set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" || return 3
947         set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" || return 3
948         umount_client $MOUNT || return 200
949         mount_client $MOUNT
950         RESULT=$($TEST)
951         if [ $RESULT -ne $FINAL ]; then
952             echo "New config not seen: wanted $FINAL got $RESULT"
953             return 4
954         else
955             echo "New config success: got $RESULT"
956         fi
957         cleanup
958 }
959 run_test 28 "permanent parameter setting"
960
961 test_29() {
962         [ "$OSTCOUNT" -lt "2" ] && echo "skipping deactivate test" && return
963         setup > /dev/null 2>&1
964         start_ost2
965         sleep 10
966
967         local PARAM="$FSNAME-OST0001.osc.active"
968         local PROC_ACT="$LPROC/osc/$FSNAME-OST0001-osc-*/active"
969         local PROC_UUID="$LPROC/osc/$FSNAME-OST0001-osc-*/ost_server_uuid"
970         if [ ! -r $PROC_ACT ]; then
971             echo "Can't read $PROC_ACT"
972             ls $LPROC/osc/$FSNAME-*
973             return 1
974         fi
975         ACTV=$(cat $PROC_ACT)
976         DEAC=$((1 - $ACTV))
977         set_and_check "cat $PROC_ACT" "$PARAM" $DEAC || return 2
978         # also check ost_server_uuid status
979         RESULT=$(grep DEACTIV $PROC_UUID)
980         if [ -z "$RESULT" ]; then
981             echo "Live client not deactivated: $(cat $PROC_UUID)"
982             return 3
983         else
984             echo "Live client success: got $RESULT"
985         fi
986
987         # check MDT too 
988         local MPROC="$LPROC/osc/$FSNAME-OST0001-osc/active"
989         if [ -r $MPROC ]; then
990             RESULT=$(cat $MPROC)
991             if [ $RESULT -ne $DEAC ]; then
992                 echo "MDT not deactivated: $(cat $MPROC)"
993                 return 4
994             fi
995             echo "MDT deactivated also"
996         fi
997
998         # test new client starts deactivated
999         umount_client $MOUNT || return 200
1000         mount_client $MOUNT
1001         RESULT=$(grep DEACTIV $PROC_UUID | grep NEW)
1002         if [ -z "$RESULT" ]; then
1003             echo "New client not deactivated from start: $(cat $PROC_UUID)"
1004             return 5
1005         else
1006             echo "New client success: got $RESULT"
1007         fi
1008
1009         # make sure it reactivates
1010         set_and_check "cat $PROC_ACT" "$PARAM" $ACTV || return 6
1011
1012         umount_client $MOUNT
1013         stop_ost2
1014         cleanup_nocli
1015         #writeconf to remove all ost2 traces for subsequent tests
1016         writeconf
1017 }
1018 run_test 29 "permanently remove an OST"
1019
1020 test_30() {
1021         # start mds first after writeconf
1022         start_mds
1023         start_ost
1024         mount_client $MOUNT
1025         TEST="cat $LPROC/llite/$FSNAME-*/max_read_ahead_whole_mb"
1026         ORIG=$($TEST) 
1027         for i in $(seq 1 20); do 
1028             set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1029         done
1030         # make sure client restart still works 
1031         umount_client $MOUNT
1032         mount_client $MOUNT || return 4
1033         [ "$($TEST)" -ne "$i" ] && return 5   
1034         set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $ORIG || return 6
1035         cleanup
1036 }
1037 run_test 30 "Big config llog"
1038
1039 test_31() { # bug 10734
1040         # ipaddr must not exist
1041         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1042         cleanup
1043 }
1044 run_test 31 "Connect to non-existent node (shouldn't crash)"
1045
1046 test_32a() {
1047         [ -z "$TUNEFS" ] && echo "No tunefs" && return
1048         [ ! -r disk1_4.zip ] && echo "Cant find disk1_4.zip, skipping" && return
1049         unzip -o -j -d $TMP/$tdir disk1_4.zip || { echo "Cant unzip disk1_4, skipping" && return ; }
1050         load_modules
1051         sysctl lnet.debug=$PTLDEBUG
1052
1053         $TUNEFS $TMP/$tdir/mds || error "tunefs failed"
1054         # nids are wrong, so client wont work, but server should start
1055         start mds $TMP/$tdir/mds "-o loop,exclude=lustre-OST0000" || return 3
1056         local UUID=$(cat $LPROC/mds/lustre-MDT0000/uuid)
1057         echo MDS uuid $UUID
1058         [ "$UUID" == "mdsA_UUID" ] || error "UUID is wrong: $UUID" 
1059
1060         $TUNEFS --mgsnode=`hostname` $TMP/$tdir/ost1 || error "tunefs failed"
1061         start ost1 $TMP/$tdir/ost1 "-o loop" || return 5
1062         UUID=$(cat $LPROC/obdfilter/lustre-OST0000/uuid)
1063         echo OST uuid $UUID
1064         [ "$UUID" == "ost1_UUID" ] || error "UUID is wrong: $UUID" 
1065
1066         local NID=$($LCTL list_nids | head -1)
1067
1068         echo "OSC changes should return err:" 
1069         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 && return 7
1070         $LCTL conf_param lustre-OST0000.failover.node=$NID && return 8
1071         echo "ok."
1072         echo "MDC changes should succeed:" 
1073         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1074         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1075         echo "ok."
1076
1077         cleanup_nocli
1078         load_modules
1079
1080         # mount a second time to make sure we didnt leave upgrade flag on
1081         $TUNEFS --dryrun $TMP/$tdir/mds || error "tunefs failed"
1082         start mds $TMP/$tdir/mds "-o loop,exclude=lustre-OST0000" || return 12
1083         cleanup_nocli
1084
1085         [ -d $TMP/$tdir ] && rm -rf $TMP/$tdir
1086 }
1087 run_test 32a "Upgrade from 1.4 (not live)"
1088
1089 test_32b() {
1090         [ -z "$TUNEFS" ] && echo "No tunefs" && return
1091         [ ! -r disk1_4.zip ] && echo "Cant find disk1_4.zip, skipping" && return
1092         unzip -o -j -d $TMP/$tdir disk1_4.zip || { echo "Cant unzip disk1_4, skipping" && return ; }
1093         load_modules
1094         sysctl lnet.debug=$PTLDEBUG
1095
1096         # writeconf will cause servers to register with their current nids
1097         $TUNEFS --writeconf $TMP/$tdir/mds || error "tunefs failed"
1098         start mds $TMP/$tdir/mds "-o loop" || return 3
1099         local UUID=$(cat $LPROC/mds/lustre-MDT0000/uuid)
1100         echo MDS uuid $UUID
1101         [ "$UUID" == "mdsA_UUID" ] || error "UUID is wrong: $UUID" 
1102
1103         $TUNEFS --mgsnode=`hostname` $TMP/$tdir/ost1 || error "tunefs failed"
1104         start ost1 $TMP/$tdir/ost1 "-o loop" || return 5
1105         UUID=$(cat $LPROC/obdfilter/lustre-OST0000/uuid)
1106         echo OST uuid $UUID
1107         [ "$UUID" == "ost1_UUID" ] || error "UUID is wrong: $UUID" 
1108
1109         echo "OSC changes should succeed:" 
1110         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || return 7
1111         $LCTL conf_param lustre-OST0000.failover.node=$NID || return 8
1112         echo "ok."
1113         echo "MDC changes should succeed:" 
1114         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1115         echo "ok."
1116
1117         # MDT and OST should have registered with new nids, so we should have
1118         # a fully-functioning client
1119         echo "Check client and old fs contents"
1120         mount_client $MOUNT
1121         set_and_check "cat $LPROC/mdc/*/max_rpcs_in_flight" "lustre-MDT0000.mdc.max_rpcs_in_flight" || return 11
1122         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "2479747619 779" ] || return 12  
1123         echo "ok."
1124
1125         cleanup
1126         [ -d $TMP/$tdir ] && rm -rf $TMP/$tdir
1127 }
1128 run_test 32b "Upgrade from 1.4 with writeconf"
1129
1130 umount_client $MOUNT    
1131 cleanup_nocli
1132
1133 equals_msg "Done"
1134 echo "$0: completed"