]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: handle writesame request in AioImageRequestWQ
authorGui Hecheng <guihecheng@cmss.chinamobile.com>
Tue, 21 Feb 2017 05:22:16 +0000 (13:22 +0800)
committerGui Hecheng <guihecheng@cmss.chinamobile.com>
Thu, 23 Feb 2017 09:25:17 +0000 (17:25 +0800)
Based on pr: https://github.com/ceph/ceph/pull/10019.

Signed-off-by: Gui Hecheng <guihecheng@cmss.chinamobile.com>
Signed-off-by: Mingxin Liu <mingxin@xsky.com>
src/librbd/io/ImageRequestWQ.cc
src/librbd/io/ImageRequestWQ.h
src/librbd/io/Types.h

index 9999503d3e53770bbd301f2e1e8616a5fa14ff72..1ce121df70c101f751e2dae7a4cc4f623c493f1a 100644 (file)
@@ -93,6 +93,31 @@ int ImageRequestWQ::discard(uint64_t off, uint64_t len) {
   return len;
 }
 
+ssize_t ImageRequestWQ::writesame(uint64_t off, uint64_t len, bufferlist &&bl,
+                                  int op_flags) {
+  CephContext *cct = m_image_ctx.cct;
+  ldout(cct, 20) << "writesame ictx=" << &m_image_ctx << ", off=" << off << ", "
+                 << "len = " << len << ", data_len " << bl.length() << dendl;
+
+  m_image_ctx.snap_lock.get_read();
+  int r = clip_io(util::get_image_ctx(&m_image_ctx), off, &len);
+  m_image_ctx.snap_lock.put_read();
+  if (r < 0) {
+    lderr(cct) << "invalid IO request: " << cpp_strerror(r) << dendl;
+    return r;
+  }
+
+  C_SaferCond cond;
+  AioCompletion *c = AioCompletion::create(&cond);
+  aio_writesame(c, off, len, std::move(bl), op_flags, false);
+
+  r = cond.wait();
+  if (r < 0) {
+    return r;
+  }
+  return len;
+}
+
 void ImageRequestWQ::aio_read(AioCompletion *c, uint64_t off, uint64_t len,
                               ReadResult &&read_result, int op_flags,
                               bool native_async) {
@@ -210,6 +235,36 @@ void ImageRequestWQ::aio_flush(AioCompletion *c, bool native_async) {
   }
 }
 
+void ImageRequestWQ::aio_writesame(AioCompletion *c, uint64_t off, uint64_t len,
+                                   bufferlist &&bl, int op_flags,
+                                   bool native_async) {
+  c->init_time(&m_image_ctx, AIO_TYPE_WRITESAME);
+  CephContext *cct = m_image_ctx.cct;
+  ldout(cct, 20) << "aio_writesame: ictx=" << &m_image_ctx << ", "
+                 << "completion=" << c << ", off=" << off << ", "
+                 << "len=" << len << ", data_len = " << bl.length() << ", "
+                 << "flags=" << op_flags << dendl;
+
+  if (native_async && m_image_ctx.event_socket.is_valid()) {
+    c->set_event_notify(true);
+  }
+
+  if (!start_in_flight_op(c)) {
+    return;
+  }
+
+  RWLock::RLocker owner_locker(m_image_ctx.owner_lock);
+  if (m_image_ctx.non_blocking_aio || writes_blocked()) {
+    queue(new ImageWriteSameRequest<>(m_image_ctx, c, off, len, std::move(bl),
+                                      op_flags));
+  } else {
+    c->start_op();
+    ImageRequest<>::aio_writesame(&m_image_ctx, c, off, len, std::move(bl),
+                                  op_flags);
+    finish_in_flight_op();
+  }
+}
+
 void ImageRequestWQ::shut_down(Context *on_shutdown) {
   assert(m_image_ctx.owner_lock.is_locked());
 
index 8bf10be4825d1566e7e050becc583aaf4d2ea55a..103a4f8c19db58cf0e97f95dfb35cee337bc1c67 100644 (file)
@@ -29,6 +29,7 @@ public:
                int op_flags);
   ssize_t write(uint64_t off, uint64_t len, bufferlist &&bl, int op_flags);
   int discard(uint64_t off, uint64_t len);
+  ssize_t writesame(uint64_t off, uint64_t len, bufferlist &&bl, int op_flags);
 
   void aio_read(AioCompletion *c, uint64_t off, uint64_t len,
                 ReadResult &&read_result, int op_flags, bool native_async=true);
@@ -37,8 +38,11 @@ public:
   void aio_discard(AioCompletion *c, uint64_t off, uint64_t len,
                    bool native_async=true);
   void aio_flush(AioCompletion *c, bool native_async=true);
+  void aio_writesame(AioCompletion *c, uint64_t off, uint64_t len,
+                     bufferlist &&bl, int op_flags, bool native_async=true);
 
   using ThreadPool::PointerWQ<ImageRequest<ImageCtx> >::drain;
+
   using ThreadPool::PointerWQ<ImageRequest<ImageCtx> >::empty;
 
   void shut_down(Context *on_shutdown);
index f80df9f3eff8cde206a053d831bf6f732a348e4f..1c3f967c0c72315ff53cc95c5f005b04b4f24ba6 100644 (file)
@@ -19,6 +19,7 @@ typedef enum {
   AIO_TYPE_WRITE,
   AIO_TYPE_DISCARD,
   AIO_TYPE_FLUSH,
+  AIO_TYPE_WRITESAME,
 } aio_type_t;
 
 typedef std::vector<std::pair<uint64_t, uint64_t> > Extents;