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