Whamcloud - gitweb
LU-427 test: Test failure on test suite lfsck
[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 --fsname=$NEWNAME $tmpdir/mds || error "tunefs failed"
1285         combined_mgs_mds || stop mgs
1286
1287         start32 mds1 $tmpdir/mds "-o loop" && \
1288                 trap cleanup_32 EXIT INT || return 3
1289
1290         local UUID=$($LCTL get_param -n mdt.${NEWNAME}-MDT0000.uuid)
1291         echo MDS uuid $UUID
1292         [ "$UUID" == "${NEWNAME}-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1293
1294         $TUNEFS --mgsnode=$HOSTNAME --writeconf --fsname=$NEWNAME $tmpdir/ost1 ||\
1295             error "tunefs failed"
1296         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1297         UUID=$($LCTL get_param -n obdfilter.${NEWNAME}-OST0000.uuid)
1298         echo OST uuid $UUID
1299         [ "$UUID" == "${NEWNAME}-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1300
1301         local NID=$($LCTL list_nids | head -1)
1302
1303         echo "OSC changes should succeed:"
1304         $LCTL conf_param ${NEWNAME}-OST0000.osc.max_dirty_mb=15 || return 7
1305         $LCTL conf_param ${NEWNAME}-OST0000.failover.node=$NID || return 8
1306         echo "ok."
1307
1308         echo "MDC changes should succeed:"
1309         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1310         $LCTL conf_param ${NEWNAME}-MDT0000.failover.node=$NID || return 10
1311         echo "ok."
1312
1313         echo "LOV changes should succeed:"
1314         $LCTL pool_new ${NEWNAME}.interop || return 11
1315         $LCTL conf_param ${NEWNAME}-MDT0000.lov.stripesize=4M || return 12
1316         echo "ok."
1317
1318         # MDT and OST should have registered with new nids, so we should have
1319         # a fully-functioning client
1320         echo "Check client and old fs contents"
1321
1322         local device=`h2$NETTYPE $HOSTNAME`:/$NEWNAME
1323         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1324         mount -t lustre $device $MOUNT || return 1
1325
1326         local old=$($LCTL get_param -n mdc.*.max_rpcs_in_flight)
1327         local new=$((old + 5))
1328         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=$new
1329         wait_update $HOSTNAME "$LCTL get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1330
1331         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "94306271 1478" ] || return 12
1332         echo "ok."
1333
1334         cleanup_32
1335
1336         rm -rf $tmpdir || true  # true is only for TMP on NFS
1337 }
1338 run_test 32b "Upgrade from 1.8 with writeconf"
1339
1340 test_33a() { # bug 12333, was test_33
1341         local rc=0
1342         local FSNAME2=test-123
1343         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1344
1345         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1346
1347         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1348                 local dev=${SINGLEMDS}_dev
1349                 local MDSDEV=${!dev}
1350                 is_blkdev $SINGLEMDS $MDSDEV && \
1351                 skip_env "mixed loopback and real device not working" && return
1352         fi
1353
1354         combined_mgs_mds || mkfs_opts="$mkfs_opts --nomgs"
1355
1356         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1357         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1358         add fs2mds $MDS_MKFS_OPTS --mkfsoptions='\"-J size=8\"' --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1359         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1360
1361         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1362         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1363         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1364         mkdir -p $MOUNT2
1365         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1366         echo "ok."
1367
1368         cp /etc/hosts $MOUNT2/ || rc=3
1369         $LFS getstripe $MOUNT2/hosts
1370
1371         umount -d $MOUNT2
1372         stop fs2ost -f
1373         stop fs2mds -f
1374         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1375         cleanup_nocli || rc=6
1376         return $rc
1377 }
1378 run_test 33a "Mount ost with a large index number"
1379
1380 test_33b() {    # was test_34
1381         setup
1382
1383         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1384         # Drop lock cancelation reply during umount
1385         #define OBD_FAIL_LDLM_CANCEL             0x304
1386         do_facet client lctl set_param fail_loc=0x80000304
1387         #lctl set_param debug=-1
1388         umount_client $MOUNT
1389         cleanup
1390 }
1391 run_test 33b "Drop cancel during umount"
1392
1393 test_34a() {
1394         setup
1395         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1396         manual_umount_client
1397         rc=$?
1398         do_facet client killall -USR1 multiop
1399         if [ $rc -eq 0 ]; then
1400                 error "umount not fail!"
1401         fi
1402         sleep 1
1403         cleanup
1404 }
1405 run_test 34a "umount with opened file should be fail"
1406
1407
1408 test_34b() {
1409         setup
1410         touch $DIR/$tfile || return 1
1411         stop_mds --force || return 2
1412
1413         manual_umount_client --force
1414         rc=$?
1415         if [ $rc -ne 0 ]; then
1416                 error "mtab after failed umount - rc $rc"
1417         fi
1418
1419         cleanup
1420         return 0
1421 }
1422 run_test 34b "force umount with failed mds should be normal"
1423
1424 test_34c() {
1425         setup
1426         touch $DIR/$tfile || return 1
1427         stop_ost --force || return 2
1428
1429         manual_umount_client --force
1430         rc=$?
1431         if [ $rc -ne 0 ]; then
1432                 error "mtab after failed umount - rc $rc"
1433         fi
1434
1435         cleanup
1436         return 0
1437 }
1438 run_test 34c "force umount with failed ost should be normal"
1439
1440 test_35a() { # bug 12459
1441         setup
1442
1443         DBG_SAVE="`lctl get_param -n debug`"
1444         lctl set_param debug="ha"
1445
1446         log "Set up a fake failnode for the MDS"
1447         FAKENID="127.0.0.2"
1448         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1449         do_facet mgs $LCTL conf_param ${device}.failover.node=$FAKENID || return 4
1450
1451         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1452         sleep 10
1453
1454         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1455         $LCTL clear
1456         log "$MSG"
1457         log "Stopping the MDT:"
1458         stop_mds || return 5
1459
1460         df $MOUNT > /dev/null 2>&1 &
1461         DFPID=$!
1462         log "Restarting the MDT:"
1463         start_mds || return 6
1464         log "Wait for df ($DFPID) ... "
1465         wait $DFPID
1466         log "done"
1467         lctl set_param debug="$DBG_SAVE"
1468
1469         # retrieve from the log the first server that the client tried to
1470         # contact after the connection loss
1471         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1472         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1473                        /import_select_connection.*$device-mdc.* using connection/ {
1474                                 if (start) {
1475                                         if (\\\$NF ~ /$FAKENID/)
1476                                                 print \\\$NF;
1477                                         else
1478                                                 print 0;
1479                                         exit;
1480                                 }
1481                        }" $TMP/lustre-log-$TESTNAME.log`
1482         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1483         cleanup
1484         # remove nid settings
1485         writeconf
1486 }
1487 run_test 35a "Reconnect to the last active server first"
1488
1489 test_35b() { # bug 18674
1490         remote_mds || { skip "local MDS" && return 0; }
1491         setup
1492
1493         debugsave
1494         $LCTL set_param debug="ha"
1495         $LCTL clear
1496         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1497         log "$MSG"
1498
1499         log "Set up a fake failnode for the MDS"
1500         FAKENID="127.0.0.2"
1501         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" | \
1502                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1503         do_facet mgs "$LCTL conf_param ${device}.failover.node=$FAKENID" || \
1504                 return 1
1505
1506         local at_max_saved=0
1507         # adaptive timeouts may prevent seeing the issue
1508         if at_is_enabled; then
1509                 at_max_saved=$(at_max_get mds)
1510                 at_max_set 0 mds client
1511         fi
1512
1513         mkdir -p $MOUNT/$tdir
1514
1515         log "Injecting EBUSY on MDS"
1516         # Setting OBD_FAIL_MDS_RESEND=0x136
1517         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
1518
1519         $LCTL set_param mdc.${FSNAME}*.stats=clear
1520
1521         log "Creating a test file and stat it"
1522         touch $MOUNT/$tdir/$tfile
1523         stat $MOUNT/$tdir/$tfile
1524
1525         log "Stop injecting EBUSY on MDS"
1526         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
1527         rm -f $MOUNT/$tdir/$tfile
1528
1529         log "done"
1530         # restore adaptive timeout
1531         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1532
1533         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1534
1535         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1536
1537         # retrieve from the log if the client has ever tried to
1538         # contact the fake server after the loss of connection
1539         FAILCONN=`awk "BEGIN {ret = 0;}
1540                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1541                                 ret = 1;
1542                                 if (\\\$NF ~ /$FAKENID/) {
1543                                         ret = 2;
1544                                         exit;
1545                                 }
1546                        }
1547                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1548
1549         [ "$FAILCONN" == "0" ] && \
1550                 log "ERROR: The client reconnection has not been triggered" && \
1551                 return 4
1552         [ "$FAILCONN" == "2" ] && \
1553                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1554                 return 5
1555
1556         # LU-290
1557         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1558         # Reconnects are supposed to be rate limited to one every 5s
1559         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1560                 log "ERROR: Too many reconnects $CONNCNT" && \
1561                 return 6
1562
1563         cleanup
1564         # remove nid settings
1565         writeconf
1566 }
1567 run_test 35b "Continue reconnection retries, if the active server is busy"
1568
1569 test_36() { # 12743
1570         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1571
1572         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1573                 { skip "remote OST" && return 0; }
1574
1575         local rc=0
1576         local FSNAME2=test1234
1577         local fs3ost_HOST=$ost_HOST
1578         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1579
1580         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1581
1582         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1583                 is_blkdev $SINGLEMDS $MDSDEV && \
1584                 skip_env "mixed loopback and real device not working" && return
1585         fi
1586
1587         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1588         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1589         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1590         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1591         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1592         # other argument
1593         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1594         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1595
1596         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1597         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1598         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1599         mkdir -p $MOUNT2
1600         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1601
1602         sleep 5 # until 11778 fixed
1603
1604         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1605
1606         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1607         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1608         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1609         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1610         DFTOTAL=`echo $STRING | cut -d, -f1`
1611         DFUSED=`echo $STRING  | cut -d, -f2`
1612         DFAVAIL=`echo $STRING | cut -d, -f3`
1613         DFFREE=$(($DFTOTAL - $DFUSED))
1614
1615         ALLOWANCE=$((64 * $OSTCOUNT))
1616
1617         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1618            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1619                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1620                 rc=1
1621         fi
1622         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1623            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1624                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1625                 rc=2
1626         fi
1627         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1628            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1629                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1630                 rc=3
1631        fi
1632
1633         umount -d $MOUNT2
1634         stop fs3ost -f || return 200
1635         stop fs2ost -f || return 201
1636         stop fs2mds -f || return 202
1637         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1638         unload_modules_conf || return 203
1639         return $rc
1640 }
1641 run_test 36 "df report consistency on OSTs with different block size"
1642
1643 test_37() {
1644         local mntpt=$(facet_mntpt $SINGLEMDS)
1645         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
1646         local mdsdev_sym="$TMP/sym_mdt.img"
1647
1648         echo "MDS :     $mdsdev"
1649         echo "SYMLINK : $mdsdev_sym"
1650         do_facet $SINGLEMDS rm -f $mdsdev_sym
1651
1652         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
1653
1654         echo "mount symlink device - $mdsdev_sym"
1655
1656         local rc=0
1657         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $MDS_MOUNT_OPTS  $mdsdev_sym $mntpt 2>&1 )
1658         rc=${PIPESTATUS[0]}
1659
1660         echo mount_op=$mount_op
1661
1662         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
1663
1664         if $(echo $mount_op | grep -q "unable to set tunable"); then
1665                 error "set tunables failed for symlink device"
1666         fi
1667
1668         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
1669
1670         return 0
1671 }
1672 run_test 37 "verify set tunables works for symlink device"
1673
1674 test_38() { # bug 14222
1675         setup
1676         # like runtests
1677         COUNT=10
1678         SRC="/etc /bin"
1679         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1680         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1681         mkdir -p $DIR/$tdir
1682         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1683                 error "copying $SRC to $DIR/$tdir"
1684         sync
1685         umount_client $MOUNT
1686         stop_mds
1687         log "rename lov_objid file on MDS"
1688         rm -f $TMP/lov_objid.orig
1689
1690         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1691         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1692         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1693
1694         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
1695         # check create in mds_lov_connect
1696         start_mds
1697         mount_client $MOUNT
1698         for f in $FILES; do
1699                 [ $V ] && log "verifying $DIR/$tdir/$f"
1700                 diff -q $f $DIR/$tdir/$f || ERROR=y
1701         done
1702         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1703         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
1704         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1705
1706         # check it's updates in sync
1707         umount_client $MOUNT
1708         stop_mds
1709
1710         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1711         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1712         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1713
1714         start_mds
1715         mount_client $MOUNT
1716         for f in $FILES; do
1717                 [ $V ] && log "verifying $DIR/$tdir/$f"
1718                 diff -q $f $DIR/$tdir/$f || ERROR=y
1719         done
1720         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1721         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
1722         umount_client $MOUNT
1723         stop_mds
1724         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1725
1726         log "files compared the same"
1727         cleanup
1728 }
1729 run_test 38 "MDS recreates missing lov_objid file from OST data"
1730
1731 test_39() {
1732         PTLDEBUG=+malloc
1733         setup
1734         cleanup
1735         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
1736                 error "memory leak detected" || true
1737 }
1738 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1739
1740 test_40() { # bug 15759
1741         start_ost
1742         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1743         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
1744         start_mds
1745         cleanup
1746 }
1747 run_test 40 "race during service thread startup"
1748
1749 test_41a() { #bug 14134
1750         echo $MDS_MOUNT_OPTS | grep "loop" && skip " loop devices does not work with nosvc option" && return
1751
1752         local rc
1753         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1754
1755         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1756         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1757         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1758         mkdir -p $MOUNT
1759         mount_client $MOUNT || return 1
1760         sleep 5
1761
1762         echo "blah blah" > $MOUNT/$tfile
1763         cat $MOUNT/$tfile
1764
1765         umount_client $MOUNT
1766         stop ost1 -f || return 201
1767         stop_mds -f || return 202
1768         stop_mds -f || return 203
1769         unload_modules_conf || return 204
1770         return $rc
1771 }
1772 run_test 41a "mount mds with --nosvc and --nomgs"
1773
1774 test_41b() {
1775         echo $MDS_MOUNT_OPTS | grep "loop" && skip " loop devices does not work with nosvc option" && return
1776
1777         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
1778
1779         stopall
1780         reformat
1781         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1782
1783         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1784         start_ost
1785         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1786         mkdir -p $MOUNT
1787         mount_client $MOUNT || return 1
1788         sleep 5
1789
1790         echo "blah blah" > $MOUNT/$tfile
1791         cat $MOUNT/$tfile || return 200
1792
1793         umount_client $MOUNT
1794         stop_ost || return 201
1795         stop_mds -f || return 202
1796         stop_mds -f || return 203
1797
1798 }
1799 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
1800
1801 test_42() { #bug 14693
1802         setup
1803         check_mount || return 2
1804         do_facet mgs $LCTL conf_param lustre.llite.some_wrong_param=10
1805         umount_client $MOUNT
1806         mount_client $MOUNT || return 1
1807         cleanup
1808         return 0
1809 }
1810 run_test 42 "invalid config param should not prevent client from mounting"
1811
1812 test_43() {
1813     [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
1814     setup
1815     chmod ugo+x $DIR || error "chmod 0 failed"
1816     set_and_check mds                                        \
1817         "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"  \
1818         "$FSNAME.mdt.root_squash"                            \
1819         "0:0"
1820     set_and_check mds                                        \
1821        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1822        "$FSNAME.mdt.nosquash_nids"                           \
1823        "NONE"
1824
1825     #
1826     # create set of test files
1827     #
1828     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
1829     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
1830     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
1831
1832     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
1833     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
1834
1835     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
1836     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
1837     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
1838
1839     #
1840     # check root_squash:
1841     #   set root squash UID:GID to RUNAS_ID
1842     #   root should be able to access only files owned by RUNAS_ID
1843     #
1844     set_and_check mds                                        \
1845        "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"   \
1846        "$FSNAME.mdt.root_squash"                             \
1847        "$RUNAS_ID:$RUNAS_ID"
1848
1849     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
1850     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1851         error "$ST: root read permission is denied"
1852     echo "$ST: root read permission is granted - ok"
1853
1854     echo "444" | \
1855     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1856         error "$ST: root write permission is denied"
1857     echo "$ST: root write permission is granted - ok"
1858
1859     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1860     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1861         error "$ST: root read permission is granted"
1862     echo "$ST: root read permission is denied - ok"
1863
1864     echo "555" | \
1865     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1866         error "$ST: root write permission is granted"
1867     echo "$ST: root write permission is denied - ok"
1868
1869     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1870     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
1871         error "$ST: root unlink permission is granted"
1872     echo "$ST: root unlink permission is denied - ok"
1873
1874     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
1875         error "$ST: root create permission is granted"
1876     echo "$ST: root create permission is denied - ok"
1877
1878     #
1879     # check nosquash_nids:
1880     #   put client's NID into nosquash_nids list,
1881     #   root should be able to access root file after that
1882     #
1883     local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
1884     NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
1885     NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
1886     set_and_check mds                                        \
1887        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1888        "$FSNAME-MDTall.mdt.nosquash_nids"                    \
1889        "$NIDLIST"
1890
1891     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1892     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1893         error "$ST: root read permission is denied"
1894     echo "$ST: root read permission is granted - ok"
1895
1896     echo "666" | \
1897     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1898         error "$ST: root write permission is denied"
1899     echo "$ST: root write permission is granted - ok"
1900
1901     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1902     rm $DIR/$tdir-rootdir/tfile-1 || \
1903         error "$ST: root unlink permission is denied"
1904     echo "$ST: root unlink permission is granted - ok"
1905     touch $DIR/$tdir-rootdir/tfile-2 || \
1906         error "$ST: root create permission is denied"
1907     echo "$ST: root create permission is granted - ok"
1908
1909     return 0
1910 }
1911 run_test 43 "check root_squash and nosquash_nids"
1912
1913 umount_client $MOUNT
1914 cleanup_nocli
1915
1916 test_44() { # 16317
1917         setup
1918         check_mount || return 2
1919         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
1920         STATS_FOUND=no
1921         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
1922         for VAL in $UUIDS; do
1923                 NID=$(echo $VAL | cut -d= -f1)
1924                 CLUUID=$(echo $VAL | cut -d= -f2)
1925                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
1926         done
1927         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
1928         cleanup
1929         return 0
1930 }
1931 run_test 44 "mounted client proc entry exists"
1932
1933 test_45() { #17310
1934         setup
1935         check_mount || return 2
1936         stop_mds
1937         df -h $MOUNT &
1938         log "sleep 60 sec"
1939         sleep 60
1940 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1941         do_facet client "lctl set_param fail_loc=0x50f"
1942         log "sleep 10 sec"
1943         sleep 10
1944         manual_umount_client --force || return 3
1945         do_facet client "lctl set_param fail_loc=0x0"
1946         start_mds
1947         mount_client $MOUNT || return 4
1948         cleanup
1949         return 0
1950 }
1951 run_test 45 "long unlink handling in ptlrpcd"
1952
1953 cleanup_46a() {
1954         trap 0
1955         local rc=0
1956         local count=$1
1957
1958         umount_client $MOUNT2 || rc=$?
1959         umount_client $MOUNT || rc=$?
1960         while [ $count -gt 0 ]; do
1961                 stop ost${count} -f || rc=$?
1962                 let count=count-1
1963         done    
1964         stop_mds || rc=$?
1965         cleanup_nocli || rc=$?
1966         #writeconf to remove all ost2 traces for subsequent tests
1967         writeconf
1968         return $rc
1969 }
1970
1971 test_46a() {
1972         echo "Testing with $OSTCOUNT OSTs"
1973         reformat_and_config
1974         start_mds || return 1
1975         #first client should see only one ost
1976         start_ost || return 2
1977         wait_osc_import_state mds ost FULL
1978         #start_client
1979         mount_client $MOUNT || return 3
1980         trap "cleanup_46a $OSTCOUNT" EXIT ERR
1981
1982         local i
1983         for (( i=2; i<=$OSTCOUNT; i++ )); do
1984             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
1985         done
1986
1987         # wait until osts in sync
1988         for (( i=2; i<=$OSTCOUNT; i++ )); do
1989             wait_osc_import_state mds ost$i FULL
1990             wait_osc_import_state client ost$i FULL
1991         done
1992
1993         #second client see all ost's
1994
1995         mount_client $MOUNT2 || return 8
1996         $LFS setstripe $MOUNT2 -c -1 || return 9
1997         $LFS getstripe $MOUNT2 || return 10
1998
1999         echo "ok" > $MOUNT2/widestripe
2000         $LFS getstripe $MOUNT2/widestripe || return 11
2001         # fill acl buffer for avoid expand lsm to them
2002         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2003             setfacl -m $acl $MOUNT2/widestripe
2004         done
2005
2006         # will be deadlock
2007         stat $MOUNT/widestripe || return 12
2008
2009         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2010         return 0
2011 }
2012 run_test 46a "handle ost additional - wide striped file"
2013
2014 test_47() { #17674
2015         reformat
2016         setup_noconfig
2017         check_mount || return 2
2018         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2019
2020         local lru_size=[]
2021         local count=0
2022         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2023             if echo $ns | grep "MDT[[:digit:]]*"; then
2024                 continue
2025             fi
2026             lrs=$(echo $ns | sed 's/.*lru_size=//')
2027             lru_size[count]=$lrs
2028             let count=count+1
2029         done
2030
2031         facet_failover ost1
2032         facet_failover $SINGLEMDS
2033         client_up || return 3
2034
2035         count=0
2036         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2037             if echo $ns | grep "MDT[[:digit:]]*"; then
2038                 continue
2039             fi
2040             lrs=$(echo $ns | sed 's/.*lru_size=//')
2041             if ! test "$lrs" -eq "${lru_size[count]}"; then
2042                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2043                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2044             fi
2045             let count=count+1
2046         done
2047
2048         cleanup
2049         return 0
2050 }
2051 run_test 47 "server restart does not make client loss lru_resize settings"
2052
2053 cleanup_48() {
2054         trap 0
2055
2056         # reformat after this test is needed - if test will failed
2057         # we will have unkillable file at FS
2058         reformat_and_config
2059 }
2060
2061 test_48() { # bug 17636
2062         reformat
2063         setup_noconfig
2064         check_mount || return 2
2065
2066         $LFS setstripe $MOUNT -c -1 || return 9
2067         $LFS getstripe $MOUNT || return 10
2068
2069         echo "ok" > $MOUNT/widestripe
2070         $LFS getstripe $MOUNT/widestripe || return 11
2071
2072         trap cleanup_48 EXIT ERR
2073
2074         # fill acl buffer for avoid expand lsm to them
2075         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2076             setfacl -m $acl $MOUNT/widestripe
2077         done
2078
2079         stat $MOUNT/widestripe || return 12
2080
2081         cleanup_48
2082         return 0
2083 }
2084 run_test 48 "too many acls on file"
2085
2086 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2087 test_49() { # bug 17710
2088         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
2089         local OLD_OST_MKFS_OPTS=$OST_MKFS_OPTS
2090         local LOCAL_TIMEOUT=20
2091
2092
2093         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$LOCAL_TIMEOUT $MKFSOPT $OSTOPT"
2094
2095         reformat
2096         setup_noconfig
2097         check_mount || return 1
2098
2099         echo "check ldlm_timout..."
2100         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2101         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2102         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2103
2104         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2105                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2106         fi
2107
2108         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2109                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2110         fi
2111
2112         umount_client $MOUNT
2113         stop_ost || return 2
2114         stop_mds || return 3
2115
2116         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"
2117
2118         reformat
2119         setup_noconfig
2120         check_mount || return 7
2121
2122         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2123         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2124         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2125
2126         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2127                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2128         fi
2129
2130         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2131                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2132         fi
2133
2134         cleanup || return $?
2135
2136         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
2137         OST_MKFS_OPTS=$OLD_OST_MKFS_OPTS
2138 }
2139 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2140
2141 lazystatfs() {
2142         # Test both statfs and lfs df and fail if either one fails
2143         multiop_bg_pause $1 f_
2144         RC1=$?
2145         PID=$!
2146         killall -USR1 multiop
2147         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2148         wait $PID || { RC1=$?; log "multiop return error "; }
2149
2150         $LFS df &
2151         PID=$!
2152         sleep 5
2153         kill -s 0 $PID
2154         RC2=$?
2155         if [ $RC2 -eq 0 ]; then
2156             kill -s 9 $PID
2157             log "lazystatfs df failed"
2158         fi
2159
2160         RC=0
2161         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2162         return $RC
2163 }
2164
2165 test_50a() {
2166         setup
2167         lctl set_param llite.$FSNAME-*.lazystatfs=1
2168         touch $DIR/$tfile
2169
2170         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2171
2172         cleanup || return $?
2173 }
2174 run_test 50a "lazystatfs all servers available =========================="
2175
2176 test_50b() {
2177         setup
2178         lctl set_param llite.$FSNAME-*.lazystatfs=1
2179         touch $DIR/$tfile
2180
2181         # Wait for client to detect down OST
2182         stop_ost || error "Unable to stop OST1"
2183         wait_osc_import_state mds ost DISCONN
2184
2185         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2186
2187         umount_client $MOUNT || error "Unable to unmount client"
2188         stop_mds || error "Unable to stop MDS"
2189 }
2190 run_test 50b "lazystatfs all servers down =========================="
2191
2192 test_50c() {
2193         start_mds || error "Unable to start MDS"
2194         start_ost || error "Unable to start OST1"
2195         start_ost2 || error "Unable to start OST2"
2196         mount_client $MOUNT || error "Unable to mount client"
2197         lctl set_param llite.$FSNAME-*.lazystatfs=1
2198         touch $DIR/$tfile
2199
2200         # Wait for client to detect down OST
2201         stop_ost || error "Unable to stop OST1"
2202         wait_osc_import_state mds ost DISCONN
2203         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2204
2205         umount_client $MOUNT || error "Unable to unmount client"
2206         stop_ost2 || error "Unable to stop OST2"
2207         stop_mds || error "Unable to stop MDS"
2208         #writeconf to remove all ost2 traces for subsequent tests
2209         writeconf
2210 }
2211 run_test 50c "lazystatfs one server down =========================="
2212
2213 test_50d() {
2214         start_mds || error "Unable to start MDS"
2215         start_ost || error "Unable to start OST1"
2216         start_ost2 || error "Unable to start OST2"
2217         mount_client $MOUNT || error "Unable to mount client"
2218         lctl set_param llite.$FSNAME-*.lazystatfs=1
2219         touch $DIR/$tfile
2220
2221         # Issue the statfs during the window where the client still
2222         # belives the OST to be available but it is in fact down.
2223         # No failure just a statfs which hangs for a timeout interval.
2224         stop_ost || error "Unable to stop OST1"
2225         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2226
2227         umount_client $MOUNT || error "Unable to unmount client"
2228         stop_ost2 || error "Unable to stop OST2"
2229         stop_mds || error "Unable to stop MDS"
2230         #writeconf to remove all ost2 traces for subsequent tests
2231         writeconf
2232 }
2233 run_test 50d "lazystatfs client/server conn race =========================="
2234
2235 test_50e() {
2236         local RC1
2237         local pid
2238
2239         reformat_and_config
2240         start_mds || return 1
2241         #first client should see only one ost
2242         start_ost || return 2
2243         wait_osc_import_state mds ost FULL
2244
2245         # Wait for client to detect down OST
2246         stop_ost || error "Unable to stop OST1"
2247         wait_osc_import_state mds ost DISCONN
2248
2249         mount_client $MOUNT || error "Unable to mount client"
2250         lctl set_param llite.$FSNAME-*.lazystatfs=0
2251
2252         multiop_bg_pause $MOUNT _f
2253         RC1=$?
2254         pid=$!
2255
2256         if [ $RC1 -ne 0 ]; then
2257                 log "multiop failed $RC1"
2258         else
2259             kill -USR1 $pid
2260             sleep $(( $TIMEOUT+1 ))
2261             kill -0 $pid
2262             [ $? -ne 0 ] && error "process isn't sleep"
2263             start_ost || error "Unable to start OST1"
2264             wait $pid || error "statfs failed"
2265         fi
2266
2267         umount_client $MOUNT || error "Unable to unmount client"
2268         stop_ost || error "Unable to stop OST1"
2269         stop_mds || error "Unable to stop MDS"
2270 }
2271 run_test 50e "normal statfs all servers down =========================="
2272
2273 test_50f() {
2274         local RC1
2275         local pid
2276         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2277
2278         start_mds || error "Unable to start mds"
2279         #first client should see only one ost
2280         start_ost || error "Unable to start OST1"
2281         wait_osc_import_state mds ost FULL
2282
2283         start_ost2 || error "Unable to start OST2"
2284         wait_osc_import_state mds ost2 FULL
2285
2286         # Wait for client to detect down OST
2287         stop_ost2 || error "Unable to stop OST2"
2288
2289         wait_osc_import_state mds ost2 DISCONN
2290         mount_client $MOUNT || error "Unable to mount client"
2291         lctl set_param llite.$FSNAME-*.lazystatfs=0
2292
2293         multiop_bg_pause $MOUNT _f
2294         RC1=$?
2295         pid=$!
2296
2297         if [ $RC1 -ne 0 ]; then
2298                 log "lazystatfs multiop failed $RC1"
2299         else
2300             kill -USR1 $pid
2301             sleep $(( $TIMEOUT+1 ))
2302             kill -0 $pid
2303             [ $? -ne 0 ] && error "process isn't sleep"
2304             start_ost2 || error "Unable to start OST2"
2305             wait $pid || error "statfs failed"
2306             stop_ost2 || error "Unable to stop OST2"
2307         fi
2308
2309         umount_client $MOUNT || error "Unable to unmount client"
2310         stop_ost || error "Unable to stop OST1"
2311         stop_mds || error "Unable to stop MDS"
2312         #writeconf to remove all ost2 traces for subsequent tests
2313         writeconf
2314 }
2315 run_test 50f "normal statfs one server in down =========================="
2316
2317 test_50g() {
2318         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2319         setup
2320         start_ost2 || error "Unable to start OST2"
2321         wait_osc_import_state mds ost2 FULL
2322         wait_osc_import_state client ost2 FULL
2323
2324         local PARAM="${FSNAME}-OST0001.osc.active"
2325
2326         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2327         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2328
2329         umount_client $MOUNT || error "Unable to unmount client"
2330         mount_client $MOUNT || error "Unable to mount client"
2331         # This df should not cause a panic
2332         df -k $MOUNT
2333
2334         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2335         rm -f $DIR/$tfile
2336         umount_client $MOUNT || error "Unable to unmount client"
2337         stop_ost2 || error "Unable to stop OST2"
2338         stop_ost || error "Unable to stop OST1"
2339         stop_mds || error "Unable to stop MDS"
2340         #writeconf to remove all ost2 traces for subsequent tests
2341         writeconf
2342 }
2343 run_test 50g "deactivated OST should not cause panic====================="
2344
2345 test_51() {
2346         local LOCAL_TIMEOUT=20
2347
2348         reformat
2349         setup_noconfig
2350         check_mount || return 1
2351
2352         mkdir $MOUNT/d1
2353         $LFS setstripe -c -1 $MOUNT/d1
2354         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2355         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2356         touch $MOUNT/d1/f1 &
2357         local pid=$!
2358         sleep 2
2359         start_ost2 || return 2
2360         wait $pid
2361         stop_ost2 || return 3
2362         cleanup
2363         #writeconf to remove all ost2 traces for subsequent tests
2364         writeconf
2365 }
2366 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2367
2368 copy_files_xattrs()
2369 {
2370         local node=$1
2371         local dest=$2
2372         local xattrs=$3
2373         shift 3
2374
2375         do_node $node mkdir -p $dest
2376         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2377
2378         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2379                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2380         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
2381
2382         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
2383         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
2384 }
2385
2386 diff_files_xattrs()
2387 {
2388         local node=$1
2389         local backup=$2
2390         local xattrs=$3
2391         shift 3
2392
2393         local backup2=${TMP}/backup2
2394
2395         do_node $node mkdir -p $backup2
2396         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2397
2398         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
2399                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2400         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
2401
2402         do_node $node "diff -rq $backup $backup2"
2403         [ $? -eq 0 ] || { error "contents differ"; return 3; }
2404
2405         local xattrs2=${TMP}/xattrs2
2406         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
2407         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
2408
2409         do_node $node "diff $xattrs $xattrs2"
2410         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
2411
2412         do_node $node "rm -rf $backup2 $xattrs2"
2413         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
2414 }
2415
2416 test_52() {
2417         start_mds
2418         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
2419         start_ost
2420         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
2421         mount_client $MOUNT
2422         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
2423
2424         local nrfiles=8
2425         local ost1mnt=$(facet_mntpt ost1)
2426         local ost1node=$(facet_active_host ost1)
2427         local ost1tmp=$TMP/conf52
2428
2429         mkdir -p $DIR/$tdir
2430         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
2431         touch $TMP/modified_first
2432         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
2433         local mtime=$(stat -c %Y $TMP/modified_first)
2434         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
2435
2436         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
2437         sleep 1
2438
2439         $LFS setstripe $DIR/$tdir -c -1 -s 1M
2440         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
2441
2442         for (( i=0; i < nrfiles; i++ )); do
2443                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
2444                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
2445                 echo -n .
2446         done
2447         echo
2448
2449         # backup files
2450         echo backup files to $TMP/files
2451         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
2452         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2453         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
2454
2455         umount_client $MOUNT
2456         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
2457         stop_ost
2458         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
2459
2460         echo mount ost1 as ldiskfs
2461         do_node $ost1node mkdir -p $ost1mnt
2462         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
2463         do_node $ost1node mount -t $FSTYPE $ost1_dev $ost1mnt $OST_MOUNT_OPTS
2464         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
2465
2466         # backup objects
2467         echo backup objects to $ost1tmp/objects
2468         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/0 -type f -size +0'\
2469                         '-newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
2470         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2471         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
2472
2473         # move objects to lost+found
2474         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
2475         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
2476
2477         # recover objects
2478         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
2479         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
2480
2481         # compare restored objects against saved ones
2482         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2483         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
2484
2485         do_node $ost1node "umount $ost1mnt"
2486         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
2487
2488         start_ost
2489         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
2490         mount_client $MOUNT
2491         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
2492
2493         # compare files
2494         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2495         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
2496
2497         rm -rf $TMP/files $TMP/file_xattrs
2498         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
2499         do_node $ost1node "rm -rf $ost1tmp"
2500         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
2501         cleanup
2502 }
2503 run_test 52 "check recovering objects from lost+found"
2504
2505 # Checks threads_min/max/started for some service
2506 #
2507 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
2508 # parameter pattern prefix like 'ost.*.ost'.
2509 thread_sanity() {
2510         local modname=$1
2511         local facet=$2
2512         local parampat=$3
2513         local opts=$4
2514         local tmin
2515         local tmin2
2516         local tmax
2517         local tmax2
2518         local tstarted
2519         local paramp
2520         local msg="Insane $modname thread counts"
2521         shift 4
2522
2523         setup
2524         check_mount || return 41
2525
2526         # We need to expand $parampat, but it may match multiple parameters, so
2527         # we'll pick the first one
2528         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
2529                 error "Couldn't expand ${parampat}.threads_min parameter name"
2530                 return 22
2531         fi
2532
2533         # Remove the .threads_min part
2534         paramp=${paramp%.threads_min}
2535
2536         # Check for sanity in defaults
2537         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2538         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2539         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
2540         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
2541         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
2542
2543         # Check that we can change min/max
2544         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + 1))"
2545         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - 1))"
2546         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2547         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2548         lassert 25 "$msg" '(($tmin2 == ($tmin + 1) && $tmax2 == ($tmax -1)))' || return $?
2549
2550         # Check that we can set min/max to the same value
2551         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2552         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
2553         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2554         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2555         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
2556
2557         # Check that we can't set max < min
2558         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
2559         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2560         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2561         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
2562
2563         # We need to ensure that we get the module options desired; to do this
2564         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
2565         LOAD_MODULES_REMOTE=true
2566         cleanup
2567         local oldvalue
2568         setmodopts -a $modname "$opts" oldvalue
2569
2570         load_modules
2571         setup
2572         check_mount || return 41
2573
2574         # Restore previous setting of MODOPTS_*
2575         setmodopts $modname "$oldvalue"
2576
2577         # Check that $opts took
2578         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
2579         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
2580         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
2581         lassert 28 "$msg" '(($tstarted == $tmin && $tstarted == $tmax ))' || return $?
2582         cleanup
2583
2584         # Workaround a YALA bug where YALA expects that modules will remain
2585         # loaded on the servers
2586         LOAD_MODULES_REMOTE=false
2587         load_modules
2588         setup
2589         cleanup
2590 }
2591
2592 test_53a() {
2593         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads=64'
2594 }
2595 run_test 53a "check OSS thread count params"
2596
2597 test_53b() {
2598         thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads=64'
2599 }
2600 run_test 53b "check MDT thread count params"
2601
2602 test_54a() {
2603     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
2604     [ $? -eq 0 ] || error "llverdev failed!"
2605     reformat_and_config
2606 }
2607 run_test 54a "test llverdev and partial verify of device"
2608
2609 test_54b() {
2610     setup
2611     run_llverfs $MOUNT -p
2612     [ $? -eq 0 ] || error "llverfs failed!"
2613     cleanup
2614 }
2615 run_test 54b "test llverfs and partial verify of filesystem"
2616
2617 lov_objid_size()
2618 {
2619         local max_ost_index=$1
2620         echo -n $(((max_ost_index + 1) * 8))
2621 }
2622
2623 test_55() {
2624         local mdsdev=$(mdsdevname 1)
2625         local ostdev=$(ostdevname 1)
2626         local saved_opts=$OST_MKFS_OPTS
2627
2628         for i in 1023 2048
2629         do
2630                 OST_MKFS_OPTS="$saved_opts --index $i"
2631                 reformat
2632
2633                 setup_noconfig
2634                 stopall
2635
2636                 setup_noconfig
2637                 sync
2638                 echo checking size of lov_objid for ost index $i
2639                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
2640                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
2641                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
2642                 else
2643                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
2644                 fi
2645                 stopall
2646         done
2647
2648         OST_MKFS_OPTS=$saved_opts
2649         reformat
2650 }
2651 run_test 55 "check lov_objid size"
2652
2653 test_56() {
2654         add mds1 $MDS_MKFS_OPTS --mkfsoptions='\"-J size=16\"' --reformat $(mdsdevname 1)
2655         add ost1 $OST_MKFS_OPTS --index=1000 --reformat $(ostdevname 1)
2656         add ost2 $OST_MKFS_OPTS --index=10000 --reformat $(ostdevname 2)
2657
2658         start_mgsmds
2659         start_ost
2660         start_ost2 || error "Unable to start second ost"
2661         mount_client $MOUNT || error "Unable to mount client"
2662         echo ok
2663         $LFS osts
2664         [ -n "$ENABLE_QUOTA" ] && { $LFS quotacheck -ug $MOUNT || error "quotacheck has failed" ; }
2665         stopall
2666         reformat
2667 }
2668 run_test 56 "check big indexes"
2669
2670 test_57a() { # bug 22656
2671         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
2672         writeconf
2673         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
2674         start_mgsmds
2675         start_ost && error "OST registration from failnode should fail"
2676         reformat
2677 }
2678 run_test 57a "initial registration from failnode should fail (should return errs)"
2679
2680 test_57b() {
2681         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
2682         writeconf
2683         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
2684         start_mgsmds
2685         start_ost || error "OST registration from servicenode should not fail"
2686         reformat
2687 }
2688 run_test 57b "initial registration from servicenode should not fail"
2689
2690 count_osts() {
2691         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
2692 }
2693
2694 test_58() { # bug 22658
2695         [ "$FSTYPE" != "ldiskfs" ] && skip "not supported for $FSTYPE" && return
2696         setup_noconfig
2697         mkdir -p $DIR/$tdir
2698         createmany -o $DIR/$tdir/$tfile-%d 100
2699         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
2700 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
2701         do_facet mds "lctl set_param fail_loc=0x601"
2702         unlinkmany $DIR/$tdir/$tfile-%d 100
2703         stop mds
2704         local MNTDIR=$(facet_mntpt mds)
2705         # remove all files from the OBJECTS dir
2706         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
2707         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
2708         do_facet mds "umount $MNTDIR"
2709         # restart MDS with missing llog files
2710         start_mds
2711         do_facet mds "lctl set_param fail_loc=0"
2712         reformat
2713 }
2714 run_test 58 "missing llog files must not prevent MDT from mounting"
2715
2716 test_59() {
2717         start_mgsmds >> /dev/null
2718         local C1=$(count_osts)
2719         if [ $C1 -eq 0 ]; then
2720                 start_ost >> /dev/null
2721                 C1=$(count_osts)
2722         fi
2723         stopall
2724         echo "original ost count: $C1 (expect > 0)"
2725         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
2726         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
2727         local C2=$(count_osts)
2728         echo "after mdt writeconf count: $C2 (expect 0)"
2729         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
2730         echo "OST start without writeconf should fail:"
2731         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
2732         echo "OST start with writeconf should succeed:"
2733         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
2734         local C3=$(count_osts)
2735         echo "after ost writeconf count: $C3 (expect 1)"
2736         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
2737         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
2738         local C4=$(count_osts)
2739         echo "after ost2 writeconf count: $C4 (expect 2)"
2740         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
2741         stop_ost2 >> /dev/null
2742         cleanup_nocli >> /dev/null
2743         #writeconf to remove all ost2 traces for subsequent tests
2744         writeconf
2745 }
2746 run_test 59 "writeconf mount option"
2747
2748 test_60() { # LU-471
2749         add mds1 $MDS_MKFS_OPTS --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' --reformat $(mdsdevname 1)
2750
2751         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
2752         rc=${PIPESTATUS[0]}
2753         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
2754
2755         # MDT default has dirdata feature
2756         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
2757         # we disable uninit_bg feature
2758         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
2759         # we set stride extended options
2760         echo $dump | grep stride > /dev/null || error "stride is not set"
2761         reformat
2762 }
2763 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
2764
2765 test_61() { # LU-80
2766     local reformat=false
2767
2768     if ! large_xattr_enabled; then
2769         reformat=true
2770         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
2771         add $SINGLEMDS $MDS_MKFS_OPTS --mkfsoptions='\"-O large_xattr\"' \
2772             --reformat $mds_dev || error "reformatting $mds_dev failed"
2773     fi
2774
2775     setup_noconfig || error "setting up the filesystem failed"
2776     client_up || error "starting client failed"
2777
2778     local file=$DIR/$tfile
2779     touch $file
2780
2781     local large_value="$(generate_string $(max_xattr_size))"
2782     local small_value="bar"
2783
2784     local name="trusted.big"
2785     log "save large xattr $name on $file"
2786     setfattr -n $name -v $large_value $file ||
2787         error "saving $name on $file failed"
2788
2789     local new_value=$(get_xattr_value $name $file)
2790     [[ "$new_value" != "$large_value" ]] &&
2791         error "$name different after saving"
2792
2793     log "shrink value of $name on $file"
2794     setfattr -n $name -v $small_value $file ||
2795         error "shrinking value of $name on $file failed"
2796
2797     new_value=$(get_xattr_value $name $file)
2798     [[ "$new_value" != "$small_value" ]] &&
2799         error "$name different after shrinking"
2800
2801     log "grow value of $name on $file"
2802     setfattr -n $name -v $large_value $file ||
2803         error "growing value of $name on $file failed"
2804
2805     new_value=$(get_xattr_value $name $file)
2806     [[ "$new_value" != "$large_value" ]] &&
2807         error "$name different after growing"
2808
2809     log "check value of $name on $file after remounting MDS"
2810     fail $SINGLEMDS
2811     new_value=$(get_xattr_value $name $file)
2812     [[ "$new_value" != "$large_value" ]] &&
2813         error "$name different after remounting MDS"
2814
2815     log "remove large xattr $name from $file"
2816     setfattr -x $name $file || error "removing $name from $file failed"
2817
2818     rm -f $file
2819     stopall
2820     $reformat && reformat
2821 }
2822 run_test 61 "large xattr"
2823
2824 if ! combined_mgs_mds ; then
2825         stop mgs
2826 fi
2827
2828 cleanup_gss
2829
2830 # restore the ${facet}_MKFS_OPTS variables
2831 for facet in MGS MDS OST; do
2832     opts=SAVED_${facet}_MKFS_OPTS
2833     if [[ -n ${!opts} ]]; then
2834         eval ${facet}_MKFS_OPTS=\"${!opts}\"
2835     fi
2836 done
2837
2838 complete $(basename $0) $SECONDS
2839 exit_status