]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-mirror: journal helper state machines now inherits from simple BaseRequest
authorJason Dillaman <dillaman@redhat.com>
Wed, 8 Jan 2020 19:29:15 +0000 (14:29 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 9 Jan 2020 15:48:52 +0000 (10:48 -0500)
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 <dillaman@redhat.com>
src/tools/rbd_mirror/BaseRequest.h [new file with mode: 0644]
src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.cc
src/tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h
src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.cc
src/tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h

diff --git a/src/tools/rbd_mirror/BaseRequest.h b/src/tools/rbd_mirror/BaseRequest.h
new file mode 100644 (file)
index 0000000..0da9865
--- /dev/null
@@ -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
index 1f46c6331e28a9ee4ec4d02ae28326498e651508..01d837a282900ef982c87931b8948eb3b784864d 100644 (file)
@@ -169,14 +169,6 @@ void CreateLocalImageRequest<I>::handle_update_client_image(int r) {
   create_local_image();
 }
 
-template <typename I>
-void CreateLocalImageRequest<I>::finish(int r) {
-  dout(10) << "r=" << r << dendl;
-
-  m_on_finish->complete(r);
-  delete this;
-}
-
 template <typename I>
 void CreateLocalImageRequest<I>::update_progress(
     const std::string& description) {
index cd2c3abca10639c29f0fd0aaa588f4b120bc883c..ee96117ea934d8d3bb589717113d8173670e5ed0 100644 (file)
@@ -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 <string>
 
 struct Context;
@@ -22,7 +23,7 @@ namespace image_replayer {
 namespace journal {
 
 template <typename ImageCtxT>
-class CreateLocalImageRequest {
+class CreateLocalImageRequest : public BaseRequest {
 public:
   typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
   typedef librbd::journal::TypeTraits<ImageCtxT> 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);
 
 };
index c3c48b94c824f7fad53a6679e3760418441d5f34..13a4b9a1383aa6c8465b797911dd0b082de0786d 100644 (file)
@@ -290,14 +290,6 @@ void PrepareReplayRequest<I>::handle_get_remote_tags(int r) {
   finish(0);
 }
 
-template <typename I>
-void PrepareReplayRequest<I>::finish(int r) {
-  dout(10) << "r=" << r << dendl;
-
-  m_on_finish->complete(r);
-  delete this;
-}
-
 template <typename I>
 void PrepareReplayRequest<I>::update_progress(const std::string &description) {
   dout(10) << description << dendl;
index 091d7956b316396362ab713c99ec2636dc15ac95..dc38f8b4cb0478f5fd931b5e6e04e786977fb43e 100644 (file)
@@ -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 <list>
 #include <string>
 
@@ -24,7 +25,7 @@ namespace image_replayer {
 namespace journal {
 
 template <typename ImageCtxT>
-class PrepareReplayRequest {
+class PrepareReplayRequest : public BaseRequest {
 public:
   typedef librbd::journal::TypeTraits<ImageCtxT> 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);
 
 };