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