From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/test/librados_test_stub/TestWatchNotify.h | 148 ++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/test/librados_test_stub/TestWatchNotify.h (limited to 'src/test/librados_test_stub/TestWatchNotify.h') diff --git a/src/test/librados_test_stub/TestWatchNotify.h b/src/test/librados_test_stub/TestWatchNotify.h new file mode 100644 index 000000000..bb973ea6b --- /dev/null +++ b/src/test/librados_test_stub/TestWatchNotify.h @@ -0,0 +1,148 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_TEST_WATCH_NOTIFY_H +#define CEPH_TEST_WATCH_NOTIFY_H + +#include "include/rados/librados.hpp" +#include "common/AsyncOpTracker.h" +#include "common/ceph_mutex.h" +#include +#include +#include +#include + +class Finisher; + +namespace librados { + +class TestCluster; +class TestRadosClient; + +class TestWatchNotify : boost::noncopyable { +public: + typedef std::pair WatcherID; + typedef std::set WatcherIDs; + typedef std::map, bufferlist> NotifyResponses; + + struct NotifyHandle { + TestRadosClient *rados_client = nullptr; + WatcherIDs pending_watcher_ids; + NotifyResponses notify_responses; + bufferlist *pbl = nullptr; + Context *on_notify = nullptr; + }; + typedef boost::shared_ptr SharedNotifyHandle; + typedef std::map NotifyHandles; + + struct WatchHandle { + TestRadosClient *rados_client = nullptr; + std::string addr; + uint32_t nonce; + uint64_t gid; + uint64_t handle; + librados::WatchCtx* watch_ctx; + librados::WatchCtx2* watch_ctx2; + }; + + typedef std::map WatchHandles; + + struct ObjectHandler; + typedef boost::shared_ptr SharedObjectHandler; + + struct Watcher { + Watcher(int64_t pool_id, const std::string& nspace, const std::string& oid) + : pool_id(pool_id), nspace(nspace), oid(oid) { + } + + int64_t pool_id; + std::string nspace; + std::string oid; + + SharedObjectHandler object_handler; + WatchHandles watch_handles; + NotifyHandles notify_handles; + }; + typedef boost::shared_ptr SharedWatcher; + + TestWatchNotify(TestCluster* test_cluster); + + int list_watchers(int64_t pool_id, const std::string& nspace, + const std::string& o, std::list *out_watchers); + + void aio_flush(TestRadosClient *rados_client, Context *on_finish); + void aio_watch(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& o, uint64_t gid, + uint64_t *handle, librados::WatchCtx *watch_ctx, + librados::WatchCtx2 *watch_ctx2, Context *on_finish); + void aio_unwatch(TestRadosClient *rados_client, uint64_t handle, + Context *on_finish); + void aio_notify(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& oid, + const bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl, + Context *on_notify); + + void flush(TestRadosClient *rados_client); + int notify(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& o, bufferlist& bl, + uint64_t timeout_ms, bufferlist *pbl); + void notify_ack(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& o, + uint64_t notify_id, uint64_t handle, uint64_t gid, + bufferlist& bl); + + int watch(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& o, uint64_t gid, + uint64_t *handle, librados::WatchCtx *ctx, + librados::WatchCtx2 *ctx2); + int unwatch(TestRadosClient *rados_client, uint64_t handle); + + void blocklist(uint32_t nonce); + +private: + typedef std::tuple PoolFile; + typedef std::map FileWatchers; + + TestCluster *m_test_cluster; + + uint64_t m_handle = 0; + uint64_t m_notify_id = 0; + + ceph::mutex m_lock = + ceph::make_mutex("librados::TestWatchNotify::m_lock"); + AsyncOpTracker m_async_op_tracker; + + FileWatchers m_file_watchers; + + SharedWatcher get_watcher(int64_t pool_id, const std::string& nspace, + const std::string& oid); + void maybe_remove_watcher(SharedWatcher shared_watcher); + + void execute_watch(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& o, + uint64_t gid, uint64_t *handle, + librados::WatchCtx *watch_ctx, + librados::WatchCtx2 *watch_ctx2, + Context *on_finish); + void execute_unwatch(TestRadosClient *rados_client, uint64_t handle, + Context *on_finish); + + void execute_notify(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string &oid, + const bufferlist &bl, bufferlist *pbl, + Context *on_notify); + void ack_notify(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string &oid, + uint64_t notify_id, const WatcherID &watcher_id, + const bufferlist &bl); + void finish_notify(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string &oid, + uint64_t notify_id); + + void handle_object_removed(int64_t pool_id, const std::string& nspace, + const std::string& oid); +}; + +} // namespace librados + +#endif // CEPH_TEST_WATCH_NOTIFY_H -- cgit v1.2.3