Whamcloud - gitweb
LU-2393 tests: conf-sanity/32b ensure uniform sort ordering
[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
905         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
906                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
907
908         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
909                 --reformat $fs2ostdev $fs2ostvdev || exit 10
910
911         setup
912         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
913         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
914         mkdir -p $MOUNT2
915         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
916         # 1 still works
917         check_mount || return 2
918         # files written on 1 should not show up on 2
919         cp /etc/passwd $DIR/$tfile
920         sleep 10
921         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
922         # 2 should work
923         sleep 5
924         cp /etc/passwd $MOUNT2/b || return 3
925         rm $MOUNT2/b || return 4
926         # 2 is actually mounted
927         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
928         # failover
929         facet_failover fs2mds
930         facet_failover fs2ost
931         df
932         umount_client $MOUNT
933         # the MDS must remain up until last MDT
934         stop_mds
935         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
936         [ -z "$MDS" ] && error "No MDT" && return 8
937         cleanup_24a
938         cleanup_nocli || return 6
939 }
940 run_test 24a "Multiple MDTs on a single node"
941
942 test_24b() {
943         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
944
945         if [ -z "$fs2mds_DEV" ]; then
946                 local dev=${SINGLEMDS}_dev
947                 local MDSDEV=${!dev}
948                 is_blkdev $SINGLEMDS $MDSDEV && \
949                 skip_env "mixed loopback and real device not working" && return
950         fi
951
952         local fs2mdsdev=$(mdsdevname 1_2)
953         local fs2mdsvdev=$(mdsvdevname 1_2)
954
955         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
956                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
957         setup
958         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
959         cleanup || return 6
960 }
961 run_test 24b "Multiple MGSs on a single node (should return err)"
962
963 test_25() {
964         setup
965         check_mount || return 2
966         local MODULES=$($LCTL modules | awk '{ print $2 }')
967         rmmod $MODULES 2>/dev/null || true
968         cleanup || return 6
969 }
970 run_test 25 "Verify modules are referenced"
971
972 test_26() {
973     load_modules
974     # we need modules before mount for sysctl, so make sure...
975     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
976 #define OBD_FAIL_MDS_FS_SETUP            0x135
977     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
978     start_mds && echo MDS started && return 1
979     lctl get_param -n devices
980     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
981     [ $DEVS -gt 0 ] && return 2
982     # start mds to drop writeconf setting
983     start_mds || return 3
984     stop_mds || return 4
985     unload_modules_conf || return $?
986 }
987 run_test 26 "MDT startup failure cleans LOV (should return errs)"
988
989 test_27a() {
990         [ "$(facet_fstype ost1)" = "zfs" ] &&
991                 skip "LU-2059: no local config for ZFS OSTs" && return
992
993         start_ost || return 1
994         start_mds || return 2
995         echo "Requeue thread should have started: "
996         ps -e | grep ll_cfg_requeue
997         set_conf_param_and_check ost1                                         \
998            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
999            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
1000         cleanup_nocli
1001 }
1002 run_test 27a "Reacquire MGS lock if OST started first"
1003
1004 test_27b() {
1005         # FIXME. ~grev
1006         setup
1007         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
1008
1009         facet_failover $SINGLEMDS
1010         set_conf_param_and_check $SINGLEMDS                             \
1011                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
1012                 "$device.mdt.identity_acquire_expire" || return 3
1013         set_conf_param_and_check client                                 \
1014                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1015                 "$device.mdc.max_rpcs_in_flight" || return 4
1016         check_mount
1017         cleanup
1018 }
1019 run_test 27b "Reacquire MGS lock after failover"
1020
1021 test_28() {
1022         setup
1023         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1024         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1025         ORIG=$($TEST)
1026         FINAL=$(($ORIG + 1))
1027         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1028         FINAL=$(($FINAL + 1))
1029         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1030         umount_client $MOUNT || return 200
1031         mount_client $MOUNT
1032         RESULT=$($TEST)
1033         if [ $RESULT -ne $FINAL ]; then
1034             echo "New config not seen: wanted $FINAL got $RESULT"
1035             return 4
1036         else
1037             echo "New config success: got $RESULT"
1038         fi
1039         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1040         cleanup
1041 }
1042 run_test 28 "permanent parameter setting"
1043
1044 test_29() {
1045         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1046         setup > /dev/null 2>&1
1047         start_ost2
1048         sleep 10
1049
1050         local PARAM="$FSNAME-OST0001.osc.active"
1051         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1052         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1053
1054         ACTV=$(lctl get_param -n $PROC_ACT)
1055         DEAC=$((1 - $ACTV))
1056         set_conf_param_and_check client \
1057                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1058         # also check ost_server_uuid status
1059         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1060         if [ -z "$RESULT" ]; then
1061             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1062             return 3
1063         else
1064             echo "Live client success: got $RESULT"
1065         fi
1066
1067         # check MDT too
1068         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0001)
1069         mdtosc=${mdtosc/-MDT*/-MDT\*}
1070         local MPROC="osc.$mdtosc.active"
1071         local MAX=30
1072         local WAIT=0
1073         while [ 1 ]; do
1074             sleep 5
1075             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
1076             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1077             if [ $RESULT -eq $DEAC ]; then
1078                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
1079                 break
1080             fi
1081             WAIT=$((WAIT + 5))
1082             if [ $WAIT -eq $MAX ]; then
1083                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
1084                 return 4
1085             fi
1086             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
1087         done
1088
1089         # test new client starts deactivated
1090         umount_client $MOUNT || return 200
1091         mount_client $MOUNT
1092         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1093         if [ -z "$RESULT" ]; then
1094             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1095             return 5
1096         else
1097             echo "New client success: got $RESULT"
1098         fi
1099
1100         # make sure it reactivates
1101         set_conf_param_and_check client \
1102                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1103
1104         umount_client $MOUNT
1105         stop_ost2
1106         cleanup_nocli
1107         #writeconf to remove all ost2 traces for subsequent tests
1108         writeconf
1109 }
1110 run_test 29 "permanently remove an OST"
1111
1112 test_30a() {
1113         setup
1114
1115         echo Big config llog
1116         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1117         ORIG=$($TEST)
1118         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1119         for i in ${LIST[@]}; do
1120                 set_conf_param_and_check client "$TEST" \
1121                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1122         done
1123         # make sure client restart still works
1124         umount_client $MOUNT
1125         mount_client $MOUNT || return 4
1126         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1127         pass
1128
1129         echo Erase parameter setting
1130         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1131         umount_client $MOUNT
1132         mount_client $MOUNT || return 6
1133         FINAL=$($TEST)
1134         echo "deleted (default) value=$FINAL, orig=$ORIG"
1135         # assumes this parameter started at the default value
1136         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1137
1138         cleanup
1139 }
1140 run_test 30a "Big config llog and conf_param deletion"
1141
1142 test_30b() {
1143         setup
1144
1145         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1146         # numerical part of it. Hopefully that's not already a failover address for
1147         # the server.
1148         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1149         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1150         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1151         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1152         echo "Using fake nid $NEW"
1153
1154         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1155         set_conf_param_and_check client "$TEST" \
1156                 "$FSNAME-OST0000.failover.node" $NEW ||
1157                 error "didn't add failover nid $NEW"
1158         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1159         echo $NIDS
1160         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1161         echo "should have 2 failover nids: $NIDCOUNT"
1162         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1163         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1164         umount_client $MOUNT
1165         mount_client $MOUNT || return 3
1166
1167         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1168         echo $NIDS
1169         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1170         echo "only 1 final nid should remain: $NIDCOUNT"
1171         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1172
1173         cleanup
1174 }
1175 run_test 30b "Remove failover nids"
1176
1177 test_31() { # bug 10734
1178         # ipaddr must not exist
1179         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1180         cleanup
1181 }
1182 run_test 31 "Connect to non-existent node (shouldn't crash)"
1183
1184 #
1185 # This is not really a test but a tool to create new disk
1186 # image tarballs for the upgrade tests.
1187 #
1188 # Disk image tarballs should be created on single-node
1189 # clusters by running this test with default configurations
1190 # plus a few mandatory environment settings that are verified
1191 # at the beginning of the test.
1192 #
1193 test_32newtarball() {
1194         local version
1195         local dst=.
1196         local src=/etc/rc.d
1197         local tmp=$TMP/t32_image_create
1198
1199         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1200                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1201                  -z "$OSTDEV1" ]; then
1202                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1203                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1204                           "OSTDEV1=<nonexistent_file>"
1205         fi
1206
1207         mkdir $tmp || {
1208                 echo "Found stale $tmp"
1209                 return 1
1210         }
1211
1212         mkdir $tmp/src
1213         tar cf - -C $src . | tar xf - -C $tmp/src
1214
1215         formatall
1216
1217         setupall
1218         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1219         stopall
1220
1221         mkdir $tmp/img
1222
1223         setupall
1224         pushd /mnt/$FSNAME
1225         ls -Rni --time-style=+%s >$tmp/img/list
1226         find . ! -name .lustre -type f -exec sha1sum {} \; |
1227                 sort -k 2 >$tmp/img/sha1sums
1228         popd
1229         $LCTL get_param -n version | head -n 1 |
1230                 sed -e 's/^lustre: *//' >$tmp/img/commit
1231         stopall
1232
1233         pushd $tmp/src
1234         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1235         popd
1236
1237         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1238                 echo "Data verification failed"
1239         fi
1240
1241         uname -r >$tmp/img/kernel
1242         uname -m >$tmp/img/arch
1243
1244         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1245         mv $OSTDEV1 $tmp/img
1246
1247         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1248                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1249         dst=$(cd $dst; pwd)
1250         pushd $tmp/img
1251         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1252         popd
1253
1254         rm -r $tmp
1255 }
1256 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1257
1258 #
1259 # The list of applicable tarballs is returned via the caller's
1260 # variable "tarballs".
1261 #
1262 t32_check() {
1263         local node=$(facet_active_host $SINGLEMDS)
1264         local r="do_node $node"
1265
1266         if [ "$CLIENTONLY" ]; then
1267                 skip "Client-only testing"
1268                 exit 0
1269         fi
1270
1271         if ! $r which $TUNEFS; then
1272                 skip_env "tunefs.lustre required on $node"
1273                 exit 0
1274         fi
1275
1276         if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1277                 skip "LU-2200: Test cannot run over Infiniband"
1278                 exit 0
1279         fi
1280
1281         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1282
1283         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1284
1285         if [ -z "$tarballs" ]; then
1286                 skip "No applicable tarballs found"
1287                 exit 0
1288         fi
1289 }
1290
1291 t32_test_cleanup() {
1292         local node=$(facet_active_host $SINGLEMDS)
1293         local r="do_node $node"
1294         local tmp=$TMP/t32
1295         local rc=$?
1296
1297         if $shall_cleanup_lustre; then
1298                 umount $tmp/mnt/lustre || rc=$?
1299         fi
1300         if $shall_cleanup_mdt; then
1301                 $r umount -d $tmp/mnt/mdt || rc=$?
1302         fi
1303         if $shall_cleanup_ost; then
1304                 $r umount -d $tmp/mnt/ost || rc=$?
1305         fi
1306         $r rm -rf $tmp || rc=$?
1307         rm -rf $tmp || rc=$?
1308         return $rc
1309 }
1310
1311 t32_bits_per_long() {
1312         #
1313         # Yes, this is not meant to be perfect.
1314         #
1315         case $1 in
1316                 ppc64|x86_64)
1317                         echo -n 64;;
1318                 i*86)
1319                         echo -n 32;;
1320         esac
1321 }
1322
1323 t32_reload_modules() {
1324         local node=$1
1325         local all_removed=false
1326         local i=0
1327
1328         while ((i < 20)); do
1329                 echo "Unloading modules on $node: Attempt $i"
1330                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1331                         all_removed=true
1332                 do_rpc_nodes $node check_mem_leak || return 1
1333                 if $all_removed; then
1334                         load_modules
1335                         return 0
1336                 fi
1337                 sleep 5
1338                 i=$((i + 1))
1339         done
1340         echo "Unloading modules on $node: Given up"
1341         return 1
1342 }
1343
1344 t32_wait_til_devices_gone() {
1345         local node=$1
1346         local devices
1347         local i=0
1348
1349         echo wait for devices to go
1350         while ((i < 20)); do
1351                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1352                 echo $device
1353                 ((devices == 0)) && return 1
1354                 sleep 5
1355                 i=$((i + 1))
1356         done
1357         echo "waiting for devices on $node: Given up"
1358         return 1
1359 }
1360
1361 t32_test() {
1362         local tarball=$1
1363         local writeconf=$2
1364         local shall_cleanup_mdt=false
1365         local shall_cleanup_ost=false
1366         local shall_cleanup_lustre=false
1367         local node=$(facet_active_host $SINGLEMDS)
1368         local r="do_node $node"
1369         local tmp=$TMP/t32
1370         local img_commit
1371         local img_kernel
1372         local img_arch
1373         local fsname=t32fs
1374         local nid=$($r $LCTL list_nids | head -1)
1375         local mopts
1376         local uuid
1377         local nrpcs_orig
1378         local nrpcs
1379         local list
1380
1381         trap 'trap - RETURN; t32_test_cleanup' RETURN
1382
1383         mkdir -p $tmp/mnt/lustre
1384         $r mkdir -p $tmp/mnt/{mdt,ost}
1385         $r tar xjvf $tarball -S -C $tmp || {
1386                 error_noexit "Unpacking the disk image tarball"
1387                 return 1
1388         }
1389         img_commit=$($r cat $tmp/commit)
1390         img_kernel=$($r cat $tmp/kernel)
1391         img_arch=$($r cat $tmp/arch)
1392         echo "Upgrading from $(basename $tarball), created with:"
1393         echo "  Commit: $img_commit"
1394         echo "  Kernel: $img_kernel"
1395         echo "    Arch: $img_arch"
1396
1397         $r $LCTL set_param debug="$PTLDEBUG"
1398
1399         $r $TUNEFS --dryrun $tmp/mdt || {
1400                 error_noexit "tunefs.lustre before mounting the MDT"
1401                 return 1
1402         }
1403         if [ "$writeconf" ]; then
1404                 mopts=loop,writeconf
1405         else
1406                 mopts=loop,exclude=$fsname-OST0000
1407         fi
1408
1409         t32_wait_til_devices_gone $node
1410
1411         $r mount -t lustre -o $mopts $tmp/mdt $tmp/mnt/mdt || {
1412                 error_noexit "Mounting the MDT"
1413                 return 1
1414         }
1415         shall_cleanup_mdt=true
1416
1417         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1418                 error_noexit "Getting MDT UUID"
1419                 return 1
1420         }
1421         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1422                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1423                 return 1
1424         fi
1425
1426         $r $TUNEFS --dryrun $tmp/ost || {
1427                 error_noexit "tunefs.lustre before mounting the OST"
1428                 return 1
1429         }
1430         if [ "$writeconf" ]; then
1431                 mopts=loop,mgsnode=$nid,$writeconf
1432         else
1433                 mopts=loop,mgsnode=$nid
1434         fi
1435         $r mount -t lustre -o $mopts $tmp/ost $tmp/mnt/ost || {
1436                 error_noexit "Mounting the OST"
1437                 return 1
1438         }
1439         shall_cleanup_ost=true
1440
1441         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1442                 error_noexit "Getting OST UUID"
1443                 return 1
1444         }
1445         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1446                 error_noexit "Unexpected OST UUID: \"$uuid\""
1447                 return 1
1448         fi
1449
1450         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1451                 error_noexit "Setting \"max_dirty_mb\""
1452                 return 1
1453         }
1454         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1455                 error_noexit "Setting OST \"failover.node\""
1456                 return 1
1457         }
1458         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1459                 error_noexit "Setting \"max_rpcs_in_flight\""
1460                 return 1
1461         }
1462         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1463                 error_noexit "Setting MDT \"failover.node\""
1464                 return 1
1465         }
1466         $r $LCTL pool_new $fsname.interop || {
1467                 error_noexit "Setting \"interop\""
1468                 return 1
1469         }
1470         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1471                 error_noexit "Setting \"lov.stripesize\""
1472                 return 1
1473         }
1474
1475         if [ "$writeconf" ]; then
1476                 mount -t lustre $nid:/$fsname $tmp/mnt/lustre || {
1477                         error_noexit "Mounting the client"
1478                         return 1
1479                 }
1480                 shall_cleanup_lustre=true
1481                 $LCTL set_param debug="$PTLDEBUG"
1482
1483                 if $r test -f $tmp/sha1sums; then
1484                         # LU-2393 - do both sorts on same node to ensure locale
1485                         # is identical
1486                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1487                         pushd $tmp/mnt/lustre
1488                         find ! -name .lustre -type f -exec sha1sum {} \; |
1489                                 sort -k 2 >$tmp/sha1sums || {
1490                                 error_noexit "sha1sum"
1491                                 return 1
1492                         }
1493                         popd
1494                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1495                                 error_noexit "sha1sum verification failed"
1496                                 return 1
1497                         fi
1498                 else
1499                         echo "sha1sum verification skipped"
1500                 fi
1501
1502                 if $r test -f $tmp/list; then
1503                         #
1504                         # There is not a Test Framework API to copy files to or
1505                         # from a remote node.
1506                         #
1507                         # LU-2393 - do both sorts on same node to ensure locale
1508                         # is identical
1509                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1510                         pushd $tmp/mnt/lustre
1511                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1512                                 error_noexit "ls"
1513                                 return 1
1514                         }
1515                         popd
1516                         #
1517                         # 32-bit and 64-bit clients use different algorithms to
1518                         # convert FIDs into inode numbers.  Hence, remove the inode
1519                         # numbers from the lists, if the original list was created
1520                         # on an architecture with different number of bits per
1521                         # "long".
1522                         #
1523                         if [ $(t32_bits_per_long $(uname -m)) !=                                                \
1524                                  $(t32_bits_per_long $img_arch) ]; then
1525                                 echo "Different number of bits per \"long\" from the disk image"
1526                                 for list in list.orig list; do
1527                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1528                                 done
1529                         fi
1530                         if ! diff -ub $tmp/list.orig $tmp/list; then
1531                                 error_noexit "list verification failed"
1532                                 return 1
1533                         fi
1534                 else
1535                         echo "list verification skipped"
1536                 fi
1537
1538                 #
1539                 # When adding new data verification tests, please check for
1540                 # the presence of the required reference files first, like
1541                 # the "sha1sums" and "list" tests above, to avoid the need to
1542                 # regenerate every image for each test addition.
1543                 #
1544
1545                 nrpcs_orig=$($LCTL get_param -n mdc.*.max_rpcs_in_flight) || {
1546                         error_noexit "Getting \"max_rpcs_in_flight\""
1547                         return 1
1548                 }
1549                 nrpcs=$((nrpcs_orig + 5))
1550                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1551                         error_noexit "Changing \"max_rpcs_in_flight\""
1552                         return 1
1553                 }
1554                 wait_update $HOSTNAME "$LCTL get_param -n mdc.*.max_rpcs_in_flight"     \
1555                             $nrpcs || {
1556                         error_noexit "Verifying \"max_rpcs_in_flight\""
1557                         return 1
1558                 }
1559
1560                 umount $tmp/mnt/lustre || {
1561                         error_noexit "Unmounting the client"
1562                         return 1
1563                 }
1564                 shall_cleanup_lustre=false
1565         else
1566                 $r umount -d $tmp/mnt/mdt || {
1567                         error_noexit "Unmounting the MDT"
1568                         return 1
1569                 }
1570                 shall_cleanup_mdt=false
1571                 $r umount -d $tmp/mnt/ost || {
1572                         error_noexit "Unmounting the OST"
1573                         return 1
1574                 }
1575                 shall_cleanup_ost=false
1576
1577                 t32_reload_modules $node || {
1578                         error_noexit "Reloading modules"
1579                         return 1
1580                 }
1581
1582                 # mount a second time to make sure we didnt leave upgrade flag on
1583                 $r $TUNEFS --dryrun $tmp/mdt || {
1584                         error_noexit "tunefs.lustre before remounting the MDT"
1585                         return 1
1586                 }
1587                 $r mount -t lustre -o loop,exclude=$fsname-OST0000 $tmp/mdt                     \
1588                                  $tmp/mnt/mdt || {
1589                         error_noexit "Remounting the MDT"
1590                         return 1
1591                 }
1592                 shall_cleanup_mdt=true
1593         fi
1594 }
1595
1596 test_32a() {
1597         local tarballs
1598         local tarball
1599         local rc=0
1600
1601         t32_check
1602         for tarball in $tarballs; do
1603                 t32_test $tarball || rc=$?
1604         done
1605         return $rc
1606 }
1607 run_test 32a "Upgrade (not live)"
1608
1609 test_32b() {
1610         local tarballs
1611         local tarball
1612         local rc=0
1613
1614         t32_check
1615         for tarball in $tarballs; do
1616                 t32_test $tarball writeconf || rc=$?
1617         done
1618         return $rc
1619 }
1620 run_test 32b "Upgrade with writeconf"
1621
1622 test_33a() { # bug 12333, was test_33
1623         local rc=0
1624         local FSNAME2=test-123
1625         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1626         local mkfsoptions
1627
1628         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1629
1630         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1631                 local dev=${SINGLEMDS}_dev
1632                 local MDSDEV=${!dev}
1633                 is_blkdev $SINGLEMDS $MDSDEV && \
1634                 skip_env "mixed loopback and real device not working" && return
1635         fi
1636
1637         local fs2mdsdev=$(mdsdevname 1_2)
1638         local fs2ostdev=$(ostdevname 1_2)
1639         local fs2mdsvdev=$(mdsvdevname 1_2)
1640         local fs2ostvdev=$(ostvdevname 1_2)
1641
1642         if [ $(facet_fstype mds1) == ldiskfs ]; then
1643                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
1644         fi
1645
1646         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
1647                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
1648         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
1649                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
1650                 $fs2ostvdev || exit 10
1651
1652         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1653         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1654         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1655         mkdir -p $MOUNT2
1656         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1657         echo "ok."
1658
1659         cp /etc/hosts $MOUNT2/ || rc=3
1660         $LFS getstripe $MOUNT2/hosts
1661
1662         umount -d $MOUNT2
1663         stop fs2ost -f
1664         stop fs2mds -f
1665         cleanup_nocli || rc=6
1666         return $rc
1667 }
1668 run_test 33a "Mount ost with a large index number"
1669
1670 test_33b() {    # was test_34
1671         setup
1672
1673         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1674         # Drop lock cancelation reply during umount
1675         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
1676         do_facet client lctl set_param fail_loc=0x80000304
1677         #lctl set_param debug=-1
1678         umount_client $MOUNT
1679         cleanup
1680 }
1681 run_test 33b "Drop cancel during umount"
1682
1683 test_34a() {
1684         setup
1685         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1686         manual_umount_client
1687         rc=$?
1688         do_facet client killall -USR1 multiop
1689         if [ $rc -eq 0 ]; then
1690                 error "umount not fail!"
1691         fi
1692         sleep 1
1693         cleanup
1694 }
1695 run_test 34a "umount with opened file should be fail"
1696
1697
1698 test_34b() {
1699         setup
1700         touch $DIR/$tfile || return 1
1701         stop_mds --force || return 2
1702
1703         manual_umount_client --force
1704         rc=$?
1705         if [ $rc -ne 0 ]; then
1706                 error "mtab after failed umount - rc $rc"
1707         fi
1708
1709         cleanup
1710         return 0
1711 }
1712 run_test 34b "force umount with failed mds should be normal"
1713
1714 test_34c() {
1715         setup
1716         touch $DIR/$tfile || return 1
1717         stop_ost --force || return 2
1718
1719         manual_umount_client --force
1720         rc=$?
1721         if [ $rc -ne 0 ]; then
1722                 error "mtab after failed umount - rc $rc"
1723         fi
1724
1725         cleanup
1726         return 0
1727 }
1728 run_test 34c "force umount with failed ost should be normal"
1729
1730 test_35a() { # bug 12459
1731         setup
1732
1733         DBG_SAVE="`lctl get_param -n debug`"
1734         lctl set_param debug="ha"
1735
1736         log "Set up a fake failnode for the MDS"
1737         FAKENID="127.0.0.2"
1738         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1739         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1740                 "$(h2$NETTYPE $FAKENID)" || return 4
1741
1742         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1743         sleep 10
1744
1745         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1746         $LCTL clear
1747         log "$MSG"
1748         log "Stopping the MDT:"
1749         stop_mds || return 5
1750
1751         df $MOUNT > /dev/null 2>&1 &
1752         DFPID=$!
1753         log "Restarting the MDT:"
1754         start_mds || return 6
1755         log "Wait for df ($DFPID) ... "
1756         wait $DFPID
1757         log "done"
1758         lctl set_param debug="$DBG_SAVE"
1759
1760         # retrieve from the log the first server that the client tried to
1761         # contact after the connection loss
1762         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1763         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1764                        /import_select_connection.*$device-mdc.* using connection/ {
1765                                 if (start) {
1766                                         if (\\\$NF ~ /$FAKENID/)
1767                                                 print \\\$NF;
1768                                         else
1769                                                 print 0;
1770                                         exit;
1771                                 }
1772                        }" $TMP/lustre-log-$TESTNAME.log`
1773         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1774         cleanup
1775         # remove nid settings
1776         writeconf
1777 }
1778 run_test 35a "Reconnect to the last active server first"
1779
1780 test_35b() { # bug 18674
1781         remote_mds || { skip "local MDS" && return 0; }
1782         setup
1783
1784         debugsave
1785         $LCTL set_param debug="ha"
1786         $LCTL clear
1787         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1788         log "$MSG"
1789
1790         log "Set up a fake failnode for the MDS"
1791         FAKENID="127.0.0.2"
1792         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" | \
1793                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1794         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1795                 "$(h2$NETTYPE $FAKENID)" || return 1
1796
1797         local at_max_saved=0
1798         # adaptive timeouts may prevent seeing the issue
1799         if at_is_enabled; then
1800                 at_max_saved=$(at_max_get mds)
1801                 at_max_set 0 mds client
1802         fi
1803
1804         mkdir -p $MOUNT/$tdir
1805
1806         log "Injecting EBUSY on MDS"
1807         # Setting OBD_FAIL_MDS_RESEND=0x136
1808         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
1809
1810         $LCTL set_param mdc.${FSNAME}*.stats=clear
1811
1812         log "Creating a test file and stat it"
1813         touch $MOUNT/$tdir/$tfile
1814         stat $MOUNT/$tdir/$tfile
1815
1816         log "Stop injecting EBUSY on MDS"
1817         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
1818         rm -f $MOUNT/$tdir/$tfile
1819
1820         log "done"
1821         # restore adaptive timeout
1822         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1823
1824         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1825
1826         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1827
1828         # retrieve from the log if the client has ever tried to
1829         # contact the fake server after the loss of connection
1830         FAILCONN=`awk "BEGIN {ret = 0;}
1831                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1832                                 ret = 1;
1833                                 if (\\\$NF ~ /$FAKENID/) {
1834                                         ret = 2;
1835                                         exit;
1836                                 }
1837                        }
1838                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1839
1840         [ "$FAILCONN" == "0" ] && \
1841                 log "ERROR: The client reconnection has not been triggered" && \
1842                 return 4
1843         [ "$FAILCONN" == "2" ] && \
1844                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1845                 return 5
1846
1847         # LU-290
1848         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1849         # Reconnects are supposed to be rate limited to one every 5s
1850         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1851                 log "ERROR: Too many reconnects $CONNCNT" && \
1852                 return 6
1853
1854         cleanup
1855         # remove nid settings
1856         writeconf
1857 }
1858 run_test 35b "Continue reconnection retries, if the active server is busy"
1859
1860 test_36() { # 12743
1861         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1862
1863         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1864                 { skip "remote OST" && return 0; }
1865
1866         local rc=0
1867         local FSNAME2=test1234
1868         local fs3ost_HOST=$ost_HOST
1869         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1870
1871         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1872
1873         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1874                 is_blkdev $SINGLEMDS $MDSDEV && \
1875                 skip_env "mixed loopback and real device not working" && return
1876         fi
1877
1878         local fs2mdsdev=$(mdsdevname 1_2)
1879         local fs2ostdev=$(ostdevname 1_2)
1880         local fs3ostdev=$(ostdevname 2_2)
1881         local fs2mdsvdev=$(mdsvdevname 1_2)
1882         local fs2ostvdev=$(ostvdevname 1_2)
1883         local fs3ostvdev=$(ostvdevname 2_2)
1884
1885         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
1886                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
1887         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
1888         #     different one than the default value here.
1889         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
1890                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
1891         add fs3ost $(mkfs_opts ost1 ${fs3ostdev}) --mgsnode=$MGSNID \
1892                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
1893
1894         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1895         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1896         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1897         mkdir -p $MOUNT2
1898         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1899
1900         sleep 5 # until 11778 fixed
1901
1902         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1903
1904         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1905         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1906         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1907         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1908         DFTOTAL=`echo $STRING | cut -d, -f1`
1909         DFUSED=`echo $STRING  | cut -d, -f2`
1910         DFAVAIL=`echo $STRING | cut -d, -f3`
1911         DFFREE=$(($DFTOTAL - $DFUSED))
1912
1913         ALLOWANCE=$((64 * $OSTCOUNT))
1914
1915         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1916            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1917                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1918                 rc=1
1919         fi
1920         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1921            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1922                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1923                 rc=2
1924         fi
1925         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1926            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1927                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1928                 rc=3
1929        fi
1930
1931         umount -d $MOUNT2
1932         stop fs3ost -f || return 200
1933         stop fs2ost -f || return 201
1934         stop fs2mds -f || return 202
1935         unload_modules_conf || return 203
1936         return $rc
1937 }
1938 run_test 36 "df report consistency on OSTs with different block size"
1939
1940 test_37() {
1941         local mntpt=$(facet_mntpt $SINGLEMDS)
1942         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
1943         local mdsdev_sym="$TMP/sym_mdt.img"
1944         local opts=$MDS_MOUNT_OPTS
1945         local rc=0
1946
1947         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1948                 skip "Currently only applicable to ldiskfs-based MDTs"
1949                 return
1950         fi
1951
1952         echo "MDS :     $mdsdev"
1953         echo "SYMLINK : $mdsdev_sym"
1954         do_facet $SINGLEMDS rm -f $mdsdev_sym
1955
1956         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
1957
1958         echo "mount symlink device - $mdsdev_sym"
1959
1960         if ! do_facet $SINGLEMDS test -b $mdsdev; then
1961                 opts=$(csa_add "$opts" -o loop)
1962         fi
1963         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
1964                 $mdsdev_sym $mntpt 2>&1)
1965         rc=${PIPESTATUS[0]}
1966
1967         echo mount_op=$mount_op
1968
1969         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
1970
1971         if $(echo $mount_op | grep -q "unable to set tunable"); then
1972                 error "set tunables failed for symlink device"
1973         fi
1974
1975         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
1976
1977         return 0
1978 }
1979 run_test 37 "verify set tunables works for symlink device"
1980
1981 test_38() { # bug 14222
1982         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1983                 skip "Only applicable to ldiskfs-based MDTs"
1984                 return
1985         fi
1986
1987         setup
1988         # like runtests
1989         COUNT=10
1990         SRC="/etc /bin"
1991         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1992         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1993         mkdir -p $DIR/$tdir
1994         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1995                 error "copying $SRC to $DIR/$tdir"
1996         sync
1997         umount_client $MOUNT
1998         stop_mds
1999         log "rename lov_objid file on MDS"
2000         rm -f $TMP/lov_objid.orig
2001
2002         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2003         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
2004         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2005
2006         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
2007         # check create in mds_lov_connect
2008         start_mds
2009         mount_client $MOUNT
2010         for f in $FILES; do
2011                 [ $V ] && log "verifying $DIR/$tdir/$f"
2012                 diff -q $f $DIR/$tdir/$f || ERROR=y
2013         done
2014         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
2015         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
2016         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
2017
2018         # check it's updates in sync
2019         umount_client $MOUNT
2020         stop_mds
2021
2022         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
2023         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2024         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
2025
2026         start_mds
2027         mount_client $MOUNT
2028         for f in $FILES; do
2029                 [ $V ] && log "verifying $DIR/$tdir/$f"
2030                 diff -q $f $DIR/$tdir/$f || ERROR=y
2031         done
2032         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
2033         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
2034         umount_client $MOUNT
2035         stop_mds
2036         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
2037
2038         log "files compared the same"
2039         cleanup
2040 }
2041 run_test 38 "MDS recreates missing lov_objid file from OST data"
2042
2043 test_39() {
2044         PTLDEBUG=+malloc
2045         setup
2046         cleanup
2047         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2048                 error "memory leak detected" || true
2049 }
2050 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2051
2052 test_40() { # bug 15759
2053         start_ost
2054         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2055         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2056         start_mds
2057         cleanup
2058 }
2059 run_test 40 "race during service thread startup"
2060
2061 test_41a() { #bug 14134
2062         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2063            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2064                 skip "Loop devices does not work with nosvc option"
2065                 return
2066         fi
2067
2068         local rc
2069         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2070
2071         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2072         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2073         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2074         mkdir -p $MOUNT
2075         mount_client $MOUNT || return 1
2076         sleep 5
2077
2078         echo "blah blah" > $MOUNT/$tfile
2079         cat $MOUNT/$tfile
2080
2081         umount_client $MOUNT
2082         stop ost1 -f || return 201
2083         stop_mds -f || return 202
2084         stop_mds -f || return 203
2085         unload_modules_conf || return 204
2086         return $rc
2087 }
2088 run_test 41a "mount mds with --nosvc and --nomgs"
2089
2090 test_41b() {
2091         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2092            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2093                 skip "Loop devices does not work with nosvc option"
2094                 return
2095         fi
2096
2097         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2098
2099         stopall
2100         reformat
2101         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2102
2103         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2104         start_ost
2105         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2106         mkdir -p $MOUNT
2107         mount_client $MOUNT || return 1
2108         sleep 5
2109
2110         echo "blah blah" > $MOUNT/$tfile
2111         cat $MOUNT/$tfile || return 200
2112
2113         umount_client $MOUNT
2114         stop_ost || return 201
2115         stop_mds -f || return 202
2116         stop_mds -f || return 203
2117
2118 }
2119 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2120
2121 test_42() { #bug 14693
2122         setup
2123         check_mount || return 2
2124         do_facet mgs $LCTL conf_param lustre.llite.some_wrong_param=10
2125         umount_client $MOUNT
2126         mount_client $MOUNT || return 1
2127         cleanup
2128         return 0
2129 }
2130 run_test 42 "invalid config param should not prevent client from mounting"
2131
2132 test_43() {
2133         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2134         setup
2135         chmod ugo+x $DIR || error "chmod 0 failed"
2136         set_conf_param_and_check mds                                    \
2137                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2138                 "$FSNAME.mdt.root_squash"                               \
2139                 "0:0"
2140         set_conf_param_and_check mds                                    \
2141                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2142                 "$FSNAME.mdt.nosquash_nids"                             \
2143                 "NONE"
2144
2145     #
2146     # create set of test files
2147     #
2148     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2149     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2150     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2151
2152     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2153     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2154
2155     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2156     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2157     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2158
2159         #
2160         # check root_squash:
2161         #   set root squash UID:GID to RUNAS_ID
2162         #   root should be able to access only files owned by RUNAS_ID
2163         #
2164         set_conf_param_and_check mds                                    \
2165                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2166                 "$FSNAME.mdt.root_squash"                               \
2167                 "$RUNAS_ID:$RUNAS_ID"
2168
2169     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2170     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2171         error "$ST: root read permission is denied"
2172     echo "$ST: root read permission is granted - ok"
2173
2174     echo "444" | \
2175     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2176         error "$ST: root write permission is denied"
2177     echo "$ST: root write permission is granted - ok"
2178
2179     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2180     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2181         error "$ST: root read permission is granted"
2182     echo "$ST: root read permission is denied - ok"
2183
2184     echo "555" | \
2185     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2186         error "$ST: root write permission is granted"
2187     echo "$ST: root write permission is denied - ok"
2188
2189     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2190     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2191         error "$ST: root unlink permission is granted"
2192     echo "$ST: root unlink permission is denied - ok"
2193
2194     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2195         error "$ST: root create permission is granted"
2196     echo "$ST: root create permission is denied - ok"
2197
2198         #
2199         # check nosquash_nids:
2200         #   put client's NID into nosquash_nids list,
2201         #   root should be able to access root file after that
2202         #
2203         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2204         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2205         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2206         set_conf_param_and_check mds                                    \
2207                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2208                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2209                 "$NIDLIST"
2210
2211     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2212     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2213         error "$ST: root read permission is denied"
2214     echo "$ST: root read permission is granted - ok"
2215
2216     echo "666" | \
2217     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2218         error "$ST: root write permission is denied"
2219     echo "$ST: root write permission is granted - ok"
2220
2221     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2222     rm $DIR/$tdir-rootdir/tfile-1 || \
2223         error "$ST: root unlink permission is denied"
2224     echo "$ST: root unlink permission is granted - ok"
2225     touch $DIR/$tdir-rootdir/tfile-2 || \
2226         error "$ST: root create permission is denied"
2227     echo "$ST: root create permission is granted - ok"
2228
2229     return 0
2230 }
2231 run_test 43 "check root_squash and nosquash_nids"
2232
2233 umount_client $MOUNT
2234 cleanup_nocli
2235
2236 test_44() { # 16317
2237         setup
2238         check_mount || return 2
2239         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2240         STATS_FOUND=no
2241         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2242         for VAL in $UUIDS; do
2243                 NID=$(echo $VAL | cut -d= -f1)
2244                 CLUUID=$(echo $VAL | cut -d= -f2)
2245                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2246         done
2247         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2248         cleanup
2249         return 0
2250 }
2251 run_test 44 "mounted client proc entry exists"
2252
2253 test_45() { #17310
2254         setup
2255         check_mount || return 2
2256         stop_mds
2257         df -h $MOUNT &
2258         log "sleep 60 sec"
2259         sleep 60
2260 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2261         do_facet client "lctl set_param fail_loc=0x50f"
2262         log "sleep 10 sec"
2263         sleep 10
2264         manual_umount_client --force || return 3
2265         do_facet client "lctl set_param fail_loc=0x0"
2266         start_mds
2267         mount_client $MOUNT || return 4
2268         cleanup
2269         return 0
2270 }
2271 run_test 45 "long unlink handling in ptlrpcd"
2272
2273 cleanup_46a() {
2274         trap 0
2275         local rc=0
2276         local count=$1
2277
2278         umount_client $MOUNT2 || rc=$?
2279         umount_client $MOUNT || rc=$?
2280         while [ $count -gt 0 ]; do
2281                 stop ost${count} -f || rc=$?
2282                 let count=count-1
2283         done    
2284         stop_mds || rc=$?
2285         cleanup_nocli || rc=$?
2286         #writeconf to remove all ost2 traces for subsequent tests
2287         writeconf
2288         return $rc
2289 }
2290
2291 test_46a() {
2292         echo "Testing with $OSTCOUNT OSTs"
2293         reformat_and_config
2294         start_mds || return 1
2295         #first client should see only one ost
2296         start_ost || return 2
2297         wait_osc_import_state mds ost FULL
2298         #start_client
2299         mount_client $MOUNT || return 3
2300         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2301
2302         local i
2303         for (( i=2; i<=$OSTCOUNT; i++ )); do
2304             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2305         done
2306
2307         # wait until osts in sync
2308         for (( i=2; i<=$OSTCOUNT; i++ )); do
2309             wait_osc_import_state mds ost$i FULL
2310             wait_osc_import_state client ost$i FULL
2311         done
2312
2313         #second client see all ost's
2314
2315         mount_client $MOUNT2 || return 8
2316         $LFS setstripe -c -1 $MOUNT2 || return 9
2317         $LFS getstripe $MOUNT2 || return 10
2318
2319         echo "ok" > $MOUNT2/widestripe
2320         $LFS getstripe $MOUNT2/widestripe || return 11
2321         # fill acl buffer for avoid expand lsm to them
2322         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2323             setfacl -m $acl $MOUNT2/widestripe
2324         done
2325
2326         # will be deadlock
2327         stat $MOUNT/widestripe || return 12
2328
2329         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2330         return 0
2331 }
2332 run_test 46a "handle ost additional - wide striped file"
2333
2334 test_47() { #17674
2335         reformat
2336         setup_noconfig
2337         check_mount || return 2
2338         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2339
2340         local lru_size=[]
2341         local count=0
2342         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2343             if echo $ns | grep "MDT[[:digit:]]*"; then
2344                 continue
2345             fi
2346             lrs=$(echo $ns | sed 's/.*lru_size=//')
2347             lru_size[count]=$lrs
2348             let count=count+1
2349         done
2350
2351         facet_failover ost1
2352         facet_failover $SINGLEMDS
2353         client_up || return 3
2354
2355         count=0
2356         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2357             if echo $ns | grep "MDT[[:digit:]]*"; then
2358                 continue
2359             fi
2360             lrs=$(echo $ns | sed 's/.*lru_size=//')
2361             if ! test "$lrs" -eq "${lru_size[count]}"; then
2362                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2363                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2364             fi
2365             let count=count+1
2366         done
2367
2368         cleanup
2369         return 0
2370 }
2371 run_test 47 "server restart does not make client loss lru_resize settings"
2372
2373 cleanup_48() {
2374         trap 0
2375
2376         # reformat after this test is needed - if test will failed
2377         # we will have unkillable file at FS
2378         reformat_and_config
2379 }
2380
2381 test_48() { # bug 17636
2382         reformat
2383         setup_noconfig
2384         check_mount || return 2
2385
2386         $LFS setstripe -c -1 $MOUNT || return 9
2387         $LFS getstripe $MOUNT || return 10
2388
2389         echo "ok" > $MOUNT/widestripe
2390         $LFS getstripe $MOUNT/widestripe || return 11
2391
2392         trap cleanup_48 EXIT ERR
2393
2394         # fill acl buffer for avoid expand lsm to them
2395         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2396             setfacl -m $acl $MOUNT/widestripe
2397         done
2398
2399         stat $MOUNT/widestripe || return 12
2400
2401         cleanup_48
2402         return 0
2403 }
2404 run_test 48 "too many acls on file"
2405
2406 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2407 test_49() { # bug 17710
2408         local timeout_orig=$TIMEOUT
2409         local ldlm_timeout_orig=$LDLM_TIMEOUT
2410         local LOCAL_TIMEOUT=20
2411
2412         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2413         TIMEOUT=$LOCAL_TIMEOUT
2414
2415         reformat
2416         setup_noconfig
2417         check_mount || return 1
2418
2419         echo "check ldlm_timout..."
2420         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2421         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2422         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2423
2424         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2425                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2426         fi
2427
2428         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2429                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2430         fi
2431
2432         umount_client $MOUNT
2433         stop_ost || return 2
2434         stop_mds || return 3
2435
2436         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2437
2438         reformat
2439         setup_noconfig
2440         check_mount || return 7
2441
2442         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2443         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2444         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2445
2446         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2447                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2448         fi
2449
2450         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2451                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2452         fi
2453
2454         cleanup || return $?
2455
2456         LDLM_TIMEOUT=$ldlm_timeout_orig
2457         TIMEOUT=$timeout_orig
2458 }
2459 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2460
2461 lazystatfs() {
2462         # Test both statfs and lfs df and fail if either one fails
2463         multiop_bg_pause $1 f_
2464         RC1=$?
2465         PID=$!
2466         killall -USR1 multiop
2467         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2468         wait $PID || { RC1=$?; log "multiop return error "; }
2469
2470         $LFS df &
2471         PID=$!
2472         sleep 5
2473         kill -s 0 $PID
2474         RC2=$?
2475         if [ $RC2 -eq 0 ]; then
2476             kill -s 9 $PID
2477             log "lazystatfs df failed"
2478         fi
2479
2480         RC=0
2481         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2482         return $RC
2483 }
2484
2485 test_50a() {
2486         setup
2487         lctl set_param llite.$FSNAME-*.lazystatfs=1
2488         touch $DIR/$tfile
2489
2490         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2491
2492         cleanup || return $?
2493 }
2494 run_test 50a "lazystatfs all servers available =========================="
2495
2496 test_50b() {
2497         setup
2498         lctl set_param llite.$FSNAME-*.lazystatfs=1
2499         touch $DIR/$tfile
2500
2501         # Wait for client to detect down OST
2502         stop_ost || error "Unable to stop OST1"
2503         wait_osc_import_state mds ost DISCONN
2504
2505         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2506
2507         umount_client $MOUNT || error "Unable to unmount client"
2508         stop_mds || error "Unable to stop MDS"
2509 }
2510 run_test 50b "lazystatfs all servers down =========================="
2511
2512 test_50c() {
2513         start_mds || error "Unable to start MDS"
2514         start_ost || error "Unable to start OST1"
2515         start_ost2 || error "Unable to start OST2"
2516         mount_client $MOUNT || error "Unable to mount client"
2517         lctl set_param llite.$FSNAME-*.lazystatfs=1
2518         touch $DIR/$tfile
2519
2520         # Wait for client to detect down OST
2521         stop_ost || error "Unable to stop OST1"
2522         wait_osc_import_state mds ost DISCONN
2523         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2524
2525         umount_client $MOUNT || error "Unable to unmount client"
2526         stop_ost2 || error "Unable to stop OST2"
2527         stop_mds || error "Unable to stop MDS"
2528         #writeconf to remove all ost2 traces for subsequent tests
2529         writeconf
2530 }
2531 run_test 50c "lazystatfs one server down =========================="
2532
2533 test_50d() {
2534         start_mds || error "Unable to start MDS"
2535         start_ost || error "Unable to start OST1"
2536         start_ost2 || error "Unable to start OST2"
2537         mount_client $MOUNT || error "Unable to mount client"
2538         lctl set_param llite.$FSNAME-*.lazystatfs=1
2539         touch $DIR/$tfile
2540
2541         # Issue the statfs during the window where the client still
2542         # belives the OST to be available but it is in fact down.
2543         # No failure just a statfs which hangs for a timeout interval.
2544         stop_ost || error "Unable to stop OST1"
2545         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2546
2547         umount_client $MOUNT || error "Unable to unmount client"
2548         stop_ost2 || error "Unable to stop OST2"
2549         stop_mds || error "Unable to stop MDS"
2550         #writeconf to remove all ost2 traces for subsequent tests
2551         writeconf
2552 }
2553 run_test 50d "lazystatfs client/server conn race =========================="
2554
2555 test_50e() {
2556         local RC1
2557         local pid
2558
2559         reformat_and_config
2560         start_mds || return 1
2561         #first client should see only one ost
2562         start_ost || return 2
2563         wait_osc_import_state mds ost FULL
2564
2565         # Wait for client to detect down OST
2566         stop_ost || error "Unable to stop OST1"
2567         wait_osc_import_state mds ost DISCONN
2568
2569         mount_client $MOUNT || error "Unable to mount client"
2570         lctl set_param llite.$FSNAME-*.lazystatfs=0
2571
2572         multiop_bg_pause $MOUNT _f
2573         RC1=$?
2574         pid=$!
2575
2576         if [ $RC1 -ne 0 ]; then
2577                 log "multiop failed $RC1"
2578         else
2579             kill -USR1 $pid
2580             sleep $(( $TIMEOUT+1 ))
2581             kill -0 $pid
2582             [ $? -ne 0 ] && error "process isn't sleep"
2583             start_ost || error "Unable to start OST1"
2584             wait $pid || error "statfs failed"
2585         fi
2586
2587         umount_client $MOUNT || error "Unable to unmount client"
2588         stop_ost || error "Unable to stop OST1"
2589         stop_mds || error "Unable to stop MDS"
2590 }
2591 run_test 50e "normal statfs all servers down =========================="
2592
2593 test_50f() {
2594         local RC1
2595         local pid
2596         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2597
2598         start_mds || error "Unable to start mds"
2599         #first client should see only one ost
2600         start_ost || error "Unable to start OST1"
2601         wait_osc_import_state mds ost FULL
2602
2603         start_ost2 || error "Unable to start OST2"
2604         wait_osc_import_state mds ost2 FULL
2605
2606         # Wait for client to detect down OST
2607         stop_ost2 || error "Unable to stop OST2"
2608
2609         wait_osc_import_state mds ost2 DISCONN
2610         mount_client $MOUNT || error "Unable to mount client"
2611         lctl set_param llite.$FSNAME-*.lazystatfs=0
2612
2613         multiop_bg_pause $MOUNT _f
2614         RC1=$?
2615         pid=$!
2616
2617         if [ $RC1 -ne 0 ]; then
2618                 log "lazystatfs multiop failed $RC1"
2619         else
2620             kill -USR1 $pid
2621             sleep $(( $TIMEOUT+1 ))
2622             kill -0 $pid
2623             [ $? -ne 0 ] && error "process isn't sleep"
2624             start_ost2 || error "Unable to start OST2"
2625             wait $pid || error "statfs failed"
2626             stop_ost2 || error "Unable to stop OST2"
2627         fi
2628
2629         umount_client $MOUNT || error "Unable to unmount client"
2630         stop_ost || error "Unable to stop OST1"
2631         stop_mds || error "Unable to stop MDS"
2632         #writeconf to remove all ost2 traces for subsequent tests
2633         writeconf
2634 }
2635 run_test 50f "normal statfs one server in down =========================="
2636
2637 test_50g() {
2638         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2639         setup
2640         start_ost2 || error "Unable to start OST2"
2641         wait_osc_import_state mds ost2 FULL
2642         wait_osc_import_state client ost2 FULL
2643
2644         local PARAM="${FSNAME}-OST0001.osc.active"
2645
2646         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2647         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2648
2649         umount_client $MOUNT || error "Unable to unmount client"
2650         mount_client $MOUNT || error "Unable to mount client"
2651         # This df should not cause a panic
2652         df -k $MOUNT
2653
2654         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2655         rm -f $DIR/$tfile
2656         umount_client $MOUNT || error "Unable to unmount client"
2657         stop_ost2 || error "Unable to stop OST2"
2658         stop_ost || error "Unable to stop OST1"
2659         stop_mds || error "Unable to stop MDS"
2660         #writeconf to remove all ost2 traces for subsequent tests
2661         writeconf
2662 }
2663 run_test 50g "deactivated OST should not cause panic====================="
2664
2665 test_51() {
2666         local LOCAL_TIMEOUT=20
2667
2668         reformat
2669         setup_noconfig
2670         check_mount || return 1
2671
2672         mkdir $MOUNT/d1
2673         $LFS setstripe -c -1 $MOUNT/d1
2674         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2675         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2676         touch $MOUNT/d1/f1 &
2677         local pid=$!
2678         sleep 2
2679         start_ost2 || return 2
2680         wait $pid
2681         stop_ost2 || return 3
2682         cleanup
2683         #writeconf to remove all ost2 traces for subsequent tests
2684         writeconf
2685 }
2686 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2687
2688 copy_files_xattrs()
2689 {
2690         local node=$1
2691         local dest=$2
2692         local xattrs=$3
2693         shift 3
2694
2695         do_node $node mkdir -p $dest
2696         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2697
2698         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2699                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2700         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
2701
2702         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
2703         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
2704 }
2705
2706 diff_files_xattrs()
2707 {
2708         local node=$1
2709         local backup=$2
2710         local xattrs=$3
2711         shift 3
2712
2713         local backup2=${TMP}/backup2
2714
2715         do_node $node mkdir -p $backup2
2716         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2717
2718         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
2719                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2720         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
2721
2722         do_node $node "diff -rq $backup $backup2"
2723         [ $? -eq 0 ] || { error "contents differ"; return 3; }
2724
2725         local xattrs2=${TMP}/xattrs2
2726         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
2727         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
2728
2729         do_node $node "diff $xattrs $xattrs2"
2730         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
2731
2732         do_node $node "rm -rf $backup2 $xattrs2"
2733         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
2734 }
2735
2736 test_52() {
2737         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2738                 skip "Only applicable to ldiskfs-based MDTs"
2739                 return
2740         fi
2741
2742         start_mds
2743         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
2744         start_ost
2745         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
2746         mount_client $MOUNT
2747         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
2748
2749         local nrfiles=8
2750         local ost1mnt=$(facet_mntpt ost1)
2751         local ost1node=$(facet_active_host ost1)
2752         local ost1tmp=$TMP/conf52
2753         local loop
2754
2755         mkdir -p $DIR/$tdir
2756         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
2757         touch $TMP/modified_first
2758         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
2759         local mtime=$(stat -c %Y $TMP/modified_first)
2760         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
2761
2762         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
2763         sleep 1
2764
2765         $LFS setstripe -c -1 -S 1M $DIR/$tdir
2766         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
2767
2768         for (( i=0; i < nrfiles; i++ )); do
2769                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
2770                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
2771                 echo -n .
2772         done
2773         echo
2774
2775         # backup files
2776         echo backup files to $TMP/files
2777         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
2778         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2779         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
2780
2781         umount_client $MOUNT
2782         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
2783         stop_ost
2784         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
2785
2786         echo mount ost1 as ldiskfs
2787         do_node $ost1node mkdir -p $ost1mnt
2788         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
2789         if ! do_node $ost1node test -b $ost1_dev; then
2790                 loop="-o loop"
2791         fi
2792         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
2793                 $ost1mnt
2794         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
2795
2796         # backup objects
2797         echo backup objects to $ost1tmp/objects
2798         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/0 -type f -size +0'\
2799                         '-newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
2800         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2801         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
2802
2803         # move objects to lost+found
2804         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
2805         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
2806
2807         # recover objects
2808         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
2809         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
2810
2811         # compare restored objects against saved ones
2812         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2813         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
2814
2815         do_node $ost1node "umount $ost1mnt"
2816         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
2817
2818         start_ost
2819         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
2820         mount_client $MOUNT
2821         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
2822
2823         # compare files
2824         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2825         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
2826
2827         rm -rf $TMP/files $TMP/file_xattrs
2828         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
2829         do_node $ost1node "rm -rf $ost1tmp"
2830         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
2831         cleanup
2832 }
2833 run_test 52 "check recovering objects from lost+found"
2834
2835 # Checks threads_min/max/started for some service
2836 #
2837 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
2838 # parameter pattern prefix like 'ost.*.ost'.
2839 thread_sanity() {
2840         local modname=$1
2841         local facet=$2
2842         local parampat=$3
2843         local opts=$4
2844         local basethr=$5
2845         local tmin
2846         local tmin2
2847         local tmax
2848         local tmax2
2849         local tstarted
2850         local paramp
2851         local msg="Insane $modname thread counts"
2852         local ncpts=$(check_cpt_number $facet)
2853         local nthrs
2854         shift 4
2855
2856         setup
2857         check_mount || return 41
2858
2859         # We need to expand $parampat, but it may match multiple parameters, so
2860         # we'll pick the first one
2861         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
2862                 error "Couldn't expand ${parampat}.threads_min parameter name"
2863                 return 22
2864         fi
2865
2866         # Remove the .threads_min part
2867         paramp=${paramp%.threads_min}
2868
2869         # Check for sanity in defaults
2870         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2871         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2872         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
2873         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
2874         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
2875         nthrs=$(expr $tmax - $tmin)
2876         if [ $nthrs -lt $ncpts ]; then
2877                 nthrs=0
2878         else
2879                 nthrs=$ncpts
2880         fi
2881
2882         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
2883                 skip_env "module parameter forced $facet thread count" &&
2884                 tmin=3 && tmax=$((3 * tmax))
2885
2886         # Check that we can change min/max
2887         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
2888         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
2889         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2890         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2891         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
2892
2893         # Check that we can set min/max to the same value
2894         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2895         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
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 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
2899
2900         # Check that we can't set max < min
2901         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
2902         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2903         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2904         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
2905
2906         # We need to ensure that we get the module options desired; to do this
2907         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
2908         LOAD_MODULES_REMOTE=true
2909         cleanup
2910         local oldvalue
2911         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
2912         setmodopts -a $modname "$newvalue" oldvalue
2913
2914         load_modules
2915         setup
2916         check_mount || return 41
2917
2918         # Restore previous setting of MODOPTS_*
2919         setmodopts $modname "$oldvalue"
2920
2921         # Check that $opts took
2922         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
2923         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
2924         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
2925         lassert 28 "$msg" '(($tstarted == $tmin && $tstarted == $tmax ))' || return $?
2926         cleanup
2927
2928         load_modules
2929         setup
2930         cleanup
2931 }
2932
2933 test_53a() {
2934         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
2935 }
2936 run_test 53a "check OSS thread count params"
2937
2938 test_53b() {
2939         thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' '16'
2940 }
2941 run_test 53b "check MDT thread count params"
2942
2943 test_54a() {
2944         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2945                 skip "Only applicable to ldiskfs-based MDTs"
2946                 return
2947         fi
2948
2949     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
2950     [ $? -eq 0 ] || error "llverdev failed!"
2951     reformat_and_config
2952 }
2953 run_test 54a "test llverdev and partial verify of device"
2954
2955 test_54b() {
2956         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2957                 skip "Only applicable to ldiskfs-based MDTs"
2958                 return
2959         fi
2960
2961     setup
2962     run_llverfs $MOUNT -p
2963     [ $? -eq 0 ] || error "llverfs failed!"
2964     cleanup
2965 }
2966 run_test 54b "test llverfs and partial verify of filesystem"
2967
2968 lov_objid_size()
2969 {
2970         local max_ost_index=$1
2971         echo -n $(((max_ost_index + 1) * 8))
2972 }
2973
2974 test_55() {
2975         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2976                 skip "Only applicable to ldiskfs-based MDTs"
2977                 return
2978         fi
2979
2980         local mdsdev=$(mdsdevname 1)
2981         local mdsvdev=$(mdsvdevname 1)
2982
2983         for i in 1023 2048
2984         do
2985                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
2986                         $mdsvdev || exit 10
2987                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
2988                         --reformat $(ostdevname 1) $(ostvdevname 1)
2989                 setup_noconfig
2990                 stopall
2991                 setup_noconfig
2992                 sync
2993
2994                 echo checking size of lov_objid for ost index $i
2995                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
2996                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
2997                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
2998                 else
2999                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3000                 fi
3001                 stopall
3002         done
3003
3004         reformat
3005 }
3006 run_test 55 "check lov_objid size"
3007
3008 test_56() {
3009         local mds_journal_size_orig=$MDSJOURNALSIZE
3010
3011         MDSJOURNALSIZE=16
3012
3013         for num in $(seq 1 $MDSCOUNT); do
3014                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3015                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3016         done
3017         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=1000 --reformat \
3018                 $(ostdevname 1) $(ostvdevname 1)
3019         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=10000 --reformat \
3020                 $(ostdevname 2) $(ostvdevname 2)
3021
3022         start_mgsmds
3023         start_ost
3024         start_ost2 || error "Unable to start second ost"
3025         mount_client $MOUNT || error "Unable to mount client"
3026         echo ok
3027         $LFS osts
3028         stopall
3029         MDSJOURNALSIZE=$mds_journal_size_orig
3030         reformat
3031 }
3032 run_test 56 "check big indexes"
3033
3034 test_57a() { # bug 22656
3035         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3036         writeconf
3037         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3038         start_mgsmds
3039         start_ost && error "OST registration from failnode should fail"
3040         reformat
3041 }
3042 run_test 57a "initial registration from failnode should fail (should return errs)"
3043
3044 test_57b() {
3045         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3046         writeconf
3047         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3048         start_mgsmds
3049         start_ost || error "OST registration from servicenode should not fail"
3050         reformat
3051 }
3052 run_test 57b "initial registration from servicenode should not fail"
3053
3054 count_osts() {
3055         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3056 }
3057
3058 test_58() { # bug 22658
3059         if [ $(facet_fstype mds) != ldiskfs ]; then
3060                 skip "Only applicable to ldiskfs-based MDTs"
3061                 return
3062         fi
3063         setup_noconfig
3064         mkdir -p $DIR/$tdir
3065         createmany -o $DIR/$tdir/$tfile-%d 100
3066         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3067 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3068         do_facet mds "lctl set_param fail_loc=0x601"
3069         unlinkmany $DIR/$tdir/$tfile-%d 100
3070         stop mds
3071         local MNTDIR=$(facet_mntpt mds)
3072         # remove all files from the OBJECTS dir
3073         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
3074         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
3075         do_facet mds "umount $MNTDIR"
3076         # restart MDS with missing llog files
3077         start_mds
3078         do_facet mds "lctl set_param fail_loc=0"
3079         reformat
3080 }
3081 run_test 58 "missing llog files must not prevent MDT from mounting"
3082
3083 test_59() {
3084         start_mgsmds >> /dev/null
3085         local C1=$(count_osts)
3086         if [ $C1 -eq 0 ]; then
3087                 start_ost >> /dev/null
3088                 C1=$(count_osts)
3089         fi
3090         stopall
3091         echo "original ost count: $C1 (expect > 0)"
3092         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3093         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3094         local C2=$(count_osts)
3095         echo "after mdt writeconf count: $C2 (expect 0)"
3096         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3097         echo "OST start without writeconf should fail:"
3098         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3099         echo "OST start with writeconf should succeed:"
3100         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3101         local C3=$(count_osts)
3102         echo "after ost writeconf count: $C3 (expect 1)"
3103         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3104         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3105         local C4=$(count_osts)
3106         echo "after ost2 writeconf count: $C4 (expect 2)"
3107         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3108         stop_ost2 >> /dev/null
3109         cleanup_nocli >> /dev/null
3110         #writeconf to remove all ost2 traces for subsequent tests
3111         writeconf
3112 }
3113 run_test 59 "writeconf mount option"
3114
3115 test_60() { # LU-471
3116         local num
3117
3118         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3119                 skip "Only applicable to ldiskfs-based MDTs"
3120                 return
3121         fi
3122
3123         for num in $(seq $MDSCOUNT); do
3124                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3125                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3126                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3127                         exit 10
3128         done
3129
3130         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3131         rc=${PIPESTATUS[0]}
3132         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3133
3134         # MDT default has dirdata feature
3135         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3136         # we disable uninit_bg feature
3137         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3138         # we set stride extended options
3139         echo $dump | grep stride > /dev/null || error "stride is not set"
3140         reformat
3141 }
3142 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3143
3144 test_61() { # LU-80
3145         local reformat=false
3146
3147         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3148                 { skip "Need MDS version at least 2.1.53"; return 0; }
3149
3150         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3151            ! large_xattr_enabled; then
3152                 reformat=true
3153                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3154
3155                 for num in $(seq $MDSCOUNT); do
3156                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3157                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3158                         error "add mds $num failed"
3159                 done
3160         fi
3161
3162     setup_noconfig || error "setting up the filesystem failed"
3163     client_up || error "starting client failed"
3164
3165     local file=$DIR/$tfile
3166     touch $file
3167
3168     local large_value="$(generate_string $(max_xattr_size))"
3169     local small_value="bar"
3170
3171     local name="trusted.big"
3172     log "save large xattr $name on $file"
3173     setfattr -n $name -v $large_value $file ||
3174         error "saving $name on $file failed"
3175
3176     local new_value=$(get_xattr_value $name $file)
3177     [[ "$new_value" != "$large_value" ]] &&
3178         error "$name different after saving"
3179
3180     log "shrink value of $name on $file"
3181     setfattr -n $name -v $small_value $file ||
3182         error "shrinking value of $name on $file failed"
3183
3184     new_value=$(get_xattr_value $name $file)
3185     [[ "$new_value" != "$small_value" ]] &&
3186         error "$name different after shrinking"
3187
3188     log "grow value of $name on $file"
3189     setfattr -n $name -v $large_value $file ||
3190         error "growing value of $name on $file failed"
3191
3192     new_value=$(get_xattr_value $name $file)
3193     [[ "$new_value" != "$large_value" ]] &&
3194         error "$name different after growing"
3195
3196     log "check value of $name on $file after remounting MDS"
3197     fail $SINGLEMDS
3198     new_value=$(get_xattr_value $name $file)
3199     [[ "$new_value" != "$large_value" ]] &&
3200         error "$name different after remounting MDS"
3201
3202     log "remove large xattr $name from $file"
3203     setfattr -x $name $file || error "removing $name from $file failed"
3204
3205     rm -f $file
3206     stopall
3207         if $reformat; then
3208                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3209                 reformat
3210         fi
3211 }
3212 run_test 61 "large xattr"
3213
3214 test_62() {
3215         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3216                 skip "Only applicable to ldiskfs-based MDTs"
3217                 return
3218         fi
3219
3220         # MRP-118
3221         local mdsdev=$(mdsdevname 1)
3222         local ostdev=$(ostdevname 1)
3223
3224         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3225                 { skip "Need MDS version at least 2.2.51"; return 0; }
3226
3227         echo "disable journal for mds"
3228         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3229         start_mds && error "MDT start should fail"
3230         echo "disable journal for ost"
3231         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3232         start_ost && error "OST start should fail"
3233         cleanup || return $?
3234         reformat_and_config
3235 }
3236 run_test 62 "start with disabled journal"
3237
3238 test_63() {
3239         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3240                 skip "Only applicable to ldiskfs-based MDTs"
3241                 return
3242         fi
3243
3244         local inode_slab=$(do_facet $SINGLEMDS \
3245                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3246         if [ -z "$inode_slab" ]; then
3247                 skip "ldiskfs module has not been loaded"
3248                 return
3249         fi
3250
3251         echo "$inode_slab ldisk inodes per page"
3252         [ "$inode_slab" -ge "3" ] ||
3253                 error "ldisk inode size is too big, $inode_slab objs per page"
3254         return
3255 }
3256 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3257
3258 test_64() {
3259         start_mds
3260         start_ost
3261         start_ost2 || error "Unable to start second ost"
3262         mount_client $MOUNT || error "Unable to mount client"
3263         stop_ost2 || error "Unable to stop second ost"
3264         echo "$LFS df"
3265         $LFS df --lazy || error "lfs df failed"
3266         cleanup || return $?
3267 }
3268 run_test 64 "check lfs df --lazy "
3269
3270 if ! combined_mgs_mds ; then
3271         stop mgs
3272 fi
3273
3274 cleanup_gss
3275
3276 complete $SECONDS
3277 exit_status