3 TMPDIR=/tmp/rbd_test_admin_socket$$
5 trap "rm -fr $TMPDIR" 0
7 . $(dirname $0)/../../standalone/ceph-helpers.sh
9 function expect_false()
12 if "$@"; then return 1; else return 0; fi
15 function rbd_watch_out_file()
17 echo ${TMPDIR}/rbd_watch_$1.out
20 function rbd_watch_pid_file()
22 echo ${TMPDIR}/rbd_watch_$1.pid
25 function rbd_watch_fifo()
27 echo ${TMPDIR}/rbd_watch_$1.fifo
30 function rbd_watch_asok()
32 echo ${TMPDIR}/rbd_watch_$1.asok
35 function rbd_get_perfcounter()
41 name=$(ceph --format xml --admin-daemon $(rbd_watch_asok ${image}) \
42 perf schema | $XMLSTARLET el -d3 |
43 grep "/librbd-.*-${image}/${counter}\$")
44 test -n "${name}" || return 1
46 ceph --format xml --admin-daemon $(rbd_watch_asok ${image}) perf dump |
47 $XMLSTARLET sel -t -m "${name}" -v .
50 function rbd_check_perfcounter()
57 val=$(rbd_get_perfcounter ${image} ${counter})
59 test "${val}" -eq "${expected_val}"
62 function rbd_watch_start()
65 local asok=$(rbd_watch_asok ${image})
67 mkfifo $(rbd_watch_fifo ${image})
68 (cat $(rbd_watch_fifo ${image}) |
69 rbd --admin-socket ${asok} watch ${image} \
70 > $(rbd_watch_out_file ${image}) 2>&1)&
72 # find pid of the started rbd watch process
75 pid=$(ps auxww | awk "/[r]bd --admin.* watch ${image}/ {print \$2}")
76 test -n "${pid}" && break
80 echo ${pid} > $(rbd_watch_pid_file ${image})
82 # find watcher admin socket
85 test -S "${asok}" && break
90 # configure debug level
91 ceph --admin-daemon "${asok}" config set debug_rbd 20
93 # check that watcher is registered
94 rbd status ${image} | expect_false grep "Watchers: none"
97 function rbd_watch_end()
102 # send 'enter' to watch to exit
103 echo > $(rbd_watch_fifo ${image})
104 # just in case it is not terminated
105 kill $(cat $(rbd_watch_pid_file ${image})) || :
107 # output rbd watch out file for easier troubleshooting
108 cat $(rbd_watch_out_file ${image})
111 rm -f $(rbd_watch_fifo ${image}) $(rbd_watch_pid_file ${image}) \
112 $(rbd_watch_out_file ${image}) $(rbd_watch_asok ${image})
119 ceph_admin="ceph --admin-daemon $(rbd_watch_asok ${image})"
121 rbd create --size 128 ${pool}/${image}
123 # check rbd cache commands are present in help output
124 rbd_cache_flush="rbd cache flush ${pool}/${image}"
125 rbd_cache_invalidate="rbd cache invalidate ${pool}/${image}"
127 rbd_watch_start ${image}
128 ${ceph_admin} help | fgrep "${rbd_cache_flush}"
129 ${ceph_admin} help | fgrep "${rbd_cache_invalidate}"
130 rbd_watch_end ${image}
132 # test rbd cache commands with disabled and enabled cache
133 for conf_rbd_cache in false true; do
135 rbd image-meta set ${image} conf_rbd_cache ${conf_rbd_cache}
137 rbd_watch_start ${image}
139 rbd_check_perfcounter ${image} flush 0
140 ${ceph_admin} ${rbd_cache_flush}
141 # 'flush' counter should increase regardless if cache is enabled
142 rbd_check_perfcounter ${image} flush 1
144 rbd_check_perfcounter ${image} invalidate_cache 0
145 ${ceph_admin} ${rbd_cache_invalidate}
146 # 'invalidate_cache' counter should increase regardless if cache is enabled
147 rbd_check_perfcounter ${image} invalidate_cache 1
149 rbd_watch_end ${image}