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