]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: sync flush should re-use existing async flush logic
authorJason Dillaman <dillaman@redhat.com>
Thu, 19 Oct 2017 14:35:31 +0000 (10:35 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 23 Oct 2017 00:38:39 +0000 (20:38 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/ImageCtx.cc
src/librbd/LibrbdAdminSocketHook.cc
src/librbd/internal.cc
src/librbd/internal.h
src/librbd/io/AioCompletion.cc
src/librbd/io/ImageRequest.cc
src/librbd/io/ImageRequestWQ.cc
src/librbd/io/ImageRequestWQ.h
src/librbd/librbd.cc
src/test/librbd/test_internal.cc

index 3918a768181904417293e75228114bcaba08510d..4fbae675cc0df43d4cf1c0581bc4e3ec740eaf8b 100644 (file)
@@ -374,8 +374,7 @@ struct C_InvalidateCache : public Context {
     plb.add_u64_counter(l_librbd_discard_bytes, "discard_bytes", "Discarded data");
     plb.add_time_avg(l_librbd_discard_latency, "discard_latency", "Discard latency");
     plb.add_u64_counter(l_librbd_flush, "flush", "Flushes");
-    plb.add_u64_counter(l_librbd_aio_flush, "aio_flush", "Async flushes");
-    plb.add_time_avg(l_librbd_aio_flush_latency, "aio_flush_latency", "Latency of async flushes");
+    plb.add_time_avg(l_librbd_flush_latency, "flush_latency", "Latency of flushes");
     plb.add_u64_counter(l_librbd_ws, "ws", "WriteSames");
     plb.add_u64_counter(l_librbd_ws_bytes, "ws_bytes", "WriteSame data");
     plb.add_time_avg(l_librbd_ws_latency, "ws_latency", "WriteSame latency");
index bda734ca948ea5a9ae8c1018bc039bbc685b86a7..02c4fb58f296b1af55be90fc399a68959307797c 100644 (file)
@@ -6,6 +6,7 @@
 #include "librbd/ImageCtx.h"
 #include "librbd/LibrbdAdminSocketHook.h"
 #include "librbd/internal.h"
+#include "librbd/io/ImageRequestWQ.h"
 
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
@@ -24,7 +25,7 @@ public:
   explicit FlushCacheCommand(ImageCtx *ictx) : ictx(ictx) {}
 
   bool call(stringstream *ss) override {
-    int r = flush(ictx);
+    int r = ictx->io_work_queue->flush();
     if (r < 0) {
       *ss << "flush: " << cpp_strerror(r);
       return false;
index 9b322997014dc7a06943416853be5cdc432389f9..6903fe8d83655df80cca808ba0538480064c0fc4 100644 (file)
@@ -2221,28 +2221,6 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
     return 0;
   }
 
-  int flush(ImageCtx *ictx)
-  {
-    CephContext *cct = ictx->cct;
-    ldout(cct, 20) << "flush " << ictx << dendl;
-
-    int r = ictx->state->refresh_if_required();
-    if (r < 0) {
-      return r;
-    }
-
-    ictx->user_flushed();
-    C_SaferCond ctx;
-    {
-      RWLock::RLocker owner_locker(ictx->owner_lock);
-      ictx->flush(&ctx);
-    }
-    r = ctx.wait();
-
-    ictx->perfcounter->inc(l_librbd_flush);
-    return r;
-  }
-
   int invalidate_cache(ImageCtx *ictx)
   {
     CephContext *cct = ictx->cct;
index 72633f592ca3b9c08ae8f611c3b132f4b31b9dfc..daedaa42e2fa9ab1cd97b2d6caeed9f5346c2e02 100644 (file)
@@ -30,9 +30,7 @@ enum {
   l_librbd_discard_bytes,
   l_librbd_discard_latency,
   l_librbd_flush,
-
-  l_librbd_aio_flush,
-  l_librbd_aio_flush_latency,
+  l_librbd_flush_latency,
   l_librbd_ws,
   l_librbd_ws_bytes,
   l_librbd_ws_latency,
@@ -205,7 +203,6 @@ namespace librbd {
   void readahead(ImageCtx *ictx,
                  const vector<pair<uint64_t,uint64_t> >& image_extents);
 
-  int flush(ImageCtx *ictx);
   int invalidate_cache(ImageCtx *ictx);
   int poll_io_events(ImageCtx *ictx, io::AioCompletion **comps, int numcomp);
   int metadata_list(ImageCtx *ictx, const string &last, uint64_t max, map<string, bufferlist> *pairs);
index 8fa067e1b63a5d2f702378af5786b8944049cdf3..e668ecd9cc709382eb7f7c818457cddd7cbbcc56 100644 (file)
@@ -71,7 +71,7 @@ void AioCompletion::complete() {
   case AIO_TYPE_DISCARD:
     ictx->perfcounter->tinc(l_librbd_discard_latency, elapsed); break;
   case AIO_TYPE_FLUSH:
-    ictx->perfcounter->tinc(l_librbd_aio_flush_latency, elapsed); break;
+    ictx->perfcounter->tinc(l_librbd_flush_latency, elapsed); break;
   case AIO_TYPE_WRITESAME:
     ictx->perfcounter->tinc(l_librbd_ws_latency, elapsed); break;
   case AIO_TYPE_COMPARE_AND_WRITE:
index cd87d92e07479f34f54e92bf2a41be3e2ba30aa7..e1d1692da1678cb5dc09eac5386945f4b6804f4e 100644 (file)
@@ -750,7 +750,7 @@ void ImageFlushRequest<I>::send_request() {
     aio_comp->put();
   }
 
-  image_ctx.perfcounter->inc(l_librbd_aio_flush);
+  image_ctx.perfcounter->inc(l_librbd_flush);
 }
 
 template <typename I>
index 81800cc4ae73cf904fb245ce98c91b83a1f210e9..7f479f45e96cb7a589eb79d1eb87201d7f6a0d26 100644 (file)
@@ -194,6 +194,23 @@ ssize_t ImageRequestWQ<I>::compare_and_write(uint64_t off, uint64_t len,
   return len;
 }
 
+template <typename I>
+int ImageRequestWQ<I>::flush() {
+  CephContext *cct = m_image_ctx.cct;
+  ldout(cct, 20) << "ictx=" << &m_image_ctx << dendl;
+
+  C_SaferCond cond;
+  AioCompletion *c = AioCompletion::create(&cond);
+  aio_flush(c, false);
+
+  int r = cond.wait();
+  if (r < 0) {
+    return r;
+  }
+
+  return 0;
+}
+
 template <typename I>
 void ImageRequestWQ<I>::aio_read(AioCompletion *c, uint64_t off, uint64_t len,
                                 ReadResult &&read_result, int op_flags,
index ad51b0f2c9f64628cdfac9ab753004a1f82f0088..5c5fc911c0f74197f8ed1c0cca138a15dc14b2fa 100644 (file)
@@ -37,6 +37,7 @@ public:
   ssize_t compare_and_write(uint64_t off, uint64_t len,
                             bufferlist &&cmp_bl, bufferlist &&bl,
                             uint64_t *mismatch_off, int op_flags);
+  int flush();
 
   void aio_read(AioCompletion *c, uint64_t off, uint64_t len,
                 ReadResult &&read_result, int op_flags, bool native_async=true);
index 999ac25233aa01fd001656ce3bea39d1569827e7..e65330c2580defce42d9f19129762c1b24eb1fbf 100644 (file)
@@ -1729,7 +1729,7 @@ namespace librbd {
   {
     ImageCtx *ictx = (ImageCtx *)ctx;
     tracepoint(librbd, flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only);
-    int r = librbd::flush(ictx);
+    int r = ictx->io_work_queue->flush();
     tracepoint(librbd, flush_exit, r);
     return r;
   }
@@ -3771,7 +3771,7 @@ extern "C" int rbd_flush(rbd_image_t image)
 {
   librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
   tracepoint(librbd, flush_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only);
-  int r = librbd::flush(ictx);
+  int r = ictx->io_work_queue->flush();
   tracepoint(librbd, flush_exit, r);
   return r;
 }
index f3c5d28b0d2138504aa568fda055293433ae4c56..d9cc73458cfe7115b4b809edaf22ced29a12a5ac 100644 (file)
@@ -905,7 +905,7 @@ TEST_F(TestInternal, WriteFullCopyup) {
   bl.append(std::string(1 << ictx->order, '1'));
   ASSERT_EQ((ssize_t)bl.length(),
             ictx->io_work_queue->write(0, bl.length(), bufferlist{bl}, 0));
-  ASSERT_EQ(0, librbd::flush(ictx));
+  ASSERT_EQ(0, ictx->io_work_queue->flush());
 
   ASSERT_EQ(0, create_snapshot("snap1", true));