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