]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_TEST_WATCH_NOTIFY_H | |
5 | #define CEPH_TEST_WATCH_NOTIFY_H | |
6 | ||
7 | #include "include/rados/librados.hpp" | |
8 | #include "common/Cond.h" | |
9 | #include "common/Mutex.h" | |
10 | #include <boost/noncopyable.hpp> | |
11 | #include <boost/shared_ptr.hpp> | |
12 | #include <list> | |
13 | #include <map> | |
14 | ||
15 | class Cond; | |
16 | class Finisher; | |
17 | ||
18 | namespace librados { | |
19 | ||
20 | class TestRadosClient; | |
21 | ||
22 | class TestWatchNotify : boost::noncopyable { | |
23 | public: | |
24 | typedef std::pair<uint64_t, uint64_t> WatcherID; | |
25 | typedef std::set<WatcherID> WatcherIDs; | |
26 | typedef std::map<std::pair<uint64_t, uint64_t>, bufferlist> NotifyResponses; | |
27 | ||
28 | struct NotifyHandle { | |
29 | TestRadosClient *rados_client = nullptr; | |
30 | WatcherIDs pending_watcher_ids; | |
31 | NotifyResponses notify_responses; | |
32 | bufferlist *pbl = nullptr; | |
33 | Context *on_notify = nullptr; | |
34 | }; | |
35 | typedef boost::shared_ptr<NotifyHandle> SharedNotifyHandle; | |
36 | typedef std::map<uint64_t, SharedNotifyHandle> NotifyHandles; | |
37 | ||
38 | struct WatchHandle { | |
39 | TestRadosClient *rados_client = nullptr; | |
40 | std::string addr; | |
41 | uint32_t nonce; | |
42 | uint64_t gid; | |
43 | uint64_t handle; | |
44 | librados::WatchCtx* watch_ctx; | |
45 | librados::WatchCtx2* watch_ctx2; | |
46 | }; | |
47 | ||
48 | typedef std::map<uint64_t, WatchHandle> WatchHandles; | |
49 | ||
50 | struct Watcher { | |
51 | WatchHandles watch_handles; | |
52 | NotifyHandles notify_handles; | |
53 | }; | |
54 | typedef boost::shared_ptr<Watcher> SharedWatcher; | |
55 | ||
56 | TestWatchNotify(); | |
57 | ||
58 | int list_watchers(const std::string& o, | |
59 | std::list<obj_watch_t> *out_watchers); | |
60 | ||
61 | void aio_flush(TestRadosClient *rados_client, Context *on_finish); | |
62 | void aio_watch(TestRadosClient *rados_client, const std::string& o, | |
63 | uint64_t gid, uint64_t *handle, librados::WatchCtx2 *watch_ctx, | |
64 | Context *on_finish); | |
65 | void aio_unwatch(TestRadosClient *rados_client, uint64_t handle, | |
66 | Context *on_finish); | |
67 | void aio_notify(TestRadosClient *rados_client, const std::string& oid, | |
68 | bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl, | |
69 | Context *on_notify); | |
70 | ||
71 | void flush(TestRadosClient *rados_client); | |
72 | int notify(TestRadosClient *rados_client, const std::string& o, | |
73 | bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl); | |
74 | void notify_ack(TestRadosClient *rados_client, const std::string& o, | |
75 | uint64_t notify_id, uint64_t handle, uint64_t gid, | |
76 | bufferlist& bl); | |
77 | int watch(TestRadosClient *rados_client, const std::string& o, uint64_t gid, | |
78 | uint64_t *handle, librados::WatchCtx *ctx, | |
79 | librados::WatchCtx2 *ctx2); | |
80 | int unwatch(TestRadosClient *rados_client, uint64_t handle); | |
81 | ||
82 | void blacklist(uint32_t nonce); | |
83 | ||
84 | private: | |
85 | ||
86 | typedef std::map<std::string, SharedWatcher> FileWatchers; | |
87 | ||
88 | uint64_t m_handle = 0; | |
89 | uint64_t m_notify_id = 0; | |
90 | ||
91 | Mutex m_lock; | |
92 | uint64_t m_pending_notifies = 0; | |
93 | ||
94 | Cond m_file_watcher_cond; | |
95 | FileWatchers m_file_watchers; | |
96 | ||
97 | SharedWatcher get_watcher(const std::string& oid); | |
98 | ||
99 | void execute_notify(TestRadosClient *rados_client, const std::string &oid, | |
100 | bufferlist &bl, uint64_t notify_id); | |
101 | void ack_notify(TestRadosClient *rados_client, const std::string &oid, | |
102 | uint64_t notify_id, const WatcherID &watcher_id, | |
103 | const bufferlist &bl); | |
104 | void finish_notify(TestRadosClient *rados_client, const std::string &oid, | |
105 | uint64_t notify_id); | |
106 | }; | |
107 | ||
108 | } // namespace librados | |
109 | ||
110 | #endif // CEPH_TEST_WATCH_NOTIFY_H |