]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: librados_test_stub reads should deep-copy
authorJason Dillaman <dillaman@redhat.com>
Fri, 6 Mar 2015 20:40:48 +0000 (15:40 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 13 Aug 2015 12:46:45 +0000 (08:46 -0400)
If a client of librados_test_stub modified a bufferlist
retrieved via a read call, the client will actually be
changing the contents of the file.  Therefore, read calls
should deep-copy the contents of the buffer::ptrs.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 76fe8d73ff79da2d734f70680208a2c188b58671)
(cherry picked from commit 7ee7dcfd609731d3c7f51b74c1d99fb3fa51c413)

src/test/librados_test_stub/TestMemIoCtxImpl.cc
src/test/librados_test_stub/TestMemIoCtxImpl.h

index 05103b0c299dd1900541417b047fac75fabd4f93..01a5b0187087fc59e65788a1616d5a901a31abe7 100644 (file)
@@ -236,7 +236,9 @@ int TestMemIoCtxImpl::read(const std::string& oid, size_t len, uint64_t off,
   }
   len = clip_io(off, len, file->data.length());
   if (bl != NULL && len > 0) {
-    bl->substr_of(file->data, off, len);
+    bufferlist bit;
+    bit.substr_of(file->data, off, len);
+    append_clone(bit, bl);
   }
   return 0;
 }
@@ -352,7 +354,9 @@ int TestMemIoCtxImpl::sparse_read(const std::string& oid, uint64_t off,
     }
   }
   if (data_bl != NULL && len > 0) {
-    data_bl->substr_of(file->data, off, len);
+    bufferlist bit;
+    bit.substr_of(file->data, off, len);
+    append_clone(bit, data_bl);
   }
   return 0;
 }
@@ -510,6 +514,17 @@ int TestMemIoCtxImpl::zero(const std::string& oid, uint64_t off, uint64_t len) {
   return write(oid, bl, len, off);
 }
 
+void TestMemIoCtxImpl::append_clone(bufferlist& src, bufferlist* dest) {
+  // deep-copy the src to ensure our memory-based mock RADOS data cannot
+  // be modified by callers
+  if (src.length() > 0) {
+    bufferlist::iterator iter = src.begin();
+    buffer::ptr ptr;
+    iter.copy(src.length(), ptr);
+    dest->append(ptr);
+  }
+}
+
 size_t TestMemIoCtxImpl::clip_io(size_t off, size_t len, size_t bl_len) {
   if (off >= bl_len) {
     len = 0;
index cfec62490ebb2a74119850102da01c290c07bf7f..68adf2105e0be010de9c2d67af9fac26edee64e3 100644 (file)
@@ -59,6 +59,7 @@ private:
   TestMemRadosClient *m_client;
   TestMemRadosClient::Pool *m_pool;
 
+  void append_clone(bufferlist& src, bufferlist* dest);
   size_t clip_io(size_t off, size_t len, size_t bl_len);
   void ensure_minimum_length(size_t len, bufferlist *bl);