[PATCH 2/2] rbd: copy-on-read for clones, write entire object into child by cls_rbd copyup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 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 <minchen@xxxxxxxxxxxxxxx>
Signed-off-by: Yunchuan Wen <yunchuanwen@xxxxxxxxxxxxxxx>
Signed-off-by: Li Wang <liwang@xxxxxxxxxxxxxxx>
---
 src/librbd/AioRequest.cc |   36 ++++++++++++++++++++++++++++++++++++
 src/librbd/AioRequest.h  |    1 +
 2 files changed, 37 insertions(+)

diff --git a/src/librbd/AioRequest.cc b/src/librbd/AioRequest.cc
index 268999c..525d376 100644
--- a/src/librbd/AioRequest.cc
+++ b/src/librbd/AioRequest.cc
@@ -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, &copyup_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;
diff --git a/src/librbd/AioRequest.h b/src/librbd/AioRequest.h
index 4081c4c..ed307d4 100644
--- a/src/librbd/AioRequest.h
+++ b/src/librbd/AioRequest.h
@@ -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();
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux