cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 39ea2d15631b21f962924e88b62e3586e531ac66 Mon Sep 17 00:00:00 2001
0a122b
From: Markus Armbruster <armbru@redhat.com>
0a122b
Date: Thu, 23 Jan 2014 14:03:33 +0100
0a122b
Subject: [PATCH 06/14] virtio-bus: cleanup plug/unplug interface
0a122b
0a122b
RH-Author: Markus Armbruster <armbru@redhat.com>
0a122b
Message-id: <1390485820-7585-4-git-send-email-armbru@redhat.com>
0a122b
Patchwork-id: 56924
0a122b
O-Subject: [PATCH 7.0 qemu-kvm 03/10] virtio-bus: cleanup plug/unplug interface
0a122b
Bugzilla: 983344
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
0a122b
From: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
Right now we have these pairs:
0a122b
0a122b
- virtio_bus_plug_device/virtio_bus_destroy_device.  The first
0a122b
  takes a VirtIODevice, the second takes a VirtioBusState
0a122b
0a122b
- device_plugged/device_unplug callbacks in the VirtioBusClass
0a122b
  (here it's just the naming that is inconsistent)
0a122b
0a122b
- virtio_bus_destroy_device is not called by anyone (and since
0a122b
  it calls qdev_free, it would be called by the proxies---but
0a122b
  then the callback is useless since the proxies can do whatever
0a122b
  they want before calling virtio_bus_destroy_device)
0a122b
0a122b
And there is a k->init but no k->exit, hence virtio_device_exit is
0a122b
overwritten by subclasses (except virtio-9p).  This cleans it up by:
0a122b
0a122b
- renaming the device_unplug callback to device_unplugged
0a122b
0a122b
- renaming virtio_bus_plug_device to virtio_bus_device_plugged,
0a122b
  matching the callback name
0a122b
0a122b
- renaming virtio_bus_destroy_device to virtio_bus_device_unplugged,
0a122b
  removing the qdev_free, making it take a VirtIODevice and calling it
0a122b
  from virtio_device_exit
0a122b
0a122b
- adding a k->exit callback
0a122b
0a122b
virtio_device_exit is still overwritten, the next patches will fix that.
0a122b
0a122b
Cc: qemu-stable@nongnu.org
0a122b
Acked-by: Andreas Faerber <afaerber@suse.de>
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
(cherry picked from commit 5e96f5d2f8d2696ef7d2d8d7282c18fa6023470b)
0a122b
0a122b
Conflicts:
0a122b
	include/hw/virtio/virtio-bus.h
0a122b
0a122b
Trivially conflicts because we lack commit 6ce69d1 "virtio: Support
0a122b
transports which can specify the vring alignment".
0a122b
Signed-off-by: Markus Armbruster <armbru@redhat.com>
0a122b
---
0a122b
 hw/virtio/virtio-bus.c         | 19 +++++++++----------
0a122b
 hw/virtio/virtio.c             |  7 ++++++-
0a122b
 include/hw/virtio/virtio-bus.h |  6 +++---
0a122b
 include/hw/virtio/virtio.h     |  1 +
0a122b
 4 files changed, 19 insertions(+), 14 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 hw/virtio/virtio-bus.c         |   19 +++++++++----------
0a122b
 hw/virtio/virtio.c             |    7 ++++++-
0a122b
 include/hw/virtio/virtio-bus.h |    6 +++---
0a122b
 include/hw/virtio/virtio.h     |    1 +
0a122b
 4 files changed, 19 insertions(+), 14 deletions(-)
0a122b
0a122b
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
0a122b
index 17dd06e..eb77019 100644
0a122b
--- a/hw/virtio/virtio-bus.c
0a122b
+++ b/hw/virtio/virtio-bus.c
0a122b
@@ -37,8 +37,8 @@ do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0)
0a122b
 #define DPRINTF(fmt, ...) do { } while (0)
0a122b
 #endif
0a122b
 
0a122b
-/* Plug the VirtIODevice */
0a122b
-int virtio_bus_plug_device(VirtIODevice *vdev)
0a122b
+/* A VirtIODevice is being plugged */
0a122b
+int virtio_bus_device_plugged(VirtIODevice *vdev)
0a122b
 {
0a122b
     DeviceState *qdev = DEVICE(vdev);
0a122b
     BusState *qbus = BUS(qdev_get_parent_bus(qdev));
0a122b
@@ -64,20 +64,19 @@ void virtio_bus_reset(VirtioBusState *bus)
0a122b
     }
0a122b
 }
0a122b
 
0a122b
-/* Destroy the VirtIODevice */
0a122b
-void virtio_bus_destroy_device(VirtioBusState *bus)
0a122b
+/* A VirtIODevice is being unplugged */
0a122b
+void virtio_bus_device_unplugged(VirtIODevice *vdev)
0a122b
 {
0a122b
-    BusState *qbus = BUS(bus);
0a122b
-    VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
0a122b
-    VirtIODevice *vdev = virtio_bus_get_device(bus);
0a122b
+    DeviceState *qdev = DEVICE(vdev);
0a122b
+    BusState *qbus = BUS(qdev_get_parent_bus(qdev));
0a122b
+    VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(qbus);
0a122b
 
0a122b
     DPRINTF("%s: remove device.\n", qbus->name);
0a122b
 
0a122b
     if (vdev != NULL) {
0a122b
-        if (klass->device_unplug != NULL) {
0a122b
-            klass->device_unplug(qbus->parent);
0a122b
+        if (klass->device_unplugged != NULL) {
0a122b
+            klass->device_unplugged(qbus->parent);
0a122b
         }
0a122b
-        object_unparent(OBJECT(vdev));
0a122b
     }
0a122b
 }
0a122b
 
0a122b
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
0a122b
index a5251cb..b5bb0b6 100644
0a122b
--- a/hw/virtio/virtio.c
0a122b
+++ b/hw/virtio/virtio.c
0a122b
@@ -1118,14 +1118,19 @@ static int virtio_device_init(DeviceState *qdev)
0a122b
     if (k->init(vdev) < 0) {
0a122b
         return -1;
0a122b
     }
0a122b
-    virtio_bus_plug_device(vdev);
0a122b
+    virtio_bus_device_plugged(vdev);
0a122b
     return 0;
0a122b
 }
0a122b
 
0a122b
 static int virtio_device_exit(DeviceState *qdev)
0a122b
 {
0a122b
     VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
0a122b
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
0a122b
 
0a122b
+    virtio_bus_device_unplugged(vdev);
0a122b
+    if (k->exit) {
0a122b
+        k->exit(vdev);
0a122b
+    }
0a122b
     if (vdev->bus_name) {
0a122b
         g_free(vdev->bus_name);
0a122b
         vdev->bus_name = NULL;
0a122b
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
0a122b
index 105ca6d..228c9d7 100644
0a122b
--- a/include/hw/virtio/virtio-bus.h
0a122b
+++ b/include/hw/virtio/virtio-bus.h
0a122b
@@ -61,16 +61,16 @@ typedef struct VirtioBusClass {
0a122b
      * transport independent exit function.
0a122b
      * This is called by virtio-bus just before the device is unplugged.
0a122b
      */
0a122b
-    void (*device_unplug)(DeviceState *d);
0a122b
+    void (*device_unplugged)(DeviceState *d);
0a122b
 } VirtioBusClass;
0a122b
 
0a122b
 struct VirtioBusState {
0a122b
     BusState parent_obj;
0a122b
 };
0a122b
 
0a122b
-int virtio_bus_plug_device(VirtIODevice *vdev);
0a122b
+int virtio_bus_device_plugged(VirtIODevice *vdev);
0a122b
 void virtio_bus_reset(VirtioBusState *bus);
0a122b
-void virtio_bus_destroy_device(VirtioBusState *bus);
0a122b
+void virtio_bus_device_unplugged(VirtIODevice *bus);
0a122b
 /* Get the device id of the plugged device. */
0a122b
 uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus);
0a122b
 /* Get the config_len field of the plugged device. */
0a122b
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
0a122b
index f2aa6a3..cd886c3 100644
0a122b
--- a/include/hw/virtio/virtio.h
0a122b
+++ b/include/hw/virtio/virtio.h
0a122b
@@ -125,6 +125,7 @@ typedef struct VirtioDeviceClass {
0a122b
     /* This is what a VirtioDevice must implement */
0a122b
     DeviceClass parent;
0a122b
     int (*init)(VirtIODevice *vdev);
0a122b
+    void (*exit)(VirtIODevice *vdev);
0a122b
     uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
0a122b
     uint32_t (*bad_features)(VirtIODevice *vdev);
0a122b
     void (*set_features)(VirtIODevice *vdev, uint32_t val);
0a122b
-- 
0a122b
1.7.1
0a122b