yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qdev-monitor-Set-properties-after-parent-is-assigned.patch

9ae3a8
From b4d1a1c8b3448337e9b5e33706913b82356d22a7 Mon Sep 17 00:00:00 2001
9ae3a8
From: Amos Kong <akong@redhat.com>
9ae3a8
Date: Tue, 11 Mar 2014 23:59:22 +0100
9ae3a8
Subject: [PATCH 1/6] qdev-monitor: Set properties after parent is assigned in device_add
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Amos Kong <akong@redhat.com>
9ae3a8
Message-id: <1394582362-8252-1-git-send-email-akong@redhat.com>
9ae3a8
Patchwork-id: 58081
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH] qdev-monitor: Set properties after parent is assigned in device_add
9ae3a8
Bugzilla: 1046248
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
9ae3a8
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1046248
9ae3a8
Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=7190260
9ae3a8
Upstream: backported from qemu-cpu subtree (qom-next branch)
9ae3a8
          commit bd140cf43d0373cca4c17efaf2ce730cdcbc0c4e
9ae3a8
9ae3a8
Test steps:
9ae3a8
 (qemu) device_add e1000,addr=adsf
9ae3a8
  Property 'e1000.addr' doesn't take value 'adsf'
9ae3a8
 (qemu) info qtree
9ae3a8
  Then qemu crashed.
9ae3a8
9ae3a8
Currently we set a link to the new device from its parent bus, but the
9ae3a8
device hasn't been added to QOM tree yet. When it fails to set properties,
9ae3a8
object_unparent() can't clean up the device.
9ae3a8
9ae3a8
Delay setting of device properties until the device has been added to
9ae3a8
the QOM composition tree. This way, when setting a property fails,
9ae3a8
object_unparent() can clean up the device properly.
9ae3a8
9ae3a8
Signed-off-by: Amos Kong <akong@redhat.com>
9ae3a8
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
Signed-off-by: Andreas Färber <afaerber@suse.de>
9ae3a8
---
9ae3a8
 qdev-monitor.c | 15 +++++++++------
9ae3a8
 1 file changed, 9 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 qdev-monitor.c |   15 +++++++++------
9ae3a8
 1 files changed, 9 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
diff --git a/qdev-monitor.c b/qdev-monitor.c
9ae3a8
index d7b9f04..ee891ea 100644
9ae3a8
--- a/qdev-monitor.c
9ae3a8
+++ b/qdev-monitor.c
9ae3a8
@@ -522,7 +522,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
9ae3a8
         return NULL;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    /* create device, set properties */
9ae3a8
+    /* create device */
9ae3a8
     dev = DEVICE(object_new(driver));
9ae3a8
 
9ae3a8
     if (bus) {
9ae3a8
@@ -533,11 +533,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
9ae3a8
     if (id) {
9ae3a8
         dev->id = id;
9ae3a8
     }
9ae3a8
-    if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) {
9ae3a8
-        object_unparent(OBJECT(dev));
9ae3a8
-        object_unref(OBJECT(dev));
9ae3a8
-        return NULL;
9ae3a8
-    }
9ae3a8
+
9ae3a8
     if (dev->id) {
9ae3a8
         object_property_add_child(qdev_get_peripheral(), dev->id,
9ae3a8
                                   OBJECT(dev), NULL);
9ae3a8
@@ -549,6 +545,13 @@ DeviceState *qdev_device_add(QemuOpts *opts)
9ae3a8
         g_free(name);
9ae3a8
     }
9ae3a8
 
9ae3a8
+    /* set properties */
9ae3a8
+    if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) {
9ae3a8
+        object_unparent(OBJECT(dev));
9ae3a8
+        object_unref(OBJECT(dev));
9ae3a8
+        return NULL;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     dev->opts = opts;
9ae3a8
     object_property_set_bool(OBJECT(dev), true, "realized", &err;;
9ae3a8
     if (err != NULL) {
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8