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