]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/usr/bin/env bash |
2 | set -ex | |
7c673cae FG |
3 | |
4 | TMPDIR=/tmp/rbd_test_admin_socket$$ | |
5 | mkdir $TMPDIR | |
6 | trap "rm -fr $TMPDIR" 0 | |
7 | ||
c07f9fc5 | 8 | . $(dirname $0)/../../standalone/ceph-helpers.sh |
7c673cae FG |
9 | |
10 | function expect_false() | |
11 | { | |
12 | set -x | |
13 | if "$@"; then return 1; else return 0; fi | |
14 | } | |
15 | ||
16 | function rbd_watch_out_file() | |
17 | { | |
18 | echo ${TMPDIR}/rbd_watch_$1.out | |
19 | } | |
20 | ||
21 | function rbd_watch_pid_file() | |
22 | { | |
23 | echo ${TMPDIR}/rbd_watch_$1.pid | |
24 | } | |
25 | ||
26 | function rbd_watch_fifo() | |
27 | { | |
28 | echo ${TMPDIR}/rbd_watch_$1.fifo | |
29 | } | |
30 | ||
31 | function rbd_watch_asok() | |
32 | { | |
33 | echo ${TMPDIR}/rbd_watch_$1.asok | |
34 | } | |
35 | ||
36 | function rbd_get_perfcounter() | |
37 | { | |
38 | local image=$1 | |
39 | local counter=$2 | |
40 | local name | |
41 | ||
42 | name=$(ceph --format xml --admin-daemon $(rbd_watch_asok ${image}) \ | |
43 | perf schema | $XMLSTARLET el -d3 | | |
44 | grep "/librbd-.*-${image}/${counter}\$") | |
45 | test -n "${name}" || return 1 | |
46 | ||
47 | ceph --format xml --admin-daemon $(rbd_watch_asok ${image}) perf dump | | |
48 | $XMLSTARLET sel -t -m "${name}" -v . | |
49 | } | |
50 | ||
51 | function rbd_check_perfcounter() | |
52 | { | |
53 | local image=$1 | |
54 | local counter=$2 | |
55 | local expected_val=$3 | |
56 | local val= | |
57 | ||
58 | val=$(rbd_get_perfcounter ${image} ${counter}) | |
59 | ||
60 | test "${val}" -eq "${expected_val}" | |
61 | } | |
62 | ||
63 | function rbd_watch_start() | |
64 | { | |
65 | local image=$1 | |
d2e6a577 | 66 | local asok=$(rbd_watch_asok ${image}) |
7c673cae FG |
67 | |
68 | mkfifo $(rbd_watch_fifo ${image}) | |
69 | (cat $(rbd_watch_fifo ${image}) | | |
d2e6a577 FG |
70 | rbd --admin-socket ${asok} watch ${image} \ |
71 | > $(rbd_watch_out_file ${image}) 2>&1)& | |
7c673cae FG |
72 | |
73 | # find pid of the started rbd watch process | |
74 | local pid | |
75 | for i in `seq 10`; do | |
d2e6a577 | 76 | pid=$(ps auxww | awk "/[r]bd --admin.* watch ${image}/ {print \$2}") |
7c673cae FG |
77 | test -n "${pid}" && break |
78 | sleep 0.1 | |
79 | done | |
80 | test -n "${pid}" | |
81 | echo ${pid} > $(rbd_watch_pid_file ${image}) | |
82 | ||
83 | # find watcher admin socket | |
7c673cae FG |
84 | test -n "${asok}" |
85 | for i in `seq 10`; do | |
86 | test -S "${asok}" && break | |
87 | sleep 0.1 | |
88 | done | |
89 | test -S "${asok}" | |
7c673cae FG |
90 | |
91 | # configure debug level | |
92 | ceph --admin-daemon "${asok}" config set debug_rbd 20 | |
93 | ||
94 | # check that watcher is registered | |
95 | rbd status ${image} | expect_false grep "Watchers: none" | |
96 | } | |
97 | ||
98 | function rbd_watch_end() | |
99 | { | |
100 | local image=$1 | |
101 | local regexp=$2 | |
102 | ||
103 | # send 'enter' to watch to exit | |
104 | echo > $(rbd_watch_fifo ${image}) | |
105 | # just in case it is not terminated | |
106 | kill $(cat $(rbd_watch_pid_file ${image})) || : | |
107 | ||
108 | # output rbd watch out file for easier troubleshooting | |
109 | cat $(rbd_watch_out_file ${image}) | |
110 | ||
111 | # cleanup | |
112 | rm -f $(rbd_watch_fifo ${image}) $(rbd_watch_pid_file ${image}) \ | |
113 | $(rbd_watch_out_file ${image}) $(rbd_watch_asok ${image}) | |
114 | } | |
115 | ||
7c673cae FG |
116 | pool="rbd" |
117 | image=testimg$$ | |
118 | ceph_admin="ceph --admin-daemon $(rbd_watch_asok ${image})" | |
119 | ||
120 | rbd create --size 128 ${pool}/${image} | |
121 | ||
122 | # check rbd cache commands are present in help output | |
123 | rbd_cache_flush="rbd cache flush ${pool}/${image}" | |
124 | rbd_cache_invalidate="rbd cache invalidate ${pool}/${image}" | |
125 | ||
126 | rbd_watch_start ${image} | |
127 | ${ceph_admin} help | fgrep "${rbd_cache_flush}" | |
128 | ${ceph_admin} help | fgrep "${rbd_cache_invalidate}" | |
129 | rbd_watch_end ${image} | |
130 | ||
131 | # test rbd cache commands with disabled and enabled cache | |
132 | for conf_rbd_cache in false true; do | |
133 | ||
134 | rbd image-meta set ${image} conf_rbd_cache ${conf_rbd_cache} | |
135 | ||
136 | rbd_watch_start ${image} | |
137 | ||
138 | rbd_check_perfcounter ${image} flush 0 | |
139 | ${ceph_admin} ${rbd_cache_flush} | |
140 | # 'flush' counter should increase regardless if cache is enabled | |
141 | rbd_check_perfcounter ${image} flush 1 | |
142 | ||
143 | rbd_check_perfcounter ${image} invalidate_cache 0 | |
144 | ${ceph_admin} ${rbd_cache_invalidate} | |
145 | # 'invalidate_cache' counter should increase regardless if cache is enabled | |
146 | rbd_check_perfcounter ${image} invalidate_cache 1 | |
147 | ||
148 | rbd_watch_end ${image} | |
149 | done | |
150 | ||
151 | rbd rm ${image} |