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