]> git.apps.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)
committerLoic Dachary <ldachary@redhat.com>
Wed, 6 May 2015 09:29:51 +0000 (11:29 +0200)
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)

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

index a9dac606155ae5703a62c22a668d2b68171fef81..2e6518a174efe85b79854732a4c927471b1c61ae 100644 (file)
@@ -237,7 +237,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;
 }
@@ -353,7 +355,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;
 }
@@ -511,6 +515,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);