qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Ting Wang <kathy.wangting@huawei.com>
Subject: [Qemu-devel] [PULL for-2.4 7/7] blockjob: add block_job_release function
Date: Tue,  7 Jul 2015 13:08:24 +0100	[thread overview]
Message-ID: <1436270904-2855-8-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1436270904-2855-1-git-send-email-stefanha@redhat.com>

From: Ting Wang <kathy.wangting@huawei.com>

There is job resource leak in function mirror_start_job,
although bdrv_create_dirty_bitmap is unlikely failed.
Add block_job_release for each release when needed.

Signed-off-by: Ting Wang <kathy.wangting@huawei.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-id: 1435311455-56048-1-git-send-email-kathy.wangting@huawei.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/mirror.c           |  2 ++
 blockjob.c               | 20 ++++++++++++--------
 include/block/blockjob.h |  8 ++++++++
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index 8888cea..d409337 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -708,6 +708,8 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
 
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {
+        g_free(s->replaces);
+        block_job_release(bs);
         return;
     }
     bdrv_set_enable_write_cache(s->target, true);
diff --git a/blockjob.c b/blockjob.c
index ec46fad..62bb906 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -66,10 +66,7 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
 
         block_job_set_speed(job, speed, &local_err);
         if (local_err) {
-            bs->job = NULL;
-            bdrv_op_unblock_all(bs, job->blocker);
-            error_free(job->blocker);
-            g_free(job);
+            block_job_release(bs);
             error_propagate(errp, local_err);
             return NULL;
         }
@@ -77,18 +74,25 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
     return job;
 }
 
-void block_job_completed(BlockJob *job, int ret)
+void block_job_release(BlockDriverState *bs)
 {
-    BlockDriverState *bs = job->bs;
+    BlockJob *job = bs->job;
 
-    assert(bs->job == job);
-    job->cb(job->opaque, ret);
     bs->job = NULL;
     bdrv_op_unblock_all(bs, job->blocker);
     error_free(job->blocker);
     g_free(job);
 }
 
+void block_job_completed(BlockJob *job, int ret)
+{
+    BlockDriverState *bs = job->bs;
+
+    assert(bs->job == job);
+    job->cb(job->opaque, ret);
+    block_job_release(bs);
+}
+
 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
 {
     Error *local_err = NULL;
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index 57d8ef1..dd9d5e6 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -166,6 +166,14 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);
 void block_job_yield(BlockJob *job);
 
 /**
+ * block_job_release:
+ * @bs: The block device.
+ *
+ * Release job resources when an error occurred or job completed.
+ */
+void block_job_release(BlockDriverState *bs);
+
+/**
  * block_job_completed:
  * @job: The job being completed.
  * @ret: The status code.
-- 
2.4.3

      parent reply	other threads:[~2015-07-07 12:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-07 12:08 [Qemu-devel] [PULL for-2.4 0/7] Block patches Stefan Hajnoczi
2015-07-07 12:08 ` [Qemu-devel] [PULL for-2.4 1/7] qcow2: remove unnecessary check Stefan Hajnoczi
2015-07-07 12:08 ` [Qemu-devel] [PULL for-2.4 2/7] block: update bdrv_drain_all()/bdrv_drain() comments Stefan Hajnoczi
2015-07-07 12:08 ` [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level Stefan Hajnoczi
2015-07-07 12:50   ` Peter Lieven
2015-07-07 13:13     ` Stefan Hajnoczi
2015-07-07 13:40       ` Kevin Wolf
2015-07-08 17:48         ` Max Reitz
2015-07-07 13:24   ` Stefan Hajnoczi
2015-07-07 13:41     ` Peter Lieven
2015-07-07 13:45       ` Kevin Wolf
2015-07-21 22:38         ` Eric Blake
2015-07-21 22:37   ` Eric Blake
2015-07-07 12:08 ` [Qemu-devel] [PULL for-2.4 4/7] block: Initialize local_err in bdrv_append_temp_snapshot Stefan Hajnoczi
2015-07-07 12:08 ` [Qemu-devel] [PULL for-2.4 5/7] block: Use bdrv_drain to replace uncessary bdrv_drain_all Stefan Hajnoczi
2015-07-07 12:08 ` [Qemu-devel] [PULL for-2.4 6/7] block/raw-posix: Don't think /dev/fd/<NN> is a floppy drive Stefan Hajnoczi
2015-07-07 12:08 ` Stefan Hajnoczi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436270904-2855-8-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=kathy.wangting@huawei.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).