diff mbox

[RFC,09/14] block: give backing image its own BlockBackend

Message ID 1423710438-14377-10-git-send-email-wency@cn.fujitsu.com
State New
Headers show

Commit Message

Wen Congyang Feb. 12, 2015, 3:07 a.m. UTC
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 block.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Max Reitz Feb. 23, 2015, 9:53 p.m. UTC | #1
On 2015-02-11 at 22:07, Wen Congyang wrote:
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>   block.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)

Our current stance on BlockBackends is (as far as I know, anyway) that a 
BlockBackend always comes with a user. In case you're creating a 
BlockBackend through -drive or blockdev-add, the user is the monitor 
(which can use it to attach it to a device, for instance). In this case, 
there is no user and nobody holds a reference to the BB (other than the 
BDS, but that doesn't count).

Therefore, this patch doesn't look quite right.

Max
diff mbox

Patch

diff --git a/block.c b/block.c
index 2335af1..a7a8932 100644
--- a/block.c
+++ b/block.c
@@ -1218,6 +1218,7 @@  int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
 {
     char *backing_filename = g_malloc0(PATH_MAX);
     int ret = 0;
+    BlockBackend *backing_blk;
     BlockDriverState *backing_hd;
     Error *local_err = NULL;
 
@@ -1255,7 +1256,8 @@  int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
         goto free_exit;
     }
 
-    backing_hd = bdrv_new();
+    backing_blk = blk_hide_new_with_bs();
+    backing_hd = blk_bs(backing_blk);
 
     if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
         qdict_put(options, "driver", qstring_from_str(bs->backing_format));
@@ -1266,7 +1268,8 @@  int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
                     *backing_filename ? backing_filename : NULL, NULL, options,
                     bdrv_backing_flags(bs->open_flags), NULL, &local_err);
     if (ret < 0) {
-        bdrv_unref(backing_hd);
+        blk_unref(backing_blk);
+        backing_blk = NULL;
         backing_hd = NULL;
         bs->open_flags |= BDRV_O_NO_BACKING;
         error_setg(errp, "Could not open backing file: %s",
@@ -1870,9 +1873,9 @@  void bdrv_close(BlockDriverState *bs)
 
     if (bs->drv) {
         if (bs->backing_hd) {
-            BlockDriverState *backing_hd = bs->backing_hd;
+            BlockBackend *backing_blk = bs->backing_hd->blk;
             bdrv_set_backing_hd(bs, NULL);
-            bdrv_unref(backing_hd);
+            blk_unref(backing_blk);
         }
         bs->drv->bdrv_close(bs);
         g_free(bs->opaque);