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