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