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