Whamcloud - gitweb
LU-7001 osp: fix llog processing
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6
7 # bug number for skipped test:  LU-8972
8 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 101"
9 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
10
11 is_sles11()                                             # LU-2181
12 {
13         if [ -r /etc/SuSE-release ]
14         then
15                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
16                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
17                         awk '{ print $3 }')
18                 if [ $vers -eq 11 ] && [ $patchlev -eq 2 ]
19                 then
20                         return 0
21                 fi
22         fi
23         return 1
24 }
25
26 if is_sles11; then                                      # LU-2181
27         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 23a 34b"
28 fi
29
30 if [ "$FAILURE_MODE" = "HARD" ]; then
31         CONFIG_EXCEPTIONS="24a " &&
32         echo "Except the tests: $CONFIG_EXCEPTIONS for " \
33              "FAILURE_MODE=$FAILURE_MODE, b=23573" &&
34                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
35 fi
36
37 # bug number for skipped test:
38 # a tool to create lustre filesystem images
39 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
40
41 SRCDIR=$(dirname $0)
42 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
43
44 PTLDEBUG=${PTLDEBUG:--1}
45 SAVE_PWD=$PWD
46 LUSTRE=${LUSTRE:-$(dirname $0)/..}
47 RLUSTRE=${RLUSTRE:-$LUSTRE}
48 export MULTIOP=${MULTIOP:-multiop}
49
50 . $LUSTRE/tests/test-framework.sh
51 init_test_env $@
52 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
53
54 # use small MDS + OST size to speed formatting time
55 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
56 # STORED_MDSSIZE is used in test_18
57 STORED_MDSSIZE=$MDSSIZE
58 STORED_OSTSIZE=$OSTSIZE
59 MDSSIZE=200000
60 OSTSIZE=200000
61
62 fs2mds_HOST=$mds_HOST
63 fs2ost_HOST=$ost_HOST
64 fs3ost_HOST=$ost_HOST
65
66 MDSDEV1_2=$fs2mds_DEV
67 OSTDEV1_2=$fs2ost_DEV
68 OSTDEV2_2=$fs3ost_DEV
69
70 if ! combined_mgs_mds; then
71         # bug number for skipped test: 23954 LU-9860 LU-9860 LU-9860 LU-9860
72         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  24b   33a     43b     53b     54b"
73         # bug number for skipped test: LU-9875 LU-9879 LU-9879 LU-9879 LU-9879
74         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  70e     80      84      87      100"
75         # bug number for skipped test: LU-8110 LU-9400 LU-9879 LU-9879 LU-9879
76         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  102     103     104     105     107"
77 fi
78
79 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
80 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
81         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
82 fi
83
84 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
85 # bug number for skipped test:
86         ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
87
88 init_logging
89
90 #
91 require_dsh_mds || exit 0
92 require_dsh_ost || exit 0
93
94 #                                  8  22   (min)"
95 [ "$SLOW" = "no" ] && EXCEPT_SLOW="45 69"
96
97 assert_DIR
98
99 gen_config() {
100         # The MGS must be started before the OSTs for a new fs, so start
101         # and stop to generate the startup logs.
102         start_mds
103         start_ost
104         wait_osc_import_state mds ost FULL
105         stop_ost
106         stop_mds
107 }
108
109 reformat_and_config() {
110         reformat
111         if ! combined_mgs_mds ; then
112                 start_mgs
113         fi
114         gen_config
115 }
116
117 writeconf_or_reformat() {
118         # There are at most 2 OSTs for write_conf test
119         # who knows if/where $TUNEFS is installed?
120         # Better reformat if it fails...
121         writeconf_all $MDSCOUNT 2 ||
122                 { echo "tunefs failed, reformatting instead" &&
123                   reformat_and_config && return 0; }
124         return 0
125 }
126
127 reformat() {
128         formatall
129 }
130
131 start_mgs () {
132         echo "start mgs"
133         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
134 }
135
136 start_mdt() {
137         local num=$1
138         local facet=mds$num
139         local dev=$(mdsdevname $num)
140         shift 1
141
142         echo "start mds service on `facet_active_host $facet`"
143         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
144 }
145
146 stop_mdt() {
147         local num=$1
148         local facet=mds$num
149         local dev=$(mdsdevname $num)
150         shift 1
151
152         echo "stop mds service on `facet_active_host $facet`"
153         # These tests all use non-failover stop
154         stop $facet -f || return 97
155 }
156
157 start_mds() {
158         local num
159
160         for num in $(seq $MDSCOUNT); do
161                 start_mdt $num $@ || return 94
162         done
163 }
164
165 start_mgsmds() {
166         if ! combined_mgs_mds ; then
167                 start_mgs
168         fi
169         start_mds $@
170 }
171
172 stop_mds() {
173         local num
174         for num in $(seq $MDSCOUNT); do
175                 stop_mdt $num || return 97
176         done
177 }
178
179 stop_mgs() {
180        echo "stop mgs service on `facet_active_host mgs`"
181        # These tests all use non-failover stop
182        stop mgs -f  || return 97
183 }
184
185 start_ost() {
186         echo "start ost1 service on `facet_active_host ost1`"
187         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS $@ || return 95
188 }
189
190 stop_ost() {
191         echo "stop ost1 service on `facet_active_host ost1`"
192         # These tests all use non-failover stop
193         stop ost1 -f || return 98
194 }
195
196 start_ost2() {
197         echo "start ost2 service on `facet_active_host ost2`"
198         start ost2 $(ostdevname 2) $OST_MOUNT_OPTS $@ || return 92
199 }
200
201 stop_ost2() {
202         echo "stop ost2 service on `facet_active_host ost2`"
203         # These tests all use non-failover stop
204         stop ost2 -f || return 93
205 }
206
207 mount_client() {
208         local MOUNTPATH=$1
209         echo "mount $FSNAME on ${MOUNTPATH}....."
210         zconf_mount $(hostname) $MOUNTPATH || return 96
211 }
212
213 remount_client() {
214         local mountopt="remount,$1"
215         local MOUNTPATH=$2
216         echo "remount '$1' lustre on ${MOUNTPATH}....."
217         zconf_mount $(hostname) $MOUNTPATH "$mountopt" || return 96
218 }
219
220 umount_client() {
221         local mountpath=$1
222         shift
223         echo "umount lustre on $mountpath....."
224         zconf_umount $HOSTNAME $mountpath $@ || return 97
225 }
226
227 manual_umount_client(){
228         local rc
229         local FORCE=$1
230         echo "manual umount lustre on ${MOUNT}...."
231         do_facet client "umount ${FORCE} $MOUNT"
232         rc=$?
233         return $rc
234 }
235
236 setup() {
237         start_mds || error "MDT start failed"
238         start_ost || error "Unable to start OST1"
239         mount_client $MOUNT || error "client start failed"
240         client_up || error "client_up failed"
241 }
242
243 setup_noconfig() {
244         start_mgsmds
245         start_ost
246         mount_client $MOUNT
247 }
248
249 unload_modules_conf () {
250         if combined_mgs_mds || ! local_mode; then
251                 unload_modules || return 1
252         fi
253 }
254
255 cleanup_nocli() {
256         stop_ost || return 202
257         stop_mds || return 201
258         unload_modules_conf || return 203
259 }
260
261 cleanup() {
262         local force=""
263         [ "x$1" != "x" ] && force='-f'
264         umount_client $MOUNT $force|| return 200
265         cleanup_nocli || return $?
266 }
267
268 cleanup_fs2() {
269         trap 0
270         echo "umount $MOUNT2 ..."
271         umount $MOUNT2 || true
272         echo "stopping fs2mds ..."
273         stop fs2mds -f || true
274         echo "stopping fs2ost ..."
275         stop fs2ost -f || true
276 }
277
278 check_mount() {
279         do_facet client "cp /etc/passwd $DIR/a" || return 71
280         do_facet client "rm $DIR/a" || return 72
281         # make sure lustre is actually mounted (touch will block,
282         # but grep won't, so do it after)
283         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
284         echo "setup single mount lustre success"
285 }
286
287 check_mount2() {
288         do_facet client "touch $DIR/a" || return 71
289         do_facet client "rm $DIR/a" || return 72
290         do_facet client "touch $DIR2/a" || return 73
291         do_facet client "rm $DIR2/a" || return 74
292         echo "setup double mount lustre success"
293 }
294
295 build_test_filter
296
297 if [ "$ONLY" == "setup" ]; then
298         setup
299         exit
300 fi
301
302 if [ "$ONLY" == "cleanup" ]; then
303         cleanup
304         exit
305 fi
306
307 init_gss
308
309 #create single point mountpoint
310
311 reformat_and_config
312
313 test_0() {
314         setup
315         check_mount || error "check_mount failed"
316         cleanup || error "cleanup failed with $?"
317 }
318 run_test 0 "single mount setup"
319
320 test_1() {
321         start_mds || error "MDS start failed"
322         start_ost || error "unable to start OST"
323         echo "start ost second time..."
324         start_ost && error "2nd OST start should fail"
325         mount_client $MOUNT || error "client start failed"
326         check_mount || error "check_mount failed"
327         cleanup || error "cleanup failed with $?"
328 }
329 run_test 1 "start up ost twice (should return errors)"
330
331 test_2() {
332         start_mds || error "MDT start failed"
333         echo "start mds second time.."
334         start_mds && error "2nd MDT start should fail"
335         start_ost || error "OST start failed"
336         mount_client $MOUNT || error "mount_client failed to start client"
337         check_mount || error "check_mount failed"
338         cleanup || error "cleanup failed with $?"
339 }
340 run_test 2 "start up mds twice (should return err)"
341
342 test_3() {
343         setup
344         #mount.lustre returns an error if already in mtab
345         mount_client $MOUNT && error "2nd client mount should fail"
346         check_mount || error "check_mount failed"
347         cleanup || error "cleanup failed with $?"
348 }
349 run_test 3 "mount client twice (should return err)"
350
351 test_4() {
352         setup
353         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
354         stop_ost || error "Unable to stop OST1"
355         umount_client $MOUNT -f || error “unmount $MOUNT failed”
356         cleanup_nocli
357         eno=$?
358         # ok for ost to fail shutdown
359         if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
360                 error "cleanup failed with $?"
361         fi
362 }
363 run_test 4 "force cleanup ost, then cleanup"
364
365 test_5a() {     # was test_5
366         setup
367         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
368         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
369
370         stop_mds || error "Unable to stop MDS"
371
372         # cleanup may return an error from the failed
373         # disconnects; for now I'll consider this successful
374         # if all the modules have unloaded.
375         $UMOUNT -f $MOUNT &
376         UMOUNT_PID=$!
377         sleep 6
378         echo "killing umount"
379         kill -TERM $UMOUNT_PID
380         echo "waiting for umount to finish"
381         wait $UMOUNT_PID
382         if grep " $MOUNT " /proc/mounts; then
383                 echo "test 5: /proc/mounts after failed umount"
384                 umount -f $MOUNT &
385                 UMOUNT_PID=$!
386                 sleep 2
387                 echo "killing umount"
388                 kill -TERM $UMOUNT_PID
389                 echo "waiting for umount to finish"
390                 wait $UMOUNT_PID
391                 grep " $MOUNT " /proc/mounts &&
392                         error "/proc/mounts after second umount"
393         fi
394
395         # manual_mount_client may fail due to umount succeeding above
396         manual_umount_client
397         # stop_mds is a no-op here, and should not fail
398         cleanup_nocli || error "cleanup_nocli failed with $?"
399         # df may have lingering entry
400         manual_umount_client
401         # mtab may have lingering entry
402         local WAIT=0
403         local MAX_WAIT=20
404         local sleep=1
405         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
406                 sleep $sleep
407                 grep -q $MOUNT" " /etc/mtab || break
408                 echo "Waiting /etc/mtab updated ... "
409                 WAIT=$(( WAIT + sleep))
410         done
411         [ "$WAIT" -eq "$MAX_WAIT" ] &&
412                 error "/etc/mtab is not updated in $WAIT secs"
413         echo "/etc/mtab updated in $WAIT secs"
414 }
415 run_test 5a "force cleanup mds, then cleanup"
416
417 cleanup_5b () {
418         trap 0
419         start_mgs
420 }
421
422 test_5b() {
423         grep " $MOUNT " /etc/mtab &&
424                 error false "unexpected entry in mtab before mount" && return 10
425
426         start_ost || error "OST start failed"
427         if ! combined_mgs_mds ; then
428                 trap cleanup_5b EXIT ERR
429                 start_mds || error "MDS start failed"
430                 stop mgs
431         fi
432
433         mount_client $MOUNT && error "mount_client $MOUNT should fail"
434         grep " $MOUNT " /etc/mtab &&
435                 error "$MOUNT entry in mtab after failed mount"
436         umount_client $MOUNT
437         # stop_mds is a no-op here, and should not fail
438         cleanup_nocli || error "cleanup_nocli failed with $?"
439         if ! combined_mgs_mds ; then
440                 cleanup_5b
441         fi
442 }
443 run_test 5b "Try to start a client with no MGS (should return errs)"
444
445 test_5c() {
446         grep " $MOUNT " /etc/mtab &&
447                 error false "unexpected entry in mtab before mount" && return 10
448
449         start_mds || error "MDS start failed"
450         start_ost || error "OST start failed"
451         local oldfs="${FSNAME}"
452         FSNAME="wrong.${FSNAME}"
453         mount_client $MOUNT || :
454         FSNAME=${oldfs}
455         grep " $MOUNT " /etc/mtab &&
456                 error "$MOUNT entry in mtab after failed mount"
457         umount_client $MOUNT
458         cleanup_nocli || error "cleanup_nocli failed with $?"
459 }
460 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
461
462 test_5d() {
463         grep " $MOUNT " /etc/mtab &&
464                 error "unexpected entry in mtab before mount"
465
466         start_ost || error "OST start failed"
467         start_mds || error "MDS start failed"
468         stop_ost -f || error "Unable to stop OST1"
469         mount_client $MOUNT || error "mount_client $MOUNT failed"
470         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
471         cleanup_nocli || error "cleanup_nocli failed with $?"
472         ! grep " $MOUNT " /etc/mtab ||
473                 error "$MOUNT entry in mtab after unmount"
474 }
475 run_test 5d "mount with ost down"
476
477 test_5e() {
478         grep " $MOUNT " /etc/mtab &&
479                 error false "unexpected entry in mtab before mount" && return 10
480
481         start_mds || error "MDS start failed"
482         start_ost || error "OST start failed"
483
484         #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
485         do_facet client "$LCTL set_param fail_loc=0x80000506"
486         mount_client $MOUNT || echo "mount failed (not fatal)"
487         cleanup || error "cleanup failed with $?"
488         grep " $MOUNT " /etc/mtab &&
489                 error "$MOUNT entry in mtab after unmount"
490         pass
491 }
492 run_test 5e "delayed connect, don't crash (bug 10268)"
493
494 test_5f() {
495         if combined_mgs_mds ; then
496                 skip "needs separate mgs and mds"
497                 return 0
498         fi
499
500         grep " $MOUNT " /etc/mtab &&
501                 error false "unexpected entry in mtab before mount" && return 10
502
503         local rc=0
504         start_ost || error "OST start failed"
505         mount_client $MOUNT &
506         local pid=$!
507         echo client_mount pid is $pid
508
509         sleep 5
510
511         if ! ps -f -p $pid >/dev/null; then
512                 wait $pid
513                 rc=$?
514                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
515                 error "mount returns $rc, expected to hang"
516                 rc=11
517                 cleanup || error "cleanup failed with $?"
518                 return $rc
519         fi
520
521         # start mds
522         start_mds || error "start MDS failed"
523
524         # mount should succeed after start mds
525         wait $pid
526         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
527         cleanup || error "final call to cleanup failed with rc $?"
528 }
529 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
530
531 test_5g() {
532         modprobe lustre
533         [ $(lustre_version_code client) -lt $(version_code 2.9.53) ] &&
534                 { skip "automount of debugfs missing before 2.9.53" && return 0; }
535         umount /sys/kernel/debug
536         $LCTL get_param -n devices | egrep -v "error" && \
537                 error "lctl can't access debugfs data"
538         grep " debugfs " /etc/mtab || error "debugfs failed to remount"
539 }
540 run_test 5g "handle missing debugfs"
541
542 test_6() {
543         setup
544         manual_umount_client
545         mount_client $MOUNT || error "mount_client $MOUNT failed"
546         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
547         cleanup || error "cleanup failed with rc $?"
548 }
549 run_test 6 "manual umount, then mount again"
550
551 test_7() {
552         setup
553         manual_umount_client
554         cleanup_nocli || error "cleanup_nocli failed with $?"
555 }
556 run_test 7 "manual umount, then cleanup"
557
558 test_8() {
559         setup
560         mount_client $MOUNT2 || error "mount_client $MOUNT2 failed"
561         check_mount2 || error "check_mount2 failed"
562         umount_client $MOUNT2 || error "umount_client $MOUNT2 failed"
563         cleanup || error "cleanup failed with rc $?"
564 }
565 run_test 8 "double mount setup"
566
567 test_9() {
568         start_ost || error "OST start failed"
569
570         do_facet ost1 $LCTL set_param debug=\'inode trace\' ||
571                 error "do_facet ost1 set_param inode trace failed."
572         do_facet ost1 $LCTL set_param subsystem_debug=\'mds ost\' ||
573                 error "do_facet ost1 set_param debug mds ost failed."
574
575         CHECK_PTLDEBUG="`do_facet ost1 $LCTL get_param -n debug`"
576         if [ "$CHECK_PTLDEBUG" ] && { \
577            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
578            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
579                 echo "lnet.debug success"
580         else
581                 error "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
582         fi
583         CHECK_SUBSYS="`do_facet ost1 $LCTL get_param -n subsystem_debug`"
584         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
585                 echo "lnet.subsystem_debug success"
586         else
587                 error "lnet.subsystem_debug: want 'mds ost' got '$CHECK_SUBSYS'"
588         fi
589         stop_ost || error "Unable to stop OST1"
590 }
591 run_test 9 "test ptldebug and subsystem for mkfs"
592
593 is_blkdev () {
594         local facet=$1
595         local dev=$2
596         local size=${3:-""}
597
598         local rc=0
599         do_facet $facet "test -b $dev" || rc=1
600         if [[ "$size" ]]; then
601                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
602                            count=1 skip=$size 2>&1" |
603                         awk '($3 == "in") { print $1 }')
604                 [[ $in  = "1+0" ]] || rc=1
605         fi
606         return $rc
607 }
608
609 #
610 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
611 # But with new MDS stack we don't care about the mode of local objects
612 # anymore, so this test is removed. See bug 22944 for more details.
613 #
614
615 test_17() {
616         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
617                 skip "ldiskfs only test"
618                 return
619         fi
620
621         setup
622         check_mount || error "check_mount failed"
623         cleanup || error "cleanup failed with rc $?"
624
625         echo "Remove mds config log"
626         if ! combined_mgs_mds ; then
627                 stop mgs
628         fi
629
630         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
631                       $(mgsdevname) || return \$?" ||
632                 error "do_facet mgs failed with $?"
633
634         if ! combined_mgs_mds ; then
635                 start_mgs
636         fi
637
638         start_ost || error "OST start failed"
639         start_mds && error "MDS start succeeded, but should fail"
640         reformat_and_config
641 }
642 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
643
644 test_18() {
645         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
646                 skip "ldiskfs only test"
647                 return
648         fi
649
650         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
651
652         local MIN=2000000
653
654         local OK=
655         # check if current MDSSIZE is large enough
656         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE &&
657                 log "use MDSSIZE=$MDSSIZE"
658
659         # check if the global config has a large enough MDSSIZE
660         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] &&
661                 [ $STORED_MDSSIZE -ge $MIN ] &&
662                 OK=1 && myMDSSIZE=$STORED_MDSSIZE &&
663                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
664
665         # check if the block device is large enough
666         is_blkdev $SINGLEMDS $MDSDEV $MIN
667         local large_enough=$?
668         if [ -n "$OK" ]; then
669                 [ $large_enough -ne 0 ] && OK=""
670         else
671                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
672                         log "use device $MDSDEV with MIN=$MIN"
673         fi
674
675         # check if a loopback device has enough space for fs metadata (5%)
676
677         if [ -z "$OK" ]; then
678                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! \
679                               -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
680                         awk '($1 != "Filesystem") { print $4 }')
681                 ! [ -z "$SPACE" ] && [ $SPACE -gt $((MIN / 20)) ] &&
682                         OK=1 && myMDSSIZE=$MIN &&
683                         log "use file $MDSDEV with MIN=$MIN"
684         fi
685
686         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
687
688         echo "mount mds with large journal..."
689
690         local OLD_MDSSIZE=$MDSSIZE
691         MDSSIZE=$myMDSSIZE
692
693         reformat_and_config
694         echo "mount lustre system..."
695         setup
696         check_mount || error "check_mount failed"
697
698         echo "check journal size..."
699         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
700         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
701                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
702         else
703                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
704         fi
705
706         cleanup || error "cleanup failed with rc $?"
707
708         MDSSIZE=$OLD_MDSSIZE
709         reformat_and_config
710 }
711 run_test 18 "check mkfs creates large journals"
712
713 test_19a() {
714         start_mds || error "MDS start failed"
715         stop_mds || error "Unable to stop MDS"
716 }
717 run_test 19a "start/stop MDS without OSTs"
718
719 test_19b() {
720         start_ost || error "Unable to start OST1"
721         stop_ost -f || error "Unable to stop OST1"
722 }
723 run_test 19b "start/stop OSTs without MDS"
724
725 test_20() {
726         # first format the ost/mdt
727         start_mds || error "MDS start failed"
728         start_ost || error "Unable to start OST1"
729         mount_client $MOUNT || error "mount_client $MOUNT failed"
730         check_mount || error "check_mount failed"
731         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed."
732         remount_client ro $MOUNT || error "remount_client with ro failed"
733         touch $DIR/$tfile && error "$DIR/$tfile created incorrectly"
734         [ -e $DIR/$tfile ] && error "$DIR/$tfile exists incorrectly"
735         remount_client rw $MOUNT || error "remount_client with rw failed"
736         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
737         MCNT=$(grep -c $MOUNT /etc/mtab)
738         [ "$MCNT" -ne 1 ] && error "$MOUNT in /etc/mtab $MCNT times"
739         umount_client $MOUNT
740         stop_mds || error "Unable to stop MDS"
741         stop_ost || error "Unable to stop OST1"
742 }
743 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
744
745 test_21a() {
746         start_mds || error "MDS start failed"
747         start_ost || error "unable to start OST1"
748         wait_osc_import_state mds ost FULL
749         stop_ost || error "unable to stop OST1"
750         stop_mds || error "unable to stop MDS"
751 }
752 run_test 21a "start mds before ost, stop ost first"
753
754 test_21b() {
755         start_ost || error "unable to start OST1"
756         start_mds || error "MDS start failed"
757         wait_osc_import_state mds ost FULL
758         stop_mds || error "unable to stop MDS"
759         stop_ost || error "unable to stop OST1"
760 }
761 run_test 21b "start ost before mds, stop mds first"
762
763 test_21c() {
764         start_ost || error "Unable to start OST1"
765         start_mds || error "MDS start failed"
766         start_ost2 || error "Unable to start OST2"
767         wait_osc_import_state mds ost2 FULL
768         stop_ost || error "Unable to stop OST1"
769         stop_ost2 || error "Unable to stop OST2"
770         stop_mds || error "Unable to stop MDS"
771         #writeconf to remove all ost2 traces for subsequent tests
772         writeconf_or_reformat
773 }
774 run_test 21c "start mds between two osts, stop mds last"
775
776 test_21d() {
777         if combined_mgs_mds ; then
778                 skip "need separate mgs device" && return 0
779         fi
780         stopall
781
782         reformat
783
784         start_mgs || error "unable to start MGS"
785         start_ost || error "unable to start OST1"
786         start_ost2 || error "unable to start OST2"
787         start_mds || error "MDS start failed"
788         wait_osc_import_state mds ost2 FULL
789
790         stop_ost || error "Unable to stop OST1"
791         stop_ost2 || error "Unable to stop OST2"
792         stop_mds || error "Unable to stop MDS"
793         stop_mgs
794         #writeconf to remove all ost2 traces for subsequent tests
795         writeconf_or_reformat
796         start_mgs || error "unable to start MGS"
797 }
798 run_test 21d "start mgs then ost and then mds"
799
800 cleanup_21e() {
801         MGSNID="$saved_mgsnid"
802         cleanup_fs2
803         echo "stopping fs2mgs ..."
804         stop $fs2mgs -f || true
805 }
806
807 test_21e() { # LU-5863
808         if [[ -z "$fs3ost_DEV" || -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
809                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
810                 skip_env "mixed loopback and real device not working" && return
811         fi
812
813         local fs2mdsdev=$(mdsdevname 1_2)
814         local fs2ostdev=$(ostdevname 1_2)
815         local fs3ostdev=$(ostdevname 2_2)
816
817         local fs2mdsvdev=$(mdsvdevname 1_2)
818         local fs2ostvdev=$(ostvdevname 1_2)
819         local fs3ostvdev=$(ostvdevname 2_2)
820
821         # temporarily use fs3ost as fs2mgs
822         local fs2mgs=fs3ost
823         local fs2mgsdev=$fs3ostdev
824         local fs2mgsvdev=$fs3ostvdev
825
826         local fsname=test1234
827
828         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
829                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
830         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS && trap cleanup_21e EXIT INT ||
831                 error "start fs2mgs failed"
832
833         local saved_mgsnid="$MGSNID"
834         MGSNID=$(do_facet $fs2mgs $LCTL list_nids | xargs | tr ' ' ,)
835
836         add fs2mds $(mkfs_opts mds1 $fs2mdsdev $fsname) \
837                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
838         add fs2ost $(mkfs_opts ost1 $fs2ostdev $fsname) \
839                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
840
841         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
842         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
843
844         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
845         $MOUNT_CMD $MGSNID:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
846         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
847
848         cleanup_21e
849 }
850 run_test 21e "separate MGS and MDS"
851
852 test_22() {
853         start_mds || error "MDS start failed"
854
855         echo "Client mount with ost in logs, but none running"
856         start_ost || error "unable to start OST1"
857         # wait until mds connected to ost and open client connection
858         wait_osc_import_state mds ost FULL
859         stop_ost || error "unable to stop OST1"
860         mount_client $MOUNT || error "mount_client $MOUNT failed"
861         # check_mount will block trying to contact ost
862         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
863         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
864         umount_client $MOUNT -f
865         pass
866
867         echo "Client mount with a running ost"
868         start_ost || error "unable to start OST1"
869         if $GSS; then
870                 # if gss enabled, wait full time to let connection from
871                 # mds to ost be established, due to the mismatch between
872                 # initial connect timeout and gss context negotiation timeout.
873                 # This perhaps could be remove after AT landed.
874                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
875                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
876         fi
877         mount_client $MOUNT || error "mount_client $MOUNT failed"
878         wait_osc_import_state mds ost FULL
879         wait_osc_import_state client ost FULL
880         check_mount || error "check_mount failed"
881         pass
882
883         cleanup || error "cleanup failed with rc $?"
884 }
885 run_test 22 "start a client before osts (should return errs)"
886
887 test_23a() {    # was test_23
888         setup
889         # fail mds
890         stop $SINGLEMDS || error "failed to stop $SINGLEMDS"
891         # force down client so that recovering mds waits for reconnect
892         local running=$(grep -c $MOUNT /proc/mounts) || true
893         if [ $running -ne 0 ]; then
894                 echo "Stopping client $MOUNT (opts: -f)"
895                 umount -f $MOUNT
896         fi
897
898         # enter recovery on failed mds
899         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
900         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "MDS start failed"
901         # try to start a new client
902         mount_client $MOUNT &
903         sleep 5
904         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
905         MOUNT_LUSTRE_PID=$(ps -ef | grep mount.lustre |
906                            grep -v grep | awk '{print $2}')
907         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
908         ps --ppid $MOUNT_PID
909         ps --ppid $MOUNT_LUSTRE_PID
910         echo "waiting for mount to finish"
911         ps -ef | grep mount
912         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
913         # SIGTERM works but it does not spread to offspring processses
914         kill -s TERM $MOUNT_PID
915         kill -s TERM $MOUNT_LUSTRE_PID
916         # we can not wait $MOUNT_PID because it is not a child of this shell
917         local PID1
918         local PID2
919         local WAIT=0
920         local MAX_WAIT=30
921         local sleep=1
922         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
923                 sleep $sleep
924                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
925                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
926                 echo PID1=$PID1
927                 echo PID2=$PID2
928                 [ -z "$PID1" -a -z "$PID2" ] && break
929                 echo "waiting for mount to finish ... "
930                 WAIT=$(( WAIT + sleep))
931         done
932         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
933                 error "MOUNT_PID $MOUNT_PID and "\
934                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
935                 ps -ef | grep mount
936         fi
937         stop_mds || error "stopping MDSes failed"
938         stop_ost || error "stopping OSSes failed"
939 }
940 run_test 23a "interrupt client during recovery mount delay"
941
942 umount_client $MOUNT
943 cleanup_nocli
944
945 test_23b() {    # was test_23
946         start_mds || error "MDS start failed"
947         start_ost || error "Unable to start OST1"
948         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
949         $LCTL set_param fail_loc=0x80000313
950         mount_client $MOUNT
951         cleanup || error "cleanup failed with rc $?"
952 }
953 run_test 23b "Simulate -EINTR during mount"
954
955 test_24a() {
956         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
957
958         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
959                 is_blkdev $SINGLEMDS $MDSDEV &&
960                 skip_env "mixed loopback and real device not working" && return
961         fi
962
963         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
964
965         local fs2mdsdev=$(mdsdevname 1_2)
966         local fs2ostdev=$(ostdevname 1_2)
967         local fs2mdsvdev=$(mdsvdevname 1_2)
968         local fs2ostvdev=$(ostvdevname 1_2)
969         local cl_user
970
971         # LU-9733 test fsname started with numbers as well
972         local FSNAME2=969362ae
973
974         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
975                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
976
977         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
978                 --reformat $fs2ostdev $fs2ostvdev || exit 10
979
980         setup
981         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
982         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
983         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
984         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
985
986         # LU-9733 test fsname started with numbers
987         cl_user=$(do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
988                         changelog_register -n) ||
989                                 error "register changelog failed"
990
991         do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
992                         changelog_deregister $cl_user ||
993                                 error "deregister changelog failed"
994         # 1 still works
995         check_mount || error "check_mount failed"
996         # files written on 1 should not show up on 2
997         cp /etc/passwd $DIR/$tfile
998         sleep 10
999         [ -e $MOUNT2/$tfile ] && error "File bleed"
1000         # 2 should work
1001         sleep 5
1002         cp /etc/passwd $MOUNT2/$tfile ||
1003                 error "cp /etc/passwd $MOUNT2/$tfile failed"
1004         rm $MOUNT2/$tfile || error "remove $MOUNT2/$tfile failed"
1005         # 2 is actually mounted
1006         grep $MOUNT2' ' /proc/mounts > /dev/null || error "$MOUNT2 not mounted"
1007         # failover
1008         facet_failover fs2mds
1009         facet_failover fs2ost
1010         df
1011         umount_client $MOUNT
1012         # the MDS must remain up until last MDT
1013         stop_mds
1014         MDS=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1015               awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1016         [ -z "$MDS" ] && error "No MDT"
1017         cleanup_fs2
1018         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1019 }
1020 run_test 24a "Multiple MDTs on a single node"
1021
1022 test_24b() {
1023         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1024
1025         if [ -z "$fs2mds_DEV" ]; then
1026                 local dev=${SINGLEMDS}_dev
1027                 local MDSDEV=${!dev}
1028                 is_blkdev $SINGLEMDS $MDSDEV &&
1029                 skip_env "mixed loopback and real device not working" && return
1030         fi
1031
1032         local fs2mdsdev=$(mdsdevname 1_2)
1033         local fs2mdsvdev=$(mdsvdevname 1_2)
1034
1035         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
1036                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
1037         setup
1038         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS &&
1039                 error "start MDS should fail"
1040         stop fs2mds -f
1041         cleanup || error "cleanup failed with rc $?"
1042 }
1043 run_test 24b "Multiple MGSs on a single node (should return err)"
1044
1045 test_25() {
1046         setup
1047         check_mount || error "check_mount failed"
1048         local MODULES=$($LCTL modules | awk '{ print $2 }')
1049         rmmod $MODULES 2>/dev/null || true
1050         cleanup || error "cleanup failed with $?"
1051 }
1052 run_test 25 "Verify modules are referenced"
1053
1054 test_26() {
1055         load_modules
1056         # we need modules before mount for sysctl, so make sure...
1057         do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
1058         #define OBD_FAIL_MDS_FS_SETUP            0x135
1059         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000135"
1060         start_mds && error "MDS started but should not have started"
1061         $LCTL get_param -n devices
1062         DEVS=$($LCTL get_param -n devices | egrep -v MG | wc -l)
1063         [ $DEVS -gt 0 ] && error "number of devices is $DEVS, should be zero"
1064         # start mds to drop writeconf setting
1065         start_mds || error "Unable to start MDS"
1066         stop_mds || error "Unable to stop MDS"
1067         unload_modules_conf || error "unload_modules_conf failed with $?"
1068 }
1069 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1070
1071 test_27a() {
1072         start_ost || error "Unable to start OST1"
1073         start_mds || error "Unable to start MDS"
1074         echo "Requeue thread should have started: "
1075         ps -e | grep ll_cfg_requeue
1076         set_conf_param_and_check ost1                                         \
1077            "$LCTL get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
1078            "$FSNAME-OST0000.ost.client_cache_seconds" ||
1079                 error "set_conf_param_and_check ost1 failed"
1080         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1081 }
1082 run_test 27a "Reacquire MGS lock if OST started first"
1083
1084 test_27b() {
1085         # FIXME. ~grev
1086         setup
1087         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1088                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1089
1090         facet_failover $SINGLEMDS
1091         set_conf_param_and_check $SINGLEMDS                             \
1092                 "$LCTL get_param -n mdt.$device.identity_acquire_expire" \
1093                 "$device.mdt.identity_acquire_expire" ||
1094                 error "set_conf_param_and_check $SINGLEMDS failed"
1095         set_conf_param_and_check client                          \
1096                 "$LCTL get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1097                 "$device.mdc.max_rpcs_in_flight" ||
1098                 error "set_conf_param_and_check client failed"
1099         check_mount
1100         cleanup || error "cleanup failed with $?"
1101 }
1102 run_test 27b "Reacquire MGS lock after failover"
1103
1104 test_28() {
1105         setup
1106         TEST="$LCTL get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1107         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1108         ORIG=$($TEST)
1109         FINAL=$(($ORIG + 1))
1110         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL ||
1111                 error "first set_conf_param_and_check client failed"
1112         FINAL=$(($FINAL + 1))
1113         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL ||
1114                 error "second set_conf_param_and_check client failed"
1115         umount_client $MOUNT || error "umount_client $MOUNT failed"
1116         mount_client $MOUNT || error "mount_client $MOUNT failed"
1117         RESULT=$($TEST)
1118         if [ $RESULT -ne $FINAL ]; then
1119                 error "New config not seen: wanted $FINAL got $RESULT"
1120         else
1121                 echo "New config success: got $RESULT"
1122         fi
1123         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG ||
1124                 error "third set_conf_param_and_check client failed"
1125         cleanup || error "cleanup failed with rc $?"
1126 }
1127 run_test 28 "permanent parameter setting"
1128
1129 test_28a() { # LU-4221
1130         [[ $(lustre_version_code ost1) -ge $(version_code 2.5.52) ]] ||
1131                 { skip "Need OST version at least 2.5.52" && return 0; }
1132         [ "$(facet_fstype ost1)" = "zfs" ] &&
1133                 skip "LU-4221: no such proc params for ZFS OSTs" && return
1134
1135         local name
1136         local param
1137         local cmd
1138         local old
1139         local new
1140         local device="$FSNAME-OST0000"
1141
1142         setup
1143
1144         # In this test we will set three kinds of proc parameters with
1145         # lctl conf_param:
1146         # 1. the ones moved from the OFD to the OSD, and only their
1147         #    symlinks kept in obdfilter
1148         # 2. non-symlink ones in the OFD
1149         # 3. non-symlink ones in the OSD
1150
1151         # Check 1.
1152         # prepare a symlink parameter in the OFD
1153         name="writethrough_cache_enable"
1154         param="$device.ost.$name"
1155         cmd="$LCTL get_param -n obdfilter.$device.$name"
1156
1157         # conf_param the symlink parameter in the OFD
1158         old=$(do_facet ost1 $cmd)
1159         new=$(((old + 1) % 2))
1160         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1161                 error "lctl conf_param $device.ost.$param=$new failed"
1162
1163         # conf_param the target parameter in the OSD
1164         param="$device.osd.$name"
1165         cmd="$LCTL get_param -n osd-*.$device.$name"
1166         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1167                 error "lctl conf_param $device.osd.$param=$old failed"
1168
1169         # Check 2.
1170         # prepare a non-symlink parameter in the OFD
1171         name="client_cache_seconds"
1172         param="$device.ost.$name"
1173         cmd="$LCTL get_param -n obdfilter.$device.$name"
1174
1175         # conf_param the parameter in the OFD
1176         old=$(do_facet ost1 $cmd)
1177         new=$((old * 2))
1178         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1179                 error "lctl conf_param $device.ost.$param=$new failed"
1180         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1181                 error "lctl conf_param $device.ost.$param=$old failed"
1182
1183         # Check 3.
1184         # prepare a non-symlink parameter in the OSD
1185         name="auto_scrub"
1186         param="$device.osd.$name"
1187         cmd="$LCTL get_param -n osd-*.$device.$name"
1188
1189         # conf_param the parameter in the OSD
1190         old=$(do_facet ost1 $cmd)
1191         new=$(((old + 1) % 2))
1192         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1193                 error "lctl conf_param $device.osd.$param=$new failed"
1194         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1195                 error "lctl conf_param $device.osd.$param=$old failed"
1196
1197         cleanup || error "cleanup failed with $?"
1198 }
1199 run_test 28a "set symlink parameters permanently with conf_param"
1200
1201 test_29() {
1202         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1203         setup > /dev/null 2>&1
1204         start_ost2 || error "Unable to start OST2"
1205         sleep 10
1206
1207         local PARAM="$FSNAME-OST0001.osc.active"
1208         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1209         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1210
1211         ACTV=$($LCTL get_param -n $PROC_ACT)
1212         DEAC=$((1 - $ACTV))
1213         set_conf_param_and_check client \
1214                 "$LCTL get_param -n $PROC_ACT" "$PARAM" $DEAC ||
1215                 error "set_conf_param_and_check client failed"
1216         # also check ost_server_uuid status
1217         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV)
1218         if [ -z "$RESULT" ]; then
1219                 error "Client not deactivated: $($LCTL get_param \
1220                        -n $PROC_UUID)"
1221         else
1222                 echo "Live client success: got $RESULT"
1223         fi
1224
1225         # check MDTs too
1226         wait_osp_active ost ${FSNAME}-OST0001 1 0
1227
1228         # test new client starts deactivated
1229         umount_client $MOUNT || error "umount_client $MOUNT failed"
1230         mount_client $MOUNT || error "mount_client $MOUNT failed"
1231         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1232         if [ -z "$RESULT" ]; then
1233                 error "New client start active: $(lctl get_param -n $PROC_UUID)"
1234         else
1235                 echo "New client success: got $RESULT"
1236         fi
1237
1238         # make sure it reactivates
1239         set_conf_param_and_check client \
1240                 "$LCTL get_param -n $PROC_ACT" "$PARAM" $ACTV ||
1241                 error "lctl get_param $PROC_ACT $PARAM $ACTV failed"
1242
1243         umount_client $MOUNT
1244         stop_ost2 || error "Unable to stop OST2"
1245         cleanup_nocli || error "cleanup_nocli failed with $?"
1246         #writeconf to remove all ost2 traces for subsequent tests
1247         writeconf_or_reformat
1248 }
1249 run_test 29 "permanently remove an OST"
1250
1251 test_30a() {
1252         setup
1253
1254         echo Big config llog
1255         TEST="$LCTL get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1256         ORIG=$($TEST)
1257         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1258         for i in ${LIST[@]}; do
1259                 set_conf_param_and_check client "$TEST" \
1260                         "$FSNAME.llite.max_read_ahead_whole_mb" $i ||
1261                         error "Set $FSNAME.llite.max_read_ahead_whole_mb failed"
1262         done
1263         # make sure client restart still works
1264         umount_client $MOUNT
1265         mount_client $MOUNT || error "mount_client $MOUNT failed"
1266         [ "$($TEST)" -ne "$i" ] &&
1267                 error "Param didn't stick across restart $($TEST) != $i"
1268         pass
1269
1270         echo Erase parameter setting
1271         do_facet mgs "$LCTL conf_param \
1272                       -d $FSNAME.llite.max_read_ahead_whole_mb" ||
1273                 error "Erase param $FSNAME.llite.max_read_ahead_whole_mb failed"
1274         umount_client $MOUNT
1275         mount_client $MOUNT || error "mount_client $MOUNT failed"
1276         FINAL=$($TEST)
1277         echo "deleted (default) value=$FINAL, orig=$ORIG"
1278         # assumes this parameter started at the default value
1279         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1280
1281         cleanup || error "cleanup failed with rc $?"
1282 }
1283 run_test 30a "Big config llog and conf_param deletion"
1284
1285 test_30b() {
1286         setup
1287
1288         local orignids=$($LCTL get_param -n \
1289                 osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1290
1291         local orignidcount=$(echo "$orignids" | wc -w)
1292
1293         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1294         # numerical part of it. Hopefully that's not already a failover address
1295         # for the server.
1296         local OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | \
1297                 awk '{print $1}')
1298         local ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1299         local NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1300         local NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1301         echo "Using fake nid $NEW"
1302
1303         local TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1304                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1305         set_conf_param_and_check client "$TEST" \
1306                 "$FSNAME-OST0000.failover.node" $NEW ||
1307                 error "didn't add failover nid $NEW"
1308         local NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1309                 grep failover_nids)
1310         echo $NIDS
1311         local NIDCOUNT=$(echo "$NIDS" | wc -w)
1312         echo "should have $((orignidcount + 1)) entries \
1313                 in failover nids string, have $NIDCOUNT"
1314         [ $NIDCOUNT -eq $((orignidcount + 1)) ] ||
1315                 error "Failover nid not added"
1316
1317         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
1318                 error "conf_param delete failed"
1319         umount_client $MOUNT
1320         mount_client $MOUNT || error "mount_client $MOUNT failed"
1321
1322         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1323                 grep failover_nids)
1324         echo $NIDS
1325         NIDCOUNT=$(echo "$NIDS" | wc -w)
1326         echo "only $orignidcount final entries should remain \
1327                 in failover nids string, have $NIDCOUNT"
1328         [ $NIDCOUNT -eq $orignidcount ] || error "Failover nids not removed"
1329
1330         cleanup || error "cleanup failed with rc $?"
1331 }
1332 run_test 30b "Remove failover nids"
1333
1334 test_31() { # bug 10734
1335         # ipaddr must not exist
1336         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1337         cleanup || error "cleanup failed with rc $?"
1338 }
1339 run_test 31 "Connect to non-existent node (shouldn't crash)"
1340
1341
1342 T32_QID=60000
1343 T32_BLIMIT=40960 # Kbytes
1344 T32_ILIMIT=4
1345
1346 #
1347 # This is not really a test but a tool to create new disk
1348 # image tarballs for the upgrade tests.
1349 #
1350 # Disk image tarballs should be created on single-node
1351 # clusters by running this test with default configurations
1352 # plus a few mandatory environment settings that are verified
1353 # at the beginning of the test.
1354 #
1355 test_32newtarball() {
1356         local version
1357         local dst=.
1358         local src=/etc/rc.d
1359         local tmp=$TMP/t32_image_create
1360         local server_version=$(lustre_version_code $SINGLEMDS)
1361         local remote_dir
1362         local striped_dir
1363         local pushd_dir
1364
1365         if [ $FSNAME != t32fs -o \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o \
1366              $OSTCOUNT -ne 1 -o -z "$OSTDEV1" ]; then
1367                 error "Needs FSNAME=t32fs MDSCOUNT=2 "                  \
1368                       "MDSDEV1=<nonexistent_file>"                      \
1369                       "MDSDEV2=<nonexistent_file>"                      \
1370                       "(or MDSDEV, in the case of b1_8)"                \
1371                       "OSTCOUNT=1 OSTDEV1=<nonexistent_file>"
1372         fi
1373
1374         mkdir $tmp || {
1375                 echo "Found stale $tmp"
1376                 return 1
1377         }
1378
1379         mkdir $tmp/src || return 1
1380         tar cf - -C $src . | tar xf - -C $tmp/src
1381         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1382                 count=$(($T32_BLIMIT / 1024 / 4))
1383         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1384
1385         # format ost with comma-separated NIDs to verify LU-4460
1386         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
1387         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1388
1389         setupall
1390
1391         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1392                 $LFS quotacheck -ug /mnt/$FSNAME
1393         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1394                 /mnt/$FSNAME
1395
1396         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1397
1398         if [[ $MDSCOUNT -ge 2 ]]; then
1399                 remote_dir=/mnt/$FSNAME/remote_dir
1400                 $LFS mkdir -i 1 $remote_dir
1401                 tar cf - -C $tmp/src . | tar xf - -C $remote_dir
1402
1403                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1404                         striped_dir=/mnt/$FSNAME/striped_dir_old
1405                         $LFS mkdir -i 1 -c 2 $striped_dir
1406                         tar cf - -C $tmp/src . | tar xf - -C $striped_dir
1407                 fi
1408         fi
1409
1410         stopall
1411
1412         mkdir $tmp/img || return 1
1413
1414         setupall
1415
1416         pushd_dir=/mnt/$FSNAME
1417         if [[ $MDSCOUNT -ge 2 ]]; then
1418                 pushd_dir=$remote_dir
1419                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1420                         pushd $striped_dir
1421                         ls -Rni --time-style=+%s >$tmp/img/list2
1422                         popd
1423                 fi
1424         fi
1425
1426         pushd $pushd_dir
1427         ls -Rni --time-style=+%s >$tmp/img/list
1428         find ! -name .lustre -type f -exec sha1sum {} \; |
1429                 sort -k 2 >$tmp/img/sha1sums
1430         popd
1431         $LCTL get_param -n version | head -n 1 |
1432                 sed -e 's/^lustre: *//' >$tmp/img/commit
1433
1434         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1435                 $LFS quotaon -ug /mnt/$FSNAME
1436         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1437         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1438                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1439                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1440                 | tr -d "*" > $tmp/img/bspace
1441         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1442                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1443                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1444                 | tr -d "*" > $tmp/img/ispace
1445         echo $T32_BLIMIT > $tmp/img/blimit
1446         echo $T32_ILIMIT > $tmp/img/ilimit
1447
1448         stopall
1449
1450         pushd $tmp/src
1451         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1452         popd
1453
1454         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1455                 echo "Data verification failed"
1456         fi
1457
1458         uname -r >$tmp/img/kernel
1459         uname -m >$tmp/img/arch
1460
1461         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1462         for num in $(seq 2 $MDSCOUNT); do
1463                 local devname=$(mdsdevname $num)
1464                 local facet=mds$num
1465                 [[ $(facet_fstype $facet) != zfs ]] ||
1466                         devname=$(mdsvdevname $num)
1467                 mv $devname $tmp/img
1468         done
1469         mv $OSTDEV1 $tmp/img
1470
1471         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1472                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1473         dst=$(cd $dst; pwd)
1474         pushd $tmp/img
1475         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1476         popd
1477
1478         rm -r $tmp
1479 }
1480 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1481
1482 #
1483 # The list of applicable tarballs is returned via the caller's
1484 # variable "tarballs".
1485 #
1486 t32_check() {
1487         local node=$(facet_active_host $SINGLEMDS)
1488         local r="do_node $node"
1489
1490         if [ "$CLIENTONLY" ]; then
1491                 skip "Client-only testing"
1492                 exit 0
1493         fi
1494
1495         if ! $r which $TUNEFS; then
1496                 skip_env "tunefs.lustre required on $node"
1497                 exit 0
1498         fi
1499
1500         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1501
1502         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 \
1503                    -name \'disk*-$IMGTYPE.tar.bz2\')
1504
1505         if [ -z "$tarballs" ]; then
1506                 skip "No applicable tarballs found"
1507                 exit 0
1508         fi
1509 }
1510
1511 t32_test_cleanup() {
1512         local tmp=$TMP/t32
1513         local facet=$SINGLEMDS
1514         local fstype=$(facet_fstype $facet)
1515         local rc=$?
1516
1517         if $shall_cleanup_lustre; then
1518                 umount $tmp/mnt/lustre || rc=$?
1519         fi
1520         if $shall_cleanup_mdt; then
1521                 $r $UMOUNT $tmp/mnt/mdt || rc=$?
1522         fi
1523         if $shall_cleanup_mdt1; then
1524                 $r $UMOUNT $tmp/mnt/mdt1 || rc=$?
1525         fi
1526         if $shall_cleanup_ost; then
1527                 $r $UMOUNT $tmp/mnt/ost || rc=$?
1528         fi
1529
1530         $r rm -rf $tmp
1531         rm -rf $tmp
1532         if [[ $fstype == zfs ]]; then
1533                 local poolname
1534                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1535
1536                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1537
1538                 for poolname in $poolname_list; do
1539                         destroy_zpool $facet $poolname
1540                 done
1541         fi
1542         combined_mgs_mds || start_mgs || rc=$?
1543         return $rc
1544 }
1545
1546 t32_bits_per_long() {
1547         #
1548         # Yes, this is not meant to be perfect.
1549         #
1550         case $1 in
1551                 ppc64|x86_64)
1552                         echo -n 64;;
1553                 i*86)
1554                         echo -n 32;;
1555         esac
1556 }
1557
1558 t32_reload_modules() {
1559         local node=$1
1560         local all_removed=false
1561         local i=0
1562
1563         while ((i < 20)); do
1564                 echo "Unloading modules on $node: Attempt $i"
1565                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1566                         all_removed=true
1567                 do_rpc_nodes $node check_mem_leak || return 1
1568                 if $all_removed; then
1569                         do_rpc_nodes $node load_modules
1570                         return 0
1571                 fi
1572                 sleep 5
1573                 i=$((i + 1))
1574         done
1575         echo "Unloading modules on $node: Given up"
1576         return 1
1577 }
1578
1579 t32_wait_til_devices_gone() {
1580         local node=$1
1581         local devices
1582         local loops
1583         local i=0
1584
1585         echo wait for devices to go
1586         while ((i < 20)); do
1587                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1588                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1589                 ((devices == 0 && loops == 0)) && return 0
1590                 sleep 5
1591                 i=$((i + 1))
1592         done
1593         echo "waiting for dev on $node: dev $devices loop $loops given up"
1594         do_rpc_nodes $node "losetup -a"
1595         do_rpc_nodes $node "$LCTL device_list"
1596         return 1
1597 }
1598
1599 t32_verify_quota() {
1600         local node=$1
1601         local fsname=$2
1602         local mnt=$3
1603         local fstype=$(facet_fstype $SINGLEMDS)
1604         local qval
1605         local cmd
1606
1607         # LU-2435: if the underlying zfs doesn't support userobj_accounting,
1608         # lustre will estimate the object count usage. This fails quota
1609         # verification in 32b. The object quota usage should be accurate after
1610         # zfs-0.7.0 is released.
1611         [ $fstype == "zfs" ] && {
1612                 local zfs_version=$(do_node $node cat /sys/module/zfs/version)
1613
1614                 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] && {
1615                         echo "Skip quota verify for zfs: $zfs_version"
1616                         return 0
1617                 }
1618         }
1619
1620         $LFS quota -u $T32_QID -v $mnt
1621
1622         qval=$($LFS quota -v -u $T32_QID $mnt |
1623                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1624                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1625                 | tr -d "*")
1626         [ $qval -eq $img_bspace ] || {
1627                 echo "bspace, act:$qval, exp:$img_bspace"
1628                 return 1
1629         }
1630
1631         qval=$($LFS quota -v -u $T32_QID $mnt |
1632                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1633                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1634                 | tr -d "*")
1635         [ $qval -eq $img_ispace ] || {
1636                 echo "ispace, act:$qval, exp:$img_ispace"
1637                 return 1
1638         }
1639
1640         qval=$($LFS quota -v -u $T32_QID $mnt |
1641                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1642                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1643                 | tr -d "*")
1644         [ $qval -eq $img_blimit ] || {
1645                 echo "blimit, act:$qval, exp:$img_blimit"
1646                 return 1
1647         }
1648
1649         qval=$($LFS quota -v -u $T32_QID $mnt |
1650                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1651                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1652                 | tr -d "*")
1653         [ $qval -eq $img_ilimit ] || {
1654                 echo "ilimit, act:$qval, exp:$img_ilimit"
1655                 return 1
1656         }
1657
1658         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1659         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1660         cmd=$cmd.quota_slave.enabled
1661         wait_update $node "$cmd" "ug" || {
1662                 echo "Enable mdt quota failed"
1663                 return 1
1664         }
1665
1666         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1667         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1668         cmd=$cmd.quota_slave.enabled
1669         wait_update $node "$cmd" "ug" || {
1670                 echo "Enable ost quota failed"
1671                 return 1
1672         }
1673
1674         chmod 0777 $mnt
1675         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1676                 bs=1M count=$((img_blimit / 1024)) oflag=sync && {
1677                 echo "Write succeed, but expect -EDQUOT"
1678                 return 1
1679         }
1680         rm -f $mnt/t32_qf_new
1681
1682         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1683                 $img_ilimit && {
1684                 echo "Create succeed, but expect -EDQUOT"
1685                 return 1
1686         }
1687         unlinkmany $mnt/t32_qf_ $img_ilimit
1688
1689         return 0
1690 }
1691
1692 t32_test() {
1693         local tarball=$1
1694         local writeconf=$2
1695         local dne_upgrade=${dne_upgrade:-"no"}
1696         local ff_convert=${ff_convert:-"no"}
1697         local shall_cleanup_mdt=false
1698         local shall_cleanup_mdt1=false
1699         local shall_cleanup_ost=false
1700         local shall_cleanup_lustre=false
1701         local mdt2_is_available=false
1702         local node=$(facet_active_host $SINGLEMDS)
1703         local r="do_node $node"
1704         local tmp=$TMP/t32
1705         local img_commit
1706         local img_kernel
1707         local img_arch
1708         local img_bspace
1709         local img_ispace
1710         local img_blimit
1711         local img_ilimit
1712         local fsname=t32fs
1713         local nid
1714         local mopts
1715         local uuid
1716         local nrpcs_orig
1717         local nrpcs
1718         local list
1719         local fstype=$(facet_fstype $SINGLEMDS)
1720         local mdt_dev=$tmp/mdt
1721         local mdt2_dev=$tmp/mdt2
1722         local ost_dev=$tmp/ost
1723         local stripe_index
1724         local stripe_count
1725         local dir
1726
1727         combined_mgs_mds || stop_mgs || error "Unable to stop MGS"
1728         trap 'trap - RETURN; t32_test_cleanup' RETURN
1729
1730         load_modules
1731         nid=$($r $LCTL list_nids | head -1)
1732
1733         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
1734         $r mkdir -p $tmp/mnt/{mdt,mdt1,ost}
1735         $r tar xjvf $tarball -S -C $tmp || {
1736                 error_noexit "Unpacking the disk image tarball"
1737                 return 1
1738         }
1739         img_commit=$($r cat $tmp/commit)
1740         img_kernel=$($r cat $tmp/kernel)
1741         img_arch=$($r cat $tmp/arch)
1742         img_bspace=$($r cat $tmp/bspace)
1743         img_ispace=$($r cat $tmp/ispace)
1744
1745         # older images did not have "blimit" and "ilimit" files
1746         # use old values for T32_BLIMIT and T32_ILIMIT
1747         $r test -f $tmp/blimit && img_blimit=$($r cat $tmp/blimit) ||
1748                 img_blimit=20480
1749         $r test -f $tmp/ilimit && img_ilimit=$($r cat $tmp/ilimit) ||
1750                 img_ilimit=2
1751
1752         echo "Upgrading from $(basename $tarball), created with:"
1753         echo "  Commit: $img_commit"
1754         echo "  Kernel: $img_kernel"
1755         echo "    Arch: $img_arch"
1756         echo "OST version: $(lustre_build_version ost1)"
1757
1758         # The conversion can be made only when both of the following
1759         # conditions are satisfied:
1760         # - ost device img version < 2.3.64
1761         # - ost server version >= 2.5
1762         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1763                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1764                         ff_convert="no"
1765
1766         ! $r test -f $mdt2_dev || mdt2_is_available=true
1767
1768         if [[ $fstype == zfs ]]; then
1769                 # import pool first
1770                 local poolname
1771                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1772
1773                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1774
1775                 for poolname in $poolname_list; do
1776                         $r "modprobe zfs;
1777                                 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1778                                 $ZPOOL import -f -d $tmp $poolname"
1779                 done
1780
1781                 # upgrade zpool to latest supported features, including
1782                 # dnode quota accounting in 0.7.0
1783                 $r "$ZPOOL upgrade -a"
1784
1785                 mdt_dev=t32fs-mdt1/mdt1
1786                 ost_dev=t32fs-ost1/ost1
1787                 ! $mdt2_is_available || mdt2_dev=t32fs-mdt2/mdt2
1788                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1789                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1790                                 error_noexit "import zfs pool failed"
1791                                 return 1
1792                         }
1793         fi
1794
1795         $r $LCTL set_param debug="$PTLDEBUG"
1796
1797         $r $TUNEFS --dryrun $mdt_dev || {
1798                 $r losetup -a
1799                 error_noexit "tunefs.lustre before mounting the MDT"
1800                 return 1
1801         }
1802
1803         if $mdt2_is_available; then
1804                 $r $TUNEFS --dryrun $mdt2_dev || {
1805                         $r losetup -a
1806                         error_noexit "tunefs.lustre before mounting the MDT"
1807                         return 1
1808                 }
1809         fi
1810
1811         if [ "$writeconf" ]; then
1812                 mopts=writeconf
1813                 if [ $fstype == "ldiskfs" ]; then
1814                         mopts="loop,$mopts"
1815                         $r $TUNEFS --quota $mdt_dev || {
1816                                 $r losetup -a
1817                                 error_noexit "Enable mdt quota feature"
1818                                 return 1
1819                         }
1820                         if $mdt2_is_available; then
1821                                 $r $TUNEFS --quota $mdt2_dev || {
1822                                         $r losetup -a
1823                                         error_noexit "Enable mdt quota feature"
1824                                         return 1
1825                                 }
1826                         fi
1827                 fi
1828         else
1829                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1830                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1831                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1832                                 "(Need MGS version at least 2.3.59)"; return 0; }
1833
1834                         local osthost=$(facet_active_host ost1)
1835                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1836
1837                         mopts=nosvc
1838                         if [ $fstype == "ldiskfs" ]; then
1839                                 mopts="loop,$mopts"
1840                         fi
1841                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1842                         $r $LCTL replace_nids $fsname-OST0000 $ostnid
1843                         $r $LCTL replace_nids $fsname-MDT0000 $nid
1844                         $r $UMOUNT $tmp/mnt/mdt
1845                 fi
1846
1847                 mopts=exclude=$fsname-OST0000
1848                 if [ $fstype == "ldiskfs" ]; then
1849                         mopts="loop,$mopts"
1850                 fi
1851         fi
1852
1853         t32_wait_til_devices_gone $node
1854
1855         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1856                 $r losetup -a
1857                 error_noexit "Mounting the MDT"
1858                 return 1
1859         }
1860         shall_cleanup_mdt=true
1861
1862         if $mdt2_is_available; then
1863                 mopts=mgsnode=$nid,$mopts
1864                 $r $MOUNT_CMD -o $mopts $mdt2_dev $tmp/mnt/mdt1 || {
1865                         $r losetup -a
1866                         error_noexit "Mounting the MDT"
1867                         return 1
1868                 }
1869
1870                 echo "mount new MDT....$mdt2_dev"
1871                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1872                         error_noexit "enable remote dir create failed"
1873
1874                 shall_cleanup_mdt1=true
1875         elif [ "$dne_upgrade" != "no" ]; then
1876                 local fs2mdsdev=$(mdsdevname 1_2)
1877                 local fs2mdsvdev=$(mdsvdevname 1_2)
1878
1879                 echo "mkfs new MDT on ${fs2mdsdev}...."
1880                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1881                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1882                 fi
1883
1884                 add $SINGLEMDS $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1885                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1886                         error_noexit "Mkfs new MDT failed"
1887                         return 1
1888                 }
1889
1890                 [[ $(facet_fstype mds1) != zfs ]] || import_zpool mds1
1891
1892                 $r $TUNEFS --dryrun $fs2mdsdev || {
1893                         error_noexit "tunefs.lustre before mounting the MDT"
1894                         return 1
1895                 }
1896
1897                 echo "mount new MDT....$fs2mdsdev"
1898                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1899                         error_noexit "mount mdt1 failed"
1900                         return 1
1901                 }
1902
1903                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1904                         error_noexit "enable remote dir create failed"
1905
1906                 shall_cleanup_mdt1=true
1907         fi
1908
1909         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1910                 error_noexit "Getting MDT UUID"
1911                 return 1
1912         }
1913         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1914                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1915                 return 1
1916         fi
1917
1918         $r $TUNEFS --dryrun $ost_dev || {
1919                 error_noexit "tunefs.lustre before mounting the OST"
1920                 return 1
1921         }
1922         if [ "$writeconf" ]; then
1923                 mopts=mgsnode=$nid,$writeconf
1924                 if [ $fstype == "ldiskfs" ]; then
1925                         mopts="loop,$mopts"
1926                         $r $TUNEFS --quota $ost_dev || {
1927                                 $r losetup -a
1928                                 error_noexit "Enable ost quota feature"
1929                                 return 1
1930                         }
1931                 fi
1932         else
1933                 mopts=mgsnode=$nid
1934                 if [ $fstype == "ldiskfs" ]; then
1935                         mopts="loop,$mopts"
1936                 fi
1937         fi
1938
1939         $r $MOUNT_CMD -onomgs -o$mopts $ost_dev $tmp/mnt/ost || {
1940                 error_noexit "Mounting the OST"
1941                 return 1
1942         }
1943         shall_cleanup_ost=true
1944
1945         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1946                 error_noexit "Getting OST UUID"
1947                 return 1
1948         }
1949         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1950                 error_noexit "Unexpected OST UUID: \"$uuid\""
1951                 return 1
1952         fi
1953
1954         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1955                 error_noexit "Setting \"max_dirty_mb\""
1956                 return 1
1957         }
1958         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1959                 error_noexit "Setting OST \"failover.node\""
1960                 return 1
1961         }
1962         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1963                 error_noexit "Setting \"max_rpcs_in_flight\""
1964                 return 1
1965         }
1966         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1967                 error_noexit "Setting MDT \"failover.node\""
1968                 return 1
1969         }
1970         $r $LCTL pool_new $fsname.interop || {
1971                 error_noexit "Setting \"interop\""
1972                 return 1
1973         }
1974         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1975                 error_noexit "Setting \"lov.stripesize\""
1976                 return 1
1977         }
1978         $r $LCTL conf_param $fsname-MDT0000.mdd.atime_diff=70 || {
1979                 error_noexit "Setting \"mdd.atime_diff\""
1980                 return 1
1981         }
1982
1983         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1984                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1985                         error_noexit "Start OI scrub on OST0"
1986                         return 1
1987                 }
1988
1989                 # The oi_scrub should be on ost1, but for test_32(),
1990                 # all on the SINGLEMDS.
1991                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1992                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1993                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1994                         error_noexit "Failed to get the expected 'completed'"
1995                         return 1
1996                 }
1997
1998                 local UPDATED=$($r $LCTL get_param -n \
1999                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
2000                                 awk '/^updated/ { print $2 }')
2001                 [ $UPDATED -ge 1 ] || {
2002                         error_noexit "Only $UPDATED objects have been converted"
2003                         return 1
2004                 }
2005         fi
2006
2007         if [ "$dne_upgrade" != "no" ]; then
2008                 $r $LCTL conf_param \
2009                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
2010                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2011                         return 1
2012                 }
2013                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
2014                         error_noexit "Setting MDT1 \"failover.node\""
2015                         return 1
2016                 }
2017                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
2018                         error_noexit "Setting MDT1 \"lov.stripesize\""
2019                         return 1
2020                 }
2021         fi
2022
2023         if [ "$writeconf" ]; then
2024                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
2025                         error_noexit "Mounting the client"
2026                         return 1
2027                 }
2028
2029                 shall_cleanup_lustre=true
2030                 $r $LCTL set_param debug="$PTLDEBUG"
2031
2032                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
2033                         error_noexit "verify quota failed"
2034                         return 1
2035                 }
2036
2037                 if $r test -f $tmp/list; then
2038                         #
2039                         # There is not a Test Framework API to copy files to or
2040                         # from a remote node.
2041                         #
2042                         # LU-2393 - do both sorts on same node to ensure locale
2043                         # is identical
2044                         local list_file=$tmp/list
2045
2046                         if $mdt2_is_available; then
2047                                 if [[ -d $tmp/mnt/lustre/striped_dir_old ]] &&
2048                                    $r test -f $tmp/list2; then
2049                                         list_file=$tmp/list2
2050                                         pushd $tmp/mnt/lustre/striped_dir_old
2051                                 else
2052                                         pushd $tmp/mnt/lustre/remote_dir
2053                                 fi
2054                         else
2055                                 pushd $tmp/mnt/lustre
2056                         fi
2057                         $r cat $list_file | sort -k 6 >$tmp/list.orig
2058                         ls -Rni --time-style=+%s | sort -k 6 |
2059                                 sed 's/\. / /' >$tmp/list || {
2060                                 error_noexit "ls"
2061                                 return 1
2062                         }
2063                         popd
2064                         #
2065                         # 32-bit and 64-bit clients use different algorithms to
2066                         # convert FIDs into inode numbers.  Hence, remove the
2067                         # inode numbers from the lists, if the original list was
2068                         # created on an architecture with different number of
2069                         # bits per "long".
2070                         #
2071                         if [ $(t32_bits_per_long $(uname -m)) != \
2072                                 $(t32_bits_per_long $img_arch) ]; then
2073                                 echo "Different number of bits per \"long\"" \
2074                                      "from the disk image"
2075                                 for list in list.orig list; do
2076                                         sed -i -e 's/^[0-9]\+[ \t]\+//' \
2077                                                   $tmp/$list
2078                                 done
2079                         fi
2080                         if ! diff -ub $tmp/list.orig $tmp/list; then
2081                                 error_noexit "list verification failed"
2082                                 return 1
2083                         fi
2084                 else
2085                         echo "list verification skipped"
2086                 fi
2087
2088                 if [ "$dne_upgrade" != "no" ]; then
2089                         $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/striped_dir || {
2090                                 error_noexit "set striped dir failed"
2091                                 return 1
2092                         }
2093
2094                         $LFS setdirstripe -D -c2 $tmp/mnt/lustre/striped_dir
2095
2096                         pushd $tmp/mnt/lustre
2097                         tar -cf - . --exclude=./striped_dir \
2098                                     --exclude=./striped_dir_old \
2099                                     --exclude=./remote_dir |
2100                                 tar -xvf - -C striped_dir 1>/dev/null || {
2101                                 error_noexit "cp to striped dir failed"
2102                                 return 1
2103                         }
2104                         popd
2105                 fi
2106
2107                 # If it is upgrade from DNE (2.5), then rename the remote dir,
2108                 # which is created in 2.5 to striped dir.
2109                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]]; then
2110                         stripe_index=$($LFS getdirstripe -i     \
2111                                        $tmp/mnt/lustre/remote_dir)
2112
2113                         [[ $stripe_index -eq 1 ]] || {
2114                                 error_noexit "get index \"$stripe_index\"" \
2115                                              "from remote dir failed"
2116                                 return 1
2117                         }
2118                         mv $tmp/mnt/lustre/remote_dir   \
2119                                 $tmp/mnt/lustre/striped_dir/ || {
2120                                 error_noexit "mv remote dir failed"
2121                                 return 1
2122                         }
2123                 fi
2124
2125                 # If it is upgraded from DNE (2.7), then move the striped dir
2126                 # which was created in 2.7 to the new striped dir.
2127                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]] &&
2128                         [[ -d $tmp/mnt/lustre/striped_dir_old ]]; then
2129                         stripe_count=$($LFS getdirstripe -c     \
2130                                        $tmp/mnt/lustre/striped_dir_old)
2131                         [[ $stripe_count -eq 2 ]] || {
2132                                 error_noexit "get count $stripe_count" \
2133                                              "from striped dir failed"
2134                                 return 1
2135                         }
2136                         mv $tmp/mnt/lustre/striped_dir_old      \
2137                                 $tmp/mnt/lustre/striped_dir/ || {
2138                                 error_noexit "mv striped dir failed"
2139                                 return 1
2140                         }
2141                 fi
2142
2143                 sync; sleep 5; sync
2144                 $r $LCTL set_param -n osd*.*.force_sync=1
2145                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
2146                         error_noexit "dd failed"
2147                         return 1
2148                 }
2149                 rm -rf $tmp/mnt/lustre/tmp_file || {
2150                         error_noexit "rm failed"
2151                         return 1
2152                 }
2153
2154                 if $r test -f $tmp/sha1sums; then
2155                         # LU-2393 - do both sorts on same node to ensure locale
2156                         # is identical
2157                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
2158                         if [ "$dne_upgrade" != "no" ]; then
2159                                 pushd $tmp/mnt/lustre/striped_dir
2160                         else
2161                                 pushd $tmp/mnt/lustre
2162                         fi
2163
2164                         find ! -path "*remote_dir*" ! -path "*striped_dir*" \
2165                                 ! -name .lustre -type f -exec sha1sum {} \; |
2166                                 sort -k 2 >$tmp/sha1sums || {
2167                                 popd
2168                                 error_noexit "sha1sum"
2169                                 return 1
2170                         }
2171                         popd
2172                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
2173                                 error_noexit "sha1sum verification failed"
2174                                 return 1
2175                         fi
2176
2177                         # if upgrade from DNE(2.5), then check remote directory
2178                         # if upgrade from DNE(2.7), then check striped directory
2179                         if $mdt2_is_available &&
2180                            [[ "$dne_upgrade" != "no" ]]; then
2181                                 local new_dir="$tmp/mnt/lustre/striped_dir"
2182                                 local striped_dir_old="$new_dir/striped_dir_old"
2183
2184                                 local dir_list="$new_dir/remote_dir"
2185                                 [[ ! -d $triped_dir_old ]] ||
2186                                         dir_list+=" $striped_dir_old"
2187
2188                                 for dir in $dir_list; do
2189                                         pushd $dir
2190                                         find ! -name .lustre -type f    \
2191                                                 -exec sha1sum {} \; |
2192                                                 sort -k 2 >$tmp/sha1sums || {
2193                                                         popd
2194                                                         error_noexit "sha1sum"
2195                                                         return 1
2196                                                 }
2197                                         popd
2198                                         if ! diff -ub $tmp/sha1sums.orig \
2199                                                 $tmp/sha1sums; then
2200                                                 error_noexit "sha1sum $dir" \
2201                                                              "failed"
2202                                                 return 1
2203                                         fi
2204                                 done
2205                         fi
2206                 else
2207                         echo "sha1sum verification skipped"
2208                 fi
2209
2210                 if [ "$dne_upgrade" != "no" ]; then
2211                         rm -rf $tmp/mnt/lustre/striped_dir || {
2212                                 error_noexit "remove remote dir failed"
2213                                 return 1
2214                         }
2215                 fi
2216
2217                 # migrate files/dirs to remote MDT, then move them back
2218                 if [ $(lustre_version_code mds1) -ge $(version_code 2.7.50) -a \
2219                      $dne_upgrade != "no" ]; then
2220                         $r $LCTL set_param -n   \
2221                                 mdt.${fsname}*.enable_remote_dir=1 2>/dev/null
2222
2223                         echo "test migration"
2224                         pushd $tmp/mnt/lustre
2225                         for dir in $(find ! -name .lustre ! -name . -type d); do
2226                                 mdt_index=$($LFS getdirstripe -i $dir)
2227                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2228                                 if [ $mdt_index = 0 -a $stripe_cnt -le 1 ]; then
2229                                         $LFS mv -M 1 $dir || {
2230                                         popd
2231                                         error_noexit "migrate MDT1 failed"
2232                                         return 1
2233                                 }
2234                                 fi
2235                         done
2236
2237                         for dir in $(find ! -name . ! -name .lustre -type d); do
2238                                 mdt_index=$($LFS getdirstripe -i $dir)
2239                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2240                                 if [ $mdt_index = 1 -a $stripe_cnt -le 1 ]; then
2241                                         $LFS mv -M 0 $dir || {
2242                                         popd
2243                                         error_noexit "migrate MDT0 failed"
2244                                         return 1
2245                                 }
2246                                 fi
2247                         done
2248                         popd
2249                 fi
2250
2251                 #
2252                 # When adding new data verification tests, please check for
2253                 # the presence of the required reference files first, like
2254                 # the "sha1sums" and "list" tests above, to avoid the need to
2255                 # regenerate every image for each test addition.
2256                 #
2257
2258                 nrpcs_orig=$($LCTL get_param \
2259                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
2260                         error_noexit "Getting \"max_rpcs_in_flight\""
2261                         return 1
2262                 }
2263                 nrpcs=$((nrpcs_orig + 5))
2264                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
2265                         error_noexit "Changing \"max_rpcs_in_flight\""
2266                         return 1
2267                 }
2268                 wait_update $HOSTNAME "$LCTL get_param \
2269                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
2270                         error_noexit "Verifying \"max_rpcs_in_flight\""
2271                         return 1
2272                 }
2273
2274                 umount $tmp/mnt/lustre || {
2275                         error_noexit "Unmounting the client"
2276                         return 1
2277                 }
2278                 shall_cleanup_lustre=false
2279         else
2280                 if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
2281                         $r $UMOUNT $tmp/mnt/mdt1 || {
2282                                 error_noexit "Unmounting the MDT2"
2283                                 return 1
2284                         }
2285                         shall_cleanup_mdt1=false
2286                 fi
2287
2288                 $r $UMOUNT $tmp/mnt/mdt || {
2289                         error_noexit "Unmounting the MDT"
2290                         return 1
2291                 }
2292                 shall_cleanup_mdt=false
2293
2294                 $r $UMOUNT $tmp/mnt/ost || {
2295                         error_noexit "Unmounting the OST"
2296                         return 1
2297                 }
2298                 shall_cleanup_ost=false
2299
2300                 t32_reload_modules $node || {
2301                         error_noexit "Reloading modules"
2302                         return 1
2303                 }
2304
2305                 if [[ $fstype == zfs ]]; then
2306                         local poolname=t32fs-mdt1
2307                         $r "modprobe zfs;
2308                             $ZPOOL list -H $poolname >/dev/null 2>&1 ||
2309                                 $ZPOOL import -f -d $tmp $poolname"
2310
2311                         # upgrade zpool to latest supported features,
2312                         # including dnode quota accounting in 0.7.0
2313                         $r "$ZPOOL upgrade $poolname"
2314                 fi
2315
2316                 # mount a second time to make sure we didnt leave upgrade flag on
2317                 $r $TUNEFS --dryrun $mdt_dev || {
2318                         $r losetup -a
2319                         error_noexit "tunefs.lustre before remounting the MDT"
2320                         return 1
2321                 }
2322
2323                 mopts=exclude=$fsname-OST0000
2324                 if [ $fstype == "ldiskfs" ]; then
2325                         mopts="loop,$mopts"
2326                 fi
2327                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2328                         error_noexit "Remounting the MDT"
2329                         return 1
2330                 }
2331                 shall_cleanup_mdt=true
2332         fi
2333 }
2334
2335 test_32a() {
2336         local tarballs
2337         local tarball
2338         local rc=0
2339
2340         t32_check
2341         for tarball in $tarballs; do
2342                 t32_test $tarball || let "rc += $?"
2343         done
2344         return $rc
2345 }
2346 run_test 32a "Upgrade (not live)"
2347
2348 test_32b() {
2349         local tarballs
2350         local tarball
2351         local rc=0
2352
2353         t32_check
2354         for tarball in $tarballs; do
2355                 t32_test $tarball writeconf || let "rc += $?"
2356         done
2357         return $rc
2358 }
2359 run_test 32b "Upgrade with writeconf"
2360
2361 test_32c() {
2362         local tarballs
2363         local tarball
2364         local rc=0
2365
2366         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2367         t32_check
2368         for tarball in $tarballs; do
2369                 # Do not support 1_8 and 2_1 direct upgrade to DNE2 anymore */
2370                 echo $tarball | grep "1_8" && continue
2371                 echo $tarball | grep "2_1" && continue
2372                 load_modules
2373                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2374         done
2375         return $rc
2376 }
2377 run_test 32c "dne upgrade test"
2378
2379 test_32d() {
2380         local tarballs
2381         local tarball
2382         local rc=0
2383
2384         t32_check
2385         for tarball in $tarballs; do
2386                 ff_convert=yes t32_test $tarball || rc=$?
2387         done
2388         return $rc
2389 }
2390 run_test 32d "convert ff test"
2391
2392 test_33a() { # bug 12333, was test_33
2393         local FSNAME2=test-123
2394         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2395         local mkfsoptions
2396
2397         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2398
2399         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2400                 local dev=${SINGLEMDS}_dev
2401                 local MDSDEV=${!dev}
2402                 is_blkdev $SINGLEMDS $MDSDEV &&
2403                         skip_env "mixed loopback and real device not working" &&
2404                         return
2405         fi
2406
2407         local fs2mdsdev=$(mdsdevname 1_2)
2408         local fs2ostdev=$(ostdevname 1_2)
2409         local fs2mdsvdev=$(mdsvdevname 1_2)
2410         local fs2ostvdev=$(ostvdevname 1_2)
2411
2412         if [ $(facet_fstype mds1) == ldiskfs ]; then
2413                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2414         fi
2415
2416         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2417                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
2418         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2419                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2420                 $fs2ostvdev || exit 10
2421
2422         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2423         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2424         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" ||
2425                 error "$LCTL conf_param $FSNAME2.sys.timeout=200 failed"
2426         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2427         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2428         echo "ok."
2429
2430         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
2431         $GETSTRIPE $MOUNT2/hosts || error "$GETSTRIPE $MOUNT2/hosts failed"
2432
2433         umount $MOUNT2
2434         stop fs2ost -f
2435         stop fs2mds -f
2436         cleanup_nocli || error "cleanup_nocli failed with $?"
2437 }
2438 run_test 33a "Mount ost with a large index number"
2439
2440 test_33b() {    # was test_34
2441         setup
2442
2443         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2444         # Drop lock cancelation reply during umount
2445         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2446         do_facet client $LCTL set_param fail_loc=0x80000304
2447         #lctl set_param debug=-1
2448         umount_client $MOUNT
2449         cleanup || error "cleanup failed with $?"
2450 }
2451 run_test 33b "Drop cancel during umount"
2452
2453 test_34a() {
2454         setup
2455         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2456         manual_umount_client
2457         rc=$?
2458         do_facet client killall -USR1 multiop
2459         if [ $rc -eq 0 ]; then
2460                 error "umount not fail!"
2461         fi
2462         sleep 1
2463         cleanup || error "cleanup failed with rc $?"
2464 }
2465 run_test 34a "umount with opened file should be fail"
2466
2467 test_34b() {
2468         setup
2469         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2470         stop_mds || error "Unable to stop MDS"
2471
2472         manual_umount_client --force || error "mtab after failed umount with $?"
2473
2474         cleanup || error "cleanup failed with $?"
2475 }
2476 run_test 34b "force umount with failed mds should be normal"
2477
2478 test_34c() {
2479         setup
2480         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2481         stop_ost || error "Unable to stop OST1"
2482
2483         manual_umount_client --force || error "mtab after failed umount with $?"
2484
2485         cleanup || error "cleanup failed with $?"
2486 }
2487 run_test 34c "force umount with failed ost should be normal"
2488
2489 test_35a() { # bug 12459
2490         setup
2491
2492         DBG_SAVE="`$LCTL get_param -n debug`"
2493         $LCTL set_param debug="ha"
2494
2495         log "Set up a fake failnode for the MDS"
2496         FAKENID="127.0.0.2"
2497         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2498                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2499         do_facet mgs "$LCTL conf_param \
2500                       ${device}.failover.node=$(h2nettype $FAKENID)" ||
2501                 error "Setting ${device}.failover.node=\
2502                        $(h2nettype $FAKENID) failed."
2503
2504         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2505         sleep 10
2506
2507         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2508         $LCTL clear
2509         log "$MSG"
2510         log "Stopping the MDT: $device"
2511         stop_mdt 1 || error "MDT0 stop fail"
2512
2513         df $MOUNT > /dev/null 2>&1 &
2514         DFPID=$!
2515         log "Restarting the MDT: $device"
2516         start_mdt 1 || error "MDT0 start fail"
2517         log "Wait for df ($DFPID) ... "
2518         wait $DFPID
2519         log "done"
2520         $LCTL set_param debug="$DBG_SAVE"
2521
2522         # retrieve from the log the first server that the client tried to
2523         # contact after the connection loss
2524         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2525         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2526                        /import_select_connection.*$device-mdc.* using connection/ {
2527                                 if (start) {
2528                                         if (\\\$NF ~ /$FAKENID/)
2529                                                 print \\\$NF;
2530                                         else
2531                                                 print 0;
2532                                         exit;
2533                                 }
2534                        }" $TMP/lustre-log-$TESTNAME.log`
2535         [ "$NEXTCONN" != "0" ] &&
2536                 error "Tried to connect to ${NEXTCONN} not last active server"
2537         cleanup || error "cleanup failed with $?"
2538         # remove nid settings
2539         writeconf_or_reformat
2540 }
2541 run_test 35a "Reconnect to the last active server first"
2542
2543 test_35b() { # bug 18674
2544         remote_mds || { skip "local MDS" && return 0; }
2545         setup
2546
2547         debugsave
2548         $LCTL set_param debug="ha"
2549         $LCTL clear
2550         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2551         log "$MSG"
2552
2553         log "Set up a fake failnode for the MDS"
2554         FAKENID="127.0.0.2"
2555         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2556                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2557         do_facet mgs "$LCTL conf_param \
2558                       ${device}.failover.node=$(h2nettype $FAKENID)" ||
2559                 error "Set ${device}.failover.node=\
2560                        $(h2nettype $FAKENID) failed"
2561
2562         local at_max_saved=0
2563         # adaptive timeouts may prevent seeing the issue
2564         if at_is_enabled; then
2565                 at_max_saved=$(at_max_get mds)
2566                 at_max_set 0 mds client
2567         fi
2568
2569         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
2570
2571         log "Injecting EBUSY on MDS"
2572         # Setting OBD_FAIL_MDS_RESEND=0x136
2573         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
2574                 error "unable to set param fail_loc=0x80000136"
2575
2576         $LCTL set_param mdc.${FSNAME}*.stats=clear
2577
2578         log "Creating a test file and stat it"
2579         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
2580         stat $MOUNT/$tdir/$tfile
2581
2582         log "Stop injecting EBUSY on MDS"
2583         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
2584                 error "unable to set param fail_loc=0"
2585         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
2586
2587         log "done"
2588         # restore adaptive timeout
2589         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2590
2591         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2592
2593         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
2594                   awk '/mds_connect/{print $2}')
2595
2596         # retrieve from the log if the client has ever tried to
2597         # contact the fake server after the loss of connection
2598         FAILCONN=`awk "BEGIN {ret = 0;}
2599                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2600                                 ret = 1;
2601                                 if (\\\$NF ~ /$FAKENID/) {
2602                                         ret = 2;
2603                                         exit;
2604                                 }
2605                        }
2606                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2607
2608         [ "$FAILCONN" == "0" ] &&
2609                 error "The client reconnection has not been triggered"
2610         [ "$FAILCONN" == "2" ] &&
2611                 error "Primary server busy, client reconnect to failover failed"
2612
2613         # LU-290
2614         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2615         # Reconnects are supposed to be rate limited to one every 5s
2616         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
2617                 error "Too many reconnects $CONNCNT"
2618
2619         cleanup || error "cleanup failed with $?"
2620         # remove nid settings
2621         writeconf_or_reformat
2622 }
2623 run_test 35b "Continue reconnection retries, if the active server is busy"
2624
2625 test_36() { # 12743
2626         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs" && return
2627
2628         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
2629                 { skip "remote OST" && return 0; }
2630
2631         local rc=0
2632         local FSNAME2=test1234
2633         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2634
2635         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2636
2637         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2638                 is_blkdev $SINGLEMDS $MDSDEV &&
2639                 skip_env "mixed loopback and real device not working" && return
2640         fi
2641
2642         local fs2mdsdev=$(mdsdevname 1_2)
2643         local fs2ostdev=$(ostdevname 1_2)
2644         local fs3ostdev=$(ostdevname 2_2)
2645         local fs2mdsvdev=$(mdsvdevname 1_2)
2646         local fs2ostvdev=$(ostvdevname 1_2)
2647         local fs3ostvdev=$(ostvdevname 2_2)
2648
2649         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2650                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2651         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2652         #     different one than the default value here.
2653         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2654                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2655         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2656                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2657
2658         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2659         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2660         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2661         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2662         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2663
2664         sleep 5 # until 11778 fixed
2665
2666         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
2667
2668         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
2669                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
2670         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
2671                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
2672         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
2673                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2674         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
2675         DFTOTAL=$(echo $STRING | cut -d, -f1)
2676         DFUSED=$(echo $STRING  | cut -d, -f2)
2677         DFAVAIL=$(echo $STRING | cut -d, -f3)
2678         DFFREE=$(($DFTOTAL - $DFUSED))
2679
2680         ALLOWANCE=$((64 * $OSTCOUNT))
2681
2682         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2683            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2684                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2685                 rc=1
2686         fi
2687         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2688            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2689                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2690                 rc=2
2691         fi
2692         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2693            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2694                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2695                 rc=3
2696        fi
2697
2698         $UMOUNT $MOUNT2
2699         stop fs3ost -f || error "unable to stop OST3"
2700         stop fs2ost -f || error "unable to stop OST2"
2701         stop fs2mds -f || error "unable to stop second MDS"
2702         unload_modules_conf || error "unable unload modules"
2703         return $rc
2704 }
2705 run_test 36 "df report consistency on OSTs with different block size"
2706
2707 test_37() {
2708         local mntpt=$(facet_mntpt $SINGLEMDS)
2709         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2710         local mdsdev_sym="$TMP/sym_mdt.img"
2711         local opts=$MDS_MOUNT_OPTS
2712         local rc=0
2713
2714         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2715                 skip "ldiskfs only test"
2716                 return
2717         fi
2718
2719         echo "MDS :     $mdsdev"
2720         echo "SYMLINK : $mdsdev_sym"
2721         do_facet $SINGLEMDS rm -f $mdsdev_sym
2722
2723         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2724
2725         echo "mount symlink device - $mdsdev_sym"
2726
2727         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2728                 opts=$(csa_add "$opts" -o loop)
2729         fi
2730         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2731                 $mdsdev_sym $mntpt 2>&1)
2732         rc=${PIPESTATUS[0]}
2733
2734         echo mount_op=$mount_op
2735
2736         do_facet $SINGLEMDS "$UMOUNT $mntpt && rm -f $mdsdev_sym"
2737
2738         if $(echo $mount_op | grep -q "unable to set tunable"); then
2739                 error "set tunables failed for symlink device"
2740         fi
2741
2742         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2743 }
2744 run_test 37 "verify set tunables works for symlink device"
2745
2746 test_38() { # bug 14222
2747         local fstype=$(facet_fstype $SINGLEMDS)
2748         local mntpt=$(facet_mntpt $SINGLEMDS)
2749
2750         setup
2751         # like runtests
2752         local COUNT=10
2753         local SRC="/etc /bin"
2754         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2755         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2756         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2757         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2758                 error "copying $SRC to $DIR/$tdir"
2759         sync
2760         umount_client $MOUNT || error "umount_client $MOUNT failed"
2761         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2762         stop_mds || error "Unable to stop MDS"
2763         log "delete lov_objid file on MDS"
2764
2765         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2766
2767         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2768
2769         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2770
2771         # check create in mds_lov_connect
2772         start_mds || error "unable to start MDS"
2773         mount_client $MOUNT || error "mount_client $MOUNT failed"
2774         for f in $FILES; do
2775                 [ $V ] && log "verifying $DIR/$tdir/$f"
2776                 diff -q $f $DIR/$tdir/$f || ERROR=y
2777         done
2778         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2779         if [ "$ERROR" = "y" ]; then
2780                 # check it's updates in sync
2781                 umount_client $MOUNT
2782                 stop_mds
2783                 mount_fstype $SIGNLEMDS
2784                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2785                 unmount_fstype $SINGLEMDS
2786                 error "old and new files are different after connect" || true
2787         fi
2788         touch $DIR/$tdir/f2 || error "f2 file create failed"
2789
2790         # check it's updates in sync
2791         umount_client $MOUNT || error "second umount_client $MOUNT failed"
2792         stop_mds
2793
2794         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2795
2796         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2797         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2798
2799         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2800
2801         start_mds || error "unable to start MDS"
2802         mount_client $MOUNT || error "mount_client $MOUNT failed"
2803         for f in $FILES; do
2804                 [ $V ] && log "verifying $DIR/$tdir/$f"
2805                 diff -q $f $DIR/$tdir/$f || ERROR=y
2806         done
2807         touch $DIR/$tdir/f3 || error "f3 file create failed"
2808         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2809         umount_client $MOUNT || error "third umount_client $MOUNT failed"
2810         stop_mds
2811         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2812         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2813         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2814
2815         [ "$ERROR" = "y" ] &&
2816                 error "old and new files are different after sync" || true
2817
2818         log "files compared the same"
2819         cleanup || error "cleanup failed with $?"
2820 }
2821 run_test 38 "MDS recreates missing lov_objid file from OST data"
2822
2823 test_39() {
2824         PTLDEBUG=+malloc
2825         setup
2826         cleanup || error "cleanup failed with $?"
2827         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2828                 error "memory leak detected" || true
2829 }
2830 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2831
2832 test_40() { # bug 15759
2833         start_ost || error "Unable to start OST1"
2834         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2835         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2836         start_mds
2837         cleanup || error "cleanup failed with rc $?"
2838 }
2839 run_test 40 "race during service thread startup"
2840
2841 test_41a() { #bug 14134
2842         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2843            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2844                 skip "Loop devices does not work with nosvc option"
2845                 return
2846         fi
2847
2848         combined_mgs_mds ||
2849                 { skip "needs combined MGT and MDT device" && return 0; }
2850
2851         start_mdt 1 -o nosvc -n
2852         if [ $MDSCOUNT -ge 2 ]; then
2853                 for num in $(seq 2 $MDSCOUNT); do
2854                         start_mdt $num || return
2855                 done
2856         fi
2857         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
2858         start_mdt 1 -o nomgs,force
2859         mount_client $MOUNT || error "mount_client $MOUNT failed"
2860         sleep 5
2861
2862         echo "blah blah" > $MOUNT/$tfile
2863         cat $MOUNT/$tfile
2864
2865         umount_client $MOUNT || error "umount_client $MOUNT failed"
2866         stop ost1 -f || error "unable to stop OST1"
2867         stop_mds || error "Unable to stop MDS"
2868         stop_mds || error "Unable to stop MDS on second try"
2869 }
2870 run_test 41a "mount mds with --nosvc and --nomgs"
2871
2872 test_41b() {
2873         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2874            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2875                 skip "Loop devices does not work with nosvc option"
2876                 return
2877         fi
2878
2879         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2880
2881         stopall
2882         reformat
2883         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2884
2885         start_mdt 1 -o nosvc -n
2886         if [ $MDSCOUNT -ge 2 ]; then
2887                 for num in $(seq 2 $MDSCOUNT); do
2888                         start_mdt $num || return
2889                 done
2890         fi
2891         start_ost || error "Unable to start OST1"
2892         start_mdt 1 -o nomgs,force
2893         mount_client $MOUNT || error "mount_client $MOUNT failed"
2894         sleep 5
2895
2896         echo "blah blah" > $MOUNT/$tfile
2897         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
2898
2899         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
2900         stop_ost || error "Unable to stop OST1"
2901         stop_mds || error "Unable to stop MDS"
2902         stop_mds || error "Unable to stop MDS on second try"
2903 }
2904 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2905
2906 test_41c() {
2907         local server_version=$(lustre_version_code $SINGLEMDS)
2908         local oss_list=$(comma_list $(osts_nodes))
2909
2910         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2911         [[ $server_version -ge $(version_code 2.5.26) &&
2912            $server_version -lt $(version_code 2.5.50) ]] ||
2913         [[ $server_version -ge $(version_code 2.5.4) &&
2914            $server_version -lt $(version_code 2.5.11) ]] ||
2915                 { skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"; return; }
2916
2917         # ensure mds1 ost1 have been created even if running sub-test standalone
2918         cleanup
2919         setup
2920         cleanup || error "cleanup failed"
2921
2922         # using directly mount command instead of start() function to avoid
2923         # any side effect of // with others/externals tools/features
2924         # ("zpool import", ...)
2925
2926         # MDT concurrent start
2927
2928         LOAD_MODULES_REMOTE=true load_modules
2929         do_facet $SINGLEMDS "lsmod | grep -q libcfs" ||
2930                 error "MDT concurrent start: libcfs module not loaded"
2931
2932         local mds1dev=$(mdsdevname 1)
2933         local mds1mnt=$(facet_mntpt mds1)
2934         local mds1fstype=$(facet_fstype mds1)
2935         local mds1opts=$MDS_MOUNT_OPTS
2936
2937         if [ $mds1fstype == ldiskfs ] &&
2938            ! do_facet mds1 test -b $mds1dev; then
2939                 mds1opts=$(csa_add "$mds1opts" -o loop)
2940         fi
2941         if [[ $mds1fstype == zfs ]]; then
2942                 import_zpool mds1 || return ${PIPESTATUS[0]}
2943         fi
2944
2945         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
2946         do_facet mds1 "$LCTL set_param fail_loc=0x80000716"
2947
2948         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts &
2949         local pid=$!
2950
2951         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts
2952         local rc2=$?
2953         wait $pid
2954         local rc=$?
2955         do_facet mds1 "$LCTL set_param fail_loc=0x0"
2956         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
2957                 echo "1st MDT start succeed"
2958                 echo "2nd MDT start failed with $rc2"
2959         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
2960                 echo "1st MDT start failed with $rc"
2961                 echo "2nd MDT start succeed"
2962         else
2963                 stop mds1 -f
2964                 error "unexpected concurrent MDT mounts result, rc=$rc rc2=$rc2"
2965         fi
2966
2967         if [ $MDSCOUNT -ge 2 ]; then
2968                 for num in $(seq 2 $MDSCOUNT); do
2969                         start_mdt $num || return
2970                 done
2971         fi
2972
2973         # OST concurrent start
2974
2975         do_rpc_nodes $oss_list "lsmod | grep -q libcfs" ||
2976                 error "OST concurrent start: libcfs module not loaded"
2977
2978         local ost1dev=$(ostdevname 1)
2979         local ost1mnt=$(facet_mntpt ost1)
2980         local ost1fstype=$(facet_fstype ost1)
2981         local ost1opts=$OST_MOUNT_OPTS
2982
2983         if [ $ost1fstype == ldiskfs ] &&
2984            ! do_facet ost1 test -b $ost1dev; then
2985                 ost1opts=$(csa_add "$ost1opts" -o loop)
2986         fi
2987         if [[ $ost1fstype == zfs ]]; then
2988                 import_zpool ost1 || return ${PIPESTATUS[0]}
2989         fi
2990
2991         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
2992         do_facet ost1 "$LCTL set_param fail_loc=0x80000716"
2993
2994         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts &
2995         pid=$!
2996
2997         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts
2998         rc2=$?
2999         wait $pid
3000         rc=$?
3001         do_facet ost1 "$LCTL set_param fail_loc=0x0"
3002         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3003                 echo "1st OST start succeed"
3004                 echo "2nd OST start failed with $rc2"
3005         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3006                 echo "1st OST start failed with $rc"
3007                 echo "2nd OST start succeed"
3008         else
3009                 stop_mds -f
3010                 stop ost1 -f
3011                 error "unexpected concurrent OST mounts result, rc=$rc rc2=$rc2"
3012         fi
3013         # cleanup
3014         stop_mds
3015         stop ost1 -f
3016
3017         # verify everything ok
3018         start_mds
3019         if [ $? != 0 ]
3020         then
3021                 stop_mds
3022                 error "MDT(s) start failed"
3023         fi
3024
3025         start_ost
3026         if [ $? != 0 ]
3027         then
3028                 stop_mds
3029                 stop ost1 -f
3030                 error "OST(s) start failed"
3031         fi
3032
3033         mount_client $MOUNT
3034         if [ $? != 0 ]
3035         then
3036                 stop_mds
3037                 stop ost1 -f
3038                 error "client start failed"
3039         fi
3040         check_mount
3041         if [ $? != 0 ]
3042         then
3043                 stop_mds
3044                 stop ost1 -f
3045                 error "client mount failed"
3046         fi
3047         cleanup
3048 }
3049 run_test 41c "concurrent mounts of MDT/OST should all fail but one"
3050
3051 test_42() { #bug 14693
3052         setup
3053         check_mount || error "client was not mounted"
3054
3055         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
3056         umount_client $MOUNT ||
3057                 error "unmounting client failed with invalid llite param"
3058         mount_client $MOUNT ||
3059                 error "mounting client failed with invalid llite param"
3060
3061         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
3062         cleanup || error "stopping $FSNAME failed with invalid sys param"
3063         setup
3064         check_mount || error "client was not mounted with invalid sys param"
3065         cleanup || error "stopping $FSNAME failed with invalid sys param"
3066 }
3067 run_test 42 "allow client/server mount/unmount with invalid config param"
3068
3069 test_43a() {
3070         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
3071                 { skip "Need MDS version at least 2.5.58" && return 0; }
3072         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
3073
3074         ID1=${ID1:-501}
3075         USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
3076         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
3077                 return
3078
3079         setup
3080         chmod ugo+x $DIR || error "chmod 0 failed"
3081         set_conf_param_and_check mds1                                   \
3082                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
3083                 "$FSNAME.mdt.root_squash"                               \
3084                 "0:0"
3085         wait_update $HOSTNAME                                           \
3086                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3087                 "0:0" ||
3088                 error "check llite root_squash failed!"
3089         set_conf_param_and_check mds1                                   \
3090                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
3091                 "$FSNAME.mdt.nosquash_nids"                             \
3092                 "NONE"
3093         wait_update $HOSTNAME                                           \
3094                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3095                 "NONE" ||
3096                 error "check llite nosquash_nids failed!"
3097
3098     #
3099     # create set of test files
3100     #
3101     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
3102     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
3103     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
3104
3105     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
3106     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
3107
3108         mkdir $DIR/$tdir-rootdir || error "mkdir failed"
3109         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
3110         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
3111
3112         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
3113         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
3114         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
3115
3116         #
3117         # check root_squash:
3118         #   set root squash UID:GID to RUNAS_ID
3119         #   root should be able to access only files owned by RUNAS_ID
3120         #
3121         set_conf_param_and_check mds1                                   \
3122                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
3123                 "$FSNAME.mdt.root_squash"                               \
3124                 "$RUNAS_ID:$RUNAS_ID"
3125         wait_update $HOSTNAME                                           \
3126                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3127                 "$RUNAS_ID:$RUNAS_ID" ||
3128                 error "check llite root_squash failed!"
3129
3130         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
3131         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3132                 error "$ST: root read permission is denied"
3133         echo "$ST: root read permission is granted - ok"
3134
3135         echo "444" |
3136         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3137                 error "$ST: root write permission is denied"
3138         echo "$ST: root write permission is granted - ok"
3139
3140         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3141         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3142                 error "$ST: root read permission is granted"
3143         echo "$ST: root read permission is denied - ok"
3144
3145         echo "555" |
3146         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3147                 error "$ST: root write permission is granted"
3148         echo "$ST: root write permission is denied - ok"
3149
3150         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3151                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
3152                         error "$ST: root unlink permission is granted"
3153         echo "$ST: root unlink permission is denied - ok"
3154
3155         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
3156                 error "$ST: root create permission is granted"
3157         echo "$ST: root create permission is denied - ok"
3158
3159         # LU-1778
3160         # check root_squash is enforced independently
3161         # of client cache content
3162         #
3163         # access file by USER1, keep access open
3164         # root should be denied access to user file
3165
3166         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
3167         pid=$!
3168         sleep 1
3169
3170         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
3171         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3172             { kill $pid; error "$ST: root read permission is granted"; }
3173         echo "$ST: root read permission is denied - ok"
3174
3175         echo "777" |
3176         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3177             { kill $pid; error "$ST: root write permission is granted"; }
3178         echo "$ST: root write permission is denied - ok"
3179
3180         kill $pid
3181         wait $pid
3182
3183         #
3184         # check nosquash_nids:
3185         #   put client's NID into nosquash_nids list,
3186         #   root should be able to access root file after that
3187         #
3188         local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
3189         NIDLIST="2@gni $NIDLIST 192.168.0.[2,10]@tcp"
3190         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
3191         set_conf_param_and_check mds1                                   \
3192                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
3193                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
3194                 "$NIDLIST"
3195         wait_update $HOSTNAME                                           \
3196                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3197                 "$NIDLIST" ||
3198                 error "check llite nosquash_nids failed!"
3199
3200         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3201         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3202                 error "$ST: root read permission is denied"
3203         echo "$ST: root read permission is granted - ok"
3204
3205         echo "666" |
3206         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3207                 error "$ST: root write permission is denied"
3208         echo "$ST: root write permission is granted - ok"
3209
3210         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3211         rm $DIR/$tdir-rootdir/tfile-1 ||
3212                 error "$ST: root unlink permission is denied"
3213         echo "$ST: root unlink permission is granted - ok"
3214         touch $DIR/$tdir-rootdir/tfile-2 ||
3215                 error "$ST: root create permission is denied"
3216         echo "$ST: root create permission is granted - ok"
3217         cleanup || error "cleanup failed with $?"
3218 }
3219 run_test 43a "check root_squash and nosquash_nids"
3220
3221 test_43b() { # LU-5690
3222         [[ $(lustre_version_code mgs) -ge $(version_code 2.7.62) ]] ||
3223                 { skip "Need MGS version 2.7.62+"; return; }
3224
3225         if [[ -z "$fs2mds_DEV" ]]; then
3226                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
3227                 skip_env "mixed loopback and real device not working" && return
3228         fi
3229
3230         local fs2mdsdev=$(mdsdevname 1_2)
3231         local fs2mdsvdev=$(mdsvdevname 1_2)
3232
3233         # temporarily use fs2mds as fs2mgs
3234         local fs2mgs=fs2mds
3235         local fs2mgsdev=$fs2mdsdev
3236         local fs2mgsvdev=$fs2mdsvdev
3237
3238         local fsname=test1234
3239
3240         load_module llite/lustre
3241         local client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
3242         local host=${client_ip//*./}
3243         local net=${client_ip/%$host/}
3244         local nosquash_nids=$(h2nettype $net[$host,$host,$host])
3245
3246         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
3247                 --param mdt.root_squash=$RUNAS_ID:$RUNAS_ID \
3248                 --param mdt.nosquash_nids=$nosquash_nids \
3249                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
3250         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS  || error "start fs2mgs failed"
3251         stop $fs2mgs -f || error "stop fs2mgs failed"
3252 }
3253 run_test 43b "parse nosquash_nids with commas in expr_list"
3254
3255 umount_client $MOUNT
3256 cleanup_nocli
3257
3258 test_44() { # 16317
3259         setup
3260         check_mount || error "check_mount"
3261         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
3262         STATS_FOUND=no
3263         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
3264         for VAL in $UUIDS; do
3265                 NID=$(echo $VAL | cut -d= -f1)
3266                 CLUUID=$(echo $VAL | cut -d= -f2)
3267                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
3268         done
3269         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
3270         cleanup || error "cleanup failed with $?"
3271 }
3272 run_test 44 "mounted client proc entry exists"
3273
3274 test_45() { #17310
3275         setup
3276         check_mount || error "check_mount"
3277         stop_mds || error "Unable to stop MDS"
3278         df -h $MOUNT &
3279         log "sleep 60 sec"
3280         sleep 60
3281         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK        0x50f
3282         do_facet client "$LCTL set_param fail_loc=0x8000050f"
3283         log "sleep 10 sec"
3284         sleep 10
3285         manual_umount_client --force || error "manual_umount_client failed"
3286         do_facet client "$LCTL set_param fail_loc=0x0"
3287         start_mds || error "unable to start MDS"
3288         mount_client $MOUNT || error "mount_client $MOUNT failed"
3289         cleanup || error "cleanup failed with $?"
3290 }
3291 run_test 45 "long unlink handling in ptlrpcd"
3292
3293 cleanup_46a() {
3294         trap 0
3295         local rc=0
3296         local count=$1
3297
3298         umount_client $MOUNT2 || rc=$?
3299         umount_client $MOUNT || rc=$?
3300         while [ $count -gt 0 ]; do
3301                 stop ost${count} -f || rc=$?
3302                 let count=count-1
3303         done
3304         stop_mds || rc=$?
3305         cleanup_nocli || rc=$?
3306         #writeconf to remove all ost2 traces for subsequent tests
3307         writeconf_or_reformat
3308         return $rc
3309 }
3310
3311 test_46a() {
3312         echo "Testing with $OSTCOUNT OSTs"
3313         reformat_and_config
3314         start_mds || error "unable to start MDS"
3315         #first client should see only one ost
3316         start_ost || error "Unable to start OST1"
3317         wait_osc_import_state mds ost FULL
3318         #start_client
3319         mount_client $MOUNT || error "mount_client $MOUNT failed"
3320         trap "cleanup_46a $OSTCOUNT" EXIT ERR
3321
3322         local i
3323         for (( i=2; i<=$OSTCOUNT; i++ )); do
3324                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
3325                         error "start_ost$i $(ostdevname $i) failed"
3326         done
3327
3328         # wait until osts in sync
3329         for (( i=2; i<=$OSTCOUNT; i++ )); do
3330             wait_osc_import_state mds ost$i FULL
3331             wait_osc_import_state client ost$i FULL
3332         done
3333
3334         #second client see all ost's
3335
3336         mount_client $MOUNT2 || error "mount_client failed"
3337         $SETSTRIPE -c -1 $MOUNT2 || error "$SETSTRIPE -c -1 $MOUNT2 failed"
3338         $GETSTRIPE $MOUNT2 || error "$GETSTRIPE $MOUNT2 failed"
3339
3340         echo "ok" > $MOUNT2/widestripe
3341         $GETSTRIPE $MOUNT2/widestripe ||
3342                 error "$GETSTRIPE $MOUNT2/widestripe failed"
3343         # fill acl buffer for avoid expand lsm to them
3344         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
3345                 while read acl; do
3346             setfacl -m $acl $MOUNT2/widestripe
3347         done
3348
3349         # will be deadlock
3350         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3351
3352         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
3353 }
3354 run_test 46a "handle ost additional - wide striped file"
3355
3356 test_47() { #17674
3357         reformat
3358         setup_noconfig
3359         check_mount || error "check_mount failed"
3360         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
3361
3362         local lru_size=[]
3363         local count=0
3364         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3365             if echo $ns | grep "MDT[[:digit:]]*"; then
3366                 continue
3367             fi
3368             lrs=$(echo $ns | sed 's/.*lru_size=//')
3369             lru_size[count]=$lrs
3370             let count=count+1
3371         done
3372
3373         facet_failover ost1
3374         facet_failover $SINGLEMDS
3375         client_up || error "client_up failed"
3376
3377         count=0
3378         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3379             if echo $ns | grep "MDT[[:digit:]]*"; then
3380                 continue
3381             fi
3382             lrs=$(echo $ns | sed 's/.*lru_size=//')
3383             if ! test "$lrs" -eq "${lru_size[count]}"; then
3384                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
3385                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
3386             fi
3387             let count=count+1
3388         done
3389
3390         cleanup || error "cleanup failed with $?"
3391 }
3392 run_test 47 "server restart does not make client loss lru_resize settings"
3393
3394 cleanup_48() {
3395         trap 0
3396
3397         # reformat after this test is needed - if the test fails,
3398         # we will have unkillable file at FS
3399         reformat_and_config
3400 }
3401
3402 test_48() { # bz-17636 LU-7473
3403         local count
3404
3405         setup_noconfig
3406         check_mount || error "check_mount failed"
3407
3408         $SETSTRIPE -c -1 $MOUNT || error "$SETSTRIPE -c -1 $MOUNT failed"
3409         $GETSTRIPE $MOUNT || error "$GETSTRIPE $MOUNT failed"
3410
3411         echo "ok" > $MOUNT/widestripe
3412         $GETSTRIPE $MOUNT/widestripe ||
3413                 error "$GETSTRIPE $MOUNT/widestripe failed"
3414
3415         # In the future, we may introduce more EAs, such as selinux, enlarged
3416         # LOV EA, and so on. These EA will use some EA space that is shared by
3417         # ACL entries. So here we only check some reasonable ACL entries count,
3418         # instead of the max number that is calculated from the max_ea_size.
3419         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.57) ];
3420         then
3421                 count=28        # hard coded of RPC protocol
3422         elif [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3423                 count=4000      # max_num 4091 max_ea_size = 32768
3424         elif ! large_xattr_enabled; then
3425                 count=450       # max_num 497 max_ea_size = 4012
3426         else
3427                 count=4500      # max_num 8187 max_ea_size = 1048492
3428                                 # not create too much (>5000) to save test time
3429         fi
3430
3431         echo "It is expected to hold at least $count ACL entries"
3432         trap cleanup_48 EXIT ERR
3433         for ((i = 0; i < $count; i++)) do
3434                 setfacl -m u:$((i + 100)):rw $MOUNT/widestripe ||
3435                         error "Fail to setfacl for $MOUNT/widestripe at $i"
3436         done
3437
3438         cancel_lru_locks mdc
3439         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3440         local r_count=$(getfacl $MOUNT/widestripe | grep "user:" | wc -l)
3441         count=$((count + 1)) # for the entry "user::rw-"
3442
3443         [ $count -eq $r_count ] ||
3444                 error "Expected ACL entries $count, but got $r_count"
3445
3446         cleanup_48
3447 }
3448 run_test 48 "too many acls on file"
3449
3450 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3451 test_49a() { # bug 17710
3452         local timeout_orig=$TIMEOUT
3453         local ldlm_timeout_orig=$LDLM_TIMEOUT
3454         local LOCAL_TIMEOUT=20
3455
3456         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3457         TIMEOUT=$LOCAL_TIMEOUT
3458
3459         reformat
3460         setup_noconfig
3461         check_mount || error "client mount failed"
3462
3463         echo "check ldlm_timout..."
3464         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3465         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3466         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3467
3468         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3469                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3470         fi
3471
3472         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3473                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
3474         fi
3475
3476         umount_client $MOUNT || error "umount_client $MOUNT failed"
3477         stop_ost || error "problem stopping OSS"
3478         stop_mds || error "problem stopping MDS"
3479
3480         LDLM_TIMEOUT=$ldlm_timeout_orig
3481         TIMEOUT=$timeout_orig
3482 }
3483 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3484
3485 test_49b() { # bug 17710
3486         local timeout_orig=$TIMEOUT
3487         local ldlm_timeout_orig=$LDLM_TIMEOUT
3488         local LOCAL_TIMEOUT=20
3489
3490         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3491         TIMEOUT=$LOCAL_TIMEOUT
3492
3493         reformat
3494         setup_noconfig
3495         check_mount || error "client mount failed"
3496
3497         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3498         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3499         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3500
3501         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3502                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3503         fi
3504
3505         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3506                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
3507         fi
3508
3509         cleanup || error "cleanup failed"
3510
3511         LDLM_TIMEOUT=$ldlm_timeout_orig
3512         TIMEOUT=$timeout_orig
3513 }
3514 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3515
3516 lazystatfs() {
3517         # Test both statfs and lfs df and fail if either one fails
3518         multiop_bg_pause $1 f_
3519         RC1=$?
3520         PID=$!
3521         killall -USR1 multiop
3522         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
3523         wait $PID || { RC1=$?; log "multiop return error "; }
3524
3525         $LFS df &
3526         PID=$!
3527         sleep 5
3528         kill -s 0 $PID
3529         RC2=$?
3530         if [ $RC2 -eq 0 ]; then
3531             kill -s 9 $PID
3532             log "lazystatfs df failed"
3533         fi
3534
3535         RC=0
3536         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
3537         return $RC
3538 }
3539
3540 test_50a() {
3541         setup
3542         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3543         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3544
3545         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3546
3547         cleanup || error "cleanup failed with rc $?"
3548 }
3549 run_test 50a "lazystatfs all servers available"
3550
3551 test_50b() {
3552         setup
3553         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3554         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3555
3556         # Wait for client to detect down OST
3557         stop_ost || error "Unable to stop OST1"
3558         wait_osc_import_state mds ost DISCONN
3559
3560         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
3561
3562         umount_client $MOUNT || error "Unable to unmount client"
3563         stop_mds || error "Unable to stop MDS"
3564 }
3565 run_test 50b "lazystatfs all servers down"
3566
3567 test_50c() {
3568         start_mds || error "Unable to start MDS"
3569         start_ost || error "Unable to start OST1"
3570         start_ost2 || error "Unable to start OST2"
3571         mount_client $MOUNT || error "Unable to mount client"
3572         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3573         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3574
3575         # Wait for client to detect down OST
3576         stop_ost || error "Unable to stop OST1"
3577         wait_osc_import_state mds ost DISCONN
3578         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3579
3580         umount_client $MOUNT || error "Unable to unmount client"
3581         stop_ost2 || error "Unable to stop OST2"
3582         stop_mds || error "Unable to stop MDS"
3583         #writeconf to remove all ost2 traces for subsequent tests
3584         writeconf_or_reformat
3585 }
3586 run_test 50c "lazystatfs one server down"
3587
3588 test_50d() {
3589         start_mds || error "Unable to start MDS"
3590         start_ost || error "Unable to start OST1"
3591         start_ost2 || error "Unable to start OST2"
3592         mount_client $MOUNT || error "Unable to mount client"
3593         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3594         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3595
3596         # Issue the statfs during the window where the client still
3597         # belives the OST to be available but it is in fact down.
3598         # No failure just a statfs which hangs for a timeout interval.
3599         stop_ost || error "Unable to stop OST1"
3600         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3601
3602         umount_client $MOUNT || error "Unable to unmount client"
3603         stop_ost2 || error "Unable to stop OST2"
3604         stop_mds || error "Unable to stop MDS"
3605         #writeconf to remove all ost2 traces for subsequent tests
3606         writeconf_or_reformat
3607 }
3608 run_test 50d "lazystatfs client/server conn race"
3609
3610 test_50e() {
3611         local RC1
3612         local pid
3613
3614         reformat_and_config
3615         start_mds || error "Unable to start MDS"
3616         #first client should see only one ost
3617         start_ost || error "Unable to start OST1"
3618         wait_osc_import_state mds ost FULL
3619
3620         # Wait for client to detect down OST
3621         stop_ost || error "Unable to stop OST1"
3622         wait_osc_import_state mds ost DISCONN
3623
3624         mount_client $MOUNT || error "Unable to mount client"
3625         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3626
3627         multiop_bg_pause $MOUNT _f
3628         RC1=$?
3629         pid=$!
3630
3631         if [ $RC1 -ne 0 ]; then
3632                 log "multiop failed $RC1"
3633         else
3634             kill -USR1 $pid
3635             sleep $(( $TIMEOUT+1 ))
3636             kill -0 $pid
3637             [ $? -ne 0 ] && error "process isn't sleep"
3638             start_ost || error "Unable to start OST1"
3639             wait $pid || error "statfs failed"
3640         fi
3641
3642         umount_client $MOUNT || error "Unable to unmount client"
3643         stop_ost || error "Unable to stop OST1"
3644         stop_mds || error "Unable to stop MDS"
3645 }
3646 run_test 50e "normal statfs all servers down"
3647
3648 test_50f() {
3649         local RC1
3650         local pid
3651         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3652
3653         start_mds || error "Unable to start mds"
3654         #first client should see only one ost
3655         start_ost || error "Unable to start OST1"
3656         wait_osc_import_state mds ost FULL
3657
3658         start_ost2 || error "Unable to start OST2"
3659         wait_osc_import_state mds ost2 FULL
3660
3661         # Wait for client to detect down OST
3662         stop_ost2 || error "Unable to stop OST2"
3663
3664         wait_osc_import_state mds ost2 DISCONN
3665         mount_client $MOUNT || error "Unable to mount client"
3666         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3667
3668         multiop_bg_pause $MOUNT _f
3669         RC1=$?
3670         pid=$!
3671
3672         if [ $RC1 -ne 0 ]; then
3673                 log "lazystatfs multiop failed $RC1"
3674         else
3675             kill -USR1 $pid
3676             sleep $(( $TIMEOUT+1 ))
3677             kill -0 $pid
3678             [ $? -ne 0 ] && error "process isn't sleep"
3679             start_ost2 || error "Unable to start OST2"
3680             wait $pid || error "statfs failed"
3681             stop_ost2 || error "Unable to stop OST2"
3682         fi
3683
3684         umount_client $MOUNT -f || error "Unable to unmount client"
3685         stop_ost || error "Unable to stop OST1"
3686         stop_mds || error "Unable to stop MDS"
3687         #writeconf to remove all ost2 traces for subsequent tests
3688         writeconf_or_reformat
3689 }
3690 run_test 50f "normal statfs one server in down"
3691
3692 test_50g() {
3693         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs" && return
3694         setup
3695         start_ost2 || error "Unable to start OST2"
3696         wait_osc_import_state mds ost2 FULL
3697         wait_osc_import_state client ost2 FULL
3698
3699         local PARAM="${FSNAME}-OST0001.osc.active"
3700
3701         $SETSTRIPE -c -1 $DIR/$tfile || error "$SETSTRIPE failed"
3702         do_facet mgs $LCTL conf_param $PARAM=0 ||
3703                 error "Unable to deactivate OST"
3704
3705         umount_client $MOUNT || error "Unable to unmount client"
3706         mount_client $MOUNT || error "Unable to mount client"
3707         # This df should not cause a panic
3708         df -k $MOUNT
3709
3710         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3711         rm -f $DIR/$tfile || error "unable to remove file $DIR/$tfile"
3712         umount_client $MOUNT || error "Unable to unmount client"
3713         stop_ost2 || error "Unable to stop OST2"
3714         stop_ost || error "Unable to stop OST1"
3715         stop_mds || error "Unable to stop MDS"
3716         #writeconf to remove all ost2 traces for subsequent tests
3717         writeconf_or_reformat
3718 }
3719 run_test 50g "deactivated OST should not cause panic"
3720
3721 # LU-642
3722 test_50h() {
3723         # prepare MDT/OST, make OSC inactive for OST1
3724         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs" && return
3725
3726         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3727         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3728                 error "tunefs OST1 failed"
3729         start_mds  || error "Unable to start MDT"
3730         start_ost  || error "Unable to start OST1"
3731         start_ost2 || error "Unable to start OST2"
3732         mount_client $MOUNT || error "client start failed"
3733
3734         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3735
3736         # activatate OSC for OST1
3737         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3738         set_conf_param_and_check client                                 \
3739                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3740                 error "Unable to activate OST1"
3741
3742         mkdir $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3743         $SETSTRIPE -c -1 -i 0 $DIR/$tdir/2 ||
3744                 error "$SETSTRIPE $DIR/$tdir/2 failed"
3745         sleep 1 && echo "create a file after OST1 is activated"
3746         # create some file
3747         createmany -o $DIR/$tdir/2/$tfile-%d 1
3748
3749         # check OSC import is working
3750         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3751                 error "some OSC imports are still not connected"
3752
3753         # cleanup
3754         umount_client $MOUNT || error "Unable to umount client"
3755         stop_ost2 || error "Unable to stop OST2"
3756         cleanup_nocli || error "cleanup_nocli failed with $?"
3757 }
3758 run_test 50h "LU-642: activate deactivated OST"
3759
3760 test_50i() {
3761         # prepare MDT/OST, make OSC inactive for OST1
3762         [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs" && return
3763
3764         load_modules
3765         [ $(facet_fstype mds2) == zfs ] && import_zpool mds2
3766         do_facet mds2 "$TUNEFS --param mdc.active=0 $(mdsdevname 2)" ||
3767                 error "tunefs MDT2 failed"
3768         start_mds  || error "Unable to start MDT"
3769         start_ost  || error "Unable to start OST1"
3770         start_ost2 || error "Unable to start OST2"
3771         mount_client $MOUNT || error "client start failed"
3772
3773         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3774
3775         $LCTL conf_param ${FSNAME}-MDT0000.mdc.active=0 &&
3776                 error "deactive MDC0 succeeds"
3777         # activate MDC for MDT2
3778         local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
3779         set_conf_param_and_check client                                 \
3780                 "$TEST" "${FSNAME}-MDT0001.mdc.active" 1 ||
3781                 error "Unable to activate MDT2"
3782
3783         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
3784         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]
3785         then
3786                 wait_dne_interconnect
3787         fi
3788         $LFS mkdir -i1 $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3789         # create some file
3790         createmany -o $DIR/$tdir/2/$tfile-%d 1 || error "create files failed"
3791
3792         rm -rf $DIR/$tdir/2 || error "unlink dir failed"
3793
3794         # deactivate MDC for MDT2
3795         local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
3796         set_conf_param_and_check client                                 \
3797                 "$TEST" "${FSNAME}-MDT0001.mdc.active" 0 ||
3798                 error "Unable to deactivate MDT2"
3799
3800         wait_osp_active mds ${FSNAME}-MDT0001 1 0
3801
3802         $LFS mkdir -i1 $DIR/$tdir/2 &&
3803                 error "mkdir $DIR/$tdir/2 succeeds after deactive MDT"
3804
3805         $LFS mkdir -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
3806                 error "mkdir $DIR/$tdir/striped_dir fails after deactive MDT2"
3807
3808         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
3809         [ $stripe_count -eq $((MDSCOUNT - 1)) ] ||
3810                 error "wrong $stripe_count != $((MDSCOUNT -1)) for striped_dir"
3811
3812         # cleanup
3813         umount_client $MOUNT || error "Unable to umount client"
3814         stop_mds
3815         stop_ost
3816         stop_ost 2
3817 }
3818 run_test 50i "activate deactivated MDT"
3819
3820 test_51() {
3821         local LOCAL_TIMEOUT=20
3822
3823         reformat
3824         setup_noconfig
3825         check_mount || error "check_mount failed"
3826
3827         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
3828         $SETSTRIPE -c -1 $MOUNT/$tdir ||
3829                 error "$SETSTRIPE -c -1 $MOUNT/$tdir failed"
3830         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3831         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x142"
3832         touch $MOUNT/$tdir/$tfile &
3833         local pid=$!
3834         sleep 2
3835         start_ost2 || error "Unable to start OST1"
3836         wait $pid
3837         stop_ost2 || error "Unable to stop OST1"
3838         umount_client $MOUNT -f || error “unmount $MOUNT failed”
3839         cleanup_nocli || error “stop server failed”
3840         #writeconf to remove all ost2 traces for subsequent tests
3841         writeconf_or_reformat
3842 }
3843 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3844
3845 copy_files_xattrs()
3846 {
3847         local node=$1
3848         local dest=$2
3849         local xattrs=$3
3850         shift 3
3851
3852         do_node $node mkdir -p $dest
3853         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3854
3855         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3856                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3857         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3858
3859         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3860         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3861 }
3862
3863 diff_files_xattrs()
3864 {
3865         local node=$1
3866         local backup=$2
3867         local xattrs=$3
3868         shift 3
3869
3870         local backup2=${TMP}/backup2
3871
3872         do_node $node mkdir -p $backup2
3873         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3874
3875         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3876                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3877         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3878
3879         do_node $node "diff -rq $backup $backup2"
3880         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3881
3882         local xattrs2=${TMP}/xattrs2
3883         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3884         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3885
3886         do_node $node "diff $xattrs $xattrs2"
3887         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3888
3889         do_node $node "rm -rf $backup2 $xattrs2"
3890         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3891 }
3892
3893 test_52() {
3894         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3895                 skip "ldiskfs only test"
3896                 return
3897         fi
3898
3899         start_mds || error "Unable to start MDS"
3900         start_ost || error "Unable to start OST1"
3901         mount_client $MOUNT || error "Unable to mount client"
3902
3903         local nrfiles=8
3904         local ost1mnt=$(facet_mntpt ost1)
3905         local ost1node=$(facet_active_host ost1)
3906         local ost1tmp=$TMP/conf52
3907         local loop
3908
3909         mkdir $DIR/$tdir || error "Unable to create $DIR/$tdir"
3910         touch $TMP/modified_first || error "Unable to create temporary file"
3911         local mtime=$(stat -c %Y $TMP/modified_first)
3912         do_node $ost1node "mkdir -p $ost1tmp &&
3913                            touch -m -d @$mtime $ost1tmp/modified_first" ||
3914                 error "Unable to create temporary file"
3915         sleep 1
3916
3917         $SETSTRIPE -c -1 -S 1M $DIR/$tdir || error "$SETSTRIPE failed"
3918
3919         for (( i=0; i < nrfiles; i++ )); do
3920                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c ||
3921                         error "multiop failed"
3922                 echo -n .
3923         done
3924         echo
3925
3926         # backup files
3927         echo backup files to $TMP/$tdir
3928         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3929         copy_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
3930                 error "Unable to copy files"
3931
3932         umount_client $MOUNT || error "Unable to umount client"
3933         stop_ost || error "Unable to stop ost1"
3934
3935         echo mount ost1 as ldiskfs
3936         do_node $ost1node mkdir -p $ost1mnt || error "Unable to create $ost1mnt"
3937         if ! do_node $ost1node test -b $ost1_dev; then
3938                 loop="-o loop"
3939         fi
3940         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3941                 $ost1mnt ||
3942                 error "Unable to mount ost1 as ldiskfs"
3943
3944         # backup objects
3945         echo backup objects to $ost1tmp/objects
3946         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3947                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3948         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3949                         $objects ||
3950                 error "Unable to copy objects"
3951
3952         # move objects to lost+found
3953         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3954         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3955
3956         do_node $ost1node "umount $ost1mnt" ||
3957                 error "Unable to umount ost1 as ldiskfs"
3958
3959         start_ost || error "Unable to start OST1"
3960         mount_client $MOUNT || error "Unable to mount client"
3961
3962         local REPAIRED=$(do_node $ost1node "$LCTL get_param \
3963                          -n osd-ldiskfs.$FSNAME-OST0000.oi_scrub" |
3964                          awk '/^lf_repa[ri]*ed/ { print $2 }')
3965         [ $REPAIRED -gt 0 ] ||
3966                 error "Some entry under /lost+found should be repaired"
3967
3968         # compare files
3969         diff_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
3970                 error "Unable to diff files"
3971
3972         rm -rf $TMP/$tdir $TMP/file_xattrs ||
3973                 error "Unable to delete temporary files"
3974         do_node $ost1node "rm -rf $ost1tmp" ||
3975                 error "Unable to delete temporary files"
3976         cleanup || error "cleanup failed with $?"
3977 }
3978 run_test 52 "check recovering objects from lost+found"
3979
3980 # Checks threads_min/max/started for some service
3981 #
3982 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3983 # parameter pattern prefix like 'ost.*.ost'.
3984 thread_sanity() {
3985         local modname=$1
3986         local facet=$2
3987         local parampat=$3
3988         local opts=$4
3989         local basethr=$5
3990         local tmin
3991         local tmin2
3992         local tmax
3993         local tmax2
3994         local tstarted
3995         local paramp
3996         local msg="Insane $modname thread counts"
3997         local ncpts=$(check_cpt_number $facet)
3998         local nthrs
3999         shift 4
4000
4001         check_mount || return 41
4002
4003         # We need to expand $parampat, but it may match multiple parameters, so
4004         # we'll pick the first one
4005         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
4006                 error "Couldn't expand ${parampat}.threads_min parameter name"
4007                 return 22
4008         fi
4009
4010         # Remove the .threads_min part
4011         paramp=${paramp%.threads_min}
4012
4013         # Check for sanity in defaults
4014         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4015                echo 0)
4016         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4017                echo 0)
4018         tstarted=$(do_facet $facet "$LCTL get_param \
4019                                     -n ${paramp}.threads_started" || echo 0)
4020         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' ||
4021                 return $?
4022         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4023                 return $?
4024         nthrs=$(expr $tmax - $tmin)
4025         if [ $nthrs -lt $ncpts ]; then
4026                 nthrs=0
4027         else
4028                 nthrs=$ncpts
4029         fi
4030
4031         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
4032                 skip_env "module parameter forced $facet thread count" &&
4033                 tmin=3 && tmax=$((3 * tmax))
4034
4035         # Check that we can change min/max
4036         do_facet $facet "$LCTL set_param \
4037                          ${paramp}.threads_min=$((tmin + nthrs))"
4038         do_facet $facet "$LCTL set_param \
4039                          ${paramp}.threads_max=$((tmax - nthrs))"
4040         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4041                 echo 0)
4042         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4043                 echo 0)
4044         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) &&
4045                             $tmax2 == ($tmax - $nthrs)))' || return $?
4046
4047         # Check that we can set min/max to the same value
4048         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4049                echo 0)
4050         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$tmin"
4051         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4052                 echo 0)
4053         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4054                 echo 0)
4055         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
4056
4057         # Check that we can't set max < min
4058         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$((tmin - 1))"
4059         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4060                 echo 0)
4061         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4062                 echo 0)
4063         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
4064
4065         # We need to ensure that we get the module options desired; to do this
4066         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
4067         LOAD_MODULES_REMOTE=true
4068         cleanup
4069         local oldvalue
4070         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
4071         setmodopts -a $modname "$newvalue" oldvalue
4072
4073         setup
4074         check_mount || return 41
4075
4076         # Restore previous setting of MODOPTS_*
4077         setmodopts $modname "$oldvalue"
4078
4079         # Check that $opts took
4080         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min")
4081         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max")
4082         tstarted=$(do_facet $facet \
4083                    "$LCTL get_param -n ${paramp}.threads_started")
4084         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4085                 return $?
4086         cleanup
4087
4088         setup
4089 }
4090
4091 test_53a() {
4092         setup
4093         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
4094         cleanup || error "cleanup failed with rc $?"
4095 }
4096 run_test 53a "check OSS thread count params"
4097
4098 test_53b() {
4099         setup
4100         local mds=$(do_facet $SINGLEMDS "$LCTL get_param \
4101                                          -N mds.*.*.threads_max 2>/dev/null")
4102         if [ -z "$mds" ]; then
4103                 #running this on an old MDT
4104                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
4105         else
4106                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
4107         fi
4108         cleanup || error "cleanup failed with $?"
4109 }
4110 run_test 53b "check MDS thread count params"
4111
4112 test_54a() {
4113         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4114                 skip "ldiskfs only test"
4115                 return
4116         fi
4117
4118         do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p ||
4119                 error "llverdev failed with rc=$?"
4120         reformat_and_config
4121 }
4122 run_test 54a "test llverdev and partial verify of device"
4123
4124 test_54b() {
4125         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4126                 skip "ldiskfs only test"
4127                 return
4128         fi
4129
4130         setup
4131         run_llverfs $MOUNT -p || error "llverfs failed with rc=$?"
4132         cleanup || error "cleanup failed with rc=$?"
4133 }
4134 run_test 54b "test llverfs and partial verify of filesystem"
4135
4136 lov_objid_size()
4137 {
4138         local max_ost_index=$1
4139         echo -n $(((max_ost_index + 1) * 8))
4140 }
4141
4142 test_55() {
4143         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4144                 skip "ldiskfs only test"
4145                 return
4146         fi
4147
4148         local mdsdev=$(mdsdevname 1)
4149         local mdsvdev=$(mdsvdevname 1)
4150
4151         for i in 1023 2048
4152         do
4153                 if ! combined_mgs_mds; then
4154                         stop_mgs || error "stopping MGS service failed"
4155                         format_mgs || error "formatting MGT failed"
4156                 fi
4157                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
4158                         $mdsvdev || exit 10
4159                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
4160                         --reformat $(ostdevname 1) $(ostvdevname 1)
4161                 setup_noconfig
4162                 stopall
4163                 setup_noconfig
4164                 sync
4165
4166                 echo checking size of lov_objid for ost index $i
4167                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" |
4168                                  grep ^User | awk -F 'Size: ' '{print $2}')
4169                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
4170                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
4171                 else
4172                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
4173                 fi
4174                 stopall
4175         done
4176
4177         reformat
4178 }
4179 run_test 55 "check lov_objid size"
4180
4181 test_56a() {
4182         local server_version=$(lustre_version_code $SINGLEMDS)
4183         local mds_journal_size_orig=$MDSJOURNALSIZE
4184         local n
4185
4186         MDSJOURNALSIZE=16
4187
4188         formatall
4189         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
4190                 $(ostdevname 1) $(ostvdevname 1)
4191         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
4192                 $(ostdevname 2) $(ostvdevname 2)
4193
4194         start_mgsmds
4195         start_ost || error "Unable to start first ost (idx 10000)"
4196         start_ost2 || error "Unable to start second ost (idx 1000)"
4197         mount_client $MOUNT || error "Unable to mount client"
4198         echo ok
4199         $LFS osts
4200
4201         if [[ $server_version -ge $(version_code 2.6.54) ]] ||
4202            [[ $server_version -ge $(version_code 2.5.4) &&
4203               $server_version -lt $(version_code 2.5.11) ]]; then
4204                 wait_osc_import_state mds ost1 FULL
4205                 wait_osc_import_state mds ost2 FULL
4206                 $SETSTRIPE --stripe-count=-1 $DIR/$tfile ||
4207                         error "Unable to setstripe $DIR/$tfile"
4208                 n=$($LFS getstripe --stripe-count $DIR/$tfile)
4209                 [ "$n" -eq 2 ] || error "Stripe count not two: $n"
4210                 rm $DIR/$tfile
4211         fi
4212
4213         stopall
4214         MDSJOURNALSIZE=$mds_journal_size_orig
4215         reformat
4216 }
4217 run_test 56a "check big OST indexes and out-of-index-order start"
4218
4219 cleanup_56b() {
4220         trap 0
4221
4222         umount_client $MOUNT -f || error "unmount client failed"
4223         stop mds1
4224         stop mds2
4225         stop mds3
4226         stopall
4227         reformat
4228 }
4229
4230 test_56b() {
4231         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs" && return
4232
4233         trap cleanup_56b EXIT RETURN ERR
4234         stopall
4235
4236         if ! combined_mgs_mds ; then
4237                 format_mgs
4238                 start_mgs
4239         fi
4240
4241         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
4242                 $(mdsdevname 1) $(mdsvdevname 1)
4243         add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
4244                 $(mdsdevname 2) $(mdsvdevname 2)
4245         add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=1000 --reformat \
4246                 $(mdsdevname 3) $(mdsvdevname 3)
4247         format_ost 1
4248         format_ost 2
4249
4250         start_mdt 1 || error "MDT 1 (idx 0) start failed"
4251         start_mdt 2 || error "MDT 2 (idx 1) start failed"
4252         start_mdt 3 || error "MDT 3 (idx 1000) start failed"
4253         start_ost || error "Unable to start first ost"
4254         start_ost2 || error "Unable to start second ost"
4255
4256         do_nodes $(comma_list $(mdts_nodes)) \
4257                 "$LCTL set_param mdt.*.enable_remote_dir=1 \
4258                 mdt.*.enable_remote_dir_gid=-1"
4259
4260         mount_client $MOUNT || error "Unable to mount client"
4261
4262         $LFS mkdir -c3 $MOUNT/$tdir || error "failed to make testdir"
4263
4264         echo "This is test file 1!" > $MOUNT/$tdir/$tfile.1 ||
4265                 error "failed to make test file 1"
4266         echo "This is test file 2!" > $MOUNT/$tdir/$tfile.2 ||
4267                 error "failed to make test file 2"
4268         echo "This is test file 1000!" > $MOUNT/$tdir/$tfile.1000 ||
4269                 error "failed to make test file 1000"
4270
4271         rm -rf $MOUNT/$tdir || error "failed to remove testdir"
4272
4273         $LFS mkdir -i1000 $MOUNT/$tdir.1000 ||
4274                 error "create remote dir at idx 1000 failed"
4275
4276         output=$($LFS df)
4277         echo "=== START lfs df OUTPUT ==="
4278         echo -e "$output"
4279         echo "==== END lfs df OUTPUT ===="
4280
4281         mdtcnt=$(echo -e "$output" | grep $FSNAME-MDT | wc -l)
4282         ostcnt=$(echo -e "$output" | grep $FSNAME-OST | wc -l)
4283
4284         echo "lfs df returned mdt count $mdtcnt and ost count $ostcnt"
4285         [ $mdtcnt -eq 3 ] || error "lfs df returned wrong mdt count"
4286         [ $ostcnt -eq 2 ] || error "lfs df returned wrong ost count"
4287
4288         echo "This is test file 1!" > $MOUNT/$tdir.1000/$tfile.1 ||
4289                 error "failed to make test file 1"
4290         echo "This is test file 2!" > $MOUNT/$tdir.1000/$tfile.2 ||
4291                 error "failed to make test file 2"
4292         echo "This is test file 1000!" > $MOUNT/$tdir.1000/$tfile.1000 ||
4293                 error "failed to make test file 1000"
4294         rm -rf $MOUNT/$tdir.1000 || error "failed to remove remote_dir"
4295
4296         output=$($LFS mdts)
4297         echo "=== START lfs mdts OUTPUT ==="
4298         echo -e "$output"
4299         echo "==== END lfs mdts OUTPUT ===="
4300
4301         echo -e "$output" | grep -v "MDTS:" | awk '{print $1}' |
4302                 sed 's/://g' > $TMP/mdts-actual.txt
4303         sort $TMP/mdts-actual.txt -o $TMP/mdts-actual.txt
4304
4305         echo -e "0\n1\n1000" > $TMP/mdts-expected.txt
4306
4307         diff $TMP/mdts-expected.txt $TMP/mdts-actual.txt
4308         result=$?
4309
4310         rm $TMP/mdts-expected.txt $TMP/mdts-actual.txt
4311
4312         [ $result -eq 0 ] || error "target_obd proc file is incorrect!"
4313 }
4314 run_test 56b "test target_obd correctness with nonconsecutive MDTs"
4315
4316 test_57a() { # bug 22656
4317         do_rpc_nodes $(facet_active_host ost1) load_modules_local
4318         local NID=$(do_facet ost1 "$LCTL get_param nis" |
4319                     tail -1 | awk '{print $1}')
4320         writeconf_or_reformat
4321         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4322         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" ||
4323                 error "tunefs failed"
4324         start_mgsmds
4325         start_ost && error "OST registration from failnode should fail"
4326         reformat
4327 }
4328 run_test 57a "initial registration from failnode should fail (should return errs)"
4329
4330 test_57b() {
4331         do_rpc_nodes $(facet_active_host ost1) load_modules_local
4332         local NID=$(do_facet ost1 "$LCTL get_param nis" |
4333                     tail -1 | awk '{print $1}')
4334         writeconf_or_reformat
4335         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4336         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" ||
4337                 error "tunefs failed"
4338         start_mgsmds
4339         start_ost || error "OST registration from servicenode should not fail"
4340         reformat
4341 }
4342 run_test 57b "initial registration from servicenode should not fail"
4343
4344 count_osts() {
4345         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
4346 }
4347
4348 test_58() { # bug 22658
4349         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
4350         setup_noconfig
4351         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4352         createmany -o $DIR/$tdir/$tfile-%d 100
4353         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
4354 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
4355         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x601"
4356         unlinkmany $DIR/$tdir/$tfile-%d 100
4357         stop_mds || error "Unable to stop MDS"
4358
4359         local MNTDIR=$(facet_mntpt $SINGLEMDS)
4360         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4361
4362         # remove all files from the OBJECTS dir
4363         mount_fstype $SINGLEMDS
4364
4365         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
4366
4367         unmount_fstype $SINGLEMDS
4368         # restart MDS with missing llog files
4369         start_mds || error "unable to start MDS"
4370         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
4371         reformat
4372 }
4373 run_test 58 "missing llog files must not prevent MDT from mounting"
4374
4375 test_59() {
4376         start_mgsmds >> /dev/null
4377         local C1=$(count_osts)
4378         if [ $C1 -eq 0 ]; then
4379                 start_ost >> /dev/null
4380                 C1=$(count_osts)
4381         fi
4382         stopall
4383         echo "original ost count: $C1 (expect > 0)"
4384         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
4385         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
4386         local C2=$(count_osts)
4387         echo "after mdt writeconf count: $C2 (expect 0)"
4388         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
4389         echo "OST start without writeconf should fail:"
4390         start_ost >> /dev/null &&
4391                 error "OST start without writeconf didn't fail"
4392         echo "OST start with writeconf should succeed:"
4393         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
4394         local C3=$(count_osts)
4395         echo "after ost writeconf count: $C3 (expect 1)"
4396         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
4397         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
4398         local C4=$(count_osts)
4399         echo "after ost2 writeconf count: $C4 (expect 2)"
4400         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
4401         stop_ost2 >> /dev/null
4402         cleanup_nocli >> /dev/null
4403         #writeconf to remove all ost2 traces for subsequent tests
4404         writeconf_or_reformat
4405 }
4406 run_test 59 "writeconf mount option"
4407
4408 test_60() { # LU-471
4409         local num
4410
4411         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4412                 skip "ldiskfs only test"
4413                 return
4414         fi
4415
4416         for num in $(seq $MDSCOUNT); do
4417                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
4418                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
4419                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4420                         exit 10
4421         done
4422
4423         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
4424         [ ${PIPESTATUS[0]} -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
4425
4426         # MDT default has dirdata feature
4427         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
4428         # we disable uninit_bg feature
4429         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
4430         # we set stride extended options
4431         echo $dump | grep stride > /dev/null || error "stride is not set"
4432         reformat
4433 }
4434 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
4435
4436 test_61() { # LU-80
4437         local lxattr=false
4438
4439         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
4440                 { skip "Need MDS version at least 2.1.53"; return 0; }
4441
4442         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4443              ! large_xattr_enabled; then
4444                 lxattr=true
4445
4446                 for num in $(seq $MDSCOUNT); do
4447                         do_facet mds${num} $TUNE2FS -O large_xattr \
4448                                 $(mdsdevname $num) ||
4449                                 error "tune2fs on mds $num failed"
4450                 done
4451         fi
4452
4453         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
4454         setup_noconfig || error "setting up the filesystem failed"
4455         client_up || error "starting client failed"
4456
4457         local file=$DIR/$tfile
4458         touch $file || error "touch $file failed"
4459
4460         local large_value="$(generate_string $(max_xattr_size))"
4461         local small_value="bar"
4462
4463         local name="trusted.big"
4464         log "save large xattr $name on $file"
4465         setfattr -n $name -v $large_value $file ||
4466                 error "saving $name on $file failed"
4467
4468         local new_value=$(get_xattr_value $name $file)
4469         [[ "$new_value" != "$large_value" ]] &&
4470                 error "$name different after saving"
4471
4472         log "shrink value of $name on $file"
4473         setfattr -n $name -v $small_value $file ||
4474                 error "shrinking value of $name on $file failed"
4475
4476         new_value=$(get_xattr_value $name $file)
4477         [[ "$new_value" != "$small_value" ]] &&
4478                 error "$name different after shrinking"
4479
4480         log "grow value of $name on $file"
4481         setfattr -n $name -v $large_value $file ||
4482                 error "growing value of $name on $file failed"
4483
4484         new_value=$(get_xattr_value $name $file)
4485         [[ "$new_value" != "$large_value" ]] &&
4486                 error "$name different after growing"
4487
4488         log "check value of $name on $file after remounting MDS"
4489         fail $SINGLEMDS
4490         new_value=$(get_xattr_value $name $file)
4491         [[ "$new_value" != "$large_value" ]] &&
4492                 error "$name different after remounting MDS"
4493
4494         log "remove large xattr $name from $file"
4495         setfattr -x $name $file || error "removing $name from $file failed"
4496
4497         if $lxattr; then
4498                 stopall || error "stopping for e2fsck run"
4499                 for num in $(seq $MDSCOUNT); do
4500                         run_e2fsck $(facet_active_host mds$num) \
4501                                 $(mdsdevname $num) "-y" ||
4502                                 error "e2fsck MDT$num failed"
4503                 done
4504                 setup_noconfig || error "remounting the filesystem failed"
4505         fi
4506
4507         # need to delete this file to avoid problems in other tests
4508         rm -f $file
4509         stopall || error "stopping systems to turn off large_xattr"
4510         if $lxattr; then
4511                 for num in $(seq $MDSCOUNT); do
4512                         do_facet mds${num} $TUNE2FS -O ^large_xattr \
4513                                 $(mdsdevname $num) ||
4514                                 error "tune2fs on mds $num failed"
4515                 done
4516         fi
4517 }
4518 run_test 61 "large xattr"
4519
4520 test_62() {
4521         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4522                 skip "ldiskfs only test"
4523                 return
4524         fi
4525
4526         # MRP-118
4527         local mdsdev=$(mdsdevname 1)
4528         local ostdev=$(ostdevname 1)
4529
4530         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
4531                 { skip "Need MDS version at least 2.2.51"; return 0; }
4532
4533         echo "disable journal for mds"
4534         do_facet mds1 $TUNE2FS -O ^has_journal $mdsdev || error "tune2fs failed"
4535         start_mds && error "MDT start should fail"
4536         echo "disable journal for ost"
4537         do_facet ost1 $TUNE2FS -O ^has_journal $ostdev || error "tune2fs failed"
4538         start_ost && error "OST start should fail"
4539         cleanup || error "cleanup failed with rc $?"
4540         reformat_and_config
4541 }
4542 run_test 62 "start with disabled journal"
4543
4544 test_63() {
4545         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4546                 skip "ldiskfs only test"
4547                 return
4548         fi
4549
4550         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ldiskfs
4551         local inode_slab=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
4552                            awk '/ldiskfs_inode_cache/ { print $5 / $6 }')
4553         if [ -z "$inode_slab" ]; then
4554                 skip "ldiskfs module has not been loaded"
4555                 return
4556         fi
4557
4558         echo "$inode_slab ldiskfs inodes per page"
4559         [ "${inode_slab%.*}" -ge "3" ] && return 0
4560
4561         # If kmalloc-128 is also 1 per page - this is a debug kernel
4562         # and so this is not an error.
4563         local kmalloc128=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
4564                            awk '/^(kmalloc|size)-128 / { print $5 / $6 }')
4565         # 32 128-byte chunks in 4k
4566         [ "${kmalloc128%.*}" -lt "32" ] ||
4567                 error "ldiskfs inode too big, only $inode_slab objs/page, " \
4568                       "kmalloc128 = $kmalloc128 objs/page"
4569 }
4570 run_test 63 "Verify each page can at least hold 3 ldiskfs inodes"
4571
4572 test_64() {
4573         start_mds || error "unable to start MDS"
4574         start_ost || error "Unable to start OST1"
4575         start_ost2 || error "Unable to start second ost"
4576         mount_client $MOUNT || error "Unable to mount client"
4577         stop_ost2 || error "Unable to stop second ost"
4578         echo "$LFS df"
4579         $LFS df --lazy
4580         umount_client $MOUNT -f || error “unmount $MOUNT failed”
4581         cleanup_nocli || error "cleanup_nocli failed with $?"
4582         #writeconf to remove all ost2 traces for subsequent tests
4583         writeconf_or_reformat
4584 }
4585 run_test 64 "check lfs df --lazy "
4586
4587 test_65() { # LU-2237
4588         # Currently, the test is only valid for ldiskfs backend
4589         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4590                 skip "ldiskfs only test" && return
4591
4592         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4593         local brpt=$(facet_mntpt brpt)
4594         local opts=""
4595
4596         if ! do_facet $SINGLEMDS "test -b $devname"; then
4597                 opts="-o loop"
4598         fi
4599
4600         stop_mds || error "Unable to stop MDS"
4601         local obj=$(do_facet $SINGLEMDS \
4602                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
4603                     grep Inode)
4604         if [ -z "$obj" ]; then
4605                 # The MDT may be just re-formatted, mount the MDT for the
4606                 # first time to guarantee the "last_rcvd" file is there.
4607                 start_mds || error "fail to mount the MDS for the first time"
4608                 stop_mds || error "Unable to stop MDS"
4609         fi
4610
4611         # remove the "last_rcvd" file
4612         do_facet $SINGLEMDS "mkdir -p $brpt"
4613         do_facet $SINGLEMDS \
4614                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
4615         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
4616         do_facet $SINGLEMDS "$UMOUNT $brpt"
4617
4618         # restart MDS, the "last_rcvd" file should be recreated.
4619         start_mds || error "fail to restart the MDS"
4620         stop_mds || error "Unable to stop MDS"
4621         obj=$(do_facet $SINGLEMDS \
4622               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
4623         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
4624 }
4625 run_test 65 "re-create the lost last_rcvd file when server mount"
4626
4627 test_66() {
4628         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
4629                 { skip "Need MGS version at least 2.3.59"; return 0; }
4630
4631         setup
4632         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
4633         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
4634
4635         echo "replace_nids should fail if MDS, OSTs and clients are UP"
4636         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4637                 error "replace_nids fail"
4638
4639         umount_client $MOUNT || error "unmounting client failed"
4640         echo "replace_nids should fail if MDS and OSTs are UP"
4641         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4642                 error "replace_nids fail"
4643
4644         stop_ost || error "Unable to stop OST1"
4645         echo "replace_nids should fail if MDS is UP"
4646         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4647                 error "replace_nids fail"
4648
4649         stop_mds || error "stopping mds failed"
4650
4651         if combined_mgs_mds; then
4652                 start_mdt 1 "-o nosvc" ||
4653                         error "starting mds with nosvc option failed"
4654         fi
4655
4656         echo "command should accept two parameters"
4657         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4658                 error "command should accept two params"
4659
4660         echo "correct device name should be passed"
4661         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4662                 error "wrong devname"
4663
4664         echo "wrong nids list should not destroy the system"
4665         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4666                 error "wrong parse"
4667
4668         echo "replace OST nid"
4669         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4670                 error "replace nids failed"
4671
4672         echo "command should accept two parameters"
4673         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4674                 error "command should accept two params"
4675
4676         echo "wrong nids list should not destroy the system"
4677         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4678                 error "wrong parse"
4679
4680         echo "replace MDS nid"
4681         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4682                 error "replace nids failed"
4683
4684         if ! combined_mgs_mds ; then
4685                 stop_mgs
4686         else
4687                 stop_mds || error "Unable to stop MDS"
4688         fi
4689
4690         setup_noconfig
4691         check_mount || error "error after nid replace"
4692         cleanup || error "cleanup failed"
4693         reformat
4694 }
4695 run_test 66 "replace nids"
4696
4697 test_67() { #LU-2950
4698         local legacy="$TMP/legacy_lnet_config"
4699         local new="$TMP/new_routes_test"
4700         local out="$TMP/config_out_file"
4701         local verify="$TMP/conv_verify"
4702         local verify_conf="$TMP/conf_verify"
4703
4704         # Create the legacy file that will be run through the
4705         # lustre_routes_conversion script
4706         cat <<- LEGACY_LNET_CONFIG > $legacy
4707                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4708                 tcp2 54 10.1.3.2@tcp;
4709                 tcp3 10.3.4.3@tcp:3;
4710                 tcp4 10.3.3.4@tcp;
4711         LEGACY_LNET_CONFIG
4712
4713         # Create the verification file to verify the output of
4714         # lustre_routes_conversion script against.
4715         cat <<- VERIFY_LNET_CONFIG > $verify
4716                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4717                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4718                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4719                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4720                 tcp4: { gateway: 10.3.3.4@tcp }
4721         VERIFY_LNET_CONFIG
4722
4723         # Create the verification file to verify the output of
4724         # lustre_routes_config script against
4725         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4726                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4727                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4728                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4729                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4730                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4731         VERIFY_LNET_CONFIG
4732
4733         lustre_routes_conversion $legacy $new > /dev/null
4734         if [ -f $new ]; then
4735                 # verify the conversion output
4736                 cmp -s $new $verify > /dev/null
4737                 if [ $? -eq 1 ]; then
4738                         error "routes conversion failed"
4739                 fi
4740
4741                 lustre_routes_config --dry-run --verbose $new > $out
4742                 # check that the script succeeded
4743                 cmp -s $out $verify_conf > /dev/null
4744                 if [ $? -eq 1 ]; then
4745                         error "routes config failed"
4746                 fi
4747         else
4748                 error "routes conversion test failed"
4749         fi
4750         # remove generated files
4751         rm -f $new $legacy $verify $verify_conf $out
4752 }
4753 run_test 67 "test routes conversion and configuration"
4754
4755 test_68() {
4756         local fid
4757         local seq
4758         local START
4759         local END
4760
4761         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4762                 { skip "Need MDS version at least 2.4.53"; return 0; }
4763
4764         umount_client $MOUNT || error "umount client failed"
4765
4766         if ! combined_mgs_mds; then
4767                 start_mgs || error "start mgs failed"
4768         fi
4769
4770         start_mdt 1 || error "MDT start failed"
4771         start_ost || error "Unable to start OST1"
4772
4773         # START-END - the sequences we'll be reserving
4774         START=$(do_facet $SINGLEMDS \
4775                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4776         END=$((START + (1 << 30)))
4777         do_facet $SINGLEMDS \
4778                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4779
4780         # reset the sequences MDT0000 has already assigned
4781         do_facet $SINGLEMDS \
4782                 $LCTL set_param seq.srv*MDT0000.space=clear
4783
4784         # remount to let the client allocate new sequence
4785         mount_client $MOUNT || error "mount client failed"
4786
4787         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4788         do_facet $SINGLEMDS \
4789                 $LCTL get_param seq.srv*MDT0000.space
4790         $LFS path2fid $DIR/$tfile
4791
4792         local old_ifs="$IFS"
4793         IFS='[:]'
4794         fid=($($LFS path2fid $DIR/$tfile))
4795         IFS="$old_ifs"
4796         let seq=${fid[1]}
4797
4798         if [[ $seq < $END ]]; then
4799                 error "used reserved sequence $seq?"
4800         fi
4801         cleanup || error "cleanup failed with $?"
4802 }
4803 run_test 68 "be able to reserve specific sequences in FLDB"
4804
4805 # Test 69: is about the total number of objects ever created on an OST.
4806 # so that when it is reformatted the normal MDS->OST orphan recovery won't
4807 # just "precreate" the missing objects. In the past it might try to recreate
4808 # millions of objects after an OST was reformatted
4809 test_69() {
4810         local server_version=$(lustre_version_code $SINGLEMDS)
4811
4812         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4813                 skip "Need MDS version at least 2.4.2" && return
4814
4815         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4816         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4817                 skip "Need MDS version at least 2.5.0" && return
4818
4819         setup
4820         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4821
4822         # use OST0000 since it probably has the most creations
4823         local OSTNAME=$(ostname_from_index 0)
4824         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4825         local last_id=$(do_facet mds1 $LCTL get_param -n \
4826                         osc.$mdtosc_proc1.prealloc_last_id)
4827
4828         # Want to have OST LAST_ID over 5 * OST_MAX_PRECREATE to
4829         # verify that the LAST_ID recovery is working properly. If
4830         # not, then the OST will refuse to allow the MDS connect
4831         # because the LAST_ID value is too different from the MDS
4832         #define OST_MAX_PRECREATE=20000
4833         local ost_max_pre=20000
4834         local num_create=$(( ost_max_pre * 5 + 1 - last_id))
4835
4836         # If the LAST_ID is already over 5 * OST_MAX_PRECREATE, we don't
4837         # need to create any files. So, skip this section.
4838         if [ $num_create -gt 0 ]; then
4839                 # Check the number of inodes available on OST0
4840                 local files=0
4841                 local ifree=$($LFS df -i $MOUNT | awk '/OST0000/ { print $4 }')
4842                 log "On OST0, $ifree inodes available. Want $num_create."
4843
4844                 $SETSTRIPE -i 0 $DIR/$tdir ||
4845                         error "$SETSTRIPE -i 0 $DIR/$tdir failed"
4846                 if [ $ifree -lt 10000 ]; then
4847                         files=$(( ifree - 50 ))
4848                 else
4849                         files=10000
4850                 fi
4851
4852                 local j=$((num_create / files + 1))
4853                 for i in $(seq 1 $j); do
4854                         createmany -o $DIR/$tdir/$tfile-$i- $files ||
4855                                 error "createmany fail create $files files: $?"
4856                         unlinkmany $DIR/$tdir/$tfile-$i- $files ||
4857                                 error "unlinkmany failed unlink $files files"
4858                 done
4859         fi
4860
4861         # delete all of the files with objects on OST0 so the
4862         # filesystem is not inconsistent later on
4863         $LFS find $MOUNT --ost 0 -print0 | xargs -0 rm
4864
4865         umount_client $MOUNT || error "umount client failed"
4866         stop_ost || error "OST0 stop failure"
4867         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4868                 $(ostdevname 1) $(ostvdevname 1) ||
4869                 error "reformat and replace $ostdev failed"
4870         start_ost || error "OST0 restart failure"
4871         wait_osc_import_state mds ost FULL
4872
4873         mount_client $MOUNT || error "mount client failed"
4874         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4875         local idx=$($GETSTRIPE -i $DIR/$tdir/$tfile-last)
4876         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4877
4878         local iused=$($LFS df -i $MOUNT | awk '/OST0000/ { print $3 }')
4879         log "On OST0, $iused used inodes"
4880         [ $iused -ge $((ost_max_pre/2 + 1000)) ] &&
4881                 error "OST replacement created too many inodes; $iused"
4882         cleanup || error "cleanup failed with $?"
4883 }
4884 run_test 69 "replace an OST with the same index"
4885
4886 test_70a() {
4887         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4888         local MDTIDX=1
4889
4890         cleanup || error "cleanup failed with $?"
4891
4892         start_mdt 1 || error "MDT0 start fail"
4893
4894         start_ost || error "OST0 start fail"
4895         for num in $(seq 2 $MDSCOUNT); do
4896                 start_mdt $num || return
4897         done
4898
4899         mount_client $MOUNT || error "mount client fails"
4900
4901         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4902
4903         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4904                 error "create remote dir fail"
4905
4906         rm -rf $DIR/$tdir || error "delete dir fail"
4907         cleanup || error "cleanup failed with $?"
4908 }
4909 run_test 70a "start MDT0, then OST, then MDT1"
4910
4911 test_70b() {
4912         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4913         local MDTIDX=1
4914
4915         start_ost || error "OST0 start fail"
4916
4917         start_mds || error "MDS start fail"
4918
4919         mount_client $MOUNT || error "mount client fails"
4920
4921         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4922
4923         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4924                 error "create remote dir fail"
4925
4926         rm -rf $DIR/$tdir || error "delete dir fail"
4927
4928         cleanup || error "cleanup failed with $?"
4929 }
4930 run_test 70b "start OST, MDT1, MDT0"
4931
4932 test_70c() {
4933         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4934         local MDTIDX=1
4935
4936         start_mds || error "MDS start fail"
4937         start_ost || error "OST0 start fail"
4938
4939         mount_client $MOUNT || error "mount client fails"
4940         stop_mdt 1 || error "MDT1 start fail"
4941
4942         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4943         echo "deactivate $mdc_for_mdt1"
4944         $LCTL --device $mdc_for_mdt1 deactivate ||
4945                 error "set $mdc_for_mdt1 deactivate failed"
4946
4947         mkdir $DIR/$tdir && error "mkdir succeed"
4948
4949         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4950                 error "create remote dir succeed"
4951
4952         cleanup || error "cleanup failed with $?"
4953 }
4954 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4955
4956 test_70d() {
4957         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4958         local MDTIDX=1
4959
4960         start_mds || error "MDS start fail"
4961         start_ost || error "OST0 start fail"
4962
4963         mount_client $MOUNT || error "mount client fails"
4964
4965         stop_mdt 2 || error "MDT1 start fail"
4966
4967         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4968                              awk '{print $4}')
4969         echo "deactivate $mdc_for_mdt2"
4970         $LCTL --device $mdc_for_mdt2 deactivate ||
4971                 error "set $mdc_for_mdt2 deactivate failed"
4972
4973         mkdir $DIR/$tdir || error "mkdir fail"
4974         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4975                 error "create remote dir succeed"
4976
4977         rm -rf $DIR/$tdir || error "delete dir fail"
4978
4979         cleanup || error "cleanup failed with $?"
4980 }
4981 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4982
4983 test_70e() {
4984         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4985
4986         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.62) ] ||
4987                 { skip "Need MDS version at least 2.7.62"; return 0; }
4988
4989         cleanup || error "cleanup failed with $?"
4990
4991         local mdsdev=$(mdsdevname 1)
4992         local ostdev=$(ostdevname 1)
4993         local mdsvdev=$(mdsvdevname 1)
4994         local ostvdev=$(ostvdevname 1)
4995         local opts_mds="$(mkfs_opts mds1 $mdsdev) --reformat $mdsdev $mdsvdev"
4996         local opts_ost="$(mkfs_opts ost1 $ostdev) --reformat $ostdev $ostvdev"
4997
4998         add mds1 $opts_mds || error "add mds1 failed"
4999         start_mdt 1 || error "start mdt1 failed"
5000         add ost1 $opts_ost || error "add ost1 failed"
5001         start_ost || error "start ost failed"
5002         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
5003
5004         local soc=$(do_facet mds1 "$LCTL get_param -n \
5005                     mdt.*MDT0000.sync_lock_cancel")
5006         [ $soc == "never" ] || error "SoC enabled on single MDS"
5007
5008         for i in $(seq 2 $MDSCOUNT); do
5009                 mdsdev=$(mdsdevname $i)
5010                 mdsvdev=$(mdsvdevname $i)
5011                 opts_mds="$(mkfs_opts mds$i $mdsdev) --reformat $mdsdev \
5012                           $mdsvdev"
5013                 add mds$i $opts_mds || error "add mds$i failed"
5014                 start_mdt $i || error "start mdt$i fail"
5015         done
5016
5017         wait_dne_interconnect
5018
5019         for i in $(seq $MDSCOUNT); do
5020                 soc=$(do_facet mds$i "$LCTL get_param -n \
5021                         mdt.*MDT000$((i - 1)).sync_lock_cancel")
5022                 [ $soc == "blocking" ] || error "SoC not enabled on DNE"
5023         done
5024
5025         for i in $(seq 2 $MDSCOUNT); do
5026                 stop_mdt $i || error "stop mdt$i fail"
5027         done
5028         soc=$(do_facet mds1 "$LCTL get_param -n \
5029                 mdt.*MDT0000.sync_lock_cancel")
5030         [ $soc == "never" ] || error "SoC enabled on single MDS"
5031         umount_client $MOUNT -f > /dev/null
5032
5033         cleanup || error "cleanup failed with $?"
5034 }
5035 run_test 70e "Sync-on-Cancel will be enabled by default on DNE"
5036
5037 test_71a() {
5038         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5039         if combined_mgs_mds; then
5040                 skip "needs separate MGS/MDT" && return
5041         fi
5042         local MDTIDX=1
5043
5044         start_mdt 1 || error "MDT0 start fail"
5045         start_ost || error "OST0 start fail"
5046         for num in $(seq 2 $MDSCOUNT); do
5047                 start_mdt $num || return
5048         done
5049
5050         start_ost2 || error "OST1 start fail"
5051
5052         mount_client $MOUNT || error "mount client fails"
5053
5054         mkdir $DIR/$tdir || error "mkdir fail"
5055         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5056                 error "create remote dir succeed"
5057
5058         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5059         rm -rf $DIR/$tdir || error "delete dir fail"
5060
5061         umount_client $MOUNT || error "umount_client failed"
5062         stop_mds || error "MDS stop fail"
5063         stop_ost || error "OST0 stop fail"
5064         stop_ost2 || error "OST1 stop fail"
5065 }
5066 run_test 71a "start MDT0 OST0, MDT1, OST1"
5067
5068 test_71b() {
5069         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5070         if combined_mgs_mds; then
5071                 skip "needs separate MGS/MDT" && return
5072         fi
5073         local MDTIDX=1
5074
5075         for num in $(seq 2 $MDSCOUNT); do
5076                 start_mdt $num || return
5077         done
5078         start_ost || error "OST0 start fail"
5079         start_mdt 1 || error "MDT0 start fail"
5080         start_ost2 || error "OST1 start fail"
5081
5082         mount_client $MOUNT || error "mount client fails"
5083
5084         mkdir $DIR/$tdir || error "mkdir fail"
5085         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5086                 error "create remote dir succeed"
5087
5088         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5089         rm -rf $DIR/$tdir || error "delete dir fail"
5090
5091         umount_client $MOUNT || error "umount_client failed"
5092         stop_mds || error "MDT0 stop fail"
5093         stop_ost || error "OST0 stop fail"
5094         stop_ost2 || error "OST1 stop fail"
5095 }
5096 run_test 71b "start MDT1, OST0, MDT0, OST1"
5097
5098 test_71c() {
5099         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5100         if combined_mgs_mds; then
5101                 skip "needs separate MGS/MDT" && return
5102         fi
5103         local MDTIDX=1
5104
5105         start_ost || error "OST0 start fail"
5106         start_ost2 || error "OST1 start fail"
5107         for num in $(seq 2 $MDSCOUNT); do
5108                 start_mdt $num || return
5109         done
5110         start_mdt 1 || error "MDT0 start fail"
5111
5112         mount_client $MOUNT || error "mount client fails"
5113
5114         mkdir $DIR/$tdir || error "mkdir fail"
5115         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5116                 error "create remote dir succeed"
5117
5118         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5119         rm -rf $DIR/$tdir || error "delete dir fail"
5120
5121         umount_client $MOUNT || error "umount_client failed"
5122         stop_mds || error "MDS stop fail"
5123         stop_ost || error "OST0 stop fail"
5124         stop_ost2 || error "OST1 stop fail"
5125
5126 }
5127 run_test 71c "start OST0, OST1, MDT1, MDT0"
5128
5129 test_71d() {
5130         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5131         if combined_mgs_mds; then
5132                 skip "needs separate MGS/MDT" && return
5133         fi
5134         local MDTIDX=1
5135
5136         start_ost || error "OST0 start fail"
5137         for num in $(seq 2 $MDSCOUNT); do
5138                 start_mdt $num || return
5139         done
5140         start_mdt 1 || error "MDT0 start fail"
5141         start_ost2 || error "OST1 start fail"
5142
5143         mount_client $MOUNT || error "mount client fails"
5144
5145         mkdir $DIR/$tdir || error "mkdir fail"
5146         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5147                         error "create remote dir succeed"
5148
5149         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5150         rm -rf $DIR/$tdir || error "delete dir fail"
5151
5152         umount_client $MOUNT || error "umount_client failed"
5153         stop_mds || error "MDS stop fail"
5154         stop_ost || error "OST0 stop fail"
5155         stop_ost2 || error "OST1 stop fail"
5156
5157 }
5158 run_test 71d "start OST0, MDT1, MDT0, OST1"
5159
5160 test_71e() {
5161         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5162         if combined_mgs_mds; then
5163                 skip "needs separate MGS/MDT" && return
5164         fi
5165         local MDTIDX=1
5166
5167         start_ost || error "OST0 start fail"
5168         for num in $(seq 2 $MDSCOUNT); do
5169                 start_mdt $num || return
5170         done
5171         start_ost2 || error "OST1 start fail"
5172         start_mdt 1 || error "MDT0 start fail"
5173
5174         mount_client $MOUNT || error "mount client fails"
5175
5176         mkdir $DIR/$tdir || error "mkdir fail"
5177         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5178                 error "create remote dir succeed"
5179
5180         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5181         rm -rf $DIR/$tdir || error "delete dir fail"
5182
5183         umount_client $MOUNT || error "umount_client failed"
5184         stop_mds || error "MDS stop fail"
5185         stop_ost || error "OST0 stop fail"
5186         stop_ost2 || error "OST1 stop fail"
5187
5188 }
5189 run_test 71e "start OST0, MDT1, OST1, MDT0"
5190
5191 test_72() { #LU-2634
5192         local mdsdev=$(mdsdevname 1)
5193         local ostdev=$(ostdevname 1)
5194         local cmd="$E2FSCK -fnvd $mdsdev"
5195         local fn=3
5196         local add_options
5197
5198         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
5199                 skip "ldiskfs only test" && return
5200
5201         if combined_mgs_mds; then
5202                 add_options='--reformat'
5203         else
5204                 add_options='--reformat --replace'
5205         fi
5206
5207         #tune MDT with "-O extents"
5208
5209         for num in $(seq $MDSCOUNT); do
5210                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
5211                         $add_options $(mdsdevname $num) $(mdsvdevname $num) ||
5212                         error "add mds $num failed"
5213                 do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
5214                         error "$TUNE2FS failed on mds${num}"
5215         done
5216
5217         add ost1 $(mkfs_opts ost1 $ostdev) $add_options $ostdev ||
5218                 error "add $ostdev failed"
5219         start_mds || error "start mds failed"
5220         start_ost || error "start ost failed"
5221         mount_client $MOUNT || error "mount client failed"
5222
5223         #create some short symlinks
5224         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5225         createmany -o $DIR/$tdir/$tfile-%d $fn
5226         echo "create $fn short symlinks"
5227         for i in $(seq -w 1 $fn); do
5228                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
5229         done
5230         ls -al $MOUNT
5231
5232         #umount
5233         umount_client $MOUNT || error "umount client failed"
5234         stop_mds || error "stop mds failed"
5235         stop_ost || error "stop ost failed"
5236
5237         #run e2fsck
5238         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
5239 }
5240 run_test 72 "test fast symlink with extents flag enabled"
5241
5242 test_73() { #LU-3006
5243         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
5244         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
5245                 error "1st tunefs failed"
5246         start_mgsmds || error "start mds failed"
5247         start_ost || error "start ost failed"
5248         mount_client $MOUNT || error "mount client failed"
5249         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
5250                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
5251         umount_client $MOUNT || error "umount client failed"
5252         stopall
5253         reformat
5254 }
5255 run_test 73 "failnode to update from mountdata properly"
5256
5257 test_75() { # LU-2374
5258         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
5259                         skip "Need MDS version at least 2.4.1" && return
5260
5261         local index=0
5262         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
5263                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
5264         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
5265                 --reformat $(ostdevname 1) $(ostvdevname 1)"
5266
5267         #check with default parameters
5268         add mds1 $opts_mds || error "add mds1 failed for default params"
5269         add ost1 $opts_ost || error "add ost1 failed for default params"
5270
5271         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
5272         opts_mds=$(echo $opts_mds |
5273                    sed -e "s/--index=$index/--index=$index --mdt/")
5274         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
5275         opts_ost=$(echo $opts_ost |
5276                    sed -e "s/--index=$index/--index=$index --ost/")
5277
5278         add mds1 $opts_mds || error "add mds1 failed for new params"
5279         add ost1 $opts_ost || error "add ost1 failed for new params"
5280         if ! combined_mgs_mds; then
5281                 stop_mgs || error "stop mgs failed"
5282         fi
5283         reformat
5284         return 0
5285 }
5286 run_test 75 "The order of --index should be irrelevant"
5287
5288 test_76a() {
5289         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
5290                 { skip "Need MDS version at least 2.4.52" && return 0; }
5291
5292         if ! combined_mgs_mds; then
5293                 start_mgs || error "start mgs failed"
5294         fi
5295         setup
5296         local MDMB_PARAM="osc.*.max_dirty_mb"
5297         echo "Change MGS params"
5298         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
5299                 head -1)
5300         echo "max_dirty_mb: $MAX_DIRTY_MB"
5301         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
5302         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
5303         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
5304         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5305                 head -1" $NEW_MAX_DIRTY_MB
5306         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5307         echo "$MAX_DIRTY_MB"
5308         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5309                 error "error while apply max_dirty_mb"
5310
5311         echo "Check the value is stored after remount"
5312         stopall
5313         setupall
5314         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5315                 head -1" $NEW_MAX_DIRTY_MB
5316         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5317         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5318                 error "max_dirty_mb is not saved after remount"
5319
5320         echo "Change OST params"
5321         CLIENT_PARAM="obdfilter.*.client_cache_count"
5322         local CLIENT_CACHE_COUNT
5323         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5324                 head -1)
5325         echo "client_cache_count: $CLIENT_CACHE_COUNT"
5326         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
5327         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
5328         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
5329         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5330                 head -1" $NEW_CLIENT_CACHE_COUNT
5331         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5332                 head -1)
5333         echo "$CLIENT_CACHE_COUNT"
5334         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5335                 error "error while apply client_cache_count"
5336
5337         echo "Check the value is stored after remount"
5338         stopall
5339         setupall
5340         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5341                 head -1" $NEW_CLIENT_CACHE_COUNT
5342         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5343                 head -1)
5344         echo "$CLIENT_CACHE_COUNT"
5345         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5346                 error "client_cache_count is not saved after remount"
5347         stopall
5348 }
5349 run_test 76a "set permanent params set_param -P"
5350
5351 test_76b() { # LU-4783
5352         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
5353                 { skip "Need MGS version at least 2.5.57" && return 0; }
5354         stopall
5355         setupall
5356         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
5357                 error "start params log failed"
5358         stopall
5359 }
5360 run_test 76b "verify params log setup correctly"
5361
5362 test_76c() {
5363         [[ $(lustre_version_code mgs) -ge $(version_code 2.8.54) ]] ||
5364                 { skip "Need MDS version at least 2.4.52" && return 0; }
5365         setupall
5366         local MASK_PARAM="mdd.*.changelog_mask"
5367         echo "Change changelog_mask"
5368         do_facet mgs $LCTL set_param -P $MASK_PARAM=-CLOSE ||
5369                 error "Can't change changlog_mask"
5370         wait_update $(facet_host mds) "$LCTL get_param -n $MASK_PARAM |
5371                 grep 'CLOSE'" ""
5372
5373         echo "Check the value is stored after mds remount"
5374         stop_mds || error "Failed to stop MDS"
5375         start_mds || error "Failed to start MDS"
5376         local CHANGELOG_MASK=$(do_facet mgs $LCTL get_param -n $MASK_PARAM)
5377         echo $CHANGELOG_MASK | grep CLOSE > /dev/null &&
5378                 error "changelog_mask is not changed"
5379
5380         stopall
5381 }
5382 run_test 76c "verify changelog_mask is applied with set_param -P"
5383
5384 test_76d() { #LU-9399
5385         setupall
5386
5387         local xattr_cache="llite.*.xattr_cache"
5388         local cmd="$LCTL get_param -n $xattr_cache | head -1"
5389         local new=$((($(eval $cmd) + 1) % 2))
5390
5391         echo "lctl set_param -P llite.*.xattr_cache=$new"
5392         do_facet mgs $LCTL set_param -P $xattr_cache=$new ||
5393                 error "Can't change xattr_cache"
5394         wait_update $HOSTNAME "$cmd" "$new"
5395
5396         echo "Check $xattr_cache on client $MOUNT"
5397         umount_client $MOUNT || error "umount $MOUNT failed"
5398         mount_client $MOUNT || error "mount $MOUNT failed"
5399         [ $(eval $cmd) -eq $new ] ||
5400                 error "$xattr_cache != $new on client $MOUNT"
5401
5402         echo "Check $xattr_cache on the new client $MOUNT2"
5403         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
5404         [ $(eval $cmd) -eq $new ] ||
5405                 error "$xattr_cache != $new on client $MOUNT2"
5406         umount_client $MOUNT2 || error "umount $MOUNT2 failed"
5407
5408         stopall
5409 }
5410 run_test 76d "verify llite.*.xattr_cache can be set by 'set_param -P' correctly"
5411
5412 test_77() { # LU-3445
5413         local server_version=$(lustre_version_code $SINGLEMDS)
5414         [[ $server_version -ge $(version_code 2.8.55) ]] ||
5415                 { skip "Need MDS version 2.8.55+ "; return; }
5416
5417         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
5418                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
5419                 skip_env "mixed loopback and real device not working" && return
5420         fi
5421
5422         local fs2mdsdev=$(mdsdevname 1_2)
5423         local fs2ostdev=$(ostdevname 1_2)
5424         local fs2mdsvdev=$(mdsvdevname 1_2)
5425         local fs2ostvdev=$(ostvdevname 1_2)
5426         local fsname=test1234
5427         local mgsnid
5428         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
5429
5430         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
5431
5432         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
5433                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
5434         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
5435                 error "start fs2mds failed"
5436
5437         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
5438         mgsnid="0.0.0.0@tcp,$mgsnid,$mgsnid:$mgsnid"
5439
5440         add fs2ost --mgsnode=$mgsnid $(mkfs_opts ost1 $fs2ostdev) \
5441                 --failnode=$failnid --fsname=$fsname \
5442                 --reformat $fs2ostdev $fs2ostvdev ||
5443                         error "add fs2ost failed"
5444         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
5445
5446         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
5447         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
5448         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
5449         cleanup_fs2
5450 }
5451 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
5452
5453 test_78() {
5454         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
5455            $(facet_fstype ost1) != ldiskfs ]] &&
5456                 skip "ldiskfs only test" && return
5457
5458         # reformat the Lustre filesystem with a smaller size
5459         local saved_MDSCOUNT=$MDSCOUNT
5460         local saved_MDSSIZE=$MDSSIZE
5461         local saved_OSTCOUNT=$OSTCOUNT
5462         local saved_OSTSIZE=$OSTSIZE
5463         MDSCOUNT=1
5464         OSTCOUNT=1
5465         MDSSIZE=$((MDSSIZE - 20000))
5466         OSTSIZE=$((OSTSIZE - 20000))
5467         reformat || error "(1) reformat Lustre filesystem failed"
5468         MDSSIZE=$saved_MDSSIZE
5469         OSTSIZE=$saved_OSTSIZE
5470
5471         # mount the Lustre filesystem
5472         setup_noconfig || error "(2) setup Lustre filesystem failed"
5473
5474         # create some files
5475         log "create test files"
5476         local i
5477         local file
5478         local num_files=100
5479
5480         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
5481         $LFS df; $LFS df -i
5482         for i in $(seq $num_files); do
5483                 file=$MOUNT/$tdir/$tfile-$i
5484                 dd if=/dev/urandom of=$file count=1 bs=1M || {
5485                         $LCTL get_param osc.*.cur*grant*
5486                         $LFS df; $LFS df -i;
5487                         # stop creating files if there is no more space
5488                         if [ ! -e $file ]; then
5489                                 num_files=$((i - 1))
5490                                 break
5491                         fi
5492
5493                         $LFS getstripe -v $file
5494                         local ost_idx=$(LFS getstripe -i $file)
5495                         do_facet ost$((ost_idx + 1)) \
5496                                 $LCTL get_param obdfilter.*.*grant*
5497                         error "(4) create $file failed"
5498                 }
5499         done
5500
5501         # unmount the Lustre filesystem
5502         cleanup || error "(5) cleanup Lustre filesystem failed"
5503
5504         # run e2fsck on the MDT and OST devices
5505         local mds_host=$(facet_active_host $SINGLEMDS)
5506         local ost_host=$(facet_active_host ost1)
5507         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5508         local ost_dev=$(ostdevname 1)
5509
5510         run_e2fsck $mds_host $mds_dev "-y"
5511         run_e2fsck $ost_host $ost_dev "-y"
5512
5513         # get the original block count of the MDT and OST filesystems
5514         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
5515         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
5516
5517         # expand the MDT and OST filesystems to the device size
5518         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
5519         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
5520
5521         # run e2fsck on the MDT and OST devices again
5522         run_e2fsck $mds_host $mds_dev "-y"
5523         run_e2fsck $ost_host $ost_dev "-y"
5524
5525         # mount the Lustre filesystem
5526         setup
5527
5528         # check the files
5529         log "check files after expanding the MDT and OST filesystems"
5530         for i in $(seq $num_files); do
5531                 file=$MOUNT/$tdir/$tfile-$i
5532                 $CHECKSTAT -t file -s 1048576 $file ||
5533                         error "(6) checkstat $file failed"
5534         done
5535
5536         # create more files
5537         log "create more files after expanding the MDT and OST filesystems"
5538         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
5539                 file=$MOUNT/$tdir/$tfile-$i
5540                 dd if=/dev/urandom of=$file count=1 bs=1M ||
5541                         error "(7) create $file failed"
5542         done
5543
5544         # unmount the Lustre filesystem
5545         cleanup || error "(8) cleanup Lustre filesystem failed"
5546
5547         # run e2fsck on the MDT and OST devices
5548         run_e2fsck $mds_host $mds_dev "-y"
5549         run_e2fsck $ost_host $ost_dev "-y"
5550
5551         # get the maximum block count of the MDT and OST filesystems
5552         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
5553         local ost_max_blks=$(get_block_count ost1 $ost_dev)
5554
5555         # get the minimum block count of the MDT and OST filesystems
5556         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
5557                                 grep minimum | sed -e 's/^.*filesystem: //g')
5558         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
5559                                 grep minimum | sed -e 's/^.*filesystem: //g')
5560
5561         # shrink the MDT and OST filesystems to a smaller size
5562         local shrunk=false
5563         local new_blks
5564         local base_blks
5565         if [[ $mds_max_blks -gt $mds_min_blks &&
5566               $mds_max_blks -gt $mds_orig_blks ]]; then
5567                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
5568                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
5569                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
5570                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
5571                         error "shrink $SINGLEMDS to $new_blks failed"
5572                 shrunk=true
5573         fi
5574
5575         if [[ $ost_max_blks -gt $ost_min_blks &&
5576               $ost_max_blks -gt $ost_orig_blks ]]; then
5577                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
5578                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
5579                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
5580                 run_resize2fs ost1 $ost_dev $new_blks ||
5581                         error "shrink ost1 to $new_blks failed"
5582                 shrunk=true
5583         fi
5584
5585         # check whether the MDT or OST filesystem was shrunk or not
5586         if ! $shrunk; then
5587                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
5588                 reformat || error "(10) reformat Lustre filesystem failed"
5589                 return 0
5590         fi
5591
5592         # run e2fsck on the MDT and OST devices again
5593         run_e2fsck $mds_host $mds_dev "-y"
5594         run_e2fsck $ost_host $ost_dev "-y"
5595
5596         # mount the Lustre filesystem again
5597         setup
5598
5599         # check the files
5600         log "check files after shrinking the MDT and OST filesystems"
5601         for i in $(seq $((num_files + 10))); do
5602                 file=$MOUNT/$tdir/$tfile-$i
5603                 $CHECKSTAT -t file -s 1048576 $file ||
5604                         error "(11) checkstat $file failed"
5605         done
5606
5607         # unmount and reformat the Lustre filesystem
5608         cleanup || error "(12) cleanup Lustre filesystem failed"
5609         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
5610
5611         MDSCOUNT=$saved_MDSCOUNT
5612         OSTCOUNT=$saved_OSTCOUNT
5613         reformat || error "(14) reformat Lustre filesystem failed"
5614 }
5615 run_test 78 "run resize2fs on MDT and OST filesystems"
5616
5617 test_79() { # LU-4227
5618         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
5619                 { skip "Need MDS version at least 2.5.59"; return 0; }
5620
5621         local mdsdev1=$(mdsdevname 1)
5622         local mdsvdev1=$(mdsvdevname 1)
5623         local mdsdev2=$(mdsdevname 2)
5624         local mdsvdev2=$(mdsvdevname 2)
5625         local ostdev1=$(ostdevname 1)
5626         local ostvdev1=$(ostvdevname 1)
5627         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
5628         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
5629         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
5630         local mgsnode_opt
5631
5632         # remove --mgs/--mgsnode from mkfs.lustre options
5633         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
5634
5635         mgsnode_opt=$(echo $opts_mds2 |
5636                 awk '{ for ( i = 1; i < NF; i++ )
5637                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5638         [ -n $mgsnode_opt ] &&
5639                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
5640
5641         mgsnode_opt=$(echo $opts_ost1 |
5642                 awk '{ for ( i = 1; i < NF; i++ )
5643                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5644         [ -n $mgsnode_opt ] &&
5645                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
5646
5647         # -MGS, format a mdt without --mgs option
5648         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
5649                 error "Must specify --mgs when formatting mdt combined with mgs"
5650
5651         # +MGS, format a mdt/ost without --mgsnode option
5652         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
5653                 > /dev/null || error "start mds1 failed"
5654         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
5655                 error "Must specify --mgsnode when formatting a mdt"
5656         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
5657                 error "Must specify --mgsnode when formatting an ost"
5658
5659         reformat
5660 }
5661 run_test 79 "format MDT/OST without mgs option (should return errors)"
5662
5663 test_80() {
5664         start_mds || error "Failed to start MDT"
5665         start_ost || error "Failed to start OST1"
5666         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
5667 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
5668         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
5669         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
5670         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
5671         sleep 30
5672         start_ost2 || error "Failed to start OST2"
5673
5674         do_facet ost1 "$LCTL set_param fail_loc=0"
5675         stopall
5676 }
5677 run_test 80 "mgc import reconnect race"
5678
5679 #Save the original values of $OSTCOUNT and $OSTINDEX$i.
5680 save_ostindex() {
5681         local new_ostcount=$1
5682         saved_ostcount=$OSTCOUNT
5683         OSTCOUNT=$new_ostcount
5684
5685         local i
5686         local index
5687         for i in $(seq $OSTCOUNT); do
5688                 index=OSTINDEX$i
5689                 eval saved_ostindex$i=${!index}
5690                 eval OSTINDEX$i=""
5691         done
5692 }
5693
5694 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
5695 restore_ostindex() {
5696         trap 0
5697
5698         local i
5699         local index
5700         for i in $(seq $OSTCOUNT); do
5701                 index=saved_ostindex$i
5702                 eval OSTINDEX$i=${!index}
5703         done
5704         OSTCOUNT=$saved_ostcount
5705
5706         formatall
5707 }
5708
5709 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
5710 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
5711 # assigned index and ensures we can mount such a formatted file system
5712 test_81() { # LU-4665
5713         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5714                 { skip "Need MDS version at least 2.6.54" && return; }
5715         [[ $OSTCOUNT -ge 3 ]] || { skip_env "needs >= 3 OSTs" && return; }
5716
5717         stopall
5718
5719         # Each time RANDOM is referenced, a random integer between 0 and 32767
5720         # is generated.
5721         local i
5722         local saved_ostindex1=$OSTINDEX1
5723         for i in 65535 $((RANDOM + 65536)); do
5724                 echo -e "\nFormat ost1 with --index=$i, should fail"
5725                 OSTINDEX1=$i
5726                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
5727                    $(ostdevname 1) $(ostvdevname 1); then
5728                         OSTINDEX1=$saved_ostindex1
5729                         error "format ost1 with --index=$i should fail"
5730                 fi
5731         done
5732         OSTINDEX1=$saved_ostindex1
5733
5734         save_ostindex 3
5735
5736         # Format OSTs with random sparse indices.
5737         trap "restore_ostindex" EXIT
5738         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices"
5739         OST_INDEX_LIST=[0,$((RANDOM * 2 % 65533 + 1)),65534] formatall
5740
5741         # Setup and check Lustre filesystem.
5742         start_mgsmds || error "start_mgsmds failed"
5743         for i in $(seq $OSTCOUNT); do
5744                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5745                         error "start ost$i failed"
5746         done
5747
5748         mount_client $MOUNT || error "mount client $MOUNT failed"
5749         check_mount || error "check client $MOUNT failed"
5750
5751         # Check max_easize.
5752         local max_easize=$($LCTL get_param -n llite.*.max_easize)
5753         [[ $max_easize -eq 128 ]] ||
5754                 error "max_easize is $max_easize, should be 128 bytes"
5755
5756         restore_ostindex
5757 }
5758 run_test 81 "sparse OST indexing"
5759
5760 # Here we exercise the stripe placement functionality on a file system that
5761 # has formatted the OST with a random index. With the file system the following
5762 # functionality is tested:
5763 #
5764 # 1. Creating a new file with a specific stripe layout.
5765 #
5766 # 2. Modifiy a existing empty file with a specific stripe layout.
5767 #
5768 # 3. Ensure we fail to set the stripe layout of a file that already has one.
5769 #
5770 # 4. If ost-index is defined we need to ensure it is the first entry in the
5771 #    ost index list returned by lfs getstripe.
5772 #
5773 # 5. Lastly ensure this functionality fails with directories.
5774 test_82a() { # LU-4665
5775         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5776                 { skip "Need MDS version at least 2.6.54" && return; }
5777         [[ $OSTCOUNT -ge 3 ]] || { skip_env "needs >= 3 OSTs" && return; }
5778
5779         stopall
5780
5781         save_ostindex 3
5782
5783         # Format OSTs with random sparse indices.
5784         local i
5785         local index
5786         local ost_indices
5787         local LOV_V1_INSANE_STRIPE_COUNT=65532
5788         for i in $(seq $OSTCOUNT); do
5789                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
5790                 ost_indices+=" $index"
5791         done
5792         ost_indices=$(comma_list $ost_indices)
5793
5794         trap "restore_ostindex" EXIT
5795         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5796         OST_INDEX_LIST=[$ost_indices] formatall
5797
5798         # Setup Lustre filesystem.
5799         start_mgsmds || error "start_mgsmds failed"
5800         for i in $(seq $OSTCOUNT); do
5801                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5802                         error "start ost$i failed"
5803         done
5804
5805         mount_client $MOUNT || error "mount client $MOUNT failed"
5806         wait_osts_up
5807
5808         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5809         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5810
5811         # 1. If the file does not exist, new file will be created
5812         #    with specified OSTs.
5813         local file=$DIR/$tdir/$tfile-1
5814         local cmd="$SETSTRIPE -o $ost_indices $file"
5815         echo -e "\n$cmd"
5816         eval $cmd || error "$cmd failed"
5817         check_stripe_count $file $OSTCOUNT
5818         check_obdidx $file $ost_indices
5819         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5820                 error "write $file failed"
5821
5822         # 2. If the file already exists and is an empty file, the file
5823         #    will be attached with specified layout.
5824         file=$DIR/$tdir/$tfile-2
5825         mcreate $file || error "mcreate $file failed"
5826         cmd="$SETSTRIPE -o $ost_indices $file"
5827         echo -e "\n$cmd"
5828         eval $cmd || error "$cmd failed"
5829         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5830                 error "write $file failed"
5831         check_stripe_count $file $OSTCOUNT
5832         check_obdidx $file $ost_indices
5833
5834         # 3. If the file already has a valid layout attached, the command
5835         #    should fail with EBUSY.
5836         echo -e "\n$cmd"
5837         eval $cmd && error "stripe is already set on $file, $cmd should fail"
5838
5839         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
5840         #    be in the OST indices list.
5841         local start_ost_idx=${ost_indices##*,}
5842         file=$DIR/$tdir/$tfile-3
5843         cmd="$SETSTRIPE -o $ost_indices -i $start_ost_idx $file"
5844         echo -e "\n$cmd"
5845         eval $cmd || error "$cmd failed"
5846         check_stripe_count $file $OSTCOUNT
5847         check_obdidx $file $ost_indices
5848         check_start_ost_idx $file $start_ost_idx
5849
5850         file=$DIR/$tdir/$tfile-4
5851         cmd="$SETSTRIPE"
5852         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
5853         cmd+=" -i $start_ost_idx $file"
5854         echo -e "\n$cmd"
5855         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
5856
5857         # 5. Specifying OST indices for directory should fail with ENOSUPP.
5858         local dir=$DIR/$tdir/$tdir
5859         mkdir $dir || error "mkdir $dir failed"
5860         cmd="$SETSTRIPE -o $ost_indices $dir"
5861         echo -e "\n$cmd"
5862         eval $cmd && error "$cmd should fail, specifying OST indices" \
5863                            "for directory is not supported"
5864
5865         restore_ostindex
5866 }
5867 run_test 82a "specify OSTs for file (succeed) or directory (fail)"
5868
5869 cleanup_82b() {
5870         trap 0
5871
5872         # Remove OSTs from a pool and destroy the pool.
5873         destroy_pool $ost_pool || true
5874
5875         if ! combined_mgs_mds ; then
5876                 umount_mgs_client
5877         fi
5878         restore_ostindex
5879 }
5880
5881 # Test 82b is run to ensure that if the user supplies a pool with a specific
5882 # stripe layout that it behaves proprerly. It should fail in the case that
5883 # the supplied OST index list points to OSTs not contained in the user
5884 # supplied pool.
5885 test_82b() { # LU-4665
5886         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5887                 { skip "Need MDS version at least 2.6.54" && return; }
5888         [[ $OSTCOUNT -ge 4 ]] || { skip_env "needs >= 4 OSTs" && return; }
5889
5890         stopall
5891
5892         save_ostindex 4
5893
5894         # Format OSTs with random sparse indices.
5895         local i
5896         local index
5897         local ost_indices
5898         local LOV_V1_INSANE_STRIPE_COUNT=65532
5899         for i in $(seq $OSTCOUNT); do
5900                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
5901                 ost_indices+=" $index"
5902         done
5903         ost_indices=$(comma_list $ost_indices)
5904
5905         trap "restore_ostindex" EXIT
5906         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5907         OST_INDEX_LIST=[$ost_indices] formatall
5908
5909         # Setup Lustre filesystem.
5910         start_mgsmds || error "start_mgsmds failed"
5911         for i in $(seq $OSTCOUNT); do
5912                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5913                         error "start ost$i failed"
5914         done
5915
5916         mount_client $MOUNT || error "mount client $MOUNT failed"
5917         if ! combined_mgs_mds ; then
5918                 mount_mgs_client
5919         fi
5920
5921         wait_osts_up
5922         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5923         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5924
5925         # Create a new pool and add OSTs into it.
5926         local ost_pool=$FSNAME.$TESTNAME
5927         create_pool $ost_pool || error "create OST pool $ost_pool failed"
5928
5929         trap - EXIT
5930         trap "cleanup_82b" EXIT
5931
5932         local ost_idx_in_list=${ost_indices##*,}
5933         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
5934                                 $ost_idx_in_list)
5935
5936         local ost_targets="$FSNAME-OST["
5937         for i in ${ost_idx_in_pool//,/ }; do
5938                 ost_targets=$ost_targets$(printf "%04x," $i)
5939         done
5940         ost_targets="${ost_targets%,}]"
5941
5942         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
5943                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
5944                                  sort -u | tr '\n' ' ')
5945
5946         local cmd="$LCTL pool_add $ost_pool $ost_targets"
5947         do_facet mgs $cmd || error "$cmd failed"
5948         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
5949                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
5950                                         error "wait_update $ost_pool failed"
5951         wait_update_facet $SINGLEMDS "$LCTL pool_list $ost_pool | wc -l" 4 ||
5952                                 error "wait_update pool_list $ost_pool failed"
5953
5954         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
5955         # then the OSTs must be the members of the pool.
5956         local file=$DIR/$tdir/$tfile
5957         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5958         echo -e "\n$cmd"
5959         eval $cmd && error "OST with index $ost_idx_in_list should be" \
5960                            "in OST pool $ost_pool"
5961
5962         # Only select OST $ost_idx_in_list from $ost_pool for file.
5963         ost_idx_in_list=${ost_idx_in_pool#*,}
5964         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5965         echo -e "\n$cmd"
5966         eval $cmd || error "$cmd failed"
5967         cmd="$GETSTRIPE $file"
5968         echo -e "\n$cmd"
5969         eval $cmd || error "$cmd failed"
5970         check_stripe_count $file 2
5971         check_obdidx $file $ost_idx_in_list
5972         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5973                 error "write $file failed"
5974
5975         cleanup_82b
5976 }
5977 run_test 82b "specify OSTs for file with --pool and --ost-list options"
5978
5979 test_83() {
5980         [[ $(lustre_version_code ost1) -ge $(version_code 2.6.91) ]] ||
5981                 { skip "Need OST version at least 2.6.91" && return 0; }
5982         if [ $(facet_fstype ost1) != ldiskfs ]; then
5983                 skip "ldiskfs only test"
5984                 return
5985         fi
5986
5987         local dev
5988         local ostmnt
5989         local fstype
5990         local mnt_opts
5991
5992         dev=$(ostdevname 1)
5993         ostmnt=$(facet_mntpt ost1)
5994         fstype=$(facet_fstype ost1)
5995
5996         # Mount the OST as an ldiskfs filesystem.
5997         log "mount the OST $dev as a $fstype filesystem"
5998         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
5999                 --reformat $dev > /dev/null ||
6000                 error "format ost1 error"
6001
6002         if ! test -b $dev; then
6003                 mnt_opts=$(csa_add "$OST_MOUNT_OPTS" -o loop)
6004         fi
6005         echo "mnt_opts $mnt_opts"
6006         do_facet ost1 mount -t $fstype $dev \
6007                 $ostmnt $mnt_opts
6008         # Run llverfs on the mounted ldiskfs filesystem.
6009         # It is needed to get ENOSPACE.
6010         log "run llverfs in partial mode on the OST $fstype $ostmnt"
6011         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
6012                 "no" || error "run_llverfs error on $fstype"
6013
6014         # Unmount the OST.
6015         log "unmount the OST $dev"
6016         stop ost1
6017
6018         # Delete file IO_scrub. Later osd_scrub_setup will try to
6019         # create "IO_scrub" but will get ENOSPACE.
6020         writeconf_all
6021         echo "start ost1 service on `facet_active_host ost1`"
6022         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
6023
6024         local err
6025         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
6026         echo "string err $err"
6027         [ -z "$err" ] || error $err
6028         reformat
6029 }
6030 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
6031 Busy inodes after unmount ..."
6032
6033 test_84() {
6034         local facet=$SINGLEMDS
6035         local num=$(echo $facet | tr -d "mds")
6036         local dev=$(mdsdevname $num)
6037         local time_min=$(recovery_time_min)
6038         local recovery_duration
6039         local completed_clients
6040         local correct_clients
6041         local wrap_up=5
6042
6043         echo "start mds service on $(facet_active_host $facet)"
6044         start_mds \
6045         "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" $@ ||
6046                 error "start MDS failed"
6047
6048         start_ost || error "start OST0000 failed"
6049         start_ost2 || error "start OST0001 failed"
6050
6051         echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
6052
6053         mount_client $MOUNT1 || error "mount $MOUNT1 failed"
6054         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
6055         # make sure new superblock labels are sync'd before disabling writes
6056         sync_all_data
6057         sleep 5
6058
6059         replay_barrier $SINGLEMDS
6060         createmany -o $DIR1/$tfile-%d 1000
6061
6062         # We need to catch the end of recovery window to extend it.
6063         # Skip 5 requests and add delay to request handling.
6064         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
6065         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
6066
6067         facet_failover --fsck $SINGLEMDS || error "failover: $?"
6068         client_up
6069
6070         echo "recovery status"
6071         do_facet $SINGLEMDS \
6072                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status"
6073
6074         recovery_duration=$(do_facet $SINGLEMDS \
6075                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6076                 awk '/recovery_duration/ { print $2 }')
6077         (( $recovery_duration > $time_min + $wrap_up )) &&
6078                 error "recovery_duration > recovery_time_hard + wrap up"
6079         completed_clients=$(do_facet $SINGLEMDS \
6080                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6081                 awk '/completed_clients/ { print $2 }')
6082
6083         correct_clients="$MDSCOUNT/$((MDSCOUNT+1))"
6084         [ "$completed_clients" = "${correct_clients}" ] ||
6085                 error "$completed_clients != $correct_clients"
6086
6087         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
6088         umount_client $MOUNT1
6089         umount_client $MOUNT2
6090
6091         stop_ost
6092         stop_ost2
6093         stop_mds
6094 }
6095 run_test 84 "check recovery_hard_time"
6096
6097 test_85() {
6098         [[ $(lustre_version_code ost1) -ge $(version_code 2.7.55) ]] ||
6099                 { skip "Need OST version at least 2.7.55" && return 0; }
6100 ##define OBD_FAIL_OSD_OST_EA_FID_SET 0x197
6101         do_facet ost1 "lctl set_param fail_loc=0x197"
6102         start_ost
6103         stop_ost
6104 }
6105 run_test 85 "osd_ost init: fail ea_fid_set"
6106
6107 cleanup_86() {
6108         trap 0
6109
6110         # ost1 has already registered to the MGS before the reformat.
6111         # So after reformatting it with option "-G", it could not be
6112         # mounted to the MGS. Cleanup the system for subsequent tests.
6113         reformat_and_config
6114 }
6115
6116 test_86() {
6117         local server_version=$(lustre_version_code $SINGLEMDS)
6118         [ "$(facet_fstype ost1)" = "zfs" ] &&
6119                 skip "LU-6442: no such mkfs params for ZFS OSTs" && return
6120         [[ $server_version -ge $(version_code 2.7.56) ]] ||
6121                 { skip "Need server version newer than 2.7.55"; return 0; }
6122
6123         local OST_OPTS="$(mkfs_opts ost1 $(ostdevname 1)) \
6124                 --reformat $(ostdevname 1) $(ostvdevname 1)"
6125
6126         local NEWSIZE=1024
6127         local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6128                 awk '/Flex block group size: / { print $NF; exit; }')
6129
6130         local opts=OST_OPTS
6131         if [[ ${!opts} != *mkfsoptions* ]]; then
6132                 eval opts=\"${!opts} \
6133                         --mkfsoptions='\\\"-O flex_bg -G $NEWSIZE\\\"'\"
6134         else
6135                 val=${!opts//--mkfsoptions=\\\"/ \
6136                         --mkfsoptions=\\\"-O flex_bg -G $NEWSIZE }
6137                 eval opts='${val}'
6138         fi
6139
6140         echo "params: $opts"
6141
6142         trap cleanup_86 EXIT ERR
6143
6144         stopall
6145         add ost1 $opts || error "add ost1 failed with new params"
6146
6147         local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6148                 awk '/Flex block group size: / { print $NF; exit; }')
6149
6150         [[ $FOUNDSIZE == $NEWSIZE ]] ||
6151                 error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
6152
6153         cleanup_86
6154 }
6155 run_test 86 "Replacing mkfs.lustre -G option"
6156
6157 test_87() { #LU-6544
6158         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.9.51) ]] ||
6159                 { skip "Need MDS version at least 2.9.51" && return; }
6160         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
6161                 { skip "ldiskfs only test" && return; }
6162         [[ $OSTCOUNT -gt 59 ]] &&
6163                 { skip "Ignore wide striping situation" && return; }
6164
6165         local mdsdev=$(mdsdevname 1)
6166         local mdsvdev=$(mdsvdevname 1)
6167         local file=$DIR/$tfile
6168         local mntpt=$(facet_mntpt $SINGLEMDS)
6169         local used_xattr_blk=0
6170         local inode_size=${1:-1024}
6171         local left_size=0
6172         local xtest="trusted.test"
6173         local value
6174         local orig
6175         local i
6176         local stripe_cnt=$(($OSTCOUNT + 2))
6177
6178         #Please see ldiskfs_make_lustre() for MDT inode size calculation
6179         if [ $stripe_cnt -gt 16 ]; then
6180                 inode_size=2048
6181         fi
6182         left_size=$(expr $inode_size - \
6183                         156 - \
6184                         32 - \
6185                         32 - 40 \* 3 - 32 \* 3 - $stripe_cnt \* 24 - 16 - 3 -  \
6186                         24 - 16 - 3 - \
6187                         24 - 18 - $(expr length $tfile) - 16 - 4)
6188         if [ $left_size -le 0 ]; then
6189                 echo "No space($left_size) is expected in inode."
6190                 echo "Try 1-byte xattr instead to verify this."
6191                 left_size=1
6192         else
6193                 echo "Estimate: at most $left_size-byte space left in inode."
6194         fi
6195
6196         unload_modules
6197         reformat
6198
6199         add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$stripe_cnt \
6200                 --reformat $mdsdev $mdsvdev || error "add mds1 failed"
6201         start_mdt 1 > /dev/null || error "start mdt1 failed"
6202         for i in $(seq $OSTCOUNT); do
6203                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
6204                         error "start ost$i failed"
6205         done
6206         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
6207         check_mount || error "check client $MOUNT failed"
6208
6209         #set xattr
6210         $SETSTRIPE -E 1M -c 1 -E 64M -c 1 -E -1 -c -1 $file ||
6211                 error "Create file with 3 components failed"
6212         $TRUNCATE $file $((1024*1024*64+1)) || error "truncate file failed"
6213         i=$($GETSTRIPE -I3 -c $file) || error "get 3rd stripe count failed"
6214         if [ $i -ne $OSTCOUNT ]; then
6215                 left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
6216                 echo -n "Since only $i out $OSTCOUNT OSTs are used, "
6217                 echo -n "the expected left space is changed to "
6218                 echo "$left_size bytes at most."
6219         fi
6220         value=$(generate_string $left_size)
6221         setfattr -n $xtest -v $value $file
6222         orig=$(get_xattr_value $xtest $file)
6223         [[ "$orig" != "$value" ]] && error "$xtest changed"
6224
6225         #Verify if inode has some expected space left
6226         umount $MOUNT > /dev/null || error "umount $MOUNT failed"
6227         stop_mdt 1 > /dev/null || error "stop mdt1 failed"
6228         mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
6229
6230         do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
6231         used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
6232                         awk '{ print $1 }')
6233         [[ $used_xattr_blk -eq 0 ]] &&
6234                 error "Please check MDS inode size calculation: \
6235                        more than $left_size-byte space left in inode."
6236         echo "Verified: at most $left_size-byte space left in inode."
6237
6238         stopall
6239 }
6240 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
6241
6242 test_88() {
6243         [ "$(facet_fstype mds1)" == "zfs" ] &&
6244                 skip "LU-6662: no implementation for ZFS" && return
6245
6246         load_modules
6247
6248         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6249                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6250
6251         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6252                 grep -e \".*opts:.*errors=remount-ro.*\"" ||
6253                 error "default mount options is missing"
6254
6255         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6256                 --mountfsoptions="user_xattr,errors=panic" \
6257                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6258
6259         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6260                 grep -e \".*opts:.*errors=panic.*\"" ||
6261                 error "user can't override default mount options"
6262 }
6263 run_test 88 "check the default mount options can be overridden"
6264
6265 test_89() { # LU-7131
6266         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.9.54) ]] ||
6267                 { skip "Need MDT version at least 2.9.54" && return 0; }
6268
6269         local key=failover.node
6270         local val1=192.0.2.254@tcp0 # Reserved IPs, see RFC 5735
6271         local val2=192.0.2.255@tcp0
6272         local mdsdev=$(mdsdevname 1)
6273         local params
6274
6275         stopall
6276
6277         [ $(facet_fstype mds1) == zfs ] && import_zpool mds1
6278         # Check that parameters are added correctly
6279         echo "tunefs --param $key=$val1"
6280         do_facet mds "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
6281                 error "tunefs --param $key=$val1 failed"
6282         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6283                 error "tunefs --dryrun failed"
6284         params=${params##*Parameters:}
6285         params=${params%%exiting*}
6286         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val1) = "1" ] ||
6287                 error "on-disk parameter not added correctly via tunefs"
6288
6289         # Check that parameters replace existing instances when added
6290         echo "tunefs --param $key=$val2"
6291         do_facet mds "$TUNEFS --param $key=$val2 $mdsdev >/dev/null" ||
6292                 error "tunefs --param $key=$val2 failed"
6293         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6294                 error "tunefs --dryrun failed"
6295         params=${params##*Parameters:}
6296         params=${params%%exiting*}
6297         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "1" ] ||
6298                 error "on-disk parameter not replaced via tunefs"
6299         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val2) = "1" ] ||
6300                 error "on-disk parameter not replaced correctly via tunefs"
6301
6302         # Check that a parameter is erased properly
6303         echo "tunefs --erase-param $key"
6304         do_facet mds "$TUNEFS --erase-param $key $mdsdev >/dev/null" ||
6305                 error "tunefs --erase-param $key failed"
6306         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6307                 error "tunefs --dryrun failed"
6308         params=${params##*Parameters:}
6309         params=${params%%exiting*}
6310         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "0" ] ||
6311                 error "on-disk parameter not erased correctly via tunefs"
6312
6313         # Check that all the parameters are erased
6314         echo "tunefs --erase-params"
6315         do_facet mds "$TUNEFS --erase-params $mdsdev >/dev/null" ||
6316                 error "tunefs --erase-params failed"
6317         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6318                 error "tunefs --dryrun failed"
6319         params=${params##*Parameters:}
6320         params=${params%%exiting*}
6321         [ -z $params ] ||
6322                 error "all on-disk parameters not erased correctly via tunefs"
6323
6324         # Check the order of options --erase-params and --param
6325         echo "tunefs --param $key=$val1 --erase-params"
6326         do_facet mds \
6327                 "$TUNEFS --param $key=$val1 --erase-params $mdsdev >/dev/null"||
6328                 error "tunefs --param $key=$val1 --erase-params failed"
6329         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6330                 error "tunefs --dryrun failed"
6331         params=${params##*Parameters:}
6332         params=${params%%exiting*}
6333         [ $(echo $params | tr ' ' '\n') == "$key=$val1" ] ||
6334                 error "on-disk param not added correctly with --erase-params"
6335
6336         reformat
6337 }
6338 run_test 89 "check tunefs --param and --erase-param{s} options"
6339
6340 # $1 test directory
6341 # $2 (optional) value of max_mod_rpcs_in_flight to set
6342 check_max_mod_rpcs_in_flight() {
6343         local dir="$1"
6344         local mmr="$2"
6345         local idx
6346         local facet
6347         local tmp
6348         local i
6349
6350         idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
6351         facet="mds$((0x$idx + 1))"
6352
6353         if [ -z "$mmr" ]; then
6354                 # get value of max_mod_rcps_in_flight
6355                 mmr=$($LCTL get_param -n \
6356                         mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
6357                         error "Unable to get max_mod_rpcs_in_flight"
6358                 echo "max_mod_rcps_in_flight is $mmr"
6359         else
6360                 # set value of max_mod_rpcs_in_flight
6361                 $LCTL set_param \
6362                     mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
6363                         error "Unable to set max_mod_rpcs_in_flight to $mmr"
6364                 echo "max_mod_rpcs_in_flight set to $mmr"
6365         fi
6366
6367         # create mmr+1 files
6368         echo "creating $((mmr + 1)) files ..."
6369         umask 0022
6370         for i in $(seq $((mmr + 1))); do
6371                 touch $dir/file-$i
6372         done
6373
6374         ### part 1 ###
6375
6376         # consumes mmr-1 modify RPC slots
6377         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6378         # drop requests on MDT so that RPC slots are consumed
6379         # during all the request resend interval
6380         do_facet $facet "$LCTL set_param fail_loc=0x159"
6381         echo "launch $((mmr - 1)) chmod in parallel ..."
6382         for i in $(seq $((mmr - 1))); do
6383                 chmod 0600 $dir/file-$i &
6384         done
6385         sleep 1
6386
6387         # send one additional modify RPC
6388         do_facet $facet "$LCTL set_param fail_loc=0"
6389         echo "launch 1 additional chmod in parallel ..."
6390         chmod 0600 $dir/file-$mmr &
6391         sleep 1
6392
6393         # check this additional modify RPC get a modify RPC slot
6394         # and succeed its operation
6395         checkstat -vp 0600 $dir/file-$mmr ||
6396                 error "Unable to send $mmr modify RPCs in parallel"
6397         wait
6398
6399         ### part 2 ###
6400
6401         # consumes mmr modify RPC slots
6402         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6403         # drop requests on MDT so that RPC slots are consumed
6404         # during all the request resend interval
6405         do_facet $facet "$LCTL set_param fail_loc=0x159"
6406         echo "launch $mmr chmod in parallel ..."
6407         for i in $(seq $mmr); do
6408                 chmod 0666 $dir/file-$i &
6409         done
6410         sleep 1
6411
6412         # send one additional modify RPC
6413         do_facet $facet "$LCTL set_param fail_loc=0"
6414         echo "launch 1 additional chmod in parallel ..."
6415         chmod 0666 $dir/file-$((mmr + 1)) &
6416         sleep 1
6417
6418         # check this additional modify RPC blocked getting a modify RPC slot
6419         checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
6420                 error "Unexpectedly send $(($mmr + 1)) modify RPCs in parallel"
6421         wait
6422 }
6423
6424 test_90a() {
6425         reformat
6426         if ! combined_mgs_mds ; then
6427                 start_mgs
6428         fi
6429         setup
6430
6431         [[ $($LCTL get_param mdc.*.import |
6432              grep "connect_flags:.*multi_mod_rpc") ]] ||
6433                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6434
6435         # check default value
6436         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6437         check_max_mod_rpcs_in_flight $DIR/$tdir
6438
6439         cleanup
6440 }
6441 run_test 90a "check max_mod_rpcs_in_flight is enforced"
6442
6443 test_90b() {
6444         local idx
6445         local facet
6446         local tmp
6447         local mmrpc
6448
6449         setup
6450
6451         [[ $($LCTL get_param mdc.*.import |
6452              grep "connect_flags:.*multi_mod_rpc") ]] ||
6453                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6454
6455         ### test 1.
6456         # update max_mod_rpcs_in_flight
6457         $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
6458         check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
6459
6460         ### test 2.
6461         # check client is able to send multiple modify RPCs in paralell
6462         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6463                 grep -c "multi_mod_rpcs")
6464         if [ "$tmp" -ne $MDSCOUNT ]; then
6465                 echo "Client not able to send multiple modify RPCs in parallel"
6466                 cleanup
6467                 return
6468         fi
6469
6470         # update max_mod_rpcs_in_flight
6471         $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
6472         check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
6473
6474         ### test 3.
6475         $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
6476         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
6477         facet="mds$((0x$idx + 1))"
6478
6479         # save MDT max_mod_rpcs_per_client
6480         mmrpc=$(do_facet $facet \
6481                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6482
6483         # update max_mod_rpcs_in_flight
6484         umount_client $MOUNT
6485         do_facet $facet \
6486                 "echo 16 > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6487         mount_client $MOUNT
6488         $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
6489         check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
6490
6491         # restore MDT max_mod_rpcs_per_client initial value
6492         do_facet $facet \
6493                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6494
6495         rm -rf $DIR/${tdir}?
6496         cleanup
6497 }
6498 run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
6499
6500 test_90c() {
6501         local tmp
6502         local mrif
6503         local mmrpc
6504
6505         setup
6506
6507         [[ $($LCTL get_param mdc.*.import |
6508              grep "connect_flags:.*multi_mod_rpc") ]] ||
6509                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6510
6511         # check client is able to send multiple modify RPCs in paralell
6512         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6513                 grep -c "multi_mod_rpcs")
6514         if [ "$tmp" -ne $MDSCOUNT ]; then
6515                 skip "Client not able to send multiple modify RPCs in parallel"
6516                 cleanup
6517                 return
6518         fi
6519
6520         # get max_rpcs_in_flight value
6521         mrif=$($LCTL get_param -n mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
6522         echo "max_rpcs_in_flight is $mrif"
6523
6524         # get MDT max_mod_rpcs_per_client
6525         mmrpc=$(do_facet mds1 \
6526                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6527         echo "max_mod_rpcs_per_client is $mmrpc"
6528
6529         # testcase 1
6530         # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
6531         # prerequisite: set max_mod_rpcs_per_client to max_rpcs_in_flight value
6532         umount_client $MOUNT
6533         do_facet mds1 \
6534                 "echo $mrif > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6535         mount_client $MOUNT
6536
6537         $LCTL set_param \
6538             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif &&
6539             error "set max_mod_rpcs_in_flight to $mrif should fail"
6540
6541         umount_client $MOUNT
6542         do_facet mds1 \
6543                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6544         mount_client $MOUNT
6545
6546         # testcase 2
6547         # attempt to set max_mod_rpcs_in_flight to max_mod_rpcs_per_client+1
6548         # prerequisite: set max_rpcs_in_flight to max_mod_rpcs_per_client+2
6549         $LCTL set_param \
6550             mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc + 2))
6551
6552         $LCTL set_param \
6553             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc + 1)) &&
6554             error "set max_mod_rpcs_in_flight to $((mmrpc + 1)) should fail"
6555
6556         cleanup
6557 }
6558 run_test 90c "check max_mod_rpcs_in_flight update limits"
6559
6560 test_90d() {
6561         local idx
6562         local facet
6563         local mmr
6564         local i
6565         local pid
6566
6567         setup
6568
6569         [[ $($LCTL get_param mdc.*.import |
6570              grep "connect_flags:.*multi_mod_rpc") ]] ||
6571                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6572
6573         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6574         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
6575         facet="mds$((0x$idx + 1))"
6576
6577         # check client version supports multislots
6578         tmp=$($LCTL get_param -N \
6579                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6580         if [ -z "$tmp" ]; then
6581                 skip "Client does not support multiple modify RPCs in flight"
6582                 cleanup
6583                 return
6584         fi
6585
6586         # get current value of max_mod_rcps_in_flight
6587         mmr=$($LCTL get_param -n \
6588                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6589         echo "max_mod_rcps_in_flight is $mmr"
6590
6591         # create mmr files
6592         echo "creating $mmr files ..."
6593         umask 0022
6594         for i in $(seq $mmr); do
6595                 touch $DIR/$tdir/file-$i
6596         done
6597
6598         # prepare for close RPC
6599         multiop_bg_pause $DIR/$tdir/file-close O_c
6600         pid=$!
6601
6602         # consumes mmr modify RPC slots
6603         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6604         # drop requests on MDT so that RPC slots are consumed
6605         # during all the request resend interval
6606         do_facet $facet "$LCTL set_param fail_loc=0x159"
6607         echo "launch $mmr chmod in parallel ..."
6608         for i in $(seq $mmr); do
6609                 chmod 0600 $DIR/$tdir/file-$i &
6610         done
6611
6612         # send one additional close RPC
6613         do_facet $facet "$LCTL set_param fail_loc=0"
6614         echo "launch 1 additional close in parallel ..."
6615         kill -USR1 $pid
6616         cancel_lru_locks mdc
6617         sleep 1
6618
6619         # check this additional close RPC get a modify RPC slot
6620         # and multiop process completed
6621         [ -d /proc/$pid ] &&
6622                 error "Unable to send the additional close RPC in parallel"
6623         wait
6624         rm -rf $DIR/$tdir
6625         cleanup
6626 }
6627 run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
6628
6629 check_uuid_on_ost() {
6630         local nid=$1
6631         do_facet ost1 "$LCTL get_param obdfilter.${FSNAME}*.exports.'$nid'.uuid"
6632 }
6633
6634 check_uuid_on_mdt() {
6635         local nid=$1
6636         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6637 }
6638
6639 test_91() {
6640         local uuid
6641         local nid
6642         local found
6643
6644         [[ $(lustre_version_code ost1) -ge $(version_code 2.7.63) ]] ||
6645                 { skip "Need OST version at least 2.7.63" && return 0; }
6646         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.63) ]] ||
6647                 { skip "Need MDT version at least 2.7.63" && return 0; }
6648
6649         start_mds || error "MDS start failed"
6650         start_ost || error "unable to start OST"
6651         mount_client $MOUNT || error "client start failed"
6652         check_mount || error "check_mount failed"
6653
6654         if remote_mds; then
6655                 nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
6656         else
6657                 nid="0@lo"
6658         fi
6659         uuid=$(get_client_uuid $MOUNT)
6660
6661         echo "list nids on mdt:"
6662         do_facet $SINGLEMDS "$LCTL list_param mdt.${FSNAME}*.exports.*"
6663         echo "uuid from $nid:"
6664         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6665
6666         found=$(check_uuid_on_mdt $nid | grep $uuid)
6667         [ -z "$found" ] && error "can't find $uuid $nid on MDT"
6668         found=$(check_uuid_on_ost $nid | grep $uuid)
6669         [ -z "$found" ] && error "can't find $uuid $nid on OST"
6670
6671         # umount the client so it won't reconnect
6672         manual_umount_client --force || error "failed to umount $?"
6673         # shouldn't disappear on MDS after forced umount
6674         found=$(check_uuid_on_mdt $nid | grep $uuid)
6675         [ -z "$found" ] && error "can't find $uuid $nid"
6676
6677         echo "evict $nid"
6678         do_facet $SINGLEMDS \
6679                 "$LCTL set_param -n mdt.${mds1_svc}.evict_client nid:$nid"
6680
6681         found=$(check_uuid_on_mdt $nid | grep $uuid)
6682         [ -n "$found" ] && error "found $uuid $nid on MDT"
6683         found=$(check_uuid_on_ost $nid | grep $uuid)
6684         [ -n "$found" ] && error "found $uuid $nid on OST"
6685
6686         # check it didn't reconnect (being umounted)
6687         sleep $((TIMEOUT+1))
6688         found=$(check_uuid_on_mdt $nid | grep $uuid)
6689         [ -n "$found" ] && error "found $uuid $nid on MDT"
6690         found=$(check_uuid_on_ost $nid | grep $uuid)
6691         [ -n "$found" ] && error "found $uuid $nid on OST"
6692
6693         cleanup
6694 }
6695 run_test 91 "evict-by-nid support"
6696
6697 generate_ldev_conf() {
6698         # generate an ldev.conf file
6699         local ldevconfpath=$1
6700         local fstype=
6701         local fsldevformat=""
6702         touch $ldevconfpath
6703
6704         fstype=$(facet_fstype mgs)
6705         if [ "$fstype" == "zfs" ]; then
6706                 fsldevformat="$fstype:"
6707         else
6708                 fsldevformat=""
6709         fi
6710
6711         printf "%s\t-\t%s-MGS0000\t%s%s\n" \
6712                 $mgs_HOST \
6713                 $FSNAME \
6714                 $fsldevformat \
6715                 $(mgsdevname) > $ldevconfpath
6716
6717         local mdsfo_host=$mdsfailover_HOST;
6718         if [ -z "$mdsfo_host" ]; then
6719                 mdsfo_host="-"
6720         fi
6721
6722         for num in $(seq $MDSCOUNT); do
6723                 fstype=$(facet_fstype mds$num)
6724                 if [ "$fstype" == "zfs" ]; then
6725                         fsldevformat="$fstype:"
6726                 else
6727                         fsldevformat=""
6728                 fi
6729
6730                 printf "%s\t%s\t%s-MDT%04d\t%s%s\n" \
6731                         $mds_HOST \
6732                         $mdsfo_host \
6733                         $FSNAME \
6734                         $num \
6735                         $fsldevformat \
6736                         $(mdsdevname $num) >> $ldevconfpath
6737         done
6738
6739         local ostfo_host=$ostfailover_HOST;
6740         if [ -z "$ostfo_host" ]; then
6741                 ostfo_host="-"
6742         fi
6743
6744         for num in $(seq $OSTCOUNT); do
6745                 fstype=$(facet_fstype ost$num)
6746                 if [ "$fstype" == "zfs" ]; then
6747                         fsldevformat="$fstype:"
6748                 else
6749                         fsldevformat=""
6750                 fi
6751
6752                 printf "%s\t%s\t%s-OST%04d\t%s%s\n" \
6753                         $ost_HOST \
6754                         $ostfo_host \
6755                         $FSNAME \
6756                         $num \
6757                         $fsldevformat \
6758                         $(ostdevname $num) >> $ldevconfpath
6759         done
6760
6761         echo "----- $ldevconfpath -----"
6762         cat $ldevconfpath
6763         echo "--- END $ldevconfpath ---"
6764
6765 }
6766
6767 generate_nids() {
6768         # generate a nids file (mapping between hostname to nid)
6769         # looks like we only have the MGS nid available to us
6770         # so just echo that to a file
6771         local nidspath=$1
6772         echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
6773
6774         echo "----- $nidspath -----"
6775         cat $nidspath
6776         echo "--- END $nidspath ---"
6777 }
6778
6779 compare_ldev_output() {
6780         ldev_output=$1
6781         expected_output=$2
6782
6783         sort $expected_output -o $expected_output
6784         sort $ldev_output -o $ldev_output
6785
6786         echo "-- START OF LDEV OUTPUT --"
6787         cat $ldev_output
6788         echo "--- END OF LDEV OUTPUT ---"
6789
6790         echo "-- START OF EXPECTED OUTPUT --"
6791         cat $expected_output
6792         echo "--- END OF EXPECTED OUTPUT ---"
6793
6794         diff $expected_output $ldev_output
6795         return $?
6796 }
6797
6798 test_92() {
6799         if [ -z "$LDEV" ]; then
6800                 error "ldev is missing!"
6801         fi
6802
6803         local LDEVCONFPATH=$TMP/ldev.conf
6804         local NIDSPATH=$TMP/nids
6805
6806         echo "Host is $(hostname)"
6807
6808         generate_ldev_conf $LDEVCONFPATH
6809         generate_nids $NIDSPATH
6810
6811         # echo the mgs nid and compare it to environment variable MGSNID
6812         # also, ldev.conf and nids is a server side thing, use the OSS
6813         # hostname
6814         local output
6815         output=$($LDEV -c $LDEVCONFPATH -H $ost_HOST -n $NIDSPATH echo %m)
6816
6817         echo "-- START OF LDEV OUTPUT --"
6818         echo -e "$output"
6819         echo "--- END OF LDEV OUTPUT ---"
6820
6821         # ldev failed, error
6822         if [ $? -ne 0 ]; then
6823                 rm $LDEVCONFPATH $NIDSPATH
6824                 error "ldev failed to execute!"
6825         fi
6826
6827         # need to process multiple lines because of combined MGS and MDS
6828         echo -e $output | awk '{ print $2 }' | while read -r line ; do
6829                 if [ "$line" != "$MGSNID" ]; then
6830                         rm $LDEVCONFPATH $NIDSPATH
6831                         error "ldev failed mgs nid '$line', expected '$MGSNID'"
6832                 fi
6833         done
6834
6835         rm $LDEVCONFPATH $NIDSPATH
6836 }
6837 run_test 92 "ldev returns MGS NID correctly in command substitution"
6838
6839 test_93() {
6840         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs" && return
6841
6842         reformat
6843         #start mgs or mgs/mdt0
6844         if ! combined_mgs_mds ; then
6845                 start_mgs
6846                 start_mdt 1
6847         else
6848                 start_mdt 1
6849         fi
6850
6851         start_ost || error "OST0 start fail"
6852
6853         #define OBD_FAIL_MGS_WRITE_TARGET_DELAY  0x90e
6854         do_facet mgs "$LCTL set_param fail_val = 10 fail_loc=0x8000090e"
6855         for num in $(seq 2 $MDSCOUNT); do
6856                 start_mdt $num &
6857         done
6858
6859         mount_client $MOUNT || error "mount client fails"
6860         wait_osc_import_state mds ost FULL
6861         wait_osc_import_state client ost FULL
6862         check_mount || error "check_mount failed"
6863
6864         cleanup || error "cleanup failed with $?"
6865 }
6866 run_test 93 "register mulitple MDT at the same time"
6867
6868 test_94() {
6869         if [ -z "$LDEV" ]; then
6870                 error "ldev is missing!"
6871         fi
6872
6873         local LDEVCONFPATH=$TMP/ldev.conf
6874         local NIDSPATH=$TMP/nids
6875
6876         generate_ldev_conf $LDEVCONFPATH
6877         generate_nids $NIDSPATH
6878
6879         local LDEV_OUTPUT=$TMP/ldev-output.txt
6880         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME > $LDEV_OUTPUT
6881
6882         # ldev failed, error
6883         if [ $? -ne 0 ]; then
6884                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
6885                 error "ldev failed to execute!"
6886         fi
6887
6888         # expected output
6889         local EXPECTED_OUTPUT=$TMP/ldev-expected.txt
6890
6891         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
6892
6893         for num in $(seq $MDSCOUNT); do
6894                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
6895         done
6896
6897         for num in $(seq $OSTCOUNT); do
6898                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
6899         done
6900
6901         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
6902
6903         if [ $? -ne 0 ]; then
6904                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
6905                 error "ldev failed to produce the correct hostlist!"
6906         fi
6907
6908         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
6909 }
6910 run_test 94 "ldev outputs correct labels for file system name query"
6911
6912 test_95() {
6913         if [ -z "$LDEV" ]; then
6914                 error "ldev is missing!"
6915         fi
6916
6917         local LDEVCONFPATH=$TMP/ldev.conf
6918         local NIDSPATH=$TMP/nids
6919
6920         generate_ldev_conf $LDEVCONFPATH
6921         generate_nids $NIDSPATH
6922
6923         # SUCCESS CASES
6924         # file sys filter
6925         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
6926         if [ $? -ne 0 ]; then
6927                 rm $LDEVCONFPATH $NIDSPATH
6928                 error "ldev label filtering w/ -F failed!"
6929         fi
6930
6931         # local filter
6932         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
6933         if [ $? -ne 0 ]; then
6934                 rm $LDEVCONFPATH $NIDSPATH
6935                 error "ldev label filtering w/ -l failed!"
6936         fi
6937
6938         # foreign filter
6939         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
6940         if [ $? -ne 0 ]; then
6941                 rm $LDEVCONFPATH $NIDSPATH
6942                 error "ldev label filtering w/ -f failed!"
6943         fi
6944
6945         # all filter
6946         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
6947         if [ $? -ne 0 ]; then
6948                 rm $LDEVCONFPATH $NIDSPATH
6949                 error "ldev label filtering w/ -a failed!"
6950         fi
6951
6952         # FAILURE CASES
6953         # all & file sys
6954         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
6955         if [ $? -eq 0 ]; then
6956                 rm $LDEVCONFPATH $NIDSPATH
6957                 error "ldev label filtering w/ -a and -F incorrectly succeeded"
6958         fi
6959
6960         # all & foreign
6961         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
6962         if [ $? -eq 0 ]; then
6963                 rm $LDEVCONFPATH $NIDSPATH
6964                 error "ldev label filtering w/ -a and -f incorrectly succeeded"
6965         fi
6966
6967         # all & local
6968         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
6969         if [ $? -eq 0 ]; then
6970                 rm $LDEVCONFPATH $NIDSPATH
6971                 error "ldev label filtering w/ -a and -l incorrectly succeeded"
6972         fi
6973
6974         # foreign & local
6975         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
6976         if [ $? -eq 0 ]; then
6977                 rm $LDEVCONFPATH $NIDSPATH
6978                 error "ldev label filtering w/ -f and -l incorrectly succeeded"
6979         fi
6980
6981         # file sys & local
6982         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
6983         if [ $? -eq 0 ]; then
6984                 rm $LDEVCONFPATH $NIDSPATH
6985                 error "ldev label filtering w/ -F and -l incorrectly succeeded"
6986         fi
6987
6988         # file sys & foreign
6989         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
6990         if [ $? -eq 0 ]; then
6991                 rm $LDEVCONFPATH $NIDSPATH
6992                 error "ldev label filtering w/ -F and -f incorrectly succeeded"
6993         fi
6994
6995         rm $LDEVCONFPATH $NIDSPATH
6996 }
6997 run_test 95 "ldev should only allow one label filter"
6998
6999 test_96() {
7000         if [ -z "$LDEV" ]; then
7001                 error "ldev is missing!"
7002         fi
7003
7004         local LDEVCONFPATH=$TMP/ldev.conf
7005         local NIDSPATH=$TMP/nids
7006
7007         generate_ldev_conf $LDEVCONFPATH
7008         generate_nids $NIDSPATH
7009
7010         local LDEV_OUTPUT=$TMP/ldev-output.txt
7011         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -H $mgs_HOST \
7012                 echo %H-%b | \
7013                 awk '{print $2}' > $LDEV_OUTPUT
7014
7015         # ldev failed, error
7016         if [ $? -ne 0 ]; then
7017                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7018                 error "ldev failed to execute!"
7019         fi
7020
7021         # expected output
7022         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7023
7024         echo "$mgs_HOST-$(facet_fstype mgs)" > $EXPECTED_OUTPUT
7025
7026         if [ "$mgs_HOST" == "$mds_HOST" ]; then
7027                 for num in $(seq $MDSCOUNT); do
7028                         echo "$mds_HOST-$(facet_fstype mds$num)" \
7029                         >> $EXPECTED_OUTPUT
7030                 done
7031         fi
7032
7033         if [ "$mgs_HOST" == "$ost_HOST" ]; then
7034                 for num in $(seq $OSTCOUNT); do
7035                         echo "$ost_HOST-$(facet_fstype ost$num)" \
7036                         >> $EXPECTED_OUTPUT
7037                 done
7038         fi
7039
7040         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7041
7042         if [ $? -ne 0 ]; then
7043                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7044                 error "ldev failed to produce the correct output!"
7045         fi
7046
7047         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7048 }
7049 run_test 96 "ldev returns hostname and backend fs correctly in command sub"
7050
7051 test_97() {
7052         if [ -z "$LDEV" ]; then
7053                 error "ldev is missing!"
7054         fi
7055
7056         local LDEVCONFPATH=$TMP/ldev.conf
7057         local NIDSPATH=$TMP/nids
7058
7059         generate_ldev_conf $LDEVCONFPATH
7060         generate_nids $NIDSPATH
7061
7062         local LDEV_OUTPUT=$TMP/ldev-output.txt
7063         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7064
7065         echo -e "\nMDT role"
7066         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mdt > $LDEV_OUTPUT
7067
7068         if [ $? -ne 0 ]; then
7069                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7070                 error "ldev failed to execute for mdt role!"
7071         fi
7072
7073         for num in $(seq $MDSCOUNT); do
7074                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7075         done
7076
7077         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7078
7079         if [ $? -ne 0 ]; then
7080                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7081                 error "ldev failed to produce the correct output for mdt role!"
7082         fi
7083
7084         echo -e "\nOST role"
7085         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R ost > $LDEV_OUTPUT
7086
7087         if [ $? -ne 0 ]; then
7088                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7089                 error "ldev failed to execute for ost role!"
7090         fi
7091
7092         rm $EXPECTED_OUTPUT
7093         for num in $(seq $OSTCOUNT); do
7094                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7095         done
7096
7097         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7098
7099         if [ $? -ne 0 ]; then
7100                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7101                 error "ldev failed to produce the correct output for ost role!"
7102         fi
7103
7104         echo -e "\nMGS role"
7105         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mgs > $LDEV_OUTPUT
7106
7107         if [ $? -ne 0 ]; then
7108                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7109                 error "ldev failed to execute for mgs role!"
7110         fi
7111
7112         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
7113
7114         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7115
7116         if [ $? -ne 0 ]; then
7117                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7118                 error "ldev failed to produce the correct output for mgs role!"
7119         fi
7120
7121         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7122 }
7123 run_test 97 "ldev returns correct ouput when querying based on role"
7124
7125 test_98()
7126 {
7127         local mountopt
7128         local temp=$MDS_MOUNT_OPTS
7129
7130         setup
7131         check_mount || error "mount failed"
7132         mountopt="user_xattr"
7133         for ((x = 1; x <= 400; x++)); do
7134                 mountopt="$mountopt,user_xattr"
7135         done
7136         remount_client $mountopt $MOUNT  2>&1 | grep "too long" ||
7137                 error "Buffer overflow check failed"
7138         cleanup || error "cleanup failed"
7139 }
7140 run_test 98 "Buffer-overflow check while parsing mount_opts"
7141
7142 test_99()
7143 {
7144         [[ $(facet_fstype ost1) != ldiskfs ]] &&
7145                 { skip "ldiskfs only test" && return; }
7146         [[ $(lustre_version_code ost1) -ge $(version_code 2.8.57) ]] ||
7147                 { skip "Need OST version at least 2.8.57" && return 0; }
7148
7149         local ost_opts="$(mkfs_opts ost1 $(ostdevname 1)) \
7150                 --reformat $(ostdevname 1) $(ostvdevname 1)"
7151         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" &&
7152                 skip "meta_bg already set" && return
7153
7154         local opts=ost_opts
7155         if [[ ${!opts} != *mkfsoptions* ]]; then
7156                 eval opts=\"${!opts} \
7157                 --mkfsoptions='\\\"-O ^resize_inode,meta_bg\\\"'\"
7158         else
7159                 local val=${!opts//--mkfsoptions=\\\"/ \
7160                 --mkfsoptions=\\\"-O ^resize_inode,meta_bg }
7161                 eval opts='${val}'
7162         fi
7163
7164         echo "params: $opts"
7165
7166         add ost1 $opts || error "add ost1 failed with new params"
7167
7168         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" ||
7169                 error "meta_bg is not set"
7170
7171         return 0
7172 }
7173 run_test 99 "Adding meta_bg option"
7174
7175 test_100() {
7176         reformat
7177         start_mds || error "MDS start failed"
7178         start_ost || error "unable to start OST"
7179         mount_client $MOUNT || error "client start failed"
7180         check_mount || error "check_mount failed"
7181
7182         # Desired output
7183         # MGS:
7184         #     0@lo
7185         # lustre-MDT0000:
7186         #     0@lo
7187         # lustre-OST0000:
7188         #     0@lo
7189         do_facet mgs 'lshowmount -v' | awk 'BEGIN {NR == 0; rc=1} /MGS:/ {rc=0}
7190                 END {exit rc}' || error "lshowmount have no output MGS"
7191
7192         do_facet mds1 'lshowmount -v' | awk 'BEGIN {NR == 2; rc=1} /-MDT0000:/
7193                 {rc=0} END {exit rc}' || error "lshowmount have no output MDT0"
7194
7195         do_facet ost1 'lshowmount -v' | awk 'BEGIN {NR == 4; rc=1} /-OST0000:/
7196                 {rc=0} END {exit rc}' || error "lshowmount have no output OST0"
7197
7198         cleanup || error "cleanup failed with $?"
7199 }
7200 run_test 100 "check lshowmount lists MGS, MDT, OST and 0@lo"
7201
7202 test_101() {
7203         local createmany_oid
7204         local dev=$FSNAME-OST0000-osc-MDT0000
7205         setup
7206
7207         createmany -o $DIR1/$tfile-%d 50000 &
7208         createmany_oid=$!
7209         # MDT->OST reconnection causes MDT<->OST last_id synchornisation
7210         # via osp_precreate_cleanup_orphans.
7211         for ((i = 0; i < 100; i++)); do
7212                 for ((k = 0; k < 10; k++)); do
7213                         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;" \
7214                                             "$LCTL --device $dev activate"
7215                 done
7216
7217                 ls -asl $MOUNT | grep '???' &&
7218                         (kill -9 $createmany_oid &>/dev/null; \
7219                          error "File hasn't object on OST")
7220
7221                 kill -s 0 $createmany_oid || break
7222         done
7223         wait $createmany_oid
7224         cleanup
7225 }
7226 run_test 101 "Race MDT->OST reconnection with create"
7227
7228 test_102() {
7229         cleanup || error "cleanup failed with $?"
7230
7231         local mds1dev=$(mdsdevname 1)
7232         local mds1mnt=$(facet_mntpt mds1)
7233         local mds1fstype=$(facet_fstype mds1)
7234         local mds1opts=$MDS_MOUNT_OPTS
7235
7236         if [ $mds1fstype == ldiskfs ] &&
7237            ! do_facet mds1 test -b $mds1dev; then
7238                 mds1opts=$(csa_add "$mds1opts" -o loop)
7239         fi
7240         if [[ $mds1fstype == zfs ]]; then
7241                 import_zpool mds1 || return ${PIPESTATUS[0]}
7242         fi
7243
7244         # unload all and only load libcfs to allow fail_loc setting
7245         do_facet mds1 lustre_rmmod || error "unable to unload modules"
7246         do_facet mds1 modprobe libcfs || error "libcfs not loaded"
7247         do_facet mds1 lsmod \| grep libcfs || error "libcfs not loaded"
7248
7249         #define OBD_FAIL_OBDCLASS_MODULE_LOAD    0x60a
7250         do_facet mds1 "$LCTL set_param fail_loc=0x8000060a"
7251
7252         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
7253                 error "mdt start must fail"
7254         do_facet mds1 lsmod \| grep  obdclass && error "obdclass must not load"
7255
7256         do_facet mds1 "$LCTL set_param fail_loc=0x0"
7257
7258         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts ||
7259                 error "mdt start must not fail"
7260
7261         cleanup || error "cleanup failed with $?"
7262 }
7263 run_test 102 "obdclass module cleanup upon error"
7264
7265 test_renamefs() {
7266         local newname=$1
7267
7268         echo "rename $FSNAME to $newname"
7269
7270         if ! combined_mgs_mds ; then
7271                 local facet=$(mgsdevname)
7272
7273                 do_facet mgs \
7274                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7275                         error "(7) Fail to rename MGS"
7276                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7277                         reimport_zpool mgs $newname-mgs
7278                 fi
7279         fi
7280
7281         for num in $(seq $MDSCOUNT); do
7282                 local facet=$(mdsdevname $num)
7283
7284                 do_facet mds${num} \
7285                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7286                         error "(8) Fail to rename MDT $num"
7287                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7288                         reimport_zpool mds${num} $newname-mdt${num}
7289                 fi
7290         done
7291
7292         for num in $(seq $OSTCOUNT); do
7293                 local facet=$(ostdevname $num)
7294
7295                 do_facet ost${num} \
7296                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7297                         error "(9) Fail to rename OST $num"
7298                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7299                         reimport_zpool ost${num} $newname-ost${num}
7300                 fi
7301         done
7302 }
7303
7304 test_103_set_pool() {
7305         local pname=$1
7306         local ost_x=$2
7307
7308         do_facet mgs $LCTL pool_add $FSNAME.$pname ${FSNAME}-$ost_x ||
7309                 error "Fail to add $ost_x to $FSNAME.$pname"
7310         wait_update $HOSTNAME \
7311                 "lctl get_param -n lov.$FSNAME-clilov-*.pools.$pname |
7312                  grep $ost_x" "$FSNAME-${ost_x}_UUID" ||
7313                 error "$ost_x is NOT in pool $FSNAME.$pname"
7314 }
7315
7316 test_103_check_pool() {
7317         local save_fsname=$1
7318         local errno=$2
7319
7320         stat $DIR/$tdir/test-framework.sh ||
7321                 error "($errno) Fail to stat"
7322         do_facet mgs $LCTL pool_list $FSNAME.pool1 ||
7323                 error "($errno) Fail to list $FSNAME.pool1"
7324         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname ||
7325                 error "($errno) Fail to list $FSNAME.$save_fsname"
7326         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname |
7327                 grep ${FSNAME}-OST0000 ||
7328                 error "($errno) List $FSNAME.$save_fsname is invalid"
7329
7330         local pname=$($LFS getstripe --pool $DIR/$tdir/d0)
7331         [ "$pname" = "$save_fsname" ] ||
7332                 error "($errno) Unexpected pool name $pname"
7333 }
7334
7335 test_103() {
7336         check_mount_and_prep
7337         rm -rf $DIR/$tdir
7338         mkdir $DIR/$tdir || error "(1) Fail to mkdir $DIR/$tdir"
7339         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir ||
7340                 error "(2) Fail to copy test-framework.sh"
7341
7342         if ! combined_mgs_mds ; then
7343                 mount_mgs_client
7344         fi
7345         do_facet mgs $LCTL pool_new $FSNAME.pool1 ||
7346                 error "(3) Fail to create $FSNAME.pool1"
7347         # name the pool name as the fsname
7348         do_facet mgs $LCTL pool_new $FSNAME.$FSNAME ||
7349                 error "(4) Fail to create $FSNAME.$FSNAME"
7350
7351         test_103_set_pool $FSNAME OST0000
7352
7353         $SETSTRIPE -p $FSNAME $DIR/$tdir/d0 ||
7354                 error "(6) Fail to setstripe on $DIR/$tdir/d0"
7355
7356         if ! combined_mgs_mds ; then
7357                 umount_mgs_client
7358         fi
7359         KEEP_ZPOOL=true
7360         stopall
7361
7362         test_renamefs mylustre
7363
7364         local save_fsname=$FSNAME
7365         FSNAME="mylustre"
7366         setupall
7367
7368         if ! combined_mgs_mds ; then
7369                 mount_mgs_client
7370         fi
7371         test_103_check_pool $save_fsname 7
7372
7373         if [ $OSTCOUNT -ge 2 ]; then
7374                 test_103_set_pool $save_fsname OST0001
7375         fi
7376
7377         $SETSTRIPE -p $save_fsname $DIR/$tdir/f0 ||
7378                 error "(16) Fail to setstripe on $DIR/$tdir/f0"
7379         if ! combined_mgs_mds ; then
7380                 umount_mgs_client
7381         fi
7382
7383         stopall
7384
7385         test_renamefs tfs
7386
7387         FSNAME="tfs"
7388         setupall
7389
7390         if ! combined_mgs_mds ; then
7391                 mount_mgs_client
7392         fi
7393         test_103_check_pool $save_fsname 17
7394
7395         if ! combined_mgs_mds ; then
7396                 umount_mgs_client
7397         fi
7398         stopall
7399
7400         test_renamefs $save_fsname
7401
7402         FSNAME=$save_fsname
7403         setupall
7404         KEEP_ZPOOL=false
7405 }
7406 run_test 103 "rename filesystem name"
7407
7408 test_104() { # LU-6952
7409         local mds_mountopts=$MDS_MOUNT_OPTS
7410         local ost_mountopts=$OST_MOUNT_OPTS
7411         local mds_mountfsopts=$MDS_MOUNT_FS_OPTS
7412         local lctl_ver=$(do_facet $SINGLEMDS $LCTL --version |
7413                         awk '{ print $2 }')
7414
7415         [[ $(version_code $lctl_ver) -lt $(version_code 2.9.55) ]] &&
7416                 { skip "this test needs utils above 2.9.55" && return 0; }
7417
7418         # specify "acl" in mount options used by mkfs.lustre
7419         if [ -z "$MDS_MOUNT_FS_OPTS" ]; then
7420                 MDS_MOUNT_FS_OPTS="acl,user_xattr"
7421         else
7422
7423                 MDS_MOUNT_FS_OPTS="${MDS_MOUNT_FS_OPTS},acl,user_xattr"
7424         fi
7425
7426         echo "mountfsopt: $MDS_MOUNT_FS_OPTS"
7427
7428         #reformat/remount the MDT to apply the MDT_MOUNT_FS_OPT options
7429         formatall
7430         if [ -z "$MDS_MOUNT_OPTS" ]; then
7431                 MDS_MOUNT_OPTS="-o noacl"
7432         else
7433                 MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7434         fi
7435
7436         for num in $(seq $MDSCOUNT); do
7437                 start mds$num $(mdsdevname $num) $MDS_MOUNT_OPTS ||
7438                         error "Failed to start MDS"
7439         done
7440
7441         for num in $(seq $OSTCOUNT); do
7442                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
7443                         error "Failed to start OST"
7444         done
7445
7446         mount_client $MOUNT
7447         setfacl -m "d:$RUNAS_ID:rwx" $MOUNT &&
7448                 error "ACL is applied when FS is mounted with noacl."
7449
7450         MDS_MOUNT_OPTS=$mds_mountopts
7451         OST_MOUNT_OPTS=$ost_mountopts
7452         MDS_MOUNT_FS_OPTS=$mds_mountfsopts
7453
7454         formatall
7455         setupall
7456 }
7457 run_test 104 "Make sure user defined options are reflected in mount"
7458
7459 error_and_umount() {
7460         umount $TMP/$tdir
7461         rmdir $TMP/$tdir
7462         error $*
7463 }
7464
7465 test_105() {
7466         cleanup -f
7467         reformat
7468         setup
7469         mkdir -p $TMP/$tdir
7470         mount --bind $DIR $TMP/$tdir || error "mount bind mnt pt failed"
7471         rm -f $TMP/$tdir/$tfile
7472         rm -f $TMP/$tdir/${tfile}1
7473
7474         # Files should not be created in ro bind mount point
7475         # remounting from rw to ro
7476         mount -o remount,ro $TMP/$tdir ||
7477                 error_and_umount "readonly remount of bind mnt pt failed"
7478         touch $TMP/$tdir/$tfile &&
7479                 error_and_umount "touch succeeds on ro bind mnt pt"
7480         [ -e $TMP/$tdir/$tfile ] &&
7481                 error_and_umount "file created on ro bind mnt pt"
7482
7483         # Files should be created in rw bind mount point
7484         # remounting from ro to rw
7485         mount -o remount,rw $TMP/$tdir ||
7486                 error_and_umount "read-write remount of bind mnt pt failed"
7487         touch $TMP/$tdir/${tfile}1 ||
7488                 error_and_umount "touch fails on rw bind mnt pt"
7489         [ -e $TMP/$tdir/${tfile}1 ] ||
7490                 error_and_umount "file not created on rw bind mnt pt"
7491         umount $TMP/$tdir || error "umount of bind mnt pt failed"
7492         rmdir $TMP/$tdir
7493         cleanup || error "cleanup failed with $?"
7494 }
7495 run_test 105 "check file creation for ro and rw bind mnt pt"
7496
7497 test_106() {
7498         local repeat=5
7499
7500         reformat
7501         setupall
7502         mkdir -p $DIR/$tdir || error "create $tdir failed"
7503         lfs setstripe -c 1 -i 0 $DIR/$tdir
7504 #define OBD_FAIL_CAT_RECORDS                        0x1312
7505         do_facet mds1 $LCTL set_param fail_loc=0x1312 fail_val=$repeat
7506
7507         for ((i = 1; i <= $repeat; i++)); do
7508
7509                 #one full plain llog
7510                 createmany -o $DIR/$tdir/f- 64768
7511
7512                 createmany -u $DIR/$tdir/f- 64768
7513         done
7514         wait_delete_completed $((TIMEOUT * 7))
7515 #ASSERTION osp_sync_thread() ( thread->t_flags != SVC_RUNNING ) failed
7516 #shows that osp code is buggy
7517         do_facet mds1 $LCTL set_param fail_loc=0 fail_val=0
7518
7519         cleanupall
7520 }
7521 run_test 106 "check osp llog processing when catalog is wrapped"
7522
7523 test_107() {
7524         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.50) ]] ||
7525                 { skip "Need MDS version > 2.10.50"; return; }
7526
7527         start_mgsmds || error "start_mgsmds failed"
7528         start_ost || error "unable to start OST"
7529
7530         # add unknown configuration parameter.
7531         local PARAM="$FSNAME-OST0000.ost.unknown_param=50"
7532         do_facet mgs "$LCTL conf_param $PARAM"
7533         cleanup_nocli || error "cleanup_nocli failed with $?"
7534         load_modules
7535
7536         # unknown param should be ignored while mounting.
7537         start_ost || error "unable to start OST after unknown param set"
7538
7539         cleanup || error "cleanup failed with $?"
7540 }
7541 run_test 107 "Unknown config param should not fail target mounting"
7542
7543 if ! combined_mgs_mds ; then
7544         stop mgs
7545 fi
7546
7547 cleanup_gss
7548
7549 # restore the values of MDSSIZE and OSTSIZE
7550 MDSSIZE=$STORED_MDSSIZE
7551 OSTSIZE=$STORED_OSTSIZE
7552 reformat
7553
7554 complete $SECONDS
7555 exit_status