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