qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, hbrock@redhat.com,
	rjones@redhat.com, imain@redhat.com, stefanha@redhat.com,
	pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v2 02/11] block: use refcnt for bs->backing_hd and bs->file
Date: Wed, 17 Jul 2013 17:42:07 +0800	[thread overview]
Message-ID: <1374054136-28741-3-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1374054136-28741-1-git-send-email-famz@redhat.com>

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block.c           | 18 ++++++++++++++----
 block/blkdebug.c  |  1 +
 block/blkverify.c |  1 +
 block/snapshot.c  |  2 +-
 block/stream.c    |  2 +-
 block/vvfat.c     |  1 +
 6 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index 4170ff6..7b46669 100644
--- a/block.c
+++ b/block.c
@@ -932,6 +932,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options)
         bs->open_flags |= BDRV_O_NO_BACKING;
         return ret;
     }
+    bdrv_ref(bs->backing_hd, false);
     return 0;
 }
 
@@ -1075,9 +1076,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
 
     if (bs->file != file) {
         bdrv_delete(file);
-        file = NULL;
     }
 
+    file = NULL;
+    bdrv_ref(bs->file, false);
+
     /* If there is a backing file, use it */
     if ((flags & BDRV_O_NO_BACKING) == 0) {
         QDict *backing_options;
@@ -1375,7 +1378,7 @@ void bdrv_close(BlockDriverState *bs)
 
     if (bs->drv) {
         if (bs->backing_hd) {
-            bdrv_delete(bs->backing_hd);
+            bdrv_unref(bs->backing_hd, false);
             bs->backing_hd = NULL;
         }
         bs->drv->bdrv_close(bs);
@@ -1399,7 +1402,7 @@ void bdrv_close(BlockDriverState *bs)
         bs->options = NULL;
 
         if (bs->file != NULL) {
-            bdrv_delete(bs->file);
+            bdrv_unref(bs->file, false);
             bs->file = NULL;
         }
     }
@@ -1587,7 +1590,11 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top)
 
     /* The contents of 'tmp' will become bs_top, as we are
      * swapping bs_new and bs_top contents. */
+    if (bs_top->backing_hd) {
+        bdrv_unref(bs_top->backing_hd, false);
+    }
     bs_top->backing_hd = bs_new;
+    bdrv_ref(bs_new, false);
     bs_top->open_flags &= ~BDRV_O_NO_BACKING;
     pstrcpy(bs_top->backing_file, sizeof(bs_top->backing_file),
             bs_new->filename);
@@ -2108,8 +2115,11 @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
     if (ret) {
         goto exit;
     }
+    if (new_top_bs->backing_hd) {
+        bdrv_unref(new_top_bs->backing_hd, false);
+    }
     new_top_bs->backing_hd = base_bs;
-
+    bdrv_ref(base_bs, false);
 
     QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, next) {
         /* so that bdrv_close() does not recursively close the chain */
diff --git a/block/blkdebug.c b/block/blkdebug.c
index ccb627a..c4ddbac 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -389,6 +389,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags)
     if (ret < 0) {
         goto fail;
     }
+    bdrv_ref(bs->file, false);
 
     ret = 0;
 fail:
diff --git a/block/blkverify.c b/block/blkverify.c
index 1d58cc3..5996045 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -144,6 +144,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags)
     if (ret < 0) {
         goto fail;
     }
+    bdrv_ref(bs->file, false);
 
     /* Open the test file */
     filename = qemu_opt_get(opts, "x-image");
diff --git a/block/snapshot.c b/block/snapshot.c
index 6c6d9de..4f145fa 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -99,7 +99,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
         ret = bdrv_snapshot_goto(bs->file, snapshot_id);
         open_ret = drv->bdrv_open(bs, NULL, bs->open_flags);
         if (open_ret < 0) {
-            bdrv_delete(bs->file);
+            bdrv_unref(bs->file, false);
             bs->drv = NULL;
             return open_ret;
         }
diff --git a/block/stream.c b/block/stream.c
index 7fe9e48..bcc8dc6 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -68,7 +68,7 @@ static void close_unused_images(BlockDriverState *top, BlockDriverState *base,
         unused = intermediate;
         intermediate = intermediate->backing_hd;
         unused->backing_hd = NULL;
-        bdrv_delete(unused);
+        bdrv_unref(unused, false);
     }
     top->backing_hd = base;
 }
diff --git a/block/vvfat.c b/block/vvfat.c
index 87b0279..353d4ac 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2949,6 +2949,7 @@ static int enable_write_target(BDRVVVFATState *s)
     s->bs->backing_hd->drv = &vvfat_write_target;
     s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
     *(void**)s->bs->backing_hd->opaque = s;
+    bdrv_ref(s->bs->backing_hd, false);
 
     return 0;
 }
-- 
1.8.3.2

  parent reply	other threads:[~2013-07-17  9:42 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-17  9:42 [Qemu-devel] [PATCH v2 00/11] Point-in-time snapshot exporting over NBD Fam Zheng
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 01/11] block: replace in_use with refcnt_soft and refcnt_hard Fam Zheng
2013-07-17 12:26   ` Paolo Bonzini
2013-07-18  4:53     ` Fam Zheng
2013-07-23  9:36   ` Stefan Hajnoczi
2013-07-23 10:32     ` Fam Zheng
2013-07-23 13:34       ` Stefan Hajnoczi
2013-07-24  0:39         ` Fam Zheng
2013-07-24  7:35           ` Stefan Hajnoczi
2013-07-24  7:44             ` Fam Zheng
2013-07-25  7:52               ` Stefan Hajnoczi
2013-07-17  9:42 ` Fam Zheng [this message]
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 03/11] block: use refcnt for drive_init/drive_uninit Fam Zheng
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 04/11] block: use refcnt for device attach/detach Fam Zheng
2013-07-23  9:44   ` Stefan Hajnoczi
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 05/11] migration: omit drive ref as we have bdrv_ref now Fam Zheng
2013-07-23  9:49   ` Stefan Hajnoczi
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 06/11] xen_disk: simplify blk_disconnect with refcnt Fam Zheng
2013-07-23  9:50   ` Stefan Hajnoczi
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 07/11] block: hold hard reference for backup/mirror target Fam Zheng
2013-07-23  9:52   ` Stefan Hajnoczi
2013-07-25  6:08     ` Fam Zheng
2013-07-25  7:59       ` Stefan Hajnoczi
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 08/11] block: simplify bdrv_drop_intermediate Fam Zheng
2013-07-24 23:16   ` Jeff Cody
2013-07-25  1:34     ` Fam Zheng
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 09/11] block: add assertion to check refcount before deleting Fam Zheng
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 10/11] block: add option 'backing' to -drive options Fam Zheng
2013-07-17 12:36   ` Paolo Bonzini
2013-07-17 12:58     ` Kevin Wolf
2013-07-17 13:13       ` Paolo Bonzini
2013-07-17 13:48         ` Kevin Wolf
2013-07-17 14:16           ` Paolo Bonzini
2013-07-17 15:09             ` Kevin Wolf
2013-07-17 15:23               ` Paolo Bonzini
2013-07-23 20:07               ` Ian Main
2013-07-22  6:07     ` Fam Zheng
2013-07-23 19:57       ` Ian Main
2013-07-17  9:42 ` [Qemu-devel] [PATCH v2 11/11] qmp: add command 'blockdev-backup' Fam Zheng
2013-07-17 12:44   ` Eric Blake
2013-07-18  4:41     ` Fam Zheng
2013-07-19 10:16       ` Wenchao Xia
2013-07-23 10:10         ` Stefan Hajnoczi
2013-07-19 10:41 ` [Qemu-devel] [PATCH v2 00/11] Point-in-time snapshot exporting over NBD Wenchao Xia
2013-07-23  1:52   ` Wenchao Xia
2013-07-23  6:35     ` Paolo Bonzini

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=1374054136-28741-3-git-send-email-famz@redhat.com \
    --to=famz@redhat.com \
    --cc=hbrock@redhat.com \
    --cc=imain@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.com \
    --cc=stefanha@redhat.com \
    /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).