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