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