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