cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 52d7a3ed9170da1248cadbbc746c32dd7c34c568 Mon Sep 17 00:00:00 2001
0a122b
From: Fam Zheng <famz@redhat.com>
0a122b
Date: Fri, 17 Jan 2014 03:07:48 +0100
0a122b
Subject: [PATCH 05/34] block: make bdrv_delete() static
0a122b
0a122b
RH-Author: Fam Zheng <famz@redhat.com>
0a122b
Message-id: <1389928083-8921-4-git-send-email-famz@redhat.com>
0a122b
Patchwork-id: 56765
0a122b
O-Subject: [RHEL-7 qemu-kvm PATCH 03/18] block: make bdrv_delete() static
0a122b
Bugzilla: 1041301
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
Manage BlockDriverState lifecycle with refcnt, so bdrv_delete() is no
0a122b
longer public and should be called by bdrv_unref() if refcnt is
0a122b
decreased to 0.
0a122b
0a122b
This is an identical change because effectively, there's no multiple
0a122b
reference of BDS now: no caller of bdrv_ref() yet, only bdrv_new() sets
0a122b
bs->refcnt to 1, so all bdrv_unref() now actually delete the BDS.
0a122b
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 4f6fd3491cf0f768b135ed2e242bd1d1d2a2efec)
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
	block/backup.c
0a122b
	block/blkverify.c
0a122b
	block/vvfat.c
0a122b
	blockdev.c
0a122b
	hw/block/xen_disk.c
0a122b
	qemu-io.c
0a122b
0a122b
All are contextual conflicts. We are doing a mechanical replacing here,
0a122b
so simply use the downstream code except replace bdrv_delete with
0a122b
bdrv_unref.
0a122b
0a122b
Several more bdrv_delete's are converted in qemu-img.c, qemu-io.c and
0a122b
block/vhdx.c.
0a122b
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
---
0a122b
 block.c               | 23 ++++++++++++-----------
0a122b
 block/blkverify.c     |  4 ++--
0a122b
 block/cow.c           |  2 +-
0a122b
 block/iscsi.c         |  2 +-
0a122b
 block/mirror.c        |  2 +-
0a122b
 block/qcow.c          |  2 +-
0a122b
 block/qcow2.c         |  2 +-
0a122b
 block/qed.c           |  2 +-
0a122b
 block/sheepdog.c      |  6 +++---
0a122b
 block/snapshot.c      |  2 +-
0a122b
 block/stream.c        |  2 +-
0a122b
 block/vhdx.c          |  2 +-
0a122b
 block/vmdk.c          | 10 +++++-----
0a122b
 block/vvfat.c         |  4 ++--
0a122b
 blockdev.c            | 10 +++++-----
0a122b
 hw/block/xen_disk.c   |  4 ++--
0a122b
 include/block/block.h |  1 -
0a122b
 qemu-img.c            | 31 +++++++++++++++----------------
0a122b
 qemu-io.c             |  6 +++---
0a122b
 19 files changed, 58 insertions(+), 59 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block.c               |   23 ++++++++++++-----------
0a122b
 block/blkverify.c     |    4 ++--
0a122b
 block/cow.c           |    2 +-
0a122b
 block/iscsi.c         |    2 +-
0a122b
 block/mirror.c        |    2 +-
0a122b
 block/qcow.c          |    2 +-
0a122b
 block/qcow2.c         |    2 +-
0a122b
 block/qed.c           |    2 +-
0a122b
 block/sheepdog.c      |    6 +++---
0a122b
 block/snapshot.c      |    2 +-
0a122b
 block/stream.c        |    2 +-
0a122b
 block/vhdx.c          |    2 +-
0a122b
 block/vmdk.c          |   10 +++++-----
0a122b
 block/vvfat.c         |    4 ++--
0a122b
 blockdev.c            |   10 +++++-----
0a122b
 hw/block/xen_disk.c   |    4 ++--
0a122b
 include/block/block.h |    1 -
0a122b
 qemu-img.c            |   31 +++++++++++++++----------------
0a122b
 qemu-io.c             |    6 +++---
0a122b
 19 files changed, 58 insertions(+), 59 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index ddf29d0..b4e3ced 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -918,7 +918,7 @@ fail:
0a122b
     if (!bs->drv) {
0a122b
         QDECREF(bs->options);
0a122b
     }
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
@@ -972,7 +972,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
0a122b
                     *backing_filename ? backing_filename : NULL, options,
0a122b
                     back_flags, back_drv, &local_err);
0a122b
     if (ret < 0) {
0a122b
-        bdrv_delete(bs->backing_hd);
0a122b
+        bdrv_unref(bs->backing_hd);
0a122b
         bs->backing_hd = NULL;
0a122b
         bs->open_flags |= BDRV_O_NO_BACKING;
0a122b
         error_propagate(errp, local_err);
0a122b
@@ -1051,12 +1051,12 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
0a122b
         bs1 = bdrv_new("");
0a122b
         ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
0a122b
         if (ret < 0) {
0a122b
-            bdrv_delete(bs1);
0a122b
+            bdrv_unref(bs1);
0a122b
             goto fail;
0a122b
         }
0a122b
         total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK;
0a122b
 
0a122b
-        bdrv_delete(bs1);
0a122b
+        bdrv_unref(bs1);
0a122b
 
0a122b
         ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename));
0a122b
         if (ret < 0) {
0a122b
@@ -1137,7 +1137,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
0a122b
     }
0a122b
 
0a122b
     if (bs->file != file) {
0a122b
-        bdrv_delete(file);
0a122b
+        bdrv_unref(file);
0a122b
         file = NULL;
0a122b
     }
0a122b
 
0a122b
@@ -1177,7 +1177,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
0a122b
 
0a122b
 unlink_and_fail:
0a122b
     if (file != NULL) {
0a122b
-        bdrv_delete(file);
0a122b
+        bdrv_unref(file);
0a122b
     }
0a122b
     if (bs->is_temporary) {
0a122b
         unlink(filename);
0a122b
@@ -1444,7 +1444,7 @@ void bdrv_close(BlockDriverState *bs)
0a122b
 
0a122b
     if (bs->drv) {
0a122b
         if (bs->backing_hd) {
0a122b
-            bdrv_delete(bs->backing_hd);
0a122b
+            bdrv_unref(bs->backing_hd);
0a122b
             bs->backing_hd = NULL;
0a122b
         }
0a122b
         bs->drv->bdrv_close(bs);
0a122b
@@ -1469,7 +1469,7 @@ void bdrv_close(BlockDriverState *bs)
0a122b
         bs->options = NULL;
0a122b
 
0a122b
         if (bs->file != NULL) {
0a122b
-            bdrv_delete(bs->file);
0a122b
+            bdrv_unref(bs->file);
0a122b
             bs->file = NULL;
0a122b
         }
0a122b
     }
0a122b
@@ -1667,11 +1667,12 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top)
0a122b
             bs_new->drv ? bs_new->drv->format_name : "");
0a122b
 }
0a122b
 
0a122b
-void bdrv_delete(BlockDriverState *bs)
0a122b
+static void bdrv_delete(BlockDriverState *bs)
0a122b
 {
0a122b
     assert(!bs->dev);
0a122b
     assert(!bs->job);
0a122b
     assert(!bs->in_use);
0a122b
+    assert(!bs->refcnt);
0a122b
 
0a122b
     /* remove from list, if necessary */
0a122b
     bdrv_make_anon(bs);
0a122b
@@ -2247,7 +2248,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
0a122b
     QSIMPLEQ_FOREACH_SAFE(intermediate_state, &states_to_delete, entry, next) {
0a122b
         /* so that bdrv_close() does not recursively close the chain */
0a122b
         intermediate_state->bs->backing_hd = NULL;
0a122b
-        bdrv_delete(intermediate_state->bs);
0a122b
+        bdrv_unref(intermediate_state->bs);
0a122b
     }
0a122b
     ret = 0;
0a122b
 
0a122b
@@ -4989,7 +4990,7 @@ out:
0a122b
     free_option_parameters(param);
0a122b
 
0a122b
     if (bs) {
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
     }
0a122b
     if (error_is_set(&local_err)) {
0a122b
         error_propagate(errp, local_err);
0a122b
diff --git a/block/blkverify.c b/block/blkverify.c
0a122b
index 92a452d..4ff7688 100644
0a122b
--- a/block/blkverify.c
0a122b
+++ b/block/blkverify.c
0a122b
@@ -159,7 +159,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
     ret = bdrv_open(s->test_file, filename, NULL, flags, NULL, &local_err);
0a122b
     if (ret < 0) {
0a122b
         error_propagate(errp, local_err);
0a122b
-        bdrv_delete(s->test_file);
0a122b
+        bdrv_unref(s->test_file);
0a122b
         s->test_file = NULL;
0a122b
         goto fail;
0a122b
     }
0a122b
@@ -173,7 +173,7 @@ static void blkverify_close(BlockDriverState *bs)
0a122b
 {
0a122b
     BDRVBlkverifyState *s = bs->opaque;
0a122b
 
0a122b
-    bdrv_delete(s->test_file);
0a122b
+    bdrv_unref(s->test_file);
0a122b
     s->test_file = NULL;
0a122b
 }
0a122b
 
0a122b
diff --git a/block/cow.c b/block/cow.c
0a122b
index cb9a3b0..909c3e7 100644
0a122b
--- a/block/cow.c
0a122b
+++ b/block/cow.c
0a122b
@@ -360,7 +360,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
0a122b
     }
0a122b
 
0a122b
 exit:
0a122b
-    bdrv_delete(cow_bs);
0a122b
+    bdrv_unref(cow_bs);
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
diff --git a/block/iscsi.c b/block/iscsi.c
0a122b
index fce909b..fa6f7c4 100644
0a122b
--- a/block/iscsi.c
0a122b
+++ b/block/iscsi.c
0a122b
@@ -1576,7 +1576,7 @@ out:
0a122b
     }
0a122b
     g_free(bs->opaque);
0a122b
     bs->opaque = NULL;
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
diff --git a/block/mirror.c b/block/mirror.c
0a122b
index 6fa733e..6843e70 100644
0a122b
--- a/block/mirror.c
0a122b
+++ b/block/mirror.c
0a122b
@@ -480,7 +480,7 @@ immediate_exit:
0a122b
         bdrv_swap(s->target, s->common.bs);
0a122b
     }
0a122b
     bdrv_close(s->target);
0a122b
-    bdrv_delete(s->target);
0a122b
+    bdrv_unref(s->target);
0a122b
     block_job_completed(&s->common, ret);
0a122b
 }
0a122b
 
0a122b
diff --git a/block/qcow.c b/block/qcow.c
0a122b
index 6bc2358..c470e05 100644
0a122b
--- a/block/qcow.c
0a122b
+++ b/block/qcow.c
0a122b
@@ -765,7 +765,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options,
0a122b
     g_free(tmp);
0a122b
     ret = 0;
0a122b
 exit:
0a122b
-    bdrv_delete(qcow_bs);
0a122b
+    bdrv_unref(qcow_bs);
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
diff --git a/block/qcow2.c b/block/qcow2.c
0a122b
index 3f7fd51..f6307af 100644
0a122b
--- a/block/qcow2.c
0a122b
+++ b/block/qcow2.c
0a122b
@@ -1591,7 +1591,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
0a122b
 
0a122b
     ret = 0;
0a122b
 out:
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
diff --git a/block/qed.c b/block/qed.c
0a122b
index 0805ba3..fb8ccd5 100644
0a122b
--- a/block/qed.c
0a122b
+++ b/block/qed.c
0a122b
@@ -607,7 +607,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
0a122b
     ret = 0; /* success */
0a122b
 out:
0a122b
     g_free(l1_table);
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     return ret;
0a122b
 }
0a122b
 
0a122b
diff --git a/block/sheepdog.c b/block/sheepdog.c
0a122b
index 09203ad..b3a2ae8 100644
0a122b
--- a/block/sheepdog.c
0a122b
+++ b/block/sheepdog.c
0a122b
@@ -1451,7 +1451,7 @@ static int sd_prealloc(const char *filename)
0a122b
     }
0a122b
 out:
0a122b
     if (bs) {
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
     }
0a122b
     g_free(buf);
0a122b
 
0a122b
@@ -1534,13 +1534,13 @@ static int sd_create(const char *filename, QEMUOptionParameter *options,
0a122b
 
0a122b
         if (!is_snapshot(&s->inode)) {
0a122b
             error_report("cannot clone from a non snapshot vdi");
0a122b
-            bdrv_delete(bs);
0a122b
+            bdrv_unref(bs);
0a122b
             ret = -EINVAL;
0a122b
             goto out;
0a122b
         }
0a122b
 
0a122b
         base_vid = s->inode.vdi_id;
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
     }
0a122b
 
0a122b
     ret = do_sd_create(s, vdi, vdi_size, base_vid, &vid, 0);
0a122b
diff --git a/block/snapshot.c b/block/snapshot.c
0a122b
index 51b4b96..b2d7681 100644
0a122b
--- a/block/snapshot.c
0a122b
+++ b/block/snapshot.c
0a122b
@@ -99,7 +99,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
0a122b
         ret = bdrv_snapshot_goto(bs->file, snapshot_id);
0a122b
         open_ret = drv->bdrv_open(bs, NULL, bs->open_flags, NULL);
0a122b
         if (open_ret < 0) {
0a122b
-            bdrv_delete(bs->file);
0a122b
+            bdrv_unref(bs->file);
0a122b
             bs->drv = NULL;
0a122b
             return open_ret;
0a122b
         }
0a122b
diff --git a/block/stream.c b/block/stream.c
0a122b
index cbae815..82fb179 100644
0a122b
--- a/block/stream.c
0a122b
+++ b/block/stream.c
0a122b
@@ -68,7 +68,7 @@ static void close_unused_images(BlockDriverState *top, BlockDriverState *base,
0a122b
         unused = intermediate;
0a122b
         intermediate = intermediate->backing_hd;
0a122b
         unused->backing_hd = NULL;
0a122b
-        bdrv_delete(unused);
0a122b
+        bdrv_unref(unused);
0a122b
     }
0a122b
     top->backing_hd = base;
0a122b
 }
0a122b
diff --git a/block/vhdx.c b/block/vhdx.c
0a122b
index 8b1a5c9..1995778 100644
0a122b
--- a/block/vhdx.c
0a122b
+++ b/block/vhdx.c
0a122b
@@ -1847,7 +1847,7 @@ static int vhdx_create(const char *filename, QEMUOptionParameter *options,
0a122b
 
0a122b
 
0a122b
 delete_and_exit:
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
 exit:
0a122b
     g_free(creator);
0a122b
     return ret;
0a122b
diff --git a/block/vmdk.c b/block/vmdk.c
0a122b
index 8662016..a1994a4 100644
0a122b
--- a/block/vmdk.c
0a122b
+++ b/block/vmdk.c
0a122b
@@ -219,7 +219,7 @@ static void vmdk_free_extents(BlockDriverState *bs)
0a122b
         g_free(e->l1_backup_table);
0a122b
         g_free(e->type);
0a122b
         if (e->file != bs->file) {
0a122b
-            bdrv_delete(e->file);
0a122b
+            bdrv_unref(e->file);
0a122b
         }
0a122b
     }
0a122b
     g_free(s->extents);
0a122b
@@ -784,7 +784,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
0a122b
             /* SPARSE extent and VMFSSPARSE extent are both "COWD" sparse file*/
0a122b
             ret = vmdk_open_sparse(bs, extent_file, bs->open_flags, errp);
0a122b
             if (ret) {
0a122b
-                bdrv_delete(extent_file);
0a122b
+                bdrv_unref(extent_file);
0a122b
                 return ret;
0a122b
             }
0a122b
             extent = &s->extents[s->num_extents - 1];
0a122b
@@ -1703,15 +1703,15 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
0a122b
         BlockDriverState *bs = bdrv_new("");
0a122b
         ret = bdrv_open(bs, backing_file, NULL, 0, NULL, errp);
0a122b
         if (ret != 0) {
0a122b
-            bdrv_delete(bs);
0a122b
+            bdrv_unref(bs);
0a122b
             return ret;
0a122b
         }
0a122b
         if (strcmp(bs->drv->format_name, "vmdk")) {
0a122b
-            bdrv_delete(bs);
0a122b
+            bdrv_unref(bs);
0a122b
             return -EINVAL;
0a122b
         }
0a122b
         parent_cid = vmdk_read_cid(bs, 0);
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
         snprintf(parent_desc_line, sizeof(parent_desc_line),
0a122b
                 "parentFileNameHint=\"%s\"", backing_file);
0a122b
     }
0a122b
diff --git a/block/vvfat.c b/block/vvfat.c
0a122b
index 2c7970d..3ddaa0b 100644
0a122b
--- a/block/vvfat.c
0a122b
+++ b/block/vvfat.c
0a122b
@@ -2896,7 +2896,7 @@ static int write_target_commit(BlockDriverState *bs, int64_t sector_num,
0a122b
 
0a122b
 static void write_target_close(BlockDriverState *bs) {
0a122b
     BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque);
0a122b
-    bdrv_delete(s->qcow);
0a122b
+    bdrv_unref(s->qcow);
0a122b
     g_free(s->qcow_filename);
0a122b
 }
0a122b
 
0a122b
@@ -2943,7 +2943,7 @@ static int enable_write_target(BDRVVVFATState *s)
0a122b
     if (ret < 0) {
0a122b
         qerror_report_err(local_err);
0a122b
         error_free(local_err);
0a122b
-        bdrv_delete(s->qcow);
0a122b
+        bdrv_unref(s->qcow);
0a122b
         goto err;
0a122b
     }
0a122b
 
0a122b
diff --git a/blockdev.c b/blockdev.c
0a122b
index 93fb339..564262a 100644
0a122b
--- a/blockdev.c
0a122b
+++ b/blockdev.c
0a122b
@@ -221,7 +221,7 @@ static void drive_uninit(DriveInfo *dinfo)
0a122b
         qemu_opts_del(dinfo->opts);
0a122b
     }
0a122b
 
0a122b
-    bdrv_delete(dinfo->bdrv);
0a122b
+    bdrv_unref(dinfo->bdrv);
0a122b
     g_free(dinfo->id);
0a122b
     QTAILQ_REMOVE(&drives, dinfo, next);
0a122b
     g_free(dinfo->serial);
0a122b
@@ -531,7 +531,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
0a122b
     return dinfo;
0a122b
 
0a122b
 err:
0a122b
-    bdrv_delete(dinfo->bdrv);
0a122b
+    bdrv_unref(dinfo->bdrv);
0a122b
     g_free(dinfo->id);
0a122b
     QTAILQ_REMOVE(&drives, dinfo, next);
0a122b
     g_free(dinfo);
0a122b
@@ -1086,7 +1086,7 @@ static void external_snapshot_abort(BlkTransactionStates *common)
0a122b
     ExternalSnapshotStates *states =
0a122b
                              DO_UPCAST(ExternalSnapshotStates, common, common);
0a122b
     if (states->new_bs) {
0a122b
-        bdrv_delete(states->new_bs);
0a122b
+        bdrv_unref(states->new_bs);
0a122b
     }
0a122b
 }
0a122b
 
0a122b
@@ -1645,7 +1645,7 @@ void qmp_drive_mirror(const char *device, const char *target,
0a122b
     ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv,
0a122b
                     &local_err);
0a122b
     if (ret < 0) {
0a122b
-        bdrv_delete(target_bs);
0a122b
+        bdrv_unref(target_bs);
0a122b
         error_propagate(errp, local_err);
0a122b
         return;
0a122b
     }
0a122b
@@ -1654,7 +1654,7 @@ void qmp_drive_mirror(const char *device, const char *target,
0a122b
                  on_source_error, on_target_error,
0a122b
                  block_job_cb, bs, &local_err);
0a122b
     if (local_err != NULL) {
0a122b
-        bdrv_delete(target_bs);
0a122b
+        bdrv_unref(target_bs);
0a122b
         error_propagate(errp, local_err);
0a122b
         return;
0a122b
     }
0a122b
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
0a122b
index 498f2e9..138ab94 100644
0a122b
--- a/hw/block/xen_disk.c
0a122b
+++ b/hw/block/xen_disk.c
0a122b
@@ -806,7 +806,7 @@ static int blk_connect(struct XenDevice *xendev)
0a122b
                 xen_be_printf(&blkdev->xendev, 0, "error: %s\n",
0a122b
                               error_get_pretty(local_err));
0a122b
                 error_free(local_err);
0a122b
-                bdrv_delete(blkdev->bs);
0a122b
+                bdrv_unref(blkdev->bs);
0a122b
                 blkdev->bs = NULL;
0a122b
             }
0a122b
         }
0a122b
@@ -924,7 +924,7 @@ static void blk_disconnect(struct XenDevice *xendev)
0a122b
             /* close/delete only if we created it ourself */
0a122b
             bdrv_close(blkdev->bs);
0a122b
             bdrv_detach_dev(blkdev->bs, blkdev);
0a122b
-            bdrv_delete(blkdev->bs);
0a122b
+            bdrv_unref(blkdev->bs);
0a122b
         }
0a122b
         blkdev->bs = NULL;
0a122b
     }
0a122b
diff --git a/include/block/block.h b/include/block/block.h
0a122b
index a3b7395..d20d63e 100644
0a122b
--- a/include/block/block.h
0a122b
+++ b/include/block/block.h
0a122b
@@ -182,7 +182,6 @@ BlockDriverState *bdrv_new(const char *device_name);
0a122b
 void bdrv_make_anon(BlockDriverState *bs);
0a122b
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
0a122b
 void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
0a122b
-void bdrv_delete(BlockDriverState *bs);
0a122b
 int bdrv_parse_cache_flags(const char *mode, int *flags);
0a122b
 int bdrv_parse_discard_flags(const char *mode, int *flags);
0a122b
 int bdrv_file_open(BlockDriverState **pbs, const char *filename,
0a122b
diff --git a/qemu-img.c b/qemu-img.c
0a122b
index f0f70e4..bc48dc1 100644
0a122b
--- a/qemu-img.c
0a122b
+++ b/qemu-img.c
0a122b
@@ -305,7 +305,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
0a122b
     return bs;
0a122b
 fail:
0a122b
     if (bs) {
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
     }
0a122b
     return NULL;
0a122b
 }
0a122b
@@ -658,7 +658,7 @@ static int img_check(int argc, char **argv)
0a122b
 
0a122b
 fail:
0a122b
     qapi_free_ImageCheck(check);
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
 
0a122b
     return ret;
0a122b
 }
0a122b
@@ -728,7 +728,7 @@ static int img_commit(int argc, char **argv)
0a122b
         break;
0a122b
     }
0a122b
 
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     if (ret) {
0a122b
         return 1;
0a122b
     }
0a122b
@@ -1110,11 +1110,11 @@ static int img_compare(int argc, char **argv)
0a122b
     ret = 0;
0a122b
 
0a122b
 out:
0a122b
-    bdrv_delete(bs2);
0a122b
+    bdrv_unref(bs2);
0a122b
     qemu_vfree(buf1);
0a122b
     qemu_vfree(buf2);
0a122b
 out2:
0a122b
-    bdrv_delete(bs1);
0a122b
+    bdrv_unref(bs1);
0a122b
 out3:
0a122b
     qemu_progress_end();
0a122b
     return ret;
0a122b
@@ -1595,12 +1595,12 @@ out:
0a122b
     free_option_parameters(param);
0a122b
     qemu_vfree(buf);
0a122b
     if (out_bs) {
0a122b
-        bdrv_delete(out_bs);
0a122b
+        bdrv_unref(out_bs);
0a122b
     }
0a122b
     if (bs) {
0a122b
         for (bs_i = 0; bs_i < bs_n; bs_i++) {
0a122b
             if (bs[bs_i]) {
0a122b
-                bdrv_delete(bs[bs_i]);
0a122b
+                bdrv_unref(bs[bs_i]);
0a122b
             }
0a122b
         }
0a122b
         g_free(bs);
0a122b
@@ -1738,7 +1738,7 @@ static ImageInfoList *collect_image_info_list(const char *filename,
0a122b
         *last = elem;
0a122b
         last = &elem->next;
0a122b
 
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
 
0a122b
         filename = fmt = NULL;
0a122b
         if (chain) {
0a122b
@@ -2024,8 +2024,7 @@ static int img_map(int argc, char **argv)
0a122b
     dump_map_entry(output_format, &curr, NULL);
0a122b
 
0a122b
 out:
0a122b
-    bdrv_close(bs);
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     return ret < 0;
0a122b
 }
0a122b
 
0a122b
@@ -2144,7 +2143,7 @@ static int img_snapshot(int argc, char **argv)
0a122b
     }
0a122b
 
0a122b
     /* Cleanup */
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     if (ret) {
0a122b
         return 1;
0a122b
     }
0a122b
@@ -2428,14 +2427,14 @@ out:
0a122b
     /* Cleanup */
0a122b
     if (!unsafe) {
0a122b
         if (bs_old_backing != NULL) {
0a122b
-            bdrv_delete(bs_old_backing);
0a122b
+            bdrv_unref(bs_old_backing);
0a122b
         }
0a122b
         if (bs_new_backing != NULL) {
0a122b
-            bdrv_delete(bs_new_backing);
0a122b
+            bdrv_unref(bs_new_backing);
0a122b
         }
0a122b
     }
0a122b
 
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     if (ret) {
0a122b
         return 1;
0a122b
     }
0a122b
@@ -2558,7 +2557,7 @@ static int img_resize(int argc, char **argv)
0a122b
     }
0a122b
 out:
0a122b
     if (bs) {
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
     }
0a122b
     if (ret) {
0a122b
         return 1;
0a122b
@@ -2640,7 +2639,7 @@ static int img_amend(int argc, char **argv)
0a122b
 
0a122b
 out:
0a122b
     if (bs) {
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
     }
0a122b
     free_option_parameters(create_options);
0a122b
     free_option_parameters(options_param);
0a122b
diff --git a/qemu-io.c b/qemu-io.c
0a122b
index 64b060c..7e258a5 100644
0a122b
--- a/qemu-io.c
0a122b
+++ b/qemu-io.c
0a122b
@@ -1761,7 +1761,7 @@ static const cmdinfo_t abort_cmd = {
0a122b
 
0a122b
 static int close_f(int argc, char **argv)
0a122b
 {
0a122b
-    bdrv_delete(bs);
0a122b
+    bdrv_unref(bs);
0a122b
     bs = NULL;
0a122b
     return 0;
0a122b
 }
0a122b
@@ -1796,7 +1796,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
0a122b
             fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
0a122b
                     error_get_pretty(local_err));
0a122b
             error_free(local_err);
0a122b
-            bdrv_delete(bs);
0a122b
+            bdrv_unref(bs);
0a122b
             bs = NULL;
0a122b
             return 1;
0a122b
         }
0a122b
@@ -2072,7 +2072,7 @@ int main(int argc, char **argv)
0a122b
     bdrv_drain_all();
0a122b
 
0a122b
     if (bs) {
0a122b
-        bdrv_delete(bs);
0a122b
+        bdrv_unref(bs);
0a122b
     }
0a122b
     return 0;
0a122b
 }
0a122b
-- 
0a122b
1.7.1
0a122b