Whamcloud - gitweb
b=11778
[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         stop_mds -f || return 2
221
222         # cleanup may return an error from the failed
223         # disconnects; for now I'll consider this successful
224         # if all the modules have unloaded.
225         umount -d $MOUNT &
226         UMOUNT_PID=$!
227         sleep 6
228         echo "killing umount"
229         kill -TERM $UMOUNT_PID
230         echo "waiting for umount to finish"
231         wait $UMOUNT_PID
232         if grep " $MOUNT " /etc/mtab; then
233                 echo "test 5: mtab after failed umount"
234                 umount $MOUNT &
235                 UMOUNT_PID=$!
236                 sleep 2
237                 echo "killing umount"
238                 kill -TERM $UMOUNT_PID
239                 echo "waiting for umount to finish"
240                 wait $UMOUNT_PID
241                 grep " $MOUNT " /etc/mtab && echo "test 5: mtab after second umount" && return 11
242         fi
243
244         manual_umount_client
245         # stop_mds is a no-op here, and should not fail
246         cleanup_nocli || return $?
247         # df may have lingering entry
248         manual_umount_client
249         # mtab may have lingering entry
250         grep -v $MOUNT" " /etc/mtab > $TMP/mtabtemp
251         mv $TMP/mtabtemp /etc/mtab
252 }
253 run_test 5 "force cleanup mds, then cleanup"
254
255 test_5b() {
256         start_ost
257         [ -d $MOUNT ] || mkdir -p $MOUNT
258         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab before mount" && return 10
259         mount_client $MOUNT && return 1
260         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab after failed mount" && return 11
261         umount_client $MOUNT    
262         # stop_mds is a no-op here, and should not fail
263         cleanup_nocli || return $?
264         return 0
265 }
266 run_test 5b "mds down, cleanup after failed mount (bug 2712) (should return errs)"
267
268 test_5c() {
269         start_ost
270         start_mds
271         [ -d $MOUNT ] || mkdir -p $MOUNT
272         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab before mount" && return 10
273         mount -t lustre $MGSNID:/wrong.$FSNAME $MOUNT || :
274         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab after failed mount" && return 11
275         umount_client $MOUNT
276         cleanup_nocli  || return $?
277 }
278 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
279
280 test_5d() {
281         start_ost
282         start_mds
283         stop_ost -f
284         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab before mount" && return 10
285         mount_client $MOUNT || return 1
286         cleanup  || return $?
287         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab after unmount" && return 11
288         return 0
289 }
290 run_test 5d "mount with ost down"
291
292 test_5e() {
293         start_ost
294         start_mds
295         # give MDS a chance to connect to OSTs (bz 10476)
296         sleep 5 
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         echo Client mount before any osts are in the logs
770         mount_client $MOUNT
771         check_mount && return 41
772         pass
773
774         echo Client mount with ost in logs, but none running
775         start_ost
776         stop_ost
777         mount_client $MOUNT
778         # check_mount will block trying to contact ost
779         umount_client $MOUNT
780         pass
781
782         echo Client mount with a running ost
783         start_ost
784         mount_client $MOUNT
785         sleep 5 #bz10476
786         check_mount || return 41
787         pass
788
789         cleanup
790 }
791 run_test 22 "start a client before osts (should return errs)"
792
793 test_23() {
794         setup
795         # fail mds
796         stop mds   
797         # force down client so that recovering mds waits for reconnect
798         zconf_umount `hostname` $MOUNT -f
799         # enter recovery on mds
800         start_mds
801         # try to start a new client
802         mount_client $MOUNT &
803         MOUNT_PID=$!
804         sleep 5
805         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
806         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
807         ps --ppid $MOUNT_PID
808         ps --ppid $MOUNT_LUSTRE_PID
809         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
810         kill -TERM $MOUNT_PID
811         echo "waiting for mount to finish"
812         ps -ef | grep mount
813         wait $MOUNT_PID
814
815         stop_mds
816         stop_ost
817 }
818 #this test isn't working yet
819 #run_test 23 "interrupt client during recovery mount delay"
820
821 test_24a() {
822         local fs2mds_HOST=$mds_HOST
823         # test 8-char fsname as well
824         local FSNAME2=test1234
825         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat ${MDSDEV}_2 || exit 10
826
827         local fs2ost_HOST=$ost_HOST
828         local fs2ostdev=$(ostdevname 1)_2
829         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
830
831         setup
832         start fs2mds ${MDSDEV}_2 $MDS_MOUNT_OPTS
833         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
834         mkdir -p $MOUNT2
835         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
836         # 1 still works
837         check_mount || return 2
838         # files written on 1 should not show up on 2
839         cp /etc/passwd $DIR/$tfile
840         sleep 10
841         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
842         # 2 should work
843         cp /etc/passwd $MOUNT2/b || return 3
844         rm $MOUNT2/b || return 4
845         # 2 is actually mounted
846         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
847         # failover 
848         facet_failover fs2mds
849         facet_failover fs2ost
850         df
851         umount_client $MOUNT 
852         # the MDS must remain up until last MDT
853         stop_mds
854         MDS=$(awk '($3 ~ "mdt" && $4 ~ "MDS") { print $4 }' $LPROC/devices)
855         [ -z "$MDS" ] && error "No MDS" && return 8
856         umount $MOUNT2
857         stop fs2mds -f
858         stop fs2ost -f
859         cleanup_nocli || return 6
860 }
861 run_test 24a "Multiple MDTs on a single node"
862
863 test_24b() {
864         local fs2mds_HOST=$mds_HOST
865         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat ${MDSDEV}_2 || exit 10
866         setup
867         start fs2mds ${MDSDEV}_2 $MDS_MOUNT_OPTS && return 2
868         cleanup || return 6
869 }
870 run_test 24b "Multiple MGSs on a single node (should return err)"
871
872 test_25() {
873         setup
874         check_mount || return 2
875         local MODULES=$($LCTL modules | awk '{ print $2 }')
876         rmmod $MODULES 2>/dev/null || true
877         cleanup || return 6
878 }
879 run_test 25 "Verify modules are referenced"
880
881 test_26() {
882     load_modules
883     # we need modules before mount for sysctl, so make sure...
884     [ -z "$(lsmod | grep lustre)" ] && modprobe lustre 
885 #define OBD_FAIL_MDS_FS_SETUP            0x135
886     sysctl -w lustre.fail_loc=0x80000135
887     start_mds && echo MDS started && return 1
888     cat $LPROC/devices
889     DEVS=$(cat $LPROC/devices | wc -l)
890     [ $DEVS -gt 0 ] && return 2
891     unload_modules || return 203
892 }
893 run_test 26 "MDT startup failure cleans LOV (should return errs)"
894
895 set_and_check() {
896         local TEST=$1
897         local PARAM=$2
898         local ORIG=$($TEST) 
899         if [ $# -gt 2 ]; then
900             local FINAL=$3
901         else
902             local -i FINAL
903             FINAL=$(($ORIG + 5))
904         fi
905         echo "Setting $PARAM from $ORIG to $FINAL"
906         $LCTL conf_param $PARAM=$FINAL
907         local RESULT
908         local MAX=20
909         local WAIT=0
910         while [ 1 ]; do
911             sleep 5
912             RESULT=$($TEST) 
913             if [ $RESULT -eq $FINAL ]; then
914                 echo "Updated config after $WAIT sec (got $RESULT)"
915                 break
916             fi
917             WAIT=$((WAIT + 5))
918             if [ $WAIT -eq $MAX ]; then
919                 echo "Config update not seen: wanted $FINAL got $RESULT"
920                 return 3
921             fi
922             echo "Waiting $(($MAX - $WAIT)) secs for config update" 
923         done
924 }
925
926 test_27a() {
927         start_ost || return 1
928         start_mds || return 2
929         echo "Requeue thread should have started: " 
930         ps -e | grep ll_cfg_requeue 
931         set_and_check "cat $LPROC/obdfilter/$FSNAME-OST0000/client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3 
932         cleanup_nocli
933 }
934 run_test 27a "Reacquire MGS lock if OST started first"
935
936 test_27b() {
937         setup
938         facet_failover mds
939         set_and_check "cat $LPROC/mds/$FSNAME-MDT0000/group_acquire_expire" "$FSNAME-MDT0000.mdt.group_acquire_expire" || return 3 
940         set_and_check "cat $LPROC/mdc/$FSNAME-MDT0000-mdc-*/max_rpcs_in_flight" "$FSNAME-MDT0000.mdc.max_rpcs_in_flight" || return 4 
941         cleanup
942 }
943 run_test 27b "Reacquire MGS lock after failover"
944
945 test_28() {
946         setup
947         TEST="cat $LPROC/llite/$FSNAME-*/max_read_ahead_whole_mb"
948         ORIG=$($TEST) 
949         declare -i FINAL
950         FINAL=$(($ORIG + 10))
951         set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" || return 3
952         set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" || return 3
953         umount_client $MOUNT || return 200
954         mount_client $MOUNT
955         RESULT=$($TEST)
956         if [ $RESULT -ne $FINAL ]; then
957             echo "New config not seen: wanted $FINAL got $RESULT"
958             return 4
959         else
960             echo "New config success: got $RESULT"
961         fi
962         cleanup
963 }
964 run_test 28 "permanent parameter setting"
965
966 test_29() {
967         [ "$OSTCOUNT" -lt "2" ] && echo "skipping deactivate test" && return
968         setup > /dev/null 2>&1
969         start_ost2
970         sleep 10
971
972         local PARAM="$FSNAME-OST0001.osc.active"
973         local PROC_ACT="$LPROC/osc/$FSNAME-OST0001-osc-*/active"
974         local PROC_UUID="$LPROC/osc/$FSNAME-OST0001-osc-*/ost_server_uuid"
975         if [ ! -r $PROC_ACT ]; then
976             echo "Can't read $PROC_ACT"
977             ls $LPROC/osc/$FSNAME-*
978             return 1
979         fi
980         ACTV=$(cat $PROC_ACT)
981         DEAC=$((1 - $ACTV))
982         set_and_check "cat $PROC_ACT" "$PARAM" $DEAC || return 2
983         # also check ost_server_uuid status
984         RESULT=$(grep DEACTIV $PROC_UUID)
985         if [ -z "$RESULT" ]; then
986             echo "Live client not deactivated: $(cat $PROC_UUID)"
987             return 3
988         else
989             echo "Live client success: got $RESULT"
990         fi
991
992         # check MDT too 
993         local MPROC="$LPROC/osc/$FSNAME-OST0001-osc/active"
994         if [ -r $MPROC ]; then
995             RESULT=$(cat $MPROC)
996             if [ $RESULT -ne $DEAC ]; then
997                 echo "MDT not deactivated: $(cat $MPROC)"
998                 return 4
999             fi
1000             echo "MDT deactivated also"
1001         fi
1002
1003         # test new client starts deactivated
1004         umount_client $MOUNT || return 200
1005         mount_client $MOUNT
1006         RESULT=$(grep DEACTIV $PROC_UUID | grep NEW)
1007         if [ -z "$RESULT" ]; then
1008             echo "New client not deactivated from start: $(cat $PROC_UUID)"
1009             return 5
1010         else
1011             echo "New client success: got $RESULT"
1012         fi
1013
1014         # make sure it reactivates
1015         set_and_check "cat $PROC_ACT" "$PARAM" $ACTV || return 6
1016
1017         umount_client $MOUNT
1018         stop_ost2
1019         cleanup_nocli
1020         #writeconf to remove all ost2 traces for subsequent tests
1021         writeconf
1022 }
1023 run_test 29 "permanently remove an OST"
1024
1025 test_30() {
1026         # start mds first after writeconf
1027         start_mds
1028         start_ost
1029         mount_client $MOUNT
1030         TEST="cat $LPROC/llite/$FSNAME-*/max_read_ahead_whole_mb"
1031         ORIG=$($TEST) 
1032         for i in $(seq 1 20); do 
1033             set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1034         done
1035         # make sure client restart still works 
1036         umount_client $MOUNT
1037         mount_client $MOUNT || return 4
1038         [ "$($TEST)" -ne "$i" ] && return 5   
1039         set_and_check "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $ORIG || return 6
1040         cleanup
1041 }
1042 run_test 30 "Big config llog"
1043
1044 test_31() { # bug 10734
1045         # ipaddr must not exist
1046         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1047         cleanup
1048 }
1049 run_test 31 "Connect to non-existent node (shouldn't crash)"
1050
1051 test_32a() {
1052         [ -z "$TUNEFS" ] && echo "No tunefs" && return
1053         [ ! -r disk1_4.zip ] && echo "Cant find disk1_4.zip, skipping" && return
1054         unzip -o -j -d $TMP/$tdir disk1_4.zip || { echo "Cant unzip disk1_4, skipping" && return ; }
1055         load_modules
1056         sysctl lnet.debug=$PTLDEBUG
1057
1058         $TUNEFS $TMP/$tdir/mds || error "tunefs failed"
1059         # nids are wrong, so client wont work, but server should start
1060         start mds $TMP/$tdir/mds "-o loop,exclude=lustre-OST0000" || return 3
1061         local UUID=$(cat $LPROC/mds/lustre-MDT0000/uuid)
1062         echo MDS uuid $UUID
1063         [ "$UUID" == "mdsA_UUID" ] || error "UUID is wrong: $UUID" 
1064
1065         $TUNEFS --mgsnode=`hostname` $TMP/$tdir/ost1 || error "tunefs failed"
1066         start ost1 $TMP/$tdir/ost1 "-o loop" || return 5
1067         UUID=$(cat $LPROC/obdfilter/lustre-OST0000/uuid)
1068         echo OST uuid $UUID
1069         [ "$UUID" == "ost1_UUID" ] || error "UUID is wrong: $UUID" 
1070
1071         local NID=$($LCTL list_nids | head -1)
1072
1073         echo "OSC changes should return err:" 
1074         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 && return 7
1075         $LCTL conf_param lustre-OST0000.failover.node=$NID && return 8
1076         echo "ok."
1077         echo "MDC changes should succeed:" 
1078         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1079         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1080         echo "ok."
1081
1082         # With a new good MDT failover nid, we should be able to mount a client
1083         # (but it cant talk to OST)
1084         local OLDMOUNTOPT=$MOUNTOPT
1085         MOUNTOPT="exclude=lustre-OST0000"
1086         mount_client $MOUNT
1087         MOUNTOPT=$OLDMOUNTOPT
1088         set_and_check "cat $LPROC/mdc/*/max_rpcs_in_flight" "lustre-MDT0000.mdc.max_rpcs_in_flight" || return 11
1089
1090         zconf_umount `hostname` $MOUNT -f
1091         cleanup_nocli
1092
1093         # mount a second time to make sure we didnt leave upgrade flag on
1094         $TUNEFS --dryrun $TMP/$tdir/mds || error "tunefs failed"
1095         start mds $TMP/$tdir/mds "-o loop,exclude=lustre-OST0000" || return 12
1096         cleanup_nocli
1097
1098         [ -d $TMP/$tdir ] && rm -rf $TMP/$tdir
1099 }
1100 run_test 32a "Upgrade from 1.4 (not live)"
1101
1102 test_32b() {
1103         [ -z "$TUNEFS" ] && echo "No tunefs" && return
1104         [ ! -r disk1_4.zip ] && echo "Cant find disk1_4.zip, skipping" && return
1105         unzip -o -j -d $TMP/$tdir disk1_4.zip || { echo "Cant unzip disk1_4, skipping" && return ; }
1106         load_modules
1107         sysctl lnet.debug=$PTLDEBUG
1108
1109         # writeconf will cause servers to register with their current nids
1110         $TUNEFS --writeconf $TMP/$tdir/mds || error "tunefs failed"
1111         start mds $TMP/$tdir/mds "-o loop" || return 3
1112         local UUID=$(cat $LPROC/mds/lustre-MDT0000/uuid)
1113         echo MDS uuid $UUID
1114         [ "$UUID" == "mdsA_UUID" ] || error "UUID is wrong: $UUID" 
1115
1116         $TUNEFS --mgsnode=`hostname` $TMP/$tdir/ost1 || error "tunefs failed"
1117         start ost1 $TMP/$tdir/ost1 "-o loop" || return 5
1118         UUID=$(cat $LPROC/obdfilter/lustre-OST0000/uuid)
1119         echo OST uuid $UUID
1120         [ "$UUID" == "ost1_UUID" ] || error "UUID is wrong: $UUID" 
1121
1122         echo "OSC changes should succeed:" 
1123         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || return 7
1124         $LCTL conf_param lustre-OST0000.failover.node=$NID || return 8
1125         echo "ok."
1126         echo "MDC changes should succeed:" 
1127         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1128         echo "ok."
1129
1130         # MDT and OST should have registered with new nids, so we should have
1131         # a fully-functioning client
1132         echo "Check client and old fs contents"
1133         mount_client $MOUNT
1134         set_and_check "cat $LPROC/mdc/*/max_rpcs_in_flight" "lustre-MDT0000.mdc.max_rpcs_in_flight" || return 11
1135         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "2479747619 779" ] || return 12  
1136         echo "ok."
1137
1138         cleanup
1139         [ -d $TMP/$tdir ] && rm -rf $TMP/$tdir
1140 }
1141 run_test 32b "Upgrade from 1.4 with writeconf"
1142
1143 umount_client $MOUNT    
1144 cleanup_nocli
1145
1146 equals_msg "Done"
1147 echo "$0: completed"