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