qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/3] block: keep BlockBackend alive until device fin


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 2/3] block: keep BlockBackend alive until device finalize time
Date: Mon, 22 Feb 2016 15:39:04 +0100

While the next patch will anticipate the death of the DriveInfo
data structure, the BlockBackend must survive after unrealize,
for example in case there are outstanding operations on it.
The good thing is that we can just use reference counting to
do it.

Signed-off-by: Paolo Bonzini <address@hidden>
---
 hw/core/qdev-properties-system.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 469ba8a..5e84b55 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -93,6 +93,7 @@ static void parse_drive(DeviceState *dev, const char *str, 
void **ptr,
         return;
     }
     *ptr = blk;
+    blk_ref(blk);
 }
 
 static void release_drive(Object *obj, const char *name, void *opaque)
@@ -101,13 +102,17 @@ static void release_drive(Object *obj, const char *name, 
void *opaque)
     Property *prop = opaque;
     BlockBackend **ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (*ptr && blk_get_attached_dev(*ptr) != NULL) {
-        /* Unrealize has already called blk_detach_dev and blockdev_del_drive
-         * if the device has been realized; in that case, blk_get_attached_dev
-         * returns NULL.  Thus, we get here if the device failed to realize,
-         * and the -drive must not be released.
-         */
-        blk_detach_dev(*ptr, dev);
+    if (*ptr) {
+        if (blk_get_attached_dev(*ptr) != NULL) {
+            /* Unrealize has already called blk_detach_dev and
+             * blockdev_del_drive if the device has been realized;
+             * in that case, blk_get_attached_dev returns NULL.  Thus,
+             * we get here if the device failed to realize, and the
+             * -drive must not be released.
+             */
+            blk_detach_dev(*ptr, dev);
+        }
+        blk_unref(*ptr);
     }
 }
 
-- 
2.5.0





reply via email to

[Prev in Thread] Current Thread [Next in Thread]