Whamcloud - gitweb
b55c9d3583c382082a17e01881c764e17cfa7813
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 # FIXME - there is no reason to use all of these different
4 #   return codes, espcially when most of them are mapped to something
5 #   else anyway.  The combination of test number and return code
6 #   figure out what failed.
7
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11
12 # bug number for skipped test:
13 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 is_sles11()                                             # LU-2181
17 {
18         if [ -r /etc/SuSE-release ]
19         then
20                 local vers=`grep VERSION /etc/SuSE-release | awk '{print $3}'`
21                 local patchlev=`grep PATCHLEVEL /etc/SuSE-release \
22                         | awk '{print $3}'`
23                 if [ $vers -eq 11 ] && [ $patchlev -eq 2 ]
24                 then
25                         return 0
26                 fi
27         fi
28         return 1
29 }
30
31 if is_sles11; then                                      # LU-2181
32         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 23a 34b"
33 fi
34
35 if [ "$FAILURE_MODE" = "HARD" ]; then
36         CONFIG_EXCEPTIONS="24a " && \
37         echo "Except the tests: $CONFIG_EXCEPTIONS for FAILURE_MODE=$FAILURE_MODE, bug 23573" && \
38         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
39 fi
40
41 # bug number for skipped test:
42 # a tool to create lustre filesystem images
43 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
44
45 SRCDIR=`dirname $0`
46 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
47
48 PTLDEBUG=${PTLDEBUG:--1}
49 SAVE_PWD=$PWD
50 LUSTRE=${LUSTRE:-`dirname $0`/..}
51 RLUSTRE=${RLUSTRE:-$LUSTRE}
52 export MULTIOP=${MULTIOP:-multiop}
53
54 . $LUSTRE/tests/test-framework.sh
55 init_test_env $@
56
57 # use small MDS + OST size to speed formatting time
58 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
59 MDSSIZE=200000
60 OSTSIZE=200000
61 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
62
63 if ! combined_mgs_mds; then
64     # bug number for skipped test:    23954
65     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
66 fi
67
68 # STORED_MDSSIZE is used in test_18
69 if [ -n "$MDSSIZE" ]; then
70     STORED_MDSSIZE=$MDSSIZE
71 fi
72
73 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
74 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
75         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
76 fi
77
78 init_logging
79
80 #
81 require_dsh_mds || exit 0
82 require_dsh_ost || exit 0
83 #
84 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45"
85
86
87 assert_DIR
88
89 reformat() {
90         formatall
91 }
92
93 writeconf1() {
94         local facet=$1
95         local dev=$2
96
97         stop ${facet} -f
98         rm -f ${facet}active
99         # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
100         do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" ||
101                 { echo "tunefs failed, reformatting instead" && reformat_and_config && return 1; }
102         return 0
103 }
104
105 writeconf() {
106         # we need ldiskfs
107         load_modules
108         # if writeconf fails anywhere, we reformat everything
109         writeconf1 mds `mdsdevname 1` || return 0
110         writeconf1 ost1 `ostdevname 1` || return 0
111         writeconf1 ost2 `ostdevname 2` || return 0
112 }
113
114 gen_config() {
115         # The MGS must be started before the OSTs for a new fs, so start
116         # and stop to generate the startup logs.
117         start_mds
118         start_ost
119         wait_osc_import_state mds ost FULL
120         stop_ost
121         stop_mds
122 }
123
124 reformat_and_config() {
125         reformat
126         if ! combined_mgs_mds ; then
127                 start_mgs
128         fi
129         gen_config
130 }
131
132 start_mgs () {
133         echo "start mgs"
134         start mgs $MGSDEV $MGS_MOUNT_OPTS
135 }
136
137 start_mds() {
138         local facet=$SINGLEMDS
139         # we can not use MDSDEV1 here because SINGLEMDS could be set not to mds1 only
140         local num=$(echo $facet | tr -d "mds")
141         local dev=$(mdsdevname $num)
142         echo "start mds service on `facet_active_host $facet`"
143         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
144 }
145
146 start_mgsmds() {
147         if ! combined_mgs_mds ; then
148                 start_mgs
149         fi
150         start_mds $@
151 }
152
153 stop_mds() {
154         echo "stop mds service on `facet_active_host $SINGLEMDS`"
155         # These tests all use non-failover stop
156         stop $SINGLEMDS -f  || return 97
157 }
158
159 stop_mgs() {
160        echo "stop mgs service on `facet_active_host mgs`"
161        # These tests all use non-failover stop
162        stop mgs -f  || return 97
163 }
164
165 start_ost() {
166         echo "start ost1 service on `facet_active_host ost1`"
167         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
168 }
169
170 stop_ost() {
171         echo "stop ost1 service on `facet_active_host ost1`"
172         # These tests all use non-failover stop
173         stop ost1 -f  || return 98
174 }
175
176 start_ost2() {
177         echo "start ost2 service on `facet_active_host ost2`"
178         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
179 }
180
181 stop_ost2() {
182         echo "stop ost2 service on `facet_active_host ost2`"
183         # These tests all use non-failover stop
184         stop ost2 -f  || return 93
185 }
186
187 mount_client() {
188         local MOUNTPATH=$1
189         echo "mount $FSNAME on ${MOUNTPATH}....."
190         zconf_mount `hostname` $MOUNTPATH  || return 96
191 }
192
193 remount_client() {
194         local mountopt="-o remount,$1"
195         local MOUNTPATH=$2
196         echo "remount '$1' lustre on ${MOUNTPATH}....."
197         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
198 }
199
200 umount_client() {
201         local MOUNTPATH=$1
202         echo "umount lustre on ${MOUNTPATH}....."
203         zconf_umount `hostname` $MOUNTPATH || return 97
204 }
205
206 manual_umount_client(){
207         local rc
208         local FORCE=$1
209         echo "manual umount lustre on ${MOUNT}...."
210         do_facet client "umount -d ${FORCE} $MOUNT"
211         rc=$?
212         return $rc
213 }
214
215 setup() {
216         start_mds || error "MDT start failed"
217         start_ost || error "OST start failed"
218         mount_client $MOUNT || error "client start failed"
219         client_up || error "client_up failed"
220 }
221
222 setup_noconfig() {
223         if ! combined_mgs_mds ; then
224                 start_mgs
225         fi
226
227         start_mds
228         start_ost
229         mount_client $MOUNT
230 }
231
232 unload_modules_conf () {
233         if combined_mgs_mds || ! local_mode; then
234                 unload_modules || return 1
235         fi
236 }
237
238 cleanup_nocli() {
239         stop_ost || return 202
240         stop_mds || return 201
241         unload_modules_conf || return 203
242 }
243
244 cleanup() {
245         umount_client $MOUNT || return 200
246         cleanup_nocli || return $?
247 }
248
249 check_mount() {
250         do_facet client "cp /etc/passwd $DIR/a" || return 71
251         do_facet client "rm $DIR/a" || return 72
252         # make sure lustre is actually mounted (touch will block,
253         # but grep won't, so do it after)
254         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
255         echo "setup single mount lustre success"
256 }
257
258 check_mount2() {
259         do_facet client "touch $DIR/a" || return 71
260         do_facet client "rm $DIR/a" || return 72
261         do_facet client "touch $DIR2/a" || return 73
262         do_facet client "rm $DIR2/a" || return 74
263         echo "setup double mount lustre success"
264 }
265
266 build_test_filter
267
268 if [ "$ONLY" == "setup" ]; then
269         setup
270         exit
271 fi
272
273 if [ "$ONLY" == "cleanup" ]; then
274         cleanup
275         exit
276 fi
277
278 init_gss
279
280 #create single point mountpoint
281
282 reformat_and_config
283
284 test_0() {
285         setup
286         check_mount || return 41
287         cleanup || return $?
288 }
289 run_test 0 "single mount setup"
290
291 test_1() {
292         start_mds || error "MDT start failed"
293         start_ost
294         echo "start ost second time..."
295         start_ost && error "2nd OST start should fail"
296         mount_client $MOUNT || error "client start failed"
297         check_mount || return 42
298         cleanup || return $?
299 }
300 run_test 1 "start up ost twice (should return errors)"
301
302 test_2() {
303         start_mds
304         echo "start mds second time.."
305         start_mds && error "2nd MDT start should fail"
306         start_ost
307         mount_client $MOUNT
308         check_mount || return 43
309         cleanup || return $?
310 }
311 run_test 2 "start up mds twice (should return err)"
312
313 test_3() {
314         setup
315         #mount.lustre returns an error if already in mtab
316         mount_client $MOUNT && error "2nd client mount should fail"
317         check_mount || return 44
318         cleanup || return $?
319 }
320 run_test 3 "mount client twice (should return err)"
321
322 test_4() {
323         setup
324         touch $DIR/$tfile || return 85
325         stop_ost -f
326         cleanup
327         eno=$?
328         # ok for ost to fail shutdown
329         if [ 202 -ne $eno ]; then
330                 return $eno;
331         fi
332         return 0
333 }
334 run_test 4 "force cleanup ost, then cleanup"
335
336 test_5a() {     # was test_5
337         setup
338         touch $DIR/$tfile || return 1
339         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
340
341         stop_mds -f || return 2
342
343         # cleanup may return an error from the failed
344         # disconnects; for now I'll consider this successful
345         # if all the modules have unloaded.
346         umount -d $MOUNT &
347         UMOUNT_PID=$!
348         sleep 6
349         echo "killing umount"
350         kill -TERM $UMOUNT_PID
351         echo "waiting for umount to finish"
352         wait $UMOUNT_PID
353         if grep " $MOUNT " /proc/mounts; then
354                 echo "test 5: /proc/mounts after failed umount"
355                 umount $MOUNT &
356                 UMOUNT_PID=$!
357                 sleep 2
358                 echo "killing umount"
359                 kill -TERM $UMOUNT_PID
360                 echo "waiting for umount to finish"
361                 wait $UMOUNT_PID
362                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
363         fi
364
365         manual_umount_client
366         # stop_mds is a no-op here, and should not fail
367         cleanup_nocli || return $?
368         # df may have lingering entry
369         manual_umount_client
370         # mtab may have lingering entry
371         local WAIT=0
372         local MAX_WAIT=20
373         local sleep=1
374         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
375                 sleep $sleep
376                 grep -q $MOUNT" " /etc/mtab || break
377                 echo "Waiting /etc/mtab updated ... "
378                 WAIT=$(( WAIT + sleep))
379         done
380         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
381         echo "/etc/mtab updated in $WAIT secs"
382 }
383 run_test 5a "force cleanup mds, then cleanup"
384
385 cleanup_5b () {
386         trap 0
387         start_mgs
388 }
389
390 test_5b() {
391         grep " $MOUNT " /etc/mtab && \
392                 error false "unexpected entry in mtab before mount" && return 10
393
394         local rc=0
395         start_ost
396         if ! combined_mgs_mds ; then
397                 trap cleanup_5b EXIT ERR
398                 start_mds
399                 stop mgs
400         fi
401
402         [ -d $MOUNT ] || mkdir -p $MOUNT
403         mount_client $MOUNT && rc=1
404         grep " $MOUNT " /etc/mtab && \
405                 error "$MOUNT entry in mtab after failed mount" && rc=11
406         umount_client $MOUNT
407         # stop_mds is a no-op here, and should not fail
408         cleanup_nocli || rc=$?
409         if ! combined_mgs_mds ; then
410                 cleanup_5b
411         fi
412         return $rc
413 }
414 run_test 5b "Try to start a client with no MGS (should return errs)"
415
416 test_5c() {
417         grep " $MOUNT " /etc/mtab && \
418                 error false "unexpected entry in mtab before mount" && return 10
419
420         local rc=0
421         start_mds
422         start_ost
423         [ -d $MOUNT ] || mkdir -p $MOUNT
424         local oldfs="${FSNAME}"
425         FSNAME="wrong.${FSNAME}"
426         mount_client $MOUNT || :
427         FSNAME=${oldfs}
428         grep " $MOUNT " /etc/mtab && \
429                 error "$MOUNT entry in mtab after failed mount" && rc=11
430         umount_client $MOUNT
431         cleanup_nocli  || rc=$?
432         return $rc
433 }
434 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
435
436 test_5d() {
437         grep " $MOUNT " /etc/mtab && \
438                 error false "unexpected entry in mtab before mount" && return 10
439
440         [ "$(facet_fstype ost1)" = "zfs" ] &&
441                 skip "LU-2059: no local config for ZFS OSTs" && return
442
443         local rc=0
444         start_ost
445         start_mds
446         stop_ost -f
447         mount_client $MOUNT || rc=1
448         cleanup  || rc=$?
449         grep " $MOUNT " /etc/mtab && \
450                 error "$MOUNT entry in mtab after unmount" && rc=11
451         return $rc
452 }
453 run_test 5d "mount with ost down"
454
455 test_5e() {
456         grep " $MOUNT " /etc/mtab && \
457                 error false "unexpected entry in mtab before mount" && return 10
458
459         local rc=0
460         start_mds
461         start_ost
462
463 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
464         do_facet client "lctl set_param fail_loc=0x80000506"
465         mount_client $MOUNT || echo "mount failed (not fatal)"
466         cleanup  || rc=$?
467         grep " $MOUNT " /etc/mtab && \
468                 error "$MOUNT entry in mtab after unmount" && rc=11
469         return $rc
470 }
471 run_test 5e "delayed connect, don't crash (bug 10268)"
472
473 test_5f() {
474         if combined_mgs_mds ; then
475                 skip "combined mgs and mds"
476                 return 0
477         fi
478
479         grep " $MOUNT " /etc/mtab && \
480                 error false "unexpected entry in mtab before mount" && return 10
481
482         local rc=0
483         start_ost
484         [ -d $MOUNT ] || mkdir -p $MOUNT
485         mount_client $MOUNT &
486         local pid=$!
487         echo client_mount pid is $pid
488
489         sleep 5
490
491         if ! ps -f -p $pid >/dev/null; then
492                 wait $pid
493                 rc=$?
494                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
495                 error "mount returns $rc, expected to hang"
496                 rc=11
497                 cleanup || rc=$?
498                 return $rc
499         fi
500
501         # start mds
502         start_mds
503
504         # mount should succeed after start mds
505         wait $pid
506         rc=$?
507         [ $rc -eq 0 ] || error "mount returned $rc"
508         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
509         cleanup || return $?
510         return $rc
511 }
512 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
513
514 test_6() {
515         setup
516         manual_umount_client
517         mount_client ${MOUNT} || return 87
518         touch $DIR/a || return 86
519         cleanup  || return $?
520 }
521 run_test 6 "manual umount, then mount again"
522
523 test_7() {
524         setup
525         manual_umount_client
526         cleanup_nocli || return $?
527 }
528 run_test 7 "manual umount, then cleanup"
529
530 test_8() {
531         setup
532         mount_client $MOUNT2
533         check_mount2 || return 45
534         umount_client $MOUNT2
535         cleanup  || return $?
536 }
537 run_test 8 "double mount setup"
538
539 test_9() {
540         start_ost
541
542         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
543         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
544
545         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
546         if [ "$CHECK_PTLDEBUG" ] && { \
547            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
548            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
549            echo "lnet.debug success"
550         else
551            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
552            return 1
553         fi
554         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
555         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
556            echo "lnet.subsystem_debug success"
557         else
558            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
559            return 1
560         fi
561         stop_ost || return $?
562 }
563 run_test 9 "test ptldebug and subsystem for mkfs"
564
565 is_blkdev () {
566         local facet=$1
567         local dev=$2
568         local size=${3:-""}
569
570         local rc=0
571         do_facet $facet "test -b $dev" || rc=1
572         if [[ "$size" ]]; then
573                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
574                         awk '($3 == "in") { print $1 }')
575                 [[ $in  = "1+0" ]] || rc=1
576         fi
577         return $rc
578 }
579
580 #
581 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
582 # But with new MDS stack we don't care about the mode of local objects
583 # anymore, so this test is removed. See bug 22944 for more details.
584 #
585
586 test_17() {
587         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
588                 skip "Only applicable to ldiskfs-based MDTs"
589                 return
590         fi
591
592         setup
593         check_mount || return 41
594         cleanup || return $?
595
596         echo "Remove mds config log"
597         if ! combined_mgs_mds ; then
598                 stop mgs
599         fi
600
601         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MGSDEV || return \$?" || return $?
602
603         if ! combined_mgs_mds ; then
604                 start_mgs
605         fi
606
607         start_ost
608         start_mds && return 42
609         reformat_and_config
610 }
611 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
612
613 test_18() {
614         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
615                 skip "Only applicable to ldiskfs-based MDTs"
616                 return
617         fi
618
619         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
620
621         local MIN=2000000
622
623         local OK=
624         # check if current MDSSIZE is large enough
625         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
626                 log "use MDSSIZE=$MDSSIZE"
627
628         # check if the global config has a large enough MDSSIZE
629         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
630                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
631                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
632
633         # check if the block device is large enough
634         [ -z "$OK" ] && $(is_blkdev $SINGLEMDS $MDSDEV $MIN) && OK=1 &&
635                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
636
637         # check if a loopback device has enough space for fs metadata (5%)
638
639         if [ -z "$OK" ]; then
640                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
641                         awk '($1 != "Filesystem") {print $4}')
642                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
643                         OK=1 && myMDSSIZE=$MIN && \
644                         log "use file $MDSDEV with MIN=$MIN"
645         fi
646
647         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
648
649
650         echo "mount mds with large journal..."
651
652         local OLD_MDSSIZE=$MDSSIZE
653         MDSSIZE=$myMDSSIZE
654
655         reformat_and_config
656         echo "mount lustre system..."
657         setup
658         check_mount || return 41
659
660         echo "check journal size..."
661         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
662         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
663                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
664         else
665                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
666         fi
667
668         cleanup || return $?
669
670         MDSSIZE=$OLD_MDSSIZE
671         reformat_and_config
672 }
673 run_test 18 "check mkfs creates large journals"
674
675 test_19a() {
676         start_mds || return 1
677         stop_mds -f || return 2
678 }
679 run_test 19a "start/stop MDS without OSTs"
680
681 test_19b() {
682         [ "$(facet_fstype ost1)" = "zfs" ] &&
683                 skip "LU-2059: no local config for ZFS OSTs" && return
684
685         start_ost || return 1
686         stop_ost -f || return 2
687 }
688 run_test 19b "start/stop OSTs without MDS"
689
690 test_20() {
691         # first format the ost/mdt
692         start_mds
693         start_ost
694         mount_client $MOUNT
695         check_mount || return 43
696         rm -f $DIR/$tfile
697         remount_client ro $MOUNT || return 44
698         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
699         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
700         remount_client rw $MOUNT || return 47
701         touch $DIR/$tfile
702         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
703         MCNT=`grep -c $MOUNT /etc/mtab`
704         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
705         umount_client $MOUNT
706         stop_mds
707         stop_ost
708 }
709 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
710
711 test_21a() {
712         start_mds
713         start_ost
714         wait_osc_import_state mds ost FULL
715         stop_ost
716         stop_mds
717 }
718 run_test 21a "start mds before ost, stop ost first"
719
720 test_21b() {
721         [ "$(facet_fstype ost1)" = "zfs" ] &&
722                 skip "LU-2059: no local config for ZFS OSTs" && return
723
724         start_ost
725         start_mds
726         wait_osc_import_state mds ost FULL
727         stop_mds
728         stop_ost
729 }
730 run_test 21b "start ost before mds, stop mds first"
731
732 test_21c() {
733         start_ost
734         start_mds
735         start_ost2
736         wait_osc_import_state mds ost2 FULL
737         stop_ost
738         stop_ost2
739         stop_mds
740         #writeconf to remove all ost2 traces for subsequent tests
741         writeconf
742 }
743 run_test 21c "start mds between two osts, stop mds last"
744
745 test_21d() {
746         if combined_mgs_mds ; then
747                 skip "need separate mgs device" && return 0
748         fi
749         stopall
750
751         reformat
752
753         start_mgs
754         start_ost
755         start_ost2
756         start_mds
757         wait_osc_import_state mds ost2 FULL
758
759         stop_ost
760         stop_ost2
761         stop_mds
762         stop_mgs
763         #writeconf to remove all ost2 traces for subsequent tests
764         writeconf
765         start_mgs
766 }
767 run_test 21d "start mgs then ost and then mds"
768
769 test_22() {
770         start_mds
771
772         echo Client mount with ost in logs, but none running
773         start_ost
774         # wait until mds connected to ost and open client connection
775         wait_osc_import_state mds ost FULL
776         stop_ost
777         mount_client $MOUNT
778         # check_mount will block trying to contact ost
779         mcreate $DIR/$tfile || return 40
780         rm -f $DIR/$tfile || return 42
781         umount_client $MOUNT
782         pass
783
784         echo Client mount with a running ost
785         start_ost
786         if $GSS; then
787                 # if gss enabled, wait full time to let connection from
788                 # mds to ost be established, due to the mismatch between
789                 # initial connect timeout and gss context negotiation timeout.
790                 # This perhaps could be remove after AT landed.
791                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
792                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
793         fi
794         mount_client $MOUNT
795         wait_osc_import_state mds ost FULL
796         wait_osc_import_state client ost FULL
797         check_mount || return 41
798         pass
799
800         cleanup
801 }
802 run_test 22 "start a client before osts (should return errs)"
803
804 test_23a() {    # was test_23
805         setup
806         # fail mds
807         stop $SINGLEMDS
808         # force down client so that recovering mds waits for reconnect
809         local running=$(grep -c $MOUNT /proc/mounts) || true
810         if [ $running -ne 0 ]; then
811                 echo "Stopping client $MOUNT (opts: -f)"
812                 umount -f $MOUNT
813         fi
814
815         # enter recovery on mds
816         start_mds
817         # try to start a new client
818         mount_client $MOUNT &
819         sleep 5
820         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
821         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
822         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
823         ps --ppid $MOUNT_PID
824         ps --ppid $MOUNT_LUSTRE_PID
825         echo "waiting for mount to finish"
826         ps -ef | grep mount
827         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
828         # SIGTERM works but it does not spread to offspring processses
829         kill -s TERM $MOUNT_PID
830         kill -s TERM $MOUNT_LUSTRE_PID
831         # we can not wait $MOUNT_PID because it is not a child of this shell
832         local PID1
833         local PID2
834         local WAIT=0
835         local MAX_WAIT=30
836         local sleep=1
837         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
838                 sleep $sleep
839                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
840                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
841                 echo PID1=$PID1
842                 echo PID2=$PID2
843                 [ -z "$PID1" -a -z "$PID2" ] && break
844                 echo "waiting for mount to finish ... "
845                 WAIT=$(( WAIT + sleep))
846         done
847         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
848                 error "MOUNT_PID $MOUNT_PID and "\
849                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
850                 ps -ef | grep mount
851         fi
852         stop_mds || error
853         stop_ost || error
854 }
855 run_test 23a "interrupt client during recovery mount delay"
856
857 umount_client $MOUNT
858 cleanup_nocli
859
860 test_23b() {    # was test_23
861         start_mds
862         start_ost
863         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
864         lctl set_param fail_loc=0x80000313
865         mount_client $MOUNT
866         cleanup
867 }
868 run_test 23b "Simulate -EINTR during mount"
869
870 fs2mds_HOST=$mds_HOST
871 fs2ost_HOST=$ost_HOST
872
873 MDSDEV1_2=$fs2mds_DEV
874 OSTDEV1_2=$fs2ost_DEV
875 OSTDEV2_2=$fs3ost_DEV
876
877 cleanup_24a() {
878         trap 0
879         echo "umount $MOUNT2 ..."
880         umount $MOUNT2 || true
881         echo "stopping fs2mds ..."
882         stop fs2mds -f || true
883         echo "stopping fs2ost ..."
884         stop fs2ost -f || true
885 }
886
887 test_24a() {
888         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
889
890         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
891                 is_blkdev $SINGLEMDS $MDSDEV && \
892                 skip_env "mixed loopback and real device not working" && return
893         fi
894
895         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
896
897         local fs2mdsdev=$(mdsdevname 1_2)
898         local fs2ostdev=$(ostdevname 1_2)
899         local fs2mdsvdev=$(mdsvdevname 1_2)
900         local fs2ostvdev=$(ostvdevname 1_2)
901
902         # test 8-char fsname as well
903         local FSNAME2=test1234
904         add fs2mds $(mkfs_opts mds1) --nomgs --mgsnode=$MGSNID \
905                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
906
907         add fs2ost $(mkfs_opts ost1) --fsname=${FSNAME2} --reformat \
908                 $fs2ostdev $fs2ostvdev || exit 10
909
910         setup
911         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
912         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
913         mkdir -p $MOUNT2
914         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
915         # 1 still works
916         check_mount || return 2
917         # files written on 1 should not show up on 2
918         cp /etc/passwd $DIR/$tfile
919         sleep 10
920         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
921         # 2 should work
922         sleep 5
923         cp /etc/passwd $MOUNT2/b || return 3
924         rm $MOUNT2/b || return 4
925         # 2 is actually mounted
926         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
927         # failover
928         facet_failover fs2mds
929         facet_failover fs2ost
930         df
931         umount_client $MOUNT
932         # the MDS must remain up until last MDT
933         stop_mds
934         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
935         [ -z "$MDS" ] && error "No MDT" && return 8
936         cleanup_24a
937         cleanup_nocli || return 6
938 }
939 run_test 24a "Multiple MDTs on a single node"
940
941 test_24b() {
942         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
943
944         if [ -z "$fs2mds_DEV" ]; then
945                 local dev=${SINGLEMDS}_dev
946                 local MDSDEV=${!dev}
947                 is_blkdev $SINGLEMDS $MDSDEV && \
948                 skip_env "mixed loopback and real device not working" && return
949         fi
950
951         local fs2mdsdev=$(mdsdevname 1_2)
952         local fs2mdsvdev=$(mdsvdevname 1_2)
953
954         add fs2mds $(mkfs_opts mds1) --mgs --fsname=${FSNAME}2 --reformat \
955                 $fs2mdsdev $fs2mdsvdev || exit 10
956         setup
957         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
958         cleanup || return 6
959 }
960 run_test 24b "Multiple MGSs on a single node (should return err)"
961
962 test_25() {
963         setup
964         check_mount || return 2
965         local MODULES=$($LCTL modules | awk '{ print $2 }')
966         rmmod $MODULES 2>/dev/null || true
967         cleanup || return 6
968 }
969 run_test 25 "Verify modules are referenced"
970
971 test_26() {
972     load_modules
973     # we need modules before mount for sysctl, so make sure...
974     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
975 #define OBD_FAIL_MDS_FS_SETUP            0x135
976     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
977     start_mds && echo MDS started && return 1
978     lctl get_param -n devices
979     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
980     [ $DEVS -gt 0 ] && return 2
981     # start mds to drop writeconf setting
982     start_mds || return 3
983     stop_mds || return 4
984     unload_modules_conf || return $?
985 }
986 run_test 26 "MDT startup failure cleans LOV (should return errs)"
987
988 test_27a() {
989         [ "$(facet_fstype ost1)" = "zfs" ] &&
990                 skip "LU-2059: no local config for ZFS OSTs" && return
991
992         start_ost || return 1
993         start_mds || return 2
994         echo "Requeue thread should have started: "
995         ps -e | grep ll_cfg_requeue
996         set_conf_param_and_check ost1                                         \
997            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
998            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
999         cleanup_nocli
1000 }
1001 run_test 27a "Reacquire MGS lock if OST started first"
1002
1003 test_27b() {
1004         # FIXME. ~grev
1005         setup
1006         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
1007
1008         facet_failover $SINGLEMDS
1009         set_conf_param_and_check $SINGLEMDS                             \
1010                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
1011                 "$device.mdt.identity_acquire_expire" || return 3
1012         set_conf_param_and_check client                                 \
1013                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1014                 "$device.mdc.max_rpcs_in_flight" || return 4
1015         check_mount
1016         cleanup
1017 }
1018 run_test 27b "Reacquire MGS lock after failover"
1019
1020 test_28() {
1021         setup
1022         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1023         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1024         ORIG=$($TEST)
1025         FINAL=$(($ORIG + 1))
1026         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1027         FINAL=$(($FINAL + 1))
1028         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1029         umount_client $MOUNT || return 200
1030         mount_client $MOUNT
1031         RESULT=$($TEST)
1032         if [ $RESULT -ne $FINAL ]; then
1033             echo "New config not seen: wanted $FINAL got $RESULT"
1034             return 4
1035         else
1036             echo "New config success: got $RESULT"
1037         fi
1038         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1039         cleanup
1040 }
1041 run_test 28 "permanent parameter setting"
1042
1043 test_29() {
1044         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1045         setup > /dev/null 2>&1
1046         start_ost2
1047         sleep 10
1048
1049         local PARAM="$FSNAME-OST0001.osc.active"
1050         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1051         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1052
1053         ACTV=$(lctl get_param -n $PROC_ACT)
1054         DEAC=$((1 - $ACTV))
1055         set_conf_param_and_check client \
1056                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1057         # also check ost_server_uuid status
1058         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1059         if [ -z "$RESULT" ]; then
1060             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1061             return 3
1062         else
1063             echo "Live client success: got $RESULT"
1064         fi
1065
1066         # check MDT too
1067         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0001)
1068         mdtosc=${mdtosc/-MDT*/-MDT\*}
1069         local MPROC="osc.$mdtosc.active"
1070         local MAX=30
1071         local WAIT=0
1072         while [ 1 ]; do
1073             sleep 5
1074             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
1075             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1076             if [ $RESULT -eq $DEAC ]; then
1077                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
1078                 break
1079             fi
1080             WAIT=$((WAIT + 5))
1081             if [ $WAIT -eq $MAX ]; then
1082                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
1083                 return 4
1084             fi
1085             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
1086         done
1087
1088         # test new client starts deactivated
1089         umount_client $MOUNT || return 200
1090         mount_client $MOUNT
1091         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1092         if [ -z "$RESULT" ]; then
1093             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1094             return 5
1095         else
1096             echo "New client success: got $RESULT"
1097         fi
1098
1099         # make sure it reactivates
1100         set_conf_param_and_check client \
1101                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1102
1103         umount_client $MOUNT
1104         stop_ost2
1105         cleanup_nocli
1106         #writeconf to remove all ost2 traces for subsequent tests
1107         writeconf
1108 }
1109 run_test 29 "permanently remove an OST"
1110
1111 test_30a() {
1112         setup
1113
1114         echo Big config llog
1115         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1116         ORIG=$($TEST)
1117         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1118         for i in ${LIST[@]}; do
1119                 set_conf_param_and_check client "$TEST" \
1120                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1121         done
1122         # make sure client restart still works
1123         umount_client $MOUNT
1124         mount_client $MOUNT || return 4
1125         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1126         pass
1127
1128         echo Erase parameter setting
1129         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1130         umount_client $MOUNT
1131         mount_client $MOUNT || return 6
1132         FINAL=$($TEST)
1133         echo "deleted (default) value=$FINAL, orig=$ORIG"
1134         # assumes this parameter started at the default value
1135         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1136
1137         cleanup
1138 }
1139 run_test 30a "Big config llog and conf_param deletion"
1140
1141 test_30b() {
1142         setup
1143
1144         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1145         # numerical part of it. Hopefully that's not already a failover address for
1146         # the server.
1147         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1148         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1149         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1150         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1151         echo "Using fake nid $NEW"
1152
1153         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1154         set_conf_param_and_check client "$TEST" \
1155                 "$FSNAME-OST0000.failover.node" $NEW ||
1156                 error "didn't add failover nid $NEW"
1157         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1158         echo $NIDS
1159         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1160         echo "should have 2 failover nids: $NIDCOUNT"
1161         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1162         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1163         umount_client $MOUNT
1164         mount_client $MOUNT || return 3
1165
1166         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1167         echo $NIDS
1168         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1169         echo "only 1 final nid should remain: $NIDCOUNT"
1170         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1171
1172         cleanup
1173 }
1174 run_test 30b "Remove failover nids"
1175
1176 test_31() { # bug 10734
1177         # ipaddr must not exist
1178         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1179         cleanup
1180 }
1181 run_test 31 "Connect to non-existent node (shouldn't crash)"
1182
1183 #
1184 # This is not really a test but a tool to create new disk
1185 # image tarballs for the upgrade tests.
1186 #
1187 # Disk image tarballs should be created on single-node
1188 # clusters by running this test with default configurations
1189 # plus a few mandatory environment settings that are verified
1190 # at the beginning of the test.
1191 #
1192 test_32newtarball() {
1193         local version
1194         local dst=.
1195         local src=/etc/rc.d
1196         local tmp=$TMP/t32_image_create
1197
1198         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1199                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1200                  -z "$OSTDEV1" ]; then
1201                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1202                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1203                           "OSTDEV1=<nonexistent_file>"
1204         fi
1205
1206         mkdir $tmp || {
1207                 echo "Found stale $tmp"
1208                 return 1
1209         }
1210
1211         mkdir $tmp/src
1212         tar cf - -C $src . | tar xf - -C $tmp/src
1213
1214         formatall
1215
1216         setupall
1217         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1218         stopall
1219
1220         mkdir $tmp/img
1221
1222         setupall
1223         pushd /mnt/$FSNAME
1224         ls -Rni --time-style=+%s >$tmp/img/list
1225         find . ! -name .lustre -type f -exec sha1sum {} \; |
1226                 sort -k 2 >$tmp/img/sha1sums
1227         popd
1228         $LCTL get_param -n version | head -n 1 |
1229                 sed -e 's/^lustre: *//' >$tmp/img/commit
1230         stopall
1231
1232         pushd $tmp/src
1233         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1234         popd
1235
1236         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1237                 echo "Data verification failed"
1238         fi
1239
1240         uname -r >$tmp/img/kernel
1241         uname -m >$tmp/img/arch
1242
1243         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1244         mv $OSTDEV1 $tmp/img
1245
1246         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1247                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1248         dst=$(cd $dst; pwd)
1249         pushd $tmp/img
1250         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1251         popd
1252
1253         rm -r $tmp
1254 }
1255 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1256
1257 #
1258 # The list of applicable tarballs is returned via the caller's
1259 # variable "tarballs".
1260 #
1261 t32_check() {
1262         local node=$(facet_active_host $SINGLEMDS)
1263         local r="do_node $node"
1264
1265         if [ "$CLIENTONLY" ]; then
1266                 skip "Client-only testing"
1267                 exit 0
1268         fi
1269
1270         if ! $r which $TUNEFS; then
1271                 skip_env "tunefs.lustre required on $node"
1272                 exit 0
1273         fi
1274
1275         if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1276                 skip "LU-2200: Test cannot run over Infiniband"
1277                 exit 0
1278         fi
1279
1280         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1281
1282         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1283
1284         if [ -z "$tarballs" ]; then
1285                 skip "No applicable tarballs found"
1286                 exit 0
1287         fi
1288 }
1289
1290 t32_test_cleanup() {
1291         local node=$(facet_active_host $SINGLEMDS)
1292         local r="do_node $node"
1293         local tmp=$TMP/t32
1294         local rc=$?
1295
1296         if $shall_cleanup_lustre; then
1297                 umount $tmp/mnt/lustre || rc=$?
1298         fi
1299         if $shall_cleanup_mdt; then
1300                 $r umount -d $tmp/mnt/mdt || rc=$?
1301         fi
1302         if $shall_cleanup_ost; then
1303                 $r umount -d $tmp/mnt/ost || rc=$?
1304         fi
1305         $r rm -rf $tmp || rc=$?
1306         rm -rf $tmp || rc=$?
1307         return $rc
1308 }
1309
1310 t32_bits_per_long() {
1311         #
1312         # Yes, this is not meant to be perfect.
1313         #
1314         case $1 in
1315                 ppc64|x86_64)
1316                         echo -n 64;;
1317                 i*86)
1318                         echo -n 32;;
1319         esac
1320 }
1321
1322 t32_reload_modules() {
1323         local node=$1
1324         local all_removed=false
1325         local i=0
1326
1327         while ((i < 20)); do
1328                 echo "Unloading modules on $node: Attempt $i"
1329                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1330                         all_removed=true
1331                 do_rpc_nodes $node check_mem_leak || return 1
1332                 if $all_removed; then
1333                         load_modules
1334                         return 0
1335                 fi
1336                 sleep 5
1337                 i=$((i + 1))
1338         done
1339         echo "Unloading modules on $node: Given up"
1340         return 1
1341 }
1342
1343 t32_wait_til_devices_gone() {
1344         local node=$1
1345         local devices
1346         local i=0
1347
1348         echo wait for devices to go
1349         while ((i < 20)); do
1350                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1351                 echo $device
1352                 ((devices == 0)) && return 1
1353                 sleep 5
1354                 i=$((i + 1))
1355         done
1356         echo "waiting for devices on $node: Given up"
1357         return 1
1358 }
1359
1360 t32_test() {
1361         local tarball=$1
1362         local writeconf=$2
1363         local shall_cleanup_mdt=false
1364         local shall_cleanup_ost=false
1365         local shall_cleanup_lustre=false
1366         local node=$(facet_active_host $SINGLEMDS)
1367         local r="do_node $node"
1368         local tmp=$TMP/t32
1369         local img_commit
1370         local img_kernel
1371         local img_arch
1372         local fsname=t32fs
1373         local nid=$($r $LCTL list_nids | head -1)
1374         local mopts
1375         local uuid
1376         local nrpcs_orig
1377         local nrpcs
1378         local list
1379
1380         trap 'trap - RETURN; t32_test_cleanup' RETURN
1381
1382         mkdir -p $tmp/mnt/lustre
1383         $r mkdir -p $tmp/mnt/{mdt,ost}
1384         $r tar xjvf $tarball -S -C $tmp || {
1385                 error_noexit "Unpacking the disk image tarball"
1386                 return 1
1387         }
1388         img_commit=$($r cat $tmp/commit)
1389         img_kernel=$($r cat $tmp/kernel)
1390         img_arch=$($r cat $tmp/arch)
1391         echo "Upgrading from $(basename $tarball), created with:"
1392         echo "  Commit: $img_commit"
1393         echo "  Kernel: $img_kernel"
1394         echo "    Arch: $img_arch"
1395
1396         $r $LCTL set_param debug="$PTLDEBUG"
1397
1398         $r $TUNEFS --dryrun $tmp/mdt || {
1399                 error_noexit "tunefs.lustre before mounting the MDT"
1400                 return 1
1401         }
1402         if [ "$writeconf" ]; then
1403                 mopts=loop,writeconf
1404         else
1405                 mopts=loop,exclude=$fsname-OST0000
1406         fi
1407
1408         t32_wait_til_devices_gone $node
1409
1410         $r mount -t lustre -o $mopts $tmp/mdt $tmp/mnt/mdt || {
1411                 error_noexit "Mounting the MDT"
1412                 return 1
1413         }
1414         shall_cleanup_mdt=true
1415
1416         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1417                 error_noexit "Getting MDT UUID"
1418                 return 1
1419         }
1420         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1421                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1422                 return 1
1423         fi
1424
1425         $r $TUNEFS --dryrun $tmp/ost || {
1426                 error_noexit "tunefs.lustre before mounting the OST"
1427                 return 1
1428         }
1429         if [ "$writeconf" ]; then
1430                 mopts=loop,mgsnode=$nid,$writeconf
1431         else
1432                 mopts=loop,mgsnode=$nid
1433         fi
1434         $r mount -t lustre -o $mopts $tmp/ost $tmp/mnt/ost || {
1435                 error_noexit "Mounting the OST"
1436                 return 1
1437         }
1438         shall_cleanup_ost=true
1439
1440         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1441                 error_noexit "Getting OST UUID"
1442                 return 1
1443         }
1444         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1445                 error_noexit "Unexpected OST UUID: \"$uuid\""
1446                 return 1
1447         fi
1448
1449         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1450                 error_noexit "Setting \"max_dirty_mb\""
1451                 return 1
1452         }
1453         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1454                 error_noexit "Setting OST \"failover.node\""
1455                 return 1
1456         }
1457         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1458                 error_noexit "Setting \"max_rpcs_in_flight\""
1459                 return 1
1460         }
1461         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1462                 error_noexit "Setting MDT \"failover.node\""
1463                 return 1
1464         }
1465         $r $LCTL pool_new $fsname.interop || {
1466                 error_noexit "Setting \"interop\""
1467                 return 1
1468         }
1469         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1470                 error_noexit "Setting \"lov.stripesize\""
1471                 return 1
1472         }
1473
1474         if [ "$writeconf" ]; then
1475                 mount -t lustre $nid:/$fsname $tmp/mnt/lustre || {
1476                         error_noexit "Mounting the client"
1477                         return 1
1478                 }
1479                 shall_cleanup_lustre=true
1480                 $LCTL set_param debug="$PTLDEBUG"
1481
1482                 if $r test -f $tmp/sha1sums; then
1483                         $r sort -k 2 $tmp/sha1sums >$tmp/sha1sums.orig
1484                         pushd $tmp/mnt/lustre
1485                         find ! -name .lustre -type f -exec sha1sum {} \; |
1486                                 sort -k 2 >$tmp/sha1sums || {
1487                                 error_noexit "sha1sum"
1488                                 return 1
1489                         }
1490                         popd
1491                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1492                                 error_noexit "sha1sum verification failed"
1493                                 return 1
1494                         fi
1495                 else
1496                         echo "sha1sum verification skipped"
1497                 fi
1498
1499                 if $r test -f $tmp/list; then
1500                         #
1501                         # There is not a Test Framework API to copy files to or
1502                         # from a remote node.
1503                         #
1504                         $r sort -k 6 $tmp/list >$tmp/list.orig
1505                         pushd $tmp/mnt/lustre
1506                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1507                                 error_noexit "ls"
1508                                 return 1
1509                         }
1510                         popd
1511                         #
1512                         # 32-bit and 64-bit clients use different algorithms to
1513                         # convert FIDs into inode numbers.  Hence, remove the inode
1514                         # numbers from the lists, if the original list was created
1515                         # on an architecture with different number of bits per
1516                         # "long".
1517                         #
1518                         if [ $(t32_bits_per_long $(uname -m)) !=                                                \
1519                                  $(t32_bits_per_long $img_arch) ]; then
1520                                 echo "Different number of bits per \"long\" from the disk image"
1521                                 for list in list.orig list; do
1522                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1523                                 done
1524                         fi
1525                         if ! diff -ub $tmp/list.orig $tmp/list; then
1526                                 error_noexit "list verification failed"
1527                                 return 1
1528                         fi
1529                 else
1530                         echo "list verification skipped"
1531                 fi
1532
1533                 #
1534                 # When adding new data verification tests, please check for
1535                 # the presence of the required reference files first, like
1536                 # the "sha1sums" and "list" tests above, to avoid the need to
1537                 # regenerate every image for each test addition.
1538                 #
1539
1540                 nrpcs_orig=$($LCTL get_param -n mdc.*.max_rpcs_in_flight) || {
1541                         error_noexit "Getting \"max_rpcs_in_flight\""
1542                         return 1
1543                 }
1544                 nrpcs=$((nrpcs_orig + 5))
1545                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1546                         error_noexit "Changing \"max_rpcs_in_flight\""
1547                         return 1
1548                 }
1549                 wait_update $HOSTNAME "$LCTL get_param -n mdc.*.max_rpcs_in_flight"     \
1550                             $nrpcs || {
1551                         error_noexit "Verifying \"max_rpcs_in_flight\""
1552                         return 1
1553                 }
1554
1555                 umount $tmp/mnt/lustre || {
1556                         error_noexit "Unmounting the client"
1557                         return 1
1558                 }
1559                 shall_cleanup_lustre=false
1560         else
1561                 $r umount -d $tmp/mnt/mdt || {
1562                         error_noexit "Unmounting the MDT"
1563                         return 1
1564                 }
1565                 shall_cleanup_mdt=false
1566                 $r umount -d $tmp/mnt/ost || {
1567                         error_noexit "Unmounting the OST"
1568                         return 1
1569                 }
1570                 shall_cleanup_ost=false
1571
1572                 t32_reload_modules $node || {
1573                         error_noexit "Reloading modules"
1574                         return 1
1575                 }
1576
1577                 # mount a second time to make sure we didnt leave upgrade flag on
1578                 $r $TUNEFS --dryrun $tmp/mdt || {
1579                         error_noexit "tunefs.lustre before remounting the MDT"
1580                         return 1
1581                 }
1582                 $r mount -t lustre -o loop,exclude=$fsname-OST0000 $tmp/mdt                     \
1583                                  $tmp/mnt/mdt || {
1584                         error_noexit "Remounting the MDT"
1585                         return 1
1586                 }
1587                 shall_cleanup_mdt=true
1588         fi
1589 }
1590
1591 test_32a() {
1592         local tarballs
1593         local tarball
1594         local rc=0
1595
1596         t32_check
1597         for tarball in $tarballs; do
1598                 t32_test $tarball || rc=$?
1599         done
1600         return $rc
1601 }
1602 run_test 32a "Upgrade (not live)"
1603
1604 test_32b() {
1605         local tarballs
1606         local tarball
1607         local rc=0
1608
1609         t32_check
1610         for tarball in $tarballs; do
1611                 t32_test $tarball writeconf || rc=$?
1612         done
1613         return $rc
1614 }
1615 run_test 32b "Upgrade with writeconf"
1616
1617 test_33a() { # bug 12333, was test_33
1618         local rc=0
1619         local FSNAME2=test-123
1620         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1621         local mkfsoptions
1622
1623         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1624
1625         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1626                 local dev=${SINGLEMDS}_dev
1627                 local MDSDEV=${!dev}
1628                 is_blkdev $SINGLEMDS $MDSDEV && \
1629                 skip_env "mixed loopback and real device not working" && return
1630         fi
1631
1632         local fs2mdsdev=$(mdsdevname 1_2)
1633         local fs2ostdev=$(ostdevname 1_2)
1634         local fs2mdsvdev=$(mdsvdevname 1_2)
1635         local fs2ostvdev=$(ostvdevname 1_2)
1636
1637         if [ $(facet_fstype mds1) == ldiskfs ]; then
1638                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
1639         fi
1640
1641         add fs2mds $(mkfs_opts mds1) --fsname=${FSNAME2} --reformat \
1642                 $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
1643         add fs2ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1644                 --index=8191 --reformat $fs2ostdev $fs2ostvdev || exit 10
1645
1646         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1647         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1648         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1649         mkdir -p $MOUNT2
1650         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1651         echo "ok."
1652
1653         cp /etc/hosts $MOUNT2/ || rc=3
1654         $LFS getstripe $MOUNT2/hosts
1655
1656         umount -d $MOUNT2
1657         stop fs2ost -f
1658         stop fs2mds -f
1659         cleanup_nocli || rc=6
1660         return $rc
1661 }
1662 run_test 33a "Mount ost with a large index number"
1663
1664 test_33b() {    # was test_34
1665         setup
1666
1667         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1668         # Drop lock cancelation reply during umount
1669         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
1670         do_facet client lctl set_param fail_loc=0x80000304
1671         #lctl set_param debug=-1
1672         umount_client $MOUNT
1673         cleanup
1674 }
1675 run_test 33b "Drop cancel during umount"
1676
1677 test_34a() {
1678         setup
1679         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1680         manual_umount_client
1681         rc=$?
1682         do_facet client killall -USR1 multiop
1683         if [ $rc -eq 0 ]; then
1684                 error "umount not fail!"
1685         fi
1686         sleep 1
1687         cleanup
1688 }
1689 run_test 34a "umount with opened file should be fail"
1690
1691
1692 test_34b() {
1693         setup
1694         touch $DIR/$tfile || return 1
1695         stop_mds --force || return 2
1696
1697         manual_umount_client --force
1698         rc=$?
1699         if [ $rc -ne 0 ]; then
1700                 error "mtab after failed umount - rc $rc"
1701         fi
1702
1703         cleanup
1704         return 0
1705 }
1706 run_test 34b "force umount with failed mds should be normal"
1707
1708 test_34c() {
1709         setup
1710         touch $DIR/$tfile || return 1
1711         stop_ost --force || return 2
1712
1713         manual_umount_client --force
1714         rc=$?
1715         if [ $rc -ne 0 ]; then
1716                 error "mtab after failed umount - rc $rc"
1717         fi
1718
1719         cleanup
1720         return 0
1721 }
1722 run_test 34c "force umount with failed ost should be normal"
1723
1724 test_35a() { # bug 12459
1725         setup
1726
1727         DBG_SAVE="`lctl get_param -n debug`"
1728         lctl set_param debug="ha"
1729
1730         log "Set up a fake failnode for the MDS"
1731         FAKENID="127.0.0.2"
1732         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1733         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1734                 "$(h2$NETTYPE $FAKENID)" || return 4
1735
1736         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1737         sleep 10
1738
1739         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1740         $LCTL clear
1741         log "$MSG"
1742         log "Stopping the MDT:"
1743         stop_mds || return 5
1744
1745         df $MOUNT > /dev/null 2>&1 &
1746         DFPID=$!
1747         log "Restarting the MDT:"
1748         start_mds || return 6
1749         log "Wait for df ($DFPID) ... "
1750         wait $DFPID
1751         log "done"
1752         lctl set_param debug="$DBG_SAVE"
1753
1754         # retrieve from the log the first server that the client tried to
1755         # contact after the connection loss
1756         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1757         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1758                        /import_select_connection.*$device-mdc.* using connection/ {
1759                                 if (start) {
1760                                         if (\\\$NF ~ /$FAKENID/)
1761                                                 print \\\$NF;
1762                                         else
1763                                                 print 0;
1764                                         exit;
1765                                 }
1766                        }" $TMP/lustre-log-$TESTNAME.log`
1767         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1768         cleanup
1769         # remove nid settings
1770         writeconf
1771 }
1772 run_test 35a "Reconnect to the last active server first"
1773
1774 test_35b() { # bug 18674
1775         remote_mds || { skip "local MDS" && return 0; }
1776         setup
1777
1778         debugsave
1779         $LCTL set_param debug="ha"
1780         $LCTL clear
1781         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1782         log "$MSG"
1783
1784         log "Set up a fake failnode for the MDS"
1785         FAKENID="127.0.0.2"
1786         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" | \
1787                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1788         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1789                 "$(h2$NETTYPE $FAKENID)" || return 1
1790
1791         local at_max_saved=0
1792         # adaptive timeouts may prevent seeing the issue
1793         if at_is_enabled; then
1794                 at_max_saved=$(at_max_get mds)
1795                 at_max_set 0 mds client
1796         fi
1797
1798         mkdir -p $MOUNT/$tdir
1799
1800         log "Injecting EBUSY on MDS"
1801         # Setting OBD_FAIL_MDS_RESEND=0x136
1802         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
1803
1804         $LCTL set_param mdc.${FSNAME}*.stats=clear
1805
1806         log "Creating a test file and stat it"
1807         touch $MOUNT/$tdir/$tfile
1808         stat $MOUNT/$tdir/$tfile
1809
1810         log "Stop injecting EBUSY on MDS"
1811         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
1812         rm -f $MOUNT/$tdir/$tfile
1813
1814         log "done"
1815         # restore adaptive timeout
1816         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1817
1818         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1819
1820         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1821
1822         # retrieve from the log if the client has ever tried to
1823         # contact the fake server after the loss of connection
1824         FAILCONN=`awk "BEGIN {ret = 0;}
1825                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1826                                 ret = 1;
1827                                 if (\\\$NF ~ /$FAKENID/) {
1828                                         ret = 2;
1829                                         exit;
1830                                 }
1831                        }
1832                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1833
1834         [ "$FAILCONN" == "0" ] && \
1835                 log "ERROR: The client reconnection has not been triggered" && \
1836                 return 4
1837         [ "$FAILCONN" == "2" ] && \
1838                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1839                 return 5
1840
1841         # LU-290
1842         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1843         # Reconnects are supposed to be rate limited to one every 5s
1844         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1845                 log "ERROR: Too many reconnects $CONNCNT" && \
1846                 return 6
1847
1848         cleanup
1849         # remove nid settings
1850         writeconf
1851 }
1852 run_test 35b "Continue reconnection retries, if the active server is busy"
1853
1854 test_36() { # 12743
1855         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1856
1857         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1858                 { skip "remote OST" && return 0; }
1859
1860         local rc=0
1861         local FSNAME2=test1234
1862         local fs3ost_HOST=$ost_HOST
1863         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1864
1865         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1866
1867         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1868                 is_blkdev $SINGLEMDS $MDSDEV && \
1869                 skip_env "mixed loopback and real device not working" && return
1870         fi
1871
1872         local fs2mdsdev=$(mdsdevname 1_2)
1873         local fs2ostdev=$(ostdevname 1_2)
1874         local fs3ostdev=$(ostdevname 2_2)
1875         local fs2mdsvdev=$(mdsvdevname 1_2)
1876         local fs2ostvdev=$(ostvdevname 1_2)
1877         local fs3ostvdev=$(ostvdevname 2_2)
1878
1879         add fs2mds $(mkfs_opts mds1) --fsname=${FSNAME2} --reformat \
1880                 $fs2mdsdev $fs2mdsvdev || exit 10
1881         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
1882         #     different one than the default value here.
1883         add fs2ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1884                 --reformat $fs2ostdev $fs2ostvdev || exit 10
1885         add fs3ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1886                 --reformat $fs3ostdev $fs3ostvdev || exit 10
1887
1888         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1889         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1890         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1891         mkdir -p $MOUNT2
1892         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1893
1894         sleep 5 # until 11778 fixed
1895
1896         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1897
1898         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1899         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1900         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1901         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1902         DFTOTAL=`echo $STRING | cut -d, -f1`
1903         DFUSED=`echo $STRING  | cut -d, -f2`
1904         DFAVAIL=`echo $STRING | cut -d, -f3`
1905         DFFREE=$(($DFTOTAL - $DFUSED))
1906
1907         ALLOWANCE=$((64 * $OSTCOUNT))
1908
1909         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1910            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1911                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1912                 rc=1
1913         fi
1914         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1915            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1916                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1917                 rc=2
1918         fi
1919         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1920            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1921                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1922                 rc=3
1923        fi
1924
1925         umount -d $MOUNT2
1926         stop fs3ost -f || return 200
1927         stop fs2ost -f || return 201
1928         stop fs2mds -f || return 202
1929         unload_modules_conf || return 203
1930         return $rc
1931 }
1932 run_test 36 "df report consistency on OSTs with different block size"
1933
1934 test_37() {
1935         local mntpt=$(facet_mntpt $SINGLEMDS)
1936         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
1937         local mdsdev_sym="$TMP/sym_mdt.img"
1938         local opts=$MDS_MOUNT_OPTS
1939         local rc=0
1940
1941         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1942                 skip "Currently only applicable to ldiskfs-based MDTs"
1943                 return
1944         fi
1945
1946         echo "MDS :     $mdsdev"
1947         echo "SYMLINK : $mdsdev_sym"
1948         do_facet $SINGLEMDS rm -f $mdsdev_sym
1949
1950         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
1951
1952         echo "mount symlink device - $mdsdev_sym"
1953
1954         if ! do_facet $SINGLEMDS test -b $mdsdev; then
1955                 opts=$(csa_add "$opts" -o loop)
1956         fi
1957         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
1958                 $mdsdev_sym $mntpt 2>&1)
1959         rc=${PIPESTATUS[0]}
1960
1961         echo mount_op=$mount_op
1962
1963         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
1964
1965         if $(echo $mount_op | grep -q "unable to set tunable"); then
1966                 error "set tunables failed for symlink device"
1967         fi
1968
1969         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
1970
1971         return 0
1972 }
1973 run_test 37 "verify set tunables works for symlink device"
1974
1975 test_38() { # bug 14222
1976         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1977                 skip "Only applicable to ldiskfs-based MDTs"
1978                 return
1979         fi
1980
1981         setup
1982         # like runtests
1983         COUNT=10
1984         SRC="/etc /bin"
1985         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1986         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1987         mkdir -p $DIR/$tdir
1988         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1989                 error "copying $SRC to $DIR/$tdir"
1990         sync
1991         umount_client $MOUNT
1992         stop_mds
1993         log "rename lov_objid file on MDS"
1994         rm -f $TMP/lov_objid.orig
1995
1996         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1997         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1998         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1999
2000         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
2001         # check create in mds_lov_connect
2002         start_mds
2003         mount_client $MOUNT
2004         for f in $FILES; do
2005                 [ $V ] && log "verifying $DIR/$tdir/$f"
2006                 diff -q $f $DIR/$tdir/$f || ERROR=y
2007         done
2008         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
2009         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
2010         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
2011
2012         # check it's updates in sync
2013         umount_client $MOUNT
2014         stop_mds
2015
2016         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
2017         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2018         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
2019
2020         start_mds
2021         mount_client $MOUNT
2022         for f in $FILES; do
2023                 [ $V ] && log "verifying $DIR/$tdir/$f"
2024                 diff -q $f $DIR/$tdir/$f || ERROR=y
2025         done
2026         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
2027         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
2028         umount_client $MOUNT
2029         stop_mds
2030         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
2031
2032         log "files compared the same"
2033         cleanup
2034 }
2035 run_test 38 "MDS recreates missing lov_objid file from OST data"
2036
2037 test_39() {
2038         PTLDEBUG=+malloc
2039         setup
2040         cleanup
2041         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2042                 error "memory leak detected" || true
2043 }
2044 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2045
2046 test_40() { # bug 15759
2047         start_ost
2048         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2049         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2050         start_mds
2051         cleanup
2052 }
2053 run_test 40 "race during service thread startup"
2054
2055 test_41a() { #bug 14134
2056         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2057            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2058                 skip "Loop devices does not work with nosvc option"
2059                 return
2060         fi
2061
2062         local rc
2063         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2064
2065         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2066         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2067         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2068         mkdir -p $MOUNT
2069         mount_client $MOUNT || return 1
2070         sleep 5
2071
2072         echo "blah blah" > $MOUNT/$tfile
2073         cat $MOUNT/$tfile
2074
2075         umount_client $MOUNT
2076         stop ost1 -f || return 201
2077         stop_mds -f || return 202
2078         stop_mds -f || return 203
2079         unload_modules_conf || return 204
2080         return $rc
2081 }
2082 run_test 41a "mount mds with --nosvc and --nomgs"
2083
2084 test_41b() {
2085         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2086            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2087                 skip "Loop devices does not work with nosvc option"
2088                 return
2089         fi
2090
2091         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2092
2093         stopall
2094         reformat
2095         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2096
2097         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2098         start_ost
2099         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2100         mkdir -p $MOUNT
2101         mount_client $MOUNT || return 1
2102         sleep 5
2103
2104         echo "blah blah" > $MOUNT/$tfile
2105         cat $MOUNT/$tfile || return 200
2106
2107         umount_client $MOUNT
2108         stop_ost || return 201
2109         stop_mds -f || return 202
2110         stop_mds -f || return 203
2111
2112 }
2113 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2114
2115 test_42() { #bug 14693
2116         setup
2117         check_mount || return 2
2118         do_facet mgs $LCTL conf_param lustre.llite.some_wrong_param=10
2119         umount_client $MOUNT
2120         mount_client $MOUNT || return 1
2121         cleanup
2122         return 0
2123 }
2124 run_test 42 "invalid config param should not prevent client from mounting"
2125
2126 test_43() {
2127         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2128         setup
2129         chmod ugo+x $DIR || error "chmod 0 failed"
2130         set_conf_param_and_check mds                                    \
2131                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2132                 "$FSNAME.mdt.root_squash"                               \
2133                 "0:0"
2134         set_conf_param_and_check mds                                    \
2135                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2136                 "$FSNAME.mdt.nosquash_nids"                             \
2137                 "NONE"
2138
2139     #
2140     # create set of test files
2141     #
2142     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2143     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2144     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2145
2146     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2147     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2148
2149     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2150     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2151     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2152
2153         #
2154         # check root_squash:
2155         #   set root squash UID:GID to RUNAS_ID
2156         #   root should be able to access only files owned by RUNAS_ID
2157         #
2158         set_conf_param_and_check mds                                    \
2159                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2160                 "$FSNAME.mdt.root_squash"                               \
2161                 "$RUNAS_ID:$RUNAS_ID"
2162
2163     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2164     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2165         error "$ST: root read permission is denied"
2166     echo "$ST: root read permission is granted - ok"
2167
2168     echo "444" | \
2169     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2170         error "$ST: root write permission is denied"
2171     echo "$ST: root write permission is granted - ok"
2172
2173     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2174     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2175         error "$ST: root read permission is granted"
2176     echo "$ST: root read permission is denied - ok"
2177
2178     echo "555" | \
2179     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2180         error "$ST: root write permission is granted"
2181     echo "$ST: root write permission is denied - ok"
2182
2183     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2184     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2185         error "$ST: root unlink permission is granted"
2186     echo "$ST: root unlink permission is denied - ok"
2187
2188     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2189         error "$ST: root create permission is granted"
2190     echo "$ST: root create permission is denied - ok"
2191
2192         #
2193         # check nosquash_nids:
2194         #   put client's NID into nosquash_nids list,
2195         #   root should be able to access root file after that
2196         #
2197         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2198         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2199         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2200         set_conf_param_and_check mds                                    \
2201                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2202                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2203                 "$NIDLIST"
2204
2205     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2206     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2207         error "$ST: root read permission is denied"
2208     echo "$ST: root read permission is granted - ok"
2209
2210     echo "666" | \
2211     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2212         error "$ST: root write permission is denied"
2213     echo "$ST: root write permission is granted - ok"
2214
2215     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2216     rm $DIR/$tdir-rootdir/tfile-1 || \
2217         error "$ST: root unlink permission is denied"
2218     echo "$ST: root unlink permission is granted - ok"
2219     touch $DIR/$tdir-rootdir/tfile-2 || \
2220         error "$ST: root create permission is denied"
2221     echo "$ST: root create permission is granted - ok"
2222
2223     return 0
2224 }
2225 run_test 43 "check root_squash and nosquash_nids"
2226
2227 umount_client $MOUNT
2228 cleanup_nocli
2229
2230 test_44() { # 16317
2231         setup
2232         check_mount || return 2
2233         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2234         STATS_FOUND=no
2235         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2236         for VAL in $UUIDS; do
2237                 NID=$(echo $VAL | cut -d= -f1)
2238                 CLUUID=$(echo $VAL | cut -d= -f2)
2239                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2240         done
2241         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2242         cleanup
2243         return 0
2244 }
2245 run_test 44 "mounted client proc entry exists"
2246
2247 test_45() { #17310
2248         setup
2249         check_mount || return 2
2250         stop_mds
2251         df -h $MOUNT &
2252         log "sleep 60 sec"
2253         sleep 60
2254 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2255         do_facet client "lctl set_param fail_loc=0x50f"
2256         log "sleep 10 sec"
2257         sleep 10
2258         manual_umount_client --force || return 3
2259         do_facet client "lctl set_param fail_loc=0x0"
2260         start_mds
2261         mount_client $MOUNT || return 4
2262         cleanup
2263         return 0
2264 }
2265 run_test 45 "long unlink handling in ptlrpcd"
2266
2267 cleanup_46a() {
2268         trap 0
2269         local rc=0
2270         local count=$1
2271
2272         umount_client $MOUNT2 || rc=$?
2273         umount_client $MOUNT || rc=$?
2274         while [ $count -gt 0 ]; do
2275                 stop ost${count} -f || rc=$?
2276                 let count=count-1
2277         done    
2278         stop_mds || rc=$?
2279         cleanup_nocli || rc=$?
2280         #writeconf to remove all ost2 traces for subsequent tests
2281         writeconf
2282         return $rc
2283 }
2284
2285 test_46a() {
2286         echo "Testing with $OSTCOUNT OSTs"
2287         reformat_and_config
2288         start_mds || return 1
2289         #first client should see only one ost
2290         start_ost || return 2
2291         wait_osc_import_state mds ost FULL
2292         #start_client
2293         mount_client $MOUNT || return 3
2294         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2295
2296         local i
2297         for (( i=2; i<=$OSTCOUNT; i++ )); do
2298             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2299         done
2300
2301         # wait until osts in sync
2302         for (( i=2; i<=$OSTCOUNT; i++ )); do
2303             wait_osc_import_state mds ost$i FULL
2304             wait_osc_import_state client ost$i FULL
2305         done
2306
2307         #second client see all ost's
2308
2309         mount_client $MOUNT2 || return 8
2310         $LFS setstripe -c -1 $MOUNT2 || return 9
2311         $LFS getstripe $MOUNT2 || return 10
2312
2313         echo "ok" > $MOUNT2/widestripe
2314         $LFS getstripe $MOUNT2/widestripe || return 11
2315         # fill acl buffer for avoid expand lsm to them
2316         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2317             setfacl -m $acl $MOUNT2/widestripe
2318         done
2319
2320         # will be deadlock
2321         stat $MOUNT/widestripe || return 12
2322
2323         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2324         return 0
2325 }
2326 run_test 46a "handle ost additional - wide striped file"
2327
2328 test_47() { #17674
2329         reformat
2330         setup_noconfig
2331         check_mount || return 2
2332         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2333
2334         local lru_size=[]
2335         local count=0
2336         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2337             if echo $ns | grep "MDT[[:digit:]]*"; then
2338                 continue
2339             fi
2340             lrs=$(echo $ns | sed 's/.*lru_size=//')
2341             lru_size[count]=$lrs
2342             let count=count+1
2343         done
2344
2345         facet_failover ost1
2346         facet_failover $SINGLEMDS
2347         client_up || return 3
2348
2349         count=0
2350         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2351             if echo $ns | grep "MDT[[:digit:]]*"; then
2352                 continue
2353             fi
2354             lrs=$(echo $ns | sed 's/.*lru_size=//')
2355             if ! test "$lrs" -eq "${lru_size[count]}"; then
2356                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2357                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2358             fi
2359             let count=count+1
2360         done
2361
2362         cleanup
2363         return 0
2364 }
2365 run_test 47 "server restart does not make client loss lru_resize settings"
2366
2367 cleanup_48() {
2368         trap 0
2369
2370         # reformat after this test is needed - if test will failed
2371         # we will have unkillable file at FS
2372         reformat_and_config
2373 }
2374
2375 test_48() { # bug 17636
2376         reformat
2377         setup_noconfig
2378         check_mount || return 2
2379
2380         $LFS setstripe -c -1 $MOUNT || return 9
2381         $LFS getstripe $MOUNT || return 10
2382
2383         echo "ok" > $MOUNT/widestripe
2384         $LFS getstripe $MOUNT/widestripe || return 11
2385
2386         trap cleanup_48 EXIT ERR
2387
2388         # fill acl buffer for avoid expand lsm to them
2389         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2390             setfacl -m $acl $MOUNT/widestripe
2391         done
2392
2393         stat $MOUNT/widestripe || return 12
2394
2395         cleanup_48
2396         return 0
2397 }
2398 run_test 48 "too many acls on file"
2399
2400 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2401 test_49() { # bug 17710
2402         local timeout_orig=$TIMEOUT
2403         local ldlm_timeout_orig=$LDLM_TIMEOUT
2404         local LOCAL_TIMEOUT=20
2405
2406         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2407         TIMEOUT=$LOCAL_TIMEOUT
2408
2409         reformat
2410         setup_noconfig
2411         check_mount || return 1
2412
2413         echo "check ldlm_timout..."
2414         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2415         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2416         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2417
2418         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2419                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2420         fi
2421
2422         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2423                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2424         fi
2425
2426         umount_client $MOUNT
2427         stop_ost || return 2
2428         stop_mds || return 3
2429
2430         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2431
2432         reformat
2433         setup_noconfig
2434         check_mount || return 7
2435
2436         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2437         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2438         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2439
2440         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2441                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2442         fi
2443
2444         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2445                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2446         fi
2447
2448         cleanup || return $?
2449
2450         LDLM_TIMEOUT=$ldlm_timeout_orig
2451         TIMEOUT=$timeout_orig
2452 }
2453 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2454
2455 lazystatfs() {
2456         # Test both statfs and lfs df and fail if either one fails
2457         multiop_bg_pause $1 f_
2458         RC1=$?
2459         PID=$!
2460         killall -USR1 multiop
2461         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2462         wait $PID || { RC1=$?; log "multiop return error "; }
2463
2464         $LFS df &
2465         PID=$!
2466         sleep 5
2467         kill -s 0 $PID
2468         RC2=$?
2469         if [ $RC2 -eq 0 ]; then
2470             kill -s 9 $PID
2471             log "lazystatfs df failed"
2472         fi
2473
2474         RC=0
2475         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2476         return $RC
2477 }
2478
2479 test_50a() {
2480         setup
2481         lctl set_param llite.$FSNAME-*.lazystatfs=1
2482         touch $DIR/$tfile
2483
2484         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2485
2486         cleanup || return $?
2487 }
2488 run_test 50a "lazystatfs all servers available =========================="
2489
2490 test_50b() {
2491         setup
2492         lctl set_param llite.$FSNAME-*.lazystatfs=1
2493         touch $DIR/$tfile
2494
2495         # Wait for client to detect down OST
2496         stop_ost || error "Unable to stop OST1"
2497         wait_osc_import_state mds ost DISCONN
2498
2499         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2500
2501         umount_client $MOUNT || error "Unable to unmount client"
2502         stop_mds || error "Unable to stop MDS"
2503 }
2504 run_test 50b "lazystatfs all servers down =========================="
2505
2506 test_50c() {
2507         start_mds || error "Unable to start MDS"
2508         start_ost || error "Unable to start OST1"
2509         start_ost2 || error "Unable to start OST2"
2510         mount_client $MOUNT || error "Unable to mount client"
2511         lctl set_param llite.$FSNAME-*.lazystatfs=1
2512         touch $DIR/$tfile
2513
2514         # Wait for client to detect down OST
2515         stop_ost || error "Unable to stop OST1"
2516         wait_osc_import_state mds ost DISCONN
2517         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2518
2519         umount_client $MOUNT || error "Unable to unmount client"
2520         stop_ost2 || error "Unable to stop OST2"
2521         stop_mds || error "Unable to stop MDS"
2522         #writeconf to remove all ost2 traces for subsequent tests
2523         writeconf
2524 }
2525 run_test 50c "lazystatfs one server down =========================="
2526
2527 test_50d() {
2528         start_mds || error "Unable to start MDS"
2529         start_ost || error "Unable to start OST1"
2530         start_ost2 || error "Unable to start OST2"
2531         mount_client $MOUNT || error "Unable to mount client"
2532         lctl set_param llite.$FSNAME-*.lazystatfs=1
2533         touch $DIR/$tfile
2534
2535         # Issue the statfs during the window where the client still
2536         # belives the OST to be available but it is in fact down.
2537         # No failure just a statfs which hangs for a timeout interval.
2538         stop_ost || error "Unable to stop OST1"
2539         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2540
2541         umount_client $MOUNT || error "Unable to unmount client"
2542         stop_ost2 || error "Unable to stop OST2"
2543         stop_mds || error "Unable to stop MDS"
2544         #writeconf to remove all ost2 traces for subsequent tests
2545         writeconf
2546 }
2547 run_test 50d "lazystatfs client/server conn race =========================="
2548
2549 test_50e() {
2550         local RC1
2551         local pid
2552
2553         reformat_and_config
2554         start_mds || return 1
2555         #first client should see only one ost
2556         start_ost || return 2
2557         wait_osc_import_state mds ost FULL
2558
2559         # Wait for client to detect down OST
2560         stop_ost || error "Unable to stop OST1"
2561         wait_osc_import_state mds ost DISCONN
2562
2563         mount_client $MOUNT || error "Unable to mount client"
2564         lctl set_param llite.$FSNAME-*.lazystatfs=0
2565
2566         multiop_bg_pause $MOUNT _f
2567         RC1=$?
2568         pid=$!
2569
2570         if [ $RC1 -ne 0 ]; then
2571                 log "multiop failed $RC1"
2572         else
2573             kill -USR1 $pid
2574             sleep $(( $TIMEOUT+1 ))
2575             kill -0 $pid
2576             [ $? -ne 0 ] && error "process isn't sleep"
2577             start_ost || error "Unable to start OST1"
2578             wait $pid || error "statfs failed"
2579         fi
2580
2581         umount_client $MOUNT || error "Unable to unmount client"
2582         stop_ost || error "Unable to stop OST1"
2583         stop_mds || error "Unable to stop MDS"
2584 }
2585 run_test 50e "normal statfs all servers down =========================="
2586
2587 test_50f() {
2588         local RC1
2589         local pid
2590         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2591
2592         start_mds || error "Unable to start mds"
2593         #first client should see only one ost
2594         start_ost || error "Unable to start OST1"
2595         wait_osc_import_state mds ost FULL
2596
2597         start_ost2 || error "Unable to start OST2"
2598         wait_osc_import_state mds ost2 FULL
2599
2600         # Wait for client to detect down OST
2601         stop_ost2 || error "Unable to stop OST2"
2602
2603         wait_osc_import_state mds ost2 DISCONN
2604         mount_client $MOUNT || error "Unable to mount client"
2605         lctl set_param llite.$FSNAME-*.lazystatfs=0
2606
2607         multiop_bg_pause $MOUNT _f
2608         RC1=$?
2609         pid=$!
2610
2611         if [ $RC1 -ne 0 ]; then
2612                 log "lazystatfs multiop failed $RC1"
2613         else
2614             kill -USR1 $pid
2615             sleep $(( $TIMEOUT+1 ))
2616             kill -0 $pid
2617             [ $? -ne 0 ] && error "process isn't sleep"
2618             start_ost2 || error "Unable to start OST2"
2619             wait $pid || error "statfs failed"
2620             stop_ost2 || error "Unable to stop OST2"
2621         fi
2622
2623         umount_client $MOUNT || error "Unable to unmount client"
2624         stop_ost || error "Unable to stop OST1"
2625         stop_mds || error "Unable to stop MDS"
2626         #writeconf to remove all ost2 traces for subsequent tests
2627         writeconf
2628 }
2629 run_test 50f "normal statfs one server in down =========================="
2630
2631 test_50g() {
2632         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2633         setup
2634         start_ost2 || error "Unable to start OST2"
2635         wait_osc_import_state mds ost2 FULL
2636         wait_osc_import_state client ost2 FULL
2637
2638         local PARAM="${FSNAME}-OST0001.osc.active"
2639
2640         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2641         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2642
2643         umount_client $MOUNT || error "Unable to unmount client"
2644         mount_client $MOUNT || error "Unable to mount client"
2645         # This df should not cause a panic
2646         df -k $MOUNT
2647
2648         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2649         rm -f $DIR/$tfile
2650         umount_client $MOUNT || error "Unable to unmount client"
2651         stop_ost2 || error "Unable to stop OST2"
2652         stop_ost || error "Unable to stop OST1"
2653         stop_mds || error "Unable to stop MDS"
2654         #writeconf to remove all ost2 traces for subsequent tests
2655         writeconf
2656 }
2657 run_test 50g "deactivated OST should not cause panic====================="
2658
2659 test_51() {
2660         local LOCAL_TIMEOUT=20
2661
2662         reformat
2663         setup_noconfig
2664         check_mount || return 1
2665
2666         mkdir $MOUNT/d1
2667         $LFS setstripe -c -1 $MOUNT/d1
2668         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2669         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2670         touch $MOUNT/d1/f1 &
2671         local pid=$!
2672         sleep 2
2673         start_ost2 || return 2
2674         wait $pid
2675         stop_ost2 || return 3
2676         cleanup
2677         #writeconf to remove all ost2 traces for subsequent tests
2678         writeconf
2679 }
2680 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2681
2682 copy_files_xattrs()
2683 {
2684         local node=$1
2685         local dest=$2
2686         local xattrs=$3
2687         shift 3
2688
2689         do_node $node mkdir -p $dest
2690         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2691
2692         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2693                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2694         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
2695
2696         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
2697         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
2698 }
2699
2700 diff_files_xattrs()
2701 {
2702         local node=$1
2703         local backup=$2
2704         local xattrs=$3
2705         shift 3
2706
2707         local backup2=${TMP}/backup2
2708
2709         do_node $node mkdir -p $backup2
2710         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2711
2712         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
2713                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2714         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
2715
2716         do_node $node "diff -rq $backup $backup2"
2717         [ $? -eq 0 ] || { error "contents differ"; return 3; }
2718
2719         local xattrs2=${TMP}/xattrs2
2720         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
2721         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
2722
2723         do_node $node "diff $xattrs $xattrs2"
2724         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
2725
2726         do_node $node "rm -rf $backup2 $xattrs2"
2727         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
2728 }
2729
2730 test_52() {
2731         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2732                 skip "Only applicable to ldiskfs-based MDTs"
2733                 return
2734         fi
2735
2736         start_mds
2737         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
2738         start_ost
2739         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
2740         mount_client $MOUNT
2741         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
2742
2743         local nrfiles=8
2744         local ost1mnt=$(facet_mntpt ost1)
2745         local ost1node=$(facet_active_host ost1)
2746         local ost1tmp=$TMP/conf52
2747         local loop
2748
2749         mkdir -p $DIR/$tdir
2750         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
2751         touch $TMP/modified_first
2752         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
2753         local mtime=$(stat -c %Y $TMP/modified_first)
2754         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
2755
2756         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
2757         sleep 1
2758
2759         $LFS setstripe -c -1 -S 1M $DIR/$tdir
2760         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
2761
2762         for (( i=0; i < nrfiles; i++ )); do
2763                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
2764                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
2765                 echo -n .
2766         done
2767         echo
2768
2769         # backup files
2770         echo backup files to $TMP/files
2771         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
2772         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2773         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
2774
2775         umount_client $MOUNT
2776         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
2777         stop_ost
2778         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
2779
2780         echo mount ost1 as ldiskfs
2781         do_node $ost1node mkdir -p $ost1mnt
2782         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
2783         if ! do_node $ost1node test -b $ost1_dev; then
2784                 loop="-o loop"
2785         fi
2786         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
2787                 $ost1mnt
2788         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
2789
2790         # backup objects
2791         echo backup objects to $ost1tmp/objects
2792         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/0 -type f -size +0'\
2793                         '-newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
2794         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2795         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
2796
2797         # move objects to lost+found
2798         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
2799         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
2800
2801         # recover objects
2802         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
2803         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
2804
2805         # compare restored objects against saved ones
2806         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2807         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
2808
2809         do_node $ost1node "umount $ost1mnt"
2810         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
2811
2812         start_ost
2813         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
2814         mount_client $MOUNT
2815         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
2816
2817         # compare files
2818         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2819         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
2820
2821         rm -rf $TMP/files $TMP/file_xattrs
2822         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
2823         do_node $ost1node "rm -rf $ost1tmp"
2824         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
2825         cleanup
2826 }
2827 run_test 52 "check recovering objects from lost+found"
2828
2829 # Checks threads_min/max/started for some service
2830 #
2831 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
2832 # parameter pattern prefix like 'ost.*.ost'.
2833 thread_sanity() {
2834         local modname=$1
2835         local facet=$2
2836         local parampat=$3
2837         local opts=$4
2838         local basethr=$5
2839         local tmin
2840         local tmin2
2841         local tmax
2842         local tmax2
2843         local tstarted
2844         local paramp
2845         local msg="Insane $modname thread counts"
2846         local ncpts=$(check_cpt_number $facet)
2847         local nthrs
2848         shift 4
2849
2850         setup
2851         check_mount || return 41
2852
2853         # We need to expand $parampat, but it may match multiple parameters, so
2854         # we'll pick the first one
2855         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
2856                 error "Couldn't expand ${parampat}.threads_min parameter name"
2857                 return 22
2858         fi
2859
2860         # Remove the .threads_min part
2861         paramp=${paramp%.threads_min}
2862
2863         # Check for sanity in defaults
2864         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2865         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2866         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
2867         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
2868         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
2869         nthrs=$(expr $tmax - $tmin)
2870         if [ $nthrs -lt $ncpts ]; then
2871                 nthrs=0
2872         else
2873                 nthrs=$ncpts
2874         fi
2875
2876         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
2877                 skip_env "module parameter forced $facet thread count" &&
2878                 tmin=3 && tmax=$((3 * tmax))
2879
2880         # Check that we can change min/max
2881         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
2882         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
2883         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2884         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2885         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
2886
2887         # Check that we can set min/max to the same value
2888         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2889         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
2890         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2891         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2892         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
2893
2894         # Check that we can't set max < min
2895         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
2896         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2897         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2898         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
2899
2900         # We need to ensure that we get the module options desired; to do this
2901         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
2902         LOAD_MODULES_REMOTE=true
2903         cleanup
2904         local oldvalue
2905         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
2906         setmodopts -a $modname "$newvalue" oldvalue
2907
2908         load_modules
2909         setup
2910         check_mount || return 41
2911
2912         # Restore previous setting of MODOPTS_*
2913         setmodopts $modname "$oldvalue"
2914
2915         # Check that $opts took
2916         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
2917         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
2918         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
2919         lassert 28 "$msg" '(($tstarted == $tmin && $tstarted == $tmax ))' || return $?
2920         cleanup
2921
2922         load_modules
2923         setup
2924         cleanup
2925 }
2926
2927 test_53a() {
2928         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
2929 }
2930 run_test 53a "check OSS thread count params"
2931
2932 test_53b() {
2933         thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' '16'
2934 }
2935 run_test 53b "check MDT thread count params"
2936
2937 test_54a() {
2938         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2939                 skip "Only applicable to ldiskfs-based MDTs"
2940                 return
2941         fi
2942
2943     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
2944     [ $? -eq 0 ] || error "llverdev failed!"
2945     reformat_and_config
2946 }
2947 run_test 54a "test llverdev and partial verify of device"
2948
2949 test_54b() {
2950         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2951                 skip "Only applicable to ldiskfs-based MDTs"
2952                 return
2953         fi
2954
2955     setup
2956     run_llverfs $MOUNT -p
2957     [ $? -eq 0 ] || error "llverfs failed!"
2958     cleanup
2959 }
2960 run_test 54b "test llverfs and partial verify of filesystem"
2961
2962 lov_objid_size()
2963 {
2964         local max_ost_index=$1
2965         echo -n $(((max_ost_index + 1) * 8))
2966 }
2967
2968 test_55() {
2969         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2970                 skip "Only applicable to ldiskfs-based MDTs"
2971                 return
2972         fi
2973
2974         local mdsdev=$(mdsdevname 1)
2975         local mdsvdev=$(mdsvdevname 1)
2976
2977         for i in 1023 2048
2978         do
2979                 add mds1 $(mkfs_opts mds1) --reformat $mdsdev $mdsvdev ||
2980                         exit 10
2981                 add ost1 $(mkfs_opts ost1) --index=$i --reformat \
2982                         $(ostdevname 1) $(ostvdevname 1)
2983                 setup_noconfig
2984                 stopall
2985                 setup_noconfig
2986                 sync
2987
2988                 echo checking size of lov_objid for ost index $i
2989                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
2990                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
2991                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
2992                 else
2993                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
2994                 fi
2995                 stopall
2996         done
2997
2998         reformat
2999 }
3000 run_test 55 "check lov_objid size"
3001
3002 test_56() {
3003         local mds_journal_size_orig=$MDSJOURNALSIZE
3004
3005         MDSJOURNALSIZE=16
3006         add mds1 $(mkfs_opts mds1) --reformat $(mdsdevname 1) $(mdsvdevname 1)
3007         add ost1 $(mkfs_opts ost1) --index=1000 --reformat \
3008                 $(ostdevname 1) $(ostvdevname 1)
3009         add ost2 $(mkfs_opts ost2) --index=10000 --reformat \
3010                 $(ostdevname 2) $(ostvdevname 2)
3011
3012         start_mgsmds
3013         start_ost
3014         start_ost2 || error "Unable to start second ost"
3015         mount_client $MOUNT || error "Unable to mount client"
3016         echo ok
3017         $LFS osts
3018         stopall
3019         MDSJOURNALSIZE=$mds_journal_size_orig
3020         reformat
3021 }
3022 run_test 56 "check big indexes"
3023
3024 test_57a() { # bug 22656
3025         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3026         writeconf
3027         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3028         start_mgsmds
3029         start_ost && error "OST registration from failnode should fail"
3030         reformat
3031 }
3032 run_test 57a "initial registration from failnode should fail (should return errs)"
3033
3034 test_57b() {
3035         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3036         writeconf
3037         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3038         start_mgsmds
3039         start_ost || error "OST registration from servicenode should not fail"
3040         reformat
3041 }
3042 run_test 57b "initial registration from servicenode should not fail"
3043
3044 count_osts() {
3045         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3046 }
3047
3048 test_58() { # bug 22658
3049         if [ $(facet_fstype mds) != ldiskfs ]; then
3050                 skip "Only applicable to ldiskfs-based MDTs"
3051                 return
3052         fi
3053         setup_noconfig
3054         mkdir -p $DIR/$tdir
3055         createmany -o $DIR/$tdir/$tfile-%d 100
3056         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3057 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3058         do_facet mds "lctl set_param fail_loc=0x601"
3059         unlinkmany $DIR/$tdir/$tfile-%d 100
3060         stop mds
3061         local MNTDIR=$(facet_mntpt mds)
3062         # remove all files from the OBJECTS dir
3063         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
3064         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
3065         do_facet mds "umount $MNTDIR"
3066         # restart MDS with missing llog files
3067         start_mds
3068         do_facet mds "lctl set_param fail_loc=0"
3069         reformat
3070 }
3071 run_test 58 "missing llog files must not prevent MDT from mounting"
3072
3073 test_59() {
3074         start_mgsmds >> /dev/null
3075         local C1=$(count_osts)
3076         if [ $C1 -eq 0 ]; then
3077                 start_ost >> /dev/null
3078                 C1=$(count_osts)
3079         fi
3080         stopall
3081         echo "original ost count: $C1 (expect > 0)"
3082         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3083         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3084         local C2=$(count_osts)
3085         echo "after mdt writeconf count: $C2 (expect 0)"
3086         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3087         echo "OST start without writeconf should fail:"
3088         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3089         echo "OST start with writeconf should succeed:"
3090         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3091         local C3=$(count_osts)
3092         echo "after ost writeconf count: $C3 (expect 1)"
3093         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3094         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3095         local C4=$(count_osts)
3096         echo "after ost2 writeconf count: $C4 (expect 2)"
3097         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3098         stop_ost2 >> /dev/null
3099         cleanup_nocli >> /dev/null
3100         #writeconf to remove all ost2 traces for subsequent tests
3101         writeconf
3102 }
3103 run_test 59 "writeconf mount option"
3104
3105 test_60() { # LU-471
3106         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3107                 skip "Only applicable to ldiskfs-based MDTs"
3108                 return
3109         fi
3110
3111         add mds1 $(mkfs_opts mds1) \
3112                 --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' --reformat \
3113                 $(mdsdevname 1) $(mdsvdevname 1) || exit 10
3114
3115         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3116         rc=${PIPESTATUS[0]}
3117         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3118
3119         # MDT default has dirdata feature
3120         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3121         # we disable uninit_bg feature
3122         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3123         # we set stride extended options
3124         echo $dump | grep stride > /dev/null || error "stride is not set"
3125         reformat
3126 }
3127 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3128
3129 test_61() { # LU-80
3130         local reformat=false
3131
3132         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3133                 { skip "Need MDS version at least 2.1.53"; return 0; }
3134
3135         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3136            ! large_xattr_enabled; then
3137                 reformat=true
3138                 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
3139                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3140                 add $SINGLEMDS $(mkfs_opts $SINGLEMDS) --reformat $mds_dev ||
3141                         error "reformatting $mds_dev failed"
3142         fi
3143
3144     setup_noconfig || error "setting up the filesystem failed"
3145     client_up || error "starting client failed"
3146
3147     local file=$DIR/$tfile
3148     touch $file
3149
3150     local large_value="$(generate_string $(max_xattr_size))"
3151     local small_value="bar"
3152
3153     local name="trusted.big"
3154     log "save large xattr $name on $file"
3155     setfattr -n $name -v $large_value $file ||
3156         error "saving $name on $file failed"
3157
3158     local new_value=$(get_xattr_value $name $file)
3159     [[ "$new_value" != "$large_value" ]] &&
3160         error "$name different after saving"
3161
3162     log "shrink value of $name on $file"
3163     setfattr -n $name -v $small_value $file ||
3164         error "shrinking value of $name on $file failed"
3165
3166     new_value=$(get_xattr_value $name $file)
3167     [[ "$new_value" != "$small_value" ]] &&
3168         error "$name different after shrinking"
3169
3170     log "grow value of $name on $file"
3171     setfattr -n $name -v $large_value $file ||
3172         error "growing value of $name on $file failed"
3173
3174     new_value=$(get_xattr_value $name $file)
3175     [[ "$new_value" != "$large_value" ]] &&
3176         error "$name different after growing"
3177
3178     log "check value of $name on $file after remounting MDS"
3179     fail $SINGLEMDS
3180     new_value=$(get_xattr_value $name $file)
3181     [[ "$new_value" != "$large_value" ]] &&
3182         error "$name different after remounting MDS"
3183
3184     log "remove large xattr $name from $file"
3185     setfattr -x $name $file || error "removing $name from $file failed"
3186
3187     rm -f $file
3188     stopall
3189         if $reformat; then
3190                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3191                 reformat
3192         fi
3193 }
3194 run_test 61 "large xattr"
3195
3196 test_62() {
3197         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3198                 skip "Only applicable to ldiskfs-based MDTs"
3199                 return
3200         fi
3201
3202         # MRP-118
3203         local mdsdev=$(mdsdevname 1)
3204         local ostdev=$(ostdevname 1)
3205
3206         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3207                 { skip "Need MDS version at least 2.2.51"; return 0; }
3208
3209         echo "disable journal for mds"
3210         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3211         start_mds && error "MDT start should fail"
3212         echo "disable journal for ost"
3213         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3214         start_ost && error "OST start should fail"
3215         cleanup || return $?
3216         reformat_and_config
3217 }
3218 run_test 62 "start with disabled journal"
3219
3220 test_63() {
3221         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3222                 skip "Only applicable to ldiskfs-based MDTs"
3223                 return
3224         fi
3225
3226         local inode_slab=$(do_facet $SINGLEMDS \
3227                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3228         if [ -z "$inode_slab" ]; then
3229                 skip "ldiskfs module has not been loaded"
3230                 return
3231         fi
3232
3233         echo "$inode_slab ldisk inodes per page"
3234         [ "$inode_slab" -ge "3" ] ||
3235                 error "ldisk inode size is too big, $inode_slab objs per page"
3236         return
3237 }
3238 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3239
3240 test_64() {
3241         start_mds
3242         start_ost
3243         start_ost2 || error "Unable to start second ost"
3244         mount_client $MOUNT || error "Unable to mount client"
3245         stop_ost2 || error "Unable to stop second ost"
3246         echo "$LFS df"
3247         $LFS df --lazy || error "lfs df failed"
3248         cleanup || return $?
3249 }
3250 run_test 64 "check lfs df --lazy "
3251
3252 if ! combined_mgs_mds ; then
3253         stop mgs
3254 fi
3255
3256 cleanup_gss
3257
3258 complete $SECONDS
3259 exit_status