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