]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add writesame AioObjectRequest
authorGui Hecheng <guihecheng@cmss.chinamobile.com>
Tue, 21 Feb 2017 02:13:26 +0000 (10:13 +0800)
committerGui Hecheng <guihecheng@cmss.chinamobile.com>
Thu, 23 Feb 2017 09:25:07 +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/ObjectRequest.cc
src/librbd/io/ObjectRequest.h

index 8352b2695aa3512c558eb42b6954767e04c02517..58b3e11f4a619f85303c1b1b20f4f66823d8aff2 100644 (file)
@@ -71,6 +71,19 @@ ObjectRequest<I>::create_zero(I *ictx, const std::string &oid,
                                object_off, object_len, snapc, completion);
 }
 
+template <typename I>
+ObjectRequest<I>*
+ObjectRequest<I>::create_writesame(I *ictx, const std::string &oid,
+                                   uint64_t object_no, uint64_t object_off,
+                                   uint64_t object_len,
+                                   const ceph::bufferlist &data,
+                                   const ::SnapContext &snapc,
+                                   Context *completion, int op_flags) {
+  return new ObjectWriteSameRequest(util::get_image_ctx(ictx), oid, object_no,
+                                    object_off, object_len, data, snapc,
+                                    completion, op_flags);
+}
+
 template <typename I>
 ObjectRequest<I>::ObjectRequest(ImageCtx *ictx, const std::string &oid,
                                 uint64_t objectno, uint64_t off,
@@ -621,6 +634,29 @@ void ObjectTruncateRequest::send_write() {
   }
 }
 
+void ObjectWriteSameRequest::add_write_ops(librados::ObjectWriteOperation *wr) {
+  RWLock::RLocker snap_locker(m_ictx->snap_lock);
+  if (m_ictx->enable_alloc_hint &&
+      (m_ictx->object_map == nullptr || !m_object_exist)) {
+    wr->set_alloc_hint(m_ictx->get_object_size(), m_ictx->get_object_size());
+  }
+
+  wr->writesame(m_object_off, m_object_len, m_write_data);
+  wr->set_op_flags2(m_op_flags);
+}
+
+void ObjectWriteSameRequest::send_write() {
+  bool write_full = (m_object_off == 0 && m_object_len == m_ictx->get_object_size());
+  ldout(m_ictx->cct, 20) << "send_write " << this << " " << m_oid << " "
+                         << m_object_off << "~" << m_object_len
+                         << " write_full " << write_full << dendl;
+  if (write_full && !has_parent()) {
+    m_guard = false;
+  }
+
+  AbstractObjectWriteRequest::send_write();
+}
+
 } // namespace io
 } // namespace librbd
 
index 0467dbb099a35c68fd90ddb4044f4fc08b6820ea..99230f77fba9104b8331569313159e0d50b57d33 100644 (file)
@@ -68,6 +68,14 @@ public:
                                     uint64_t object_len,
                                     const ::SnapContext &snapc,
                                     Context *completion);
+  static ObjectRequest* create_writesame(ImageCtxT *ictx,
+                                         const std::string &oid,
+                                         uint64_t object_no,
+                                         uint64_t object_off,
+                                         uint64_t object_len,
+                                         const ceph::bufferlist &data,
+                                         const ::SnapContext &snapc,
+                                         Context *completion, int op_flags);
 
   ObjectRequest(ImageCtx *ictx, const std::string &oid,
                 uint64_t objectno, uint64_t off, uint64_t len,
@@ -450,6 +458,37 @@ protected:
   }
 };
 
+class ObjectWriteSameRequest : public AbstractObjectWriteRequest {
+public:
+  ObjectWriteSameRequest(ImageCtx *ictx, const std::string &oid, uint64_t object_no,
+                         uint64_t object_off, uint64_t object_len,
+                         const ceph::bufferlist &data,
+                         const ::SnapContext &snapc, Context *completion,
+                         int op_flags)
+    : AbstractObjectWriteRequest(ictx, oid, object_no, object_off,
+                                 object_len, snapc, completion, false),
+      m_write_data(data), m_op_flags(op_flags) {
+  }
+
+  virtual const char *get_op_type() const {
+    return "writesame";
+  }
+
+  virtual bool pre_object_map_update(uint8_t *new_state) {
+    *new_state = OBJECT_EXISTS;
+    return true;
+  }
+
+protected:
+  virtual void add_write_ops(librados::ObjectWriteOperation *wr);
+
+  virtual void send_write();
+
+private:
+  ceph::bufferlist m_write_data;
+  int m_op_flags;
+};
+
 } // namespace io
 } // namespace librbd