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