]>
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" | |
11fdf7f2 | 8 | #include "common/AsyncOpTracker.h" |
9f95a23c | 9 | #include "common/ceph_mutex.h" |
7c673cae FG |
10 | #include <boost/noncopyable.hpp> |
11 | #include <boost/shared_ptr.hpp> | |
12 | #include <list> | |
13 | #include <map> | |
14 | ||
7c673cae FG |
15 | class Finisher; |
16 | ||
17 | namespace librados { | |
18 | ||
11fdf7f2 | 19 | class TestCluster; |
7c673cae FG |
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 | ||
11fdf7f2 TL |
50 | struct ObjectHandler; |
51 | typedef boost::shared_ptr<ObjectHandler> SharedObjectHandler; | |
52 | ||
7c673cae | 53 | struct Watcher { |
11fdf7f2 TL |
54 | Watcher(int64_t pool_id, const std::string& nspace, const std::string& oid) |
55 | : pool_id(pool_id), nspace(nspace), oid(oid) { | |
56 | } | |
57 | ||
58 | int64_t pool_id; | |
59 | std::string nspace; | |
60 | std::string oid; | |
61 | ||
62 | SharedObjectHandler object_handler; | |
7c673cae FG |
63 | WatchHandles watch_handles; |
64 | NotifyHandles notify_handles; | |
65 | }; | |
66 | typedef boost::shared_ptr<Watcher> SharedWatcher; | |
67 | ||
11fdf7f2 | 68 | TestWatchNotify(TestCluster* test_cluster); |
7c673cae | 69 | |
11fdf7f2 TL |
70 | int list_watchers(int64_t pool_id, const std::string& nspace, |
71 | const std::string& o, std::list<obj_watch_t> *out_watchers); | |
7c673cae FG |
72 | |
73 | void aio_flush(TestRadosClient *rados_client, Context *on_finish); | |
11fdf7f2 TL |
74 | void aio_watch(TestRadosClient *rados_client, int64_t pool_id, |
75 | const std::string& nspace, const std::string& o, uint64_t gid, | |
76 | uint64_t *handle, librados::WatchCtx *watch_ctx, | |
77 | librados::WatchCtx2 *watch_ctx2, Context *on_finish); | |
7c673cae FG |
78 | void aio_unwatch(TestRadosClient *rados_client, uint64_t handle, |
79 | Context *on_finish); | |
11fdf7f2 TL |
80 | void aio_notify(TestRadosClient *rados_client, int64_t pool_id, |
81 | const std::string& nspace, const std::string& oid, | |
82 | const bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl, | |
7c673cae FG |
83 | Context *on_notify); |
84 | ||
85 | void flush(TestRadosClient *rados_client); | |
11fdf7f2 TL |
86 | int notify(TestRadosClient *rados_client, int64_t pool_id, |
87 | const std::string& nspace, const std::string& o, bufferlist& bl, | |
88 | uint64_t timeout_ms, bufferlist *pbl); | |
89 | void notify_ack(TestRadosClient *rados_client, int64_t pool_id, | |
90 | const std::string& nspace, const std::string& o, | |
7c673cae FG |
91 | uint64_t notify_id, uint64_t handle, uint64_t gid, |
92 | bufferlist& bl); | |
11fdf7f2 TL |
93 | |
94 | int watch(TestRadosClient *rados_client, int64_t pool_id, | |
95 | const std::string& nspace, const std::string& o, uint64_t gid, | |
7c673cae FG |
96 | uint64_t *handle, librados::WatchCtx *ctx, |
97 | librados::WatchCtx2 *ctx2); | |
98 | int unwatch(TestRadosClient *rados_client, uint64_t handle); | |
99 | ||
f67539c2 | 100 | void blocklist(uint32_t nonce); |
7c673cae FG |
101 | |
102 | private: | |
11fdf7f2 TL |
103 | typedef std::tuple<int64_t, std::string, std::string> PoolFile; |
104 | typedef std::map<PoolFile, SharedWatcher> FileWatchers; | |
7c673cae | 105 | |
11fdf7f2 | 106 | TestCluster *m_test_cluster; |
7c673cae FG |
107 | |
108 | uint64_t m_handle = 0; | |
109 | uint64_t m_notify_id = 0; | |
110 | ||
9f95a23c TL |
111 | ceph::mutex m_lock = |
112 | ceph::make_mutex("librados::TestWatchNotify::m_lock"); | |
11fdf7f2 | 113 | AsyncOpTracker m_async_op_tracker; |
7c673cae | 114 | |
7c673cae FG |
115 | FileWatchers m_file_watchers; |
116 | ||
11fdf7f2 TL |
117 | SharedWatcher get_watcher(int64_t pool_id, const std::string& nspace, |
118 | const std::string& oid); | |
119 | void maybe_remove_watcher(SharedWatcher shared_watcher); | |
120 | ||
121 | void execute_watch(TestRadosClient *rados_client, int64_t pool_id, | |
122 | const std::string& nspace, const std::string& o, | |
123 | uint64_t gid, uint64_t *handle, | |
124 | librados::WatchCtx *watch_ctx, | |
125 | librados::WatchCtx2 *watch_ctx2, | |
126 | Context *on_finish); | |
127 | void execute_unwatch(TestRadosClient *rados_client, uint64_t handle, | |
128 | Context *on_finish); | |
129 | ||
130 | void execute_notify(TestRadosClient *rados_client, int64_t pool_id, | |
131 | const std::string& nspace, const std::string &oid, | |
132 | const bufferlist &bl, bufferlist *pbl, | |
133 | Context *on_notify); | |
134 | void ack_notify(TestRadosClient *rados_client, int64_t pool_id, | |
135 | const std::string& nspace, const std::string &oid, | |
7c673cae FG |
136 | uint64_t notify_id, const WatcherID &watcher_id, |
137 | const bufferlist &bl); | |
11fdf7f2 TL |
138 | void finish_notify(TestRadosClient *rados_client, int64_t pool_id, |
139 | const std::string& nspace, const std::string &oid, | |
7c673cae | 140 | uint64_t notify_id); |
11fdf7f2 TL |
141 | |
142 | void handle_object_removed(int64_t pool_id, const std::string& nspace, | |
143 | const std::string& oid); | |
7c673cae FG |
144 | }; |
145 | ||
146 | } // namespace librados | |
147 | ||
148 | #endif // CEPH_TEST_WATCH_NOTIFY_H |