render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0007-virtio-bus-cleanup-plug-unplug-interface.patch

bacd9b
From e26f88b6280b2386c36d3b3d5ec820deb1ac7749 Mon Sep 17 00:00:00 2001
298366
From: Paolo Bonzini <pbonzini@redhat.com>
298366
Date: Fri, 20 Sep 2013 16:57:53 +0200
298366
Subject: [PATCH] virtio-bus: cleanup plug/unplug interface
298366
298366
Right now we have these pairs:
298366
298366
- virtio_bus_plug_device/virtio_bus_destroy_device.  The first
298366
  takes a VirtIODevice, the second takes a VirtioBusState
298366
298366
- device_plugged/device_unplug callbacks in the VirtioBusClass
298366
  (here it's just the naming that is inconsistent)
298366
298366
- virtio_bus_destroy_device is not called by anyone (and since
298366
  it calls qdev_free, it would be called by the proxies---but
298366
  then the callback is useless since the proxies can do whatever
298366
  they want before calling virtio_bus_destroy_device)
298366
298366
And there is a k->init but no k->exit, hence virtio_device_exit is
298366
overwritten by subclasses (except virtio-9p).  This cleans it up by:
298366
298366
- renaming the device_unplug callback to device_unplugged
298366
298366
- renaming virtio_bus_plug_device to virtio_bus_device_plugged,
298366
  matching the callback name
298366
298366
- renaming virtio_bus_destroy_device to virtio_bus_device_unplugged,
298366
  removing the qdev_free, making it take a VirtIODevice and calling it
298366
  from virtio_device_exit
298366
298366
- adding a k->exit callback
298366
298366
virtio_device_exit is still overwritten, the next patches will fix that.
298366
298366
Cc: qemu-stable@nongnu.org
298366
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
298366
---
298366
 hw/virtio/virtio-bus.c         | 18 +++++++++---------
298366
 hw/virtio/virtio.c             |  7 ++++++-
298366
 include/hw/virtio/virtio-bus.h |  6 +++---
298366
 include/hw/virtio/virtio.h     |  1 +
298366
 4 files changed, 19 insertions(+), 13 deletions(-)
298366
298366
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
45bdef
index 17dd06e..7aed6a4 100644
298366
--- a/hw/virtio/virtio-bus.c
298366
+++ b/hw/virtio/virtio-bus.c
298366
@@ -37,8 +37,8 @@ do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0)
298366
 #define DPRINTF(fmt, ...) do { } while (0)
298366
 #endif
298366
 
298366
-/* Plug the VirtIODevice */
298366
-int virtio_bus_plug_device(VirtIODevice *vdev)
298366
+/* A VirtIODevice is being plugged */
298366
+int virtio_bus_device_plugged(VirtIODevice *vdev)
298366
 {
298366
     DeviceState *qdev = DEVICE(vdev);
298366
     BusState *qbus = BUS(qdev_get_parent_bus(qdev));
298366
@@ -64,20 +64,20 @@ void virtio_bus_reset(VirtioBusState *bus)
298366
     }
298366
 }
298366
 
298366
-/* Destroy the VirtIODevice */
298366
-void virtio_bus_destroy_device(VirtioBusState *bus)
298366
+/* A VirtIODevice is being unplugged */
298366
+void virtio_bus_device_unplugged(VirtIODevice *vdev)
298366
 {
298366
-    BusState *qbus = BUS(bus);
298366
+    DeviceState *qdev = DEVICE(vdev);
298366
+    BusState *qbus = BUS(qdev_get_parent_bus(qdev));
298366
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
298366
     VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
298366
-    VirtIODevice *vdev = virtio_bus_get_device(bus);
298366
 
298366
     DPRINTF("%s: remove device.\n", qbus->name);
298366
 
298366
     if (vdev != NULL) {
298366
-        if (klass->device_unplug != NULL) {
298366
-            klass->device_unplug(qbus->parent);
298366
+        if (klass->device_unplugged != NULL) {
298366
+            klass->device_unplugged(qbus->parent);
298366
         }
45bdef
-        object_unparent(OBJECT(vdev));
298366
     }
298366
 }
298366
 
298366
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
298366
index 2f1e73b..965b2c0 100644
298366
--- a/hw/virtio/virtio.c
298366
+++ b/hw/virtio/virtio.c
298366
@@ -1158,14 +1158,19 @@ static int virtio_device_init(DeviceState *qdev)
298366
     if (k->init(vdev) < 0) {
298366
         return -1;
298366
     }
298366
-    virtio_bus_plug_device(vdev);
298366
+    virtio_bus_device_plugged(vdev);
298366
     return 0;
298366
 }
298366
 
298366
 static int virtio_device_exit(DeviceState *qdev)
298366
 {
298366
     VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
298366
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
298366
 
298366
+    virtio_bus_device_unplugged(vdev);
298366
+    if (k->exit) {
298366
+        k->exit(vdev);
298366
+    }
298366
     if (vdev->bus_name) {
298366
         g_free(vdev->bus_name);
298366
         vdev->bus_name = NULL;
298366
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
298366
index ba0f86a..0756545 100644
298366
--- a/include/hw/virtio/virtio-bus.h
298366
+++ b/include/hw/virtio/virtio-bus.h
298366
@@ -61,7 +61,7 @@ typedef struct VirtioBusClass {
298366
      * transport independent exit function.
298366
      * This is called by virtio-bus just before the device is unplugged.
298366
      */
298366
-    void (*device_unplug)(DeviceState *d);
298366
+    void (*device_unplugged)(DeviceState *d);
298366
     /*
298366
      * Does the transport have variable vring alignment?
298366
      * (ie can it ever call virtio_queue_set_align()?)
298366
@@ -74,9 +74,9 @@ struct VirtioBusState {
298366
     BusState parent_obj;
298366
 };
298366
 
298366
-int virtio_bus_plug_device(VirtIODevice *vdev);
298366
+int virtio_bus_device_plugged(VirtIODevice *vdev);
298366
 void virtio_bus_reset(VirtioBusState *bus);
298366
-void virtio_bus_destroy_device(VirtioBusState *bus);
298366
+void virtio_bus_device_unplugged(VirtIODevice *bus);
298366
 /* Get the device id of the plugged device. */
298366
 uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
298366
 /* Get the config_len field of the plugged device. */
298366
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
298366
index a90522d..59756c2 100644
298366
--- a/include/hw/virtio/virtio.h
298366
+++ b/include/hw/virtio/virtio.h
298366
@@ -127,6 +127,7 @@ typedef struct VirtioDeviceClass {
298366
     /* This is what a VirtioDevice must implement */
298366
     DeviceClass parent;
298366
     int (*init)(VirtIODevice *vdev);
298366
+    void (*exit)(VirtIODevice *vdev);
298366
     uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
298366
     uint32_t (*bad_features)(VirtIODevice *vdev);
298366
     void (*set_features)(VirtIODevice *vdev, uint32_t val);