]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados_test_stub: add reference counting to pools
authorJason Dillaman <dillaman@redhat.com>
Mon, 29 Jun 2015 22:38:48 +0000 (18:38 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 4 Sep 2015 03:28:54 +0000 (23:28 -0400)
This will ensure that in-flight operations can't access freed
pool memory.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librados_test_stub/TestMemIoCtxImpl.cc
src/test/librados_test_stub/TestMemIoCtxImpl.h
src/test/librados_test_stub/TestMemRadosClient.cc
src/test/librados_test_stub/TestMemRadosClient.h

index a5b27cd3d2227e487a0aa3fe98bfd1316889f58c..bb39b49d62db141dac2cb838bb0139c69b397126 100644 (file)
@@ -23,14 +23,21 @@ TestMemIoCtxImpl::TestMemIoCtxImpl() {
 }
 
 TestMemIoCtxImpl::TestMemIoCtxImpl(const TestMemIoCtxImpl& rhs)
-  : TestIoCtxImpl(rhs), m_client(rhs.m_client), m_pool(rhs.m_pool) {
-  }
+    : TestIoCtxImpl(rhs), m_client(rhs.m_client), m_pool(rhs.m_pool) {
+  m_pool->get();
+}
 
 TestMemIoCtxImpl::TestMemIoCtxImpl(TestMemRadosClient &client, int64_t pool_id,
                                    const std::string& pool_name,
                                    TestMemRadosClient::Pool *pool)
-  : TestIoCtxImpl(client, pool_id, pool_name), m_client(&client), m_pool(pool) {
-  }
+    : TestIoCtxImpl(client, pool_id, pool_name), m_client(&client),
+      m_pool(pool) {
+  m_pool->get();
+}
+
+TestMemIoCtxImpl::~TestMemIoCtxImpl() {
+  m_pool->put();
+}
 
 TestIoCtxImpl *TestMemIoCtxImpl::clone() {
   return new TestMemIoCtxImpl(*this);
index 4fc2eb47ac51eadc5e4ab590d81c310b347665ed..e58b97a3fecaef948aaeb845ac23690e3fb34432 100644 (file)
@@ -12,9 +12,10 @@ namespace librados {
 class TestMemIoCtxImpl : public TestIoCtxImpl {
 public:
   TestMemIoCtxImpl();
-  explicit TestMemIoCtxImpl(TestMemRadosClient &client, int64_t m_pool_id,
-                            const std::string& pool_name,
-                            TestMemRadosClient::Pool *pool);
+  TestMemIoCtxImpl(TestMemRadosClient &client, int64_t m_pool_id,
+                   const std::string& pool_name,
+                   TestMemRadosClient::Pool *pool);
+  virtual ~TestMemIoCtxImpl();
 
   virtual TestIoCtxImpl *clone();
 
index b89f4eb6fed2a6bd939db8e9937bed5fe36c851e..b8bdf0777c31f637b98a2f2dc21f16c8c85b9d28 100644 (file)
@@ -78,7 +78,7 @@ int TestMemRadosClient::pool_delete(const std::string &pool_name) {
   if (iter == m_pools.end()) {
     return -ENOENT;
   }
-  delete iter->second;
+  iter->second->put();
   m_pools.erase(iter);
   return 0;
 }
index a6fb3bdb1d5fee1a3190b54c3422239f50c04322..e0afacb3a7054af98dc67aca94bb44bdabee5498 100644 (file)
@@ -6,8 +6,10 @@
 
 #include "test/librados_test_stub/TestRadosClient.h"
 #include "include/atomic.h"
+#include "include/assert.h"
 #include "include/buffer.h"
 #include "include/interval_set.h"
+#include "common/RefCountedObj.h"
 #include "common/RWLock.h"
 #include <boost/shared_ptr.hpp>
 #include <list>
@@ -48,7 +50,7 @@ public:
   typedef std::map<std::string, FileSnapshots> Files;
 
   typedef std::set<uint64_t> SnapSeqs;
-  struct Pool {
+  struct Pool : public RefCountedObject {
     Pool();
 
     int64_t pool_id;