Whamcloud - gitweb
LU-9219 tests: add missing mgs reformat to conf-sanity/56
[fs/lustre-release.git] / lustre / tests / mds-survey.sh
1 #!/bin/bash
2 #set -x
3 set -e
4
5 LUSTRE=${LUSTRE:-`dirname $0`/..}
6 . $LUSTRE/tests/test-framework.sh
7 init_test_env $@
8 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
9 init_logging
10
11 file_count=${file_count:-150000}
12 dir_count=${dir_count:-4}
13 thrhi=${thrhi:-8}
14 thrlo=${thrlo:-1}
15
16 [ "$SLOW" = no ] && { file_count=50000; dir_count=2; thrhi=4; }
17
18 # Skip these tests
19 ALWAYS_EXCEPT="$MDS_SURVEY_EXCEPT"
20
21 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
22 if [ -z ${MDSSURVEY} ]; then
23     skip_env "mds-survey not found" && exit
24 fi
25
26 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.51) ]; then
27         skip_env "Need MDS version at least 2.3.51" && exit
28 fi
29
30 build_test_filter
31 check_and_setup_lustre
32
33 adjust_inode() {
34     local require_inode=0
35     local avail_mdt_inode=0
36     local avail_ost_inode=0
37
38     require_inode=$((file_count * thrhi))
39     # get available inode for mdt
40     avail_mdt_inode=$(mdt_free_inodes 0)
41     avail_mdt_inode=$((avail_mdt_inode * 9 / 10))
42
43     # get available inode for ost
44     for i in $($LFS df -i | grep ${FSNAME}-OST | awk '{print $4}'); do
45         avail_ost_inode=$((avail_ost_inode + i))
46     done
47     avail_ost_inode=$((avail_ost_inode * 9 / 10))
48
49     ((require_inode > avail_mdt_inode)) && require_inode=$avail_mdt_inode
50     ((require_inode > avail_ost_inode)) && require_inode=$avail_ost_inode
51
52     if ((require_inode == 0)); then
53         error "Fail to get the inode count"
54     fi
55     # convert it back to per thread inode
56     require_inode=$((require_inode / thrhi))
57
58     echo $require_inode
59 }
60
61
62 file_count=$(adjust_inode)
63 ost_count=$($LCTL dl | grep -c osc)
64
65 # first unmount all the lustre clients
66 cleanup_mount $MOUNT
67 cleanup_mount $MOUNT2
68
69 get_target() {
70         local node=$1
71         local mdt
72         local mdts
73         local target
74
75         mdts=$(do_node $node "$LCTL dl" |
76                awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
77
78         for mdt in $mdts; do
79                 target+="${target:+ }$node:$mdt"
80         done
81
82         echo -n $target
83 }
84
85 get_targets() {
86         local targets
87         local node
88
89         for node in $(mdts_nodes); do
90                 targets+="${targets:+ }$(get_target $node)"
91         done
92
93         echo -n $targets
94 }
95
96 mds_survey_run() {
97         local layer=${1:-mdd}
98         local stripe_count=${2:-0}
99         local rc=0
100
101         rm -f ${TMP}/mds_survey*
102
103         local cmd="file_count=$file_count thrlo=$thrlo thrhi=$thrhi"
104         cmd+=" dir_count=$dir_count layer=$layer stripe_count=$stripe_count"
105         cmd+=" rslt_loc=${TMP} targets=\"$(get_targets)\" $MDSSURVEY"
106
107         trap cleanup_echo_devs EXIT ERR
108
109         echo + $cmd
110         eval $cmd || rc=$?
111         cat ${TMP}/mds_survey*
112         rm -f ${TMP}/mds_survey*
113         ((rc == 0)) || error "mds-survey failed"
114 }
115
116 test_1() {
117     mds_survey_run "mdd" "0"
118 }
119 run_test 1 "Metadata survey with zero-stripe"
120
121 test_2() {
122     if [ $ost_count -eq 0 ]; then
123         skip_env "Need to mount OST to test" && return
124     fi
125     mds_survey_run "mdd" "1"
126 }
127 run_test 2 "Metadata survey with stripe_count = 1"
128
129 # remount the clients
130 restore_mount $MOUNT
131
132 complete $SECONDS
133 cleanup_echo_devs
134 check_and_cleanup_lustre
135 exit_status