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