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