thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
0a122b
From c2d17bffc7268369f912357d7061db65e398432f Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <c2d17bffc7268369f912357d7061db65e398432f.1387288155.git.minovotn@redhat.com>
0a122b
In-Reply-To: <527da6c2ce2c09d0183aa8595fc95f136f61b6df.1387288155.git.minovotn@redhat.com>
0a122b
References: <527da6c2ce2c09d0183aa8595fc95f136f61b6df.1387288155.git.minovotn@redhat.com>
0a122b
From: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
Date: Thu, 12 Dec 2013 16:21:22 +0100
0a122b
Subject: [PATCH 2/8] qdev: Drop misleading qdev_free() function
0a122b
MIME-Version: 1.0
0a122b
Content-Type: text/plain; charset=UTF-8
0a122b
Content-Transfer-Encoding: 8bit
0a122b
0a122b
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
Message-id: <1386865288-1575-3-git-send-email-stefanha@redhat.com>
0a122b
Patchwork-id: 56256
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 2/8] qdev: Drop misleading qdev_free() function
0a122b
Bugzilla: 1003773
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
0a122b
0a122b
The qdev_free() function name is misleading since all the function does
0a122b
is unlink the device from its parent.  The device is not necessarily
0a122b
freed.
0a122b
0a122b
The device will be freed when its QObject refcount reaches zero.  It is
0a122b
usual for the parent (bus) to hold the final reference but there are
0a122b
cases where something else holds a reference so "free" is a misleading
0a122b
name.
0a122b
0a122b
Call object_unparent(obj) directly instead of having a qdev wrapper
0a122b
function.
0a122b
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Signed-off-by: Andreas Färber <afaerber@suse.de>
0a122b
(cherry picked from commit 02a5c4c97422b40034f31265e0f139f7846172a8)
0a122b
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
	hw/scsi/scsi-bus.c
0a122b
	hw/xen/xen_platform.c
0a122b
0a122b
The conflicts are straightforward.
0a122b
---
0a122b
 hw/acpi/piix4.c        |  2 +-
0a122b
 hw/core/qdev.c         | 12 +++---------
0a122b
 hw/pci/pci-hotplug.c   |  2 +-
0a122b
 hw/pci/pci_bridge.c    |  2 +-
0a122b
 hw/pci/pcie.c          |  2 +-
0a122b
 hw/pci/shpc.c          |  2 +-
0a122b
 hw/s390x/virtio-ccw.c  |  2 +-
0a122b
 hw/scsi/scsi-bus.c     |  4 ++--
0a122b
 hw/usb/bus.c           |  7 ++++---
0a122b
 hw/usb/dev-storage.c   |  2 +-
0a122b
 hw/usb/host-legacy.c   |  2 +-
0a122b
 hw/virtio/virtio-bus.c |  4 +---
0a122b
 hw/xen/xen_platform.c  |  2 +-
0a122b
 include/hw/qdev-core.h |  1 -
0a122b
 qdev-monitor.c         |  2 +-
0a122b
 15 files changed, 20 insertions(+), 28 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 hw/acpi/piix4.c        |  2 +-
0a122b
 hw/core/qdev.c         | 12 +++---------
0a122b
 hw/pci/pci-hotplug.c   |  2 +-
0a122b
 hw/pci/pci_bridge.c    |  2 +-
0a122b
 hw/pci/pcie.c          |  2 +-
0a122b
 hw/pci/shpc.c          |  2 +-
0a122b
 hw/s390x/virtio-ccw.c  |  2 +-
0a122b
 hw/scsi/scsi-bus.c     |  4 ++--
0a122b
 hw/usb/bus.c           |  7 ++++---
0a122b
 hw/usb/dev-storage.c   |  2 +-
0a122b
 hw/usb/host-legacy.c   |  2 +-
0a122b
 hw/virtio/virtio-bus.c |  4 +---
0a122b
 hw/xen/xen_platform.c  |  2 +-
0a122b
 include/hw/qdev-core.h |  1 -
0a122b
 qdev-monitor.c         |  2 +-
0a122b
 15 files changed, 20 insertions(+), 28 deletions(-)
0a122b
0a122b
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
0a122b
index d79a7b0..8af97cf 100644
0a122b
--- a/hw/acpi/piix4.c
0a122b
+++ b/hw/acpi/piix4.c
0a122b
@@ -315,7 +315,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
0a122b
             if (pc->no_hotplug) {
0a122b
                 slot_free = false;
0a122b
             } else {
0a122b
-                qdev_free(qdev);
0a122b
+                object_unparent(OBJECT(qdev));
0a122b
             }
0a122b
         }
0a122b
     }
0a122b
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
0a122b
index 9190a7e..70a0dee 100644
0a122b
--- a/hw/core/qdev.c
0a122b
+++ b/hw/core/qdev.c
0a122b
@@ -164,7 +164,7 @@ int qdev_init(DeviceState *dev)
0a122b
     if (local_err != NULL) {
0a122b
         qerror_report_err(local_err);
0a122b
         error_free(local_err);
0a122b
-        qdev_free(dev);
0a122b
+        object_unparent(OBJECT(dev));
0a122b
         return -1;
0a122b
     }
0a122b
     return 0;
0a122b
@@ -258,7 +258,7 @@ void qbus_reset_all_fn(void *opaque)
0a122b
 int qdev_simple_unplug_cb(DeviceState *dev)
0a122b
 {
0a122b
     /* just zap it */
0a122b
-    qdev_free(dev);
0a122b
+    object_unparent(OBJECT(dev));
0a122b
     return 0;
0a122b
 }
0a122b
 
0a122b
@@ -280,12 +280,6 @@ void qdev_init_nofail(DeviceState *dev)
0a122b
     }
0a122b
 }
0a122b
 
0a122b
-/* Unlink device from bus and free the structure.  */
0a122b
-void qdev_free(DeviceState *dev)
0a122b
-{
0a122b
-    object_unparent(OBJECT(dev));
0a122b
-}
0a122b
-
0a122b
 void qdev_machine_creation_done(void)
0a122b
 {
0a122b
     /*
0a122b
@@ -458,7 +452,7 @@ static void bus_unparent(Object *obj)
0a122b
 
0a122b
     while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
0a122b
         DeviceState *dev = kid->child;
0a122b
-        qdev_free(dev);
0a122b
+        object_unparent(OBJECT(dev));
0a122b
     }
0a122b
     if (bus->parent) {
0a122b
         QLIST_REMOVE(bus, sibling);
0a122b
diff --git a/hw/pci/pci-hotplug.c b/hw/pci/pci-hotplug.c
0a122b
index c708752..667e40c 100644
0a122b
--- a/hw/pci/pci-hotplug.c
0a122b
+++ b/hw/pci/pci-hotplug.c
0a122b
@@ -224,7 +224,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
0a122b
         }
0a122b
         dev = pci_create(bus, devfn, "virtio-blk-pci");
0a122b
         if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
0a122b
-            qdev_free(&dev->qdev);
0a122b
+            object_unparent(OBJECT(dev));
0a122b
             dev = NULL;
0a122b
             break;
0a122b
         }
0a122b
diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
0a122b
index 3897bd8..a786f26 100644
0a122b
--- a/hw/pci/pci_bridge.c
0a122b
+++ b/hw/pci/pci_bridge.c
0a122b
@@ -386,7 +386,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
0a122b
     pci_bridge_region_cleanup(s, s->windows);
0a122b
     memory_region_destroy(&s->address_space_mem);
0a122b
     memory_region_destroy(&s->address_space_io);
0a122b
-    /* qbus_free() is called automatically by qdev_free() */
0a122b
+    /* qbus_free() is called automatically during device deletion */
0a122b
 }
0a122b
 
0a122b
 /*
0a122b
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
0a122b
index 62bd0b8..4b84443 100644
0a122b
--- a/hw/pci/pcie.c
0a122b
+++ b/hw/pci/pcie.c
0a122b
@@ -251,7 +251,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
0a122b
                                    PCI_EXP_SLTSTA_PDS);
0a122b
         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
0a122b
     } else {
0a122b
-        qdev_free(&pci_dev->qdev);
0a122b
+        object_unparent(OBJECT(pci_dev));
0a122b
         pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
0a122b
                                      PCI_EXP_SLTSTA_PDS);
0a122b
         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
0a122b
diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
0a122b
index d35c2ee..1e57952 100644
0a122b
--- a/hw/pci/shpc.c
0a122b
+++ b/hw/pci/shpc.c
0a122b
@@ -254,7 +254,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
0a122b
          ++devfn) {
0a122b
         PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
0a122b
         if (affected_dev) {
0a122b
-            qdev_free(&affected_dev->qdev);
0a122b
+            object_unparent(OBJECT(affected_dev));
0a122b
         }
0a122b
     }
0a122b
 }
0a122b
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
0a122b
index d981101..7ba1376 100644
0a122b
--- a/hw/s390x/virtio-ccw.c
0a122b
+++ b/hw/s390x/virtio-ccw.c
0a122b
@@ -1036,7 +1036,7 @@ static int virtio_ccw_busdev_unplug(DeviceState *dev)
0a122b
 
0a122b
     css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
0a122b
 
0a122b
-    qdev_free(dev);
0a122b
+    object_unparent(OBJECT(dev));
0a122b
     return 0;
0a122b
 }
0a122b
 
0a122b
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
0a122b
index 9082ea7..6733c1a 100644
0a122b
--- a/hw/scsi/scsi-bus.c
0a122b
+++ b/hw/scsi/scsi-bus.c
0a122b
@@ -178,7 +178,7 @@ static int scsi_qdev_init(DeviceState *qdev)
0a122b
         d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
0a122b
         assert(d);
0a122b
         if (d->lun == dev->lun && dev != d) {
0a122b
-            qdev_free(&d->qdev);
0a122b
+            object_unparent(OBJECT(d));
0a122b
         }
0a122b
     }
0a122b
 
0a122b
@@ -229,7 +229,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
0a122b
         qdev_prop_set_string(dev, "serial", serial);
0a122b
     }
0a122b
     if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
0a122b
-        qdev_free(dev);
0a122b
+        object_unparent(OBJECT(dev));
0a122b
         return NULL;
0a122b
     }
0a122b
     if (qdev_init(dev) < 0)
0a122b
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
0a122b
index f83d1de..ade9abc 100644
0a122b
--- a/hw/usb/bus.c
0a122b
+++ b/hw/usb/bus.c
0a122b
@@ -351,8 +351,9 @@ void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
0a122b
 
0a122b
 void usb_unregister_port(USBBus *bus, USBPort *port)
0a122b
 {
0a122b
-    if (port->dev)
0a122b
-        qdev_free(&port->dev->qdev);
0a122b
+    if (port->dev) {
0a122b
+        object_unparent(OBJECT(port->dev));
0a122b
+    }
0a122b
     QTAILQ_REMOVE(&bus->free, port, next);
0a122b
     bus->nfree--;
0a122b
 }
0a122b
@@ -500,7 +501,7 @@ int usb_device_delete_addr(int busnr, int addr)
0a122b
         return -1;
0a122b
     dev = port->dev;
0a122b
 
0a122b
-    qdev_free(&dev->qdev);
0a122b
+    object_unparent(OBJECT(dev));
0a122b
     return 0;
0a122b
 }
0a122b
 
0a122b
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
0a122b
index 44a0e34..f60b048 100644
0a122b
--- a/hw/usb/dev-storage.c
0a122b
+++ b/hw/usb/dev-storage.c
0a122b
@@ -699,7 +699,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
0a122b
         return NULL;
0a122b
     }
0a122b
     if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
0a122b
-        qdev_free(&dev->qdev);
0a122b
+        object_unparent(OBJECT(dev));
0a122b
         return NULL;
0a122b
     }
0a122b
     if (qdev_init(&dev->qdev) < 0)
0a122b
diff --git a/hw/usb/host-legacy.c b/hw/usb/host-legacy.c
0a122b
index 3a5f705..3cc9c42 100644
0a122b
--- a/hw/usb/host-legacy.c
0a122b
+++ b/hw/usb/host-legacy.c
0a122b
@@ -132,7 +132,7 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
0a122b
     return dev;
0a122b
 
0a122b
 fail:
0a122b
-    qdev_free(&dev->qdev);
0a122b
+    object_unparent(OBJECT(dev));
0a122b
     return NULL;
0a122b
 }
0a122b
 
0a122b
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
0a122b
index 6849a01..e6b103c 100644
0a122b
--- a/hw/virtio/virtio-bus.c
0a122b
+++ b/hw/virtio/virtio-bus.c
0a122b
@@ -67,7 +67,6 @@ void virtio_bus_reset(VirtioBusState *bus)
0a122b
 /* Destroy the VirtIODevice */
0a122b
 void virtio_bus_destroy_device(VirtioBusState *bus)
0a122b
 {
0a122b
-    DeviceState *qdev;
0a122b
     BusState *qbus = BUS(bus);
0a122b
     VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
0a122b
     DPRINTF("%s: remove device.\n", qbus->name);
0a122b
@@ -76,8 +75,7 @@ void virtio_bus_destroy_device(VirtioBusState *bus)
0a122b
         if (klass->device_unplug != NULL) {
0a122b
             klass->device_unplug(qbus->parent);
0a122b
         }
0a122b
-        qdev = DEVICE(bus->vdev);
0a122b
-        qdev_free(qdev);
0a122b
+        object_unparent(OBJECT(bus->vdev));
0a122b
         bus->vdev = NULL;
0a122b
     }
0a122b
 }
0a122b
diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c
0a122b
index bb9d0cd..98fe405 100644
0a122b
--- a/hw/xen/xen_platform.c
0a122b
+++ b/hw/xen/xen_platform.c
0a122b
@@ -88,7 +88,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
0a122b
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
0a122b
             PCI_CLASS_NETWORK_ETHERNET
0a122b
             && strcmp(d->name, "xen-pci-passthrough") != 0) {
0a122b
-        qdev_free(&d->qdev);
0a122b
+        object_unparent(OBJECT(d));
0a122b
     }
0a122b
 }
0a122b
 
0a122b
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
0a122b
index 44feb54..ad39ea9 100644
0a122b
--- a/include/hw/qdev-core.h
0a122b
+++ b/include/hw/qdev-core.h
0a122b
@@ -232,7 +232,6 @@ void qdev_init_nofail(DeviceState *dev);
0a122b
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
0a122b
                                  int required_for_version);
0a122b
 void qdev_unplug(DeviceState *dev, Error **errp);
0a122b
-void qdev_free(DeviceState *dev);
0a122b
 int qdev_simple_unplug_cb(DeviceState *dev);
0a122b
 void qdev_machine_creation_done(void);
0a122b
 bool qdev_machine_modified(void);
0a122b
diff --git a/qdev-monitor.c b/qdev-monitor.c
0a122b
index 9d4f61d..f78ff64 100644
0a122b
--- a/qdev-monitor.c
0a122b
+++ b/qdev-monitor.c
0a122b
@@ -521,7 +521,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
0a122b
         qdev->id = id;
0a122b
     }
0a122b
     if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
0a122b
-        qdev_free(qdev);
0a122b
+        object_unparent(OBJECT(qdev));
0a122b
         object_unref(OBJECT(qdev));
0a122b
         return NULL;
0a122b
     }
0a122b
-- 
0a122b
1.7.11.7
0a122b