]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/librbd: handle writesame op in librados_test_stub, required
authorGui Hecheng <guihecheng@cmss.chinamobile.com>
Wed, 4 Jan 2017 07:49:47 +0000 (15:49 +0800)
committerGui Hecheng <guihecheng@cmss.chinamobile.com>
Thu, 23 Feb 2017 09:25:27 +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/test/librados_test_stub/LibradosTestStub.cc
src/test/librados_test_stub/TestIoCtxImpl.h
src/test/librados_test_stub/TestMemIoCtxImpl.cc
src/test/librados_test_stub/TestMemIoCtxImpl.h

index 5b59ef17df2a7c5863138712b7b0f66c18c01a8c..16c0f4da3682fcf2209bd7e5b1cd103a520c8995 100644 (file)
@@ -668,6 +668,14 @@ int IoCtx::write_full(const std::string& oid, bufferlist& bl) {
                      ctx->get_snap_context()));
 }
 
+int IoCtx::writesame(const std::string& oid, bufferlist& bl, size_t len,
+                     uint64_t off) {
+  TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl);
+  return ctx->execute_operation(
+    oid, boost::bind(&TestIoCtxImpl::writesame, _1, _2, bl, len, off,
+                     ctx->get_snap_context()));
+}
+
 static int save_operation_result(int result, int *pval) {
   if (pval != NULL) {
     *pval = result;
@@ -840,6 +848,12 @@ void ObjectWriteOperation::write_full(const bufferlist& bl) {
   o->ops.push_back(boost::bind(&TestIoCtxImpl::write_full, _1, _2, bl, _4));
 }
 
+void ObjectWriteOperation::writesame(uint64_t off, uint64_t len, const bufferlist& bl) {
+  TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
+  o->ops.push_back(boost::bind(&TestIoCtxImpl::writesame, _1, _2, bl, len,
+                              off, _4));
+}
+
 void ObjectWriteOperation::zero(uint64_t off, uint64_t len) {
   TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
   o->ops.push_back(boost::bind(&TestIoCtxImpl::zero, _1, _2, off, len));
index a121ded3f67d7a259f0269201eb5c77272429d69..30f1206169183676d3cecf745cd02a904b071fbe 100644 (file)
@@ -143,6 +143,8 @@ public:
                     uint64_t off, const SnapContext &snapc) = 0;
   virtual int write_full(const std::string& oid, bufferlist& bl,
                          const SnapContext &snapc) = 0;
+  virtual int writesame(const std::string& oid, bufferlist& bl, size_t len,
+                        uint64_t off, const SnapContext &snapc) = 0;
   virtual int xattr_get(const std::string& oid,
                         std::map<std::string, bufferlist>* attrset) = 0;
   virtual int xattr_set(const std::string& oid, const std::string &name,
index 239b0779dabc44d55ecd458af04bfc78fd387367..3df216adabbd7b9889469f36b9f3db82cc94d657 100644 (file)
@@ -499,6 +499,39 @@ int TestMemIoCtxImpl::write_full(const std::string& oid, bufferlist& bl,
   return 0;
 }
 
+int TestMemIoCtxImpl::writesame(const std::string& oid, bufferlist& bl, size_t len,
+                                uint64_t off, const SnapContext &snapc) {
+  if (get_snap_read() != CEPH_NOSNAP) {
+    return -EROFS;
+  }
+
+  if (len == 0 || (len % bl.length())) {
+    return -EINVAL;
+  }
+
+  TestMemRadosClient::SharedFile file;
+  {
+    RWLock::WLocker l(m_pool->file_lock);
+    file = get_file(oid, true, snapc);
+  }
+
+  RWLock::WLocker l(file->lock);
+  if (len > 0) {
+    interval_set<uint64_t> is;
+    is.insert(off, len);
+    is.intersection_of(file->snap_overlap);
+    file->snap_overlap.subtract(is);
+  }
+
+  ensure_minimum_length(off + len, &file->data);
+  while (len > 0) {
+    file->data.copy_in(off, bl.length(), bl);
+    off += bl.length();
+    len -= bl.length();
+  }
+  return 0;
+}
+
 int TestMemIoCtxImpl::xattr_get(const std::string& oid,
                                 std::map<std::string, bufferlist>* attrset) {
   TestMemRadosClient::SharedFile file;
index ab04772013e63fc74e4a72b6a0af7cbb5ec620ae..97e9e89525ee54c2753b100a3e0050a991d730ad 100644 (file)
@@ -52,6 +52,8 @@ public:
                     uint64_t off, const SnapContext &snapc);
   virtual int write_full(const std::string& oid, bufferlist& bl,
                          const SnapContext &snapc);
+  virtual int writesame(const std::string& oid, bufferlist& bl, size_t len,
+                        uint64_t off, const SnapContext &snapc);
   virtual int xattr_get(const std::string& oid,
                         std::map<std::string, bufferlist>* attrset);
   virtual int xattr_set(const std::string& oid, const std::string &name,