]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: new intermediate request class for handling journal ops
authorJason Dillaman <dillaman@redhat.com>
Wed, 26 Aug 2015 19:07:33 +0000 (15:07 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 17 Nov 2015 20:14:13 +0000 (15:14 -0500)
All operations that should be recorded to the journal will inherit
from the new librbd::operation::Request class.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/AsyncRequest.h
src/librbd/Makefile.am
src/librbd/ObjectMap.h
src/librbd/operation/FlattenRequest.cc
src/librbd/operation/FlattenRequest.h
src/librbd/operation/Request.cc [new file with mode: 0644]
src/librbd/operation/Request.h [new file with mode: 0644]
src/librbd/operation/ResizeRequest.cc
src/librbd/operation/ResizeRequest.h
src/librbd/operation/TrimRequest.cc
src/librbd/operation/TrimRequest.h

index 5ecaf8202fecd0b1018551d85157ef902eea9839..ca306d531c9e2f7414307841619b5f5b2457bf52 100644 (file)
@@ -22,7 +22,9 @@ public:
 
   void complete(int r) {
     if (should_complete(r)) {
-      m_on_finish->complete(filter_return_code(r));
+      r = filter_return_code(r);
+      finish(r);
+      m_on_finish->complete(r);
       delete this;
     }
   }
@@ -47,9 +49,12 @@ protected:
   void async_complete(int r);
 
   virtual bool should_complete(int r) = 0;
-  virtual int filter_return_code(int r) {
+  virtual int filter_return_code(int r) const {
     return r;
   }
+
+  virtual void finish(int r) {
+  }
 private:
   bool m_canceled;
   typename xlist<AsyncRequest<ImageCtxT> *>::item m_xlist_item;
index c8d840e906067ec9048a66a65662351144a44cad..90776dac70be68691697ea37e496ac90a1e1751d 100644 (file)
@@ -27,6 +27,7 @@ librbd_internal_la_SOURCES = \
        librbd/ObjectMap.cc \
        librbd/operation/FlattenRequest.cc \
        librbd/operation/RebuildObjectMapRequest.cc \
+       librbd/operation/Request.cc \
        librbd/operation/ResizeRequest.cc \
        librbd/operation/TrimRequest.cc
 noinst_LTLIBRARIES += librbd_internal.la
@@ -78,6 +79,7 @@ noinst_HEADERS += \
        librbd/WatchNotifyTypes.h \
        librbd/operation/FlattenRequest.h \
        librbd/operation/RebuildObjectMapRequest.h \
+       librbd/operation/Request.h \
        librbd/operation/ResizeRequest.h \
        librbd/operation/TrimRequest.h
 
index c85703a286feb0a724ca4dd4b2195db6df44fcd8..f0d1bbe9434b1e058e0656a94accebbb0249783f 100644 (file)
@@ -73,7 +73,7 @@ private:
     const uint64_t m_snap_id;
 
     virtual bool should_complete(int r);
-    virtual int filter_return_code(int r) {
+    virtual int filter_return_code(int r) const {
       // never propagate an error back to the caller
       return 0;
     }
index e3d91812a1318812ee47a63a6252db66d34c5571..2a08e4562dc2717a3346fad0d932f13aff538751 100644 (file)
@@ -89,7 +89,7 @@ bool FlattenRequest::should_complete(int r) {
   return false;
 }
 
-void FlattenRequest::send() {
+void FlattenRequest::send_op() {
   assert(m_image_ctx.owner_lock.is_locked());
   CephContext *cct = m_image_ctx.cct;
   ldout(cct, 5) << this << " send" << dendl;
index 8474f9c3dfcb78a5f22ee73845a3b5e6ed1c8152..f8ef2670e61510849da333549fa7953def102405 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef CEPH_LIBRBD_OPERATION_FLATTEN_REQUEST_H
 #define CEPH_LIBRBD_OPERATION_FLATTEN_REQUEST_H
 
-#include "librbd/AsyncRequest.h"
+#include "librbd/operation/Request.h"
 #include "librbd/parent_types.h"
 #include "common/snap_types.h"
 
@@ -14,21 +14,20 @@ class ProgressContext;
 
 namespace operation {
 
-class FlattenRequest : public AsyncRequest<>
+class FlattenRequest : public Request
 {
 public:
   FlattenRequest(ImageCtx &image_ctx, Context *on_finish,
                      uint64_t object_size, uint64_t overlap_objects,
                      const ::SnapContext &snapc, ProgressContext &prog_ctx)
-    : AsyncRequest(image_ctx, on_finish), m_object_size(object_size),
+    : Request(image_ctx, on_finish), m_object_size(object_size),
       m_overlap_objects(overlap_objects), m_snapc(snapc), m_prog_ctx(prog_ctx),
       m_ignore_enoent(false)
   {
   }
 
-  virtual void send();
-
 protected:
+  virtual void send_op();
   virtual bool should_complete(int r);
 
 private:
diff --git a/src/librbd/operation/Request.cc b/src/librbd/operation/Request.cc
new file mode 100644 (file)
index 0000000..82017de
--- /dev/null
@@ -0,0 +1,23 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "librbd/operation/Request.h"
+
+namespace librbd {
+namespace operation {
+
+Request::Request(ImageCtx &image_ctx, Context *on_finish)
+  : AsyncRequest(image_ctx, on_finish) {
+}
+
+void Request::send() {
+  // TODO: record op start in journal
+  send_op();
+}
+
+void Request::finish(int r) {
+  // TODO: record op finish in journal
+}
+
+} // namespace operation
+} // namespace librbd
diff --git a/src/librbd/operation/Request.h b/src/librbd/operation/Request.h
new file mode 100644 (file)
index 0000000..b4a805d
--- /dev/null
@@ -0,0 +1,27 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_OPERATION_REQUEST_H
+#define CEPH_LIBRBD_OPERATION_REQUEST_H
+
+#include "librbd/AsyncRequest.h"
+
+namespace librbd {
+namespace operation {
+
+class Request : public AsyncRequest<> {
+public:
+  Request(ImageCtx &image_ctx, Context *on_finish);
+
+  virtual void send();
+
+protected:
+  virtual void finish(int r);
+  virtual void send_op() = 0;
+
+};
+
+} // namespace operation
+} // namespace librbd
+
+#endif // CEPH_LIBRBD_OPERATION_REQUEST_H
index 03247431f43161b1e5ffa9330b8bc78a32ed8fbf..afe925bac8c9538b88b8bfb3f542d098b1dafee7 100644 (file)
@@ -20,7 +20,7 @@ namespace operation {
 ResizeRequest::ResizeRequest(ImageCtx &image_ctx, Context *on_finish,
                                        uint64_t new_size,
                                        ProgressContext &prog_ctx)
-  : AsyncRequest(image_ctx, on_finish),
+  : Request(image_ctx, on_finish),
     m_original_size(0), m_new_size(new_size),
     m_prog_ctx(prog_ctx), m_new_parent_overlap(0),
     m_xlist_item(this)
@@ -99,7 +99,7 @@ bool ResizeRequest::should_complete(int r) {
   return false;
 }
 
-void ResizeRequest::send() {
+void ResizeRequest::send_op() {
   assert(m_image_ctx.owner_lock.is_locked());
 
   {
index f7b941005fbda1dae5998f17c07109df401ede09..dcef8fa22ac91bd4eb4897ac3f1d79d7cd18b35d 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef CEPH_LIBRBD_OPERATION_RESIZE_REQUEST_H
 #define CEPH_LIBRBD_OPERATION_RESIZE_REQUEST_H
 
-#include "librbd/AsyncRequest.h"
+#include "librbd/operation/Request.h"
 #include "include/xlist.h"
 
 namespace librbd
@@ -14,15 +14,13 @@ class ProgressContext;
 
 namespace operation {
 
-class ResizeRequest : public AsyncRequest<>
+class ResizeRequest : public Request
 {
 public:
   ResizeRequest(ImageCtx &image_ctx, Context *on_finish, uint64_t new_size,
                      ProgressContext &prog_ctx);
   virtual ~ResizeRequest();
 
-  virtual void send();
-
   inline bool shrinking() const {
     return m_new_size < m_original_size;
   }
@@ -31,6 +29,10 @@ public:
     return m_new_size;
   }
 
+protected:
+  virtual void send_op();
+  virtual bool should_complete(int r);
+
 private:
   /**
    * Resize goes through the following state machine to resize the image
@@ -84,8 +86,6 @@ private:
 
   xlist<ResizeRequest *>::item m_xlist_item;
 
-  virtual bool should_complete(int r);
-
   void send_flush();
   void send_invalidate_cache();
   void send_trim_image();
index 8d9546d15f72df23e8264618a2fe7398066f5433..d29f2018b7f525239262785c4c4643234a1bdaf8 100644 (file)
@@ -138,7 +138,7 @@ bool TrimRequest::should_complete(int r)
 
   case STATE_CLEAN_BOUNDARY:
     ldout(cct, 5) << "CLEAN_BOUNDARY" << dendl;
-    finish(0);
+    send_finish(0);
     break;
 
   case STATE_FINISHED:
@@ -304,7 +304,7 @@ void TrimRequest::send_clean_boundary() {
   assert(m_image_ctx.owner_lock.is_locked());
   CephContext *cct = m_image_ctx.cct;
   if (m_delete_off <= m_new_size) {
-    finish(0);
+    send_finish(0);
     return;
   }
 
@@ -349,7 +349,7 @@ void TrimRequest::send_clean_boundary() {
   completion->finish_adding_requests();
 }
 
-void TrimRequest::finish(int r) {
+void TrimRequest::send_finish(int r) {
   m_state = STATE_FINISHED;
   async_complete(r);
 }
index d781c0c97b142eb6edce59b87efc693d042d9ed6..d8b9358297ac4d43c3b2680681f2e4ce93908a27 100644 (file)
@@ -84,7 +84,7 @@ private:
   void send_pre_remove();
   void send_post_remove();
   void send_clean_boundary();
-  void finish(int r);
+  void send_finish(int r);
 };
 
 } // namespace operation