From 416ce7621d75aeaabd3888dbc736ea4245206a3f Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 2 Mar 2015 08:21:06 -0500 Subject: [PATCH] librbd: delete Contexts when object map aio_update not required 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 --- src/librbd/AioRequest.cc | 10 ++++++---- src/librbd/AsyncTrimRequest.cc | 13 ++++++++----- src/librbd/CopyupRequest.cc | 5 +++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/librbd/AioRequest.cc b/src/librbd/AioRequest.cc index 1e6a28d1c51bc..9ed4b0ef527ac 100644 --- a/src/librbd/AioRequest.cc +++ b/src/librbd/AioRequest.cc @@ -446,17 +446,18 @@ namespace librbd { boost::optional 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 << " " diff --git a/src/librbd/AsyncTrimRequest.cc b/src/librbd/AsyncTrimRequest.cc index 4f373482eb8f2..21c8a69d64ecf 100644 --- a/src/librbd/AsyncTrimRequest.cc +++ b/src/librbd/AsyncTrimRequest.cc @@ -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; } } diff --git a/src/librbd/CopyupRequest.cc b/src/librbd/CopyupRequest.cc index 687dbe1ce0e16..a58ec84f6ccda 100644 --- a/src/librbd/CopyupRequest.cc +++ b/src/librbd/CopyupRequest.cc @@ -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(), - create_callback_context())) { + boost::optional(), ctx)) { + delete ctx; copyup = true; } } -- 2.39.5