76daa3
From 564521b7f134594c3fa42e0e1335f296848ced6a Mon Sep 17 00:00:00 2001
76daa3
From: Max Reitz <mreitz@redhat.com>
76daa3
Date: Fri, 19 May 2017 14:58:00 +0200
76daa3
Subject: [PATCH 27/27] block: Do not unref bs->file on error in BD's open
76daa3
76daa3
RH-Author: Max Reitz <mreitz@redhat.com>
76daa3
Message-id: <20170519145800.28315-2-mreitz@redhat.com>
76daa3
Patchwork-id: 75385
76daa3
O-Subject: [RHV-7.4 qemu-kvm-rhev PATCH 1/1] block: Do not unref bs->file on error in BD's open
76daa3
Bugzilla: 1452752
76daa3
RH-Acked-by: John Snow <jsnow@redhat.com>
76daa3
RH-Acked-by: Fam Zheng <famz@redhat.com>
76daa3
RH-Acked-by: Thomas Huth <thuth@redhat.com>
76daa3
76daa3
The block layer takes care of removing the bs->file child if the block
76daa3
driver's bdrv_open()/bdrv_file_open() implementation fails. The block
76daa3
driver therefore does not need to do so, and indeed should not unless it
76daa3
sets bs->file to NULL afterwards -- because if this is not done, the
76daa3
bdrv_unref_child() in bdrv_open_inherit() will dereference the freed
76daa3
memory block at bs->file afterwards, which is not good.
76daa3
76daa3
We can now decide whether to add a "bs->file = NULL;" after each of the
76daa3
offending bdrv_unref_child() invocations, or just drop them altogether.
76daa3
The latter is simpler, so let's do that.
76daa3
76daa3
Cc: qemu-stable <qemu-stable@nongnu.org>
76daa3
Signed-off-by: Max Reitz <mreitz@redhat.com>
76daa3
Reviewed-by: Eric Blake <eblake@redhat.com>
76daa3
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
76daa3
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
76daa3
(cherry picked from commit de234897b60e034ba94b307fc289e2dc692c9251)
76daa3
Signed-off-by: Max Reitz <mreitz@redhat.com>
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 block/blkdebug.c  | 4 +---
76daa3
 block/blkreplay.c | 3 ---
76daa3
 block/blkverify.c | 3 ---
76daa3
 3 files changed, 1 insertion(+), 9 deletions(-)
76daa3
76daa3
diff --git a/block/blkdebug.c b/block/blkdebug.c
76daa3
index 15a9966..9bd066e 100644
76daa3
--- a/block/blkdebug.c
76daa3
+++ b/block/blkdebug.c
76daa3
@@ -389,14 +389,12 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
76daa3
     } else if (align) {
76daa3
         error_setg(errp, "Invalid alignment");
76daa3
         ret = -EINVAL;
76daa3
-        goto fail_unref;
76daa3
+        goto out;
76daa3
     }
76daa3
 
76daa3
     ret = 0;
76daa3
     goto out;
76daa3
 
76daa3
-fail_unref:
76daa3
-    bdrv_unref_child(bs, bs->file);
76daa3
 out:
76daa3
     if (ret < 0) {
76daa3
         g_free(s->config_file);
76daa3
diff --git a/block/blkreplay.c b/block/blkreplay.c
76daa3
index e110211..6aa5fd4 100755
76daa3
--- a/block/blkreplay.c
76daa3
+++ b/block/blkreplay.c
76daa3
@@ -37,9 +37,6 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
76daa3
 
76daa3
     ret = 0;
76daa3
 fail:
76daa3
-    if (ret < 0) {
76daa3
-        bdrv_unref_child(bs, bs->file);
76daa3
-    }
76daa3
     return ret;
76daa3
 }
76daa3
 
76daa3
diff --git a/block/blkverify.c b/block/blkverify.c
76daa3
index 9a1e21c..af23281 100644
76daa3
--- a/block/blkverify.c
76daa3
+++ b/block/blkverify.c
76daa3
@@ -142,9 +142,6 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
76daa3
 
76daa3
     ret = 0;
76daa3
 fail:
76daa3
-    if (ret < 0) {
76daa3
-        bdrv_unref_child(bs, bs->file);
76daa3
-    }
76daa3
     qemu_opts_del(opts);
76daa3
     return ret;
76daa3
 }
76daa3
-- 
76daa3
1.8.3.1
76daa3