Whamcloud - gitweb
LU-3009 tests: failure on conf-sanity test_17
[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:     LU-2828
13 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 59 64"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 is_sles11()                                             # LU-2181
17 {
18         if [ -r /etc/SuSE-release ]
19         then
20                 local vers=`grep VERSION /etc/SuSE-release | awk '{print $3}'`
21                 local patchlev=`grep PATCHLEVEL /etc/SuSE-release \
22                         | awk '{print $3}'`
23                 if [ $vers -eq 11 ] && [ $patchlev -eq 2 ]
24                 then
25                         return 0
26                 fi
27         fi
28         return 1
29 }
30
31 if is_sles11; then                                      # LU-2181
32         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 23a 34b"
33 fi
34
35 if [ "$FAILURE_MODE" = "HARD" ]; then
36         CONFIG_EXCEPTIONS="24a " && \
37         echo "Except the tests: $CONFIG_EXCEPTIONS for FAILURE_MODE=$FAILURE_MODE, bug 23573" && \
38         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
39 fi
40
41 # bug number for skipped test:
42 # a tool to create lustre filesystem images
43 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
44
45 SRCDIR=`dirname $0`
46 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
47
48 PTLDEBUG=${PTLDEBUG:--1}
49 SAVE_PWD=$PWD
50 LUSTRE=${LUSTRE:-`dirname $0`/..}
51 RLUSTRE=${RLUSTRE:-$LUSTRE}
52 export MULTIOP=${MULTIOP:-multiop}
53
54 . $LUSTRE/tests/test-framework.sh
55 init_test_env $@
56
57 # use small MDS + OST size to speed formatting time
58 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
59 MDSSIZE=200000
60 OSTSIZE=200000
61 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
62
63 if ! combined_mgs_mds; then
64     # bug number for skipped test:    23954
65     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
66 fi
67
68 # STORED_MDSSIZE is used in test_18
69 if [ -n "$MDSSIZE" ]; then
70     STORED_MDSSIZE=$MDSSIZE
71 fi
72
73 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
74 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
75         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
76 fi
77
78 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
79 # bug number for skipped test:        LU-2778 LU-2059
80         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 57b     50h"
81
82 init_logging
83
84 #
85 require_dsh_mds || exit 0
86 require_dsh_ost || exit 0
87 #
88 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45"
89
90
91 assert_DIR
92
93 gen_config() {
94         # The MGS must be started before the OSTs for a new fs, so start
95         # and stop to generate the startup logs.
96         start_mds
97         start_ost
98         wait_osc_import_state mds ost FULL
99         stop_ost
100         stop_mds
101 }
102
103 reformat_and_config() {
104         reformat
105         if ! combined_mgs_mds ; then
106                 start_mgs
107         fi
108         gen_config
109 }
110
111 writeconf_or_reformat() {
112         # There are at most 2 OSTs for write_conf test
113         # who knows if/where $TUNEFS is installed?
114         # Better reformat if it fails...
115         writeconf_all $MDSCOUNT 2 ||
116                 { echo "tunefs failed, reformatting instead" &&
117                   reformat_and_config && return 0; }
118         return 0
119 }
120
121 reformat() {
122         formatall
123 }
124
125 start_mgs () {
126         echo "start mgs"
127         start mgs $MGSDEV $MGS_MOUNT_OPTS
128 }
129
130 start_mdt() {
131         local num=$1
132         local facet=mds$num
133         local dev=$(mdsdevname $num)
134         shift 1
135
136         echo "start mds service on `facet_active_host $facet`"
137         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
138 }
139
140 stop_mdt() {
141         local num=$1
142         local facet=mds$num
143         local dev=$(mdsdevname $num)
144         shift 1
145
146         echo "stop mds service on `facet_active_host $facet`"
147         # These tests all use non-failover stop
148         stop $facet -f  || return 97
149 }
150
151 start_mds() {
152         local num
153
154         for num in $(seq $MDSCOUNT); do
155                 start_mdt $num $@ || return 94
156         done
157 }
158
159 start_mgsmds() {
160         if ! combined_mgs_mds ; then
161                 start_mgs
162         fi
163         start_mds $@
164 }
165
166 stop_mds() {
167         local num
168         for num in $(seq $MDSCOUNT); do
169                 stop_mdt $num || return 97
170         done
171 }
172
173 stop_mgs() {
174        echo "stop mgs service on `facet_active_host mgs`"
175        # These tests all use non-failover stop
176        stop mgs -f  || return 97
177 }
178
179 start_ost() {
180         echo "start ost1 service on `facet_active_host ost1`"
181         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
182 }
183
184 stop_ost() {
185         echo "stop ost1 service on `facet_active_host ost1`"
186         # These tests all use non-failover stop
187         stop ost1 -f  || return 98
188 }
189
190 start_ost2() {
191         echo "start ost2 service on `facet_active_host ost2`"
192         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
193 }
194
195 stop_ost2() {
196         echo "stop ost2 service on `facet_active_host ost2`"
197         # These tests all use non-failover stop
198         stop ost2 -f  || return 93
199 }
200
201 mount_client() {
202         local MOUNTPATH=$1
203         echo "mount $FSNAME on ${MOUNTPATH}....."
204         zconf_mount `hostname` $MOUNTPATH  || return 96
205 }
206
207 remount_client() {
208         local mountopt="-o remount,$1"
209         local MOUNTPATH=$2
210         echo "remount '$1' lustre on ${MOUNTPATH}....."
211         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
212 }
213
214 umount_client() {
215         local MOUNTPATH=$1
216         echo "umount lustre on ${MOUNTPATH}....."
217         zconf_umount `hostname` $MOUNTPATH || return 97
218 }
219
220 manual_umount_client(){
221         local rc
222         local FORCE=$1
223         echo "manual umount lustre on ${MOUNT}...."
224         do_facet client "umount -d ${FORCE} $MOUNT"
225         rc=$?
226         return $rc
227 }
228
229 setup() {
230         start_mds || error "MDT start failed"
231         start_ost || error "OST start failed"
232         mount_client $MOUNT || error "client start failed"
233         client_up || error "client_up failed"
234 }
235
236 setup_noconfig() {
237         if ! combined_mgs_mds ; then
238                 start_mgs
239         fi
240
241         start_mds
242         start_ost
243         mount_client $MOUNT
244 }
245
246 unload_modules_conf () {
247         if combined_mgs_mds || ! local_mode; then
248                 unload_modules || return 1
249         fi
250 }
251
252 cleanup_nocli() {
253         stop_ost || return 202
254         stop_mds || return 201
255         unload_modules_conf || return 203
256 }
257
258 cleanup() {
259         umount_client $MOUNT || return 200
260         cleanup_nocli || return $?
261 }
262
263 check_mount() {
264         do_facet client "cp /etc/passwd $DIR/a" || return 71
265         do_facet client "rm $DIR/a" || return 72
266         # make sure lustre is actually mounted (touch will block,
267         # but grep won't, so do it after)
268         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
269         echo "setup single mount lustre success"
270 }
271
272 check_mount2() {
273         do_facet client "touch $DIR/a" || return 71
274         do_facet client "rm $DIR/a" || return 72
275         do_facet client "touch $DIR2/a" || return 73
276         do_facet client "rm $DIR2/a" || return 74
277         echo "setup double mount lustre success"
278 }
279
280 build_test_filter
281
282 if [ "$ONLY" == "setup" ]; then
283         setup
284         exit
285 fi
286
287 if [ "$ONLY" == "cleanup" ]; then
288         cleanup
289         exit
290 fi
291
292 init_gss
293
294 #create single point mountpoint
295
296 reformat_and_config
297
298 test_0() {
299         setup
300         check_mount || return 41
301         cleanup || return $?
302 }
303 run_test 0 "single mount setup"
304
305 test_1() {
306         start_mds || error "MDT start failed"
307         start_ost
308         echo "start ost second time..."
309         start_ost && error "2nd OST start should fail"
310         mount_client $MOUNT || error "client start failed"
311         check_mount || return 42
312         cleanup || return $?
313 }
314 run_test 1 "start up ost twice (should return errors)"
315
316 test_2() {
317         start_mdt 1
318         echo "start mds second time.."
319         start_mdt 1 && error "2nd MDT start should fail"
320         start_ost
321         mount_client $MOUNT
322         check_mount || return 43
323         cleanup || return $?
324 }
325 run_test 2 "start up mds twice (should return err)"
326
327 test_3() {
328         setup
329         #mount.lustre returns an error if already in mtab
330         mount_client $MOUNT && error "2nd client mount should fail"
331         check_mount || return 44
332         cleanup || return $?
333 }
334 run_test 3 "mount client twice (should return err)"
335
336 test_4() {
337         setup
338         touch $DIR/$tfile || return 85
339         stop_ost -f
340         cleanup
341         eno=$?
342         # ok for ost to fail shutdown
343         if [ 202 -ne $eno ]; then
344                 return $eno;
345         fi
346         return 0
347 }
348 run_test 4 "force cleanup ost, then cleanup"
349
350 test_5a() {     # was test_5
351         setup
352         touch $DIR/$tfile || return 1
353         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
354
355         stop_mds -f || return 2
356
357         # cleanup may return an error from the failed
358         # disconnects; for now I'll consider this successful
359         # if all the modules have unloaded.
360         umount -d $MOUNT &
361         UMOUNT_PID=$!
362         sleep 6
363         echo "killing umount"
364         kill -TERM $UMOUNT_PID
365         echo "waiting for umount to finish"
366         wait $UMOUNT_PID
367         if grep " $MOUNT " /proc/mounts; then
368                 echo "test 5: /proc/mounts after failed umount"
369                 umount $MOUNT &
370                 UMOUNT_PID=$!
371                 sleep 2
372                 echo "killing umount"
373                 kill -TERM $UMOUNT_PID
374                 echo "waiting for umount to finish"
375                 wait $UMOUNT_PID
376                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
377         fi
378
379         manual_umount_client
380         # stop_mds is a no-op here, and should not fail
381         cleanup_nocli || return $?
382         # df may have lingering entry
383         manual_umount_client
384         # mtab may have lingering entry
385         local WAIT=0
386         local MAX_WAIT=20
387         local sleep=1
388         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
389                 sleep $sleep
390                 grep -q $MOUNT" " /etc/mtab || break
391                 echo "Waiting /etc/mtab updated ... "
392                 WAIT=$(( WAIT + sleep))
393         done
394         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
395         echo "/etc/mtab updated in $WAIT secs"
396 }
397 run_test 5a "force cleanup mds, then cleanup"
398
399 cleanup_5b () {
400         trap 0
401         start_mgs
402 }
403
404 test_5b() {
405         grep " $MOUNT " /etc/mtab && \
406                 error false "unexpected entry in mtab before mount" && return 10
407
408         local rc=0
409         start_ost
410         if ! combined_mgs_mds ; then
411                 trap cleanup_5b EXIT ERR
412                 start_mds
413                 stop mgs
414         fi
415
416         [ -d $MOUNT ] || mkdir -p $MOUNT
417         mount_client $MOUNT && rc=1
418         grep " $MOUNT " /etc/mtab && \
419                 error "$MOUNT entry in mtab after failed mount" && rc=11
420         umount_client $MOUNT
421         # stop_mds is a no-op here, and should not fail
422         cleanup_nocli || rc=$?
423         if ! combined_mgs_mds ; then
424                 cleanup_5b
425         fi
426         return $rc
427 }
428 run_test 5b "Try to start a client with no MGS (should return errs)"
429
430 test_5c() {
431         grep " $MOUNT " /etc/mtab && \
432                 error false "unexpected entry in mtab before mount" && return 10
433
434         local rc=0
435         start_mds
436         start_ost
437         [ -d $MOUNT ] || mkdir -p $MOUNT
438         local oldfs="${FSNAME}"
439         FSNAME="wrong.${FSNAME}"
440         mount_client $MOUNT || :
441         FSNAME=${oldfs}
442         grep " $MOUNT " /etc/mtab && \
443                 error "$MOUNT entry in mtab after failed mount" && rc=11
444         umount_client $MOUNT
445         cleanup_nocli  || rc=$?
446         return $rc
447 }
448 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
449
450 test_5d() {
451         grep " $MOUNT " /etc/mtab && \
452                 error false "unexpected entry in mtab before mount" && return 10
453
454         [ "$(facet_fstype ost1)" = "zfs" ] &&
455                 skip "LU-2059: no local config for ZFS OSTs" && return
456
457         local rc=0
458         start_ost
459         start_mds
460         stop_ost -f
461         mount_client $MOUNT || rc=1
462         cleanup  || rc=$?
463         grep " $MOUNT " /etc/mtab && \
464                 error "$MOUNT entry in mtab after unmount" && rc=11
465         return $rc
466 }
467 run_test 5d "mount with ost down"
468
469 test_5e() {
470         grep " $MOUNT " /etc/mtab && \
471                 error false "unexpected entry in mtab before mount" && return 10
472
473         local rc=0
474         start_mds
475         start_ost
476
477 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
478         do_facet client "lctl set_param fail_loc=0x80000506"
479         mount_client $MOUNT || echo "mount failed (not fatal)"
480         cleanup  || rc=$?
481         grep " $MOUNT " /etc/mtab && \
482                 error "$MOUNT entry in mtab after unmount" && rc=11
483         return $rc
484 }
485 run_test 5e "delayed connect, don't crash (bug 10268)"
486
487 test_5f() {
488         if combined_mgs_mds ; then
489                 skip "combined mgs and mds"
490                 return 0
491         fi
492
493         grep " $MOUNT " /etc/mtab && \
494                 error false "unexpected entry in mtab before mount" && return 10
495
496         local rc=0
497         start_ost
498         [ -d $MOUNT ] || mkdir -p $MOUNT
499         mount_client $MOUNT &
500         local pid=$!
501         echo client_mount pid is $pid
502
503         sleep 5
504
505         if ! ps -f -p $pid >/dev/null; then
506                 wait $pid
507                 rc=$?
508                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
509                 error "mount returns $rc, expected to hang"
510                 rc=11
511                 cleanup || rc=$?
512                 return $rc
513         fi
514
515         # start mds
516         start_mds
517
518         # mount should succeed after start mds
519         wait $pid
520         rc=$?
521         [ $rc -eq 0 ] || error "mount returned $rc"
522         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
523         cleanup || return $?
524         return $rc
525 }
526 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
527
528 test_6() {
529         setup
530         manual_umount_client
531         mount_client ${MOUNT} || return 87
532         touch $DIR/a || return 86
533         cleanup  || return $?
534 }
535 run_test 6 "manual umount, then mount again"
536
537 test_7() {
538         setup
539         manual_umount_client
540         cleanup_nocli || return $?
541 }
542 run_test 7 "manual umount, then cleanup"
543
544 test_8() {
545         setup
546         mount_client $MOUNT2
547         check_mount2 || return 45
548         umount_client $MOUNT2
549         cleanup  || return $?
550 }
551 run_test 8 "double mount setup"
552
553 test_9() {
554         start_ost
555
556         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
557         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
558
559         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
560         if [ "$CHECK_PTLDEBUG" ] && { \
561            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
562            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
563            echo "lnet.debug success"
564         else
565            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
566            return 1
567         fi
568         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
569         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
570            echo "lnet.subsystem_debug success"
571         else
572            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
573            return 1
574         fi
575         stop_ost || return $?
576 }
577 run_test 9 "test ptldebug and subsystem for mkfs"
578
579 is_blkdev () {
580         local facet=$1
581         local dev=$2
582         local size=${3:-""}
583
584         local rc=0
585         do_facet $facet "test -b $dev" || rc=1
586         if [[ "$size" ]]; then
587                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
588                         awk '($3 == "in") { print $1 }')
589                 [[ $in  = "1+0" ]] || rc=1
590         fi
591         return $rc
592 }
593
594 #
595 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
596 # But with new MDS stack we don't care about the mode of local objects
597 # anymore, so this test is removed. See bug 22944 for more details.
598 #
599
600 test_17() {
601         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
602                 skip "Only applicable to ldiskfs-based MDTs"
603                 return
604         fi
605
606         setup
607         check_mount || return 41
608         cleanup || return $?
609
610         echo "Remove mds config log"
611         if ! combined_mgs_mds ; then
612                 stop mgs
613         fi
614
615         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
616                 $(mgsdevname) || return \$?" || return $?
617
618         if ! combined_mgs_mds ; then
619                 start_mgs
620         fi
621
622         start_ost
623         start_mds && return 42
624         reformat_and_config
625 }
626 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
627
628 test_18() {
629         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
630                 skip "Only applicable to ldiskfs-based MDTs"
631                 return
632         fi
633
634         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
635
636         local MIN=2000000
637
638         local OK=
639         # check if current MDSSIZE is large enough
640         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
641                 log "use MDSSIZE=$MDSSIZE"
642
643         # check if the global config has a large enough MDSSIZE
644         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
645                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
646                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
647
648         # check if the block device is large enough
649         is_blkdev $SINGLEMDS $MDSDEV $MIN
650         local large_enough=$?
651         if [ -n "$OK" ]; then
652                 [ $large_enough -ne 0 ] && OK=""
653         else
654                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
655                         log "use device $MDSDEV with MIN=$MIN"
656         fi
657
658         # check if a loopback device has enough space for fs metadata (5%)
659
660         if [ -z "$OK" ]; then
661                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
662                         awk '($1 != "Filesystem") {print $4}')
663                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
664                         OK=1 && myMDSSIZE=$MIN && \
665                         log "use file $MDSDEV with MIN=$MIN"
666         fi
667
668         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
669
670
671         echo "mount mds with large journal..."
672
673         local OLD_MDSSIZE=$MDSSIZE
674         MDSSIZE=$myMDSSIZE
675
676         reformat_and_config
677         echo "mount lustre system..."
678         setup
679         check_mount || return 41
680
681         echo "check journal size..."
682         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
683         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
684                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
685         else
686                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
687         fi
688
689         cleanup || return $?
690
691         MDSSIZE=$OLD_MDSSIZE
692         reformat_and_config
693 }
694 run_test 18 "check mkfs creates large journals"
695
696 test_19a() {
697         start_mds || return 1
698         stop_mds -f || return 2
699 }
700 run_test 19a "start/stop MDS without OSTs"
701
702 test_19b() {
703         [ "$(facet_fstype ost1)" = "zfs" ] &&
704                 skip "LU-2059: no local config for ZFS OSTs" && return
705
706         start_ost || return 1
707         stop_ost -f || return 2
708 }
709 run_test 19b "start/stop OSTs without MDS"
710
711 test_20() {
712         # first format the ost/mdt
713         start_mds
714         start_ost
715         mount_client $MOUNT
716         check_mount || return 43
717         rm -f $DIR/$tfile
718         remount_client ro $MOUNT || return 44
719         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
720         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
721         remount_client rw $MOUNT || return 47
722         touch $DIR/$tfile
723         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
724         MCNT=`grep -c $MOUNT /etc/mtab`
725         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
726         umount_client $MOUNT
727         stop_mds
728         stop_ost
729 }
730 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
731
732 test_21a() {
733         start_mds
734         start_ost
735         wait_osc_import_state mds ost FULL
736         stop_ost
737         stop_mds
738 }
739 run_test 21a "start mds before ost, stop ost first"
740
741 test_21b() {
742         [ "$(facet_fstype ost1)" = "zfs" ] &&
743                 skip "LU-2059: no local config for ZFS OSTs" && return
744
745         start_ost
746         start_mds
747         wait_osc_import_state mds ost FULL
748         stop_mds
749         stop_ost
750 }
751 run_test 21b "start ost before mds, stop mds first"
752
753 test_21c() {
754         start_ost
755         start_mds
756         start_ost2
757         wait_osc_import_state mds ost2 FULL
758         stop_ost
759         stop_ost2
760         stop_mds
761         #writeconf to remove all ost2 traces for subsequent tests
762         writeconf_or_reformat
763 }
764 run_test 21c "start mds between two osts, stop mds last"
765
766 test_21d() {
767         if combined_mgs_mds ; then
768                 skip "need separate mgs device" && return 0
769         fi
770         stopall
771
772         reformat
773
774         start_mgs
775         start_ost
776         start_ost2
777         start_mds
778         wait_osc_import_state mds ost2 FULL
779
780         stop_ost
781         stop_ost2
782         stop_mds
783         stop_mgs
784         #writeconf to remove all ost2 traces for subsequent tests
785         writeconf_or_reformat
786         start_mgs
787 }
788 run_test 21d "start mgs then ost and then mds"
789
790 test_22() {
791         local num
792
793         start_mds
794
795         echo Client mount with ost in logs, but none running
796         start_ost
797         # wait until mds connected to ost and open client connection
798         for num in $(seq 1 $MDSCOUNT); do
799                 wait_osc_import_state mds${num} ost FULL
800         done
801         stop_ost
802         mount_client $MOUNT
803         # check_mount will block trying to contact ost
804         mcreate $DIR/$tfile || return 40
805         rm -f $DIR/$tfile || return 42
806         umount_client $MOUNT
807         pass
808
809         echo Client mount with a running ost
810         start_ost
811         if $GSS; then
812                 # if gss enabled, wait full time to let connection from
813                 # mds to ost be established, due to the mismatch between
814                 # initial connect timeout and gss context negotiation timeout.
815                 # This perhaps could be remove after AT landed.
816                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
817                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
818         fi
819         mount_client $MOUNT
820         for num in $(seq 1 $MDSCOUNT); do
821                 wait_osc_import_state mds${num} ost FULL
822         done
823         wait_osc_import_state client ost FULL
824         check_mount || return 41
825         pass
826
827         cleanup
828 }
829 run_test 22 "start a client before osts (should return errs)"
830
831 test_23a() {    # was test_23
832         setup
833         # fail mds
834         stop $SINGLEMDS
835         # force down client so that recovering mds waits for reconnect
836         local running=$(grep -c $MOUNT /proc/mounts) || true
837         if [ $running -ne 0 ]; then
838                 echo "Stopping client $MOUNT (opts: -f)"
839                 umount -f $MOUNT
840         fi
841
842         # enter recovery on mds
843         start_mds
844         # try to start a new client
845         mount_client $MOUNT &
846         sleep 5
847         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
848         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
849         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
850         ps --ppid $MOUNT_PID
851         ps --ppid $MOUNT_LUSTRE_PID
852         echo "waiting for mount to finish"
853         ps -ef | grep mount
854         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
855         # SIGTERM works but it does not spread to offspring processses
856         kill -s TERM $MOUNT_PID
857         kill -s TERM $MOUNT_LUSTRE_PID
858         # we can not wait $MOUNT_PID because it is not a child of this shell
859         local PID1
860         local PID2
861         local WAIT=0
862         local MAX_WAIT=30
863         local sleep=1
864         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
865                 sleep $sleep
866                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
867                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
868                 echo PID1=$PID1
869                 echo PID2=$PID2
870                 [ -z "$PID1" -a -z "$PID2" ] && break
871                 echo "waiting for mount to finish ... "
872                 WAIT=$(( WAIT + sleep))
873         done
874         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
875                 error "MOUNT_PID $MOUNT_PID and "\
876                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
877                 ps -ef | grep mount
878         fi
879         stop_mds || error
880         stop_ost || error
881 }
882 run_test 23a "interrupt client during recovery mount delay"
883
884 umount_client $MOUNT
885 cleanup_nocli
886
887 test_23b() {    # was test_23
888         start_mds
889         start_ost
890         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
891         lctl set_param fail_loc=0x80000313
892         mount_client $MOUNT
893         cleanup
894 }
895 run_test 23b "Simulate -EINTR during mount"
896
897 fs2mds_HOST=$mds_HOST
898 fs2ost_HOST=$ost_HOST
899
900 MDSDEV1_2=$fs2mds_DEV
901 OSTDEV1_2=$fs2ost_DEV
902 OSTDEV2_2=$fs3ost_DEV
903
904 cleanup_24a() {
905         trap 0
906         echo "umount $MOUNT2 ..."
907         umount $MOUNT2 || true
908         echo "stopping fs2mds ..."
909         stop fs2mds -f || true
910         echo "stopping fs2ost ..."
911         stop fs2ost -f || true
912 }
913
914 test_24a() {
915         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
916
917         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
918                 is_blkdev $SINGLEMDS $MDSDEV && \
919                 skip_env "mixed loopback and real device not working" && return
920         fi
921
922         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
923
924         local fs2mdsdev=$(mdsdevname 1_2)
925         local fs2ostdev=$(ostdevname 1_2)
926         local fs2mdsvdev=$(mdsvdevname 1_2)
927         local fs2ostvdev=$(ostvdevname 1_2)
928
929         # test 8-char fsname as well
930         local FSNAME2=test1234
931
932         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
933                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
934
935         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
936                 --reformat $fs2ostdev $fs2ostvdev || exit 10
937
938         setup
939         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
940         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
941         mkdir -p $MOUNT2
942         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
943         # 1 still works
944         check_mount || return 2
945         # files written on 1 should not show up on 2
946         cp /etc/passwd $DIR/$tfile
947         sleep 10
948         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
949         # 2 should work
950         sleep 5
951         cp /etc/passwd $MOUNT2/b || return 3
952         rm $MOUNT2/b || return 4
953         # 2 is actually mounted
954         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
955         # failover
956         facet_failover fs2mds
957         facet_failover fs2ost
958         df
959         umount_client $MOUNT
960         # the MDS must remain up until last MDT
961         stop_mds
962         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
963         [ -z "$MDS" ] && error "No MDT" && return 8
964         cleanup_24a
965         cleanup_nocli || return 6
966 }
967 run_test 24a "Multiple MDTs on a single node"
968
969 test_24b() {
970         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
971
972         if [ -z "$fs2mds_DEV" ]; then
973                 local dev=${SINGLEMDS}_dev
974                 local MDSDEV=${!dev}
975                 is_blkdev $SINGLEMDS $MDSDEV && \
976                 skip_env "mixed loopback and real device not working" && return
977         fi
978
979         local fs2mdsdev=$(mdsdevname 1_2)
980         local fs2mdsvdev=$(mdsvdevname 1_2)
981
982         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
983                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
984         setup
985         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
986         cleanup || return 6
987 }
988 run_test 24b "Multiple MGSs on a single node (should return err)"
989
990 test_25() {
991         setup
992         check_mount || return 2
993         local MODULES=$($LCTL modules | awk '{ print $2 }')
994         rmmod $MODULES 2>/dev/null || true
995         cleanup || return 6
996 }
997 run_test 25 "Verify modules are referenced"
998
999 test_26() {
1000     load_modules
1001     # we need modules before mount for sysctl, so make sure...
1002     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
1003 #define OBD_FAIL_MDS_FS_SETUP            0x135
1004     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
1005     start_mds && echo MDS started && return 1
1006     lctl get_param -n devices
1007     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
1008     [ $DEVS -gt 0 ] && return 2
1009     # start mds to drop writeconf setting
1010     start_mds || return 3
1011     stop_mds || return 4
1012     unload_modules_conf || return $?
1013 }
1014 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1015
1016 test_27a() {
1017         [ "$(facet_fstype ost1)" = "zfs" ] &&
1018                 skip "LU-2059: no local config for ZFS OSTs" && return
1019
1020         start_ost || return 1
1021         start_mds || return 2
1022         echo "Requeue thread should have started: "
1023         ps -e | grep ll_cfg_requeue
1024         set_conf_param_and_check ost1                                         \
1025            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
1026            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
1027         cleanup_nocli
1028 }
1029 run_test 27a "Reacquire MGS lock if OST started first"
1030
1031 test_27b() {
1032         # FIXME. ~grev
1033         setup
1034         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1035                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1036
1037         facet_failover $SINGLEMDS
1038         set_conf_param_and_check $SINGLEMDS                             \
1039                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
1040                 "$device.mdt.identity_acquire_expire" || return 3
1041         set_conf_param_and_check client                                 \
1042                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1043                 "$device.mdc.max_rpcs_in_flight" || return 4
1044         check_mount
1045         cleanup
1046 }
1047 run_test 27b "Reacquire MGS lock after failover"
1048
1049 test_28() {
1050         setup
1051         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1052         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1053         ORIG=$($TEST)
1054         FINAL=$(($ORIG + 1))
1055         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1056         FINAL=$(($FINAL + 1))
1057         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1058         umount_client $MOUNT || return 200
1059         mount_client $MOUNT
1060         RESULT=$($TEST)
1061         if [ $RESULT -ne $FINAL ]; then
1062             echo "New config not seen: wanted $FINAL got $RESULT"
1063             return 4
1064         else
1065             echo "New config success: got $RESULT"
1066         fi
1067         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1068         cleanup
1069 }
1070 run_test 28 "permanent parameter setting"
1071
1072 test_29() {
1073         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1074         setup > /dev/null 2>&1
1075         start_ost2
1076         sleep 10
1077
1078         local PARAM="$FSNAME-OST0001.osc.active"
1079         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1080         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1081
1082         ACTV=$(lctl get_param -n $PROC_ACT)
1083         DEAC=$((1 - $ACTV))
1084         set_conf_param_and_check client \
1085                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1086         # also check ost_server_uuid status
1087         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1088         if [ -z "$RESULT" ]; then
1089             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1090             return 3
1091         else
1092             echo "Live client success: got $RESULT"
1093         fi
1094
1095         # check MDTs too
1096         for num in $(seq $MDSCOUNT); do
1097                 local mdtosc=$(get_mdtosc_proc_path mds${num} $FSNAME-OST0001)
1098                 local MPROC="osc.$mdtosc.active"
1099                 local MAX=30
1100                 local WAIT=0
1101                 while [ 1 ]; do
1102                         sleep 5
1103                         RESULT=$(do_facet mds${num} " lctl get_param -n $MPROC")
1104                         [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1105                         if [ $RESULT -eq $DEAC ]; then
1106                                 echo -n "MDT deactivated also after"
1107                                 echo "$WAIT sec (got $RESULT)"
1108                                 break
1109                         fi
1110                         WAIT=$((WAIT + 5))
1111                         if [ $WAIT -eq $MAX ]; then
1112                                 echo -n "MDT not deactivated: wanted $DEAC"
1113                                 echo  "got $RESULT"
1114                                 return 4
1115                         fi
1116                         echo "Waiting $(($MAX - $WAIT))secs for MDT deactivated"
1117                 done
1118         done
1119         # test new client starts deactivated
1120         umount_client $MOUNT || return 200
1121         mount_client $MOUNT
1122         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1123         if [ -z "$RESULT" ]; then
1124             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1125             return 5
1126         else
1127             echo "New client success: got $RESULT"
1128         fi
1129
1130         # make sure it reactivates
1131         set_conf_param_and_check client \
1132                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1133
1134         umount_client $MOUNT
1135         stop_ost2
1136         cleanup_nocli
1137         #writeconf to remove all ost2 traces for subsequent tests
1138         writeconf_or_reformat
1139 }
1140 run_test 29 "permanently remove an OST"
1141
1142 test_30a() {
1143         setup
1144
1145         echo Big config llog
1146         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1147         ORIG=$($TEST)
1148         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1149         for i in ${LIST[@]}; do
1150                 set_conf_param_and_check client "$TEST" \
1151                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1152         done
1153         # make sure client restart still works
1154         umount_client $MOUNT
1155         mount_client $MOUNT || return 4
1156         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1157         pass
1158
1159         echo Erase parameter setting
1160         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1161         umount_client $MOUNT
1162         mount_client $MOUNT || return 6
1163         FINAL=$($TEST)
1164         echo "deleted (default) value=$FINAL, orig=$ORIG"
1165         # assumes this parameter started at the default value
1166         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1167
1168         cleanup
1169 }
1170 run_test 30a "Big config llog and conf_param deletion"
1171
1172 test_30b() {
1173         setup
1174
1175         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1176         # numerical part of it. Hopefully that's not already a failover address for
1177         # the server.
1178         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1179         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1180         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1181         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1182         echo "Using fake nid $NEW"
1183
1184         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1185         set_conf_param_and_check client "$TEST" \
1186                 "$FSNAME-OST0000.failover.node" $NEW ||
1187                 error "didn't add failover nid $NEW"
1188         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1189         echo $NIDS
1190         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1191         echo "should have 2 failover nids: $NIDCOUNT"
1192         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1193         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1194         umount_client $MOUNT
1195         mount_client $MOUNT || return 3
1196
1197         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1198         echo $NIDS
1199         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1200         echo "only 1 final nid should remain: $NIDCOUNT"
1201         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1202
1203         cleanup
1204 }
1205 run_test 30b "Remove failover nids"
1206
1207 test_31() { # bug 10734
1208         # ipaddr must not exist
1209         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1210         cleanup
1211 }
1212 run_test 31 "Connect to non-existent node (shouldn't crash)"
1213
1214
1215 T32_QID=60000
1216 T32_BLIMIT=20480 # Kbytes
1217 T32_ILIMIT=2
1218
1219 #
1220 # This is not really a test but a tool to create new disk
1221 # image tarballs for the upgrade tests.
1222 #
1223 # Disk image tarballs should be created on single-node
1224 # clusters by running this test with default configurations
1225 # plus a few mandatory environment settings that are verified
1226 # at the beginning of the test.
1227 #
1228 test_32newtarball() {
1229         local version
1230         local dst=.
1231         local src=/etc/rc.d
1232         local tmp=$TMP/t32_image_create
1233
1234         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1235                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1236                  -z "$OSTDEV1" ]; then
1237                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1238                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1239                           "OSTDEV1=<nonexistent_file>"
1240         fi
1241
1242         mkdir $tmp || {
1243                 echo "Found stale $tmp"
1244                 return 1
1245         }
1246
1247         mkdir $tmp/src
1248         tar cf - -C $src . | tar xf - -C $tmp/src
1249         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1250                 count=$(($T32_BLIMIT / 1024 / 2))
1251         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1252
1253         formatall
1254
1255         setupall
1256
1257         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1258                 $LFS quotacheck -ug /mnt/$FSNAME
1259         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1260                 /mnt/$FSNAME
1261
1262         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1263         stopall
1264
1265         mkdir $tmp/img
1266
1267         setupall
1268         pushd /mnt/$FSNAME
1269         ls -Rni --time-style=+%s >$tmp/img/list
1270         find . ! -name .lustre -type f -exec sha1sum {} \; |
1271                 sort -k 2 >$tmp/img/sha1sums
1272         popd
1273         $LCTL get_param -n version | head -n 1 |
1274                 sed -e 's/^lustre: *//' >$tmp/img/commit
1275
1276         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1277                 $LFS quotaon -ug /mnt/$FSNAME
1278         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1279         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1280                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1281                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1282                 | tr -d "*" > $tmp/img/bspace
1283         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1284                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1285                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1286                 | tr -d "*" > $tmp/img/ispace
1287
1288         stopall
1289
1290         pushd $tmp/src
1291         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1292         popd
1293
1294         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1295                 echo "Data verification failed"
1296         fi
1297
1298         uname -r >$tmp/img/kernel
1299         uname -m >$tmp/img/arch
1300
1301         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1302         mv $OSTDEV1 $tmp/img
1303
1304         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1305                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1306         dst=$(cd $dst; pwd)
1307         pushd $tmp/img
1308         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1309         popd
1310
1311         rm -r $tmp
1312 }
1313 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1314
1315 #
1316 # The list of applicable tarballs is returned via the caller's
1317 # variable "tarballs".
1318 #
1319 t32_check() {
1320         local node=$(facet_active_host $SINGLEMDS)
1321         local r="do_node $node"
1322
1323         if [ "$CLIENTONLY" ]; then
1324                 skip "Client-only testing"
1325                 exit 0
1326         fi
1327
1328         if ! $r which $TUNEFS; then
1329                 skip_env "tunefs.lustre required on $node"
1330                 exit 0
1331         fi
1332
1333         if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1334                 skip "LU-2200: Test cannot run over Infiniband"
1335                 exit 0
1336         fi
1337
1338         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1339
1340         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1341
1342         if [ -z "$tarballs" ]; then
1343                 skip "No applicable tarballs found"
1344                 exit 0
1345         fi
1346 }
1347
1348 t32_test_cleanup() {
1349         local node=$(facet_active_host $SINGLEMDS)
1350         local r="do_node $node"
1351         local tmp=$TMP/t32
1352         local rc=$?
1353
1354         if $shall_cleanup_lustre; then
1355                 umount $tmp/mnt/lustre || rc=$?
1356         fi
1357         if $shall_cleanup_mdt; then
1358                 $r umount -d $tmp/mnt/mdt || rc=$?
1359         fi
1360         if $shall_cleanup_mdt1; then
1361                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1362         fi
1363         if $shall_cleanup_ost; then
1364                 $r umount -d $tmp/mnt/ost || rc=$?
1365         fi
1366         $r rm -rf $tmp || rc=$?
1367         rm -rf $tmp || rc=$?
1368         return $rc
1369 }
1370
1371 t32_bits_per_long() {
1372         #
1373         # Yes, this is not meant to be perfect.
1374         #
1375         case $1 in
1376                 ppc64|x86_64)
1377                         echo -n 64;;
1378                 i*86)
1379                         echo -n 32;;
1380         esac
1381 }
1382
1383 t32_reload_modules() {
1384         local node=$1
1385         local all_removed=false
1386         local i=0
1387
1388         while ((i < 20)); do
1389                 echo "Unloading modules on $node: Attempt $i"
1390                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1391                         all_removed=true
1392                 do_rpc_nodes $node check_mem_leak || return 1
1393                 if $all_removed; then
1394                         load_modules
1395                         return 0
1396                 fi
1397                 sleep 5
1398                 i=$((i + 1))
1399         done
1400         echo "Unloading modules on $node: Given up"
1401         return 1
1402 }
1403
1404 t32_wait_til_devices_gone() {
1405         local node=$1
1406         local devices
1407         local i=0
1408
1409         echo wait for devices to go
1410         while ((i < 20)); do
1411                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1412                 echo $device
1413                 ((devices == 0)) && return 1
1414                 sleep 5
1415                 i=$((i + 1))
1416         done
1417         echo "waiting for devices on $node: Given up"
1418         return 1
1419 }
1420
1421 t32_verify_quota() {
1422         local node=$1
1423         local fsname=$2
1424         local mnt=$3
1425         local fstype=$(facet_fstype $SINGLEMDS)
1426         local qval
1427         local cmd
1428
1429         $LFS quota -u $T32_QID -v $mnt
1430
1431         qval=$($LFS quota -v -u $T32_QID $mnt |
1432                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1433                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1434                 | tr -d "*")
1435         [ $qval -eq $img_bspace ] || {
1436                 echo "bspace, act:$qval, exp:$img_bspace"
1437                 return 1
1438         }
1439
1440         qval=$($LFS quota -v -u $T32_QID $mnt |
1441                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1442                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1443                 | tr -d "*")
1444         [ $qval -eq $img_ispace ] || {
1445                 echo "ispace, act:$qval, exp:$img_ispace"
1446                 return 1
1447         }
1448
1449         qval=$($LFS quota -v -u $T32_QID $mnt |
1450                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1451                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1452                 | tr -d "*")
1453         [ $qval -eq $T32_BLIMIT ] || {
1454                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1455                 return 1
1456         }
1457
1458         qval=$($LFS quota -v -u $T32_QID $mnt |
1459                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1460                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1461                 | tr -d "*")
1462         [ $qval -eq $T32_ILIMIT ] || {
1463                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1464                 return 1
1465         }
1466
1467         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1468         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1469         cmd=$cmd.quota_slave.enabled
1470         wait_update $node "$cmd" "ug" || {
1471                 echo "Enable mdt quota failed"
1472                 return 1
1473         }
1474
1475         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1476         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1477         cmd=$cmd.quota_slave.enabled
1478         wait_update $node "$cmd" "ug" || {
1479                 echo "Enable ost quota failed"
1480                 return 1
1481         }
1482
1483         chmod 0777 $mnt
1484         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1485                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1486                 echo "Write succeed, but expect -EDQUOT"
1487                 return 1
1488         }
1489         rm -f $mnt/t32_qf_new
1490
1491         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1492                 $T32_ILIMIT && {
1493                 echo "Create succeed, but expect -EDQUOT"
1494                 return 1
1495         }
1496         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1497
1498         return 0
1499 }
1500
1501 t32_test() {
1502         local tarball=$1
1503         local writeconf=$2
1504         local dne_upgrade=${dne_upgrade:-"no"}
1505         local shall_cleanup_mdt=false
1506         local shall_cleanup_mdt1=false
1507         local shall_cleanup_ost=false
1508         local shall_cleanup_lustre=false
1509         local node=$(facet_active_host $SINGLEMDS)
1510         local r="do_node $node"
1511         local node2=$(facet_active_host mds2)
1512         local r2="do_node $node2"
1513         local tmp=$TMP/t32
1514         local img_commit
1515         local img_kernel
1516         local img_arch
1517         local img_bspace
1518         local img_ispace
1519         local fsname=t32fs
1520         local nid=$($r $LCTL list_nids | head -1)
1521         local mopts
1522         local uuid
1523         local nrpcs_orig
1524         local nrpcs
1525         local list
1526         local fstype=$(facet_fstype $SINGLEMDS)
1527
1528         trap 'trap - RETURN; t32_test_cleanup' RETURN
1529
1530         mkdir -p $tmp/mnt/lustre
1531         $r mkdir -p $tmp/mnt/{mdt,ost}
1532         $r tar xjvf $tarball -S -C $tmp || {
1533                 error_noexit "Unpacking the disk image tarball"
1534                 return 1
1535         }
1536         img_commit=$($r cat $tmp/commit)
1537         img_kernel=$($r cat $tmp/kernel)
1538         img_arch=$($r cat $tmp/arch)
1539         img_bspace=$($r cat $tmp/bspace)
1540         img_ispace=$($r cat $tmp/ispace)
1541         echo "Upgrading from $(basename $tarball), created with:"
1542         echo "  Commit: $img_commit"
1543         echo "  Kernel: $img_kernel"
1544         echo "    Arch: $img_arch"
1545
1546         $r $LCTL set_param debug="$PTLDEBUG"
1547
1548         $r $TUNEFS --dryrun $tmp/mdt || {
1549                 error_noexit "tunefs.lustre before mounting the MDT"
1550                 return 1
1551         }
1552         if [ "$writeconf" ]; then
1553                 mopts=loop,writeconf
1554                 if [ $fstype == "ldiskfs" ]; then
1555                         $r $TUNEFS --quota $tmp/mdt || {
1556                                 error_noexit "Enable mdt quota feature"
1557                                 return 1
1558                         }
1559                 fi
1560         else
1561                 mopts=loop,exclude=$fsname-OST0000
1562         fi
1563
1564         t32_wait_til_devices_gone $node
1565
1566         $r mount -t lustre -o $mopts $tmp/mdt $tmp/mnt/mdt || {
1567                 error_noexit "Mounting the MDT"
1568                 return 1
1569         }
1570         shall_cleanup_mdt=true
1571
1572         if [ "$dne_upgrade" != "no" ]; then
1573                 echo "mkfs new MDT...."
1574                 add mds2 $(mkfs_opts mds2 $(mdsdevname 2) $fsname) --reformat \
1575                         $(mdsdevname 2) $(mdsvdevname 2) > /dev/null || {
1576                         error_noexit "Mkfs new MDT failed"
1577                         return 1
1578                 }
1579
1580                 $r2 $TUNEFS --dryrun $(mdsdevname 2) || {
1581                         error_noexit "tunefs.lustre before mounting the MDT"
1582                         return 1
1583                 }
1584
1585                 echo "mount new MDT...."
1586                 $r2 mkdir -p $tmp/mnt/mdt1
1587                 $r2 mount -t lustre -o $mopts $(mdsdevname 2) $tmp/mnt/mdt1 || {
1588                         error_noexit "mount mdt1 failed"
1589                         return 1
1590                 }
1591                 shall_cleanup_mdt1=true
1592         fi
1593
1594         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1595                 error_noexit "Getting MDT UUID"
1596                 return 1
1597         }
1598         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1599                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1600                 return 1
1601         fi
1602
1603         $r $TUNEFS --dryrun $tmp/ost || {
1604                 error_noexit "tunefs.lustre before mounting the OST"
1605                 return 1
1606         }
1607         if [ "$writeconf" ]; then
1608                 mopts=loop,mgsnode=$nid,$writeconf
1609                 if [ $fstype == "ldiskfs" ]; then
1610                         $r $TUNEFS --quota $tmp/ost || {
1611                                 error_noexit "Enable ost quota feature"
1612                                 return 1
1613                         }
1614                 fi
1615         else
1616                 mopts=loop,mgsnode=$nid
1617         fi
1618         $r mount -t lustre -o $mopts $tmp/ost $tmp/mnt/ost || {
1619                 error_noexit "Mounting the OST"
1620                 return 1
1621         }
1622         shall_cleanup_ost=true
1623
1624         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1625                 error_noexit "Getting OST UUID"
1626                 return 1
1627         }
1628         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1629                 error_noexit "Unexpected OST UUID: \"$uuid\""
1630                 return 1
1631         fi
1632
1633         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1634                 error_noexit "Setting \"max_dirty_mb\""
1635                 return 1
1636         }
1637         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1638                 error_noexit "Setting OST \"failover.node\""
1639                 return 1
1640         }
1641         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1642                 error_noexit "Setting \"max_rpcs_in_flight\""
1643                 return 1
1644         }
1645         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1646                 error_noexit "Setting MDT \"failover.node\""
1647                 return 1
1648         }
1649         $r $LCTL pool_new $fsname.interop || {
1650                 error_noexit "Setting \"interop\""
1651                 return 1
1652         }
1653         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1654                 error_noexit "Setting \"lov.stripesize\""
1655                 return 1
1656         }
1657
1658         if [ "$dne_upgrade" != "no" ]; then
1659                 $r $LCTL conf_param \
1660                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1661                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1662                         return 1
1663                 }
1664                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1665                         error_noexit "Setting MDT1 \"failover.node\""
1666                         return 1
1667                 }
1668                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1669                         error_noexit "Setting MDT1 \"lov.stripesize\""
1670                         return 1
1671                 }
1672
1673         fi
1674
1675         if [ "$writeconf" ]; then
1676                 mount -t lustre $nid:/$fsname $tmp/mnt/lustre || {
1677                         error_noexit "Mounting the client"
1678                         return 1
1679                 }
1680                 shall_cleanup_lustre=true
1681                 $LCTL set_param debug="$PTLDEBUG"
1682
1683                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
1684                         error_noexit "verify quota failed"
1685                         return 1
1686                 }
1687
1688                 if [ "$dne_upgrade" != "no" ]; then
1689                         $LFS mkdir -i 1 $tmp/mnt/lustre/remote_dir || {
1690                                 error_noexit "set remote dir failed"
1691                                 return 1
1692                         }
1693
1694                         pushd $tmp/mnt/lustre
1695                         tar -cf - . --exclude=./remote_dir |
1696                                 tar -xvf - -C remote_dir 1>/dev/null || {
1697                                 error_noexit "cp to remote dir failed"
1698                                 return 1
1699                         }
1700                         popd
1701                 fi
1702
1703                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1704                         error_noexit "dd failed"
1705                         return 1
1706                 }
1707                 rm -rf $tmp/mnt/lustre/tmp_file || {
1708                         error_noexit "rm failed"
1709                         return 1
1710                 }
1711
1712                 if $r test -f $tmp/sha1sums; then
1713                         # LU-2393 - do both sorts on same node to ensure locale
1714                         # is identical
1715                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1716                         if [ "$dne_upgrade" != "no" ]; then
1717                                 pushd $tmp/mnt/lustre/remote_dir
1718                         else
1719                                 pushd $tmp/mnt/lustre
1720                         fi
1721
1722                         find ! -name .lustre -type f -exec sha1sum {} \; |
1723                                 sort -k 2 >$tmp/sha1sums || {
1724                                 error_noexit "sha1sum"
1725                                 return 1
1726                         }
1727                         popd
1728                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1729                                 error_noexit "sha1sum verification failed"
1730                                 return 1
1731                         fi
1732                 else
1733                         echo "sha1sum verification skipped"
1734                 fi
1735
1736                 if [ "$dne_upgrade" != "no" ]; then
1737                         rm -rf $tmp/mnt/lustre/remote_dir || {
1738                                 error_noexit "remove remote dir failed"
1739                                 return 1
1740                         }
1741                 fi
1742
1743                 if $r test -f $tmp/list; then
1744                         #
1745                         # There is not a Test Framework API to copy files to or
1746                         # from a remote node.
1747                         #
1748                         # LU-2393 - do both sorts on same node to ensure locale
1749                         # is identical
1750                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1751                         pushd $tmp/mnt/lustre
1752                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1753                                 error_noexit "ls"
1754                                 return 1
1755                         }
1756                         popd
1757                         #
1758                         # 32-bit and 64-bit clients use different algorithms to
1759                         # convert FIDs into inode numbers.  Hence, remove the inode
1760                         # numbers from the lists, if the original list was created
1761                         # on an architecture with different number of bits per
1762                         # "long".
1763                         #
1764                         if [ $(t32_bits_per_long $(uname -m)) !=                                                \
1765                                  $(t32_bits_per_long $img_arch) ]; then
1766                                 echo "Different number of bits per \"long\" from the disk image"
1767                                 for list in list.orig list; do
1768                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1769                                 done
1770                         fi
1771                         if ! diff -ub $tmp/list.orig $tmp/list; then
1772                                 error_noexit "list verification failed"
1773                                 return 1
1774                         fi
1775                 else
1776                         echo "list verification skipped"
1777                 fi
1778
1779                 #
1780                 # When adding new data verification tests, please check for
1781                 # the presence of the required reference files first, like
1782                 # the "sha1sums" and "list" tests above, to avoid the need to
1783                 # regenerate every image for each test addition.
1784                 #
1785
1786                 nrpcs_orig=$($LCTL get_param \
1787                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
1788                         error_noexit "Getting \"max_rpcs_in_flight\""
1789                         return 1
1790                 }
1791                 nrpcs=$((nrpcs_orig + 5))
1792                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1793                         error_noexit "Changing \"max_rpcs_in_flight\""
1794                         return 1
1795                 }
1796                 wait_update $HOSTNAME "$LCTL get_param \
1797                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
1798                         error_noexit "Verifying \"max_rpcs_in_flight\""
1799                         return 1
1800                 }
1801
1802                 umount $tmp/mnt/lustre || {
1803                         error_noexit "Unmounting the client"
1804                         return 1
1805                 }
1806                 shall_cleanup_lustre=false
1807         else
1808                 $r umount -d $tmp/mnt/mdt || {
1809                         error_noexit "Unmounting the MDT"
1810                         return 1
1811                 }
1812                 shall_cleanup_mdt=false
1813                 $r umount -d $tmp/mnt/ost || {
1814                         error_noexit "Unmounting the OST"
1815                         return 1
1816                 }
1817                 shall_cleanup_ost=false
1818
1819                 t32_reload_modules $node || {
1820                         error_noexit "Reloading modules"
1821                         return 1
1822                 }
1823
1824                 # mount a second time to make sure we didnt leave upgrade flag on
1825                 $r $TUNEFS --dryrun $tmp/mdt || {
1826                         error_noexit "tunefs.lustre before remounting the MDT"
1827                         return 1
1828                 }
1829                 $r mount -t lustre -o loop,exclude=$fsname-OST0000 $tmp/mdt                     \
1830                                  $tmp/mnt/mdt || {
1831                         error_noexit "Remounting the MDT"
1832                         return 1
1833                 }
1834                 shall_cleanup_mdt=true
1835         fi
1836 }
1837
1838 test_32a() {
1839         local tarballs
1840         local tarball
1841         local rc=0
1842
1843         t32_check
1844         for tarball in $tarballs; do
1845                 t32_test $tarball || rc=$?
1846         done
1847         return $rc
1848 }
1849 run_test 32a "Upgrade (not live)"
1850
1851 test_32b() {
1852         local tarballs
1853         local tarball
1854         local rc=0
1855
1856         t32_check
1857         for tarball in $tarballs; do
1858                 t32_test $tarball writeconf || rc=$?
1859         done
1860         return $rc
1861 }
1862 run_test 32b "Upgrade with writeconf"
1863
1864 test_32c() {
1865         local tarballs
1866         local tarball
1867         local rc=0
1868
1869         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1870         t32_check
1871         for tarball in $tarballs; do
1872                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
1873         done
1874         return $rc
1875 }
1876 run_test 32c "dne upgrade test"
1877
1878 test_33a() { # bug 12333, was test_33
1879         local rc=0
1880         local FSNAME2=test-123
1881         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1882         local mkfsoptions
1883
1884         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1885
1886         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1887                 local dev=${SINGLEMDS}_dev
1888                 local MDSDEV=${!dev}
1889                 is_blkdev $SINGLEMDS $MDSDEV && \
1890                 skip_env "mixed loopback and real device not working" && return
1891         fi
1892
1893         local fs2mdsdev=$(mdsdevname 1_2)
1894         local fs2ostdev=$(ostdevname 1_2)
1895         local fs2mdsvdev=$(mdsvdevname 1_2)
1896         local fs2ostvdev=$(ostvdevname 1_2)
1897
1898         if [ $(facet_fstype mds1) == ldiskfs ]; then
1899                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
1900         fi
1901
1902         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
1903                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
1904         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
1905                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
1906                 $fs2ostvdev || exit 10
1907
1908         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1909         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1910         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1911         mkdir -p $MOUNT2
1912         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1913         echo "ok."
1914
1915         cp /etc/hosts $MOUNT2/ || rc=3
1916         $LFS getstripe $MOUNT2/hosts
1917
1918         umount -d $MOUNT2
1919         stop fs2ost -f
1920         stop fs2mds -f
1921         cleanup_nocli || rc=6
1922         return $rc
1923 }
1924 run_test 33a "Mount ost with a large index number"
1925
1926 test_33b() {    # was test_34
1927         setup
1928
1929         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1930         # Drop lock cancelation reply during umount
1931         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
1932         do_facet client lctl set_param fail_loc=0x80000304
1933         #lctl set_param debug=-1
1934         umount_client $MOUNT
1935         cleanup
1936 }
1937 run_test 33b "Drop cancel during umount"
1938
1939 test_34a() {
1940         setup
1941         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1942         manual_umount_client
1943         rc=$?
1944         do_facet client killall -USR1 multiop
1945         if [ $rc -eq 0 ]; then
1946                 error "umount not fail!"
1947         fi
1948         sleep 1
1949         cleanup
1950 }
1951 run_test 34a "umount with opened file should be fail"
1952
1953
1954 test_34b() {
1955         setup
1956         touch $DIR/$tfile || return 1
1957         stop_mds --force || return 2
1958
1959         manual_umount_client --force
1960         rc=$?
1961         if [ $rc -ne 0 ]; then
1962                 error "mtab after failed umount - rc $rc"
1963         fi
1964
1965         cleanup
1966         return 0
1967 }
1968 run_test 34b "force umount with failed mds should be normal"
1969
1970 test_34c() {
1971         setup
1972         touch $DIR/$tfile || return 1
1973         stop_ost --force || return 2
1974
1975         manual_umount_client --force
1976         rc=$?
1977         if [ $rc -ne 0 ]; then
1978                 error "mtab after failed umount - rc $rc"
1979         fi
1980
1981         cleanup
1982         return 0
1983 }
1984 run_test 34c "force umount with failed ost should be normal"
1985
1986 test_35a() { # bug 12459
1987         setup
1988
1989         DBG_SAVE="`lctl get_param -n debug`"
1990         lctl set_param debug="ha"
1991
1992         log "Set up a fake failnode for the MDS"
1993         FAKENID="127.0.0.2"
1994         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1995         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1996                 "$(h2$NETTYPE $FAKENID)" || return 4
1997
1998         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1999         sleep 10
2000
2001         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2002         $LCTL clear
2003         log "$MSG"
2004         log "Stopping the MDT: $device"
2005         stop_mdt 1 || return 5
2006
2007         df $MOUNT > /dev/null 2>&1 &
2008         DFPID=$!
2009         log "Restarting the MDT: $device"
2010         start_mdt 1 || return 6
2011         log "Wait for df ($DFPID) ... "
2012         wait $DFPID
2013         log "done"
2014         lctl set_param debug="$DBG_SAVE"
2015
2016         # retrieve from the log the first server that the client tried to
2017         # contact after the connection loss
2018         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2019         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2020                        /import_select_connection.*$device-mdc.* using connection/ {
2021                                 if (start) {
2022                                         if (\\\$NF ~ /$FAKENID/)
2023                                                 print \\\$NF;
2024                                         else
2025                                                 print 0;
2026                                         exit;
2027                                 }
2028                        }" $TMP/lustre-log-$TESTNAME.log`
2029         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
2030         cleanup
2031         # remove nid settings
2032         writeconf_or_reformat
2033 }
2034 run_test 35a "Reconnect to the last active server first"
2035
2036 test_35b() { # bug 18674
2037         remote_mds || { skip "local MDS" && return 0; }
2038         setup
2039
2040         debugsave
2041         $LCTL set_param debug="ha"
2042         $LCTL clear
2043         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2044         log "$MSG"
2045
2046         log "Set up a fake failnode for the MDS"
2047         FAKENID="127.0.0.2"
2048         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" | \
2049                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2050         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
2051                 "$(h2$NETTYPE $FAKENID)" || return 1
2052
2053         local at_max_saved=0
2054         # adaptive timeouts may prevent seeing the issue
2055         if at_is_enabled; then
2056                 at_max_saved=$(at_max_get mds)
2057                 at_max_set 0 mds client
2058         fi
2059
2060         mkdir -p $MOUNT/$tdir
2061
2062         log "Injecting EBUSY on MDS"
2063         # Setting OBD_FAIL_MDS_RESEND=0x136
2064         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
2065
2066         $LCTL set_param mdc.${FSNAME}*.stats=clear
2067
2068         log "Creating a test file and stat it"
2069         touch $MOUNT/$tdir/$tfile
2070         stat $MOUNT/$tdir/$tfile
2071
2072         log "Stop injecting EBUSY on MDS"
2073         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
2074         rm -f $MOUNT/$tdir/$tfile
2075
2076         log "done"
2077         # restore adaptive timeout
2078         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2079
2080         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2081
2082         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
2083
2084         # retrieve from the log if the client has ever tried to
2085         # contact the fake server after the loss of connection
2086         FAILCONN=`awk "BEGIN {ret = 0;}
2087                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2088                                 ret = 1;
2089                                 if (\\\$NF ~ /$FAKENID/) {
2090                                         ret = 2;
2091                                         exit;
2092                                 }
2093                        }
2094                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2095
2096         [ "$FAILCONN" == "0" ] && \
2097                 log "ERROR: The client reconnection has not been triggered" && \
2098                 return 4
2099         [ "$FAILCONN" == "2" ] && \
2100                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
2101                 return 5
2102
2103         # LU-290
2104         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2105         # Reconnects are supposed to be rate limited to one every 5s
2106         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
2107                 log "ERROR: Too many reconnects $CONNCNT" && \
2108                 return 6
2109
2110         cleanup
2111         # remove nid settings
2112         writeconf_or_reformat
2113 }
2114 run_test 35b "Continue reconnection retries, if the active server is busy"
2115
2116 test_36() { # 12743
2117         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
2118
2119         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
2120                 { skip "remote OST" && return 0; }
2121
2122         local rc=0
2123         local FSNAME2=test1234
2124         local fs3ost_HOST=$ost_HOST
2125         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2126
2127         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2128
2129         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2130                 is_blkdev $SINGLEMDS $MDSDEV && \
2131                 skip_env "mixed loopback and real device not working" && return
2132         fi
2133
2134         local fs2mdsdev=$(mdsdevname 1_2)
2135         local fs2ostdev=$(ostdevname 1_2)
2136         local fs3ostdev=$(ostdevname 2_2)
2137         local fs2mdsvdev=$(mdsvdevname 1_2)
2138         local fs2ostvdev=$(ostvdevname 1_2)
2139         local fs3ostvdev=$(ostvdevname 2_2)
2140
2141         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2142                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2143         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2144         #     different one than the default value here.
2145         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2146                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2147         add fs3ost $(mkfs_opts ost1 ${fs3ostdev}) --mgsnode=$MGSNID \
2148                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2149
2150         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2151         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2152         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2153         mkdir -p $MOUNT2
2154         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
2155
2156         sleep 5 # until 11778 fixed
2157
2158         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
2159
2160         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
2161         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
2162         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
2163         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
2164         DFTOTAL=`echo $STRING | cut -d, -f1`
2165         DFUSED=`echo $STRING  | cut -d, -f2`
2166         DFAVAIL=`echo $STRING | cut -d, -f3`
2167         DFFREE=$(($DFTOTAL - $DFUSED))
2168
2169         ALLOWANCE=$((64 * $OSTCOUNT))
2170
2171         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2172            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2173                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2174                 rc=1
2175         fi
2176         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2177            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2178                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2179                 rc=2
2180         fi
2181         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2182            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2183                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2184                 rc=3
2185        fi
2186
2187         umount -d $MOUNT2
2188         stop fs3ost -f || return 200
2189         stop fs2ost -f || return 201
2190         stop fs2mds -f || return 202
2191         unload_modules_conf || return 203
2192         return $rc
2193 }
2194 run_test 36 "df report consistency on OSTs with different block size"
2195
2196 test_37() {
2197         local mntpt=$(facet_mntpt $SINGLEMDS)
2198         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2199         local mdsdev_sym="$TMP/sym_mdt.img"
2200         local opts=$MDS_MOUNT_OPTS
2201         local rc=0
2202
2203         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2204                 skip "Currently only applicable to ldiskfs-based MDTs"
2205                 return
2206         fi
2207
2208         echo "MDS :     $mdsdev"
2209         echo "SYMLINK : $mdsdev_sym"
2210         do_facet $SINGLEMDS rm -f $mdsdev_sym
2211
2212         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2213
2214         echo "mount symlink device - $mdsdev_sym"
2215
2216         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2217                 opts=$(csa_add "$opts" -o loop)
2218         fi
2219         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2220                 $mdsdev_sym $mntpt 2>&1)
2221         rc=${PIPESTATUS[0]}
2222
2223         echo mount_op=$mount_op
2224
2225         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2226
2227         if $(echo $mount_op | grep -q "unable to set tunable"); then
2228                 error "set tunables failed for symlink device"
2229         fi
2230
2231         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2232
2233         return 0
2234 }
2235 run_test 37 "verify set tunables works for symlink device"
2236
2237 test_38() { # bug 14222
2238         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2239                 skip "Only applicable to ldiskfs-based MDTs"
2240                 return
2241         fi
2242
2243         setup
2244         # like runtests
2245         COUNT=10
2246         SRC="/etc /bin"
2247         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
2248         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2249         mkdir -p $DIR/$tdir
2250         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
2251                 error "copying $SRC to $DIR/$tdir"
2252         sync
2253         umount_client $MOUNT
2254         stop_mds
2255         log "rename lov_objid file on MDS"
2256         rm -f $TMP/lov_objid.orig
2257
2258         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2259         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
2260         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2261
2262         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
2263         # check create in mds_lov_connect
2264         start_mds
2265         mount_client $MOUNT
2266         for f in $FILES; do
2267                 [ $V ] && log "verifying $DIR/$tdir/$f"
2268                 diff -q $f $DIR/$tdir/$f || ERROR=y
2269         done
2270         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
2271         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
2272         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
2273
2274         # check it's updates in sync
2275         umount_client $MOUNT
2276         stop_mds
2277
2278         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
2279         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2280         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
2281
2282         start_mds
2283         mount_client $MOUNT
2284         for f in $FILES; do
2285                 [ $V ] && log "verifying $DIR/$tdir/$f"
2286                 diff -q $f $DIR/$tdir/$f || ERROR=y
2287         done
2288         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
2289         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
2290         umount_client $MOUNT
2291         stop_mds
2292         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
2293
2294         log "files compared the same"
2295         cleanup
2296 }
2297 run_test 38 "MDS recreates missing lov_objid file from OST data"
2298
2299 test_39() {
2300         PTLDEBUG=+malloc
2301         setup
2302         cleanup
2303         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2304                 error "memory leak detected" || true
2305 }
2306 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2307
2308 test_40() { # bug 15759
2309         start_ost
2310         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2311         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2312         start_mds
2313         cleanup
2314 }
2315 run_test 40 "race during service thread startup"
2316
2317 test_41a() { #bug 14134
2318         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2319            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2320                 skip "Loop devices does not work with nosvc option"
2321                 return
2322         fi
2323
2324         local rc
2325         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2326
2327         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2328         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2329         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2330         mkdir -p $MOUNT
2331         mount_client $MOUNT || return 1
2332         sleep 5
2333
2334         echo "blah blah" > $MOUNT/$tfile
2335         cat $MOUNT/$tfile
2336
2337         umount_client $MOUNT
2338         stop ost1 -f || return 201
2339         stop_mds -f || return 202
2340         stop_mds -f || return 203
2341         unload_modules_conf || return 204
2342         return $rc
2343 }
2344 run_test 41a "mount mds with --nosvc and --nomgs"
2345
2346 test_41b() {
2347         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2348            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2349                 skip "Loop devices does not work with nosvc option"
2350                 return
2351         fi
2352
2353         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2354
2355         stopall
2356         reformat
2357         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2358
2359         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2360         start_ost
2361         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2362         mkdir -p $MOUNT
2363         mount_client $MOUNT || return 1
2364         sleep 5
2365
2366         echo "blah blah" > $MOUNT/$tfile
2367         cat $MOUNT/$tfile || return 200
2368
2369         umount_client $MOUNT
2370         stop_ost || return 201
2371         stop_mds -f || return 202
2372         stop_mds -f || return 203
2373
2374 }
2375 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2376
2377 test_42() { #bug 14693
2378         setup
2379         check_mount || error "client was not mounted"
2380
2381         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2382         umount_client $MOUNT ||
2383                 error "unmounting client failed with invalid llite param"
2384         mount_client $MOUNT ||
2385                 error "mounting client failed with invalid llite param"
2386
2387         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2388         cleanup || error "stopping $FSNAME failed with invalid sys param"
2389         setup
2390         check_mount || "client was not mounted with invalid sys param"
2391         cleanup || error "stopping $FSNAME failed with invalid sys param"
2392         return 0
2393 }
2394 run_test 42 "allow client/server mount/unmount with invalid config param"
2395
2396 test_43() {
2397         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2398         setup
2399         chmod ugo+x $DIR || error "chmod 0 failed"
2400         set_conf_param_and_check mds                                    \
2401                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2402                 "$FSNAME.mdt.root_squash"                               \
2403                 "0:0"
2404         set_conf_param_and_check mds                                    \
2405                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2406                 "$FSNAME.mdt.nosquash_nids"                             \
2407                 "NONE"
2408
2409     #
2410     # create set of test files
2411     #
2412     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2413     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2414     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2415
2416     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2417     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2418
2419     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2420     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2421     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2422
2423         #
2424         # check root_squash:
2425         #   set root squash UID:GID to RUNAS_ID
2426         #   root should be able to access only files owned by RUNAS_ID
2427         #
2428         set_conf_param_and_check mds                                    \
2429                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2430                 "$FSNAME.mdt.root_squash"                               \
2431                 "$RUNAS_ID:$RUNAS_ID"
2432
2433     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2434     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2435         error "$ST: root read permission is denied"
2436     echo "$ST: root read permission is granted - ok"
2437
2438     echo "444" | \
2439     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2440         error "$ST: root write permission is denied"
2441     echo "$ST: root write permission is granted - ok"
2442
2443     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2444     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2445         error "$ST: root read permission is granted"
2446     echo "$ST: root read permission is denied - ok"
2447
2448     echo "555" | \
2449     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2450         error "$ST: root write permission is granted"
2451     echo "$ST: root write permission is denied - ok"
2452
2453     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2454     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2455         error "$ST: root unlink permission is granted"
2456     echo "$ST: root unlink permission is denied - ok"
2457
2458     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2459         error "$ST: root create permission is granted"
2460     echo "$ST: root create permission is denied - ok"
2461
2462         #
2463         # check nosquash_nids:
2464         #   put client's NID into nosquash_nids list,
2465         #   root should be able to access root file after that
2466         #
2467         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2468         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2469         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2470         set_conf_param_and_check mds                                    \
2471                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2472                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2473                 "$NIDLIST"
2474
2475     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2476     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2477         error "$ST: root read permission is denied"
2478     echo "$ST: root read permission is granted - ok"
2479
2480     echo "666" | \
2481     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2482         error "$ST: root write permission is denied"
2483     echo "$ST: root write permission is granted - ok"
2484
2485     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2486     rm $DIR/$tdir-rootdir/tfile-1 || \
2487         error "$ST: root unlink permission is denied"
2488     echo "$ST: root unlink permission is granted - ok"
2489     touch $DIR/$tdir-rootdir/tfile-2 || \
2490         error "$ST: root create permission is denied"
2491     echo "$ST: root create permission is granted - ok"
2492
2493     return 0
2494 }
2495 run_test 43 "check root_squash and nosquash_nids"
2496
2497 umount_client $MOUNT
2498 cleanup_nocli
2499
2500 test_44() { # 16317
2501         setup
2502         check_mount || return 2
2503         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2504         STATS_FOUND=no
2505         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2506         for VAL in $UUIDS; do
2507                 NID=$(echo $VAL | cut -d= -f1)
2508                 CLUUID=$(echo $VAL | cut -d= -f2)
2509                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2510         done
2511         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2512         cleanup
2513         return 0
2514 }
2515 run_test 44 "mounted client proc entry exists"
2516
2517 test_45() { #17310
2518         setup
2519         check_mount || return 2
2520         stop_mds
2521         df -h $MOUNT &
2522         log "sleep 60 sec"
2523         sleep 60
2524 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2525         do_facet client "lctl set_param fail_loc=0x50f"
2526         log "sleep 10 sec"
2527         sleep 10
2528         manual_umount_client --force || return 3
2529         do_facet client "lctl set_param fail_loc=0x0"
2530         start_mds
2531         mount_client $MOUNT || return 4
2532         cleanup
2533         return 0
2534 }
2535 run_test 45 "long unlink handling in ptlrpcd"
2536
2537 cleanup_46a() {
2538         trap 0
2539         local rc=0
2540         local count=$1
2541
2542         umount_client $MOUNT2 || rc=$?
2543         umount_client $MOUNT || rc=$?
2544         while [ $count -gt 0 ]; do
2545                 stop ost${count} -f || rc=$?
2546                 let count=count-1
2547         done    
2548         stop_mds || rc=$?
2549         cleanup_nocli || rc=$?
2550         #writeconf to remove all ost2 traces for subsequent tests
2551         writeconf_or_reformat
2552         return $rc
2553 }
2554
2555 test_46a() {
2556         echo "Testing with $OSTCOUNT OSTs"
2557         reformat_and_config
2558         start_mds || return 1
2559         #first client should see only one ost
2560         start_ost || return 2
2561         wait_osc_import_state mds ost FULL
2562         #start_client
2563         mount_client $MOUNT || return 3
2564         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2565
2566         local i
2567         for (( i=2; i<=$OSTCOUNT; i++ )); do
2568             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2569         done
2570
2571         # wait until osts in sync
2572         for (( i=2; i<=$OSTCOUNT; i++ )); do
2573             wait_osc_import_state mds ost$i FULL
2574             wait_osc_import_state client ost$i FULL
2575         done
2576
2577         #second client see all ost's
2578
2579         mount_client $MOUNT2 || return 8
2580         $LFS setstripe -c -1 $MOUNT2 || return 9
2581         $LFS getstripe $MOUNT2 || return 10
2582
2583         echo "ok" > $MOUNT2/widestripe
2584         $LFS getstripe $MOUNT2/widestripe || return 11
2585         # fill acl buffer for avoid expand lsm to them
2586         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2587             setfacl -m $acl $MOUNT2/widestripe
2588         done
2589
2590         # will be deadlock
2591         stat $MOUNT/widestripe || return 12
2592
2593         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2594         return 0
2595 }
2596 run_test 46a "handle ost additional - wide striped file"
2597
2598 test_47() { #17674
2599         reformat
2600         setup_noconfig
2601         check_mount || return 2
2602         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2603
2604         local lru_size=[]
2605         local count=0
2606         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2607             if echo $ns | grep "MDT[[:digit:]]*"; then
2608                 continue
2609             fi
2610             lrs=$(echo $ns | sed 's/.*lru_size=//')
2611             lru_size[count]=$lrs
2612             let count=count+1
2613         done
2614
2615         facet_failover ost1
2616         facet_failover $SINGLEMDS
2617         client_up || return 3
2618
2619         count=0
2620         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2621             if echo $ns | grep "MDT[[:digit:]]*"; then
2622                 continue
2623             fi
2624             lrs=$(echo $ns | sed 's/.*lru_size=//')
2625             if ! test "$lrs" -eq "${lru_size[count]}"; then
2626                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2627                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2628             fi
2629             let count=count+1
2630         done
2631
2632         cleanup
2633         return 0
2634 }
2635 run_test 47 "server restart does not make client loss lru_resize settings"
2636
2637 cleanup_48() {
2638         trap 0
2639
2640         # reformat after this test is needed - if test will failed
2641         # we will have unkillable file at FS
2642         reformat_and_config
2643 }
2644
2645 test_48() { # bug 17636
2646         reformat
2647         setup_noconfig
2648         check_mount || return 2
2649
2650         $LFS setstripe -c -1 $MOUNT || return 9
2651         $LFS getstripe $MOUNT || return 10
2652
2653         echo "ok" > $MOUNT/widestripe
2654         $LFS getstripe $MOUNT/widestripe || return 11
2655
2656         trap cleanup_48 EXIT ERR
2657
2658         # fill acl buffer for avoid expand lsm to them
2659         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2660             setfacl -m $acl $MOUNT/widestripe
2661         done
2662
2663         stat $MOUNT/widestripe || return 12
2664
2665         cleanup_48
2666         return 0
2667 }
2668 run_test 48 "too many acls on file"
2669
2670 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2671 test_49() { # bug 17710
2672         local timeout_orig=$TIMEOUT
2673         local ldlm_timeout_orig=$LDLM_TIMEOUT
2674         local LOCAL_TIMEOUT=20
2675
2676         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2677         TIMEOUT=$LOCAL_TIMEOUT
2678
2679         reformat
2680         setup_noconfig
2681         check_mount || return 1
2682
2683         echo "check ldlm_timout..."
2684         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2685         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2686         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2687
2688         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2689                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2690         fi
2691
2692         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2693                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2694         fi
2695
2696         umount_client $MOUNT
2697         stop_ost || return 2
2698         stop_mds || return 3
2699
2700         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2701
2702         reformat
2703         setup_noconfig
2704         check_mount || return 7
2705
2706         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2707         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2708         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2709
2710         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2711                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2712         fi
2713
2714         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2715                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2716         fi
2717
2718         cleanup || return $?
2719
2720         LDLM_TIMEOUT=$ldlm_timeout_orig
2721         TIMEOUT=$timeout_orig
2722 }
2723 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2724
2725 lazystatfs() {
2726         # Test both statfs and lfs df and fail if either one fails
2727         multiop_bg_pause $1 f_
2728         RC1=$?
2729         PID=$!
2730         killall -USR1 multiop
2731         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2732         wait $PID || { RC1=$?; log "multiop return error "; }
2733
2734         $LFS df &
2735         PID=$!
2736         sleep 5
2737         kill -s 0 $PID
2738         RC2=$?
2739         if [ $RC2 -eq 0 ]; then
2740             kill -s 9 $PID
2741             log "lazystatfs df failed"
2742         fi
2743
2744         RC=0
2745         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2746         return $RC
2747 }
2748
2749 test_50a() {
2750         setup
2751         lctl set_param llite.$FSNAME-*.lazystatfs=1
2752         touch $DIR/$tfile
2753
2754         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2755
2756         cleanup || return $?
2757 }
2758 run_test 50a "lazystatfs all servers available =========================="
2759
2760 test_50b() {
2761         setup
2762         lctl set_param llite.$FSNAME-*.lazystatfs=1
2763         touch $DIR/$tfile
2764
2765         # Wait for client to detect down OST
2766         stop_ost || error "Unable to stop OST1"
2767         wait_osc_import_state mds ost DISCONN
2768
2769         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2770
2771         umount_client $MOUNT || error "Unable to unmount client"
2772         stop_mds || error "Unable to stop MDS"
2773 }
2774 run_test 50b "lazystatfs all servers down =========================="
2775
2776 test_50c() {
2777         start_mds || error "Unable to start MDS"
2778         start_ost || error "Unable to start OST1"
2779         start_ost2 || error "Unable to start OST2"
2780         mount_client $MOUNT || error "Unable to mount client"
2781         lctl set_param llite.$FSNAME-*.lazystatfs=1
2782         touch $DIR/$tfile
2783
2784         # Wait for client to detect down OST
2785         stop_ost || error "Unable to stop OST1"
2786         wait_osc_import_state mds ost DISCONN
2787         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2788
2789         umount_client $MOUNT || error "Unable to unmount client"
2790         stop_ost2 || error "Unable to stop OST2"
2791         stop_mds || error "Unable to stop MDS"
2792         #writeconf to remove all ost2 traces for subsequent tests
2793         writeconf_or_reformat
2794 }
2795 run_test 50c "lazystatfs one server down =========================="
2796
2797 test_50d() {
2798         start_mds || error "Unable to start MDS"
2799         start_ost || error "Unable to start OST1"
2800         start_ost2 || error "Unable to start OST2"
2801         mount_client $MOUNT || error "Unable to mount client"
2802         lctl set_param llite.$FSNAME-*.lazystatfs=1
2803         touch $DIR/$tfile
2804
2805         # Issue the statfs during the window where the client still
2806         # belives the OST to be available but it is in fact down.
2807         # No failure just a statfs which hangs for a timeout interval.
2808         stop_ost || error "Unable to stop OST1"
2809         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2810
2811         umount_client $MOUNT || error "Unable to unmount client"
2812         stop_ost2 || error "Unable to stop OST2"
2813         stop_mds || error "Unable to stop MDS"
2814         #writeconf to remove all ost2 traces for subsequent tests
2815         writeconf_or_reformat
2816 }
2817 run_test 50d "lazystatfs client/server conn race =========================="
2818
2819 test_50e() {
2820         local RC1
2821         local pid
2822
2823         reformat_and_config
2824         start_mds || return 1
2825         #first client should see only one ost
2826         start_ost || return 2
2827         wait_osc_import_state mds ost FULL
2828
2829         # Wait for client to detect down OST
2830         stop_ost || error "Unable to stop OST1"
2831         wait_osc_import_state mds ost DISCONN
2832
2833         mount_client $MOUNT || error "Unable to mount client"
2834         lctl set_param llite.$FSNAME-*.lazystatfs=0
2835
2836         multiop_bg_pause $MOUNT _f
2837         RC1=$?
2838         pid=$!
2839
2840         if [ $RC1 -ne 0 ]; then
2841                 log "multiop failed $RC1"
2842         else
2843             kill -USR1 $pid
2844             sleep $(( $TIMEOUT+1 ))
2845             kill -0 $pid
2846             [ $? -ne 0 ] && error "process isn't sleep"
2847             start_ost || error "Unable to start OST1"
2848             wait $pid || error "statfs failed"
2849         fi
2850
2851         umount_client $MOUNT || error "Unable to unmount client"
2852         stop_ost || error "Unable to stop OST1"
2853         stop_mds || error "Unable to stop MDS"
2854 }
2855 run_test 50e "normal statfs all servers down =========================="
2856
2857 test_50f() {
2858         local RC1
2859         local pid
2860         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2861
2862         start_mds || error "Unable to start mds"
2863         #first client should see only one ost
2864         start_ost || error "Unable to start OST1"
2865         wait_osc_import_state mds ost FULL
2866
2867         start_ost2 || error "Unable to start OST2"
2868         wait_osc_import_state mds ost2 FULL
2869
2870         # Wait for client to detect down OST
2871         stop_ost2 || error "Unable to stop OST2"
2872
2873         wait_osc_import_state mds ost2 DISCONN
2874         mount_client $MOUNT || error "Unable to mount client"
2875         lctl set_param llite.$FSNAME-*.lazystatfs=0
2876
2877         multiop_bg_pause $MOUNT _f
2878         RC1=$?
2879         pid=$!
2880
2881         if [ $RC1 -ne 0 ]; then
2882                 log "lazystatfs multiop failed $RC1"
2883         else
2884             kill -USR1 $pid
2885             sleep $(( $TIMEOUT+1 ))
2886             kill -0 $pid
2887             [ $? -ne 0 ] && error "process isn't sleep"
2888             start_ost2 || error "Unable to start OST2"
2889             wait $pid || error "statfs failed"
2890             stop_ost2 || error "Unable to stop OST2"
2891         fi
2892
2893         umount_client $MOUNT || error "Unable to unmount client"
2894         stop_ost || error "Unable to stop OST1"
2895         stop_mds || error "Unable to stop MDS"
2896         #writeconf to remove all ost2 traces for subsequent tests
2897         writeconf_or_reformat
2898 }
2899 run_test 50f "normal statfs one server in down =========================="
2900
2901 test_50g() {
2902         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2903         setup
2904         start_ost2 || error "Unable to start OST2"
2905         wait_osc_import_state mds ost2 FULL
2906         wait_osc_import_state client ost2 FULL
2907
2908         local PARAM="${FSNAME}-OST0001.osc.active"
2909
2910         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2911         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2912
2913         umount_client $MOUNT || error "Unable to unmount client"
2914         mount_client $MOUNT || error "Unable to mount client"
2915         # This df should not cause a panic
2916         df -k $MOUNT
2917
2918         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2919         rm -f $DIR/$tfile
2920         umount_client $MOUNT || error "Unable to unmount client"
2921         stop_ost2 || error "Unable to stop OST2"
2922         stop_ost || error "Unable to stop OST1"
2923         stop_mds || error "Unable to stop MDS"
2924         #writeconf to remove all ost2 traces for subsequent tests
2925         writeconf_or_reformat
2926 }
2927 run_test 50g "deactivated OST should not cause panic====================="
2928
2929 # LU-642
2930 test_50h() {
2931         # prepare MDT/OST, make OSC inactive for OST1
2932         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2933         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
2934                 error "tunefs OST1 failed"
2935         start_mds  || error "Unable to start MDT"
2936         start_ost  || error "Unable to start OST1"
2937         start_ost2 || error "Unable to start OST2"
2938         mount_client $MOUNT || error "client start failed"
2939
2940         mkdir -p $DIR/$tdir
2941
2942         # activatate OSC for OST1
2943         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
2944         set_conf_param_and_check client                                 \
2945                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
2946                 error "Unable to activate OST1"
2947
2948         mkdir -p $DIR/$tdir/2
2949         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2
2950         sleep 1 && echo "create a file after OST1 is activated"
2951         # create some file
2952         createmany -o $DIR/$tdir/2/$tfile-%d 1
2953
2954         # check OSC import is working
2955         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
2956                 error "some OSC imports are still not connected"
2957
2958         # cleanup
2959         umount_client $MOUNT || error "Unable to umount client"
2960         stop_ost2 || error "Unable to stop OST2"
2961         cleanup_nocli
2962 }
2963 run_test 50h "LU-642: activate deactivated OST  ==="
2964
2965 test_51() {
2966         local LOCAL_TIMEOUT=20
2967
2968         reformat
2969         setup_noconfig
2970         check_mount || return 1
2971
2972         mkdir $MOUNT/d1
2973         $LFS setstripe -c -1 $MOUNT/d1
2974         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2975         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2976         touch $MOUNT/d1/f1 &
2977         local pid=$!
2978         sleep 2
2979         start_ost2 || return 2
2980         wait $pid
2981         stop_ost2 || return 3
2982         cleanup
2983         #writeconf to remove all ost2 traces for subsequent tests
2984         writeconf_or_reformat
2985 }
2986 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2987
2988 copy_files_xattrs()
2989 {
2990         local node=$1
2991         local dest=$2
2992         local xattrs=$3
2993         shift 3
2994
2995         do_node $node mkdir -p $dest
2996         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2997
2998         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2999                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3000         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3001
3002         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3003         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3004 }
3005
3006 diff_files_xattrs()
3007 {
3008         local node=$1
3009         local backup=$2
3010         local xattrs=$3
3011         shift 3
3012
3013         local backup2=${TMP}/backup2
3014
3015         do_node $node mkdir -p $backup2
3016         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3017
3018         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3019                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3020         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3021
3022         do_node $node "diff -rq $backup $backup2"
3023         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3024
3025         local xattrs2=${TMP}/xattrs2
3026         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3027         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3028
3029         do_node $node "diff $xattrs $xattrs2"
3030         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3031
3032         do_node $node "rm -rf $backup2 $xattrs2"
3033         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3034 }
3035
3036 test_52() {
3037         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3038                 skip "Only applicable to ldiskfs-based MDTs"
3039                 return
3040         fi
3041
3042         start_mds
3043         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
3044         start_ost
3045         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
3046         mount_client $MOUNT
3047         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
3048
3049         local nrfiles=8
3050         local ost1mnt=$(facet_mntpt ost1)
3051         local ost1node=$(facet_active_host ost1)
3052         local ost1tmp=$TMP/conf52
3053         local loop
3054
3055         mkdir -p $DIR/$tdir
3056         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
3057         touch $TMP/modified_first
3058         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
3059         local mtime=$(stat -c %Y $TMP/modified_first)
3060         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
3061
3062         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
3063         sleep 1
3064
3065         $LFS setstripe -c -1 -S 1M $DIR/$tdir
3066         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
3067
3068         for (( i=0; i < nrfiles; i++ )); do
3069                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
3070                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
3071                 echo -n .
3072         done
3073         echo
3074
3075         # backup files
3076         echo backup files to $TMP/files
3077         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3078         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3079         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
3080
3081         umount_client $MOUNT
3082         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
3083         stop_ost
3084         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
3085
3086         echo mount ost1 as ldiskfs
3087         do_node $ost1node mkdir -p $ost1mnt
3088         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
3089         if ! do_node $ost1node test -b $ost1_dev; then
3090                 loop="-o loop"
3091         fi
3092         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3093                 $ost1mnt
3094         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
3095
3096         # backup objects
3097         echo backup objects to $ost1tmp/objects
3098         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3099                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3100         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3101                         $objects
3102         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
3103
3104         # move objects to lost+found
3105         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3106         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3107
3108         # recover objects
3109         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
3110         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3111
3112         # compare restored objects against saved ones
3113         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3114         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
3115
3116         do_node $ost1node "umount $ost1mnt"
3117         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
3118
3119         start_ost
3120         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
3121         mount_client $MOUNT
3122         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
3123
3124         # compare files
3125         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3126         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
3127
3128         rm -rf $TMP/files $TMP/file_xattrs
3129         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
3130         do_node $ost1node "rm -rf $ost1tmp"
3131         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
3132         cleanup
3133 }
3134 run_test 52 "check recovering objects from lost+found"
3135
3136 # Checks threads_min/max/started for some service
3137 #
3138 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3139 # parameter pattern prefix like 'ost.*.ost'.
3140 thread_sanity() {
3141         local modname=$1
3142         local facet=$2
3143         local parampat=$3
3144         local opts=$4
3145         local basethr=$5
3146         local tmin
3147         local tmin2
3148         local tmax
3149         local tmax2
3150         local tstarted
3151         local paramp
3152         local msg="Insane $modname thread counts"
3153         local ncpts=$(check_cpt_number $facet)
3154         local nthrs
3155         shift 4
3156
3157         check_mount || return 41
3158
3159         # We need to expand $parampat, but it may match multiple parameters, so
3160         # we'll pick the first one
3161         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3162                 error "Couldn't expand ${parampat}.threads_min parameter name"
3163                 return 22
3164         fi
3165
3166         # Remove the .threads_min part
3167         paramp=${paramp%.threads_min}
3168
3169         # Check for sanity in defaults
3170         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3171         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3172         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
3173         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
3174         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3175         nthrs=$(expr $tmax - $tmin)
3176         if [ $nthrs -lt $ncpts ]; then
3177                 nthrs=0
3178         else
3179                 nthrs=$ncpts
3180         fi
3181
3182         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3183                 skip_env "module parameter forced $facet thread count" &&
3184                 tmin=3 && tmax=$((3 * tmax))
3185
3186         # Check that we can change min/max
3187         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
3188         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
3189         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3190         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3191         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
3192
3193         # Check that we can set min/max to the same value
3194         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3195         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
3196         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3197         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3198         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3199
3200         # Check that we can't set max < min
3201         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
3202         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3203         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3204         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3205
3206         # We need to ensure that we get the module options desired; to do this
3207         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3208         LOAD_MODULES_REMOTE=true
3209         cleanup
3210         local oldvalue
3211         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3212         setmodopts -a $modname "$newvalue" oldvalue
3213
3214         load_modules
3215         setup
3216         check_mount || return 41
3217
3218         # Restore previous setting of MODOPTS_*
3219         setmodopts $modname "$oldvalue"
3220
3221         # Check that $opts took
3222         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
3223         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
3224         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
3225         lassert 28 "$msg" '(($tstarted == $tmin && $tstarted == $tmax ))' || return $?
3226         cleanup
3227
3228         load_modules
3229         setup
3230 }
3231
3232 test_53a() {
3233         setup
3234         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3235         cleanup
3236 }
3237 run_test 53a "check OSS thread count params"
3238
3239 test_53b() {
3240         setup
3241         local mds=$(do_facet $SINGLEMDS "lctl get_param -N mds.*.*.threads_max \
3242                     2>/dev/null")
3243         if [ -z "$mds" ]; then
3244                 #running this on an old MDT
3245                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3246         else
3247                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3248         fi
3249         cleanup
3250 }
3251 run_test 53b "check MDS thread count params"
3252
3253 test_54a() {
3254         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3255                 skip "Only applicable to ldiskfs-based MDTs"
3256                 return
3257         fi
3258
3259     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
3260     [ $? -eq 0 ] || error "llverdev failed!"
3261     reformat_and_config
3262 }
3263 run_test 54a "test llverdev and partial verify of device"
3264
3265 test_54b() {
3266         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3267                 skip "Only applicable to ldiskfs-based MDTs"
3268                 return
3269         fi
3270
3271     setup
3272     run_llverfs $MOUNT -p
3273     [ $? -eq 0 ] || error "llverfs failed!"
3274     cleanup
3275 }
3276 run_test 54b "test llverfs and partial verify of filesystem"
3277
3278 lov_objid_size()
3279 {
3280         local max_ost_index=$1
3281         echo -n $(((max_ost_index + 1) * 8))
3282 }
3283
3284 test_55() {
3285         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3286                 skip "Only applicable to ldiskfs-based MDTs"
3287                 return
3288         fi
3289
3290         local mdsdev=$(mdsdevname 1)
3291         local mdsvdev=$(mdsvdevname 1)
3292
3293         for i in 1023 2048
3294         do
3295                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3296                         $mdsvdev || exit 10
3297                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3298                         --reformat $(ostdevname 1) $(ostvdevname 1)
3299                 setup_noconfig
3300                 stopall
3301                 setup_noconfig
3302                 sync
3303
3304                 echo checking size of lov_objid for ost index $i
3305                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3306                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3307                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3308                 else
3309                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3310                 fi
3311                 stopall
3312         done
3313
3314         reformat
3315 }
3316 run_test 55 "check lov_objid size"
3317
3318 test_56() {
3319         local mds_journal_size_orig=$MDSJOURNALSIZE
3320
3321         MDSJOURNALSIZE=16
3322
3323         for num in $(seq 1 $MDSCOUNT); do
3324                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3325                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3326         done
3327         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=1000 --reformat \
3328                 $(ostdevname 1) $(ostvdevname 1)
3329         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=10000 --reformat \
3330                 $(ostdevname 2) $(ostvdevname 2)
3331
3332         start_mgsmds
3333         start_ost
3334         start_ost2 || error "Unable to start second ost"
3335         mount_client $MOUNT || error "Unable to mount client"
3336         echo ok
3337         $LFS osts
3338         stopall
3339         MDSJOURNALSIZE=$mds_journal_size_orig
3340         reformat
3341 }
3342 run_test 56 "check big indexes"
3343
3344 test_57a() { # bug 22656
3345         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3346         writeconf_or_reformat
3347         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3348         start_mgsmds
3349         start_ost && error "OST registration from failnode should fail"
3350         reformat
3351 }
3352 run_test 57a "initial registration from failnode should fail (should return errs)"
3353
3354 test_57b() {
3355         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3356         writeconf_or_reformat
3357         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3358         start_mgsmds
3359         start_ost || error "OST registration from servicenode should not fail"
3360         reformat
3361 }
3362 run_test 57b "initial registration from servicenode should not fail"
3363
3364 count_osts() {
3365         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3366 }
3367
3368 test_58() { # bug 22658
3369         if [ $(facet_fstype mds) != ldiskfs ]; then
3370                 skip "Only applicable to ldiskfs-based MDTs"
3371                 return
3372         fi
3373         setup_noconfig
3374         mkdir -p $DIR/$tdir
3375         createmany -o $DIR/$tdir/$tfile-%d 100
3376         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3377 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3378         do_facet mds "lctl set_param fail_loc=0x601"
3379         unlinkmany $DIR/$tdir/$tfile-%d 100
3380         stop mds
3381         local MNTDIR=$(facet_mntpt mds)
3382         # remove all files from the OBJECTS dir
3383         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
3384         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
3385         do_facet mds "umount $MNTDIR"
3386         # restart MDS with missing llog files
3387         start_mds
3388         do_facet mds "lctl set_param fail_loc=0"
3389         reformat
3390 }
3391 run_test 58 "missing llog files must not prevent MDT from mounting"
3392
3393 test_59() {
3394         start_mgsmds >> /dev/null
3395         local C1=$(count_osts)
3396         if [ $C1 -eq 0 ]; then
3397                 start_ost >> /dev/null
3398                 C1=$(count_osts)
3399         fi
3400         stopall
3401         echo "original ost count: $C1 (expect > 0)"
3402         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3403         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3404         local C2=$(count_osts)
3405         echo "after mdt writeconf count: $C2 (expect 0)"
3406         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3407         echo "OST start without writeconf should fail:"
3408         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3409         echo "OST start with writeconf should succeed:"
3410         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3411         local C3=$(count_osts)
3412         echo "after ost writeconf count: $C3 (expect 1)"
3413         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3414         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3415         local C4=$(count_osts)
3416         echo "after ost2 writeconf count: $C4 (expect 2)"
3417         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3418         stop_ost2 >> /dev/null
3419         cleanup_nocli >> /dev/null
3420         #writeconf to remove all ost2 traces for subsequent tests
3421         writeconf_or_reformat
3422 }
3423 run_test 59 "writeconf mount option"
3424
3425 test_60() { # LU-471
3426         local num
3427
3428         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3429                 skip "Only applicable to ldiskfs-based MDTs"
3430                 return
3431         fi
3432
3433         for num in $(seq $MDSCOUNT); do
3434                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3435                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3436                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3437                         exit 10
3438         done
3439
3440         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3441         rc=${PIPESTATUS[0]}
3442         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3443
3444         # MDT default has dirdata feature
3445         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3446         # we disable uninit_bg feature
3447         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3448         # we set stride extended options
3449         echo $dump | grep stride > /dev/null || error "stride is not set"
3450         reformat
3451 }
3452 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3453
3454 test_61() { # LU-80
3455         local reformat=false
3456
3457         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3458                 { skip "Need MDS version at least 2.1.53"; return 0; }
3459
3460         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3461            ! large_xattr_enabled; then
3462                 reformat=true
3463                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3464
3465                 for num in $(seq $MDSCOUNT); do
3466                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3467                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3468                         error "add mds $num failed"
3469                 done
3470         fi
3471
3472     setup_noconfig || error "setting up the filesystem failed"
3473     client_up || error "starting client failed"
3474
3475     local file=$DIR/$tfile
3476     touch $file
3477
3478     local large_value="$(generate_string $(max_xattr_size))"
3479     local small_value="bar"
3480
3481     local name="trusted.big"
3482     log "save large xattr $name on $file"
3483     setfattr -n $name -v $large_value $file ||
3484         error "saving $name on $file failed"
3485
3486     local new_value=$(get_xattr_value $name $file)
3487     [[ "$new_value" != "$large_value" ]] &&
3488         error "$name different after saving"
3489
3490     log "shrink value of $name on $file"
3491     setfattr -n $name -v $small_value $file ||
3492         error "shrinking value of $name on $file failed"
3493
3494     new_value=$(get_xattr_value $name $file)
3495     [[ "$new_value" != "$small_value" ]] &&
3496         error "$name different after shrinking"
3497
3498     log "grow value of $name on $file"
3499     setfattr -n $name -v $large_value $file ||
3500         error "growing value of $name on $file failed"
3501
3502     new_value=$(get_xattr_value $name $file)
3503     [[ "$new_value" != "$large_value" ]] &&
3504         error "$name different after growing"
3505
3506     log "check value of $name on $file after remounting MDS"
3507     fail $SINGLEMDS
3508     new_value=$(get_xattr_value $name $file)
3509     [[ "$new_value" != "$large_value" ]] &&
3510         error "$name different after remounting MDS"
3511
3512     log "remove large xattr $name from $file"
3513     setfattr -x $name $file || error "removing $name from $file failed"
3514
3515     rm -f $file
3516     stopall
3517         if $reformat; then
3518                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3519                 reformat
3520         fi
3521 }
3522 run_test 61 "large xattr"
3523
3524 test_62() {
3525         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3526                 skip "Only applicable to ldiskfs-based MDTs"
3527                 return
3528         fi
3529
3530         # MRP-118
3531         local mdsdev=$(mdsdevname 1)
3532         local ostdev=$(ostdevname 1)
3533
3534         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3535                 { skip "Need MDS version at least 2.2.51"; return 0; }
3536
3537         echo "disable journal for mds"
3538         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3539         start_mds && error "MDT start should fail"
3540         echo "disable journal for ost"
3541         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3542         start_ost && error "OST start should fail"
3543         cleanup || return $?
3544         reformat_and_config
3545 }
3546 run_test 62 "start with disabled journal"
3547
3548 test_63() {
3549         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3550                 skip "Only applicable to ldiskfs-based MDTs"
3551                 return
3552         fi
3553
3554         local inode_slab=$(do_facet $SINGLEMDS \
3555                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3556         if [ -z "$inode_slab" ]; then
3557                 skip "ldiskfs module has not been loaded"
3558                 return
3559         fi
3560
3561         echo "$inode_slab ldisk inodes per page"
3562         [ "$inode_slab" -ge "3" ] ||
3563                 error "ldisk inode size is too big, $inode_slab objs per page"
3564         return
3565 }
3566 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3567
3568 test_64() {
3569         start_mds
3570         start_ost
3571         start_ost2 || error "Unable to start second ost"
3572         mount_client $MOUNT || error "Unable to mount client"
3573         stop_ost2 || error "Unable to stop second ost"
3574         echo "$LFS df"
3575         $LFS df --lazy || error "lfs df failed"
3576         cleanup || return $?
3577         #writeconf to remove all ost2 traces for subsequent tests
3578         writeconf_or_reformat
3579 }
3580 run_test 64 "check lfs df --lazy "
3581
3582 test_65() { # LU-2237
3583         # Currently, the test is only valid for ldiskfs backend
3584         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3585                 skip "non-ldiskfs backend" && return
3586
3587         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3588         local brpt=$(facet_mntpt brpt)
3589         local opts=""
3590
3591         if ! do_facet $SINGLEMDS "test -b $devname"; then
3592                 opts="-o loop"
3593         fi
3594
3595         stop_mds
3596         local obj=$(do_facet $SINGLEMDS \
3597                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3598                     grep Inode)
3599         if [ -z "$obj" ]; then
3600                 # The MDT may be just re-formatted, mount the MDT for the
3601                 # first time to guarantee the "last_rcvd" file is there.
3602                 start_mds || error "fail to mount the MDS for the first time"
3603                 stop_mds
3604         fi
3605
3606         # remove the "last_rcvd" file
3607         do_facet $SINGLEMDS "mkdir -p $brpt"
3608         do_facet $SINGLEMDS \
3609                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3610         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3611         do_facet $SINGLEMDS "umount $brpt"
3612
3613         # restart MDS, the "last_rcvd" file should be recreated.
3614         start_mds || error "fail to restart the MDS"
3615         stop_mds
3616         obj=$(do_facet $SINGLEMDS \
3617               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3618         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3619 }
3620 run_test 65 "re-create the lost last_rcvd file when server mount"
3621
3622 test_66() {
3623         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3624                 { skip "Need MGS version at least 2.3.59"; return 0; }
3625
3626         setup
3627         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
3628         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
3629
3630         echo "replace_nids should fail if MDS, OSTs and clients are UP"
3631         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3632                 error "replace_nids fail"
3633
3634         umount_client $MOUNT || error "unmounting client failed"
3635         echo "replace_nids should fail if MDS and OSTs are UP"
3636         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3637                 error "replace_nids fail"
3638
3639         stop_ost
3640         echo "replace_nids should fail if MDS is UP"
3641         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3642                 error "replace_nids fail"
3643
3644         stop_mds || error "stopping mds failed"
3645
3646         if combined_mgs_mds; then
3647                 start_mds "-o nosvc" ||
3648                         error "starting mds with nosvc option failed"
3649         fi
3650
3651         echo "command should accept two parameters"
3652         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
3653                 error "command should accept two params"
3654
3655         echo "correct device name should be passed"
3656         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
3657                 error "wrong devname"
3658
3659         echo "wrong nids list should not destroy the system"
3660         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
3661                 error "wrong parse"
3662
3663         echo "replace OST nid"
3664         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
3665                 error "replace nids failed"
3666
3667         echo "command should accept two parameters"
3668         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
3669                 error "command should accept two params"
3670
3671         echo "wrong nids list should not destroy the system"
3672         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
3673                 error "wrong parse"
3674
3675         echo "replace MDS nid"
3676         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
3677                 error "replace nids failed"
3678
3679         if ! combined_mgs_mds ; then
3680                 stop_mgs
3681         else
3682                 stop_mds
3683         fi
3684
3685         setup_noconfig
3686         check_mount || error "error after nid replace"
3687         cleanup
3688         reformat
3689 }
3690 run_test 66 "replace nids"
3691
3692 test_70a() {
3693         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3694         local MDTIDX=1
3695
3696         start_mdt 1 || error "MDT0 start fail"
3697
3698         start_ost || error "OST0 start fail"
3699
3700         start_mdt 2 || error "MDT1 start fail"
3701
3702         mount_client $MOUNT || error "mount client fails"
3703
3704         mkdir -p $DIR/$tdir || error "create dir fail"
3705
3706         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3707                                         error "create remote dir fail"
3708
3709         rm -rf $DIR/$tdir || error "delete dir fail"
3710         cleanup || return $?
3711 }
3712 run_test 70a "start MDT0, then OST, then MDT1"
3713
3714 test_70b() {
3715         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3716         local MDTIDX=1
3717
3718         start_ost || error "OST0 start fail"
3719
3720         start_mdt 1 || error "MDT0 start fail"
3721         start_mdt 2 || error "MDT1 start fail"
3722
3723         mount_client $MOUNT || error "mount client fails"
3724
3725         mkdir -p $DIR/$tdir || error "create dir fail"
3726
3727         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3728                                         error "create remote dir fail"
3729
3730         rm -rf $DIR/$tdir || error "delete dir fail"
3731
3732         cleanup || return $?
3733 }
3734 run_test 70b "start OST, MDT1, MDT0"
3735
3736 test_70c() {
3737         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3738         local MDTIDX=1
3739
3740         start_mdt 1 || error "MDT0 start fail"
3741         start_mdt 2 || error "MDT1 start fail"
3742         start_ost || error "OST0 start fail"
3743
3744         mount_client $MOUNT || error "mount client fails"
3745         stop_mdt 1 || error "MDT1 start fail"
3746
3747         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
3748         echo "deactivate $mdc_for_mdt1"
3749         $LCTL --device $mdc_for_mdt1 deactivate || return 1
3750
3751         mkdir -p $DIR/$tdir && error "mkdir succeed"
3752
3753         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
3754                                         error "create remote dir succeed"
3755
3756         cleanup || return $?
3757 }
3758 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
3759
3760 test_70d() {
3761         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3762         local MDTIDX=1
3763
3764         start_mdt 1 || error "MDT0 start fail"
3765         start_mdt 2 || error "MDT1 start fail"
3766         start_ost || error "OST0 start fail"
3767
3768         mount_client $MOUNT || error "mount client fails"
3769
3770         stop_mdt 2 || error "MDT1 start fail"
3771
3772         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
3773                              awk '{print $4}')
3774         echo "deactivate $mdc_for_mdt2"
3775         $LCTL --device $mdc_for_mdt2 deactivate ||
3776                         error "set $mdc_for_mdt2 deactivate failed"
3777
3778         mkdir -p $DIR/$tdir || error "mkdir fail"
3779         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
3780                         error "create remote dir succeed"
3781
3782         rm -rf $DIR/$tdir || error "delete dir fail"
3783
3784         cleanup || return $?
3785 }
3786 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
3787
3788 test_71a() {
3789         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3790         if combined_mgs_mds; then
3791                 skip "needs separate MGS/MDT" && return
3792         fi
3793         local MDTIDX=1
3794
3795         start_mdt 1 || error "MDT0 start fail"
3796         start_ost || error "OST0 start fail"
3797         start_mdt 2 || error "MDT1 start fail"
3798         start_ost2 || error "OST1 start fail"
3799
3800         mount_client $MOUNT || error "mount client fails"
3801
3802         mkdir -p $DIR/$tdir || error "mkdir fail"
3803         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3804                         error "create remote dir succeed"
3805
3806         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3807         rm -rf $DIR/$tdir || error "delete dir fail"
3808
3809         umount_client $MOUNT
3810         stop_mdt 1 || error "MDT0 stop fail"
3811         stop_mdt 2 || error "MDT1 stop fail"
3812         stop_ost || error "OST0 stop fail"
3813         stop_ost2 || error "OST1 stop fail"
3814 }
3815 run_test 71a "start MDT0 OST0, MDT1, OST1"
3816
3817 test_71b() {
3818         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3819         if combined_mgs_mds; then
3820                 skip "needs separate MGS/MDT" && return
3821         fi
3822         local MDTIDX=1
3823
3824         start_mdt 2 || error "MDT1 start fail"
3825         start_ost || error "OST0 start fail"
3826         start_mdt 1 || error "MDT0 start fail"
3827         start_ost2 || error "OST1 start fail"
3828
3829         mount_client $MOUNT || error "mount client fails"
3830
3831         mkdir -p $DIR/$tdir || error "mkdir fail"
3832         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3833                         error "create remote dir succeed"
3834
3835         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3836         rm -rf $DIR/$tdir || error "delete dir fail"
3837
3838         umount_client $MOUNT
3839         stop_mdt 1 || error "MDT0 stop fail"
3840         stop_mdt 2 || error "MDT1 stop fail"
3841         stop_ost || error "OST0 stop fail"
3842         stop_ost2 || error "OST1 stop fail"
3843 }
3844 run_test 71b "start MDT1, OST0, MDT0, OST1"
3845
3846 test_71c() {
3847         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3848         if combined_mgs_mds; then
3849                 skip "needs separate MGS/MDT" && return
3850         fi
3851         local MDTIDX=1
3852
3853         start_ost || error "OST0 start fail"
3854         start_ost2 || error "OST1 start fail"
3855         start_mdt 2 || error "MDT1 start fail"
3856         start_mdt 1 || error "MDT0 start fail"
3857
3858         mount_client $MOUNT || error "mount client fails"
3859
3860         mkdir -p $DIR/$tdir || error "mkdir fail"
3861         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3862                         error "create remote dir succeed"
3863
3864         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3865         rm -rf $DIR/$tdir || error "delete dir fail"
3866
3867         umount_client $MOUNT
3868         stop_mdt 1 || error "MDT0 stop fail"
3869         stop_mdt 2 || error "MDT1 stop fail"
3870         stop_ost || error "OST0 stop fail"
3871         stop_ost2 || error "OST1 stop fail"
3872
3873 }
3874 run_test 71c "start OST0, OST1, MDT1, MDT0"
3875
3876 test_71d() {
3877         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3878         if combined_mgs_mds; then
3879                 skip "needs separate MGS/MDT" && return
3880         fi
3881         local MDTIDX=1
3882
3883         start_ost || error "OST0 start fail"
3884         start_mdt 2 || error "MDT0 start fail"
3885         start_mdt 1 || error "MDT0 start fail"
3886         start_ost2 || error "OST1 start fail"
3887
3888         mount_client $MOUNT || error "mount client fails"
3889
3890         mkdir -p $DIR/$tdir || error "mkdir fail"
3891         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3892                         error "create remote dir succeed"
3893
3894         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3895         rm -rf $DIR/$tdir || error "delete dir fail"
3896
3897         umount_client $MOUNT
3898         stop_mdt 1 || error "MDT0 stop fail"
3899         stop_mdt 2 || error "MDT1 stop fail"
3900         stop_ost || error "OST0 stop fail"
3901         stop_ost2 || error "OST1 stop fail"
3902
3903 }
3904 run_test 71d "start OST0, MDT1, MDT0, OST1"
3905
3906 test_71e() {
3907         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3908         if combined_mgs_mds; then
3909                 skip "needs separate MGS/MDT" && return
3910         fi
3911         local MDTIDX=1
3912
3913         start_ost || error "OST0 start fail"
3914         start_mdt 2 || error "MDT1 start fail"
3915         start_ost2 || error "OST1 start fail"
3916         start_mdt 1 || error "MDT0 start fail"
3917
3918         mount_client $MOUNT || error "mount client fails"
3919
3920         mkdir -p $DIR/$tdir || error "mkdir fail"
3921         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3922                         error "create remote dir succeed"
3923
3924         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3925         rm -rf $DIR/$tdir || error "delete dir fail"
3926
3927         umount_client $MOUNT
3928         stop_mdt 1 || error "MDT0 stop fail"
3929         stop_mdt 2 || error "MDT1 stop fail"
3930         stop_ost || error "OST0 stop fail"
3931         stop_ost2 || error "OST1 stop fail"
3932
3933 }
3934 run_test 71e "start OST0, MDT1, OST1, MDT0"
3935
3936 test_72() { #LU-2634
3937         local mdsdev=$(mdsdevname 1)
3938         local ostdev=$(ostdevname 1)
3939         local cmd="$E2FSCK -fnvd $mdsdev"
3940         local fn=3
3941
3942         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3943                 skip "ldiskfs only test" && return
3944
3945         #tune MDT with "-O extents"
3946         add $SINGLEMDS \
3947                 $(mkfs_opts $SINGLEMDS ${mdsdev}) --reformat $mdsdev ||
3948                         error "add $SINGLEMDS failed"
3949         $TUNE2FS -O extents $mdsdev
3950         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
3951                 error "add $ostdev failed"
3952         start_mgsmds || error "start mds failed"
3953         start_ost || error "start ost failed"
3954         mount_client $MOUNT || error "mount client failed"
3955
3956         #create some short symlinks
3957         mkdir -p $DIR/$tdir
3958         createmany -o $DIR/$tdir/$tfile-%d $fn
3959         echo "create $fn short symlinks"
3960         for i in $(seq -w 1 $fn); do
3961                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
3962         done
3963         ls -al $MOUNT
3964
3965         #umount
3966         umount_client $MOUNT || error "umount client failed"
3967         stop_mds || error "stop mds failed"
3968         stop_ost || error "stop ost failed"
3969
3970         #run e2fsck
3971         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
3972 }
3973 run_test 72 "test fast symlink with extents flag enabled"
3974
3975 if ! combined_mgs_mds ; then
3976         stop mgs
3977 fi
3978
3979 cleanup_gss
3980
3981 complete $SECONDS
3982 exit_status