Whamcloud - gitweb
LU-1082 test: create test for mds-survey
[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 build_test_filter
12 check_and_setup_lustre
13
14 file_count=${file_count:-100000}
15 dir_count=${dir_count:-4}
16 thrhi=${thrhi:-8}
17 thrlo=${thrlo:-1}
18
19 [ "$SLOW" = no ] && { file_count=50000; dir_count=2; thrhi=4; }
20
21 # Skip these tests
22 ALWAYS_EXCEPT="$MDS_SURVEY_EXCEPT"
23
24 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
25 if [ -z ${MDSSURVEY} ]; then
26     skip_env "mds-survey not found" && exit
27 fi
28
29 # check for available inode, reduce to fit
30 inode_per_thr=$((dir_count * file_count))
31 require_inode=$((inode_per_thr * thrhi * 11/10))
32 avail_inode=$($LFS df -i $MOUNT | grep "filesystem summary:"  | \
33     awk '{print $5}')
34
35 while [ $require_inode -ge $avail_inode  ]; do
36     echo "Require $require_inode inode to run, only have $avail_inode"
37     # reduce 20%
38     file_count=$((file_count * 8 / 10))
39     inode_per_thr=$((dir_count * file_count))
40     require_inode=$((inode_per_thr * thrhi * 11 / 10))
41 done
42
43 if [ $require_inode -eq 0 ]; then
44     skip_env "Not enough inode to run" && exit
45 fi
46
47 ost_count=$($LCTL dl | grep -c osc)
48
49 # first unmount all the lustre clients
50 cleanup_mount $MOUNT
51 cleanup_mount $MOUNT2
52
53 get_target() {
54     local mds=$(facet_host $SINGLEMDS)
55     echo $(do_nodes $mds 'lctl dl' | \
56         awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
57 }
58
59 mds_survey_run() {
60     local layer=${1:-mdd}
61     local stripe_count=${2:-0}
62     local mds=$(facet_host $SINGLEMDS)
63
64     rm -f ${TMP}/mds_survey*
65
66     local target=$(get_target)
67     local cmd1="file_count=$file_count thrlo=$thrlo thrhi=$thrhi"
68     local cmd2="dir_count=$dir_count layer=$layer stripe_count=$stripe_count"
69     local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
70     local cmd="$cmd1 $cmd2 $cmd3"
71
72     echo + $cmd
73     eval $cmd || error "mds-survey failed"
74     cat ${TMP}/mds_survey*
75     rm -f ${TMP}/mds_survey*
76 }
77
78 test_1() {
79     mds_survey_run "mdd" "0"
80 }
81 run_test 1 "Metadata survey with zero-stripe"
82
83 test_2() {
84     if [ $ost_count -eq 0 ]; then
85         skip_env "Need to mount OST to test" && return
86     fi
87     mds_survey_run "mdd" "1"
88 }
89 run_test 2 "Metadata survey with stripe_count = 1"
90
91 # remount the clients
92 restore_mount $MOUNT
93
94 complete $(basename $0) $SECONDS
95 cleanup_echo_devs
96 check_and_cleanup_lustre
97 exit_status