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