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