From b96529ef330fb8595966d4d9c10eb814c4850076 Mon Sep 17 00:00:00 2001 From: Gui Hecheng Date: Tue, 21 Feb 2017 10:13:26 +0800 Subject: [PATCH] librbd: add writesame AioObjectRequest Based on pr: https://github.com/ceph/ceph/pull/10019. Signed-off-by: Gui Hecheng Signed-off-by: Mingxin Liu --- src/librbd/io/ObjectRequest.cc | 36 +++++++++++++++++++++++++++++++ src/librbd/io/ObjectRequest.h | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/librbd/io/ObjectRequest.cc b/src/librbd/io/ObjectRequest.cc index 8352b2695aa35..58b3e11f4a619 100644 --- a/src/librbd/io/ObjectRequest.cc +++ b/src/librbd/io/ObjectRequest.cc @@ -71,6 +71,19 @@ ObjectRequest::create_zero(I *ictx, const std::string &oid, object_off, object_len, snapc, completion); } +template +ObjectRequest* +ObjectRequest::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 ObjectRequest::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 diff --git a/src/librbd/io/ObjectRequest.h b/src/librbd/io/ObjectRequest.h index 0467dbb099a35..99230f77fba91 100644 --- a/src/librbd/io/ObjectRequest.h +++ b/src/librbd/io/ObjectRequest.h @@ -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 -- 2.39.5