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