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