From: Jason Dillaman Date: Wed, 8 Jan 2020 19:29:15 +0000 (-0500) Subject: rbd-mirror: journal helper state machines now inherits from simple BaseRequest X-Git-Tag: v15.1.0~250^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=35c59e75cf3508a6c5d061147cf886a4942d0083;p=ceph.git rbd-mirror: journal helper state machines now inherits from simple BaseRequest The StateBuilder will need to construct and return a simple interface when creating the CreateLocalImageRequest and PrepareReplayRequest state machines regardless of whether it's for journal or snapshot mirroring. Signed-off-by: Jason Dillaman --- diff --git a/src/tools/rbd_mirror/BaseRequest.h b/src/tools/rbd_mirror/BaseRequest.h new file mode 100644 index 000000000000..0da98651d64e --- /dev/null +++ b/src/tools/rbd_mirror/BaseRequest.h @@ -0,0 +1,33 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_RBD_MIRROR_BASE_REQUEST_H +#define CEPH_RBD_MIRROR_BASE_REQUEST_H + +#include "include/Context.h" + +namespace rbd { +namespace mirror { + +class BaseRequest { +public: + BaseRequest(Context *on_finish) : m_on_finish(on_finish) { + } + virtual ~BaseRequest() {} + + virtual void send() = 0; + +protected: + virtual void finish(int r) { + m_on_finish->complete(r); + delete this; + } + +private: + Context *m_on_finish; +}; + +} // namespace mirror +} // namespace rbd + +#endif // CEPH_RBD_MIRROR_BASE_REQUEST_H diff --git a/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.cc b/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.cc index 1f46c6331e28..01d837a28290 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.cc @@ -169,14 +169,6 @@ void CreateLocalImageRequest::handle_update_client_image(int r) { create_local_image(); } -template -void CreateLocalImageRequest::finish(int r) { - dout(10) << "r=" << r << dendl; - - m_on_finish->complete(r); - delete this; -} - template void CreateLocalImageRequest::update_progress( const std::string& description) { diff --git a/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h b/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h index cd2c3abca106..ee96117ea934 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h +++ b/src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h @@ -7,6 +7,7 @@ #include "include/rados/librados_fwd.hpp" #include "librbd/journal/Types.h" #include "librbd/journal/TypeTraits.h" +#include "tools/rbd_mirror/BaseRequest.h" #include struct Context; @@ -22,7 +23,7 @@ namespace image_replayer { namespace journal { template -class CreateLocalImageRequest { +class CreateLocalImageRequest : public BaseRequest { public: typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta; typedef librbd::journal::TypeTraits TypeTraits; @@ -49,13 +50,13 @@ public: const std::string& remote_mirror_uuid, MirrorPeerClientMeta* client_meta, ProgressContext* progress_ctx, std::string* local_image_id, Context* on_finish) - : m_threads(threads), m_local_io_ctx(local_io_ctx), + : BaseRequest(on_finish), + m_threads(threads), m_local_io_ctx(local_io_ctx), m_remote_image_ctx(remote_image_ctx), m_remote_journaler(remote_journaler), m_global_image_id(global_image_id), m_remote_mirror_uuid(remote_mirror_uuid), m_client_meta(client_meta), - m_progress_ctx(progress_ctx), m_local_image_id(local_image_id), - m_on_finish(on_finish) { + m_progress_ctx(progress_ctx), m_local_image_id(local_image_id) { } void send(); @@ -92,7 +93,6 @@ private: MirrorPeerClientMeta* m_client_meta; ProgressContext* m_progress_ctx; std::string* m_local_image_id; - Context* m_on_finish; void unregister_client(); void handle_unregister_client(int r); @@ -106,8 +106,6 @@ private: void update_client_image(); void handle_update_client_image(int r); - void finish(int r); - void update_progress(const std::string& description); }; diff --git a/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc b/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc index c3c48b94c824..13a4b9a1383a 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc @@ -290,14 +290,6 @@ void PrepareReplayRequest::handle_get_remote_tags(int r) { finish(0); } -template -void PrepareReplayRequest::finish(int r) { - dout(10) << "r=" << r << dendl; - - m_on_finish->complete(r); - delete this; -} - template void PrepareReplayRequest::update_progress(const std::string &description) { dout(10) << description << dendl; diff --git a/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h b/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h index 091d7956b316..dc38f8b4cb04 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h +++ b/src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h @@ -9,6 +9,7 @@ #include "librbd/journal/Types.h" #include "librbd/journal/TypeTraits.h" #include "librbd/mirror/Types.h" +#include "tools/rbd_mirror/BaseRequest.h" #include #include @@ -24,7 +25,7 @@ namespace image_replayer { namespace journal { template -class PrepareReplayRequest { +class PrepareReplayRequest : public BaseRequest { public: typedef librbd::journal::TypeTraits TypeTraits; typedef typename TypeTraits::Journaler Journaler; @@ -50,15 +51,16 @@ public: const std::string& remote_mirror_uuid, MirrorPeerClientMeta* client_meta, ProgressContext* progress_ctx, bool* resync_requested, bool* syncing, Context* on_finish) - : m_local_image_ctx(local_image_ctx), m_remote_journaler(remote_journaler), + : BaseRequest(on_finish), + m_local_image_ctx(local_image_ctx), m_remote_journaler(remote_journaler), m_remote_promotion_state(remote_promotion_state), m_local_mirror_uuid(local_mirror_uuid), m_remote_mirror_uuid(remote_mirror_uuid), m_client_meta(client_meta), m_progress_ctx(progress_ctx), m_resync_requested(resync_requested), - m_syncing(syncing), m_on_finish(on_finish) { + m_syncing(syncing) { } - void send(); + void send() override; private: /** @@ -91,7 +93,6 @@ private: ProgressContext* m_progress_ctx; bool* m_resync_requested; bool* m_syncing; - Context* m_on_finish; uint64_t m_local_tag_tid = 0; librbd::journal::TagData m_local_tag_data; @@ -109,7 +110,6 @@ private: void get_remote_tags(); void handle_get_remote_tags(int r); - void finish(int r); void update_progress(const std::string& description); };