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