]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados_test_stub: support for truncating/removing with old snap contexts
authorJason Dillaman <dillaman@redhat.com>
Sun, 6 Mar 2016 18:01:09 +0000 (13:01 -0500)
committerJason Dillaman <dillaman@redhat.com>
Sun, 13 Mar 2016 03:40:14 +0000 (22:40 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librados_test_stub/LibradosTestStub.cc
src/test/librados_test_stub/MockTestMemIoCtxImpl.h
src/test/librados_test_stub/TestIoCtxImpl.h
src/test/librados_test_stub/TestMemIoCtxImpl.cc
src/test/librados_test_stub/TestMemIoCtxImpl.h

index 2c95c245ff68a1c8644b4b1957c9370541b4b25c..8df054775d0d099879862b6e414b0a0b5917d6cb 100644 (file)
@@ -538,8 +538,7 @@ int IoCtx::read(const std::string& oid, bufferlist& bl, size_t len,
 int IoCtx::remove(const std::string& oid) {
   TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl);
   return ctx->execute_operation(
-    oid, boost::bind(&TestIoCtxImpl::remove, _1, _2));
-  return ctx->remove(oid);
+    oid, boost::bind(&TestIoCtxImpl::remove, _1, _2, ctx->get_snap_context()));
 }
 
 int IoCtx::selfmanaged_snap_create(uint64_t *snapid) {
@@ -581,6 +580,13 @@ int IoCtx::tmap_update(const std::string& oid, bufferlist& cmdbl) {
     oid, boost::bind(&TestIoCtxImpl::tmap_update, _1, _2, cmdbl));
 }
 
+int IoCtx::trunc(const std::string& oid, uint64_t off) {
+  TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl);
+  return ctx->execute_operation(
+    oid, boost::bind(&TestIoCtxImpl::truncate, _1, _2, off,
+                     ctx->get_snap_context()));
+}
+
 int IoCtx::unwatch2(uint64_t handle) {
   TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl);
   return ctx->unwatch(handle);
@@ -751,7 +757,7 @@ void ObjectWriteOperation::omap_set(const std::map<std::string, bufferlist> &map
 
 void ObjectWriteOperation::remove() {
   TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
-  o->ops.push_back(boost::bind(&TestIoCtxImpl::remove, _1, _2));
+  o->ops.push_back(boost::bind(&TestIoCtxImpl::remove, _1, _2, _4));
 }
 
 void ObjectWriteOperation::selfmanaged_snap_rollback(uint64_t snapid) {
index c9da11b1c04baa2ed0158e9a84f81b730ada2a37..40ccc8f23a21c9ba08518921d4d763432cc5f7d9 100644 (file)
@@ -48,6 +48,11 @@ public:
                                   snapc);
   }
 
+  MOCK_METHOD2(list_snaps, int(const std::string& o, snap_set_t *out_snaps));
+  int do_list_snaps(const std::string& o, snap_set_t *out_snaps) {
+    return TestMemIoCtxImpl::list_snaps(o, out_snaps);
+  }
+
   MOCK_METHOD2(list_watchers, int(const std::string& o,
                                   std::list<obj_watch_t> *out_watchers));
   int do_list_watchers(const std::string& o,
@@ -64,9 +69,9 @@ public:
     return TestMemIoCtxImpl::read(oid, len, off, bl);
   }
 
-  MOCK_METHOD1(remove, int(const std::string& oid));
-  int do_remove(const std::string& oid) {
-    return TestMemIoCtxImpl::remove(oid);
+  MOCK_METHOD2(remove, int(const std::string& oid, const SnapContext &snapc));
+  int do_remove(const std::string& oid, const SnapContext &snapc) {
+    return TestMemIoCtxImpl::remove(oid, snapc);
   }
 
   MOCK_METHOD1(selfmanaged_snap_create, int(uint64_t *snap_id));
@@ -112,9 +117,10 @@ public:
     using namespace ::testing;
 
     ON_CALL(*this, exec(_, _, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec));
+    ON_CALL(*this, list_snaps(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_snaps));
     ON_CALL(*this, list_watchers(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_watchers));
     ON_CALL(*this, read(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read));
-    ON_CALL(*this, remove(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove));
+    ON_CALL(*this, remove(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove));
     ON_CALL(*this, selfmanaged_snap_create(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_create));
     ON_CALL(*this, selfmanaged_snap_remove(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_remove));
     ON_CALL(*this, selfmanaged_snap_rollback(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_rollback));
index 0db715f34b3820631bd77d7e023bea71ec3f9e72..b6d845da375c446a76773451504b41d4a8bf495a 100644 (file)
@@ -114,7 +114,7 @@ public:
                            bufferlist *pbl);
   virtual int read(const std::string& oid, size_t len, uint64_t off,
                    bufferlist *bl) = 0;
-  virtual int remove(const std::string& oid) = 0;
+  virtual int remove(const std::string& oid, const SnapContext &snapc) = 0;
   virtual int selfmanaged_snap_create(uint64_t *snapid) = 0;
   virtual int selfmanaged_snap_remove(uint64_t snapid) = 0;
   virtual int selfmanaged_snap_rollback(const std::string& oid,
index 9b95c502f15c341d98505d46b3818be8df834dae..6c522e8e2aa5ccc63812d7f4ca14934e24388a57 100644 (file)
@@ -46,7 +46,8 @@ TestIoCtxImpl *TestMemIoCtxImpl::clone() {
 
 int TestMemIoCtxImpl::aio_remove(const std::string& oid, AioCompletionImpl *c) {
   m_client->add_aio_operation(oid, true,
-                              boost::bind(&TestMemIoCtxImpl::remove, this, oid),
+                              boost::bind(&TestMemIoCtxImpl::remove, this, oid,
+                                          get_snap_context()),
                               c);
   return 0;
 }
@@ -270,18 +271,17 @@ int TestMemIoCtxImpl::read(const std::string& oid, size_t len, uint64_t off,
   return len;
 }
 
-int TestMemIoCtxImpl::remove(const std::string& oid) {
+int TestMemIoCtxImpl::remove(const std::string& oid, const SnapContext &snapc) {
   if (get_snap_read() != CEPH_NOSNAP) {
     return -EROFS;
   }
 
   RWLock::WLocker l(m_pool->file_lock);
-  TestMemRadosClient::SharedFile file = get_file(oid, false,
-                                                 get_snap_context());
+  TestMemRadosClient::SharedFile file = get_file(oid, false, snapc);
   if (file == NULL) {
     return -ENOENT;
   }
-  file = get_file(oid, true, get_snap_context());
+  file = get_file(oid, true, snapc);
 
   RWLock::WLocker l2(file->lock);
   file->exists = false;
index 6556c9c723ef8711c8166adae969c11033be1a00..ab04772013e63fc74e4a72b6a0af7cbb5ec620ae 100644 (file)
@@ -38,7 +38,7 @@ public:
                        bufferlist> &map);
   virtual int read(const std::string& oid, size_t len, uint64_t off,
                    bufferlist *bl);
-  virtual int remove(const std::string& oid);
+  virtual int remove(const std::string& oid, const SnapContext &snapc);
   virtual int selfmanaged_snap_create(uint64_t *snapid);
   virtual int selfmanaged_snap_remove(uint64_t snapid);
   virtual int selfmanaged_snap_rollback(const std::string& oid,