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