rbd: copy-on-read for clones, add an option for copy-on-read
cover rbd: copy-on-read for clones, add an option for copy-on-read
Add an option rbd_clone_cor to enable copy-on-read
Signed-off-by Min Chen <[email protected]>
Signed-off-by Yunchuan Wen <[email protected]>
Signed-off-by Li Wang <[email protected]>
--- src/common/config_opts.h | 1 + src/librbd/AioRequest.cc | 1 + 2 files changed, 2 insertions(+)
src/common/config_opts.h +1 -0
@@ -620,6 +620,7 @@ OPTION(rbd_cache_block_writes_upfront, OPT_BOOL, false) // whether to block writ OPTION(rbd_concurrent_management_ops, OPT_INT, 10) // how many operations can be in flight for a management operation like deleting or resizing an image OPTION(rbd_balance_snap_reads, OPT_BOOL, false) OPTION(rbd_localize_snap_reads, OPT_BOOL, false) +OPTION (rbd_clone_cor,OPT_BOOL , false)//copy-on-read option for rbd clones /* * The following options change the behavior for librbd's image creation methods that
src/librbd/AioRequest.cc +1 -0
@@ -59,6 +59,7 @@ namespace librbd { ldout(m_ictx->cct, 20) << "should_complete " << this << " " << m_oid << " " << m_object_off << "~" << m_object_len << " r = " << r << dendl; + bool COR = m_ictx->cct->_conf->rbd_clone_cor; if (!m_tried_parent && r == -ENOENT) { RWLock::RLocker l(m_ictx->snap_lock); RWLock::RLocker l2(m_ictx->parent_lock);
Signature · 1 line
1.7.10.4
PATCH 1/2 rbd: copy-on-read for clones, read entire object from parent
rbd copy-on-read is implmented in AioRequest. If object extent doesn't exist in clone, then read the entire range of object from parent. Bufferlist m_entire_data is added to AioRequest to save object instead of m_read_data which just keeps data read, and copy read range to m_read_data from m_entire_data
Signed-off-by Min Chen <[email protected]>
Signed-off-by Yunchuan Wen <[email protected]>
Signed-off-by Li Wang <[email protected]>
--- src/librbd/AioRequest.cc | 36 ++++++++++++++++++++++++++++++++++-- src/librbd/AioRequest.h | 2 ++ 2 files changed, 36 insertions(+), 2 deletions(-)
src/librbd/AioRequest.cc +34 -2
@@ -52,6 +52,19 @@ namespace librbd { m_parent_completion); } + //copy-on-read : read the entire object from parent, using bufferlist m_entire_object + void AioRequest::read_from_parent_COR(vector<pair<uint64_t,uint64_t> >& image_extents) + { + assert(!m_parent_completion); + m_parent_completion = aio_create_completion_internal(this, rbd_req_cb); + ldout(m_ictx->cct, 20) << "read_from_parent_COR this = " << this + << " parent completion " << m_parent_completion + << " extents " << image_extents + << dendl; + aio_read(m_ictx->parent, image_extents, NULL, &m_entire_object, + m_parent_completion); + } + /** read **/ bool AioRead::should_complete(int r)
@@ -78,11 +91,30 @@ namespace librbd { uint64_t object_overlap = m_ictx->prune_parent_extents(image_extents, image_overlap); if (object_overlap) { m_tried_parent = true; - read_from_parent(image_extents); + if(COR)//copy-on-read option + { + vector<pair<uint64_t,uint64_t> > extend_image_extents; + //extend range to entire object + Striper::extent_to_file(m_ictx->cct, &m_ictx->layout, + m_object_no, 0, m_ictx->layout.fl_object_size, + extend_image_extents); + //read entire object from parent , and put it in m_entire_object + read_from_parent_COR(extend_image_extents); + } + else + read_from_parent(image_extents); return false; } } - + if(COR) //copy-on-read option + { + //if read entire object from parent success + if(m_tried_parent && r>0) + { + // copy the read range to m_read_data + m_read_data.substr_of(m_entire_object, m_object_off, m_object_len); + } + } return true; }
src/librbd/AioRequest.h +2 -0
@@ -47,6 +47,7 @@ namespace librbd { protected: void read_from_parent(vector<pair<uint64_t,uint64_t> >& image_extents); + void read_from_parent_COR(vector<pair<uint64_t,uint64_t> >& image_extents);ImageCtx *m_ictx; librados::IoCtx *m_ioctx;
@@ -57,6 +58,7 @@ namespace librbd {AioCompletion *m_parent_completion; ceph::bufferlist m_read_data;bool m_hide_enoent; + ceph::bufferlist m_entire_object; }; class AioRead : public AioRequest {
Signature · 1 line
1.7.10.4
PATCH 2/2 rbd: copy-on-read for clones, write entire object into child by cls_rbd copyup
In reply to Min ChenThe object has been already saved in m_entire_object bufferlist
Send "copyup" to osd with m_entire_object, then cls_rbd copyup will write the object to child.
Signed-off-by Min Chen <[email protected]>
Signed-off-by Yunchuan Wen <[email protected]>
Signed-off-by Li Wang <[email protected]>
--- src/librbd/AioRequest.cc | 36 ++++++++++++++++++++++++++++++++++++ src/librbd/AioRequest.h | 1 + 2 files changed, 37 insertions(+)
src/librbd/AioRequest.cc +36 -0
@@ -66,6 +66,41 @@ namespace librbd { } /** read **/ + //copy-on-read: after read entire object, just write it into child + ssize_t AioRead::write_COR() + { + ldout(m_ictx->cct, 20) << "write_COR" << dendl; + int ret = 0; + + m_ictx->snap_lock.get_read(); + ::SnapContext snapc = m_ictx->snapc; + m_ictx->snap_lock.put_read(); + + librados::ObjectWriteOperation copyup_cor; + copyup_cor.exec("rbd","copyup",m_entire_object); + + std::vector<librados::snap_t> m_snaps; + for (std::vector<snapid_t>::const_iterator it = snapc.snaps.begin(); + it != snapc.snaps.end(); ++it) { + m_snaps.push_back(it->val); + } + + librados::AioCompletion *rados_completion = + librados::Rados::aio_create_completion(NULL, NULL, NULL); + m_ictx->md_ctx.aio_operate(m_oid, rados_completion, ©up_cor, + snapc.seq.val, m_snaps); + rados_completion->wait_for_complete(); + ret = rados_completion->get_return_value(); + ldout(m_ictx->cct, 20) << "ret = " << ret <<dendl; + rados_completion->release(); + + if (ret < 0) { + ldout(m_ictx->cct, 20) << "couldn't write object! error " << ret << dendl; + ret = -EIO; + } + return ret; + } + bool AioRead::should_complete(int r) {
@@ -113,6 +148,7 @@ namespace librbd { { // copy the read range to m_read_data m_read_data.substr_of(m_entire_object, m_object_off, m_object_len); + write_COR(); } } return true;
src/librbd/AioRequest.h +1 -0
@@ -74,6 +74,7 @@ namespace librbd { m_tried_parent(false), m_sparse(sparse) { } virtual ~AioRead() {} +ssize_t write_COR (); virtual bool should_complete(int r); virtual int send();
Signature · 1 line
1.7.10.4