]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: simplify AioCompletion reference counting for 'fail' case
authorJason Dillaman <dillaman@redhat.com>
Sat, 27 Apr 2019 11:54:36 +0000 (07:54 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 2 May 2019 13:30:45 +0000 (09:30 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/io/AioCompletion.cc
src/librbd/io/ImageDispatchSpec.cc
src/librbd/io/ImageDispatchSpec.h
src/librbd/io/ImageRequest.cc
src/librbd/io/ImageRequestWQ.cc
src/librbd/librbd.cc
src/test/librbd/io/test_mock_ImageRequestWQ.cc
src/test/librbd/operation/test_mock_ResizeRequest.cc

index e151d622433dc5fd809ebfd7649733033dcf0b99..b282397f01d19d7920b2dec009c5e98a6d25ee07 100644 (file)
@@ -147,6 +147,8 @@ void AioCompletion::fail(int r)
 
   lderr(cct) << cpp_strerror(r) << dendl;
   ceph_assert(pending_count == 0);
+
+  get();
   rval = r;
   complete();
   put();
index 2c405d74dc1eb7724c641e1bd555d53d894905e4..f33b8ef6aedd4a26e0385d1362525dbcb04fa8b1 100644 (file)
@@ -117,7 +117,6 @@ void ImageDispatchSpec<I>::send() {
 
 template <typename I>
 void ImageDispatchSpec<I>::fail(int r) {
-  m_aio_comp->get();
   m_aio_comp->fail(r);
 }
 
index 93c53a0fe8b2cd6e55c59385a544715630cfefca..60f1ea5bb804d6a890259361295678aea7e612c3 100644 (file)
@@ -7,6 +7,7 @@
 #include "include/int_types.h"
 #include "include/buffer.h"
 #include "common/zipkin_trace.h"
+#include "librbd/io/AioCompletion.h"
 #include "librbd/io/Types.h"
 #include "librbd/io/ReadResult.h"
 #include <boost/variant/variant.hpp>
@@ -17,8 +18,6 @@ class ImageCtx;
 
 namespace io {
 
-class AioCompletion;
-
 template <typename ImageCtxT = ImageCtx>
 class ImageDispatchSpec {
 public:
@@ -122,6 +121,10 @@ public:
                                  0, parent_trace);
   }
 
+  ~ImageDispatchSpec() {
+    m_aio_comp->put();
+  }
+
   void send();
   void fail(int r);
 
@@ -161,6 +164,7 @@ private:
     : m_image_ctx(image_ctx), m_aio_comp(aio_comp),
       m_image_extents(std::move(image_extents)), m_request(std::move(request)),
       m_op_flags(op_flags), m_parent_trace(parent_trace) {
+    m_aio_comp->get();
   }
 
   ImageCtxT& m_image_ctx;
index 78ce3bb7e4ed1ecc61a95b809bba3ce0c30ad040..50723eef18c1b56534185cc580bf4251557964d5 100644 (file)
@@ -230,7 +230,6 @@ void ImageRequest<I>::send() {
   ldout(cct, 20) << get_request_type() << ": ictx=" << &image_ctx << ", "
                  << "completion=" << aio_comp << dendl;
 
-  aio_comp->get();
   int r = clip_request();
   if (r < 0) {
     m_aio_comp->fail(r);
@@ -398,8 +397,6 @@ void ImageReadRequest<I>::send_request() {
     }
   }
 
-  aio_comp->put();
-
   image_ctx.perfcounter->inc(l_librbd_rd);
   image_ctx.perfcounter->inc(l_librbd_rd_bytes, buffer_ofs);
 }
@@ -477,7 +474,6 @@ void AbstractImageWriteRequest<I>::send_request() {
   }
 
   update_stats(clip_len);
-  aio_comp->put();
 }
 
 template <typename I>
@@ -709,7 +705,6 @@ void ImageFlushRequest<I>::send_request() {
 
   // ensure all in-flight IOs are settled if non-user flush request
   aio_comp->async_op.flush(ctx);
-  aio_comp->put();
 
   // might be flushing during image shutdown
   if (image_ctx.perfcounter != nullptr) {
index a61f9a26c4b08afbd83ccad54ff256c519534e55..fb15ca339ea64b69eb4263e4eece805be870c959 100644 (file)
@@ -839,7 +839,6 @@ int ImageRequestWQ<I>::start_in_flight_io(AioCompletion *c) {
     CephContext *cct = m_image_ctx.cct;
     lderr(cct) << "IO received on closed image" << dendl;
 
-    c->get();
     c->fail(-ESHUTDOWN);
     return false;
   }
index f6d8ca2c22d9850b70c331e4c31ac12974e60271..d77d4287be0252249b3824e832af64547be597ad 100644 (file)
@@ -95,6 +95,9 @@ struct C_AioCompletion : public Context {
     aio_comp->init_time(ictx, aio_type);
     aio_comp->get();
   }
+  virtual ~C_AioCompletion() {
+    aio_comp->put();
+  }
 
   void finish(int r) override {
     ldout(cct, 20) << "C_AioComplete::finish: r=" << r << dendl;
@@ -102,7 +105,6 @@ struct C_AioCompletion : public Context {
       aio_comp->fail(r);
     } else {
       aio_comp->complete();
-      aio_comp->put();
     }
   }
 };
index 50daa83c777bc506e9a58127d39a69939d0f9863..19b3e9465a65970644d48d9203430fec88a505c5 100644 (file)
@@ -217,7 +217,6 @@ struct TestMockIoImageRequestWQ : public TestMockFixture {
   void expect_fail(MockImageDispatchSpec &mock_image_request, int r) {
     EXPECT_CALL(mock_image_request, fail(r))
       .WillOnce(Invoke([&mock_image_request](int r) {
-                    mock_image_request.aio_comp->get();
                     mock_image_request.aio_comp->fail(r);
                   }));
   }
index 931d5f4620e4d63e792a6d0055ba6a0c4d6a4f7f..4b08fc6dc5b5bf0b925ccdd74a0aebd9e9ab42e0 100644 (file)
@@ -158,7 +158,6 @@ public:
       .WillOnce(Invoke([&mock_image_ctx, &mock_io_image_dispatch_spec, r]() {
                   auto aio_comp = mock_io_image_dispatch_spec.s_instance->aio_comp;
                   auto ctx = new FunctionContext([aio_comp](int r) {
-                    aio_comp->get();
                     aio_comp->fail(r);
                   });
                   mock_image_ctx.image_ctx->op_work_queue->queue(ctx, r);