]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: delete Contexts when object map aio_update not required
authorJason Dillaman <dillaman@redhat.com>
Mon, 2 Mar 2015 13:21:06 +0000 (08:21 -0500)
committerJason Dillaman <dillaman@redhat.com>
Tue, 3 Mar 2015 02:18:39 +0000 (21:18 -0500)
If an object map update is not required when modifying an image,
properly free the memory allocated for the callback Context.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/AioRequest.cc
src/librbd/AsyncTrimRequest.cc
src/librbd/CopyupRequest.cc

index 1e6a28d1c51bcaa1595b3233dc11a7fd95c8f595..9ed4b0ef527ac4011f24efa65d538c124007e3f4 100644 (file)
@@ -446,17 +446,18 @@ namespace librbd {
         boost::optional<uint8_t> current_state;
         pre_object_map_update(&new_state);
 
-        m_state = LIBRBD_AIO_WRITE_PRE; 
+        m_state = LIBRBD_AIO_WRITE_PRE;
         FunctionContext *ctx = new FunctionContext(
           boost::bind(&AioRequest::complete, this, _1));
         if (!m_ictx->object_map.aio_update(m_object_no, new_state,
                                            current_state, ctx)) {
          // no object map update required
+         delete ctx;
          return false;
        }
       }
     }
-    
+
     if (lost_exclusive_lock) {
       complete(-ERESTART);
     }
@@ -485,10 +486,11 @@ namespace librbd {
     if (!m_ictx->object_map.aio_update(m_object_no, OBJECT_NONEXISTENT,
                                        OBJECT_PENDING, ctx)) {
       // no object map update required
+      delete ctx;
       return true;
     }
-    return false;  
-  } 
+    return false;
+  }
 
   void AbstractWrite::send_write() {
     ldout(m_ictx->cct, 20) << "send_write " << this << " " << m_oid << " "
index 4f373482eb8f2976c2da9439ab024c25012c7dff..21c8a69d64ecf3b90efc5dbd6eeb6f954745f3cf 100644 (file)
@@ -172,9 +172,11 @@ void AsyncTrimRequest::send_pre_remove() {
         lost_exclusive_lock = true;
       } else {
         // flag the objects as pending deletion
+        Context *ctx = create_callback_context();
         if (!m_image_ctx.object_map.aio_update(m_delete_start, m_num_objects,
-                                               OBJECT_PENDING, OBJECT_EXISTS,
-                                               create_callback_context())) {
+                                              OBJECT_PENDING, OBJECT_EXISTS,
+                                               ctx)) {
+          delete ctx;
           remove_objects = true;
         }
       }
@@ -207,10 +209,11 @@ bool AsyncTrimRequest::send_post_remove() {
         ldout(m_image_ctx.cct, 1) << "lost exclusive lock during trim" << dendl;
       } else {
         // flag the pending objects as removed
+        Context *ctx = create_callback_context();
         if (!m_image_ctx.object_map.aio_update(m_delete_start, m_num_objects,
-                                               OBJECT_NONEXISTENT,
-                                               OBJECT_PENDING,
-                                               create_callback_context())) {
+                                              OBJECT_NONEXISTENT,
+                                              OBJECT_PENDING, ctx)) {
+          delete ctx;
          clean_boundary = true;
        }
       }
index 687dbe1ce0e16706fcdab52156048847077c4243..a58ec84f6ccdaa43cc6c60d3051c7bd09ea101c2 100644 (file)
@@ -186,9 +186,10 @@ namespace librbd {
        return true;
       } else {
        m_state = STATE_OBJECT_MAP;
+        Context *ctx = create_callback_context();
         if (!m_ictx->object_map.aio_update(m_object_no, OBJECT_EXISTS,
-                                           boost::optional<uint8_t>(),
-                                           create_callback_context())) {
+                                          boost::optional<uint8_t>(), ctx)) {
+          delete ctx;
          copyup = true;
        }
       }