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