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