]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Fixed remaining part of the seg fault described in bug 9356 by adding reference count...
authorSebastien Ponce <sebastien.ponce@cern.ch>
Wed, 15 Oct 2014 14:05:00 +0000 (16:05 +0200)
committerSebastien Ponce <sebastien.ponce@cern.ch>
Mon, 20 Oct 2014 16:46:31 +0000 (18:46 +0200)
Signed-off-by: Sebastien Ponce <sebastien.ponce@cern.ch>
src/libradosstriper/RadosStriperImpl.cc
src/libradosstriper/RadosStriperImpl.h

index 3691e32fcc61ccc25b041eee10b2eedf7bca968b..798fca3fcf6e19f988a01c3cacd16876a50f30fc 100644 (file)
@@ -114,7 +114,9 @@ libradosstriper::RadosStriperImpl::CompletionData::CompletionData
 (libradosstriper::RadosStriperImpl* striper,
  const std::string& soid,
  const std::string& lockCookie,
- librados::AioCompletionImpl *userCompletion) :
+ librados::AioCompletionImpl *userCompletion,
+ int n) :
+  RefCountedObject(striper->cct(), n),
   m_striper(striper), m_soid(soid), m_lockCookie(lockCookie), m_ack(0) {
   m_striper->get();
   if (userCompletion) m_ack = new librados::IoCtxImpl::C_aio_Ack(userCompletion);
@@ -136,8 +138,9 @@ libradosstriper::RadosStriperImpl::ReadCompletionData::ReadCompletionData
  librados::AioCompletionImpl *userCompletion,
  bufferlist* bl,
  std::vector<ObjectExtent>* extents,
- std::vector<bufferlist>* resultbl) :
-  CompletionData(striper, soid, lockCookie, userCompletion),
+ std::vector<bufferlist>* resultbl,
+ int n) :
+  CompletionData(striper, soid, lockCookie, userCompletion, n),
   m_bl(bl), m_extents(extents), m_resultbl(resultbl) {}
 
 libradosstriper::RadosStriperImpl::ReadCompletionData::~ReadCompletionData() {
@@ -164,8 +167,9 @@ libradosstriper::RadosStriperImpl::WriteCompletionData::WriteCompletionData
 (libradosstriper::RadosStriperImpl* striper,
  const std::string& soid,
  const std::string& lockCookie,
- librados::AioCompletionImpl *userCompletion) :
-  CompletionData(striper, soid, lockCookie, userCompletion), m_safe(0) {
+ librados::AioCompletionImpl *userCompletion,
+ int n) :
+  CompletionData(striper, soid, lockCookie, userCompletion, n), m_safe(0) {
   if (userCompletion) m_safe = new librados::IoCtxImpl::C_aio_Safe(userCompletion);
 }
 
@@ -381,7 +385,7 @@ static void striper_read_aio_req_complete(rados_striper_multi_completion_t c, vo
   libradosstriper::MultiAioCompletionImpl *comp =
     reinterpret_cast<libradosstriper::MultiAioCompletionImpl*>(c);
   cdata->complete(comp->rval);
-  delete cdata;
+  cdata->put();
 }
 
 static void rados_req_read_safe(rados_completion_t c, void *arg)
@@ -647,6 +651,7 @@ static void striper_write_req_complete(rados_striper_multi_completion_t c, void
   libradosstriper::RadosStriperImpl::WriteCompletionData *cdata =
     reinterpret_cast<libradosstriper::RadosStriperImpl::WriteCompletionData*>(arg);
   cdata->m_striper->closeForWrite(cdata->m_soid, cdata->m_lockCookie);
+  cdata->put();
 }
 
 int libradosstriper::RadosStriperImpl::write_in_open_object(const std::string& soid,
@@ -657,6 +662,7 @@ int libradosstriper::RadosStriperImpl::write_in_open_object(const std::string& s
                                                            uint64_t off) {
   // create a completion object
   WriteCompletionData *cdata = new WriteCompletionData(this, soid, lockCookie);
+  cdata->get();
   libradosstriper::MultiAioCompletionImpl *c = new libradosstriper::MultiAioCompletionImpl;
   c->set_complete_callback(cdata, striper_write_req_complete);
   // call the asynchronous API
@@ -668,8 +674,8 @@ int libradosstriper::RadosStriperImpl::write_in_open_object(const std::string& s
     // return result
     rc = c->get_return_value();
   }
-  delete cdata;
   c->put();
+  cdata->put();
   return rc;
 }
 
@@ -681,9 +687,7 @@ static void striper_write_aio_req_complete(rados_striper_multi_completion_t c, v
   libradosstriper::MultiAioCompletionImpl *comp =
     reinterpret_cast<libradosstriper::MultiAioCompletionImpl*>(c);
   cdata->complete(comp->rval);
-  if (0 == comp->pending_safe) {
-    delete cdata;
-  }
+  cdata->put();
 }
 
 static void striper_write_aio_req_safe(rados_striper_multi_completion_t c, void *arg)
@@ -693,9 +697,7 @@ static void striper_write_aio_req_safe(rados_striper_multi_completion_t c, void
   libradosstriper::MultiAioCompletionImpl *comp =
     reinterpret_cast<libradosstriper::MultiAioCompletionImpl*>(c);
   cdata->safe(comp->rval);
-  if (0 == comp->pending_complete) {
-    delete cdata;
-  }
+  cdata->put();
 }
 
 int libradosstriper::RadosStriperImpl::aio_write_in_open_object(const std::string& soid,
@@ -707,7 +709,9 @@ int libradosstriper::RadosStriperImpl::aio_write_in_open_object(const std::strin
                                                                uint64_t off) {
   // create a completion object
   m_ioCtxImpl->get();
-  WriteCompletionData *cdata = new WriteCompletionData(this, soid, lockCookie, c);
+  // we need 2 references as both striper_write_aio_req_complete and
+  // striper_write_aio_req_safe will release one
+  WriteCompletionData *cdata = new WriteCompletionData(this, soid, lockCookie, c, 2);
   c->io = m_ioCtxImpl;
   libradosstriper::MultiAioCompletionImpl *nc = new libradosstriper::MultiAioCompletionImpl;
   nc->set_complete_callback(cdata, striper_write_aio_req_complete);
index bc0203277fcd012d81798dc47bbab56080d53c7c..c1496b93be616228d6118bab8fc5e37a42acfb4f 100644 (file)
@@ -33,24 +33,25 @@ struct libradosstriper::RadosStriperImpl {
    * struct handling the data needed to pass to the call back
    * function in asynchronous operations
    */
-  struct CompletionData {
-    /// striper to be used to handle the write completion
-    libradosstriper::RadosStriperImpl *m_striper;
-    /// striped object concerned by the write operation
-    std::string m_soid;
-    /// shared lock to be released at completion
-    std::string m_lockCookie;
-    /// completion handler
-    librados::IoCtxImpl::C_aio_Ack *m_ack;
+  struct CompletionData : RefCountedObject {
     /// constructor
     CompletionData(libradosstriper::RadosStriperImpl * striper,
                   const std::string& soid,
                   const std::string& lockCookie,
-                  librados::AioCompletionImpl *userCompletion = 0);
+                  librados::AioCompletionImpl *userCompletion = 0,
+                   int n = 1);
     /// destructor
     virtual ~CompletionData();
     /// complete method
     void complete(int r);
+    /// striper to be used to handle the write completion
+    libradosstriper::RadosStriperImpl *m_striper;
+    /// striped object concerned by the write operation
+    std::string m_soid;
+    /// shared lock to be released at completion
+    std::string m_lockCookie;
+    /// completion handler
+    librados::IoCtxImpl::C_aio_Ack *m_ack;
   };
 
   /**
@@ -71,7 +72,8 @@ struct libradosstriper::RadosStriperImpl {
                       librados::AioCompletionImpl *userCompletion,
                       bufferlist* bl,
                       std::vector<ObjectExtent>* extents,
-                      std::vector<bufferlist>* resultbl);
+                      std::vector<bufferlist>* resultbl,
+                       int n = 1);
     /// destructor
     virtual ~ReadCompletionData();
     /// complete method
@@ -89,7 +91,8 @@ struct libradosstriper::RadosStriperImpl {
     WriteCompletionData(libradosstriper::RadosStriperImpl * striper,
                        const std::string& soid,
                        const std::string& lockCookie,
-                       librados::AioCompletionImpl *userCompletion = 0);
+                       librados::AioCompletionImpl *userCompletion = 0,
+                        int n = 1);
     /// destructor
     virtual ~WriteCompletionData();
     /// safe method