Whamcloud - gitweb
New tag 2.15.63
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6
7 SRCDIR=$(dirname $0)
8 PTLDEBUG=${PTLDEBUG:--1}
9 LUSTRE=${LUSTRE:-$(dirname $0)/..}
10 . $LUSTRE/tests/test-framework.sh
11 init_test_env "$@"
12 init_logging
13
14 #                                  tool to create lustre filesystem images
15 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 32newtarball"
16
17 always_except LU-11915 110
18
19 if $SHARED_KEY; then
20         always_except LU-9795 84 86 103
21 fi
22
23 if ! combined_mgs_mds; then
24         always_except LU-11991 32a 32b 32c 32d 32e
25         always_except LU-9897 84
26         always_except LU-12032 123F
27 fi
28
29 #                                     8  22  40 165  (min)
30 [ "$SLOW" = "no" ] && EXCEPT_SLOW="45 69 106 111 114"
31
32 build_test_filter
33
34 # use small MDS + OST size to speed formatting time
35 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
36 # STORED_MDSSIZE is used in test_18
37 STORED_MDSSIZE=$MDSSIZE
38 STORED_OSTSIZE=$OSTSIZE
39 MDSSIZE=200000
40 [ "$mds1_FSTYPE" = zfs ] && MDSSIZE=400000
41 OSTSIZE=200000
42 [ "$ost1_FSTYPE" = zfs ] && OSTSIZE=400000
43
44 fs2mds_HOST=$mds_HOST
45 fs2ost_HOST=$ost_HOST
46 fs3ost_HOST=$ost_HOST
47
48 MDSDEV1_2=$fs2mds_DEV
49 OSTDEV1_2=$fs2ost_DEV
50 OSTDEV2_2=$fs3ost_DEV
51
52 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
53 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
54         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
55 fi
56
57 #
58 require_dsh_mds || exit 0
59 require_dsh_ost || exit 0
60
61 assert_DIR
62
63 gen_config() {
64         # The MGS must be started before the OSTs for a new fs, so start
65         # and stop to generate the startup logs.
66         start_mds
67         start_ost
68         wait_osc_import_state mds ost FULL
69         stop_ost
70         stop_mds
71 }
72
73 reformat_and_config() {
74         reformat
75         if ! combined_mgs_mds ; then
76                 start_mgs
77         fi
78         gen_config
79 }
80
81 writeconf_or_reformat() {
82         # There are at most 2 OSTs for write_conf test
83         # who knows if/where $TUNEFS is installed?
84         # Better reformat if it fails...
85         writeconf_all $MDSCOUNT 2 ||
86                 { echo "tunefs failed, reformatting instead" &&
87                   reformat_and_config && return 0; }
88         return 0
89 }
90
91 reformat() {
92         formatall
93 }
94
95 start_mgs () {
96         echo "start mgs service on $(facet_active_host mgs)"
97         start mgs $(mgsdevname) $MGS_MOUNT_OPTS "$@"
98 }
99
100 start_mdt() {
101         local num=$1
102         local facet=mds$num
103         local dev=$(mdsdevname $num)
104         shift 1
105
106         echo "start mds service on `facet_active_host $facet`"
107         start $facet ${dev} $MDS_MOUNT_OPTS "$@" || return 94
108 }
109
110 stop_mdt_no_force() {
111         local num=$1
112         local facet=mds$num
113         local dev=$(mdsdevname $num)
114         shift 1
115
116         echo "stop mds service on `facet_active_host $facet`"
117         stop $facet || return 97
118 }
119
120 stop_mdt() {
121         local num=$1
122         local facet=mds$num
123         local dev=$(mdsdevname $num)
124         shift 1
125
126         echo "stop mds service on `facet_active_host $facet`"
127         # These tests all use non-failover stop
128         stop $facet -f || return 97
129 }
130
131 start_mds() {
132         local mdscount=$MDSCOUNT
133         local num
134
135         [[ "$1" == "--mdscount" ]] && mdscount=$2 && shift 2
136
137         for ((num=1; num <= $mdscount; num++ )); do
138                 start_mdt $num "$@" || return 94
139         done
140         for ((num=1; num <= $mdscount; num++ )); do
141                 wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds${num} FULL
142         done
143 }
144
145 start_mgsmds() {
146         if ! combined_mgs_mds ; then
147                 start_mgs
148         fi
149         start_mds "$@"
150 }
151
152 stop_mds() {
153         local num
154         for num in $(seq $MDSCOUNT); do
155                 stop_mdt $num || return 97
156         done
157 }
158
159 stop_mgs() {
160         echo "stop mgs service on `facet_active_host mgs`"
161         # These tests all use non-failover stop
162         stop mgs -f  || return 97
163 }
164
165 start_ost() {
166         echo "start ost1 service on `facet_active_host ost1`"
167         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS "$@" || return 95
168         wait_clients_import_ready ${CLIENTS:-$HOSTNAME} ost1
169 }
170
171 stop_ost() {
172         echo "stop ost1 service on `facet_active_host ost1`"
173         # These tests all use non-failover stop
174         stop ost1 -f || return 98
175 }
176
177 start_ost2() {
178         echo "start ost2 service on `facet_active_host ost2`"
179         start ost2 $(ostdevname 2) $OST_MOUNT_OPTS "$@" || return 92
180         wait_clients_import_ready ${CLIENTS:-$HOSTNAME} ost2
181 }
182
183 stop_ost2() {
184         echo "stop ost2 service on `facet_active_host ost2`"
185         # These tests all use non-failover stop
186         stop ost2 -f || return 93
187 }
188
189 mount_client() {
190         local mountpath=$1
191         local mountopt="$2"
192
193         echo "mount $FSNAME ${mountopt:+with opts $mountopt} on $mountpath....."
194         zconf_mount $HOSTNAME $mountpath $mountopt || return 96
195 }
196
197 umount_client() {
198         local mountpath=$1
199         shift
200         echo "umount lustre on $mountpath....."
201         zconf_umount $HOSTNAME $mountpath "$@" || return 97
202 }
203
204 manual_umount_client(){
205         local rc
206         local FORCE=$1
207         echo "manual umount lustre on ${MOUNT}...."
208         do_facet client "umount ${FORCE} $MOUNT"
209         rc=$?
210         return $rc
211 }
212
213 setup() {
214         start_mds || error "MDT start failed"
215         start_ost || error "Unable to start OST1"
216         mount_client $MOUNT || error "client start failed"
217         client_up || error "client_up failed"
218 }
219
220 setup_noconfig() {
221         start_mgsmds
222         start_ost
223         mount_client $MOUNT
224 }
225
226 unload_modules_conf () {
227         if combined_mgs_mds || ! local_mode; then
228                 unload_modules || return 1
229         fi
230 }
231
232 cleanup_nocli() {
233         stop_ost || return 202
234         stop_mds || return 201
235         unload_modules_conf || return 203
236 }
237
238 cleanup() {
239         local force=""
240         [ "x$1" != "x" ] && force='-f'
241         umount_client $MOUNT $force|| return 200
242         cleanup_nocli || return $?
243 }
244
245 cleanup_fs2() {
246         trap 0
247         echo "umount $MOUNT2 ..."
248         umount $MOUNT2 || true
249         echo "stopping fs2mds ..."
250         stop fs2mds -f || true
251         echo "stopping fs2ost ..."
252         stop fs2ost -f || true
253 }
254
255 check_mount() {
256         do_facet client "cp /etc/passwd $DIR/a" || return 71
257         do_facet client "rm $DIR/a" || return 72
258         # make sure lustre is actually mounted (touch will block,
259         # but grep won't, so do it after)
260         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
261         echo "setup single mount lustre success"
262 }
263
264 check_mount2() {
265         do_facet client "touch $DIR/a" || return 71
266         do_facet client "rm $DIR/a" || return 72
267         do_facet client "touch $DIR2/a" || return 73
268         do_facet client "rm $DIR2/a" || return 74
269         echo "setup double mount lustre success"
270 }
271
272 generate_name() {
273         cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $1 | head -n 1
274 }
275
276 if [ "$ONLY" == "setup" ]; then
277         setup
278         exit
279 fi
280
281 if [ "$ONLY" == "cleanup" ]; then
282         cleanup
283         exit
284 fi
285
286 init_gss
287
288 #create single point mountpoint
289
290 reformat_and_config
291
292 test_0() {
293         setup
294         check_mount || error "check_mount failed"
295         cleanup || error "cleanup failed with $?"
296 }
297 run_test 0 "single mount setup"
298
299 test_1() {
300         start_mds || error "MDS start failed"
301         start_ost || error "unable to start OST"
302         echo "start ost second time..."
303         start_ost && error "2nd OST start should fail"
304         mount_client $MOUNT || error "client start failed"
305         check_mount || error "check_mount failed"
306         cleanup || error "cleanup failed with $?"
307 }
308 run_test 1 "start up ost twice (should return errors)"
309
310 test_2() {
311         start_mds || error "MDT start failed"
312         echo "start mds second time.."
313         start_mds && error "2nd MDT start should fail"
314         start_ost || error "OST start failed"
315         mount_client $MOUNT || error "mount_client failed to start client"
316         check_mount || error "check_mount failed"
317         cleanup || error "cleanup failed with $?"
318 }
319 run_test 2 "start up mds twice (should return err)"
320
321 test_3() {
322         setup
323         #mount.lustre returns an error if already in mtab
324         mount_client $MOUNT && error "2nd client mount should fail"
325         check_mount || error "check_mount failed"
326         cleanup || error "cleanup failed with $?"
327 }
328 run_test 3 "mount client twice (should return err)"
329
330 test_4() {
331         setup
332         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
333         stop_ost || error "Unable to stop OST1"
334         umount_client $MOUNT -f || error "unmount $MOUNT failed"
335         cleanup_nocli
336         eno=$?
337         # ok for ost to fail shutdown
338         if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
339                 error "cleanup failed with $?"
340         fi
341 }
342 run_test 4 "force cleanup ost, then cleanup"
343
344 test_5a() {     # was test_5
345         setup
346         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
347         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
348
349         stop_mds || error "Unable to stop MDS"
350
351         # cleanup may return an error from the failed
352         # disconnects; for now I'll consider this successful
353         # if all the modules have unloaded.
354         $UMOUNT -f $MOUNT &
355         UMOUNT_PID=$!
356         sleep 6
357         echo "killing umount"
358         kill -TERM $UMOUNT_PID
359         echo "waiting for umount to finish"
360         wait $UMOUNT_PID
361         if grep " $MOUNT " /proc/mounts; then
362                 echo "test 5: /proc/mounts after failed umount"
363                 umount -f $MOUNT &
364                 UMOUNT_PID=$!
365                 sleep 2
366                 echo "killing umount"
367                 kill -TERM $UMOUNT_PID
368                 echo "waiting for umount to finish"
369                 wait $UMOUNT_PID
370                 grep " $MOUNT " /proc/mounts &&
371                         error "/proc/mounts after second umount"
372         fi
373
374         # manual_mount_client may fail due to umount succeeding above
375         manual_umount_client
376         # stop_mds is a no-op here, and should not fail
377         cleanup_nocli || error "cleanup_nocli failed with $?"
378         # df may have lingering entry
379         manual_umount_client
380         # mtab may have lingering entry
381         local WAIT=0
382         local MAX_WAIT=20
383         local sleep=1
384         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
385                 sleep $sleep
386                 grep -q $MOUNT" " /etc/mtab || break
387                 echo "Waiting /etc/mtab updated ... "
388                 WAIT=$(( WAIT + sleep))
389         done
390         [ "$WAIT" -eq "$MAX_WAIT" ] &&
391                 error "/etc/mtab is not updated in $WAIT secs"
392         echo "/etc/mtab updated in $WAIT secs"
393 }
394 run_test 5a "force cleanup mds, then cleanup"
395
396 cleanup_5b () {
397         trap 0
398         start_mgs
399 }
400
401 test_5b() {
402         grep " $MOUNT " /etc/mtab &&
403                 error false "unexpected entry in mtab before mount" && return 10
404
405         start_ost || error "OST start failed"
406         if ! combined_mgs_mds ; then
407                 trap cleanup_5b EXIT ERR
408                 start_mds || error "MDS start failed"
409                 stop mgs
410         fi
411
412         mount_client $MOUNT && error "mount_client $MOUNT should fail"
413         grep " $MOUNT " /etc/mtab &&
414                 error "$MOUNT entry in mtab after failed mount"
415         umount_client $MOUNT
416         # stop_mds is a no-op here, and should not fail
417         cleanup_nocli || error "cleanup_nocli failed with $?"
418         if ! combined_mgs_mds ; then
419                 cleanup_5b
420         fi
421 }
422 run_test 5b "Try to start a client with no MGS (should return errs)"
423
424 test_5c() {
425         grep " $MOUNT " /etc/mtab &&
426                 error false "unexpected entry in mtab before mount" && return 10
427
428         start_mds || error "MDS start failed"
429         start_ost || error "OST start failed"
430         local oldfs="${FSNAME}"
431         FSNAME="wrong.${FSNAME}"
432         mount_client $MOUNT || :
433         FSNAME=${oldfs}
434         grep " $MOUNT " /etc/mtab &&
435                 error "$MOUNT entry in mtab after failed mount"
436         umount_client $MOUNT
437         cleanup_nocli || error "cleanup_nocli failed with $?"
438 }
439 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
440
441 test_5d() {
442         grep " $MOUNT " /etc/mtab &&
443                 error "unexpected entry in mtab before mount"
444
445         start_ost || error "OST start failed"
446         start_mds || error "MDS start failed"
447         stop_ost -f || error "Unable to stop OST1"
448         mount_client $MOUNT || error "mount_client $MOUNT failed"
449         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
450         cleanup_nocli || error "cleanup_nocli failed with $?"
451         ! grep " $MOUNT " /etc/mtab ||
452                 error "$MOUNT entry in mtab after unmount"
453 }
454 run_test 5d "mount with ost down"
455
456 test_5e() {
457         grep " $MOUNT " /etc/mtab &&
458                 error false "unexpected entry in mtab before mount" && return 10
459
460         start_mds || error "MDS start failed"
461         start_ost || error "OST start failed"
462
463         #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
464         do_facet client "$LCTL set_param fail_loc=0x80000506"
465         mount_client $MOUNT || echo "mount failed (not fatal)"
466         cleanup || error "cleanup failed with $?"
467         grep " $MOUNT " /etc/mtab &&
468                 error "$MOUNT entry in mtab after unmount"
469         pass
470 }
471 run_test 5e "delayed connect, don't crash (bug 10268)"
472
473 test_5f() {
474         combined_mgs_mds && skip "needs separate mgs and mds"
475
476         grep " $MOUNT " /etc/mtab &&
477                 error false "unexpected entry in mtab before mount" && return 10
478
479         local rc=0
480         start_ost || error "OST start failed"
481         mount_client $MOUNT &
482         local pid=$!
483         echo client_mount pid is $pid
484
485         sleep 5
486
487         if ! ps -f -p $pid >/dev/null; then
488                 wait $pid
489                 rc=$?
490                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
491                 error "mount returns $rc, expected to hang"
492                 rc=11
493                 cleanup || error "cleanup failed with $?"
494                 return $rc
495         fi
496
497         # start mds
498         start_mds || error "start MDS failed"
499
500         # mount should succeed after start mds
501         wait $pid
502         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
503         cleanup || error "final call to cleanup failed with rc $?"
504 }
505 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
506
507 test_5g() {
508         modprobe lustre
509         [ "$CLIENT_VERSION" -lt $(version_code 2.9.53) ] &&
510                 skip "automount of debugfs missing before 2.9.53"
511         umount /sys/kernel/debug
512         $LCTL get_param -n devices | egrep -v "error" && \
513                 error "lctl can't access debugfs data"
514         grep " debugfs " /etc/mtab || error "debugfs failed to remount"
515 }
516 run_test 5g "handle missing debugfs"
517
518 test_5h() {
519         setup
520
521         stop mds1
522         #define OBD_FAIL_MDS_FS_SETUP            0x135
523         do_facet mds1 "$LCTL set_param fail_loc=0x80000135"
524         start_mdt 1 && error "start mdt should fail"
525         start_mdt 1 || error "start mdt failed"
526         client_up || error "client_up failed"
527         cleanup
528 }
529 run_test 5h "start mdt failure at mdt_fs_setup()"
530
531 test_5i() {
532         (( $MDS1_VERSION >= $(version_code 2.12.54) )) ||
533                 skip "Need MDS version at least 2.12.54"
534
535         setup
536
537         stop mds1
538         #define OBD_FAIL_QUOTA_INIT              0xA05
539         do_facet mds1 "$LCTL set_param fail_loc=0x80000A05"
540         start_mdt 1 && error "start mdt should fail"
541         start_mdt 1 || error "start mdt failed"
542         client_up || error "client_up failed"
543         cleanup
544 }
545 run_test 5i "start mdt failure at mdt_quota_init()"
546
547 test_5j() {
548         unload_modules
549         load_module ../libcfs/libcfs/libcfs ||
550                 error "Failed to load modules libcfs rc = $?"
551         $LCTL set_param debug=all
552         rmmod -v libcfs
553 }
554 run_test 5j "verify libcfs doesn't crash when setting debug flags"
555
556 test_6() {
557         setup
558         manual_umount_client
559         mount_client $MOUNT || error "mount_client $MOUNT failed"
560         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
561         cleanup || error "cleanup failed with rc $?"
562 }
563 run_test 6 "manual umount, then mount again"
564
565 test_7() {
566         setup
567         manual_umount_client
568         cleanup_nocli || error "cleanup_nocli failed with $?"
569 }
570 run_test 7 "manual umount, then cleanup"
571
572 test_8() {
573         setup
574         mount_client $MOUNT2 || error "mount_client $MOUNT2 failed"
575         check_mount2 || error "check_mount2 failed"
576         umount_client $MOUNT2 || error "umount_client $MOUNT2 failed"
577         cleanup || error "cleanup failed with rc $?"
578 }
579 run_test 8 "double mount setup"
580
581 test_9() {
582         start_ost || error "OST start failed"
583
584         do_facet ost1 $LCTL set_param debug=\'inode trace\' ||
585                 error "do_facet ost1 set_param inode trace failed."
586         do_facet ost1 $LCTL set_param subsystem_debug=\'mds ost\' ||
587                 error "do_facet ost1 set_param debug mds ost failed."
588
589         CHECK_PTLDEBUG="`do_facet ost1 $LCTL get_param -n debug`"
590         if [ "$CHECK_PTLDEBUG" ] && { \
591            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
592            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
593                 echo "lnet.debug success"
594         else
595                 error "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
596         fi
597         CHECK_SUBSYS="`do_facet ost1 $LCTL get_param -n subsystem_debug`"
598         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
599                 echo "lnet.subsystem_debug success"
600         else
601                 error "lnet.subsystem_debug: want 'mds ost' got '$CHECK_SUBSYS'"
602         fi
603         stop_ost || error "Unable to stop OST1"
604 }
605 run_test 9 "test ptldebug and subsystem for mkfs"
606
607 test_10a() {
608         setup
609
610         if ! combined_mgs_mds; then
611                 files=$(do_facet mgs "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
612                 [ -z $files ] || echo "MGS $files is a broken symlink"
613         fi
614
615         files=$(do_facet mds1 "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
616         [ -z $files ] || echo "MDS $files is a broken symlink"
617
618         files=$(do_facet ost1 "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
619         [ -z $files ] || echo "OSS $files is a broken symlink"
620
621         files=$(do_facet client "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
622         [ -z $files ] || echo "clients $files is a broken symlink"
623
624         cleanup || error "cleanup failed with rc $?"
625 }
626 run_test 10a "find lctl param broken symlinks"
627
628 #
629 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
630 # But with new MDS stack we don't care about the mode of local objects
631 # anymore, so this test is removed. See bug 22944 for more details.
632 #
633
634 test_17() {
635         if [ "$mds1_FSTYPE" != ldiskfs ]; then
636                 skip "ldiskfs only test"
637         fi
638
639         setup
640         check_mount || error "check_mount failed"
641         cleanup || error "cleanup failed with rc $?"
642
643         echo "Remove mds config log"
644         if ! combined_mgs_mds ; then
645                 stop mgs
646         fi
647
648         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
649                       $(mgsdevname) || return \$?" ||
650                 error "do_facet mgs failed with $?"
651
652         if ! combined_mgs_mds ; then
653                 start_mgs
654         fi
655
656         start_ost || error "OST start failed"
657         start_mds && error "MDS start succeeded, but should fail"
658         reformat_and_config
659 }
660 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
661
662 test_18() {
663         if [ "$mds1_FSTYPE" != ldiskfs ]; then
664                 skip "ldiskfs only test"
665         fi
666
667         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
668
669         local MIN=2000000
670
671         local OK=
672         # check if current MDSSIZE is large enough
673         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE &&
674                 log "use MDSSIZE=$MDSSIZE"
675
676         # check if the global config has a large enough MDSSIZE
677         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] &&
678                 [ $STORED_MDSSIZE -ge $MIN ] &&
679                 OK=1 && myMDSSIZE=$STORED_MDSSIZE &&
680                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
681
682         # check if the block device is large enough
683         is_blkdev $SINGLEMDS $MDSDEV $MIN
684         local large_enough=$?
685         if [ -n "$OK" ]; then
686                 [ $large_enough -ne 0 ] && OK=""
687         else
688                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
689                         log "use device $MDSDEV with MIN=$MIN"
690         fi
691
692         # check if a loopback device has enough space for fs metadata (5%)
693
694         if [ -z "$OK" ]; then
695                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! \
696                               -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
697                         awk '($1 != "Filesystem") { print $4 }')
698                 ! [ -z "$SPACE" ] && [ $SPACE -gt $((MIN / 20)) ] &&
699                         OK=1 && myMDSSIZE=$MIN &&
700                         log "use file $MDSDEV with MIN=$MIN"
701         fi
702
703         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS"
704
705         echo "mount mds with large journal..."
706
707         local OLD_MDSSIZE=$MDSSIZE
708         MDSSIZE=$myMDSSIZE
709
710         reformat_and_config
711         echo "mount lustre system..."
712         setup
713         check_mount || error "check_mount failed"
714
715         echo "check journal size..."
716         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
717         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
718                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
719         else
720                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
721         fi
722
723         cleanup || error "cleanup failed with rc $?"
724
725         MDSSIZE=$OLD_MDSSIZE
726         reformat_and_config
727 }
728 run_test 18 "check mkfs creates large journals"
729
730 test_19a() {
731         start_mds || error "MDS start failed"
732         stop_mds || error "Unable to stop MDS"
733 }
734 run_test 19a "start/stop MDS without OSTs"
735
736 test_19b() {
737         start_ost || error "Unable to start OST1"
738         stop_ost -f || error "Unable to stop OST1"
739 }
740 run_test 19b "start/stop OSTs without MDS"
741
742 test_20() {
743         # first format the ost/mdt
744         start_mds || error "MDS start failed"
745         start_ost || error "Unable to start OST1"
746         mount_client $MOUNT || error "mount_client $MOUNT failed"
747         check_mount || error "check_mount failed"
748         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed."
749         mount_client $MOUNT remount,ro || error "remount client with ro failed"
750         touch $DIR/$tfile && error "$DIR/$tfile created incorrectly"
751         [ -e $DIR/$tfile ] && error "$DIR/$tfile exists incorrectly"
752         mount_client $MOUNT remount,rw || error "remount client with rw failed"
753         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
754         MCNT=$(grep -c $MOUNT' ' /etc/mtab)
755         [ "$MCNT" -ne 1 ] && error "$MOUNT in /etc/mtab $MCNT times"
756         umount_client $MOUNT
757         stop_mds || error "Unable to stop MDS"
758         stop_ost || error "Unable to stop OST1"
759 }
760 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
761
762 test_21a() {
763         start_mds || error "MDS start failed"
764         start_ost || error "unable to start OST1"
765         wait_osc_import_state mds ost FULL
766         stop_ost || error "unable to stop OST1"
767         stop_mds || error "unable to stop MDS"
768 }
769 run_test 21a "start mds before ost, stop ost first"
770
771 test_21b() {
772         start_ost || error "unable to start OST1"
773         start_mds || error "MDS start failed"
774         wait_osc_import_state mds ost FULL
775         stop_mds || error "unable to stop MDS"
776         stop_ost || error "unable to stop OST1"
777 }
778 run_test 21b "start ost before mds, stop mds first"
779
780 test_21c() {
781         start_ost || error "Unable to start OST1"
782         start_mds || error "MDS start failed"
783         start_ost2 || error "Unable to start OST2"
784         wait_osc_import_state mds ost2 FULL
785         stop_ost || error "Unable to stop OST1"
786         stop_ost2 || error "Unable to stop OST2"
787         stop_mds || error "Unable to stop MDS"
788         #writeconf to remove all ost2 traces for subsequent tests
789         writeconf_or_reformat
790 }
791 run_test 21c "start mds between two osts, stop mds last"
792
793 test_21d() {
794         combined_mgs_mds && skip "need separate mgs device"
795
796         stopall
797         reformat
798
799         start_mgs || error "unable to start MGS"
800         start_ost || error "unable to start OST1"
801         start_ost2 || error "unable to start OST2"
802         start_mds || error "MDS start failed"
803         wait_osc_import_state mds ost2 FULL
804
805         local zkeeper=${KEEP_ZPOOL}
806         stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
807         KEEP_ZPOOL="true"
808
809         stop_ost || error "Unable to stop OST1"
810         stop_ost2 || error "Unable to stop OST2"
811         stop_mds || error "Unable to stop MDS"
812         stop_mgs
813         #writeconf to remove all ost2 traces for subsequent tests
814         writeconf_or_reformat
815         KEEP_ZPOOL="${zkeeper}"
816
817         start_mgs || error "unable to start MGS"
818 }
819 run_test 21d "start mgs then ost and then mds"
820
821 cleanup_21e() {
822         MGSNID="$saved_mgsnid"
823         cleanup_fs2
824         echo "stopping fs2mgs ..."
825         stop $fs2mgs -f || true
826 }
827
828 test_21e() { # LU-5863
829         if [[ -z "$fs3ost_DEV" || -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
830                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
831                 skip_env "mixed loopback and real device not working"
832         fi
833
834         local fs2mdsdev=$(mdsdevname 1_2)
835         local fs2ostdev=$(ostdevname 1_2)
836         local fs3ostdev=$(ostdevname 2_2)
837
838         local fs2mdsvdev=$(mdsvdevname 1_2)
839         local fs2ostvdev=$(ostvdevname 1_2)
840         local fs3ostvdev=$(ostvdevname 2_2)
841
842         # temporarily use fs3ost as fs2mgs
843         local fs2mgs=fs3ost
844         local fs2mgsdev=$fs3ostdev
845         local fs2mgsvdev=$fs3ostvdev
846
847         local fsname=test1234
848
849         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
850                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
851         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS && trap cleanup_21e EXIT INT ||
852                 error "start fs2mgs failed"
853
854         local saved_mgsnid="$MGSNID"
855         MGSNID=$(do_facet $fs2mgs $LCTL list_nids | xargs | tr ' ' ,)
856
857         add fs2mds $(mkfs_opts mds1 $fs2mdsdev $fsname) \
858                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
859         add fs2ost $(mkfs_opts ost1 $fs2ostdev $fsname) \
860                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
861
862         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
863         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
864
865         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
866         $MOUNT_CMD $MGSNID:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
867         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
868
869         cleanup_21e
870 }
871 run_test 21e "separate MGS and MDS"
872
873 test_22() {
874         start_mds || error "MDS start failed"
875
876         echo "Client mount with ost in logs, but none running"
877         start_ost || error "unable to start OST1"
878         # wait until mds connected to ost and open client connection
879         wait_osc_import_state mds ost FULL
880         stop_ost || error "unable to stop OST1"
881         mount_client $MOUNT || error "mount_client $MOUNT failed"
882         # check_mount will block trying to contact ost
883         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
884         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
885         umount_client $MOUNT -f
886         pass
887
888         echo "Client mount with a running ost"
889         start_ost || error "unable to start OST1"
890         if $GSS; then
891                 # if gss enabled, wait full time to let connection from
892                 # mds to ost be established, due to the mismatch between
893                 # initial connect timeout and gss context negotiation timeout.
894                 # This perhaps could be remove after AT landed.
895                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
896                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
897         fi
898         mount_client $MOUNT || error "mount_client $MOUNT failed"
899         wait_osc_import_state mds ost FULL
900         wait_osc_import_ready client ost
901         check_mount || error "check_mount failed"
902         pass
903
904         cleanup || error "cleanup failed with rc $?"
905 }
906 run_test 22 "start a client before osts (should return errs)"
907
908 test_23a() {    # was test_23
909         setup
910         # fail mds
911         stop $SINGLEMDS || error "failed to stop $SINGLEMDS"
912         # force down client so that recovering mds waits for reconnect
913         local running=$(grep -c $MOUNT /proc/mounts) || true
914         if [ $running -ne 0 ]; then
915                 echo "Stopping client $MOUNT (opts: -f)"
916                 umount -f $MOUNT
917         fi
918
919         # enter recovery on failed mds
920         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
921         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "MDS start failed"
922         # try to start a new client
923         mount_client $MOUNT &
924         sleep 5
925         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
926         MOUNT_LUSTRE_PID=$(ps -ef | grep mount.lustre |
927                            grep -v grep | awk '{print $2}')
928         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
929         ps --ppid $MOUNT_PID
930         ps --ppid $MOUNT_LUSTRE_PID
931         echo "waiting for mount to finish"
932         ps -ef | grep mount
933         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
934         # SIGTERM works but it does not spread to offspring processses
935         kill -s TERM $MOUNT_PID
936         kill -s TERM $MOUNT_LUSTRE_PID
937         # we can not wait $MOUNT_PID because it is not a child of this shell
938         local PID1
939         local PID2
940         local WAIT=0
941         local MAX_WAIT=30
942         local sleep=1
943         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
944                 sleep $sleep
945                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
946                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
947                 echo PID1=$PID1
948                 echo PID2=$PID2
949                 [ -z "$PID1" -a -z "$PID2" ] && break
950                 echo "waiting for mount to finish ... "
951                 WAIT=$(( WAIT + sleep))
952         done
953         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
954                 error "MOUNT_PID $MOUNT_PID and "\
955                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
956                 ps -ef | grep mount
957         fi
958         cleanup || error "cleanup failed with rc $?"
959 }
960 run_test 23a "interrupt client during recovery mount delay"
961
962 test_23b() {    # was test_23
963         start_mds || error "MDS start failed"
964         start_ost || error "Unable to start OST1"
965         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
966         $LCTL set_param fail_loc=0x80000313
967         mount_client $MOUNT
968         cleanup || error "cleanup failed with rc $?"
969 }
970 run_test 23b "Simulate -EINTR during mount"
971
972 test_24a() {
973         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
974
975         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
976                 is_blkdev $SINGLEMDS $MDSDEV &&
977                 skip_env "mixed loopback and real device not working"
978         fi
979
980         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
981
982         local fs2mdsdev=$(mdsdevname 1_2)
983         local fs2ostdev=$(ostdevname 1_2)
984         local fs2mdsvdev=$(mdsvdevname 1_2)
985         local fs2ostvdev=$(ostvdevname 1_2)
986         local cl_user
987
988         # LU-9733 test fsname started with numbers as well
989         local FSNAME2=969362ae
990
991         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
992                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
993
994         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
995                 --reformat $fs2ostdev $fs2ostvdev || exit 10
996
997         setup
998         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
999         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1000         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
1001         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
1002
1003         # LU-9733 test fsname started with numbers
1004         cl_user=$(do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
1005                         changelog_register -n) ||
1006                                 error "register changelog failed"
1007
1008         do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
1009                         changelog_deregister $cl_user ||
1010                                 error "deregister changelog failed"
1011         # 1 still works
1012         check_mount || error "check_mount failed"
1013         # files written on 1 should not show up on 2
1014         cp /etc/passwd $DIR/$tfile
1015         sleep 10
1016         [ -e $MOUNT2/$tfile ] && error "File bleed"
1017         # 2 should work
1018         sleep 5
1019         cp /etc/passwd $MOUNT2/$tfile ||
1020                 error "cp /etc/passwd $MOUNT2/$tfile failed"
1021         rm $MOUNT2/$tfile || error "remove $MOUNT2/$tfile failed"
1022         # 2 is actually mounted
1023         grep $MOUNT2' ' /proc/mounts > /dev/null || error "$MOUNT2 not mounted"
1024         # failover
1025         facet_failover fs2mds
1026         facet_failover fs2ost
1027         df
1028         umount_client $MOUNT
1029         # the MDS must remain up until last MDT
1030         stop_mds
1031         MDS=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1032               awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1033         [ -z "$MDS" ] && error "No MDT"
1034         cleanup_fs2
1035         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1036 }
1037 run_test 24a "Multiple MDTs on a single node"
1038
1039 test_24b() {
1040         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1041         combined_mgs_mds ||
1042                 skip "needs combined MGT and MDT device"
1043
1044         if [ -z "$fs2mds_DEV" ]; then
1045                 local dev=${SINGLEMDS}_dev
1046                 local MDSDEV=${!dev}
1047                 is_blkdev $SINGLEMDS $MDSDEV &&
1048                 skip_env "mixed loopback and real device not working"
1049         fi
1050
1051         local fs2mdsdev=$(mdsdevname 1_2)
1052         local fs2mdsvdev=$(mdsvdevname 1_2)
1053
1054         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
1055                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
1056         setup
1057         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && {
1058                 cleanup
1059                 error "start MDS should fail"
1060         }
1061         stop fs2mds -f
1062         cleanup || error "cleanup failed with rc $?"
1063 }
1064 run_test 24b "Multiple MGSs on a single node (should return err)"
1065
1066 test_25() {
1067         setup_noconfig
1068         check_mount || error "check_mount failed"
1069         local MODULES=$($LCTL modules | awk '{ print $2 }')
1070         rmmod $MODULES 2>/dev/null || true
1071         cleanup || error "cleanup failed with $?"
1072 }
1073 run_test 25 "Verify modules are referenced"
1074
1075 test_26() {
1076         load_modules
1077         # we need modules before mount for sysctl, so make sure...
1078         do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
1079         #define OBD_FAIL_MDS_FS_SETUP            0x135
1080         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000135"
1081         start_mds && error "MDS started but should not have started"
1082         $LCTL get_param -n devices
1083         DEVS=$($LCTL get_param -n devices | egrep -v MG | wc -l)
1084         [ $DEVS -gt 0 ] && error "number of devices is $DEVS, should be zero"
1085         # start mds to drop writeconf setting
1086         start_mds || error "Unable to start MDS"
1087         stop_mds || error "Unable to stop MDS"
1088         unload_modules_conf || error "unload_modules_conf failed with $?"
1089 }
1090 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1091
1092 test_27a() {
1093         cleanup
1094         start_ost || error "Unable to start OST1"
1095         start_mds || error "Unable to start MDS"
1096         echo "Requeue thread should have started: "
1097         ps -e | grep ll_cfg_requeue
1098         set_persistent_param_and_check ost1                     \
1099            "obdfilter.$FSNAME-OST0000.client_cache_seconds"     \
1100            "$FSNAME-OST0000.ost.client_cache_seconds"
1101         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1102 }
1103 run_test 27a "Reacquire MGS lock if OST started first"
1104
1105 test_27b() {
1106         # FIXME. ~grev
1107         setup_noconfig
1108         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1109                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1110
1111         facet_failover $SINGLEMDS
1112         set_persistent_param_and_check $SINGLEMDS       \
1113                 "mdt.$device.identity_acquire_expire"   \
1114                 "$device.mdt.identity_acquire_expire"
1115         set_persistent_param_and_check client           \
1116                 "mdc.$device-mdc-*.max_rpcs_in_flight"  \
1117                 "$device.mdc.max_rpcs_in_flight"
1118         check_mount
1119         cleanup || error "cleanup failed with $?"
1120 }
1121 run_test 27b "Reacquire MGS lock after failover"
1122
1123 test_28A() { # was test_28
1124         setup_noconfig
1125
1126         local TEST="llite.$FSNAME-*.max_read_ahead_whole_mb"
1127         local PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1128         local orig=$($LCTL get_param -n $TEST)
1129         local max=$($LCTL get_param -n \
1130                         llite.$FSNAME-*.max_read_ahead_per_file_mb)
1131
1132         orig=${orig%%.[0-9]*}
1133         max=${max%%.[0-9]*}
1134         echo "ORIG:$orig MAX:$max"
1135         [[ $max -le $orig ]] && orig=$((max - 3))
1136         echo "ORIG:$orig MAX:$max"
1137
1138         local final=$((orig + 1))
1139
1140         set_persistent_param_and_check client "$TEST" "$PARAM" $final
1141         final=$((final + 1))
1142         set_persistent_param_and_check client "$TEST" "$PARAM" $final
1143         umount_client $MOUNT || error "umount_client $MOUNT failed"
1144         mount_client $MOUNT || error "mount_client $MOUNT failed"
1145
1146         local result=$($LCTL get_param -n $TEST)
1147
1148         if [ $result -ne $final ]; then
1149                 error "New config not seen: wanted $final got $result"
1150         else
1151                 echo "New config success: got $result"
1152         fi
1153         set_persistent_param_and_check client "$TEST" "$PARAM" $orig
1154         cleanup || error "cleanup failed with rc $?"
1155 }
1156 run_test 28A "permanent parameter setting"
1157
1158 test_28a() { # LU-4221
1159         [[ "$OST1_VERSION" -ge $(version_code 2.5.52) ]] ||
1160                 skip "Need OST version at least 2.5.52"
1161         [ "$ost1_FSTYPE" = zfs ] &&
1162                 skip "LU-4221: no such proc params for ZFS OSTs"
1163
1164         local name
1165         local param
1166         local cmd
1167         local old
1168         local new
1169         local device="$FSNAME-OST0000"
1170
1171         setup_noconfig
1172
1173         # In this test we will set three kinds of proc parameters with
1174         # lctl set_param -P or lctl conf_param:
1175         # 1. non-symlink ones in the OFD
1176         # 2. non-symlink ones in the OSD
1177
1178         # Check 1.
1179         # prepare a non-symlink parameter in the OFD
1180         name="client_cache_seconds"
1181         param="$device.ost.$name"
1182         cmd="obdfilter.$device.$name"
1183
1184         # permanently setting the parameter in the OFD
1185         old=$(do_facet ost1 $LCTL get_param -n $cmd)
1186         new=$((old * 2))
1187         set_persistent_param_and_check ost1 "$cmd" "$param" $new
1188         set_persistent_param_and_check ost1 "$cmd" "$param" $old
1189
1190         # Check 2.
1191         # prepare a non-symlink parameter in the OSD
1192         name="auto_scrub"
1193         param="$device.osd.$name"
1194         cmd="osd-*.$device.$name"
1195
1196         # conf_param the parameter in the OSD
1197         old=$(do_facet ost1 $LCTL get_param -n $cmd)
1198         new=$(((old + 1) % 2))
1199         set_persistent_param_and_check ost1 "$cmd" "$param" $new
1200         set_persistent_param_and_check ost1 "$cmd" "$param" $old
1201
1202         cleanup || error "cleanup failed with $?"
1203 }
1204 run_test 28a "set symlink parameters permanently with lctl"
1205
1206 test_29() {
1207         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
1208         setup_noconfig > /dev/null 2>&1
1209         start_ost2 || error "Unable to start OST2"
1210         sleep 10
1211
1212         local PARAM="$FSNAME-OST0001.osc.active"
1213         # With lctl set_param -P the value $PROC_ACT will be sent to
1214         # all nodes. The [!M] filter out the ability to set active
1215         # on the MDS servers which is tested with wait_osp_* below.
1216         # For ost_server_uuid that only exist on client so filtering
1217         # is safe.
1218         local PROC_ACT="os[cp].$FSNAME-OST0001-osc-[^M]*.active"
1219         local PROC_UUID="os[cp].$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1220
1221         ACTV=$($LCTL get_param -n $PROC_ACT)
1222         DEAC=$((1 - $ACTV))
1223         set_persistent_param_and_check client $PROC_ACT $PARAM $DEAC
1224         # also check ost_server_uuid status
1225         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV)
1226         if [ -z "$RESULT" ]; then
1227                 error "Client not deactivated: $($LCTL get_param \
1228                        -n $PROC_UUID)"
1229         else
1230                 echo "Live client success: got $RESULT"
1231         fi
1232
1233         # check MDTs too
1234         wait_osp_active ost ${FSNAME}-OST0001 1 0
1235
1236         # test new client starts deactivated
1237         umount_client $MOUNT || error "umount_client $MOUNT failed"
1238         mount_client $MOUNT || error "mount_client $MOUNT failed"
1239
1240         # the 2nd and 3rd field of ost_server_uuid do not update at the same
1241         # time when using lctl set_param -P
1242         wait_update_facet client                                        \
1243                 "$LCTL get_param -n $PROC_UUID | awk '{print \\\$3 }'"  \
1244                 "DEACTIVATED" ||
1245                 error "New client start active: $($LCTL get_param -n $PROC_UUID)"
1246
1247         echo "New client success: got '$($LCTL get_param -n $PROC_UUID)'"
1248
1249         # make sure it reactivates
1250         set_persistent_param_and_check client $PROC_ACT $PARAM $ACTV
1251
1252         umount_client $MOUNT
1253         stop_ost2 || error "Unable to stop OST2"
1254         cleanup_nocli || error "cleanup_nocli failed with $?"
1255         #writeconf to remove all ost2 traces for subsequent tests
1256         writeconf_or_reformat
1257 }
1258 run_test 29 "permanently remove an OST"
1259
1260 test_30a() {
1261         setup_noconfig
1262
1263         echo Big config llog
1264         local path="llite.$FSNAME-*"
1265         local cpath="$FSNAME.llite"
1266         local param="max_read_ahead_whole_mb"
1267
1268         local test="${path}.$param"
1269         local conf="${cpath}.$param"
1270
1271         local orig=$($LCTL get_param -n $test)
1272         local list=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1273         for i in ${list[*]}; do
1274                 set_persistent_param_and_check client $test $conf $i
1275         done
1276         # make sure client restart still works
1277         umount_client $MOUNT
1278         mount_client $MOUNT || error "mount_client $MOUNT failed"
1279         [ "$($LCTL get_param -n $test)" -ne "$i" ] &&
1280                 error "Param didn't stick across restart $($test) != $i"
1281         pass
1282
1283         echo Erase parameter setting
1284         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1285                 do_facet mgs "$PERM_CMD -d $test" ||
1286                         error "Erase param $test failed"
1287         else
1288                 do_facet mgs "$PERM_CMD -d $conf" ||
1289                         error "Erase param $conf failed"
1290         fi
1291         umount_client $MOUNT
1292         mount_client $MOUNT || error "mount_client $MOUNT failed"
1293         local final=$($LCTL get_param -n $test)
1294         echo "deleted (default) value=$final, orig=$orig"
1295         orig=${orig%%.[0-9]*}
1296         final=${final%%.[0-9]*}
1297         # assumes this parameter started at the default value
1298         [ "$final" -eq "$orig" ] ||
1299                 error "Deleted value=$final -ne orig=$orig"
1300
1301         cleanup || error "cleanup failed with rc $?"
1302 }
1303 run_test 30a "Big config llog and permanent parameter deletion"
1304
1305 test_30b() {
1306         setup_noconfig
1307
1308         local orignids=$($LCTL get_param -n \
1309                 osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1310
1311         local orignidcount=$(echo "$orignids" | wc -w)
1312
1313         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1314         # numerical part of it. Hopefully that's not already a failover address
1315         # for the server.
1316         local OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | \
1317                 awk '{print $1}')
1318         local ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1319         local NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1320         local NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1321         echo "Using fake nid $NEW"
1322
1323         local TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1324                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1325         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1326                 PARAM="osc.$FSNAME-OST0000-osc-[^M]*.import"
1327                 echo "Setting $PARAM from $TEST to $NEW"
1328                 do_facet mgs "$PERM_CMD $PARAM='connection=$NEW'" ||
1329                         error "$PERM_CMD $PARAM failed"
1330         else
1331                 PARAM="$FSNAME-OST0000.failover.node"
1332                 echo "Setting $PARAM from $TEST to $NEW"
1333                 do_facet mgs "$PERM_CMD $PARAM='$NEW'" ||
1334                         error "$PARAM $PARAM failed"
1335         fi
1336         wait_update_facet client "$TEST" "$NEW" ||
1337                 error "check $PARAM failed!"
1338
1339         local NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1340                 grep failover_nids)
1341         local NIDCOUNT=$(echo "$NIDS" | wc -w)
1342         echo "should have $((orignidcount + 1)) entries \
1343                 in failover nids string, have $NIDCOUNT"
1344         [ $NIDCOUNT -eq $((orignidcount + 1)) ] ||
1345                 error "Failover nid not added"
1346
1347         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1348                 do_facet mgs "$PERM_CMD -d osc.$FSNAME-OST0000-osc-*.import"
1349         else
1350                 do_facet mgs "$PERM_CMD -d $FSNAME-OST0000.failover.node" ||
1351                         error "$PERM_CMD delete failed"
1352         fi
1353         umount_client $MOUNT
1354         mount_client $MOUNT || error "mount_client $MOUNT failed"
1355
1356         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1357                 grep failover_nids)
1358         NIDCOUNT=$(echo "$NIDS" | wc -w)
1359         echo "only $orignidcount final entries should remain \
1360                 in failover nids string, have $NIDCOUNT"
1361         [ $NIDCOUNT -eq $orignidcount ] || error "Failover nids not removed"
1362
1363         cleanup || error "cleanup failed with rc $?"
1364 }
1365 run_test 30b "Remove failover nids"
1366
1367 test_31() { # bug 10734
1368         # ipaddr must not exist
1369         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1370         cleanup || error "cleanup failed with rc $?"
1371 }
1372 run_test 31 "Connect to non-existent node (shouldn't crash)"
1373
1374
1375 T32_QID=60000
1376 T32_BLIMIT=40960 # Kbytes
1377 T32_ILIMIT=4
1378 T32_PRJID=1000
1379 T32_PROLIMIT=$((T32_BLIMIT/10))
1380 #
1381 # This is not really a test but a tool to create new disk
1382 # image tarballs for the upgrade tests.
1383 #
1384 # Disk image tarballs should be created on single-node
1385 # clusters by running this test with default configurations
1386 # plus a few mandatory environment settings that are verified
1387 # at the beginning of the test.
1388 #
1389 test_32newtarball() {
1390         local version
1391         local dst=.
1392         local src=/etc/rc.d
1393         local tmp=$TMP/t32_image_create
1394         local remote_dir
1395         local striped_dir
1396         local pushd_dir
1397         local pfl_dir
1398         local pfl_file
1399         local dom_dir
1400         local dom_file
1401         local flr_dir
1402         local flr_file
1403         local pj_quota_dir
1404         local pj_quota_file_old
1405         local target_dir
1406
1407         if [ $FSNAME != t32fs -o \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o \
1408         $OSTCOUNT -ne 2 -o -z "$OSTDEV1" ]; then
1409                 error   "Needs FSNAME=t32fs MDSCOUNT=2 "                \
1410                         "MDSDEV1=<nonexistent_file> "                   \
1411                         "MDSDEV2=<nonexistent_file> "                   \
1412                         "(or MDSDEV, in the case of b1_8) "             \
1413                         "OSTCOUNT=2 OSTDEV1=<nonexistent_file> "        \
1414                         "OSTDEV2=<nonexistent_file>"
1415         fi
1416
1417         mkdir $tmp || {
1418                 echo "Found stale $tmp"
1419                 return 1
1420         }
1421
1422         mkdir $tmp/src || return 1
1423         tar cf - -C $src . | tar xf - -C $tmp/src
1424
1425         # format ost with comma-separated NIDs to verify LU-4460
1426         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
1427         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1428
1429         setupall
1430
1431         [[ "$MDS1_VERSION" -ge $(version_code 2.3.50) ]] ||
1432                 $LFS quotacheck -ug /mnt/$FSNAME
1433         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1434                 /mnt/$FSNAME
1435
1436         if [[ $MDSCOUNT -ge 2 ]]; then
1437                 remote_dir=/mnt/$FSNAME/remote_dir
1438                 $LFS mkdir -i 1 $remote_dir
1439                 tar cf - -C $tmp/src . | tar xf - -C $remote_dir
1440
1441                 target_dir=$remote_dir
1442                 if [[ $MDS1_VERSION -ge $(version_code 2.7.0) ]]; then
1443                         striped_dir=/mnt/$FSNAME/striped_dir_old
1444                         $LFS mkdir -i 1 -c 2 $striped_dir
1445                         tar cf - -C $tmp/src . | tar xf - -C $striped_dir
1446                 fi
1447         else
1448                 tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1449                 target_dir=/mnt/$FSNAME
1450         fi
1451
1452         # add project quota #
1453         [[ $mds1_FSTYPE == "ldiskfs" &&
1454                 $MDS1_VERSION -gt $(version_code 2.9.55) ]] ||
1455         [[ $mds1_FSTYPE == "zfs" &&
1456                 $MDS1_VERSION -gt $(version_code 2.10.53) ]] && {
1457                 pj_quota_dir=$target_dir/project_quota_dir
1458                 pj_quota_file_old=$pj_quota_dir/pj_quota_file_old
1459
1460                 enable_project_quota
1461                 set_mdt_qtype ugp ||
1462                         error "enable mdt quota failed"
1463
1464                 set_ost_qtype ugp ||
1465                         error "enable ost quota failed"
1466
1467                 mkdir -p $pj_quota_dir
1468                 $LFS setquota -p $T32_PRJID -b 0 -B $T32_PROLIMIT -i 0 \
1469                         -I $T32_ILIMIT $pj_quota_dir ||
1470                         error "setquota -p $T32_PRJID failed"
1471
1472                 $LFS setstripe $pj_quota_file_old -c 1 ||
1473                         error "setstripe $pj_quota_file_old failed"
1474
1475                 chown $T32_QID:$T32_QID $pj_quota_file_old ||
1476                         error "chown $pj_quota_file_old failed"
1477
1478                 change_project -p $T32_PRJID $pj_quota_file_old
1479
1480                 mkdir -p $tmp/src/project_quota_dir
1481                 cp $pj_quota_file_old $tmp/src/project_quota_dir/
1482         }
1483
1484         #####################
1485         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1486
1487         #if [[ $MDSCOUNT -ge 2 ]]; then
1488         #       remote_dir=/mnt/$FSNAME/remote_dir
1489         #       $LFS mkdir -i 1 $remote_dir
1490         #       tar cf - -C $tmp/src . | tar xf - -C $remote_dir
1491
1492         #       if [[ "$MDS1_VERSION" -ge $(version_code 2.7.0) ]]; then
1493         #               striped_dir=/mnt/$FSNAME/striped_dir_old
1494         #               $LFS mkdir -i 1 -c 2 $striped_dir
1495         #               tar cf - -C $tmp/src . | tar xf - -C $striped_dir
1496         #       fi
1497         #fi
1498
1499         # PFL file #
1500         if [[ $MDS1_VERSION -ge $(version_code 2.9.51) ]]; then
1501                 pfl_dir=$target_dir/pfl_dir
1502                 pfl_file=$pfl_dir/pfl_file
1503                 mkdir -p $pfl_dir
1504                 $LFS setstripe -E 2M -c 1 -o 0 -E -1 -S 2M -c 1 -o 1 \
1505                                         $pfl_file ||
1506                         error "Create PFL file failed"
1507
1508                 dd if=/dev/urandom of=$pfl_file bs=1k count=3k
1509                 mkdir -p $tmp/src/pfl_dir
1510                 cp $pfl_file $tmp/src/pfl_dir/
1511         fi
1512
1513         ############
1514         # DoM / FLR file #
1515         if [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]]; then
1516                 dom_dir=$target_dir/dom_dir
1517                 dom_file=$dom_dir/dom_file
1518                 flr_dir=$target_dir/flr_dir
1519                 flr_file=$flr_dir/flr_file
1520
1521                 mkdir -p $dom_dir
1522                 $LFS setstripe -E 1M -L mdt -E -1 -S 4M $dom_file
1523                 dd if=/dev/urandom of=$dom_file bs=1k count=2k
1524                 mkdir -p $tmp/src/dom_dir
1525                 cp $dom_file $tmp/src/dom_dir
1526         # FLR #
1527                 mkdir -p $flr_dir
1528                 $LFS mirror create -N2 $flr_file
1529                 dd if=/dev/urandom of=$flr_file bs=1k count=1
1530                 mkdir -p $tmp/src/flr_dir
1531                 cp $flr_file $tmp/src/flr_dir
1532         fi
1533         ############
1534
1535         local large_xattr_dir=/mnt/$FSNAME/large_xattr_test_dir
1536         local xattr_file=$large_xattr_dir/large_xattr_file
1537
1538         mkdir $large_xattr_dir
1539         touch $xattr_file
1540         setfattr -n user.fooattr -v $(printf "%c" {1..4096} ) $xattr_file ||
1541                 rm -f $xattr_file
1542
1543         stopall
1544
1545         mkdir $tmp/img || return 1
1546
1547         setupall
1548
1549         pushd_dir=/mnt/$FSNAME
1550         if [[ $MDSCOUNT -ge 2 ]]; then
1551                 pushd_dir=$remote_dir
1552                 if [[ "$MDS1_VERSION" -ge $(version_code 2.7.0) ]]; then
1553                         pushd $striped_dir
1554                         BLOCKSIZE=1024 ls -Rni --time-style=+%s >$tmp/img/list2
1555                         popd
1556                 fi
1557         fi
1558
1559         pushd $pushd_dir
1560         BLOCKSIZE=1024 ls -Rni --time-style=+%s >$tmp/img/list
1561         find ! -name .lustre -type f -exec sha1sum {} \; |
1562                 sort -k 2 >$tmp/img/sha1sums
1563         popd
1564         $LCTL get_param -n version | head -n 1 |
1565                 sed -e 's/^lustre: *//' >$tmp/img/commit
1566
1567         [[ "$MDS1_VERSION" -ge $(version_code 2.3.50) ]] ||
1568                 $LFS quotaon -ug /mnt/$FSNAME
1569         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1570         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1571                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1572                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1573                 | tr -d "*" > $tmp/img/bspace
1574         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1575                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1576                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1577                 | tr -d "*" > $tmp/img/ispace
1578         echo $T32_BLIMIT > $tmp/img/blimit
1579         echo $T32_ILIMIT > $tmp/img/ilimit
1580
1581         $MULTIOP /mnt/$FSNAME/orph_file Ouw_c&
1582         pid=$!
1583         sync
1584         stop_mdt_no_force 1
1585         debugfs -R "ls /PENDING" ${MDSDEV1:-$MDSDEV}
1586         cp ${MDSDEV1:-$MDSDEV} $tmp/img
1587         start_mdt 1
1588         kill -s USR1 $pid
1589         wait $pid
1590
1591         #################
1592         stopall
1593
1594         pushd $tmp/src
1595         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1596         popd
1597
1598         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1599                 echo "Data verification failed"
1600         fi
1601
1602         uname -r >$tmp/img/kernel
1603         uname -m >$tmp/img/arch
1604
1605         for ((num=1; num <= $MDSCOUNT; num++)); do
1606                 local devname=$(mdsdevname $num)
1607                 local facet=mds$num
1608                 local image_name
1609
1610                 [[ num -eq 1 ]] && image_name=mdt || image_name=mdt$num
1611                 [[ $(facet_fstype $facet) != zfs ]] ||
1612                         devname=$(mdsvdevname $num)
1613                 dd conv=sparse bs=4k if=$devname of=$tmp/img/$image_name
1614         done
1615
1616         for ((num=1; num <= $OSTCOUNT; num++)); do
1617                 local devname=$(ostdevname $num)
1618                 local facet=oss$num
1619                 local image_name
1620
1621                 [[ num -eq 1 ]] && image_name=ost || image_name=ost$num
1622                 [[ $(facet_fstype $facet) != zfs ]] ||
1623                         devname=$(ostdevname $num)
1624                 dd conv=sparse bs=4k if=$devname of=$tmp/img/$image_name
1625         done
1626
1627         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1628                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1629         dst=$(cd $dst; pwd)
1630         pushd $tmp/img
1631         tar cjvf $dst/disk$version-"$mds1_FSTYPE".tar.bz2 -S *
1632         popd
1633
1634         rm -r $tmp
1635 }
1636 # run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1637
1638 #
1639 # The list of applicable tarballs is returned via the caller's
1640 # variable "tarballs".
1641 #
1642 t32_check() {
1643         [ "$CLIENTONLY" ] && skip "Client-only testing"
1644
1645         check_versions || skip "do not upgrade with mismatched client/server"
1646
1647         local node=$(facet_active_host $SINGLEMDS)
1648         local r="do_node $node"
1649
1650         ! $r which "$TUNEFS" && skip_env "tunefs.lustre required on $node"
1651
1652         local IMGTYPE="$mds1_FSTYPE"
1653
1654         [[ -n "$T32IMAGE" ]] && tarballs=$T32IMAGE ||
1655                 tarballs=$($r find $RLUSTRE/tests -maxdepth 1 \
1656                            -name \'disk*-$IMGTYPE.tar.bz2\')
1657
1658         [ -z "$tarballs" ] && skip "No applicable tarballs found"
1659 }
1660
1661 t32_test_cleanup() {
1662         local tmp=$TMP/t32
1663         local facet=$SINGLEMDS
1664         local rc=$?
1665
1666         echo "== cleanup with rc=$rc =="
1667         if $shall_cleanup_lustre; then
1668                 umount $tmp/mnt/lustre || rc=$?
1669         fi
1670         if $shall_cleanup_mdt; then
1671                 $r $UMOUNT $tmp/mnt/mdt || rc=$?
1672         fi
1673         if $shall_cleanup_mdt1; then
1674                 $r $UMOUNT $tmp/mnt/mdt1 || rc=$?
1675         fi
1676         if $shall_cleanup_ost; then
1677                 $r $UMOUNT $tmp/mnt/ost || rc=$?
1678         fi
1679         if $shall_cleanup_ost1; then
1680                 $r $UMOUNT $tmp/mnt/ost1 || rc=$?
1681         fi
1682
1683         $r rm -rf $tmp
1684         rm -rf $tmp
1685         if [[ "$mds1_FSTYPE" == zfs ]]; then
1686                 local poolname
1687                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1688
1689                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1690
1691                 for poolname in $poolname_list; do
1692                         destroy_zpool $facet $poolname
1693                 done
1694         fi
1695         combined_mgs_mds || start_mgs || rc=$?
1696         return $rc
1697 }
1698
1699 t32_bits_per_long() {
1700         #
1701         # Yes, this is not meant to be perfect.
1702         #
1703         case $1 in
1704                 ppc64|x86_64)
1705                         echo -n 64;;
1706                 i*86)
1707                         echo -n 32;;
1708         esac
1709 }
1710
1711 t32_reload_modules() {
1712         local node=$1
1713         local all_removed=false
1714         local i=0
1715
1716         [ "$mds1_FSTYPE" == zfs ] && do_rpc_nodes $node "service zed stop"
1717
1718         while ((i < 20)); do
1719                 echo "Unloading modules on $node: Attempt $i"
1720                 do_rpc_nodes $node $LUSTRE_RMMOD "$mds1_FSTYPE" &&
1721                         all_removed=true
1722                 do_rpc_nodes $node check_mem_leak || return 1
1723                 if $all_removed; then
1724                         do_rpc_nodes $node load_modules
1725                         return 0
1726                 fi
1727                 if [ "$mds1_FSTYPE" == zfs ]; then
1728                         do_rpc_nodes $node "$ZPOOL status -v"
1729                 fi
1730                 sleep 5
1731                 i=$((i + 1))
1732         done
1733         echo "Unloading modules on $node: Given up"
1734         return 1
1735 }
1736
1737 t32_wait_til_devices_gone() {
1738         local node=$1
1739         local devices
1740         local loops
1741         local i=0
1742
1743         echo wait for devices to go
1744         while ((i < 20)); do
1745                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1746                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1747                 ((devices == 0 && loops == 0)) && return 0
1748                 sleep 5
1749                 i=$((i + 1))
1750         done
1751         echo "waiting for dev on $node: dev $devices loop $loops given up"
1752         do_rpc_nodes $node "losetup -a"
1753         do_rpc_nodes $node "$LCTL device_list"
1754         return 1
1755 }
1756
1757 t32_verify_quota() {
1758         local facet=$1
1759         local fsname=$2
1760         local mnt=$3
1761         local qval
1762         local cmd
1763
1764         # LU-2435: if the underlying zfs doesn't support userobj_accounting,
1765         # lustre will estimate the object count usage. This fails quota
1766         # verification in 32b. The object quota usage should be accurate after
1767         # zfs-0.7.0 is released.
1768         [ "$mds1_FSTYPE" == zfs ] && {
1769                 local zfs_version=$(do_facet $facet cat /sys/module/zfs/version)
1770
1771                 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] && {
1772                         echo "Skip quota verify for zfs: $zfs_version"
1773                         return 0
1774                 }
1775         }
1776
1777         $LFS quota -u $T32_QID -v $mnt
1778
1779         qval=$($LFS quota -v -u $T32_QID $mnt |
1780                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1781                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1782                 | tr -d "*")
1783         [ $qval -eq $img_bspace ] || {
1784                 echo "bspace, act:$qval, exp:$img_bspace"
1785                 return 1
1786         }
1787
1788         qval=$($LFS quota -v -u $T32_QID $mnt |
1789                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1790                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1791                 | tr -d "*")
1792         [ $qval -eq $img_ispace ] || {
1793                 echo "ispace, act:$qval, exp:$img_ispace"
1794                 return 1
1795         }
1796
1797         qval=$($LFS quota -v -u $T32_QID $mnt |
1798                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1799                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1800                 | tr -d "*")
1801         [ $qval -eq $img_blimit ] || {
1802                 echo "blimit, act:$qval, exp:$img_blimit"
1803                 return 1
1804         }
1805
1806         qval=$($LFS quota -v -u $T32_QID $mnt |
1807                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1808                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1809                 | tr -d "*")
1810         [ $qval -eq $img_ilimit ] || {
1811                 echo "ilimit, act:$qval, exp:$img_ilimit"
1812                 return 1
1813         }
1814
1815         set_persistent_param_and_check $facet \
1816                 "osd-$mds1_FSTYPE.$fsname-MDT0000.quota_slave.enabled" \
1817                 "$fsname.quota.mdt" ug
1818
1819         set_persistent_param_and_check $facet \
1820                 "osd-$mds1_FSTYPE.$fsname-OST0000.quota_slave.enabled" \
1821                 "$fsname.quota.ost" ug
1822
1823         chmod 0777 $mnt
1824         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1825                 bs=1M count=$((img_blimit / 1024)) oflag=sync && {
1826                 echo "Write succeed, but expect -EDQUOT"
1827                 return 1
1828         }
1829         rm -f $mnt/t32_qf_new
1830
1831         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1832                 $img_ilimit && {
1833                 echo "Create succeed, but expect -EDQUOT"
1834                 return 1
1835         }
1836         unlinkmany $mnt/t32_qf_ $img_ilimit
1837
1838         return 0
1839 }
1840
1841 getquota() {
1842         local spec=$4
1843         local uuid=$3
1844         local mnt=$5
1845
1846         sync_all_data > /dev/null 2>&1 || true
1847
1848         [ "$uuid" != "global" ] || uuid=$mnt
1849
1850         $LFS quota -v "$1" "$2" $mnt |
1851                 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
1852                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1853                 | tr -d "*"
1854 }
1855
1856 t32_test() {
1857         local tarball=$1
1858         local writeconf=$2
1859         local dne_upgrade=${dne_upgrade:-"no"}
1860         local dom_upgrade=${dom_upgrade:-"no"}
1861         local project_upgrade=${project_upgrade:-"no"}
1862         local ff_convert=${ff_convert:-"no"}
1863         local pfl_upgrade=${pfl_upgrade:-"no"}
1864         local project_quota_upgrade=${project_quota_upgrade:-"no"}
1865         local dom_new_upgrade=${dom_new_upgrade:-"no"}
1866         local flr_upgrade=${flr_upgrade:-"no"}
1867         local shall_cleanup_mdt=false
1868         local shall_cleanup_mdt1=false
1869         local shall_cleanup_ost=false
1870         local shall_cleanup_ost1=false
1871         local shall_cleanup_lustre=false
1872         local mdt2_is_available=false
1873         local ost2_is_available=false
1874         local node=$(facet_active_host $SINGLEMDS)
1875         local r="do_node $node"
1876         local tmp=$TMP/t32
1877         local img_commit
1878         local img_kernel
1879         local img_arch
1880         local img_bspace
1881         local img_ispace
1882         local img_blimit
1883         local img_ilimit
1884         local fsname=t32fs
1885         local nid
1886         local mopts
1887         local uuid
1888         local nrpcs_orig
1889         local nrpcs
1890         local list
1891         local mdt_dev=$tmp/mdt
1892         local mdt2_dev=$tmp/mdt2
1893         local ost_dev=$tmp/ost
1894         local ost2_dev=$tmp/ost2
1895         local stripe_index
1896         local stripe_count
1897         local dir
1898         local pfl_file=$tmp/mnt/lustre/remote_dir/pfl_dir/pfl_file
1899         local flr_file=$tmp/mnt/lustre/remote_dir/flr_dir/flr_file
1900         local dom_file=$tmp/mnt/lustre/remote_dir/dom_dir/dom_file
1901         local quota_dir=$tmp/mnt/lustre/remote_dir/project_quota_dir
1902
1903         combined_mgs_mds || stop_mgs || error "Unable to stop MGS"
1904         trap 'trap - RETURN; t32_test_cleanup' RETURN
1905
1906         load_modules
1907         nid=$($r $LCTL list_nids | head -1)
1908
1909         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
1910         $r mkdir -p $tmp/mnt/{mdt,mdt1,ost,ost1}
1911         $r tar xjvf $tarball -S -C $tmp || {
1912                 error_noexit "Unpacking the disk image tarball"
1913                 return 1
1914         }
1915         img_commit=$($r cat $tmp/commit)
1916         img_kernel=$($r cat $tmp/kernel)
1917         img_arch=$($r cat $tmp/arch)
1918         img_bspace=$($r cat $tmp/bspace)
1919         img_ispace=$($r cat $tmp/ispace)
1920
1921         # older images did not have "blimit" and "ilimit" files
1922         # use old values for T32_BLIMIT and T32_ILIMIT
1923         $r test -f $tmp/blimit && img_blimit=$($r cat $tmp/blimit) ||
1924                 img_blimit=20480
1925         $r test -f $tmp/ilimit && img_ilimit=$($r cat $tmp/ilimit) ||
1926                 img_ilimit=2
1927
1928         echo "Upgrading from $(basename $tarball), created with:"
1929         echo "  Commit: $img_commit"
1930         echo "  Kernel: $img_kernel"
1931         echo "    Arch: $img_arch"
1932         echo "OST version: $(lustre_build_version ost1)"
1933
1934         # The conversion can be made only when both of the following
1935         # conditions are satisfied:
1936         # - ost device img version < 2.3.64
1937         # - ost server version >= 2.5
1938         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1939                 "$OST1_VERSION" -lt $(version_code 2.5.0) ] &&
1940                         ff_convert="no"
1941
1942         ! $r test -f $mdt2_dev || mdt2_is_available=true
1943         ! $r test -f $ost2_dev || ost2_is_available=true
1944
1945         if [[ "$mds1_FSTYPE" == zfs ]]; then
1946                 echo "== fstype is zfs =="
1947                 # import pool first
1948                 local poolname
1949                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1950
1951                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1952
1953                 for poolname in $poolname_list; do
1954                         $r "modprobe zfs;
1955                                 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1956                                 $ZPOOL import -f -d $tmp $poolname"
1957                 done
1958
1959                 # upgrade zpool to latest supported features, including
1960                 # dnode quota accounting in 0.7.0
1961                 $r "$ZPOOL upgrade -a"
1962
1963                 mdt_dev=t32fs-mdt1/mdt1
1964                 ost_dev=t32fs-ost1/ost1
1965                 ! $mdt2_is_available || mdt2_dev=t32fs-mdt2/mdt2
1966                 ! $ost2_is_available || ost2_dev=t32fs-ost2/ost2
1967                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1968                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1969                                 error_noexit "import zfs pool failed"
1970                                 return 1
1971                         }
1972         elif [ "$project_upgrade" != "no" ]; then
1973                 echo "== project upgrade =="
1974                 ! $r tune2fs -O project $mdt_dev &&
1975                         error_noexit "enable project on mdt0 failed" &&
1976                                 return 1
1977                 $mdt2_is_available && ! $r tune2fs "-O project" $mdt2_dev &&
1978                         error_noexit "enable project on mdt failed" &&
1979                                 return 1
1980                 ! $r tune2fs -O project $ost_dev &&
1981                         error_noexit "enable project on ost failed" &&
1982                                 return 1
1983                 $ost2_is_available && ! $r tune2fs -O project $ost2_dev &&
1984                         error_noexit "enable project on ost2 failed" &&
1985                                 return 1
1986         fi
1987
1988         $r $LCTL set_param debug="$PTLDEBUG"
1989
1990         $r $TUNEFS --dryrun $mdt_dev || {
1991                 $r losetup -a
1992                 error_noexit "tunefs.lustre before mounting the MDT"
1993                 return 1
1994         }
1995
1996         if $mdt2_is_available; then
1997                 $r $TUNEFS --dryrun $mdt2_dev || {
1998                         $r losetup -a
1999                         error_noexit "tunefs.lustre before mounting the MDT"
2000                         return 1
2001                 }
2002         fi
2003
2004         if [ "$writeconf" ]; then
2005                 echo "== writeconf mdt tunefs and quota =="
2006                 mopts=writeconf
2007                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2008                         mopts="loop,$mopts"
2009                         $r $TUNEFS --quota $mdt_dev || {
2010                                 $r losetup -a
2011                                 error_noexit "Enable mdt quota feature"
2012                                 return 1
2013                         }
2014
2015                         if [ "$project_quota_upgrade" != "no" ]; then
2016                                 echo "== enable mdt2 project quota =="
2017                                 $r $TUNE2FS -O project $mdt_dev || {
2018                                         $r losetup -a
2019                                         error_noexit "tune2fs $mdt_dev failed"
2020                                         return 1
2021                                 }
2022                         fi
2023
2024                         if $mdt2_is_available; then
2025                                 $r $TUNEFS --quota $mdt2_dev || {
2026                                         $r losetup -a
2027                                         error_noexit "Enable mdt2 quota feature"
2028                                         return 1
2029                                 }
2030                                 if [ "$project_quota_upgrade" != "no" ]; then
2031                                         echo "== enable mdt2 project quota =="
2032                                         $r $TUNE2FS -O project $mdt2_dev || {
2033                                                 $r losetup -a
2034                                                 error_noexit \
2035                                                     "tune2fs $mdt2_dev failed"
2036                                                 return 1
2037                                         }
2038                                 fi
2039                         fi
2040                 fi
2041         else
2042                 echo "== replace nids =="
2043                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
2044                         [[ "$MGS_VERSION" -ge $(version_code 2.3.59) ]] ||
2045                         skip "LU-2200: Cannot run over IB w/o lctl replace_nids "
2046                                 "(Need MGS version at least 2.3.59)"
2047                 fi
2048
2049                 local osthost=$(facet_active_host ost1)
2050                 local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
2051
2052                 mopts=nosvc
2053                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2054                         mopts="loop,$mopts"
2055                 fi
2056                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
2057                 $r $LCTL replace_nids $fsname-OST0000 $ostnid || {
2058                         $r $LCTL dl
2059                         error_noexit "replace_nids $fsname-OST0000 $ostnid failed"
2060                         return 1
2061                 }
2062                 if $ost2_is_available; then
2063                         $r $LCTL replace_nids $fsname-OST0001 $ostnid || {
2064                                 $r $LCTL dl
2065                                 error_noexit "replace_nids $fsname-OST0001 $ostnid failed"
2066                                 return 1
2067                         }
2068                 fi
2069                 $r $LCTL replace_nids $fsname-MDT0000 $nid || {
2070                         $r $LCTL dl
2071                         error_noexit "replace_nids $fsname-MDT0000 $nid failed"
2072                         return 1
2073                 }
2074                 if $mdt2_is_available; then
2075                         $r $LCTL replace_nids $fsname-MDT0001 $nid || {
2076                                 $r $LCTL dl
2077                                 error_noexit "replace_nids $fsname-MDT0001 $nid failed"
2078                                 return 1
2079                         }
2080                 fi
2081                 $r $UMOUNT $tmp/mnt/mdt
2082
2083                 mopts=exclude=$fsname-OST0000
2084                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2085                         mopts="loop,$mopts"
2086                 fi
2087         fi
2088
2089         t32_wait_til_devices_gone $node
2090
2091         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2092                 $r losetup -a
2093                 error_noexit "Mounting the MDT"
2094                 return 1
2095         }
2096         shall_cleanup_mdt=true
2097
2098         if $mdt2_is_available; then
2099                 echo "== mdt2 available =="
2100                 mopts=mgsnode=$nid,$mopts
2101                 $r $MOUNT_CMD -o $mopts $mdt2_dev $tmp/mnt/mdt1 || {
2102                         $r losetup -a
2103                         error_noexit "Mounting the MDT"
2104                         return 1
2105                 }
2106                 shall_cleanup_mdt1=true
2107                 echo "== mount new MDT $mdt2_dev =="
2108
2109                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 || {
2110                         error_noexit "enable remote dir create failed"
2111                         return 1
2112                 }
2113
2114         elif [ "$dne_upgrade" != "no" ]; then
2115                 local fs2mdsdev=$(mdsdevname 1_2)
2116                 local fs2mdsvdev=$(mdsvdevname 1_2)
2117
2118                 echo "== mkfs new MDT on ${fs2mdsdev} =="
2119                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2120                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
2121                 fi
2122
2123                 add $SINGLEMDS $(mds2failover_HOST="" \
2124                         mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
2125                         $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
2126                         error_noexit "Mkfs new MDT failed"
2127                         return 1
2128                 }
2129
2130                 [[ "$mds1_FSTYPE" != zfs ]] || import_zpool mds1
2131
2132                 $r $TUNEFS --dryrun $fs2mdsdev || {
2133                         error_noexit "tunefs.lustre before mounting the MDT"
2134                         return 1
2135                 }
2136
2137                 echo "== mount new MDT....$fs2mdsdev =="
2138                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
2139                         error_noexit "mount mdt1 failed"
2140                         return 1
2141                 }
2142
2143                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
2144                         error_noexit "enable remote dir create failed"
2145
2146                 shall_cleanup_mdt1=true
2147         fi
2148
2149         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
2150                 error_noexit "Getting MDT UUID"
2151                 return 1
2152         }
2153         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
2154                 error_noexit "Unexpected MDT UUID: \"$uuid\""
2155                 return 1
2156         fi
2157
2158         $r $TUNEFS --dryrun $ost_dev || {
2159                 error_noexit "tunefs.lustre before mounting the OST"
2160                 return 1
2161         }
2162
2163         if $ost2_is_available; then
2164                 $r $TUNEFS --dryrun $ost2_dev || {
2165                         error_noexit "tunefs.lustre before mounting the OST"
2166                         return 1
2167                 }
2168         fi
2169
2170         if [ "$writeconf" ]; then
2171                 echo "== writeconf and ost quota tunefs =="
2172                 mopts=mgsnode=$nid,$writeconf
2173                 if [ "$ost1_FSTYPE" == ldiskfs ]; then
2174                         mopts="loop,$mopts"
2175                         $r $TUNEFS --quota $ost_dev || {
2176                                 $r losetup -a
2177                                 error_noexit "Enable ost quota feature"
2178                                 return 1
2179                         }
2180
2181                         if [ "$project_quota_upgrade" != "no" ]; then
2182                                 echo "== enable ost project quota =="
2183                                 $r $TUNE2FS -O project $ost_dev || {
2184                                         $r losetup -a
2185                                         error_noexit "tune2fs $ost_dev failed"
2186                                         return 1
2187                                 }
2188                         fi
2189
2190                         if $ost2_is_available; then
2191                                 $r $TUNEFS --quota $ost2_dev || {
2192                                         $r losetup -a
2193                                         error_noexit "Enable ost2 quota feature"
2194                                         return 1
2195                                 }
2196                                 if [ "$project_quota_upgrade" != "no" ]; then
2197                                         echo "== enable ost2 project quota =="
2198                                         $r $TUNE2FS -O project $ost2_dev || {
2199                                                 $r losetup -a
2200                                                 error_noexit \
2201                                                 "tune2fs $ost2_dev failed"
2202                                                 return 1
2203                                         }
2204                                 fi
2205                         fi
2206                 fi
2207         else
2208                 mopts=mgsnode=$nid
2209                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2210                         mopts="loop,$mopts"
2211                 fi
2212         fi
2213
2214         $r $MOUNT_CMD -onomgs -o$mopts $ost_dev $tmp/mnt/ost || {
2215                 error_noexit "Mounting the OST"
2216                 return 1
2217         }
2218
2219         if $ost2_is_available; then
2220                 $r $MOUNT_CMD -onomgs -o$mopts $ost2_dev $tmp/mnt/ost1 || {
2221                         error_noexit "Mounting the OST2"
2222                         return 1
2223                 }
2224                 shall_cleanup_ost1=true
2225         fi
2226
2227         shall_cleanup_ost=true
2228
2229         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
2230                 error_noexit "Getting OST UUID"
2231                 return 1
2232         }
2233         if [ "$uuid" != $fsname-OST0000_UUID ]; then
2234                 error_noexit "Unexpected OST UUID: \"$uuid\""
2235                 return 1
2236         fi
2237
2238         if $ost2_is_available; then
2239                 uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0001.uuid) ||{
2240                         error_noexit "Getting OST1 UUID"
2241                         return 1
2242                 }
2243                 if [ "$uuid" != $fsname-OST0001_UUID ]; then
2244                         error_noexit "Unexpected OST1 UUID: \"$uuid\""
2245                         return 1
2246                 fi
2247         fi
2248
2249         if [[ $PERM_CMD =~ "set_param" ]]; then
2250                 echo "== perm cmd = '$PERM_CMD' =="
2251                 $r $PERM_CMD osc.$fsname-OST0000*.import=connection=$nid || {
2252                         error_noexit "Setting OST \"failover.node\""
2253                         return 1
2254                 }
2255                 $r $PERM_CMD mdc.$fsname-MDT0000*.import=connection=$nid || {
2256                         error_noexit "Setting MDT \"failover.node\""
2257                         return 1
2258                 }
2259                 $r $PERM_CMD osc.$fsname-OST0000-*.max_dirty_mb=15 || {
2260                         error_noexit "Setting \"max_dirty_mb\""
2261                         return 1
2262                 }
2263                 $r $PERM_CMD mdc.$fsname-MDT0000-*.max_rpcs_in_flight=9 || {
2264                         error_noexit "Setting \"max_rpcs_in_flight\""
2265                         return 1
2266                 }
2267                 $r $PERM_CMD lov.$fsname-MDT0000-*.stripesize=4M || {
2268                         error_noexit "Setting \"lov.stripesize\""
2269                         return 1
2270                 }
2271                 $r $PERM_CMD mdd.$fsname-MDT0000-*.atime_diff=70 || {
2272                         error_noexit "Setting \"mdd.atime_diff\""
2273                         return 1
2274                 }
2275         else
2276                 echo "== perm cmd = '$PERM_CMD' =="
2277                 $r $PERM_CMD $fsname-OST0000.failover.node=$nid || {
2278                         error_noexit "Setting OST \"failover.node\""
2279                         return 1
2280                 }
2281
2282                 $r $PERM_CMD $fsname-MDT0000.failover.node=$nid || {
2283                         error_noexit "Setting MDT \"failover.node\""
2284                         return 1
2285                 }
2286
2287                 $r $PERM_CMD $fsname-OST0000.osc.max_dirty_mb=15 || {
2288                         error_noexit "Setting \"max_dirty_mb\""
2289                         return 1
2290                 }
2291                 $r $PERM_CMD $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
2292                         error_noexit "Setting \"max_rpcs_in_flight\""
2293                         return 1
2294                 }
2295                 $r $PERM_CMD $fsname-MDT0000.lov.stripesize=4M || {
2296                         error_noexit "Setting \"lov.stripesize\""
2297                         return 1
2298                 }
2299                 $r $PERM_CMD $fsname-MDT0000.mdd.atime_diff=70 || {
2300                         error_noexit "Setting \"mdd.atime_diff\""
2301                         return 1
2302                 }
2303         fi
2304
2305         $r $LCTL pool_new $fsname.interop || {
2306                 error_noexit "Setting \"interop\""
2307                 return 1
2308         }
2309
2310         if [ "$ff_convert" != "no" -a "$ost1_FSTYPE" == ldiskfs ]; then
2311                 echo "== ff convert ($ff_convert) =="
2312                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
2313                         error_noexit "Start OI scrub on OST0"
2314                         return 1
2315                 }
2316
2317                 # The oi_scrub should be on ost1, but for test_32(),
2318                 # all on the SINGLEMDS.
2319                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
2320                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
2321                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
2322                         error_noexit "Failed to get the expected 'completed'"
2323                         return 1
2324                 }
2325
2326                 local UPDATED=$($r $LCTL get_param -n \
2327                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
2328                                 awk '/^updated/ { print $2 }')
2329                 [ $UPDATED -ge 1 ] || {
2330                         error_noexit "Only $UPDATED objects have been converted"
2331                         return 1
2332                 }
2333         fi
2334
2335         if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
2336                 echo "== dne upgrate ($dne_upgrade) or mdt2 available =="
2337                 if [[ $PERM_CMD =~ "set_param" ]]; then
2338                         $r $PERM_CMD mdc.$fsname-MDT0001*.import=connection=$nid || {
2339                                 error_noexit "Setting MDT1 \"failover.node\""
2340                                 return 1
2341                         }
2342
2343                         $r $PERM_CMD mdc.$fsname-MDT0001-*.max_rpcs_in_flight=9 || {
2344                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2345                                 return 1
2346                         }
2347                         $r $PERM_CMD lov.$fsname-MDT0001-*.stripesize=4M || {
2348                                 error_noexit "Setting MDT1 \"lov.stripesize\""
2349                                 return 1
2350                         }
2351                 else
2352                         $r $PERM_CMD $fsname-MDT0001.failover.node=$nid || {
2353                                 error_noexit "Setting MDT1 \"failover.node\""
2354                                 return 1
2355                         }
2356                         $r $PERM_CMD $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
2357                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2358                                 return 1
2359                         }
2360                         $r $PERM_CMD $fsname-MDT0001.lov.stripesize=4M || {
2361                                 error_noexit "Setting MDT1 \"lov.stripesize\""
2362                                 return 1
2363                         }
2364                 fi
2365         fi
2366
2367         if [ "$writeconf" ]; then
2368                 echo "== writeconf and client mount =="
2369                 $MOUNT_CMD $nid:/$fsname -o user_xattr $tmp/mnt/lustre || {
2370                         error_noexit "Mounting the client"
2371                         return 1
2372                 }
2373
2374                 shall_cleanup_lustre=true
2375                 $r $LCTL set_param debug="$PTLDEBUG"
2376
2377                 t32_verify_quota $SINGLEMDS $fsname $tmp/mnt/lustre || {
2378                         error_noexit "verify quota failed"
2379                         return 1
2380                 }
2381
2382                 if $r test -f $tmp/list; then
2383                         echo "== list verification =="
2384                         #
2385                         # There is not a Test Framework API to copy files to or
2386                         # from a remote node.
2387                         #
2388                         # LU-2393 - do both sorts on same node to ensure locale
2389                         # is identical
2390                         local list_file=$tmp/list
2391
2392                         if $mdt2_is_available; then
2393                                 if [[ -d $tmp/mnt/lustre/striped_dir_old ]] &&
2394                                    $r test -f $tmp/list2; then
2395                                         list_file=$tmp/list2
2396                                         pushd $tmp/mnt/lustre/striped_dir_old
2397                                 else
2398                                         pushd $tmp/mnt/lustre/remote_dir
2399                                 fi
2400                         else
2401                                 pushd $tmp/mnt/lustre
2402                         fi
2403                         $r cat $list_file | sort -k 6 >$tmp/list.orig
2404                         BLOCKSIZE=1024 ls -Rni --time-style=+%s | sort -k 6 |
2405                                 sed 's/\. / /' >$tmp/list || {
2406                                 error_noexit "ls"
2407                                 return 1
2408                         }
2409                         popd
2410                         #
2411                         # 32-bit and 64-bit clients use different algorithms to
2412                         # convert FIDs into inode numbers.  Hence, remove the
2413                         # inode numbers from the lists, if the original list was
2414                         # created on an architecture with different number of
2415                         # bits per "long".
2416                         #
2417                         if [ $(t32_bits_per_long $(uname -m)) != \
2418                                 $(t32_bits_per_long $img_arch) ]; then
2419                                 echo "Different number of bits per \"long\"" \
2420                                      "from the disk image"
2421                                 for list in list.orig list; do
2422                                         sed -i -e 's/^[0-9]\+[ \t]\+//' \
2423                                                   $tmp/$list
2424                                 done
2425                         fi
2426                         if ! diff -ub $tmp/list.orig $tmp/list; then
2427                                 error_noexit "list verification failed"
2428                                 return 1
2429                         fi
2430                 else
2431                         echo "== list verification skipped =="
2432                 fi
2433
2434                 #non-dom upgrade to dom
2435                 if [ "$dom_upgrade" != "no" ]; then
2436                         echo "== dom upgrade =="
2437                         $LFS setstripe -E 1M -L mdt -E EOF $tmp/mnt/lustre/dom || {
2438                                 error_noexit "Verify DoM creation"
2439                                 return 1
2440                         }
2441                         [ $($LFS getstripe -L $tmp/mnt/lustre/dom) == "mdt" ] || {
2442                                 error_noexit "Verify a DoM file"
2443                                 return 1
2444                         }
2445                         dd if=/dev/urandom of=$tmp/mnt/lustre/dom bs=4096 \
2446                                 count=1 conv=fsync || {
2447                                 error_noexit "Cannot write to DoM file"
2448                                 return 1
2449                         }
2450                         [ $(stat -c%s $tmp/mnt/lustre/dom) == 4096 ] || {
2451                                 error_noexit "DoM: bad size after write"
2452                                 return 1
2453                         }
2454                         rm $tmp/mnt/lustre/dom
2455
2456                         set_persistent_param_and_check mds \
2457                            "lod.*MDT0000*.dom_stripesize" \
2458                            "$fsname-MDT0000.lod.dom_stripesize" 0 || {
2459                                 error_noexit "Changing \"dom_stripesize\""
2460                                 return 1
2461                         }
2462                 fi
2463
2464                 #dom upgrade
2465                 #$LFS setstripe -E 1M -L mdt -E -1 -S 4M $dom_file
2466                 if [ "$dom_new_upgrade" != "no" ]; then
2467                         if ! $mdt2_is_available; then
2468                                 dom_file=$tmp/mnt/lustre/dom_dir/dom_file
2469                         fi
2470                         echo "== check DoM file can be accessed =="
2471                         [ $($LFS getstripe -I1 -L $dom_file) == "mdt" ] || {
2472                                 error_noexit "Verify a DoM file"
2473                                 return 1
2474                         }
2475                         [ $(stat -c%s $dom_file) == $((2 * 1024 * 1024)) ] || {
2476                                 error_noexit "DoM: bad size after write"
2477                                 return 1
2478                         }
2479                 fi
2480
2481                 if [ "$flr_upgrade" != "no" ]; then
2482                         if ! $mdt2_is_available; then
2483                                 flr_file=$tmp/mnt/lustre/flr_dir/flr_file
2484                         fi
2485                         local mirror_count=$($LFS getstripe -N $flr_file)
2486                         echo "== check FLR file =="
2487                         [ $mirror_count == 2 ] || {
2488                                 error_noexit "FLR mirror count wrong"
2489                                 return 1
2490                         }
2491                 fi
2492
2493                 if [ "$dne_upgrade" != "no" ]; then
2494                         echo "== dne upgrade striped_dir  =="
2495                         $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/striped_dir || {
2496                                 error_noexit "set striped dir failed"
2497                                 return 1
2498                         }
2499                         $LFS setdirstripe -D -c2 $tmp/mnt/lustre/striped_dir
2500
2501                         pushd $tmp/mnt/lustre
2502                         tar -c --exclude=./striped_dir \
2503                                 --exclude=./striped_dir_old \
2504                                 --exclude=./remote_dir -f - .|
2505                                 tar -xvf - -C striped_dir 1>/dev/null || {
2506                                 error_noexit "cp to striped dir failed"
2507                                 return 1
2508                         }
2509                         popd
2510                 fi
2511
2512                 if [ "$pfl_upgrade" != "no" ]; then
2513                         local comp_size
2514                         local comp_cnt
2515                         local stripe_size
2516                         local stripe_cnt
2517                         local comp_id
2518
2519                         echo "== check PFL file =="
2520                         if ! $mdt2_is_available; then
2521                                 pfl_file=$tmp/mnt/lustre/pfl_dir/pfl_file
2522                         fi
2523                         comp_cnt=$($LFS getstripe --component-count $pfl_file)
2524                         [ $comp_cnt == 2 ] || {
2525                                 error_noexit "wrong comp_cnt $comp_cnt"
2526                                 return 1
2527                         }
2528
2529                         comp_size=$($LFS getstripe -I1 -E $pfl_file)
2530                         [ $comp_size == 2097152 ] || {
2531                                 error_noexit "wrong component size $comp_size"
2532                                 return 1
2533                         }
2534
2535                         comp_id=$($LFS getstripe -I1 -i $pfl_file)
2536                         [ $comp_id == 0 ] || {
2537                                 error_noexit "wrong comp id $comp_id"
2538                                 return 1
2539                         }
2540
2541                         comp_id=$($LFS getstripe -I2 -i $pfl_file)
2542                         [ $comp_id -eq 1 ] || {
2543                                 error_noexit "wrong comp id $comp_id"
2544                                 return 1
2545                         }
2546
2547                         stripe_size=$($LFS getstripe -I1 -S $pfl_file)
2548                         [ $stripe_size -eq 1048576 ] || {
2549                                 error_noexit "wrong stripe size $stripe_size"
2550                                 return 1
2551                         }
2552
2553                         stripe_size=$($LFS getstripe -I2 -S $pfl_file)
2554                         [ $comp_size -eq 2097152 ] || {
2555                                 error_noexit "wrong component size $comp_size"
2556                                 return 1
2557                         }
2558                 fi
2559
2560                 local large_xattr_dir=$tmp/mnt/lustre/large_xattr_test_dir
2561
2562                 if [[ -d $large_xattr_dir ]]; then
2563                         echo "== check Large EA =="
2564                         local xattr_file=$large_xattr_dir/large_xattr_file
2565
2566                         xattr_val=$(getfattr --only-values\
2567                                 -n user.fooattr $xattr_file) || {
2568                                 error_noexit "Large EA cannot be read"
2569                                 return 1
2570                         }
2571
2572                         [[ $xattr_val == $(printf "%c" {1..4096}) ]] || {
2573                                 error_noexit "Wrong large EA value"
2574                                 return 1;
2575                         }
2576                 fi
2577
2578                 if [ "$project_quota_upgrade" != "no" ]; then
2579                         if ! $mdt2_is_available; then
2580                                 quota_dir=$tmp/mnt/lustre/project_quota_dir
2581                         fi
2582                         local hardlimit
2583
2584                         echo "== check Project Quota =="
2585                         hardlimit=$(getquota -p $T32_PRJID global 3 \
2586                                                         ${tmp}/mnt/lustre)
2587                         [ $hardlimit == $T32_PROLIMIT ] || {
2588                                 error_noexit "wrong hardlimit $hardlimit"
2589                                 return 1
2590                         }
2591                 fi
2592
2593                 # If it is upgrade from DNE (2.5), then rename the remote dir,
2594                 # which is created in 2.5 to striped dir.
2595                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]]; then
2596                         echo "== rename remote_dir =="
2597                         stripe_index=$($LFS getdirstripe -i     \
2598                                        $tmp/mnt/lustre/remote_dir)
2599
2600                         [[ $stripe_index -eq 1 ]] || {
2601                                 error_noexit "get index \"$stripe_index\"" \
2602                                              "from remote dir failed"
2603                                 return 1
2604                         }
2605                         mv $tmp/mnt/lustre/remote_dir   \
2606                                 $tmp/mnt/lustre/striped_dir/ || {
2607                                 error_noexit "mv remote dir failed"
2608                                 return 1
2609                         }
2610                 fi
2611
2612                 # If it is upgraded from DNE (2.7), then move the striped dir
2613                 # which was created in 2.7 to the new striped dir.
2614                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]] &&
2615                         echo "== rename striped dir =="
2616                         [[ -d $tmp/mnt/lustre/striped_dir_old ]]; then
2617                         stripe_count=$($LFS getdirstripe -c     \
2618                                        $tmp/mnt/lustre/striped_dir_old)
2619                         [[ $stripe_count -eq 2 ]] || {
2620                                 error_noexit "get count $stripe_count" \
2621                                              "from striped dir failed"
2622                                 return 1
2623                         }
2624                         mv $tmp/mnt/lustre/striped_dir_old      \
2625                                 $tmp/mnt/lustre/striped_dir/ || {
2626                                 error_noexit "mv striped dir failed"
2627                                 return 1
2628                         }
2629                 fi
2630
2631                 sync; sleep 5; sync
2632                 $r $LCTL set_param -n osd*.*.force_sync=1
2633                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
2634                         error_noexit "dd failed"
2635                         return 1
2636                 }
2637                 rm -rf $tmp/mnt/lustre/tmp_file || {
2638                         error_noexit "rm failed"
2639                         return 1
2640                 }
2641
2642                 if $r test -f $tmp/sha1sums; then
2643                         echo "== checking sha1sums =="
2644                         # LU-2393 - do both sorts on same node to ensure locale
2645                         # is identical
2646                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
2647                         if [[ "$dne_upgrade" != "no" ]]; then
2648                                 if [[ -d $tmp/mnt/lustre/striped_dir/remote_dir ]]; then
2649                                         pushd $tmp/mnt/lustre/striped_dir/remote_dir
2650                                 else
2651                                         pushd $tmp/mnt/lustre/striped_dir
2652                                 fi
2653                         elif [[ "$pfl_upgrade" != "no" ]] ||
2654                                 [[ "$flr_upgrade" != "no" ]] ||
2655                                 [[ "$dom_new_upgrade" != "no" ]] ||
2656                                 [[ "$project_quota_upgrade" != "no" ]] ||
2657                                 [[ -d $tmp/mnt/lustre/remote_dir ]]; then
2658                                 pushd $tmp/mnt/lustre/remote_dir
2659                         else
2660                                 pushd $tmp/mnt/lustre
2661                         fi
2662
2663                         find ! -path "*remote_dir*" ! -path "*striped_dir*" \
2664                              ! -name .lustre -type f -exec sha1sum {} \; |
2665                                 sort -k 2 >$tmp/sha1sums || {
2666                                 popd
2667                                 error_noexit "sha1sum"
2668                                 return 1
2669                         }
2670                         local save=$PWD
2671
2672                         popd
2673                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
2674                                 echo "==** find $save files start **=="
2675                                 find $save -type f -ls
2676                                 echo "==** find $save files finish **=="
2677                                 error_noexit "sha1sum verification failed"
2678                                 return 1
2679                         fi
2680
2681                         # if upgrade from DNE(2.5), then check remote directory
2682                         # if upgrade from DNE(2.7), then check striped directory
2683                         if $mdt2_is_available &&
2684                            [[ "$dne_upgrade" != "no" ]]; then
2685                                 echo "== mdt2 upgrade sha1sum check =="
2686                                 local new_dir="$tmp/mnt/lustre/striped_dir"
2687                                 local striped_dir_old="$new_dir/striped_dir_old"
2688
2689                                 local dir_list="$new_dir/remote_dir"
2690                                 [[ ! -d $triped_dir_old ]] ||
2691                                         dir_list+=" $striped_dir_old"
2692
2693                                 for dir in $dir_list; do
2694                                         echo "== dir = $dir =="
2695                                         pushd $dir
2696                                         find ! -name .lustre -type f \
2697                                                 -exec sha1sum {} \; |
2698                                                 sort -k 2 >$tmp/sha1sums || {
2699                                                         ls -alR
2700                                                         popd
2701                                                         error_noexit "sha1sum"
2702                                                         return 1
2703                                                 }
2704                                         popd
2705                                         if ! diff -ub $tmp/sha1sums.orig \
2706                                                 $tmp/sha1sums; then
2707                                                 ls -alR $dir
2708                                                 error_noexit "sha1sum $dir" \
2709                                                              "failed"
2710                                                 return 1
2711                                         fi
2712                                 done
2713                         fi
2714                 else
2715                         echo "== sha1sum verification skipped =="
2716                 fi
2717
2718                 # PFL write test after sha1sum check
2719                 if [ "$pfl_upgrade" != "no" ]; then
2720                         local rw_len=$((3 * 1034 * 1024))
2721
2722                         if ! $mdt2_is_available; then
2723                                 pfl_file=$tmp/mnt/lustre/pfl_dir/pfl_file
2724                         fi
2725                         small_write $pfl_file $rw_len || {
2726                                 error_noexit "PFL RW Failed"
2727                                 return 1
2728                         }
2729                 fi
2730
2731                 if [ "$dne_upgrade" != "no" ]; then
2732                         rm -rf $tmp/mnt/lustre/striped_dir || {
2733                                 error_noexit "remove remote dir failed"
2734                                 return 1
2735                         }
2736                 fi
2737
2738                 # migrate files/dirs to remote MDT, then move them back
2739                 if [ "$MDS1_VERSION" -ge $(version_code 2.7.50) -a \
2740                      $dne_upgrade != "no" ]; then
2741                         $r $LCTL set_param -n   \
2742                                 mdt.${fsname}*.enable_remote_dir=1 2>/dev/null
2743
2744                         echo "== test migration =="
2745                         pushd $tmp/mnt/lustre
2746                         for dir in $(find ! -name .lustre ! -name . -type d); do
2747                                 mdt_index=$($LFS getdirstripe -i $dir)
2748                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2749                                 if [ $mdt_index = 0 -a $stripe_cnt -le 1 ]; then
2750                                         $LFS migrate -m 1 $dir || {
2751                                         popd
2752                                         error_noexit "migrate MDT1 failed"
2753                                         return 1
2754                                 }
2755                                 fi
2756                         done
2757
2758                         for dir in $(find ! -name . ! -name .lustre -type d); do
2759                                 mdt_index=$($LFS getdirstripe -i $dir)
2760                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2761                                 if [ $mdt_index = 1 -a $stripe_cnt -le 1 ]; then
2762                                         $LFS migrate -m 0 $dir || {
2763                                         popd
2764                                         error_noexit "migrate MDT0 failed"
2765                                         return 1
2766                                 }
2767                                 fi
2768                         done
2769                         popd
2770                 fi
2771
2772                 #
2773                 # When adding new data verification tests, please check for
2774                 # the presence of the required reference files first, like
2775                 # the "sha1sums" and "list" tests above, to avoid the need to
2776                 # regenerate every image for each test addition.
2777                 #
2778
2779                 nrpcs_orig=$($LCTL get_param \
2780                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
2781                         error_noexit "Getting \"max_rpcs_in_flight\""
2782                         return 1
2783                 }
2784                 nrpcs=$((nrpcs_orig + 5))
2785
2786                 set_persistent_param_and_check client \
2787                    "mdc.$fsname-MDT0000*.max_rpcs_in_flight" \
2788                    "$fsname-MDT0000.mdc.max_rpcs_in_flight" $nrpcs || {
2789                         error_noexit "Changing \"max_rpcs_in_flight\""
2790                         return 1
2791                 }
2792
2793                 umount $tmp/mnt/lustre || {
2794                         error_noexit "Unmounting the client"
2795                         return 1
2796                 }
2797                 shall_cleanup_lustre=false
2798         else
2799                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
2800                         error_noexit "Mounting the client"
2801                         return 1
2802                 }
2803
2804                 if [ "$mds1_FSTYPE" == ldiskfs -a \
2805                     "$project_upgrade" != "no" ]; then
2806                         ! $LFS project -d -p 1 $tmp/mnt/lustre/* &&
2807                                 error_noexit "set project failed" &&
2808                                         return 1
2809                 fi
2810
2811                 [[ $(do_facet mds1 pgrep orph_.*-MDD | wc -l) == 0 ]] ||
2812                         error "MDD orphan cleanup thread not quit"
2813
2814                 umount $tmp/mnt/lustre || {
2815                         error_noexit "Unmounting the client"
2816                         return 1
2817                 }
2818
2819                 if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
2820                         $r $UMOUNT $tmp/mnt/mdt1 || {
2821                                 error_noexit "Unmounting the MDT2"
2822                                 return 1
2823                         }
2824                         if [[ "$mds1_FSTYPE" == zfs ]]; then
2825                             $r "$ZPOOL export t32fs-mdt2"
2826                         fi
2827                         shall_cleanup_mdt1=false
2828                 fi
2829
2830                 $r $UMOUNT $tmp/mnt/mdt || {
2831                         error_noexit "Unmounting the MDT"
2832                         return 1
2833                 }
2834                 if [[ "$mds1_FSTYPE" == zfs ]]; then
2835                     $r "$ZPOOL export t32fs-mdt1"
2836                 fi
2837                 shall_cleanup_mdt=false
2838
2839                 $r $UMOUNT $tmp/mnt/ost || {
2840                         error_noexit "Unmounting the OST"
2841                         return 1
2842                 }
2843                 if $ost2_is_available; then
2844                         $r $UMOUNT $tmp/mnt/ost1 || {
2845                                 error_noexit "Unmounting the OST1"
2846                                 return 1
2847                         }
2848                         shall_cleanup_ost1=false
2849                 fi
2850
2851                 if [[ $ost1_FSTYPE == zfs ]]; then
2852                         $r "$ZPOOL export t32fs-ost1"
2853                         if $ost2_is_available; then
2854                                 $r "$ZPOOL export t32fs-ost2"
2855                         fi
2856                 fi
2857                 shall_cleanup_ost=false
2858
2859                 t32_reload_modules $node || {
2860                         error_noexit "Reloading modules"
2861                         return 1
2862                 }
2863
2864                 if [[ "$mds1_FSTYPE" == zfs ]]; then
2865                         local poolname=t32fs-mdt1
2866                         $r "modprobe zfs;
2867                             $ZPOOL list -H $poolname >/dev/null 2>&1 ||
2868                                 $ZPOOL import -f -d $tmp $poolname"
2869
2870                         # upgrade zpool to latest supported features,
2871                         # including dnode quota accounting in 0.7.0
2872                         $r "$ZPOOL upgrade $poolname"
2873                 fi
2874
2875                 # mount a second time to make sure we didnt leave upgrade flag on
2876                 $r $TUNEFS --dryrun $mdt_dev || {
2877                         $r losetup -a
2878                         error_noexit "tunefs.lustre before remounting the MDT"
2879                         return 1
2880                 }
2881
2882                 mopts=exclude=$fsname-OST0000
2883                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2884                         mopts="loop,$mopts"
2885                 fi
2886                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2887                         error_noexit "Remounting the MDT"
2888                         return 1
2889                 }
2890                 shall_cleanup_mdt=true
2891         fi
2892 }
2893
2894 test_32a() {
2895         local tarballs
2896         local tarball
2897         local rc=0
2898
2899         t32_check
2900         for tarball in $tarballs; do
2901                 banner "testing $tarball upgrade"
2902                 t32_test $tarball || let "rc += $?"
2903         done
2904         return $rc
2905 }
2906 run_test 32a "Upgrade (not live)"
2907
2908 test_32b() {
2909         local tarballs
2910         local tarball
2911         local rc=0
2912
2913         t32_check
2914         for tarball in $tarballs; do
2915                 banner "testing $tarball upgrade with writeconf"
2916                 t32_test $tarball writeconf || let "rc += $?"
2917         done
2918         return $rc
2919 }
2920 run_test 32b "Upgrade with writeconf"
2921
2922 test_32c() {
2923         local tarballs
2924         local tarball
2925         local rc=0
2926
2927         t32_check
2928         for tarball in $tarballs; do
2929                 banner "testing $tarball upgrade with DNE"
2930                 load_modules
2931                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2932         done
2933         return $rc
2934 }
2935 run_test 32c "dne upgrade test"
2936
2937 test_32d() {
2938         local tarballs
2939         local tarball
2940         local rc=0
2941
2942         t32_check
2943         for tarball in $tarballs; do
2944                 banner "testing $tarball with filter_fid upgrade"
2945                 ff_convert=yes t32_test $tarball || rc=$?
2946         done
2947         return $rc
2948 }
2949 run_test 32d "convert filter_fid upgrade test"
2950
2951 test_32e() {
2952         [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
2953                 skip "Need MDS version at least 2.10.56"
2954
2955         local tarballs
2956         local tarball
2957         local rc=0
2958
2959         t32_check
2960         for tarball in $tarballs; do
2961                 [[ "$tarball" =~ "2_9" ]] ||
2962                         { echo "skip $(basename $tarball)"; continue; }
2963                 #load_modules
2964                 banner "testing $tarball upgrade with DoM"
2965                 dom_upgrade=yes t32_test $tarball writeconf || let "rc += $?"
2966         done
2967         return $rc
2968 }
2969 run_test 32e "dom upgrade test"
2970
2971 test_32f() {
2972         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
2973                 skip "Need MDS version at least 2.10.56"
2974
2975         local tarballs
2976         local tarball
2977         local rc=0
2978
2979         t32_check
2980         for tarball in $tarballs; do
2981                 [[ "$tarball" =~ "2_10" ]] ||
2982                         { echo "skip $(basename $tarball)"; continue; }
2983                 pfl_upgrade=yes project_quota_upgrade=yes \
2984                 t32_test $tarball writeconf || let "rc += $?"
2985         done
2986         return $rc
2987 }
2988 run_test 32f "pfl upgrade test"
2989
2990 test_32g() {
2991         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
2992                 skip "Need MDS version at least 2.10.56"
2993
2994         local tarballs
2995         local tarball
2996         local rc=0
2997
2998         t32_check
2999         for tarball in $tarballs; do
3000                 [[ $tarball =~ "2_12" ]] ||
3001                         { echo "skip $(basename $tarball)"; continue; }
3002                 flr_upgrade=yes dom_new_upgrade=yes \
3003                 t32_test $tarball writeconf || let "rc += $?"
3004         done
3005         return $rc
3006 }
3007 run_test 32g "flr/dom upgrade test"
3008
3009 test_33a() { # bug 12333, was test_33
3010         local FSNAME2=test-$testnum
3011
3012         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3013         local mkfsoptions
3014
3015         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
3016
3017         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
3018                 local dev=${SINGLEMDS}_dev
3019                 local MDSDEV=${!dev}
3020
3021                 is_blkdev $SINGLEMDS $MDSDEV &&
3022                         skip_env "mixed loopback and real device not working"
3023         fi
3024
3025         local fs2mdsdev=$(mdsdevname 1_2)
3026         local fs2ostdev=$(ostdevname 1_2)
3027         local fs2mdsvdev=$(mdsvdevname 1_2)
3028         local fs2ostvdev=$(ostvdevname 1_2)
3029
3030         if [ "$mds1_FSTYPE" == ldiskfs ]; then
3031                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
3032         fi
3033
3034         if combined_mgs_mds; then
3035                 local mgs_flag="--mgs"
3036         fi
3037
3038         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --fsname=${FSNAME2} \
3039                 --reformat $mgs_flag $mkfsoptions $fs2mdsdev $fs2mdsvdev ||
3040                 exit 10
3041         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
3042                 --fsname=${FSNAME2} --index=0x1fff --reformat $fs2ostdev \
3043                 $fs2ostvdev || exit 10
3044
3045         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
3046         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
3047
3048         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3049                 do_facet mgs "$PERM_CMD timeout=200" ||
3050                         error "$PERM_CMD timeout=200 failed"
3051         else
3052                 do_facet mgs "$PERM_CMD $FSNAME2.sys.timeout=200" ||
3053                         error "$PERM_CMD $FSNAME2.sys.timeout=200 failed"
3054         fi
3055         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
3056         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
3057         echo "ok."
3058
3059         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
3060         $LFS getstripe $MOUNT2/hosts ||
3061                 error "$LFS getstripe $MOUNT2/hosts failed"
3062
3063         umount $MOUNT2
3064
3065         if (( "$MGS_VERSION" >= $(version_code 2.15.51) &&
3066               "$MDS1_VERSION" >= $(version_code 2.15.51) )); then
3067                 # test lctl del_ost on large index
3068                 do_facet mgs "$LCTL del_ost -t ${FSNAME2}-OST1fff" ||
3069                         error "del_ost failed with $?"
3070                 $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 ||
3071                         error "$MOUNT_CMD failed"
3072                 echo "ok."
3073                 $LFS df | grep -q OST1fff &&
3074                         error "del_ost did not remove OST1fff!"
3075                 umount $MOUNT2
3076         fi
3077
3078         stop fs2ost -f
3079         stop fs2mds -f
3080         cleanup_nocli || error "cleanup_nocli failed with $?"
3081 }
3082 run_test 33a "Mount ost with a large index number"
3083
3084 test_33b() {    # was test_34
3085         setup
3086
3087         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
3088         # Drop lock cancelation reply during umount
3089         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
3090         do_facet client $LCTL set_param fail_loc=0x80000304
3091         #lctl set_param debug=-1
3092         umount_client $MOUNT
3093         cleanup || error "cleanup failed with $?"
3094 }
3095 run_test 33b "Drop cancel during umount"
3096
3097 test_33c() {
3098         (( MDS1_VERSION >= $(version_code 2.15.57) )) ||
3099                 skip "Need MDS version at least 2.15.57"
3100         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3101         local tstid=${TSTID:-"$(id -u $TSTUSR)"}
3102         local mkfsoptions
3103         local qpool="qpool1"
3104
3105         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
3106
3107         local fs2mdsdev=$(mdsdevname 1_2)
3108         local fs2ostdev=$(ostdevname 1_2)
3109         local fs2mdsvdev=$(mdsvdevname 1_2)
3110         local fs2ostvdev=$(ostvdevname 1_2)
3111
3112         if [ "$mds1_FSTYPE" == ldiskfs ]; then
3113                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
3114         fi
3115
3116         if combined_mgs_mds; then
3117                 local mgs_flag="--mgs"
3118         fi
3119
3120         load_modules
3121         stack_trap unload_modules_conf
3122
3123         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --fsname=${FSNAME} \
3124                 --reformat $mgs_flag $mkfsoptions $fs2mdsdev $fs2mdsvdev ||
3125                 exit 10
3126         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
3127                 --fsname=${FSNAME} --index=0x7c6 --reformat $fs2ostdev \
3128                 $fs2ostvdev || exit 10
3129
3130
3131         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
3132         stack_trap "stop fs2mds -f"
3133         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
3134         stack_trap "stop fs2ost -f"
3135
3136         mount_client $MOUNT || error "client start failed"
3137         stack_trap "umount_client $MOUNT"
3138         mkdir_on_mdt0 $DIR/$tdir || error "cannot create $DIR/$tdir"
3139         chmod 0777 $DIR/$tdir || error "chown failed"
3140         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3141                 do_facet mgs $PERM_CMD \
3142                         osd-*.$FSNAME-OST*.quota_slave.enable=$QUOTA_TYPE
3143         else
3144                 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
3145                         error "set ost quota type failed"
3146         fi
3147
3148         local old_MDSCOUNT=$MDSCOUNT
3149         MDSCOUNT=1
3150         stack_trap "MDSCOUNT=$old_MDSCOUNT"
3151
3152         pool_add $qpool || error "pool_add failed"
3153         pool_add_targets $qpool 0x7c6
3154
3155         $LFS setquota -u $tstid -B20M -b 0 $MOUNT
3156         $LFS setquota -g $tstid -B20M -b 0 $MOUNT
3157         $LFS setquota -u $tstid -B20M -b 0 --pool $qpool $MOUNT
3158         $LFS setquota -g $tstid -B20M -b 0 --pool $qpool $MOUNT
3159
3160         for i in {1..10}; do
3161                 runas -u $tstid -g $tstid dd if=/dev/zero of=$DIR/$tdir/f1 \
3162                         bs=1M count=30 oflag=direct
3163                 sleep 3
3164                 rm -f $DIR/$tdir/f1
3165         done
3166
3167         destroy_pools
3168         #umount_client $MOUNT || error "client start failed"
3169         #stop fs2ost -f
3170         #stop fs2mds -f
3171         #cleanup_nocli || error "cleanup_nocli failed with $?"
3172 }
3173 run_test 33c "Mount ost with a large index number"
3174
3175 test_34a() {
3176         setup
3177         do_facet client "bash runmultiop_bg_pause $DIR/file O_c"
3178         manual_umount_client
3179         rc=$?
3180         do_facet client killall -USR1 multiop
3181         if [ $rc -eq 0 ]; then
3182                 error "umount not fail!"
3183         fi
3184         sleep 1
3185         cleanup || error "cleanup failed with rc $?"
3186 }
3187 run_test 34a "umount with opened file should be fail"
3188
3189 test_34b() {
3190         setup
3191         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3192         stop_mds || error "Unable to stop MDS"
3193
3194         manual_umount_client --force || error "mtab after failed umount with $?"
3195
3196         cleanup || error "cleanup failed with $?"
3197 }
3198 run_test 34b "force umount with failed mds should be normal"
3199
3200 test_34c() {
3201         setup
3202         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3203         stop_ost || error "Unable to stop OST1"
3204
3205         manual_umount_client --force || error "mtab after failed umount with $?"
3206
3207         cleanup || error "cleanup failed with $?"
3208 }
3209 run_test 34c "force umount with failed ost should be normal"
3210
3211 test_35a() { # bug 12459
3212         setup
3213
3214         DBG_SAVE="`$LCTL get_param -n debug`"
3215         $LCTL set_param debug="ha"
3216
3217         log "Set up a fake failnode for the MDS"
3218         FAKENID="127.0.0.2"
3219         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
3220                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
3221
3222         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3223                 do_facet mgs "$PERM_CMD \
3224                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
3225                         error "Setting mdc.*${device}*.import=connection=\
3226                                $(h2nettype $FAKENID) failed."
3227         else
3228                 do_facet mgs "$PERM_CMD \
3229                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
3230                         error "Setting ${device}.failover.node=\
3231                                $(h2nettype $FAKENID) failed."
3232         fi
3233         log "Wait for RECONNECT_INTERVAL seconds (10s)"
3234         sleep 10
3235
3236         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
3237         $LCTL clear
3238         log "$MSG"
3239         log "Stopping the MDT: $device"
3240         stop_mdt 1 || error "MDT0 stop fail"
3241
3242         df $MOUNT > /dev/null 2>&1 &
3243         DFPID=$!
3244         log "Restarting the MDT: $device"
3245         start_mdt 1 || error "MDT0 start fail"
3246         log "Wait for df ($DFPID) ... "
3247         wait $DFPID
3248         log "done"
3249         $LCTL set_param debug="$DBG_SAVE"
3250
3251         # retrieve from the log the first server that the client tried to
3252         # contact after the connection loss
3253         $LCTL dk $TMP/lustre-log-$TESTNAME.log
3254         NEXTCONN=`awk "/${MSG}/ {start = 1;}
3255                        /import_select_connection.*$device-mdc.* using connection/ {
3256                                 if (start) {
3257                                         if (\\\$NF ~ /$FAKENID/)
3258                                                 print \\\$NF;
3259                                         else
3260                                                 print 0;
3261                                         exit;
3262                                 }
3263                        }" $TMP/lustre-log-$TESTNAME.log`
3264         [ "$NEXTCONN" != "0" ] &&
3265                 error "Tried to connect to ${NEXTCONN} not last active server"
3266         cleanup || error "cleanup failed with $?"
3267         # remove nid settings
3268         writeconf_or_reformat
3269 }
3270 run_test 35a "Reconnect to the last active server first"
3271
3272 test_35b() { # bug 18674
3273         remote_mds || skip "local MDS"
3274         setup
3275
3276         debugsave
3277         $LCTL set_param debug="ha"
3278         $LCTL clear
3279         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
3280         log "$MSG"
3281
3282         log "Set up a fake failnode for the MDS"
3283         FAKENID="127.0.0.2"
3284         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
3285                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
3286
3287         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3288                 do_facet mgs "$PERM_CMD \
3289                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
3290                         error "Set mdc.*${device}*.import=connection=\
3291                                $(h2nettype $FAKENID) failed"
3292         else
3293                 do_facet mgs "$PERM_CMD \
3294                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
3295                         error "Set ${device}.failover.node=\
3296                                $(h2nettype $FAKENID) failed"
3297         fi
3298
3299         local at_max_saved=0
3300         # adaptive timeouts may prevent seeing the issue
3301         if at_is_enabled; then
3302                 at_max_saved=$(at_max_get mds)
3303                 at_max_set 0 mds client
3304         fi
3305
3306         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
3307
3308         log "Injecting EBUSY on MDS"
3309         # Setting OBD_FAIL_MDS_RESEND=0x136
3310         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
3311                 error "unable to set param fail_loc=0x80000136"
3312
3313         $LCTL set_param mdc.${FSNAME}*.stats=clear
3314
3315         log "Creating a test file and stat it"
3316         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
3317         stat $MOUNT/$tdir/$tfile
3318
3319         log "Stop injecting EBUSY on MDS"
3320         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
3321                 error "unable to set param fail_loc=0"
3322         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
3323
3324         log "done"
3325         # restore adaptive timeout
3326         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
3327
3328         $LCTL dk $TMP/lustre-log-$TESTNAME.log
3329
3330         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
3331                   awk '/mds_connect/{print $2}')
3332
3333         # retrieve from the log if the client has ever tried to
3334         # contact the fake server after the loss of connection
3335         FAILCONN=`awk "BEGIN {ret = 0;}
3336                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
3337                                 ret = 1;
3338                                 if (\\\$NF ~ /$FAKENID/) {
3339                                         ret = 2;
3340                                         exit;
3341                                 }
3342                        }
3343                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
3344
3345         [ "$FAILCONN" == "0" ] &&
3346                 error "The client reconnection has not been triggered"
3347         [ "$FAILCONN" == "2" ] &&
3348                 error "Primary server busy, client reconnect to failover failed"
3349
3350         # LU-290
3351         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
3352         # Reconnects are supposed to be rate limited to one every 5s
3353         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
3354                 error "Too many reconnects $CONNCNT"
3355
3356         cleanup || error "cleanup failed with $?"
3357         # remove nid settings
3358         writeconf_or_reformat
3359 }
3360 run_test 35b "Continue reconnection retries, if the active server is busy"
3361
3362 test_36() { # 12743
3363         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
3364
3365         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
3366                 skip "remote OST"
3367
3368         local rc=0
3369         local FSNAME2=test1234
3370         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3371
3372         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
3373
3374         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
3375                 is_blkdev $SINGLEMDS $MDSDEV &&
3376                         skip_env "mixed loopback and real device not working"
3377         fi
3378
3379         local fs2mdsdev=$(mdsdevname 1_2)
3380         local fs2ostdev=$(ostdevname 1_2)
3381         local fs3ostdev=$(ostdevname 2_2)
3382         local fs2mdsvdev=$(mdsvdevname 1_2)
3383         local fs2ostvdev=$(ostvdevname 1_2)
3384         local fs3ostvdev=$(ostvdevname 2_2)
3385
3386         load_modules
3387         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
3388                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
3389         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
3390         #     different one than the default value here.
3391         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
3392                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
3393         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
3394                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
3395
3396         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
3397         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
3398         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
3399         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
3400         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
3401
3402         sleep 5 # until 11778 fixed
3403
3404         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
3405
3406         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
3407                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
3408         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
3409                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
3410         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
3411                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
3412         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
3413         DFTOTAL=$(echo $STRING | cut -d, -f1)
3414         DFUSED=$(echo $STRING  | cut -d, -f2)
3415         DFAVAIL=$(echo $STRING | cut -d, -f3)
3416         DFFREE=$(($DFTOTAL - $DFUSED))
3417
3418         ALLOWANCE=$((64 * $OSTCOUNT))
3419
3420         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
3421            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
3422                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
3423                 rc=1
3424         fi
3425         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
3426            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
3427                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
3428                 rc=2
3429         fi
3430         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
3431            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
3432                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
3433                 rc=3
3434         fi
3435
3436         $UMOUNT $MOUNT2
3437         stop fs3ost -f || error "unable to stop OST3"
3438         stop fs2ost -f || error "unable to stop OST2"
3439         stop fs2mds -f || error "unable to stop second MDS"
3440         unload_modules_conf || error "unable unload modules"
3441         return $rc
3442 }
3443 run_test 36 "df report consistency on OSTs with different block size"
3444
3445 test_37() {
3446         local mntpt=$(facet_mntpt $SINGLEMDS)
3447         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
3448         local mdsdev_sym="$TMP/sym_mdt.img"
3449         local opts=$MDS_MOUNT_OPTS
3450         local rc=0
3451
3452         if [ "$mds1_FSTYPE" != ldiskfs ]; then
3453                 skip "ldiskfs only test"
3454         fi
3455
3456         echo "MDS :     $mdsdev"
3457         echo "SYMLINK : $mdsdev_sym"
3458         do_facet $SINGLEMDS rm -f $mdsdev_sym
3459
3460         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
3461
3462         echo "mount symlink device - $mdsdev_sym"
3463
3464         if ! do_facet $SINGLEMDS test -b $mdsdev; then
3465                 opts=$(csa_add "$opts" -o loop)
3466         fi
3467
3468         load_modules
3469         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
3470                 $mdsdev_sym $mntpt 2>&1)
3471         rc=${PIPESTATUS[0]}
3472
3473         echo mount_op=$mount_op
3474
3475         do_facet $SINGLEMDS "$UMOUNT $mntpt && rm -f $mdsdev_sym"
3476
3477         if $(echo $mount_op | grep -q "unable to set tunable"); then
3478                 error "set tunables failed for symlink device"
3479         fi
3480
3481         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
3482 }
3483 run_test 37 "verify set tunables works for symlink device"
3484
3485 test_38() { # bug 14222
3486         local mntpt=$(facet_mntpt $SINGLEMDS)
3487
3488         setup
3489         # like runtests
3490         local COUNT=10
3491         local SRC="/etc /bin"
3492         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
3493
3494         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
3495         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3496         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
3497                 error "copying $SRC to $DIR/$tdir"
3498         sync
3499         umount_client $MOUNT || error "umount_client $MOUNT failed"
3500         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
3501         stop_mds || error "Unable to stop MDS"
3502         log "delete lov_objid file on MDS"
3503
3504         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
3505
3506         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
3507
3508         unmount_fstype $SINGLEMDS || error "umount failed (1)"
3509
3510         # check create in mds_lov_connect
3511         start_mds || error "unable to start MDS"
3512         mount_client $MOUNT || error "mount_client $MOUNT failed"
3513         for f in $FILES; do
3514                 [ $V ] && log "verifying $DIR/$tdir/$f"
3515                 diff -q $f $DIR/$tdir/$f || ERROR=y
3516         done
3517         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
3518         if [ "$ERROR" = "y" ]; then
3519                 # check it's updates in sync
3520                 umount_client $MOUNT
3521                 stop_mds
3522                 mount_fstype $SIGNLEMDS
3523                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
3524                 unmount_fstype $SINGLEMDS
3525                 error "old and new files are different after connect" || true
3526         fi
3527         touch $DIR/$tdir/f2 || error "f2 file create failed"
3528
3529         # check it's updates in sync
3530         umount_client $MOUNT || error "second umount_client $MOUNT failed"
3531         stop_mds
3532
3533         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
3534
3535         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
3536         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
3537
3538         unmount_fstype $SINGLEMDS || error "umount failed (3)"
3539
3540         start_mds || error "unable to start MDS"
3541         mount_client $MOUNT || error "mount_client $MOUNT failed"
3542         for f in $FILES; do
3543                 [ $V ] && log "verifying $DIR/$tdir/$f"
3544                 diff -q $f $DIR/$tdir/$f || ERROR=y
3545         done
3546         touch $DIR/$tdir/f3 || error "f3 file create failed"
3547         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
3548         umount_client $MOUNT || error "third umount_client $MOUNT failed"
3549         stop_mds
3550         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
3551         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
3552         unmount_fstype $SINGLEMDS || error "umount failed (4)"
3553
3554         [[ "$ERROR" != "y" ]] ||
3555                 error "old and new files are different after sync"
3556
3557         log "files compared the same"
3558         cleanup || error "cleanup failed with $?"
3559 }
3560 run_test 38 "MDS recreates missing lov_objid file from OST data"
3561
3562 test_39() {
3563         [[ -n "$(type -p perl)" ]] || skip_env "need perl for leak_finder.pl"
3564
3565         PTLDEBUG=+malloc
3566         setup
3567         cleanup || error "cleanup failed with $?"
3568         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
3569                 error "memory leak detected" || true
3570 }
3571 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
3572
3573 test_40() { # bug 15759
3574         start_ost || error "Unable to start OST1"
3575         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
3576         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
3577         start_mds
3578         cleanup || error "cleanup failed with rc $?"
3579 }
3580 run_test 40 "race during service thread startup"
3581
3582 test_41a() { #bug 14134
3583         if [ "$mds1_FSTYPE" == ldiskfs ] &&
3584            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
3585                 skip "Loop devices does not work with nosvc option"
3586         fi
3587
3588         combined_mgs_mds || skip "needs combined MGT and MDT device"
3589
3590         start_mdt 1 -o nosvc -n
3591         if [ $MDSCOUNT -ge 2 ]; then
3592                 for num in $(seq 2 $MDSCOUNT); do
3593                         start_mdt $num || return
3594                 done
3595         fi
3596         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
3597         start_mdt 1 -o nomgs,force
3598         mount_client $MOUNT || error "mount_client $MOUNT failed"
3599         sleep 5
3600
3601         echo "blah blah" > $MOUNT/$tfile
3602         cat $MOUNT/$tfile
3603
3604         umount_client $MOUNT || error "umount_client $MOUNT failed"
3605         stop ost1 -f || error "unable to stop OST1"
3606         stop_mds || error "Unable to stop MDS"
3607         stop_mds || error "Unable to stop MDS on second try"
3608 }
3609 run_test 41a "mount mds with --nosvc and --nomgs"
3610
3611 test_41b() {
3612         if [ "$mds1_FSTYPE" == ldiskfs ] &&
3613            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
3614                 skip "Loop devices does not work with nosvc option"
3615         fi
3616
3617         ! combined_mgs_mds && skip "needs combined mgs device"
3618
3619         stopall
3620         reformat
3621         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3622
3623         start_mdt 1 -o nosvc -n
3624         if [ $MDSCOUNT -ge 2 ]; then
3625                 for num in $(seq 2 $MDSCOUNT); do
3626                         start_mdt $num || return
3627                 done
3628         fi
3629         start_ost || error "Unable to start OST1"
3630         start_mdt 1 -o nomgs,force
3631         mount_client $MOUNT || error "mount_client $MOUNT failed"
3632         sleep 5
3633
3634         echo "blah blah" > $MOUNT/$tfile
3635         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
3636
3637         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
3638         stop_ost || error "Unable to stop OST1"
3639         stop_mds || error "Unable to stop MDS"
3640         stop_mds || error "Unable to stop MDS on second try"
3641 }
3642 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
3643
3644 test_41c() {
3645         local oss_list=$(comma_list $(osts_nodes))
3646
3647         (( "$MDS1_VERSION" >= $(version_code 2.15.62.4) )) ||
3648                 skip "Need MDS >= 2.15.62.4 for parallel device locking"
3649
3650         # ensure mds1 ost1 have been created even if running sub-test standalone
3651         cleanup
3652         setup
3653         cleanup || error "cleanup failed"
3654
3655         # using directly mount command instead of start() function to avoid
3656         # any side effect of // with others/externals tools/features
3657         # ("zpool import", ...)
3658
3659         # MDT concurrent start
3660
3661         LOAD_MODULES_REMOTE=true load_modules
3662         do_facet $SINGLEMDS "lsmod | grep -q libcfs" ||
3663                 error "MDT concurrent start: libcfs module not loaded"
3664
3665         local mds1dev=$(mdsdevname 1)
3666         local mds1mnt=$(facet_mntpt mds1)
3667         local mds1opts=$MDS_MOUNT_OPTS
3668
3669         if [[ "$mds1_FSTYPE" == ldiskfs ]] &&
3670            ! do_facet mds1 test -b $mds1dev; then
3671                 mds1opts=$(csa_add "$mds1opts" -o loop)
3672         fi
3673         if [[ "$mds1_FSTYPE" == zfs ]]; then
3674                 import_zpool mds1 || return ${PIPESTATUS[0]}
3675         fi
3676
3677         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
3678         do_facet mds1 "$LCTL set_param fail_loc=0x80000716"
3679
3680         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts &
3681         local pid=$!
3682
3683         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts
3684         local rc2=$?
3685         wait $pid
3686         local rc=$?
3687
3688         do_facet mds1 "$LCTL set_param fail_loc=0x0"
3689         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3690                 echo "1st MDT start succeed"
3691                 echo "2nd MDT start failed with $rc2"
3692         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3693                 echo "1st MDT start failed with $rc"
3694                 echo "2nd MDT start succeed"
3695         else
3696                 stop mds1 -f
3697                 error "unexpected concurrent MDT mounts result, rc=$rc rc2=$rc2"
3698         fi
3699
3700         if [ $MDSCOUNT -ge 2 ]; then
3701                 for num in $(seq 2 $MDSCOUNT); do
3702                         start_mdt $num || return
3703                 done
3704         fi
3705
3706         # OST concurrent start
3707
3708         do_rpc_nodes $oss_list "lsmod | grep -q libcfs" ||
3709                 error "OST concurrent start: libcfs module not loaded"
3710
3711         local ost1dev=$(ostdevname 1)
3712         local ost1mnt=$(facet_mntpt ost1)
3713         local ost1opts=$OST_MOUNT_OPTS
3714
3715         if [ "$ost1_FSTYPE" == ldiskfs ] &&
3716            ! do_facet ost1 test -b $ost1dev; then
3717                 ost1opts=$(csa_add "$ost1opts" -o loop)
3718         fi
3719         if [[ "$ost1_FSTYPE" == zfs ]]; then
3720                 import_zpool ost1 || return ${PIPESTATUS[0]}
3721         fi
3722
3723         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
3724         do_facet ost1 "$LCTL set_param fail_loc=0x80000716"
3725
3726         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts &
3727         pid=$!
3728
3729         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts
3730         rc2=$?
3731         wait $pid
3732         rc=$?
3733         do_facet ost1 "$LCTL set_param fail_loc=0x0"
3734         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3735                 echo "1st OST start succeed"
3736                 echo "2nd OST start failed with $rc2"
3737         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3738                 echo "1st OST start failed with $rc"
3739                 echo "2nd OST start succeed"
3740         else
3741                 stop_mds -f
3742                 stop ost1 -f
3743                 error "unexpected concurrent OST mounts result, rc=$rc rc2=$rc2"
3744         fi
3745         # cleanup
3746         stop_mds
3747         stop ost1 -f
3748
3749         # verify everything ok
3750         start_mds
3751         if [ $? != 0 ]
3752         then
3753                 stop_mds
3754                 error "MDT(s) start failed"
3755         fi
3756
3757         start_ost
3758         if [ $? != 0 ]
3759         then
3760                 stop_mds
3761                 stop ost1 -f
3762                 error "OST(s) start failed"
3763         fi
3764
3765         mount_client $MOUNT
3766         if [ $? != 0 ]
3767         then
3768                 stop_mds
3769                 stop ost1 -f
3770                 error "client start failed"
3771         fi
3772         check_mount
3773         if [ $? != 0 ]
3774         then
3775                 stop_mds
3776                 stop ost1 -f
3777                 error "client mount failed"
3778         fi
3779         cleanup
3780 }
3781 run_test 41c "concurrent mounts of MDT/OST should all fail but one"
3782
3783 test_42() { #bug 14693
3784         local PARAM
3785
3786         setup
3787         check_mount || error "client was not mounted"
3788
3789         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3790                 PARAM="llite.$FSNAME-*.some_wrong_param"
3791         else
3792                 PARAM="$FSNAME.llite.some_wrong_param"
3793         fi
3794
3795         do_facet mgs $PERM_CMD $PARAM=10
3796         umount_client $MOUNT ||
3797                 error "unmounting client failed with invalid llite param"
3798         mount_client $MOUNT ||
3799                 error "mounting client failed with invalid llite param"
3800
3801         do_facet mgs $PERM_CMD $PARAM=20
3802         cleanup || error "stopping $FSNAME failed with invalid sys param"
3803         setup
3804         check_mount || error "client was not mounted with invalid sys param"
3805         cleanup || error "stopping $FSNAME failed with invalid sys param"
3806 }
3807 run_test 42 "allow client/server mount/unmount with invalid config param"
3808
3809 test_43a() {
3810         [[ "$MGS_VERSION" -ge $(version_code 2.5.58) ]] ||
3811                 skip "Need MDS version at least 2.5.58"
3812         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
3813
3814         ID1=${ID1:-501}
3815         USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
3816         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1"
3817
3818         setup
3819         chmod ugo+x $DIR || error "chmod 0 failed"
3820         set_persistent_param_and_check mds1                             \
3821                 "mdt.$FSNAME-MDT0000.root_squash"                       \
3822                 "$FSNAME.mdt.root_squash"                               \
3823                 "0:0"
3824         wait_update $HOSTNAME                                           \
3825                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3826                 "0:0" ||
3827                 error "check llite root_squash failed!"
3828         set_persistent_param_and_check mds1                             \
3829                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
3830                 "$FSNAME.mdt.nosquash_nids"                             \
3831                 "NONE"
3832         wait_update $HOSTNAME                                           \
3833                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3834                 "NONE" ||
3835                 error "check llite nosquash_nids failed!"
3836
3837         #
3838         # create set of test files
3839         #
3840         echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
3841         chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
3842         chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
3843
3844         echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
3845         chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
3846
3847         mkdir_on_mdt0 $DIR/$tdir-rootdir || error "mkdir failed"
3848         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
3849         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
3850
3851         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
3852         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
3853         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
3854
3855         #
3856         # check root_squash:
3857         #   set root squash UID:GID to RUNAS_ID
3858         #   root should be able to access only files owned by RUNAS_ID
3859         #
3860         set_persistent_param_and_check mds1                             \
3861                 "mdt.$FSNAME-MDT0000.root_squash"                       \
3862                 "$FSNAME.mdt.root_squash"                               \
3863                 "$RUNAS_ID:$RUNAS_ID"
3864         wait_update $HOSTNAME                                           \
3865                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3866                 "$RUNAS_ID:$RUNAS_ID" ||
3867                 error "check llite root_squash failed!"
3868
3869         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
3870         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3871                 error "$ST: root read permission is denied"
3872         echo "$ST: root read permission is granted - ok"
3873
3874         echo "444" |
3875         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3876                 error "$ST: root write permission is denied"
3877         echo "$ST: root write permission is granted - ok"
3878
3879         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3880         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3881                 error "$ST: root read permission is granted"
3882         echo "$ST: root read permission is denied - ok"
3883
3884         echo "555" |
3885         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3886                 error "$ST: root write permission is granted"
3887         echo "$ST: root write permission is denied - ok"
3888
3889         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3890                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
3891                         error "$ST: root unlink permission is granted"
3892         echo "$ST: root unlink permission is denied - ok"
3893
3894         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
3895                 error "$ST: root create permission is granted"
3896         echo "$ST: root create permission is denied - ok"
3897
3898         # LU-1778
3899         # check root_squash is enforced independently
3900         # of client cache content
3901         #
3902         # access file by USER1, keep access open
3903         # root should be denied access to user file
3904
3905         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
3906         pid=$!
3907         sleep 1
3908
3909         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
3910         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3911             { kill $pid; error "$ST: root read permission is granted"; }
3912         echo "$ST: root read permission is denied - ok"
3913
3914         echo "777" |
3915         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3916             { kill $pid; error "$ST: root write permission is granted"; }
3917         echo "$ST: root write permission is denied - ok"
3918
3919         kill $pid
3920         wait $pid
3921
3922         #
3923         # check nosquash_nids:
3924         #   put client's NID into nosquash_nids list,
3925         #   root should be able to access root file after that
3926         #
3927         local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
3928         NIDLIST="2@gni $NIDLIST 192.168.0.[2,10]@tcp"
3929         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
3930         set_persistent_param_and_check mds1                             \
3931                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
3932                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
3933                 "$NIDLIST"
3934         wait_update $HOSTNAME                                           \
3935                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3936                 "$NIDLIST" ||
3937                 error "check llite nosquash_nids failed!"
3938
3939         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3940         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3941                 error "$ST: root read permission is denied"
3942         echo "$ST: root read permission is granted - ok"
3943
3944         echo "666" |
3945         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3946                 error "$ST: root write permission is denied"
3947         echo "$ST: root write permission is granted - ok"
3948
3949         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3950         rm $DIR/$tdir-rootdir/tfile-1 ||
3951                 error "$ST: root unlink permission is denied"
3952         echo "$ST: root unlink permission is granted - ok"
3953         touch $DIR/$tdir-rootdir/tfile-2 ||
3954                 error "$ST: root create permission is denied"
3955         echo "$ST: root create permission is granted - ok"
3956         cleanup || error "cleanup failed with $?"
3957 }
3958 run_test 43a "check root_squash and nosquash_nids"
3959
3960 test_43b() { # LU-5690
3961         [[ "$MGS_VERSION" -ge $(version_code 2.7.62) ]] ||
3962                 skip "Need MGS version 2.7.62+"
3963
3964         if [[ -z "$fs2mds_DEV" ]]; then
3965                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
3966                 skip_env "mixed loopback and real device not working"
3967         fi
3968
3969         local fs2mdsdev=$(mdsdevname 1_2)
3970         local fs2mdsvdev=$(mdsvdevname 1_2)
3971
3972         # temporarily use fs2mds as fs2mgs
3973         local fs2mgs=fs2mds
3974         local fs2mgsdev=$fs2mdsdev
3975         local fs2mgsvdev=$fs2mdsvdev
3976
3977         local fsname=test1234
3978
3979         load_module llite/lustre
3980         local client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
3981         local host=${client_ip//*./}
3982         local net=${client_ip/%$host/}
3983         local nosquash_nids=$(h2nettype $net[$host,$host,$host])
3984
3985         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
3986                 --param mdt.root_squash=$RUNAS_ID:$RUNAS_ID \
3987                 --param mdt.nosquash_nids=$nosquash_nids \
3988                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
3989         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS  || error "start fs2mgs failed"
3990         stop $fs2mgs -f || error "stop fs2mgs failed"
3991         cleanup || error "cleanup failed with $?"
3992 }
3993 run_test 43b "parse nosquash_nids with commas in expr_list"
3994
3995 test_44() { # 16317
3996         setup
3997         check_mount || error "check_mount"
3998         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
3999         STATS_FOUND=no
4000         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
4001         for VAL in $UUIDS; do
4002                 NID=$(echo $VAL | cut -d= -f1)
4003                 CLUUID=$(echo $VAL | cut -d= -f2)
4004                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
4005         done
4006         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
4007         cleanup || error "cleanup failed with $?"
4008 }
4009 run_test 44 "mounted client proc entry exists"
4010
4011 test_45() { #17310
4012         setup
4013         check_mount || error "check_mount"
4014         stop_mds || error "Unable to stop MDS"
4015         df -h $MOUNT &
4016         log "sleep 60 sec"
4017         sleep 60
4018         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK        0x50f
4019         do_facet client "$LCTL set_param fail_loc=0x8000050f"
4020         log "sleep 10 sec"
4021         sleep 10
4022         manual_umount_client --force || error "manual_umount_client failed"
4023         do_facet client "$LCTL set_param fail_loc=0x0"
4024         start_mds || error "unable to start MDS"
4025         mount_client $MOUNT || error "mount_client $MOUNT failed"
4026         cleanup || error "cleanup failed with $?"
4027 }
4028 run_test 45 "long unlink handling in ptlrpcd"
4029
4030 cleanup_46a() {
4031         trap 0
4032         local rc=0
4033         local count=$1
4034
4035         umount_client $MOUNT2 || rc=$?
4036         umount_client $MOUNT || rc=$?
4037         while [ $count -gt 0 ]; do
4038                 stop ost${count} -f || rc=$?
4039                 let count=count-1
4040         done
4041         stop_mds || rc=$?
4042         cleanup_nocli || rc=$?
4043         #writeconf to remove all ost2 traces for subsequent tests
4044         writeconf_or_reformat
4045         return $rc
4046 }
4047
4048 test_46a() {
4049         echo "Testing with $OSTCOUNT OSTs"
4050         reformat_and_config
4051         start_mds || error "unable to start MDS"
4052         #first client should see only one ost
4053         start_ost || error "Unable to start OST1"
4054         wait_osc_import_state mds ost FULL
4055         #start_client
4056         mount_client $MOUNT || error "mount_client $MOUNT failed"
4057         trap "cleanup_46a $OSTCOUNT" EXIT ERR
4058
4059         local i
4060         for (( i=2; i<=$OSTCOUNT; i++ )); do
4061                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
4062                         error "start_ost$i $(ostdevname $i) failed"
4063         done
4064
4065         # wait until osts in sync
4066         for (( i=2; i<=$OSTCOUNT; i++ )); do
4067             wait_osc_import_state mds ost$i FULL
4068             wait_osc_import_ready client ost$i
4069         done
4070
4071         #second client see all ost's
4072
4073         mount_client $MOUNT2 || error "mount_client failed"
4074         $LFS setstripe -c -1 $MOUNT2 ||
4075                 error "$LFS setstripe -c -1 $MOUNT2 failed"
4076         $LFS getstripe $MOUNT2 || error "$LFS getstripe $MOUNT2 failed"
4077
4078         echo "ok" > $MOUNT2/widestripe
4079         $LFS getstripe $MOUNT2/widestripe ||
4080                 error "$LFS getstripe $MOUNT2/widestripe failed"
4081         # fill acl buffer for avoid expand lsm to them
4082         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
4083                 while read acl; do
4084             setfacl -m $acl $MOUNT2/widestripe
4085         done
4086
4087         # will be deadlock
4088         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
4089
4090         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
4091 }
4092 run_test 46a "handle ost additional - wide striped file"
4093
4094 test_47() { #17674
4095         reformat
4096         setup_noconfig
4097         check_mount || error "check_mount failed"
4098         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
4099
4100         local lru_size=[]
4101         local count=0
4102         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
4103                 if echo $ns | grep "MDT[[:digit:]]*"; then
4104                         continue
4105                 fi
4106                 lrs=$(echo $ns | sed 's/.*lru_size=//')
4107                 lru_size[count]=$lrs
4108                 let count=count+1
4109         done
4110
4111         facet_failover ost1
4112         facet_failover $SINGLEMDS
4113         client_up || error "client_up failed"
4114
4115         count=0
4116         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
4117                 if echo $ns | grep "MDT[[:digit:]]*"; then
4118                         continue
4119                 fi
4120                 lrs=$(echo $ns | sed 's/.*lru_size=//')
4121                 if ! test "$lrs" -eq "${lru_size[count]}"; then
4122                         n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
4123                         error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
4124                 fi
4125                 let count=count+1
4126         done
4127
4128         cleanup || error "cleanup failed with $?"
4129 }
4130 run_test 47 "server restart does not make client loss lru_resize settings"
4131
4132 cleanup_48() {
4133         trap 0
4134
4135         # reformat after this test is needed - if the test fails,
4136         # we will have unkillable file at FS
4137         reformat_and_config
4138 }
4139
4140 test_48() { # bz-17636 LU-7473
4141         local count
4142
4143         setup_noconfig
4144         check_mount || error "check_mount failed"
4145
4146         $LFS setstripe -c -1 $MOUNT ||
4147                 error "$LFS setstripe -c -1 $MOUNT failed"
4148         $LFS getstripe $MOUNT || error "$LFS getstripe $MOUNT failed"
4149
4150         echo "ok" > $MOUNT/widestripe
4151         $LFS getstripe $MOUNT/widestripe ||
4152                 error "$LFS getstripe $MOUNT/widestripe failed"
4153
4154         # In the future, we may introduce more EAs, such as selinux, enlarged
4155         # LOV EA, and so on. These EA will use some EA space that is shared by
4156         # ACL entries. So here we only check some reasonable ACL entries count,
4157         # instead of the max number that is calculated from the max_ea_size.
4158         if [ "$MDS1_VERSION" -lt $(version_code 2.8.57) ]; then
4159                 count=28        # hard coded of RPC protocol
4160         elif large_xattr_enabled; then
4161                 count=4500      # max_num 8187 max_ea_size = 65452
4162                                 # not create too many (4500) to save test time
4163         else
4164                 count=450       # max_num 497 max_ea_size = 4012
4165         fi
4166
4167         echo "It is expected to hold at least $count ACL entries"
4168         trap cleanup_48 EXIT ERR
4169         for ((i = 0; i < $count; i++)) do
4170                 setfacl -m u:$((i + 100)):rw $MOUNT/widestripe ||
4171                         error "Fail to setfacl for $MOUNT/widestripe at $i"
4172         done
4173
4174         cancel_lru_locks mdc
4175         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
4176         local r_count=$(getfacl $MOUNT/widestripe | grep "user:" | wc -l)
4177
4178         count=$((count + 1)) # for the entry "user::rw-"
4179
4180         [ $count -eq $r_count ] ||
4181                 error "Expected ACL entries $count, but got $r_count"
4182
4183         cleanup_48
4184 }
4185 run_test 48 "too many acls on file"
4186
4187 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
4188 test_49a() { # bug 17710
4189         local timeout_orig=$TIMEOUT
4190         local ldlm_timeout_orig=$LDLM_TIMEOUT
4191         local LOCAL_TIMEOUT=20
4192
4193         LDLM_TIMEOUT=$LOCAL_TIMEOUT
4194         TIMEOUT=$LOCAL_TIMEOUT
4195
4196         reformat
4197         setup_noconfig
4198         check_mount || error "client mount failed"
4199
4200         echo "check ldlm_timout..."
4201         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
4202         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
4203         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
4204
4205         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
4206                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
4207         fi
4208
4209         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
4210                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
4211         fi
4212
4213         umount_client $MOUNT || error "umount_client $MOUNT failed"
4214         stop_ost || error "problem stopping OSS"
4215         stop_mds || error "problem stopping MDS"
4216
4217         LDLM_TIMEOUT=$ldlm_timeout_orig
4218         TIMEOUT=$timeout_orig
4219 }
4220 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
4221
4222 test_49b() { # bug 17710
4223         local timeout_orig=$TIMEOUT
4224         local ldlm_timeout_orig=$LDLM_TIMEOUT
4225         local LOCAL_TIMEOUT=20
4226
4227         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
4228         TIMEOUT=$LOCAL_TIMEOUT
4229
4230         reformat
4231         setup_noconfig
4232         check_mount || error "client mount failed"
4233
4234         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
4235         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
4236         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
4237
4238         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
4239                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
4240         fi
4241
4242         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
4243                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
4244         fi
4245
4246         cleanup || error "cleanup failed"
4247
4248         LDLM_TIMEOUT=$ldlm_timeout_orig
4249         TIMEOUT=$timeout_orig
4250 }
4251 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
4252
4253 lazystatfs() {
4254         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
4255         sleep 2
4256         # Test both statfs and lfs df and fail if either one fails
4257         multiop_bg_pause $1 f_
4258         RC=$?
4259         PID=$!
4260         killall -USR1 multiop
4261         [ $RC -ne 0 ] && log "lazystatfs multiop failed"
4262         wait $PID || { RC=$?; log "multiop return error "; }
4263
4264         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
4265         sleep 2
4266         $LFS df -l &
4267         PID=$!
4268         sleep 5
4269         if kill -s 0 $PID; then
4270                 RC=1
4271                 kill -s 9 $PID
4272                 log "lazystatfs lfs df failed to complete in 5s"
4273         fi
4274
4275         return $RC
4276 }
4277
4278 test_50a() {
4279         setup
4280         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4281         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4282
4283         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
4284
4285         cleanup || error "cleanup failed with rc $?"
4286 }
4287 run_test 50a "lazystatfs all servers available"
4288
4289 test_50b() {
4290         setup
4291         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4292         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4293
4294         # Wait for client to detect down OST
4295         stop_ost || error "Unable to stop OST1"
4296         wait_osc_import_state client ost DISCONN
4297         $LCTL dl
4298         log "OSCs should all be DISCONN"
4299
4300         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
4301
4302         umount_client $MOUNT || error "Unable to unmount client"
4303         stop_mds || error "Unable to stop MDS"
4304 }
4305 run_test 50b "lazystatfs all servers down"
4306
4307 test_50c() {
4308         start_mds || error "Unable to start MDS"
4309         start_ost || error "Unable to start OST1"
4310         start_ost2 || error "Unable to start OST2"
4311         mount_client $MOUNT || error "Unable to mount client"
4312         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4313         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4314
4315         # Wait for client to detect down OST
4316         stop_ost || error "Unable to stop OST1"
4317         wait_osc_import_state mds ost DISCONN
4318         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
4319
4320         umount_client $MOUNT || error "Unable to unmount client"
4321         stop_ost2 || error "Unable to stop OST2"
4322         stop_mds || error "Unable to stop MDS"
4323         #writeconf to remove all ost2 traces for subsequent tests
4324         writeconf_or_reformat
4325 }
4326 run_test 50c "lazystatfs one server down"
4327
4328 test_50d() {
4329         start_mds || error "Unable to start MDS"
4330         start_ost || error "Unable to start OST1"
4331         start_ost2 || error "Unable to start OST2"
4332         mount_client $MOUNT || error "Unable to mount client"
4333         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4334         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4335
4336         # Issue the statfs during the window where the client still
4337         # belives the OST to be available but it is in fact down.
4338         # No failure just a statfs which hangs for a timeout interval.
4339         stop_ost || error "Unable to stop OST1"
4340         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
4341
4342         umount_client $MOUNT || error "Unable to unmount client"
4343         stop_ost2 || error "Unable to stop OST2"
4344         stop_mds || error "Unable to stop MDS"
4345         #writeconf to remove all ost2 traces for subsequent tests
4346         writeconf_or_reformat
4347 }
4348 run_test 50d "lazystatfs client/server conn race"
4349
4350 test_50e() {
4351         local RC1
4352         local pid
4353
4354         reformat_and_config
4355         start_mds || error "Unable to start MDS"
4356         #first client should see only one ost
4357         start_ost || error "Unable to start OST1"
4358         wait_osc_import_state mds ost FULL
4359
4360         # Wait for client to detect down OST
4361         stop_ost || error "Unable to stop OST1"
4362         wait_osc_import_state mds ost DISCONN
4363
4364         mount_client $MOUNT || error "Unable to mount client"
4365         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
4366
4367         multiop_bg_pause $MOUNT _f
4368         RC1=$?
4369         pid=$!
4370
4371         if [ $RC1 -ne 0 ]; then
4372                 log "multiop failed $RC1"
4373         else
4374             kill -USR1 $pid
4375             sleep $(( $TIMEOUT+1 ))
4376             kill -0 $pid
4377             [ $? -ne 0 ] && error "process isn't sleep"
4378             start_ost || error "Unable to start OST1"
4379             wait $pid || error "statfs failed"
4380         fi
4381
4382         umount_client $MOUNT || error "Unable to unmount client"
4383         stop_ost || error "Unable to stop OST1"
4384         stop_mds || error "Unable to stop MDS"
4385 }
4386 run_test 50e "normal statfs all servers down"
4387
4388 test_50f() {
4389         local RC1
4390         local pid
4391         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
4392
4393         start_mds || error "Unable to start mds"
4394         #first client should see only one ost
4395         start_ost || error "Unable to start OST1"
4396         wait_osc_import_state mds ost FULL
4397
4398         start_ost2 || error "Unable to start OST2"
4399         wait_osc_import_state mds ost2 FULL
4400
4401         # Wait for client to detect down OST
4402         stop_ost2 || error "Unable to stop OST2"
4403
4404         wait_osc_import_state mds ost2 DISCONN
4405         mount_client $MOUNT || error "Unable to mount client"
4406         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
4407
4408         multiop_bg_pause $MOUNT _f
4409         RC1=$?
4410         pid=$!
4411
4412         if [ $RC1 -ne 0 ]; then
4413                 log "lazystatfs multiop failed $RC1"
4414         else
4415             kill -USR1 $pid
4416             sleep $(( $TIMEOUT+1 ))
4417             kill -0 $pid
4418             [ $? -ne 0 ] && error "process isn't sleep"
4419             start_ost2 || error "Unable to start OST2"
4420             wait $pid || error "statfs failed"
4421             stop_ost2 || error "Unable to stop OST2"
4422         fi
4423
4424         umount_client $MOUNT -f || error "Unable to unmount client"
4425         stop_ost || error "Unable to stop OST1"
4426         stop_mds || error "Unable to stop MDS"
4427         #writeconf to remove all ost2 traces for subsequent tests
4428         writeconf_or_reformat
4429 }
4430 run_test 50f "normal statfs one server in down"
4431
4432 test_50g() {
4433         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs"
4434         setup
4435         start_ost2 || error "Unable to start OST2"
4436         wait_osc_import_state mds ost2 FULL
4437         wait_osc_import_ready client ost2
4438
4439         if [[ $PERM_CMD == *"set_param -P"* ]]; then
4440                 local PARAM="osc.${FSNAME}-OST0001*.active"
4441         else
4442                 local PARAM="${FSNAME}-OST0001.osc.active"
4443         fi
4444
4445         $LFS setstripe -c -1 $DIR/$tfile || error "$LFS setstripe failed"
4446         do_facet mgs $PERM_CMD $PARAM=0 || error "Unable to deactivate OST"
4447
4448         umount_client $MOUNT || error "Unable to unmount client"
4449         mount_client $MOUNT || error "Unable to mount client"
4450         # This df should not cause a panic
4451         df -k $MOUNT
4452
4453         do_facet mgs $PERM_CMD $PARAM=1 || error "Unable to activate OST"
4454         rm -f $DIR/$tfile || error "unable to remove file $DIR/$tfile"
4455         umount_client $MOUNT || error "Unable to unmount client"
4456         stop_ost2 || error "Unable to stop OST2"
4457         stop_ost || error "Unable to stop OST1"
4458         stop_mds || error "Unable to stop MDS"
4459         #writeconf to remove all ost2 traces for subsequent tests
4460         writeconf_or_reformat
4461 }
4462 run_test 50g "deactivated OST should not cause panic"
4463
4464 # LU-642
4465 test_50h() {
4466         # prepare MDT/OST, make OSC inactive for OST1
4467         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs"
4468
4469         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
4470         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
4471                 error "tunefs OST1 failed"
4472         start_mds  || error "Unable to start MDT"
4473         start_ost  || error "Unable to start OST1"
4474         start_ost2 || error "Unable to start OST2"
4475         mount_client $MOUNT || error "client start failed"
4476
4477         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4478
4479         # activatate OSC for OST1
4480         set_persistent_param_and_check client            \
4481                 "osc.${FSNAME}-OST0000-osc-[!M]*.active" \
4482                 "${FSNAME}-OST0000.osc.active" 1
4483
4484         mkdir $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
4485         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2 ||
4486                 error "$LFS setstripe $DIR/$tdir/2 failed"
4487         sleep 1 && echo "create a file after OST1 is activated"
4488         # doing some io, shouldn't crash
4489         dd if=/dev/zero of=$DIR/$tdir/2/$tfile-io bs=1M count=10
4490
4491         # check OSC import is working
4492         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
4493                 error "some OSC imports are still not connected"
4494
4495         # cleanup
4496         rm -rf $DIR/$tdir
4497         umount_client $MOUNT || error "Unable to umount client"
4498         stop_ost2 || error "Unable to stop OST2"
4499         cleanup_nocli || error "cleanup_nocli failed with $?"
4500 }
4501 run_test 50h "LU-642: activate deactivated OST"
4502
4503 test_50i() {
4504         # prepare MDT/OST, make OSC inactive for OST1
4505         [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
4506
4507         load_modules
4508         [ $(facet_fstype mds2) == zfs ] && import_zpool mds2
4509         do_facet mds2 "$TUNEFS --param mdc.active=0 $(mdsdevname 2)" ||
4510                 error "tunefs MDT2 failed"
4511         start_mds  || error "Unable to start MDT"
4512         start_ost  || error "Unable to start OST1"
4513         start_ost2 || error "Unable to start OST2"
4514         mount_client $MOUNT || error "client start failed"
4515
4516         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4517
4518         if [[ $PERM_CMD == *"set_param -P"* ]]; then
4519                 $PERM_CMD mdc.${FSNAME}-MDT0001-mdc-*.active=0 &&
4520                         error "deactive MDC0 succeeds"
4521         else
4522                 $PERM_CMD ${FSNAME}-MDT0000.mdc.active=0 &&
4523                         error "deactive MDC0 succeeds"
4524         fi
4525
4526         # activate MDC for MDT2
4527         set_persistent_param_and_check client            \
4528                 "mdc.${FSNAME}-MDT0001-mdc-*.active" \
4529                 "${FSNAME}-MDT0001.mdc.active" 1
4530
4531         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
4532         if [ "$MDS1_VERSION" -ge $(version_code 2.7.60) ]
4533         then
4534                 wait_dne_interconnect
4535         fi
4536         $LFS mkdir -i1 $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
4537         # create some file
4538         createmany -o $DIR/$tdir/2/$tfile-%d 1 || error "create files failed"
4539
4540         rm -rf $DIR/$tdir/2 || error "unlink dir failed"
4541
4542         # deactivate MDC for MDT2
4543         set_persistent_param_and_check client           \
4544                 "mdc.${FSNAME}-MDT0001-mdc-*.active"    \
4545                 "${FSNAME}-MDT0001.mdc.active" 0
4546
4547         wait_osp_active mds ${FSNAME}-MDT0001 1 0
4548
4549         $LFS mkdir -i1 $DIR/$tdir/2 &&
4550                 error "mkdir $DIR/$tdir/2 succeeds after deactive MDT"
4551
4552         $LFS mkdir -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
4553                 error "mkdir $DIR/$tdir/striped_dir fails after deactive MDT2"
4554
4555         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
4556         [ $stripe_count -eq $((MDSCOUNT - 1)) ] ||
4557                 error "wrong $stripe_count != $((MDSCOUNT -1)) for striped_dir"
4558
4559         # cleanup
4560         umount_client $MOUNT || error "Unable to umount client"
4561         stop_mds
4562         stop_ost
4563         stop_ost 2
4564 }
4565 run_test 50i "activate deactivated MDT"
4566
4567 test_51() {
4568         local LOCAL_TIMEOUT=20
4569
4570         reformat
4571         setup_noconfig
4572         check_mount || error "check_mount failed"
4573
4574         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
4575         $LFS setstripe -c -1 $MOUNT/$tdir ||
4576                 error "$LFS setstripe -c -1 $MOUNT/$tdir failed"
4577         #define OBD_FAIL_MDS_REINT_DELAY         0x142
4578         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x142"
4579         touch $MOUNT/$tdir/$tfile &
4580         local pid=$!
4581         sleep 2
4582         start_ost2 || error "Unable to start OST1"
4583         wait $pid
4584         stop_ost2 || error "Unable to stop OST1"
4585         umount_client $MOUNT -f || error "unmount $MOUNT failed"
4586         cleanup_nocli || error "stop server failed"
4587         #writeconf to remove all ost2 traces for subsequent tests
4588         writeconf_or_reformat
4589 }
4590 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
4591
4592 copy_files_xattrs()
4593 {
4594         local node=$1
4595         local dest=$2
4596         local xattrs=$3
4597         shift 3
4598
4599         do_node $node mkdir -p $dest
4600         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
4601
4602         do_node $node  'tar cf - '$*' | tar xf - -C '$dest';
4603                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
4604         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
4605
4606         do_node $node 'getfattr -d -m "[a-z]*\\." '$*' > '$xattrs
4607         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
4608 }
4609
4610 diff_files_xattrs()
4611 {
4612         local node=$1
4613         local backup=$2
4614         local xattrs=$3
4615         shift 3
4616
4617         local backup2=${TMP}/backup2
4618
4619         do_node $node mkdir -p $backup2
4620         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
4621
4622         do_node $node  'tar cf - '$*' | tar xf - -C '$backup2';
4623                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
4624         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
4625
4626         do_node $node "diff -rq $backup $backup2"
4627         [ $? -eq 0 ] || { error "contents differ"; return 3; }
4628
4629         local xattrs2=${TMP}/xattrs2
4630         do_node $node 'getfattr -d -m "[a-z]*\\." '$*' > '$xattrs2
4631         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
4632
4633         do_node $node "diff $xattrs $xattrs2"
4634         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
4635
4636         do_node $node "rm -rf $backup2 $xattrs2"
4637         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
4638 }
4639
4640 test_52() {
4641         if [ "$mds1_FSTYPE" != ldiskfs ]; then
4642                 skip "ldiskfs only test"
4643         fi
4644
4645         start_mds || error "Unable to start MDS"
4646         start_ost || error "Unable to start OST1"
4647         mount_client $MOUNT || error "Unable to mount client"
4648
4649         local nrfiles=8
4650         local ost1mnt=$(facet_mntpt ost1)
4651         local ost1node=$(facet_active_host ost1)
4652         local ost1tmp=$TMP/conf52
4653         local loop
4654
4655         mkdir $DIR/$tdir || error "Unable to create $DIR/$tdir"
4656         touch $TMP/modified_first || error "Unable to create temporary file"
4657         local mtime=$(stat -c %Y $TMP/modified_first)
4658         do_node $ost1node "mkdir -p $ost1tmp &&
4659                            touch -m -d @$mtime $ost1tmp/modified_first" ||
4660                 error "Unable to create temporary file"
4661         sleep 1
4662
4663         $LFS setstripe -c -1 -S 1M $DIR/$tdir || error "$LFS setstripe failed"
4664
4665         for (( i=0; i < nrfiles; i++ )); do
4666                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c ||
4667                         error "multiop failed"
4668                 echo -n .
4669         done
4670         echo
4671
4672         # sync all the data and make sure no pending data on the client,
4673         # thus the SOM xattr would not be changed any more.
4674         cancel_lru_locks osc
4675
4676         # backup files
4677         echo backup files to $TMP/$tdir
4678         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
4679         copy_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
4680                 error "Unable to copy files"
4681
4682         umount_client $MOUNT || error "Unable to umount client"
4683         stop_ost || error "Unable to stop ost1"
4684
4685         echo mount ost1 as ldiskfs
4686         do_node $ost1node mkdir -p $ost1mnt || error "Unable to create $ost1mnt"
4687         if ! do_node $ost1node test -b $ost1_dev; then
4688                 loop="-o loop"
4689         fi
4690         do_node $ost1node mount -t "$ost1_FSTYPE" $loop $ost1_dev \
4691                 $ost1mnt ||
4692                 error "Unable to mount ost1 as ldiskfs"
4693
4694         # backup objects
4695         echo backup objects to $ost1tmp/objects
4696         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
4697                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
4698         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
4699                         $objects ||
4700                 error "Unable to copy objects"
4701
4702         # move objects to lost+found
4703         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
4704         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
4705
4706         do_node $ost1node "umount $ost1mnt" ||
4707                 error "Unable to umount ost1 as ldiskfs"
4708
4709         start_ost || error "Unable to start OST1"
4710         mount_client $MOUNT || error "Unable to mount client"
4711
4712         local REPAIRED=$(do_node $ost1node "$LCTL get_param \
4713                          -n osd-ldiskfs.$FSNAME-OST0000.oi_scrub" |
4714                          awk '/^lf_repa[ri]*ed/ { print $2 }')
4715         [ $REPAIRED -gt 0 ] ||
4716                 error "Some entry under /lost+found should be repaired"
4717
4718         # compare files
4719         diff_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
4720                 error "Unable to diff files"
4721
4722         rm -rf $TMP/$tdir $TMP/file_xattrs ||
4723                 error "Unable to delete temporary files"
4724         do_node $ost1node "rm -rf $ost1tmp" ||
4725                 error "Unable to delete temporary files"
4726         cleanup || error "cleanup failed with $?"
4727 }
4728 run_test 52 "check recovering objects from lost+found"
4729
4730 # Checks threads_min/max/started for some service
4731 #
4732 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
4733 # parameter pattern prefix like 'ost.*.ost'.
4734 thread_sanity() {
4735         local modname=$1
4736         local facet=$2
4737         local parampat=$3
4738         local opts=$4
4739         local basethr=$5
4740         local tmin
4741         local tmin2
4742         local tmax
4743         local tmax2
4744         local tstarted
4745         local paramp
4746         local msg="Insane $modname thread counts"
4747         local ncpts=$(check_cpt_number $facet)
4748         local nthrs
4749         shift 4
4750
4751         check_mount || return 41
4752
4753         # We need to expand $parampat, but it may match multiple parameters, so
4754         # we'll pick the first one
4755         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
4756                 error "Couldn't expand ${parampat}.threads_min parameter name"
4757                 return 22
4758         fi
4759
4760         # Remove the .threads_min part
4761         paramp=${paramp%.threads_min}
4762
4763         # Check for sanity in defaults
4764         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4765                echo 0)
4766         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4767                echo 0)
4768         tstarted=$(do_facet $facet "$LCTL get_param \
4769                                     -n ${paramp}.threads_started" || echo 0)
4770         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' ||
4771                 return $?
4772         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4773                 return $?
4774         nthrs=$(expr $tmax - $tmin)
4775         if [ $nthrs -lt $ncpts ]; then
4776                 nthrs=0
4777         else
4778                 nthrs=$ncpts
4779         fi
4780
4781         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
4782                 skip_env "module parameter forced $facet thread count"
4783
4784         # Check that we can change min/max
4785         do_facet $facet "$LCTL set_param \
4786                          ${paramp}.threads_min=$((tmin + nthrs))"
4787         do_facet $facet "$LCTL set_param \
4788                          ${paramp}.threads_max=$((tmax - nthrs))"
4789         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4790                 echo 0)
4791         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4792                 echo 0)
4793         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) &&
4794                             $tmax2 == ($tmax - $nthrs)))' || return $?
4795
4796         # Check that we can set min/max to the same value
4797         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4798                echo 0)
4799         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$tmin"
4800         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4801                 echo 0)
4802         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4803                 echo 0)
4804         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
4805
4806         # Check that we can't set max < min
4807         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$((tmin - 1))"
4808         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4809                 echo 0)
4810         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4811                 echo 0)
4812         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
4813
4814         # We need to ensure that we get the module options desired; to do this
4815         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
4816         LOAD_MODULES_REMOTE=true
4817         cleanup
4818         local oldvalue
4819         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
4820
4821         setmodopts -a $modname "$newvalue" oldvalue
4822
4823         setup
4824         check_mount || return 41
4825
4826         # Restore previous setting of MODOPTS_*
4827         setmodopts $modname "$oldvalue"
4828
4829         (( $MDS1_VERSION > $(version_code 2.12.52.91) )) || {
4830                 echo "skip interop for MDS < v2_12_52-91-g183cb1e3cdd2"
4831                 return 0
4832         }
4833
4834         # Check that $opts took
4835         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4836                 echo 0)
4837         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4838                 echo 0)
4839         tstarted=$(do_facet $facet \
4840                    "$LCTL get_param -n ${paramp}.threads_started" || echo 0)
4841         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4842                 return $?
4843 }
4844
4845 test_53a() {
4846         setup
4847         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
4848         cleanup || error "cleanup failed with rc $?"
4849 }
4850 run_test 53a "check OSS thread count params"
4851
4852 test_53b() {
4853         setup
4854         thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
4855         cleanup || error "cleanup failed with $?"
4856 }
4857 run_test 53b "check MDS thread count params"
4858
4859 test_54a() {
4860         if [ "$mds1_FSTYPE" != ldiskfs ]; then
4861                 skip "ldiskfs only test"
4862         fi
4863
4864         do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p ||
4865                 error "llverdev failed with rc=$?"
4866         reformat_and_config
4867 }
4868 run_test 54a "test llverdev and partial verify of device"
4869
4870 test_54b() {
4871         if [ "$mds1_FSTYPE" != ldiskfs ]; then
4872                 skip "ldiskfs only test"
4873         fi
4874
4875         setup
4876         run_llverfs $MOUNT -p || error "llverfs failed with rc=$?"
4877         cleanup || error "cleanup failed with rc=$?"
4878 }
4879 run_test 54b "test llverfs and partial verify of filesystem"
4880
4881 lov_objid_size()
4882 {
4883         local max_ost_index=$1
4884
4885         echo -n $(((max_ost_index + 1) * 8))
4886 }
4887
4888 test_55() {
4889         if [ "$mds1_FSTYPE" != ldiskfs ]; then
4890                 skip "ldiskfs only test"
4891         fi
4892
4893         local mdsdev=$(mdsdevname 1)
4894         local mdsvdev=$(mdsvdevname 1)
4895
4896         for i in 1023 2048
4897         do
4898                 if ! combined_mgs_mds; then
4899                         stop_mgs || error "stopping MGS service failed"
4900                         format_mgs || error "formatting MGT failed"
4901                 fi
4902                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
4903                         $mdsvdev || exit 10
4904                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
4905                         --reformat $(ostdevname 1) $(ostvdevname 1)
4906                 setup_noconfig
4907                 stopall
4908                 setup_noconfig
4909                 sync
4910
4911                 echo checking size of lov_objid for ost index $i
4912                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" |
4913                                  grep ^User | awk -F 'Size: ' '{print $2}')
4914                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
4915                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
4916                 else
4917                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
4918                 fi
4919                 stopall
4920         done
4921
4922         reformat_and_config
4923 }
4924 run_test 55 "check lov_objid size"
4925
4926 test_56a() {
4927         local mds_journal_size_orig=$MDSJOURNALSIZE
4928         local n
4929
4930         MDSJOURNALSIZE=16
4931
4932         formatall
4933         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
4934                 $(ostdevname 1) $(ostvdevname 1)
4935         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
4936                 $(ostdevname 2) $(ostvdevname 2)
4937
4938         start_mgsmds
4939         start_ost || error "Unable to start first ost (idx 10000)"
4940         start_ost2 || error "Unable to start second ost (idx 1000)"
4941         mount_client $MOUNT || error "Unable to mount client"
4942         echo ok
4943         $LFS osts
4944
4945         # test instantiating PFL components with sparse index LU-15513
4946         mkdir -p $MOUNT/$tdir
4947         $LFS setstripe -E 4M -c 1 -E 1G -c 4 -S4M -E eof -c -1 $MOUNT/$tdir
4948         dd if=/dev/zero of=$MOUNT/$tdir/$tfile bs=4K count=1 seek=10k ||
4949                 error "dd to second component failed"
4950
4951         if [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
4952            [[ "$MDS1_VERSION" -ge $(version_code 2.5.4) &&
4953               "$MDS1_VERSION" -lt $(version_code 2.5.11) ]]; then
4954                 wait_osc_import_state mds ost1 FULL
4955                 wait_osc_import_state mds ost2 FULL
4956                 $LFS setstripe --stripe-count=-1 $DIR/$tfile ||
4957                         error "Unable to setstripe $DIR/$tfile"
4958                 n=$($LFS getstripe --stripe-count $DIR/$tfile)
4959                 [ "$n" -eq 2 ] || error "Stripe count not two: $n"
4960                 rm $DIR/$tfile
4961         fi
4962
4963         stopall
4964         MDSJOURNALSIZE=$mds_journal_size_orig
4965         reformat_and_config
4966 }
4967 run_test 56a "check big OST indexes and out-of-index-order start"
4968
4969 cleanup_56b() {
4970         trap 0
4971
4972         umount_client $MOUNT -f || error "unmount client failed"
4973         stop mds1
4974         stop mds2
4975         stop mds3
4976         stopall
4977         reformat_and_config
4978 }
4979
4980 test_56b() {
4981         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
4982
4983         trap cleanup_56b EXIT RETURN ERR
4984         stopall
4985
4986         if ! combined_mgs_mds ; then
4987                 format_mgs
4988                 start_mgs
4989         fi
4990
4991         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
4992                 $(mdsdevname 1) $(mdsvdevname 1)
4993         add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
4994                 $(mdsdevname 2) $(mdsvdevname 2)
4995         add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=1000 --reformat \
4996                 $(mdsdevname 3) $(mdsvdevname 3)
4997         format_ost 1
4998         format_ost 2
4999
5000         start_mdt 1 || error "MDT 1 (idx 0) start failed"
5001         start_mdt 2 || error "MDT 2 (idx 1) start failed"
5002         start_mdt 3 || error "MDT 3 (idx 1000) start failed"
5003         start_ost || error "Unable to start first ost"
5004         start_ost2 || error "Unable to start second ost"
5005
5006         do_nodes $(comma_list $(mdts_nodes)) \
5007                 "$LCTL set_param mdt.*.enable_remote_dir=1 \
5008                 mdt.*.enable_remote_dir_gid=-1"
5009
5010         mount_client $MOUNT || error "Unable to mount client"
5011
5012         $LFS mkdir -c3 $MOUNT/$tdir || error "failed to make testdir"
5013
5014         echo "This is test file 1!" > $MOUNT/$tdir/$tfile.1 ||
5015                 error "failed to make test file 1"
5016         echo "This is test file 2!" > $MOUNT/$tdir/$tfile.2 ||
5017                 error "failed to make test file 2"
5018         echo "This is test file 1000!" > $MOUNT/$tdir/$tfile.1000 ||
5019                 error "failed to make test file 1000"
5020
5021         rm -rf $MOUNT/$tdir || error "failed to remove testdir"
5022
5023         $LFS mkdir -i1000 $MOUNT/$tdir.1000 ||
5024                 error "create remote dir at idx 1000 failed"
5025
5026         output=$($LFS df)
5027         echo "=== START lfs df OUTPUT ==="
5028         echo -e "$output"
5029         echo "==== END lfs df OUTPUT ===="
5030
5031         mdtcnt=$(echo -e "$output" | grep $FSNAME-MDT | wc -l)
5032         ostcnt=$(echo -e "$output" | grep $FSNAME-OST | wc -l)
5033
5034         echo "lfs df returned mdt count $mdtcnt and ost count $ostcnt"
5035         [ $mdtcnt -eq 3 ] || error "lfs df returned wrong mdt count"
5036         [ $ostcnt -eq 2 ] || error "lfs df returned wrong ost count"
5037
5038         echo "This is test file 1!" > $MOUNT/$tdir.1000/$tfile.1 ||
5039                 error "failed to make test file 1"
5040         echo "This is test file 2!" > $MOUNT/$tdir.1000/$tfile.2 ||
5041                 error "failed to make test file 2"
5042         echo "This is test file 1000!" > $MOUNT/$tdir.1000/$tfile.1000 ||
5043                 error "failed to make test file 1000"
5044         rm -rf $MOUNT/$tdir.1000 || error "failed to remove remote_dir"
5045
5046         output=$($LFS mdts)
5047         echo "=== START lfs mdts OUTPUT ==="
5048         echo -e "$output"
5049         echo "==== END lfs mdts OUTPUT ===="
5050
5051         echo -e "$output" | grep -v "MDTS:" | awk '{print $1}' |
5052                 sed 's/://g' > $TMP/mdts-actual.txt
5053         sort $TMP/mdts-actual.txt -o $TMP/mdts-actual.txt
5054
5055         echo -e "0\n1\n1000" > $TMP/mdts-expected.txt
5056
5057         diff $TMP/mdts-expected.txt $TMP/mdts-actual.txt
5058         result=$?
5059
5060         rm $TMP/mdts-expected.txt $TMP/mdts-actual.txt
5061
5062         [ $result -eq 0 ] || error "target_obd proc file is incorrect!"
5063 }
5064 run_test 56b "test target_obd correctness with nonconsecutive MDTs"
5065
5066 test_57a() { # bug 22656
5067         do_rpc_nodes $(facet_active_host ost1) load_modules_local
5068         local NID=$(do_facet ost1 "$LCTL get_param nis" |
5069                     tail -1 | awk '{print $1}')
5070         writeconf_or_reformat
5071         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
5072         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" ||
5073                 error "tunefs failed"
5074         start_mgsmds
5075         start_ost && error "OST registration from failnode should fail"
5076         cleanup
5077 }
5078 run_test 57a "initial registration from failnode should fail (should return errs)"
5079
5080 test_57b() {
5081         do_rpc_nodes $(facet_active_host ost1) load_modules_local
5082         local NID=$(do_facet ost1 "$LCTL get_param nis" |
5083                     tail -1 | awk '{print $1}')
5084         writeconf_or_reformat
5085         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
5086         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" ||
5087                 error "tunefs failed"
5088         start_mgsmds
5089         start_ost || error "OST registration from servicenode should not fail"
5090         cleanup
5091 }
5092 run_test 57b "initial registration from servicenode should not fail"
5093
5094 count_osts() {
5095         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
5096 }
5097
5098 test_58() { # bug 22658
5099         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
5100         setup_noconfig
5101         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5102         createmany -o $DIR/$tdir/$tfile-%d 100
5103         unlinkmany $DIR/$tdir/$tfile-%d 100
5104         stop_mds || error "Unable to stop MDS"
5105
5106         local MNTDIR=$(facet_mntpt $SINGLEMDS)
5107         local devname=$(mdsdevname ${SINGLEMDS//mds/})
5108
5109         # remove all files from the OBJECTS dir
5110         mount_fstype $SINGLEMDS
5111
5112         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
5113
5114         unmount_fstype $SINGLEMDS
5115         # restart MDS with missing llog files
5116         start_mds || error "unable to start MDS"
5117         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
5118         cleanup
5119 }
5120 run_test 58 "missing llog files must not prevent MDT from mounting"
5121
5122 test_59() {
5123         start_mgsmds >> /dev/null
5124         local C1=$(count_osts)
5125         if [ $C1 -eq 0 ]; then
5126                 start_ost >> /dev/null
5127                 C1=$(count_osts)
5128         fi
5129         stopall
5130         echo "original ost count: $C1 (expect > 0)"
5131         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
5132         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
5133         local C2=$(count_osts)
5134         echo "after mdt writeconf count: $C2 (expect 0)"
5135         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
5136         echo "OST start without writeconf should fail:"
5137         start_ost >> /dev/null &&
5138                 error "OST start without writeconf didn't fail"
5139         echo "OST start with writeconf should succeed:"
5140         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
5141         local C3=$(count_osts)
5142         echo "after ost writeconf count: $C3 (expect 1)"
5143         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
5144         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
5145         local C4=$(count_osts)
5146         echo "after ost2 writeconf count: $C4 (expect 2)"
5147         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
5148         stop_ost2 >> /dev/null
5149         cleanup_nocli >> /dev/null
5150         #writeconf to remove all ost2 traces for subsequent tests
5151         writeconf_or_reformat
5152 }
5153 run_test 59 "writeconf mount option"
5154
5155 test_60a() { # LU-471
5156         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5157                 skip "ldiskfs only test"
5158         fi
5159
5160         local num
5161
5162         for num in $(seq $MDSCOUNT); do
5163                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
5164                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
5165                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
5166                         exit 10
5167         done
5168
5169         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
5170         [ ${PIPESTATUS[0]} -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
5171
5172         # MDT default has dirdata feature
5173         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
5174         # we disable uninit_bg feature
5175         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
5176         # we set stride extended options
5177         echo $dump | grep stride > /dev/null || error "stride is not set"
5178         stop_mds
5179         reformat_and_config
5180 }
5181 run_test 60a "check mkfs.lustre --mkfsoptions -E -O options setting"
5182
5183 test_60b() {
5184         [[ "$mds1_FSTYPE" == ldiskfs ]] || skip "ldiskfs only test"
5185
5186         local features=$(do_facet $SINGLEMDS $DUMPE2FS $(mdsdevname 1) |
5187                          grep features)
5188         [ ${PIPESTATUS[0]} -eq 0 ] || error "$DUMPE2FS $(mdsdevname 1) failed"
5189
5190         echo $features
5191         # ea_inode feature should be enabled by default for MDTs
5192         [[ "$features" =~ "ea_inode" ]] || error "ea_inode is not set"
5193         # large_dir feature should be enabled by default for MDTs
5194         [[ "$features" =~ "large_dir" ]] || error "large_dir is not set"
5195 }
5196 run_test 60b "check mkfs.lustre MDT default features"
5197
5198 test_61a() { # LU-80
5199         local lxattr=$(large_xattr_enabled)
5200
5201         (( "$MDS1_VERSION" >= $(version_code 2.1.53) )) ||
5202                 skip "Need MDS version at least 2.1.53 for large_xattr"
5203
5204         if [[ "$mds1_FSTYPE" == ldiskfs ]] && ! large_xattr_enabled; then
5205                 lxattr=true
5206
5207                 for ((num=1; num <= $MDSCOUNT; num++)); do
5208                         do_facet mds${num} $TUNE2FS -O ea_inode \
5209                                 $(mdsdevname $num) ||
5210                                 error "tune2fs on mds $num failed"
5211                 done
5212         fi
5213
5214         setup || error "setting up the filesystem failed"
5215         client_up || error "starting client failed"
5216
5217         local file=$DIR/$tfile
5218         touch $file || error "touch $file failed"
5219
5220         local large_value="$(generate_string $(max_xattr_size))"
5221         local small_value="bar"
5222
5223         local name="trusted.big"
5224         log "save large xattr of $(max_xattr_size) bytes on $name on $file"
5225         setfattr -n $name -v $large_value $file ||
5226                 error "saving $name on $file failed"
5227
5228         local new_value=$(get_xattr_value $name $file)
5229         [[ "$new_value" != "$large_value" ]] &&
5230                 error "$name different after saving"
5231
5232         log "shrink value of $name on $file"
5233         setfattr -n $name -v $small_value $file ||
5234                 error "shrinking value of $name on $file failed"
5235
5236         new_value=$(get_xattr_value $name $file)
5237         [[ "$new_value" != "$small_value" ]] &&
5238                 error "$name different after shrinking"
5239
5240         log "grow value of $name on $file"
5241         setfattr -n $name -v $large_value $file ||
5242                 error "growing value of $name on $file failed"
5243
5244         new_value=$(get_xattr_value $name $file)
5245         [[ "$new_value" != "$large_value" ]] &&
5246                 error "$name different after growing"
5247
5248         log "check value of $name on $file after remounting MDS"
5249         fail $SINGLEMDS
5250         new_value=$(get_xattr_value $name $file)
5251         [[ "$new_value" != "$large_value" ]] &&
5252                 error "$name different after remounting MDS"
5253
5254         log "remove large xattr $name from $file"
5255         setfattr -x $name $file || error "removing $name from $file failed"
5256
5257         if $lxattr && [ "$mds1_FSTYPE" == ldiskfs ]; then
5258                 stopall || error "stopping for e2fsck run"
5259                 for num in $(seq $MDSCOUNT); do
5260                         run_e2fsck $(facet_active_host mds$num) \
5261                                 $(mdsdevname $num) "-y" ||
5262                                 error "e2fsck MDT$num failed"
5263                 done
5264                 setup_noconfig || error "remounting the filesystem failed"
5265         fi
5266
5267         # need to delete this file to avoid problems in other tests
5268         rm -f $file
5269         cleanup || error "stopping systems failed"
5270 }
5271 run_test 61a "large xattr"
5272
5273 test_61b() { # LU-80
5274         local lxattr=$(large_xattr_enabled)
5275
5276         (( $MDS1_VERSION >= $(version_code 2.15.51) )) ||
5277                 skip "Need MDS version at least 2.15.51 for large_xattr fix"
5278
5279         [[ "$mds1_FSTYPE" == "ldiskfs" ]] || skip "ldiskfs specific bug"
5280
5281         if ! large_xattr_enabled; then
5282                 lxattr=true
5283
5284                 for (( num=1; num <= $MDSCOUNT; num++ )); do
5285                         do_facet mds${num} $TUNE2FS -O ea_inode \
5286                                 $(mdsdevname $num) ||
5287                                 error "tune2fs on mds $num failed"
5288                 done
5289         fi
5290
5291         setup || error "setting up the filesystem failed"
5292         client_up || error "starting client failed"
5293
5294         local _file=$MOUNT/panda
5295         local large_value="$(generate_string $(max_xattr_size))"
5296         local name="trusted.big"
5297
5298         touch ${_file} || error "touch ${_file} failed"
5299         setfattr -n $name -v $large_value ${_file} ||
5300                 error "saving $name on $file failed"
5301
5302         MDT_DEV="${FSNAME}-MDT0000"
5303         MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
5304
5305         stopall || error "stopping for e2fsck run"
5306
5307
5308         ino=$(do_facet $SINGLEMDS "$DEBUGFS -R 'stat /ROOT/panda' \
5309                 ${MDT_DEVNAME} | grep trusted.big")
5310         ino=$(echo "${ino}" | awk '{print $2;}')
5311         echo "large ea "${ino}
5312
5313         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"ln $ino /lost+found\\\" \
5314                  ${MDT_DEVNAME}"
5315
5316         setup_noconfig || error "remounting the filesystem failed"
5317
5318         do_facet $SINGLEMDS $LCTL lfsck_start -M ${MDT_DEV} -t namespace || {
5319                 error "can't start lfsck namespace"
5320         }
5321
5322         sleep 5
5323         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
5324                 mdd.${MDT_DEV}.lfsck_namespace |
5325                 awk '/^status/ { print \\\$2 }'" "completed" 32 || {
5326                 error "(2) unexpected status"
5327         }
5328
5329         stopall || error "stopping for e2fsck run"
5330         for num in $(seq $MDSCOUNT); do
5331                 run_e2fsck $(facet_active_host mds$num) \
5332                         $(mdsdevname $num) "-y" ||
5333                         error "e2fsck MDT$num failed"
5334         done
5335         setup_noconfig || error "remounting the filesystem failed"
5336
5337         # need to delete this file to avoid problems in other tests
5338         rm -f $file
5339         cleanup || error "stopping systems failed"
5340 }
5341 run_test 61b "large xattr"
5342
5343 test_62() {
5344         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5345                 skip "ldiskfs only test"
5346         fi
5347         [[ "$MDS1_VERSION" -ge $(version_code 2.2.51) ]] ||
5348                 skip "Need MDS version at least 2.2.51"
5349
5350         # MRP-118
5351         local mdsdev=$(mdsdevname 1)
5352         local ostdev=$(ostdevname 1)
5353
5354         echo "disable journal for mds"
5355         do_facet mds1 $TUNE2FS -O ^has_journal $mdsdev || error "tune2fs failed"
5356         start_mds && error "MDT start should fail"
5357         echo "disable journal for ost"
5358         do_facet ost1 $TUNE2FS -O ^has_journal $ostdev || error "tune2fs failed"
5359         start_ost && error "OST start should fail"
5360         cleanup || error "cleanup failed with rc $?"
5361         reformat_and_config
5362 }
5363 run_test 62 "start with disabled journal"
5364
5365 test_63() {
5366         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5367                 skip "ldiskfs only test"
5368         fi
5369
5370         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ldiskfs
5371         local inode_slab=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
5372                            awk '/ldiskfs_inode_cache/ { print $5 / $6 }')
5373         if [ -z "$inode_slab" ]; then
5374                 skip "ldiskfs module has not been loaded"
5375         fi
5376
5377         if grep -q "CONFIG_DEBUG_LOCK_ALLOC=y" /boot/config-$(uname -r); then
5378                 skip "test is not compatible with CONFIG_DEBUG_LOCK_ALLOC=y"
5379         fi
5380
5381         echo "$inode_slab ldiskfs inodes per page"
5382         [ "${inode_slab%.*}" -ge "3" ] && return 0
5383
5384         # If kmalloc-128 is also 1 per page - this is a debug kernel
5385         # and so this is not an error.
5386         local kmalloc128=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
5387                            awk '/^(dma-kmalloc|size)-128 / { print $5 / $6 }')
5388         # 32 128-byte chunks in 4k
5389         [ "${kmalloc128%.*}" -lt "32" ] ||
5390                 error "ldiskfs inode too big, only $inode_slab objs/page, " \
5391                       "kmalloc128 = $kmalloc128 objs/page"
5392 }
5393 run_test 63 "Verify each page can at least hold 3 ldiskfs inodes"
5394
5395 test_64() {
5396         start_mds || error "unable to start MDS"
5397         start_ost || error "Unable to start OST1"
5398         start_ost2 || error "Unable to start second ost"
5399         mount_client $MOUNT || error "Unable to mount client"
5400         stop_ost2 || error "Unable to stop second ost"
5401         echo "$LFS df"
5402         $LFS df --lazy
5403         umount_client $MOUNT -f || error "unmount $MOUNT failed"
5404         cleanup_nocli || error "cleanup_nocli failed with $?"
5405         #writeconf to remove all ost2 traces for subsequent tests
5406         writeconf_or_reformat
5407 }
5408 run_test 64 "check lfs df --lazy "
5409
5410 test_65() { # LU-2237
5411         # Currently, the test is only valid for ldiskfs backend
5412         [ "$mds1_FSTYPE" != ldiskfs ] &&
5413                 skip "ldiskfs only test"
5414
5415         local devname=$(mdsdevname ${SINGLEMDS//mds/})
5416         local brpt=$(facet_mntpt brpt)
5417         local opts=""
5418
5419         if ! do_facet $SINGLEMDS "test -b $devname"; then
5420                 opts="-o loop"
5421         fi
5422
5423         stop_mds || error "Unable to stop MDS"
5424         local obj=$(do_facet $SINGLEMDS \
5425                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
5426                     grep Inode)
5427         if [ -z "$obj" ]; then
5428                 # The MDT may be just re-formatted, mount the MDT for the
5429                 # first time to guarantee the "last_rcvd" file is there.
5430                 start_mds || error "fail to mount the MDS for the first time"
5431                 stop_mds || error "Unable to stop MDS"
5432         fi
5433
5434         # remove the "last_rcvd" file
5435         do_facet $SINGLEMDS "mkdir -p $brpt"
5436         do_facet $SINGLEMDS \
5437                 "mount -t $mds1_FSTYPE $opts $devname $brpt"
5438         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
5439         do_facet $SINGLEMDS "$UMOUNT $brpt"
5440
5441         # restart MDS, the "last_rcvd" file should be recreated.
5442         start_mds || error "fail to restart the MDS"
5443         stop_mds || error "Unable to stop MDS"
5444         obj=$(do_facet $SINGLEMDS \
5445               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
5446         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
5447 }
5448 run_test 65 "re-create the lost last_rcvd file when server mount"
5449
5450 test_66() {
5451         [[ "$MGS_VERSION" -ge $(version_code 2.3.59) ]] ||
5452                 skip "Need MGS version at least 2.3.59"
5453
5454         check_versions || skip "do not replace_nids with mismatched versions"
5455
5456         setup
5457         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
5458         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
5459
5460         # add EXCLUDE records to config log, they are not to be
5461         # removed by lctl replace_nids
5462         set_conf_param_and_check mds                                    \
5463             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
5464             "$FSNAME-OST0000.osc.active"                                \
5465             "0"
5466
5467         echo "replace_nids should fail if MDS, OSTs and clients are UP"
5468         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
5469                 error "replace_nids fail"
5470
5471         umount_client $MOUNT || error "unmounting client failed"
5472         echo "replace_nids should fail if MDS and OSTs are UP"
5473         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
5474                 error "replace_nids fail"
5475
5476         stop_ost || error "Unable to stop OST1"
5477         echo "replace_nids should fail if MDS is UP"
5478         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
5479                 error "replace_nids fail"
5480
5481         stop_mds || error "stopping mds failed"
5482
5483         if combined_mgs_mds; then
5484                 start_mdt 1 "-o nosvc" ||
5485                         error "starting mds with nosvc option failed"
5486         fi
5487
5488         echo "command should accept two parameters"
5489         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
5490                 error "command should accept two params"
5491
5492         echo "correct device name should be passed"
5493         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
5494                 error "wrong devname"
5495
5496         echo "wrong nids list should not destroy the system"
5497         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
5498                 error "wrong parse"
5499         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "asdfasdf, asdfadf" &&
5500                 error "wrong parse"
5501
5502         echo "replace OST nid"
5503         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
5504                 error "replace nids failed"
5505
5506         echo "command should accept two parameters"
5507         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
5508                 error "command should accept two params"
5509
5510         echo "wrong nids list should not destroy the system"
5511         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
5512                 error "wrong parse"
5513
5514         local FAKE_NIDS="192.168.0.112@tcp1,192.168.0.112@tcp2"
5515         local FAKE_FAILOVER="192.168.0.113@tcp1,192.168.0.113@tcp2"
5516         local NIDS_AND_FAILOVER="$MDS_NID,$FAKE_NIDS:$FAKE_FAILOVER"
5517         echo "set NIDs with failover"
5518         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $NIDS_AND_FAILOVER ||
5519                 error "replace nids failed"
5520
5521
5522         echo "replace MDS nid"
5523         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
5524                 error "replace nids failed"
5525
5526         if ! combined_mgs_mds ; then
5527                 stop_mgs
5528         else
5529                 stop_mds || error "Unable to stop MDS"
5530         fi
5531
5532         start_mgsmds || error "start mgsmds failed"
5533         set_conf_param_and_check mds                                    \
5534             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
5535             "$FSNAME-OST0000.osc.active"                                \
5536             "1"
5537         start_ost || error "unable to start OST"
5538         mount_client $MOUNT || error "mount client failed"
5539
5540         check_mount || error "error after nid replace"
5541         cleanup || error "cleanup failed"
5542         reformat_and_config
5543 }
5544 run_test 66 "replace nids"
5545
5546 test_67() { #LU-2950
5547         local legacy="$TMP/legacy_lnet_config"
5548         local new="$TMP/new_routes_test"
5549         local out="$TMP/config_out_file"
5550         local verify="$TMP/conv_verify"
5551         local verify_conf="$TMP/conf_verify"
5552
5553         # Create the legacy file that will be run through the
5554         # lustre_routes_conversion script
5555         cat <<- LEGACY_LNET_CONFIG > $legacy
5556                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
5557                 tcp2 54 10.1.3.2@tcp;
5558                 tcp3 10.3.4.3@tcp:3;
5559                 tcp4 10.3.3.4@tcp;
5560         LEGACY_LNET_CONFIG
5561
5562         # Create the verification file to verify the output of
5563         # lustre_routes_conversion script against.
5564         cat <<- VERIFY_LNET_CONFIG > $verify
5565                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
5566                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
5567                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
5568                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
5569                 tcp4: { gateway: 10.3.3.4@tcp }
5570         VERIFY_LNET_CONFIG
5571
5572         # Create the verification file to verify the output of
5573         # lustre_routes_config script against
5574         cat <<- VERIFY_LNET_CONFIG > $verify_conf
5575                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
5576                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
5577                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
5578                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
5579                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
5580         VERIFY_LNET_CONFIG
5581
5582         $LUSTRE_ROUTES_CONVERSION $legacy $new > /dev/null
5583         if [ -f $new ]; then
5584                 # verify the conversion output
5585                 cmp -s $new $verify > /dev/null
5586                 if [ $? -eq 1 ]; then
5587                         error "routes conversion failed"
5588                 fi
5589
5590                 lustre_routes_config --dry-run --verbose $new > $out
5591                 # check that the script succeeded
5592                 cmp -s $out $verify_conf > /dev/null
5593                 if [ $? -eq 1 ]; then
5594                         error "routes config failed"
5595                 fi
5596         else
5597                 error "routes conversion test failed"
5598         fi
5599         # remove generated files
5600         rm -f $new $legacy $verify $verify_conf $out
5601 }
5602 run_test 67 "test routes conversion and configuration"
5603
5604 test_68() {
5605         local fid
5606         local seq
5607         local START
5608         local END
5609
5610         [ "$MDS1_VERSION" -ge $(version_code 2.4.53) ] ||
5611                 skip "Need MDS version at least 2.4.53"
5612
5613         umount_client $MOUNT || error "umount client failed"
5614
5615         start_mgsmds
5616         start_ost
5617
5618         # START-END - the sequences we'll be reserving
5619         START=$(do_facet $SINGLEMDS \
5620                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
5621         END=$((START + (1 << 30)))
5622         do_facet $SINGLEMDS \
5623                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
5624
5625         # reset the sequences MDT0000 has already assigned
5626         do_facet $SINGLEMDS \
5627                 $LCTL set_param seq.srv*MDT0000.space=clear
5628
5629         # remount to let the client allocate new sequence
5630         mount_client $MOUNT || error "mount client failed"
5631
5632         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
5633         do_facet $SINGLEMDS \
5634                 $LCTL get_param seq.srv*MDT0000.space
5635         $LFS path2fid $DIR/$tfile
5636
5637         local old_ifs="$IFS"
5638         IFS='[:]'
5639         fid=($($LFS path2fid $DIR/$tfile))
5640         IFS="$old_ifs"
5641         let seq=${fid[1]}
5642
5643         if [[ $seq < $END ]]; then
5644                 error "used reserved sequence $seq?"
5645         fi
5646         cleanup || error "cleanup failed with $?"
5647 }
5648 run_test 68 "be able to reserve specific sequences in FLDB"
5649
5650 # Test 69: is about the total number of objects ever created on an OST.
5651 # so that when it is reformatted the normal MDS->OST orphan recovery won't
5652 # just "precreate" the missing objects. In the past it might try to recreate
5653 # millions of objects after an OST was reformatted
5654 test_69() {
5655         [[ "$MDS1_VERSION" -lt $(version_code 2.4.2) ]] &&
5656                 skip "Need MDS version at least 2.4.2"
5657
5658         [[ "$MDS1_VERSION" -ge $(version_code 2.4.50) ]] &&
5659         [[ "$MDS1_VERSION" -lt $(version_code 2.5.0) ]] &&
5660                 skip "Need MDS version at least 2.5.0"
5661
5662         setup
5663         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5664         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param \
5665                 seq.*OST*-super.width=$DATA_SEQ_MAX_WIDTH
5666
5667         # use OST0000 since it probably has the most creations
5668         local OSTNAME=$(ostname_from_index 0)
5669         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
5670         local last_id=$(do_facet mds1 $LCTL get_param -n \
5671                         osp.$mdtosc_proc1.prealloc_last_id)
5672
5673         # Want to have OST LAST_ID over 5 * OST_MAX_PRECREATE to
5674         # verify that the LAST_ID recovery is working properly. If
5675         # not, then the OST will refuse to allow the MDS connect
5676         # because the LAST_ID value is too different from the MDS
5677         #define OST_MAX_PRECREATE=20000
5678         local ost_max_pre=20000
5679         local num_create=$(( ost_max_pre * 5 + 1 - last_id))
5680
5681         # If the LAST_ID is already over 5 * OST_MAX_PRECREATE, we don't
5682         # need to create any files. So, skip this section.
5683         if [ $num_create -gt 0 ]; then
5684                 # Check the number of inodes available on OST0
5685                 local files=0
5686                 local ifree=$($LFS df -i $MOUNT |
5687                         awk '/OST0000/ { print $4 }'; exit ${PIPESTATUS[0]})
5688                 log "On OST0, $ifree inodes available. Want $num_create. rc=$?"
5689
5690                 $LFS setstripe -i 0 $DIR/$tdir ||
5691                         error "$LFS setstripe -i 0 $DIR/$tdir failed"
5692                 if [ $ifree -lt 10000 ]; then
5693                         files=$(( ifree - 50 ))
5694                 else
5695                         files=10000
5696                 fi
5697
5698                 local j=$((num_create / files + 1))
5699                 for i in $(seq 1 $j); do
5700                         createmany -o $DIR/$tdir/$tfile-$i- $files ||
5701                                 error "createmany fail create $files files: $?"
5702                         unlinkmany $DIR/$tdir/$tfile-$i- $files ||
5703                                 error "unlinkmany failed unlink $files files"
5704                 done
5705         fi
5706
5707         # delete all of the files with objects on OST0 so the
5708         # filesystem is not inconsistent later on
5709         $LFS find $MOUNT --ost 0 -print0 | xargs -0 rm
5710
5711         umount_client $MOUNT || error "umount client failed"
5712         stop_ost || error "OST0 stop failure"
5713         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
5714                 $(ostdevname 1) $(ostvdevname 1) ||
5715                 error "reformat and replace $ostdev failed"
5716         start_ost || error "OST0 restart failure"
5717         wait_osc_import_state mds ost FULL
5718
5719         mount_client $MOUNT || error "mount client failed"
5720         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
5721         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
5722         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
5723
5724         local iused=$($LFS df -i $MOUNT |
5725                 awk '/OST0000/ { print $3 }'; exit ${PIPESTATUS[0]})
5726         log "On OST0, $iused used inodes rc=$?"
5727         [ $iused -ge $((ost_max_pre + 1000)) ] &&
5728                 error "OST replacement created too many inodes; $iused"
5729         cleanup || error "cleanup failed with $?"
5730 }
5731 run_test 69 "replace an OST with the same index"
5732
5733 test_70a() {
5734         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5735         local MDTIDX=1
5736
5737         cleanup || error "cleanup failed with $?"
5738
5739         start_mdt 1 || error "MDT0 start fail"
5740
5741         start_ost || error "OST0 start fail"
5742         for num in $(seq 2 $MDSCOUNT); do
5743                 start_mdt $num || return
5744         done
5745
5746         mount_client $MOUNT || error "mount client fails"
5747
5748         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
5749
5750         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5751                 error "create remote dir fail"
5752
5753         rm -rf $DIR/$tdir || error "delete dir fail"
5754         cleanup || error "cleanup failed with $?"
5755 }
5756 run_test 70a "start MDT0, then OST, then MDT1"
5757
5758 test_70b() {
5759         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5760         local MDTIDX=1
5761
5762         start_ost || error "OST0 start fail"
5763
5764         start_mds || error "MDS start fail"
5765
5766         mount_client $MOUNT || error "mount client fails"
5767
5768         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
5769
5770         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5771                 error "create remote dir fail"
5772
5773         rm -rf $DIR/$tdir || error "delete dir fail"
5774
5775         cleanup || error "cleanup failed with $?"
5776 }
5777 run_test 70b "start OST, MDT1, MDT0"
5778
5779 test_70c() {
5780         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5781         local MDTIDX=1
5782
5783         start_mds || error "MDS start fail"
5784         start_ost || error "OST0 start fail"
5785
5786         mount_client $MOUNT || error "mount client fails"
5787         stop_mdt 1 || error "MDT1 start fail"
5788
5789         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
5790         echo "deactivate $mdc_for_mdt1"
5791         $LCTL --device $mdc_for_mdt1 deactivate ||
5792                 error "set $mdc_for_mdt1 deactivate failed"
5793
5794         mkdir $DIR/$tdir && error "mkdir succeed"
5795
5796         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
5797                 error "create remote dir succeed"
5798
5799         cleanup || error "cleanup failed with $?"
5800 }
5801 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
5802
5803 test_70d() {
5804         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5805         local MDTIDX=1
5806
5807         start_mds || error "MDS start fail"
5808         start_ost || error "OST0 start fail"
5809
5810         mount_client $MOUNT || error "mount client fails"
5811
5812         stop_mdt 2 || error "MDT1 start fail"
5813
5814         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
5815                              awk '{print $4}')
5816         echo "deactivate $mdc_for_mdt2"
5817         $LCTL --device $mdc_for_mdt2 deactivate ||
5818                 error "set $mdc_for_mdt2 deactivate failed"
5819
5820         mkdir $DIR/$tdir || error "mkdir fail"
5821         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
5822                 error "create remote dir succeed"
5823
5824         rm -rf $DIR/$tdir || error "delete dir fail"
5825
5826         cleanup || error "cleanup failed with $?"
5827 }
5828 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
5829
5830 test_70e() {
5831         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5832
5833         [ "$MDS1_VERSION" -ge $(version_code 2.7.62) ] ||
5834                 skip "Need MDS version at least 2.7.62"
5835
5836         reformat || error "reformat failed with $?"
5837
5838         load_modules
5839
5840         local mdsdev=$(mdsdevname 1)
5841         local ostdev=$(ostdevname 1)
5842         local mdsvdev=$(mdsvdevname 1)
5843         local ostvdev=$(ostvdevname 1)
5844         local opts_mds="$(mkfs_opts mds1 $mdsdev) --reformat $mdsdev $mdsvdev"
5845         local opts_ost="$(mkfs_opts ost1 $ostdev) --reformat $ostdev $ostvdev"
5846
5847         if ! combined_mgs_mds ; then
5848                 start_mgs
5849         fi
5850
5851         add mds1 $opts_mds || error "add mds1 failed"
5852         start_mdt 1 || error "start mdt1 failed"
5853         add ost1 $opts_ost || error "add ost1 failed"
5854         start_ost || error "start ost failed"
5855         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
5856
5857         local soc=$(do_facet mds1 "$LCTL get_param -n \
5858                     mdt.*MDT0000.sync_lock_cancel")
5859         [ $soc == "never" ] || error "SoC enabled on single MDS"
5860
5861         for i in $(seq 2 $MDSCOUNT); do
5862                 mdsdev=$(mdsdevname $i)
5863                 mdsvdev=$(mdsvdevname $i)
5864                 opts_mds="$(mkfs_opts mds$i $mdsdev) --reformat $mdsdev \
5865                           $mdsvdev"
5866                 add mds$i $opts_mds || error "add mds$i failed"
5867                 start_mdt $i || error "start mdt$i fail"
5868         done
5869
5870         wait_dne_interconnect
5871
5872         for i in $(seq $MDSCOUNT); do
5873                 soc=$(do_facet mds$i "$LCTL get_param -n \
5874                         mdt.*MDT000$((i - 1)).sync_lock_cancel")
5875                 [ $soc == "blocking" ] || error "SoC not enabled on DNE"
5876         done
5877
5878         for i in $(seq 2 $MDSCOUNT); do
5879                 stop_mdt $i || error "stop mdt$i fail"
5880         done
5881         soc=$(do_facet mds1 "$LCTL get_param -n \
5882                 mdt.*MDT0000.sync_lock_cancel")
5883         [ $soc == "never" ] || error "SoC enabled on single MDS"
5884         umount_client $MOUNT -f > /dev/null
5885
5886         cleanup || error "cleanup failed with $?"
5887 }
5888 run_test 70e "Sync-on-Cancel will be enabled by default on DNE"
5889
5890 test_71a() {
5891         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5892         if combined_mgs_mds; then
5893                 skip "needs separate MGS/MDT"
5894         fi
5895         local MDTIDX=1
5896
5897         start_mdt 1 || error "MDT0 start fail"
5898         start_ost || error "OST0 start fail"
5899         for num in $(seq 2 $MDSCOUNT); do
5900                 start_mdt $num || return
5901         done
5902
5903         start_ost2 || error "OST1 start fail"
5904
5905         mount_client $MOUNT || error "mount client fails"
5906
5907         mkdir $DIR/$tdir || error "mkdir fail"
5908         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5909                 error "create remote dir succeed"
5910
5911         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5912         rm -rf $DIR/$tdir || error "delete dir fail"
5913
5914         umount_client $MOUNT || error "umount_client failed"
5915         stop_mds || error "MDS stop fail"
5916         stop_ost || error "OST0 stop fail"
5917         stop_ost2 || error "OST1 stop fail"
5918 }
5919 run_test 71a "start MDT0 OST0, MDT1, OST1"
5920
5921 test_71b() {
5922         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5923         if combined_mgs_mds; then
5924                 skip "needs separate MGS/MDT"
5925         fi
5926         local MDTIDX=1
5927
5928         for num in $(seq 2 $MDSCOUNT); do
5929                 start_mdt $num || return
5930         done
5931         start_ost || error "OST0 start fail"
5932         start_mdt 1 || error "MDT0 start fail"
5933         start_ost2 || error "OST1 start fail"
5934
5935         mount_client $MOUNT || error "mount client fails"
5936
5937         mkdir $DIR/$tdir || error "mkdir fail"
5938         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5939                 error "create remote dir succeed"
5940
5941         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5942         rm -rf $DIR/$tdir || error "delete dir fail"
5943
5944         umount_client $MOUNT || error "umount_client failed"
5945         stop_mds || error "MDT0 stop fail"
5946         stop_ost || error "OST0 stop fail"
5947         stop_ost2 || error "OST1 stop fail"
5948 }
5949 run_test 71b "start MDT1, OST0, MDT0, OST1"
5950
5951 test_71c() {
5952         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5953         combined_mgs_mds && skip "needs separate MGS/MDT"
5954
5955         local MDTIDX=1
5956
5957         start_ost || error "OST0 start fail"
5958         start_ost2 || error "OST1 start fail"
5959         for num in $(seq 2 $MDSCOUNT); do
5960                 start_mdt $num || return
5961         done
5962         start_mdt 1 || error "MDT0 start fail"
5963
5964         mount_client $MOUNT || error "mount client fails"
5965
5966         mkdir $DIR/$tdir || error "mkdir fail"
5967         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5968                 error "create remote dir succeed"
5969
5970         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5971         rm -rf $DIR/$tdir || error "delete dir fail"
5972
5973         umount_client $MOUNT || error "umount_client failed"
5974         stop_mds || error "MDS stop fail"
5975         stop_ost || error "OST0 stop fail"
5976         stop_ost2 || error "OST1 stop fail"
5977
5978 }
5979 run_test 71c "start OST0, OST1, MDT1, MDT0"
5980
5981 test_71d() {
5982         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5983         combined_mgs_mds && skip "needs separate MGS/MDT"
5984
5985         local MDTIDX=1
5986
5987         start_ost || error "OST0 start fail"
5988         for num in $(seq 2 $MDSCOUNT); do
5989                 start_mdt $num || return
5990         done
5991         start_mdt 1 || error "MDT0 start fail"
5992         start_ost2 || error "OST1 start fail"
5993
5994         mount_client $MOUNT || error "mount client fails"
5995
5996         mkdir $DIR/$tdir || error "mkdir fail"
5997         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5998                         error "create remote dir succeed"
5999
6000         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
6001         rm -rf $DIR/$tdir || error "delete dir fail"
6002
6003         umount_client $MOUNT || error "umount_client failed"
6004         stop_mds || error "MDS stop fail"
6005         stop_ost || error "OST0 stop fail"
6006         stop_ost2 || error "OST1 stop fail"
6007
6008 }
6009 run_test 71d "start OST0, MDT1, MDT0, OST1"
6010
6011 test_71e() {
6012         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6013         combined_mgs_mds && skip "needs separate MGS/MDT"
6014
6015         local MDTIDX=1
6016
6017         start_ost || error "OST0 start fail"
6018         for num in $(seq 2 $MDSCOUNT); do
6019                 start_mdt $num || return
6020         done
6021         start_ost2 || error "OST1 start fail"
6022         start_mdt 1 || error "MDT0 start fail"
6023
6024         mount_client $MOUNT || error "mount client fails"
6025
6026         mkdir $DIR/$tdir || error "mkdir fail"
6027         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6028                 error "create remote dir succeed"
6029
6030         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
6031         rm -rf $DIR/$tdir || error "delete dir fail"
6032
6033         umount_client $MOUNT || error "umount_client failed"
6034         stop_mds || error "MDS stop fail"
6035         stop_ost || error "OST0 stop fail"
6036         stop_ost2 || error "OST1 stop fail"
6037
6038 }
6039 run_test 71e "start OST0, MDT1, OST1, MDT0"
6040
6041 test_72() { #LU-2634
6042         [ "$mds1_FSTYPE" != ldiskfs ] &&
6043                 skip "ldiskfs only test"
6044
6045         local mdsdev=$(mdsdevname 1)
6046         local ostdev=$(ostdevname 1)
6047         local cmd="$E2FSCK -fnvd $mdsdev"
6048         local fn=3
6049         local add_options
6050
6051         cleanup
6052         load_modules
6053
6054         if combined_mgs_mds; then
6055                 add_options='--reformat'
6056         else
6057                 add_options='--reformat --replace'
6058         fi
6059
6060         #tune MDT with "-O extents"
6061
6062         for num in $(seq $MDSCOUNT); do
6063                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
6064                         $add_options $(mdsdevname $num) $(mdsvdevname $num) ||
6065                         error "add mds $num failed"
6066                 do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
6067                         error "$TUNE2FS failed on mds${num}"
6068         done
6069
6070         add ost1 $(mkfs_opts ost1 $ostdev) $add_options $ostdev ||
6071                 error "add $ostdev failed"
6072         start_mds || error "start mds failed"
6073         start_ost || error "start ost failed"
6074         mount_client $MOUNT || error "mount client failed"
6075
6076         #create some short symlinks
6077         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6078         createmany -o $DIR/$tdir/$tfile-%d $fn
6079         echo "create $fn short symlinks"
6080         for i in $(seq -w 1 $fn); do
6081                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
6082         done
6083         ls -al $MOUNT
6084
6085         #umount
6086         umount_client $MOUNT || error "umount client failed"
6087         stop_mds || error "stop mds failed"
6088         stop_ost || error "stop ost failed"
6089
6090         #run e2fsck
6091         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
6092 }
6093 run_test 72 "test fast symlink with extents flag enabled"
6094
6095 test_73() { #LU-3006
6096         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
6097         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
6098                 error "1st tunefs failed"
6099         start_mgsmds || error "start mds failed"
6100         start_ost || error "start ost failed"
6101         mount_client $MOUNT || error "mount client failed"
6102         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
6103                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
6104         umount_client $MOUNT || error "umount client failed"
6105         stop_ost
6106         stop_mds
6107 }
6108 run_test 73 "failnode to update from mountdata properly"
6109
6110 # LU-15246
6111 test_74() {
6112         (( $MDS1_VERSION >= $(version_code 2.15.57.16) )) ||
6113                 skip "need MDS version >= 2.15.57.16 for per-device timeouts"
6114
6115         setup
6116         stack_trap "cleanup"
6117
6118         # Prepare fs2, share the mgs of fs
6119         local FSNAME2=fs15246
6120         local fs2mdsdev=$(mdsdevname 1_2)
6121         local fs2ostdev=$(ostdevname 1_2)
6122         local fs2mdsvdev=$(mdsvdevname 1_2)
6123         local fs2ostvdev=$(ostvdevname 1_2)
6124
6125         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --fsname=$FSNAME2 \
6126                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
6127         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --fsname=$FSNAME2 \
6128                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
6129
6130         stack_trap "cleanup_fs2"
6131
6132         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
6133         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
6134
6135         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
6136         $MOUNT_CMD $MGSNID:/$FSNAME2 $MOUNT2 || error "mount $MOUNT2 failed"
6137
6138         echo "========== All mounted lustre fs ===================="
6139         mount | grep 'type lustre'
6140         echo "====================================================="
6141
6142         # Set and check osc/ldlm_enqueue_min
6143         $LCTL set_param osc.${FSNAME}-*.ldlm_enqueue_min=99 ||
6144                 error "failed to set per-device adaptive parameters on client"
6145         stack_trap "$LCTL set_param osc.${FSNAME}-*.ldlm_enqueue_min=0"
6146
6147         local ldlm_enqueue_min
6148         ldlm_enqueue_min=$($LCTL get_param -n osc.${FSNAME}-*.ldlm_enqueue_min \
6149                            | uniq)
6150         (( $ldlm_enqueue_min == 99 )) ||
6151                 error "wrong ldlm_enqueue_min value for osc.${FSNAME}-*"
6152
6153         # Check fs2 as reference
6154         ldlm_enqueue_min=$($LCTL get_param -n osc.${FSNAME2}-*.ldlm_enqueue_min\
6155                            | uniq)
6156         (( $ldlm_enqueue_min == 0 )) ||
6157                 error "wrong ldlm_enqueue_min value for osc.${FSNAME2}-*"
6158
6159         # Set and check obdfilter/at_min
6160         do_facet ost1 $LCTL set_param obdfilter.${FSNAME}-*.at_min=1 ||
6161                 error "failed to set per-device adaptive parameters on ost"
6162         stack_trap "do_facet ost1 $LCTL set_param obdfilter.${FSNAME}-*.at_min=0"
6163
6164         local at_min
6165         at_min=$(do_facet ost1 $LCTL get_param -n obdfilter.${FSNAME}-*.at_min \
6166                 | uniq)
6167         (( $at_min == 1 )) ||
6168                 error "wrong at_min value for obdfilter.${FSNAME}-*"
6169
6170         # set and check mdc/at_max
6171         $LCTL set_param mdc.${FSNAME}-*.at_max=599 ||
6172                 error "failed to set per-device adaptive parameters on client"
6173         stack_trap "$LCTL set_param mdc.${FSNAME}-*.at_max=0"
6174
6175         local at_max
6176         at_max=$($LCTL get_param -n mdc.${FSNAME}-*.at_max | uniq)
6177         (( $at_max == 599 )) ||
6178                 error "wrong at_max value for osc.${FSNAME}-*"
6179
6180         # Check fs2 as reference
6181         at_max=$($LCTL get_param -n mdc.${FSNAME2}-*.at_max | uniq)
6182         (( $at_max == 0 )) ||
6183                 error "wrong at_max value for osc.${FSNAME2}-*"
6184
6185         # Set and check mds/at_max
6186         do_facet mds1 $LCTL set_param *.${FSNAME}-*.at_max=599 ||
6187                 error "failed to set per-device adaptive parameters on mds"
6188         stack_trap "do_facet mds1 $LCTL set_param *.${FSNAME}-*.at_max=0"
6189
6190         local at_max
6191         at_max=$(do_facet mds1 $LCTL get_param -n mdt.${FSNAME}-*.at_max | uniq)
6192         (( at_max == 599 )) ||
6193                 error "wrong at_max value for mdt.${FSNAME}-*"
6194
6195         # Set and check mgs&mgc/at_history
6196         local mgs_nid=$(do_facet $SINGLEMDS $LCTL list_nids | tail -1)
6197         $LCTL set_param mgc.MGC$mgs_nid.at_history=588
6198         stack_trap "$LCTL set_param mgc.MGC$mgs_nid.at_history=0"
6199
6200         local at_history
6201         at_history=$($LCTL get_param -n mgc.MGC$mgs_nid.at_history)
6202         (( $at_history == 588 )) ||
6203                 error "wrong at_history value for mgc.MGC$mgs_nid"
6204
6205         do_facet mgs $LCTL set_param mgs.MGS.at_history=588
6206         stack_trap "do_facet mgs $LCTL set_param mgs.MGS.at_history=0"
6207         at_history=$(do_facet mgs $LCTL get_param -n mgs.MGS.at_history)
6208         (( $at_history == 588 )) ||
6209                 error "wrong at_history value for mgs.MGS"
6210 }
6211 run_test 74 "Test per-device adaptive timeout parameters"
6212
6213 test_75() { # LU-2374
6214         [[ "$MDS1_VERSION" -lt $(version_code 2.4.1) ]] &&
6215                 skip "Need MDS version at least 2.4.1"
6216
6217         local index=0
6218         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
6219                 --replace --reformat $(mdsdevname 1) $(mdsvdevname 1)"
6220         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
6221                 --replace --reformat $(ostdevname 1) $(ostvdevname 1)"
6222
6223         load_modules
6224         #check with default parameters
6225         add mds1 $opts_mds || error "add mds1 failed for default params"
6226         add ost1 $opts_ost || error "add ost1 failed for default params"
6227
6228         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
6229         opts_mds=$(echo $opts_mds |
6230                    sed -e "s/--index=$index/--index=$index --mdt/")
6231         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
6232         opts_ost=$(echo $opts_ost |
6233                    sed -e "s/--index=$index/--index=$index --ost/")
6234
6235         add mds1 $opts_mds || error "add mds1 failed for new params"
6236         add ost1 $opts_ost || error "add ost1 failed for new params"
6237
6238         reformat_and_config
6239         return 0
6240 }
6241 run_test 75 "The order of --index should be irrelevant"
6242
6243 test_76a() {
6244         [[ "$MGS_VERSION" -ge $(version_code 2.4.52) ]] ||
6245                 skip "Need MDS version at least 2.4.52"
6246
6247         setup
6248         local MDMB_PARAM="osc.*.max_dirty_mb"
6249         echo "Change MGS params"
6250         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
6251                 head -1)
6252         echo "max_dirty_mb: $MAX_DIRTY_MB"
6253         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB - 10))
6254         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
6255         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
6256         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
6257                 head -1" $NEW_MAX_DIRTY_MB
6258         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
6259         echo "$MAX_DIRTY_MB"
6260         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
6261                 error "error while apply max_dirty_mb"
6262
6263         echo "Check the value is stored after remount"
6264         stopall
6265         setupall
6266         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
6267                 head -1" $NEW_MAX_DIRTY_MB
6268         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
6269         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
6270                 error "max_dirty_mb is not saved after remount"
6271
6272         echo "Change OST params"
6273         CLIENT_PARAM="obdfilter.*.client_cache_count"
6274         local CLIENT_CACHE_COUNT
6275         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
6276                 head -1)
6277         echo "client_cache_count: $CLIENT_CACHE_COUNT"
6278         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
6279         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
6280         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
6281         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
6282                 head -1" $NEW_CLIENT_CACHE_COUNT
6283         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
6284                 head -1)
6285         echo "$CLIENT_CACHE_COUNT"
6286         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
6287                 error "error while apply client_cache_count"
6288
6289         echo "Check the value is stored after remount"
6290         stopall
6291         setupall
6292         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
6293                 head -1" $NEW_CLIENT_CACHE_COUNT
6294         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
6295                 head -1)
6296         echo "$CLIENT_CACHE_COUNT"
6297         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
6298                 error "client_cache_count is not saved after remount"
6299         stopall
6300 }
6301 run_test 76a "set permanent params with lctl across mounts"
6302
6303 test_76b() { # LU-4783
6304         [[ "$MGS_VERSION" -ge $(version_code 2.5.57) ]] ||
6305                 skip "Need MGS version at least 2.5.57"
6306         stopall
6307         setupall
6308         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
6309                 error "start params log failed"
6310         stopall
6311 }
6312 run_test 76b "verify params log setup correctly"
6313
6314 test_76c() {
6315         [[ "$MGS_VERSION" -ge $(version_code 2.8.54) ]] ||
6316                 skip "Need MDS version at least 2.4.52"
6317         setupall
6318         local MASK_PARAM="mdd.*.changelog_mask"
6319         echo "Change changelog_mask"
6320         do_facet mgs $LCTL set_param -P $MASK_PARAM=-CLOSE ||
6321                 error "Can't change changlog_mask"
6322         wait_update $(facet_host mds) "$LCTL get_param -n $MASK_PARAM |
6323                 grep 'CLOSE'" ""
6324
6325         echo "Check the value is stored after mds remount"
6326         stop_mds || error "Failed to stop MDS"
6327         start_mds || error "Failed to start MDS"
6328         local CHANGELOG_MASK=$(do_facet mgs $LCTL get_param -n $MASK_PARAM)
6329         echo $CHANGELOG_MASK | grep CLOSE > /dev/null &&
6330                 error "changelog_mask is not changed"
6331
6332         stopall
6333 }
6334 run_test 76c "verify changelog_mask is applied with lctl set_param -P"
6335
6336 test_76d() { #LU-9399
6337         setupall
6338
6339         local xattr_cache="llite.*.xattr_cache"
6340         local cmd="$LCTL get_param -n $xattr_cache | head -1"
6341         local new=$((($(eval $cmd) + 1) % 2))
6342
6343         echo "lctl set_param -P llite.*.xattr_cache=$new"
6344         do_facet mgs $LCTL set_param -P $xattr_cache=$new ||
6345                 error "Can't change xattr_cache"
6346         wait_update $HOSTNAME "$cmd" "$new"
6347
6348         echo "Check $xattr_cache on client $MOUNT"
6349         umount_client $MOUNT || error "umount $MOUNT failed"
6350         mount_client $MOUNT || error "mount $MOUNT failed"
6351         [ $(eval $cmd) -eq $new ] ||
6352                 error "$xattr_cache != $new on client $MOUNT"
6353
6354         echo "Check $xattr_cache on the new client $MOUNT2"
6355         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
6356         [ $(eval $cmd) -eq $new ] ||
6357                 error "$xattr_cache != $new on client $MOUNT2"
6358         umount_client $MOUNT2 || error "umount $MOUNT2 failed"
6359
6360         stopall
6361 }
6362 run_test 76d "verify llite.*.xattr_cache can be set by 'lctl set_param -P' correctly"
6363
6364 test_77() { # LU-3445
6365         [[ "$MDS1_VERSION" -ge $(version_code 2.8.55) ]] ||
6366                 skip "Need MDS version 2.8.55+ "
6367
6368         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
6369                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
6370                 skip_env "mixed loopback and real device not working"
6371         fi
6372
6373         local fs2mdsdev=$(mdsdevname 1_2)
6374         local fs2ostdev=$(ostdevname 1_2)
6375         local fs2mdsvdev=$(mdsvdevname 1_2)
6376         local fs2ostvdev=$(ostvdevname 1_2)
6377         local fsname=test1234
6378         local mgsnid
6379         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
6380
6381         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
6382
6383         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
6384                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
6385         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
6386                 error "start fs2mds failed"
6387
6388         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
6389         mgsnid="0.0.0.0@tcp,$mgsnid,$mgsnid:$mgsnid"
6390
6391         add fs2ost --mgsnode=$mgsnid $(mkfs_opts ost1 $fs2ostdev) \
6392                 --failnode=$failnid --fsname=$fsname \
6393                 --reformat $fs2ostdev $fs2ostvdev ||
6394                         error "add fs2ost failed"
6395         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
6396
6397         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
6398         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
6399         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
6400         cleanup_fs2
6401 }
6402 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
6403
6404 test_78() {
6405         [[ "$mds1_FSTYPE" != ldiskfs ||
6406            "$ost1_FSTYPE" != ldiskfs ]] &&
6407                 skip "ldiskfs only test"
6408
6409         # reformat the Lustre filesystem with a smaller size
6410         local saved_MDSCOUNT=$MDSCOUNT
6411         local saved_MDSSIZE=$MDSSIZE
6412         local saved_OSTCOUNT=$OSTCOUNT
6413         local saved_OSTSIZE=$OSTSIZE
6414         MDSCOUNT=1
6415         OSTCOUNT=1
6416         MDSSIZE=$((MDSSIZE - 20000))
6417         OSTSIZE=$((OSTSIZE - 20000))
6418         reformat || error "(1) reformat Lustre filesystem failed"
6419         MDSSIZE=$saved_MDSSIZE
6420         OSTSIZE=$saved_OSTSIZE
6421
6422         # mount the Lustre filesystem
6423         setup_noconfig || error "(2) setup Lustre filesystem failed"
6424
6425         # create some files
6426         log "create test files"
6427         local i
6428         local file
6429         local num_files=100
6430
6431         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
6432         $LFS df; $LFS df -i
6433         for i in $(seq $num_files); do
6434                 file=$MOUNT/$tdir/$tfile-$i
6435                 dd if=/dev/urandom of=$file count=1 bs=1M || {
6436                         $LCTL get_param osc.*.cur*grant*
6437                         $LFS df; $LFS df -i;
6438                         # stop creating files if there is no more space
6439                         if [ ! -e $file ]; then
6440                                 num_files=$((i - 1))
6441                                 break
6442                         fi
6443
6444                         $LFS getstripe -v $file
6445                         local ost_idx=$(LFS getstripe -i $file)
6446                         do_facet ost$((ost_idx + 1)) \
6447                                 $LCTL get_param obdfilter.*.*grant*
6448                         error "(4) create $file failed"
6449                 }
6450         done
6451
6452         # unmount the Lustre filesystem
6453         cleanup || error "(5) cleanup Lustre filesystem failed"
6454
6455         # run e2fsck on the MDT and OST devices
6456         local mds_host=$(facet_active_host $SINGLEMDS)
6457         local ost_host=$(facet_active_host ost1)
6458         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6459         local ost_dev=$(ostdevname 1)
6460
6461         run_e2fsck $mds_host $mds_dev "-y"
6462         run_e2fsck $ost_host $ost_dev "-y"
6463
6464         # get the original block count of the MDT and OST filesystems
6465         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
6466         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
6467
6468         # expand the MDT and OST filesystems to the device size
6469         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
6470         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
6471
6472         # run e2fsck on the MDT and OST devices again
6473         run_e2fsck $mds_host $mds_dev "-y"
6474         run_e2fsck $ost_host $ost_dev "-y"
6475
6476         # mount the Lustre filesystem
6477         setup
6478
6479         # check the files
6480         log "check files after expanding the MDT and OST filesystems"
6481         for i in $(seq $num_files); do
6482                 file=$MOUNT/$tdir/$tfile-$i
6483                 $CHECKSTAT -t file -s 1048576 $file ||
6484                         error "(6) checkstat $file failed"
6485         done
6486
6487         # create more files
6488         log "create more files after expanding the MDT and OST filesystems"
6489         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
6490                 file=$MOUNT/$tdir/$tfile-$i
6491                 dd if=/dev/urandom of=$file count=1 bs=1M ||
6492                         error "(7) create $file failed"
6493         done
6494
6495         # unmount the Lustre filesystem
6496         cleanup || error "(8) cleanup Lustre filesystem failed"
6497
6498         # run e2fsck on the MDT and OST devices
6499         run_e2fsck $mds_host $mds_dev "-y"
6500         run_e2fsck $ost_host $ost_dev "-y"
6501
6502         # get the maximum block count of the MDT and OST filesystems
6503         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
6504         local ost_max_blks=$(get_block_count ost1 $ost_dev)
6505
6506         # get the minimum block count of the MDT and OST filesystems
6507         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
6508                                 grep minimum | sed -e 's/^.*filesystem: //g')
6509         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
6510                                 grep minimum | sed -e 's/^.*filesystem: //g')
6511
6512         # shrink the MDT and OST filesystems to a smaller size
6513         local shrunk=false
6514         local new_blks
6515         local base_blks
6516         if [[ $mds_max_blks -gt $mds_min_blks &&
6517               $mds_max_blks -gt $mds_orig_blks ]]; then
6518                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
6519                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
6520                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
6521                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
6522                         error "shrink $SINGLEMDS to $new_blks failed"
6523                 shrunk=true
6524         fi
6525
6526         if [[ $ost_max_blks -gt $ost_min_blks &&
6527               $ost_max_blks -gt $ost_orig_blks ]]; then
6528                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
6529                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
6530                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
6531                 run_resize2fs ost1 $ost_dev $new_blks ||
6532                         error "shrink ost1 to $new_blks failed"
6533                 shrunk=true
6534         fi
6535
6536         # check whether the MDT or OST filesystem was shrunk or not
6537         if ! $shrunk; then
6538                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
6539                 reformat_and_config ||
6540                         error "(10) reformat Lustre filesystem failed"
6541                 return 0
6542         fi
6543
6544         # run e2fsck on the MDT and OST devices again
6545         run_e2fsck $mds_host $mds_dev "-y"
6546         run_e2fsck $ost_host $ost_dev "-y"
6547
6548         # mount the Lustre filesystem again
6549         setup
6550
6551         # check the files
6552         log "check files after shrinking the MDT and OST filesystems"
6553         for i in $(seq $((num_files + 10))); do
6554                 file=$MOUNT/$tdir/$tfile-$i
6555                 $CHECKSTAT -t file -s 1048576 $file ||
6556                         error "(11) checkstat $file failed"
6557         done
6558
6559         # unmount and reformat the Lustre filesystem
6560         cleanup || error "(12) cleanup Lustre filesystem failed"
6561         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
6562
6563         MDSCOUNT=$saved_MDSCOUNT
6564         OSTCOUNT=$saved_OSTCOUNT
6565         reformat_and_config || error "(14) reformat Lustre filesystem failed"
6566 }
6567 run_test 78 "run resize2fs on MDT and OST filesystems"
6568
6569 test_79() { # LU-4227
6570         [[ "$MDS1_VERSION" -ge $(version_code 2.5.59) ]] ||
6571                 skip "Need MDS version at least 2.5.59"
6572
6573         local mdsdev1=$(mdsdevname 1)
6574         local mdsvdev1=$(mdsvdevname 1)
6575         local mdsdev2=$(mdsdevname 2)
6576         local mdsvdev2=$(mdsvdevname 2)
6577         local ostdev1=$(ostdevname 1)
6578         local ostvdev1=$(ostvdevname 1)
6579         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
6580         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
6581         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
6582         local mgsnode_opt
6583
6584         # remove --mgs/--mgsnode from mkfs.lustre options
6585         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
6586
6587         mgsnode_opt=$(echo $opts_mds2 |
6588                 awk '{ for ( i = 1; i < NF; i++ )
6589                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
6590         [ -n "$mgsnode_opt" ] &&
6591                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
6592
6593         mgsnode_opt=$(echo $opts_ost1 |
6594                 awk '{ for ( i = 1; i < NF; i++ )
6595                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
6596         [ -n "$mgsnode_opt" ] &&
6597                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
6598         load_modules
6599         # -MGS, format a mdt without --mgs option
6600         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
6601                 error "Must specify --mgs when formatting mdt combined with mgs"
6602
6603         # +MGS, format a mdt/ost without --mgsnode option
6604         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
6605                 > /dev/null || error "start mds1 failed"
6606         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
6607                 error "Must specify --mgsnode when formatting a mdt"
6608         add ost1 $opts_ost1 $ostdev1 $ostvdev1 &&
6609                 error "Must specify --mgsnode when formatting an ost"
6610
6611         reformat_and_config
6612 }
6613 run_test 79 "format MDT/OST without mgs option (should return errors)"
6614
6615 test_80() {
6616         start_mds || error "Failed to start MDT"
6617         start_ost || error "Failed to start OST1"
6618         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
6619 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
6620         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
6621         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
6622         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
6623         sleep 30
6624         start_ost2 || error "Failed to start OST2"
6625
6626         do_facet ost1 "$LCTL set_param fail_loc=0"
6627         stop_ost2
6628         stop_ost
6629         stop_mds
6630 }
6631 run_test 80 "mgc import reconnect race"
6632
6633 #Save the original values of $OSTCOUNT and $OSTINDEX$i.
6634 save_ostindex() {
6635         local new_ostcount=$1
6636         saved_ostcount=$OSTCOUNT
6637         OSTCOUNT=$new_ostcount
6638
6639         local i
6640         local index
6641         for ((i = 1; i <= $OSTCOUNT; i++ )); do
6642                 index=OSTINDEX$i
6643                 eval saved_ostindex$i=${!index}
6644                 eval OSTINDEX$i=""
6645         done
6646 }
6647
6648 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
6649 restore_ostindex() {
6650         local i
6651         local index
6652
6653         echo "restoring OSTCOUNT=$saved_ostcount and OSTINDEXn"
6654
6655         for ((i = 1; i <= $OSTCOUNT; i++ )); do
6656                 index=saved_ostindex$i
6657                 eval OSTINDEX$i=${!index}
6658         done
6659         OSTCOUNT=$saved_ostcount
6660
6661         reformat
6662         if ! combined_mgs_mds ; then
6663                 start_mgs
6664         fi
6665 }
6666
6667 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
6668 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
6669 # assigned index and ensures we can mount such a formatted file system
6670 test_81() { # LU-4665
6671         (( MDS1_VERSION >= $(version_code 2.6.54) )) ||
6672                 skip "Need MDS version at least 2.6.54"
6673         (( OSTCOUNT >= 3 )) || skip_env "needs >= 3 OSTs"
6674
6675         stopall
6676
6677         # Each time RANDOM is referenced, a random integer between 0 and 32767
6678         # is generated.
6679         local i
6680         local saved_ostindex1=$OSTINDEX1
6681         for i in 65535 $((RANDOM + 65536)); do
6682                 echo -e "\nFormat ost1 with --index=$i, should fail"
6683                 OSTINDEX1=$i
6684                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
6685                    $(ostdevname 1) $(ostvdevname 1); then
6686                         OSTINDEX1=$saved_ostindex1
6687                         error "format ost1 with --index=$i should fail"
6688                 fi
6689         done
6690         OSTINDEX1=$saved_ostindex1
6691
6692         save_ostindex 3
6693         stack_trap restore_ostindex
6694
6695         # Format OSTs with random sparse indices.
6696         local rand_ost=$(((RANDOM * 2 % 65533) + 1))
6697         echo  "Format $OSTCOUNT OSTs with OST_INDEX_LIST=[0,$rand_ost,65534]"
6698         OST_INDEX_LIST=[0,$rand_ost,65534] formatall ||
6699                 error "formatall failed with $?"
6700
6701         # Setup and check Lustre filesystem.
6702         start_mgsmds || error "start_mgsmds failed"
6703         for ((i = 1; i <= $OSTCOUNT; i++ )); do
6704                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
6705                         error "start ost$i failed"
6706         done
6707
6708         mount_client $MOUNT || error "mount client $MOUNT failed"
6709         check_mount || error "check client $MOUNT failed"
6710         $LFS df
6711
6712         # Check max_easize.
6713         local max_easize=$($LCTL get_param -n llite.*.max_easize)
6714         local xattr_size_max=$((4096 - 84)) # 4096 less ldiskfs ea overhead
6715
6716         # XATTR_SIZE_MAX less ldiskfs ea overhead
6717         large_xattr_enabled && xattr_size_max=$((65536 - 84))
6718         (( max_easize >= xattr_size_max )) ||
6719                 error "max_easize $max_easize < $xattr_size_max bytes"
6720
6721         test_mkdir $DIR/$tdir
6722         $LFS setstripe -i $rand_ost $DIR/$tdir/$tfile ||
6723                 error "error creating $tfile on ost$rand_ost"
6724         $LFS getstripe $DIR/$tdir/$tfile
6725
6726         local cmd
6727         local idx
6728         local found
6729         local uuid
6730
6731         cmd="getstripe -i $DIR/$tdir/$tfile"
6732         echo lfs $cmd
6733         found=$($LFS $cmd)
6734         (( $found == $rand_ost )) || error "index $found is not $rand_ost"
6735
6736         cmd="find $DIR/$tdir -i $rand_ost"
6737         echo lfs $cmd
6738         $LFS $cmd
6739         found=$($LFS $cmd)
6740         [[ "$found" == "$DIR/$tdir/$tfile" ]] ||
6741                 error "'lfs find' returned '$found', not '$tfile' by index"
6742
6743         $LFS osts
6744         uuid=$(ostuuid_from_index $rand_ost)
6745
6746         cmd="find $DIR/$tdir -O $uuid"
6747         echo lfs $cmd
6748         $LFS $cmd
6749         found=$($LFS $cmd)
6750
6751         [[ "$found" == "$DIR/$tdir/$tfile" ]] ||
6752                 error "'lfs find' returned '$found', not '$tfile' by UUID"
6753 }
6754 run_test 81 "sparse OST indexing"
6755
6756 # Here we exercise the stripe placement functionality on a file system that
6757 # has formatted the OST with a random index. With the file system the following
6758 # functionality is tested:
6759 #
6760 # 1. Creating a new file with a specific stripe layout.
6761 #
6762 # 2. Modifiy a existing empty file with a specific stripe layout.
6763 #
6764 # 3. Ensure we fail to set the stripe layout of a file that already has one.
6765 #
6766 # 4. If ost-index is defined we need to ensure it is the first entry in the
6767 #    ost index list returned by lfs getstripe.
6768 #
6769 # 5. Lastly ensure this functionality fails with directories.
6770 test_82a() { # LU-4665
6771         [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
6772                 skip "Need MDS version at least 2.6.54"
6773         [[ $OSTCOUNT -ge 3 ]] || skip_env "needs >= 3 OSTs"
6774
6775         stopall
6776
6777         save_ostindex 3
6778
6779         # Format OSTs with random sparse indices.
6780         local i
6781         local index
6782         local ost_indices
6783         local LOV_V1_INSANE_STRIPE_COUNT=65532
6784         for i in $(seq $OSTCOUNT); do
6785                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
6786                 ost_indices+=" $index"
6787         done
6788         ost_indices=$(comma_list $ost_indices)
6789
6790         stack_trap "restore_ostindex" EXIT
6791         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
6792         OST_INDEX_LIST=[$ost_indices] formatall
6793
6794         # Setup Lustre filesystem.
6795         start_mgsmds || error "start_mgsmds failed"
6796         for i in $(seq $OSTCOUNT); do
6797                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
6798                         error "start ost$i failed"
6799         done
6800
6801         # Collect debug information - start of test
6802         do_nodes $(comma_list $(mdts_nodes)) \
6803                    $LCTL get_param osp.*.prealloc_*_id
6804
6805         mount_client $MOUNT || error "mount client $MOUNT failed"
6806         wait_osts_up
6807
6808         $LFS df $MOUNT
6809         check_lfs_df_ret_val $? || error "$LFS df $MOUNT failed"
6810         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6811
6812         stack_trap "do_nodes $(comma_list $(mdts_nodes)) \
6813                    $LCTL get_param osp.*.prealloc_*_id || true" EXIT
6814
6815         # 1. If the file does not exist, new file will be created
6816         #    with specified OSTs.
6817         local file=$DIR/$tdir/$tfile-1
6818         local cmd="$LFS setstripe -o $ost_indices $file"
6819         echo -e "\n$cmd"
6820         eval $cmd || error "$cmd failed"
6821         check_stripe_count $file $OSTCOUNT
6822         check_obdidx $file $ost_indices
6823         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
6824                 error "write $file failed"
6825
6826         # 2. If the file already exists and is an empty file, the file
6827         #    will be attached with specified layout.
6828         file=$DIR/$tdir/$tfile-2
6829         mcreate $file || error "mcreate $file failed"
6830         cmd="$LFS setstripe -o $ost_indices $file"
6831         echo -e "\n$cmd"
6832         eval $cmd || error "$cmd failed"
6833         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
6834                 error "write $file failed"
6835         check_stripe_count $file $OSTCOUNT
6836         check_obdidx $file $ost_indices
6837
6838         # 3. If the file already has a valid layout attached, the command
6839         #    should fail with EBUSY.
6840         echo -e "\n$cmd"
6841         eval $cmd && error "stripe is already set on $file, $cmd should fail"
6842
6843         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
6844         #    be in the OST indices list.
6845         local start_ost_idx=${ost_indices##*,}
6846         file=$DIR/$tdir/$tfile-3
6847         cmd="$LFS setstripe -o $ost_indices -i $start_ost_idx $file"
6848         echo -e "\n$cmd"
6849         eval $cmd || error "$cmd failed"
6850         check_stripe_count $file $OSTCOUNT
6851         check_obdidx $file $ost_indices
6852         check_start_ost_idx $file $start_ost_idx
6853
6854         file=$DIR/$tdir/$tfile-4
6855         cmd="$LFS setstripe"
6856         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
6857         cmd+=" -i $start_ost_idx $file"
6858         echo -e "\n$cmd"
6859         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
6860
6861         # 5. Specifying OST indices for directory should succeed.
6862         local dir=$DIR/$tdir/$tdir
6863         mkdir $dir || error "mkdir $dir failed"
6864         cmd="$LFS setstripe -o $ost_indices $dir"
6865         if [ "$MDS1_VERSION" -gt $(version_code 2.11.53) ] &&
6866                 [ "$CLIENT_VERSION" -gt $(version_code 2.11.53) ]; then
6867                 echo -e "\n$cmd"
6868                 eval $cmd || error "unable to specify OST indices on directory"
6869         else
6870                 echo "need MDS+client version at least 2.11.53"
6871         fi
6872 }
6873 run_test 82a "specify OSTs for file (succeed) or directory (succeed)"
6874
6875 # Test 82b is run to ensure that if the user supplies a pool with a specific
6876 # stripe layout that it behaves proprerly. It should fail in the case that
6877 # the supplied OST index list points to OSTs not contained in the user
6878 # supplied pool.
6879 test_82b() { # LU-4665
6880         [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
6881                 skip "Need MDS version at least 2.6.54"
6882         [[ $OSTCOUNT -ge 4 ]] || skip_env "needs >= 4 OSTs"
6883
6884         stopall
6885
6886         save_ostindex 4
6887
6888         # Format OSTs with random sparse indices.
6889         local i
6890         local index
6891         local ost_indices
6892         local LOV_V1_INSANE_STRIPE_COUNT=65532
6893         for i in $(seq $OSTCOUNT); do
6894                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
6895                 ost_indices+=" $index"
6896         done
6897         ost_indices=$(comma_list $ost_indices)
6898
6899         stack_trap "restore_ostindex" EXIT
6900         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
6901         OST_INDEX_LIST=[$ost_indices] formatall
6902
6903         # Setup Lustre filesystem.
6904         start_mgsmds || error "start_mgsmds failed"
6905         for i in $(seq $OSTCOUNT); do
6906                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
6907                         error "start ost$i failed"
6908         done
6909
6910         mount_client $MOUNT || error "mount client $MOUNT failed"
6911
6912         wait_osts_up
6913         $LFS df $MOUNT
6914         check_lfs_df_ret_val $? || error "$LFS df $MOUNT failed"
6915         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6916
6917         # Create a new pool and add OSTs into it.
6918         local ost_pool=$FSNAME.$TESTNAME
6919         create_pool $ost_pool || error "create OST pool $ost_pool failed"
6920
6921         local ost_idx_in_list=${ost_indices##*,}
6922         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
6923                                 $ost_idx_in_list)
6924
6925         local ost_targets="$FSNAME-OST["
6926         for i in ${ost_idx_in_pool//,/ }; do
6927                 ost_targets=$ost_targets$(printf "%04x," $i)
6928         done
6929         ost_targets="${ost_targets%,}]"
6930
6931         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
6932                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
6933                                  sort -u | tr '\n' ' ')
6934
6935         local cmd="$LCTL pool_add $ost_pool $ost_targets"
6936         do_facet mgs $cmd || error "$cmd failed"
6937         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
6938                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
6939                                         error "wait_update $ost_pool failed"
6940         wait_update_facet $SINGLEMDS "$LCTL pool_list $ost_pool | wc -l" 4 ||
6941                                 error "wait_update pool_list $ost_pool failed"
6942
6943         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
6944         # then the OSTs must be the members of the pool.
6945         local file=$DIR/$tdir/$tfile
6946         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
6947         echo -e "\n$cmd"
6948         eval $cmd && error "OST with index $ost_idx_in_list should be" \
6949                            "in OST pool $ost_pool"
6950
6951         # Only select OST $ost_idx_in_list from $ost_pool for file.
6952         ost_idx_in_list=${ost_idx_in_pool#*,}
6953         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
6954         echo -e "\n$cmd"
6955         eval $cmd || error "$cmd failed"
6956         cmd="$LFS getstripe $file"
6957         echo -e "\n$cmd"
6958         eval $cmd || error "$cmd failed"
6959         check_stripe_count $file 2
6960         check_obdidx $file $ost_idx_in_list
6961         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
6962                 error "write $file failed"
6963 }
6964 run_test 82b "specify OSTs for file with --pool and --ost-list options"
6965
6966 test_83() {
6967         [[ "$OST1_VERSION" -ge $(version_code 2.6.91) ]] ||
6968                 skip "Need OST version at least 2.6.91"
6969         if [ "$ost1_FSTYPE" != ldiskfs ]; then
6970                 skip "ldiskfs only test"
6971         fi
6972
6973         local dev
6974         local ostmnt
6975         local fstype
6976         local mnt_opts
6977
6978         dev=$(ostdevname 1)
6979         ostmnt=$(facet_mntpt ost1)
6980
6981         # Mount the OST as an ldiskfs filesystem.
6982         log "mount the OST $dev as a $ost1_FSTYPE filesystem"
6983         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
6984                 --reformat $dev > /dev/null ||
6985                 error "format ost1 error"
6986
6987         if ! test -b $dev; then
6988                 mnt_opts=$(csa_add "$OST_MOUNT_FS_OPTS" -o loop)
6989         fi
6990         echo "mnt_opts $mnt_opts"
6991         do_facet ost1 mount -t "$ost1_FSTYPE" $dev \
6992                 $ostmnt $mnt_opts
6993         # Run llverfs on the mounted ldiskfs filesystem.
6994         # It is needed to get ENOSPACE.
6995         log "run llverfs in partial mode on the OST $ost1_FSTYPE $ostmnt"
6996         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
6997                 "no" || error "run_llverfs error on $ost1_FSTYPE"
6998
6999         # Unmount the OST.
7000         log "unmount the OST $dev"
7001         stop ost1
7002
7003         # Delete file IO_scrub. Later osd_scrub_setup will try to
7004         # create "IO_scrub" but will get ENOSPACE.
7005         writeconf_all
7006         echo "start ost1 service on `facet_active_host ost1`"
7007         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
7008
7009         local err
7010         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
7011         echo "string err $err"
7012         [ -z "$err" ] || error $err
7013         reformat_and_config
7014 }
7015 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
7016 Busy inodes after unmount ..."
7017
7018 test_84() {
7019         local facet=$SINGLEMDS
7020         local num=$(echo $facet | tr -d "mds")
7021         local dev=$(mdsdevname $num)
7022         local time_min=$(recovery_time_min)
7023         local recovery_duration
7024         local completed_clients
7025         local correct_clients
7026         local wrap_up=5
7027
7028         echo "start mds service on $(facet_active_host $facet)"
7029         start_mds "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" ||
7030                 error "start MDS failed"
7031
7032         start_ost || error "start OST0000 failed"
7033         wait_osc_import_state mds ost1 FULL
7034         start_ost2 || error "start OST0001 failed"
7035         wait_osc_import_state mds ost2 FULL
7036
7037         echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
7038
7039         mount_client $MOUNT1 || error "mount $MOUNT1 failed"
7040         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
7041         # make sure new superblock labels are sync'd before disabling writes
7042         sync_all_data
7043         sleep 5
7044
7045         replay_barrier $SINGLEMDS
7046         createmany -o $DIR1/$tfile-%d 1000
7047
7048         # We need to catch the end of recovery window to extend it.
7049         # Skip 5 requests and add delay to request handling.
7050         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
7051         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
7052
7053         facet_failover --fsck $SINGLEMDS || error "failover: $?"
7054         client_up
7055
7056         echo "recovery status"
7057         do_facet $SINGLEMDS \
7058                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status"
7059
7060         recovery_duration=$(do_facet $SINGLEMDS \
7061                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
7062                 awk '/recovery_duration/ { print $2 }')
7063         (( $recovery_duration > $time_min + $wrap_up )) &&
7064                 error "recovery_duration > recovery_time_hard + wrap up"
7065         completed_clients=$(do_facet $SINGLEMDS \
7066                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
7067                 awk '/completed_clients/ { print $2 }')
7068
7069         correct_clients="$MDSCOUNT/$((MDSCOUNT+1))"
7070         [ "$completed_clients" = "${correct_clients}" ] ||
7071                 error "$completed_clients != $correct_clients"
7072
7073         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
7074         umount_client $MOUNT1
7075         umount_client $MOUNT2
7076
7077         stop_ost
7078         stop_ost2
7079         stop_mds
7080 }
7081 run_test 84 "check recovery_hard_time"
7082
7083 test_85() {
7084         [[ "$OST1_VERSION" -ge $(version_code 2.7.55) ]] ||
7085                 skip "Need OST version at least 2.7.55"
7086 ##define OBD_FAIL_OSD_OST_EA_FID_SET 0x197
7087         do_facet ost1 "lctl set_param fail_loc=0x197"
7088         start_ost
7089         stop_ost
7090 }
7091 run_test 85 "osd_ost init: fail ea_fid_set"
7092
7093 cleanup_86() {
7094         trap 0
7095
7096         # ost1 has already registered to the MGS before the reformat.
7097         # So after reformatting it with option "-G", it could not be
7098         # mounted to the MGS. Cleanup the system for subsequent tests.
7099         reformat_and_config
7100 }
7101
7102 test_86() {
7103         [ "$ost1_FSTYPE" = zfs ] &&
7104                 skip "LU-6442: no such mkfs params for ZFS OSTs"
7105         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
7106                 skip "Need server version newer than 2.7.55"
7107
7108         local NEWSIZE=1024
7109         local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
7110                 awk '/Flex block group size: / { print $NF; exit; }')
7111
7112         [ "$OLDSIZE" == "$NEWSIZE" ] && skip "$NEWSIZE groups already"
7113
7114         local opts=" -O flex_bg -G $NEWSIZE"
7115         opts=$(OST_FS_MKFS_OPTS+="$opts" mkfs_opts ost1 $(ostdevname 1))
7116         opts+=" --reformat $(ostdevname 1) $(ostvdevname 1)"
7117         echo "params: $opts"
7118
7119         trap cleanup_86 EXIT ERR
7120
7121         stopall
7122         add ost1 $opts || error "add ost1 failed with new params"
7123
7124         local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
7125                 awk '/Flex block group size: / { print $NF; exit; }')
7126
7127         [[ $FOUNDSIZE == $NEWSIZE ]] ||
7128                 error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
7129
7130         cleanup_86
7131 }
7132 run_test 86 "Replacing mkfs.lustre -G option"
7133
7134 test_87() { #LU-6544
7135         [[ "$MDS1_VERSION" -ge $(version_code 2.9.51) ]] ||
7136                 skip "Need MDS version at least 2.9.51"
7137         [[ "$mds1_FSTYPE" != ldiskfs ]] &&
7138                 skip "ldiskfs only test"
7139         [[ $OSTCOUNT -gt 59 ]] &&
7140                 skip "Ignore wide striping situation"
7141         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
7142
7143         local mdsdev=$(mdsdevname 1)
7144         local mdsvdev=$(mdsvdevname 1)
7145         local file=$DIR/$tfile
7146         local mntpt=$(facet_mntpt $SINGLEMDS)
7147         local used_xattr_blk=0
7148         local inode_size=${1:-1024}
7149         local left_size=0
7150         local xtest="trusted.test"
7151         local value
7152         local orig
7153         local i
7154         local stripe_cnt=$(($OSTCOUNT + 2))
7155
7156         #Please see ldiskfs_make_lustre() for MDT inode size calculation
7157         if [ $stripe_cnt -gt 16 ]; then
7158                 inode_size=2048
7159         fi
7160         left_size=$(expr $inode_size - \
7161                         156 - \
7162                         32 - \
7163                         32 - 40 \* 3 - 32 \* 3 - $stripe_cnt \* 24 - 16 - 3 -  \
7164                         24 - 16 - 3 - \
7165                         24 - 18 - $(expr length $tfile) - 16 - 4)
7166         if [ $left_size -le 0 ]; then
7167                 echo "No space($left_size) is expected in inode."
7168                 echo "Try 1-byte xattr instead to verify this."
7169                 left_size=1
7170         else
7171                 echo "Estimate: at most $left_size-byte space left in inode."
7172         fi
7173
7174         unload_modules
7175         reformat
7176
7177         if ! combined_mgs_mds ; then
7178                 start_mgs
7179         fi
7180
7181         add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$stripe_cnt \
7182                 --reformat $mdsdev $mdsvdev || error "add mds1 failed"
7183         start_mdt 1 > /dev/null || error "start mdt1 failed"
7184         for i in $(seq $OSTCOUNT); do
7185                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
7186                         error "start ost$i failed"
7187         done
7188         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
7189         check_mount || error "check client $MOUNT failed"
7190
7191         #set xattr
7192         $LFS setstripe -E 1M -S 1M -c 1 -E 64M -c 1 -E -1 -c -1 $file ||
7193                 error "Create file with 3 components failed"
7194         $TRUNCATE $file $((1024*1024*64+1)) || error "truncate file failed"
7195         i=$($LFS getstripe -I3 -c $file) || error "get 3rd stripe count failed"
7196         if [ $i -ne $OSTCOUNT ]; then
7197                 left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
7198                 echo -n "Since only $i out $OSTCOUNT OSTs are used, "
7199                 echo -n "the expected left space is changed to "
7200                 echo "$left_size bytes at most."
7201         fi
7202         value=$(generate_string $left_size)
7203         setfattr -n $xtest -v $value $file
7204         orig=$(get_xattr_value $xtest $file)
7205         [[ "$orig" != "$value" ]] && error "$xtest changed"
7206
7207         #Verify if inode has some expected space left
7208         umount $MOUNT > /dev/null || error "umount $MOUNT failed"
7209         stop_mdt 1 > /dev/null || error "stop mdt1 failed"
7210         mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
7211
7212         do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
7213         used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
7214                         awk '{ print $1 }')
7215         [[ $used_xattr_blk -eq 0 ]] &&
7216                 error "Please check MDS inode size calculation: \
7217                        more than $left_size-byte space left in inode."
7218         echo "Verified: at most $left_size-byte space left in inode."
7219
7220         unmount_ldiskfs $SINGLEMDS
7221
7222         for i in $(seq $OSTCOUNT); do
7223                 stop ost$i -f || error "stop ost$i failed"
7224         done
7225 }
7226 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
7227
7228 test_88() {
7229         [ "$mds1_FSTYPE" == zfs ] &&
7230                 skip "LU-6662: no implementation for ZFS"
7231
7232         load_modules
7233
7234         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
7235                 --reformat $(mdsdevname 1) || error "add mds1 failed"
7236
7237         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
7238                 grep -e \".*opts:.*errors=remount-ro.*\"" ||
7239                 error "default mount options is missing"
7240
7241         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
7242                 --mountfsoptions="user_xattr,errors=panic" \
7243                 --reformat $(mdsdevname 1) || error "add mds1 failed"
7244
7245         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
7246                 grep -e \".*opts:.*errors=panic.*\"" ||
7247                 error "user can't override default mount options"
7248 }
7249 run_test 88 "check the default mount options can be overridden"
7250
7251 test_89() { # LU-7131
7252         [[ "$MDS1_VERSION" -ge $(version_code 2.9.54) ]] ||
7253                 skip "Need MDT version at least 2.9.54"
7254
7255         local key=failover.node
7256         local val1=192.0.2.254@tcp0 # Reserved IPs, see RFC 5735
7257         local val2=192.0.2.255@tcp0
7258         local mdsdev=$(mdsdevname 1)
7259         local params
7260
7261         stopall
7262
7263         if [[ "$mds1_FSTYPE" == zfs ]]; then
7264                 import_zpool mds1 || return ${PIPESTATUS[0]}
7265         fi
7266
7267         # Check that parameters are added correctly
7268         echo "tunefs --param $key=$val1"
7269         do_facet mds1 "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
7270                 error "tunefs --param $key=$val1 failed"
7271         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7272                 error "tunefs --dryrun failed"
7273         params=${params##*Parameters:}
7274         params=${params%%exiting*}
7275         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val1) = "1" ] ||
7276                 error "on-disk parameter not added correctly via tunefs"
7277
7278         # Check that parameters replace existing instances when added
7279         echo "tunefs --param $key=$val2"
7280         do_facet mds1 "$TUNEFS --param $key=$val2 $mdsdev >/dev/null" ||
7281                 error "tunefs --param $key=$val2 failed"
7282         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7283                 error "tunefs --dryrun failed"
7284         params=${params##*Parameters:}
7285         params=${params%%exiting*}
7286         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "1" ] ||
7287                 error "on-disk parameter not replaced via tunefs"
7288         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val2) = "1" ] ||
7289                 error "on-disk parameter not replaced correctly via tunefs"
7290
7291         # Check that a parameter is erased properly
7292         echo "tunefs --erase-param $key"
7293         do_facet mds1 "$TUNEFS --erase-param $key $mdsdev >/dev/null" ||
7294                 error "tunefs --erase-param $key failed"
7295         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7296                 error "tunefs --dryrun failed"
7297         params=${params##*Parameters:}
7298         params=${params%%exiting*}
7299         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "0" ] ||
7300                 error "on-disk parameter not erased correctly via tunefs"
7301
7302         # Check that all the parameters are erased
7303         do_facet mds1 "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
7304                 error "tunefs --param $key=$val1 failed"
7305         echo "tunefs --erase-params"
7306         do_facet mds1 "$TUNEFS --erase-params $mdsdev >/dev/null" ||
7307                 error "tunefs --erase-params failed"
7308         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7309                 error "tunefs --dryrun failed"
7310         params=${params##*Parameters:}
7311         params=${params%%exiting*}
7312         params=$(echo $params | tr ' ' '\n')
7313         [ -z "$params" ] ||
7314                 error "all on-disk parameters not erased correctly via tunefs $params"
7315
7316         # Check the order of options --erase-params and --param
7317         echo "tunefs --param $key=$val1 --erase-params"
7318         do_facet mds1 \
7319                 "$TUNEFS --param $key=$val1 --erase-params $mdsdev >/dev/null"||
7320                 error "tunefs --param $key=$val1 --erase-params failed"
7321         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7322                 error "tunefs --dryrun failed"
7323         params=${params##*Parameters:}
7324         params=${params%%exiting*}
7325         [ $(echo $params | tr ' ' '\n') == "$key=$val1" ] ||
7326                 error "on-disk param not added correctly with --erase-params"
7327
7328         reformat_and_config
7329 }
7330 run_test 89 "check tunefs --param and --erase-param{s} options"
7331
7332 # $1 test directory
7333 # $2 (optional) value of max_mod_rpcs_in_flight to set
7334 check_max_mod_rpcs_in_flight() {
7335         local dir="$1"
7336         local mmr="$2"
7337         local idx
7338         local facet
7339         local tmp
7340         local i
7341
7342         idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
7343         facet="mds$((0x$idx + 1))"
7344
7345         if [ -z "$mmr" ]; then
7346                 # get value of max_mod_rcps_in_flight
7347                 mmr=$($LCTL get_param -n \
7348                         mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
7349                         error "Unable to get max_mod_rpcs_in_flight"
7350                 echo "max_mod_rcps_in_flight is $mmr"
7351         else
7352                 # set value of max_mod_rpcs_in_flight
7353                 $LCTL set_param \
7354                     mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
7355                         error "Unable to set max_mod_rpcs_in_flight to $mmr"
7356                 echo "max_mod_rpcs_in_flight set to $mmr"
7357         fi
7358
7359         # create mmr+1 files
7360         echo "creating $((mmr + 1)) files ..."
7361         umask 0022
7362         for i in $(seq $((mmr + 1))); do
7363                 touch $dir/file-$i
7364         done
7365
7366         ### part 1 ###
7367
7368         # consumes mmr-1 modify RPC slots
7369         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
7370         # drop requests on MDT so that RPC slots are consumed
7371         # during all the request resend interval
7372         do_facet $facet "$LCTL set_param fail_loc=0x159"
7373         echo "launch $((mmr - 1)) chmod in parallel ..."
7374         for i in $(seq $((mmr - 1))); do
7375                 chmod 0600 $dir/file-$i &
7376         done
7377         sleep 1
7378
7379         # send one additional modify RPC
7380         do_facet $facet "$LCTL set_param fail_loc=0"
7381         echo "launch 1 additional chmod in parallel ..."
7382         chmod 0600 $dir/file-$mmr &
7383         sleep 1
7384
7385         # check this additional modify RPC get a modify RPC slot
7386         # and succeed its operation
7387         checkstat -vp 0600 $dir/file-$mmr ||
7388                 error "Unable to send $mmr modify RPCs in parallel"
7389         wait
7390
7391         ### part 2 ###
7392
7393         # consumes mmr modify RPC slots
7394         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
7395         # drop requests on MDT so that RPC slots are consumed
7396         # during all the request resend interval
7397         do_facet $facet "$LCTL set_param fail_loc=0x159"
7398         echo "launch $mmr chmod in parallel ..."
7399         for i in $(seq $mmr); do
7400                 chmod 0666 $dir/file-$i &
7401         done
7402         sleep 1
7403
7404         # send one additional modify RPC
7405         do_facet $facet "$LCTL set_param fail_loc=0"
7406         echo "launch 1 additional chmod in parallel ..."
7407         chmod 0666 $dir/file-$((mmr + 1)) &
7408         sleep 1
7409
7410         # check this additional modify RPC blocked getting a modify RPC slot
7411         checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
7412                 error "Unexpectedly send $(($mmr + 1)) modify RPCs in parallel"
7413         wait
7414 }
7415
7416 get_mdt_max_mod_rpcs_in_flight_val() {
7417         local max_mrif
7418         local facet="$1"
7419
7420         # It will be enough to get one value from one MDT
7421         max_mrif=$(do_facet $facet \
7422                 "$LCTL get_param -n \
7423                 mdt.$FSNAME-MDT*.max_mod_rpcs_in_flight | head -n 1")
7424         if [[ $max_mrif ]]; then
7425                 echo $max_mrif
7426         else
7427                 max_mrif=$(do_facet $facet \
7428                 cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
7429                 echo $max_mrif
7430         fi
7431 }
7432
7433 set_mdt_max_mod_rpcs_in_flight() {
7434         local lctl_op
7435         local max_mrif="$1"
7436         local facet="$2"
7437
7438         lctl_op=$($LCTL get_param \
7439                 mdt.*.max_mod_rpcs_in_flight)
7440         if [[ $lctl_op ]]; then
7441                 do_facet $facet \
7442                         "$LCTL set_param \
7443                         mdt.$FSNAME-MDT*.max_mod_rpcs_in_flight=$max_mrif"
7444         else
7445                 do_facet $facet \
7446                         "echo $max_mrif > \
7447                         /sys/module/mdt/parameters/max_mod_rpcs_per_client"
7448                 echo "the deprecated max_mod_rpcs_per_client \
7449                                 parameter was involved"
7450         fi
7451 }
7452
7453 test_90a() {
7454         setup
7455
7456         [[ $($LCTL get_param mdc.*.import |
7457              grep "connect_flags:.*multi_mod_rpc") ]] ||
7458                 skip "Need MDC with 'multi_mod_rpcs' feature"
7459
7460         # check default value
7461         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
7462         check_max_mod_rpcs_in_flight $DIR/$tdir
7463
7464         cleanup
7465 }
7466 run_test 90a "check max_mod_rpcs_in_flight is enforced"
7467
7468 test_90b() {
7469         local idx
7470         local facet
7471         local tmp
7472         local mmrpc
7473
7474         setup
7475
7476         [[ $($LCTL get_param mdc.*.import |
7477              grep "connect_flags:.*multi_mod_rpc") ]] ||
7478                 skip "Need MDC with 'multi_mod_rpcs' feature"
7479
7480         ### test 1.
7481         # update max_mod_rpcs_in_flight
7482         $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
7483         check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
7484
7485         ### test 2.
7486         # check client is able to send multiple modify RPCs in paralell
7487         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
7488                 grep -c "multi_mod_rpcs")
7489         if [ "$tmp" -ne $MDSCOUNT ]; then
7490                 cleanup
7491                 skip "Client not able to send multiple modify RPCs in parallel"
7492         fi
7493
7494         # update max_mod_rpcs_in_flight
7495         $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
7496         check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
7497
7498         ### test 3.
7499         $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
7500         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
7501         facet="mds$((0x$idx + 1))"
7502
7503         mmrpc=$(get_mdt_max_mod_rpcs_in_flight_val $facet)
7504         echo "mdt_max_mod_rpcs_in_flight is $mmrpc"
7505         # update max_mod_rpcs_in_flight
7506         umount_client $MOUNT
7507         set_mdt_max_mod_rpcs_in_flight 16 $facet
7508         mount_client $MOUNT
7509         $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
7510         check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
7511
7512         # restore MDT max_mod_rpcs_in_flight initial value
7513         set_mdt_max_mod_rpcs_in_flight $mmrpc $facet
7514
7515         rm -rf $DIR/${tdir}?
7516         cleanup
7517 }
7518 run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
7519
7520 save_params_90c() {
7521         # get max_rpcs_in_flight value
7522         mrif_90c=$($LCTL get_param -n \
7523                    mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
7524         echo "max_rpcs_in_flight is $mrif_90c"
7525
7526         # get MDC max_mod_rpcs_in_flight value
7527         mmrif_90c=$($LCTL get_param -n \
7528                     mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight)
7529         echo "MDC max_mod_rpcs_in_flight is $mmrif_90c"
7530
7531         # get MDT max_mod_rpcs_in_flight value
7532         mmrpc_90c=$(get_mdt_max_mod_rpcs_in_flight_val "mds1")
7533         echo "mdt_max_mod_rpcs_in_flight is $mmrpc_90c"
7534 }
7535
7536 restore_params_90c() {
7537         trap 0
7538
7539         # restore max_rpcs_in_flight value
7540         do_facet mgs $LCTL set_param -P \
7541                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$mrif_90c
7542
7543         # restore max_mod_rpcs_in_flight value
7544         do_facet mgs $LCTL set_param -P \
7545                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mmrif_90c
7546
7547         # restore MDT max_mod_rpcs_in_flight value
7548         set_mdt_max_mod_rpcs_in_flight $mmrpc_90c "mds1"
7549 }
7550
7551 test_90c() {
7552         local tmp
7553
7554         setup
7555
7556         [[ $($LCTL get_param mdc.*.import |
7557              grep "connect_flags:.*multi_mod_rpc") ]] ||
7558                 skip "Need MDC with 'multi_mod_rpcs' feature"
7559
7560         # check client is able to send multiple modify RPCs in paralell
7561         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
7562                 grep -c "multi_mod_rpcs")
7563         if [ "$tmp" -ne $MDSCOUNT ]; then
7564                 cleanup
7565                 skip "Client not able to send multiple modify RPCs in parallel"
7566         fi
7567
7568         save_params_90c
7569         stack_trap restore_params_90c
7570
7571         # testcase 1
7572         # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
7573         # prerequisite: set MDT max_mod_rpcs_in_flight to
7574         # max_rpcs_in_flight value
7575         set_mdt_max_mod_rpcs_in_flight $mrif_90c "mds1"
7576
7577         # if max_mod_rpcs_in_flight is set to be equal to or larger than
7578         # max_rpcs_in_flight, then max_rpcs_in_flight will be increased
7579         if [[ "$CLIENT_VERSION" -ge $(version_code 2.13.53) ]]; then
7580                 $LCTL set_param \
7581                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif_90c ||
7582                         error "set max_mod_rpcs_in_flight to $mrif_90c failed"
7583
7584                 local new_mrif=$($LCTL get_param -n \
7585                                  mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
7586                 ((new_mrif == mrif_90c + 1)) ||
7587                         error "max_rpcs_in_flight was not increased"
7588         fi
7589
7590         umount_client $MOUNT
7591         set_mdt_max_mod_rpcs_in_flight $mmrpc_90c "mds1"
7592         mount_client $MOUNT
7593
7594         # testcase 2
7595         # attempt to set max_mod_rpcs_in_flight to MDT max_mod_rpcs_in_flight+1
7596         # prerequisite: set max_rpcs_in_flight to MDT max_mod_rpcs_in_flight+2
7597         $LCTL set_param \
7598                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc_90c + 2))
7599
7600         $LCTL set_param \
7601         mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc_90c + 1)) &&
7602         error "set max_mod_rpcs_in_flight to $((mmrpc_90c + 1)) should fail"
7603
7604         # testcase 3
7605         # attempt to set max_mod_rpcs_in_flight permanently
7606         do_facet mgs $LCTL set_param -P \
7607                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$mrif_90c
7608
7609         do_facet mgs $LCTL set_param -P \
7610                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif_90c
7611
7612         remount_client $MOUNT
7613
7614         wait_update_facet --verbose client "$LCTL get_param -n \
7615                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight" \
7616                 "$((mrif_90c + 1))" ||
7617                 error "expected '$((mrif_90c + 1))' for max_rpcs_in_flight"
7618
7619         wait_update_facet --verbose client "$LCTL get_param -n \
7620                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight" \
7621                 "$mrif_90c" ||
7622                 error "expected '$mrif_90c' for max_mod_rpcs_in_flight"
7623
7624         restore_params_90c
7625         cleanup
7626 }
7627 run_test 90c "check max_mod_rpcs_in_flight update limits"
7628
7629 test_90d() {
7630         local idx
7631         local facet
7632         local mmr
7633         local i
7634         local pid
7635
7636         setup
7637
7638         [[ $($LCTL get_param mdc.*.import |
7639              grep "connect_flags:.*multi_mod_rpc") ]] ||
7640                 skip "Need MDC with 'multi_mod_rpcs' feature"
7641
7642         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
7643         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
7644         facet="mds$((0x$idx + 1))"
7645
7646         # check client version supports multislots
7647         tmp=$($LCTL get_param -N \
7648                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
7649         if [ -z "$tmp" ]; then
7650                 cleanup
7651                 skip "Client does not support multiple modify RPCs in flight"
7652         fi
7653
7654         # get current value of max_mod_rcps_in_flight
7655         mmr=$($LCTL get_param -n \
7656                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
7657         echo "max_mod_rcps_in_flight is $mmr"
7658
7659         # create mmr files
7660         echo "creating $mmr files ..."
7661         umask 0022
7662         for i in $(seq $mmr); do
7663                 touch $DIR/$tdir/file-$i
7664         done
7665
7666         # prepare for close RPC
7667         multiop_bg_pause $DIR/$tdir/file-close O_c
7668         pid=$!
7669
7670         # consumes mmr modify RPC slots
7671         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
7672         # drop requests on MDT so that RPC slots are consumed
7673         # during all the request resend interval
7674         do_facet $facet "$LCTL set_param fail_loc=0x159"
7675         echo "launch $mmr chmod in parallel ..."
7676         for i in $(seq $mmr); do
7677                 chmod 0600 $DIR/$tdir/file-$i &
7678         done
7679
7680         # send one additional close RPC
7681         do_facet $facet "$LCTL set_param fail_loc=0"
7682         echo "launch 1 additional close in parallel ..."
7683         kill -USR1 $pid
7684         cancel_lru_locks mdc
7685         sleep 1
7686
7687         # check this additional close RPC get a modify RPC slot
7688         # and multiop process completed
7689         [ -d /proc/$pid ] &&
7690                 error "Unable to send the additional close RPC in parallel"
7691         wait
7692         rm -rf $DIR/$tdir
7693         cleanup
7694 }
7695 run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
7696
7697 check_uuid_on_ost() {
7698         local nid=$1
7699         do_facet ost1 "$LCTL get_param obdfilter.${FSNAME}*.exports.'$nid'.uuid"
7700 }
7701
7702 check_uuid_on_mdt() {
7703         local nid=$1
7704         do_facet $SINGLEMDS "$LCTL get_param mdt.${mds1_svc}*.exports.'$nid'.uuid"
7705 }
7706
7707 test_91() {
7708         local uuid
7709         local nid
7710         local found
7711
7712         [[ "$OST1_VERSION" -ge $(version_code 2.7.63) ]] ||
7713                 skip "Need OST version at least 2.7.63"
7714         [[ "$MDS1_VERSION" -ge $(version_code 2.7.63) ]] ||
7715                 skip "Need MDT version at least 2.7.63"
7716
7717         start_mds || error "MDS start failed"
7718         start_ost || error "unable to start OST"
7719         mount_client $MOUNT || error "client start failed"
7720         check_mount || error "check_mount failed"
7721
7722         if remote_mds; then
7723                 nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
7724         else
7725                 nid="0@lo"
7726         fi
7727         uuid=$(get_client_uuid $MOUNT)
7728
7729         echo "list nids on mdt:"
7730         do_facet $SINGLEMDS "$LCTL list_param mdt.${FSNAME}*.exports.*"
7731         echo "uuid from $nid:"
7732         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
7733
7734         found=$(check_uuid_on_mdt $nid | grep $uuid)
7735         [ -z "$found" ] && error "can't find $uuid $nid on MDT"
7736         found=$(check_uuid_on_ost $nid | grep $uuid)
7737         [ -z "$found" ] && error "can't find $uuid $nid on OST"
7738
7739         # umount the client so it won't reconnect
7740         manual_umount_client --force || error "failed to umount $?"
7741         # shouldn't disappear on MDS after forced umount
7742         found=$(check_uuid_on_mdt $nid | grep $uuid)
7743         [ -z "$found" ] && error "can't find $uuid $nid"
7744
7745         echo "evict $nid"
7746         do_facet $SINGLEMDS \
7747                 "$LCTL set_param -n mdt.${mds1_svc}.evict_client nid:$nid"
7748         sleep 1 # eviction above is async, give it some time to proceed
7749
7750         found=$(check_uuid_on_mdt $nid | grep $uuid)
7751         [ -n "$found" ] && error "found $uuid $nid on MDT"
7752         found=$(check_uuid_on_ost $nid | grep $uuid)
7753         [ -n "$found" ] && error "found $uuid $nid on OST"
7754
7755         # check it didn't reconnect (being umounted)
7756         sleep $((TIMEOUT+1))
7757         found=$(check_uuid_on_mdt $nid | grep $uuid)
7758         [ -n "$found" ] && error "found $uuid $nid on MDT"
7759         found=$(check_uuid_on_ost $nid | grep $uuid)
7760         [ -n "$found" ] && error "found $uuid $nid on OST"
7761
7762         cleanup
7763 }
7764 run_test 91 "evict-by-nid support"
7765
7766 generate_ldev_conf() {
7767         # generate an ldev.conf file
7768         local ldevconfpath=$1
7769         local fstype=
7770         local fsldevformat=""
7771         rm -f $ldevconfpath
7772
7773         local facets="mgs,$(get_facets OST),$(get_facets MDS)"
7774         for facet in ${facets//,/ }; do
7775                 fsldevformat=""
7776                 fstype=$(facet_fstype $facet)
7777                 [ "$fstype" = zfs ] && fsldevformat="$fstype:"
7778                 local host=$(facet_host $facet)
7779                 local fo="-"
7780                 local varfo=${facet}failover_HOST
7781                 if [ $facet == mgs ] && combined_mgs_mds; then
7782                         varfo=mds1failover_HOST
7783                 fi
7784                 [ -n "${!varfo}" ] && fo=${!varfo}
7785                 local type=$(echo $facet | tr -d "[:digit:]" | \
7786                         tr "[:lower:]" "[:upper:]" | sed s/MDS/MDT/ )
7787                 local num=1
7788                 [ ${facet} == mgs ] ||
7789                         num=$(facet_number $facet)
7790                 printf "%s\t%s\t%s-%s%04x\t%s%s\n" \
7791                         ${host} \
7792                         ${fo} \
7793                         $FSNAME \
7794                         $type \
7795                         $(( num - 1 )) \
7796                         $fsldevformat \
7797                         $(facet_device $facet) >> $ldevconfpath
7798         done
7799
7800         echo "----- $ldevconfpath -----"
7801         cat $ldevconfpath
7802         echo "--- END $ldevconfpath ---"
7803
7804 }
7805
7806 generate_nids() {
7807         # generate a nids file (mapping between hostname to nid)
7808         # looks like we only have the MGS nid available to us
7809         # so just echo that to a file
7810         local nidspath=$1
7811         echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
7812
7813         echo "----- $nidspath -----"
7814         cat $nidspath
7815         echo "--- END $nidspath ---"
7816 }
7817
7818 compare_ldev_output() {
7819         local ldev_output=$1
7820         local expected_output=$2
7821
7822         sort $expected_output -o $expected_output
7823         sort $ldev_output -o $ldev_output
7824
7825         echo "-- START OF LDEV OUTPUT --"
7826         cat $ldev_output
7827         echo "--- END OF LDEV OUTPUT ---"
7828
7829         echo "-- START OF EXPECTED OUTPUT --"
7830         cat $expected_output
7831         echo "--- END OF EXPECTED OUTPUT ---"
7832
7833         diff $expected_output $ldev_output
7834         return $?
7835 }
7836
7837 test_92() {
7838         if [ -z "$LDEV" ]; then
7839                 error "ldev is missing!"
7840         fi
7841
7842         local LDEVCONFPATH=$TMP/ldev.conf
7843         local NIDSPATH=$TMP/nids
7844
7845         echo "Host is $(hostname)"
7846
7847         generate_ldev_conf $LDEVCONFPATH
7848         generate_nids $NIDSPATH
7849
7850         # echo the mgs nid and compare it to environment variable MGSNID
7851         local facets="$(get_facets OST),$(get_facets MDS),mgs"
7852         for facet in ${facets//,/ }; do
7853                 local host=$(facet_host $facet)
7854                 local output=$($LDEV -c $LDEVCONFPATH -H $host -n $NIDSPATH echo %m)
7855
7856                 echo "-- START OF LDEV OUTPUT --"
7857                 echo -e "$output"
7858                 echo "--- END OF LDEV OUTPUT ---"
7859
7860                 [ -z "$output" ] &&
7861                         error "ldev failed to execute!"
7862
7863                 # need to process multiple lines because of
7864                 # several targets on host
7865                 echo -e $output | awk '{ print $2 }' | while read -r line ; do
7866                         [ "$line" = "$MGSNID" ] ||
7867                                 error "ldev failed mgs nid '$line', \
7868                                         expected '$MGSNID'"
7869                 done
7870         done
7871         rm -f $LDEVCONFPATH $NIDSPATH
7872 }
7873 run_test 92 "ldev returns MGS NID correctly in command substitution"
7874
7875 test_93() {
7876         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
7877
7878         reformat
7879         #start mgs or mgs/mdt0
7880         if ! combined_mgs_mds ; then
7881                 start_mgs
7882                 start_mdt 1
7883         else
7884                 start_mdt 1
7885         fi
7886
7887         start_ost || error "OST0 start fail"
7888
7889         #define OBD_FAIL_MGS_WRITE_TARGET_DELAY  0x90e
7890         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x8000090e"
7891         for num in $(seq 2 $MDSCOUNT); do
7892                 start_mdt $num &
7893         done
7894
7895         mount_client $MOUNT || error "mount client fails"
7896         wait_osc_import_state mds ost FULL
7897         wait_osc_import_ready client ost
7898         check_mount || error "check_mount failed"
7899
7900         cleanup || error "cleanup failed with $?"
7901 }
7902 run_test 93 "register mulitple MDT at the same time"
7903
7904 test_94() {
7905         if [ -z "$LDEV" ]; then
7906                 error "ldev is missing!"
7907         fi
7908
7909         local LDEVCONFPATH=$TMP/ldev.conf
7910         local NIDSPATH=$TMP/nids
7911
7912         generate_ldev_conf $LDEVCONFPATH
7913         generate_nids $NIDSPATH
7914
7915         local LDEV_OUTPUT=$TMP/ldev-output.txt
7916         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME > $LDEV_OUTPUT
7917
7918         # ldev failed, error
7919         if [ $? -ne 0 ]; then
7920                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7921                 error "ldev failed to execute!"
7922         fi
7923
7924         # expected output
7925         local EXPECTED_OUTPUT=$TMP/ldev-expected.txt
7926
7927         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
7928
7929         for num in $(seq $MDSCOUNT); do
7930                 printf "%s-MDT%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
7931         done
7932
7933         for num in $(seq $OSTCOUNT); do
7934                 printf "%s-OST%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
7935         done
7936
7937         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7938
7939         if [ $? -ne 0 ]; then
7940                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7941                 error "ldev failed to produce the correct hostlist!"
7942         fi
7943
7944         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7945 }
7946 run_test 94 "ldev outputs correct labels for file system name query"
7947
7948 test_95() {
7949         if [ -z "$LDEV" ]; then
7950                 error "ldev is missing!"
7951         fi
7952
7953         local LDEVCONFPATH=$TMP/ldev.conf
7954         local NIDSPATH=$TMP/nids
7955
7956         generate_ldev_conf $LDEVCONFPATH
7957         generate_nids $NIDSPATH
7958
7959         # SUCCESS CASES
7960         # file sys filter
7961         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
7962         if [ $? -ne 0 ]; then
7963                 rm $LDEVCONFPATH $NIDSPATH
7964                 error "ldev label filtering w/ -F failed!"
7965         fi
7966
7967         # local filter
7968         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
7969         if [ $? -ne 0 ]; then
7970                 rm $LDEVCONFPATH $NIDSPATH
7971                 error "ldev label filtering w/ -l failed!"
7972         fi
7973
7974         # foreign filter
7975         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
7976         if [ $? -ne 0 ]; then
7977                 rm $LDEVCONFPATH $NIDSPATH
7978                 error "ldev label filtering w/ -f failed!"
7979         fi
7980
7981         # all filter
7982         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
7983         if [ $? -ne 0 ]; then
7984                 rm $LDEVCONFPATH $NIDSPATH
7985                 error "ldev label filtering w/ -a failed!"
7986         fi
7987
7988         # FAILURE CASES
7989         # all & file sys
7990         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
7991         if [ $? -eq 0 ]; then
7992                 rm $LDEVCONFPATH $NIDSPATH
7993                 error "ldev label filtering w/ -a and -F incorrectly succeeded"
7994         fi
7995
7996         # all & foreign
7997         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
7998         if [ $? -eq 0 ]; then
7999                 rm $LDEVCONFPATH $NIDSPATH
8000                 error "ldev label filtering w/ -a and -f incorrectly succeeded"
8001         fi
8002
8003         # all & local
8004         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
8005         if [ $? -eq 0 ]; then
8006                 rm $LDEVCONFPATH $NIDSPATH
8007                 error "ldev label filtering w/ -a and -l incorrectly succeeded"
8008         fi
8009
8010         # foreign & local
8011         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
8012         if [ $? -eq 0 ]; then
8013                 rm $LDEVCONFPATH $NIDSPATH
8014                 error "ldev label filtering w/ -f and -l incorrectly succeeded"
8015         fi
8016
8017         # file sys & local
8018         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
8019         if [ $? -eq 0 ]; then
8020                 rm $LDEVCONFPATH $NIDSPATH
8021                 error "ldev label filtering w/ -F and -l incorrectly succeeded"
8022         fi
8023
8024         # file sys & foreign
8025         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
8026         if [ $? -eq 0 ]; then
8027                 rm $LDEVCONFPATH $NIDSPATH
8028                 error "ldev label filtering w/ -F and -f incorrectly succeeded"
8029         fi
8030
8031         rm $LDEVCONFPATH $NIDSPATH
8032 }
8033 run_test 95 "ldev should only allow one label filter"
8034
8035 test_96() {
8036         if [ -z "$LDEV" ]; then
8037                 error "ldev is missing!"
8038         fi
8039
8040         local LDEVCONFPATH=$TMP/ldev.conf
8041         local NIDSPATH=$TMP/nids
8042
8043         generate_ldev_conf $LDEVCONFPATH
8044         generate_nids $NIDSPATH
8045
8046         local LDEV_OUTPUT=$TMP/ldev-output.txt
8047         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -H $mgs_HOST \
8048                 echo %H-%b | \
8049                 awk '{print $2}' > $LDEV_OUTPUT
8050
8051         # ldev failed, error
8052         if [ $? -ne 0 ]; then
8053                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
8054                 error "ldev failed to execute!"
8055         fi
8056
8057         # expected output
8058         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
8059
8060         echo "$mgs_HOST-$(facet_fstype mgs)" > $EXPECTED_OUTPUT
8061
8062         local facets="$(get_facets OST),$(get_facets MDS)"
8063         for facet in ${facets//,/ }; do
8064                 local host=$(facet_host $facet)
8065                 [ "$mgs_HOST" == "$host" ] &&
8066                         echo "$host-$(facet_fstype $facet)" \
8067                         >> $EXPECTED_OUTPUT
8068         done
8069
8070         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8071
8072         if [ $? -ne 0 ]; then
8073                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8074                 error "ldev failed to produce the correct output!"
8075         fi
8076
8077         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8078 }
8079 run_test 96 "ldev returns hostname and backend fs correctly in command sub"
8080
8081 test_97() {
8082         if [ -z "$LDEV" ]; then
8083                 error "ldev is missing!"
8084         fi
8085
8086         local LDEVCONFPATH=$TMP/ldev.conf
8087         local NIDSPATH=$TMP/nids
8088
8089         generate_ldev_conf $LDEVCONFPATH
8090         generate_nids $NIDSPATH
8091
8092         local LDEV_OUTPUT=$TMP/ldev-output.txt
8093         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
8094
8095         echo -e "\nMDT role"
8096         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mdt > $LDEV_OUTPUT
8097
8098         if [ $? -ne 0 ]; then
8099                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
8100                 error "ldev failed to execute for mdt role!"
8101         fi
8102
8103         for num in $(seq $MDSCOUNT); do
8104                 printf "%s-MDT%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
8105         done
8106
8107         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8108
8109         if [ $? -ne 0 ]; then
8110                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8111                 error "ldev failed to produce the correct output for mdt role!"
8112         fi
8113
8114         echo -e "\nOST role"
8115         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R ost > $LDEV_OUTPUT
8116
8117         if [ $? -ne 0 ]; then
8118                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
8119                 error "ldev failed to execute for ost role!"
8120         fi
8121
8122         rm $EXPECTED_OUTPUT
8123         for num in $(seq $OSTCOUNT); do
8124                 printf "%s-OST%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
8125         done
8126
8127         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8128
8129         if [ $? -ne 0 ]; then
8130                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8131                 error "ldev failed to produce the correct output for ost role!"
8132         fi
8133
8134         echo -e "\nMGS role"
8135         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mgs > $LDEV_OUTPUT
8136
8137         if [ $? -ne 0 ]; then
8138                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
8139                 error "ldev failed to execute for mgs role!"
8140         fi
8141
8142         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
8143
8144         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8145
8146         if [ $? -ne 0 ]; then
8147                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8148                 error "ldev failed to produce the correct output for mgs role!"
8149         fi
8150
8151         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8152 }
8153 run_test 97 "ldev returns correct ouput when querying based on role"
8154
8155 test_98()
8156 {
8157         local mountopt
8158
8159         setup
8160         check_mount || error "mount failed"
8161         mountopt="user_xattr"
8162         for ((x = 1; x <= PAGE_SIZE/11; x++)); do
8163                 mountopt="$mountopt,user_xattr"
8164         done
8165         mount_client $MOUNT remount,$mountopt 2>&1 | grep "too long" ||
8166                 error "Buffer overflow check failed"
8167         cleanup || error "cleanup failed"
8168 }
8169 run_test 98 "Buffer-overflow check while parsing mount_opts"
8170
8171 test_99()
8172 {
8173         [[ "$ost1_FSTYPE" != ldiskfs ]] &&
8174                 skip "ldiskfs only test"
8175         [[ "$OST1_VERSION" -ge $(version_code 2.8.57) ]] ||
8176                 skip "Need OST version at least 2.8.57"
8177
8178         local ost_opts="$(mkfs_opts ost1 $(ostdevname 1)) \
8179                 --reformat $(ostdevname 1) $(ostvdevname 1)"
8180         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" &&
8181                 skip "meta_bg already set"
8182
8183         local opts=ost_opts
8184         if [[ ${!opts} != *mkfsoptions* ]]; then
8185                 eval opts=\"${!opts} \
8186                 --mkfsoptions='\\\"-O ^resize_inode,meta_bg\\\"'\"
8187         else
8188                 local val=${!opts//--mkfsoptions=\\\"/ \
8189                 --mkfsoptions=\\\"-O ^resize_inode,meta_bg }
8190                 eval opts='${val}'
8191         fi
8192
8193         echo "params: $opts"
8194
8195         load_modules
8196         add ost1 $opts || error "add ost1 failed with new params"
8197
8198         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" ||
8199                 error "meta_bg is not set"
8200 }
8201 run_test 99 "Adding meta_bg option"
8202
8203 test_100() {
8204         reformat
8205
8206         start_mgsmds || error "MDS start failed"
8207         start_ost || error "unable to start OST"
8208         mount_client $MOUNT || error "client start failed"
8209         check_mount || error "check_mount failed"
8210
8211         # Desired output
8212         # MGS:
8213         #     0@lo
8214         # $FSNAME-MDT0000:
8215         #     0@lo
8216         # $FSNAME-OST0000:
8217         #     0@lo
8218         do_facet mgs 'lshowmount -v' | awk 'BEGIN {NR == 0; rc=1} /MGS:/ {rc=0}
8219                 END {exit rc}' || error "lshowmount have no output MGS"
8220
8221         do_facet mds1 'lshowmount -v' | awk 'BEGIN {NR == 2; rc=1} /-MDT0000:/
8222                 {rc=0} END {exit rc}' || error "lshowmount have no output MDT0"
8223
8224         do_facet ost1 'lshowmount -v' | awk 'BEGIN {NR == 4; rc=1} /-OST0000:/
8225                 {rc=0} END {exit rc}' || error "lshowmount have no output OST0"
8226
8227         cleanup || error "cleanup failed with $?"
8228 }
8229 run_test 100 "check lshowmount lists MGS, MDT, OST and 0@lo"
8230
8231 test_101a() {
8232         local createmany_pid
8233         local dev=$FSNAME-OST0000-osc-MDT0000
8234         setup
8235
8236         mkdir $DIR1/$tdir
8237         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param \
8238                 seq.*OST*-super.width=$DATA_SEQ_MAX_WIDTH
8239         createmany -o $DIR1/$tdir/$tfile-%d 50000 &
8240         createmany_pid=$!
8241         # MDT->OST reconnection causes MDT<->OST last_id synchornisation
8242         # via osp_precreate_cleanup_orphans.
8243         for ((i = 0; i < 100; i++)); do
8244                 for ((k = 0; k < 10; k++)); do
8245                         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;" \
8246                                             "$LCTL --device $dev activate"
8247                 done
8248
8249                 ls -asl $MOUNT | grep '???' &&
8250                         { kill -9 $createmany_pid &>/dev/null;
8251                           error "File has no object on OST"; }
8252
8253                 kill -s 0 $createmany_pid || break
8254         done
8255         wait $createmany_pid
8256
8257         unlinkmany $DIR1/$tdir/$tfile-%d 50000
8258         cleanup
8259 }
8260 run_test 101a "Race MDT->OST reconnection with create"
8261
8262 test_101b () {
8263         local dev=$FSNAME-OST0000-osc-MDT0000
8264         local dir=$DIR1/$tdir
8265         setup
8266
8267         mkdir $dir
8268         $LFS setstripe -c 1 -i 0 $dir
8269         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;"
8270 #define OBD_FAIL_OSP_CON_EVENT_DELAY 0x2107
8271         do_facet mds1 "$LCTL set_param fail_loc=0x80002107 fail_val=20"
8272         do_facet $SINGLEMDS "$LCTL --device $dev activate;"
8273         stop_ost
8274         sleep 25
8275         start_ost
8276
8277         wait_osc_import_ready client ost1
8278         touch $dir/$tfile || error "Can't create file"
8279
8280         cleanup
8281 }
8282 run_test 101b "Race events DISCONNECT and ACTIVE in osp"
8283
8284 test_102() {
8285         [[ "$MDS1_VERSION" -gt $(version_code 2.9.53) ]] ||
8286                 skip "Need server version greater than 2.9.53"
8287         [[ "$(mdsdevname 1)" != "$(mgsdevname)" ]] &&
8288                 [[ "$(facet_host mds1)" == "$(facet_host mgs)" ]] &&
8289                 skip "MGS must be on different node or combined"
8290
8291         cleanup || error "cleanup failed with $?"
8292
8293         local mds1dev=$(mdsdevname 1)
8294         local mds1mnt=$(facet_mntpt mds1)
8295         local mds1opts=$MDS_MOUNT_OPTS
8296
8297         if [ "$mds1_FSTYPE" == ldiskfs ] &&
8298            ! do_facet mds1 test -b $mds1dev; then
8299                 mds1opts=$(csa_add "$mds1opts" -o loop)
8300         fi
8301         if [[ "$mds1_FSTYPE" == zfs ]]; then
8302                 import_zpool mds1 || return ${PIPESTATUS[0]}
8303         fi
8304
8305         # unload all and only load libcfs to allow fail_loc setting
8306         do_facet mds1 $LUSTRE_RMMOD || error "unable to unload modules"
8307         do_rpc_nodes $(facet_active_host mds1) load_module ../libcfs/libcfs/libcfs
8308         do_facet mds1 lsmod | grep libcfs || error "libcfs not loaded"
8309
8310         #define OBD_FAIL_OBDCLASS_MODULE_LOAD    0x60a
8311         do_facet mds1 "$LCTL set_param fail_loc=0x8000060a"
8312
8313         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
8314                 error "mdt start must fail" || log "mount failed as expected"
8315         do_facet mds1 lsmod | grep obdclass && error "obdclass must not load" ||
8316                 log "obdclass not loaded as expected"
8317
8318         do_facet mds1 "$LCTL set_param fail_loc=0x0"
8319
8320         do_rpc_nodes $(facet_active_host mds1) load_modules
8321         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
8322                 log "mds1 mounted properly" ||
8323                 error "mdt start must not fail"
8324
8325         cleanup || error "cleanup failed with $?"
8326 }
8327 run_test 102 "obdclass module cleanup upon error"
8328
8329 test_renamefs() {
8330         local newname=$1
8331
8332         echo "rename $FSNAME to $newname"
8333
8334         if ! combined_mgs_mds ; then
8335                 local dev=$(mgsdevname)
8336
8337                 do_facet mgs \
8338                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
8339                                 error "(7) Fail to rename MGS"
8340                 if [ "$(facet_fstype mgs)" = "zfs" ]; then
8341                         reimport_zpool mgs $newname-mgs
8342                 fi
8343         fi
8344
8345         for num in $(seq $MDSCOUNT); do
8346                 local dev=$(mdsdevname $num)
8347
8348                 do_facet mds${num} \
8349                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
8350                                 error "(8) Fail to rename MDT $num"
8351                 if [ "$(facet_fstype mds${num})" = "zfs" ]; then
8352                         reimport_zpool mds${num} $newname-mdt${num}
8353                 fi
8354         done
8355
8356         for num in $(seq $OSTCOUNT); do
8357                 local dev=$(ostdevname $num)
8358
8359                 do_facet ost${num} \
8360                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
8361                                 error "(9) Fail to rename OST $num"
8362                 if [ "$(facet_fstype ost${num})" = "zfs" ]; then
8363                         reimport_zpool ost${num} $newname-ost${num}
8364                 fi
8365         done
8366 }
8367
8368 test_103_set_pool() {
8369         local pname=$1
8370         local ost_x=$2
8371
8372         do_facet mgs $LCTL pool_add $FSNAME.$pname ${FSNAME}-$ost_x ||
8373                 error "Fail to add $ost_x to $FSNAME.$pname"
8374         wait_update $HOSTNAME \
8375                 "lctl get_param -n lov.$FSNAME-clilov-*.pools.$pname |
8376                  grep $ost_x" "$FSNAME-${ost_x}_UUID" ||
8377                 error "$ost_x is NOT in pool $FSNAME.$pname"
8378 }
8379
8380 test_103_check_pool() {
8381         local save_fsname=$1
8382         local errno=$2
8383
8384         stat $DIR/$tdir/test-framework.sh ||
8385                 error "($errno) Fail to stat"
8386         do_facet mgs $LCTL pool_list $FSNAME.pool1 ||
8387                 error "($errno) Fail to list $FSNAME.pool1"
8388         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname ||
8389                 error "($errno) Fail to list $FSNAME.$save_fsname"
8390         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname |
8391                 grep ${FSNAME}-OST0000 ||
8392                 error "($errno) List $FSNAME.$save_fsname is invalid"
8393
8394         local pname=$($LFS getstripe --pool $DIR/$tdir/d0)
8395         [ "$pname" = "$save_fsname" ] ||
8396                 error "($errno) Unexpected pool name $pname"
8397 }
8398
8399 test_103() {
8400         check_mount_and_prep
8401         rm -rf $DIR/$tdir
8402         mkdir $DIR/$tdir || error "(1) Fail to mkdir $DIR/$tdir"
8403         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir ||
8404                 error "(2) Fail to copy test-framework.sh"
8405
8406         do_facet mgs $LCTL pool_new $FSNAME.pool1 ||
8407                 error "(3) Fail to create $FSNAME.pool1"
8408         # name the pool name as the fsname
8409         do_facet mgs $LCTL pool_new $FSNAME.$FSNAME ||
8410                 error "(4) Fail to create $FSNAME.$FSNAME"
8411
8412         test_103_set_pool $FSNAME OST0000
8413
8414         $LFS setstripe -p $FSNAME $DIR/$tdir/d0 ||
8415                 error "(6) Fail to setstripe on $DIR/$tdir/d0"
8416
8417         KEEP_ZPOOL=true
8418         stopall
8419
8420         test_renamefs mylustre
8421
8422         local save_fsname=$FSNAME
8423         FSNAME="mylustre"
8424         setupall
8425
8426         test_103_check_pool $save_fsname 7
8427
8428         if [ $OSTCOUNT -ge 2 ]; then
8429                 test_103_set_pool $save_fsname OST0001
8430         fi
8431
8432         $LFS setstripe -p $save_fsname $DIR/$tdir/f0 ||
8433                 error "(16) Fail to setstripe on $DIR/$tdir/f0"
8434
8435         stopall
8436
8437         test_renamefs tfs
8438
8439         FSNAME="tfs"
8440         setupall
8441
8442         test_103_check_pool $save_fsname 17
8443
8444         stopall
8445
8446         test_renamefs $save_fsname
8447
8448         FSNAME=$save_fsname
8449         setupall
8450         KEEP_ZPOOL=false
8451 }
8452 run_test 103 "rename filesystem name"
8453
8454 test_104a() { # LU-6952
8455         local mds_mountopts=$MDS_MOUNT_OPTS
8456         local ost_mountopts=$OST_MOUNT_OPTS
8457         local mds_mountfsopts=$MDS_MOUNT_FS_OPTS
8458         local lctl_ver=$(do_facet $SINGLEMDS $LCTL --version |
8459                         awk '{ print $2 }')
8460
8461         [[ $(version_code $lctl_ver) -lt $(version_code 2.9.55) ]] &&
8462                 skip "this test needs utils above 2.9.55"
8463
8464         # specify "acl" in mount options used by mkfs.lustre
8465         if [ -z "$MDS_MOUNT_FS_OPTS" ]; then
8466                 MDS_MOUNT_FS_OPTS="acl,user_xattr"
8467         else
8468
8469                 MDS_MOUNT_FS_OPTS="${MDS_MOUNT_FS_OPTS},acl,user_xattr"
8470         fi
8471
8472         echo "mountfsopt: $MDS_MOUNT_FS_OPTS"
8473
8474         #reformat/remount the MDT to apply the MDT_MOUNT_FS_OPT options
8475         formatall
8476         if ! combined_mgs_mds ; then
8477                 start_mgs
8478         fi
8479
8480         if [ -z "$MDS_MOUNT_OPTS" ]; then
8481                 MDS_MOUNT_OPTS="-o noacl"
8482         else
8483                 MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
8484         fi
8485
8486         for num in $(seq $MDSCOUNT); do
8487                 start mds$num $(mdsdevname $num) $MDS_MOUNT_OPTS ||
8488                         error "Failed to start MDS"
8489         done
8490
8491         for num in $(seq $OSTCOUNT); do
8492                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
8493                         error "Failed to start OST"
8494         done
8495
8496         mount_client $MOUNT
8497         setfacl -m "d:$RUNAS_ID:rwx" $MOUNT &&
8498                 error "ACL is applied when FS is mounted with noacl."
8499
8500         MDS_MOUNT_OPTS=$mds_mountopts
8501         OST_MOUNT_OPTS=$ost_mountopts
8502         MDS_MOUNT_FS_OPTS=$mds_mountfsopts
8503 }
8504 run_test 104a "Make sure user defined options are reflected in mount"
8505
8506 test_104b() { # LU-12859
8507         mount_client $MOUNT3 flock,localflock
8508         stack_trap "umount_client $MOUNT3" EXIT
8509         mount | grep "$MOUNT3 .*,flock" && error "flock is still set"
8510         mount | grep "$MOUNT3 .*,localflock" || error "localflock is not set"
8511         umount_client $MOUNT3
8512         mount_client $MOUNT3 localflock,flock
8513         mount | grep "$MOUNT3 .*,localflock" && error "localflock is still set"
8514         mount | grep "$MOUNT3 .*,flock" || error "flock is not set"
8515         umount_client $MOUNT3
8516         mount_client $MOUNT3 localflock,flock,noflock
8517         flock_is_enabled $MOUNT3 && error "some flock is still enabled" || true
8518 }
8519 run_test 104b "Mount uses last flock argument"
8520
8521 error_and_umount() {
8522         umount $TMP/$tdir
8523         rmdir $TMP/$tdir
8524         error $*
8525 }
8526
8527 test_105() {
8528         cleanup -f
8529         reformat
8530         setup_noconfig
8531         mkdir -p $TMP/$tdir
8532         mount --bind $DIR $TMP/$tdir || error "mount bind mnt pt failed"
8533         rm -f $TMP/$tdir/$tfile
8534         rm -f $TMP/$tdir/${tfile}1
8535
8536         # Files should not be created in ro bind mount point
8537         # remounting from rw to ro
8538         mount -o remount,ro $TMP/$tdir ||
8539                 error_and_umount "readonly remount of bind mnt pt failed"
8540         touch $TMP/$tdir/$tfile &&
8541                 error_and_umount "touch succeeds on ro bind mnt pt"
8542         [ -e $TMP/$tdir/$tfile ] &&
8543                 error_and_umount "file created on ro bind mnt pt"
8544
8545         # Files should be created in rw bind mount point
8546         # remounting from ro to rw
8547         mount -o remount,rw $TMP/$tdir ||
8548                 error_and_umount "read-write remount of bind mnt pt failed"
8549         touch $TMP/$tdir/${tfile}1 ||
8550                 error_and_umount "touch fails on rw bind mnt pt"
8551         [ -e $TMP/$tdir/${tfile}1 ] ||
8552                 error_and_umount "file not created on rw bind mnt pt"
8553         umount $TMP/$tdir || error "umount of bind mnt pt failed"
8554         rmdir $TMP/$tdir
8555         cleanup || error "cleanup failed with $?"
8556 }
8557 run_test 105 "check file creation for ro and rw bind mnt pt"
8558
8559 test_106() {
8560         local repeat=5
8561         local creates=64768     # one full plain llog
8562
8563         # ensure there are enough inodes in the filesystem
8564         (( OSTSIZE < (creates + 1024) * 8)) && OSTSIZE=$(((creates + 1024) * 8))
8565         reformat
8566         setup_noconfig
8567         lfs df -i
8568         mkdir -p $DIR/$tdir || error "create $tdir failed"
8569         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param \
8570                 seq.*OST*-super.width=$DATA_SEQ_MAX_WIDTH
8571         lfs setstripe -c 1 -i 0 $DIR/$tdir
8572 #define OBD_FAIL_CAT_RECORDS                        0x1312
8573         do_facet mds1 $LCTL set_param fail_loc=0x1312 fail_val=$repeat
8574
8575         for ((i = 1; i <= $repeat; i++)); do
8576                 createmany -o $DIR/$tdir/f- $creates || lfs df -i
8577                 createmany -u $DIR/$tdir/f- $creates
8578                 wait_delete_completed $((TIMEOUT * 7))
8579         done
8580 #ASSERTION osp_sync_thread() ( thread->t_flags != SVC_RUNNING ) failed
8581 #shows that osp code is buggy
8582         do_facet mds1 $LCTL set_param fail_loc=0 fail_val=0
8583
8584         cleanup
8585 }
8586 run_test 106 "check osp llog processing when catalog is wrapped"
8587
8588 test_107() {
8589         [[ "$MDS1_VERSION" -ge $(version_code 2.10.50) ]] ||
8590                 skip "Need MDS version > 2.10.50"
8591         local cmd
8592
8593         start_mgsmds || error "start_mgsmds failed"
8594         start_ost || error "unable to start OST"
8595
8596         # add unknown configuration parameter.
8597         if [[ $PERM_CMD == *"set_param -P"* ]]; then
8598                 cmd="$PERM_CMD ost.$FSNAME-OST0000*.unknown_param"
8599         else
8600                 cmd="$PERM_CMD $FSNAME-OST0000*.ost.unknown_param"
8601         fi
8602         do_facet mgs "$cmd=50"
8603         cleanup_nocli || error "cleanup_nocli failed with $?"
8604         load_modules
8605
8606         # unknown param should be ignored while mounting.
8607         start_ost || error "unable to start OST after unknown param set"
8608
8609         cleanup || error "cleanup failed with $?"
8610 }
8611 run_test 107 "Unknown config param should not fail target mounting"
8612
8613 t_108_prep() {
8614         local facet
8615
8616         $rcmd rm -rf $tmp > /dev/null 2>&1
8617         $rcmd mkdir -p $tmp/{mnt,images} || error "failed to mkdir remotely"
8618
8619         for facet in $facets; do
8620                 [ "$mds1_FSTYPE" = zfs ] &&
8621                         $rcmd $ZPOOL -f export lustre-$facet > /dev/null 2>&1
8622                 $rcmd mkdir $tmp/mnt/$facet ||
8623                         error "failed to mkdir $tmp/mnt/$facet"
8624                 $rcmd dd if=/dev/zero of=$tmp/images/$facet \
8625                         seek=199 bs=1M count=1 ||
8626                         error "failed to create $tmp/images/$facet"
8627         done
8628 }
8629
8630 t_108_mkfs() {
8631         local role=$1
8632         local idx=$2
8633         local bkfs=$3
8634         local mgs=$4
8635         local facet=${role}$((idx + 1))
8636         local pool=""
8637         [ $# -eq 5 ] && pool=$5
8638
8639         do_facet $SINGLEMDS $MKFS --fsname=lustre --$mgs \
8640                 --$role --index=$idx --replace --backfstype=$bkfs \
8641                 --device-size=200000 --reformat $pool $tmp/images/$facet ||
8642                 error "failed to mkfs for $facet"
8643 }
8644
8645 t_108_check() {
8646         echo "mounting client..."
8647         mount -t lustre ${nid}:/lustre $MOUNT ||
8648                 error "failed to mount lustre"
8649
8650         echo "check list"
8651         ls -l $MOUNT/local_dir || error "failed to list"
8652
8653         echo "check truncate && write"
8654         echo "dummmmmmmmmmmmm" > $MOUNT/remote_dir/fsx.c ||
8655                 error "failed to tuncate & write"
8656
8657         echo "check create"
8658         touch $MOUNT/foooo ||
8659                 error "failed to create"
8660
8661         echo "check read && write && append"
8662         sha1sum $MOUNT/conf-sanity.sh |
8663                 awk '{ print $1 }' > $MOUNT/checksum.new ||
8664                 error "failed to read(1)"
8665         sha1sum $MOUNT/remote_dir/unlinkmany.c |
8666                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
8667                 error "failed to read(2)"
8668         sha1sum $MOUNT/striped_dir/lockahead_test.o |
8669                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
8670                 error "failed to read(3)"
8671
8672         echo "verify data"
8673         diff $MOUNT/checksum.new $MOUNT/checksum.src ||
8674                 error "failed to verify data"
8675
8676         echo "done."
8677 }
8678
8679 t_108_cleanup() {
8680         trap 0
8681         local facet
8682
8683         echo "cleanup..."
8684         umount -f $MOUNT || error "failed to umount client"
8685         for facet in $facets; do
8686                 $rcmd umount -f $tmp/mnt/$facet ||
8687                         error "failed to umount $facet"
8688                 if [ "$mds1_FSTYPE" = zfs ]; then
8689                         $rcmd $ZPOOL export -f lustre-$facet ||
8690                                 error "failed to export lustre-$facet"
8691                 fi
8692         done
8693
8694         $rcmd rm -rf $tmp || error "failed to rm the dir $tmp"
8695 }
8696
8697 test_108a() {
8698         [ "$CLIENTONLY" ] && skip "Client-only testing"
8699         [ "$mds1_FSTYPE" != zfs ] && skip "zfs only test"
8700         [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
8701                 skip "Need server version at least 2.10.58"
8702
8703         stopall
8704         load_modules
8705
8706         local tmp=$TMP/$tdir
8707         local rcmd="do_facet $SINGLEMDS"
8708         local facets="mdt1 mdt2 ost1 ost2"
8709         local nid=$($rcmd $LCTL list_nids | head -1)
8710         local facet
8711
8712         trap t_108_cleanup EXIT ERR
8713         t_108_prep
8714
8715         t_108_mkfs mdt 0 zfs mgs lustre-mdt1/mdt1
8716         t_108_mkfs mdt 1 zfs mgsnode=$nid lustre-mdt2/mdt2
8717         t_108_mkfs ost 0 zfs mgsnode=$nid lustre-ost1/ost1
8718         t_108_mkfs ost 1 zfs mgsnode=$nid lustre-ost2/ost2
8719
8720         for facet in $facets; do
8721                 $rcmd zfs set mountpoint=$tmp/mnt/$facet canmount=on \
8722                         lustre-$facet/$facet ||
8723                         error "failed to zfs set for $facet (1)"
8724                 $rcmd zfs mount lustre-$facet/$facet ||
8725                         error "failed to local mount $facet"
8726                 $rcmd tar jxf $LUSTRE/tests/ldiskfs_${facet}_2_11.tar.bz2 \
8727                         --xattrs --xattrs-include="trusted.*" \
8728                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
8729                         error "failed to untar image for $facet"
8730                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
8731                         error "failed to cleanup for $facet"
8732                 $rcmd zfs umount lustre-$facet/$facet ||
8733                         error "failed to local umount $facet"
8734                 $rcmd zfs set canmount=off lustre-$facet/$facet ||
8735                         error "failed to zfs set $facet (2)"
8736         done
8737
8738         echo "changing server nid..."
8739         $rcmd mount -t lustre -o nosvc lustre-mdt1/mdt1 $tmp/mnt/mdt1
8740         $rcmd lctl replace_nids $FSNAME-MDT0000 $nid
8741         $rcmd lctl replace_nids $FSNAME-MDT0001 $nid
8742         $rcmd lctl replace_nids $FSNAME-OST0000 $nid
8743         $rcmd lctl replace_nids $FSNAME-OST0001 $nid
8744         $rcmd umount $tmp/mnt/mdt1
8745
8746         for facet in $facets; do
8747                 echo "mounting $facet from backup..."
8748                 $rcmd mount -t lustre -o abort_recov lustre-$facet/$facet \
8749                         $tmp/mnt/$facet || error "failed to mount $facet"
8750         done
8751
8752         # ZFS backend can detect migration and trigger OI scrub automatically
8753         # sleep 3 seconds for scrub done
8754         sleep 3
8755
8756         t_108_check
8757         t_108_cleanup
8758 }
8759 run_test 108a "migrate from ldiskfs to ZFS"
8760
8761 test_108b() {
8762         [ "$CLIENTONLY" ] && skip "Client-only testing"
8763         [ "$mds1_FSTYPE" != ldiskfs ] && skip "ldiskfs only test"
8764         [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
8765                 skip "Need server version at least 2.10.58"
8766
8767         stopall
8768         load_modules
8769
8770         local tmp=$TMP/$tdir
8771         local rcmd="do_facet $SINGLEMDS"
8772         local facets="mdt1 mdt2 ost1 ost2"
8773         local scrub_list="MDT0000 MDT0001 OST0000 OST0001"
8774         local nid=$($rcmd $LCTL list_nids | head -1)
8775         local facet
8776
8777         trap t_108_cleanup EXIT ERR
8778         t_108_prep
8779
8780         t_108_mkfs mdt 0 ldiskfs mgs
8781         t_108_mkfs mdt 1 ldiskfs mgsnode=$nid
8782         t_108_mkfs ost 0 ldiskfs mgsnode=$nid
8783         t_108_mkfs ost 1 ldiskfs mgsnode=$nid
8784
8785         for facet in $facets; do
8786                 $rcmd mount -t ldiskfs -o loop $tmp/images/$facet \
8787                         $tmp/mnt/$facet ||
8788                         error "failed to local mount $facet"
8789
8790                 $rcmd tar jxf $LUSTRE/tests/zfs_${facet}_2_11.tar.bz2 \
8791                         --xattrs --xattrs-include="*.*" \
8792                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
8793                         error "failed to untar image for $facet"
8794                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
8795                         error "failed to cleanup for $facet"
8796                 $rcmd umount $tmp/mnt/$facet ||
8797                         error "failed to local umount $facet"
8798         done
8799
8800         echo "changing server nid..."
8801         $rcmd mount -t lustre -o nosvc,loop $tmp/images/mdt1 $tmp/mnt/mdt1
8802         $rcmd lctl replace_nids $FSNAME-MDT0000 $nid
8803         $rcmd lctl replace_nids $FSNAME-MDT0001 $nid
8804         $rcmd lctl replace_nids $FSNAME-OST0000 $nid
8805         $rcmd lctl replace_nids $FSNAME-OST0001 $nid
8806         $rcmd umount $tmp/mnt/mdt1
8807
8808         for facet in $facets; do
8809                 echo "mounting $facet from backup..."
8810                 $rcmd mount -t lustre -o loop,abort_recov $tmp/images/$facet \
8811                         $tmp/mnt/$facet || error "failed to mount $facet"
8812         done
8813
8814         for facet in $scrub_list; do
8815                 $rcmd $LCTL lfsck_start -M $FSNAME-$facet -t scrub ||
8816                         error "failed to start OI scrub on $facet"
8817         done
8818
8819         # sleep 3 seconds for scrub done
8820         sleep 3
8821
8822         t_108_check
8823         t_108_cleanup
8824 }
8825 run_test 108b "migrate from ZFS to ldiskfs"
8826
8827 #
8828 # set number of permanent parameters
8829 #
8830 test_109_set_params() {
8831         local fsname=$1
8832
8833         set_persistent_param_and_check mds                          \
8834             "mdd.$fsname-MDT0000.atime_diff"                        \
8835             "$fsname-MDT0000.mdd.atime_diff"                        \
8836             "62"
8837         set_persistent_param_and_check mds                          \
8838             "mdd.$fsname-MDT0000.atime_diff"                        \
8839             "$fsname-MDT0000.mdd.atime_diff"                        \
8840             "63"
8841         set_persistent_param_and_check client                       \
8842             "llite.$fsname*.max_read_ahead_mb"                      \
8843             "$fsname.llite.max_read_ahead_mb"                       \
8844             "32"
8845         set_persistent_param_and_check client                       \
8846             "llite.$fsname*.max_read_ahead_mb"                      \
8847             "$fsname.llite.max_read_ahead_mb"                       \
8848             "64"
8849         create_pool $fsname.pool1 || error "create pool failed"
8850         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
8851                 error "pool_add failed"
8852         do_facet mgs $LCTL pool_remove $fsname.pool1 OST0000 ||
8853                 error "pool_remove failed"
8854         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
8855                 error "pool_add failed"
8856 }
8857
8858 #
8859 # check permanent parameters
8860 #
8861 test_109_test_params() {
8862         local fsname=$1
8863
8864         local atime_diff=$(do_facet mds $LCTL \
8865                 get_param -n mdd.$fsname-MDT0000.atime_diff)
8866         [ $atime_diff == 63 ] || error "wrong mdd parameter after clear_conf"
8867         local max_read_ahead_mb=$(do_facet client $LCTL \
8868                 get_param -n llite.$fsname*.max_read_ahead_mb)
8869         [ $max_read_ahead_mb == 64 ] ||
8870                 error "wrong llite parameter after clear_conf"
8871         local ost_in_pool=$(do_facet mds $LCTL pool_list $fsname.pool1 |
8872                 grep -v "^Pool:" | sed 's/_UUID//')
8873         [ $ost_in_pool = "$fsname-OST0000" ] ||
8874                 error "wrong pool after clear_conf"
8875 }
8876
8877 #
8878 # run lctl clear_conf, store CONFIGS before and after that
8879 #
8880 test_109_clear_conf()
8881 {
8882         local clear_conf_arg=$1
8883
8884         local mgsdev
8885         if ! combined_mgs_mds ; then
8886                 mgsdev=$(mgsdevname)
8887                 stop_mgs || error "stop_mgs failed"
8888                 start_mgs "-o nosvc" || error "start_mgs nosvc failed"
8889         else
8890                 mgsdev=$(mdsdevname 1)
8891                 start_mdt 1 "-o nosvc" || error "start_mdt 1 nosvc failed"
8892         fi
8893
8894         do_facet mgs "rm -rf $TMP/${tdir}/conf1; mkdir -p $TMP/${tdir}/conf1;" \
8895                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf1\\\" \
8896                 $mgsdev"
8897
8898         #
8899         # the command being tested
8900         #
8901         do_facet mgs $LCTL clear_conf $clear_conf_arg ||
8902                 error "clear_conf failed"
8903         if ! combined_mgs_mds ; then
8904                 stop_mgs || error "stop_mgs failed"
8905         else
8906                 stop_mdt 1 || error "stop_mdt 1 failed"
8907         fi
8908
8909         do_facet mgs "rm -rf $TMP/${tdir}/conf2; mkdir -p $TMP/${tdir}/conf2;" \
8910                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf2\\\" \
8911                 $mgsdev"
8912 }
8913
8914 test_109_file_shortened() {
8915         local file=$1
8916         local sizes=($(do_facet mgs "stat -c %s " \
8917                 "$TMP/${tdir}/conf1/CONFIGS/$file" \
8918                 "$TMP/${tdir}/conf2/CONFIGS/$file"))
8919         [ ${sizes[1]} -lt ${sizes[0]} ] && return 0
8920         return 1
8921 }
8922
8923 test_109a()
8924 {
8925         [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
8926                 skip "Needs MDS version 2.10.59 or later."
8927         [ "$(facet_fstype mgs)" == zfs ] &&
8928                 skip "LU-8727: no implementation for ZFS"
8929
8930         stopall
8931         reformat
8932         setup_noconfig
8933         client_up || error "client_up failed"
8934
8935         #
8936         # set number of permanent parameters
8937         #
8938         test_109_set_params $FSNAME
8939
8940         umount_client $MOUNT || error "umount_client failed"
8941         stop_ost || error "stop_ost failed"
8942         stop_mds || error "stop_mds failed"
8943
8944         test_109_clear_conf $FSNAME
8945         #
8946         # make sure that all configs are cleared
8947         #
8948         test_109_file_shortened $FSNAME-MDT0000 ||
8949                 error "failed to clear MDT0000 config"
8950         test_109_file_shortened $FSNAME-client ||
8951                 error "failed to clear client config"
8952
8953         setup_noconfig
8954
8955         #
8956         # check that configurations are intact
8957         #
8958         test_109_test_params $FSNAME
8959
8960         #
8961         # Destroy pool.
8962         #
8963         destroy_test_pools || error "destroy test pools failed"
8964
8965         cleanup
8966 }
8967 run_test 109a "test lctl clear_conf fsname"
8968
8969 test_109b()
8970 {
8971         [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
8972                 skip "Needs MDS version 2.10.59 or later."
8973         [ "$(facet_fstype mgs)" == zfs ] &&
8974                 skip "LU-8727: no implementation for ZFS"
8975
8976         stopall
8977         reformat
8978         setup_noconfig
8979         client_up || error "client_up failed"
8980
8981         #
8982         # set number of permanent parameters
8983         #
8984         test_109_set_params $FSNAME
8985
8986         umount_client $MOUNT || error "umount_client failed"
8987         stop_ost || error "stop_ost failed"
8988         stop_mds || error "stop_mds failed"
8989
8990         test_109_clear_conf $FSNAME-MDT0000
8991         #
8992         # make sure that only one config is cleared
8993         #
8994         test_109_file_shortened $FSNAME-MDT0000 ||
8995                 error "failed to clear MDT0000 config"
8996         test_109_file_shortened $FSNAME-client &&
8997                 error "failed to clear client config"
8998
8999         setup_noconfig
9000         #
9001         # check that configurations are intact
9002         #
9003         test_109_test_params $FSNAME
9004
9005         #
9006         # Destroy pool.
9007         #
9008         destroy_test_pools || error "destroy test pools failed"
9009
9010         cleanup
9011 }
9012 run_test 109b "test lctl clear_conf one config"
9013
9014 test_110()
9015 {
9016         [[ "$mds1_FSTYPE" != ldiskfs ]] &&
9017                 skip "Only applicable to ldiskfs-based MDTs"
9018
9019         do_facet $SINGLEMDS $DEBUGFS -w -R supported_features |grep large_dir ||
9020                 skip "large_dir option is not supported on MDS"
9021         do_facet ost1 $DEBUGFS -w -R supported_features | grep large_dir ||
9022                 skip "large_dir option is not supported on OSS"
9023
9024         stopall # stop all targets before modifying the target counts
9025         local old_mdscount=$MDSCOUNT
9026         local old_ostcount=$OSTCOUNT
9027         local replace=""
9028         stack_trap "MDSCOUNT=$old_mdscount OSTCOUNT=$old_ostcount; reformat"
9029         MDSCOUNT=1
9030         OSTCOUNT=1
9031
9032         # ext4_dir_entry_2 struct size:264
9033         # dx_root struct size:8
9034         # dx_node struct size:8
9035         # dx_entry struct size:8
9036         # For 1024 bytes block size.
9037         # First level directory entries: 126
9038         # Second level directory entries: 127
9039         # Entries in leaf: 3
9040         # For 2 levels limit: 48006
9041         # For 3 levels limit : 6096762
9042         # Create 80000 files to safely exceed 2-level htree limit.
9043         CONF_SANITY_110_LINKS=${CONF_SANITY_110_LINKS:-80000}
9044
9045         # can fit at most 3 filenames per 1KB leaf block, but each
9046         # leaf/index block will only be 3/4 full before split at each level
9047         (( MDSSIZE < CONF_SANITY_110_LINKS / 3 * 4/3 * 4/3 )) &&
9048                 CONF_SANITY_110_LINKS=$((MDSSIZE * 3 * 3/4 * 3/4))
9049
9050         combined_mgs_mds || replace=" --replace "
9051         local opts="$(mkfs_opts mds1 $(mdsdevname 1)) \
9052                     $replace --reformat $(mdsdevname 1) $(mdsvdevname 1)"
9053         if [[ $opts != *large_dir* ]]; then
9054                 if [[ $opts != *mkfsoptions* ]]; then
9055                         opts+=" --mkfsoptions=\\\"-O large_dir -b 1024 -i 65536\\\""
9056                 else
9057                         opts="${opts//--mkfsoptions=\\\"/ \
9058                                 --mkfsoptions=\\\"-O large_dir -b 1024 -i 65536 }"
9059                 fi
9060         fi
9061         echo "MDT params: $opts"
9062         load_modules
9063         combined_mgs_mds || start_mgs
9064         add mds1 $opts || error "add mds1 failed with new params"
9065         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
9066
9067         opts="$(mkfs_opts ost1 $(ostdevname 1)) \
9068                 $replace --reformat $(ostdevname 1) $(ostvdevname 1)"
9069
9070         if [[ $opts != *large_dir* ]]; then
9071                 if [[ $opts != *mkfsoptions* ]]; then
9072                         opts+=" --mkfsoptions=\\\"-O large_dir\\\" "
9073                 else
9074                         opts="${opts//--mkfsoptions=\\\"/ \
9075                                 --mkfsoptions=\\\"-O large_dir }"
9076                 fi
9077         fi
9078         echo "OST params: $opts"
9079         add ost1 $opts || error "add ost1 failed with new params"
9080         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
9081
9082         MOUNT_2=yes mountcli || error "mount clients failed"
9083
9084         mkdir -v $DIR/$tdir || error "cannot create $DIR/$tdir"
9085         local pids count=0 group=0
9086
9087         echo "creating $CONF_SANITY_110_LINKS in total"
9088         while (( count < CONF_SANITY_110_LINKS )); do
9089                 local len=$((253 - $(wc -c <<<"$tfile-$group-40000-")))
9090                 local dir=DIR$((group % 2 + 1))
9091                 local target=${!dir}/$tdir/$tfile-$group
9092                 local long=$target-$(generate_name $len)-
9093                 local create=$((CONF_SANITY_110_LINKS - count))
9094
9095                 (( create > 40000 )) && create=40000
9096                 touch $target || error "creating $target failed"
9097                 echo "creating $create hard links to $target"
9098                 createmany -l $target $long $create &
9099                 pids+=" $!"
9100
9101                 count=$((count + create))
9102                 group=$((group + 1))
9103         done
9104         echo "waiting for PIDs$pids to complete"
9105         wait $pids || error "createmany failed after $group groups"
9106
9107         umount_client $MOUNT2 -f
9108         cleanup
9109
9110         run_e2fsck $(facet_active_host mds1) $(mdsdevname 1) -n
9111         MDSCOUNT=$old_mdscount
9112         OSTCOUNT=$old_ostcount
9113 }
9114 run_test 110 "Adding large_dir with 3-level htree"
9115
9116 test_111() {
9117         [[ "$mds1_FSTYPE" != ldiskfs ]] &&
9118                 skip "Only applicable to ldiskfs-based MDTs"
9119
9120         is_dm_flakey_dev $SINGLEMDS $(mdsdevname 1) &&
9121                 skip "This test can not be executed on flakey dev"
9122
9123         do_facet $SINGLEMDS $DEBUGFS -w -R supported_features |grep large_dir ||
9124                 skip "large_dir option is not supported on MDS"
9125
9126         do_facet ost1 $DEBUGFS -w -R supported_features | grep large_dir ||
9127                 skip "large_dir option is not supported on OSS"
9128
9129         # cleanup before changing target counts
9130         cleanup
9131         local old_mdscount=$MDSCOUNT
9132         local old_ostcount=$OSTCOUNT
9133         local old_mdssize=$MDSSIZE
9134         local replace=""
9135         stack_trap "MDSSIZE=$old_mdssize MDSCOUNT=$old_mdscount \
9136                     OSTCOUNT=$old_ostcount; reformat"
9137         MDSCOUNT=1
9138         OSTCOUNT=1
9139         (( MDSSIZE < 2400000 )) && MDSSIZE=2400000 # need at least 2.4GB
9140
9141         local mdsdev=$(mdsdevname 1)
9142         combined_mgs_mds || replace=" --replace "
9143         local opts="$(mkfs_opts mds1 $(mdsdevname 1)) \
9144                     $replace --reformat $(mdsdevname 1) $(mdsvdevname 1)"
9145         if [[ $opts != *large_dir* ]]; then
9146                 if [[ $opts != *mkfsoptions* ]]; then
9147                         opts+=" --mkfsoptions=\\\"-O large_dir -i 1048576 \\\" "
9148                 else
9149                         opts="${opts//--mkfsoptions=\\\"/ \
9150                                 --mkfsoptions=\\\"-O large_dir -i 1048576 }"
9151                 fi
9152         fi
9153         echo "MDT params: $opts"
9154         load_modules
9155         combined_mgs_mds || start_mgs
9156         __touch_device mds 1
9157         add mds1 $opts || error "add mds1 failed with new params"
9158         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
9159
9160         opts="$(mkfs_opts ost1 $(ostdevname 1)) \
9161                 $replace --reformat $(ostdevname 1) $(ostvdevname 1)"
9162         if [[ $opts != *large_dir* ]]; then
9163                 if [[ $opts != *mkfsoptions* ]]; then
9164                         opts+=" --mkfsoptions=\\\"-O large_dir \\\""
9165                 else
9166                         opts="${opts//--mkfsoptions=\\\"/ --mkfsoptions=\\\"-O large_dir }"
9167                 fi
9168         fi
9169         echo "OST params: $opts"
9170         __touch_device ost 1
9171         add ost1 $opts || error "add ost1 failed with new params"
9172         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
9173
9174         MOUNT_2=yes mountcli
9175         mkdir $DIR/$tdir || error "cannot create $DIR/$tdir"
9176         lfs df $DIR/$tdir
9177         lfs df -i $DIR/$tdir
9178
9179         local group=0
9180
9181         local start=$SECONDS
9182         local dirsize=0
9183         local dirmax=$((2 << 30))
9184         local needskip=0
9185         local taken=0
9186         local rate=0
9187         local left=0
9188         local num=0
9189         while (( !needskip & dirsize < dirmax )); do
9190                 local pids=""
9191
9192                 for cli in ${CLIENTS//,/ }; do
9193                         local len=$((253 - $(wc -c <<<"$cli-$group-60000-")))
9194                         local target=$cli-$group
9195                         local long=$DIR/$tdir/$target-$(generate_name $len)-
9196
9197                         RPWD=$DIR/$tdir do_node $cli touch $target ||
9198                                 error "creating $target failed"
9199                         echo "creating 60000 hardlinks to $target"
9200                         RPWD=$DIR/$tdir do_node $cli createmany -l $target $long 60000 &
9201                         pids+=" $!"
9202
9203                         group=$((group + 1))
9204                         target=$cli-$group
9205                         long=$DIR2/$tdir/$target-$(generate_name $len)-
9206
9207                         RPWD=$DIR2/$tdir do_node $cli touch $target ||
9208                                 error "creating $target failed"
9209                         echo "creating 60000 hardlinks to $target"
9210                         RPWD=$DIR2/$tdir do_node $cli createmany -l $target $long 60000 &
9211                         pids+=" $!"
9212
9213                         group=$((group + 1))
9214                 done
9215                 echo "waiting for PIDs$pids to complete"
9216                 wait $pids || error "createmany failed after $group groups"
9217                 dirsize=$(stat -c %s $DIR/$tdir)
9218                 taken=$((SECONDS - start))
9219                 rate=$((dirsize / taken))
9220                 left=$(((dirmax - dirsize) / rate))
9221                 num=$((group * 60000))
9222                 echo "estimate ${left}s left after $num files / ${taken}s"
9223                 # if the estimated time remaining is too large (it may change
9224                 # over time as the create rate is not constant) then exit
9225                 # without declaring a failure.
9226                 (( left > 1200 )) && needskip=1
9227         done
9228
9229         umount_client $MOUNT2 -f
9230         cleanup
9231
9232         ! (( $needskip )) ||
9233                 echo "ETA ${left}s after $num files / ${taken}s is too long"
9234
9235         run_e2fsck $(facet_active_host mds1) $(mdsdevname 1) -n
9236         MDSCOUNT=$old_mdscount
9237         OSTCOUNT=$old_ostcount
9238         MDSSIZE=$old_mdssize
9239 }
9240 run_test 111 "Adding large_dir with over 2GB directory"
9241
9242 test_112a() {
9243         local param="no_create"
9244
9245         (( $OST1_VERSION > $(version_code 2.14.0) )) ||
9246                 skip "need OSS at least 2.14.0"
9247         (( $OST1_VERSION >= $(version_code 2.15.56.125) )) ||
9248                 param="no_precreate"
9249
9250         start_mds || error "MDS start failed"
9251         start_ost || error "OSS start failed"
9252         echo "start ost2 service on $(facet_active_host ost2)"
9253         start ost2 $(ostdevname 2) $(csa_add "$OST_MOUNT_OPTS" -o $param) ||
9254                 error "start ost2 facet failed"
9255         local val=$(do_facet ost2 \
9256                    "$LCTL get_param -n obdfilter.$FSNAME-OST0001*.$param")
9257         (( $val == 1 )) || error "obdfilter.$FSNAME-OST0001*.$param=$val"
9258
9259         mount_client $MOUNT || error "mount client failed"
9260         wait_osc_import_state mds1 ost1 FULL
9261         wait_osc_import_ready client ost1
9262         wait_osc_import_ready client ost2
9263
9264         $LFS setstripe -i 0 $DIR/$tfile.0 ||
9265                 error "problem creating $tfile.0 on OST0000"
9266         $LFS setstripe -i 1 $DIR/$tfile.1 && $LFS getstripe $DIR/$tfile.1 &&
9267                 (( $($LFS getstripe -i $DIR/$tfile.1) == 1 )) &&
9268                 error "allowed to create $tfile.1 on OST0001"
9269         $LFS df -v $MOUNT
9270         $LFS df -v $MOUNT | grep -q "OST:1.*N" ||
9271                 error "NOCREATE not in 'lfs df'"
9272
9273         do_facet ost2 $LCTL set_param obdfilter.$FSNAME-OST0001*.$param=0
9274         sleep_maxage
9275         $LFS setstripe -i 1 $DIR/$tfile.2 ||
9276                 error "failed to create $tfile.2 on ost1 facet"
9277         # files not cleaned with ONLY_REPEAT because of client unmount below
9278         rm -f $DIR/$tfile.[012]
9279         stop_ost2 || error "stop ost2 facet failed"
9280         cleanup
9281 }
9282 run_test 112a "mount OST with no_create option"
9283
9284 test_112b() {
9285         (( MDSCOUNT >= 2 )) || skip "need at least 2 MDTs"
9286         (( $MDS1_VERSION >= $(version_code 2.15.56.125) )) ||
9287                 skip "need MDS >= 2.15.56.125"
9288         local mdsnum=$MDSCOUNT
9289         local facet=mds$mdsnum
9290         local mdtidx=$((mdsnum - 1))
9291         local mdtname=$FSNAME-MDT$(printf %04x $mdtidx)
9292
9293         start_mds --mdscount $((mdsnum - 1)) || error "MDS start failed"
9294         start_mdt $mdsnum -o no_create || error "start $facet failed"
9295         local val=$(do_facet $facet \
9296                    "$LCTL get_param -n mdt.$mdtname*.no_create")
9297         (( $val == 1 )) || error "mdt.$mdtname*.no_create=$val"
9298         start_ost || error "ost1 start failed"
9299         start_ost2 || error "ost1 start failed"
9300
9301         mount_client $MOUNT || error "mount client failed"
9302         wait_osc_import_ready $facet ost2
9303
9304         $LFS df -v $MOUNT
9305         $LFS df -v $MOUNT | grep -q "MDT:$mdtidx.*N" ||
9306                 error "NOCREATE not in 'lfs df'"
9307
9308         $LFS mkdir -i $mdtidx $DIR/$tdir ||
9309                 $LFS setdirstripe -D -c 1 -i -1 --max-inherit-rr 2 $DIR/$tdir ||
9310                 error "error creating $tdir on $mdtname"
9311         stack_trap "rm -rf $DIR/$tdir"
9312
9313         mkdir $DIR/$tdir/d1.{1..100} || error "mkdir $tdir/d1.{1..100} failed"
9314         $LFS getdirstripe -i $DIR/$tdir/d1.* | sort | uniq -c
9315         do_facet $facet $LCTL set_param mdt.$mdtname*.no_create=0
9316         # allow one initial create for delayed statfs on client
9317         (( $($LFS getdirstripe -i $DIR/$tdir/d1.* | grep -c $mdtidx) < 2 )) ||
9318                 error "allowed create on $mdtname"
9319         sleep_maxage_lmv
9320
9321         mkdir $DIR/$tdir/d2.{1..100} || error "mkdir $tdir/d2.{1..100} failed"
9322         $LFS getdirstripe -i $DIR/$tdir/d2.{1..100} | sort | uniq -c
9323         (( $($LFS getdirstripe -i $DIR/$tdir/d2.* | grep -c $mdtidx) > 10 )) ||
9324                 error "no create on $mdtname"
9325         # files not cleaned with ONLY_REPEAT because of client unmount below
9326         rm -r $DIR/$tdir
9327         stop_ost2 || error "ost1 start failed"
9328         cleanup
9329 }
9330 run_test 112b "mount MDT with no_create option"
9331
9332 # Global for 113
9333 SAVE_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
9334 SAVE_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
9335 SAVE_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
9336
9337 cleanup_113() {
9338         trap 0
9339
9340         stopall
9341         MGS_MOUNT_OPTS=$SAVE_MGS_MOUNT_OPTS
9342         MDS_MOUNT_OPTS=$SAVE_MDS_MOUNT_OPTS
9343         OST_MOUNT_OPTS=$SAVE_OST_MOUNT_OPTS
9344         # Revert old mount options back
9345         setupall
9346         # Subsequent following test requires
9347         # conf-sanity to be in stopall state.
9348         # Force 'stopall' so others following
9349         # test can pass
9350         stopall
9351 }
9352
9353 # Error out with mount info
9354 error_113() {
9355         local server_nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
9356         local err=$1
9357
9358         echo "--Client Mount Info--"
9359         mount | grep -i lustre
9360         echo "--Server Mount Info--"
9361         do_nodes $server_nodes mount | grep -i lustre
9362
9363         error $err
9364 }
9365
9366 test_113() {
9367         local ost_version="2.15.51" # Minimum version required
9368
9369         (( OST1_VERSION >= $(version_code $ost_version) )) ||
9370                 skip "Need server version at least $ost_version"
9371         sync; sleep 3
9372         stack_trap cleanup_113 EXIT
9373
9374         # Reset before starting
9375         stopall
9376         setupall
9377
9378         # Verify MDS's should start with "rw"
9379         do_facet $SINGLEMDS mount | grep "lustre.*rw,.*MDT" ||
9380                 error_113 "$SINGLEMDS should be read-write"
9381
9382         # Verify OST's should start with "rw"
9383         for (( i=1; i <= OSTCOUNT; i++ )); do
9384                 do_facet ost$i mount | grep "lustre.*rw,.*OST" ||
9385                         error_113 "ost$i should be read-write"
9386         done
9387
9388         # rdonly_dev does not currently work for ldiskfs
9389         # We skip the rdonly_dev check until then.
9390         if [[ $ost1_FSTYPE == ldiskfs ]]; then
9391                 echo "Shadow Mountpoint correctly reports rw for ldiskfs"
9392                 return 0
9393         fi
9394
9395         #
9396         # Only ZFS specific tests below.
9397         #
9398
9399         # Must stop all (server+client) and restart to verify new
9400         # mount options
9401         stopall
9402
9403         # add rdonly_dev to mount option
9404         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
9405         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
9406         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
9407
9408         # Only restart server(mds/ost). Sufficient for test
9409         setupall server_only || error "Fail to start servers"
9410
9411         # Verify MDS's should be "ro"
9412         do_facet $SINGLEMDS mount | grep "lustre.*ro,.*MDT.*rdonly_dev" ||
9413                 error_113 "$SINGLEMDS should be read-only"
9414
9415         # Verify OST's should be "ro"
9416         for (( i=1; i <= OSTCOUNT; i++ )); do
9417                 do_facet ost$i mount | grep "lustre.*ro,.*OST.*rdonly_dev" ||
9418                         error_113 "ost$i should be read-only"
9419         done
9420 }
9421 run_test 113 "Shadow mountpoint correctly report ro/rw for mounts"
9422
9423 #
9424 # Purpose: To verify dynamic thread (OSS) creation.
9425 # (This was sanity/115)
9426 #
9427 test_114() {
9428         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9429         remote_ost_nodsh && skip "remote OST with nodsh"
9430
9431         # Lustre does not stop service threads once they are started.
9432         # Reset number of running threads to default.
9433         stopall
9434         setupall
9435
9436         local OSTIO_pre
9437         local save_params="$TMP/sanity-$TESTNAME.parameters"
9438
9439         # Get ll_ost_io count before I/O
9440         OSTIO_pre=$(do_facet ost1 \
9441                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
9442         # Exit if lustre is not running (ll_ost_io not running).
9443         [ -z "$OSTIO_pre" ] && error "no OSS threads"
9444
9445         echo "Starting with $OSTIO_pre threads"
9446         local thread_max=$((OSTIO_pre * 2))
9447         local rpc_in_flight=$((thread_max * 2))
9448
9449         # this is limited to OSC_MAX_RIF_MAX (256)
9450         [ $rpc_in_flight -gt 256 ] && rpc_in_flight=256
9451         thread_max=$((rpc_in_flight / 2))
9452         [ $thread_max -le $OSTIO_pre ] && skip "Too many ost_io threads" &&
9453                 return
9454
9455         # Number of I/O Process proposed to be started.
9456         local nfiles
9457         local facets=$(get_facets OST)
9458
9459         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
9460         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
9461
9462         # Set in_flight to $rpc_in_flight
9463         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
9464                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
9465         nfiles=${rpc_in_flight}
9466         # Set ost thread_max to $thread_max
9467         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
9468
9469         # 5 Minutes should be sufficient for max number of OSS
9470         # threads(thread_max) to be created.
9471         local timeout=300
9472
9473         # Start I/O.
9474         local wtl=${WTL:-"$LUSTRE/tests/write_time_limit"}
9475
9476         test_mkdir $DIR/$tdir
9477         for ((i = 1; i <= nfiles; i++)); do
9478                 local file=$DIR/$tdir/${tfile}-$i
9479
9480                 $LFS setstripe -c -1 -i 0 $file
9481                 ($wtl $file $timeout)&
9482         done
9483
9484         # I/O Started - Wait for thread_started to reach thread_max or report
9485         # error if thread_started is more than thread_max.
9486         echo "Waiting for thread_started to reach thread_max"
9487         local thread_started=0
9488         local end_time=$((SECONDS + timeout))
9489
9490         while [ $SECONDS -le $end_time ] ; do
9491                 echo -n "."
9492                 # Get ost i/o thread_started count.
9493                 thread_started=$(do_facet ost1 \
9494                         "$LCTL get_param \
9495                         ost.OSS.ost_io.threads_started | cut -d= -f2")
9496                 # Break out if thread_started is equal/greater than thread_max
9497                 if (( $thread_started >= $thread_max )); then
9498                         echo ll_ost_io thread_started $thread_started, \
9499                                 equal/greater than thread_max $thread_max
9500                         break
9501                 fi
9502                 sleep 1
9503         done
9504
9505         # Cleanup - We have the numbers, Kill i/o jobs if running.
9506         jobcount=($(jobs -p))
9507
9508         for ((i=0; i < ${#jobcount[*]}; i++)); do
9509                 kill -9 ${jobcount[$i]}
9510                 if [ $? -ne 0 ] ; then
9511                         echo "warning: cannot kill WTL pid ${jobcount[$i]}"
9512                 fi
9513         done
9514
9515         # Cleanup files left by WTL binary.
9516         for ((i = 1; i <= nfiles; i++)); do
9517                 local file=$DIR/$tdir/${tfile}-$i
9518
9519                 rm -rf $file
9520                 if [ $? -ne 0 ] ; then
9521                         echo "Warning: Failed to delete file $file"
9522                 fi
9523         done
9524
9525         restore_lustre_params <$save_params
9526         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
9527
9528         # Error out if no new thread has started or Thread started is greater
9529         # than thread max.
9530         if (( $thread_started <= $OSTIO_pre ||
9531                 $thread_started > $thread_max )); then
9532                 error "ll_ost_io: thread_started $thread_started" \
9533                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
9534                       "No new thread started or thread started greater " \
9535                       "than thread_max."
9536         fi
9537 }
9538 run_test 114 "verify dynamic thread creation===================="
9539
9540 cleanup_115()
9541 {
9542         trap 0
9543         stopall
9544         do_facet mds1 rm -f $1
9545 }
9546
9547 test_115() {
9548         if [ "$mds1_FSTYPE" != ldiskfs ]; then
9549                 skip "Only applicable to ldiskfs-based MDTs"
9550         fi
9551         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
9552
9553         local dbfs_ver=$(do_facet mds1 $DEBUGFS -V 2>&1)
9554
9555         echo "debugfs version: $dbfs_ver"
9556         echo "$dbfs_ver" | egrep -w "1.44.3.wc1|1.44.5.wc1|1.45.2.wc1" &&
9557                 skip_env "This version of debugfs doesn't show inode number"
9558
9559         local IMAGESIZE=$((3072 << 30)) # 3072 GiB
9560
9561         stopall
9562
9563         FLAKEY=false
9564
9565         echo "client1: "
9566         $LCTL dl
9567         mount | grep lustre
9568         echo "mds1: "
9569         do_facet mds1 "hostname; $LCTL dl; mount"
9570         echo "ost1: "
9571         do_facet ost1 "hostname; $LCTL dl; mount"
9572         # We need MDT size 3072GB, because it is smallest
9573         # partition that can store 2B inodes
9574         do_facet mds1 "mkdir -p $TMP/$tdir"
9575         local mdsimgname=$TMP/$tdir/lustre-mdt
9576
9577         do_facet mds1 "rm -f $mdsimgname"
9578         do_facet mds1 "touch $mdsimgname"
9579         stack_trap "cleanup_115 $mdsimgname" EXIT
9580         do_facet mds1 "$TRUNCATE $mdsimgname $IMAGESIZE" ||
9581                 skip "Backend FS doesn't support sparse files"
9582         local mdsdev=$(do_facet mds1 "losetup -f")
9583
9584         do_facet mds1 "losetup $mdsdev $mdsimgname"
9585
9586         local mds_opts="$(mkfs_opts mds1 $(mdsdevname 1))        \
9587                 --mkfsoptions='-O ea_inode,^resize_inode,meta_bg \
9588                 -N 2247484000 -E lazy_itable_init' --device-size=$IMAGESIZE"
9589         add mds1 $mds_opts --mgs --reformat $mdsdev || {
9590                 do_facet $SINGLEMDS \
9591                         "losetup -d $mdsdev && rm -f $mdsimgname"
9592                 skip_env "format large MDT failed"
9593         }
9594
9595         local ostdev=$(ostdevname 1)
9596
9597         local opts="$(mkfs_opts ost1 $ostdev) \
9598                 --reformat $ostdev $ostdev"
9599         add ost1 $opts || error "add ost1 failed with new params"
9600         start mds1  $mdsdev $MDS_MOUNT_OPTS || error "start MDS failed"
9601         start_ost || error "start OSS failed"
9602         mount_client $MOUNT || error "mount client failed"
9603
9604         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir fail"
9605         local goal="/sys/fs/ldiskfs/$(basename $mdsdev)/inode_goal"
9606         echo goal: $goal
9607         # 2147483648 is 0x80000000
9608         do_facet mds1 "echo 2147483648 >> $goal; grep . $goal"
9609         touch $DIR/$tdir/$tfile
9610
9611         # attrs from 1 to 16 go to block, 17th - to inode
9612         local i
9613
9614         for i in {1..17}; do
9615                 local nm="trusted.ea$i"
9616                 setfattr -n $nm -v $(printf "xattr%0250d" $i) $DIR/$tdir/$tfile
9617         done
9618
9619         do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tdir/$tfile' $mdsdev"
9620
9621         # inode <2147483649> trusted.ea16 (255)
9622         local inode_num=$(do_facet mds1 \
9623                         "$DEBUGFS -c -R 'stat ROOT/$tdir/$tfile' $mdsdev" |
9624                          awk '/ea17/ { print $2 }' |
9625                          sed -e 's/>//' -e 's/<//' -e 's/\"//')
9626         echo "inode num: $inode_num"
9627         [ $inode_num -ge 2147483648 ] || error "inode $inode_num too small"
9628         do_facet mds1 "losetup -d $mdsdev"
9629 }
9630 run_test 115 "Access large xattr with inodes number over 2TB"
9631
9632 test_116() {
9633         [ "$mds1_FSTYPE" != ldiskfs ] && skip "ldiskfs only test"
9634         [ "$MDS1_VERSION" -lt $(version_code 2.10.59) ] &&
9635                 skip "Need server version at least 2.10.59"
9636         do_facet $SINGLEMDS which mkfs.xfs ||
9637                 skip_env "No mkfs.xfs installed"
9638
9639         stopall
9640         load_modules
9641
9642         local tmpmnt=$TMP/$tdir
9643         local mdtimg=$tfile-mdt0
9644
9645         do_facet $SINGLEMDS mkdir -p $tmpmnt
9646         stack_trap "do_facet $SINGLEMDS rmdir $tmpmnt" EXIT
9647
9648         do_facet $SINGLEMDS touch $TMP/$mdtimg
9649         stack_trap "do_facet $SINGLEMDS rm -f $TMP/$mdtimg" EXIT
9650         do_facet $SINGLEMDS mkfs -t xfs -d file,size=1t,name=$TMP/$mdtimg ||
9651                 error "mkfs temporary xfs image"
9652
9653         do_facet $SINGLEMDS mount $TMP/$mdtimg $tmpmnt ||
9654                 error "mount temporary xfs image"
9655         stack_trap "do_facet $SINGLEMDS umount $tmpmnt" EXIT
9656         local old_mdssize=$MDSSIZE
9657         local old_mdsisize=$MDSISIZE
9658
9659         MDSSIZE=$((17 * 1024 * 1024 * 1024)) # 17T MDT
9660         MDSISIZE=$((16 << 20))
9661         local opts17t="$(mkfs_opts $SINGLEMDS)"
9662
9663         MDSSIZE=$old_mdssize
9664         MDSISIZE=$old_mdsisize
9665
9666         do_facet $SINGLEMDS $MKFS \
9667                 ${opts17t/-E /-E lazy_itable_init,lazy_journal_init,} \
9668                 $tmpmnt/$mdtimg ||
9669                 error "failed to mkfs for $tmpmnt/$mdtimg"
9670
9671         do_facet $SINGLEMDS $TUNE2FS -l $tmpmnt/$mdtimg |
9672                 grep -qw 'features.*extent' || error "extent should be enabled"
9673         reformat_and_config
9674 }
9675 run_test 116 "big size MDT support"
9676
9677 test_117() {
9678         # Call setup only if LustreFS is not mounted
9679         check_mount || setup
9680
9681         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.nrs_policies=fifo"
9682         do_facet ost1 "$LCTL get_param -n ost.OSS.ost_io.nrs_tbf_rule" &&
9683                 error "get_param should fail"
9684         cleanup || error "cleanup failed with rc $?"
9685 }
9686 run_test 117 "lctl get_param return errors properly"
9687
9688 test_119() {
9689         local had_config
9690         local size_mb
9691
9692         [[ "$MDSCOUNT" -ge 2 ]] || skip "Need more at least 2 MDTs"
9693
9694         had_config=$(do_facet mds1 "$LCTL get_param debug | grep config")
9695         do_facet mds1 "$LCTL set_param debug=+config"
9696         do_facet mds1 "$LCTL clear"
9697
9698         setup
9699         do_facet mds2 "$TUNEFS --writeconf $(mdsdevname 2)" &>/dev/null
9700         # mount after writeconf will make "add osp" added to mdt0 config:
9701         # 53 (224)marker  60 (flags=0x01, v2.5.1.0) lustre-MDT0001  'add osp'
9702         # 54 (080)add_uuid  nid=...  0:  1:...
9703         # 55 (144)attach    0:lustre-MDT0001-osp-MDT0000  1:osp  2:...
9704         # 56 (144)setup     0:lustre-MDT0001-osp-MDT0000  1:...  2:...
9705         # 57 (136)modify_mdc_tgts add 0:lustre-MDT0000-mdtlov  1:...  2:1  3:1
9706         # duplicate modify_mdc_tgts caused crashes
9707
9708         debug_size_save
9709         # using larger debug_mb size to avoid lctl dk log truncation
9710         size_mb=$((DEBUG_SIZE_SAVED * 4))
9711         for i in {1..3}; do
9712                 stop_mdt 2
9713                 # though config processing stops after failed attach and setup
9714                 # it will proceed after the failed command after each writeconf
9715                 # this is the original scenario of the issue
9716                 do_facet mds2 "$TUNEFS --writeconf $(mdsdevname 2)" &>/dev/null
9717                 do_facet mds1 "$LCTL set_param debug_mb=$size_mb"
9718                 start_mdt 2
9719
9720                 wait_update_facet_cond mds1 \
9721                         "$LCTL dk | grep -c Processed.log.$FSNAME-MDT0000" \
9722                         ">" 1 300
9723         done
9724         debug_size_restore
9725
9726         [[ -z "$had_config" ]] && do_facet mds1 lctl set_param debug=-config
9727
9728         reformat
9729 }
9730 run_test 119 "writeconf on slave mdt shouldn't duplicate mdc/osp and crash"
9731
9732 test_120() { # LU-11130
9733         [ "$MDSCOUNT" -lt 2 ] && skip "mdt count < 2"
9734         [ "$mds1_FSTYPE" != ldiskfs ] &&
9735                 skip "ldiskfs only test"
9736         [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ] &&
9737                 skip "Need DNE2 capable MD target with LU-11130 fix"
9738
9739         setup
9740
9741         local mds1host=$(facet_active_host mds1)
9742         local mds1dev=$(mdsdevname 1)
9743
9744         $LFS mkdir -i 1 $DIR/$tdir
9745         $LFS mkdir -i 0 $DIR/$tdir/mds1dir
9746
9747         ln -s foo $DIR/$tdir/bar
9748         mv $DIR/$tdir/bar $DIR/$tdir/mds1dir/bar2 ||
9749                 error "cross-target rename failed"
9750
9751         stopall
9752
9753         run_e2fsck $mds1host $mds1dev "-n"
9754 }
9755 run_test 120 "cross-target rename should not create bad symlinks"
9756
9757 test_121(){
9758         stopall
9759         start_mgsmds || error "MGS MDS Start failed"
9760         fail mgs
9761         stop_mds || error "Stopping MDSes failed"
9762         #failback
9763         start_mds
9764         fail mgs
9765         stop_mds || error "Stopping MDSes failed"
9766 }
9767 run_test 121 "failover MGS"
9768
9769 test_122a() {
9770         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
9771         [[ "$OST1_VERSION" -ge $(version_code 2.11.53) ]] ||
9772                 skip "Need OST version at least 2.11.53"
9773
9774         reformat
9775         LOAD_MODULES_REMOTE=true load_modules
9776 #define OBD_FAIL_OFD_SET_OID 0x1e0
9777         do_facet ost1 $LCTL set_param fail_loc=0x00001e0
9778
9779         setup_noconfig
9780         $LFS mkdir -i1 -c1 $DIR/$tdir
9781         $LFS setstripe -i0 -c1 $DIR/$tdir
9782         do_facet ost1 $LCTL set_param fail_loc=0
9783         createmany -o $DIR/$tdir/file_ 1000 ||
9784                 error "Fail to create a new sequence"
9785
9786         cleanup
9787 }
9788 run_test 122a "Check OST sequence update"
9789
9790 test_123aa() {
9791         remote_mgs_nodsh && skip "remote MGS with nodsh"
9792         [ -d $MOUNT/.lustre ] || setup
9793
9794         # test old logid format until removal from llog_ioctl.c::str2logid()
9795         if (( $MGS_VERSION < $(version_code 2.99.53) )); then
9796                 do_facet mgs $LCTL dl | grep MGS
9797                 do_facet mgs "$LCTL --device %MGS llog_print \
9798                               \\\\\\\$$FSNAME-client 1 10" ||
9799                         error "old llog_print failed"
9800         fi
9801
9802         # test new logid format
9803         if [ $MGS_VERSION -ge $(version_code 2.9.53) ]; then
9804                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
9805                         error "new llog_print failed"
9806         fi
9807 }
9808 run_test 123aa "llog_print works with FIDs and simple names"
9809
9810 test_123ab() {
9811         remote_mgs_nodsh && skip "remote MGS with nodsh"
9812         [[ $MGS_VERSION -gt $(version_code 2.11.51) ]] ||
9813                 skip "Need server with working llog_print support"
9814
9815         [ -d $MOUNT/.lustre ] || setup
9816
9817         local yaml
9818         local orig_val
9819         local mgs_arg=""
9820
9821         [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] ||
9822                 mgs_arg="--device MGS"
9823
9824         orig_val=$(do_facet mgs $LCTL get_param jobid_name)
9825         do_facet mgs $LCTL set_param -P jobid_name="TESTNAME"
9826
9827         yaml=$(do_facet mgs $LCTL $mgs_arg llog_print params |
9828                grep jobid_name | tail -n 1)
9829
9830         local param=$(awk '{ print $10 }' <<< "$yaml")
9831         local val=$(awk '{ print $12 }' <<< "$yaml")
9832         #return to the default
9833         do_facet mgs $LCTL set_param -P jobid_name=$orig_val
9834         [ $val = "TESTNAME" ] || error "bad value: $val"
9835         [ $param = "jobid_name," ] || error "Bad param: $param"
9836 }
9837 run_test 123ab "llog_print params output values from set_param -P"
9838
9839 test_123ac() { # LU-11566
9840         remote_mgs_nodsh && skip "remote MGS with nodsh"
9841         do_facet mgs "$LCTL help llog_print" 2>&1 | grep -q -- --start ||
9842                 skip "Need 'lctl llog_print --start' on MGS"
9843
9844         local start=10
9845         local end=50
9846         local mgs_arg=""
9847
9848         [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] ||
9849                 mgs_arg="--device MGS"
9850
9851         [ -d $MOUNT/.lustre ] || setup
9852
9853         # - { index: 10, event: add_uuid, nid: 192.168.20.1@tcp(0x20000c0a81401,
9854         #     node: 192.168.20.1@tcp }
9855         do_facet mgs $LCTL $mgs_arg \
9856                 llog_print --start $start --end $end $FSNAME-client | tr -d , |
9857                 while read DASH BRACE INDEX idx EVENT BLAH BLAH BLAH; do
9858                 (( idx >= start )) || error "llog_print index $idx < $start"
9859                 (( idx <= end )) || error "llog_print index $idx > $end"
9860         done
9861 }
9862 run_test 123ac "llog_print with --start and --end"
9863
9864 test_123ad() { # LU-11566
9865         remote_mgs_nodsh && skip "remote MGS with nodsh"
9866         # older versions of lctl may not print all records properly
9867         do_facet mgs "$LCTL help llog_print" 2>&1 | grep -q -- --start ||
9868                 skip "Need 'lctl llog_print --start' on MGS"
9869
9870         [ -d $MOUNT/.lustre ] || setup
9871
9872         # append a new record, to avoid issues if last record was cancelled
9873         local old=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1)
9874         do_facet mgs $LCTL conf_param $FSNAME-OST0000.osc.max_dirty_mb=$old
9875
9876         # logid:            [0x3:0xa:0x0]:0
9877         # flags:            4 (plain)
9878         # records_count:    72
9879         # last_index:       72
9880         local num=$(do_facet mgs $LCTL --device MGS llog_info $FSNAME-client |
9881                     awk '/last_index:/ { print $2 - 1 }')
9882
9883         # - { index: 71, event: set_timeout, num: 0x14, param: sys.timeout=20 }
9884         local last=$(do_facet mgs $LCTL --device MGS llog_print $FSNAME-client |
9885                      tail -1 | awk '{ print $4 }' | tr -d , )
9886         (( last == num )) || error "llog_print only showed $last/$num records"
9887 }
9888 run_test 123ad "llog_print shows all records"
9889
9890 test_123ae() { # LU-11566
9891         local max
9892         local mgs_arg=""
9893         local log
9894         local id
9895         local orig
9896         local new
9897
9898         remote_mgs_nodsh && skip "remote MGS with nodsh"
9899         [ -d $MOUNT/.lustre ] || setupall
9900
9901         max=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1)
9902         pgs=$($LCTL get_param -n osc.*-OST0000-*.max_pages_per_rpc | head -1)
9903         [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] ||
9904                 mgs_arg="--device MGS"
9905
9906         if do_facet mgs "$LCTL help llog_cancel" 2>&1| grep -q -- --log_id; then
9907                 # save one set_param -P record in case none exist
9908
9909                 do_facet mgs $LCTL set_param -P osc.*.max_pages_per_rpc=$pgs
9910                 stack_trap "do_facet mgs $LCTL set_param -P -d \
9911                                 osc.*.max_pages_per_rpc"
9912
9913                 log=params
9914                 orig=$(do_facet mgs $LCTL $mgs_arg llog_print $log |
9915                         tail -1 | awk '{ print $4 }' | tr -d , )
9916                 do_facet mgs $LCTL set_param -P osc.*.max_dirty_mb=$max
9917                 do_facet mgs $LCTL $mgs_arg llog_print $log | tail -1 |
9918                         grep "parameter: osc.*.max_dirty_mb" ||
9919                         error "new set_param -P wasn't stored in params log"
9920
9921                 # - { index: 71, event: set_param, device: general,
9922                 #     param: osc.*.max_dirty_mb, value: 256 }
9923                 id=$(do_facet mgs $LCTL $mgs_arg llog_print $log |
9924                      tail -1 | awk '{ print $4 }' | tr -d , )
9925                 do_facet mgs $LCTL $mgs_arg llog_cancel $log --log_idx=$id
9926                 local new=$(do_facet mgs $LCTL $mgs_arg llog_print $log |
9927                             tail -1 | awk '{ print $4 }' | tr -d , )
9928                 (( new == orig )) ||
9929                         error "new llog_cancel now $new, not at $orig records"
9930         fi
9931
9932         # test old positional parameters for a while still
9933         if [ "$MGS_VERSION" -le $(version_code 3.1.53) ]; then
9934                 log=$FSNAME-client
9935
9936                 do_facet mgs $LCTL conf_param \
9937                         $FSNAME-OST0000.osc.max_pages_per_rpc=$pgs
9938                 stack_trap "do_facet mgs $LCTL conf_param -d \
9939                                 $FSNAME-OST0000.osc.max_pages_per_rpc"
9940
9941                 orig=$(do_facet mgs $LCTL --device MGS llog_print $log |
9942                        tail -1 | awk '{ print $4 }' | tr -d , )
9943                 do_facet mgs $LCTL conf_param $FSNAME-OST0000.osc.max_dirty_mb=$max
9944                 do_facet mgs $LCTL --device MGS llog_print $log |
9945                         tail -1 | grep "parameter: osc.max_dirty_mb" ||
9946                         error "old conf_param wasn't stored in params log"
9947                 do_facet mgs $LCTL --device MGS llog_print $log
9948                 # - { index: 71, event: conf_param, device: testfs-OST0000-osc,
9949                 #     param: osc.max_dirty_mb=256 }
9950                 id=$(do_facet mgs $LCTL --device MGS llog_print $log |
9951                      tail -1 | awk '{ print $4 }' | tr -d , )
9952                 do_facet mgs $LCTL --device MGS llog_cancel $log $id
9953                 do_facet mgs $LCTL --device MGS llog_print $log
9954                 new=$(do_facet mgs $LCTL --device MGS llog_print $log |
9955                       tail -1 | awk '{ print $4 }' | tr -d , )
9956                 (( new == orig )) ||
9957                         error "old llog_cancel now $new, not at $orig records"
9958         fi
9959 }
9960 run_test 123ae "llog_cancel can cancel requested record"
9961
9962 test_123af() { #LU-13609
9963         [ "$MGS_VERSION" -ge $(version_code 2.13.54) -a \
9964            "$MDS1_VERSION" -ge $(version_code 2.13.54) ] ||
9965                 skip "Need both MGS and MDS version at least 2.13.54"
9966
9967         [ -d $MOUNT/.lustre ] || setupall
9968         stack_trap "do_facet mds1 $LCTL set_param fail_loc=0" EXIT
9969
9970         local device
9971         local facet
9972         local cmd
9973         local orig_clist
9974         local orig_count
9975         local new_clist
9976         local new_count
9977
9978         for device in "MGS" "$FSNAME-MDT0000"; do
9979                 cmd="--device $device llog_catlist"
9980                 echo "lctl $cmd ..."
9981                 if [ "$device" = "MGS" ]; then
9982                         facet="mgs"
9983                 else
9984                         facet="mds1"
9985                 fi
9986                 orig_clist=($(do_facet $facet $LCTL $cmd | awk '{ print $2 }'))
9987                 orig_count=${#orig_clist[@]}
9988                 echo "orig_clist: ${orig_clist[*]}"
9989
9990                 #define OBD_FAIL_CATLIST 0x131b
9991                 #fetch to llog records from the second one
9992                 do_facet $facet $LCTL set_param fail_loc=0x131b fail_val=2
9993
9994                 new_clist=($(do_facet $facet $LCTL $cmd | awk '{ print $2 }'))
9995                 new_count=${#new_clist[@]}
9996                 echo "new_clist: ${new_clist[*]}"
9997
9998                 [ $new_count -eq $((orig_count - 1)) ] ||
9999                         error "$new_count != $orig_count - 1"
10000                 for i in $(seq 0 $new_count); do
10001                         j=$((i + 1))
10002                         [ "${orig_clist[$j]}" = "${new_clist[$i]}" ] ||
10003                                 error "${orig_clist[$j]} != ${new_clist[$i]}"
10004                 done
10005                 do_facet mds1 $LCTL set_param fail_loc=0
10006                 echo "done"
10007         done
10008 }
10009 run_test 123af "llog_catlist can show all config files correctly"
10010
10011 test_123ag() { # LU-15142
10012         local rec
10013         local orig_val
10014
10015         remote_mgs_nodsh && skip "remote MGS with nodsh"
10016         (( $MGS_VERSION >= $(version_code 2.14.55) )) ||
10017                 skip "Need server version least 2.14.55"
10018
10019         [ -d $MOUNT/.lustre ] || setup
10020
10021         orig_val=$(do_facet mgs $LCTL get_param jobid_name)
10022         stack_trap "do_facet mgs $LCTL set_param -P jobid_name=$orig_val"
10023
10024         do_facet mgs $LCTL set_param -P jobid_name="TESTNAME1"
10025         do_facet mgs $LCTL set_param -P -d jobid_name
10026         rec=$(do_facet mgs $LCTL --device MGS llog_print params |
10027                 grep -c jobid_name)
10028         (( rec == 0 )) || error "parameter was not deleted, check #1"
10029         do_facet mgs $LCTL set_param -P jobid_name="TESTNAME1"
10030         rec=$(do_facet mgs $LCTL --device MGS llog_print params |
10031                 grep -c jobid_name)
10032         (( rec == 1)) || error "parameter is not set"
10033         # usage with ordinary set_param format works too
10034         do_facet mgs $LCTL set_param -P -d jobid_name="ANY"
10035         rec=$(do_facet mgs $LCTL --device MGS llog_print params |
10036                 grep -c jobid_name)
10037         (( rec == 0 )) || error "parameter was not deleted, check #2"
10038 }
10039 run_test 123ag "llog_print skips values deleted by set_param -P -d"
10040
10041 test_123ah() { #LU-7668 del_ost
10042         (( "$MGS_VERSION" >= $(version_code 2.15.51) &&
10043            "$MDS1_VERSION" >= $(version_code 2.15.51) )) ||
10044                 skip "Need MGS/MDS version >= 2.15.51 for del_ost"
10045
10046         [ -d $MOUNT/.lustre ] || setupall
10047         stack_trap "do_facet mds1 $LCTL set_param fail_loc=0" EXIT
10048
10049         local cmd="--device MGS llog_print"
10050
10051         cli_llogcnt_orig=$(do_facet mgs $LCTL $cmd $FSNAME-client |
10052                                 grep -c $FSNAME-OST0000)
10053         mds1_llogcnt_orig=$(do_facet mgs $LCTL $cmd $FSNAME-MDT0000 |
10054                                 grep -c $FSNAME-OST0000)
10055
10056         [ $cli_llogcnt_orig -gt 0 ] ||
10057                 error "$FSNAME-OST0000 not found (client)"
10058         [ $mds1_llogcnt_orig -gt 0 ] || error "$FSNAME-OST0000 not found (MDT)"
10059
10060         # -n/--dryrun should NOT modify catalog
10061         do_facet mgs "$LCTL del_ost -n -t $FSNAME-OST0000" ||
10062                 error "del_ost --dryrun failed with $?"
10063
10064         local cli_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-client |
10065                         grep -c $FSNAME-OST0000)
10066         local mds1_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-MDT0000 |
10067                         grep -c $FSNAME-OST0000)
10068
10069         [ $cli_llogcnt -eq $cli_llogcnt_orig ] ||
10070                 error "--dryrun error: $cli_llogcnt != $cli_llogcnt_orig"
10071         [ $mds1_llogcnt -eq $mds1_llogcnt_orig ] ||
10072                 error "--dryrun error: $mds1_llogcnt != $mds1_llogcnt_orig"
10073
10074         # actual run
10075         do_facet mgs "$LCTL del_ost --target $FSNAME-OST0000" ||
10076                 error "del_ost failed with $?"
10077
10078         local cli_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-client |
10079                         grep -c $FSNAME-OST0000)
10080         local mds1_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-MDT0000 |
10081                         grep -c $FSNAME-OST0000)
10082
10083         # every catalog entry for OST0000 should have been cancelled
10084         [ $cli_llogcnt -eq 0 ] || error "$FSNAME-OST0000 not cancelled (cli)"
10085         [ $mds1_llogcnt -eq 0 ] || error "$FSNAME-OST0000 not cancelled (MDT)"
10086
10087         umount_client $MOUNT
10088         mount_client $MOUNT
10089
10090         $LFS df | grep -q OST0000 && error "del_ost did not remove OST0000!"
10091         cleanup
10092         reformat_and_config
10093 }
10094 run_test 123ah "del_ost cancels config log entries correctly"
10095
10096 cleanup_123ai() {
10097         local timeout=$1
10098
10099         echo "cleanup test 123ai"
10100
10101         # cancel last timeout record
10102         do_facet mgs "$LCTL set_param -P -d timeout"
10103
10104         # restore timeout value
10105         do_nodes $(comma_list $(all_nodes)) "$LCTL set_param timeout=$timeout"
10106 }
10107
10108 test_123ai() { #LU-16167
10109         local i
10110         local count
10111         local old_count
10112         local old_timeout
10113
10114         remote_mgs_nodsh && skip "remote MGS with nodsh"
10115         (( MDS1_VERSION >= $(version_code 2.15.51) )) ||
10116                 skip "Need MDS version at least 2.15.51"
10117
10118         [ -d $MOUNT/.lustre ] || setup
10119
10120         old_count=$(do_facet mgs "$LCTL --device MGS llog_print -r params" |
10121                 grep -c "parameter: timeout")
10122
10123         old_timeout=$($LCTL get_param -n timeout)
10124         stack_trap "cleanup_123ai $old_timeout" EXIT
10125
10126         # add and cancel params (2 * MAX_IOC_BUFLEN / 128 + 1 = 129)
10127         for i in {1..129}; do
10128                 do_facet mgs "$LCTL set_param -P timeout=$i" ||
10129                         error "fail to set timeout=$i on MGS"
10130         done
10131
10132         count=$(do_facet mgs "$LCTL --device MGS llog_print -r params" |
10133                 grep -c "parameter: timeout")
10134
10135         ((count - old_count == 129)) ||
10136                 error "number timeout record missmatch ($count - $old_count != 129)"
10137
10138         do_facet mgs "$LCTL --device MGS llog_print params" |
10139                 tail -1 | grep  "timeout, value: 129" ||
10140                 error "llog_print could not display the last record (timeout=129)"
10141
10142 }
10143 run_test 123ai "llog_print display all non skipped records"
10144
10145 test_123_prep() {
10146         remote_mgs_nodsh && skip "remote MGS with nodsh"
10147
10148         [ -d $MOUNT/.lustre ] || setup
10149         yaml_file="$TMP/$tfile.yaml"
10150
10151         do_facet mgs rm "$yaml_file"
10152         cfgfiles=$(do_facet mgs "lctl --device MGS llog_catlist" |
10153                          sed 's/config_log://')
10154
10155         # set jobid_var to a different value for test
10156         orig_val=$(do_facet mgs $LCTL get_param jobid_var)
10157
10158         do_facet mgs $LCTL set_param -P jobid_var="TESTNAME"
10159
10160         for i in $cfgfiles params; do
10161                 do_facet mgs "lctl --device MGS llog_print ${i} >> $yaml_file"
10162         done
10163
10164         echo "Unmounting FS"
10165         stopall
10166         echo "Writeconf"
10167         writeconf_all
10168         echo "Remounting"
10169         setup_noconfig
10170 }
10171
10172 test_123_restore() {
10173         set_val=$(do_facet mgs $LCTL get_param jobid_var)
10174
10175         do_facet mgs $LCTL set_param -P $orig_val
10176
10177         [ $set_val == "jobid_var=TESTNAME" ] ||
10178                 error "$set_val is not TESTNAME"
10179
10180         do_facet mgs rm "$yaml_file"
10181         cleanup
10182 }
10183
10184 test_123F() {
10185         local yaml_file
10186         local cfgfiles
10187         local orig_val
10188         local set_val
10189
10190         test_123_prep
10191
10192         # Reapply the config from before
10193         echo "Setting configuration parameters"
10194         do_facet mgs "lctl set_param -F $yaml_file"
10195
10196         test_123_restore
10197 }
10198 run_test 123F "clear and reset all parameters using set_param -F"
10199
10200 test_123G() {
10201         local yaml_file
10202         local cfgfiles
10203         local orig_val
10204         local set_val
10205
10206         test_123_prep
10207
10208         # Reapply the config from before
10209         echo "Setting configuration parameters"
10210         do_facet mgs "lctl apply_yaml $yaml_file"
10211
10212         test_123_restore
10213 }
10214 run_test 123G "clear and reset all parameters using apply_yaml"
10215
10216
10217 test_124()
10218 {
10219         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
10220         [ -z $mds2failover_HOST ] && skip "needs MDT failover setup"
10221
10222         setup
10223         do_facet mgs $LCTL --device MGS llog_print $FSNAME-client |
10224                 grep 1.2.3.4@tcp && error "Should not be fake nid"
10225         do_facet mgs $LCTL conf_param $FSNAME-MDT0001.failover.node=1.2.3.4@tcp\
10226                 || error "Set params error"
10227         do_facet mgs $LCTL --device MGS llog_print $FSNAME-client |
10228                 grep 1.2.3.4@tcp || error "Fake nid should be added"
10229         cleanup
10230
10231         load_modules
10232         if combined_mgs_mds; then
10233                 start_mdt 1 "-o nosvc" ||
10234                         error "starting mds with nosvc option failed"
10235         fi
10236         local nid=$(do_facet mds2 $LCTL list_nids | head -1)
10237         local failover_nid=$(do_node $mds2failover_HOST $LCTL list_nids | head -1)
10238
10239         do_facet mgs $LCTL replace_nids $FSNAME-MDT0001 $nid:$failover_nid ||
10240                 error "replace_nids execution error"
10241
10242         if combined_mgs_mds; then
10243                 stop_mdt 1
10244         fi
10245
10246         setup
10247         fail mds2
10248         echo "lfs setdirstripe"
10249         $LFS setdirstripe -i 1 $MOUNT/$tdir || error "setdirstirpe error"
10250         echo ok
10251 }
10252 run_test 124 "check failover after replace_nids"
10253
10254 get_max_sectors_kb() {
10255         local facet="$1"
10256         local device="$2"
10257         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10258         local max_sectors_path="/sys/block/${dev_base}/queue/max_sectors_kb"
10259
10260         do_facet ${facet} "[[ -e ${max_sectors_path} ]] &&
10261                            cat ${max_sectors_path}"
10262 }
10263
10264 get_max_hw_sectors_kb() {
10265         local facet="$1"
10266         local device="$2"
10267         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10268         local max_hw_path="/sys/block/${dev_base}/queue/max_hw_sectors_kb"
10269
10270         do_facet ${facet} "[[ -e ${max_hw_path} ]] && cat ${max_hw_path}"
10271 }
10272
10273 set_max_sectors_kb() {
10274         local facet="$1"
10275         local device="$2"
10276         local value="$3"
10277         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10278         local max_sectors_path="/sys/block/${dev_base}/queue/max_sectors_kb"
10279
10280         do_facet ${facet} "[[ -e ${max_sectors_path} ]] &&
10281                            echo ${value} > ${max_sectors_path}"
10282         rc=$?
10283
10284         [[ $rc -ne 0 ]] && echo "Failed to set ${max_sectors_path} to ${value}"
10285
10286         return $rc
10287 }
10288
10289 # Return 0 if all slave devices have max_sectors_kb == max_hw_sectors_kb
10290 # Otherwise return > 0
10291 check_slaves_max_sectors_kb()
10292 {
10293         local facet="$1"
10294         local device="$2"
10295         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10296         local slaves_dir=/sys/block/${dev_base}/slaves
10297         local slave_devices=$(do_facet ${facet} "ls ${slaves_dir} 2>/dev/null")
10298         [[ -z ${slave_devices} ]] && return 0
10299
10300         local slave max_sectors new_max_sectors max_hw_sectors path
10301         local rc=0
10302
10303         for slave in ${slave_devices}; do
10304                 path="/dev/${slave}"
10305                 ! is_blkdev ${facet} ${path} && continue
10306                 max_sectors=$(get_max_sectors_kb ${facet} ${path})
10307                 max_hw_sectors=$(get_max_hw_sectors_kb ${facet} ${path})
10308                 new_max_sectors=${max_hw_sectors}
10309                 [[ ${new_max_sectors} -gt ${RQ_SIZE_LIMIT} ]] &&
10310                         new_max_sectors=${RQ_SIZE_LIMIT}
10311
10312                 if [[ ${max_sectors} -ne ${new_max_sectors} ]]; then
10313                         echo "${path} ${max_sectors} ${new_max_sectors}"
10314                         ((rc++))
10315                 fi
10316                 check_slaves_max_sectors_kb ${facet} ${path}
10317                 ((rc + $?))
10318         done
10319
10320         return $rc
10321 }
10322
10323 test_125()
10324 {
10325         local facet_list="mgs mds1 ost1"
10326         combined_mgs_mds && facet_list="mgs ost1"
10327
10328         local facet
10329         for facet in ${facet_list}; do
10330                 [[ $(facet_fstype ${facet}) != ldiskfs ]] &&
10331                         skip "ldiskfs only test" &&
10332                         return 0
10333                 ! is_blkdev ${facet} $(facet_device ${facet}) &&
10334                         skip "requires all real devices" &&
10335                         return 0
10336         done
10337
10338         local rc=0
10339         # We don't increase IO request size limit past 16MB. See comments in
10340         # lustre/utils/libmount_utils_ldiskfs.c:tune_max_sectors_kb()
10341         RQ_SIZE_LIMIT=$((16 * 1024))
10342         local device old_max_sectors new_max_sectors max_hw_sectors
10343         for facet in ${facet_list}; do
10344                 device=$(facet_device ${facet})
10345                 old_max_sectors=$(get_max_sectors_kb ${facet} ${device})
10346                 max_hw_sectors=$(get_max_hw_sectors_kb ${facet} ${device})
10347
10348                 # The expected value after l_tunedisk is executed
10349                 new_max_sectors=$old_max_sectors
10350                 [[ ${new_max_sectors_kb} -gt ${RQ_SIZE_LIMIT} ]] &&
10351                         new_max_sectors_kb=${RQ_SIZE_LIMIT}
10352
10353                 # Ensure the current value of max_sectors_kb does not equal
10354                 # max_hw_sectors_kb, so we can tell whether l_tunedisk did
10355                 # anything
10356                 set_max_sectors_kb ${facet} ${device} $((new_max_sectors - 1))
10357
10358                 # Value before l_tunedisk
10359                 local pre_max_sectors=$(get_max_sectors_kb ${facet} ${device})
10360                 if [[ ${pre_max_sectors} -ne $((new_max_sectors - 1)) ]]; then
10361                         echo "unable to satsify test pre-condition:"
10362                         echo "${pre_max_sectors} != $((new_max_sectors - 1))"
10363                         ((rc++))
10364                         continue
10365                 fi
10366
10367                 echo "Before: ${facet} ${device} ${pre_max_sectors} ${max_hw_sectors}"
10368
10369                 do_facet ${facet} "l_tunedisk ${device}"
10370
10371                 # Value after l_tunedisk
10372                 local post_max_sectors=$(get_max_sectors_kb ${facet} ${device})
10373
10374                 echo "After: ${facet} ${device} ${post_max_sectors} ${max_hw_sectors}"
10375
10376                 if [[ ${facet} != ost1 ]]; then
10377                         if [[ ${post_max_sectors} -ne ${pre_max_sectors} ]]; then
10378                                 echo "l_tunedisk modified max_sectors_kb of ${facet}"
10379                                 ((rc++))
10380                         fi
10381
10382                         set_max_sectors_kb ${facet} ${device} ${old_max_sectors}
10383                 else
10384                         if [[ ${post_max_sectors} -eq ${pre_max_sectors} ]]; then
10385                                 echo "l_tunedisk failed to modify max_sectors_kb of ${facet}"
10386                                 ((rc++))
10387                         fi
10388
10389                         check_slaves_max_sectors_kb ${facet} ${device} ||
10390                                 ((rc++))
10391                 fi
10392         done
10393
10394         return $rc
10395 }
10396 run_test 125 "check l_tunedisk only tunes OSTs and their slave devices"
10397
10398 test_126() {
10399         [[ "$MDS1_VERSION" -ge $(version_code 2.13.52) ]] ||
10400                 skip "Need MDS version at least 2.13.52"
10401
10402         cleanup
10403         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ../libcfs/libcfs/libcfs
10404         #define OBD_FAIL_OBD_SETUP 0x60d
10405         do_facet mds1 $LCTL set_param fail_loc=0x60d
10406         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules &
10407         for i in {1..40}; do
10408                 do_facet mds1 lsmod | grep -q osd_$mds1_FSTYPE && break
10409                 sleep 1
10410         done
10411         clear_failloc $SINGLEMDS 20 &
10412         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
10413 }
10414 run_test 126 "mount in parallel shouldn't cause a crash"
10415
10416 test_127() {
10417         [[ "$ost1_FSTYPE" == ldiskfs ]] || skip "ldiskfs only test"
10418
10419         cleanup
10420         setup
10421         zconf_umount_clients $RCLIENTS $MOUNT
10422
10423         wait_osp_active ost ${FSNAME}-OST0000 0 1
10424         local osc_tgt="$FSNAME-OST0000-osc-$($LFS getname -i $DIR)"
10425         local avail1=($($LCTL get_param -n osc.${osc_tgt}.kbytesavail))
10426
10427         $LFS setstripe -i 0 $DIR/$tfile || error "failed creating $DIR/$tfile"
10428         dd if=/dev/zero of=$DIR/$tfile bs=1M oflag=direct || true
10429
10430         local avail2=($($LCTL get_param -n osc.${osc_tgt}.kbytesavail))
10431
10432         if ((avail2 * 100 / avail1 > 1)); then
10433                 lfs df $DIR
10434                 ls -l $DIR/$tfile
10435                 error "more than 1% space left: before=$avail1 after=$avail2"
10436         fi
10437
10438         local mbs=$(($(stat -c %s $DIR/$tfile) / (1024 * 1024)))
10439
10440         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$mbs conv=notrunc \
10441                 oflag=direct || error "overwrite failed"
10442 }
10443 run_test 127 "direct io overwrite on full ost"
10444
10445 test_128()
10446 {
10447         combined_mgs_mds && skip "need separate mgs device"
10448         [ "$ost2_FSTYPE" == zfs ] && import_zpool ost2
10449
10450         format_ost 2
10451         # Try to apply nolocallogs to the virgin OST. Should fail.
10452         do_facet ost2 "$TUNEFS --nolocallogs $(ostdevname 2)" &&
10453                 error "nolocallogs should not be allowed on the virgin target"
10454
10455         setupall
10456         stopall
10457
10458         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
10459         # Start OST without MGS (local configs)
10460         do_facet ost1 "$TUNEFS --dryrun $(ostdevname 1)"
10461         start_ost || error "unable to start OST1"
10462         stop_ost || error "Unable to stop OST1"
10463
10464         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
10465         # Do not allow reading local configs, should fail
10466         do_facet ost1 "$TUNEFS --nolocallogs $(ostdevname 1)" ||
10467                 error "Can not set nolocallogs"
10468         start_ost && error "OST1 started, but should fail"
10469
10470         # Connect to MGS successfully, reset nolocallogs flag
10471         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
10472         start_mgs || error "unable to start MGS"
10473         start_ost || error "unable to start OST1"
10474
10475         do_facet ost1 "$TUNEFS --dryrun $(ostdevname 1)" | grep "nolocallogs" &&
10476                 error "nolocallogs expected to be reset"
10477
10478         stop_ost || error "Unable to stop OST1"
10479 }
10480 run_test 128 "Force using remote logs with --nolocallogs"
10481
10482 test_129()
10483 {
10484         (( MDS1_VERSION >= $(version_code 2.14.57) )) ||
10485                 skip "Need MDS version at least 2.14.57"
10486         stopall
10487         start_mgsmds || error "MGS/MDS start failed"
10488         format_ost 1
10489         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &&
10490                 error "start ost1 should fail" || true
10491         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &&
10492                 error "second start ost1 should fail" || true
10493         do_facet ost1 "$TUNEFS --writeconf $(ostdevname 1)"
10494         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
10495                 error "start ost1 failed"
10496         stop ost1
10497         stop_mds
10498 }
10499 run_test 129 "attempt to connect an OST with the same index should fail"
10500
10501 test_130()
10502 {
10503         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
10504         setupall
10505         stop_mdt 2 || error "mdt2 stop failed"
10506         do_facet mds2 "$TUNEFS --writeconf $(mdsdevname 2)"
10507         start_mdt 2 || error "mdt2 start failed"
10508         do_facet mds2 "$LCTL dl" | grep MDT0001-osp-MDT0001 &&
10509                 error "Illegal OSP device created" || true
10510 }
10511 run_test 130 "re-register an MDT after writeconf"
10512
10513 test_131() {
10514         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip "ldiskfs only test"
10515         (( $MDS1_VERSION >= $(version_code 2.14.56.35) )) ||
10516                 skip "Need MDS version at least 2.14.56.35"
10517         do_facet mds1 $DEBUGFS -R features $(mdsdevname 1) |
10518                 grep -q project || skip "skip project quota not supported"
10519
10520         local projid
10521
10522         setupall
10523         test_mkdir -c $MDSCOUNT -p $DIR/$tdir
10524         $LFS project -p 1000 $DIR/$tdir || error "set dir project id failed"
10525         createmany -o $DIR/$tdir/f 512
10526         for ((i = 0; i < 512; ++i)); do
10527                 $LFS project -p $i $DIR/$tdir/f${i} ||
10528                         error "set f${i} project id failed"
10529         done
10530
10531         test_mkdir -c $MDSCOUNT -p $DIR/$tdir.inherit
10532         $LFS project -p 1001 -s $DIR/$tdir.inherit
10533         createmany -o $DIR/$tdir.inherit/f 128
10534         (( $($LFS project $DIR/$tdir.inherit/f* |
10535                 awk '$1 == 1001 { print }' | wc -l) == 128 )) ||
10536                         error "files did not inherit projid 1001"
10537
10538         stopall
10539
10540         for i in $(seq $MDSCOUNT); do
10541                 mds_backup_restore mds$i ||
10542                         error "Backup/restore on mds$i failed"
10543         done
10544
10545         setupall
10546
10547         projid=($($LFS project -d $DIR/$tdir))
10548         [ ${projid[0]} == "1000" ] ||
10549                 error "projid expected 1000 not ${projid[0]}"
10550         for ((i = 0; i < 512; ++i)); do
10551                 projid=($($LFS project $DIR/$tdir/f${i}))
10552                 [ ${projid[0]} == "$i" ] ||
10553                         error "projid expected $i not ${projid[0]}"
10554         done
10555
10556         (( $($LFS project $DIR/$tdir.inherit/f* |
10557                 awk '$1 == 1001 { print }' | wc -l) == 128 )) ||
10558                         error "restore did not copy projid 1001"
10559 }
10560 run_test 131 "MDT backup restore with project ID"
10561
10562 test_132() {
10563         local err_cnt
10564         local err_cnt2
10565
10566         (( MDS1_VERSION >= $(version_code 2.14.57) )) ||
10567                 skip "Need MDS version at least 2.14.57"
10568         reformat
10569         combined_mgs_mds || start_mgs || error "unable to start MGS"
10570         start_mdt 1 || error "unable to start mdt1"
10571
10572         err_cnt=$(do_facet mds1 dmesg | grep -c "cannot take the layout locks")
10573         stop_mdt 1 || error "stop mdt1 failed"
10574
10575         [ "$mds1_FSTYPE" == zfs ] && import_zpool mds1
10576         do_facet mds1 $TUNEFS --param mdt.hsm_control=enabled $(mdsdevname 1) ||
10577                 error "tunefs failed"
10578         start_mdt 1 || error "cannot start mdt1"
10579
10580         err_cnt2=$(do_facet mds1 dmesg | grep -c "cannot take the layout locks")
10581         [ $err_cnt -eq $err_cnt2 ] || error "Can not take the layout lock"
10582         stop_mdt 1 || error "stop mdt1 failed"
10583 }
10584 run_test 132 "hsm_actions processed after failover"
10585
10586 # This test verifies we do RR allocation within a pool even if there is a
10587 # significant imbalance vs an OST outside the pool
10588 test_133() {
10589         [[ $OSTCOUNT -lt 4 ]] && skip_env "needs >= 4 OSTs"
10590         [[ "$OST1_VERSION" -ge $(version_code 2.15.51) ]] ||
10591                 skip "Need OST version at least 2.15.51"
10592         # This is the easiest way to ensure OSTs start out balanced
10593         reformat_and_config
10594         setupall
10595
10596         check_set_fallocate_or_skip
10597
10598         local testfile=$DIR/$tdir/$tfile
10599         local pool="testpool"
10600         local ostrange=$((OSTCOUNT - 1))
10601         # Select all but the last OST to add to the pool
10602         local poolostrange=$((OSTCOUNT - 2))
10603         local filenum=20
10604         local filecount
10605         local stripecount
10606
10607         declare -a AVAIL
10608         free_min_max
10609
10610         [ $MINV -eq 0 ] && error "no free space in OST$MINI"
10611         [ $MAXV -gt $((2 * $MINV)) ] &&
10612                 error "OSTs badly unbalanced after reformat"
10613
10614         create_pool $FSNAME.$pool || error "failed to create a pool"
10615         do_facet mgs $LCTL pool_add $FSNAME.$pool OST[0-$poolostrange] ||
10616                 error "failed to add OST[0-$poolostrange] to the pool"
10617
10618         test_mkdir -p $DIR/$tdir || error "failed to mkdir $DIR/$tdir"
10619         # Consume space on the OSTs in the pool so they are unbalanced with the
10620         # OST outside of the pool
10621         # fill each OST 90% with fallocate so they are widely
10622         # imbalanced
10623         local size=$(((MINV * 9 / 10) * 1024))
10624         for ((i = 0; i <= poolostrange; i++)); do
10625                 $LFS setstripe -c 1 -i $i $testfile$i ||
10626                         error "failed to setstripe $testfile$i"
10627                 fallocate -l $size $testfile$i || error "fallocate failed"
10628         done
10629         ls -la $DIR/$tdir
10630         sleep_maxage
10631         $LFS df
10632
10633         # Create files in the pool now that there is an imbalance
10634         filecount=$(((OSTCOUNT - 1) * filenum))
10635         for ((i = 0; i < filecount; i++)); do
10636                 $LFS setstripe -p $pool $testfile-$i ||
10637                         error "failed to setstripe -p $pool $testfile-$i"
10638         done
10639         $LFS getstripe -i $testfile-* > /tmp/$tfile.log
10640         # Count the number of files with a stripe on each OST to verify the
10641         # pool allocated with round-robin
10642         for ((i = 0; i <= poolostrange; i++)); do
10643                 stripecount=$(grep -c $i /tmp/$tfile.log)
10644                 # Allow a little leeway
10645                 if (( stripecount < filenum - 1 ||
10646                       stripecount > filenum + 1 )); then
10647                         cat /tmp/$tfile.log
10648                         error "$stripecount != $filenum files on OST$i"
10649                 fi
10650         done
10651
10652         # Create files across the system now that there is an imbalance
10653         filecount=$((OSTCOUNT * filenum))
10654         for ((i = 1; i < filecount; i++)); do
10655                 $LFS setstripe $testfile-$i.2 ||
10656                         error "failed to setstripe $testfile-$i.2"
10657         done
10658         $LFS getstripe -i $testfile-*.2 > /tmp/$tfile.log
10659         local qos_used=""
10660         # Count the number of files with a stripe on each OST to verify the
10661         # files are *NOT* allocated with round-robin
10662         for ((i = 0; i <= ostrange; i++)); do
10663                 stripecount=$(grep -c $i /tmp/$tfile.log)
10664                 if [[ $stripecount -ne $filenum ]]; then
10665                         qos_used="true"
10666                         echo "QOS: $stripecount != $filenum files on OST$i"
10667                 fi
10668         done
10669         if [ -z "$qos_used" ]; then
10670                 error "QOS not used on imbalanced OSTs!"
10671         fi
10672
10673         rm -rf /tmp/$tfile.log $DIR/$tdir
10674         do_facet mgs $LCTL pool_remove $FSNAME.$pool OST[0-$poolostrange] ||
10675                 "failed to remove OST[0-$poolostrange] from the pool"
10676         do_facet mgs $LCTL pool_destroy $FSNAME.$pool ||
10677                 error "failed to destroy pool"
10678 }
10679 run_test 133 "stripe QOS: free space balance in a pool"
10680
10681 test_134() {
10682         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip "ldiskfs only test"
10683         local errors
10684         local rc
10685         local mdt_dev=$(facet_device mds1)
10686         local tmp_dir=$TMP/$tdir
10687         local out=$tmp_dir/check_iam.txt
10688         local CHECK_IAM=${CHECK_IAM:-$(do_facet mds1 "which check_iam 2> /dev/null || true")}
10689
10690         [[ -n "$CHECK_IAM" ]] || skip "check_iam not found"
10691
10692         mkdir -p $tmp_dir
10693         for ((i=0; i<64; i++)); do
10694                 local f=oi.16.$i
10695                 #cmd introduce a random corruption to IAM file
10696                 local cmd="dd if=/dev/urandom of=$tmp_dir/$f bs=2 conv=notrunc count=1 seek=$((RANDOM % 36))"
10697                 do_facet mds1 "mkdir -p $tmp_dir; \
10698                    $DEBUGFS -c -R 'dump $f $tmp_dir/$f' $mdt_dev 2>&1; \
10699                    $CHECK_IAM -v $tmp_dir/$f 2>&1; \
10700                    echo $cmd; eval $cmd 2>/dev/null;
10701                    $CHECK_IAM -v $tmp_dir/$f 2>&1; echo \\\$?" >> $out 2>&1
10702         done
10703
10704         tail -n50 $out
10705
10706         stack_trap "rm -rf $tmp_dir && do_facet mds1 rm -rf $tmp_dir" EXIT
10707
10708         rc=$(grep -c "fault\|except" $out)
10709         (( rc == 0 )) || { cat $out &&
10710                 error "check_iam failed with fault or exception $rc"; }
10711
10712         rc=$(grep -c "^255" $out)
10713         errors=$(grep -c "FINISHED WITH ERRORS" $out)
10714
10715         (( rc == errors )) || { cat $out &&
10716                 error "check_iam errcode does not fit with errors $rc $errors"; }
10717 }
10718 run_test 134 "check_iam works without faults"
10719
10720 cleanup_test_135(){
10721         local oldgc=$1
10722
10723         printf "\nCleanup test_135\n" >&2
10724         do_facet mds1 "$LCTL set_param -n $oldgc"
10725         rm -rf $DIR/$tdir &> /dev/null
10726         cleanup
10727 }
10728
10729 __test_135_file_thread() {
10730         local service="$1"
10731         local init_time=$(awk '{print $1}' /proc/uptime)
10732         local awkcmd="/crosses index zero/ {if (\$1 > $init_time) exit(1);}"
10733
10734         #Generate a full plain llogs
10735         while dmesg | sed -r 's/(\[|\])//g' | awk "$awkcmd" ; do
10736                 createmany -o $DIR/$tdir/f 4500 >&2
10737                 createmany -u $DIR/$tdir/f 4500 >&2
10738         done
10739 }
10740
10741 __test_135_reader() {
10742         local fd=$1
10743         local cl_user=$2
10744         local firstidx=$(changelog_user_rec mds1 $cl_user)
10745         local oldidx=$firstidx
10746         local newidx=0
10747         local pid=0
10748         local other
10749
10750         while read -t10 -u$fd newidx other; do
10751                 (( (newidx - oldidx) == 1 )) ||
10752                         error  "changelog jump detected (last: $oldidx, current: $newidx)"
10753
10754                 if (( (newidx - firstidx + 1) % 13000 == 0 )); then
10755                         [[ $pid -eq 0 ]] ||
10756                                 wait $pid || error "changelog_clear failed"
10757                         changelog_clear $((newidx - 1)) mds1 >&2 & pid=$!
10758                 fi
10759                 oldidx=$newidx
10760         done
10761
10762         [[ $pid -eq 0 ]] ||
10763                 wait $pid || error "changelog_clear failed"
10764
10765         echo "$oldidx"
10766 }
10767
10768 test_135() {
10769         (( MDS1_VERSION >= $(version_code 2.15.52) )) ||
10770                 skip "need MDS version at least 2.15.52"
10771
10772         local service=$(facet_svc mds1)
10773         local rc=0
10774         local lastread lastidx
10775         local files_pid reader_pid
10776         local fd
10777         local init_time
10778         local cl_user
10779
10780         # Need to reformat because we are changing llog catalog sizes to 5.
10781         # Otherwise, processing could fail with existing catalogs (last_idx>5).
10782         reformat
10783         setup_noconfig
10784
10785         # Disable changelog garbage colector
10786         local oldgc=$(do_facet mds1 "$LCTL get_param mdd.${service}.changelog_gc")
10787         do_facet mds1 "$LCTL set_param -n mdd.${service}.changelog_gc=0"
10788         stack_trap "cleanup_test_135 $oldgc" EXIT INT
10789
10790         # change the changelog_catalog size to 5 entries for everybody
10791 #define OBD_FAIL_CAT_RECORDS                        0x1312
10792         do_node $(comma_list $(all_nodes)) $LCTL set_param fail_loc=0x1312 fail_val=5
10793
10794         # disable console ratelimit
10795         local rl=$(cat /sys/module/libcfs/parameters/libcfs_console_ratelimit)
10796         echo 0 > /sys/module/libcfs/parameters/libcfs_console_ratelimit
10797         stack_trap "echo $rl > /sys/module/libcfs/parameters/libcfs_console_ratelimit" EXIT
10798
10799         test_mkdir -c 1 -i 0 $DIR/$tdir || error "Failed to create directory"
10800         changelog_chmask "ALL" || error "changelog_chmask failed"
10801         changelog_register || error "changelog_register failed"
10802
10803         cl_user="${CL_USERS[mds1]%% *}"
10804         changelog_users mds1 | grep -q $cl_user ||
10805                 error "User $cl_user not found in changelog_users"
10806
10807         # Start reader thread
10808         coproc $LFS changelog --follow $service
10809         reader_pid=$!
10810         fd=${COPROC[0]}
10811         stack_trap "echo kill changelog reader; kill $reader_pid" EXIT
10812
10813         echo -e "\nWrap arround changelog catalog"
10814
10815         # Start file writer thread
10816         __test_135_file_thread "$service" & files_pid=$!
10817         stack_trap "(pkill -P$files_pid; kill $files_pid) &> /dev/null || true" EXIT
10818
10819         # Check changelog entries
10820         lastread=$(__test_135_reader $fd $cl_user) || exit $?
10821         ! kill -0 $files_pid 2>/dev/null ||
10822                 error "creation thread is running. Is changelog reader stuck?"
10823
10824         lastidx=$(changelog_users mds1 | awk '/current_index/ {print $NF}' )
10825         [[ "$lastread" -eq "$lastidx" ]] ||
10826                 error "invalid changelog lastidx (read: $lastread, mds: $lastidx)"
10827 }
10828 run_test 135 "check the behavior when changelog is wrapped around"
10829
10830 cleanup_136 () {
10831         do_facet mds2 "$LCTL --device ec cleanup" || true
10832         do_facet mds2 "$LCTL --device ec detach" || true
10833
10834         stopall
10835         reformat_and_config
10836 }
10837
10838 test_136() {
10839         (( MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
10840
10841         reformat
10842         setup_noconfig
10843
10844         do_facet mds2 "$LCTL attach echo_client ec ec_uuid" ||
10845             error "echo attach fail"
10846
10847         stack_trap cleanup_136 EXIT
10848
10849         do_facet mds2 "$LCTL --device ec setup lustre-MDT0001 mdt" &&
10850             error "attach to MDT should fail!"
10851
10852         do_facet mds2 "$LCTL --device ec setup lustre-MDT0001 mdd" ||
10853             error "attach to MDD should OK"
10854         do_facet mds2 "$LCTL --device ec test_mkdir /tt" &&
10855             error "mkdir test should fail with remote object"
10856
10857         return 0
10858 }
10859 run_test 136 "don't panic with bad obdecho setup"
10860
10861 wait_osp_import() {
10862         local facet=$1
10863         local remtgt=$(facet_svc $2)
10864         local expected=$3
10865         local loctgt=$(facet_svc $facet)
10866         local param="osp.$remtgt-os[pc]-${loctgt#*-}.*_server_uuid"
10867
10868         do_rpc_nodes "$(facet_active_host $facet)" \
10869                         wait_import_state $expected $param ||
10870                 error "$param: import is not in expected state"
10871 }
10872
10873 test_137() {
10874         (( MDS1_VERSION >= $(version_code 2.15.61) )) ||
10875                 skip "need MDS version at least 2.15.61"
10876
10877         (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
10878
10879         local failnode=1.2.3.4@$NETTYPE
10880         local keep_zpool=$KEEP_ZPOOL
10881
10882         reformat
10883         #start mgs or mgs/mdt0
10884         if ! combined_mgs_mds ; then
10885                 start_mgs || error "Fail to register mgs"
10886                 start_mdt 1 || error "Fail to register mds1"
10887         else
10888                 start_mdt 1 || error "Fail to register mds1"
10889         fi
10890
10891         start_ost || error "OST0 start fail"
10892
10893         mount_client $MOUNT || error "mount client fails"
10894         wait_osc_import_ready client ost
10895         check_mount || error "check_mount failed"
10896
10897         # Add failover node on OST0000
10898         stop_ost
10899         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
10900         do_facet ost1 "$TUNEFS --failnode=$failnode $(ostdevname 1)" ||
10901                 error "ost1 tunefs failed"
10902         start_ost || error "OST0 start fail"
10903
10904         # Add pool and parameters on MDT0000 to check the inheritance
10905         do_facet mgs $LCTL pool_new $FSNAME.pool1 || error "pool_new failed"
10906         do_facet mgs $LCTL pool_add $FSNAME.pool1 OST0000 ||
10907                 error "pool_add failed"
10908
10909         set_conf_param_and_check mds1                                   \
10910             "$LCTL get_param -n lod.$FSNAME-MDT0000*.dom_stripesize"    \
10911             "$FSNAME-MDT0000.lod.dom_stripesize"                        \
10912             "$((2<<20))"
10913
10914         start_mdt 2 || error "Fail to register mds2"
10915
10916         wait_osp_import mds1 mds2 FULL
10917         wait_osp_import mds2 mds1 FULL
10918         wait_osp_import mds2 ost1 FULL
10919
10920         # Add failover node on MDT0001
10921         stop_mdt 2 || error "Fail to umount  mds2"
10922         [ "$mds1_FSTYPE" == zfs ] && import_zpool mds2
10923         do_facet mds2 "$TUNEFS --failnode=$failnode $(mdsdevname 2)" ||
10924                 error "mds2 tunefs failed"
10925         start_mdt 2 || error "Fail to mount mds2"
10926
10927         wait_osp_import mds1 mds2 FULL
10928         wait_osp_import mds2 mds1 FULL
10929         wait_osp_import mds2 ost1 FULL
10930
10931         local i
10932         for ((i=3; i <= MDSCOUNT; i++)); do
10933                 start_mdt $i || error "Fail to register mds$i"
10934         done
10935
10936         wait_osc_import_state mds ost FULL
10937
10938         for ((i=2; i <= MDSCOUNT; i++)); do
10939                 local import
10940                 local facet=mds$i
10941                 local tgt=$(facet_svc $facet)
10942                 local lod="lod.$tgt*"
10943
10944                 wait_osp_active mds $tgt $(( i - 1 )) 1
10945
10946                 do_facet $facet $LCTL get_param -n $lod.pools.pool1 |
10947                         grep -q "OST0000" || error "pool1 should be inherited"
10948
10949                 val=$(do_facet $facet $LCTL get_param -n $lod.dom_stripesize)
10950                 (( val == (2<<20) )) ||
10951                         error "dom_stripesize should be inherited"
10952
10953                 import="osc.$FSNAME-OST0000-osc-${tgt#*-}.import"
10954                 do_facet $facet $LCTL get_param -n $import |
10955                         grep -q "failover_nids:.*$failnode" ||
10956                         error "$failnode not found in $import"
10957
10958                 [[ "${tgt#*-}" != MDT0001 ]] || continue
10959
10960                 import="osp.$FSNAME-MDT0001-osp-${tgt#*-}.import"
10961                 do_facet $facet $LCTL get_param -n $import |
10962                         grep -q "failover_nids:.*$failnode" ||
10963                         error "$failnode not found in $import"
10964         done
10965
10966         cleanup || error "cleanup failed with rc $?"
10967         reformat_and_config
10968 }
10969 run_test 137 "a new MDT should inherit pools, parameters and failnode"
10970
10971 test_140() {
10972         (( MDS1_VERSION >= $(version_code 2.15.55) )) ||
10973                 skip "need MDS version at least 2.15.55"
10974         (( MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
10975
10976         RM_UPDATELOG=$(do_facet mds2 "which remove_updatelog 2> /dev/null")
10977         RM_UPDATELOG=${RM_UPDATELOG:-"$LUSTRE/scripts/remove_updatelog"}
10978
10979         [ -f "$RM_UPDATELOG" ] ||
10980                 skip_env "remove_updatelog is not found on mds2"
10981
10982         local mntpt=$(facet_mntpt mds2)
10983
10984         setup_noconfig
10985         test_mkdir -c $MDSCOUNT -p $DIR/$tdir ||
10986                 error "mkdir $DIR/$tdir failed"
10987         mkdir $DIR/$tdir/d{1..256}
10988
10989         stop_mdt 1
10990         stop_mdt 2
10991
10992         mount_fstype mds2 || error "mount as fstype mds2 failed"
10993         do_facet mds2 $RM_UPDATELOG -n $mntpt
10994         MDTS=($(do_facet mds2 $RM_UPDATELOG -n $mntpt |
10995                 grep -o "Processing MDT[0-9]*" | awk -F'MDT' '{print $2}'))
10996         (( ${#MDTS[@]} == MDSCOUNT )) ||
10997                 error "Processed ${#MDTS[@]} from $MDSCOUNT"
10998
10999         do_facet mds2 $RM_UPDATELOG -n -m 1,0 $mntpt
11000         MDTS=($(do_facet mds2 $RM_UPDATELOG -n -m 1,0 $mntpt |
11001                 grep -o "Processing MDT[0-9]*" | awk -F'MDT' '{print $2}'))
11002         (( ${#MDTS[@]} == 2 )) ||
11003                 error "Processed ${#MDTS[@]} instead of 2"
11004         (( ${MDTS[0]} == 1 && ${MDTS[1]} == 0 )) ||
11005                 error "Processed: ${MDTS[*]}, expected: 1 0"
11006
11007         do_facet mds2 $RM_UPDATELOG -m 0 $mntpt
11008         unmount_fstype mds2
11009         start_mdt 2 || error "mds2 start fail"
11010         start_mdt 1 || error "mds1 start fail"
11011         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds1 FULL
11012         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
11013
11014         rm -rf $DIR/$tdir || error "Can't remove $tdir"
11015         stopall
11016         reformat_and_config
11017 }
11018 run_test 140 "remove_updatelog script actions"
11019
11020 test_150() {
11021         setup
11022
11023         local max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11024                               awk '/^max_cached_mb/ { print $2 }')
11025         stack_trap "$LCTL set_param -n llite.*.max_cached_mb=$max_cached_mb"
11026
11027         $LCTL set_param llite.*.max_cached_mb='100%'
11028
11029         local new_max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11030                                   awk '/^max_cached_mb/ { print $2 }')
11031         local total_ram_mb=$(free -m | grep 'Mem:' | awk '{print $2}')
11032
11033         $LCTL get_param llite.*.max_cached_mb
11034         echo "total ram mb: $total_ram_mb"
11035         (( new_max_cached_mb == total_ram_mb )) ||
11036                 error "setting cache to 100% not equal to total RAM"
11037
11038         $LCTL set_param llite.*.max_cached_mb='50%'
11039         new_max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11040                             awk '/^max_cached_mb/ { print $2 }')
11041
11042         $LCTL get_param llite.*.max_cached_mb
11043         (( new_max_cached_mb == $((total_ram_mb / 2)) )) ||
11044                 error "setting cache to 50% not equal to 50% of RAM"
11045
11046         $LCTL set_param llite.*.max_cached_mb='105%' &&
11047                 error "should not be able to set insane value"
11048
11049         $LCTL set_param llite.*.max_cached_mb='0%'
11050         new_max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11051                             awk '/^max_cached_mb/ { print $2 }')
11052         # Minimum cache size is 64 MiB
11053         $LCTL get_param llite.*.max_cached_mb
11054         (( new_max_cached_mb == 64 )) ||
11055                 error "setting cache to 0% != minimum cache size"
11056 }
11057 run_test 150 "test setting max_cached_mb to a %"
11058
11059 test_151() {
11060         (( MDS1_VERSION >= $(version_code 2.15.58) )) ||
11061                 skip "need MDS version at least 2.15.58"
11062         [[ "$ost1_FSTYPE" == ldiskfs ]] || skip "ldiskfs only test"
11063
11064         cleanup
11065         if ! combined_mgs_mds ; then
11066                 stop mgs
11067         fi
11068
11069         echo "Damage ost1 local config log"
11070         do_facet ost1 "$DEBUGFS -w -R 'punch CONFIGS/$FSNAME-OST0000 0 1' \
11071                       $(ostdevname 1) || return \$?" ||
11072                 error "do_facet ost1 failed with $?"
11073
11074         # expect OST to fail mount with no MGS and bad local config
11075         start_ost && error "OST start should fail"
11076
11077         if ! combined_mgs_mds ; then
11078                 start_mgs
11079         fi
11080         start_mds || error "MDS start failed"
11081         # now it should start with MGS config
11082         start_ost || error "OST start failed"
11083         reformat_and_config
11084 }
11085 run_test 151 "damaged local config doesn't prevent mounting"
11086
11087 test_152() {
11088         (( MDS1_VERSION >= $(version_code 2.15.59.53) )) ||
11089                 skip "need MDS >= 2.15.59.53 for sequence allocation retry"
11090         (( MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
11091         local tf=$DIR/$tdir/$tfile
11092         local nost=$((OSTCOUNT+1))
11093         local nostdevname=$(ostdevname $nost)
11094
11095         setupall
11096         test_mkdir -i 1 -c1 $DIR/$tdir || error "can't mkdir"
11097
11098         log "ADD OST$nost"
11099         add ost$nost $(mkfs_opts ost1 $nostdevname) --index=$nost \
11100                 --reformat $nostdevname $(ostvdevname $nost)
11101         [[ -d "$nostdevname" ]] || stack_trap "do_facet mds1 rm -f $nostdevname"
11102
11103 #define OBD_FAIL_OPS_FAIL_SEQ_ALLOC             0x2109
11104         do_facet mds1 $LCTL set_param fail_loc=0x80002109 fail_val=2
11105         echo "START OST$nost"
11106         stack_trap "stop ost$nost"
11107         start ost$nost $nostdevname $OST_MOUNT_OPTS &
11108         local PID=$!
11109         sleep 2
11110
11111         $LFS setstripe -c -1 $tf &
11112         local PID2=$!
11113         sleep 2
11114
11115         log "STOP OST$nost"
11116         # probably mount hasn't completed yet, so stop races with it
11117         while true; do
11118                 stop ost$nost
11119                 jobs -pr | grep -E "^$PID\$" && sleep 0.5 && continue
11120                 break
11121         done
11122         wait $PID
11123         wait $PID2
11124         do_facet mds1 $LCTL set_param fail_loc=0
11125         log "START OST$nost again"
11126         start ost$nost $nostdevname $OST_MOUNT_OPTS ||
11127                 error "can't start ost$nost"
11128         sleep 10
11129         $LFS setstripe -c -1 $tf-2 || error "can't touch  $tf-2"
11130         $LFS getstripe -v $tf-2
11131         local stripes=$($LFS getstripe -c $tf-2)
11132         (( stripes == $nost )) || error "$tf-2 $stripes != $nost"
11133 }
11134 run_test 152 "seq allocation error in OSP"
11135
11136 test_153a() {
11137         reformat_and_config
11138
11139         start_mds || error "MDS start failed"
11140         start_ost || error "OST start failed"
11141
11142         local nid=$($LCTL list_nids | grep ${NETTYPE} | head -n1)
11143         local net=${nid#*@}
11144         local MGS_NID=$(do_facet mgs $LCTL list_nids | head -1)
11145         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
11146         local FAKE_PNID="192.168.252.112@${net}"
11147         local FAKE_NIDS="${FAKE_PNID},${FAKE_PNID}2"
11148         local FAKE_FAILOVER="10.252.252.113@${net},10.252.252.113@${net}2"
11149         local NIDS_AND_FAILOVER="$FAKE_NIDS:$FAKE_FAILOVER:$OST1_NID:$MGS_NID"
11150         local period=0
11151         local pid
11152         local rc
11153
11154         mount -t lustre $NIDS_AND_FAILOVER:/lustre $MOUNT &
11155         pid=$!
11156         while (( period < 30 )); do
11157                 [[ -n "$(ps -p $pid -o pid=)" ]] || break
11158                 echo "waiting for mount ..."
11159                 sleep 5
11160                 period=$((period + 5))
11161         done
11162         $LCTL get_param mgc.MGC${FAKE_PNID}.import | grep "uptodate:"
11163         check_mount || error "check_mount failed"
11164         umount $MOUNT
11165         cleanup || error "cleanup failed with rc $?"
11166 }
11167 run_test 153a "bypass invalid NIDs quickly"
11168
11169 #
11170 # (This was sanity/802a)
11171 #
11172 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
11173 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
11174 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
11175 saved_MOUNT_OPTS=$MOUNT_OPTS
11176
11177 cleanup_802a() {
11178         stopall
11179         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
11180         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
11181         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
11182         MOUNT_OPTS=$saved_MOUNT_OPTS
11183         setupall
11184 }
11185
11186 test_802a() {
11187         [[ $mds1_FSTYPE = zfs ]] || skip "ZFS specific test"
11188         [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
11189         [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
11190                 skip "Need server version at least 2.9.55"
11191
11192         [[ $ENABLE_QUOTA ]] && skip "Quota enabled for read-only test"
11193
11194         # Reset before starting
11195         stopall
11196         setupall
11197
11198         mkdir $DIR/$tdir || error "(1) fail to mkdir"
11199
11200         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
11201                 error "(2) Fail to copy"
11202
11203         stack_trap cleanup_802a EXIT
11204
11205         # sync by force before remount as readonly
11206         sync; sync_all_data; sleep 3; sync_all_data
11207
11208         stopall
11209
11210         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
11211         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
11212         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
11213
11214         echo "Mount the server as read only"
11215         setupall server_only || error "(3) Fail to start servers"
11216
11217         echo "Mount client without ro should fail"
11218         mount_client $MOUNT &&
11219                 error "(4) Mount client without 'ro' should fail"
11220
11221         echo "Mount client with ro should succeed"
11222         MOUNT_OPTS=$(csa_add "$MOUNT_OPTS" -o ro)
11223         mount_client $MOUNT ||
11224                 error "(5) Mount client with 'ro' should succeed"
11225
11226         echo "Modify should be refused"
11227         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
11228
11229         echo "Read should be allowed"
11230         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
11231                 error "(7) Read should succeed under ro mode"
11232 }
11233 run_test 802a "simulate readonly device"
11234
11235 if ! combined_mgs_mds ; then
11236         stop mgs
11237 fi
11238
11239 cleanup_gss
11240
11241 # restore the values of MDSSIZE and OSTSIZE
11242 MDSSIZE=$STORED_MDSSIZE
11243 OSTSIZE=$STORED_OSTSIZE
11244 reformat
11245
11246 complete_test $SECONDS
11247 check_and_cleanup_lustre
11248 exit_status