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