Whamcloud - gitweb
b=22771 add changelog entry
[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         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1095         # numerical part of it. Hopefully that's not already a failover address for
1096         # the server.
1097         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1098         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1099         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1100         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1101         echo "Using fake nid $NEW"
1102
1103         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1104         set_and_check client "$TEST" "$FSNAME-OST0000.failover.node" $NEW || error "didn't add failover nid $NEW"
1105         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1106         echo $NIDS
1107         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1108         echo "should have 2 failover nids: $NIDCOUNT"
1109         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1110         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1111         umount_client $MOUNT
1112         mount_client $MOUNT || return 3
1113
1114         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1115         echo $NIDS
1116         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1117         echo "only 1 final nid should remain: $NIDCOUNT"
1118         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1119
1120         cleanup
1121 }
1122 run_test 30b "Remove failover nids"
1123
1124 test_31() { # bug 10734
1125         # ipaddr must not exist
1126         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1127         cleanup
1128 }
1129 run_test 31 "Connect to non-existent node (returns errors, should not crash)"
1130
1131 # Use these start32/stop32 fn instead of t-f start/stop fn,
1132 # for local devices, to skip global facet vars init
1133 stop32 () {
1134         local facet=$1
1135         shift
1136         echo "Stopping local ${MOUNT%/*}/${facet} (opts:$@)"
1137         umount -d $@ ${MOUNT%/*}/${facet}
1138         losetup -a
1139 }
1140
1141 start32 () {
1142         local facet=$1
1143         shift
1144         local device=$1
1145         shift
1146         mkdir -p ${MOUNT%/*}/${facet}
1147
1148         echo "Starting local ${facet}: $@ $device ${MOUNT%/*}/${facet}"
1149         mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
1150         RC=$?
1151         if [ $RC -ne 0 ]; then
1152                 echo "mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}"
1153                 echo "Start of ${device} of local ${facet} failed ${RC}"
1154         fi
1155         losetup -a
1156         return $RC
1157 }
1158
1159 cleanup_nocli32 () {
1160         stop32 mds -f
1161         stop32 ost1 -f
1162         wait_exit_ST client
1163 }
1164
1165 cleanup_32() {
1166         trap 0
1167         echo "Cleanup test_32 umount $MOUNT ..."
1168         umount -f $MOUNT || true
1169         echo "Cleanup local mds ost1 ..."
1170         cleanup_nocli32
1171         unload_modules
1172 }
1173
1174 test_32a() {
1175         # this test is totally useless on a client-only system
1176         client_only && skip "client only testing" && return 0
1177         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1178         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return 0
1179
1180         local DISK1_6=$LUSTRE/tests/disk1_6.tar.bz2
1181         [ ! -r $DISK1_6 ] && skip_env "Cant find $DISK1_6, skipping" && return
1182
1183         local tmpdir=$TMP/conf32a
1184         mkdir -p $tmpdir
1185
1186         tar xjvf $DISK1_6 -C $tmpdir ||
1187                 { skip_env "Cant untar $DISK1_6, skipping" && return ; }
1188         load_modules
1189         lctl set_param debug=$PTLDEBUG
1190
1191         $TUNEFS $tmpdir/mds || error "tunefs failed"
1192
1193         # nids are wrong, so client wont work, but server should start
1194         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1195                 trap cleanup_32 EXIT INT || return 3
1196
1197         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
1198         echo MDS uuid $UUID
1199         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1200
1201         $TUNEFS --mgsnode=`hostname` $tmpdir/ost1 || error "tunefs failed"
1202         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1203         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1204         echo OST uuid $UUID
1205         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1206
1207         local NID=$($LCTL list_nids | head -1)
1208
1209         echo "OSC changes should succeed:"
1210         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || return 7
1211         $LCTL conf_param lustre-OST0000.failover.node=$NID || return 8
1212         echo "ok."
1213         echo "MDC changes should succeed:"
1214         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1215         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1216         echo "ok."
1217
1218         cleanup_32
1219
1220         # mount a second time to make sure we didnt leave upgrade flag on
1221         load_modules
1222         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1223         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1224                 trap cleanup_32 EXIT INT || return 12
1225
1226         cleanup_32
1227
1228         rm -rf $tmpdir || true  # true is only for TMP on NFS
1229 }
1230 run_test 32a "Upgrade from 1.6 (not live)"
1231
1232 test_32b() {
1233         # this test is totally useless on a client-only system
1234         client_only && skip "client only testing" && return 0
1235         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1236         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return
1237
1238         local DISK1_6=$LUSTRE/tests/disk1_6.tar.bz2
1239         [ ! -r $DISK1_6 ] && skip_env "Cant find $DISK1_6, skipping" && return
1240
1241         local tmpdir=$TMP/conf32b
1242         mkdir -p $tmpdir
1243
1244         tar xjvf $DISK1_6 -C $tmpdir ||
1245                 { skip_env "Cant untar $DISK1_6, skipping" && return ; }
1246
1247         load_modules
1248         lctl set_param debug=$PTLDEBUG
1249
1250         # Ugrade process in according to comment 2 bug 20246
1251         # writeconf will cause servers to register with their current nids
1252         $TUNEFS --mdt --writeconf --erase-param \
1253                 --param="mdt.group_upcall=/usr/sbin/l_getgroups" $tmpdir/mds || \
1254                 error "tunefs mds failed"
1255
1256         start32 mds $tmpdir/mds "-o loop,abort_recov" && \
1257                 trap cleanup_32 EXIT INT || return 3
1258
1259         stop32 mds
1260         start32 mds "-o loop" $tmpdir/mds || return 4
1261         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
1262         echo MDS uuid $UUID
1263         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1264
1265         $TUNEFS --ost --writeconf  --erase-param --mgsnode=`hostname`@$NETTYPE $tmpdir/ost1 || \
1266                 error "tunefs ost failed"
1267         start32 ost1 $tmpdir/ost1 "-o loop,abort_recov" || return 5
1268
1269         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1270         echo OST uuid $UUID
1271         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1272
1273         local NID=$($LCTL list_nids | head -1)
1274
1275         echo "OSC changes should succeed:"
1276         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || error "OSC conf_param failed"
1277         $LCTL conf_param lustre-OST0000.failover.node=$NID || error "add failover nid=$NID failed"
1278         echo "ok."
1279         echo "MDC changes should succeed:"
1280         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1281         echo "ok."
1282
1283         # MDT and OST should have registered with new nids, so we should have
1284         # a fully-functioning client
1285         echo "Check client and old fs contents"
1286
1287         local device=`h2$NETTYPE $HOSTNAME`:/lustre
1288         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1289         mount -t lustre $device $MOUNT || return 1
1290
1291         local old=$(lctl get_param -n mdc.*.max_rpcs_in_flight)
1292         local new=$((old + 5))
1293         lctl conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=$new
1294         wait_update $HOSTNAME "lctl get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1295
1296         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "2940530074 2837" ] || return 12
1297         echo "ok."
1298
1299         cleanup_32
1300
1301         rm -rf $tmpdir || true  # true is only for TMP on NFS
1302 }
1303 run_test 32b "Upgrade from 1.6 with writeconf"
1304
1305 test_33a() { # bug 12333, was test_33
1306         local rc=0
1307         local FSNAME2=test-123
1308         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1309
1310         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1311                 is_blkdev mds $MDSDEV && \
1312                 skip_env "mixed loopback and real device not working" && return
1313         fi
1314
1315         # interop 1.8 <-> 2.0
1316         local mkfs_opts
1317         local major=$(get_mds_version_major)
1318         local minor=$(get_mds_version_minor)
1319         if [ $major -le 1 -a $minor -le 8 ]; then
1320                 mkfs_opts=""
1321         else
1322                 mkfs_opts="--mkfsoptions='-J size=8'" # bug 17931
1323         fi
1324
1325         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1326         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1327         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} $mkfs_opts --reformat $fs2mdsdev || exit 10
1328         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1329
1330         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1331         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1332         do_facet mds "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1333         mkdir -p $MOUNT2
1334         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1335         cp /etc/hosts $MOUNT2/. || rc=3
1336         echo "ok."
1337
1338         cp /etc/hosts $MOUNT2/ || rc=3
1339         $LFS getstripe $MOUNT2/hosts
1340
1341         umount -d $MOUNT2
1342         stop fs2ost -f
1343         stop fs2mds -f
1344         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1345         cleanup_nocli || rc=6
1346         return $rc
1347 }
1348 run_test 33a "Mount ost with a large index number"
1349
1350 test_33b() {    # was test_33a
1351         setup
1352
1353         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1354         # Drop lock cancelation reply during umount
1355         #define OBD_FAIL_LDLM_CANCEL             0x304
1356         do_facet client lctl set_param fail_loc=0x80000304
1357         #lctl set_param debug=-1
1358         umount_client $MOUNT
1359         cleanup
1360 }
1361 run_test 33b "Drop cancel during umount"
1362
1363 test_34a() {
1364         setup
1365         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1366         manual_umount_client
1367         rc=$?
1368         do_facet client killall -USR1 multiop
1369         if [ $rc -eq 0 ]; then
1370                 error "umount not fail!"
1371         fi
1372         sleep 1
1373         cleanup
1374 }
1375 run_test 34a "umount with opened file should be fail"
1376
1377
1378 test_34b() {
1379         setup
1380         touch $DIR/$tfile || return 1
1381         stop_mds --force || return 2
1382
1383         manual_umount_client --force
1384         rc=$?
1385         if [ $rc -ne 0 ]; then
1386                 error "mtab after failed umount - rc $rc"
1387         fi
1388
1389         cleanup
1390         return 0
1391 }
1392 run_test 34b "force umount with failed mds should be normal"
1393
1394 test_34c() {
1395         setup
1396         touch $DIR/$tfile || return 1
1397         stop_ost --force || return 2
1398
1399         manual_umount_client --force
1400         rc=$?
1401         if [ $rc -ne 0 ]; then
1402                 error "mtab after failed umount - rc $rc"
1403         fi
1404
1405         cleanup
1406         return 0
1407 }
1408 run_test 34c "force umount with failed ost should be normal"
1409
1410 test_35a() { # bug 12459
1411         setup
1412
1413         debugsave
1414         lctl set_param debug="ha"
1415
1416         log "Set up a fake failnode for the MDS"
1417         FAKENID="127.0.0.2"
1418         do_facet mds $LCTL conf_param ${FSNAME}-MDT0000.failover.node=$FAKENID || return 4
1419
1420         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1421         sleep 10
1422
1423         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1424         $LCTL clear
1425         log "$MSG"
1426         log "Stopping the MDT:"
1427         stop_mds || return 5
1428
1429         df $MOUNT > /dev/null 2>&1 &
1430         DFPID=$!
1431         log "Restarting the MDT:"
1432         start_mds || return 6
1433         log "Wait for df ($DFPID) ... "
1434         wait $DFPID
1435         log "done"
1436         debugrestore
1437
1438         # retrieve from the log the first server that the client tried to
1439         # contact after the connection loss
1440         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1441         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1442                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1443                                 if (start) {
1444                                         if (\\\$NF ~ /$FAKENID/)
1445                                                 print \\\$NF;
1446                                         else
1447                                                 print 0;
1448                                         exit;
1449                                 }
1450                        }" $TMP/lustre-log-$TESTNAME.log`
1451         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1452         cleanup
1453         # remove nid settings
1454         writeconf
1455 }
1456 run_test 35a "Reconnect to the last active server first"
1457
1458 test_35b() { # bug 18674
1459         remote_mds || { skip "local MDS" && return 0; }
1460         setup
1461
1462         debugsave
1463         $LCTL set_param debug="ha"
1464         $LCTL clear
1465         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1466         log "$MSG"
1467
1468         log "Set up a fake failnode for the MDS"
1469         FAKENID="127.0.0.2"
1470         do_facet mds $LCTL conf_param ${FSNAME}-MDT0000.failover.node=$FAKENID || \
1471                 return 1
1472
1473         local at_max_saved=0
1474         # adaptive timeouts may prevent seeing the issue 
1475         if at_is_enabled; then
1476                 at_max_saved=$(at_max_get mds)
1477                 at_max_set 0 mds client
1478         fi
1479
1480         mkdir -p $MOUNT/$tdir
1481
1482         log "Injecting EBUSY on MDS"
1483         # Setting OBD_FAIL_MDS_RESEND=0x136
1484         do_facet mds "$LCTL set_param fail_loc=0x80000136" || return 2
1485
1486         $LCTL set_param mdc.${FSNAME}*.stats=clear
1487
1488         log "Creating a test file and stat it"
1489         touch $MOUNT/$tdir/$tfile
1490         stat $MOUNT/$tdir/$tfile
1491
1492         log "Stop injecting EBUSY on MDS"
1493         do_facet mds "$LCTL set_param fail_loc=0" || return 3
1494         rm -f $MOUNT/$tdir/$tfile
1495
1496         log "done"
1497         # restore adaptive timeout
1498         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1499
1500         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1501
1502         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1503
1504         # retrieve from the log if the client has ever tried to
1505         # contact the fake server after the loss of connection
1506         FAILCONN=`awk "BEGIN {ret = 0;}
1507                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1508                                 ret = 1;
1509                                 if (\\\$NF ~ /$FAKENID/) {
1510                                         ret = 2;
1511                                         exit;
1512                                 }
1513                        }
1514                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1515
1516         [ "$FAILCONN" == "0" ] && \
1517                 log "ERROR: The client reconnection has not been triggered" && \
1518                 return 4
1519         [ "$FAILCONN" == "2" ] && \
1520                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1521                 return 5
1522
1523         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1524         # Reconnects are supposed to be rate limited to one every 5s
1525         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1526                 log "ERROR: Too many reconnects $CONNCNT" && \
1527                 return 6
1528
1529         cleanup
1530         # remove nid settings
1531         writeconf
1532 }
1533 run_test 35b "Continue reconnection retries, if the active server is busy"
1534
1535 test_36() { # 12743
1536         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1537
1538         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1539                 { skip "remote OST" && return 0; }
1540
1541         local rc=0
1542         local FSNAME2=test1234
1543         local fs3ost_HOST=$ost_HOST
1544
1545         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1546
1547         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1548                 is_blkdev mds $MDSDEV && \
1549                 skip_env "mixed loopback and real device not working" && return
1550         fi
1551
1552         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1553         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1554         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1555         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1556         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1557         # other argument
1558         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1559         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1560
1561         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1562         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1563         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1564         mkdir -p $MOUNT2
1565         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1566
1567         sleep 5 # until 11778 fixed
1568
1569         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1570
1571         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1572         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1573         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1574         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1575         DFTOTAL=`echo $STRING | cut -d, -f1`
1576         DFUSED=`echo $STRING  | cut -d, -f2`
1577         DFAVAIL=`echo $STRING | cut -d, -f3`
1578         DFFREE=$(($DFTOTAL - $DFUSED))
1579
1580         ALLOWANCE=$((64 * $OSTCOUNT))
1581
1582         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1583            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1584                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1585                 rc=1
1586         fi
1587         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1588            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1589                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1590                 rc=2
1591         fi
1592         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1593            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1594                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1595                 rc=3
1596        fi
1597
1598         umount -d $MOUNT2
1599         stop fs3ost -f || return 200
1600         stop fs2ost -f || return 201
1601         stop fs2mds -f || return 202
1602         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1603         unload_modules || return 203
1604         return $rc
1605 }
1606 run_test 36 "df report consistency on OSTs with different block size"
1607
1608 test_37() {
1609         client_only && skip "client only testing" && return 0
1610         LOCAL_MDSDEV="$TMP/mdt.img"
1611         SYM_MDSDEV="$TMP/sym_mdt.img"
1612
1613         echo "MDS :     $LOCAL_MDSDEV"
1614         echo "SYMLINK : $SYM_MDSDEV"
1615         rm -f $LOCAL_MDSDEV
1616
1617         touch $LOCAL_MDSDEV
1618         mkfs.lustre --reformat --fsname=lustre --mdt --mgs --device-size=9000 $LOCAL_MDSDEV ||
1619                 error "mkfs.lustre $LOCAL_MDSDEV failed"
1620         ln -s $LOCAL_MDSDEV $SYM_MDSDEV
1621
1622         echo "mount symlink device - $SYM_MDSDEV"
1623
1624         mount_op=`mount -v -t lustre -o loop $SYM_MDSDEV ${MOUNT%/*}/mds 2>&1 | grep "unable to set tunable"`
1625         umount -d ${MOUNT%/*}/mds
1626         rm -f $LOCAL_MDSDEV $SYM_MDSDEV
1627
1628         if [ -n "$mount_op" ]; then
1629                 error "**** FAIL: set tunables failed for symlink device"
1630         fi
1631         return 0
1632 }
1633 run_test 37 "verify set tunables works for symlink device"
1634
1635 test_38() { # bug 14222
1636         setup
1637         # like runtests
1638         COUNT=10
1639         SRC="/etc /bin"
1640         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1641         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1642         mkdir -p $DIR/$tdir
1643         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1644                 error "copying $SRC to $DIR/$tdir"
1645         sync
1646         umount_client $MOUNT
1647         stop_mds
1648         log "rename lov_objid file on MDS"
1649         rm -f $TMP/lov_objid.orig
1650         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1651         do_facet mds "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1652
1653         do_facet mds "od -Ax -td8 $TMP/lov_objid.orig"
1654         # check create in mds_lov_connect
1655         start_mds
1656         mount_client $MOUNT
1657         for f in $FILES; do
1658                 [ $V ] && log "verifying $DIR/$tdir/$f"
1659                 diff -q $f $DIR/$tdir/$f || ERROR=y
1660         done
1661         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1662         do_facet mds "od -Ax -td8 $TMP/lov_objid.new"
1663         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1664
1665
1666         # check it's updates in sync
1667         umount_client $MOUNT
1668         stop_mds
1669
1670         do_facet mds dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1671         do_facet mds "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1672         do_facet mds "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1673
1674         start_mds
1675         mount_client $MOUNT
1676         for f in $FILES; do
1677                 [ $V ] && log "verifying $DIR/$tdir/$f"
1678                 diff -q $f $DIR/$tdir/$f || ERROR=y
1679         done
1680         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1681         do_facet mds "od -Ax -td8 $TMP/lov_objid.new1"
1682         umount_client $MOUNT
1683         stop_mds
1684         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1685
1686         log "files compared the same"
1687         cleanup
1688 }
1689 run_test 38 "MDS recreates missing lov_objid file from OST data"
1690
1691 test_39() { #bug 14413
1692         PTLDEBUG=+malloc
1693         setup
1694         cleanup
1695         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
1696                 error "memory leak detected" || true
1697 }
1698 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1699
1700 test_40() { # bug 15759
1701         start_ost
1702         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1703         do_facet mds "lctl set_param fail_loc=0x80000706"
1704         start_mds
1705         cleanup
1706 }
1707 run_test 40 "race during service thread startup"
1708
1709 test_41() { #bug 14134
1710         local rc
1711         start mds $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1712         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1713         start mds $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1714         mkdir -p $MOUNT
1715         mount_client $MOUNT || return 1
1716         sleep 5
1717
1718         echo "blah blah" > $MOUNT/$tfile
1719         cat $MOUNT/$tfile
1720
1721         umount_client $MOUNT
1722         stop ost1 -f || return 201
1723         stop mds -f || return 202
1724         stop mds -f || return 203
1725         unload_modules || return 204
1726         return $rc
1727 }
1728 run_test 41 "mount mds with --nosvc and --nomgs"
1729
1730 test_42() { #bug 14693
1731         setup
1732         check_mount || return 2
1733         do_facet client lctl conf_param lustre.llite.some_wrong_param=10
1734         umount_client $MOUNT
1735         mount_client $MOUNT || return 1
1736         cleanup
1737         return 0
1738 }
1739 run_test 42 "invalid config param should not prevent client from mounting"
1740
1741 test_43() { #bug 15993
1742         setup
1743         VERSION_1_8=$(do_facet mds $LCTL get_param version | grep ^lustre.*1\.[78])
1744         if [ -z "$VERSION_1_8" ]; then
1745                 skip "skipping test for non 1.8 MDS"
1746                 cleanup
1747                 return 0
1748         fi
1749
1750         check_mount || return 2
1751         testfile=$DIR/$tfile
1752         lma="this-should-be-removed-after-remount-and-accessed"
1753         touch $testfile
1754         echo "set/get trusted.lma"
1755 #define OBD_FAIL_MDS_ALLOW_COMMON_EA_SETTING    0x13f
1756         do_facet mds "lctl set_param fail_loc=0x13f"
1757         lctl set_param fail_loc=0x13f
1758         setfattr -n trusted.lma -v $lma $testfile || error "create common EA"
1759         do_facet mds "lctl set_param fail_loc=0"
1760         lctl set_param fail_loc=0
1761         ATTR=$(getfattr -n trusted.lma $testfile 2> /dev/null | grep trusted.lma)
1762         [ "$ATTR" = "trusted.lma=\"$lma\"" ] || error "check common EA"
1763         umount_client $MOUNT
1764         stop_mds
1765         sleep 5
1766         start_mds
1767         mount_client $MOUNT
1768         check_mount || return 3
1769 #define OBD_FAIL_MDS_REMOVE_COMMON_EA    0x13e
1770         do_facet mds "lctl set_param fail_loc=0x13e"
1771         stat $testfile
1772         do_facet mds "lctl set_param fail_loc=0"
1773         getfattr -d -m trusted $testfile 2> /dev/null | \
1774             grep "trusted.lma" && error "common EA not removed" || true
1775         cleanup
1776         return 0
1777 }
1778 run_test 43 "remove common EA if it exists"
1779
1780 test_44() { # 16317
1781         setup
1782         check_mount || return 2
1783         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
1784         STATS_FOUND=no
1785         UUIDS=$(do_facet mds "$LCTL get_param $(get_mds_mdt_device_proc_path).${FSNAME}*.exports.*.uuid")
1786         for VAL in $UUIDS; do
1787                 NID=$(echo $VAL | cut -d= -f1)
1788                 CLUUID=$(echo $VAL | cut -d= -f2)
1789                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
1790         done
1791         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
1792         cleanup
1793         return 0
1794 }
1795 run_test 44 "mounted client proc entry exists"
1796
1797 test_45() { #17310
1798         setup
1799         check_mount || return 2
1800         stop_mds
1801         df -h $MOUNT &
1802         log "sleep 60 sec"
1803         sleep 60
1804 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1805         do_facet client "lctl set_param fail_loc=0x50f"
1806         log "sleep 10 sec"
1807         sleep 10
1808         manual_umount_client --force || return 3
1809         do_facet client "lctl set_param fail_loc=0x0"
1810         start_mds
1811         mount_client $MOUNT || return 4
1812         cleanup
1813         return 0
1814 }
1815 run_test 45 "long unlink handling in ptlrpcd"
1816
1817 cleanup_46a() {
1818         trap 0
1819         local rc=0
1820         local count=$1
1821
1822         umount_client $MOUNT2 || rc=$?
1823         umount_client $MOUNT || rc=$?
1824         while [ $count -gt 0 ]; do
1825                 stop ost${count} -f || rc=$?
1826                 let count=count-1
1827         done    
1828         stop_mds || rc=$? 
1829         cleanup_nocli || rc=$?
1830         #writeconf to remove all ost2 traces for subsequent tests
1831         writeconf
1832         return $rc
1833 }
1834
1835 test_46a() {
1836         echo "Testing with $OSTCOUNT OSTs"
1837         reformat_and_config
1838         start_mds || return 1
1839         #first client should see only one ost
1840         start_ost || return 2
1841         wait_osc_import_state mds ost FULL
1842         #start_client
1843         mount_client $MOUNT || return 3
1844         trap "cleanup_46a $OSTCOUNT" EXIT ERR
1845
1846         local i 
1847         for (( i=2; i<=$OSTCOUNT; i++ )); do
1848             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
1849         done
1850
1851         # wait until osts in sync
1852         for (( i=2; i<=$OSTCOUNT; i++ )); do
1853             wait_osc_import_state mds ost$i FULL
1854         done
1855
1856         #second client see all ost's
1857
1858         mount_client $MOUNT2 || return 8
1859         $LFS setstripe $MOUNT2 -c -1 || return 9
1860         $LFS getstripe $MOUNT2 || return 10
1861
1862         echo "ok" > $MOUNT2/widestripe
1863         $LFS getstripe $MOUNT2/widestripe || return 11
1864         # fill acl buffer for avoid expand lsm to them
1865         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
1866             setfacl -m $acl $MOUNT2/widestripe
1867         done
1868
1869         # will be deadlock
1870         stat $MOUNT/widestripe || return 12
1871
1872         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
1873         return 0
1874 }
1875 run_test 46a "handle ost additional - wide striped file"
1876
1877 test_47() { #17674
1878         reformat
1879         setup_noconfig
1880         check_mount || return 2
1881         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
1882
1883         local lru_size=[]
1884         local count=0
1885         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1886             lrs=$(echo $ns | sed 's/.*lru_size=//')
1887             lru_size[count]=$lrs
1888             let count=count+1
1889         done
1890
1891         facet_failover ost1
1892         facet_failover mds
1893         client_up || return 3
1894
1895         count=0
1896         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1897             lrs=$(echo $ns | sed 's/.*lru_size=//')
1898             if ! test "$lrs" -eq "${lru_size[count]}"; then
1899                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
1900                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
1901             fi
1902             let count=count+1
1903         done
1904
1905         cleanup
1906         return 0
1907 }
1908 run_test 47 "server restart does not make client loss lru_resize settings"
1909
1910 cleanup_48() {
1911         trap 0
1912
1913         # reformat after this test is needed - if test will failed
1914         # we will have unkillable file at FS
1915         reformat_and_config
1916 }
1917
1918 test_48() { # bug 17636
1919         reformat
1920         setup_noconfig
1921         check_mount || return 2
1922
1923         $LFS setstripe $MOUNT -c -1 || return 9
1924         $LFS getstripe $MOUNT || return 10
1925
1926         echo "ok" > $MOUNT/widestripe
1927         $LFS getstripe $MOUNT/widestripe || return 11
1928
1929         trap cleanup_48 EXIT ERR
1930
1931         # fill acl buffer for avoid expand lsm to them
1932         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
1933             setfacl -m $acl $MOUNT/widestripe
1934         done
1935
1936         stat $MOUNT/widestripe || return 12
1937
1938         cleanup_48
1939         return 0
1940 }
1941 run_test 48 "too many acls on file"
1942
1943 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
1944 test_49() { # bug 17710
1945         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
1946         local OLD_OST_MKFS_OPTS=$OST_MKFS_OPTS
1947         local LOCAL_TIMEOUT=20
1948
1949         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$LOCAL_TIMEOUT $MKFSOPT $OSTOPT"
1950
1951         reformat
1952         setup_noconfig
1953         check_mount || return 1
1954
1955         echo "check ldlm_timout..."
1956         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1957         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1958         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1959
1960         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1961                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1962         fi
1963
1964         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
1965                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1966         fi
1967
1968         umount_client $MOUNT
1969         stop_ost || return 2
1970         stop_mds || return 3
1971
1972         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"
1973
1974         reformat
1975         setup_noconfig
1976         check_mount || return 7
1977
1978         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1979         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1980         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1981
1982         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1983                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1984         fi
1985
1986         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
1987                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1988         fi
1989
1990         cleanup || return $?
1991
1992         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
1993         OST_MKFS_OPTS=$OLD_OST_MKFS_OPTS
1994 }
1995 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
1996
1997 lazystatfs() {
1998         # Test both statfs and lfs df and fail if either one fails
1999         multiop_bg_pause $1 f_
2000         RC1=$?
2001         PID=$!
2002         killall -USR1 multiop
2003         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2004         wait $PID || { RC1=$?; log "multiop return error "; }
2005
2006         $LFS df &
2007         PID=$!
2008         sleep 5
2009         kill -s 0 $PID
2010         RC2=$?
2011         if [ $RC2 -eq 0 ]; then
2012             kill -s 9 $PID
2013             log "lazystatfs df failed"
2014         fi
2015
2016         RC=0
2017         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2018         return $RC
2019 }
2020
2021 test_50a() {
2022         setup
2023         lctl set_param llite.$FSNAME-*.lazystatfs=1
2024         touch $DIR/$tfile
2025
2026         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2027
2028         cleanup || return $?
2029 }
2030 run_test 50a "lazystatfs all servers available =========================="
2031
2032 test_50b() {
2033         setup
2034         lctl set_param llite.$FSNAME-*.lazystatfs=1
2035         touch $DIR/$tfile
2036
2037         # Wait for client to detect down OST
2038         stop_ost || error "Unable to stop OST1"
2039         wait_osc_import_state mds ost DISCONN
2040
2041         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2042
2043         umount_client $MOUNT || error "Unable to unmount client"
2044         stop_mds || error "Unable to stop MDS"
2045 }
2046 run_test 50b "lazystatfs all servers down =========================="
2047
2048 test_50c() {
2049         start_mds || error "Unable to start MDS"
2050         start_ost || error "Unable to start OST1"
2051         start_ost2 || error "Unable to start OST2"
2052         mount_client $MOUNT || error "Unable to mount client"
2053         lctl set_param llite.$FSNAME-*.lazystatfs=1
2054         touch $DIR/$tfile
2055
2056         # Wait for client to detect down OST
2057         stop_ost || error "Unable to stop OST1"
2058         wait_osc_import_state mds ost DISCONN
2059         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2060
2061         umount_client $MOUNT || error "Unable to unmount client"
2062         stop_ost2 || error "Unable to stop OST2"
2063         stop_mds || error "Unable to stop MDS"
2064 }
2065 run_test 50c "lazystatfs one server down =========================="
2066
2067 test_50d() {
2068         start_mds || error "Unable to start MDS"
2069         start_ost || error "Unable to start OST1"
2070         start_ost2 || error "Unable to start OST2"
2071         mount_client $MOUNT || error "Unable to mount client"
2072         lctl set_param llite.$FSNAME-*.lazystatfs=1
2073         touch $DIR/$tfile
2074
2075         # Issue the statfs during the window where the client still
2076         # belives the OST to be available but it is in fact down.
2077         # No failure just a statfs which hangs for a timeout interval.
2078         stop_ost || error "Unable to stop OST1"
2079         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2080
2081         umount_client $MOUNT || error "Unable to unmount client"
2082         stop_ost2 || error "Unable to stop OST2"
2083         stop_mds || error "Unable to stop MDS"
2084 }
2085 run_test 50d "lazystatfs client/server conn race =========================="
2086
2087 test_50e() {
2088         local RC1
2089         local pid
2090
2091         reformat_and_config
2092         start_mds || return 1
2093         #first client should see only one ost
2094         start_ost || return 2
2095         wait_osc_import_state mds ost FULL
2096
2097         # Wait for client to detect down OST
2098         stop_ost || error "Unable to stop OST1"
2099         wait_osc_import_state mds ost DISCONN
2100
2101         mount_client $MOUNT || error "Unable to mount client"
2102         lctl set_param llite.$FSNAME-*.lazystatfs=0
2103
2104         multiop_bg_pause $MOUNT _f
2105         RC1=$?
2106         pid=$!
2107
2108         if [ $RC1 -ne 0 ]; then
2109                 log "lazystatfs multiop failed $RC1"
2110         else
2111             kill -USR1 $pid
2112             sleep $(( $TIMEOUT+1 ))
2113             kill -0 $pid
2114             [ $? -ne 0 ] && error "process isn't sleep"
2115             start_ost || error "Unable to start OST1"
2116             wait $pid || error "statfs failed"
2117         fi
2118
2119         umount_client $MOUNT || error "Unable to unmount client"
2120         stop_ost || error "Unable to stop OST1"
2121         stop_mds || error "Unable to stop MDS"
2122 }
2123 run_test 50e "normal statfs all servers down =========================="
2124
2125 test_50f() {
2126         local RC1
2127         local pid
2128         CONN_PROC="osc.$FSNAME-OST0001-osc.ost_server_uuid"
2129
2130         start_mds || error "Unable to start mds"
2131         #first client should see only one ost
2132         start_ost || error "Unable to start OST1"
2133         wait_osc_import_state mds ost FULL
2134
2135         start_ost2 || error "Unable to start OST2"
2136         wait_osc_import_state mds ost2 FULL
2137
2138         # Wait for client to detect down OST
2139         stop_ost2 || error "Unable to stop OST2"
2140         wait_osc_import_state mds ost2 DISCONN
2141
2142         mount_client $MOUNT || error "Unable to mount client"
2143         lctl set_param llite.$FSNAME-*.lazystatfs=0
2144
2145         multiop_bg_pause $MOUNT _f
2146         RC1=$?
2147         pid=$!
2148
2149         if [ $RC1 -ne 0 ]; then
2150                 log "lazystatfs multiop failed $RC1"
2151         else
2152             kill -USR1 $pid
2153             sleep $(( $TIMEOUT+1 ))
2154             kill -0 $pid
2155             [ $? -ne 0 ] && error "process isn't sleep"
2156             start_ost2 || error "Unable to start OST2"
2157             wait $pid || error "statfs failed"
2158             stop_ost2 || error "Unable to stop OST2"
2159         fi
2160
2161         umount_client $MOUNT || error "Unable to unmount client"
2162         stop_ost || error "Unable to stop OST1"
2163         stop_mds || error "Unable to stop MDS"
2164         #writeconf to remove all ost2 traces for subsequent tests
2165         writeconf
2166 }
2167 run_test 50f "normal statfs one server in down =========================="
2168
2169 test_50g() {
2170         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2171         setup
2172         start_ost2 || error "Unable to start OST2"
2173
2174         local PARAM="${FSNAME}-OST0001.osc.active"
2175
2176         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2177         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2178
2179         umount_client $MOUNT || error "Unable to unmount client"
2180         mount_client $MOUNT || error "Unable to mount client"
2181         # This df should not cause a panic
2182         df -k $MOUNT
2183
2184         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2185         rm -f $DIR/$tfile
2186         umount_client $MOUNT || error "Unable to unmount client"
2187         stop_ost2 || error "Unable to stop OST2"
2188         stop_ost || error "Unable to stop OST1"
2189         stop_mds || error "Unable to stop MDS"
2190         #writeconf to remove all ost2 traces for subsequent tests
2191         writeconf
2192 }
2193 run_test 50g "deactivated OST should not cause panic====================="
2194
2195 lov_objid_size()
2196 {
2197         local max_ost_index=$1
2198         echo -n $(($max_ost_index * 8 + 8))
2199 }
2200
2201 test_55() {
2202         local saved_opts=$OST_MKFS_OPTS
2203
2204         for i in 0 1023 2048
2205         do
2206                 OST_MKFS_OPTS="$saved_opts --index $i"
2207                 reformat
2208
2209                 setup_noconfig
2210                 cp /etc/passwd $DIR/1
2211                 stopall
2212
2213                 setup
2214                 cp /etc/passwd $DIR/2
2215                 sync
2216
2217                 echo checking size of lov_objid for ost index $i
2218                 local file_size=`do_facet mds \
2219                     "$DEBUGFS -R 'stat lov_objid' $MDSDEV 2>/dev/null" | \
2220                     grep ^User | awk '{print $6}'`
2221                 if [ "$file_size" != $(lov_objid_size $i) ]; then
2222                         error "lov_objid size has to be $(lov_objid_size $i), \
2223 not $file_size"
2224                 else
2225                         echo ok, lov_objid size is correct: $file_size
2226                 fi
2227                 stopall
2228         done
2229
2230         OST_MKFS_OPTS=$saved_opts
2231         reformat
2232 }
2233 run_test 55 "check lov_objid size"
2234
2235 test_56() {
2236         add mds $MDS_MKFS_OPTS --mkfsoptions='\"-J size=16\"' --reformat $MDSDEV
2237         add ost1 $OST_MKFS_OPTS --index=1000 --reformat `ostdevname 1`
2238         add ost2 $OST_MKFS_OPTS --index=10000 --reformat `ostdevname 2`
2239
2240         start_mds
2241         start_ost
2242         start_ost2 || error "Unable to start second ost"
2243         mount_client $MOUNT || error "Unable to mount client"
2244
2245         stopall
2246         reformat
2247 }
2248 run_test 56 "check big indexes"
2249
2250 test_57() { # bug 22656
2251         local NID=$($LCTL list_nids | head -1)
2252         writeconf
2253         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
2254         if ! combined_mgs_mds ; then
2255                 start_mgs
2256         fi
2257         start_mds
2258         stop_mds
2259         start_ost && error "OST registration from failnode should fail"
2260         reformat
2261 }
2262 run_test 57 "initial registration from failnode should fail (should return errs)"
2263
2264 test_58() { # bug 22658
2265         [ "$FSTYPE" != "ldiskfs" ] && skip "not supported for $FSTYPE" && return
2266         setup
2267         mkdir -p $DIR/$tdir
2268         createmany -o $DIR/$tdir/$tfile-%d 100
2269         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
2270 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
2271         do_facet mds "lctl set_param fail_loc=0x601"
2272         unlinkmany $DIR/$tdir/$tfile-%d 100
2273         stop mds
2274         local MNTDIR=$(facet_mntpt mds)
2275         # remove all files from the OBJECTS dir
2276         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
2277         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
2278         do_facet mds "umount $MNTDIR"
2279         # restart MDS with missing llog files
2280         start_mds
2281         do_facet mds "lctl set_param fail_loc=0"
2282         reformat
2283 }
2284 run_test 58 "missing llog files must not prevent MDT from mounting"
2285
2286 if ! combined_mgs_mds ; then
2287         stop mgs
2288 fi
2289
2290 equals_msg `basename $0`: test complete
2291 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true
2292 count_osts() {
2293         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
2294 }
2295
2296 test_58() {
2297         start_mds >> /dev/null
2298         local C1=$(count_osts)
2299         echo "original ost count: $C1 (expect > 0)"
2300         stop_mds >> /dev/null
2301         start_mds -o writeconf >> /dev/null || error "MDT start failed"
2302         local C2=$(count_osts)
2303         echo "after mdt writeconf count: $C2 (expect 0)"
2304         [ $C1 -gt 0 ] && [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
2305         echo "OST start without writeconf should fail:"
2306         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
2307         echo "OST start with writeconf should succeed:"
2308         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
2309         local C3=$(count_osts)
2310         echo "after ost writeconf count: $C3 (expect 1)"
2311         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
2312         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
2313         local C4=$(count_osts)
2314         echo "after ost2 writeconf count: $C4 (expect 2)"
2315         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
2316         stop_ost2 >> /dev/null
2317         cleanup_nocli >> /dev/null
2318 }
2319 run_test 58 "writeconf mount option"
2320