Whamcloud - gitweb
b=21846 fix the test_32 in sanity-quota.sh and enable it
[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 # bug number for skipped test:      13369
15 ALWAYS_EXCEPT=" $CONF_SANITY_EXCEPT 34a"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 SRCDIR=`dirname $0`
19 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
20
21 SAVE_PWD=$PWD
22 LUSTRE=${LUSTRE:-`dirname $0`/..}
23 RLUSTRE=${RLUSTRE:-$LUSTRE}
24 HOSTNAME=`hostname`
25
26 . $LUSTRE/tests/test-framework.sh
27 init_test_env $@
28 # STORED_MDSSIZE is used in test_18
29 if [ -n "$MDSSIZE" ]; then
30     STORED_MDSSIZE=$MDSSIZE
31 fi
32 # use small MDS + OST size to speed formatting time
33 MDSSIZE=40000
34 OSTSIZE=40000
35 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
36
37 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
38 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
39
40 #
41 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30 31 45"
42
43 assert_DIR
44
45 reformat() {
46         formatall
47 }
48
49 writeconf1() {
50         local facet=$1
51         local dev=$2
52
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 $dev" ||
57                 { echo "tunefs failed, reformatting instead" && reformat_and_config && return 1; }
58         return 0
59 }
60
61 writeconf() {
62         # if writeconf failed, we reformatted
63         writeconf1 mds $MDSDEV || return 0
64         writeconf1 ost1 `ostdevname 1` || return 0
65         writeconf1 ost2 `ostdevname 2` || return 0
66 }
67
68 gen_config() {
69         # The MGS must be started before the OSTs for a new fs, so start
70         # and stop to generate the startup logs.
71         start_mds
72         start_ost
73         wait_osc_import_state mds ost FULL
74         stop_ost
75         stop_mds
76 }
77
78 reformat_and_config() {
79         reformat
80         if ! combined_mgs_mds ; then
81                 start_mgs
82         fi
83         gen_config
84 }
85
86 start_mgs () {
87         echo "start mgs"
88         start mgs $MGSDEV $mgs_MOUNT_OPTS
89 }
90
91 start_mds() {
92         echo "start mds service on `facet_active_host mds`"
93         start mds $MDSDEV $MDS_MOUNT_OPTS || return 94
94 }
95
96 stop_mgs() {
97         echo "stop mgs service on `facet_active_host mgs`"
98         # These tests all use non-failover stop
99         stop mgs -f  || return 97
100 }
101
102 stop_mds() {
103         echo "stop mds service on `facet_active_host mds`"
104         # These tests all use non-failover stop
105         stop mds -f  || return 97
106 }
107
108 start_ost() {
109         echo "start ost1 service on `facet_active_host ost1`"
110         start ost1 `ostdevname 1` $OST_MOUNT_OPTS || return 95
111 }
112
113 stop_ost() {
114         echo "stop ost1 service on `facet_active_host ost1`"
115         # These tests all use non-failover stop
116         stop ost1 -f  || return 98
117 }
118
119 start_ost2() {
120         echo "start ost2 service on `facet_active_host ost2`"
121         start ost2 `ostdevname 2` $OST_MOUNT_OPTS || return 92
122 }
123
124 stop_ost2() {
125         echo "stop ost2 service on `facet_active_host ost2`"
126         # These tests all use non-failover stop
127         stop ost2 -f  || return 93
128 }
129
130 start_client() {
131         echo "start client on `facet_active_host client`"
132         start client || return 99
133 }
134
135 stop_client() {
136         echo "stop client on `facet_active_host client`"
137         stop client || return 100
138 }
139
140 mount_client() {
141         local MOUNTPATH=$1
142         echo "mount $FSNAME on ${MOUNTPATH}....."
143         zconf_mount `hostname` $MOUNTPATH  || return 96
144 }
145
146 remount_client() {
147         local SAVEMOUNTOPT=$MOUNTOPT
148         MOUNTOPT="remount,$1"
149         local MOUNTPATH=$2
150         echo "remount '$1' lustre on ${MOUNTPATH}....."
151         zconf_mount `hostname`  $MOUNTPATH  || return 96
152         MOUNTOPT=$SAVEMOUNTOPT
153 }
154
155 umount_client() {
156         local MOUNTPATH=$1
157         echo "umount lustre on ${MOUNTPATH}....."
158         zconf_umount `hostname` $MOUNTPATH || return 97
159 }
160
161 manual_umount_client(){
162         local rc
163         local FORCE=$1
164         echo "manual umount lustre on ${MOUNT}...."
165         do_facet client "umount -d ${FORCE} $MOUNT"
166         rc=$?
167         return $rc
168 }
169
170 setup() {
171         start_mds || error "MDT start failed"
172         start_ost || error "OST start failed"
173         mount_client $MOUNT || error "client start failed"
174         df $MOUNT
175 }
176
177 setup_noconfig() {
178         if ! combined_mgs_mds ; then
179                 start_mgs
180         fi
181
182         start_mds
183         start_ost
184         mount_client $MOUNT
185 }
186
187 cleanup_nocli() {
188         stop_mds || return 201
189         stop_ost || return 202
190         unload_modules || return 203
191 }
192
193 cleanup() {
194         umount_client $MOUNT || return 200
195         cleanup_nocli || return $?
196 }
197
198 check_mount() {
199         do_facet client "cp /etc/passwd $DIR/a" || return 71
200         do_facet client "rm $DIR/a" || return 72
201         # make sure lustre is actually mounted (touch will block,
202         # but grep won't, so do it after)
203         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
204         echo "setup single mount lustre success"
205 }
206
207 check_mount2() {
208         do_facet client "touch $DIR/a" || return 71
209         do_facet client "rm $DIR/a" || return 72
210         do_facet client "touch $DIR2/a" || return 73
211         do_facet client "rm $DIR2/a" || return 74
212         echo "setup double mount lustre success"
213 }
214
215 build_test_filter
216
217 if [ "$ONLY" == "setup" ]; then
218         setup
219         exit
220 fi
221
222 if [ "$ONLY" == "cleanup" ]; then
223         cleanup
224         exit
225 fi
226
227 #create single point mountpoint
228
229 reformat_and_config
230
231 test_0() {
232         setup
233         check_mount || return 41
234         cleanup || return $?
235 }
236 run_test 0 "single mount setup"
237
238 test_1() {
239         start_ost
240         echo "start ost second time..."
241         start_ost && error "2nd OST start should fail"
242         start_mds || error "MDT start failed"
243         mount_client $MOUNT || error "client start failed"
244         check_mount || return 42
245         cleanup || return $?
246 }
247 run_test 1 "start up ost twice (should return errors)"
248
249 test_2() {
250         start_ost
251         start_mds
252         echo "start mds second time.."
253         start_mds && error "2nd MDT start should fail"
254         mount_client $MOUNT
255         check_mount || return 43
256         cleanup || return $?
257 }
258 run_test 2 "start up mds twice (should return err)"
259
260 test_3() {
261         setup
262         #mount.lustre returns an error if already in mtab
263         mount_client $MOUNT && error "2nd client mount should fail"
264         check_mount || return 44
265         cleanup || return $?
266 }
267 run_test 3 "mount client twice (should return err)"
268
269 test_4() {
270         setup
271         touch $DIR/$tfile || return 85
272         stop_ost -f
273         cleanup
274         eno=$?
275         # ok for ost to fail shutdown
276         if [ 202 -ne $eno ]; then
277                 return $eno;
278         fi
279         return 0
280 }
281 run_test 4 "force cleanup ost, then cleanup"
282
283 test_5a() {     # was test_5
284         setup
285         touch $DIR/$tfile || return 1
286         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
287
288         stop_mds -f || return 2
289
290         # cleanup may return an error from the failed
291         # disconnects; for now I'll consider this successful
292         # if all the modules have unloaded.
293         umount -d $MOUNT &
294         UMOUNT_PID=$!
295         sleep 6
296         echo "killing umount"
297         kill -TERM $UMOUNT_PID
298         echo "waiting for umount to finish"
299         wait $UMOUNT_PID
300         if grep " $MOUNT " /proc/mounts; then
301                 echo "test 5: /proc/mounts after failed umount"
302                 umount $MOUNT &
303                 UMOUNT_PID=$!
304                 sleep 2
305                 echo "killing umount"
306                 kill -TERM $UMOUNT_PID
307                 echo "waiting for umount to finish"
308                 wait $UMOUNT_PID
309                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
310         fi
311
312         manual_umount_client
313         # stop_mds is a no-op here, and should not fail
314         cleanup_nocli || return $?
315         # df may have lingering entry
316         manual_umount_client
317         # mtab may have lingering entry
318         local WAIT=0
319         local MAX_WAIT=20
320         local sleep=1
321         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
322                 sleep $sleep
323                 grep -q $MOUNT" " /etc/mtab || break
324                 echo "Waiting /etc/mtab updated ... "
325                 WAIT=$(( WAIT + sleep))
326         done
327         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
328         echo "/etc/mtab updated in $WAIT secs"
329 }
330 run_test 5a "force cleanup mds, then cleanup"
331
332 cleanup_5b () {
333         trap 0
334         start_mgs
335 }
336
337 test_5b() {
338         grep " $MOUNT " /etc/mtab && \
339                 error false "unexpected entry in mtab before mount" && return 10
340
341         local rc=0
342         start_ost
343         if ! combined_mgs_mds ; then
344                 trap cleanup_5b EXIT ERR
345                 start_mds
346                 stop mgs
347         fi
348
349         [ -d $MOUNT ] || mkdir -p $MOUNT
350         mount_client $MOUNT && rc=1
351         grep " $MOUNT " /etc/mtab && \
352                 error "$MOUNT entry in mtab after failed mount" && rc=11
353         umount_client $MOUNT
354         # stop_mds is a no-op here, and should not fail
355         cleanup_nocli || rc=$?
356         if ! combined_mgs_mds ; then
357                 cleanup_5b
358         fi
359         return $rc
360 }
361 run_test 5b "Try to start a client with no MGS (should return errs)"
362
363 test_5c() {
364         grep " $MOUNT " /etc/mtab && \
365                 error false "unexpected entry in mtab before mount" && return 10
366
367         local rc=0
368         start_ost
369         start_mds
370         [ -d $MOUNT ] || mkdir -p $MOUNT
371         local oldfs="${FSNAME}"
372         FSNAME="wrong.${FSNAME}"
373         mount_client $MOUNT || :
374         FSNAME=${oldfs}
375         grep " $MOUNT " /etc/mtab && \
376                 error "$MOUNT entry in mtab after failed mount" && rc=11
377         umount_client $MOUNT
378         cleanup_nocli  || rc=$?
379         return $rc
380 }
381 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
382
383 test_5d() {
384         grep " $MOUNT " /etc/mtab && \
385                 error false "unexpected entry in mtab before mount" && return 10
386
387         local rc=0
388         start_ost
389         start_mds
390         stop_ost -f
391         mount_client $MOUNT || rc=1
392         cleanup  || rc=$?
393         grep " $MOUNT " /etc/mtab && \
394                 error "$MOUNT entry in mtab after unmount" && rc=11
395         return $rc
396 }
397 run_test 5d "mount with ost down"
398
399 test_5e() {
400         grep " $MOUNT " /etc/mtab && \
401                 error false "unexpected entry in mtab before mount" && return 10
402
403         local rc=0
404         start_ost
405         start_mds
406
407 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
408         do_facet client "lctl set_param fail_loc=0x80000506"
409         mount_client $MOUNT || echo "mount failed (not fatal)"
410         cleanup  || rc=$?
411         grep " $MOUNT " /etc/mtab && \
412                 error "$MOUNT entry in mtab after unmount" && rc=11
413         return $rc
414 }
415 run_test 5e "delayed connect, don't crash (bug 10268)"
416
417 test_5f() {
418         if combined_mgs_mds ; then
419                 skip "combined mgs and mds"
420                 return 0
421         fi
422
423         grep " $MOUNT " /etc/mtab && \
424                 error false "unexpected entry in mtab before mount" && return 10
425
426         local rc=0
427         start_ost
428         [ -d $MOUNT ] || mkdir -p $MOUNT
429         mount_client $MOUNT &
430         local pid=$!
431         echo client_mount pid is $pid
432
433         sleep 5
434
435         if ! ps -f -p $pid >/dev/null; then 
436                 wait $pid
437                 rc=$?
438                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
439                 error "mount returns $rc, expected to hang"
440                 rc=11
441                 cleanup || rc=$?
442                 return $rc
443         fi
444
445         # start mds
446         start_mds
447
448         # mount should succeed after start mds 
449         wait $pid
450         rc=$?
451         [ $rc -eq 0 ] || error "mount returned $rc"
452         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
453         cleanup || return $?
454         return $rc
455 }
456 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
457
458 test_6() {
459         setup
460         manual_umount_client
461         mount_client ${MOUNT} || return 87
462         touch $DIR/a || return 86
463         cleanup  || return $?
464 }
465 run_test 6 "manual umount, then mount again"
466
467 test_7() {
468         setup
469         manual_umount_client
470         cleanup_nocli || return $?
471 }
472 run_test 7 "manual umount, then cleanup"
473
474 test_8() {
475         setup
476         mount_client $MOUNT2
477         check_mount2 || return 45
478         umount_client $MOUNT2
479         cleanup  || return $?
480 }
481 run_test 8 "double mount setup"
482
483 test_9() {
484         start_ost
485
486         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
487         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
488
489         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
490         # interop 1.8 <-> 2.0: "trace inode warning error emerg console"
491         local lustre_version=$(get_lustre_version ost1)
492         echo ost1 running $lustre_version
493         if [ "$CHECK_PTLDEBUG" ] && [ "$CHECK_PTLDEBUG" = "trace inode" ]; then
494             echo "lnet.debug success"
495         elif [[ $lustre_version != 1.8* ]] && \
496                 [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ]; then
497             echo "lnet.debug success"
498         else
499            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
500            return 1
501         fi
502         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
503         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
504            echo "lnet.subsystem_debug success"
505         else
506            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
507            return 1
508         fi
509         stop_ost || return $?
510 }
511 run_test 9 "test ptldebug and subsystem for mkfs"
512
513 is_blkdev () {
514         local facet=$1
515         local dev=$2
516         local size=${3:-""}
517
518         local rc=0
519         do_facet $facet "test -b $dev" || rc=1
520         if [[ "$size" ]]; then
521                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
522                         awk '($3 == "in") { print $1 }')
523                 [[ $in  = "1+0" ]] || rc=1
524         fi
525         return $rc
526 }
527
528 test_16() {
529         setup
530         # interop 1.8 <-> 2.0: 20: no LOGS
531         local files="{OBJECTS,PENDING}"
532         local lustre_version=$(get_lustre_version mds)
533         if [[ $lustre_version = 1.8* ]]; then
534                 files="{OBJECTS,PENDING,LOGS}"
535         fi
536         
537         check_mount || return 41
538         cleanup || return $?
539
540         local TMPMTPT="${TMP}/conf16"
541
542         is_blkdev mds $MDSDEV || LOOPOPT="-o loop"
543
544         log "change the mode of $MDSDEV/$files to 555"
545         do_facet mds "mkdir -p $TMPMTPT &&
546                       mount $LOOPOPT -t $FSTYPE $MDSDEV $TMPMTPT &&
547                       chmod 555 $TMPMTPT/$files &&
548                       umount $TMPMTPT" || return $?
549
550         log "mount Lustre to change the mode of $files, then umount Lustre"
551         setup
552         check_mount || return 41
553         cleanup || return $?
554
555         log "read the mode of $files and check if they has been changed properly"
556         local file
557         for file in ${files//[\{\},]/ }; do
558             expected=`do_facet mds "$DEBUGFS -R 'stat $file' $MDSDEV 2> /dev/null" | \
559                        grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
560
561             if [ "$expected" = "0777" ]; then
562                 log "Success:Lustre change the mode of $file correctly"
563             else
564                 error "Lustre does not change mode of $file properly"
565             fi
566         done
567 }
568 run_test 16 "verify that lustre will correct the mode of OBJECTS/LOGS/PENDING"
569
570 test_17() {
571         setup
572         check_mount || return 41
573         cleanup || return $?
574
575         echo "Remove mds config log"
576         if ! combined_mgs_mds ; then
577                 stop mgs
578         fi
579
580         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MGSDEV || return \$?" || return $?
581
582         if ! combined_mgs_mds ; then
583                 start_mgs
584         fi
585
586         start_ost
587         start_mds && return 42
588         reformat_and_config
589 }
590 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
591
592 test_18() {
593         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return
594
595         local MIN=2000000
596
597         local OK=
598         # check if current MDSSIZE is large enough
599         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
600                 log "use MDSSIZE=$MDSSIZE"
601
602         # check if the global config has a large enough MDSSIZE
603         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
604                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
605                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
606
607         # check if the block device is large enough
608         [ -z "$OK" ] && $(is_blkdev mds $MDSDEV $MIN) && OK=1 &&
609                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
610
611         # check if a loopback device has enough space for fs metadata (5%)
612
613         if [ -z "$OK" ]; then
614                 local SPACE=$(do_facet mds "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
615                         awk '($1 != "Filesystem") {print $4}')
616                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
617                         OK=1 && myMDSSIZE=$MIN && \
618                         log "use file $MDSDEV with MIN=$MIN"
619         fi
620
621         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
622
623
624         echo "mount mds with large journal..."
625         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
626
627         local opts="--mdt --fsname=$FSNAME --device-size=$myMDSSIZE --param sys.timeout=$TIMEOUT $MDSOPT" 
628
629         if combined_mgs_mds ; then
630             MDS_MKFS_OPTS="--mgs $opts"
631         else
632             MDS_MKFS_OPTS="--mgsnode=$MGSNID $opts"
633         fi
634
635         reformat_and_config
636         echo "mount lustre system..."
637         setup
638         check_mount || return 41
639
640         echo "check journal size..."
641         local FOUNDSIZE=$(do_facet mds "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
642         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
643                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
644         else
645                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
646         fi
647
648         cleanup || return $?
649
650         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
651         reformat_and_config
652 }
653 run_test 18 "check mkfs creates large journals"
654
655 test_19a() {
656         start_mds || return 1
657         stop_mds -f || return 2
658 }
659 run_test 19a "start/stop MDS without OSTs"
660
661 test_19b() {
662         start_ost || return 1
663         stop_ost -f || return 2
664 }
665 run_test 19b "start/stop OSTs without MDS"
666
667 test_20() {
668         # first format the ost/mdt
669         start_ost
670         start_mds
671         mount_client $MOUNT
672         check_mount || return 43
673         rm -f $DIR/$tfile
674         remount_client ro $MOUNT || return 44
675         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
676         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
677         remount_client rw $MOUNT || return 47
678         touch $DIR/$tfile
679         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
680         MCNT=`grep -c $MOUNT /etc/mtab`
681         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
682         umount_client $MOUNT
683         stop_mds
684         stop_ost
685 }
686 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
687
688 test_21a() {
689         start_mds
690         start_ost
691         wait_osc_import_state mds ost FULL
692         stop_ost
693         stop_mds
694 }
695 run_test 21a "start mds before ost, stop ost first"
696
697 test_21b() {
698         start_ost
699         start_mds
700         wait_osc_import_state mds ost FULL
701         stop_mds
702         stop_ost
703 }
704 run_test 21b "start ost before mds, stop mds first"
705
706 test_21c() {
707         start_ost
708         start_mds
709         start_ost2
710         wait_osc_import_state mds ost2 FULL
711
712         stop_ost
713         stop_ost2
714         stop_mds
715         #writeconf to remove all ost2 traces for subsequent tests
716         writeconf
717 }
718 run_test 21c "start mds between two osts, stop mds last"
719
720 test_21d() {
721         if combined_mgs_mds ; then
722                 skip "need separate mgs device" && return 0
723         fi
724         stopall
725
726         reformat
727
728         start_mgs
729         start_ost
730         start_ost2
731         start_mds
732         wait_osc_import_state mds ost2 FULL
733
734         stop_ost
735         stop_ost2
736         stop_mds
737         stop_mgs
738 }
739 run_test 21d "start mgs then ost and then mds"
740
741
742 test_22() {
743         start_mds
744
745         echo Client mount with ost in logs, but none running
746         start_ost
747         wait_osc_import_state mds ost FULL
748         stop_ost
749         mount_client $MOUNT
750         # check_mount will block trying to contact ost
751         mcreate $DIR/$tfile || return 40
752         rm -f $DIR/$tfile || return 42
753         umount_client $MOUNT
754         pass
755
756         echo Client mount with a running ost
757         start_ost
758         mount_client $MOUNT
759         check_mount || return 41
760         pass
761
762         cleanup
763 }
764 run_test 22 "start a client before osts (should return errs)"
765
766 test_23a() {    # was test_23
767         setup
768         # fail mds
769         stop mds
770         # force down client so that recovering mds waits for reconnect
771         local running=$(grep -c $MOUNT /proc/mounts) || true
772         if [ $running -ne 0 ]; then
773                 echo "Stopping client $MOUNT (opts: -f)"
774                 umount -f $MOUNT
775         fi
776
777         # enter recovery on mds
778         start_mds
779         # try to start a new client
780         mount_client $MOUNT &
781         sleep 5
782         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
783         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
784         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
785         ps --ppid $MOUNT_PID
786         ps --ppid $MOUNT_LUSTRE_PID
787         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
788         kill -TERM $MOUNT_LUSTRE_PID
789         echo "waiting for mount to finish"
790         ps -ef | grep mount
791         # we can not wait $MOUNT_PID because it is not a child of this shell
792         local PID1
793         local PID2
794         local WAIT=0
795         local MAX_WAIT=30
796         local sleep=1
797         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
798                 sleep $sleep
799                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
800                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
801                 echo PID1=$PID1
802                 echo PID2=$PID2
803                 [ -z "$PID1" -a -z "$PID2" ] && break
804                 echo "waiting for mount to finish ... "
805                 WAIT=$(( WAIT + sleep))
806         done
807         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
808                 error "MOUNT_PID $MOUNT_PID and \
809                 MOUNT__LUSTRE_PID $MOUNT__LUSTRE_PID still not killed in $WAIT secs"
810                 ps -ef | grep mount
811         fi
812         stop_mds || error
813         stop_ost || error
814 }
815 run_test 23a "interrupt client during recovery mount delay"
816
817 umount_client $MOUNT
818 cleanup_nocli
819
820 test_23b() {    # was test_23
821         start_ost
822         start_mds
823         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
824         lctl set_param fail_loc=0x80000313
825         mount_client $MOUNT
826         cleanup
827 }
828 run_test 23b "Simulate -EINTR during mount"
829
830 fs2mds_HOST=$mds_HOST
831 fs2ost_HOST=$ost_HOST
832
833 cleanup_24a() {
834         trap 0
835         echo "umount $MOUNT2 ..."
836         umount $MOUNT2 || true
837         echo "stopping fs2mds ..."
838         stop fs2mds -f || true
839         echo "stopping fs2ost ..."
840         stop fs2ost -f || true
841 }
842
843 test_24a() {
844         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
845                 is_blkdev mds $MDSDEV && \
846                 skip_env "mixed loopback and real device not working" && return
847         fi
848
849         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
850         
851         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
852         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
853
854         # test 8-char fsname as well
855         local FSNAME2=test1234
856         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat $fs2mdsdev || exit 10
857
858         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
859
860         setup
861         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
862         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
863         mkdir -p $MOUNT2
864         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
865         # 1 still works
866         check_mount || return 2
867         # files written on 1 should not show up on 2
868         cp /etc/passwd $DIR/$tfile
869         sleep 10
870         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
871         # 2 should work
872         cp /etc/passwd $MOUNT2/b || return 3
873         rm $MOUNT2/b || return 4
874         # 2 is actually mounted
875         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
876         # failover
877         facet_failover fs2mds
878         facet_failover fs2ost
879         df
880         umount_client $MOUNT
881         # the MDS must remain up until last MDT
882         stop_mds
883
884         local mdt_obdname=$(do_facet mds "lctl get_param -n devices" | \
885         awk '/ mdt / { print $4 }' | head -1)
886         [ -z "$mdt_obdname" ] && error "No MDT" && return 8
887         
888         cleanup_24a
889         cleanup_nocli || return 6
890 }
891 run_test 24a "Multiple MDTs on a single node"
892
893 test_24b() {
894         if [ -z "$fs2mds_DEV" ]; then
895                 is_blkdev mds $MDSDEV && \
896                 skip_env "mixed loopback and real device not working" && return
897         fi
898
899         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
900
901         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat $fs2mdsdev || exit 10
902         setup
903         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
904         cleanup || return 6
905 }
906 run_test 24b "Multiple MGSs on a single node (should return err)"
907
908 test_25() {
909         setup
910         check_mount || return 2
911         local MODULES=$($LCTL modules | awk '{ print $2 }')
912         rmmod $MODULES 2>/dev/null || true
913         cleanup || return 6
914 }
915 run_test 25 "Verify modules are referenced"
916
917 test_26() {
918     load_modules
919     # we need modules before mount for sysctl, so make sure...
920     do_facet mds "lsmod | grep -q lustre || modprobe lustre"
921 #define OBD_FAIL_MDS_FS_SETUP            0x135
922     do_facet mds "lctl set_param fail_loc=0x80000135"
923     start_mds && echo MDS started && return 1
924     lctl get_param -n devices
925     DEVS=$(lctl get_param -n devices | wc -l)
926     [ $DEVS -gt 0 ] && return 2
927     unload_modules || return 203
928 }
929 run_test 26 "MDT startup failure cleans LOV (should return errs)"
930
931 set_and_check() {
932         local myfacet=$1
933         local TEST=$2
934         local PARAM=$3
935         local ORIG=$(do_facet $myfacet "$TEST")
936         if [ $# -gt 3 ]; then
937             local FINAL=$4
938         else
939             local -i FINAL
940             FINAL=$(($ORIG + 5))
941         fi
942         echo "Setting $PARAM from $ORIG to $FINAL"
943         do_facet mds "$LCTL conf_param $PARAM=$FINAL" || error conf_param failed
944
945         wait_update $(facet_host $myfacet) "$TEST" $FINAL || error check failed!
946 }
947
948 test_27a() {
949         start_ost || return 1
950         start_mds || return 2
951         echo "Requeue thread should have started: "
952         ps -e | grep ll_cfg_requeue
953         set_and_check ost1 "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
954         cleanup_nocli
955 }
956 run_test 27a "Reacquire MGS lock if OST started first"
957
958 test_27b() {
959         setup
960
961         # interop 1.8 <-> 2.0:
962         # 1.8: group_acquire_expire, 2.0: identity_acquire_expire 
963         local acquire_expire=$(do_facet mds lctl get_param md*.$FSNAME-MDT0000.*acquire_expire | \
964                 cut -d= -f1 | cut -d. -f3)
965         facet_failover mds
966         set_and_check mds "lctl get_param -n md*.$FSNAME-MDT0000.$acquire_expire" \
967                 "$FSNAME-MDT0000.mdt.$acquire_expire" || return 3
968         set_and_check client "lctl get_param -n mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight" \
969                 "$FSNAME-MDT0000.mdc.max_rpcs_in_flight" || return 4
970         check_mount
971         cleanup
972 }
973 run_test 27b "Reacquire MGS lock after failover"
974
975 test_28() {
976         setup
977         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
978         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
979         ORIG=$($TEST)
980         FINAL=$(($ORIG + 1))
981         set_and_check client "$TEST" "$PARAM" $FINAL || return 3
982         FINAL=$(($FINAL + 1))
983         set_and_check client "$TEST" "$PARAM" $FINAL || return 4
984         umount_client $MOUNT || return 200
985         mount_client $MOUNT
986         RESULT=$($TEST)
987         if [ $RESULT -ne $FINAL ]; then
988             echo "New config not seen: wanted $FINAL got $RESULT"
989             return 4
990         else
991             echo "New config success: got $RESULT"
992         fi
993         set_and_check client "$TEST" "$PARAM" $ORIG || return 5
994         cleanup
995 }
996 run_test 28 "permanent parameter setting"
997
998 test_29() {
999         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1000         setup > /dev/null 2>&1
1001         start_ost2
1002         sleep 10
1003
1004         local PARAM="$FSNAME-OST0001.osc.active"
1005         local PROC_ACT="osc.$FSNAME-OST0001-osc-*.active"
1006         local PROC_UUID="osc.$FSNAME-OST0001-osc-*.ost_server_uuid"
1007
1008         ACTV=$(lctl get_param -n $PROC_ACT)
1009         DEAC=$((1 - $ACTV))
1010         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1011         # also check ost_server_uuid status
1012         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1013         if [ -z "$RESULT" ]; then
1014             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1015             return 3
1016         else
1017             echo "Live client success: got $RESULT"
1018         fi
1019
1020         # check MDT too
1021         local MPROC="osc.$(get_mdtosc_proc_path $FSNAME-OST0001).active"
1022         local MAX=30
1023         local WAIT=0
1024         while [ 1 ]; do
1025             sleep 5
1026             RESULT=`do_facet mds " lctl get_param -n $MPROC"`
1027             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1028             if [ $RESULT -eq $DEAC ]; then
1029                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
1030                 break
1031             fi
1032             WAIT=$((WAIT + 5))
1033             if [ $WAIT -eq $MAX ]; then
1034                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
1035                 return 4
1036             fi
1037             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
1038         done
1039
1040         # test new client starts deactivated
1041         umount_client $MOUNT || return 200
1042         mount_client $MOUNT
1043         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1044         if [ -z "$RESULT" ]; then
1045             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1046             return 5
1047         else
1048             echo "New client success: got $RESULT"
1049         fi
1050
1051         # make sure it reactivates
1052         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1053
1054         umount_client $MOUNT
1055         stop_ost2
1056         cleanup_nocli
1057         #writeconf to remove all ost2 traces for subsequent tests
1058         writeconf
1059 }
1060 run_test 29 "permanently remove an OST"
1061
1062 test_30a() {
1063         setup
1064
1065         echo Big config llog
1066         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1067         ORIG=$($TEST)
1068         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1069         for i in ${LIST[@]}; do
1070             set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1071         done
1072         # make sure client restart still works
1073         umount_client $MOUNT
1074         mount_client $MOUNT || return 4
1075         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1076         pass
1077
1078         echo Erase parameter setting
1079         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1080         umount_client $MOUNT
1081         mount_client $MOUNT || return 6
1082         FINAL=$($TEST)
1083         echo "deleted (default) value=$FINAL, orig=$ORIG"
1084         # assumes this parameter started at the default value
1085         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1086
1087         cleanup
1088 }
1089 run_test 30a "Big config llog and conf_param deletion"
1090
1091 test_30b() {
1092         setup
1093
1094         NEW="1.2.3.4@tcp"
1095         TEST="lctl get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1096         set_and_check client "$TEST" "$FSNAME-OST0000.failover.node" $NEW || error "didn't add failover nid $NEW"
1097         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1098         echo $NIDS
1099         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1100         echo "should have 2 failover nids: $NIDCOUNT"
1101         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1102         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1103         umount_client $MOUNT
1104         mount_client $MOUNT || return 3
1105
1106         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1107         echo $NIDS
1108         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1109         echo "only 1 final nid should remain: $NIDCOUNT"
1110         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1111
1112         cleanup
1113 }
1114 run_test 30b "Remove failover nids"
1115
1116 test_31() { # bug 10734
1117         # ipaddr must not exist
1118         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1119         cleanup
1120 }
1121 run_test 31 "Connect to non-existent node (returns errors, should not crash)"
1122
1123 # Use these start32/stop32 fn instead of t-f start/stop fn,
1124 # for local devices, to skip global facet vars init
1125 stop32 () {
1126         local facet=$1
1127         shift
1128         echo "Stopping local ${MOUNT%/*}/${facet} (opts:$@)"
1129         umount -d $@ ${MOUNT%/*}/${facet}
1130         losetup -a
1131 }
1132
1133 start32 () {
1134         local facet=$1
1135         shift
1136         local device=$1
1137         shift
1138         mkdir -p ${MOUNT%/*}/${facet}
1139
1140         echo "Starting local ${facet}: $@ $device ${MOUNT%/*}/${facet}"
1141         mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
1142         RC=$?
1143         if [ $RC -ne 0 ]; then
1144                 echo "mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}"
1145                 echo "Start of ${device} of local ${facet} failed ${RC}"
1146         fi
1147         losetup -a
1148         return $RC
1149 }
1150
1151 cleanup_nocli32 () {
1152         stop32 mds -f
1153         stop32 ost1 -f
1154         wait_exit_ST client
1155 }
1156
1157 cleanup_32() {
1158         trap 0
1159         echo "Cleanup test_32 umount $MOUNT ..."
1160         umount -f $MOUNT || true
1161         echo "Cleanup local mds ost1 ..."
1162         cleanup_nocli32
1163         unload_modules
1164 }
1165
1166 test_32a() {
1167         # this test is totally useless on a client-only system
1168         client_only && skip "client only testing" && return 0
1169         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1170         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return 0
1171
1172         local DISK1_6=$LUSTRE/tests/disk1_6.tar.bz2
1173         [ ! -r $DISK1_6 ] && skip_env "Cant find $DISK1_6, skipping" && return
1174
1175         local tmpdir=$TMP/conf32a
1176         mkdir -p $tmpdir
1177
1178         tar xjvf $DISK1_6 -C $tmpdir ||
1179                 { skip_env "Cant untar $DISK1_6, skipping" && return ; }
1180         load_modules
1181         lctl set_param debug=$PTLDEBUG
1182
1183         $TUNEFS $tmpdir/mds || error "tunefs failed"
1184
1185         # nids are wrong, so client wont work, but server should start
1186         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1187                 trap cleanup_32 EXIT INT || return 3
1188
1189         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
1190         echo MDS uuid $UUID
1191         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1192
1193         $TUNEFS --mgsnode=`hostname` $tmpdir/ost1 || error "tunefs failed"
1194         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1195         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1196         echo OST uuid $UUID
1197         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1198
1199         local NID=$($LCTL list_nids | head -1)
1200
1201         echo "OSC changes should succeed:"
1202         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || return 7
1203         $LCTL conf_param lustre-OST0000.failover.node=$NID || return 8
1204         echo "ok."
1205         echo "MDC changes should succeed:"
1206         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1207         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1208         echo "ok."
1209
1210         cleanup_32
1211
1212         # mount a second time to make sure we didnt leave upgrade flag on
1213         load_modules
1214         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1215         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1216                 trap cleanup_32 EXIT INT || return 12
1217
1218         cleanup_32
1219
1220         rm -rf $tmpdir || true  # true is only for TMP on NFS
1221 }
1222 run_test 32a "Upgrade from 1.6 (not live)"
1223
1224 test_32b() {
1225         # this test is totally useless on a client-only system
1226         client_only && skip "client only testing" && return 0
1227         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1228         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return
1229
1230         local DISK1_6=$LUSTRE/tests/disk1_6.tar.bz2
1231         [ ! -r $DISK1_6 ] && skip_env "Cant find $DISK1_6, skipping" && return
1232
1233         local tmpdir=$TMP/conf32b
1234         mkdir -p $tmpdir
1235
1236         tar xjvf $DISK1_6 -C $tmpdir ||
1237                 { skip_env "Cant untar $DISK1_6, skipping" && return ; }
1238
1239         load_modules
1240         lctl set_param debug=$PTLDEBUG
1241
1242         # Ugrade process in according to comment 2 bug 20246
1243         # writeconf will cause servers to register with their current nids
1244         $TUNEFS --mdt --writeconf --erase-param \
1245                 --param="mdt.group_upcall=/usr/sbin/l_getgroups" $tmpdir/mds || \
1246                 error "tunefs mds failed"
1247
1248         start32 mds $tmpdir/mds "-o loop,abort_recov" && \
1249                 trap cleanup_32 EXIT INT || return 3
1250
1251         stop32 mds
1252         start32 mds "-o loop" $tmpdir/mds || return 4
1253         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
1254         echo MDS uuid $UUID
1255         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1256
1257         $TUNEFS --ost --writeconf  --erase-param --mgsnode=`hostname`@$NETTYPE $tmpdir/ost1 || \
1258                 error "tunefs ost failed"
1259         start32 ost1 $tmpdir/ost1 "-o loop,abort_recov" || return 5
1260
1261         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1262         echo OST uuid $UUID
1263         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1264
1265         local NID=$($LCTL list_nids | head -1)
1266
1267         echo "OSC changes should succeed:"
1268         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || error "OSC conf_param failed"
1269         $LCTL conf_param lustre-OST0000.failover.node=$NID || error "add failover nid=$NID failed"
1270         echo "ok."
1271         echo "MDC changes should succeed:"
1272         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1273         echo "ok."
1274
1275         # MDT and OST should have registered with new nids, so we should have
1276         # a fully-functioning client
1277         echo "Check client and old fs contents"
1278
1279         local device=`h2$NETTYPE $HOSTNAME`:/lustre
1280         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1281         mount -t lustre $device $MOUNT || return 1
1282
1283         local old=$(lctl get_param -n mdc.*.max_rpcs_in_flight)
1284         local new=$((old + 5))
1285         lctl conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=$new
1286         wait_update $HOSTNAME "lctl get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1287
1288         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "2940530074 2837" ] || return 12
1289         echo "ok."
1290
1291         cleanup_32
1292
1293         rm -rf $tmpdir || true  # true is only for TMP on NFS
1294 }
1295 run_test 32b "Upgrade from 1.6 with writeconf"
1296
1297 test_33a() { # bug 12333, was test_33
1298         local rc=0
1299         local FSNAME2=test-123
1300         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1301
1302         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1303                 is_blkdev mds $MDSDEV && \
1304                 skip_env "mixed loopback and real device not working" && return
1305         fi
1306
1307         # interop 1.8 <-> 2.0
1308         local mkfs_opts
1309         local major=$(get_mds_version_major)
1310         local minor=$(get_mds_version_minor)
1311         if [ $major -le 1 -a $minor -le 8 ]; then
1312                 mkfs_opts=""
1313         else
1314                 mkfs_opts="--mkfsoptions='-J size=8'" # bug 17931
1315         fi
1316
1317         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1318         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1319         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} $mkfs_opts --reformat $fs2mdsdev || exit 10
1320         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1321
1322         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1323         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1324         do_facet mds "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1325         mkdir -p $MOUNT2
1326         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1327         cp /etc/hosts $MOUNT2/. || rc=3
1328         echo "ok."
1329
1330         cp /etc/hosts $MOUNT2/ || rc=3
1331         $LFS getstripe $MOUNT2/hosts
1332
1333         umount -d $MOUNT2
1334         stop fs2ost -f
1335         stop fs2mds -f
1336         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1337         cleanup_nocli || rc=6
1338         return $rc
1339 }
1340 run_test 33a "Mount ost with a large index number"
1341
1342 test_33b() {    # was test_33a
1343         setup
1344
1345         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1346         # Drop lock cancelation reply during umount
1347         #define OBD_FAIL_LDLM_CANCEL             0x304
1348         do_facet client lctl set_param fail_loc=0x80000304
1349         #lctl set_param debug=-1
1350         umount_client $MOUNT
1351         cleanup
1352 }
1353 run_test 33b "Drop cancel during umount"
1354
1355 test_34a() {
1356         setup
1357         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1358         manual_umount_client
1359         rc=$?
1360         do_facet client killall -USR1 multiop
1361         if [ $rc -eq 0 ]; then
1362                 error "umount not fail!"
1363         fi
1364         sleep 1
1365         cleanup
1366 }
1367 run_test 34a "umount with opened file should be fail"
1368
1369
1370 test_34b() {
1371         setup
1372         touch $DIR/$tfile || return 1
1373         stop_mds --force || return 2
1374
1375         manual_umount_client --force
1376         rc=$?
1377         if [ $rc -ne 0 ]; then
1378                 error "mtab after failed umount - rc $rc"
1379         fi
1380
1381         cleanup
1382         return 0
1383 }
1384 run_test 34b "force umount with failed mds should be normal"
1385
1386 test_34c() {
1387         setup
1388         touch $DIR/$tfile || return 1
1389         stop_ost --force || return 2
1390
1391         manual_umount_client --force
1392         rc=$?
1393         if [ $rc -ne 0 ]; then
1394                 error "mtab after failed umount - rc $rc"
1395         fi
1396
1397         cleanup
1398         return 0
1399 }
1400 run_test 34c "force umount with failed ost should be normal"
1401
1402 test_35a() { # bug 12459
1403         setup
1404
1405         debugsave
1406         lctl set_param debug="ha"
1407
1408         log "Set up a fake failnode for the MDS"
1409         FAKENID="127.0.0.2"
1410         do_facet mds $LCTL conf_param ${FSNAME}-MDT0000.failover.node=$FAKENID || return 4
1411
1412         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1413         sleep 10
1414
1415         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1416         $LCTL clear
1417         log "$MSG"
1418         log "Stopping the MDT:"
1419         stop_mds || return 5
1420
1421         df $MOUNT > /dev/null 2>&1 &
1422         DFPID=$!
1423         log "Restarting the MDT:"
1424         start_mds || return 6
1425         log "Wait for df ($DFPID) ... "
1426         wait $DFPID
1427         log "done"
1428         debugrestore
1429
1430         # retrieve from the log the first server that the client tried to
1431         # contact after the connection loss
1432         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1433         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1434                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1435                                 if (start) {
1436                                         if (\\\$NF ~ /$FAKENID/)
1437                                                 print \\\$NF;
1438                                         else
1439                                                 print 0;
1440                                         exit;
1441                                 }
1442                        }" $TMP/lustre-log-$TESTNAME.log`
1443         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1444         cleanup
1445         # remove nid settings
1446         writeconf
1447 }
1448 run_test 35a "Reconnect to the last active server first"
1449
1450 test_35b() { # bug 18674
1451         remote_mds || { skip "local MDS" && return 0; }
1452         setup
1453
1454         debugsave
1455         $LCTL set_param debug="ha"
1456         $LCTL clear
1457         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1458         log "$MSG"
1459
1460         log "Set up a fake failnode for the MDS"
1461         FAKENID="127.0.0.2"
1462         do_facet mds $LCTL conf_param ${FSNAME}-MDT0000.failover.node=$FAKENID || \
1463                 return 1
1464
1465         local at_max_saved=0
1466         # adaptive timeouts may prevent seeing the issue 
1467         if at_is_enabled; then
1468                 at_max_saved=$(at_max_get mds)
1469                 at_max_set 0 mds client
1470         fi
1471
1472         mkdir -p $MOUNT/$tdir
1473
1474         log "Injecting EBUSY on MDS"
1475         # Setting OBD_FAIL_MDS_RESEND=0x136
1476         do_facet mds "$LCTL set_param fail_loc=0x80000136" || return 2
1477
1478         $LCTL set_param mdc.${FSNAME}*.stats=clear
1479
1480         log "Creating a test file and stat it"
1481         touch $MOUNT/$tdir/$tfile
1482         stat $MOUNT/$tdir/$tfile
1483
1484         log "Stop injecting EBUSY on MDS"
1485         do_facet mds "$LCTL set_param fail_loc=0" || return 3
1486         rm -f $MOUNT/$tdir/$tfile
1487
1488         log "done"
1489         # restore adaptive timeout
1490         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1491
1492         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1493
1494         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1495
1496         # retrieve from the log if the client has ever tried to
1497         # contact the fake server after the loss of connection
1498         FAILCONN=`awk "BEGIN {ret = 0;}
1499                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1500                                 ret = 1;
1501                                 if (\\\$NF ~ /$FAKENID/) {
1502                                         ret = 2;
1503                                         exit;
1504                                 }
1505                        }
1506                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1507
1508         [ "$FAILCONN" == "0" ] && \
1509                 log "ERROR: The client reconnection has not been triggered" && \
1510                 return 4
1511         [ "$FAILCONN" == "2" ] && \
1512                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1513                 return 5
1514
1515         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1516         # Reconnects are supposed to be rate limited to one every 5s
1517         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1518                 log "ERROR: Too many reconnects $CONNCNT" && \
1519                 return 6
1520
1521         cleanup
1522         # remove nid settings
1523         writeconf
1524 }
1525 run_test 35b "Continue reconnection retries, if the active server is busy"
1526
1527 test_36() { # 12743
1528         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1529
1530         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1531                 { skip "remote OST" && return 0; }
1532
1533         local rc=0
1534         local FSNAME2=test1234
1535         local fs3ost_HOST=$ost_HOST
1536
1537         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1538
1539         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1540                 is_blkdev mds $MDSDEV && \
1541                 skip_env "mixed loopback and real device not working" && return
1542         fi
1543
1544         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1545         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1546         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1547         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1548         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1549         # other argument
1550         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1551         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1552
1553         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1554         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1555         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1556         mkdir -p $MOUNT2
1557         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1558
1559         sleep 5 # until 11778 fixed
1560
1561         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1562
1563         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1564         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1565         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1566         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1567         DFTOTAL=`echo $STRING | cut -d, -f1`
1568         DFUSED=`echo $STRING  | cut -d, -f2`
1569         DFAVAIL=`echo $STRING | cut -d, -f3`
1570         DFFREE=$(($DFTOTAL - $DFUSED))
1571
1572         ALLOWANCE=$((64 * $OSTCOUNT))
1573
1574         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1575            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1576                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1577                 rc=1
1578         fi
1579         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1580            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1581                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1582                 rc=2
1583         fi
1584         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1585            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1586                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1587                 rc=3
1588        fi
1589
1590         umount -d $MOUNT2
1591         stop fs3ost -f || return 200
1592         stop fs2ost -f || return 201
1593         stop fs2mds -f || return 202
1594         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1595         unload_modules || return 203
1596         return $rc
1597 }
1598 run_test 36 "df report consistency on OSTs with different block size"
1599
1600 test_37() {
1601         client_only && skip "client only testing" && return 0
1602         LOCAL_MDSDEV="$TMP/mdt.img"
1603         SYM_MDSDEV="$TMP/sym_mdt.img"
1604
1605         echo "MDS :     $LOCAL_MDSDEV"
1606         echo "SYMLINK : $SYM_MDSDEV"
1607         rm -f $LOCAL_MDSDEV
1608
1609         touch $LOCAL_MDSDEV
1610         mkfs.lustre --reformat --fsname=lustre --mdt --mgs --device-size=9000 $LOCAL_MDSDEV ||
1611                 error "mkfs.lustre $LOCAL_MDSDEV failed"
1612         ln -s $LOCAL_MDSDEV $SYM_MDSDEV
1613
1614         echo "mount symlink device - $SYM_MDSDEV"
1615
1616         mount_op=`mount -v -t lustre -o loop $SYM_MDSDEV ${MOUNT%/*}/mds 2>&1 | grep "unable to set tunable"`
1617         umount -d ${MOUNT%/*}/mds
1618         rm -f $LOCAL_MDSDEV $SYM_MDSDEV
1619
1620         if [ -n "$mount_op" ]; then
1621                 error "**** FAIL: set tunables failed for symlink device"
1622         fi
1623         return 0
1624 }
1625 run_test 37 "verify set tunables works for symlink device"
1626
1627 test_38() { # bug 14222
1628         setup
1629         # like runtests
1630         COUNT=10
1631         SRC="/etc /bin"
1632         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1633         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1634         mkdir -p $DIR/$tdir
1635         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1636                 error "copying $SRC to $DIR/$tdir"
1637         sync
1638         umount_client $MOUNT
1639         stop_mds
1640         log "rename lov_objid file on MDS"
1641         rm -f $TMP/lov_objid.orig
1642         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1643         do_facet mds "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1644
1645         do_facet mds "od -Ax -td8 $TMP/lov_objid.orig"
1646         # check create in mds_lov_connect
1647         start_mds
1648         mount_client $MOUNT
1649         for f in $FILES; do
1650                 [ $V ] && log "verifying $DIR/$tdir/$f"
1651                 diff -q $f $DIR/$tdir/$f || ERROR=y
1652         done
1653         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1654         do_facet mds "od -Ax -td8 $TMP/lov_objid.new"
1655         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1656
1657
1658         # check it's updates in sync
1659         umount_client $MOUNT
1660         stop_mds
1661
1662         do_facet mds dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1663         do_facet mds "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1664         do_facet mds "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1665
1666         start_mds
1667         mount_client $MOUNT
1668         for f in $FILES; do
1669                 [ $V ] && log "verifying $DIR/$tdir/$f"
1670                 diff -q $f $DIR/$tdir/$f || ERROR=y
1671         done
1672         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1673         do_facet mds "od -Ax -td8 $TMP/lov_objid.new1"
1674         umount_client $MOUNT
1675         stop_mds
1676         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1677
1678         log "files compared the same"
1679         cleanup
1680 }
1681 run_test 38 "MDS recreates missing lov_objid file from OST data"
1682
1683 test_39() { #bug 14413
1684         PTLDEBUG=+malloc
1685         setup
1686         cleanup
1687         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
1688                 error "memory leak detected" || true
1689 }
1690 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1691
1692 test_40() { # bug 15759
1693         start_ost
1694         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1695         do_facet mds "lctl set_param fail_loc=0x80000706"
1696         start_mds
1697         cleanup
1698 }
1699 run_test 40 "race during service thread startup"
1700
1701 test_41() { #bug 14134
1702         local rc
1703         start mds $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1704         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1705         start mds $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1706         mkdir -p $MOUNT
1707         mount_client $MOUNT || return 1
1708         sleep 5
1709
1710         echo "blah blah" > $MOUNT/$tfile
1711         cat $MOUNT/$tfile
1712
1713         umount_client $MOUNT
1714         stop ost1 -f || return 201
1715         stop mds -f || return 202
1716         stop mds -f || return 203
1717         unload_modules || return 204
1718         return $rc
1719 }
1720 run_test 41 "mount mds with --nosvc and --nomgs"
1721
1722 test_42() { #bug 14693
1723         setup
1724         check_mount || return 2
1725         do_facet client lctl conf_param lustre.llite.some_wrong_param=10
1726         umount_client $MOUNT
1727         mount_client $MOUNT || return 1
1728         cleanup
1729         return 0
1730 }
1731 run_test 42 "invalid config param should not prevent client from mounting"
1732
1733 test_43() { #bug 15993
1734         setup
1735         VERSION_1_8=$(do_facet mds $LCTL get_param version | grep ^lustre.*1\.[78])
1736         if [ -z "$VERSION_1_8" ]; then
1737                 skip "skipping test for non 1.8 MDS"
1738                 cleanup
1739                 return 0
1740         fi
1741
1742         check_mount || return 2
1743         testfile=$DIR/$tfile
1744         lma="this-should-be-removed-after-remount-and-accessed"
1745         touch $testfile
1746         echo "set/get trusted.lma"
1747 #define OBD_FAIL_MDS_ALLOW_COMMON_EA_SETTING    0x13f
1748         do_facet mds "lctl set_param fail_loc=0x13f"
1749         lctl set_param fail_loc=0x13f
1750         setfattr -n trusted.lma -v $lma $testfile || error "create common EA"
1751         do_facet mds "lctl set_param fail_loc=0"
1752         lctl set_param fail_loc=0
1753         ATTR=$(getfattr -n trusted.lma $testfile 2> /dev/null | grep trusted.lma)
1754         [ "$ATTR" = "trusted.lma=\"$lma\"" ] || error "check common EA"
1755         umount_client $MOUNT
1756         stop_mds
1757         sleep 5
1758         start_mds
1759         mount_client $MOUNT
1760         check_mount || return 3
1761 #define OBD_FAIL_MDS_REMOVE_COMMON_EA    0x13e
1762         do_facet mds "lctl set_param fail_loc=0x13e"
1763         stat $testfile
1764         do_facet mds "lctl set_param fail_loc=0"
1765         getfattr -d -m trusted $testfile 2> /dev/null | \
1766             grep "trusted.lma" && error "common EA not removed" || true
1767         cleanup
1768         return 0
1769 }
1770 run_test 43 "remove common EA if it exists"
1771
1772 test_44() { # 16317
1773         setup
1774         check_mount || return 2
1775         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
1776         STATS_FOUND=no
1777         UUIDS=$(do_facet mds "$LCTL get_param $(get_mds_mdt_device_proc_path).${FSNAME}*.exports.*.uuid")
1778         for VAL in $UUIDS; do
1779                 NID=$(echo $VAL | cut -d= -f1)
1780                 CLUUID=$(echo $VAL | cut -d= -f2)
1781                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
1782         done
1783         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
1784         cleanup
1785         return 0
1786 }
1787 run_test 44 "mounted client proc entry exists"
1788
1789 test_45() { #17310
1790         setup
1791         check_mount || return 2
1792         stop_mds
1793         df -h $MOUNT &
1794         log "sleep 60 sec"
1795         sleep 60
1796 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1797         do_facet client "lctl set_param fail_loc=0x50f"
1798         log "sleep 10 sec"
1799         sleep 10
1800         manual_umount_client --force || return 3
1801         do_facet client "lctl set_param fail_loc=0x0"
1802         start_mds
1803         mount_client $MOUNT || return 4
1804         cleanup
1805         return 0
1806 }
1807 run_test 45 "long unlink handling in ptlrpcd"
1808
1809 cleanup_46a() {
1810         trap 0
1811         local rc=0
1812         local count=$1
1813
1814         umount_client $MOUNT2 || rc=$?
1815         umount_client $MOUNT || rc=$?
1816         while [ $count -gt 0 ]; do
1817                 stop ost${count} -f || rc=$?
1818                 let count=count-1
1819         done    
1820         stop_mds || rc=$? 
1821         cleanup_nocli || rc=$?
1822         #writeconf to remove all ost2 traces for subsequent tests
1823         writeconf
1824         return $rc
1825 }
1826
1827 test_46a() {
1828         echo "Testing with $OSTCOUNT OSTs"
1829         reformat_and_config
1830         start_mds || return 1
1831         #first client should see only one ost
1832         start_ost || return 2
1833         wait_osc_import_state mds ost FULL
1834         #start_client
1835         mount_client $MOUNT || return 3
1836         trap "cleanup_46a $OSTCOUNT" EXIT ERR
1837
1838         local i 
1839         for (( i=2; i<=$OSTCOUNT; i++ )); do
1840             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
1841         done
1842
1843         # wait until osts in sync
1844         for (( i=2; i<=$OSTCOUNT; i++ )); do
1845             wait_osc_import_state mds ost$i FULL
1846         done
1847
1848         #second client see all ost's
1849
1850         mount_client $MOUNT2 || return 8
1851         $LFS setstripe $MOUNT2 -c -1 || return 9
1852         $LFS getstripe $MOUNT2 || return 10
1853
1854         echo "ok" > $MOUNT2/widestripe
1855         $LFS getstripe $MOUNT2/widestripe || return 11
1856         # fill acl buffer for avoid expand lsm to them
1857         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
1858             setfacl -m $acl $MOUNT2/widestripe
1859         done
1860
1861         # will be deadlock
1862         stat $MOUNT/widestripe || return 12
1863
1864         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
1865         return 0
1866 }
1867 run_test 46a "handle ost additional - wide striped file"
1868
1869 test_47() { #17674
1870         reformat
1871         setup_noconfig
1872         check_mount || return 2
1873         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
1874
1875         local lru_size=[]
1876         local count=0
1877         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1878             lrs=$(echo $ns | sed 's/.*lru_size=//')
1879             lru_size[count]=$lrs
1880             let count=count+1
1881         done
1882
1883         facet_failover ost1
1884         facet_failover mds
1885         client_up || return 3
1886
1887         count=0
1888         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1889             lrs=$(echo $ns | sed 's/.*lru_size=//')
1890             if ! test "$lrs" -eq "${lru_size[count]}"; then
1891                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
1892                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
1893             fi
1894             let count=count+1
1895         done
1896
1897         cleanup
1898         return 0
1899 }
1900 run_test 47 "server restart does not make client loss lru_resize settings"
1901
1902 cleanup_48() {
1903         trap 0
1904
1905         # reformat after this test is needed - if test will failed
1906         # we will have unkillable file at FS
1907         reformat_and_config
1908 }
1909
1910 test_48() { # bug 17636
1911         reformat
1912         setup_noconfig
1913         check_mount || return 2
1914
1915         $LFS setstripe $MOUNT -c -1 || return 9
1916         $LFS getstripe $MOUNT || return 10
1917
1918         echo "ok" > $MOUNT/widestripe
1919         $LFS getstripe $MOUNT/widestripe || return 11
1920
1921         trap cleanup_48 EXIT ERR
1922
1923         # fill acl buffer for avoid expand lsm to them
1924         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
1925             setfacl -m $acl $MOUNT/widestripe
1926         done
1927
1928         stat $MOUNT/widestripe || return 12
1929
1930         cleanup_48
1931         return 0
1932 }
1933 run_test 48 "too many acls on file"
1934
1935 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
1936 test_49() { # bug 17710
1937         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
1938         local OLD_OST_MKFS_OPTS=$OST_MKFS_OPTS
1939         local LOCAL_TIMEOUT=20
1940
1941         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$LOCAL_TIMEOUT $MKFSOPT $OSTOPT"
1942
1943         reformat
1944         setup_noconfig
1945         check_mount || return 1
1946
1947         echo "check ldlm_timout..."
1948         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1949         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1950         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1951
1952         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1953                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1954         fi
1955
1956         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
1957                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1958         fi
1959
1960         umount_client $MOUNT
1961         stop_ost || return 2
1962         stop_mds || return 3
1963
1964         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$((LOCAL_TIMEOUT - 1)) $MKFSOPT $OSTOPT"
1965
1966         reformat
1967         setup_noconfig
1968         check_mount || return 7
1969
1970         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1971         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1972         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1973
1974         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1975                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1976         fi
1977
1978         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
1979                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1980         fi
1981
1982         cleanup || return $?
1983
1984         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
1985         OST_MKFS_OPTS=$OLD_OST_MKFS_OPTS
1986 }
1987 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
1988
1989 lazystatfs() {
1990         # Test both statfs and lfs df and fail if either one fails
1991         multiop_bg_pause $1 f_
1992         RC1=$?
1993         PID=$!
1994         killall -USR1 multiop
1995         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
1996         wait $PID || { RC1=$?; log "multiop return error "; }
1997
1998         $LFS df &
1999         PID=$!
2000         sleep 5
2001         kill -s 0 $PID
2002         RC2=$?
2003         if [ $RC2 -eq 0 ]; then
2004             kill -s 9 $PID
2005             log "lazystatfs df failed"
2006         fi
2007
2008         RC=0
2009         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2010         return $RC
2011 }
2012
2013 test_50a() {
2014         setup
2015         lctl set_param llite.$FSNAME-*.lazystatfs=1
2016         touch $DIR/$tfile
2017
2018         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2019
2020         cleanup || return $?
2021 }
2022 run_test 50a "lazystatfs all servers available =========================="
2023
2024 test_50b() {
2025         setup
2026         lctl set_param llite.$FSNAME-*.lazystatfs=1
2027         touch $DIR/$tfile
2028
2029         # Wait for client to detect down OST
2030         stop_ost || error "Unable to stop OST1"
2031         wait_osc_import_state mds ost DISCONN
2032
2033         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2034
2035         umount_client $MOUNT || error "Unable to unmount client"
2036         stop_mds || error "Unable to stop MDS"
2037 }
2038 run_test 50b "lazystatfs all servers down =========================="
2039
2040 test_50c() {
2041         start_mds || error "Unable to start MDS"
2042         start_ost || error "Unable to start OST1"
2043         start_ost2 || error "Unable to start OST2"
2044         mount_client $MOUNT || error "Unable to mount client"
2045         lctl set_param llite.$FSNAME-*.lazystatfs=1
2046         touch $DIR/$tfile
2047
2048         # Wait for client to detect down OST
2049         stop_ost || error "Unable to stop OST1"
2050         wait_osc_import_state mds ost DISCONN
2051         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2052
2053         umount_client $MOUNT || error "Unable to unmount client"
2054         stop_ost2 || error "Unable to stop OST2"
2055         stop_mds || error "Unable to stop MDS"
2056 }
2057 run_test 50c "lazystatfs one server down =========================="
2058
2059 test_50d() {
2060         start_mds || error "Unable to start MDS"
2061         start_ost || error "Unable to start OST1"
2062         start_ost2 || error "Unable to start OST2"
2063         mount_client $MOUNT || error "Unable to mount client"
2064         lctl set_param llite.$FSNAME-*.lazystatfs=1
2065         touch $DIR/$tfile
2066
2067         # Issue the statfs during the window where the client still
2068         # belives the OST to be available but it is in fact down.
2069         # No failure just a statfs which hangs for a timeout interval.
2070         stop_ost || error "Unable to stop OST1"
2071         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2072
2073         umount_client $MOUNT || error "Unable to unmount client"
2074         stop_ost2 || error "Unable to stop OST2"
2075         stop_mds || error "Unable to stop MDS"
2076 }
2077 run_test 50d "lazystatfs client/server conn race =========================="
2078
2079 test_50e() {
2080         local RC1
2081         local pid
2082
2083         reformat_and_config
2084         start_mds || return 1
2085         #first client should see only one ost
2086         start_ost || return 2
2087         wait_osc_import_state mds ost FULL
2088
2089         # Wait for client to detect down OST
2090         stop_ost || error "Unable to stop OST1"
2091         wait_osc_import_state mds ost DISCONN
2092
2093         mount_client $MOUNT || error "Unable to mount client"
2094         lctl set_param llite.$FSNAME-*.lazystatfs=0
2095
2096         multiop_bg_pause $MOUNT _f
2097         RC1=$?
2098         pid=$!
2099
2100         if [ $RC1 -ne 0 ]; then
2101                 log "lazystatfs multiop failed $RC1"
2102         else
2103             kill -USR1 $pid
2104             sleep $(( $TIMEOUT+1 ))
2105             kill -0 $pid
2106             [ $? -ne 0 ] && error "process isn't sleep"
2107             start_ost || error "Unable to start OST1"
2108             wait $pid || error "statfs failed"
2109         fi
2110
2111         umount_client $MOUNT || error "Unable to unmount client"
2112         stop_ost || error "Unable to stop OST1"
2113         stop_mds || error "Unable to stop MDS"
2114 }
2115 run_test 50e "normal statfs all servers down =========================="
2116
2117 test_50f() {
2118         local RC1
2119         local pid
2120         CONN_PROC="osc.$FSNAME-OST0001-osc.ost_server_uuid"
2121
2122         start_mds || error "Unable to start mds"
2123         #first client should see only one ost
2124         start_ost || error "Unable to start OST1"
2125         wait_osc_import_state mds ost FULL
2126
2127         start_ost2 || error "Unable to start OST2"
2128         wait_osc_import_state mds ost2 FULL
2129
2130         # Wait for client to detect down OST
2131         stop_ost2 || error "Unable to stop OST2"
2132         wait_osc_import_state mds ost2 DISCONN
2133
2134         mount_client $MOUNT || error "Unable to mount client"
2135         lctl set_param llite.$FSNAME-*.lazystatfs=0
2136
2137         multiop_bg_pause $MOUNT _f
2138         RC1=$?
2139         pid=$!
2140
2141         if [ $RC1 -ne 0 ]; then
2142                 log "lazystatfs multiop failed $RC1"
2143         else
2144             kill -USR1 $pid
2145             sleep $(( $TIMEOUT+1 ))
2146             kill -0 $pid
2147             [ $? -ne 0 ] && error "process isn't sleep"
2148             start_ost2 || error "Unable to start OST2"
2149             wait $pid || error "statfs failed"
2150             stop_ost2 || error "Unable to stop OST2"
2151         fi
2152
2153         umount_client $MOUNT || error "Unable to unmount client"
2154         stop_ost || error "Unable to stop OST1"
2155         stop_mds || error "Unable to stop MDS"
2156         #writeconf to remove all ost2 traces for subsequent tests
2157         writeconf
2158 }
2159 run_test 50f "normal statfs one server in down =========================="
2160
2161 test_50g() {
2162         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2163         setup
2164         start_ost2 || error "Unable to start OST2"
2165
2166         local PARAM="${FSNAME}-OST0001.osc.active"
2167
2168         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2169         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2170
2171         umount_client $MOUNT || error "Unable to unmount client"
2172         mount_client $MOUNT || error "Unable to mount client"
2173         # This df should not cause a panic
2174         df -k $MOUNT
2175
2176         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2177         rm -f $DIR/$tfile
2178         umount_client $MOUNT || error "Unable to unmount client"
2179         stop_ost2 || error "Unable to stop OST2"
2180         stop_ost || error "Unable to stop OST1"
2181         stop_mds || error "Unable to stop MDS"
2182         #writeconf to remove all ost2 traces for subsequent tests
2183         writeconf
2184 }
2185 run_test 50g "deactivated OST should not cause panic====================="
2186
2187 if ! combined_mgs_mds ; then
2188         stop mgs
2189 fi
2190
2191 equals_msg `basename $0`: test complete
2192 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true