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