Whamcloud - gitweb
4f6dcda7a36dfdf95d4d86e63c5205347d18a293
[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
81         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 57b     50h"
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"
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 -t lustre $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_29() {
1068         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1069         setup > /dev/null 2>&1
1070         start_ost2
1071         sleep 10
1072
1073         local PARAM="$FSNAME-OST0001.osc.active"
1074         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1075         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1076
1077         ACTV=$(lctl get_param -n $PROC_ACT)
1078         DEAC=$((1 - $ACTV))
1079         set_conf_param_and_check client \
1080                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1081         # also check ost_server_uuid status
1082         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1083         if [ -z "$RESULT" ]; then
1084             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1085             return 3
1086         else
1087             echo "Live client success: got $RESULT"
1088         fi
1089
1090         # check MDTs too
1091         for num in $(seq $MDSCOUNT); do
1092                 local mdtosc=$(get_mdtosc_proc_path mds${num} $FSNAME-OST0001)
1093                 local MPROC="osc.$mdtosc.active"
1094                 local MAX=30
1095                 local WAIT=0
1096                 while [ 1 ]; do
1097                         sleep 5
1098                         RESULT=$(do_facet mds${num} " lctl get_param -n $MPROC")
1099                         [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1100                         if [ $RESULT -eq $DEAC ]; then
1101                                 echo -n "MDT deactivated also after"
1102                                 echo "$WAIT sec (got $RESULT)"
1103                                 break
1104                         fi
1105                         WAIT=$((WAIT + 5))
1106                         if [ $WAIT -eq $MAX ]; then
1107                                 echo -n "MDT not deactivated: wanted $DEAC"
1108                                 echo  "got $RESULT"
1109                                 return 4
1110                         fi
1111                         echo "Waiting $(($MAX - $WAIT))secs for MDT deactivated"
1112                 done
1113         done
1114         # test new client starts deactivated
1115         umount_client $MOUNT || return 200
1116         mount_client $MOUNT
1117         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1118         if [ -z "$RESULT" ]; then
1119             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1120             return 5
1121         else
1122             echo "New client success: got $RESULT"
1123         fi
1124
1125         # make sure it reactivates
1126         set_conf_param_and_check client \
1127                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1128
1129         umount_client $MOUNT
1130         stop_ost2
1131         cleanup_nocli
1132         #writeconf to remove all ost2 traces for subsequent tests
1133         writeconf_or_reformat
1134 }
1135 run_test 29 "permanently remove an OST"
1136
1137 test_30a() {
1138         setup
1139
1140         echo Big config llog
1141         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1142         ORIG=$($TEST)
1143         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1144         for i in ${LIST[@]}; do
1145                 set_conf_param_and_check client "$TEST" \
1146                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1147         done
1148         # make sure client restart still works
1149         umount_client $MOUNT
1150         mount_client $MOUNT || return 4
1151         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1152         pass
1153
1154         echo Erase parameter setting
1155         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1156         umount_client $MOUNT
1157         mount_client $MOUNT || return 6
1158         FINAL=$($TEST)
1159         echo "deleted (default) value=$FINAL, orig=$ORIG"
1160         # assumes this parameter started at the default value
1161         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1162
1163         cleanup
1164 }
1165 run_test 30a "Big config llog and conf_param deletion"
1166
1167 test_30b() {
1168         setup
1169
1170         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1171         # numerical part of it. Hopefully that's not already a failover address for
1172         # the server.
1173         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1174         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1175         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1176         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1177         echo "Using fake nid $NEW"
1178
1179         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1180         set_conf_param_and_check client "$TEST" \
1181                 "$FSNAME-OST0000.failover.node" $NEW ||
1182                 error "didn't add failover nid $NEW"
1183         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1184         echo $NIDS
1185         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1186         echo "should have 2 failover nids: $NIDCOUNT"
1187         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1188         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1189         umount_client $MOUNT
1190         mount_client $MOUNT || return 3
1191
1192         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1193         echo $NIDS
1194         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1195         echo "only 1 final nid should remain: $NIDCOUNT"
1196         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1197
1198         cleanup
1199 }
1200 run_test 30b "Remove failover nids"
1201
1202 test_31() { # bug 10734
1203         # ipaddr must not exist
1204         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1205         cleanup
1206 }
1207 run_test 31 "Connect to non-existent node (shouldn't crash)"
1208
1209
1210 T32_QID=60000
1211 T32_BLIMIT=20480 # Kbytes
1212 T32_ILIMIT=2
1213
1214 #
1215 # This is not really a test but a tool to create new disk
1216 # image tarballs for the upgrade tests.
1217 #
1218 # Disk image tarballs should be created on single-node
1219 # clusters by running this test with default configurations
1220 # plus a few mandatory environment settings that are verified
1221 # at the beginning of the test.
1222 #
1223 test_32newtarball() {
1224         local version
1225         local dst=.
1226         local src=/etc/rc.d
1227         local tmp=$TMP/t32_image_create
1228
1229         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1230                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1231                  -z "$OSTDEV1" ]; then
1232                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1233                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1234                           "OSTDEV1=<nonexistent_file>"
1235         fi
1236
1237         mkdir $tmp || {
1238                 echo "Found stale $tmp"
1239                 return 1
1240         }
1241
1242         mkdir $tmp/src
1243         tar cf - -C $src . | tar xf - -C $tmp/src
1244         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1245                 count=$(($T32_BLIMIT / 1024 / 2))
1246         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1247
1248         formatall
1249
1250         setupall
1251
1252         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1253                 $LFS quotacheck -ug /mnt/$FSNAME
1254         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1255                 /mnt/$FSNAME
1256
1257         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1258         stopall
1259
1260         mkdir $tmp/img
1261
1262         setupall
1263         pushd /mnt/$FSNAME
1264         ls -Rni --time-style=+%s >$tmp/img/list
1265         find . ! -name .lustre -type f -exec sha1sum {} \; |
1266                 sort -k 2 >$tmp/img/sha1sums
1267         popd
1268         $LCTL get_param -n version | head -n 1 |
1269                 sed -e 's/^lustre: *//' >$tmp/img/commit
1270
1271         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1272                 $LFS quotaon -ug /mnt/$FSNAME
1273         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1274         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1275                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1276                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1277                 | tr -d "*" > $tmp/img/bspace
1278         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1279                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1280                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1281                 | tr -d "*" > $tmp/img/ispace
1282
1283         stopall
1284
1285         pushd $tmp/src
1286         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1287         popd
1288
1289         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1290                 echo "Data verification failed"
1291         fi
1292
1293         uname -r >$tmp/img/kernel
1294         uname -m >$tmp/img/arch
1295
1296         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1297         mv $OSTDEV1 $tmp/img
1298
1299         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1300                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1301         dst=$(cd $dst; pwd)
1302         pushd $tmp/img
1303         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1304         popd
1305
1306         rm -r $tmp
1307 }
1308 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1309
1310 #
1311 # The list of applicable tarballs is returned via the caller's
1312 # variable "tarballs".
1313 #
1314 t32_check() {
1315         local node=$(facet_active_host $SINGLEMDS)
1316         local r="do_node $node"
1317
1318         if [ "$CLIENTONLY" ]; then
1319                 skip "Client-only testing"
1320                 exit 0
1321         fi
1322
1323         if ! $r which $TUNEFS; then
1324                 skip_env "tunefs.lustre required on $node"
1325                 exit 0
1326         fi
1327
1328         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1329
1330         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1331
1332         if [ -z "$tarballs" ]; then
1333                 skip "No applicable tarballs found"
1334                 exit 0
1335         fi
1336 }
1337
1338 t32_test_cleanup() {
1339         local tmp=$TMP/t32
1340         local rc=$?
1341
1342         if $shall_cleanup_lustre; then
1343                 umount $tmp/mnt/lustre || rc=$?
1344         fi
1345         if $shall_cleanup_mdt; then
1346                 $r umount -d $tmp/mnt/mdt || rc=$?
1347         fi
1348         if $shall_cleanup_mdt1; then
1349                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1350         fi
1351         if $shall_cleanup_ost; then
1352                 $r umount -d $tmp/mnt/ost || rc=$?
1353         fi
1354
1355         $r rm -rf $tmp
1356         rm -rf $tmp
1357         return $rc
1358 }
1359
1360 t32_bits_per_long() {
1361         #
1362         # Yes, this is not meant to be perfect.
1363         #
1364         case $1 in
1365                 ppc64|x86_64)
1366                         echo -n 64;;
1367                 i*86)
1368                         echo -n 32;;
1369         esac
1370 }
1371
1372 t32_reload_modules() {
1373         local node=$1
1374         local all_removed=false
1375         local i=0
1376
1377         while ((i < 20)); do
1378                 echo "Unloading modules on $node: Attempt $i"
1379                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1380                         all_removed=true
1381                 do_rpc_nodes $node check_mem_leak || return 1
1382                 if $all_removed; then
1383                         do_rpc_nodes $node load_modules
1384                         return 0
1385                 fi
1386                 sleep 5
1387                 i=$((i + 1))
1388         done
1389         echo "Unloading modules on $node: Given up"
1390         return 1
1391 }
1392
1393 t32_wait_til_devices_gone() {
1394         local node=$1
1395         local devices
1396         local i=0
1397
1398         echo wait for devices to go
1399         while ((i < 20)); do
1400                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1401                 ((devices == 0)) && return 0
1402                 sleep 5
1403                 i=$((i + 1))
1404         done
1405         echo "waiting for devices on $node: Given up"
1406         return 1
1407 }
1408
1409 t32_verify_quota() {
1410         local node=$1
1411         local fsname=$2
1412         local mnt=$3
1413         local fstype=$(facet_fstype $SINGLEMDS)
1414         local qval
1415         local cmd
1416
1417         $LFS quota -u $T32_QID -v $mnt
1418
1419         qval=$($LFS quota -v -u $T32_QID $mnt |
1420                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1421                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1422                 | tr -d "*")
1423         [ $qval -eq $img_bspace ] || {
1424                 echo "bspace, act:$qval, exp:$img_bspace"
1425                 return 1
1426         }
1427
1428         qval=$($LFS quota -v -u $T32_QID $mnt |
1429                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1430                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1431                 | tr -d "*")
1432         [ $qval -eq $img_ispace ] || {
1433                 echo "ispace, act:$qval, exp:$img_ispace"
1434                 return 1
1435         }
1436
1437         qval=$($LFS quota -v -u $T32_QID $mnt |
1438                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1439                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1440                 | tr -d "*")
1441         [ $qval -eq $T32_BLIMIT ] || {
1442                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1443                 return 1
1444         }
1445
1446         qval=$($LFS quota -v -u $T32_QID $mnt |
1447                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1448                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1449                 | tr -d "*")
1450         [ $qval -eq $T32_ILIMIT ] || {
1451                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1452                 return 1
1453         }
1454
1455         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1456         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1457         cmd=$cmd.quota_slave.enabled
1458         wait_update $node "$cmd" "ug" || {
1459                 echo "Enable mdt quota failed"
1460                 return 1
1461         }
1462
1463         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1464         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1465         cmd=$cmd.quota_slave.enabled
1466         wait_update $node "$cmd" "ug" || {
1467                 echo "Enable ost quota failed"
1468                 return 1
1469         }
1470
1471         chmod 0777 $mnt
1472         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1473                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1474                 echo "Write succeed, but expect -EDQUOT"
1475                 return 1
1476         }
1477         rm -f $mnt/t32_qf_new
1478
1479         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1480                 $T32_ILIMIT && {
1481                 echo "Create succeed, but expect -EDQUOT"
1482                 return 1
1483         }
1484         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1485
1486         return 0
1487 }
1488
1489 t32_test() {
1490         local tarball=$1
1491         local writeconf=$2
1492         local dne_upgrade=${dne_upgrade:-"no"}
1493         local ff_convert=${ff_convert:-"no"}
1494         local shall_cleanup_mdt=false
1495         local shall_cleanup_mdt1=false
1496         local shall_cleanup_ost=false
1497         local shall_cleanup_lustre=false
1498         local node=$(facet_active_host $SINGLEMDS)
1499         local r="do_node $node"
1500         local node2=$(facet_active_host mds2)
1501         local tmp=$TMP/t32
1502         local img_commit
1503         local img_kernel
1504         local img_arch
1505         local img_bspace
1506         local img_ispace
1507         local fsname=t32fs
1508         local nid=$($r $LCTL list_nids | head -1)
1509         local mopts
1510         local uuid
1511         local nrpcs_orig
1512         local nrpcs
1513         local list
1514         local fstype=$(facet_fstype $SINGLEMDS)
1515
1516         trap 'trap - RETURN; t32_test_cleanup' RETURN
1517
1518         mkdir -p $tmp/mnt/lustre
1519         $r mkdir -p $tmp/mnt/{mdt,ost}
1520         $r tar xjvf $tarball -S -C $tmp || {
1521                 error_noexit "Unpacking the disk image tarball"
1522                 return 1
1523         }
1524         img_commit=$($r cat $tmp/commit)
1525         img_kernel=$($r cat $tmp/kernel)
1526         img_arch=$($r cat $tmp/arch)
1527         img_bspace=$($r cat $tmp/bspace)
1528         img_ispace=$($r cat $tmp/ispace)
1529         echo "Upgrading from $(basename $tarball), created with:"
1530         echo "  Commit: $img_commit"
1531         echo "  Kernel: $img_kernel"
1532         echo "    Arch: $img_arch"
1533
1534         local version=$(version_code $img_commit)
1535         [[ $version -gt $(version_code 2.4.0) ]] && ff_convert="no"
1536
1537         $r $LCTL set_param debug="$PTLDEBUG"
1538
1539         $r $TUNEFS --dryrun $tmp/mdt || {
1540                 error_noexit "tunefs.lustre before mounting the MDT"
1541                 return 1
1542         }
1543         if [ "$writeconf" ]; then
1544                 mopts=loop,writeconf
1545                 if [ $fstype == "ldiskfs" ]; then
1546                         $r $TUNEFS --quota $tmp/mdt || {
1547                                 error_noexit "Enable mdt quota feature"
1548                                 return 1
1549                         }
1550                 fi
1551         else
1552                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1553                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1554                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1555                                 "(Need MGS version at least 2.3.59)"; return 0; }
1556
1557                         local osthost=$(facet_active_host ost1)
1558                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1559
1560                         $r mount -t lustre -o loop,nosvc $tmp/mdt $tmp/mnt/mdt
1561                         $r lctl replace_nids $fsname-OST0000 $ostnid
1562                         $r lctl replace_nids $fsname-MDT0000 $nid
1563                         $r umount $tmp/mnt/mdt
1564                 fi
1565
1566                 mopts=loop,exclude=$fsname-OST0000
1567         fi
1568
1569         t32_wait_til_devices_gone $node
1570
1571         $r mount -t lustre -o $mopts $tmp/mdt $tmp/mnt/mdt || {
1572                 error_noexit "Mounting the MDT"
1573                 return 1
1574         }
1575         shall_cleanup_mdt=true
1576
1577         if [ "$dne_upgrade" != "no" ]; then
1578                 local fs2mdsdev=$(mdsdevname 1_2)
1579                 local fs2mdsvdev=$(mdsvdevname 1_2)
1580
1581                 echo "mkfs new MDT on ${fs2mdsdev}...."
1582                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1583                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1584                 fi
1585
1586                 add fs2mds $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1587                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1588                         error_noexit "Mkfs new MDT failed"
1589                         return 1
1590                 }
1591
1592                 $r $TUNEFS --dryrun $fs2mdsdev || {
1593                         error_noexit "tunefs.lustre before mounting the MDT"
1594                         return 1
1595                 }
1596
1597                 echo "mount new MDT....$fs2mdsdev"
1598                 $r mkdir -p $tmp/mnt/mdt1
1599                 $r mount -t lustre -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1600                         error_noexit "mount mdt1 failed"
1601                         return 1
1602                 }
1603                 shall_cleanup_mdt1=true
1604         fi
1605
1606         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1607                 error_noexit "Getting MDT UUID"
1608                 return 1
1609         }
1610         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1611                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1612                 return 1
1613         fi
1614
1615         $r $TUNEFS --dryrun $tmp/ost || {
1616                 error_noexit "tunefs.lustre before mounting the OST"
1617                 return 1
1618         }
1619         if [ "$writeconf" ]; then
1620                 mopts=loop,mgsnode=$nid,$writeconf
1621                 if [ $fstype == "ldiskfs" ]; then
1622                         $r $TUNEFS --quota $tmp/ost || {
1623                                 error_noexit "Enable ost quota feature"
1624                                 return 1
1625                         }
1626                 fi
1627         else
1628                 mopts=loop,mgsnode=$nid
1629         fi
1630         $r mount -t lustre -o $mopts $tmp/ost $tmp/mnt/ost || {
1631                 error_noexit "Mounting the OST"
1632                 return 1
1633         }
1634         shall_cleanup_ost=true
1635
1636         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1637                 error_noexit "Getting OST UUID"
1638                 return 1
1639         }
1640         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1641                 error_noexit "Unexpected OST UUID: \"$uuid\""
1642                 return 1
1643         fi
1644
1645         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1646                 error_noexit "Setting \"max_dirty_mb\""
1647                 return 1
1648         }
1649         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1650                 error_noexit "Setting OST \"failover.node\""
1651                 return 1
1652         }
1653         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1654                 error_noexit "Setting \"max_rpcs_in_flight\""
1655                 return 1
1656         }
1657         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1658                 error_noexit "Setting MDT \"failover.node\""
1659                 return 1
1660         }
1661         $r $LCTL pool_new $fsname.interop || {
1662                 error_noexit "Setting \"interop\""
1663                 return 1
1664         }
1665         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1666                 error_noexit "Setting \"lov.stripesize\""
1667                 return 1
1668         }
1669
1670         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1671                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1672                         error_noexit "Start OI scrub on OST0"
1673                         return 1
1674                 }
1675
1676                 # The oi_scrub should be on ost1, but for test_32(),
1677                 # all on the SINGLEMDS.
1678                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1679                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1680                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1681                         error_noexit "Failed to get the expected 'completed'"
1682                         return 1
1683                 }
1684
1685                 local UPDATED=$($r $LCTL get_param -n \
1686                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1687                                 awk '/^updated/ { print $2 }')
1688                 [ $UPDATED -ge 1 ] || {
1689                         error_noexit "Only $UPDATED objects have been converted"
1690                         return 1
1691                 }
1692         fi
1693
1694         if [ "$dne_upgrade" != "no" ]; then
1695                 $r $LCTL conf_param \
1696                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1697                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1698                         return 1
1699                 }
1700                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1701                         error_noexit "Setting MDT1 \"failover.node\""
1702                         return 1
1703                 }
1704                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1705                         error_noexit "Setting MDT1 \"lov.stripesize\""
1706                         return 1
1707                 }
1708
1709         fi
1710
1711         if [ "$writeconf" ]; then
1712                 mount -t lustre $nid:/$fsname $tmp/mnt/lustre || {
1713                         error_noexit "Mounting the client"
1714                         return 1
1715                 }
1716                 shall_cleanup_lustre=true
1717                 $LCTL set_param debug="$PTLDEBUG"
1718
1719                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
1720                         error_noexit "verify quota failed"
1721                         return 1
1722                 }
1723
1724                 if [ "$dne_upgrade" != "no" ]; then
1725                         $LFS mkdir -i 1 $tmp/mnt/lustre/remote_dir || {
1726                                 error_noexit "set remote dir failed"
1727                                 return 1
1728                         }
1729
1730                         pushd $tmp/mnt/lustre
1731                         tar -cf - . --exclude=./remote_dir |
1732                                 tar -xvf - -C remote_dir 1>/dev/null || {
1733                                 error_noexit "cp to remote dir failed"
1734                                 return 1
1735                         }
1736                         popd
1737                 fi
1738
1739                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1740                         error_noexit "dd failed"
1741                         return 1
1742                 }
1743                 rm -rf $tmp/mnt/lustre/tmp_file || {
1744                         error_noexit "rm failed"
1745                         return 1
1746                 }
1747
1748                 if $r test -f $tmp/sha1sums; then
1749                         # LU-2393 - do both sorts on same node to ensure locale
1750                         # is identical
1751                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1752                         if [ "$dne_upgrade" != "no" ]; then
1753                                 pushd $tmp/mnt/lustre/remote_dir
1754                         else
1755                                 pushd $tmp/mnt/lustre
1756                         fi
1757
1758                         find ! -name .lustre -type f -exec sha1sum {} \; |
1759                                 sort -k 2 >$tmp/sha1sums || {
1760                                 error_noexit "sha1sum"
1761                                 return 1
1762                         }
1763                         popd
1764                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1765                                 error_noexit "sha1sum verification failed"
1766                                 return 1
1767                         fi
1768                 else
1769                         echo "sha1sum verification skipped"
1770                 fi
1771
1772                 if [ "$dne_upgrade" != "no" ]; then
1773                         rm -rf $tmp/mnt/lustre/remote_dir || {
1774                                 error_noexit "remove remote dir failed"
1775                                 return 1
1776                         }
1777                 fi
1778
1779                 if $r test -f $tmp/list; then
1780                         #
1781                         # There is not a Test Framework API to copy files to or
1782                         # from a remote node.
1783                         #
1784                         # LU-2393 - do both sorts on same node to ensure locale
1785                         # is identical
1786                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1787                         pushd $tmp/mnt/lustre
1788                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1789                                 error_noexit "ls"
1790                                 return 1
1791                         }
1792                         popd
1793                         #
1794                         # 32-bit and 64-bit clients use different algorithms to
1795                         # convert FIDs into inode numbers.  Hence, remove the inode
1796                         # numbers from the lists, if the original list was created
1797                         # on an architecture with different number of bits per
1798                         # "long".
1799                         #
1800                         if [ $(t32_bits_per_long $(uname -m)) != \
1801                                 $(t32_bits_per_long $img_arch) ]; then
1802                                 echo "Different number of bits per \"long\" from the disk image"
1803                                 for list in list.orig list; do
1804                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1805                                 done
1806                         fi
1807                         if ! diff -ub $tmp/list.orig $tmp/list; then
1808                                 error_noexit "list verification failed"
1809                                 return 1
1810                         fi
1811                 else
1812                         echo "list verification skipped"
1813                 fi
1814
1815                 #
1816                 # When adding new data verification tests, please check for
1817                 # the presence of the required reference files first, like
1818                 # the "sha1sums" and "list" tests above, to avoid the need to
1819                 # regenerate every image for each test addition.
1820                 #
1821
1822                 nrpcs_orig=$($LCTL get_param \
1823                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
1824                         error_noexit "Getting \"max_rpcs_in_flight\""
1825                         return 1
1826                 }
1827                 nrpcs=$((nrpcs_orig + 5))
1828                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1829                         error_noexit "Changing \"max_rpcs_in_flight\""
1830                         return 1
1831                 }
1832                 wait_update $HOSTNAME "$LCTL get_param \
1833                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
1834                         error_noexit "Verifying \"max_rpcs_in_flight\""
1835                         return 1
1836                 }
1837
1838                 umount $tmp/mnt/lustre || {
1839                         error_noexit "Unmounting the client"
1840                         return 1
1841                 }
1842                 shall_cleanup_lustre=false
1843         else
1844                 if [ "$dne_upgrade" != "no" ]; then
1845                         $r umount -d $tmp/mnt/mdt1 || {
1846                                 error_noexit "Unmounting the MDT2"
1847                                 return 1
1848                         }
1849                         shall_cleanup_mdt1=false
1850                 fi
1851
1852                 $r umount -d $tmp/mnt/mdt || {
1853                         error_noexit "Unmounting the MDT"
1854                         return 1
1855                 }
1856                 shall_cleanup_mdt=false
1857
1858                 $r umount -d $tmp/mnt/ost || {
1859                         error_noexit "Unmounting the OST"
1860                         return 1
1861                 }
1862                 shall_cleanup_ost=false
1863
1864                 t32_reload_modules $node || {
1865                         error_noexit "Reloading modules"
1866                         return 1
1867                 }
1868
1869                 # mount a second time to make sure we didnt leave upgrade flag on
1870                 $r $TUNEFS --dryrun $tmp/mdt || {
1871                         error_noexit "tunefs.lustre before remounting the MDT"
1872                         return 1
1873                 }
1874                 $r mount -t lustre -o loop,exclude=$fsname-OST0000 $tmp/mdt \
1875                                  $tmp/mnt/mdt || {
1876                         error_noexit "Remounting the MDT"
1877                         return 1
1878                 }
1879                 shall_cleanup_mdt=true
1880         fi
1881 }
1882
1883 test_32a() {
1884         local tarballs
1885         local tarball
1886         local rc=0
1887
1888         t32_check
1889         for tarball in $tarballs; do
1890                 t32_test $tarball || let "rc += $?"
1891         done
1892         return $rc
1893 }
1894 run_test 32a "Upgrade (not live)"
1895
1896 test_32b() {
1897         local tarballs
1898         local tarball
1899         local rc=0
1900
1901         t32_check
1902         for tarball in $tarballs; do
1903                 t32_test $tarball writeconf || let "rc += $?"
1904         done
1905         return $rc
1906 }
1907 run_test 32b "Upgrade with writeconf"
1908
1909 test_32c() {
1910         local tarballs
1911         local tarball
1912         local rc=0
1913
1914         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1915         t32_check
1916         for tarball in $tarballs; do
1917                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
1918         done
1919         return $rc
1920 }
1921 run_test 32c "dne upgrade test"
1922
1923 test_32d() {
1924         local tarballs
1925         local tarball
1926         local rc=0
1927
1928         t32_check
1929         for tarball in $tarballs; do
1930                 ff_convert=yes t32_test $tarball || rc=$?
1931         done
1932         return $rc
1933 }
1934 run_test 32d "convert ff test"
1935
1936 test_33a() { # bug 12333, was test_33
1937         local rc=0
1938         local FSNAME2=test-123
1939         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1940         local mkfsoptions
1941
1942         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1943
1944         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1945                 local dev=${SINGLEMDS}_dev
1946                 local MDSDEV=${!dev}
1947                 is_blkdev $SINGLEMDS $MDSDEV && \
1948                 skip_env "mixed loopback and real device not working" && return
1949         fi
1950
1951         local fs2mdsdev=$(mdsdevname 1_2)
1952         local fs2ostdev=$(ostdevname 1_2)
1953         local fs2mdsvdev=$(mdsvdevname 1_2)
1954         local fs2ostvdev=$(ostvdevname 1_2)
1955
1956         if [ $(facet_fstype mds1) == ldiskfs ]; then
1957                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
1958         fi
1959
1960         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
1961                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
1962         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
1963                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
1964                 $fs2ostvdev || exit 10
1965
1966         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1967         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1968         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1969         mkdir -p $MOUNT2
1970         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1971         echo "ok."
1972
1973         cp /etc/hosts $MOUNT2/ || rc=3
1974         $LFS getstripe $MOUNT2/hosts
1975
1976         umount -d $MOUNT2
1977         stop fs2ost -f
1978         stop fs2mds -f
1979         cleanup_nocli || rc=6
1980         return $rc
1981 }
1982 run_test 33a "Mount ost with a large index number"
1983
1984 test_33b() {    # was test_34
1985         setup
1986
1987         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1988         # Drop lock cancelation reply during umount
1989         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
1990         do_facet client lctl set_param fail_loc=0x80000304
1991         #lctl set_param debug=-1
1992         umount_client $MOUNT
1993         cleanup
1994 }
1995 run_test 33b "Drop cancel during umount"
1996
1997 test_34a() {
1998         setup
1999         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2000         manual_umount_client
2001         rc=$?
2002         do_facet client killall -USR1 multiop
2003         if [ $rc -eq 0 ]; then
2004                 error "umount not fail!"
2005         fi
2006         sleep 1
2007         cleanup
2008 }
2009 run_test 34a "umount with opened file should be fail"
2010
2011
2012 test_34b() {
2013         setup
2014         touch $DIR/$tfile || return 1
2015         stop_mds --force || return 2
2016
2017         manual_umount_client --force
2018         rc=$?
2019         if [ $rc -ne 0 ]; then
2020                 error "mtab after failed umount - rc $rc"
2021         fi
2022
2023         cleanup
2024         return 0
2025 }
2026 run_test 34b "force umount with failed mds should be normal"
2027
2028 test_34c() {
2029         setup
2030         touch $DIR/$tfile || return 1
2031         stop_ost --force || return 2
2032
2033         manual_umount_client --force
2034         rc=$?
2035         if [ $rc -ne 0 ]; then
2036                 error "mtab after failed umount - rc $rc"
2037         fi
2038
2039         cleanup
2040         return 0
2041 }
2042 run_test 34c "force umount with failed ost should be normal"
2043
2044 test_35a() { # bug 12459
2045         setup
2046
2047         DBG_SAVE="`lctl get_param -n debug`"
2048         lctl set_param debug="ha"
2049
2050         log "Set up a fake failnode for the MDS"
2051         FAKENID="127.0.0.2"
2052         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
2053                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2054         do_facet mgs "$LCTL conf_param \
2055                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 4
2056
2057         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2058         sleep 10
2059
2060         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2061         $LCTL clear
2062         log "$MSG"
2063         log "Stopping the MDT: $device"
2064         stop_mdt 1 || return 5
2065
2066         df $MOUNT > /dev/null 2>&1 &
2067         DFPID=$!
2068         log "Restarting the MDT: $device"
2069         start_mdt 1 || return 6
2070         log "Wait for df ($DFPID) ... "
2071         wait $DFPID
2072         log "done"
2073         lctl set_param debug="$DBG_SAVE"
2074
2075         # retrieve from the log the first server that the client tried to
2076         # contact after the connection loss
2077         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2078         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2079                        /import_select_connection.*$device-mdc.* using connection/ {
2080                                 if (start) {
2081                                         if (\\\$NF ~ /$FAKENID/)
2082                                                 print \\\$NF;
2083                                         else
2084                                                 print 0;
2085                                         exit;
2086                                 }
2087                        }" $TMP/lustre-log-$TESTNAME.log`
2088         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
2089         cleanup
2090         # remove nid settings
2091         writeconf_or_reformat
2092 }
2093 run_test 35a "Reconnect to the last active server first"
2094
2095 test_35b() { # bug 18674
2096         remote_mds || { skip "local MDS" && return 0; }
2097         setup
2098
2099         debugsave
2100         $LCTL set_param debug="ha"
2101         $LCTL clear
2102         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2103         log "$MSG"
2104
2105         log "Set up a fake failnode for the MDS"
2106         FAKENID="127.0.0.2"
2107         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2108                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2109         do_facet mgs "$LCTL conf_param \
2110                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 1
2111
2112         local at_max_saved=0
2113         # adaptive timeouts may prevent seeing the issue
2114         if at_is_enabled; then
2115                 at_max_saved=$(at_max_get mds)
2116                 at_max_set 0 mds client
2117         fi
2118
2119         mkdir -p $MOUNT/$tdir
2120
2121         log "Injecting EBUSY on MDS"
2122         # Setting OBD_FAIL_MDS_RESEND=0x136
2123         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
2124
2125         $LCTL set_param mdc.${FSNAME}*.stats=clear
2126
2127         log "Creating a test file and stat it"
2128         touch $MOUNT/$tdir/$tfile
2129         stat $MOUNT/$tdir/$tfile
2130
2131         log "Stop injecting EBUSY on MDS"
2132         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
2133         rm -f $MOUNT/$tdir/$tfile
2134
2135         log "done"
2136         # restore adaptive timeout
2137         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2138
2139         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2140
2141         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
2142
2143         # retrieve from the log if the client has ever tried to
2144         # contact the fake server after the loss of connection
2145         FAILCONN=`awk "BEGIN {ret = 0;}
2146                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2147                                 ret = 1;
2148                                 if (\\\$NF ~ /$FAKENID/) {
2149                                         ret = 2;
2150                                         exit;
2151                                 }
2152                        }
2153                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2154
2155         [ "$FAILCONN" == "0" ] && \
2156                 log "ERROR: The client reconnection has not been triggered" && \
2157                 return 4
2158         [ "$FAILCONN" == "2" ] && \
2159                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
2160                 return 5
2161
2162         # LU-290
2163         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2164         # Reconnects are supposed to be rate limited to one every 5s
2165         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
2166                 log "ERROR: Too many reconnects $CONNCNT" && \
2167                 return 6
2168
2169         cleanup
2170         # remove nid settings
2171         writeconf_or_reformat
2172 }
2173 run_test 35b "Continue reconnection retries, if the active server is busy"
2174
2175 test_36() { # 12743
2176         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
2177
2178         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
2179                 { skip "remote OST" && return 0; }
2180
2181         local rc=0
2182         local FSNAME2=test1234
2183         local fs3ost_HOST=$ost_HOST
2184         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2185
2186         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2187
2188         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2189                 is_blkdev $SINGLEMDS $MDSDEV && \
2190                 skip_env "mixed loopback and real device not working" && return
2191         fi
2192
2193         local fs2mdsdev=$(mdsdevname 1_2)
2194         local fs2ostdev=$(ostdevname 1_2)
2195         local fs3ostdev=$(ostdevname 2_2)
2196         local fs2mdsvdev=$(mdsvdevname 1_2)
2197         local fs2ostvdev=$(ostvdevname 1_2)
2198         local fs3ostvdev=$(ostvdevname 2_2)
2199
2200         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2201                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2202         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2203         #     different one than the default value here.
2204         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2205                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2206         add fs3ost $(mkfs_opts ost1 ${fs3ostdev}) --mgsnode=$MGSNID \
2207                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2208
2209         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2210         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2211         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2212         mkdir -p $MOUNT2
2213         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
2214
2215         sleep 5 # until 11778 fixed
2216
2217         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
2218
2219         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
2220         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
2221         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
2222         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
2223         DFTOTAL=`echo $STRING | cut -d, -f1`
2224         DFUSED=`echo $STRING  | cut -d, -f2`
2225         DFAVAIL=`echo $STRING | cut -d, -f3`
2226         DFFREE=$(($DFTOTAL - $DFUSED))
2227
2228         ALLOWANCE=$((64 * $OSTCOUNT))
2229
2230         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2231            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2232                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2233                 rc=1
2234         fi
2235         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2236            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2237                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2238                 rc=2
2239         fi
2240         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2241            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2242                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2243                 rc=3
2244        fi
2245
2246         umount -d $MOUNT2
2247         stop fs3ost -f || return 200
2248         stop fs2ost -f || return 201
2249         stop fs2mds -f || return 202
2250         unload_modules_conf || return 203
2251         return $rc
2252 }
2253 run_test 36 "df report consistency on OSTs with different block size"
2254
2255 test_37() {
2256         local mntpt=$(facet_mntpt $SINGLEMDS)
2257         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2258         local mdsdev_sym="$TMP/sym_mdt.img"
2259         local opts=$MDS_MOUNT_OPTS
2260         local rc=0
2261
2262         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2263                 skip "Currently only applicable to ldiskfs-based MDTs"
2264                 return
2265         fi
2266
2267         echo "MDS :     $mdsdev"
2268         echo "SYMLINK : $mdsdev_sym"
2269         do_facet $SINGLEMDS rm -f $mdsdev_sym
2270
2271         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2272
2273         echo "mount symlink device - $mdsdev_sym"
2274
2275         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2276                 opts=$(csa_add "$opts" -o loop)
2277         fi
2278         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2279                 $mdsdev_sym $mntpt 2>&1)
2280         rc=${PIPESTATUS[0]}
2281
2282         echo mount_op=$mount_op
2283
2284         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2285
2286         if $(echo $mount_op | grep -q "unable to set tunable"); then
2287                 error "set tunables failed for symlink device"
2288         fi
2289
2290         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2291
2292         return 0
2293 }
2294 run_test 37 "verify set tunables works for symlink device"
2295
2296 test_38() { # bug 14222
2297         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2298                 skip "Only applicable to ldiskfs-based MDTs"
2299                 return
2300         fi
2301
2302         setup
2303         # like runtests
2304         COUNT=10
2305         SRC="/etc /bin"
2306         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
2307         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2308         mkdir -p $DIR/$tdir
2309         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
2310                 error "copying $SRC to $DIR/$tdir"
2311         sync
2312         umount_client $MOUNT
2313         stop_mds
2314         log "rename lov_objid file on MDS"
2315         rm -f $TMP/lov_objid.orig
2316
2317         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2318         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
2319         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2320
2321         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
2322         # check create in mds_lov_connect
2323         start_mds
2324         mount_client $MOUNT
2325         for f in $FILES; do
2326                 [ $V ] && log "verifying $DIR/$tdir/$f"
2327                 diff -q $f $DIR/$tdir/$f || ERROR=y
2328         done
2329         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
2330         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
2331         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
2332
2333         # check it's updates in sync
2334         umount_client $MOUNT
2335         stop_mds
2336
2337         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
2338         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2339         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
2340
2341         start_mds
2342         mount_client $MOUNT
2343         for f in $FILES; do
2344                 [ $V ] && log "verifying $DIR/$tdir/$f"
2345                 diff -q $f $DIR/$tdir/$f || ERROR=y
2346         done
2347         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
2348         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
2349         umount_client $MOUNT
2350         stop_mds
2351         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
2352
2353         log "files compared the same"
2354         cleanup
2355 }
2356 run_test 38 "MDS recreates missing lov_objid file from OST data"
2357
2358 test_39() {
2359         PTLDEBUG=+malloc
2360         setup
2361         cleanup
2362         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2363                 error "memory leak detected" || true
2364 }
2365 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2366
2367 test_40() { # bug 15759
2368         start_ost
2369         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2370         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2371         start_mds
2372         cleanup
2373 }
2374 run_test 40 "race during service thread startup"
2375
2376 test_41a() { #bug 14134
2377         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2378            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2379                 skip "Loop devices does not work with nosvc option"
2380                 return
2381         fi
2382
2383         local rc
2384         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2385
2386         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2387         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2388         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2389         mkdir -p $MOUNT
2390         mount_client $MOUNT || return 1
2391         sleep 5
2392
2393         echo "blah blah" > $MOUNT/$tfile
2394         cat $MOUNT/$tfile
2395
2396         umount_client $MOUNT
2397         stop ost1 -f || return 201
2398         stop_mds -f || return 202
2399         stop_mds -f || return 203
2400         unload_modules_conf || return 204
2401         return $rc
2402 }
2403 run_test 41a "mount mds with --nosvc and --nomgs"
2404
2405 test_41b() {
2406         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2407            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2408                 skip "Loop devices does not work with nosvc option"
2409                 return
2410         fi
2411
2412         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2413
2414         stopall
2415         reformat
2416         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2417
2418         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2419         start_ost
2420         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2421         mkdir -p $MOUNT
2422         mount_client $MOUNT || return 1
2423         sleep 5
2424
2425         echo "blah blah" > $MOUNT/$tfile
2426         cat $MOUNT/$tfile || return 200
2427
2428         umount_client $MOUNT
2429         stop_ost || return 201
2430         stop_mds -f || return 202
2431         stop_mds -f || return 203
2432
2433 }
2434 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2435
2436 test_42() { #bug 14693
2437         setup
2438         check_mount || error "client was not mounted"
2439
2440         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2441         umount_client $MOUNT ||
2442                 error "unmounting client failed with invalid llite param"
2443         mount_client $MOUNT ||
2444                 error "mounting client failed with invalid llite param"
2445
2446         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2447         cleanup || error "stopping $FSNAME failed with invalid sys param"
2448         load_modules
2449         setup
2450         check_mount || "client was not mounted with invalid sys param"
2451         cleanup || error "stopping $FSNAME failed with invalid sys param"
2452         return 0
2453 }
2454 run_test 42 "allow client/server mount/unmount with invalid config param"
2455
2456 test_43() {
2457         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2458         setup
2459         chmod ugo+x $DIR || error "chmod 0 failed"
2460         set_conf_param_and_check mds                                    \
2461                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2462                 "$FSNAME.mdt.root_squash"                               \
2463                 "0:0"
2464         set_conf_param_and_check mds                                    \
2465                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2466                 "$FSNAME.mdt.nosquash_nids"                             \
2467                 "NONE"
2468
2469     #
2470     # create set of test files
2471     #
2472     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2473     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2474     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2475
2476     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2477     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2478
2479     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2480     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2481     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2482
2483         #
2484         # check root_squash:
2485         #   set root squash UID:GID to RUNAS_ID
2486         #   root should be able to access only files owned by RUNAS_ID
2487         #
2488         set_conf_param_and_check mds                                    \
2489                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2490                 "$FSNAME.mdt.root_squash"                               \
2491                 "$RUNAS_ID:$RUNAS_ID"
2492
2493     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2494     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2495         error "$ST: root read permission is denied"
2496     echo "$ST: root read permission is granted - ok"
2497
2498     echo "444" | \
2499     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2500         error "$ST: root write permission is denied"
2501     echo "$ST: root write permission is granted - ok"
2502
2503     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2504     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2505         error "$ST: root read permission is granted"
2506     echo "$ST: root read permission is denied - ok"
2507
2508     echo "555" | \
2509     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2510         error "$ST: root write permission is granted"
2511     echo "$ST: root write permission is denied - ok"
2512
2513     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2514     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2515         error "$ST: root unlink permission is granted"
2516     echo "$ST: root unlink permission is denied - ok"
2517
2518     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2519         error "$ST: root create permission is granted"
2520     echo "$ST: root create permission is denied - ok"
2521
2522         #
2523         # check nosquash_nids:
2524         #   put client's NID into nosquash_nids list,
2525         #   root should be able to access root file after that
2526         #
2527         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2528         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2529         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2530         set_conf_param_and_check mds                                    \
2531                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2532                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2533                 "$NIDLIST"
2534
2535     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2536     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2537         error "$ST: root read permission is denied"
2538     echo "$ST: root read permission is granted - ok"
2539
2540     echo "666" | \
2541     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2542         error "$ST: root write permission is denied"
2543     echo "$ST: root write permission is granted - ok"
2544
2545     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2546     rm $DIR/$tdir-rootdir/tfile-1 || \
2547         error "$ST: root unlink permission is denied"
2548     echo "$ST: root unlink permission is granted - ok"
2549     touch $DIR/$tdir-rootdir/tfile-2 || \
2550         error "$ST: root create permission is denied"
2551     echo "$ST: root create permission is granted - ok"
2552
2553     return 0
2554 }
2555 run_test 43 "check root_squash and nosquash_nids"
2556
2557 umount_client $MOUNT
2558 cleanup_nocli
2559
2560 test_44() { # 16317
2561         setup
2562         check_mount || return 2
2563         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2564         STATS_FOUND=no
2565         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2566         for VAL in $UUIDS; do
2567                 NID=$(echo $VAL | cut -d= -f1)
2568                 CLUUID=$(echo $VAL | cut -d= -f2)
2569                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2570         done
2571         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2572         cleanup
2573         return 0
2574 }
2575 run_test 44 "mounted client proc entry exists"
2576
2577 test_45() { #17310
2578         setup
2579         check_mount || return 2
2580         stop_mds
2581         df -h $MOUNT &
2582         log "sleep 60 sec"
2583         sleep 60
2584 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2585         do_facet client "lctl set_param fail_loc=0x50f"
2586         log "sleep 10 sec"
2587         sleep 10
2588         manual_umount_client --force || return 3
2589         do_facet client "lctl set_param fail_loc=0x0"
2590         start_mds
2591         mount_client $MOUNT || return 4
2592         cleanup
2593         return 0
2594 }
2595 run_test 45 "long unlink handling in ptlrpcd"
2596
2597 cleanup_46a() {
2598         trap 0
2599         local rc=0
2600         local count=$1
2601
2602         umount_client $MOUNT2 || rc=$?
2603         umount_client $MOUNT || rc=$?
2604         while [ $count -gt 0 ]; do
2605                 stop ost${count} -f || rc=$?
2606                 let count=count-1
2607         done    
2608         stop_mds || rc=$?
2609         cleanup_nocli || rc=$?
2610         #writeconf to remove all ost2 traces for subsequent tests
2611         writeconf_or_reformat
2612         return $rc
2613 }
2614
2615 test_46a() {
2616         echo "Testing with $OSTCOUNT OSTs"
2617         reformat_and_config
2618         start_mds || return 1
2619         #first client should see only one ost
2620         start_ost || return 2
2621         wait_osc_import_state mds ost FULL
2622         #start_client
2623         mount_client $MOUNT || return 3
2624         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2625
2626         local i
2627         for (( i=2; i<=$OSTCOUNT; i++ )); do
2628             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2629         done
2630
2631         # wait until osts in sync
2632         for (( i=2; i<=$OSTCOUNT; i++ )); do
2633             wait_osc_import_state mds ost$i FULL
2634             wait_osc_import_state client ost$i FULL
2635         done
2636
2637         #second client see all ost's
2638
2639         mount_client $MOUNT2 || return 8
2640         $LFS setstripe -c -1 $MOUNT2 || return 9
2641         $LFS getstripe $MOUNT2 || return 10
2642
2643         echo "ok" > $MOUNT2/widestripe
2644         $LFS getstripe $MOUNT2/widestripe || return 11
2645         # fill acl buffer for avoid expand lsm to them
2646         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2647             setfacl -m $acl $MOUNT2/widestripe
2648         done
2649
2650         # will be deadlock
2651         stat $MOUNT/widestripe || return 12
2652
2653         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2654         return 0
2655 }
2656 run_test 46a "handle ost additional - wide striped file"
2657
2658 test_47() { #17674
2659         reformat
2660         setup_noconfig
2661         check_mount || return 2
2662         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2663
2664         local lru_size=[]
2665         local count=0
2666         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2667             if echo $ns | grep "MDT[[:digit:]]*"; then
2668                 continue
2669             fi
2670             lrs=$(echo $ns | sed 's/.*lru_size=//')
2671             lru_size[count]=$lrs
2672             let count=count+1
2673         done
2674
2675         facet_failover ost1
2676         facet_failover $SINGLEMDS
2677         client_up || return 3
2678
2679         count=0
2680         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2681             if echo $ns | grep "MDT[[:digit:]]*"; then
2682                 continue
2683             fi
2684             lrs=$(echo $ns | sed 's/.*lru_size=//')
2685             if ! test "$lrs" -eq "${lru_size[count]}"; then
2686                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2687                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2688             fi
2689             let count=count+1
2690         done
2691
2692         cleanup
2693         return 0
2694 }
2695 run_test 47 "server restart does not make client loss lru_resize settings"
2696
2697 cleanup_48() {
2698         trap 0
2699
2700         # reformat after this test is needed - if test will failed
2701         # we will have unkillable file at FS
2702         reformat_and_config
2703 }
2704
2705 test_48() { # bug 17636
2706         reformat
2707         setup_noconfig
2708         check_mount || return 2
2709
2710         $LFS setstripe -c -1 $MOUNT || return 9
2711         $LFS getstripe $MOUNT || return 10
2712
2713         echo "ok" > $MOUNT/widestripe
2714         $LFS getstripe $MOUNT/widestripe || return 11
2715
2716         trap cleanup_48 EXIT ERR
2717
2718         # fill acl buffer for avoid expand lsm to them
2719         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2720             setfacl -m $acl $MOUNT/widestripe
2721         done
2722
2723         stat $MOUNT/widestripe || return 12
2724
2725         cleanup_48
2726         return 0
2727 }
2728 run_test 48 "too many acls on file"
2729
2730 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2731 test_49() { # bug 17710
2732         local timeout_orig=$TIMEOUT
2733         local ldlm_timeout_orig=$LDLM_TIMEOUT
2734         local LOCAL_TIMEOUT=20
2735
2736         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2737         TIMEOUT=$LOCAL_TIMEOUT
2738
2739         reformat
2740         setup_noconfig
2741         check_mount || return 1
2742
2743         echo "check ldlm_timout..."
2744         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2745         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2746         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2747
2748         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2749                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2750         fi
2751
2752         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2753                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2754         fi
2755
2756         umount_client $MOUNT
2757         stop_ost || return 2
2758         stop_mds || return 3
2759
2760         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2761
2762         reformat
2763         setup_noconfig
2764         check_mount || return 7
2765
2766         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2767         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2768         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2769
2770         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2771                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2772         fi
2773
2774         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2775                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2776         fi
2777
2778         cleanup || return $?
2779
2780         LDLM_TIMEOUT=$ldlm_timeout_orig
2781         TIMEOUT=$timeout_orig
2782 }
2783 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2784
2785 lazystatfs() {
2786         # Test both statfs and lfs df and fail if either one fails
2787         multiop_bg_pause $1 f_
2788         RC1=$?
2789         PID=$!
2790         killall -USR1 multiop
2791         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2792         wait $PID || { RC1=$?; log "multiop return error "; }
2793
2794         $LFS df &
2795         PID=$!
2796         sleep 5
2797         kill -s 0 $PID
2798         RC2=$?
2799         if [ $RC2 -eq 0 ]; then
2800             kill -s 9 $PID
2801             log "lazystatfs df failed"
2802         fi
2803
2804         RC=0
2805         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2806         return $RC
2807 }
2808
2809 test_50a() {
2810         setup
2811         lctl set_param llite.$FSNAME-*.lazystatfs=1
2812         touch $DIR/$tfile
2813
2814         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2815
2816         cleanup || return $?
2817 }
2818 run_test 50a "lazystatfs all servers available =========================="
2819
2820 test_50b() {
2821         setup
2822         lctl set_param llite.$FSNAME-*.lazystatfs=1
2823         touch $DIR/$tfile
2824
2825         # Wait for client to detect down OST
2826         stop_ost || error "Unable to stop OST1"
2827         wait_osc_import_state mds ost DISCONN
2828
2829         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2830
2831         umount_client $MOUNT || error "Unable to unmount client"
2832         stop_mds || error "Unable to stop MDS"
2833 }
2834 run_test 50b "lazystatfs all servers down =========================="
2835
2836 test_50c() {
2837         start_mds || error "Unable to start MDS"
2838         start_ost || error "Unable to start OST1"
2839         start_ost2 || error "Unable to start OST2"
2840         mount_client $MOUNT || error "Unable to mount client"
2841         lctl set_param llite.$FSNAME-*.lazystatfs=1
2842         touch $DIR/$tfile
2843
2844         # Wait for client to detect down OST
2845         stop_ost || error "Unable to stop OST1"
2846         wait_osc_import_state mds ost DISCONN
2847         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2848
2849         umount_client $MOUNT || error "Unable to unmount client"
2850         stop_ost2 || error "Unable to stop OST2"
2851         stop_mds || error "Unable to stop MDS"
2852         #writeconf to remove all ost2 traces for subsequent tests
2853         writeconf_or_reformat
2854 }
2855 run_test 50c "lazystatfs one server down =========================="
2856
2857 test_50d() {
2858         start_mds || error "Unable to start MDS"
2859         start_ost || error "Unable to start OST1"
2860         start_ost2 || error "Unable to start OST2"
2861         mount_client $MOUNT || error "Unable to mount client"
2862         lctl set_param llite.$FSNAME-*.lazystatfs=1
2863         touch $DIR/$tfile
2864
2865         # Issue the statfs during the window where the client still
2866         # belives the OST to be available but it is in fact down.
2867         # No failure just a statfs which hangs for a timeout interval.
2868         stop_ost || error "Unable to stop OST1"
2869         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2870
2871         umount_client $MOUNT || error "Unable to unmount client"
2872         stop_ost2 || error "Unable to stop OST2"
2873         stop_mds || error "Unable to stop MDS"
2874         #writeconf to remove all ost2 traces for subsequent tests
2875         writeconf_or_reformat
2876 }
2877 run_test 50d "lazystatfs client/server conn race =========================="
2878
2879 test_50e() {
2880         local RC1
2881         local pid
2882
2883         reformat_and_config
2884         start_mds || return 1
2885         #first client should see only one ost
2886         start_ost || return 2
2887         wait_osc_import_state mds ost FULL
2888
2889         # Wait for client to detect down OST
2890         stop_ost || error "Unable to stop OST1"
2891         wait_osc_import_state mds ost DISCONN
2892
2893         mount_client $MOUNT || error "Unable to mount client"
2894         lctl set_param llite.$FSNAME-*.lazystatfs=0
2895
2896         multiop_bg_pause $MOUNT _f
2897         RC1=$?
2898         pid=$!
2899
2900         if [ $RC1 -ne 0 ]; then
2901                 log "multiop failed $RC1"
2902         else
2903             kill -USR1 $pid
2904             sleep $(( $TIMEOUT+1 ))
2905             kill -0 $pid
2906             [ $? -ne 0 ] && error "process isn't sleep"
2907             start_ost || error "Unable to start OST1"
2908             wait $pid || error "statfs failed"
2909         fi
2910
2911         umount_client $MOUNT || error "Unable to unmount client"
2912         stop_ost || error "Unable to stop OST1"
2913         stop_mds || error "Unable to stop MDS"
2914 }
2915 run_test 50e "normal statfs all servers down =========================="
2916
2917 test_50f() {
2918         local RC1
2919         local pid
2920         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2921
2922         start_mds || error "Unable to start mds"
2923         #first client should see only one ost
2924         start_ost || error "Unable to start OST1"
2925         wait_osc_import_state mds ost FULL
2926
2927         start_ost2 || error "Unable to start OST2"
2928         wait_osc_import_state mds ost2 FULL
2929
2930         # Wait for client to detect down OST
2931         stop_ost2 || error "Unable to stop OST2"
2932
2933         wait_osc_import_state mds ost2 DISCONN
2934         mount_client $MOUNT || error "Unable to mount client"
2935         lctl set_param llite.$FSNAME-*.lazystatfs=0
2936
2937         multiop_bg_pause $MOUNT _f
2938         RC1=$?
2939         pid=$!
2940
2941         if [ $RC1 -ne 0 ]; then
2942                 log "lazystatfs multiop failed $RC1"
2943         else
2944             kill -USR1 $pid
2945             sleep $(( $TIMEOUT+1 ))
2946             kill -0 $pid
2947             [ $? -ne 0 ] && error "process isn't sleep"
2948             start_ost2 || error "Unable to start OST2"
2949             wait $pid || error "statfs failed"
2950             stop_ost2 || error "Unable to stop OST2"
2951         fi
2952
2953         umount_client $MOUNT || error "Unable to unmount client"
2954         stop_ost || error "Unable to stop OST1"
2955         stop_mds || error "Unable to stop MDS"
2956         #writeconf to remove all ost2 traces for subsequent tests
2957         writeconf_or_reformat
2958 }
2959 run_test 50f "normal statfs one server in down =========================="
2960
2961 test_50g() {
2962         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2963         setup
2964         start_ost2 || error "Unable to start OST2"
2965         wait_osc_import_state mds ost2 FULL
2966         wait_osc_import_state client ost2 FULL
2967
2968         local PARAM="${FSNAME}-OST0001.osc.active"
2969
2970         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2971         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2972
2973         umount_client $MOUNT || error "Unable to unmount client"
2974         mount_client $MOUNT || error "Unable to mount client"
2975         # This df should not cause a panic
2976         df -k $MOUNT
2977
2978         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2979         rm -f $DIR/$tfile
2980         umount_client $MOUNT || error "Unable to unmount client"
2981         stop_ost2 || error "Unable to stop OST2"
2982         stop_ost || error "Unable to stop OST1"
2983         stop_mds || error "Unable to stop MDS"
2984         #writeconf to remove all ost2 traces for subsequent tests
2985         writeconf_or_reformat
2986 }
2987 run_test 50g "deactivated OST should not cause panic====================="
2988
2989 # LU-642
2990 test_50h() {
2991         # prepare MDT/OST, make OSC inactive for OST1
2992         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2993         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
2994                 error "tunefs OST1 failed"
2995         start_mds  || error "Unable to start MDT"
2996         start_ost  || error "Unable to start OST1"
2997         start_ost2 || error "Unable to start OST2"
2998         mount_client $MOUNT || error "client start failed"
2999
3000         mkdir -p $DIR/$tdir
3001
3002         # activatate OSC for OST1
3003         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3004         set_conf_param_and_check client                                 \
3005                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3006                 error "Unable to activate OST1"
3007
3008         mkdir -p $DIR/$tdir/2
3009         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2
3010         sleep 1 && echo "create a file after OST1 is activated"
3011         # create some file
3012         createmany -o $DIR/$tdir/2/$tfile-%d 1
3013
3014         # check OSC import is working
3015         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3016                 error "some OSC imports are still not connected"
3017
3018         # cleanup
3019         umount_client $MOUNT || error "Unable to umount client"
3020         stop_ost2 || error "Unable to stop OST2"
3021         cleanup_nocli
3022 }
3023 run_test 50h "LU-642: activate deactivated OST  ==="
3024
3025 test_51() {
3026         local LOCAL_TIMEOUT=20
3027
3028         reformat
3029         setup_noconfig
3030         check_mount || return 1
3031
3032         mkdir $MOUNT/d1
3033         $LFS setstripe -c -1 $MOUNT/d1
3034         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3035         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
3036         touch $MOUNT/d1/f1 &
3037         local pid=$!
3038         sleep 2
3039         start_ost2 || return 2
3040         wait $pid
3041         stop_ost2 || return 3
3042         cleanup
3043         #writeconf to remove all ost2 traces for subsequent tests
3044         writeconf_or_reformat
3045 }
3046 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3047
3048 copy_files_xattrs()
3049 {
3050         local node=$1
3051         local dest=$2
3052         local xattrs=$3
3053         shift 3
3054
3055         do_node $node mkdir -p $dest
3056         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3057
3058         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3059                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3060         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3061
3062         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3063         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3064 }
3065
3066 diff_files_xattrs()
3067 {
3068         local node=$1
3069         local backup=$2
3070         local xattrs=$3
3071         shift 3
3072
3073         local backup2=${TMP}/backup2
3074
3075         do_node $node mkdir -p $backup2
3076         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3077
3078         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3079                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3080         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3081
3082         do_node $node "diff -rq $backup $backup2"
3083         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3084
3085         local xattrs2=${TMP}/xattrs2
3086         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3087         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3088
3089         do_node $node "diff $xattrs $xattrs2"
3090         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3091
3092         do_node $node "rm -rf $backup2 $xattrs2"
3093         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3094 }
3095
3096 test_52() {
3097         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3098                 skip "Only applicable to ldiskfs-based MDTs"
3099                 return
3100         fi
3101
3102         start_mds
3103         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
3104         start_ost
3105         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
3106         mount_client $MOUNT
3107         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
3108
3109         local nrfiles=8
3110         local ost1mnt=$(facet_mntpt ost1)
3111         local ost1node=$(facet_active_host ost1)
3112         local ost1tmp=$TMP/conf52
3113         local loop
3114
3115         mkdir -p $DIR/$tdir
3116         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
3117         touch $TMP/modified_first
3118         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
3119         local mtime=$(stat -c %Y $TMP/modified_first)
3120         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
3121
3122         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
3123         sleep 1
3124
3125         $LFS setstripe -c -1 -S 1M $DIR/$tdir
3126         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
3127
3128         for (( i=0; i < nrfiles; i++ )); do
3129                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
3130                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
3131                 echo -n .
3132         done
3133         echo
3134
3135         # backup files
3136         echo backup files to $TMP/files
3137         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3138         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3139         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
3140
3141         umount_client $MOUNT
3142         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
3143         stop_ost
3144         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
3145
3146         echo mount ost1 as ldiskfs
3147         do_node $ost1node mkdir -p $ost1mnt
3148         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
3149         if ! do_node $ost1node test -b $ost1_dev; then
3150                 loop="-o loop"
3151         fi
3152         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3153                 $ost1mnt
3154         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
3155
3156         # backup objects
3157         echo backup objects to $ost1tmp/objects
3158         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3159                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3160         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3161                         $objects
3162         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
3163
3164         # move objects to lost+found
3165         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3166         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3167
3168         # recover objects
3169         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
3170         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3171
3172         # compare restored objects against saved ones
3173         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3174         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
3175
3176         do_node $ost1node "umount $ost1mnt"
3177         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
3178
3179         start_ost
3180         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
3181         mount_client $MOUNT
3182         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
3183
3184         # compare files
3185         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3186         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
3187
3188         rm -rf $TMP/files $TMP/file_xattrs
3189         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
3190         do_node $ost1node "rm -rf $ost1tmp"
3191         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
3192         cleanup
3193 }
3194 run_test 52 "check recovering objects from lost+found"
3195
3196 # Checks threads_min/max/started for some service
3197 #
3198 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3199 # parameter pattern prefix like 'ost.*.ost'.
3200 thread_sanity() {
3201         local modname=$1
3202         local facet=$2
3203         local parampat=$3
3204         local opts=$4
3205         local basethr=$5
3206         local tmin
3207         local tmin2
3208         local tmax
3209         local tmax2
3210         local tstarted
3211         local paramp
3212         local msg="Insane $modname thread counts"
3213         local ncpts=$(check_cpt_number $facet)
3214         local nthrs
3215         shift 4
3216
3217         check_mount || return 41
3218
3219         # We need to expand $parampat, but it may match multiple parameters, so
3220         # we'll pick the first one
3221         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3222                 error "Couldn't expand ${parampat}.threads_min parameter name"
3223                 return 22
3224         fi
3225
3226         # Remove the .threads_min part
3227         paramp=${paramp%.threads_min}
3228
3229         # Check for sanity in defaults
3230         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3231         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3232         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
3233         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
3234         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3235         nthrs=$(expr $tmax - $tmin)
3236         if [ $nthrs -lt $ncpts ]; then
3237                 nthrs=0
3238         else
3239                 nthrs=$ncpts
3240         fi
3241
3242         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3243                 skip_env "module parameter forced $facet thread count" &&
3244                 tmin=3 && tmax=$((3 * tmax))
3245
3246         # Check that we can change min/max
3247         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
3248         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
3249         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3250         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3251         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
3252
3253         # Check that we can set min/max to the same value
3254         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3255         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
3256         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3257         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3258         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3259
3260         # Check that we can't set max < min
3261         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
3262         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3263         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3264         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3265
3266         # We need to ensure that we get the module options desired; to do this
3267         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3268         LOAD_MODULES_REMOTE=true
3269         cleanup
3270         local oldvalue
3271         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3272         setmodopts -a $modname "$newvalue" oldvalue
3273
3274         load_modules
3275         setup
3276         check_mount || return 41
3277
3278         # Restore previous setting of MODOPTS_*
3279         setmodopts $modname "$oldvalue"
3280
3281         # Check that $opts took
3282         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
3283         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
3284         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
3285         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3286         cleanup
3287
3288         load_modules
3289         setup
3290 }
3291
3292 test_53a() {
3293         setup
3294         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3295         cleanup
3296 }
3297 run_test 53a "check OSS thread count params"
3298
3299 test_53b() {
3300         setup
3301         local mds=$(do_facet $SINGLEMDS "lctl get_param -N mds.*.*.threads_max \
3302                     2>/dev/null")
3303         if [ -z "$mds" ]; then
3304                 #running this on an old MDT
3305                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3306         else
3307                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3308         fi
3309         cleanup
3310 }
3311 run_test 53b "check MDS thread count params"
3312
3313 test_54a() {
3314         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3315                 skip "Only applicable to ldiskfs-based MDTs"
3316                 return
3317         fi
3318
3319     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
3320     [ $? -eq 0 ] || error "llverdev failed!"
3321     reformat_and_config
3322 }
3323 run_test 54a "test llverdev and partial verify of device"
3324
3325 test_54b() {
3326         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3327                 skip "Only applicable to ldiskfs-based MDTs"
3328                 return
3329         fi
3330
3331     setup
3332     run_llverfs $MOUNT -p
3333     [ $? -eq 0 ] || error "llverfs failed!"
3334     cleanup
3335 }
3336 run_test 54b "test llverfs and partial verify of filesystem"
3337
3338 lov_objid_size()
3339 {
3340         local max_ost_index=$1
3341         echo -n $(((max_ost_index + 1) * 8))
3342 }
3343
3344 test_55() {
3345         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3346                 skip "Only applicable to ldiskfs-based MDTs"
3347                 return
3348         fi
3349
3350         local mdsdev=$(mdsdevname 1)
3351         local mdsvdev=$(mdsvdevname 1)
3352
3353         for i in 1023 2048
3354         do
3355                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3356                         $mdsvdev || exit 10
3357                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3358                         --reformat $(ostdevname 1) $(ostvdevname 1)
3359                 setup_noconfig
3360                 stopall
3361                 setup_noconfig
3362                 sync
3363
3364                 echo checking size of lov_objid for ost index $i
3365                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3366                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3367                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3368                 else
3369                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3370                 fi
3371                 stopall
3372         done
3373
3374         reformat
3375 }
3376 run_test 55 "check lov_objid size"
3377
3378 test_56() {
3379         local mds_journal_size_orig=$MDSJOURNALSIZE
3380
3381         MDSJOURNALSIZE=16
3382
3383         for num in $(seq 1 $MDSCOUNT); do
3384                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3385                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3386         done
3387         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=1000 --reformat \
3388                 $(ostdevname 1) $(ostvdevname 1)
3389         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=10000 --reformat \
3390                 $(ostdevname 2) $(ostvdevname 2)
3391
3392         start_mgsmds
3393         start_ost
3394         start_ost2 || error "Unable to start second ost"
3395         mount_client $MOUNT || error "Unable to mount client"
3396         echo ok
3397         $LFS osts
3398         stopall
3399         MDSJOURNALSIZE=$mds_journal_size_orig
3400         reformat
3401 }
3402 run_test 56 "check big indexes"
3403
3404 test_57a() { # bug 22656
3405         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3406         writeconf_or_reformat
3407         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3408         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3409         start_mgsmds
3410         start_ost && error "OST registration from failnode should fail"
3411         reformat
3412 }
3413 run_test 57a "initial registration from failnode should fail (should return errs)"
3414
3415 test_57b() {
3416         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3417         writeconf_or_reformat
3418         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3419         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3420         start_mgsmds
3421         start_ost || error "OST registration from servicenode should not fail"
3422         reformat
3423 }
3424 run_test 57b "initial registration from servicenode should not fail"
3425
3426 count_osts() {
3427         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3428 }
3429
3430 test_58() { # bug 22658
3431         if [ $(facet_fstype mds) != ldiskfs ]; then
3432                 skip "Only applicable to ldiskfs-based MDTs"
3433                 return
3434         fi
3435         setup_noconfig
3436         mkdir -p $DIR/$tdir
3437         createmany -o $DIR/$tdir/$tfile-%d 100
3438         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3439 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3440         do_facet $SINGLEMDS "lctl set_param fail_loc=0x601"
3441         unlinkmany $DIR/$tdir/$tfile-%d 100
3442         stop_mds
3443
3444         local MNTDIR=$(facet_mntpt $SINGLEMDS)
3445         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3446         local opts=""
3447         if ! do_facet $SINGLEMDS "test -b $devname"; then
3448                 opts="-o loop"
3449         fi
3450
3451         # remove all files from the OBJECTS dir
3452         do_facet $SINGLEMDS "mount -t ldiskfs $opts $devname $MNTDIR"
3453         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
3454         do_facet $SINGLEMDS "umount $MNTDIR"
3455         # restart MDS with missing llog files
3456         start_mds
3457         do_facet mds "lctl set_param fail_loc=0"
3458         reformat
3459 }
3460 run_test 58 "missing llog files must not prevent MDT from mounting"
3461
3462 test_59() {
3463         start_mgsmds >> /dev/null
3464         local C1=$(count_osts)
3465         if [ $C1 -eq 0 ]; then
3466                 start_ost >> /dev/null
3467                 C1=$(count_osts)
3468         fi
3469         stopall
3470         echo "original ost count: $C1 (expect > 0)"
3471         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3472         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3473         local C2=$(count_osts)
3474         echo "after mdt writeconf count: $C2 (expect 0)"
3475         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3476         echo "OST start without writeconf should fail:"
3477         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3478         echo "OST start with writeconf should succeed:"
3479         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3480         local C3=$(count_osts)
3481         echo "after ost writeconf count: $C3 (expect 1)"
3482         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3483         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3484         local C4=$(count_osts)
3485         echo "after ost2 writeconf count: $C4 (expect 2)"
3486         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3487         stop_ost2 >> /dev/null
3488         cleanup_nocli >> /dev/null
3489         #writeconf to remove all ost2 traces for subsequent tests
3490         writeconf_or_reformat
3491 }
3492 run_test 59 "writeconf mount option"
3493
3494 test_60() { # LU-471
3495         local num
3496
3497         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3498                 skip "Only applicable to ldiskfs-based MDTs"
3499                 return
3500         fi
3501
3502         for num in $(seq $MDSCOUNT); do
3503                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3504                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3505                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3506                         exit 10
3507         done
3508
3509         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3510         rc=${PIPESTATUS[0]}
3511         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3512
3513         # MDT default has dirdata feature
3514         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3515         # we disable uninit_bg feature
3516         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3517         # we set stride extended options
3518         echo $dump | grep stride > /dev/null || error "stride is not set"
3519         reformat
3520 }
3521 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3522
3523 test_61() { # LU-80
3524         local reformat=false
3525
3526         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3527                 { skip "Need MDS version at least 2.1.53"; return 0; }
3528
3529         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3530            ! large_xattr_enabled; then
3531                 reformat=true
3532                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3533
3534                 for num in $(seq $MDSCOUNT); do
3535                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3536                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3537                         error "add mds $num failed"
3538                 done
3539         fi
3540
3541     setup_noconfig || error "setting up the filesystem failed"
3542     client_up || error "starting client failed"
3543
3544     local file=$DIR/$tfile
3545     touch $file
3546
3547     local large_value="$(generate_string $(max_xattr_size))"
3548     local small_value="bar"
3549
3550     local name="trusted.big"
3551     log "save large xattr $name on $file"
3552     setfattr -n $name -v $large_value $file ||
3553         error "saving $name on $file failed"
3554
3555     local new_value=$(get_xattr_value $name $file)
3556     [[ "$new_value" != "$large_value" ]] &&
3557         error "$name different after saving"
3558
3559     log "shrink value of $name on $file"
3560     setfattr -n $name -v $small_value $file ||
3561         error "shrinking value of $name on $file failed"
3562
3563     new_value=$(get_xattr_value $name $file)
3564     [[ "$new_value" != "$small_value" ]] &&
3565         error "$name different after shrinking"
3566
3567     log "grow value of $name on $file"
3568     setfattr -n $name -v $large_value $file ||
3569         error "growing value of $name on $file failed"
3570
3571     new_value=$(get_xattr_value $name $file)
3572     [[ "$new_value" != "$large_value" ]] &&
3573         error "$name different after growing"
3574
3575     log "check value of $name on $file after remounting MDS"
3576     fail $SINGLEMDS
3577     new_value=$(get_xattr_value $name $file)
3578     [[ "$new_value" != "$large_value" ]] &&
3579         error "$name different after remounting MDS"
3580
3581     log "remove large xattr $name from $file"
3582     setfattr -x $name $file || error "removing $name from $file failed"
3583
3584     rm -f $file
3585     stopall
3586         if $reformat; then
3587                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3588                 reformat
3589         fi
3590 }
3591 run_test 61 "large xattr"
3592
3593 test_62() {
3594         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3595                 skip "Only applicable to ldiskfs-based MDTs"
3596                 return
3597         fi
3598
3599         # MRP-118
3600         local mdsdev=$(mdsdevname 1)
3601         local ostdev=$(ostdevname 1)
3602
3603         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3604                 { skip "Need MDS version at least 2.2.51"; return 0; }
3605
3606         echo "disable journal for mds"
3607         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3608         start_mds && error "MDT start should fail"
3609         echo "disable journal for ost"
3610         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3611         start_ost && error "OST start should fail"
3612         cleanup || return $?
3613         reformat_and_config
3614 }
3615 run_test 62 "start with disabled journal"
3616
3617 test_63() {
3618         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3619                 skip "Only applicable to ldiskfs-based MDTs"
3620                 return
3621         fi
3622
3623         local inode_slab=$(do_facet $SINGLEMDS \
3624                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3625         if [ -z "$inode_slab" ]; then
3626                 skip "ldiskfs module has not been loaded"
3627                 return
3628         fi
3629
3630         echo "$inode_slab ldisk inodes per page"
3631         [ "$inode_slab" -ge "3" ] ||
3632                 error "ldisk inode size is too big, $inode_slab objs per page"
3633         return
3634 }
3635 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3636
3637 test_64() {
3638         start_mds
3639         start_ost
3640         start_ost2 || error "Unable to start second ost"
3641         mount_client $MOUNT || error "Unable to mount client"
3642         stop_ost2 || error "Unable to stop second ost"
3643         echo "$LFS df"
3644         $LFS df --lazy || error "lfs df failed"
3645         cleanup || return $?
3646         #writeconf to remove all ost2 traces for subsequent tests
3647         writeconf_or_reformat
3648 }
3649 run_test 64 "check lfs df --lazy "
3650
3651 test_65() { # LU-2237
3652         # Currently, the test is only valid for ldiskfs backend
3653         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3654                 skip "non-ldiskfs backend" && return
3655
3656         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3657         local brpt=$(facet_mntpt brpt)
3658         local opts=""
3659
3660         if ! do_facet $SINGLEMDS "test -b $devname"; then
3661                 opts="-o loop"
3662         fi
3663
3664         stop_mds
3665         local obj=$(do_facet $SINGLEMDS \
3666                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3667                     grep Inode)
3668         if [ -z "$obj" ]; then
3669                 # The MDT may be just re-formatted, mount the MDT for the
3670                 # first time to guarantee the "last_rcvd" file is there.
3671                 start_mds || error "fail to mount the MDS for the first time"
3672                 stop_mds
3673         fi
3674
3675         # remove the "last_rcvd" file
3676         do_facet $SINGLEMDS "mkdir -p $brpt"
3677         do_facet $SINGLEMDS \
3678                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3679         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3680         do_facet $SINGLEMDS "umount $brpt"
3681
3682         # restart MDS, the "last_rcvd" file should be recreated.
3683         start_mds || error "fail to restart the MDS"
3684         stop_mds
3685         obj=$(do_facet $SINGLEMDS \
3686               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3687         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3688 }
3689 run_test 65 "re-create the lost last_rcvd file when server mount"
3690
3691 test_66() {
3692         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3693                 { skip "Need MGS version at least 2.3.59"; return 0; }
3694
3695         setup
3696         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
3697         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
3698
3699         echo "replace_nids should fail if MDS, OSTs and clients are UP"
3700         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3701                 error "replace_nids fail"
3702
3703         umount_client $MOUNT || error "unmounting client failed"
3704         echo "replace_nids should fail if MDS and OSTs are UP"
3705         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3706                 error "replace_nids fail"
3707
3708         stop_ost
3709         echo "replace_nids should fail if MDS is UP"
3710         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3711                 error "replace_nids fail"
3712
3713         stop_mds || error "stopping mds failed"
3714
3715         if combined_mgs_mds; then
3716                 start_mdt 1 "-o nosvc" ||
3717                         error "starting mds with nosvc option failed"
3718         fi
3719
3720         echo "command should accept two parameters"
3721         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
3722                 error "command should accept two params"
3723
3724         echo "correct device name should be passed"
3725         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
3726                 error "wrong devname"
3727
3728         echo "wrong nids list should not destroy the system"
3729         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
3730                 error "wrong parse"
3731
3732         echo "replace OST nid"
3733         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
3734                 error "replace nids failed"
3735
3736         echo "command should accept two parameters"
3737         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
3738                 error "command should accept two params"
3739
3740         echo "wrong nids list should not destroy the system"
3741         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
3742                 error "wrong parse"
3743
3744         echo "replace MDS nid"
3745         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
3746                 error "replace nids failed"
3747
3748         if ! combined_mgs_mds ; then
3749                 stop_mgs
3750         else
3751                 stop_mds
3752         fi
3753
3754         setup_noconfig
3755         check_mount || error "error after nid replace"
3756         cleanup || error "cleanup failed"
3757         reformat
3758 }
3759 run_test 66 "replace nids"
3760
3761 test_67() { #LU-2950
3762         local legacy="$TMP/legacy_lnet_config"
3763         local new="$TMP/new_routes_test"
3764         local out="$TMP/config_out_file"
3765         local verify="$TMP/conv_verify"
3766         local verify_conf="$TMP/conf_verify"
3767
3768         # Create the legacy file that will be run through the
3769         # lustre_routes_conversion script
3770         cat <<- LEGACY_LNET_CONFIG > $legacy
3771                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
3772                 tcp2 54 10.1.3.2@tcp;
3773                 tcp3 10.3.4.3@tcp:3;
3774                 tcp4 10.3.3.4@tcp;
3775         LEGACY_LNET_CONFIG
3776
3777         # Create the verification file to verify the output of
3778         # lustre_routes_conversion script against.
3779         cat <<- VERIFY_LNET_CONFIG > $verify
3780                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
3781                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
3782                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
3783                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
3784                 tcp4: { gateway: 10.3.3.4@tcp }
3785         VERIFY_LNET_CONFIG
3786
3787         # Create the verification file to verify the output of
3788         # lustre_routes_config script against
3789         cat <<- VERIFY_LNET_CONFIG > $verify_conf
3790                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
3791                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
3792                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
3793                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
3794                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
3795         VERIFY_LNET_CONFIG
3796
3797         lustre_routes_conversion $legacy $new > /dev/null
3798         if [ -f $new ]; then
3799                 # verify the conversion output
3800                 cmp -s $new $verify > /dev/null
3801                 if [ $? -eq 1 ]; then
3802                         error "routes conversion failed"
3803                 fi
3804
3805                 lustre_routes_config --dry-run --verbose $new > $out
3806                 # check that the script succeeded
3807                 cmp -s $out $verify_conf > /dev/null
3808                 if [ $? -eq 1 ]; then
3809                         error "routes config failed"
3810                 fi
3811         else
3812                 error "routes conversion test failed"
3813         fi
3814         # remove generated files
3815         rm -f $new $legacy $verify $verify_conf $out
3816 }
3817 run_test 67 "test routes conversion and configuration"
3818
3819 test_68() {
3820         local fid
3821         local seq
3822         local START
3823         local END
3824
3825         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
3826                 { skip "Need MDS version at least 2.4.53"; return 0; }
3827
3828         umount_client $MOUNT || error "umount client failed"
3829
3830         start_mdt 1 || error "MDT start failed"
3831         start_ost
3832
3833         # START-END - the sequences we'll be reserving
3834         START=$(do_facet $SINGLEMDS \
3835                 lctl get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
3836         END=$((START + (1 << 30)))
3837         do_facet $SINGLEMDS \
3838                 lctl set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
3839
3840         # reset the sequences MDT0000 has already assigned
3841         do_facet $SINGLEMDS \
3842                 lctl set_param seq.srv*MDT0000.space=clear
3843
3844         # remount to let the client allocate new sequence
3845         mount_client $MOUNT || error "mount client failed"
3846
3847         touch $DIR/$tfile
3848         do_facet $SINGLEMDS \
3849                 lctl get_param seq.srv*MDT0000.space
3850         $LFS path2fid $DIR/$tfile
3851
3852         local old_ifs="$IFS"
3853         IFS='[:]'
3854         fid=($($LFS path2fid $DIR/$tfile))
3855         IFS="$old_ifs"
3856         let seq=${fid[1]}
3857
3858         if [[ $seq < $END ]]; then
3859                 error "used reserved sequence $seq?"
3860         fi
3861         cleanup || return $?
3862 }
3863 run_test 68 "be able to reserve specific sequences in FLDB"
3864
3865 test_69() {
3866         setup
3867
3868         # use OST0000 since it probably has the most creations
3869         local OSTNAME=$(ostname_from_index 0)
3870         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
3871         local last_id=$(do_facet mds1 lctl get_param -n \
3872                         osc.$mdtosc_proc1.prealloc_last_id)
3873
3874         # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
3875         # verify that the LAST_ID recovery is working properly.  If
3876         # not, then the OST will refuse to allow the MDS connect
3877         # because the LAST_ID value is too different from the MDS
3878         #define OST_MAX_PRECREATE=20000
3879         local num_create=$((20000 * 3/2 - $last_id + 100))
3880
3881         mkdir $DIR/$tdir
3882         $LFS setstripe -i 0 $DIR/$tdir
3883         createmany $DIR/$tdir/$tfile- $num_create
3884         # delete all of the files with objects on OST0 so the
3885         # filesystem is not inconsistent later on
3886         $LFS find $MOUNT --index 0 -print0 | xargs -0 unlink
3887
3888         stop_ost || error "OST0 stop failure"
3889         add ost1 $(mkfs_opts ost1 $ostdev) --reformat --replace $ostdev ||
3890                 error "reformat and replace $ostdev failed"
3891         start_ost || error "OST0 restart failure"
3892
3893         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
3894         local idx=$($LFS getstripe -c $DIR/$tdir/$tfile-last)
3895         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
3896 }
3897 run_test 68 "replace an OST with the same index"
3898
3899 test_70a() {
3900         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3901         local MDTIDX=1
3902
3903         start_mdt 1 || error "MDT0 start fail"
3904
3905         start_ost || error "OST0 start fail"
3906
3907         start_mdt 2 || error "MDT1 start fail"
3908
3909         mount_client $MOUNT || error "mount client fails"
3910
3911         mkdir -p $DIR/$tdir || error "create dir fail"
3912
3913         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3914                                         error "create remote dir fail"
3915
3916         rm -rf $DIR/$tdir || error "delete dir fail"
3917         cleanup || return $?
3918 }
3919 run_test 70a "start MDT0, then OST, then MDT1"
3920
3921 test_70b() {
3922         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3923         local MDTIDX=1
3924
3925         start_ost || error "OST0 start fail"
3926
3927         start_mdt 1 || error "MDT0 start fail"
3928         start_mdt 2 || error "MDT1 start fail"
3929
3930         mount_client $MOUNT || error "mount client fails"
3931
3932         mkdir -p $DIR/$tdir || error "create dir fail"
3933
3934         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3935                                         error "create remote dir fail"
3936
3937         rm -rf $DIR/$tdir || error "delete dir fail"
3938
3939         cleanup || return $?
3940 }
3941 run_test 70b "start OST, MDT1, MDT0"
3942
3943 test_70c() {
3944         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3945         local MDTIDX=1
3946
3947         start_mdt 1 || error "MDT0 start fail"
3948         start_mdt 2 || error "MDT1 start fail"
3949         start_ost || error "OST0 start fail"
3950
3951         mount_client $MOUNT || error "mount client fails"
3952         stop_mdt 1 || error "MDT1 start fail"
3953
3954         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
3955         echo "deactivate $mdc_for_mdt1"
3956         $LCTL --device $mdc_for_mdt1 deactivate || return 1
3957
3958         mkdir -p $DIR/$tdir && error "mkdir succeed"
3959
3960         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
3961                                         error "create remote dir succeed"
3962
3963         cleanup || return $?
3964 }
3965 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
3966
3967 test_70d() {
3968         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3969         local MDTIDX=1
3970
3971         start_mdt 1 || error "MDT0 start fail"
3972         start_mdt 2 || error "MDT1 start fail"
3973         start_ost || error "OST0 start fail"
3974
3975         mount_client $MOUNT || error "mount client fails"
3976
3977         stop_mdt 2 || error "MDT1 start fail"
3978
3979         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
3980                              awk '{print $4}')
3981         echo "deactivate $mdc_for_mdt2"
3982         $LCTL --device $mdc_for_mdt2 deactivate ||
3983                         error "set $mdc_for_mdt2 deactivate failed"
3984
3985         mkdir -p $DIR/$tdir || error "mkdir fail"
3986         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
3987                         error "create remote dir succeed"
3988
3989         rm -rf $DIR/$tdir || error "delete dir fail"
3990
3991         cleanup || return $?
3992 }
3993 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
3994
3995 test_71a() {
3996         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3997         if combined_mgs_mds; then
3998                 skip "needs separate MGS/MDT" && return
3999         fi
4000         local MDTIDX=1
4001
4002         start_mdt 1 || error "MDT0 start fail"
4003         start_ost || error "OST0 start fail"
4004         start_mdt 2 || error "MDT1 start fail"
4005         start_ost2 || error "OST1 start fail"
4006
4007         mount_client $MOUNT || error "mount client fails"
4008
4009         mkdir -p $DIR/$tdir || error "mkdir fail"
4010         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4011                         error "create remote dir succeed"
4012
4013         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4014         rm -rf $DIR/$tdir || error "delete dir fail"
4015
4016         umount_client $MOUNT
4017         stop_mdt 1 || error "MDT0 stop fail"
4018         stop_mdt 2 || error "MDT1 stop fail"
4019         stop_ost || error "OST0 stop fail"
4020         stop_ost2 || error "OST1 stop fail"
4021 }
4022 run_test 71a "start MDT0 OST0, MDT1, OST1"
4023
4024 test_71b() {
4025         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4026         if combined_mgs_mds; then
4027                 skip "needs separate MGS/MDT" && return
4028         fi
4029         local MDTIDX=1
4030
4031         start_mdt 2 || error "MDT1 start fail"
4032         start_ost || error "OST0 start fail"
4033         start_mdt 1 || error "MDT0 start fail"
4034         start_ost2 || error "OST1 start fail"
4035
4036         mount_client $MOUNT || error "mount client fails"
4037
4038         mkdir -p $DIR/$tdir || error "mkdir fail"
4039         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4040                         error "create remote dir succeed"
4041
4042         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4043         rm -rf $DIR/$tdir || error "delete dir fail"
4044
4045         umount_client $MOUNT
4046         stop_mdt 1 || error "MDT0 stop fail"
4047         stop_mdt 2 || error "MDT1 stop fail"
4048         stop_ost || error "OST0 stop fail"
4049         stop_ost2 || error "OST1 stop fail"
4050 }
4051 run_test 71b "start MDT1, OST0, MDT0, OST1"
4052
4053 test_71c() {
4054         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4055         if combined_mgs_mds; then
4056                 skip "needs separate MGS/MDT" && return
4057         fi
4058         local MDTIDX=1
4059
4060         start_ost || error "OST0 start fail"
4061         start_ost2 || error "OST1 start fail"
4062         start_mdt 2 || error "MDT1 start fail"
4063         start_mdt 1 || error "MDT0 start fail"
4064
4065         mount_client $MOUNT || error "mount client fails"
4066
4067         mkdir -p $DIR/$tdir || error "mkdir fail"
4068         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4069                         error "create remote dir succeed"
4070
4071         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4072         rm -rf $DIR/$tdir || error "delete dir fail"
4073
4074         umount_client $MOUNT
4075         stop_mdt 1 || error "MDT0 stop fail"
4076         stop_mdt 2 || error "MDT1 stop fail"
4077         stop_ost || error "OST0 stop fail"
4078         stop_ost2 || error "OST1 stop fail"
4079
4080 }
4081 run_test 71c "start OST0, OST1, MDT1, MDT0"
4082
4083 test_71d() {
4084         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4085         if combined_mgs_mds; then
4086                 skip "needs separate MGS/MDT" && return
4087         fi
4088         local MDTIDX=1
4089
4090         start_ost || error "OST0 start fail"
4091         start_mdt 2 || error "MDT0 start fail"
4092         start_mdt 1 || error "MDT0 start fail"
4093         start_ost2 || error "OST1 start fail"
4094
4095         mount_client $MOUNT || error "mount client fails"
4096
4097         mkdir -p $DIR/$tdir || error "mkdir fail"
4098         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4099                         error "create remote dir succeed"
4100
4101         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4102         rm -rf $DIR/$tdir || error "delete dir fail"
4103
4104         umount_client $MOUNT
4105         stop_mdt 1 || error "MDT0 stop fail"
4106         stop_mdt 2 || error "MDT1 stop fail"
4107         stop_ost || error "OST0 stop fail"
4108         stop_ost2 || error "OST1 stop fail"
4109
4110 }
4111 run_test 71d "start OST0, MDT1, MDT0, OST1"
4112
4113 test_71e() {
4114         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4115         if combined_mgs_mds; then
4116                 skip "needs separate MGS/MDT" && return
4117         fi
4118         local MDTIDX=1
4119
4120         start_ost || error "OST0 start fail"
4121         start_mdt 2 || error "MDT1 start fail"
4122         start_ost2 || error "OST1 start fail"
4123         start_mdt 1 || error "MDT0 start fail"
4124
4125         mount_client $MOUNT || error "mount client fails"
4126
4127         mkdir -p $DIR/$tdir || error "mkdir fail"
4128         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4129                         error "create remote dir succeed"
4130
4131         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4132         rm -rf $DIR/$tdir || error "delete dir fail"
4133
4134         umount_client $MOUNT
4135         stop_mdt 1 || error "MDT0 stop fail"
4136         stop_mdt 2 || error "MDT1 stop fail"
4137         stop_ost || error "OST0 stop fail"
4138         stop_ost2 || error "OST1 stop fail"
4139
4140 }
4141 run_test 71e "start OST0, MDT1, OST1, MDT0"
4142
4143 test_72() { #LU-2634
4144         local mdsdev=$(mdsdevname 1)
4145         local ostdev=$(ostdevname 1)
4146         local cmd="$E2FSCK -fnvd $mdsdev"
4147         local fn=3
4148
4149         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4150                 skip "ldiskfs only test" && return
4151
4152         #tune MDT with "-O extents"
4153
4154         for num in $(seq $MDSCOUNT); do
4155                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
4156                 --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4157                 error "add mds $num failed"
4158                 $TUNE2FS -O extents $(mdsdevname $num)
4159         done
4160
4161         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
4162                 error "add $ostdev failed"
4163         start_mgsmds || error "start mds failed"
4164         start_ost || error "start ost failed"
4165         mount_client $MOUNT || error "mount client failed"
4166
4167         #create some short symlinks
4168         mkdir -p $DIR/$tdir
4169         createmany -o $DIR/$tdir/$tfile-%d $fn
4170         echo "create $fn short symlinks"
4171         for i in $(seq -w 1 $fn); do
4172                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
4173         done
4174         ls -al $MOUNT
4175
4176         #umount
4177         umount_client $MOUNT || error "umount client failed"
4178         stop_mds || error "stop mds failed"
4179         stop_ost || error "stop ost failed"
4180
4181         #run e2fsck
4182         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
4183 }
4184 run_test 72 "test fast symlink with extents flag enabled"
4185
4186 test_73() { #LU-3006
4187         load_modules
4188         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4189         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
4190                 error "1st tunefs failed"
4191         start_mgsmds || error "start mds failed"
4192         start_ost || error "start ost failed"
4193         mount_client $MOUNT || error "mount client failed"
4194         lctl get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
4195                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
4196         umount_client $MOUNT || error "umount client failed"
4197         stopall
4198         reformat
4199 }
4200 run_test 73 "failnode to update from mountdata properly"
4201
4202 test_74() { # LU-1606
4203         for TESTPROG in $LUSTRE_TESTS_API_DIR/*.c; do
4204                 gcc -Wall -Werror $LUSTRE_TESTS_API_DIR/simple_test.c \
4205                         -I$LUSTRE/include \
4206                         -L$LUSTRE/utils -llustreapi ||
4207                                 error "client api broken"
4208         done
4209         cleanup || return $?
4210 }
4211 run_test 74 "Lustre client api program can compile and link"
4212
4213 test_75() { # LU-2374
4214         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
4215                         skip "Need MDS version at least 2.4.1" && return
4216
4217         local index=0
4218         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
4219                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
4220         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
4221                 --reformat $(ostdevname 1) $(ostvdevname 1)"
4222
4223         #check with default parameters
4224         add mds1 $opts_mds || error "add mds1 failed for default params"
4225         add ost1 $opts_ost || error "add ost1 failed for default params"
4226
4227         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
4228         opts_mds=$(echo $opts_mds |
4229                    sed -e "s/--index=$index/--index=$index --mdt/")
4230         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
4231         opts_ost=$(echo $opts_ost |
4232                    sed -e "s/--index=$index/--index=$index --ost/")
4233
4234         add mds1 $opts_mds || error "add mds1 failed for new params"
4235         add ost1 $opts_ost || error "add ost1 failed for new params"
4236         return 0
4237 }
4238 run_test 75 "The order of --index should be irrelevant"
4239
4240 test_76() {
4241         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
4242                 { skip "Need MDS version at least 2.4.52" && return 0; }
4243         setup
4244         local MDMB_PARAM="osc.*.max_dirty_mb"
4245         echo "Change MGS params"
4246         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
4247                 head -1)
4248         echo "max_dirty_mb: $MAX_DIRTY_MB"
4249         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
4250         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
4251         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
4252         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4253                 head -1" $NEW_MAX_DIRTY_MB
4254         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4255         echo "$MAX_DIRTY_MB"
4256         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4257                 error "error while apply max_dirty_mb"
4258
4259         echo "Check the value is stored after remount"
4260         stopall
4261         setupall
4262         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4263                 head -1" $NEW_MAX_DIRTY_MB
4264         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4265         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4266                 error "max_dirty_mb is not saved after remount"
4267
4268         echo "Change OST params"
4269         CLIENT_PARAM="obdfilter.*.client_cache_count"
4270         local CLIENT_CACHE_COUNT
4271         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4272                 head -1)
4273         echo "client_cache_count: $CLIENT_CACHE_COUNT"
4274         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
4275         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
4276         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
4277         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4278                 head -1" $NEW_CLIENT_CACHE_COUNT
4279         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4280                 head -1)
4281         echo "$CLIENT_CACHE_COUNT"
4282         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4283                 error "error while apply client_cache_count"
4284
4285         echo "Check the value is stored after remount"
4286         stopall
4287         setupall
4288         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4289                 head -1" $NEW_CLIENT_CACHE_COUNT
4290         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4291                 head -1)
4292         echo "$CLIENT_CACHE_COUNT"
4293         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4294                 error "client_cache_count is not saved after remount"
4295         stopall
4296 }
4297 run_test 76 "set permanent params set_param -P"
4298
4299 test_77() { # LU-3445
4300         local server_version=$(lustre_version_code $SINGLEMDS)
4301
4302         [[ $server_version -ge $(version_code 2.2.60) ]] &&
4303         [[ $server_version -le $(version_code 2.4.0) ]] &&
4304                 skip "Need MDS version < 2.2.60 or > 2.4.0" && return
4305
4306         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
4307                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4308                 skip_env "mixed loopback and real device not working" && return
4309         fi
4310
4311         local fs2mdsdev=$(mdsdevname 1_2)
4312         local fs2ostdev=$(ostdevname 1_2)
4313         local fs2mdsvdev=$(mdsvdevname 1_2)
4314         local fs2ostvdev=$(ostvdevname 1_2)
4315         local fsname=test1234
4316         local mgsnid
4317         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
4318
4319         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
4320                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
4321         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT ||
4322                 error "start fs2mds failed"
4323
4324         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
4325         [[ $mgsnid = *,* ]] || mgsnid+=",$mgsnid"
4326
4327         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --mgsnode=$mgsnid \
4328                 --failnode=$failnid --fsname=$fsname \
4329                 --reformat $fs2ostdev $fs2ostvdev ||
4330                         error "add fs2ost failed"
4331         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
4332
4333         mkdir -p $MOUNT2
4334         mount -t lustre $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
4335         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
4336         cleanup_24a
4337 }
4338 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
4339
4340 if ! combined_mgs_mds ; then
4341         stop mgs
4342 fi
4343
4344 cleanup_gss
4345
4346 complete $SECONDS
4347 exit_status