qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/61] Virtio refactoring.
@ 2013-01-07 18:40 fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus fred.konrad
                   ` (63 more replies)
  0 siblings, 64 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here is the full series for virtio-refactoring.

You can clone that from here :
git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring

virtio-mmio parts is not included but you can clone them from here :
git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_mmio

I think that the old VirtioBindings can be fixed later as nothing use interface
now and I didn't find any example in the code.

Also I didn't try all the devices.

Thanks,

Fred

Changes between v9:
    * Refactored all the remaining devices with the same way as virtio-blk.
    * Moved the virtio device's structure in the header.
    * Fixed the init with only one allocation.
    * Fixed the indentation and code style errors.
    * s390 device's are refactored the same way as pci one.
    * Moved max_dev from BusState to BusClass.

Changes v8 -> v9:
    * Modified virtio-bus.c function name. (virtio_device_ prefix.)
    * Removed qdev_create(..) in virtio-blk-x, object_new
      + object_property_add_child used instead.

Changes v7 -> v8:
    * Moved virtio-blk-pci PCI IDs to "Add the virtio-blk device.".
    * virtio : Added virtio_device_init which init children and plug the device.
    * virtio : Added virtio_common_cleanup in the same way as
      virtio_common_init.
    * virtio-blk : Moved virtio_plug_device to virtio-device init.
    * virtio-blk : Inline the virtio_blk_exit function in
      virtio_blk_device_exit and use virtio_common_cleanup.
    * virtio-s390-bus : Added virtio-s390-bus.
    * virtio-s390-device : Added a virtio-s390-bus.
    * virtio-blk-s390 : Switched to the new API.
    * virtio : removed function pointer.
    * virtio : removed VirtinBindings.
    * virtio : cleaned up init and exit function.

Changes v6 -> v7:
    * virtio-bus : Added virtio-bus-reset.
    * virtio-pci : Fixed virtio-pci-exit.
    * virtio-pci : Added virtio-pci-rst.
    * virtio-pci : Added VirtioPCIClass filled with an init function.
    * virtio-blk : Added virtio_blk_set_conf.
    * virtio-blk : QOM casts.
    * virtio-blk-pci : Switched to the new API.

Changes v5 -> v6:
    * Renamed virtio_common_init_ to virtio_init, modify virtio_common_init to
      allocate and call virtio_init. Drop the unused structure size parameters.
    * Renamed init/exit callback in VirtioBusClass.
    * Renamed virtio_blk_init virtio_blk_common_init.
    * Modified virtio_blk_init to call virtio_blk_common_init.

Changes v4 -> v5:
    * use ERROR_CLASS_GENERIC_ERROR in place of creating a new error type for
      the maximum device limitation. ( Peter )
    * Removed bus_in_use function. We assume that the virtio-bus is not in use,
      when plugin in. ( Peter )
    * Added virtio_bus_destroy_device().
    * Implemented the exit function of virtio-pci.
    * Implemented the init callback for virtio-pci ( must be modified, it still
      access vdev directly. ).
    * Implemented the exit callback for virtio-pci.
    * Started virtio-device refactoring.
    * Started virtio-blk refactoring. 

Changes v3 -> v4:
    * Added virtio-bus.o in Makefile.objs ( accidentally dropped from v3 ).
    * *const* TypeInfo in virtio-bus.
    * Introduced virtio-pci-bus.
    * Reintroduced virtio-pci.
    * Introduced virtio-device.
    * Started virtio-blk refactoring.
    * Added an error type in qerror.h for the "bus full" error.

Changes v2 -> v3:
    * Added VirtioBusClass.
    * Renamed VirtioBus -> VirtioBusState.
    * Renamed qbus -> parent_obj.
    * Plug the device only in a non-full bus.

Changes v1 -> v2:
    * All the little fix you suggest ( License, Debug printf, naming convention,
      ...)
    * Added get_virtio_device_id(), and remove the pci_id* from the VirtioBus
      structure.
    * Added virtio_bus_reset().
    * Added cast macros VIRTIO_BUS.
    * Added virtio_bus_plug_device.
    * Replaced the old-style "bus->qbus" by BUS() macro.

KONRAD Frederic (61):
  qdev : add a maximum device allowed field for the bus.
  virtio-bus : introduce virtio-bus
  virtio-pci-bus : introduce virtio-pci-bus.
  virtio-pci : refactor virtio-pci device.
  virtio-device : refactor virtio-device.
  virtio-s390-bus : add virtio-s390-bus.
  virtio-s390-device : create a virtio-s390-bus during init.
  virtio-blk : show VirtIOBlock structure.
  virtio-blk : don't use pointer for configuration.
  virtio-blk : add the virtio-blk device.
  virtio-blk-pci : switch to new API.
  virtio-blk-s390 : switch to the new API.
  virtio-blk : cleanup : use QOM cast.
  virtio-blk : cleanup : remove qdev field.
  virtio-net : show the VirtIONet structure.
  virtio-net : add the virtio-net device.
  virtio-net-pci : switch to the new API.
  virtio-net-s390 : switch to the new API.
  virtio-net : cleanup : use QOM cast.
  virtio-net : cleanup : init and exit function.
  virtio-net : cleanup : remove qdev field.
  virtio-scsi : show the VirtIOSCSI structure.
  virtio-scsi : don't use pointer for configuration.
  virtio-scsi : allocate cmd_vqs array separately.
  virtio-scsi : moving host_features from properties to transport
    properties.
  virtio-scsi : add the virtio-scsi device.
  virtio-scsi-pci : switch to new API.
  virtio-scsi-s390 : switch to the new API.
  virtio-scsi : cleanup : use QOM casts.
  virtio-scsi : cleanup : init and exit functions.
  virtio-scsi : cleanup : remove qdev field.
  virtio-balloon : show the VirtIOBalloon structure.
  virtio-balloon : add the virtio-balloon device.
  virtio-balloon-pci : switch to the new API.
  virtio-balloon : cleanup : init and exit function.
  virtio-balloon : cleanup : QOM casts.
  virtio-balloon : cleanup : remove qdev field.
  virtio-rng : show the VirtIORNG structure.
  virtio-rng : don't use pointer for configuration.
  virtio-rng : add virtio-rng device.
  virtio-rng-s390 : switch to the new API.
  virtio-rng-pci : switch to the new API.
  virtio-rng.c : cleanup : init and exit functions.
  virtio-rng.c : cleanup : remove qdev field.
  virtio-rng.c : cleanup : use QOM casts.
  virtio-serial : show structures.
  virtio-serial : add the virtio-serial device.
  virtio-serial-pci : switch to the new API.
  virtio-serial-s390 : switch to the new API.
  virtio-serial : cleanup : init and exit functions.
  virtio-serial : cleanup : use QOM casts.
  virtio-serial : cleanup : remove qdev field.
  virtio-9p : add the virtio-9p device.
  virtio-9p-pci : switch to the new API.
  virtio-9p : cleanup : init function.
  virtio-9p : cleanup : QOM casts.
  virtio : remove the function pointer.
  virtio-pci : cleanup : init, exit and reset functions.
  s390-virtio-bus : cleanup
  virtio : remove virtiobindings.
  virtio : cleanup : init and exit function.

 hw/9pfs/virtio-9p-device.c | 144 ++++++----
 hw/9pfs/virtio-9p.c        |   2 +-
 hw/9pfs/virtio-9p.h        |  27 +-
 hw/Makefile.objs           |   1 +
 hw/qdev-core.h             |   2 +
 hw/qdev-monitor.c          |  12 +
 hw/s390-virtio-bus.c       | 221 +++++++++------
 hw/s390-virtio-bus.h       |  78 ++++-
 hw/vhost.c                 |  38 ++-
 hw/virtio-balloon.c        | 111 ++++----
 hw/virtio-balloon.h        |  14 +
 hw/virtio-blk.c            | 148 +++++-----
 hw/virtio-blk.h            |  42 +++
 hw/virtio-bus.c            | 161 +++++++++++
 hw/virtio-bus.h            |  94 +++++++
 hw/virtio-net.c            | 270 +++++++++---------
 hw/virtio-net.h            |  58 ++++
 hw/virtio-pci.c            | 689 +++++++++++++++++++++++++--------------------
 hw/virtio-pci.h            | 131 ++++++++-
 hw/virtio-rng.c            | 143 ++++++----
 hw/virtio-rng.h            |  33 +++
 hw/virtio-scsi.c           | 139 +++++----
 hw/virtio-scsi.h           |  31 +-
 hw/virtio-serial-bus.c     | 199 +++++++------
 hw/virtio-serial.h         |  50 ++++
 hw/virtio.c                | 156 ++++++----
 hw/virtio.h                |  52 ++--
 27 files changed, 2018 insertions(+), 1028 deletions(-)
 create mode 100644 hw/virtio-bus.c
 create mode 100644 hw/virtio-bus.h

-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-08 17:05   ` Peter Maydell
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 02/61] virtio-bus : introduce virtio-bus fred.konrad
                   ` (62 subsequent siblings)
  63 siblings, 1 reply; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Add a max_dev field to BusClass to specify the maximum amount of devices allowed
on the bus ( have no effect if max_dev=0 )

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/qdev-core.h    |  2 ++
 hw/qdev-monitor.c | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index fdf14ec..8bcaeac 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -87,6 +87,8 @@ struct BusClass {
      */
     char *(*get_fw_dev_path)(DeviceState *dev);
     int (*reset)(BusState *bus);
+    /* maximum devices allowed on the bus, 0 : no limit. */
+    int max_dev;
 };
 
 typedef struct BusChild {
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index b739867..9e9d840 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -283,6 +283,7 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
 static BusState *qbus_find_recursive(BusState *bus, const char *name,
                                      const char *bus_typename)
 {
+    BusClass *bus_class = BUS_GET_CLASS(bus);
     BusChild *kid;
     BusState *child, *ret;
     int match = 1;
@@ -293,6 +294,17 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
     if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
         match = 0;
     }
+    if ((bus_class->max_dev != 0) && (bus_class->max_dev <= bus->max_index)) {
+        if (name != NULL) {
+            /* bus was explicitly specified : return an error. */
+            qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
+                          bus->name);
+            return NULL;
+        } else {
+            /* bus was not specified : try to find another one. */
+            match = 0;
+        }
+    }
     if (match) {
         return bus;
     }
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 02/61] virtio-bus : introduce virtio-bus
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-08 17:09   ` Peter Maydell
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus fred.konrad
                   ` (61 subsequent siblings)
  63 siblings, 1 reply; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Introduce virtio-bus. Refactored transport device will create a bus which
extends virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/Makefile.objs |   1 +
 hw/virtio-bus.c  | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-bus.h  |  98 ++++++++++++++++++++++++++++++
 3 files changed, 277 insertions(+)
 create mode 100644 hw/virtio-bus.c
 create mode 100644 hw/virtio-bus.h

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index b8bbed3..6011a66 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -3,6 +3,7 @@ common-obj-y += loader.o
 common-obj-$(CONFIG_VIRTIO) += virtio-console.o
 common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
 common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
+common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
 common-obj-y += fw_cfg.o
 common-obj-$(CONFIG_PCI) += pci_bridge_dev.o
 common-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
new file mode 100644
index 0000000..c5e67b0
--- /dev/null
+++ b/hw/virtio-bus.c
@@ -0,0 +1,178 @@
+/*
+ * VirtioBus
+ *
+ *  Copyright (C) 2012 : GreenSocs Ltd
+ *      http://www.greensocs.com/ , email: info@greensocs.com
+ *
+ *  Developed by :
+ *  Frederic Konrad   <fred.konrad@greensocs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "hw.h"
+#include "qemu/error-report.h"
+#include "qdev.h"
+#include "virtio-bus.h"
+#include "virtio.h"
+
+/* #define DEBUG_VIRTIO_BUS */
+
+#ifdef DEBUG_VIRTIO_BUS
+#define DPRINTF(fmt, ...) \
+do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) do { } while (0)
+#endif
+
+/* Plug the VirtIODevice */
+int virtio_bus_plug_device(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    BusState *qbus = BUS(qdev_get_parent_bus(qdev));
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
+    VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
+    DPRINTF("%s : plug device.\n", qbus->name);
+
+    bus->vdev = vdev;
+
+    /*
+     * The lines below will disappear when we drop VirtIOBindings, at the end
+     * of the series.
+     */
+    bus->bindings.notify = klass->notify;
+    bus->bindings.save_config = klass->save_config;
+    bus->bindings.save_queue = klass->save_queue;
+    bus->bindings.load_config = klass->load_config;
+    bus->bindings.load_queue = klass->load_queue;
+    bus->bindings.load_done = klass->load_done;
+    bus->bindings.get_features = klass->get_features;
+    bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
+    bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
+    bus->bindings.set_host_notifier = klass->set_host_notifier;
+    bus->bindings.vmstate_change = klass->vmstate_change;
+    virtio_bind_device(bus->vdev, &bus->bindings, qbus->parent);
+
+    if (klass->device_plugged != NULL) {
+        klass->device_plugged(qbus->parent);
+    }
+
+    return 0;
+}
+
+/* Reset the virtio_bus */
+void virtio_bus_reset(VirtioBusState *bus)
+{
+    DPRINTF("%s : reset device.\n", qbus->name);
+    if (bus->vdev != NULL) {
+        virtio_reset(bus->vdev);
+    }
+}
+
+/* Destroy the VirtIODevice */
+void virtio_bus_destroy_device(VirtioBusState *bus)
+{
+    DeviceState *qdev;
+    BusState *qbus = BUS(bus);
+    VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
+    DPRINTF("%s : remove device.\n", qbus->name);
+
+    if (bus->vdev != NULL) {
+        if (klass->device_unplug != NULL) {
+            klass->device_unplug(qbus->parent);
+        }
+        qdev = DEVICE(bus->vdev);
+        qdev_free(qdev);
+        bus->vdev = NULL;
+    }
+}
+
+/* Get the device id of the plugged device. */
+uint16_t virtio_device_get_id(VirtioBusState *bus)
+{
+    assert(bus->vdev != NULL);
+    return bus->vdev->device_id;
+}
+
+/* Get the nvectors field of the plugged device. */
+int virtio_device_get_nvectors(VirtioBusState *bus)
+{
+    assert(bus->vdev != NULL);
+    return bus->vdev->nvectors;
+}
+
+/* Set the nvectors field of the plugged device. */
+void virtio_device_set_nvectors(VirtioBusState *bus, int nvectors)
+{
+    assert(bus->vdev != NULL);
+    bus->vdev->nvectors = nvectors;
+}
+
+/* Get the config_len field of the plugged device. */
+size_t virtio_device_get_config_len(VirtioBusState *bus)
+{
+    assert(bus->vdev != NULL);
+    return bus->vdev->config_len;
+}
+
+/* Get the features of the plugged device. */
+uint32_t virtio_device_get_features(VirtioBusState *bus,
+                                    uint32_t requested_features)
+{
+    VirtioDeviceClass *k;
+    assert(bus->vdev != NULL);
+    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
+    assert(k->get_features != NULL);
+    return k->get_features(bus->vdev, requested_features);
+}
+
+/* Get bad features of the plugged device. */
+uint32_t virtio_device_get_bad_features(VirtioBusState *bus)
+{
+    VirtioDeviceClass *k;
+    assert(bus->vdev != NULL);
+    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
+    if (k->bad_features != NULL) {
+        return k->bad_features(bus->vdev);
+    } else {
+        return 0;
+    }
+}
+
+/* Get config of the plugged device. */
+void virtio_device_get_config(VirtioBusState *bus, uint8_t *config)
+{
+    VirtioDeviceClass *k;
+    assert(bus->vdev != NULL);
+    k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
+    if (k->get_config != NULL) {
+        k->get_config(bus->vdev, config);
+    }
+}
+
+static const TypeInfo virtio_bus_info = {
+    .name = TYPE_VIRTIO_BUS,
+    .parent = TYPE_BUS,
+    .instance_size = sizeof(VirtioBusState),
+    .abstract = true,
+    .class_size = sizeof(VirtioBusClass),
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_bus_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
new file mode 100644
index 0000000..7bea64a
--- /dev/null
+++ b/hw/virtio-bus.h
@@ -0,0 +1,98 @@
+/*
+ * VirtioBus
+ *
+ *  Copyright (C) 2012 : GreenSocs Ltd
+ *      http://www.greensocs.com/ , email: info@greensocs.com
+ *
+ *  Developed by :
+ *  Frederic Konrad   <fred.konrad@greensocs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef VIRTIO_BUS_H
+#define VIRTIO_BUS_H
+
+#include "qdev.h"
+#include "sysemu/sysemu.h"
+#include "virtio.h"
+
+#define TYPE_VIRTIO_BUS "virtio-bus"
+#define VIRTIO_BUS_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
+#define VIRTIO_BUS_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
+#define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
+
+typedef struct VirtioBusState VirtioBusState;
+
+typedef struct VirtioBusClass {
+    /* This is what a VirtioBus must implement */
+    BusClass parent;
+    void (*notify)(DeviceState *d, uint16_t vector);
+    void (*save_config)(DeviceState *d, QEMUFile *f);
+    void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
+    int (*load_config)(DeviceState *d, QEMUFile *f);
+    int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
+    int (*load_done)(DeviceState *d, QEMUFile *f);
+    unsigned (*get_features)(DeviceState *d);
+    bool (*query_guest_notifiers)(DeviceState *d);
+    int (*set_guest_notifiers)(DeviceState *d, bool assigned);
+    int (*set_host_notifier)(DeviceState *d, int n, bool assigned);
+    void (*vmstate_change)(DeviceState *d, bool running);
+    /*
+     * transport independent init function.
+     * This is called by virtio-bus just after the device is plugged.
+     */
+    void (*device_plugged)(DeviceState *d);
+    /*
+     * transport independent exit function.
+     * This is called by virtio-bus just before the device is unplugged.
+     */
+    void (*device_unplug)(DeviceState *d);
+} VirtioBusClass;
+
+struct VirtioBusState {
+    BusState parent_obj;
+    /*
+     * Only one VirtIODevice can be plugged on the bus.
+     */
+    VirtIODevice *vdev;
+    /*
+     * This will be removed at the end of the series.
+     */
+    VirtIOBindings bindings;
+};
+
+int virtio_bus_plug_device(VirtIODevice *vdev);
+void virtio_bus_reset(VirtioBusState *bus);
+void virtio_bus_destroy_device(VirtioBusState *bus);
+/* Get the device id of the plugged device. */
+uint16_t virtio_device_get_id(VirtioBusState *bus);
+/* Get the nvectors field of the plugged device. */
+int virtio_device_get_nvectors(VirtioBusState *bus);
+/* Set the nvectors field of the plugged device. */
+void virtio_device_set_nvectors(VirtioBusState *bus, int nvectors);
+/* Get the config_len field of the plugged device. */
+size_t virtio_device_get_config_len(VirtioBusState *bus);
+/* Get the features of the plugged device. */
+uint32_t virtio_device_get_features(VirtioBusState *bus,
+                                    uint32_t requested_features);
+/* Get bad features of the plugged device. */
+uint32_t virtio_device_get_bad_features(VirtioBusState *bus);
+/* Get config of the plugged device. */
+void virtio_device_get_config(VirtioBusState *bus, uint8_t *config);
+
+#endif /* VIRTIO_BUS_H */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 02/61] virtio-bus : introduce virtio-bus fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-08 18:08   ` Peter Maydell
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device fred.konrad
                   ` (60 subsequent siblings)
  63 siblings, 1 reply; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci
transport device.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h | 18 ++++++++++++++++--
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index c7f0c4d..5ff03e8 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -31,6 +31,7 @@
 #include "sysemu/blockdev.h"
 #include "virtio-pci.h"
 #include "qemu/range.h"
+#include "virtio-bus.h"
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -1162,6 +1163,41 @@ static TypeInfo virtio_scsi_info = {
     .class_init    = virtio_scsi_class_init,
 };
 
+/* virtio-pci-bus */
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
+{
+    DeviceState *qdev = DEVICE(dev);
+    BusState *qbus = qbus_create(TYPE_VIRTIO_PCI_BUS, qdev, NULL);
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
+    qbus->allow_hotplug = 0;
+    return bus;
+}
+
+static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
+{
+    BusClass *bus_class = BUS_CLASS(klass);
+    VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
+    bus_class->max_dev = 1;
+    k->notify = virtio_pci_notify;
+    k->save_config = virtio_pci_save_config;
+    k->load_config = virtio_pci_load_config;
+    k->save_queue = virtio_pci_save_queue;
+    k->load_queue = virtio_pci_load_queue;
+    k->get_features = virtio_pci_get_features;
+    k->query_guest_notifiers = virtio_pci_query_guest_notifiers;
+    k->set_host_notifier = virtio_pci_set_host_notifier;
+    k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
+    k->vmstate_change = virtio_pci_vmstate_change;
+}
+
+static const TypeInfo virtio_pci_bus_info = {
+    .name          = TYPE_VIRTIO_PCI_BUS,
+    .parent        = TYPE_VIRTIO_BUS,
+    .instance_size = sizeof(VirtioBusState),
+    .class_init    = virtio_pci_bus_class_init,
+};
+
 static void virtio_pci_register_types(void)
 {
     type_register_static(&virtio_blk_info);
@@ -1170,6 +1206,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_balloon_info);
     type_register_static(&virtio_scsi_info);
     type_register_static(&virtio_rng_info);
+    type_register_static(&virtio_pci_bus_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index b58d9a2..2ac18b3 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -20,6 +20,20 @@
 #include "virtio-rng.h"
 #include "virtio-serial.h"
 #include "virtio-scsi.h"
+#include "virtio-bus.h"
+
+typedef struct VirtIOPCIProxy VirtIOPCIProxy;
+
+/* virtio-pci-bus */
+#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
+#define VIRTIO_PCI_BUS_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS(obj) \
+        OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_PCI_BUS)
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev);
 
 /* Performance improves when virtqueue kick processing is decoupled from the
  * vcpu thread using ioeventfd for some devices. */
@@ -31,7 +45,7 @@ typedef struct {
     unsigned int users;
 } VirtIOIRQFD;
 
-typedef struct {
+struct VirtIOPCIProxy {
     PCIDevice pci_dev;
     VirtIODevice *vdev;
     MemoryRegion bar;
@@ -51,7 +65,7 @@ typedef struct {
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
-} VirtIOPCIProxy;
+};
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (2 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-08 17:54   ` Peter Maydell
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 05/61] virtio-device : refactor virtio-device fred.konrad
                   ` (59 subsequent siblings)
  63 siblings, 1 reply; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create the virtio-pci device. This transport device will create a
virtio-pci-bus, so one VirtIODevice can be connected.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h |  18 ++++++++
 2 files changed, 145 insertions(+)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 5ff03e8..1f0ecbe 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1163,6 +1163,130 @@ static TypeInfo virtio_scsi_info = {
     .class_init    = virtio_scsi_class_init,
 };
 
+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
+ */
+
+/* This is called by virtio-bus just after the device is plugged. */
+static void virtio_pci_device_plugged(DeviceState *d)
+{
+    VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
+    VirtioBusState *bus = proxy->bus;
+    uint8_t *config;
+    uint32_t size;
+
+    /* Put the PCI IDs */
+    switch (virtio_device_get_id(proxy->bus)) {
+
+
+    default:
+        error_report("unknown device id\n");
+        break;
+
+    }
+
+    proxy->vdev = proxy->bus->vdev;
+
+    config = proxy->pci_dev.config;
+    if (proxy->class_code) {
+        pci_config_set_class(config, proxy->class_code);
+    }
+    pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
+                 pci_get_word(config + PCI_VENDOR_ID));
+    pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_device_get_id(proxy->bus));
+    config[PCI_INTERRUPT_PIN] = 1;
+
+    if (proxy->nvectors &&
+        msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, 1)) {
+        proxy->nvectors = 0;
+    }
+
+    proxy->pci_dev.config_write = virtio_write_config;
+
+    size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
+         + virtio_device_get_config_len(bus);
+    if (size & (size - 1)) {
+        size = 1 << qemu_fls(size);
+    }
+
+    memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
+                          "virtio-pci", size);
+    pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
+                     &proxy->bar);
+
+    if (!kvm_has_many_ioeventfds()) {
+        proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
+    }
+
+    proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
+    proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
+    proxy->host_features = virtio_device_get_features(bus,
+                                                      proxy->host_features);
+}
+
+/* This is called by virtio-bus just before the device is unplugged. */
+static void virtio_pci_device_unplug(DeviceState *d)
+{
+    VirtIOPCIProxy *dev = VIRTIO_PCI(d);
+    virtio_pci_stop_ioeventfd(dev);
+}
+
+static int virtio_pci_init(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
+    VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
+    dev->bus = virtio_pci_bus_new(dev);
+    if (k->init != NULL) {
+        return k->init(dev);
+    }
+    return 0;
+}
+
+static void virtio_pci_exit(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
+    VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
+    BusState *qbus = BUS(proxy->bus);
+    virtio_bus_destroy_device(bus);
+    qbus_free(qbus);
+    virtio_exit_pci(pci_dev);
+}
+
+/*
+ * This will be renamed virtio_pci_reset at the end of the series.
+ * virtio_pci_reset is still in use at this moment.
+ */
+static void virtio_pci_rst(DeviceState *qdev)
+{
+    VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
+    VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
+    virtio_pci_stop_ioeventfd(proxy);
+    virtio_bus_reset(bus);
+    msix_unuse_all_vectors(&proxy->pci_dev);
+    proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
+}
+
+static void virtio_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = virtio_pci_init;
+    k->exit = virtio_pci_exit;
+    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    k->revision = VIRTIO_PCI_ABI_VERSION;
+    k->class_id = PCI_CLASS_OTHERS;
+    dc->reset = virtio_pci_rst;
+}
+
+static const TypeInfo virtio_pci_info = {
+    .name          = TYPE_VIRTIO_PCI,
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VirtIOPCIProxy),
+    .class_init    = virtio_pci_class_init,
+    .class_size    = sizeof(VirtioPCIClass),
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1189,6 +1313,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
     k->set_host_notifier = virtio_pci_set_host_notifier;
     k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
     k->vmstate_change = virtio_pci_vmstate_change;
+    k->device_plugged = virtio_pci_device_plugged;
+    k->device_unplug = virtio_pci_device_unplug;
 }
 
 static const TypeInfo virtio_pci_bus_info = {
@@ -1207,6 +1333,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_scsi_info);
     type_register_static(&virtio_rng_info);
     type_register_static(&virtio_pci_bus_info);
+    type_register_static(&virtio_pci_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 2ac18b3..05d52cb 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -45,6 +45,22 @@ typedef struct {
     unsigned int users;
 } VirtIOIRQFD;
 
+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
+ */
+#define TYPE_VIRTIO_PCI "virtio-pci"
+#define VIRTIO_PCI_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
+#define VIRTIO_PCI_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
+#define VIRTIO_PCI(obj) \
+        OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
+
+typedef struct VirtioPCIClass {
+    PCIDeviceClass parent_class;
+    int (*init)(VirtIOPCIProxy *vpci_dev);
+} VirtioPCIClass;
+
 struct VirtIOPCIProxy {
     PCIDevice pci_dev;
     VirtIODevice *vdev;
@@ -65,6 +81,8 @@ struct VirtIOPCIProxy {
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
+    /* That's the virtio-bus on which VirtioDevice will be connected. */
+    VirtioBusState *bus;
 };
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 05/61] virtio-device : refactor virtio-device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (3 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 06/61] virtio-s390-bus : add virtio-s390-bus fred.konrad
                   ` (58 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create the virtio-device which is abstract. All the virtio-device can extend
this class.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
 hw/virtio.h | 30 ++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 12 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index 77b53a9..ca170c3 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -17,6 +17,7 @@
 #include "qemu/error-report.h"
 #include "virtio.h"
 #include "qemu/atomic.h"
+#include "virtio-bus.h"
 
 /* The alignment to use between consumer and producer parts of vring.
  * x86 pagesize again. */
@@ -875,11 +876,16 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
     return 0;
 }
 
-void virtio_cleanup(VirtIODevice *vdev)
+void virtio_common_cleanup(VirtIODevice *vdev)
 {
     qemu_del_vm_change_state_handler(vdev->vmstate);
     g_free(vdev->config);
     g_free(vdev->vq);
+}
+
+void virtio_cleanup(VirtIODevice *vdev)
+{
+    virtio_common_cleanup(vdev);
     g_free(vdev);
 }
 
@@ -902,14 +908,10 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     }
 }
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
-                                 size_t config_size, size_t struct_size)
+void virtio_init(VirtIODevice *vdev, const char *name,
+                 uint16_t device_id, size_t config_size)
 {
-    VirtIODevice *vdev;
     int i;
-
-    vdev = g_malloc0(struct_size);
-
     vdev->device_id = device_id;
     vdev->status = 0;
     vdev->isr = 0;
@@ -917,20 +919,28 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
     vdev->config_vector = VIRTIO_NO_VECTOR;
     vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX);
     vdev->vm_running = runstate_is_running();
-    for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
+    for (i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
         vdev->vq[i].vector = VIRTIO_NO_VECTOR;
         vdev->vq[i].vdev = vdev;
     }
 
     vdev->name = name;
     vdev->config_len = config_size;
-    if (vdev->config_len)
+    if (vdev->config_len) {
         vdev->config = g_malloc0(config_size);
-    else
+    } else {
         vdev->config = NULL;
+    }
+    vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
+                                                     vdev);
+}
 
-    vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change, vdev);
-
+VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
+                                 size_t config_size, size_t struct_size)
+{
+    VirtIODevice *vdev;
+    vdev = g_malloc0(struct_size);
+    virtio_init(vdev, name, device_id, config_size);
     return vdev;
 }
 
@@ -1056,3 +1066,39 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
 {
     return &vq->host_notifier;
 }
+
+static int virtio_device_init(DeviceState *qdev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
+    assert(k->init != NULL);
+    if (k->init(vdev) < 0) {
+        return -1;
+    }
+    virtio_bus_plug_device(vdev);
+    return 0;
+}
+
+static void virtio_device_class_init(ObjectClass *klass, void *data)
+{
+    /* Set the default value here. */
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_device_init;
+    dc->bus_type = TYPE_VIRTIO_BUS;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIODevice),
+    .class_init = virtio_device_class_init,
+    .abstract = true,
+    .class_size = sizeof(VirtioDeviceClass),
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio.h b/hw/virtio.h
index 1dec9dc..c134960 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -108,8 +108,17 @@ typedef struct {
 
 #define VIRTIO_NO_VECTOR 0xffff
 
+#define TYPE_VIRTIO_DEVICE "virtio-device"
+#define VIRTIO_DEVICE_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioDeviceClass, obj, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioDeviceClass, klass, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE(obj) \
+        OBJECT_CHECK(VirtIODevice, (obj), TYPE_VIRTIO_DEVICE)
+
 struct VirtIODevice
 {
+    DeviceState parent_obj;
     const char *name;
     uint8_t status;
     uint8_t isr;
@@ -119,6 +128,10 @@ struct VirtIODevice
     void *config;
     uint16_t config_vector;
     int nvectors;
+    /*
+     * Function pointers will be removed ( at the end of the series )
+     * as they are in VirtioDeviceClass.
+     */
     uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
     uint32_t (*bad_features)(VirtIODevice *vdev);
     void (*set_features)(VirtIODevice *vdev, uint32_t val);
@@ -134,6 +147,23 @@ struct VirtIODevice
     VMChangeStateEntry *vmstate;
 };
 
+typedef struct {
+    /* This is what a VirtioDevice must implement */
+    DeviceClass parent;
+    int (*init)(VirtIODevice *vdev);
+    uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
+    uint32_t (*bad_features)(VirtIODevice *vdev);
+    void (*set_features)(VirtIODevice *vdev, uint32_t val);
+    void (*get_config)(VirtIODevice *vdev, uint8_t *config);
+    void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
+    void (*reset)(VirtIODevice *vdev);
+    void (*set_status)(VirtIODevice *vdev, uint8_t val);
+} VirtioDeviceClass;
+
+void virtio_init(VirtIODevice *vdev, const char *name,
+                         uint16_t device_id, size_t config_size);
+void virtio_common_cleanup(VirtIODevice *vdev);
+
 VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
                             void (*handle_output)(VirtIODevice *,
                                                   VirtQueue *));
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 06/61] virtio-s390-bus : add virtio-s390-bus.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (4 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 05/61] virtio-device : refactor virtio-device fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 07/61] virtio-s390-device : create a virtio-s390-bus during init fred.konrad
                   ` (57 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This add the virtio-s390-bus which extends virtio-bus. So one VirtIODevice can
be connected on this bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 29 +++++++++++++++++++++++++++++
 hw/s390-virtio-bus.h | 13 +++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 7e99175..0fa0a74 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -32,6 +32,7 @@
 #include "sysemu/kvm.h"
 
 #include "hw/s390-virtio-bus.h"
+#include "hw/virtio-bus.h"
 
 /* #define DEBUG_S390 */
 
@@ -569,8 +570,36 @@ static TypeInfo s390_virtio_bridge_info = {
     .class_init    = s390_virtio_bridge_class_init,
 };
 
+/* virtio-s390-bus */
+
+VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev)
+{
+    DeviceState *qdev = DEVICE(dev);
+    BusState *qbus = qbus_create(TYPE_VIRTIO_S390_BUS, qdev, NULL);
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
+    qbus->allow_hotplug = 0;
+    return bus;
+}
+
+static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
+{
+    VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
+    BusClass *bus_class = BUS_CLASS(klass);
+    bus_class->max_dev = 1;
+    k->notify = virtio_s390_notify;
+    k->get_features = virtio_s390_get_features;
+}
+
+static const TypeInfo virtio_s390_bus_info = {
+    .name          = TYPE_VIRTIO_S390_BUS,
+    .parent        = TYPE_VIRTIO_BUS,
+    .instance_size = sizeof(VirtioBusState),
+    .class_init    = virtio_s390_bus_class_init,
+};
+
 static void s390_virtio_register_types(void)
 {
+    type_register_static(&virtio_s390_bus_info);
     type_register_static(&s390_virtio_bus_info);
     type_register_static(&virtio_s390_device_info);
     type_register_static(&s390_virtio_serial);
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index 23fedd5..81af7a0 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -24,6 +24,7 @@
 #include "virtio-rng.h"
 #include "virtio-serial.h"
 #include "virtio-scsi.h"
+#include "virtio-bus.h"
 
 #define VIRTIO_DEV_OFFS_TYPE		0	/* 8 bits */
 #define VIRTIO_DEV_OFFS_NUM_VQ		1	/* 8 bits */
@@ -59,8 +60,20 @@
 #define S390_VIRTIO_BUS(obj) \
      OBJECT_CHECK(VirtIOS390Bus, (obj), TYPE_S390_VIRTIO_BUS)
 
+/* virtio-s390-bus */
+
+#define TYPE_VIRTIO_S390_BUS "virtio-s390-bus"
+#define VIRTIO_S390_BUS_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_S390_BUS)
+#define VIRTIO_S390_BUS_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_S390_BUS)
+#define VIRTIO_S390_BUS(obj) \
+        OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_S390_BUS)
+
 typedef struct VirtIOS390Device VirtIOS390Device;
 
+VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev);
+
 typedef struct VirtIOS390DeviceClass {
     DeviceClass qdev;
     int (*init)(VirtIOS390Device *dev);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 07/61] virtio-s390-device : create a virtio-s390-bus during init.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (5 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 06/61] virtio-s390-bus : add virtio-s390-bus fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure fred.konrad
                   ` (56 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

A virtio-s390-bus is created during the init. So one VirtIODevice can be
connected on the virtio-s390-device through this bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 2 ++
 hw/s390-virtio-bus.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 0fa0a74..946de31 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -503,6 +503,8 @@ static int s390_virtio_busdev_init(DeviceState *dev)
     VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
     VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
 
+    _dev->bus = virtio_s390_bus_new(_dev);
+
     return _info->init(_dev);
 }
 
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index 81af7a0..178e281 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -92,6 +92,7 @@ struct VirtIOS390Device {
     virtio_net_conf net;
     VirtIOSCSIConf scsi;
     VirtIORNGConf rng;
+    VirtioBusState *bus;
 };
 
 typedef struct VirtIOS390Bus {
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (6 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 07/61] virtio-s390-device : create a virtio-s390-bus during init fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-08 16:18   ` Peter Maydell
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 09/61] virtio-blk : don't use pointer for configuration fred.konrad
                   ` (55 subsequent siblings)
  63 siblings, 1 reply; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As we discuss with anthony and andreas, this structure must be showed to avoid
two memory allocations for virtio-blk-x.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-blk.c | 16 ----------------
 hw/virtio-blk.h | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index df57b35..38a53e9 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -25,22 +25,6 @@
 # include <scsi/sg.h>
 #endif
 
-typedef struct VirtIOBlock
-{
-    VirtIODevice vdev;
-    BlockDriverState *bs;
-    VirtQueue *vq;
-    void *rq;
-    QEMUBH *bh;
-    BlockConf *conf;
-    VirtIOBlkConf *blk;
-    unsigned short sector_mask;
-    DeviceState *qdev;
-#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
-    VirtIOBlockDataPlane *dataplane;
-#endif
-} VirtIOBlock;
-
 static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
 {
     return (VirtIOBlock *)vdev;
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 43ca492..2a7aef2 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -108,6 +108,21 @@ struct VirtIOBlkConf
     uint32_t data_plane;
 };
 
+typedef struct VirtIOBlock {
+    VirtIODevice vdev;
+    BlockDriverState *bs;
+    VirtQueue *vq;
+    void *rq;
+    QEMUBH *bh;
+    BlockConf *conf;
+    VirtIOBlkConf *blk;
+    unsigned short sector_mask;
+    DeviceState *qdev;
+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
+    VirtIOBlockDataPlane *dataplane;
+#endif
+} VirtIOBlock;
+
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 09/61] virtio-blk : don't use pointer for configuration.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (7 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 10/61] virtio-blk : add the virtio-blk device fred.konrad
                   ` (54 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The configuration field must not be a pointer as it will be used for virtio-blk
properties. So *blk is replaced by blk in VirtIOBlock structure.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-blk.c | 8 ++++----
 hw/virtio-blk.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 38a53e9..93a52b5 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -154,7 +154,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
      */
     req->scsi = (void *)req->elem.in_sg[req->elem.in_num - 2].iov_base;
 
-    if (!req->dev->blk->scsi) {
+    if (!req->dev->blk.scsi) {
         status = VIRTIO_BLK_S_UNSUPP;
         goto fail;
     }
@@ -374,7 +374,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
          * terminated by '\0' only when shorter than buffer.
          */
         strncpy(req->elem.in_sg[0].iov_base,
-                s->blk->serial ? s->blk->serial : "",
+                s->blk.serial ? s->blk.serial : "",
                 MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
         virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
         g_free(req);
@@ -537,7 +537,7 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
     features |= (1 << VIRTIO_BLK_F_BLK_SIZE);
     features |= (1 << VIRTIO_BLK_F_SCSI);
 
-    if (s->blk->config_wce) {
+    if (s->blk.config_wce) {
         features |= (1 << VIRTIO_BLK_F_CONFIG_WCE);
     }
     if (bdrv_enable_write_cache(s->bs))
@@ -652,7 +652,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
     s->vdev.reset = virtio_blk_reset;
     s->bs = blk->conf.bs;
     s->conf = &blk->conf;
-    s->blk = blk;
+    memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
     s->rq = NULL;
     s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
 
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 2a7aef2..df07419 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -115,7 +115,7 @@ typedef struct VirtIOBlock {
     void *rq;
     QEMUBH *bh;
     BlockConf *conf;
-    VirtIOBlkConf *blk;
+    VirtIOBlkConf blk;
     unsigned short sector_mask;
     DeviceState *qdev;
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 10/61] virtio-blk : add the virtio-blk device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (8 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 09/61] virtio-blk : don't use pointer for configuration fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 11/61] virtio-blk-pci : switch to new API fred.konrad
                   ` (53 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-blk which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-blk.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 hw/virtio-blk.h | 28 +++++++++++++++++
 hw/virtio-pci.c | 18 ++++-------
 3 files changed, 126 insertions(+), 17 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 93a52b5..8ed1a96 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -24,7 +24,11 @@
 #ifdef __linux__
 # include <scsi/sg.h>
 #endif
+#include "virtio-bus.h"
 
+/*
+ * Moving to QOM later in this series.
+ */
 static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
 {
     return (VirtIOBlock *)vdev;
@@ -622,9 +626,16 @@ static const BlockDevOps virtio_block_ops = {
     .resize_cb = virtio_blk_resize,
 };
 
-VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
 {
-    VirtIOBlock *s;
+    VirtIOBlock *s = VIRTIO_BLK(dev);
+    memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
+}
+
+static VirtIODevice *virtio_blk_common_init(DeviceState *dev,
+                                          VirtIOBlkConf *blk, VirtIOBlock **ps)
+{
+    VirtIOBlock *s = *ps;
     static int virtio_blk_id;
 
     if (!blk->conf.bs) {
@@ -641,9 +652,20 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
         return NULL;
     }
 
-    s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
-                                          sizeof(struct virtio_blk_config),
-                                          sizeof(VirtIOBlock));
+    /*
+     * We have two cases here : the old virtio-blk-pci device, and the
+     * refactored virtio-blk.
+     */
+    if (s == NULL) {
+        /* virtio-blk-pci */
+        s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
+                                              sizeof(struct virtio_blk_config),
+                                              sizeof(VirtIOBlock));
+    } else {
+        /* virtio-blk */
+        virtio_init(VIRTIO_DEVICE(s), "virtio-blk", VIRTIO_ID_BLOCK,
+                    sizeof(struct virtio_blk_config));
+    }
 
     s->vdev.get_config = virtio_blk_update_config;
     s->vdev.set_config = virtio_blk_set_config;
@@ -677,6 +699,12 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
     return &s->vdev;
 }
 
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+{
+    VirtIOBlock *s = NULL;
+    return virtio_blk_common_init(dev, blk, &s);
+}
+
 void virtio_blk_exit(VirtIODevice *vdev)
 {
     VirtIOBlock *s = to_virtio_blk(vdev);
@@ -689,3 +717,62 @@ void virtio_blk_exit(VirtIODevice *vdev)
     blockdev_mark_auto_del(s->bs);
     virtio_cleanup(vdev);
 }
+
+
+static int virtio_blk_device_init(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOBlock *s = VIRTIO_BLK(vdev);
+    VirtIOBlkConf *blk = &(s->blk);
+    if (virtio_blk_common_init(qdev, blk, &s) == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
+static int virtio_blk_device_exit(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VirtIOBlock *s = VIRTIO_BLK(dev);
+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
+    virtio_blk_data_plane_destroy(s->dataplane);
+    s->dataplane = NULL;
+#endif
+    unregister_savevm(s->qdev, "virtio-blk", s);
+    blockdev_mark_auto_del(s->bs);
+    virtio_common_cleanup(vdev);
+    return 0;
+}
+
+static Property virtio_blk_properties[] = {
+    DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlock, blk)
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blk_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_blk_device_exit;
+    dc->props = virtio_blk_properties;
+    vdc->init = virtio_blk_device_init;
+    vdc->get_config = virtio_blk_update_config;
+    vdc->set_config = virtio_blk_set_config;
+    vdc->get_features = virtio_blk_get_features;
+    vdc->set_status = virtio_blk_set_status;
+    vdc->reset = virtio_blk_reset;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_BLK,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOBlock),
+    .class_init = virtio_blk_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index df07419..4a65ef6 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -17,6 +17,10 @@
 #include "virtio.h"
 #include "hw/block-common.h"
 
+#define TYPE_VIRTIO_BLK "virtio-blk"
+#define VIRTIO_BLK(obj) \
+        OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
+
 /* from Linux's linux/virtio_blk.h */
 
 /* The ID for virtio_block */
@@ -126,4 +130,28 @@ typedef struct VirtIOBlock {
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
 
+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
+#define DEFINE_DATA_PLANE_PROPERTIES(_state, _field)                          \
+        DEFINE_PROP_BIT("x-data-plane", _state, _field.data_plane, 0, false),
+#else
+#define DEFINE_DATA_PLANE_PROPERTIES(_state, _field)
+#endif /* CONFIG_VIRTIO_BLK_DATA_PLANE */
+
+#ifdef __linux__
+#define DEFINE_VIRTIO_BLK_SCSI_PROPERTY(_state, _field)                       \
+        DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true),
+#else
+#define DEFINE_VIRTIO_BLK_SCSI_PROPERTY(_state, _field)
+#endif /* __linux__ */
+
+#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field)                          \
+        DEFINE_BLOCK_PROPERTIES(_state, _field.conf),                         \
+        DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf),                     \
+        DEFINE_PROP_STRING("serial", _state, _field.serial),                  \
+        DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true),    \
+        DEFINE_VIRTIO_BLK_SCSI_PROPERTY(_state, _field)                       \
+        DEFINE_DATA_PLANE_PROPERTIES(_state, _field)
+
+void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk);
+
 #endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 1f0ecbe..919d3e7 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -931,19 +931,10 @@ static void virtio_rng_exit_pci(PCIDevice *pci_dev)
 
 static Property virtio_blk_properties[] = {
     DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
-    DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf),
-    DEFINE_BLOCK_CHS_PROPERTIES(VirtIOPCIProxy, blk.conf),
-    DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
-#ifdef __linux__
-    DEFINE_PROP_BIT("scsi", VirtIOPCIProxy, blk.scsi, 0, true),
-#endif
-    DEFINE_PROP_BIT("config-wce", VirtIOPCIProxy, blk.config_wce, 0, true),
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
-    DEFINE_PROP_BIT("x-data-plane", VirtIOPCIProxy, blk.data_plane, 0, false),
-#endif
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
     DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOPCIProxy, blk)
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -1177,8 +1168,11 @@ static void virtio_pci_device_plugged(DeviceState *d)
 
     /* Put the PCI IDs */
     switch (virtio_device_get_id(proxy->bus)) {
-
-
+    case VIRTIO_ID_BLOCK:
+        pci_config_set_device_id(proxy->pci_dev.config,
+                                 PCI_DEVICE_ID_VIRTIO_BLOCK);
+        pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
+        break;
     default:
         error_report("unknown device id\n");
         break;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 11/61] virtio-blk-pci : switch to new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (9 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 10/61] virtio-blk : add the virtio-blk device fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 12/61] virtio-blk-s390 : switch to the " fred.konrad
                   ` (52 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-blk-pci is modified for the new API. The device
virtio-blk-pci extends virtio-pci. It creates and connects a virtio-blk
during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 109 +++++++++++++++++++++++++-------------------------------
 hw/virtio-pci.h |  15 +++++++-
 2 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 919d3e7..6043ee4 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -775,26 +775,6 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
     proxy->host_features = vdev->get_features(vdev, proxy->host_features);
 }
 
-static int virtio_blk_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
-        proxy->class_code != PCI_CLASS_STORAGE_OTHER)
-        proxy->class_code = PCI_CLASS_STORAGE_SCSI;
-
-    vdev = virtio_blk_init(&pci_dev->qdev, &proxy->blk);
-    if (!vdev) {
-        return -1;
-    }
-    vdev->nvectors = proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-    /* make the actual value visible */
-    proxy->nvectors = vdev->nvectors;
-    return 0;
-}
-
 static void virtio_exit_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -803,15 +783,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
     msix_uninit_exclusive_bar(pci_dev);
 }
 
-static void virtio_blk_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_blk_exit(proxy->vdev);
-    virtio_exit_pci(pci_dev);
-}
-
 static int virtio_serial_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -929,37 +900,6 @@ static void virtio_rng_exit_pci(PCIDevice *pci_dev)
     virtio_exit_pci(pci_dev);
 }
 
-static Property virtio_blk_properties[] = {
-    DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
-    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-    DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOPCIProxy, blk)
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_blk_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = virtio_blk_init_pci;
-    k->exit = virtio_blk_exit_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = PCI_CLASS_STORAGE_SCSI;
-    dc->reset = virtio_pci_reset;
-    dc->props = virtio_blk_properties;
-}
-
-static TypeInfo virtio_blk_info = {
-    .name          = "virtio-blk-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
-    .class_init    = virtio_blk_class_init,
-};
-
 static Property virtio_net_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
@@ -1281,6 +1221,53 @@ static const TypeInfo virtio_pci_info = {
     .class_size    = sizeof(VirtioPCIClass),
 };
 
+/* virtio-blk-pci */
+
+static Property virtio_blk_pci_properties[] = {
+    DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+    DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkPCI, blk)
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_blk_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+    virtio_blk_set_conf(vdev, &(dev->blk));
+    qdev_set_parent_bus(vdev, BUS(vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+    return 0;
+}
+
+static void virtio_blk_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+    dc->props = virtio_blk_pci_properties;
+    k->init = virtio_blk_pci_init;
+}
+
+static void virtio_blk_pci_instance_init(Object *obj)
+{
+    VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BLK);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static const TypeInfo virtio_blk_pci_info = {
+    .name          = TYPE_VIRTIO_BLK_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIOBlkPCI),
+    .instance_init = virtio_blk_pci_instance_init,
+    .class_init    = virtio_blk_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1320,7 +1307,6 @@ static const TypeInfo virtio_pci_bus_info = {
 
 static void virtio_pci_register_types(void)
 {
-    type_register_static(&virtio_blk_info);
     type_register_static(&virtio_net_info);
     type_register_static(&virtio_serial_info);
     type_register_static(&virtio_balloon_info);
@@ -1328,6 +1314,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_rng_info);
     type_register_static(&virtio_pci_bus_info);
     type_register_static(&virtio_pci_info);
+    type_register_static(&virtio_blk_pci_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 05d52cb..9f22f79 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -23,6 +23,7 @@
 #include "virtio-bus.h"
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
+typedef struct VirtIOBlkPCI VirtIOBlkPCI;
 
 /* virtio-pci-bus */
 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
@@ -68,7 +69,6 @@ struct VirtIOPCIProxy {
     uint32_t flags;
     uint32_t class_code;
     uint32_t nvectors;
-    VirtIOBlkConf blk;
     NICConf nic;
     uint32_t host_features;
 #ifdef CONFIG_LINUX
@@ -85,6 +85,19 @@ struct VirtIOPCIProxy {
     VirtioBusState *bus;
 };
 
+/*
+ * virtio-blk-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
+#define VIRTIO_BLK_PCI(obj) \
+        OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
+
+struct VirtIOBlkPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOBlock vdev;
+    VirtIOBlkConf blk;
+};
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 12/61] virtio-blk-s390 : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (10 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 11/61] virtio-blk-pci : switch to new API fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 13/61] virtio-blk : cleanup : use QOM cast fred.konrad
                   ` (51 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-blk-s390 is modified for the new API. The device
virtio-blk-s390 extends virtio-s390-device as before. It creates and
connects a virtio-blk during the init. The properties are not modified.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 30 +++++++++++++++++++-----------
 hw/s390-virtio-bus.h | 13 ++++++++++++-
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 946de31..d40fb8b 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -163,16 +163,23 @@ static int s390_virtio_net_init(VirtIOS390Device *dev)
     return s390_virtio_device_init(dev, vdev);
 }
 
-static int s390_virtio_blk_init(VirtIOS390Device *dev)
+static int s390_virtio_blk_init(VirtIOS390Device *s390_dev)
 {
-    VirtIODevice *vdev;
-
-    vdev = virtio_blk_init((DeviceState *)dev, &dev->blk);
-    if (!vdev) {
+    VirtIOBlkS390 *dev = VIRTIO_BLK_S390(s390_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+    virtio_blk_set_conf(vdev, &(dev->blk));
+    qdev_set_parent_bus(vdev, BUS(s390_dev->bus));
+    if (qdev_init(vdev) < 0) {
         return -1;
     }
+    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+}
 
-    return s390_virtio_device_init(dev, vdev);
+static void s390_virtio_blk_instance_init(Object *obj)
+{
+    VirtIOBlkS390 *dev = VIRTIO_BLK_S390(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BLK);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
 static int s390_virtio_serial_init(VirtIOS390Device *dev)
@@ -428,11 +435,11 @@ static TypeInfo s390_virtio_net = {
 };
 
 static Property s390_virtio_blk_properties[] = {
-    DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, blk.conf),
-    DEFINE_BLOCK_CHS_PROPERTIES(VirtIOS390Device, blk.conf),
-    DEFINE_PROP_STRING("serial", VirtIOS390Device, blk.serial),
+    DEFINE_BLOCK_PROPERTIES(VirtIOBlkS390, blk.conf),
+    DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlkS390, blk.conf),
+    DEFINE_PROP_STRING("serial", VirtIOBlkS390, blk.serial),
 #ifdef __linux__
-    DEFINE_PROP_BIT("scsi", VirtIOS390Device, blk.scsi, 0, true),
+    DEFINE_PROP_BIT("scsi", VirtIOBlkS390, blk.scsi, 0, true),
 #endif
     DEFINE_PROP_END_OF_LIST(),
 };
@@ -449,7 +456,8 @@ static void s390_virtio_blk_class_init(ObjectClass *klass, void *data)
 static TypeInfo s390_virtio_blk = {
     .name          = "virtio-blk-s390",
     .parent        = TYPE_VIRTIO_S390_DEVICE,
-    .instance_size = sizeof(VirtIOS390Device),
+    .instance_size = sizeof(VirtIOBlkS390),
+    .instance_init = s390_virtio_blk_instance_init,
     .class_init    = s390_virtio_blk_class_init,
 };
 
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index 178e281..f5d0b94 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -85,7 +85,6 @@ struct VirtIOS390Device {
     ram_addr_t feat_offs;
     uint8_t feat_len;
     VirtIODevice *vdev;
-    VirtIOBlkConf blk;
     NICConf nic;
     uint32_t host_features;
     virtio_serial_conf serial;
@@ -116,5 +115,17 @@ VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem);
 void s390_virtio_device_sync(VirtIOS390Device *dev);
 void s390_virtio_reset_idx(VirtIOS390Device *dev);
 
+/* virtio-blk-s390 */
+
+#define TYPE_VIRTIO_BLK_S390 "virtio-blk-s390"
+#define VIRTIO_BLK_S390(obj) \
+        OBJECT_CHECK(VirtIOBlkS390, (obj), TYPE_VIRTIO_BLK_S390)
+
+typedef struct VirtIOBlkS390 {
+    VirtIOS390Device parent_obj;
+    VirtIOBlock vdev;
+    VirtIOBlkConf blk;
+} VirtIOBlkS390;
+
 
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 13/61] virtio-blk : cleanup : use QOM cast.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (11 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 12/61] virtio-blk-s390 : switch to the " fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 14/61] virtio-blk : cleanup : remove qdev field fred.konrad
                   ` (50 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-blk-pci and virtio-blk-s390 are switched to the new API,
we can use QOM casts and remove the separate init/exit for the old API.
This shouldn't been applyied before virtio-blk-pci and virtio-blk-s390
refactoring as their VirtIODevice were not a QOM object.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-blk.c | 123 +++++++++++++++++---------------------------------------
 hw/virtio-blk.h |   2 +-
 2 files changed, 39 insertions(+), 86 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 8ed1a96..c19d347 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -26,14 +26,6 @@
 #endif
 #include "virtio-bus.h"
 
-/*
- * Moving to QOM later in this series.
- */
-static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
-{
-    return (VirtIOBlock *)vdev;
-}
-
 typedef struct VirtIOBlockReq
 {
     VirtIOBlock *dev;
@@ -49,12 +41,13 @@ typedef struct VirtIOBlockReq
 static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
 {
     VirtIOBlock *s = req->dev;
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
 
     trace_virtio_blk_req_complete(req, status);
 
     stb_p(&req->in->status, status);
     virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
-    virtio_notify(&s->vdev, s->vq);
+    virtio_notify(vdev, s->vq);
 }
 
 static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
@@ -399,7 +392,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
 
 static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOBlock *s = to_virtio_blk(vdev);
+    VirtIOBlock *s = VIRTIO_BLK(vdev);
     VirtIOBlockReq *req;
     MultiReqBuffer mrb = {
         .num_writes = 0,
@@ -430,7 +423,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 
 static void virtio_blk_dma_restart_bh(void *opaque)
 {
-    VirtIOBlock *s = opaque;
+    VirtIOBlock *s = VIRTIO_BLK(opaque);
     VirtIOBlockReq *req = s->rq;
     MultiReqBuffer mrb = {
         .num_writes = 0,
@@ -452,7 +445,7 @@ static void virtio_blk_dma_restart_bh(void *opaque)
 static void virtio_blk_dma_restart_cb(void *opaque, int running,
                                       RunState state)
 {
-    VirtIOBlock *s = opaque;
+    VirtIOBlock *s = VIRTIO_BLK(opaque);
 
     if (!running) {
         return;
@@ -485,7 +478,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
  */
 static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
-    VirtIOBlock *s = to_virtio_blk(vdev);
+    VirtIOBlock *s = VIRTIO_BLK(vdev);
     struct virtio_blk_config blkcfg;
     uint64_t capacity;
     int blk_size = s->conf->logical_block_size;
@@ -524,7 +517,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 
 static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
 {
-    VirtIOBlock *s = to_virtio_blk(vdev);
+    VirtIOBlock *s = VIRTIO_BLK(vdev);
     struct virtio_blk_config blkcfg;
 
     memcpy(&blkcfg, config, sizeof(blkcfg));
@@ -533,7 +526,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
 
 static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
 {
-    VirtIOBlock *s = to_virtio_blk(vdev);
+    VirtIOBlock *s = VIRTIO_BLK(vdev);
 
     features |= (1 << VIRTIO_BLK_F_SEG_MAX);
     features |= (1 << VIRTIO_BLK_F_GEOMETRY);
@@ -555,7 +548,7 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
 
 static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
 {
-    VirtIOBlock *s = to_virtio_blk(vdev);
+    VirtIOBlock *s = VIRTIO_BLK(vdev);
     uint32_t features;
 
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
@@ -574,10 +567,11 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
 
 static void virtio_blk_save(QEMUFile *f, void *opaque)
 {
-    VirtIOBlock *s = opaque;
+    VirtIOBlock *s = VIRTIO_BLK(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     VirtIOBlockReq *req = s->rq;
 
-    virtio_save(&s->vdev, f);
+    virtio_save(vdev, f);
     
     while (req) {
         qemu_put_sbyte(f, 1);
@@ -589,13 +583,14 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)
 
 static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
 {
-    VirtIOBlock *s = opaque;
+    VirtIOBlock *s = VIRTIO_BLK(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     int ret;
 
     if (version_id != 2)
         return -EINVAL;
 
-    ret = virtio_load(&s->vdev, f);
+    ret = virtio_load(vdev, f);
     if (ret) {
         return ret;
     }
@@ -617,9 +612,9 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
 
 static void virtio_blk_resize(void *opaque)
 {
-    VirtIOBlock *s = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
 
-    virtio_notify_config(&s->vdev);
+    virtio_notify_config(vdev);
 }
 
 static const BlockDevOps virtio_block_ops = {
@@ -632,101 +627,59 @@ void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
     memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
 }
 
-static VirtIODevice *virtio_blk_common_init(DeviceState *dev,
-                                          VirtIOBlkConf *blk, VirtIOBlock **ps)
+static int virtio_blk_device_init(VirtIODevice *vdev)
 {
-    VirtIOBlock *s = *ps;
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOBlock *s = VIRTIO_BLK(vdev);
+    VirtIOBlkConf *blk = &(s->blk);
     static int virtio_blk_id;
 
     if (!blk->conf.bs) {
         error_report("drive property not set");
-        return NULL;
+        return -1;
     }
     if (!bdrv_is_inserted(blk->conf.bs)) {
         error_report("Device needs media, but drive is empty");
-        return NULL;
+        return -1;
     }
 
     blkconf_serial(&blk->conf, &blk->serial);
     if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) {
-        return NULL;
+        return -1;
     }
 
-    /*
-     * We have two cases here : the old virtio-blk-pci device, and the
-     * refactored virtio-blk.
-     */
-    if (s == NULL) {
-        /* virtio-blk-pci */
-        s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
-                                              sizeof(struct virtio_blk_config),
-                                              sizeof(VirtIOBlock));
-    } else {
-        /* virtio-blk */
-        virtio_init(VIRTIO_DEVICE(s), "virtio-blk", VIRTIO_ID_BLOCK,
-                    sizeof(struct virtio_blk_config));
-    }
+    virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
+                sizeof(struct virtio_blk_config));
 
-    s->vdev.get_config = virtio_blk_update_config;
-    s->vdev.set_config = virtio_blk_set_config;
-    s->vdev.get_features = virtio_blk_get_features;
-    s->vdev.set_status = virtio_blk_set_status;
-    s->vdev.reset = virtio_blk_reset;
+    vdev->get_config = virtio_blk_update_config;
+    vdev->set_config = virtio_blk_set_config;
+    vdev->get_features = virtio_blk_get_features;
+    vdev->set_status = virtio_blk_set_status;
+    vdev->reset = virtio_blk_reset;
     s->bs = blk->conf.bs;
     s->conf = &blk->conf;
     memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
     s->rq = NULL;
     s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
 
-    s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
+    s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
-    if (!virtio_blk_data_plane_create(&s->vdev, blk, &s->dataplane)) {
-        virtio_cleanup(&s->vdev);
-        return NULL;
+    if (!virtio_blk_data_plane_create(vdev, blk, &s->dataplane)) {
+        virtio_cleanup(vdev);
+        return -1;
     }
 #endif
 
     qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
-    s->qdev = dev;
-    register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
+    s->qdev = qdev;
+    register_savevm(qdev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
     bdrv_set_buffer_alignment(s->bs, s->conf->logical_block_size);
 
     bdrv_iostatus_enable(s->bs);
-    add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
-
-    return &s->vdev;
-}
 
-VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
-{
-    VirtIOBlock *s = NULL;
-    return virtio_blk_common_init(dev, blk, &s);
-}
-
-void virtio_blk_exit(VirtIODevice *vdev)
-{
-    VirtIOBlock *s = to_virtio_blk(vdev);
-
-#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
-    virtio_blk_data_plane_destroy(s->dataplane);
-    s->dataplane = NULL;
-#endif
-    unregister_savevm(s->qdev, "virtio-blk", s);
-    blockdev_mark_auto_del(s->bs);
-    virtio_cleanup(vdev);
-}
-
-
-static int virtio_blk_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIOBlock *s = VIRTIO_BLK(vdev);
-    VirtIOBlkConf *blk = &(s->blk);
-    if (virtio_blk_common_init(qdev, blk, &s) == NULL) {
-        return -1;
-    }
+    add_boot_device_path(s->conf->bootindex, qdev, "/disk@0,0");
     return 0;
 }
 
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 4a65ef6..2b3c99a 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -113,7 +113,7 @@ struct VirtIOBlkConf
 };
 
 typedef struct VirtIOBlock {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
     BlockDriverState *bs;
     VirtQueue *vq;
     void *rq;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 14/61] virtio-blk : cleanup : remove qdev field.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (12 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 13/61] virtio-blk : cleanup : use QOM cast fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 15/61] virtio-net : show the VirtIONet structure fred.konrad
                   ` (49 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The qdev field is no longer needed, just drop it.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-blk.c | 3 +--
 hw/virtio-blk.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index c19d347..74ba97b 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -671,7 +671,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
 #endif
 
     qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
-    s->qdev = qdev;
     register_savevm(qdev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
@@ -691,7 +690,7 @@ static int virtio_blk_device_exit(DeviceState *dev)
     virtio_blk_data_plane_destroy(s->dataplane);
     s->dataplane = NULL;
 #endif
-    unregister_savevm(s->qdev, "virtio-blk", s);
+    unregister_savevm(dev, "virtio-blk", s);
     blockdev_mark_auto_del(s->bs);
     virtio_common_cleanup(vdev);
     return 0;
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 2b3c99a..f281ac3 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -121,7 +121,6 @@ typedef struct VirtIOBlock {
     BlockConf *conf;
     VirtIOBlkConf blk;
     unsigned short sector_mask;
-    DeviceState *qdev;
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
     VirtIOBlockDataPlane *dataplane;
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 15/61] virtio-net : show the VirtIONet structure.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (13 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 14/61] virtio-blk : cleanup : remove qdev field fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 16/61] virtio-net : add the virtio-net device fred.konrad
                   ` (48 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As we discuss with anthony and andreas, this structure must be showed to avoid
two memory allocations for virtio-net-x.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-net.c | 41 -----------------------------------------
 hw/virtio-net.h | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 5d03b31..4ece6c2 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -26,47 +26,6 @@
 #define MAC_TABLE_ENTRIES    64
 #define MAX_VLAN    (1 << 12)   /* Per 802.1Q definition */
 
-typedef struct VirtIONet
-{
-    VirtIODevice vdev;
-    uint8_t mac[ETH_ALEN];
-    uint16_t status;
-    VirtQueue *rx_vq;
-    VirtQueue *tx_vq;
-    VirtQueue *ctrl_vq;
-    NICState *nic;
-    QEMUTimer *tx_timer;
-    QEMUBH *tx_bh;
-    uint32_t tx_timeout;
-    int32_t tx_burst;
-    int tx_waiting;
-    uint32_t has_vnet_hdr;
-    size_t host_hdr_len;
-    size_t guest_hdr_len;
-    uint8_t has_ufo;
-    struct {
-        VirtQueueElement elem;
-        ssize_t len;
-    } async_tx;
-    int mergeable_rx_bufs;
-    uint8_t promisc;
-    uint8_t allmulti;
-    uint8_t alluni;
-    uint8_t nomulti;
-    uint8_t nouni;
-    uint8_t nobcast;
-    uint8_t vhost_started;
-    struct {
-        int in_use;
-        int first_multi;
-        uint8_t multi_overflow;
-        uint8_t uni_overflow;
-        uint8_t *macs;
-    } mac_table;
-    uint32_t *vlans;
-    DeviceState *qdev;
-} VirtIONet;
-
 /* TODO
  * - we could suppress RX interrupt if we were so inclined.
  */
diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index d46fb98..f6ff85d 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -124,6 +124,47 @@ struct virtio_net_ctrl_mac {
     uint32_t entries;
     uint8_t macs[][ETH_ALEN];
 };
+
+typedef struct VirtIONet {
+    VirtIODevice vdev;
+    uint8_t mac[ETH_ALEN];
+    uint16_t status;
+    VirtQueue *rx_vq;
+    VirtQueue *tx_vq;
+    VirtQueue *ctrl_vq;
+    NICState *nic;
+    QEMUTimer *tx_timer;
+    QEMUBH *tx_bh;
+    uint32_t tx_timeout;
+    int32_t tx_burst;
+    int tx_waiting;
+    uint32_t has_vnet_hdr;
+    size_t host_hdr_len;
+    size_t guest_hdr_len;
+    uint8_t has_ufo;
+    struct {
+        VirtQueueElement elem;
+        ssize_t len;
+    } async_tx;
+    int mergeable_rx_bufs;
+    uint8_t promisc;
+    uint8_t allmulti;
+    uint8_t alluni;
+    uint8_t nomulti;
+    uint8_t nouni;
+    uint8_t nobcast;
+    uint8_t vhost_started;
+    struct {
+        int in_use;
+        int first_multi;
+        uint8_t multi_overflow;
+        uint8_t uni_overflow;
+        uint8_t *macs;
+    } mac_table;
+    uint32_t *vlans;
+    DeviceState *qdev;
+} VirtIONet;
+
 #define VIRTIO_NET_CTRL_MAC    1
  #define VIRTIO_NET_CTRL_MAC_TABLE_SET        0
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 16/61] virtio-net : add the virtio-net device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (14 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 15/61] virtio-net : show the VirtIONet structure fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 17/61] virtio-net-pci : switch to the new API fred.konrad
                   ` (47 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-net which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-net.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 hw/virtio-net.h |  18 +++++++++
 hw/virtio-pci.c |  12 +++---
 hw/virtio-pci.h |   4 +-
 4 files changed, 136 insertions(+), 13 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 4ece6c2..6fe7e58 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -20,6 +20,7 @@
 #include "qemu/timer.h"
 #include "virtio-net.h"
 #include "vhost_net.h"
+#include "virtio-bus.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -30,6 +31,9 @@
  * - we could suppress RX interrupt if we were so inclined.
  */
 
+/*
+ * Moving to QOM later in this serie.
+ */
 static VirtIONet *to_virtio_net(VirtIODevice *vdev)
 {
     return (VirtIONet *)vdev;
@@ -969,14 +973,33 @@ static NetClientInfo net_virtio_info = {
     .link_status_changed = virtio_net_set_link_status,
 };
 
-VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
-                              virtio_net_conf *net)
+void virtio_net_set_conf(DeviceState *dev, virtio_net_conf *net_conf,
+                         NICConf *nic_conf)
 {
-    VirtIONet *n;
+    VirtIONet *n = VIRTIO_NET(dev);
+    memcpy(&(n->net_conf), net_conf, sizeof(struct virtio_net_conf));
+    memcpy(&(n->nic_conf), nic_conf, sizeof(struct NICConf));
+}
 
-    n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET,
-                                        sizeof(struct virtio_net_config),
-                                        sizeof(VirtIONet));
+static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
+                                           virtio_net_conf *net, VirtIONet **pn)
+{
+    VirtIONet *n = *pn;
+
+    /*
+     * We have two cases here : the old virtio-net-pci device, and the
+     * refactored virtio-net.
+     */
+    if (n == NULL) {
+        /* virtio-net-pci */
+        n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET,
+                                            sizeof(struct virtio_net_config),
+                                            sizeof(VirtIONet));
+    } else {
+        /* virtio-net */
+        virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
+                                      sizeof(struct virtio_net_config));
+    }
 
     n->vdev.get_config = virtio_net_get_config;
     n->vdev.set_config = virtio_net_set_config;
@@ -1036,6 +1059,13 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
     return &n->vdev;
 }
 
+VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
+                              virtio_net_conf *net)
+{
+    VirtIONet *n = NULL;
+    return virtio_net_common_init(dev, conf, net, &n);
+}
+
 void virtio_net_exit(VirtIODevice *vdev)
 {
     VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
@@ -1060,3 +1090,76 @@ void virtio_net_exit(VirtIODevice *vdev)
     qemu_del_net_client(&n->nic->nc);
     virtio_cleanup(&n->vdev);
 }
+
+static int virtio_net_device_init(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
+    if (virtio_net_common_init(qdev, &(n->nic_conf),
+                               &(n->net_conf), &n) == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
+static int virtio_net_device_exit(DeviceState *qdev)
+{
+    VirtIONet *n = VIRTIO_NET(qdev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+
+    /* This will stop vhost backend if appropriate. */
+    virtio_net_set_status(vdev, 0);
+
+    qemu_purge_queued_packets(&n->nic->nc);
+
+    unregister_savevm(qdev, "virtio-net", n);
+
+    g_free(n->mac_table.macs);
+    g_free(n->vlans);
+
+    if (n->tx_timer) {
+        qemu_del_timer(n->tx_timer);
+        qemu_free_timer(n->tx_timer);
+    } else {
+        qemu_bh_delete(n->tx_bh);
+    }
+
+    qemu_del_net_client(&n->nic->nc);
+    virtio_common_cleanup(vdev);
+    return 0;
+}
+
+static Property virtio_net_properties[] = {
+    DEFINE_VIRTIO_NET_PROPERTIES(VirtIONet),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_net_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_net_device_exit;
+    dc->props = virtio_net_properties;
+    vdc->init = virtio_net_device_init;
+    vdc->get_config = virtio_net_get_config;
+    vdc->set_config = virtio_net_set_config;
+    vdc->get_features = virtio_net_get_features;
+    vdc->set_features = virtio_net_set_features;
+    vdc->bad_features = virtio_net_bad_features;
+    vdc->reset = virtio_net_reset;
+    vdc->set_status = virtio_net_set_status;
+}
+
+static const TypeInfo virtio_net_info = {
+    .name = TYPE_VIRTIO_NET,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIONet),
+    .class_init = virtio_net_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_net_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index f6ff85d..2bdc8fd 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -17,6 +17,10 @@
 #include "virtio.h"
 #include "pci/pci.h"
 
+#define TYPE_VIRTIO_NET "virtio-net"
+#define VIRTIO_NET(obj) \
+        OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
+
 #define ETH_ALEN    6
 
 /* from Linux's virtio_net.h */
@@ -162,6 +166,8 @@ typedef struct VirtIONet {
         uint8_t *macs;
     } mac_table;
     uint32_t *vlans;
+    virtio_net_conf net_conf;
+    NICConf nic_conf;
     DeviceState *qdev;
 } VirtIONet;
 
@@ -200,4 +206,16 @@ typedef struct VirtIONet {
         DEFINE_PROP_BIT("ctrl_rx", _state, _field, VIRTIO_NET_F_CTRL_RX, true), \
         DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \
         DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true)
+
+#define DEFINE_VIRTIO_NET_PROPERTIES(_state)                        \
+        DEFINE_NIC_PROPERTIES(_state, nic_conf),                    \
+        DEFINE_PROP_UINT32("x-txtimer", _state, net_conf.txtimer,   \
+                           TX_TIMER_INTERVAL),                      \
+        DEFINE_PROP_INT32("x-txburst", _state, net_conf.txburst,    \
+                          TX_BURST),                                \
+        DEFINE_PROP_STRING("tx", _state, net_conf.tx)
+
+void virtio_net_set_conf(DeviceState *dev, virtio_net_conf *net_conf,
+                         NICConf *nic_conf);
+
 #endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 6043ee4..8ed6a08 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -819,7 +819,7 @@ static int virtio_net_init_pci(PCIDevice *pci_dev)
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
 
-    vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic, &proxy->net);
+    vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic_conf, &proxy->net_conf);
 
     vdev->nvectors = proxy->nvectors;
     virtio_init_pci(proxy, vdev);
@@ -904,10 +904,7 @@ static Property virtio_net_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
     DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
-    DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy, net.txtimer, TX_TIMER_INTERVAL),
-    DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy, net.txburst, TX_BURST),
-    DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
+    DEFINE_VIRTIO_NET_PROPERTIES(VirtIOPCIProxy),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -1113,6 +1110,11 @@ static void virtio_pci_device_plugged(DeviceState *d)
                                  PCI_DEVICE_ID_VIRTIO_BLOCK);
         pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
         break;
+    case VIRTIO_ID_NET:
+        pci_config_set_device_id(proxy->pci_dev.config,
+                                 PCI_DEVICE_ID_VIRTIO_NET);
+        pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_NETWORK_ETHERNET);
+        break;
     default:
         error_report("unknown device id\n");
         break;
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 9f22f79..e6647e2 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -69,13 +69,13 @@ struct VirtIOPCIProxy {
     uint32_t flags;
     uint32_t class_code;
     uint32_t nvectors;
-    NICConf nic;
+    NICConf nic_conf;
     uint32_t host_features;
 #ifdef CONFIG_LINUX
     V9fsConf fsconf;
 #endif
     virtio_serial_conf serial;
-    virtio_net_conf net;
+    virtio_net_conf net_conf;
     VirtIOSCSIConf scsi;
     VirtIORNGConf rng;
     bool ioeventfd_disabled;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 17/61] virtio-net-pci : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (15 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 16/61] virtio-net : add the virtio-net device fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 18/61] virtio-net-s390 " fred.konrad
                   ` (46 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-net-pci is modified for the new API. The device
virtio-net-pci extends virtio-pci. It creates and connects a virtio-net
during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 108 +++++++++++++++++++++++++++-----------------------------
 hw/virtio-pci.h |  17 +++++++--
 2 files changed, 67 insertions(+), 58 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 8ed6a08..06bdbe1 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -814,30 +814,6 @@ static void virtio_serial_exit_pci(PCIDevice *pci_dev)
     virtio_exit_pci(pci_dev);
 }
 
-static int virtio_net_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic_conf, &proxy->net_conf);
-
-    vdev->nvectors = proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-
-    /* make the actual value visible */
-    proxy->nvectors = vdev->nvectors;
-    return 0;
-}
-
-static void virtio_net_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_net_exit(proxy->vdev);
-    virtio_exit_pci(pci_dev);
-}
-
 static int virtio_balloon_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -900,37 +876,6 @@ static void virtio_rng_exit_pci(PCIDevice *pci_dev)
     virtio_exit_pci(pci_dev);
 }
 
-static Property virtio_net_properties[] = {
-    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
-    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
-    DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_VIRTIO_NET_PROPERTIES(VirtIOPCIProxy),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_net_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = virtio_net_init_pci;
-    k->exit = virtio_net_exit_pci;
-    k->romfile = "pxe-virtio.rom";
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = PCI_DEVICE_ID_VIRTIO_NET;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = PCI_CLASS_NETWORK_ETHERNET;
-    dc->reset = virtio_pci_reset;
-    dc->props = virtio_net_properties;
-}
-
-static TypeInfo virtio_net_info = {
-    .name          = "virtio-net-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
-    .class_init    = virtio_net_class_init,
-};
-
 static Property virtio_serial_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
@@ -1270,6 +1215,57 @@ static const TypeInfo virtio_blk_pci_info = {
     .class_init    = virtio_blk_pci_class_init,
 };
 
+/* virtio-net-pci */
+
+static Property virtio_net_properties[] = {
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+    DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetPCI),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+    virtio_net_set_conf(vdev, &(dev->net_conf), &(dev->nic_conf));
+    qdev_set_parent_bus(vdev, BUS(vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+    return 0;
+}
+
+static void virtio_net_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass);
+
+    k->romfile = "pxe-virtio.rom";
+    k->revision = VIRTIO_PCI_ABI_VERSION;
+    dc->props = virtio_net_properties;
+    vpciklass->init = virtio_net_pci_init;
+}
+
+
+static void virtio_net_pci_instance_init(Object *obj)
+{
+    VirtIONetPCI *dev = VIRTIO_NET_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_NET);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static TypeInfo virtio_net_pci_info = {
+    .name          = TYPE_VIRTIO_NET_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIONetPCI),
+    .instance_init = virtio_net_pci_instance_init,
+    .class_init    = virtio_net_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1309,7 +1305,6 @@ static const TypeInfo virtio_pci_bus_info = {
 
 static void virtio_pci_register_types(void)
 {
-    type_register_static(&virtio_net_info);
     type_register_static(&virtio_serial_info);
     type_register_static(&virtio_balloon_info);
     type_register_static(&virtio_scsi_info);
@@ -1317,6 +1312,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_pci_bus_info);
     type_register_static(&virtio_pci_info);
     type_register_static(&virtio_blk_pci_info);
+    type_register_static(&virtio_net_pci_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index e6647e2..b8cf743 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -24,6 +24,7 @@
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
+typedef struct VirtIONetPCI VirtIONetPCI;
 
 /* virtio-pci-bus */
 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
@@ -69,13 +70,11 @@ struct VirtIOPCIProxy {
     uint32_t flags;
     uint32_t class_code;
     uint32_t nvectors;
-    NICConf nic_conf;
     uint32_t host_features;
 #ifdef CONFIG_LINUX
     V9fsConf fsconf;
 #endif
     virtio_serial_conf serial;
-    virtio_net_conf net_conf;
     VirtIOSCSIConf scsi;
     VirtIORNGConf rng;
     bool ioeventfd_disabled;
@@ -98,6 +97,20 @@ struct VirtIOBlkPCI {
     VirtIOBlkConf blk;
 };
 
+/*
+ * virtio-net-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
+#define VIRTIO_NET_PCI(obj) \
+        OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
+
+struct VirtIONetPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIONet vdev;
+    virtio_net_conf net_conf;
+    NICConf nic_conf;
+};
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 18/61] virtio-net-s390 : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (16 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 17/61] virtio-net-pci : switch to the new API fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast fred.konrad
                   ` (45 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-net-s390 is modified for the new API. The device
virtio-net-s390 extends virtio-s390-device as before. It creates and
connects a virtio-net during the init. The properties are not modified.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 32 ++++++++++++++++++++------------
 hw/s390-virtio-bus.h | 15 +++++++++++++--
 2 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index d40fb8b..8a2c8b3 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -151,16 +151,23 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
     return 0;
 }
 
-static int s390_virtio_net_init(VirtIOS390Device *dev)
+static int s390_virtio_net_init(VirtIOS390Device *s390_dev)
 {
-    VirtIODevice *vdev;
-
-    vdev = virtio_net_init((DeviceState *)dev, &dev->nic, &dev->net);
-    if (!vdev) {
+    VirtIONetS390 *dev = VIRTIO_NET_S390(s390_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+    virtio_net_set_conf(vdev, &(dev->net), &(dev->nic));
+    qdev_set_parent_bus(vdev, BUS(s390_dev->bus));
+    if (qdev_init(vdev) < 0) {
         return -1;
     }
+    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+}
 
-    return s390_virtio_device_init(dev, vdev);
+static void s390_virtio_net_instance_init(Object *obj)
+{
+    VirtIONetS390 *dev = VIRTIO_NET_S390(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_NET);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
 static int s390_virtio_blk_init(VirtIOS390Device *s390_dev)
@@ -409,12 +416,12 @@ static const VirtIOBindings virtio_s390_bindings = {
 };
 
 static Property s390_virtio_net_properties[] = {
-    DEFINE_NIC_PROPERTIES(VirtIOS390Device, nic),
-    DEFINE_PROP_UINT32("x-txtimer", VirtIOS390Device,
+    DEFINE_NIC_PROPERTIES(VirtIONetS390, nic),
+    DEFINE_PROP_UINT32("x-txtimer", VirtIONetS390,
                        net.txtimer, TX_TIMER_INTERVAL),
-    DEFINE_PROP_INT32("x-txburst", VirtIOS390Device,
+    DEFINE_PROP_INT32("x-txburst", VirtIONetS390,
                       net.txburst, TX_BURST),
-    DEFINE_PROP_STRING("tx", VirtIOS390Device, net.tx),
+    DEFINE_PROP_STRING("tx", VirtIONetS390, net.tx),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -428,9 +435,10 @@ static void s390_virtio_net_class_init(ObjectClass *klass, void *data)
 }
 
 static TypeInfo s390_virtio_net = {
-    .name          = "virtio-net-s390",
+    .name          = TYPE_VIRTIO_NET_S390,
     .parent        = TYPE_VIRTIO_S390_DEVICE,
-    .instance_size = sizeof(VirtIOS390Device),
+    .instance_size = sizeof(VirtIONetS390),
+    .instance_init = s390_virtio_net_instance_init,
     .class_init    = s390_virtio_net_class_init,
 };
 
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index f5d0b94..f67ca51 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -85,10 +85,8 @@ struct VirtIOS390Device {
     ram_addr_t feat_offs;
     uint8_t feat_len;
     VirtIODevice *vdev;
-    NICConf nic;
     uint32_t host_features;
     virtio_serial_conf serial;
-    virtio_net_conf net;
     VirtIOSCSIConf scsi;
     VirtIORNGConf rng;
     VirtioBusState *bus;
@@ -127,5 +125,18 @@ typedef struct VirtIOBlkS390 {
     VirtIOBlkConf blk;
 } VirtIOBlkS390;
 
+/* virtio-net-s390 */
+
+#define TYPE_VIRTIO_NET_S390 "virtio-net-s390"
+#define VIRTIO_NET_S390(obj) \
+        OBJECT_CHECK(VirtIONetS390, (obj), TYPE_VIRTIO_NET_S390)
+
+typedef struct VirtIONetS390 {
+    VirtIOS390Device parent_obj;
+    VirtIONet vdev;
+    virtio_net_conf net;
+    NICConf nic;
+} VirtIONetS390;
+
 
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (17 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 18/61] virtio-net-s390 " fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 21:16   ` Michael S. Tsirkin
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 20/61] virtio-net : cleanup : init and exit function fred.konrad
                   ` (44 subsequent siblings)
  63 siblings, 1 reply; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-net-pci and virtio-net-s390 are switched to the new API,
we can use QOM casts. This shouldn't been applyied before virtio-net-pci
and virtio-net-s390 refactoring as their VirtIODevice were not a QOM
object.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-net.c | 147 ++++++++++++++++++++++++++++++--------------------------
 hw/virtio-net.h |   2 +-
 2 files changed, 80 insertions(+), 69 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 6fe7e58..9cf549a 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -31,17 +31,9 @@
  * - we could suppress RX interrupt if we were so inclined.
  */
 
-/*
- * Moving to QOM later in this serie.
- */
-static VirtIONet *to_virtio_net(VirtIODevice *vdev)
-{
-    return (VirtIONet *)vdev;
-}
-
 static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
     struct virtio_net_config netcfg;
 
     stw_p(&netcfg.status, n->status);
@@ -51,7 +43,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
 
 static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
     struct virtio_net_config netcfg;
 
     memcpy(&netcfg, config, sizeof(netcfg));
@@ -64,12 +56,14 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
 
 static bool virtio_net_started(VirtIONet *n, uint8_t status)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     return (status & VIRTIO_CONFIG_S_DRIVER_OK) &&
-        (n->status & VIRTIO_NET_S_LINK_UP) && n->vdev.vm_running;
+        (n->status & VIRTIO_NET_S_LINK_UP) && vdev->vm_running;
 }
 
 static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     if (!n->nic->nc.peer) {
         return;
     }
@@ -86,10 +80,10 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
     }
     if (!n->vhost_started) {
         int r;
-        if (!vhost_net_query(tap_get_vhost_net(n->nic->nc.peer), &n->vdev)) {
+        if (!vhost_net_query(tap_get_vhost_net(n->nic->nc.peer), vdev)) {
             return;
         }
-        r = vhost_net_start(tap_get_vhost_net(n->nic->nc.peer), &n->vdev);
+        r = vhost_net_start(tap_get_vhost_net(n->nic->nc.peer), vdev);
         if (r < 0) {
             error_report("unable to start vhost net: %d: "
                          "falling back on userspace virtio", -r);
@@ -97,14 +91,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
             n->vhost_started = 1;
         }
     } else {
-        vhost_net_stop(tap_get_vhost_net(n->nic->nc.peer), &n->vdev);
+        vhost_net_stop(tap_get_vhost_net(n->nic->nc.peer), vdev);
         n->vhost_started = 0;
     }
 }
 
 static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     virtio_net_vhost_status(n, status);
 
@@ -130,7 +124,9 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
 
 static void virtio_net_set_link_status(NetClientState *nc)
 {
-    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
+    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     uint16_t old_status = n->status;
 
     if (nc->link_down)
@@ -139,14 +135,14 @@ static void virtio_net_set_link_status(NetClientState *nc)
         n->status |= VIRTIO_NET_S_LINK_UP;
 
     if (n->status != old_status)
-        virtio_notify_config(&n->vdev);
+        virtio_notify_config(vdev);
 
-    virtio_net_set_status(&n->vdev, n->vdev.status);
+    virtio_net_set_status(vdev, vdev->status);
 }
 
 static void virtio_net_reset(VirtIODevice *vdev)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     /* Reset back to compatibility mode */
     n->promisc = 1;
@@ -207,7 +203,7 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs)
 
 static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     features |= (1 << VIRTIO_NET_F_MAC);
 
@@ -255,7 +251,7 @@ static uint32_t virtio_net_bad_features(VirtIODevice *vdev)
 
 static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     virtio_net_set_mrg_rx_bufs(n, !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF)));
 
@@ -386,7 +382,7 @@ static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd,
 
 static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
     struct virtio_net_ctrl_hdr ctrl;
     virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
     VirtQueueElement elem;
@@ -424,20 +420,22 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 
 static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     qemu_flush_queued_packets(&n->nic->nc);
 }
 
 static int virtio_net_can_receive(NetClientState *nc)
 {
-    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
-    if (!n->vdev.vm_running) {
+    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
+    if (!vdev->vm_running) {
         return 0;
     }
 
     if (!virtio_queue_ready(n->rx_vq) ||
-        !(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
+        !(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK))
         return 0;
 
     return 1;
@@ -562,7 +560,9 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
 
 static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 {
-    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
+    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     struct iovec mhdr_sg[VIRTQUEUE_MAX_SIZE];
     struct virtio_net_hdr_mrg_rxbuf mhdr;
     unsigned mhdr_cnt = 0;
@@ -594,7 +594,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
                     "i %zd mergeable %d offset %zd, size %zd, "
                     "guest hdr len %zd, host hdr len %zd guest features 0x%x",
                     i, n->mergeable_rx_bufs, offset, size,
-                    n->guest_hdr_len, n->host_hdr_len, n->vdev.guest_features);
+                    n->guest_hdr_len, n->host_hdr_len, vdev->guest_features);
             exit(1);
         }
 
@@ -651,7 +651,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t
     }
 
     virtqueue_flush(n->rx_vq, i);
-    virtio_notify(&n->vdev, n->rx_vq);
+    virtio_notify(vdev, n->rx_vq);
 
     return size;
 }
@@ -660,10 +660,12 @@ static int32_t virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq);
 
 static void virtio_net_tx_complete(NetClientState *nc, ssize_t len)
 {
-    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
+    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
 
     virtqueue_push(n->tx_vq, &n->async_tx.elem, 0);
-    virtio_notify(&n->vdev, n->tx_vq);
+    virtio_notify(vdev, n->tx_vq);
 
     n->async_tx.elem.out_num = n->async_tx.len = 0;
 
@@ -674,13 +676,14 @@ static void virtio_net_tx_complete(NetClientState *nc, ssize_t len)
 /* TX */
 static int32_t virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     VirtQueueElement elem;
     int32_t num_packets = 0;
-    if (!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+    if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
         return num_packets;
     }
 
-    assert(n->vdev.vm_running);
+    assert(vdev->vm_running);
 
     if (n->async_tx.elem.out_num) {
         virtio_queue_set_notification(n->tx_vq, 0);
@@ -729,7 +732,7 @@ static int32_t virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
         len += ret;
 
         virtqueue_push(vq, &elem, 0);
-        virtio_notify(&n->vdev, vq);
+        virtio_notify(vdev, vq);
 
         if (++num_packets >= n->tx_burst) {
             break;
@@ -740,10 +743,10 @@ static int32_t virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
 
 static void virtio_net_handle_tx_timer(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     /* This happens when device was stopped but VCPU wasn't. */
-    if (!n->vdev.vm_running) {
+    if (!vdev->vm_running) {
         n->tx_waiting = 1;
         return;
     }
@@ -763,14 +766,14 @@ static void virtio_net_handle_tx_timer(VirtIODevice *vdev, VirtQueue *vq)
 
 static void virtio_net_handle_tx_bh(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIONet *n = to_virtio_net(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     if (unlikely(n->tx_waiting)) {
         return;
     }
     n->tx_waiting = 1;
     /* This happens when device was stopped but VCPU wasn't. */
-    if (!n->vdev.vm_running) {
+    if (!vdev->vm_running) {
         return;
     }
     virtio_queue_set_notification(vq, 0);
@@ -779,14 +782,16 @@ static void virtio_net_handle_tx_bh(VirtIODevice *vdev, VirtQueue *vq)
 
 static void virtio_net_tx_timer(void *opaque)
 {
-    VirtIONet *n = opaque;
-    assert(n->vdev.vm_running);
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
+    assert(vdev->vm_running);
 
     n->tx_waiting = 0;
 
     /* Just in case the driver is not ready on more */
-    if (!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
+    if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
         return;
+    }
 
     virtio_queue_set_notification(n->tx_vq, 1);
     virtio_net_flush_tx(n, n->tx_vq);
@@ -794,16 +799,18 @@ static void virtio_net_tx_timer(void *opaque)
 
 static void virtio_net_tx_bh(void *opaque)
 {
-    VirtIONet *n = opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     int32_t ret;
 
-    assert(n->vdev.vm_running);
+    assert(vdev->vm_running);
 
     n->tx_waiting = 0;
 
     /* Just in case the driver is not ready on more */
-    if (unlikely(!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK)))
+    if (unlikely(!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK))) {
         return;
+    }
 
     ret = virtio_net_flush_tx(n, n->tx_vq);
     if (ret == -EBUSY) {
@@ -831,12 +838,13 @@ static void virtio_net_tx_bh(void *opaque)
 
 static void virtio_net_save(QEMUFile *f, void *opaque)
 {
-    VirtIONet *n = opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
 
     /* At this point, backend must be stopped, otherwise
      * it might keep writing to memory. */
     assert(!n->vhost_started);
-    virtio_save(&n->vdev, f);
+    virtio_save(vdev, f);
 
     qemu_put_buffer(f, n->mac, ETH_ALEN);
     qemu_put_be32(f, n->tx_waiting);
@@ -859,14 +867,15 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
 
 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
 {
-    VirtIONet *n = opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     int i;
     int ret;
 
     if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
         return -EINVAL;
 
-    ret = virtio_load(&n->vdev, f);
+    ret = virtio_load(vdev, f);
     if (ret) {
         return ret;
     }
@@ -915,11 +924,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
 
         if (n->has_vnet_hdr) {
             tap_set_offload(n->nic->nc.peer,
-                    (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
-                    (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
-                    (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
-                    (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_ECN)  & 1,
-                    (n->vdev.guest_features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
+                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
+                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
+                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
+                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_ECN)  & 1,
+                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
         }
     }
 
@@ -959,7 +968,8 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
 
 static void virtio_net_cleanup(NetClientState *nc)
 {
-    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
+    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
+    VirtIONet *n = VIRTIO_NET(opaque);
 
     n->nic = NULL;
 }
@@ -985,6 +995,7 @@ static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
                                            virtio_net_conf *net, VirtIONet **pn)
 {
     VirtIONet *n = *pn;
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 
     /*
      * We have two cases here : the old virtio-net-pci device, and the
@@ -1001,14 +1012,14 @@ static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
                                       sizeof(struct virtio_net_config));
     }
 
-    n->vdev.get_config = virtio_net_get_config;
-    n->vdev.set_config = virtio_net_set_config;
-    n->vdev.get_features = virtio_net_get_features;
-    n->vdev.set_features = virtio_net_set_features;
-    n->vdev.bad_features = virtio_net_bad_features;
-    n->vdev.reset = virtio_net_reset;
-    n->vdev.set_status = virtio_net_set_status;
-    n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
+    vdev->get_config = virtio_net_get_config;
+    vdev->set_config = virtio_net_set_config;
+    vdev->get_features = virtio_net_get_features;
+    vdev->set_features = virtio_net_set_features;
+    vdev->bad_features = virtio_net_bad_features;
+    vdev->reset = virtio_net_reset;
+    vdev->set_status = virtio_net_set_status;
+    n->rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
 
     if (net->tx && strcmp(net->tx, "timer") && strcmp(net->tx, "bh")) {
         error_report("virtio-net: "
@@ -1018,14 +1029,14 @@ static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
     }
 
     if (net->tx && !strcmp(net->tx, "timer")) {
-        n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx_timer);
+        n->tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_timer);
         n->tx_timer = qemu_new_timer_ns(vm_clock, virtio_net_tx_timer, n);
         n->tx_timeout = net->txtimer;
     } else {
-        n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx_bh);
+        n->tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh);
         n->tx_bh = qemu_bh_new(virtio_net_tx_bh, n);
     }
-    n->ctrl_vq = virtio_add_queue(&n->vdev, 64, virtio_net_handle_ctrl);
+    n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl);
     qemu_macaddr_default_if_unset(&conf->macaddr);
     memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
@@ -1056,7 +1067,7 @@ static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
 
     add_boot_device_path(conf->bootindex, dev, "/ethernet-phy@0");
 
-    return &n->vdev;
+    return vdev;
 }
 
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
@@ -1068,7 +1079,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
 
 void virtio_net_exit(VirtIODevice *vdev)
 {
-    VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
 
     /* This will stop vhost backend if appropriate. */
     virtio_net_set_status(vdev, 0);
@@ -1088,7 +1099,7 @@ void virtio_net_exit(VirtIODevice *vdev)
     }
 
     qemu_del_net_client(&n->nic->nc);
-    virtio_cleanup(&n->vdev);
+    virtio_cleanup(vdev);
 }
 
 static int virtio_net_device_init(VirtIODevice *vdev)
diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index 2bdc8fd..3246a28 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -130,7 +130,7 @@ struct virtio_net_ctrl_mac {
 };
 
 typedef struct VirtIONet {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
     uint8_t mac[ETH_ALEN];
     uint16_t status;
     VirtQueue *rx_vq;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 20/61] virtio-net : cleanup : init and exit function.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (18 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 21/61] virtio-net : cleanup : remove qdev field fred.konrad
                   ` (43 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.
This shouldn't been applyied before virtio-net-pci and virtio-net-s390
refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-net.c | 95 ++++++++++++---------------------------------------------
 1 file changed, 20 insertions(+), 75 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 9cf549a..263ca46 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -991,26 +991,13 @@ void virtio_net_set_conf(DeviceState *dev, virtio_net_conf *net_conf,
     memcpy(&(n->nic_conf), nic_conf, sizeof(struct NICConf));
 }
 
-static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
-                                           virtio_net_conf *net, VirtIONet **pn)
+static int virtio_net_device_init(VirtIODevice *vdev)
 {
-    VirtIONet *n = *pn;
-    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-
-    /*
-     * We have two cases here : the old virtio-net-pci device, and the
-     * refactored virtio-net.
-     */
-    if (n == NULL) {
-        /* virtio-net-pci */
-        n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET,
-                                            sizeof(struct virtio_net_config),
-                                            sizeof(VirtIONet));
-    } else {
-        /* virtio-net */
-        virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
-                                      sizeof(struct virtio_net_config));
-    }
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
+
+    virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
+                                  sizeof(struct virtio_net_config));
 
     vdev->get_config = virtio_net_get_config;
     vdev->set_config = virtio_net_set_config;
@@ -1021,27 +1008,29 @@ static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
     vdev->set_status = virtio_net_set_status;
     n->rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
 
-    if (net->tx && strcmp(net->tx, "timer") && strcmp(net->tx, "bh")) {
+    if (n->net_conf.tx && strcmp(n->net_conf.tx, "timer") &&
+                           strcmp(n->net_conf.tx, "bh")) {
         error_report("virtio-net: "
                      "Unknown option tx=%s, valid options: \"timer\" \"bh\"",
-                     net->tx);
+                     n->net_conf.tx);
         error_report("Defaulting to \"bh\"");
     }
 
-    if (net->tx && !strcmp(net->tx, "timer")) {
+    if (n->net_conf.tx && !strcmp(n->net_conf.tx, "timer")) {
         n->tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_timer);
         n->tx_timer = qemu_new_timer_ns(vm_clock, virtio_net_tx_timer, n);
-        n->tx_timeout = net->txtimer;
+        n->tx_timeout = n->net_conf.txtimer;
     } else {
         n->tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh);
         n->tx_bh = qemu_bh_new(virtio_net_tx_bh, n);
     }
     n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl);
-    qemu_macaddr_default_if_unset(&conf->macaddr);
-    memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
+    qemu_macaddr_default_if_unset(&(n->nic_conf.macaddr));
+    memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
 
-    n->nic = qemu_new_nic(&net_virtio_info, conf, object_get_typename(OBJECT(dev)), dev->id, n);
+    n->nic = qemu_new_nic(&net_virtio_info, &(n->nic_conf),
+                          object_get_typename(OBJECT(qdev)), qdev->id, n);
     peer_test_vnet_hdr(n);
     if (peer_has_vnet_hdr(n)) {
         tap_using_vnet_hdr(n->nic->nc.peer, 1);
@@ -1050,10 +1039,10 @@ static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
         n->host_hdr_len = 0;
     }
 
-    qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
+    qemu_format_nic_info_str(&n->nic->nc, n->nic_conf.macaddr.a);
 
     n->tx_waiting = 0;
-    n->tx_burst = net->txburst;
+    n->tx_burst = n->net_conf.txburst;
     virtio_net_set_mrg_rx_bufs(n, 0);
     n->promisc = 1; /* for compatibility */
 
@@ -1061,55 +1050,11 @@ static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
 
     n->vlans = g_malloc0(MAX_VLAN >> 3);
 
-    n->qdev = dev;
-    register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
+    n->qdev = qdev;
+    register_savevm(qdev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
 
-    add_boot_device_path(conf->bootindex, dev, "/ethernet-phy@0");
-
-    return vdev;
-}
-
-VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
-                              virtio_net_conf *net)
-{
-    VirtIONet *n = NULL;
-    return virtio_net_common_init(dev, conf, net, &n);
-}
-
-void virtio_net_exit(VirtIODevice *vdev)
-{
-    VirtIONet *n = VIRTIO_NET(vdev);
-
-    /* This will stop vhost backend if appropriate. */
-    virtio_net_set_status(vdev, 0);
-
-    qemu_purge_queued_packets(&n->nic->nc);
-
-    unregister_savevm(n->qdev, "virtio-net", n);
-
-    g_free(n->mac_table.macs);
-    g_free(n->vlans);
-
-    if (n->tx_timer) {
-        qemu_del_timer(n->tx_timer);
-        qemu_free_timer(n->tx_timer);
-    } else {
-        qemu_bh_delete(n->tx_bh);
-    }
-
-    qemu_del_net_client(&n->nic->nc);
-    virtio_cleanup(vdev);
-}
-
-static int virtio_net_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIONet *n = VIRTIO_NET(vdev);
-    if (virtio_net_common_init(qdev, &(n->nic_conf),
-                               &(n->net_conf), &n) == NULL) {
-        return -1;
-    }
+    add_boot_device_path(n->nic_conf.bootindex, qdev, "/ethernet-phy@0");
     return 0;
 }
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 21/61] virtio-net : cleanup : remove qdev field.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (19 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 20/61] virtio-net : cleanup : init and exit function fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 22/61] virtio-scsi : show the VirtIOSCSI structure fred.konrad
                   ` (42 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The qdev field is no longer needed. Just drop it.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-net.c | 1 -
 hw/virtio-net.h | 1 -
 2 files changed, 2 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 263ca46..7f87166 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -1050,7 +1050,6 @@ static int virtio_net_device_init(VirtIODevice *vdev)
 
     n->vlans = g_malloc0(MAX_VLAN >> 3);
 
-    n->qdev = qdev;
     register_savevm(qdev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
 
diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index 3246a28..a01416b 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -168,7 +168,6 @@ typedef struct VirtIONet {
     uint32_t *vlans;
     virtio_net_conf net_conf;
     NICConf nic_conf;
-    DeviceState *qdev;
 } VirtIONet;
 
 #define VIRTIO_NET_CTRL_MAC    1
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 22/61] virtio-scsi : show the VirtIOSCSI structure.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (20 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 21/61] virtio-net : cleanup : remove qdev field fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 23/61] virtio-scsi : don't use pointer for configuration fred.konrad
                   ` (41 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As we discuss with anthony and andreas, this structure must be showed to avoid
two memory allocations for virtio-scsi-x.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-scsi.c | 15 ---------------
 hw/virtio-scsi.h | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index bfe1860..4e2d884 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -129,21 +129,6 @@ typedef struct {
     uint32_t max_lun;
 } QEMU_PACKED VirtIOSCSIConfig;
 
-typedef struct {
-    VirtIODevice vdev;
-    DeviceState *qdev;
-    VirtIOSCSIConf *conf;
-
-    SCSIBus bus;
-    uint32_t sense_size;
-    uint32_t cdb_size;
-    int resetting;
-    bool events_dropped;
-    VirtQueue *ctrl_vq;
-    VirtQueue *event_vq;
-    VirtQueue *cmd_vqs[0];
-} VirtIOSCSI;
-
 typedef struct VirtIOSCSIReq {
     VirtIOSCSI *dev;
     VirtQueue *vq;
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 8d9d15f..38b9c0f 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -16,6 +16,7 @@
 
 #include "virtio.h"
 #include "pci/pci.h"
+#include <hw/scsi.h>
 
 /* The ID for virtio_scsi */
 #define VIRTIO_ID_SCSI  8
@@ -31,6 +32,21 @@ struct VirtIOSCSIConf {
     uint32_t cmd_per_lun;
 };
 
+typedef struct {
+    VirtIODevice vdev;
+    DeviceState *qdev;
+    VirtIOSCSIConf *conf;
+
+    SCSIBus bus;
+    uint32_t sense_size;
+    uint32_t cdb_size;
+    int resetting;
+    bool events_dropped;
+    VirtQueue *ctrl_vq;
+    VirtQueue *event_vq;
+    VirtQueue *cmd_vqs[0];
+} VirtIOSCSI;
+
 #define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _features_field, _conf_field) \
     DEFINE_VIRTIO_COMMON_FEATURES(_state, _features_field), \
     DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1), \
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 23/61] virtio-scsi : don't use pointer for configuration.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (21 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 22/61] virtio-scsi : show the VirtIOSCSI structure fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 24/61] virtio-scsi : allocate cmd_vqs array separately fred.konrad
                   ` (40 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The configuration field must not be a pointer as it will be used for virtio-scsi
properties. So *conf is replaced by conf.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-scsi.c | 14 +++++++-------
 hw/virtio-scsi.h |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 4e2d884..1bd689c 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -236,7 +236,7 @@ static void virtio_scsi_save_request(QEMUFile *f, SCSIRequest *sreq)
     VirtIOSCSIReq *req = sreq->hba_private;
     uint32_t n = virtio_queue_get_id(req->vq) - 2;
 
-    assert(n < req->dev->conf->num_queues);
+    assert(n < req->dev->conf.num_queues);
     qemu_put_be32s(f, &n);
     qemu_put_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
 }
@@ -250,7 +250,7 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
 
     req = g_malloc(sizeof(*req));
     qemu_get_be32s(f, &n);
-    assert(n < s->conf->num_queues);
+    assert(n < s->conf.num_queues);
     qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
     virtio_scsi_parse_req(s, s->cmd_vqs[n], req);
 
@@ -512,10 +512,10 @@ static void virtio_scsi_get_config(VirtIODevice *vdev,
     VirtIOSCSIConfig *scsiconf = (VirtIOSCSIConfig *)config;
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
 
-    stl_raw(&scsiconf->num_queues, s->conf->num_queues);
+    stl_raw(&scsiconf->num_queues, s->conf.num_queues);
     stl_raw(&scsiconf->seg_max, 128 - 2);
-    stl_raw(&scsiconf->max_sectors, s->conf->max_sectors);
-    stl_raw(&scsiconf->cmd_per_lun, s->conf->cmd_per_lun);
+    stl_raw(&scsiconf->max_sectors, s->conf.max_sectors);
+    stl_raw(&scsiconf->cmd_per_lun, s->conf.cmd_per_lun);
     stl_raw(&scsiconf->event_info_size, sizeof(VirtIOSCSIEvent));
     stl_raw(&scsiconf->sense_size, s->sense_size);
     stl_raw(&scsiconf->cdb_size, s->cdb_size);
@@ -693,7 +693,7 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
                                          sizeof(VirtIOSCSIConfig), sz);
 
     s->qdev = dev;
-    s->conf = proxyconf;
+    memcpy(&(s->conf), proxyconf, sizeof(struct VirtIOSCSIConf));
 
     /* TODO set up vdev function pointers */
     s->vdev.get_config = virtio_scsi_get_config;
@@ -705,7 +705,7 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
                                    virtio_scsi_handle_ctrl);
     s->event_vq = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
                                    virtio_scsi_handle_event);
-    for (i = 0; i < s->conf->num_queues; i++) {
+    for (i = 0; i < s->conf.num_queues; i++) {
         s->cmd_vqs[i] = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
                                          virtio_scsi_handle_cmd);
     }
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 38b9c0f..6e027be 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -35,7 +35,7 @@ struct VirtIOSCSIConf {
 typedef struct {
     VirtIODevice vdev;
     DeviceState *qdev;
-    VirtIOSCSIConf *conf;
+    VirtIOSCSIConf conf;
 
     SCSIBus bus;
     uint32_t sense_size;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 24/61] virtio-scsi : allocate cmd_vqs array separately.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (22 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 23/61] virtio-scsi : don't use pointer for configuration fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 25/61] virtio-scsi : moving host_features from properties to transport properties fred.konrad
                   ` (39 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Allocate/Free the cmd_vqs array separately to have a fixed size device.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-scsi.c | 6 +++---
 hw/virtio-scsi.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 1bd689c..7b922ab 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -685,12 +685,12 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
 {
     VirtIOSCSI *s;
     static int virtio_scsi_id;
-    size_t sz;
     int i;
 
-    sz = sizeof(VirtIOSCSI) + proxyconf->num_queues * sizeof(VirtQueue *);
     s = (VirtIOSCSI *)virtio_common_init("virtio-scsi", VIRTIO_ID_SCSI,
-                                         sizeof(VirtIOSCSIConfig), sz);
+                                         sizeof(VirtIOSCSIConfig),
+                                         sizeof(VirtIOSCSI));
+    s->cmd_vqs = g_malloc0(proxyconf->num_queues * sizeof(VirtQueue *));
 
     s->qdev = dev;
     memcpy(&(s->conf), proxyconf, sizeof(struct VirtIOSCSIConf));
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 6e027be..c659ba1 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -44,7 +44,7 @@ typedef struct {
     bool events_dropped;
     VirtQueue *ctrl_vq;
     VirtQueue *event_vq;
-    VirtQueue *cmd_vqs[0];
+    VirtQueue **cmd_vqs;
 } VirtIOSCSI;
 
 #define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _features_field, _conf_field) \
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 25/61] virtio-scsi : moving host_features from properties to transport properties.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (23 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 24/61] virtio-scsi : allocate cmd_vqs array separately fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 26/61] virtio-scsi : add the virtio-scsi device fred.konrad
                   ` (38 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

host_features field is part of the transport device. So move all the
host_features related properties into transport device.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 7 ++++++-
 hw/virtio-pci.c      | 7 ++++++-
 hw/virtio-scsi.h     | 9 +++------
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 8a2c8b3..283b7b6 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -543,7 +543,12 @@ static TypeInfo virtio_s390_device_info = {
 };
 
 static Property s390_virtio_scsi_properties[] = {
-    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOS390Device, host_features, scsi),
+    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOS390Device, scsi),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
+    DEFINE_PROP_BIT("hotplug", VirtIOS390Device, host_features,
+                    VIRTIO_SCSI_F_HOTPLUG, true),
+    DEFINE_PROP_BIT("param_change", VirtIOS390Device, host_features,
+                    VIRTIO_SCSI_F_CHANGE, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 06bdbe1..8955b73 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1010,7 +1010,12 @@ static void virtio_scsi_exit_pci(PCIDevice *pci_dev)
 static Property virtio_scsi_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
-    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, host_features, scsi),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_PROP_BIT("hotplug", VirtIOPCIProxy, host_features,
+                    VIRTIO_SCSI_F_HOTPLUG, true),
+    DEFINE_PROP_BIT("param_change", VirtIOPCIProxy, host_features,
+                    VIRTIO_SCSI_F_CHANGE, true),
+    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, scsi),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index c659ba1..197a7b5 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -47,12 +47,9 @@ typedef struct {
     VirtQueue **cmd_vqs;
 } VirtIOSCSI;
 
-#define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _features_field, _conf_field) \
-    DEFINE_VIRTIO_COMMON_FEATURES(_state, _features_field), \
+#define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _conf_field) \
     DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1), \
-    DEFINE_PROP_UINT32("max_sectors", _state, _conf_field.max_sectors, 0xFFFF), \
-    DEFINE_PROP_UINT32("cmd_per_lun", _state, _conf_field.cmd_per_lun, 128), \
-    DEFINE_PROP_BIT("hotplug", _state, _features_field, VIRTIO_SCSI_F_HOTPLUG, true), \
-    DEFINE_PROP_BIT("param_change", _state, _features_field, VIRTIO_SCSI_F_CHANGE, true)
+    DEFINE_PROP_UINT32("max_sectors", _state, _conf_field.max_sectors, 0xFFFF),\
+    DEFINE_PROP_UINT32("cmd_per_lun", _state, _conf_field.cmd_per_lun, 128)
 
 #endif /* _QEMU_VIRTIO_SCSI_H */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 26/61] virtio-scsi : add the virtio-scsi device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (24 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 25/61] virtio-scsi : moving host_features from properties to transport properties fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 27/61] virtio-scsi-pci : switch to new API fred.konrad
                   ` (37 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-scsi which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c  |  5 ++++
 hw/virtio-scsi.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-scsi.h |  7 +++++
 3 files changed, 98 insertions(+), 5 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 8955b73..be382c0 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1065,6 +1065,11 @@ static void virtio_pci_device_plugged(DeviceState *d)
                                  PCI_DEVICE_ID_VIRTIO_NET);
         pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_NETWORK_ETHERNET);
         break;
+    case VIRTIO_ID_SCSI:
+        pci_config_set_device_id(proxy->pci_dev.config,
+                                 PCI_DEVICE_ID_VIRTIO_SCSI);
+        pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
+        break;
     default:
         error_report("unknown device id\n");
         break;
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 7b922ab..ad07a65 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -16,6 +16,7 @@
 #include "virtio-scsi.h"
 #include <hw/scsi.h>
 #include <hw/scsi-defs.h>
+#include "virtio-bus.h"
 
 #define VIRTIO_SCSI_VQ_SIZE     128
 #define VIRTIO_SCSI_CDB_SIZE    32
@@ -681,15 +682,36 @@ static struct SCSIBusInfo virtio_scsi_scsi_info = {
     .load_request = virtio_scsi_load_request,
 };
 
-VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
+void virtio_scsi_set_conf(DeviceState *qdev, VirtIOSCSIConf *conf)
 {
-    VirtIOSCSI *s;
+    VirtIOSCSI *s = VIRTIO_SCSI(qdev);
+    memcpy(&(s->conf), conf, sizeof(struct VirtIOSCSIConf));
+}
+
+static VirtIODevice *virtio_scsi_common_init(DeviceState *dev,
+                                             VirtIOSCSIConf *proxyconf,
+                                             VirtIOSCSI **ps)
+{
+    VirtIOSCSI *s = *ps;
     static int virtio_scsi_id;
     int i;
 
-    s = (VirtIOSCSI *)virtio_common_init("virtio-scsi", VIRTIO_ID_SCSI,
-                                         sizeof(VirtIOSCSIConfig),
-                                         sizeof(VirtIOSCSI));
+    /*
+     * We have two cases here : the old virtio-net-pci device, and the
+     * refactored virtio-net.
+     */
+
+    if (s == NULL) {
+        /* virtio-scsi-pci */
+        s = (VirtIOSCSI *)virtio_common_init("virtio-scsi", VIRTIO_ID_SCSI,
+                                             sizeof(VirtIOSCSIConfig),
+                                             sizeof(VirtIOSCSI));
+    } else {
+        /* virtio-scsi */
+        virtio_init(VIRTIO_DEVICE(s), "virtio-scsi", VIRTIO_ID_SCSI,
+                    sizeof(VirtIOSCSIConfig));
+    }
+
     s->cmd_vqs = g_malloc0(proxyconf->num_queues * sizeof(VirtQueue *));
 
     s->qdev = dev;
@@ -721,9 +743,68 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
     return &s->vdev;
 }
 
+VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
+{
+    VirtIOSCSI *s = NULL;
+    return virtio_scsi_common_init(dev, proxyconf, &s);
+}
+
 void virtio_scsi_exit(VirtIODevice *vdev)
 {
     VirtIOSCSI *s = (VirtIOSCSI *)vdev;
     unregister_savevm(s->qdev, "virtio-scsi", s);
     virtio_cleanup(vdev);
 }
+
+static int virtio_scsi_device_init(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+    if (virtio_scsi_common_init(qdev, &(s->conf), &s) == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
+static int virtio_scsi_device_exit(DeviceState *qdev)
+{
+    VirtIOSCSI *s = VIRTIO_SCSI(qdev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+
+    unregister_savevm(qdev, "virtio-scsi", s);
+    g_free(s->cmd_vqs);
+    virtio_common_cleanup(vdev);
+    return 0;
+}
+
+static Property virtio_scsi_properties[] = {
+    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSI, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_scsi_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_scsi_device_exit;
+    dc->props = virtio_scsi_properties;
+    vdc->init = virtio_scsi_device_init;
+    vdc->get_config = virtio_scsi_get_config;
+    vdc->set_config = virtio_scsi_set_config;
+    vdc->get_features = virtio_scsi_get_features;
+    vdc->reset = virtio_scsi_reset;
+}
+
+static const TypeInfo virtio_scsi_info = {
+    .name = TYPE_VIRTIO_SCSI,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOSCSI),
+    .class_init = virtio_scsi_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_scsi_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 197a7b5..67d9067 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -18,6 +18,11 @@
 #include "pci/pci.h"
 #include <hw/scsi.h>
 
+#define TYPE_VIRTIO_SCSI "virtio-scsi"
+#define VIRTIO_SCSI(obj) \
+        OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
+
+
 /* The ID for virtio_scsi */
 #define VIRTIO_ID_SCSI  8
 
@@ -52,4 +57,6 @@ typedef struct {
     DEFINE_PROP_UINT32("max_sectors", _state, _conf_field.max_sectors, 0xFFFF),\
     DEFINE_PROP_UINT32("cmd_per_lun", _state, _conf_field.cmd_per_lun, 128)
 
+void virtio_scsi_set_conf(DeviceState *qdev, VirtIOSCSIConf *conf);
+
 #endif /* _QEMU_VIRTIO_SCSI_H */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 27/61] virtio-scsi-pci : switch to new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (25 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 26/61] virtio-scsi : add the virtio-scsi device fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 28/61] virtio-scsi-s390 : switch to the " fred.konrad
                   ` (36 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-scsi-pci is modified for the new API. The device virtio-scsi-pci
extends virtio-pci. It creates and connects a virtio-scsi during the init.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 121 +++++++++++++++++++++++++++-----------------------------
 hw/virtio-pci.h |  15 ++++++-
 2 files changed, 72 insertions(+), 64 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index be382c0..bbdb576 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -979,68 +979,6 @@ static TypeInfo virtio_rng_info = {
     .class_init    = virtio_rng_class_init,
 };
 
-static int virtio_scsi_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    vdev = virtio_scsi_init(&pci_dev->qdev, &proxy->scsi);
-    if (!vdev) {
-        return -EINVAL;
-    }
-
-    vdev->nvectors = proxy->nvectors == DEV_NVECTORS_UNSPECIFIED
-                                        ? proxy->scsi.num_queues + 3
-                                        : proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-
-    /* make the actual value visible */
-    proxy->nvectors = vdev->nvectors;
-    return 0;
-}
-
-static void virtio_scsi_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    virtio_scsi_exit(proxy->vdev);
-    virtio_exit_pci(pci_dev);
-}
-
-static Property virtio_scsi_properties[] = {
-    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
-    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_PROP_BIT("hotplug", VirtIOPCIProxy, host_features,
-                    VIRTIO_SCSI_F_HOTPLUG, true),
-    DEFINE_PROP_BIT("param_change", VirtIOPCIProxy, host_features,
-                    VIRTIO_SCSI_F_CHANGE, true),
-    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, scsi),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_scsi_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = virtio_scsi_init_pci;
-    k->exit = virtio_scsi_exit_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI;
-    k->revision = 0x00;
-    k->class_id = PCI_CLASS_STORAGE_SCSI;
-    dc->reset = virtio_pci_reset;
-    dc->props = virtio_scsi_properties;
-}
-
-static TypeInfo virtio_scsi_info = {
-    .name          = "virtio-scsi-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
-    .class_init    = virtio_scsi_class_init,
-};
-
 /*
  * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
  */
@@ -1276,6 +1214,63 @@ static TypeInfo virtio_net_pci_info = {
     .class_init    = virtio_net_pci_class_init,
 };
 
+/* virtio-scsi-pci */
+
+static Property virtio_scsi_pci_properties[] = {
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+                       DEV_NVECTORS_UNSPECIFIED),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_PROP_BIT("hotplug", VirtIOPCIProxy, host_features,
+                    VIRTIO_SCSI_F_HOTPLUG, true),
+    DEFINE_PROP_BIT("param_change", VirtIOPCIProxy, host_features,
+                    VIRTIO_SCSI_F_CHANGE, true),
+    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSIPCI, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_scsi_pci_init_pci(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+
+    virtio_scsi_set_conf(vdev, &(dev->conf));
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = dev->conf.num_queues + 3;
+    }
+
+    qdev_set_parent_bus(vdev, BUS(vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+    return 0;
+}
+
+static void virtio_scsi_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+
+    k->init = virtio_scsi_pci_init_pci;
+    dc->props = virtio_scsi_pci_properties;
+}
+
+static void virtio_scsi_pci_instance_init(Object *obj)
+{
+    VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SCSI);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static TypeInfo virtio_scsi_pci_info = {
+    .name          = TYPE_VIRTIO_SCSI_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIOSCSIPCI),
+    .instance_init = virtio_scsi_pci_instance_init,
+    .class_init    = virtio_scsi_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1317,12 +1312,12 @@ static void virtio_pci_register_types(void)
 {
     type_register_static(&virtio_serial_info);
     type_register_static(&virtio_balloon_info);
-    type_register_static(&virtio_scsi_info);
     type_register_static(&virtio_rng_info);
     type_register_static(&virtio_pci_bus_info);
     type_register_static(&virtio_pci_info);
     type_register_static(&virtio_blk_pci_info);
     type_register_static(&virtio_net_pci_info);
+    type_register_static(&virtio_scsi_pci_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index b8cf743..4114240 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -25,6 +25,7 @@
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
+typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
 
 /* virtio-pci-bus */
 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
@@ -75,7 +76,6 @@ struct VirtIOPCIProxy {
     V9fsConf fsconf;
 #endif
     virtio_serial_conf serial;
-    VirtIOSCSIConf scsi;
     VirtIORNGConf rng;
     bool ioeventfd_disabled;
     bool ioeventfd_started;
@@ -111,6 +111,19 @@ struct VirtIONetPCI {
     NICConf nic_conf;
 };
 
+/*
+ * virtio-scsi-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_SCSI_PCI "virtio-scsi-pci"
+#define VIRTIO_SCSI_PCI(obj) \
+        OBJECT_CHECK(VirtIOSCSIPCI, (obj), TYPE_VIRTIO_SCSI_PCI)
+
+struct VirtIOSCSIPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOSCSI vdev;
+    VirtIOSCSIConf conf;
+};
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 28/61] virtio-scsi-s390 : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (26 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 27/61] virtio-scsi-pci : switch to new API fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 29/61] virtio-scsi : cleanup : use QOM casts fred.konrad
                   ` (35 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-scsi-s390 is modified for the new API. The device
virtio-scsi-s390 extends virtio-s390-device as before. It creates and
connects a virtio-scsi during the init. The properties are not modified.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 26 +++++++++++++++++---------
 hw/s390-virtio-bus.h | 13 ++++++++++++-
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 283b7b6..569cac2 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -210,16 +210,23 @@ static int s390_virtio_serial_init(VirtIOS390Device *dev)
     return r;
 }
 
-static int s390_virtio_scsi_init(VirtIOS390Device *dev)
+static int s390_virtio_scsi_init(VirtIOS390Device *s390_dev)
 {
-    VirtIODevice *vdev;
-
-    vdev = virtio_scsi_init((DeviceState *)dev, &dev->scsi);
-    if (!vdev) {
+    VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(s390_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+    virtio_scsi_set_conf(vdev, &(dev->scsi));
+    qdev_set_parent_bus(vdev, BUS(s390_dev->bus));
+    if (qdev_init(vdev) < 0) {
         return -1;
     }
+    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+}
 
-    return s390_virtio_device_init(dev, vdev);
+static void s390_virtio_scsi_instance_init(Object *obj)
+{
+    VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SCSI);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
 static int s390_virtio_rng_init(VirtIOS390Device *dev)
@@ -543,7 +550,7 @@ static TypeInfo virtio_s390_device_info = {
 };
 
 static Property s390_virtio_scsi_properties[] = {
-    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOS390Device, scsi),
+    DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSIS390, scsi),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
     DEFINE_PROP_BIT("hotplug", VirtIOS390Device, host_features,
                     VIRTIO_SCSI_F_HOTPLUG, true),
@@ -562,9 +569,10 @@ static void s390_virtio_scsi_class_init(ObjectClass *klass, void *data)
 }
 
 static TypeInfo s390_virtio_scsi = {
-    .name          = "virtio-scsi-s390",
+    .name          = TYPE_VIRTIO_SCSI_S390,
     .parent        = TYPE_VIRTIO_S390_DEVICE,
-    .instance_size = sizeof(VirtIOS390Device),
+    .instance_size = sizeof(VirtIOSCSIS390),
+    .instance_init = s390_virtio_scsi_instance_init,
     .class_init    = s390_virtio_scsi_class_init,
 };
 
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index f67ca51..62c2b1c 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -87,7 +87,6 @@ struct VirtIOS390Device {
     VirtIODevice *vdev;
     uint32_t host_features;
     virtio_serial_conf serial;
-    VirtIOSCSIConf scsi;
     VirtIORNGConf rng;
     VirtioBusState *bus;
 };
@@ -138,5 +137,17 @@ typedef struct VirtIONetS390 {
     NICConf nic;
 } VirtIONetS390;
 
+/* virtio-scsi-s390 */
+
+#define TYPE_VIRTIO_SCSI_S390 "virtio-scsi-s390"
+#define VIRTIO_SCSI_S390(obj) \
+        OBJECT_CHECK(VirtIOSCSIS390, (obj), TYPE_VIRTIO_SCSI_S390)
+
+typedef struct VirtIOSCSIS390 {
+    VirtIOS390Device parent_obj;
+    VirtIOSCSI vdev;
+    VirtIOSCSIConf scsi;
+} VirtIOSCSIS390;
+
 
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 29/61] virtio-scsi : cleanup : use QOM casts.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (27 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 28/61] virtio-scsi-s390 : switch to the " fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 30/61] virtio-scsi : cleanup : init and exit functions fred.konrad
                   ` (34 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-scsi-pci and virtio-scsi-s390 are switched to the new API,
we can use QOM casts. This shouldn't been applyied before
virtio-scsi-pci and virtio-scsi-s390 refactoring as their VirtIODevice
were not a QOM object.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-scsi.c | 46 ++++++++++++++++++++++++++--------------------
 hw/virtio-scsi.h |  2 +-
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index ad07a65..d81df9c 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -171,6 +171,7 @@ static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
 {
     VirtIOSCSI *s = req->dev;
     VirtQueue *vq = req->vq;
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     virtqueue_push(vq, &req->elem, req->qsgl.size + req->elem.in_sg[0].iov_len);
     qemu_sglist_destroy(&req->qsgl);
     if (req->sreq) {
@@ -178,7 +179,7 @@ static void virtio_scsi_complete_req(VirtIOSCSIReq *req)
         scsi_req_unref(req->sreq);
     }
     g_free(req);
-    virtio_notify(&s->vdev, vq);
+    virtio_notify(vdev, vq);
 }
 
 static void virtio_scsi_bad_req(void)
@@ -561,16 +562,16 @@ static void virtio_scsi_reset(VirtIODevice *vdev)
  */
 static void virtio_scsi_save(QEMUFile *f, void *opaque)
 {
-    VirtIOSCSI *s = opaque;
-    virtio_save(&s->vdev, f);
+    VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
+    virtio_save(vdev, f);
 }
 
 static int virtio_scsi_load(QEMUFile *f, void *opaque, int version_id)
 {
-    VirtIOSCSI *s = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
     int ret;
 
-    ret = virtio_load(&s->vdev, f);
+    ret = virtio_load(vdev, f);
     if (ret) {
         return ret;
     }
@@ -582,9 +583,10 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
 {
     VirtIOSCSIReq *req = virtio_scsi_pop_req(s, s->event_vq);
     VirtIOSCSIEvent *evt;
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     int in_size;
 
-    if (!(s->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+    if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
         return;
     }
 
@@ -628,7 +630,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
 
 static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
+    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
 
     if (s->events_dropped) {
         virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
@@ -638,8 +640,9 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
 static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)
 {
     VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
 
-    if (((s->vdev.guest_features >> VIRTIO_SCSI_F_CHANGE) & 1) &&
+    if (((vdev->guest_features >> VIRTIO_SCSI_F_CHANGE) & 1) &&
         dev->type != TYPE_ROM) {
         virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE,
                                sense.asc | (sense.ascq << 8));
@@ -649,8 +652,9 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)
 static void virtio_scsi_hotplug(SCSIBus *bus, SCSIDevice *dev)
 {
     VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
 
-    if ((s->vdev.guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
+    if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
         virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_TRANSPORT_RESET,
                                VIRTIO_SCSI_EVT_RESET_RESCAN);
     }
@@ -659,8 +663,9 @@ static void virtio_scsi_hotplug(SCSIBus *bus, SCSIDevice *dev)
 static void virtio_scsi_hot_unplug(SCSIBus *bus, SCSIDevice *dev)
 {
     VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
 
-    if ((s->vdev.guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
+    if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
         virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_TRANSPORT_RESET,
                                VIRTIO_SCSI_EVT_RESET_REMOVED);
     }
@@ -693,6 +698,7 @@ static VirtIODevice *virtio_scsi_common_init(DeviceState *dev,
                                              VirtIOSCSI **ps)
 {
     VirtIOSCSI *s = *ps;
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     static int virtio_scsi_id;
     int i;
 
@@ -718,17 +724,17 @@ static VirtIODevice *virtio_scsi_common_init(DeviceState *dev,
     memcpy(&(s->conf), proxyconf, sizeof(struct VirtIOSCSIConf));
 
     /* TODO set up vdev function pointers */
-    s->vdev.get_config = virtio_scsi_get_config;
-    s->vdev.set_config = virtio_scsi_set_config;
-    s->vdev.get_features = virtio_scsi_get_features;
-    s->vdev.reset = virtio_scsi_reset;
-
-    s->ctrl_vq = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
-                                   virtio_scsi_handle_ctrl);
-    s->event_vq = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
+    vdev->get_config = virtio_scsi_get_config;
+    vdev->set_config = virtio_scsi_set_config;
+    vdev->get_features = virtio_scsi_get_features;
+    vdev->reset = virtio_scsi_reset;
+
+    s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
+                                  virtio_scsi_handle_ctrl);
+    s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
                                    virtio_scsi_handle_event);
     for (i = 0; i < s->conf.num_queues; i++) {
-        s->cmd_vqs[i] = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
+        s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
                                          virtio_scsi_handle_cmd);
     }
 
@@ -740,7 +746,7 @@ static VirtIODevice *virtio_scsi_common_init(DeviceState *dev,
     register_savevm(dev, "virtio-scsi", virtio_scsi_id++, 1,
                     virtio_scsi_save, virtio_scsi_load, s);
 
-    return &s->vdev;
+    return vdev;
 }
 
 VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 67d9067..50fa6c5 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -38,7 +38,7 @@ struct VirtIOSCSIConf {
 };
 
 typedef struct {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
     DeviceState *qdev;
     VirtIOSCSIConf conf;
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 30/61] virtio-scsi : cleanup : init and exit functions.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (28 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 29/61] virtio-scsi : cleanup : use QOM casts fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 31/61] virtio-scsi : cleanup : remove qdev field fred.konrad
                   ` (33 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.
This shouldn't been applyied before virtio-scsi-pci and virtio-scsi-s390
refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-scsi.c | 59 ++++++++++----------------------------------------------
 1 file changed, 10 insertions(+), 49 deletions(-)

diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index d81df9c..b2e0d70 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -693,35 +693,19 @@ void virtio_scsi_set_conf(DeviceState *qdev, VirtIOSCSIConf *conf)
     memcpy(&(s->conf), conf, sizeof(struct VirtIOSCSIConf));
 }
 
-static VirtIODevice *virtio_scsi_common_init(DeviceState *dev,
-                                             VirtIOSCSIConf *proxyconf,
-                                             VirtIOSCSI **ps)
+static int virtio_scsi_device_init(VirtIODevice *vdev)
 {
-    VirtIOSCSI *s = *ps;
-    VirtIODevice *vdev = VIRTIO_DEVICE(s);
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
     static int virtio_scsi_id;
     int i;
 
-    /*
-     * We have two cases here : the old virtio-net-pci device, and the
-     * refactored virtio-net.
-     */
+    virtio_init(VIRTIO_DEVICE(s), "virtio-scsi", VIRTIO_ID_SCSI,
+                sizeof(VirtIOSCSIConfig));
 
-    if (s == NULL) {
-        /* virtio-scsi-pci */
-        s = (VirtIOSCSI *)virtio_common_init("virtio-scsi", VIRTIO_ID_SCSI,
-                                             sizeof(VirtIOSCSIConfig),
-                                             sizeof(VirtIOSCSI));
-    } else {
-        /* virtio-scsi */
-        virtio_init(VIRTIO_DEVICE(s), "virtio-scsi", VIRTIO_ID_SCSI,
-                    sizeof(VirtIOSCSIConfig));
-    }
+    s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
 
-    s->cmd_vqs = g_malloc0(proxyconf->num_queues * sizeof(VirtQueue *));
-
-    s->qdev = dev;
-    memcpy(&(s->conf), proxyconf, sizeof(struct VirtIOSCSIConf));
+    s->qdev = qdev;
 
     /* TODO set up vdev function pointers */
     vdev->get_config = virtio_scsi_get_config;
@@ -738,37 +722,14 @@ static VirtIODevice *virtio_scsi_common_init(DeviceState *dev,
                                          virtio_scsi_handle_cmd);
     }
 
-    scsi_bus_new(&s->bus, dev, &virtio_scsi_scsi_info);
-    if (!dev->hotplugged) {
+    scsi_bus_new(&s->bus, qdev, &virtio_scsi_scsi_info);
+    if (!qdev->hotplugged) {
         scsi_bus_legacy_handle_cmdline(&s->bus);
     }
 
-    register_savevm(dev, "virtio-scsi", virtio_scsi_id++, 1,
+    register_savevm(qdev, "virtio-scsi", virtio_scsi_id++, 1,
                     virtio_scsi_save, virtio_scsi_load, s);
 
-    return vdev;
-}
-
-VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
-{
-    VirtIOSCSI *s = NULL;
-    return virtio_scsi_common_init(dev, proxyconf, &s);
-}
-
-void virtio_scsi_exit(VirtIODevice *vdev)
-{
-    VirtIOSCSI *s = (VirtIOSCSI *)vdev;
-    unregister_savevm(s->qdev, "virtio-scsi", s);
-    virtio_cleanup(vdev);
-}
-
-static int virtio_scsi_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIOSCSI *s = VIRTIO_SCSI(vdev);
-    if (virtio_scsi_common_init(qdev, &(s->conf), &s) == NULL) {
-        return -1;
-    }
     return 0;
 }
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 31/61] virtio-scsi : cleanup : remove qdev field.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (29 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 30/61] virtio-scsi : cleanup : init and exit functions fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 32/61] virtio-balloon : show the VirtIOBalloon structure fred.konrad
                   ` (32 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The qdev field is no longer needed. Just drop it.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-scsi.c | 2 --
 hw/virtio-scsi.h | 1 -
 2 files changed, 3 deletions(-)

diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index b2e0d70..273ca69 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -705,8 +705,6 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
 
     s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
 
-    s->qdev = qdev;
-
     /* TODO set up vdev function pointers */
     vdev->get_config = virtio_scsi_get_config;
     vdev->set_config = virtio_scsi_set_config;
diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
index 50fa6c5..d945d4c 100644
--- a/hw/virtio-scsi.h
+++ b/hw/virtio-scsi.h
@@ -39,7 +39,6 @@ struct VirtIOSCSIConf {
 
 typedef struct {
     VirtIODevice parent_obj;
-    DeviceState *qdev;
     VirtIOSCSIConf conf;
 
     SCSIBus bus;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 32/61] virtio-balloon : show the VirtIOBalloon structure.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (30 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 31/61] virtio-scsi : cleanup : remove qdev field fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 33/61] virtio-balloon : add the virtio-balloon device fred.konrad
                   ` (31 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As we discuss with anthony and andreas, this structure must be showed to avoid
two memory allocations for virtio-balloon-x.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-balloon.c | 12 ------------
 hw/virtio-balloon.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 3040bc6..3ea1790 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -27,18 +27,6 @@
 #include <sys/mman.h>
 #endif
 
-typedef struct VirtIOBalloon
-{
-    VirtIODevice vdev;
-    VirtQueue *ivq, *dvq, *svq;
-    uint32_t num_pages;
-    uint32_t actual;
-    uint64_t stats[VIRTIO_BALLOON_S_NR];
-    VirtQueueElement stats_vq_elem;
-    size_t stats_vq_offset;
-    DeviceState *qdev;
-} VirtIOBalloon;
-
 static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev)
 {
     return (VirtIOBalloon *)vdev;
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index b1828f4..0cd211e 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -52,4 +52,15 @@ typedef struct VirtIOBalloonStat {
     uint64_t val;
 } QEMU_PACKED VirtIOBalloonStat;
 
+typedef struct VirtIOBalloon {
+    VirtIODevice vdev;
+    VirtQueue *ivq, *dvq, *svq;
+    uint32_t num_pages;
+    uint32_t actual;
+    uint64_t stats[VIRTIO_BALLOON_S_NR];
+    VirtQueueElement stats_vq_elem;
+    size_t stats_vq_offset;
+    DeviceState *qdev;
+} VirtIOBalloon;
+
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 33/61] virtio-balloon : add the virtio-balloon device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (31 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 32/61] virtio-balloon : show the VirtIOBalloon structure fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 34/61] virtio-balloon-pci : switch to the new API fred.konrad
                   ` (30 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-balloon which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-balloon.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-balloon.h |  4 +++
 hw/virtio-pci.c     |  6 ++++
 3 files changed, 102 insertions(+), 7 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 3ea1790..fc94e3e 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -27,6 +27,11 @@
 #include <sys/mman.h>
 #endif
 
+#include "virtio-bus.h"
+
+/*
+ * Will be modified later in the serie.
+ */
 static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev)
 {
     return (VirtIOBalloon *)vdev;
@@ -219,25 +224,45 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-VirtIODevice *virtio_balloon_init(DeviceState *dev)
+static VirtIODevice *virtio_balloon_common_init(DeviceState *dev,
+                                                VirtIOBalloon **ps)
 {
-    VirtIOBalloon *s;
+    VirtIOBalloon *s = *ps;
     int ret;
 
-    s = (VirtIOBalloon *)virtio_common_init("virtio-balloon",
-                                            VIRTIO_ID_BALLOON,
-                                            8, sizeof(VirtIOBalloon));
-
+    /*
+     * We have two cases here : the old virtio-balloon-x device, and the
+     * refactored virtio-balloon.
+     * This will disappear later in the serie.
+     */
+    int old_device = (s == NULL);
+    if (s == NULL) {
+        /* old virtio-balloon-pci or virtio-balloon-s390, no memory allocated */
+        s = (VirtIOBalloon *)virtio_common_init("virtio-balloon",
+                                                VIRTIO_ID_BALLOON,
+                                                8, sizeof(VirtIOBalloon));
+    } else {
+        /* new API virtio-balloon. ( memory allocated by qdev ) */
+        virtio_init(VIRTIO_DEVICE(s), "virtio-balloon", VIRTIO_ID_BALLOON, 8);
+    }
+    /*
+     * This will disappear later in the serie.
+     * We will use VirtioDeviceClass instead.
+     */
     s->vdev.get_config = virtio_balloon_get_config;
     s->vdev.set_config = virtio_balloon_set_config;
     s->vdev.get_features = virtio_balloon_get_features;
 
     ret = qemu_add_balloon_handler(virtio_balloon_to_target,
                                    virtio_balloon_stat, s);
-    if (ret < 0) {
+    if ((ret < 0) && (old_device)) {
         virtio_cleanup(&s->vdev);
         return NULL;
     }
+    if (ret < 0) {
+        virtio_common_cleanup(VIRTIO_DEVICE(s));
+        return NULL;
+    }
 
     s->ivq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output);
     s->dvq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output);
@@ -252,6 +277,15 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev)
     return &s->vdev;
 }
 
+/*
+ * This two functions will be removed later in the serie.
+ */
+VirtIODevice *virtio_balloon_init(DeviceState *dev)
+{
+    VirtIOBalloon *s = NULL;
+    return virtio_balloon_common_init(dev, &s);
+}
+
 void virtio_balloon_exit(VirtIODevice *vdev)
 {
     VirtIOBalloon *s = DO_UPCAST(VirtIOBalloon, vdev, vdev);
@@ -260,3 +294,54 @@ void virtio_balloon_exit(VirtIODevice *vdev)
     unregister_savevm(s->qdev, "virtio-balloon", s);
     virtio_cleanup(vdev);
 }
+
+static int virtio_balloon_device_init(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
+    if (virtio_balloon_common_init(qdev, &s) == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
+static int virtio_balloon_device_exit(DeviceState *qdev)
+{
+    VirtIOBalloon *s = VIRTIO_BALLOON(qdev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+
+    qemu_remove_balloon_handler(s);
+    unregister_savevm(qdev, "virtio-balloon", s);
+    virtio_common_cleanup(vdev);
+    return 0;
+}
+
+static Property virtio_balloon_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_balloon_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_balloon_device_exit;
+    dc->props = virtio_balloon_properties;
+    vdc->init = virtio_balloon_device_init;
+    vdc->get_config = virtio_balloon_get_config;
+    vdc->set_config = virtio_balloon_set_config;
+    vdc->get_features = virtio_balloon_get_features;
+}
+
+static const TypeInfo virtio_balloon_info = {
+    .name = TYPE_VIRTIO_BALLOON,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOBalloon),
+    .class_init = virtio_balloon_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_balloon_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index 0cd211e..c106026 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -18,6 +18,10 @@
 #include "virtio.h"
 #include "pci/pci.h"
 
+#define TYPE_VIRTIO_BALLOON "virtio-balloon"
+#define VIRTIO_BALLOON(obj) \
+        OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON)
+
 /* from Linux's linux/virtio_balloon.h */
 
 /* The ID for virtio_balloon */
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index bbdb576..7c48eab 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -22,6 +22,7 @@
 #include "virtio-net.h"
 #include "virtio-serial.h"
 #include "virtio-scsi.h"
+#include "virtio-balloon.h"
 #include "pci/pci.h"
 #include "qemu/error-report.h"
 #include "pci/msi.h"
@@ -1008,6 +1009,11 @@ static void virtio_pci_device_plugged(DeviceState *d)
                                  PCI_DEVICE_ID_VIRTIO_SCSI);
         pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
         break;
+    case VIRTIO_ID_BALLOON:
+        pci_config_set_device_id(proxy->pci_dev.config,
+                                 PCI_DEVICE_ID_VIRTIO_BALLOON);
+        pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_OTHERS);
+        break;
     default:
         error_report("unknown device id\n");
         break;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 34/61] virtio-balloon-pci : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (32 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 33/61] virtio-balloon : add the virtio-balloon device fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 35/61] virtio-balloon : cleanup : init and exit function fred.konrad
                   ` (29 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-balloon-pci is modified for the new API. The device
virtio-balloon-pci extends virtio-pci. It creates and connects a
virtio-balloon during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 106 ++++++++++++++++++++++++++------------------------------
 hw/virtio-pci.h |  14 ++++++++
 2 files changed, 64 insertions(+), 56 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7c48eab..6dc7732 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -815,33 +815,6 @@ static void virtio_serial_exit_pci(PCIDevice *pci_dev)
     virtio_exit_pci(pci_dev);
 }
 
-static int virtio_balloon_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    if (proxy->class_code != PCI_CLASS_OTHERS &&
-        proxy->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */
-        proxy->class_code = PCI_CLASS_OTHERS;
-    }
-
-    vdev = virtio_balloon_init(&pci_dev->qdev);
-    if (!vdev) {
-        return -1;
-    }
-    virtio_init_pci(proxy, vdev);
-    return 0;
-}
-
-static void virtio_balloon_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_balloon_exit(proxy->vdev);
-    virtio_exit_pci(pci_dev);
-}
-
 static int virtio_rng_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -908,34 +881,6 @@ static TypeInfo virtio_serial_info = {
     .class_init    = virtio_serial_class_init,
 };
 
-static Property virtio_balloon_properties[] = {
-    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_balloon_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = virtio_balloon_init_pci;
-    k->exit = virtio_balloon_exit_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = PCI_CLASS_OTHERS;
-    dc->reset = virtio_pci_reset;
-    dc->props = virtio_balloon_properties;
-}
-
-static TypeInfo virtio_balloon_info = {
-    .name          = "virtio-balloon-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
-    .class_init    = virtio_balloon_class_init,
-};
-
 static void virtio_rng_initfn(Object *obj)
 {
     PCIDevice *pci_dev = PCI_DEVICE(obj);
@@ -1277,6 +1222,55 @@ static TypeInfo virtio_scsi_pci_info = {
     .class_init    = virtio_scsi_pci_class_init,
 };
 
+/* virtio-balloon-pci */
+
+static Property virtio_balloon_pci_properties[] = {
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_balloon_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+
+    if (vpci_dev->class_code != PCI_CLASS_OTHERS &&
+        vpci_dev->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */
+        vpci_dev->class_code = PCI_CLASS_OTHERS;
+    }
+
+    qdev_set_parent_bus(vdev, BUS(vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+    return 0;
+}
+
+static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+
+    k->init = virtio_balloon_pci_init;
+    dc->props = virtio_balloon_pci_properties;
+}
+
+static void virtio_balloon_pci_instance_init(Object *obj)
+{
+    VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BALLOON);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static TypeInfo virtio_balloon_pci_info = {
+    .name          = TYPE_VIRTIO_BALLOON_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIOBalloonPCI),
+    .instance_init = virtio_balloon_pci_instance_init,
+    .class_init    = virtio_balloon_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1317,13 +1311,13 @@ static const TypeInfo virtio_pci_bus_info = {
 static void virtio_pci_register_types(void)
 {
     type_register_static(&virtio_serial_info);
-    type_register_static(&virtio_balloon_info);
     type_register_static(&virtio_rng_info);
     type_register_static(&virtio_pci_bus_info);
     type_register_static(&virtio_pci_info);
     type_register_static(&virtio_blk_pci_info);
     type_register_static(&virtio_net_pci_info);
     type_register_static(&virtio_scsi_pci_info);
+    type_register_static(&virtio_balloon_pci_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 4114240..d67e945 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -20,12 +20,14 @@
 #include "virtio-rng.h"
 #include "virtio-serial.h"
 #include "virtio-scsi.h"
+#include "virtio-balloon.h"
 #include "virtio-bus.h"
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
+typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
 
 /* virtio-pci-bus */
 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
@@ -124,6 +126,18 @@ struct VirtIOSCSIPCI {
     VirtIOSCSIConf conf;
 };
 
+/*
+ * virtio-balloon-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
+#define VIRTIO_BALLOON_PCI(obj) \
+        OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
+
+struct VirtIOBalloonPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOBalloon vdev;
+};
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 35/61] virtio-balloon : cleanup : init and exit function.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (33 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 34/61] virtio-balloon-pci : switch to the new API fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 36/61] virtio-balloon : cleanup : QOM casts fred.konrad
                   ` (28 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.
This shouldn't been applyied before virtio-balloon-pci refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-balloon.c | 68 ++++++++++-------------------------------------------
 1 file changed, 12 insertions(+), 56 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index fc94e3e..3990a6b 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -224,27 +224,14 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static VirtIODevice *virtio_balloon_common_init(DeviceState *dev,
-                                                VirtIOBalloon **ps)
+static int virtio_balloon_device_init(VirtIODevice *vdev)
 {
-    VirtIOBalloon *s = *ps;
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
     int ret;
 
-    /*
-     * We have two cases here : the old virtio-balloon-x device, and the
-     * refactored virtio-balloon.
-     * This will disappear later in the serie.
-     */
-    int old_device = (s == NULL);
-    if (s == NULL) {
-        /* old virtio-balloon-pci or virtio-balloon-s390, no memory allocated */
-        s = (VirtIOBalloon *)virtio_common_init("virtio-balloon",
-                                                VIRTIO_ID_BALLOON,
-                                                8, sizeof(VirtIOBalloon));
-    } else {
-        /* new API virtio-balloon. ( memory allocated by qdev ) */
-        virtio_init(VIRTIO_DEVICE(s), "virtio-balloon", VIRTIO_ID_BALLOON, 8);
-    }
+    virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, 8);
+
     /*
      * This will disappear later in the serie.
      * We will use VirtioDeviceClass instead.
@@ -255,53 +242,22 @@ static VirtIODevice *virtio_balloon_common_init(DeviceState *dev,
 
     ret = qemu_add_balloon_handler(virtio_balloon_to_target,
                                    virtio_balloon_stat, s);
-    if ((ret < 0) && (old_device)) {
-        virtio_cleanup(&s->vdev);
-        return NULL;
-    }
+
     if (ret < 0) {
         virtio_common_cleanup(VIRTIO_DEVICE(s));
-        return NULL;
+        return -1;
     }
 
-    s->ivq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output);
-    s->dvq = virtio_add_queue(&s->vdev, 128, virtio_balloon_handle_output);
-    s->svq = virtio_add_queue(&s->vdev, 128, virtio_balloon_receive_stats);
+    s->ivq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
+    s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
+    s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
 
     reset_stats(s);
 
-    s->qdev = dev;
-    register_savevm(dev, "virtio-balloon", -1, 1,
+    s->qdev = qdev;
+    register_savevm(qdev, "virtio-balloon", -1, 1,
                     virtio_balloon_save, virtio_balloon_load, s);
 
-    return &s->vdev;
-}
-
-/*
- * This two functions will be removed later in the serie.
- */
-VirtIODevice *virtio_balloon_init(DeviceState *dev)
-{
-    VirtIOBalloon *s = NULL;
-    return virtio_balloon_common_init(dev, &s);
-}
-
-void virtio_balloon_exit(VirtIODevice *vdev)
-{
-    VirtIOBalloon *s = DO_UPCAST(VirtIOBalloon, vdev, vdev);
-
-    qemu_remove_balloon_handler(s);
-    unregister_savevm(s->qdev, "virtio-balloon", s);
-    virtio_cleanup(vdev);
-}
-
-static int virtio_balloon_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
-    if (virtio_balloon_common_init(qdev, &s) == NULL) {
-        return -1;
-    }
     return 0;
 }
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 36/61] virtio-balloon : cleanup : QOM casts.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (34 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 35/61] virtio-balloon : cleanup : init and exit function fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 37/61] virtio-balloon : cleanup : remove qdev field fred.konrad
                   ` (27 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-balloon-pci is switched to the new API, we can use QOM
casts. This shouldn't been applyied before virtio-balloon-pci
refactoring as its VirtIODevice was not a QOM object.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-balloon.c | 39 +++++++++++++++++----------------------
 hw/virtio-balloon.h |  2 +-
 2 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 3990a6b..2cb57b2 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -29,14 +29,6 @@
 
 #include "virtio-bus.h"
 
-/*
- * Will be modified later in the serie.
- */
-static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev)
-{
-    return (VirtIOBalloon *)vdev;
-}
-
 static void balloon_page(void *addr, int deflate)
 {
 #if defined(__linux__)
@@ -62,7 +54,7 @@ static inline void reset_stats(VirtIOBalloon *dev)
 
 static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOBalloon *s = to_virtio_balloon(vdev);
+    VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
     VirtQueueElement elem;
     MemoryRegionSection section;
 
@@ -96,7 +88,7 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 
 static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOBalloon *s = DO_UPCAST(VirtIOBalloon, vdev, vdev);
+    VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
     VirtQueueElement *elem = &s->stats_vq_elem;
     VirtIOBalloonStat stat;
     size_t offset = 0;
@@ -125,7 +117,7 @@ static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
 
 static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
-    VirtIOBalloon *dev = to_virtio_balloon(vdev);
+    VirtIOBalloon *dev = VIRTIO_BALLOON(vdev);
     struct virtio_balloon_config config;
 
     config.num_pages = cpu_to_le32(dev->num_pages);
@@ -137,7 +129,7 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 static void virtio_balloon_set_config(VirtIODevice *vdev,
                                       const uint8_t *config_data)
 {
-    VirtIOBalloon *dev = to_virtio_balloon(vdev);
+    VirtIOBalloon *dev = VIRTIO_BALLOON(vdev);
     struct virtio_balloon_config config;
     uint32_t oldactual = dev->actual;
     memcpy(&config, config_data, 8);
@@ -156,7 +148,7 @@ static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f)
 
 static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
 {
-    VirtIOBalloon *dev = opaque;
+    VirtIOBalloon *dev = VIRTIO_BALLOON(opaque);
 
 #if 0
     /* Disable guest-provided stats for now. For more details please check:
@@ -185,22 +177,24 @@ static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
 
 static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
 {
-    VirtIOBalloon *dev = opaque;
+    VirtIOBalloon *dev = VIRTIO_BALLOON(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
 
     if (target > ram_size) {
         target = ram_size;
     }
     if (target) {
         dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT;
-        virtio_notify_config(&dev->vdev);
+        virtio_notify_config(vdev);
     }
 }
 
 static void virtio_balloon_save(QEMUFile *f, void *opaque)
 {
-    VirtIOBalloon *s = opaque;
+    VirtIOBalloon *s = VIRTIO_BALLOON(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
 
-    virtio_save(&s->vdev, f);
+    virtio_save(vdev, f);
 
     qemu_put_be32(f, s->num_pages);
     qemu_put_be32(f, s->actual);
@@ -208,13 +202,14 @@ static void virtio_balloon_save(QEMUFile *f, void *opaque)
 
 static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
 {
-    VirtIOBalloon *s = opaque;
+    VirtIOBalloon *s = VIRTIO_BALLOON(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     int ret;
 
     if (version_id != 1)
         return -EINVAL;
 
-    ret = virtio_load(&s->vdev, f);
+    ret = virtio_load(vdev, f);
     if (ret) {
         return ret;
     }
@@ -236,9 +231,9 @@ static int virtio_balloon_device_init(VirtIODevice *vdev)
      * This will disappear later in the serie.
      * We will use VirtioDeviceClass instead.
      */
-    s->vdev.get_config = virtio_balloon_get_config;
-    s->vdev.set_config = virtio_balloon_set_config;
-    s->vdev.get_features = virtio_balloon_get_features;
+    vdev->get_config = virtio_balloon_get_config;
+    vdev->set_config = virtio_balloon_set_config;
+    vdev->get_features = virtio_balloon_get_features;
 
     ret = qemu_add_balloon_handler(virtio_balloon_to_target,
                                    virtio_balloon_stat, s);
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index c106026..96327e6 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -57,7 +57,7 @@ typedef struct VirtIOBalloonStat {
 } QEMU_PACKED VirtIOBalloonStat;
 
 typedef struct VirtIOBalloon {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
     VirtQueue *ivq, *dvq, *svq;
     uint32_t num_pages;
     uint32_t actual;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 37/61] virtio-balloon : cleanup : remove qdev field.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (35 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 36/61] virtio-balloon : cleanup : QOM casts fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 38/61] virtio-rng : show the VirtIORNG structure fred.konrad
                   ` (26 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The qdev field is no longer needed, just drop it.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-balloon.c | 1 -
 hw/virtio-balloon.h | 1 -
 2 files changed, 2 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 2cb57b2..e2cb2fc 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -249,7 +249,6 @@ static int virtio_balloon_device_init(VirtIODevice *vdev)
 
     reset_stats(s);
 
-    s->qdev = qdev;
     register_savevm(qdev, "virtio-balloon", -1, 1,
                     virtio_balloon_save, virtio_balloon_load, s);
 
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index 96327e6..9284f16 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -64,7 +64,6 @@ typedef struct VirtIOBalloon {
     uint64_t stats[VIRTIO_BALLOON_S_NR];
     VirtQueueElement stats_vq_elem;
     size_t stats_vq_offset;
-    DeviceState *qdev;
 } VirtIOBalloon;
 
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 38/61] virtio-rng : show the VirtIORNG structure.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (36 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 37/61] virtio-balloon : cleanup : remove qdev field fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 39/61] virtio-rng : don't use pointer for configuration fred.konrad
                   ` (25 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As we discuss with anthony and andreas, this structure must be showed to avoid
two memory allocations for virtio-rng-x.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-rng.c | 19 -------------------
 hw/virtio-rng.h | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index e063127..d79aa46 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -15,25 +15,6 @@
 #include "virtio-rng.h"
 #include "qemu/rng.h"
 
-typedef struct VirtIORNG {
-    VirtIODevice vdev;
-
-    DeviceState *qdev;
-
-    /* Only one vq - guest puts buffer(s) on it when it needs entropy */
-    VirtQueue *vq;
-
-    VirtIORNGConf *conf;
-
-    RngBackend *rng;
-
-    /* We purposefully don't migrate this state.  The quota will reset on the
-     * destination as a result.  Rate limiting is host state, not guest state.
-     */
-    QEMUTimer *rate_limit_timer;
-    int64_t quota_remaining;
-} VirtIORNG;
-
 static bool is_guest_ready(VirtIORNG *vrng)
 {
     if (virtio_queue_ready(vrng->vq)
diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h
index f42d748..3711c97 100644
--- a/hw/virtio-rng.h
+++ b/hw/virtio-rng.h
@@ -25,4 +25,23 @@ struct VirtIORNGConf {
     RndRandom *default_backend;
 };
 
+typedef struct VirtIORNG {
+    VirtIODevice vdev;
+
+    DeviceState *qdev;
+
+    /* Only one vq - guest puts buffer(s) on it when it needs entropy */
+    VirtQueue *vq;
+
+    VirtIORNGConf *conf;
+
+    RngBackend *rng;
+
+    /* We purposefully don't migrate this state.  The quota will reset on the
+     * destination as a result.  Rate limiting is host state, not guest state.
+     */
+    QEMUTimer *rate_limit_timer;
+    int64_t quota_remaining;
+} VirtIORNG;
+
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 39/61] virtio-rng : don't use pointer for configuration.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (37 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 38/61] virtio-rng : show the VirtIORNG structure fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 40/61] virtio-rng : add virtio-rng device fred.konrad
                   ` (24 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The configuration field must not be a pointer as it will be used for
virtio-rng properties. So *conf is replaced by conf.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-rng.c | 12 ++++++------
 hw/virtio-rng.h |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index d79aa46..e672c40 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -123,10 +123,10 @@ static void check_rate_limit(void *opaque)
 {
     VirtIORNG *s = opaque;
 
-    s->quota_remaining = s->conf->max_bytes;
+    s->quota_remaining = s->conf.max_bytes;
     virtio_rng_process(s);
     qemu_mod_timer(s->rate_limit_timer,
-                   qemu_get_clock_ms(vm_clock) + s->conf->period_ms);
+                   qemu_get_clock_ms(vm_clock) + s->conf.period_ms);
 }
 
 
@@ -158,16 +158,16 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
     vrng->vdev.get_features = get_features;
 
     vrng->qdev = dev;
-    vrng->conf = conf;
+    memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
 
-    assert(vrng->conf->max_bytes <= INT64_MAX);
-    vrng->quota_remaining = vrng->conf->max_bytes;
+    assert(vrng->conf.max_bytes <= INT64_MAX);
+    vrng->quota_remaining = vrng->conf.max_bytes;
 
     vrng->rate_limit_timer = qemu_new_timer_ms(vm_clock,
                                                check_rate_limit, vrng);
 
     qemu_mod_timer(vrng->rate_limit_timer,
-                   qemu_get_clock_ms(vm_clock) + vrng->conf->period_ms);
+                   qemu_get_clock_ms(vm_clock) + vrng->conf.period_ms);
 
     register_savevm(dev, "virtio-rng", -1, 1, virtio_rng_save,
                     virtio_rng_load, vrng);
diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h
index 3711c97..3deb283 100644
--- a/hw/virtio-rng.h
+++ b/hw/virtio-rng.h
@@ -33,7 +33,7 @@ typedef struct VirtIORNG {
     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
     VirtQueue *vq;
 
-    VirtIORNGConf *conf;
+    VirtIORNGConf conf;
 
     RngBackend *rng;
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 40/61] virtio-rng : add virtio-rng device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (38 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 39/61] virtio-rng : don't use pointer for configuration fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 41/61] virtio-rng-s390 : switch to the new API fred.konrad
                   ` (23 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-rng which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c |  13 +++----
 hw/virtio-rng.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-rng.h |  16 ++++++++
 3 files changed, 133 insertions(+), 14 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 6dc7732..4e35e04 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -892,13 +892,7 @@ static void virtio_rng_initfn(Object *obj)
 
 static Property virtio_rng_properties[] = {
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    /* Set a default rate limit of 2^47 bytes per minute or roughly 2TB/s.  If
-       you have an entropy source capable of generating more entropy than this
-       and you can pass it through via virtio-rng, then hats off to you.  Until
-       then, this is unlimited for all practical purposes.
-    */
-    DEFINE_PROP_UINT64("max-bytes", VirtIOPCIProxy, rng.max_bytes, INT64_MAX),
-    DEFINE_PROP_UINT32("period", VirtIOPCIProxy, rng.period_ms, 1 << 16),
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIOPCIProxy, rng),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -959,6 +953,11 @@ static void virtio_pci_device_plugged(DeviceState *d)
                                  PCI_DEVICE_ID_VIRTIO_BALLOON);
         pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_OTHERS);
         break;
+    case VIRTIO_ID_RNG:
+        pci_config_set_device_id(proxy->pci_dev.config,
+                                 PCI_DEVICE_ID_VIRTIO_RNG);
+        pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_OTHERS);
+        break;
     default:
         error_report("unknown device id\n");
         break;
diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index e672c40..98adef1 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -129,17 +129,33 @@ static void check_rate_limit(void *opaque)
                    qemu_get_clock_ms(vm_clock) + s->conf.period_ms);
 }
 
+void virtio_rng_set_conf(DeviceState *dev, VirtIORNGConf *conf)
+{
+    VirtIORNG *vrng = VIRTIO_RNG(dev);
+    memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
+}
 
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
+static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
+                                            VirtIORNGConf *conf,
+                                            VirtIORNG **pvrng)
 {
-    VirtIORNG *vrng;
+    VirtIORNG *vrng = *pvrng;
     VirtIODevice *vdev;
     Error *local_err = NULL;
 
-    vdev = virtio_common_init("virtio-rng", VIRTIO_ID_RNG, 0,
-                              sizeof(VirtIORNG));
-
-    vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+    /*
+     * We have two cases here : the old virtio-rng-x device, and the
+     * refactored virtio-rng.
+     * This will disappear later in the serie.
+     */
+    if (vrng == NULL) {
+        vdev = virtio_common_init("virtio-rng", VIRTIO_ID_RNG, 0,
+                                  sizeof(VirtIORNG));
+        vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+    } else {
+        vdev = VIRTIO_DEVICE(vrng);
+        virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
+    }
 
     vrng->rng = conf->rng;
     if (vrng->rng == NULL) {
@@ -155,8 +171,12 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
     }
 
     vrng->vq = virtio_add_queue(vdev, 8, handle_input);
+    /*
+     * This will disappear later in the serie.
+     * We will use VirtioDeviceClass instead.
+     */
     vrng->vdev.get_features = get_features;
-
+    /**/
     vrng->qdev = dev;
     memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
 
@@ -175,6 +195,15 @@ VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
     return vdev;
 }
 
+/*
+ * This two functions will be removed later in the serie.
+ */
+VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
+{
+    VirtIORNG *vdev = NULL;
+    return virtio_rng_common_init(dev, conf, &vdev);
+}
+
 void virtio_rng_exit(VirtIODevice *vdev)
 {
     VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
@@ -184,3 +213,78 @@ void virtio_rng_exit(VirtIODevice *vdev)
     unregister_savevm(vrng->qdev, "virtio-rng", vrng);
     virtio_cleanup(vdev);
 }
+/**/
+
+static int virtio_rng_device_init(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIORNG *vrng = VIRTIO_RNG(vdev);
+
+    if (vrng->conf.rng == NULL) {
+        vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
+
+        object_property_add_child(OBJECT(qdev),
+                                  "default-backend",
+                                  OBJECT(vrng->conf.default_backend),
+                                  NULL);
+
+        object_property_set_link(OBJECT(qdev),
+                                 OBJECT(vrng->conf.default_backend),
+                                 "rng", NULL);
+    }
+
+    if (virtio_rng_common_init(qdev, &(vrng->conf), &vrng) == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
+static int virtio_rng_device_exit(DeviceState *qdev)
+{
+    VirtIORNG *vrng = VIRTIO_RNG(qdev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+
+    qemu_del_timer(vrng->rate_limit_timer);
+    qemu_free_timer(vrng->rate_limit_timer);
+    unregister_savevm(qdev, "virtio-rng", vrng);
+    virtio_common_cleanup(vdev);
+    return 0;
+}
+
+static Property virtio_rng_properties[] = {
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNG, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_rng_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_rng_device_exit;
+    dc->props = virtio_rng_properties;
+    vdc->init = virtio_rng_device_init;
+    vdc->get_features = get_features;
+}
+
+static void virtio_rng_initfn(Object *obj)
+{
+    VirtIORNG *vrng = VIRTIO_RNG(obj);
+
+    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
+                             (Object **)&vrng->conf.rng, NULL);
+}
+
+static const TypeInfo virtio_rng_info = {
+    .name = TYPE_VIRTIO_RNG,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIORNG),
+    .instance_init = virtio_rng_initfn,
+    .class_init = virtio_rng_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_rng_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h
index 3deb283..fd6d01f 100644
--- a/hw/virtio-rng.h
+++ b/hw/virtio-rng.h
@@ -15,6 +15,10 @@
 #include "qemu/rng.h"
 #include "qemu/rng-random.h"
 
+#define TYPE_VIRTIO_RNG "virtio-rng"
+#define VIRTIO_RNG(obj) \
+        OBJECT_CHECK(VirtIORNG, (obj), TYPE_VIRTIO_RNG)
+
 /* The Virtio ID for the virtio rng device */
 #define VIRTIO_ID_RNG    4
 
@@ -44,4 +48,16 @@ typedef struct VirtIORNG {
     int64_t quota_remaining;
 } VirtIORNG;
 
+/* Set a default rate limit of 2^47 bytes per minute or roughly 2TB/s.  If
+   you have an entropy source capable of generating more entropy than this
+   and you can pass it through via virtio-rng, then hats off to you.  Until
+   then, this is unlimited for all practical purposes.
+*/
+#define DEFINE_VIRTIO_RNG_PROPERTIES(_state, _conf_field)                    \
+        DEFINE_PROP_UINT64("max-bytes", _state, _conf_field.max_bytes,       \
+                           INT64_MAX),                                       \
+        DEFINE_PROP_UINT32("period", _state, _conf_field.period_ms, 1 << 16)
+
+void virtio_rng_set_conf(DeviceState *dev, VirtIORNGConf *conf);
+
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 41/61] virtio-rng-s390 : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (39 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 40/61] virtio-rng : add virtio-rng device fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 42/61] virtio-rng-pci " fred.konrad
                   ` (22 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-rng-s390 is modified for the new API. The device
virtio-rng-s390 extends virtio-s390-device as before. It creates and
connects a virtio-rng during the init. The properties are not modified.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 35 ++++++++++++++++++-----------------
 hw/s390-virtio-bus.h | 13 ++++++++++++-
 2 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 569cac2..f3e1f07 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -229,16 +229,25 @@ static void s390_virtio_scsi_instance_init(Object *obj)
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
-static int s390_virtio_rng_init(VirtIOS390Device *dev)
+static int s390_virtio_rng_init(VirtIOS390Device *s390_dev)
 {
-    VirtIODevice *vdev;
-
-    vdev = virtio_rng_init((DeviceState *)dev, &dev->rng);
-    if (!vdev) {
+    VirtIORNGS390 *dev = VIRTIO_RNG_S390(s390_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+    virtio_rng_set_conf(vdev, &(dev->rng));
+    qdev_set_parent_bus(vdev, BUS(s390_dev->bus));
+    if (qdev_init(vdev) < 0) {
         return -1;
     }
+    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+}
 
-    return s390_virtio_device_init(dev, vdev);
+static void s390_virtio_rng_instance_init(Object *obj)
+{
+    VirtIORNGS390 *dev = VIRTIO_RNG_S390(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
+                             (Object **)&dev->rng.rng, NULL);
 }
 
 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
@@ -498,14 +507,6 @@ static TypeInfo s390_virtio_serial = {
     .class_init    = s390_virtio_serial_class_init,
 };
 
-static void s390_virtio_rng_initfn(Object *obj)
-{
-    VirtIOS390Device *dev = VIRTIO_S390_DEVICE(obj);
-
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&dev->rng.rng, NULL);
-}
-
 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
 {
     VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
@@ -514,10 +515,10 @@ static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
 }
 
 static TypeInfo s390_virtio_rng = {
-    .name          = "virtio-rng-s390",
+    .name          = TYPE_VIRTIO_RNG_S390,
     .parent        = TYPE_VIRTIO_S390_DEVICE,
-    .instance_size = sizeof(VirtIOS390Device),
-    .instance_init = s390_virtio_rng_initfn,
+    .instance_size = sizeof(VirtIORNGS390),
+    .instance_init = s390_virtio_rng_instance_init,
     .class_init    = s390_virtio_rng_class_init,
 };
 
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index 62c2b1c..3eb9b69 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -87,7 +87,6 @@ struct VirtIOS390Device {
     VirtIODevice *vdev;
     uint32_t host_features;
     virtio_serial_conf serial;
-    VirtIORNGConf rng;
     VirtioBusState *bus;
 };
 
@@ -149,5 +148,17 @@ typedef struct VirtIOSCSIS390 {
     VirtIOSCSIConf scsi;
 } VirtIOSCSIS390;
 
+/* virtio-rng-s390 */
+
+#define TYPE_VIRTIO_RNG_S390 "virtio-rng-s390"
+#define VIRTIO_RNG_S390(obj) \
+        OBJECT_CHECK(VirtIORNGS390, (obj), TYPE_VIRTIO_RNG_S390)
+
+typedef struct VirtIORNGS390 {
+    VirtIOS390Device parent_obj;
+    VirtIORNG vdev;
+    VirtIORNGConf rng;
+} VirtIORNGS390;
+
 
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 42/61] virtio-rng-pci : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (40 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 41/61] virtio-rng-s390 : switch to the new API fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 43/61] virtio-rng.c : cleanup : init and exit functions fred.konrad
                   ` (21 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-rng-pci is modified for the new API. The device
virtio-rng-pci extends virtio-pci. It creates and connects a virtio-rng
during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 134 ++++++++++++++++++++++++++------------------------------
 hw/virtio-pci.h |  15 ++++++-
 2 files changed, 75 insertions(+), 74 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 4e35e04..8b89758 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -815,41 +815,6 @@ static void virtio_serial_exit_pci(PCIDevice *pci_dev)
     virtio_exit_pci(pci_dev);
 }
 
-static int virtio_rng_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    if (proxy->rng.rng == NULL) {
-        proxy->rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-
-        object_property_add_child(OBJECT(pci_dev),
-                                  "default-backend",
-                                  OBJECT(proxy->rng.default_backend),
-                                  NULL);
-
-        object_property_set_link(OBJECT(pci_dev),
-                                 OBJECT(proxy->rng.default_backend),
-                                 "rng", NULL);
-    }
-
-    vdev = virtio_rng_init(&pci_dev->qdev, &proxy->rng);
-    if (!vdev) {
-        return -1;
-    }
-    virtio_init_pci(proxy, vdev);
-    return 0;
-}
-
-static void virtio_rng_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_rng_exit(proxy->vdev);
-    virtio_exit_pci(pci_dev);
-}
-
 static Property virtio_serial_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
@@ -881,44 +846,6 @@ static TypeInfo virtio_serial_info = {
     .class_init    = virtio_serial_class_init,
 };
 
-static void virtio_rng_initfn(Object *obj)
-{
-    PCIDevice *pci_dev = PCI_DEVICE(obj);
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&proxy->rng.rng, NULL);
-}
-
-static Property virtio_rng_properties[] = {
-    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIOPCIProxy, rng),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_rng_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = virtio_rng_init_pci;
-    k->exit = virtio_rng_exit_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = PCI_CLASS_OTHERS;
-    dc->reset = virtio_pci_reset;
-    dc->props = virtio_rng_properties;
-}
-
-static TypeInfo virtio_rng_info = {
-    .name          = "virtio-rng-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
-    .instance_init = virtio_rng_initfn,
-    .class_init    = virtio_rng_class_init,
-};
-
 /*
  * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
  */
@@ -1270,6 +1197,67 @@ static TypeInfo virtio_balloon_pci_info = {
     .class_init    = virtio_balloon_pci_class_init,
 };
 
+/* virtio-rng-pci */
+
+static Property virtio_rng_pci_properties[] = {
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORngPCI, conf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_rng_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&vrng->vdev);
+
+    if (vrng->conf.rng == NULL) {
+        vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
+
+        object_property_add_child(OBJECT(vrng),
+                                  "default-backend",
+                                  OBJECT(vrng->conf.default_backend),
+                                  NULL);
+
+        object_property_set_link(OBJECT(vrng),
+                                 OBJECT(vrng->conf.default_backend),
+                                 "rng", NULL);
+    }
+
+    virtio_rng_set_conf(vdev, &(vrng->conf));
+    qdev_set_parent_bus(vdev, BUS(vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+    return 0;
+}
+
+static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+
+    k->init = virtio_rng_pci_init;
+    dc->props = virtio_rng_pci_properties;
+}
+
+static void virtio_rng_initfn(Object *obj)
+{
+    VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
+                             (Object **)&dev->conf.rng, NULL);
+
+}
+
+static TypeInfo virtio_rng_info = {
+    .name          = TYPE_VIRTIO_RNG_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIORngPCI),
+    .instance_init = virtio_rng_initfn,
+    .class_init    = virtio_rng_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index d67e945..8f418b4 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -28,6 +28,7 @@ typedef struct VirtIOBlkPCI VirtIOBlkPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
+typedef struct VirtIORngPCI VirtIORngPCI;
 
 /* virtio-pci-bus */
 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
@@ -78,7 +79,6 @@ struct VirtIOPCIProxy {
     V9fsConf fsconf;
 #endif
     virtio_serial_conf serial;
-    VirtIORNGConf rng;
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
@@ -138,6 +138,19 @@ struct VirtIOBalloonPCI {
     VirtIOBalloon vdev;
 };
 
+/*
+ * virtio-rng-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
+#define VIRTIO_RNG_PCI(obj) \
+        OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
+
+struct VirtIORngPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIORNG vdev;
+    VirtIORNGConf conf;
+};
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 43/61] virtio-rng.c : cleanup : init and exit functions.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (41 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 42/61] virtio-rng-pci " fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 44/61] virtio-rng.c : cleanup : remove qdev field fred.konrad
                   ` (20 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.
This shouldn't been applyied before virtio-rng-pci and virtio-rng-s390
refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-rng.c | 88 ++++++++++++++-------------------------------------------
 1 file changed, 21 insertions(+), 67 deletions(-)

diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index 98adef1..646bcf3 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -135,39 +135,38 @@ void virtio_rng_set_conf(DeviceState *dev, VirtIORNGConf *conf)
     memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
 }
 
-static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
-                                            VirtIORNGConf *conf,
-                                            VirtIORNG **pvrng)
+static int virtio_rng_device_init(VirtIODevice *vdev)
 {
-    VirtIORNG *vrng = *pvrng;
-    VirtIODevice *vdev;
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIORNG *vrng = VIRTIO_RNG(vdev);
     Error *local_err = NULL;
 
-    /*
-     * We have two cases here : the old virtio-rng-x device, and the
-     * refactored virtio-rng.
-     * This will disappear later in the serie.
-     */
-    if (vrng == NULL) {
-        vdev = virtio_common_init("virtio-rng", VIRTIO_ID_RNG, 0,
-                                  sizeof(VirtIORNG));
-        vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
-    } else {
-        vdev = VIRTIO_DEVICE(vrng);
-        virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
+    if (vrng->conf.rng == NULL) {
+        vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
+
+        object_property_add_child(OBJECT(qdev),
+                                  "default-backend",
+                                  OBJECT(vrng->conf.default_backend),
+                                  NULL);
+
+        object_property_set_link(OBJECT(qdev),
+                                 OBJECT(vrng->conf.default_backend),
+                                 "rng", NULL);
     }
 
-    vrng->rng = conf->rng;
+    virtio_init(vdev, "virtio-rng", VIRTIO_ID_RNG, 0);
+
+    vrng->rng = vrng->conf.rng;
     if (vrng->rng == NULL) {
         qerror_report(QERR_INVALID_PARAMETER_VALUE, "rng", "a valid object");
-        return NULL;
+        return -1;
     }
 
     rng_backend_open(vrng->rng, &local_err);
     if (local_err) {
         qerror_report_err(local_err);
         error_free(local_err);
-        return NULL;
+        return -1;
     }
 
     vrng->vq = virtio_add_queue(vdev, 8, handle_input);
@@ -177,8 +176,7 @@ static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
      */
     vrng->vdev.get_features = get_features;
     /**/
-    vrng->qdev = dev;
-    memcpy(&(vrng->conf), conf, sizeof(struct VirtIORNGConf));
+    vrng->qdev = qdev;
 
     assert(vrng->conf.max_bytes <= INT64_MAX);
     vrng->quota_remaining = vrng->conf.max_bytes;
@@ -189,53 +187,9 @@ static VirtIODevice *virtio_rng_common_init(DeviceState *dev,
     qemu_mod_timer(vrng->rate_limit_timer,
                    qemu_get_clock_ms(vm_clock) + vrng->conf.period_ms);
 
-    register_savevm(dev, "virtio-rng", -1, 1, virtio_rng_save,
+    register_savevm(qdev, "virtio-rng", -1, 1, virtio_rng_save,
                     virtio_rng_load, vrng);
 
-    return vdev;
-}
-
-/*
- * This two functions will be removed later in the serie.
- */
-VirtIODevice *virtio_rng_init(DeviceState *dev, VirtIORNGConf *conf)
-{
-    VirtIORNG *vdev = NULL;
-    return virtio_rng_common_init(dev, conf, &vdev);
-}
-
-void virtio_rng_exit(VirtIODevice *vdev)
-{
-    VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
-
-    qemu_del_timer(vrng->rate_limit_timer);
-    qemu_free_timer(vrng->rate_limit_timer);
-    unregister_savevm(vrng->qdev, "virtio-rng", vrng);
-    virtio_cleanup(vdev);
-}
-/**/
-
-static int virtio_rng_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIORNG *vrng = VIRTIO_RNG(vdev);
-
-    if (vrng->conf.rng == NULL) {
-        vrng->conf.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
-
-        object_property_add_child(OBJECT(qdev),
-                                  "default-backend",
-                                  OBJECT(vrng->conf.default_backend),
-                                  NULL);
-
-        object_property_set_link(OBJECT(qdev),
-                                 OBJECT(vrng->conf.default_backend),
-                                 "rng", NULL);
-    }
-
-    if (virtio_rng_common_init(qdev, &(vrng->conf), &vrng) == NULL) {
-        return -1;
-    }
     return 0;
 }
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 44/61] virtio-rng.c : cleanup : remove qdev field.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (42 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 43/61] virtio-rng.c : cleanup : init and exit functions fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 45/61] virtio-rng.c : cleanup : use QOM casts fred.konrad
                   ` (19 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The qdev field is no longer needed, just drop it.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-rng.c | 1 -
 hw/virtio-rng.h | 2 --
 2 files changed, 3 deletions(-)

diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index 646bcf3..4e84f9e 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -176,7 +176,6 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
      */
     vrng->vdev.get_features = get_features;
     /**/
-    vrng->qdev = qdev;
 
     assert(vrng->conf.max_bytes <= INT64_MAX);
     vrng->quota_remaining = vrng->conf.max_bytes;
diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h
index fd6d01f..ae0c56da 100644
--- a/hw/virtio-rng.h
+++ b/hw/virtio-rng.h
@@ -32,8 +32,6 @@ struct VirtIORNGConf {
 typedef struct VirtIORNG {
     VirtIODevice vdev;
 
-    DeviceState *qdev;
-
     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
     VirtQueue *vq;
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 45/61] virtio-rng.c : cleanup : use QOM casts.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (43 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 44/61] virtio-rng.c : cleanup : remove qdev field fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 46/61] virtio-serial : show structures fred.konrad
                   ` (18 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-rng-pci and virtio-rng-s390 are switched to the new API,
we can use QOM casts. This shouldn't been applyied before virtio-rng-pci
and virtio-rg-s390 refactoring as their VirtIODevice were not a QOM
object.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-rng.c | 31 +++++++++++++++++--------------
 hw/virtio-rng.h |  2 +-
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index 4e84f9e..67407a7 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -17,8 +17,9 @@
 
 static bool is_guest_ready(VirtIORNG *vrng)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
     if (virtio_queue_ready(vrng->vq)
-        && (vrng->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+        && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
         return true;
     }
     return false;
@@ -37,7 +38,8 @@ static void virtio_rng_process(VirtIORNG *vrng);
 /* Send data from a char device over to the guest */
 static void chr_read(void *opaque, const void *buf, size_t size)
 {
-    VirtIORNG *vrng = opaque;
+    VirtIORNG *vrng = VIRTIO_RNG(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
     VirtQueueElement elem;
     size_t len;
     int offset;
@@ -59,7 +61,7 @@ static void chr_read(void *opaque, const void *buf, size_t size)
 
         virtqueue_push(vrng->vq, &elem, len);
     }
-    virtio_notify(&vrng->vdev, vrng->vq);
+    virtio_notify(vdev, vrng->vq);
 }
 
 static void virtio_rng_process(VirtIORNG *vrng)
@@ -85,7 +87,7 @@ static void virtio_rng_process(VirtIORNG *vrng)
 
 static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIORNG *vrng = DO_UPCAST(VirtIORNG, vdev, vdev);
+    VirtIORNG *vrng = VIRTIO_RNG(vdev);
     virtio_rng_process(vrng);
 }
 
@@ -96,19 +98,20 @@ static uint32_t get_features(VirtIODevice *vdev, uint32_t f)
 
 static void virtio_rng_save(QEMUFile *f, void *opaque)
 {
-    VirtIORNG *vrng = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
 
-    virtio_save(&vrng->vdev, f);
+    virtio_save(vdev, f);
 }
 
 static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
 {
-    VirtIORNG *vrng = opaque;
+    VirtIORNG *vrng = VIRTIO_RNG(opaque);
+    VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
 
     if (version_id != 1) {
         return -EINVAL;
     }
-    virtio_load(&vrng->vdev, f);
+    virtio_load(vdev, f);
 
     /* We may have an element ready but couldn't process it due to a quota
      * limit.  Make sure to try again after live migration when the quota may
@@ -121,12 +124,12 @@ static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
 
 static void check_rate_limit(void *opaque)
 {
-    VirtIORNG *s = opaque;
+    VirtIORNG *vrng = VIRTIO_RNG(opaque);
 
-    s->quota_remaining = s->conf.max_bytes;
-    virtio_rng_process(s);
-    qemu_mod_timer(s->rate_limit_timer,
-                   qemu_get_clock_ms(vm_clock) + s->conf.period_ms);
+    vrng->quota_remaining = vrng->conf.max_bytes;
+    virtio_rng_process(vrng);
+    qemu_mod_timer(vrng->rate_limit_timer,
+                   qemu_get_clock_ms(vm_clock) + vrng->conf.period_ms);
 }
 
 void virtio_rng_set_conf(DeviceState *dev, VirtIORNGConf *conf)
@@ -174,7 +177,7 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
      * This will disappear later in the serie.
      * We will use VirtioDeviceClass instead.
      */
-    vrng->vdev.get_features = get_features;
+    vdev->get_features = get_features;
     /**/
 
     assert(vrng->conf.max_bytes <= INT64_MAX);
diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h
index ae0c56da..ee0847a 100644
--- a/hw/virtio-rng.h
+++ b/hw/virtio-rng.h
@@ -30,7 +30,7 @@ struct VirtIORNGConf {
 };
 
 typedef struct VirtIORNG {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
 
     /* Only one vq - guest puts buffer(s) on it when it needs entropy */
     VirtQueue *vq;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 46/61] virtio-serial : show structures.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (44 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 45/61] virtio-rng.c : cleanup : use QOM casts fred.konrad
@ 2013-01-07 18:40 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 47/61] virtio-serial : add the virtio-serial device fred.konrad
                   ` (17 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:40 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As we discuss with anthony and andreas, this structure must be showed to avoid
two memory allocations for virtio-serial-x.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-serial-bus.c | 41 -----------------------------------------
 hw/virtio-serial.h     | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 7272bfd..b7cce7a 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -25,47 +25,6 @@
 #include "trace.h"
 #include "virtio-serial.h"
 
-/* The virtio-serial bus on top of which the ports will ride as devices */
-struct VirtIOSerialBus {
-    BusState qbus;
-
-    /* This is the parent device that provides the bus for ports. */
-    VirtIOSerial *vser;
-
-    /* The maximum number of ports that can ride on top of this bus */
-    uint32_t max_nr_ports;
-};
-
-typedef struct VirtIOSerialPostLoad {
-    QEMUTimer *timer;
-    uint32_t nr_active_ports;
-    struct {
-        VirtIOSerialPort *port;
-        uint8_t host_connected;
-    } *connected;
-} VirtIOSerialPostLoad;
-
-struct VirtIOSerial {
-    VirtIODevice vdev;
-
-    VirtQueue *c_ivq, *c_ovq;
-    /* Arrays of ivqs and ovqs: one per port */
-    VirtQueue **ivqs, **ovqs;
-
-    VirtIOSerialBus bus;
-
-    DeviceState *qdev;
-
-    QTAILQ_HEAD(, VirtIOSerialPort) ports;
-
-    /* bitmap for identifying active ports */
-    uint32_t *ports_map;
-
-    struct virtio_console_config config;
-
-    struct VirtIOSerialPostLoad *post_load;
-};
-
 static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
 {
     VirtIOSerialPort *port;
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index 16e3982..722d01b 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -173,6 +173,47 @@ struct VirtIOSerialPort {
     bool throttled;
 };
 
+/* The virtio-serial bus on top of which the ports will ride as devices */
+struct VirtIOSerialBus {
+    BusState qbus;
+
+    /* This is the parent device that provides the bus for ports. */
+    VirtIOSerial *vser;
+
+    /* The maximum number of ports that can ride on top of this bus */
+    uint32_t max_nr_ports;
+};
+
+typedef struct VirtIOSerialPostLoad {
+    QEMUTimer *timer;
+    uint32_t nr_active_ports;
+    struct {
+        VirtIOSerialPort *port;
+        uint8_t host_connected;
+    } *connected;
+} VirtIOSerialPostLoad;
+
+struct VirtIOSerial {
+    VirtIODevice vdev;
+
+    VirtQueue *c_ivq, *c_ovq;
+    /* Arrays of ivqs and ovqs: one per port */
+    VirtQueue **ivqs, **ovqs;
+
+    VirtIOSerialBus bus;
+
+    DeviceState *qdev;
+
+    QTAILQ_HEAD(, VirtIOSerialPort) ports;
+
+    /* bitmap for identifying active ports */
+    uint32_t *ports_map;
+
+    struct virtio_console_config config;
+
+    struct VirtIOSerialPostLoad *post_load;
+};
+
 /* Interface to the virtio-serial bus */
 
 /*
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 47/61] virtio-serial : add the virtio-serial device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (45 preceding siblings ...)
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 46/61] virtio-serial : show structures fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 48/61] virtio-serial-pci : switch to the new API fred.konrad
                   ` (16 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-serial which extends virtio-device, so it can be connected
on virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c        |   8 +++-
 hw/virtio-serial-bus.c | 100 +++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-serial.h     |  11 ++++++
 3 files changed, 111 insertions(+), 8 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 8b89758..3aa96fc 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -820,7 +820,7 @@ static Property virtio_serial_properties[] = {
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
     DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, serial.max_virtserial_ports, 31),
+    DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOPCIProxy, serial),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -885,6 +885,12 @@ static void virtio_pci_device_plugged(DeviceState *d)
                                  PCI_DEVICE_ID_VIRTIO_RNG);
         pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_OTHERS);
         break;
+    case VIRTIO_ID_CONSOLE:
+        pci_config_set_device_id(proxy->pci_dev.config,
+                                 PCI_DEVICE_ID_VIRTIO_CONSOLE);
+        pci_config_set_class(proxy->pci_dev.config,
+                             PCI_CLASS_COMMUNICATION_OTHER);
+        break;
     default:
         error_report("unknown device id\n");
         break;
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index b7cce7a..5186191 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -904,10 +904,12 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
     return 0;
 }
 
-VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
+static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
+                                               virtio_serial_conf *conf,
+                                               VirtIODevice **pvdev)
 {
     VirtIOSerial *vser;
-    VirtIODevice *vdev;
+    VirtIODevice *vdev = *pvdev;
     uint32_t i, max_supported_ports;
 
     if (!conf->max_virtserial_ports)
@@ -921,11 +923,22 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
         return NULL;
     }
 
-    vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE,
-                              sizeof(struct virtio_console_config),
-                              sizeof(VirtIOSerial));
-
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    /*
+     * We have two cases here : the old virtio-serial-pci device, and the
+     * refactored virtio-serial.
+     */
+    if (vdev == NULL) {
+        /* virtio-serial-pci */
+        vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE,
+                                  sizeof(struct virtio_console_config),
+                                  sizeof(VirtIOSerial));
+        vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    } else {
+        /* virtio-serial */
+        virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
+                    sizeof(struct virtio_console_config));
+        vser = VIRTIO_SERIAL(vdev);
+    }
 
     /* Spawn a new virtio-serial bus on which the ports will ride as devices */
     qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, dev, NULL);
@@ -989,6 +1002,16 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
     return vdev;
 }
 
+/*
+ * The two following functions will be cleaned up at the end.
+ */
+
+VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
+{
+    VirtIODevice *vdev = NULL;
+    return virtio_serial_common_init(dev, conf, &vdev);
+}
+
 void virtio_serial_exit(VirtIODevice *vdev)
 {
     VirtIOSerial *vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
@@ -1026,10 +1049,73 @@ static TypeInfo virtio_serial_port_type_info = {
     .class_init = virtio_serial_port_class_init,
 };
 
+void virtio_serial_set_conf(DeviceState *dev, virtio_serial_conf *serial)
+{
+    VirtIOSerial *s = VIRTIO_SERIAL(dev);
+    memcpy(&(s->serial), serial, sizeof(virtio_serial_conf));
+}
+
+static int virtio_serial_device_init(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
+    if (virtio_serial_common_init(qdev, &(vser->serial), &vdev) == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
+static int virtio_serial_device_exit(DeviceState *dev)
+{
+    VirtIOSerial *vser = VIRTIO_SERIAL(dev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+
+    unregister_savevm(dev, "virtio-console", vser);
+
+    g_free(vser->ivqs);
+    g_free(vser->ovqs);
+    g_free(vser->ports_map);
+    if (vser->post_load) {
+        g_free(vser->post_load->connected);
+        qemu_del_timer(vser->post_load->timer);
+        qemu_free_timer(vser->post_load->timer);
+        g_free(vser->post_load);
+    }
+    virtio_common_cleanup(vdev);
+    return 0;
+}
+
+static Property virtio_serial_properties[] = {
+    DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOSerial, serial),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_serial_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->exit = virtio_serial_device_exit;
+    dc->props = virtio_serial_properties;
+    vdc->init = virtio_serial_device_init;
+    vdc->get_features = get_features;
+    vdc->get_config = get_config;
+    vdc->set_config = set_config;
+    vdc->set_status = set_status;
+    vdc->reset = vser_reset;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_SERIAL,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOSerial),
+    .class_init = virtio_serial_class_init,
+};
+
 static void virtio_serial_register_types(void)
 {
     type_register_static(&virtser_bus_info);
     type_register_static(&virtio_serial_port_type_info);
+    type_register_static(&virtio_device_info);
 }
 
 type_init(virtio_serial_register_types)
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index 722d01b..f5960f9 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -212,6 +212,8 @@ struct VirtIOSerial {
     struct virtio_console_config config;
 
     struct VirtIOSerialPostLoad *post_load;
+
+    virtio_serial_conf serial;
 };
 
 /* Interface to the virtio-serial bus */
@@ -246,4 +248,13 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
  */
 void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle);
 
+#define TYPE_VIRTIO_SERIAL "virtio-serial"
+#define VIRTIO_SERIAL(obj) \
+        OBJECT_CHECK(VirtIOSerial, (obj), TYPE_VIRTIO_SERIAL)
+
+#define DEFINE_VIRTIO_SERIAL_PROPERTIES(_state, _field) \
+        DEFINE_PROP_UINT32("max_ports", _state, _field.max_virtserial_ports, 31)
+
+void virtio_serial_set_conf(DeviceState *dev, virtio_serial_conf *serial);
+
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 48/61] virtio-serial-pci : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (46 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 47/61] virtio-serial : add the virtio-serial device fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 49/61] virtio-serial-s390 " fred.konrad
                   ` (15 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-serial-pci is modified for the new API. The device
virtio-serial-pci extends virtio-pci. It creates and connects a
virtio-serial during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 123 +++++++++++++++++++++++++++-----------------------------
 hw/virtio-pci.h |  15 ++++++-
 2 files changed, 74 insertions(+), 64 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 3aa96fc..7d66c51 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -784,68 +784,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
     msix_uninit_exclusive_bar(pci_dev);
 }
 
-static int virtio_serial_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    if (proxy->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
-        proxy->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
-        proxy->class_code != PCI_CLASS_OTHERS)          /* qemu-kvm  */
-        proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER;
-
-    vdev = virtio_serial_init(&pci_dev->qdev, &proxy->serial);
-    if (!vdev) {
-        return -1;
-    }
-    vdev->nvectors = proxy->nvectors == DEV_NVECTORS_UNSPECIFIED
-                                        ? proxy->serial.max_virtserial_ports + 1
-                                        : proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-    proxy->nvectors = vdev->nvectors;
-    return 0;
-}
-
-static void virtio_serial_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_serial_exit(proxy->vdev);
-    virtio_exit_pci(pci_dev);
-}
-
-static Property virtio_serial_properties[] = {
-    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
-    DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
-    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOPCIProxy, serial),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_serial_class_init(ObjectClass *klass, void *data)
-{
-    DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
-    k->init = virtio_serial_init_pci;
-    k->exit = virtio_serial_exit_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
-    dc->reset = virtio_pci_reset;
-    dc->props = virtio_serial_properties;
-}
-
-static TypeInfo virtio_serial_info = {
-    .name          = "virtio-serial-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
-    .class_init    = virtio_serial_class_init,
-};
-
 /*
  * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
  */
@@ -1264,6 +1202,65 @@ static TypeInfo virtio_rng_info = {
     .class_init    = virtio_rng_pci_class_init,
 };
 
+/* virtio-serial-pci */
+
+static int virtio_serial_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+    VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+
+    if (vpci_dev->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
+        vpci_dev->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
+        vpci_dev->class_code != PCI_CLASS_OTHERS) {        /* qemu-kvm  */
+            vpci_dev->class_code = PCI_CLASS_COMMUNICATION_OTHER;
+    }
+
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = dev->serial.max_virtserial_ports + 1;
+    }
+
+    virtio_serial_set_conf(vdev, &(dev->serial));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
+    return 0;
+}
+
+static Property virtio_serial_pci_properties[] = {
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+                    DEV_NVECTORS_UNSPECIFIED),
+    DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+    DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOSerialPCI, serial),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_serial_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+
+    k->init = virtio_serial_pci_init;
+    dc->props = virtio_serial_pci_properties;
+}
+
+static void virtio_serial_pci_instance_init(Object *obj)
+{
+    VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SERIAL);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static TypeInfo virtio_serial_pci_info = {
+    .name          = TYPE_VIRTIO_SERIAL_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(VirtIOSerialPCI),
+    .instance_init = virtio_serial_pci_instance_init,
+    .class_init    = virtio_serial_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1303,7 +1300,6 @@ static const TypeInfo virtio_pci_bus_info = {
 
 static void virtio_pci_register_types(void)
 {
-    type_register_static(&virtio_serial_info);
     type_register_static(&virtio_rng_info);
     type_register_static(&virtio_pci_bus_info);
     type_register_static(&virtio_pci_info);
@@ -1311,6 +1307,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_net_pci_info);
     type_register_static(&virtio_scsi_pci_info);
     type_register_static(&virtio_balloon_pci_info);
+    type_register_static(&virtio_serial_pci_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 8f418b4..98b51d8 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -29,6 +29,7 @@ typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
 typedef struct VirtIORngPCI VirtIORngPCI;
+typedef struct VirtIOSerialPCI VirtIOSerialPCI;
 
 /* virtio-pci-bus */
 #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
@@ -78,7 +79,6 @@ struct VirtIOPCIProxy {
 #ifdef CONFIG_LINUX
     V9fsConf fsconf;
 #endif
-    virtio_serial_conf serial;
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
@@ -151,6 +151,19 @@ struct VirtIORngPCI {
     VirtIORNGConf conf;
 };
 
+/*
+ * virtio-serial-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_SERIAL_PCI "virtio-serial-pci"
+#define VIRTIO_SERIAL_PCI(obj) \
+        OBJECT_CHECK(VirtIOSerialPCI, (obj), TYPE_VIRTIO_SERIAL_PCI)
+
+struct VirtIOSerialPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOSerial vdev;
+    virtio_serial_conf serial;
+};
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 49/61] virtio-serial-s390 : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (47 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 48/61] virtio-serial-pci : switch to the new API fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 50/61] virtio-serial : cleanup : init and exit functions fred.konrad
                   ` (14 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-serial-s390 is modified for the new API. The device
virtio-serial-s390 extends virtio-s390-device as before. It creates and
connects a virtio-serial during the init. The properties are not
modified.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 31 +++++++++++++++++++++----------
 hw/s390-virtio-bus.h | 10 +++++++++-
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index f3e1f07..52978b3 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -189,27 +189,37 @@ static void s390_virtio_blk_instance_init(Object *obj)
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
 }
 
-static int s390_virtio_serial_init(VirtIOS390Device *dev)
+static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
 {
+    VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(s390_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+    DeviceState *qdev = DEVICE(s390_dev);
     VirtIOS390Bus *bus;
-    VirtIODevice *vdev;
     int r;
 
-    bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
+    bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
 
-    vdev = virtio_serial_init((DeviceState *)dev, &dev->serial);
-    if (!vdev) {
+    virtio_serial_set_conf(vdev, &(dev->serial));
+    qdev_set_parent_bus(vdev, BUS(s390_dev->bus));
+    if (qdev_init(vdev) < 0) {
         return -1;
     }
 
-    r = s390_virtio_device_init(dev, vdev);
+    r = s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
     if (!r) {
-        bus->console = dev;
+        bus->console = s390_dev;
     }
 
     return r;
 }
 
+static void s390_virtio_serial_instance_init(Object *obj)
+{
+    VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SERIAL);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
 static int s390_virtio_scsi_init(VirtIOS390Device *s390_dev)
 {
     VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(s390_dev);
@@ -486,7 +496,7 @@ static TypeInfo s390_virtio_blk = {
 };
 
 static Property s390_virtio_serial_properties[] = {
-    DEFINE_PROP_UINT32("max_ports", VirtIOS390Device,
+    DEFINE_PROP_UINT32("max_ports", VirtIOSerialS390,
                        serial.max_virtserial_ports, 31),
     DEFINE_PROP_END_OF_LIST(),
 };
@@ -501,9 +511,10 @@ static void s390_virtio_serial_class_init(ObjectClass *klass, void *data)
 }
 
 static TypeInfo s390_virtio_serial = {
-    .name          = "virtio-serial-s390",
+    .name          = TYPE_VIRTIO_SERIAL_S390,
     .parent        = TYPE_VIRTIO_S390_DEVICE,
-    .instance_size = sizeof(VirtIOS390Device),
+    .instance_size = sizeof(VirtIOSerialS390),
+    .instance_init = s390_virtio_serial_instance_init,
     .class_init    = s390_virtio_serial_class_init,
 };
 
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index 3eb9b69..c9ca5a1 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -86,7 +86,6 @@ struct VirtIOS390Device {
     uint8_t feat_len;
     VirtIODevice *vdev;
     uint32_t host_features;
-    virtio_serial_conf serial;
     VirtioBusState *bus;
 };
 
@@ -160,5 +159,14 @@ typedef struct VirtIORNGS390 {
     VirtIORNGConf rng;
 } VirtIORNGS390;
 
+#define TYPE_VIRTIO_SERIAL_S390 "virtio-serial-s390"
+#define VIRTIO_SERIAL_S390(obj) \
+        OBJECT_CHECK(VirtIOSerialS390, (obj), TYPE_VIRTIO_SERIAL_S390)
+
+typedef struct VirtIOSerialS390 {
+    VirtIOS390Device parent_obj;
+    VirtIOSerial vdev;
+    virtio_serial_conf serial;
+} VirtIOSerialS390;
 
 #endif
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 50/61] virtio-serial : cleanup : init and exit functions.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (48 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 49/61] virtio-serial-s390 " fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 51/61] virtio-serial : cleanup : use QOM casts fred.konrad
                   ` (13 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.
This shouldn't been applyied before virtio-serial-pci and
virtio-serial-s390 refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-serial-bus.c | 94 ++++++++++++--------------------------------------
 1 file changed, 22 insertions(+), 72 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 5186191..f1c7d75 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -904,51 +904,39 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
     return 0;
 }
 
-static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
-                                               virtio_serial_conf *conf,
-                                               VirtIODevice **pvdev)
+static int virtio_serial_device_init(VirtIODevice *vdev)
 {
-    VirtIOSerial *vser;
-    VirtIODevice *vdev = *pvdev;
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
     uint32_t i, max_supported_ports;
 
-    if (!conf->max_virtserial_ports)
-        return NULL;
+    if (!vser->serial.max_virtserial_ports) {
+        return -1;
+    }
 
     /* Each port takes 2 queues, and one pair is for the control queue */
     max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
 
-    if (conf->max_virtserial_ports > max_supported_ports) {
+    if (vser->serial.max_virtserial_ports > max_supported_ports) {
         error_report("maximum ports supported: %u", max_supported_ports);
-        return NULL;
+        return -1;
     }
 
-    /*
-     * We have two cases here : the old virtio-serial-pci device, and the
-     * refactored virtio-serial.
-     */
-    if (vdev == NULL) {
-        /* virtio-serial-pci */
-        vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE,
-                                  sizeof(struct virtio_console_config),
-                                  sizeof(VirtIOSerial));
-        vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
-    } else {
-        /* virtio-serial */
-        virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
-                    sizeof(struct virtio_console_config));
-        vser = VIRTIO_SERIAL(vdev);
-    }
+
+    virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
+                sizeof(struct virtio_console_config));
 
     /* Spawn a new virtio-serial bus on which the ports will ride as devices */
-    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, dev, NULL);
+    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, qdev, NULL);
     vser->bus.qbus.allow_hotplug = 1;
     vser->bus.vser = vser;
     QTAILQ_INIT(&vser->ports);
 
-    vser->bus.max_nr_ports = conf->max_virtserial_ports;
-    vser->ivqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
-    vser->ovqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
+    vser->bus.max_nr_ports = vser->serial.max_virtserial_ports;
+    vser->ivqs = g_malloc(vser->serial.max_virtserial_ports
+                          * sizeof(VirtQueue *));
+    vser->ovqs = g_malloc(vser->serial.max_virtserial_ports
+                          * sizeof(VirtQueue *));
 
     /* Add a queue for host to guest transfers for port 0 (backward compat) */
     vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input);
@@ -973,8 +961,8 @@ static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
         vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output);
     }
 
-    vser->config.max_nr_ports = tswap32(conf->max_virtserial_ports);
-    vser->ports_map = g_malloc0(((conf->max_virtserial_ports + 31) / 32)
+    vser->config.max_nr_ports = tswap32(vser->serial.max_virtserial_ports);
+    vser->ports_map = g_malloc0(((vser->serial.max_virtserial_ports + 31) / 32)
         * sizeof(vser->ports_map[0]));
     /*
      * Reserve location 0 for a console port for backward compat
@@ -988,7 +976,7 @@ static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
     vser->vdev.set_status = set_status;
     vser->vdev.reset = vser_reset;
 
-    vser->qdev = dev;
+    vser->qdev = qdev;
 
     vser->post_load = NULL;
 
@@ -996,38 +984,10 @@ static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
      * Register for the savevm section with the virtio-console name
      * to preserve backward compat
      */
-    register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save,
+    register_savevm(qdev, "virtio-console", -1, 3, virtio_serial_save,
                     virtio_serial_load, vser);
 
-    return vdev;
-}
-
-/*
- * The two following functions will be cleaned up at the end.
- */
-
-VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
-{
-    VirtIODevice *vdev = NULL;
-    return virtio_serial_common_init(dev, conf, &vdev);
-}
-
-void virtio_serial_exit(VirtIODevice *vdev)
-{
-    VirtIOSerial *vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
-
-    unregister_savevm(vser->qdev, "virtio-console", vser);
-
-    g_free(vser->ivqs);
-    g_free(vser->ovqs);
-    g_free(vser->ports_map);
-    if (vser->post_load) {
-        g_free(vser->post_load->connected);
-        qemu_del_timer(vser->post_load->timer);
-        qemu_free_timer(vser->post_load->timer);
-        g_free(vser->post_load);
-    }
-    virtio_cleanup(vdev);
+    return 0;
 }
 
 static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
@@ -1055,16 +1015,6 @@ void virtio_serial_set_conf(DeviceState *dev, virtio_serial_conf *serial)
     memcpy(&(s->serial), serial, sizeof(virtio_serial_conf));
 }
 
-static int virtio_serial_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
-    if (virtio_serial_common_init(qdev, &(vser->serial), &vdev) == NULL) {
-        return -1;
-    }
-    return 0;
-}
-
 static int virtio_serial_device_exit(DeviceState *dev)
 {
     VirtIOSerial *vser = VIRTIO_SERIAL(dev);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 51/61] virtio-serial : cleanup : use QOM casts.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (49 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 50/61] virtio-serial : cleanup : init and exit functions fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 52/61] virtio-serial : cleanup : remove qdev field fred.konrad
                   ` (12 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-serial-pci and virtio-serial-s390 are switched to the new
API, we can use QOM casts. This shouldn't been applyied before
virtio-serial-pci and virtio-serial-s390 refactoring as their
VirtIODevice were not a QOM object.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-serial-bus.c | 50 ++++++++++++++++++++++++++------------------------
 hw/virtio-serial.h     |  2 +-
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index f1c7d75..3bcb2d7 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -53,7 +53,8 @@ static VirtIOSerialPort *find_port_by_vq(VirtIOSerial *vser, VirtQueue *vq)
 
 static bool use_multiport(VirtIOSerial *vser)
 {
-    return vser->vdev.guest_features & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
+    VirtIODevice *vdev = VIRTIO_DEVICE(vser);
+    return vdev->guest_features & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
 }
 
 static size_t write_to_port(VirtIOSerialPort *port,
@@ -83,7 +84,7 @@ static size_t write_to_port(VirtIOSerialPort *port,
         virtqueue_push(vq, &elem, len);
     }
 
-    virtio_notify(&port->vser->vdev, vq);
+    virtio_notify(VIRTIO_DEVICE(port->vser), vq);
     return offset;
 }
 
@@ -173,7 +174,7 @@ static void flush_queued_data(VirtIOSerialPort *port)
     if (!virtio_queue_ready(port->ovq)) {
         return;
     }
-    do_flush_queued_data(port, port->ovq, &port->vser->vdev);
+    do_flush_queued_data(port, port->ovq, VIRTIO_DEVICE(port->vser));
 }
 
 static size_t send_control_msg(VirtIOSerial *vser, void *buf, size_t len)
@@ -192,7 +193,7 @@ static size_t send_control_msg(VirtIOSerial *vser, void *buf, size_t len)
     memcpy(elem.in_sg[0].iov_base, buf, len);
 
     virtqueue_push(vq, &elem, len);
-    virtio_notify(&vser->vdev, vq);
+    virtio_notify(VIRTIO_DEVICE(vser), vq);
     return len;
 }
 
@@ -231,7 +232,7 @@ int virtio_serial_close(VirtIOSerialPort *port)
      * consume, reset the throttling flag and discard the data.
      */
     port->throttled = false;
-    discard_vq_data(port->ovq, &port->vser->vdev);
+    discard_vq_data(port->ovq, VIRTIO_DEVICE(port->vser));
 
     send_control_event(port->vser, port->id, VIRTIO_CONSOLE_PORT_OPEN, 0);
 
@@ -254,11 +255,12 @@ ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
  */
 size_t virtio_serial_guest_ready(VirtIOSerialPort *port)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(port->vser);
     VirtQueue *vq = port->ivq;
     unsigned int bytes;
 
     if (!virtio_queue_ready(vq) ||
-        !(port->vser->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK) ||
+        !(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) ||
         virtio_queue_empty(vq)) {
         return 0;
     }
@@ -413,7 +415,7 @@ static void control_out(VirtIODevice *vdev, VirtQueue *vq)
     uint8_t *buf;
     size_t len;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = VIRTIO_SERIAL(vdev);
 
     len = 0;
     buf = NULL;
@@ -446,7 +448,7 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
     VirtIOSerial *vser;
     VirtIOSerialPort *port;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = VIRTIO_SERIAL(vdev);
     port = find_port_by_vq(vser, vq);
 
     if (!port || !port->host_connected) {
@@ -468,7 +470,7 @@ static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
 {
     VirtIOSerial *vser;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = VIRTIO_SERIAL(vdev);
 
     if (vser->bus.max_nr_ports > 1) {
         features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT);
@@ -481,7 +483,7 @@ static void get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
     VirtIOSerial *vser;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = VIRTIO_SERIAL(vdev);
     memcpy(config_data, &vser->config, sizeof(struct virtio_console_config));
 }
 
@@ -513,7 +515,7 @@ static void set_status(VirtIODevice *vdev, uint8_t status)
     VirtIOSerial *vser;
     VirtIOSerialPort *port;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = VIRTIO_SERIAL(vdev);
     port = find_port_by_id(vser, 0);
 
     if (port && !use_multiport(port->vser)
@@ -535,19 +537,19 @@ static void vser_reset(VirtIODevice *vdev)
 {
     VirtIOSerial *vser;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = VIRTIO_SERIAL(vdev);
     guest_reset(vser);
 }
 
 static void virtio_serial_save(QEMUFile *f, void *opaque)
 {
-    VirtIOSerial *s = opaque;
+    VirtIOSerial *s = VIRTIO_SERIAL(opaque);
     VirtIOSerialPort *port;
     uint32_t nr_active_ports;
     unsigned int i, max_nr_ports;
 
     /* The virtio device */
-    virtio_save(&s->vdev, f);
+    virtio_save(VIRTIO_DEVICE(s), f);
 
     /* The config space */
     qemu_put_be16s(f, &s->config.cols);
@@ -598,7 +600,7 @@ static void virtio_serial_save(QEMUFile *f, void *opaque)
 static void virtio_serial_post_load_timer_cb(void *opaque)
 {
     uint32_t i;
-    VirtIOSerial *s = opaque;
+    VirtIOSerial *s = VIRTIO_SERIAL(opaque);
     VirtIOSerialPort *port;
     uint8_t host_connected;
 
@@ -681,7 +683,7 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id,
 
 static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
 {
-    VirtIOSerial *s = opaque;
+    VirtIOSerial *s = VIRTIO_SERIAL(opaque);
     uint32_t max_nr_ports, nr_active_ports, ports_map;
     unsigned int i;
     int ret;
@@ -691,7 +693,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
     }
 
     /* The virtio device */
-    ret = virtio_load(&s->vdev, f);
+    ret = virtio_load(VIRTIO_DEVICE(s), f);
     if (ret) {
         return ret;
     }
@@ -818,7 +820,7 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id)
     assert(port);
 
     /* Flush out any unconsumed buffers first */
-    discard_vq_data(port->ovq, &port->vser->vdev);
+    discard_vq_data(port->ovq, VIRTIO_DEVICE(port->vser));
 
     send_control_event(vser, port->id, VIRTIO_CONSOLE_PORT_REMOVE, 1);
 }
@@ -882,7 +884,7 @@ static int virtser_port_qdev_init(DeviceState *qdev)
     add_port(port->vser, port->id);
 
     /* Send an update to the guest about this new port added */
-    virtio_notify_config(&port->vser->vdev);
+    virtio_notify_config(VIRTIO_DEVICE(port->vser));
 
     return ret;
 }
@@ -970,11 +972,11 @@ static int virtio_serial_device_init(VirtIODevice *vdev)
      */
     mark_port_added(vser, 0);
 
-    vser->vdev.get_features = get_features;
-    vser->vdev.get_config = get_config;
-    vser->vdev.set_config = set_config;
-    vser->vdev.set_status = set_status;
-    vser->vdev.reset = vser_reset;
+    vdev->get_features = get_features;
+    vdev->get_config = get_config;
+    vdev->set_config = set_config;
+    vdev->set_status = set_status;
+    vdev->reset = vser_reset;
 
     vser->qdev = qdev;
 
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index f5960f9..7517e8c 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -194,7 +194,7 @@ typedef struct VirtIOSerialPostLoad {
 } VirtIOSerialPostLoad;
 
 struct VirtIOSerial {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
 
     VirtQueue *c_ivq, *c_ovq;
     /* Arrays of ivqs and ovqs: one per port */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 52/61] virtio-serial : cleanup : remove qdev field.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (50 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 51/61] virtio-serial : cleanup : use QOM casts fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 53/61] virtio-9p : add the virtio-9p device fred.konrad
                   ` (11 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

The qdev field is no longer needed, just drop it.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-serial-bus.c | 2 --
 hw/virtio-serial.h     | 2 --
 2 files changed, 4 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 3bcb2d7..d1f47a4 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -978,8 +978,6 @@ static int virtio_serial_device_init(VirtIODevice *vdev)
     vdev->set_status = set_status;
     vdev->reset = vser_reset;
 
-    vser->qdev = qdev;
-
     vser->post_load = NULL;
 
     /*
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index 7517e8c..42f9b7c 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -202,8 +202,6 @@ struct VirtIOSerial {
 
     VirtIOSerialBus bus;
 
-    DeviceState *qdev;
-
     QTAILQ_HEAD(, VirtIOSerialPort) ports;
 
     /* bitmap for identifying active ports */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 53/61] virtio-9p : add the virtio-9p device.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (51 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 52/61] virtio-serial : cleanup : remove qdev field fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 54/61] virtio-9p-pci : switch to the new API fred.konrad
                   ` (10 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Create virtio-9p which extends virtio-device, so it can be connected on
virtio-bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/9pfs/virtio-9p-device.c | 84 +++++++++++++++++++++++++++++++++++++++-------
 hw/9pfs/virtio-9p.h        | 11 ++++++
 hw/virtio-pci.c            |  5 +++
 3 files changed, 87 insertions(+), 13 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 6761bce..8a88739 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -46,19 +46,36 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config)
     g_free(cfg);
 }
 
-VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
+void virtio_9p_set_conf(DeviceState *dev, V9fsConf *conf)
 {
-    V9fsState *s;
+    V9fsState *s = VIRTIO_9P(dev);
+    memcpy(&(s->fsconf), conf, sizeof(V9fsConf));
+}
+
+static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,
+                                           V9fsState **ps)
+{
+    V9fsState *s = *ps;
     int i, len;
     struct stat stat;
     FsDriverEntry *fse;
     V9fsPath path;
 
-    s = (V9fsState *)virtio_common_init("virtio-9p",
-                                    VIRTIO_ID_9P,
-                                    sizeof(struct virtio_9p_config)+
-                                    MAX_TAG_LEN,
-                                    sizeof(V9fsState));
+    /*
+     * We have two cases here : the old virtio-9p-pci device, and the
+     * refactored virtio-9p.
+     */
+
+    if (s == NULL) {
+        s = (V9fsState *)virtio_common_init("virtio-9p",
+                                        VIRTIO_ID_9P,
+                                        sizeof(struct virtio_9p_config)+
+                                        MAX_TAG_LEN,
+                                        sizeof(V9fsState));
+    } else {
+        virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P,
+                    sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
+    }
     /* initialize pdu allocator */
     QLIST_INIT(&s->free_list);
     QLIST_INIT(&s->active_list);
@@ -141,6 +158,12 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
     return &s->vdev;
 }
 
+VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
+{
+    V9fsState *s = NULL;
+    return virtio_9p_common_init(dev, conf, &s);
+}
+
 static int virtio_9p_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -154,16 +177,15 @@ static int virtio_9p_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
-static Property virtio_9p_properties[] = {
+static Property virtio_9p_pci_properties[] = {
     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
-    DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
+    DEFINE_VIRTIO_9P_PROPERTIES(VirtIOPCIProxy, fsconf),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void virtio_9p_class_init(ObjectClass *klass, void *data)
+static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -173,7 +195,7 @@ static void virtio_9p_class_init(ObjectClass *klass, void *data)
     k->device_id = 0x1009;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = 0x2;
-    dc->props = virtio_9p_properties;
+    dc->props = virtio_9p_pci_properties;
     dc->reset = virtio_pci_reset;
 }
 
@@ -181,11 +203,47 @@ static TypeInfo virtio_9p_info = {
     .name          = "virtio-9p-pci",
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(VirtIOPCIProxy),
-    .class_init    = virtio_9p_class_init,
+    .class_init    = virtio_9p_pci_class_init,
+};
+
+/* virtio-9p device */
+
+static int virtio_9p_device_init(VirtIODevice *vdev)
+{
+    DeviceState *qdev = DEVICE(vdev);
+    V9fsState *s = VIRTIO_9P(vdev);
+    V9fsConf *fsconf = &(s->fsconf);
+    if (virtio_9p_common_init(qdev, fsconf, &s) == NULL) {
+        return -1;
+    }
+    return 0;
+}
+
+static Property virtio_9p_properties[] = {
+    DEFINE_VIRTIO_9P_PROPERTIES(V9fsState, fsconf),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_9p_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->props = virtio_9p_properties;
+    vdc->init = virtio_9p_device_init;
+    vdc->get_features = virtio_9p_get_features;
+    vdc->get_config = virtio_9p_get_config;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_9P,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(V9fsState),
+    .class_init = virtio_9p_class_init,
 };
 
 static void virtio_9p_register_types(void)
 {
+    type_register_static(&virtio_device_info);
     type_register_static(&virtio_9p_info);
     virtio_9p_set_fd_limit();
 }
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 406fe52..3be634f 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -225,6 +225,7 @@ typedef struct V9fsState
     CoRwlock rename_lock;
     int32_t root_fid;
     Error *migration_blocker;
+    V9fsConf fsconf;
 } V9fsState;
 
 typedef struct V9fsStatState {
@@ -402,4 +403,14 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
 #define pdu_unmarshal(pdu, offset, fmt, args...)  \
     v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args)
 
+#define TYPE_VIRTIO_9P "virtio-9p"
+#define VIRTIO_9P(obj) \
+        OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P)
+
+#define DEFINE_VIRTIO_9P_PROPERTIES(_state, _field)             \
+        DEFINE_PROP_STRING("mount_tag", _state, _field.tag),    \
+        DEFINE_PROP_STRING("fsdev", _state, _field.fsdev_id)
+
+void virtio_9p_set_conf(DeviceState *dev, V9fsConf *conf);
+
 #endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7d66c51..0e45b1a 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -23,6 +23,7 @@
 #include "virtio-serial.h"
 #include "virtio-scsi.h"
 #include "virtio-balloon.h"
+#include "9pfs/virtio-9p.h"
 #include "pci/pci.h"
 #include "qemu/error-report.h"
 #include "pci/msi.h"
@@ -829,6 +830,10 @@ static void virtio_pci_device_plugged(DeviceState *d)
         pci_config_set_class(proxy->pci_dev.config,
                              PCI_CLASS_COMMUNICATION_OTHER);
         break;
+    case VIRTIO_ID_9P:
+        pci_config_set_device_id(proxy->pci_dev.config, 0x1009);
+        pci_config_set_class(proxy->pci_dev.config, 0x0002);
+        break;
     default:
         error_report("unknown device id\n");
         break;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 54/61] virtio-9p-pci : switch to the new API.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (52 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 53/61] virtio-9p : add the virtio-9p device fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 55/61] virtio-9p : cleanup : init function fred.konrad
                   ` (9 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Here the virtio-9p-pci is modified for the new API. The device
virtio-9p-pci extends virtio-pci. It creates and connects a virtio-9p
during the init. The properties are not changed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/9pfs/virtio-9p-device.c | 48 +++++++++++++++++++++++++---------------------
 hw/9pfs/virtio-9p.h        | 14 ++++++++++++++
 hw/virtio-pci.h            |  3 ---
 3 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 8a88739..7e4b239 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -164,45 +164,49 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
     return virtio_9p_common_init(dev, conf, &s);
 }
 
-static int virtio_9p_init_pci(PCIDevice *pci_dev)
+static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
 {
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
-    vdev->nvectors = proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-    /* make the actual value visible */
-    proxy->nvectors = vdev->nvectors;
+    V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev);
+    DeviceState *vdev = DEVICE(&dev->vdev);
+
+    virtio_9p_set_conf(vdev, &(dev->fsconf));
+    qdev_set_parent_bus(vdev, BUS(vpci_dev->bus));
+    if (qdev_init(vdev) < 0) {
+        return -1;
+    }
     return 0;
 }
 
 static Property virtio_9p_pci_properties[] = {
-    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-    DEFINE_VIRTIO_9P_PROPERTIES(VirtIOPCIProxy, fsconf),
+    DEFINE_VIRTIO_9P_PROPERTIES(V9fsPCIState, fsconf),
     DEFINE_PROP_END_OF_LIST(),
 };
 
 static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
 
     k->init = virtio_9p_init_pci;
-    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-    k->device_id = 0x1009;
-    k->revision = VIRTIO_PCI_ABI_VERSION;
-    k->class_id = 0x2;
     dc->props = virtio_9p_pci_properties;
-    dc->reset = virtio_pci_reset;
 }
 
-static TypeInfo virtio_9p_info = {
-    .name          = "virtio-9p-pci",
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VirtIOPCIProxy),
+static void virtio_9p_pci_instance_init(Object *obj)
+{
+    V9fsPCIState *dev = VIRTIO_9P_PCI(obj);
+    object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_9P);
+    object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+}
+
+static TypeInfo virtio_9p_pci_info = {
+    .name          = TYPE_VIRTIO_9P_PCI,
+    .parent        = TYPE_VIRTIO_PCI,
+    .instance_size = sizeof(V9fsPCIState),
+    .instance_init = virtio_9p_pci_instance_init,
     .class_init    = virtio_9p_pci_class_init,
 };
 
@@ -244,7 +248,7 @@ static const TypeInfo virtio_device_info = {
 static void virtio_9p_register_types(void)
 {
     type_register_static(&virtio_device_info);
-    type_register_static(&virtio_9p_info);
+    type_register_static(&virtio_9p_pci_info);
     virtio_9p_set_fd_limit();
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 3be634f..9b342dc 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -11,6 +11,7 @@
 #include "fsdev/virtio-9p-marshal.h"
 #include "qemu/thread.h"
 #include "block/coroutine.h"
+#include "hw/virtio-pci.h"
 
 
 /* The feature bitmap for virtio 9P */
@@ -413,4 +414,17 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
 
 void virtio_9p_set_conf(DeviceState *dev, V9fsConf *conf);
 
+/*
+ * virtio-9p-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
+#define VIRTIO_9P_PCI(obj) \
+        OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
+
+typedef struct V9fsPCIState {
+    VirtIOPCIProxy parent_obj;
+    V9fsState vdev;
+    V9fsConf fsconf;
+} V9fsPCIState;
+
 #endif
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 98b51d8..e251d93 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -76,9 +76,6 @@ struct VirtIOPCIProxy {
     uint32_t class_code;
     uint32_t nvectors;
     uint32_t host_features;
-#ifdef CONFIG_LINUX
-    V9fsConf fsconf;
-#endif
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 55/61] virtio-9p : cleanup : init function.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (53 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 54/61] virtio-9p-pci : switch to the new API fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 56/61] virtio-9p : cleanup : QOM casts fred.konrad
                   ` (8 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init function as it is no longer needed. This shouldn't
been applyied before virtio-9p-pci refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/9pfs/virtio-9p-device.c | 75 ++++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 52 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 7e4b239..02f01ae 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -52,30 +52,17 @@ void virtio_9p_set_conf(DeviceState *dev, V9fsConf *conf)
     memcpy(&(s->fsconf), conf, sizeof(V9fsConf));
 }
 
-static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,
-                                           V9fsState **ps)
+static int virtio_9p_device_init(VirtIODevice *vdev)
 {
-    V9fsState *s = *ps;
+    V9fsState *s = VIRTIO_9P(vdev);
     int i, len;
     struct stat stat;
     FsDriverEntry *fse;
     V9fsPath path;
 
-    /*
-     * We have two cases here : the old virtio-9p-pci device, and the
-     * refactored virtio-9p.
-     */
+    virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P,
+                sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
 
-    if (s == NULL) {
-        s = (V9fsState *)virtio_common_init("virtio-9p",
-                                        VIRTIO_ID_9P,
-                                        sizeof(struct virtio_9p_config)+
-                                        MAX_TAG_LEN,
-                                        sizeof(V9fsState));
-    } else {
-        virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P,
-                    sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
-    }
     /* initialize pdu allocator */
     QLIST_INIT(&s->free_list);
     QLIST_INIT(&s->active_list);
@@ -83,22 +70,23 @@ static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,
         QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
     }
 
-    s->vq = virtio_add_queue(&s->vdev, MAX_REQ, handle_9p_output);
+    s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
 
-    fse = get_fsdev_fsentry(conf->fsdev_id);
+    fse = get_fsdev_fsentry(s->fsconf.fsdev_id);
 
     if (!fse) {
         /* We don't have a fsdev identified by fsdev_id */
         fprintf(stderr, "Virtio-9p device couldn't find fsdev with the "
-                "id = %s\n", conf->fsdev_id ? conf->fsdev_id : "NULL");
-        exit(1);
+                "id = %s\n",
+                s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL");
+        return -1;
     }
 
-    if (!conf->tag) {
+    if (!s->fsconf.tag) {
         /* we haven't specified a mount_tag */
         fprintf(stderr, "fsdev with id %s needs mount_tag arguments\n",
-                conf->fsdev_id);
-        exit(1);
+                s->fsconf.fsdev_id);
+        return -1;
     }
 
     s->ctx.export_flags = fse->export_flags;
@@ -108,14 +96,14 @@ static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,
         s->ctx.fs_root = NULL;
     }
     s->ctx.exops.get_st_gen = NULL;
-    len = strlen(conf->tag);
+    len = strlen(s->fsconf.tag);
     if (len > MAX_TAG_LEN - 1) {
         fprintf(stderr, "mount tag '%s' (%d bytes) is longer than "
-                "maximum (%d bytes)", conf->tag, len, MAX_TAG_LEN - 1);
-        exit(1);
+                "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN - 1);
+        return -1;
     }
 
-    s->tag = strdup(conf->tag);
+    s->tag = strdup(s->fsconf.tag);
     s->ctx.uid = -1;
 
     s->ops = fse->ops;
@@ -127,12 +115,12 @@ static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,
 
     if (s->ops->init(&s->ctx) < 0) {
         fprintf(stderr, "Virtio-9p Failed to initialize fs-driver with id:%s"
-                " and export path:%s\n", conf->fsdev_id, s->ctx.fs_root);
-        exit(1);
+                " and export path:%s\n", s->fsconf.fsdev_id, s->ctx.fs_root);
+        return -1;
     }
     if (v9fs_init_worker_threads() < 0) {
         fprintf(stderr, "worker thread initialization failed\n");
-        exit(1);
+        return -1;
     }
 
     /*
@@ -144,24 +132,18 @@ static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,
     if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) {
         fprintf(stderr,
                 "error in converting name to path %s", strerror(errno));
-        exit(1);
+        return -1;
     }
     if (s->ops->lstat(&s->ctx, &path, &stat)) {
         fprintf(stderr, "share path %s does not exist\n", fse->path);
-        exit(1);
+        return -1;
     } else if (!S_ISDIR(stat.st_mode)) {
         fprintf(stderr, "share path %s is not a directory\n", fse->path);
-        exit(1);
+        return -1;
     }
     v9fs_path_free(&path);
 
-    return &s->vdev;
-}
-
-VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
-{
-    V9fsState *s = NULL;
-    return virtio_9p_common_init(dev, conf, &s);
+    return 0;
 }
 
 static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
@@ -212,17 +194,6 @@ static TypeInfo virtio_9p_pci_info = {
 
 /* virtio-9p device */
 
-static int virtio_9p_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    V9fsState *s = VIRTIO_9P(vdev);
-    V9fsConf *fsconf = &(s->fsconf);
-    if (virtio_9p_common_init(qdev, fsconf, &s) == NULL) {
-        return -1;
-    }
-    return 0;
-}
-
 static Property virtio_9p_properties[] = {
     DEFINE_VIRTIO_9P_PROPERTIES(V9fsState, fsconf),
     DEFINE_PROP_END_OF_LIST(),
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 56/61] virtio-9p : cleanup : QOM casts.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (54 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 55/61] virtio-9p : cleanup : init function fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer fred.konrad
                   ` (7 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

As the virtio-9p-pci is switched to the new API, we can use QOM casts.
This shouldn't been applyied before virtio-9p-pci refactoring as its
VirtIODevice was not a QOM object.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/9pfs/virtio-9p-device.c | 11 +++--------
 hw/9pfs/virtio-9p.c        |  2 +-
 hw/9pfs/virtio-9p.h        |  2 +-
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 02f01ae..a99ff5a 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -26,16 +26,11 @@ static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
     return features;
 }
 
-static V9fsState *to_virtio_9p(VirtIODevice *vdev)
-{
-    return (V9fsState *)vdev;
-}
-
 static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config)
 {
     int len;
     struct virtio_9p_config *cfg;
-    V9fsState *s = to_virtio_9p(vdev);
+    V9fsState *s = VIRTIO_9P(vdev);
 
     len = strlen(s->tag);
     cfg = g_malloc0(sizeof(struct virtio_9p_config) + len);
@@ -107,9 +102,9 @@ static int virtio_9p_device_init(VirtIODevice *vdev)
     s->ctx.uid = -1;
 
     s->ops = fse->ops;
-    s->vdev.get_features = virtio_9p_get_features;
+    vdev->get_features = virtio_9p_get_features;
     s->config_size = sizeof(struct virtio_9p_config) + len;
-    s->vdev.get_config = virtio_9p_get_config;
+    vdev->get_config = virtio_9p_get_config;
     s->fid_list = NULL;
     qemu_co_rwlock_init(&s->rename_lock);
 
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0aaf0d2..aedea0c 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -631,7 +631,7 @@ static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)
     virtqueue_push(s->vq, &pdu->elem, len);
 
     /* FIXME: we should batch these completions */
-    virtio_notify(&s->vdev, s->vq);
+    virtio_notify(VIRTIO_DEVICE(s), s->vq);
 
     /* Now wakeup anybody waiting in flush for this request */
     qemu_co_queue_next(&pdu->complete);
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 9b342dc..f21e33f 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -207,7 +207,7 @@ struct V9fsFidState
 
 typedef struct V9fsState
 {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
     VirtQueue *vq;
     V9fsPDU pdus[MAX_REQ];
     QLIST_HEAD(, V9fsPDU) free_list;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (55 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 56/61] virtio-9p : cleanup : QOM casts fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-09 20:40   ` Blue Swirl
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 58/61] virtio-pci : cleanup : init, exit and reset functions fred.konrad
                   ` (6 subsequent siblings)
  63 siblings, 1 reply; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove the function pointer in VirtIODevice, and use only
VirtioDeviceClass function pointer. It should be applied after all
the device have been refactored.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/9pfs/virtio-9p-device.c |  2 --
 hw/virtio-balloon.c        |  8 --------
 hw/virtio-blk.c            |  5 -----
 hw/virtio-net.c            |  7 -------
 hw/virtio-pci.c            |  2 +-
 hw/virtio-rng.c            |  6 ------
 hw/virtio-scsi.c           |  6 ------
 hw/virtio-serial-bus.c     |  6 ------
 hw/virtio.c                | 41 ++++++++++++++++++++++++++---------------
 hw/virtio.h                | 11 -----------
 10 files changed, 27 insertions(+), 67 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index a99ff5a..17be320 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -102,9 +102,7 @@ static int virtio_9p_device_init(VirtIODevice *vdev)
     s->ctx.uid = -1;
 
     s->ops = fse->ops;
-    vdev->get_features = virtio_9p_get_features;
     s->config_size = sizeof(struct virtio_9p_config) + len;
-    vdev->get_config = virtio_9p_get_config;
     s->fid_list = NULL;
     qemu_co_rwlock_init(&s->rename_lock);
 
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index e2cb2fc..40d3c15 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -227,14 +227,6 @@ static int virtio_balloon_device_init(VirtIODevice *vdev)
 
     virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, 8);
 
-    /*
-     * This will disappear later in the serie.
-     * We will use VirtioDeviceClass instead.
-     */
-    vdev->get_config = virtio_balloon_get_config;
-    vdev->set_config = virtio_balloon_set_config;
-    vdev->get_features = virtio_balloon_get_features;
-
     ret = qemu_add_balloon_handler(virtio_balloon_to_target,
                                    virtio_balloon_stat, s);
 
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 74ba97b..14e4543 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -651,11 +651,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
     virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
                 sizeof(struct virtio_blk_config));
 
-    vdev->get_config = virtio_blk_update_config;
-    vdev->set_config = virtio_blk_set_config;
-    vdev->get_features = virtio_blk_get_features;
-    vdev->set_status = virtio_blk_set_status;
-    vdev->reset = virtio_blk_reset;
     s->bs = blk->conf.bs;
     s->conf = &blk->conf;
     memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 7f87166..3ae0d79 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -999,13 +999,6 @@ static int virtio_net_device_init(VirtIODevice *vdev)
     virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
                                   sizeof(struct virtio_net_config));
 
-    vdev->get_config = virtio_net_get_config;
-    vdev->set_config = virtio_net_set_config;
-    vdev->get_features = virtio_net_get_features;
-    vdev->set_features = virtio_net_set_features;
-    vdev->bad_features = virtio_net_bad_features;
-    vdev->reset = virtio_net_reset;
-    vdev->set_status = virtio_net_set_status;
     n->rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
 
     if (n->net_conf.tx && strcmp(n->net_conf.tx, "timer") &&
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 0e45b1a..c47b9b1 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -276,7 +276,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     case VIRTIO_PCI_GUEST_FEATURES:
 	/* Guest does not negotiate properly?  We have to assume nothing. */
 	if (val & (1 << VIRTIO_F_BAD_FEATURE)) {
-            val = vdev->bad_features ? vdev->bad_features(vdev) : 0;
+            val = virtio_device_get_bad_features(proxy->bus);
 	}
         virtio_set_features(vdev, val);
         break;
diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
index 67407a7..57e0dae 100644
--- a/hw/virtio-rng.c
+++ b/hw/virtio-rng.c
@@ -173,12 +173,6 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
     }
 
     vrng->vq = virtio_add_queue(vdev, 8, handle_input);
-    /*
-     * This will disappear later in the serie.
-     * We will use VirtioDeviceClass instead.
-     */
-    vdev->get_features = get_features;
-    /**/
 
     assert(vrng->conf.max_bytes <= INT64_MAX);
     vrng->quota_remaining = vrng->conf.max_bytes;
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 273ca69..0e43230 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -705,12 +705,6 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
 
     s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
 
-    /* TODO set up vdev function pointers */
-    vdev->get_config = virtio_scsi_get_config;
-    vdev->set_config = virtio_scsi_set_config;
-    vdev->get_features = virtio_scsi_get_features;
-    vdev->reset = virtio_scsi_reset;
-
     s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
                                   virtio_scsi_handle_ctrl);
     s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index d1f47a4..ef74c26 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -972,12 +972,6 @@ static int virtio_serial_device_init(VirtIODevice *vdev)
      */
     mark_port_added(vser, 0);
 
-    vdev->get_features = get_features;
-    vdev->get_config = get_config;
-    vdev->set_config = set_config;
-    vdev->set_status = set_status;
-    vdev->reset = vser_reset;
-
     vser->post_load = NULL;
 
     /*
diff --git a/hw/virtio.c b/hw/virtio.c
index ca170c3..d72b84a 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -517,10 +517,11 @@ void virtio_update_irq(VirtIODevice *vdev)
 
 void virtio_set_status(VirtIODevice *vdev, uint8_t val)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     trace_virtio_set_status(vdev, val);
 
-    if (vdev->set_status) {
-        vdev->set_status(vdev, val);
+    if (k->set_status) {
+        k->set_status(vdev, val);
     }
     vdev->status = val;
 }
@@ -528,12 +529,14 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
 void virtio_reset(void *opaque)
 {
     VirtIODevice *vdev = opaque;
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     int i;
 
     virtio_set_status(vdev, 0);
 
-    if (vdev->reset)
-        vdev->reset(vdev);
+    if (k->reset) {
+        k->reset(vdev);
+    }
 
     vdev->guest_features = 0;
     vdev->queue_sel = 0;
@@ -557,9 +560,10 @@ void virtio_reset(void *opaque)
 
 uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     uint8_t val;
 
-    vdev->get_config(vdev, vdev->config);
+    k->get_config(vdev, vdev->config);
 
     if (addr > (vdev->config_len - sizeof(val)))
         return (uint32_t)-1;
@@ -570,9 +574,10 @@ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
 
 uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     uint16_t val;
 
-    vdev->get_config(vdev, vdev->config);
+    k->get_config(vdev, vdev->config);
 
     if (addr > (vdev->config_len - sizeof(val)))
         return (uint32_t)-1;
@@ -583,9 +588,10 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
 
 uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     uint32_t val;
 
-    vdev->get_config(vdev, vdev->config);
+    k->get_config(vdev, vdev->config);
 
     if (addr > (vdev->config_len - sizeof(val)))
         return (uint32_t)-1;
@@ -596,6 +602,7 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
 
 void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     uint8_t val = data;
 
     if (addr > (vdev->config_len - sizeof(val)))
@@ -603,12 +610,13 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 
     stb_p(vdev->config + addr, val);
 
-    if (vdev->set_config)
-        vdev->set_config(vdev, vdev->config);
+    if (k->set_config)
+        k->set_config(vdev, vdev->config);
 }
 
 void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     uint16_t val = data;
 
     if (addr > (vdev->config_len - sizeof(val)))
@@ -616,12 +624,13 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 
     stw_p(vdev->config + addr, val);
 
-    if (vdev->set_config)
-        vdev->set_config(vdev, vdev->config);
+    if (k->set_config)
+        k->set_config(vdev, vdev->config);
 }
 
 void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     uint32_t val = data;
 
     if (addr > (vdev->config_len - sizeof(val)))
@@ -629,8 +638,9 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
 
     stl_p(vdev->config + addr, val);
 
-    if (vdev->set_config)
-        vdev->set_config(vdev, vdev->config);
+    if (k->set_config) {
+        k->set_config(vdev, vdev->config);
+    }
 }
 
 void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
@@ -799,13 +809,14 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 
 int virtio_set_features(VirtIODevice *vdev, uint32_t val)
 {
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     uint32_t supported_features =
         vdev->binding->get_features(vdev->binding_opaque);
     bool bad = (val & ~supported_features) != 0;
 
     val &= supported_features;
-    if (vdev->set_features) {
-        vdev->set_features(vdev, val);
+    if (k->set_features) {
+        k->set_features(vdev, val);
     }
     vdev->guest_features = val;
     return bad ? -1 : 0;
diff --git a/hw/virtio.h b/hw/virtio.h
index c134960..fbbf8e8 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -128,17 +128,6 @@ struct VirtIODevice
     void *config;
     uint16_t config_vector;
     int nvectors;
-    /*
-     * Function pointers will be removed ( at the end of the series )
-     * as they are in VirtioDeviceClass.
-     */
-    uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
-    uint32_t (*bad_features)(VirtIODevice *vdev);
-    void (*set_features)(VirtIODevice *vdev, uint32_t val);
-    void (*get_config)(VirtIODevice *vdev, uint8_t *config);
-    void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
-    void (*reset)(VirtIODevice *vdev);
-    void (*set_status)(VirtIODevice *vdev, uint8_t val);
     VirtQueue *vq;
     const VirtIOBindings *binding;
     DeviceState *binding_opaque;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 58/61] virtio-pci : cleanup : init, exit and reset functions.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (56 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 59/61] s390-virtio-bus : cleanup fred.konrad
                   ` (5 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove the init, exit and reset functions as they are no longer used. The
new API virtio_pci_rst function is renamed virtio_pci_reset.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-pci.c | 71 ++++-----------------------------------------------------
 hw/virtio-pci.h |  3 ---
 2 files changed, 4 insertions(+), 70 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index c47b9b1..4588073 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -257,15 +257,6 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
     proxy->ioeventfd_started = false;
 }
 
-void virtio_pci_reset(DeviceState *d)
-{
-    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
-    virtio_pci_stop_ioeventfd(proxy);
-    virtio_reset(proxy->vdev);
-    msix_unuse_all_vectors(&proxy->pci_dev);
-    proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
-}
-
 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 {
     VirtIOPCIProxy *proxy = opaque;
@@ -734,57 +725,6 @@ static const VirtIOBindings virtio_pci_bindings = {
     .vmstate_change = virtio_pci_vmstate_change,
 };
 
-void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
-{
-    uint8_t *config;
-    uint32_t size;
-
-    proxy->vdev = vdev;
-
-    config = proxy->pci_dev.config;
-
-    if (proxy->class_code) {
-        pci_config_set_class(config, proxy->class_code);
-    }
-    pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
-                 pci_get_word(config + PCI_VENDOR_ID));
-    pci_set_word(config + PCI_SUBSYSTEM_ID, vdev->device_id);
-    config[PCI_INTERRUPT_PIN] = 1;
-
-    if (vdev->nvectors &&
-        msix_init_exclusive_bar(&proxy->pci_dev, vdev->nvectors, 1)) {
-        vdev->nvectors = 0;
-    }
-
-    proxy->pci_dev.config_write = virtio_write_config;
-
-    size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len;
-    if (size & (size-1))
-        size = 1 << qemu_fls(size);
-
-    memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
-                          "virtio-pci", size);
-    pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
-                     &proxy->bar);
-
-    if (!kvm_has_many_ioeventfds()) {
-        proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
-    }
-
-    virtio_bind_device(vdev, &virtio_pci_bindings, DEVICE(proxy));
-    proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
-    proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
-    proxy->host_features = vdev->get_features(vdev, proxy->host_features);
-}
-
-static void virtio_exit_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
-    memory_region_destroy(&proxy->bar);
-    msix_uninit_exclusive_bar(pci_dev);
-}
-
 /*
  * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
  */
@@ -904,14 +844,11 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
     BusState *qbus = BUS(proxy->bus);
     virtio_bus_destroy_device(bus);
     qbus_free(qbus);
-    virtio_exit_pci(pci_dev);
+    memory_region_destroy(&proxy->bar);
+    msix_uninit_exclusive_bar(pci_dev);
 }
 
-/*
- * This will be renamed virtio_pci_reset at the end of the series.
- * virtio_pci_reset is still in use at this moment.
- */
-static void virtio_pci_rst(DeviceState *qdev)
+static void virtio_pci_reset(DeviceState *qdev)
 {
     VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
     VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
@@ -931,7 +868,7 @@ static void virtio_pci_class_init(ObjectClass *klass, void *data)
     k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_OTHERS;
-    dc->reset = virtio_pci_rst;
+    dc->reset = virtio_pci_reset;
 }
 
 static const TypeInfo virtio_pci_info = {
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index e251d93..4acddfd 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -161,9 +161,6 @@ struct VirtIOSerialPCI {
     virtio_serial_conf serial;
 };
 
-void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
-void virtio_pci_reset(DeviceState *d);
-
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 59/61] s390-virtio-bus : cleanup
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (57 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 58/61] virtio-pci : cleanup : init, exit and reset functions fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 60/61] virtio : remove virtiobindings fred.konrad
                   ` (4 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

This is a cleanup for s390-virtio-bus : the init function is called by
virtio-bus just after the device is plugged.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 52978b3..017fc0d 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -122,33 +122,34 @@ static void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token)
     }
 }
 
-static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
+/* This is called by virtio-bus just after the device is plugged. */
+static void s390_virtio_device_plugged(DeviceState *d)
 {
     VirtIOS390Bus *bus;
+    VirtIOS390Device *dev = VIRTIO_S390_DEVICE(d);
     int dev_len;
 
     bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
-    dev->vdev = vdev;
+    dev->vdev = dev->bus->vdev;
     dev->dev_offs = bus->dev_offs;
     dev->feat_len = sizeof(uint32_t); /* always keep 32 bits features */
 
     dev_len = VIRTIO_DEV_OFFS_CONFIG;
     dev_len += s390_virtio_device_num_vq(dev) * VIRTIO_VQCONFIG_LEN;
     dev_len += dev->feat_len * 2;
-    dev_len += vdev->config_len;
+    dev_len += virtio_device_get_config_len(dev->bus);
 
     bus->dev_offs += dev_len;
 
-    virtio_bind_device(vdev, &virtio_s390_bindings, DEVICE(dev));
-    dev->host_features = vdev->get_features(vdev, dev->host_features);
+    dev->host_features = virtio_device_get_features(dev->bus,
+                         dev->host_features);
+
     s390_virtio_device_sync(dev);
     s390_virtio_reset_idx(dev);
     if (dev->qdev.hotplugged) {
         S390CPU *cpu = s390_cpu_addr2state(0);
         s390_virtio_irq(cpu, VIRTIO_PARAM_DEV_ADD, dev->dev_offs);
     }
-
-    return 0;
 }
 
 static int s390_virtio_net_init(VirtIOS390Device *s390_dev)
@@ -160,7 +161,7 @@ static int s390_virtio_net_init(VirtIOS390Device *s390_dev)
     if (qdev_init(vdev) < 0) {
         return -1;
     }
-    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+    return 0;
 }
 
 static void s390_virtio_net_instance_init(Object *obj)
@@ -179,7 +180,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *s390_dev)
     if (qdev_init(vdev) < 0) {
         return -1;
     }
-    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+    return 0;
 }
 
 static void s390_virtio_blk_instance_init(Object *obj)
@@ -195,7 +196,6 @@ static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
     DeviceState *vdev = DEVICE(&dev->vdev);
     DeviceState *qdev = DEVICE(s390_dev);
     VirtIOS390Bus *bus;
-    int r;
 
     bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
 
@@ -204,13 +204,8 @@ static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
     if (qdev_init(vdev) < 0) {
         return -1;
     }
-
-    r = s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
-    if (!r) {
-        bus->console = s390_dev;
-    }
-
-    return r;
+    bus->console = s390_dev;
+    return 0;
 }
 
 static void s390_virtio_serial_instance_init(Object *obj)
@@ -229,7 +224,7 @@ static int s390_virtio_scsi_init(VirtIOS390Device *s390_dev)
     if (qdev_init(vdev) < 0) {
         return -1;
     }
-    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+    return 0;
 }
 
 static void s390_virtio_scsi_instance_init(Object *obj)
@@ -248,7 +243,7 @@ static int s390_virtio_rng_init(VirtIOS390Device *s390_dev)
     if (qdev_init(vdev) < 0) {
         return -1;
     }
-    return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
+    return 0;
 }
 
 static void s390_virtio_rng_instance_init(Object *obj)
@@ -337,9 +332,7 @@ void s390_virtio_device_sync(VirtIOS390Device *dev)
     cur_offs += dev->feat_len * 2;
 
     /* Sync config space */
-    if (dev->vdev->get_config) {
-        dev->vdev->get_config(dev->vdev, dev->vdev->config);
-    }
+    virtio_device_get_config(dev->bus, dev->vdev->config);
 
     cpu_physical_memory_write(cur_offs,
                               dev->vdev->config, dev->vdev->config_len);
@@ -631,6 +624,7 @@ static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
     bus_class->max_dev = 1;
     k->notify = virtio_s390_notify;
     k->get_features = virtio_s390_get_features;
+    k->device_plugged = s390_virtio_device_plugged;
 }
 
 static const TypeInfo virtio_s390_bus_info = {
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 60/61] virtio : remove virtiobindings.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (58 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 59/61] s390-virtio-bus : cleanup fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 61/61] virtio : cleanup : init and exit function fred.konrad
                   ` (3 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/s390-virtio-bus.c |  7 -------
 hw/vhost.c           | 38 +++++++++++++++++++++++++-----------
 hw/virtio-bus.c      | 17 -----------------
 hw/virtio-bus.h      |  4 ----
 hw/virtio-pci.c      | 13 -------------
 hw/virtio.c          | 54 +++++++++++++++++++++++++++++++---------------------
 hw/virtio.h          | 19 ------------------
 7 files changed, 59 insertions(+), 93 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 017fc0d..7b9cb60 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -52,8 +52,6 @@ static const TypeInfo s390_virtio_bus_info = {
     .instance_size = sizeof(VirtIOS390Bus),
 };
 
-static const VirtIOBindings virtio_s390_bindings;
-
 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
 
 /* length of VirtIO device pages */
@@ -429,11 +427,6 @@ static unsigned virtio_s390_get_features(DeviceState *d)
 
 /**************** S390 Virtio Bus Device Descriptions *******************/
 
-static const VirtIOBindings virtio_s390_bindings = {
-    .notify = virtio_s390_notify,
-    .get_features = virtio_s390_get_features,
-};
-
 static Property s390_virtio_net_properties[] = {
     DEFINE_NIC_PROPERTIES(VirtIONetS390, nic),
     DEFINE_PROP_UINT32("x-txtimer", VirtIONetS390,
diff --git a/hw/vhost.c b/hw/vhost.c
index 4e1cb47..7e9171d 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -19,6 +19,7 @@
 #include "qemu/range.h"
 #include <linux/vhost.h>
 #include "exec/address-spaces.h"
+#include "virtio-bus.h"
 
 static void vhost_dev_sync_region(struct vhost_dev *dev,
                                   MemoryRegionSection *section,
@@ -811,9 +812,13 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)
 
 bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev)
 {
-    return !vdev->binding->query_guest_notifiers ||
-        vdev->binding->query_guest_notifiers(vdev->binding_opaque) ||
-        hdev->force;
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+
+    return !k->query_guest_notifiers ||
+           k->query_guest_notifiers(qbus->parent) ||
+           hdev->force;
 }
 
 /* Stop processing guest IO notifications in qemu.
@@ -821,15 +826,18 @@ bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev)
  */
 int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 {
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
     int i, r;
-    if (!vdev->binding->set_host_notifier) {
+    if (!k->set_host_notifier) {
         fprintf(stderr, "binding does not support host notifiers\n");
         r = -ENOSYS;
         goto fail;
     }
 
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = vdev->binding->set_host_notifier(vdev->binding_opaque, i, true);
+        r = k->set_host_notifier(qbus->parent, i, true);
         if (r < 0) {
             fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r);
             goto fail_vq;
@@ -839,7 +847,7 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
     return 0;
 fail_vq:
     while (--i >= 0) {
-        r = vdev->binding->set_host_notifier(vdev->binding_opaque, i, false);
+        r = k->set_host_notifier(qbus->parent, i, false);
         if (r < 0) {
             fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r);
             fflush(stderr);
@@ -857,10 +865,13 @@ fail:
  */
 void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 {
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
     int i, r;
 
     for (i = 0; i < hdev->nvqs; ++i) {
-        r = vdev->binding->set_host_notifier(vdev->binding_opaque, i, false);
+        r = k->set_host_notifier(qbus->parent, i, false);
         if (r < 0) {
             fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r);
             fflush(stderr);
@@ -872,14 +883,17 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
 /* Host notifiers must be enabled at this point. */
 int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)
 {
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
     int i, r;
-    if (!vdev->binding->set_guest_notifiers) {
+    if (!k->set_guest_notifiers) {
         fprintf(stderr, "binding does not support guest notifiers\n");
         r = -ENOSYS;
         goto fail;
     }
 
-    r = vdev->binding->set_guest_notifiers(vdev->binding_opaque, true);
+    r = k->set_guest_notifiers(qbus->parent, true);
     if (r < 0) {
         fprintf(stderr, "Error binding guest notifier: %d\n", -r);
         goto fail_notifiers;
@@ -929,7 +943,7 @@ fail_vq:
     }
 fail_mem:
 fail_features:
-    vdev->binding->set_guest_notifiers(vdev->binding_opaque, false);
+    k->set_guest_notifiers(qbus->parent, false);
 fail_notifiers:
 fail:
     return r;
@@ -938,6 +952,8 @@ fail:
 /* Host notifiers must be enabled at this point. */
 void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev)
 {
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
     int i, r;
 
     for (i = 0; i < hdev->nvqs; ++i) {
@@ -950,7 +966,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev)
         vhost_sync_dirty_bitmap(hdev, &hdev->mem_sections[i],
                                 0, (hwaddr)~0x0ull);
     }
-    r = vdev->binding->set_guest_notifiers(vdev->binding_opaque, false);
+    r = k->set_guest_notifiers(qbus->parent, false);
     if (r < 0) {
         fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
         fflush(stderr);
diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
index c5e67b0..ff93997 100644
--- a/hw/virtio-bus.c
+++ b/hw/virtio-bus.c
@@ -48,23 +48,6 @@ int virtio_bus_plug_device(VirtIODevice *vdev)
 
     bus->vdev = vdev;
 
-    /*
-     * The lines below will disappear when we drop VirtIOBindings, at the end
-     * of the series.
-     */
-    bus->bindings.notify = klass->notify;
-    bus->bindings.save_config = klass->save_config;
-    bus->bindings.save_queue = klass->save_queue;
-    bus->bindings.load_config = klass->load_config;
-    bus->bindings.load_queue = klass->load_queue;
-    bus->bindings.load_done = klass->load_done;
-    bus->bindings.get_features = klass->get_features;
-    bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
-    bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
-    bus->bindings.set_host_notifier = klass->set_host_notifier;
-    bus->bindings.vmstate_change = klass->vmstate_change;
-    virtio_bind_device(bus->vdev, &bus->bindings, qbus->parent);
-
     if (klass->device_plugged != NULL) {
         klass->device_plugged(qbus->parent);
     }
diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
index 7bea64a..9a43728 100644
--- a/hw/virtio-bus.h
+++ b/hw/virtio-bus.h
@@ -70,10 +70,6 @@ struct VirtioBusState {
      * Only one VirtIODevice can be plugged on the bus.
      */
     VirtIODevice *vdev;
-    /*
-     * This will be removed at the end of the series.
-     */
-    VirtIOBindings bindings;
 };
 
 int virtio_bus_plug_device(VirtIODevice *vdev);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 4588073..581ab76 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -712,19 +712,6 @@ static void virtio_pci_vmstate_change(DeviceState *d, bool running)
     }
 }
 
-static const VirtIOBindings virtio_pci_bindings = {
-    .notify = virtio_pci_notify,
-    .save_config = virtio_pci_save_config,
-    .load_config = virtio_pci_load_config,
-    .save_queue = virtio_pci_save_queue,
-    .load_queue = virtio_pci_load_queue,
-    .get_features = virtio_pci_get_features,
-    .query_guest_notifiers = virtio_pci_query_guest_notifiers,
-    .set_host_notifier = virtio_pci_set_host_notifier,
-    .set_guest_notifiers = virtio_pci_set_guest_notifiers,
-    .vmstate_change = virtio_pci_vmstate_change,
-};
-
 /*
  * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
  */
diff --git a/hw/virtio.c b/hw/virtio.c
index d72b84a..a852adf 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -505,8 +505,12 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
 /* virtio device */
 static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector)
 {
-    if (vdev->binding->notify) {
-        vdev->binding->notify(vdev->binding_opaque, vector);
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+
+    if (k->notify) {
+        k->notify(qbus->parent, vector);
     }
 }
 
@@ -776,10 +780,14 @@ void virtio_notify_config(VirtIODevice *vdev)
 
 void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
     int i;
 
-    if (vdev->binding->save_config)
-        vdev->binding->save_config(vdev->binding_opaque, f);
+    if (k->save_config) {
+        k->save_config(qbus->parent, f);
+    }
 
     qemu_put_8s(f, &vdev->status);
     qemu_put_8s(f, &vdev->isr);
@@ -802,16 +810,19 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
         qemu_put_be32(f, vdev->vq[i].vring.num);
         qemu_put_be64(f, vdev->vq[i].pa);
         qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
-        if (vdev->binding->save_queue)
-            vdev->binding->save_queue(vdev->binding_opaque, i, f);
+        if (k->save_queue) {
+            k->save_queue(qbus->parent, i, f);
+        }
     }
 }
 
 int virtio_set_features(VirtIODevice *vdev, uint32_t val)
 {
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *vbusk = VIRTIO_BUS_GET_CLASS(vbus);
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
-    uint32_t supported_features =
-        vdev->binding->get_features(vdev->binding_opaque);
+    uint32_t supported_features = vbusk->get_features(qbus->parent);
     bool bad = (val & ~supported_features) != 0;
 
     val &= supported_features;
@@ -827,9 +838,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
     int num, i, ret;
     uint32_t features;
     uint32_t supported_features;
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
 
-    if (vdev->binding->load_config) {
-        ret = vdev->binding->load_config(vdev->binding_opaque, f);
+    if (k->load_config) {
+        ret = k->load_config(qbus->parent, f);
         if (ret)
             return ret;
     }
@@ -840,7 +854,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
     qemu_get_be32s(f, &features);
 
     if (virtio_set_features(vdev, features) < 0) {
-        supported_features = vdev->binding->get_features(vdev->binding_opaque);
+        supported_features = k->get_features(qbus->parent);
         error_report("Features 0x%x unsupported. Allowed features: 0x%x",
                      features, supported_features);
         return -1;
@@ -876,8 +890,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
                          i, vdev->vq[i].last_avail_idx);
                 return -1;
 	}
-        if (vdev->binding->load_queue) {
-            ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);
+        if (k->load_queue) {
+            ret = k->load_queue(qbus->parent, i, f);
             if (ret)
                 return ret;
         }
@@ -903,6 +917,9 @@ void virtio_cleanup(VirtIODevice *vdev)
 static void virtio_vmstate_change(void *opaque, int running, RunState state)
 {
     VirtIODevice *vdev = opaque;
+    BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+    VirtioBusState *vbus = VIRTIO_BUS(qbus);
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
     bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK);
     vdev->vm_running = running;
 
@@ -910,8 +927,8 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
         virtio_set_status(vdev, vdev->status);
     }
 
-    if (vdev->binding->vmstate_change) {
-        vdev->binding->vmstate_change(vdev->binding_opaque, backend_run);
+    if (k->vmstate_change) {
+        k->vmstate_change(qbus->parent, backend_run);
     }
 
     if (!backend_run) {
@@ -955,13 +972,6 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
     return vdev;
 }
 
-void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
-                        DeviceState *opaque)
-{
-    vdev->binding = binding;
-    vdev->binding_opaque = opaque;
-}
-
 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
 {
     return vdev->vq[n].vring.desc;
diff --git a/hw/virtio.h b/hw/virtio.h
index fbbf8e8..3199676 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -90,20 +90,6 @@ typedef struct VirtQueueElement
     struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
 } VirtQueueElement;
 
-typedef struct {
-    void (*notify)(DeviceState *d, uint16_t vector);
-    void (*save_config)(DeviceState *d, QEMUFile *f);
-    void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
-    int (*load_config)(DeviceState *d, QEMUFile *f);
-    int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
-    int (*load_done)(DeviceState *d, QEMUFile *f);
-    unsigned (*get_features)(DeviceState *d);
-    bool (*query_guest_notifiers)(DeviceState *d);
-    int (*set_guest_notifiers)(DeviceState *d, bool assigned);
-    int (*set_host_notifier)(DeviceState *d, int n, bool assigned);
-    void (*vmstate_change)(DeviceState *d, bool running);
-} VirtIOBindings;
-
 #define VIRTIO_PCI_QUEUE_MAX 64
 
 #define VIRTIO_NO_VECTOR 0xffff
@@ -129,8 +115,6 @@ struct VirtIODevice
     uint16_t config_vector;
     int nvectors;
     VirtQueue *vq;
-    const VirtIOBindings *binding;
-    DeviceState *binding_opaque;
     uint16_t device_id;
     bool vm_running;
     VMChangeStateEntry *vmstate;
@@ -209,9 +193,6 @@ void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 int virtio_set_features(VirtIODevice *vdev, uint32_t val);
 
-void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
-                        DeviceState *opaque);
-
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
 VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* [Qemu-devel] [PATCH 61/61] virtio : cleanup : init and exit function.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (59 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 60/61] virtio : remove virtiobindings fred.konrad
@ 2013-01-07 18:41 ` fred.konrad
  2013-01-07 19:11 ` [Qemu-devel] [PATCH 00/61] Virtio refactoring Anthony Liguori
                   ` (2 subsequent siblings)
  63 siblings, 0 replies; 89+ messages in thread
From: fred.konrad @ 2013-01-07 18:41 UTC (permalink / raw)
  To: qemu-devel, aliguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

From: KONRAD Frederic <fred.konrad@greensocs.com>

Clean the init and the exit function. It should be applied when all the device
have been refactored.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio.c | 15 ---------------
 hw/virtio.h |  4 ----
 2 files changed, 19 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index a852adf..7214aa0 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -908,12 +908,6 @@ void virtio_common_cleanup(VirtIODevice *vdev)
     g_free(vdev->vq);
 }
 
-void virtio_cleanup(VirtIODevice *vdev)
-{
-    virtio_common_cleanup(vdev);
-    g_free(vdev);
-}
-
 static void virtio_vmstate_change(void *opaque, int running, RunState state)
 {
     VirtIODevice *vdev = opaque;
@@ -963,15 +957,6 @@ void virtio_init(VirtIODevice *vdev, const char *name,
                                                      vdev);
 }
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
-                                 size_t config_size, size_t struct_size)
-{
-    VirtIODevice *vdev;
-    vdev = g_malloc0(struct_size);
-    virtio_init(vdev, name, device_id, config_size);
-    return vdev;
-}
-
 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
 {
     return vdev->vq[n].vring.desc;
diff --git a/hw/virtio.h b/hw/virtio.h
index 3199676..c37f8f1 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -162,8 +162,6 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f);
 
 int virtio_load(VirtIODevice *vdev, QEMUFile *f);
 
-void virtio_cleanup(VirtIODevice *vdev);
-
 void virtio_notify_config(VirtIODevice *vdev);
 
 void virtio_queue_set_notification(VirtQueue *vq, int enable);
@@ -174,8 +172,6 @@ int virtio_queue_empty(VirtQueue *vq);
 
 /* Host binding interface.  */
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
-                                 size_t config_size, size_t struct_size);
 uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr);
 uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr);
 uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (60 preceding siblings ...)
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 61/61] virtio : cleanup : init and exit function fred.konrad
@ 2013-01-07 19:11 ` Anthony Liguori
  2013-01-08 13:40   ` KONRAD Frédéric
  2013-01-08 15:54   ` Peter Maydell
  2013-01-07 20:04 ` Michael S. Tsirkin
  2013-01-08 14:21 ` Peter Maydell
  63 siblings, 2 replies; 89+ messages in thread
From: Anthony Liguori @ 2013-01-07 19:11 UTC (permalink / raw)
  To: fred.konrad, qemu-devel
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

fred.konrad@greensocs.com writes:

> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Here is the full series for virtio-refactoring.
>
> You can clone that from here :
> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring
>
> virtio-mmio parts is not included but you can clone them from here :
> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_mmio
>
> I think that the old VirtioBindings can be fixed later as nothing use interface
> now and I didn't find any example in the code.
>
> Also I didn't try all the devices.

I appreciate the thoroughness here but 66 patches is too much all at
once.  Can this be done in chunks or more reasonable patch sizes?  It
would make review and committing a lot easier.

Regards,

Anthony Liguori

>
> Thanks,
>
> Fred
>
> Changes between v9:
>     * Refactored all the remaining devices with the same way as virtio-blk.
>     * Moved the virtio device's structure in the header.
>     * Fixed the init with only one allocation.
>     * Fixed the indentation and code style errors.
>     * s390 device's are refactored the same way as pci one.
>     * Moved max_dev from BusState to BusClass.
>
> Changes v8 -> v9:
>     * Modified virtio-bus.c function name. (virtio_device_ prefix.)
>     * Removed qdev_create(..) in virtio-blk-x, object_new
>       + object_property_add_child used instead.
>
> Changes v7 -> v8:
>     * Moved virtio-blk-pci PCI IDs to "Add the virtio-blk device.".
>     * virtio : Added virtio_device_init which init children and plug the device.
>     * virtio : Added virtio_common_cleanup in the same way as
>       virtio_common_init.
>     * virtio-blk : Moved virtio_plug_device to virtio-device init.
>     * virtio-blk : Inline the virtio_blk_exit function in
>       virtio_blk_device_exit and use virtio_common_cleanup.
>     * virtio-s390-bus : Added virtio-s390-bus.
>     * virtio-s390-device : Added a virtio-s390-bus.
>     * virtio-blk-s390 : Switched to the new API.
>     * virtio : removed function pointer.
>     * virtio : removed VirtinBindings.
>     * virtio : cleaned up init and exit function.
>
> Changes v6 -> v7:
>     * virtio-bus : Added virtio-bus-reset.
>     * virtio-pci : Fixed virtio-pci-exit.
>     * virtio-pci : Added virtio-pci-rst.
>     * virtio-pci : Added VirtioPCIClass filled with an init function.
>     * virtio-blk : Added virtio_blk_set_conf.
>     * virtio-blk : QOM casts.
>     * virtio-blk-pci : Switched to the new API.
>
> Changes v5 -> v6:
>     * Renamed virtio_common_init_ to virtio_init, modify virtio_common_init to
>       allocate and call virtio_init. Drop the unused structure size parameters.
>     * Renamed init/exit callback in VirtioBusClass.
>     * Renamed virtio_blk_init virtio_blk_common_init.
>     * Modified virtio_blk_init to call virtio_blk_common_init.
>
> Changes v4 -> v5:
>     * use ERROR_CLASS_GENERIC_ERROR in place of creating a new error type for
>       the maximum device limitation. ( Peter )
>     * Removed bus_in_use function. We assume that the virtio-bus is not in use,
>       when plugin in. ( Peter )
>     * Added virtio_bus_destroy_device().
>     * Implemented the exit function of virtio-pci.
>     * Implemented the init callback for virtio-pci ( must be modified, it still
>       access vdev directly. ).
>     * Implemented the exit callback for virtio-pci.
>     * Started virtio-device refactoring.
>     * Started virtio-blk refactoring. 
>
> Changes v3 -> v4:
>     * Added virtio-bus.o in Makefile.objs ( accidentally dropped from v3 ).
>     * *const* TypeInfo in virtio-bus.
>     * Introduced virtio-pci-bus.
>     * Reintroduced virtio-pci.
>     * Introduced virtio-device.
>     * Started virtio-blk refactoring.
>     * Added an error type in qerror.h for the "bus full" error.
>
> Changes v2 -> v3:
>     * Added VirtioBusClass.
>     * Renamed VirtioBus -> VirtioBusState.
>     * Renamed qbus -> parent_obj.
>     * Plug the device only in a non-full bus.
>
> Changes v1 -> v2:
>     * All the little fix you suggest ( License, Debug printf, naming convention,
>       ...)
>     * Added get_virtio_device_id(), and remove the pci_id* from the VirtioBus
>       structure.
>     * Added virtio_bus_reset().
>     * Added cast macros VIRTIO_BUS.
>     * Added virtio_bus_plug_device.
>     * Replaced the old-style "bus->qbus" by BUS() macro.
>
> KONRAD Frederic (61):
>   qdev : add a maximum device allowed field for the bus.
>   virtio-bus : introduce virtio-bus
>   virtio-pci-bus : introduce virtio-pci-bus.
>   virtio-pci : refactor virtio-pci device.
>   virtio-device : refactor virtio-device.
>   virtio-s390-bus : add virtio-s390-bus.
>   virtio-s390-device : create a virtio-s390-bus during init.
>   virtio-blk : show VirtIOBlock structure.
>   virtio-blk : don't use pointer for configuration.
>   virtio-blk : add the virtio-blk device.
>   virtio-blk-pci : switch to new API.
>   virtio-blk-s390 : switch to the new API.
>   virtio-blk : cleanup : use QOM cast.
>   virtio-blk : cleanup : remove qdev field.
>   virtio-net : show the VirtIONet structure.
>   virtio-net : add the virtio-net device.
>   virtio-net-pci : switch to the new API.
>   virtio-net-s390 : switch to the new API.
>   virtio-net : cleanup : use QOM cast.
>   virtio-net : cleanup : init and exit function.
>   virtio-net : cleanup : remove qdev field.
>   virtio-scsi : show the VirtIOSCSI structure.
>   virtio-scsi : don't use pointer for configuration.
>   virtio-scsi : allocate cmd_vqs array separately.
>   virtio-scsi : moving host_features from properties to transport
>     properties.
>   virtio-scsi : add the virtio-scsi device.
>   virtio-scsi-pci : switch to new API.
>   virtio-scsi-s390 : switch to the new API.
>   virtio-scsi : cleanup : use QOM casts.
>   virtio-scsi : cleanup : init and exit functions.
>   virtio-scsi : cleanup : remove qdev field.
>   virtio-balloon : show the VirtIOBalloon structure.
>   virtio-balloon : add the virtio-balloon device.
>   virtio-balloon-pci : switch to the new API.
>   virtio-balloon : cleanup : init and exit function.
>   virtio-balloon : cleanup : QOM casts.
>   virtio-balloon : cleanup : remove qdev field.
>   virtio-rng : show the VirtIORNG structure.
>   virtio-rng : don't use pointer for configuration.
>   virtio-rng : add virtio-rng device.
>   virtio-rng-s390 : switch to the new API.
>   virtio-rng-pci : switch to the new API.
>   virtio-rng.c : cleanup : init and exit functions.
>   virtio-rng.c : cleanup : remove qdev field.
>   virtio-rng.c : cleanup : use QOM casts.
>   virtio-serial : show structures.
>   virtio-serial : add the virtio-serial device.
>   virtio-serial-pci : switch to the new API.
>   virtio-serial-s390 : switch to the new API.
>   virtio-serial : cleanup : init and exit functions.
>   virtio-serial : cleanup : use QOM casts.
>   virtio-serial : cleanup : remove qdev field.
>   virtio-9p : add the virtio-9p device.
>   virtio-9p-pci : switch to the new API.
>   virtio-9p : cleanup : init function.
>   virtio-9p : cleanup : QOM casts.
>   virtio : remove the function pointer.
>   virtio-pci : cleanup : init, exit and reset functions.
>   s390-virtio-bus : cleanup
>   virtio : remove virtiobindings.
>   virtio : cleanup : init and exit function.
>
>  hw/9pfs/virtio-9p-device.c | 144 ++++++----
>  hw/9pfs/virtio-9p.c        |   2 +-
>  hw/9pfs/virtio-9p.h        |  27 +-
>  hw/Makefile.objs           |   1 +
>  hw/qdev-core.h             |   2 +
>  hw/qdev-monitor.c          |  12 +
>  hw/s390-virtio-bus.c       | 221 +++++++++------
>  hw/s390-virtio-bus.h       |  78 ++++-
>  hw/vhost.c                 |  38 ++-
>  hw/virtio-balloon.c        | 111 ++++----
>  hw/virtio-balloon.h        |  14 +
>  hw/virtio-blk.c            | 148 +++++-----
>  hw/virtio-blk.h            |  42 +++
>  hw/virtio-bus.c            | 161 +++++++++++
>  hw/virtio-bus.h            |  94 +++++++
>  hw/virtio-net.c            | 270 +++++++++---------
>  hw/virtio-net.h            |  58 ++++
>  hw/virtio-pci.c            | 689 +++++++++++++++++++++++++--------------------
>  hw/virtio-pci.h            | 131 ++++++++-
>  hw/virtio-rng.c            | 143 ++++++----
>  hw/virtio-rng.h            |  33 +++
>  hw/virtio-scsi.c           | 139 +++++----
>  hw/virtio-scsi.h           |  31 +-
>  hw/virtio-serial-bus.c     | 199 +++++++------
>  hw/virtio-serial.h         |  50 ++++
>  hw/virtio.c                | 156 ++++++----
>  hw/virtio.h                |  52 ++--
>  27 files changed, 2018 insertions(+), 1028 deletions(-)
>  create mode 100644 hw/virtio-bus.c
>  create mode 100644 hw/virtio-bus.h
>
> -- 
> 1.7.11.7

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (61 preceding siblings ...)
  2013-01-07 19:11 ` [Qemu-devel] [PATCH 00/61] Virtio refactoring Anthony Liguori
@ 2013-01-07 20:04 ` Michael S. Tsirkin
  2013-01-07 20:15   ` Anthony Liguori
  2013-01-08 14:21 ` Peter Maydell
  63 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2013-01-07 20:04 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, peter.maydell, aliguori, e.voevodin, mark.burton,
	qemu-devel, agraf, amit.shah, aneesh.kumar, stefanha,
	cornelia.huck, pbonzini, afaerber

On Mon, Jan 07, 2013 at 07:40:13PM +0100, fred.konrad@greensocs.com wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
> 
> Here is the full series for virtio-refactoring.
> 
> You can clone that from here :
> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring
> 
> virtio-mmio parts is not included but you can clone them from here :
> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_mmio
> 
> I think that the old VirtioBindings can be fixed later as nothing use interface
> now and I didn't find any example in the code.
> 
> Also I didn't try all the devices.
> 
> Thanks,
> 
> Fred

I'd like to see this question from the previous revision answered:
Why make sane bindings like pci carry the maintainance overhead of the
artificial bus?
why don't you create your own bus for mmio and put your devices there?
Allocate resources when you init a device.


> -- 
> 1.7.11.7

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-07 20:04 ` Michael S. Tsirkin
@ 2013-01-07 20:15   ` Anthony Liguori
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony Liguori @ 2013-01-07 20:15 UTC (permalink / raw)
  To: Michael S. Tsirkin, fred.konrad
  Cc: kwolf, peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber

"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Mon, Jan 07, 2013 at 07:40:13PM +0100, fred.konrad@greensocs.com wrote:
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>> 
>> Here is the full series for virtio-refactoring.
>> 
>> You can clone that from here :
>> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring
>> 
>> virtio-mmio parts is not included but you can clone them from here :
>> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_mmio
>> 
>> I think that the old VirtioBindings can be fixed later as nothing use interface
>> now and I didn't find any example in the code.
>> 
>> Also I didn't try all the devices.
>> 
>> Thanks,
>> 
>> Fred
>
> I'd like to see this question from the previous revision answered:
> Why make sane bindings like pci carry the maintainance overhead of the
> artificial bus?

This question is silly.

There is absolutely nothing sane about virtio-pci.  This series properly
models virtio.

Regards,

Anthony Liguori

> why don't you create your own bus for mmio and put your devices there?
> Allocate resources when you init a device.
>
>
>> -- 
>> 1.7.11.7

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast fred.konrad
@ 2013-01-07 21:16   ` Michael S. Tsirkin
  2013-01-07 21:17     ` Anthony Liguori
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2013-01-07 21:16 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, peter.maydell, aliguori, e.voevodin, mark.burton,
	qemu-devel, agraf, amit.shah, aneesh.kumar, stefanha,
	cornelia.huck, pbonzini, afaerber

On Mon, Jan 07, 2013 at 07:40:32PM +0100, fred.konrad@greensocs.com wrote:
> @@ -130,7 +124,9 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
>  
>  static void virtio_net_set_link_status(NetClientState *nc)
>  {
> -    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
> +    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
> +    VirtIONet *n = VIRTIO_NET(opaque);
> +    VirtIODevice *vdev = VIRTIO_DEVICE(n);
>      uint16_t old_status = n->status;
>  
>      if (nc->link_down)

I note this adds more pointer chasing due to runtime casts on data path
operations.  Can well be trivial but this really needs to be verified
with a performance test. Was this done? Same comment applies to block.
An alternative is to add _fast casts without runtime checks.

-- 
MST

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.
  2013-01-07 21:16   ` Michael S. Tsirkin
@ 2013-01-07 21:17     ` Anthony Liguori
  2013-01-07 21:33       ` Michael S. Tsirkin
  0 siblings, 1 reply; 89+ messages in thread
From: Anthony Liguori @ 2013-01-07 21:17 UTC (permalink / raw)
  To: Michael S. Tsirkin, fred.konrad
  Cc: kwolf, peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber

"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Mon, Jan 07, 2013 at 07:40:32PM +0100, fred.konrad@greensocs.com wrote:
>> @@ -130,7 +124,9 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
>>  
>>  static void virtio_net_set_link_status(NetClientState *nc)
>>  {
>> -    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
>> +    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
>> +    VirtIONet *n = VIRTIO_NET(opaque);
>> +    VirtIODevice *vdev = VIRTIO_DEVICE(n);
>>      uint16_t old_status = n->status;
>>  
>>      if (nc->link_down)
>
> I note this adds more pointer chasing due to runtime casts on data path
> operations.  Can well be trivial but this really needs to be verified
> with a performance test. Was this done? Same comment applies to block.
> An alternative is to add _fast casts without runtime checks.

I'm pretty sure other things like the one big global mutex are more
important than the number of pointer dereferences...

Do you have any evidence to suggest that this would be a problem in practice?

Regards,

Anthony Liguori

>
> -- 
> MST

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.
  2013-01-07 21:17     ` Anthony Liguori
@ 2013-01-07 21:33       ` Michael S. Tsirkin
  2013-01-07 21:53         ` Anthony Liguori
  0 siblings, 1 reply; 89+ messages in thread
From: Michael S. Tsirkin @ 2013-01-07 21:33 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: kwolf, peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber, fred.konrad

On Mon, Jan 07, 2013 at 03:17:18PM -0600, Anthony Liguori wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> 
> > On Mon, Jan 07, 2013 at 07:40:32PM +0100, fred.konrad@greensocs.com wrote:
> >> @@ -130,7 +124,9 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
> >>  
> >>  static void virtio_net_set_link_status(NetClientState *nc)
> >>  {
> >> -    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
> >> +    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
> >> +    VirtIONet *n = VIRTIO_NET(opaque);
> >> +    VirtIODevice *vdev = VIRTIO_DEVICE(n);
> >>      uint16_t old_status = n->status;
> >>  
> >>      if (nc->link_down)
> >
> > I note this adds more pointer chasing due to runtime casts on data path
> > operations.  Can well be trivial but this really needs to be verified
> > with a performance test. Was this done? Same comment applies to block.
> > An alternative is to add _fast casts without runtime checks.
> 
> I'm pretty sure other things like the one big global mutex are more
> important than the number of pointer dereferences...

True. But we have plans to fix that, right?

> Do you have any evidence to suggest that this would be a problem in practice?
> 
> Regards,
> 
> Anthony Liguori

No. It's not this change specifically, I'm generally concerned if we let
ourselves bloat datapath in an uncontrolled way, the waste will add up
over time.

> >
> > -- 
> > MST

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.
  2013-01-07 21:33       ` Michael S. Tsirkin
@ 2013-01-07 21:53         ` Anthony Liguori
  0 siblings, 0 replies; 89+ messages in thread
From: Anthony Liguori @ 2013-01-07 21:53 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: kwolf, peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber, fred.konrad

"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Mon, Jan 07, 2013 at 03:17:18PM -0600, Anthony Liguori wrote:
>> "Michael S. Tsirkin" <mst@redhat.com> writes:
>> 
>> > On Mon, Jan 07, 2013 at 07:40:32PM +0100, fred.konrad@greensocs.com wrote:
>> >> @@ -130,7 +124,9 @@ static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
>> >>  
>> >>  static void virtio_net_set_link_status(NetClientState *nc)
>> >>  {
>> >> -    VirtIONet *n = DO_UPCAST(NICState, nc, nc)->opaque;
>> >> +    void *opaque = DO_UPCAST(NICState, nc, nc)->opaque;
>> >> +    VirtIONet *n = VIRTIO_NET(opaque);
>> >> +    VirtIODevice *vdev = VIRTIO_DEVICE(n);
>> >>      uint16_t old_status = n->status;
>> >>  
>> >>      if (nc->link_down)
>> >
>> > I note this adds more pointer chasing due to runtime casts on data path
>> > operations.  Can well be trivial but this really needs to be verified
>> > with a performance test. Was this done? Same comment applies to block.
>> > An alternative is to add _fast casts without runtime checks.
>> 
>> I'm pretty sure other things like the one big global mutex are more
>> important than the number of pointer dereferences...
>
> True. But we have plans to fix that, right?
>
>> Do you have any evidence to suggest that this would be a problem in practice?
>> 
>> Regards,
>> 
>> Anthony Liguori
>
> No. It's not this change specifically, I'm generally concerned if we let
> ourselves bloat datapath in an uncontrolled way, the waste will add up
> over time.

I don't think a pointer indirection can be called "bloat[ing] datapath
in an uncontrolled way".

We shouldn't focus on minor things like this, but rather on things like
notification mitigation and lock contention which we know has a direct
impact on performance.

Regards,

Anthony Liguori

>
>> >
>> > -- 
>> > MST

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-07 19:11 ` [Qemu-devel] [PATCH 00/61] Virtio refactoring Anthony Liguori
@ 2013-01-08 13:40   ` KONRAD Frédéric
  2013-01-08 15:54   ` Peter Maydell
  1 sibling, 0 replies; 89+ messages in thread
From: KONRAD Frédéric @ 2013-01-08 13:40 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: kwolf, peter.maydell, e.voevodin, mst, mark.burton, qemu-devel,
	agraf, amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 07/01/2013 20:11, Anthony Liguori wrote:
> fred.konrad@greensocs.com writes:
>
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Here is the full series for virtio-refactoring.
>>
>> You can clone that from here :
>> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring
>>
>> virtio-mmio parts is not included but you can clone them from here :
>> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_mmio
>>
>> I think that the old VirtioBindings can be fixed later as nothing use interface
>> now and I didn't find any example in the code.
>>
>> Also I didn't try all the devices.
> I appreciate the thoroughness here but 66 patches is too much all at
> once.  Can this be done in chunks or more reasonable patch sizes?  It
> would make review and committing a lot easier.
I made little step to make review easier.

I can cut the series between each devices.
Or do you prefer fusionning some step ?

Fred

> Regards,
>
> Anthony Liguori
>
>> Thanks,
>>
>> Fred
>>
>> Changes between v9:
>>      * Refactored all the remaining devices with the same way as virtio-blk.
>>      * Moved the virtio device's structure in the header.
>>      * Fixed the init with only one allocation.
>>      * Fixed the indentation and code style errors.
>>      * s390 device's are refactored the same way as pci one.
>>      * Moved max_dev from BusState to BusClass.
>>
>> Changes v8 -> v9:
>>      * Modified virtio-bus.c function name. (virtio_device_ prefix.)
>>      * Removed qdev_create(..) in virtio-blk-x, object_new
>>        + object_property_add_child used instead.
>>
>> Changes v7 -> v8:
>>      * Moved virtio-blk-pci PCI IDs to "Add the virtio-blk device.".
>>      * virtio : Added virtio_device_init which init children and plug the device.
>>      * virtio : Added virtio_common_cleanup in the same way as
>>        virtio_common_init.
>>      * virtio-blk : Moved virtio_plug_device to virtio-device init.
>>      * virtio-blk : Inline the virtio_blk_exit function in
>>        virtio_blk_device_exit and use virtio_common_cleanup.
>>      * virtio-s390-bus : Added virtio-s390-bus.
>>      * virtio-s390-device : Added a virtio-s390-bus.
>>      * virtio-blk-s390 : Switched to the new API.
>>      * virtio : removed function pointer.
>>      * virtio : removed VirtinBindings.
>>      * virtio : cleaned up init and exit function.
>>
>> Changes v6 -> v7:
>>      * virtio-bus : Added virtio-bus-reset.
>>      * virtio-pci : Fixed virtio-pci-exit.
>>      * virtio-pci : Added virtio-pci-rst.
>>      * virtio-pci : Added VirtioPCIClass filled with an init function.
>>      * virtio-blk : Added virtio_blk_set_conf.
>>      * virtio-blk : QOM casts.
>>      * virtio-blk-pci : Switched to the new API.
>>
>> Changes v5 -> v6:
>>      * Renamed virtio_common_init_ to virtio_init, modify virtio_common_init to
>>        allocate and call virtio_init. Drop the unused structure size parameters.
>>      * Renamed init/exit callback in VirtioBusClass.
>>      * Renamed virtio_blk_init virtio_blk_common_init.
>>      * Modified virtio_blk_init to call virtio_blk_common_init.
>>
>> Changes v4 -> v5:
>>      * use ERROR_CLASS_GENERIC_ERROR in place of creating a new error type for
>>        the maximum device limitation. ( Peter )
>>      * Removed bus_in_use function. We assume that the virtio-bus is not in use,
>>        when plugin in. ( Peter )
>>      * Added virtio_bus_destroy_device().
>>      * Implemented the exit function of virtio-pci.
>>      * Implemented the init callback for virtio-pci ( must be modified, it still
>>        access vdev directly. ).
>>      * Implemented the exit callback for virtio-pci.
>>      * Started virtio-device refactoring.
>>      * Started virtio-blk refactoring.
>>
>> Changes v3 -> v4:
>>      * Added virtio-bus.o in Makefile.objs ( accidentally dropped from v3 ).
>>      * *const* TypeInfo in virtio-bus.
>>      * Introduced virtio-pci-bus.
>>      * Reintroduced virtio-pci.
>>      * Introduced virtio-device.
>>      * Started virtio-blk refactoring.
>>      * Added an error type in qerror.h for the "bus full" error.
>>
>> Changes v2 -> v3:
>>      * Added VirtioBusClass.
>>      * Renamed VirtioBus -> VirtioBusState.
>>      * Renamed qbus -> parent_obj.
>>      * Plug the device only in a non-full bus.
>>
>> Changes v1 -> v2:
>>      * All the little fix you suggest ( License, Debug printf, naming convention,
>>        ...)
>>      * Added get_virtio_device_id(), and remove the pci_id* from the VirtioBus
>>        structure.
>>      * Added virtio_bus_reset().
>>      * Added cast macros VIRTIO_BUS.
>>      * Added virtio_bus_plug_device.
>>      * Replaced the old-style "bus->qbus" by BUS() macro.
>>
>> KONRAD Frederic (61):
>>    qdev : add a maximum device allowed field for the bus.
>>    virtio-bus : introduce virtio-bus
>>    virtio-pci-bus : introduce virtio-pci-bus.
>>    virtio-pci : refactor virtio-pci device.
>>    virtio-device : refactor virtio-device.
>>    virtio-s390-bus : add virtio-s390-bus.
>>    virtio-s390-device : create a virtio-s390-bus during init.
>>    virtio-blk : show VirtIOBlock structure.
>>    virtio-blk : don't use pointer for configuration.
>>    virtio-blk : add the virtio-blk device.
>>    virtio-blk-pci : switch to new API.
>>    virtio-blk-s390 : switch to the new API.
>>    virtio-blk : cleanup : use QOM cast.
>>    virtio-blk : cleanup : remove qdev field.
>>    virtio-net : show the VirtIONet structure.
>>    virtio-net : add the virtio-net device.
>>    virtio-net-pci : switch to the new API.
>>    virtio-net-s390 : switch to the new API.
>>    virtio-net : cleanup : use QOM cast.
>>    virtio-net : cleanup : init and exit function.
>>    virtio-net : cleanup : remove qdev field.
>>    virtio-scsi : show the VirtIOSCSI structure.
>>    virtio-scsi : don't use pointer for configuration.
>>    virtio-scsi : allocate cmd_vqs array separately.
>>    virtio-scsi : moving host_features from properties to transport
>>      properties.
>>    virtio-scsi : add the virtio-scsi device.
>>    virtio-scsi-pci : switch to new API.
>>    virtio-scsi-s390 : switch to the new API.
>>    virtio-scsi : cleanup : use QOM casts.
>>    virtio-scsi : cleanup : init and exit functions.
>>    virtio-scsi : cleanup : remove qdev field.
>>    virtio-balloon : show the VirtIOBalloon structure.
>>    virtio-balloon : add the virtio-balloon device.
>>    virtio-balloon-pci : switch to the new API.
>>    virtio-balloon : cleanup : init and exit function.
>>    virtio-balloon : cleanup : QOM casts.
>>    virtio-balloon : cleanup : remove qdev field.
>>    virtio-rng : show the VirtIORNG structure.
>>    virtio-rng : don't use pointer for configuration.
>>    virtio-rng : add virtio-rng device.
>>    virtio-rng-s390 : switch to the new API.
>>    virtio-rng-pci : switch to the new API.
>>    virtio-rng.c : cleanup : init and exit functions.
>>    virtio-rng.c : cleanup : remove qdev field.
>>    virtio-rng.c : cleanup : use QOM casts.
>>    virtio-serial : show structures.
>>    virtio-serial : add the virtio-serial device.
>>    virtio-serial-pci : switch to the new API.
>>    virtio-serial-s390 : switch to the new API.
>>    virtio-serial : cleanup : init and exit functions.
>>    virtio-serial : cleanup : use QOM casts.
>>    virtio-serial : cleanup : remove qdev field.
>>    virtio-9p : add the virtio-9p device.
>>    virtio-9p-pci : switch to the new API.
>>    virtio-9p : cleanup : init function.
>>    virtio-9p : cleanup : QOM casts.
>>    virtio : remove the function pointer.
>>    virtio-pci : cleanup : init, exit and reset functions.
>>    s390-virtio-bus : cleanup
>>    virtio : remove virtiobindings.
>>    virtio : cleanup : init and exit function.
>>
>>   hw/9pfs/virtio-9p-device.c | 144 ++++++----
>>   hw/9pfs/virtio-9p.c        |   2 +-
>>   hw/9pfs/virtio-9p.h        |  27 +-
>>   hw/Makefile.objs           |   1 +
>>   hw/qdev-core.h             |   2 +
>>   hw/qdev-monitor.c          |  12 +
>>   hw/s390-virtio-bus.c       | 221 +++++++++------
>>   hw/s390-virtio-bus.h       |  78 ++++-
>>   hw/vhost.c                 |  38 ++-
>>   hw/virtio-balloon.c        | 111 ++++----
>>   hw/virtio-balloon.h        |  14 +
>>   hw/virtio-blk.c            | 148 +++++-----
>>   hw/virtio-blk.h            |  42 +++
>>   hw/virtio-bus.c            | 161 +++++++++++
>>   hw/virtio-bus.h            |  94 +++++++
>>   hw/virtio-net.c            | 270 +++++++++---------
>>   hw/virtio-net.h            |  58 ++++
>>   hw/virtio-pci.c            | 689 +++++++++++++++++++++++++--------------------
>>   hw/virtio-pci.h            | 131 ++++++++-
>>   hw/virtio-rng.c            | 143 ++++++----
>>   hw/virtio-rng.h            |  33 +++
>>   hw/virtio-scsi.c           | 139 +++++----
>>   hw/virtio-scsi.h           |  31 +-
>>   hw/virtio-serial-bus.c     | 199 +++++++------
>>   hw/virtio-serial.h         |  50 ++++
>>   hw/virtio.c                | 156 ++++++----
>>   hw/virtio.h                |  52 ++--
>>   27 files changed, 2018 insertions(+), 1028 deletions(-)
>>   create mode 100644 hw/virtio-bus.c
>>   create mode 100644 hw/virtio-bus.h
>>
>> -- 
>> 1.7.11.7

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
                   ` (62 preceding siblings ...)
  2013-01-07 20:04 ` Michael S. Tsirkin
@ 2013-01-08 14:21 ` Peter Maydell
  2013-01-08 14:33   ` KONRAD Frédéric
  63 siblings, 1 reply; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 14:21 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Here is the full series for virtio-refactoring.
>
> You can clone that from here :
> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring

This doesn't work as either an HTTP url or a git url. You mean
 git://git.greensocs.com/qemu_virtio.git virtio_refactoring

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-08 14:21 ` Peter Maydell
@ 2013-01-08 14:33   ` KONRAD Frédéric
  0 siblings, 0 replies; 89+ messages in thread
From: KONRAD Frédéric @ 2013-01-08 14:33 UTC (permalink / raw)
  To: Peter Maydell
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber

On 08/01/2013 15:21, Peter Maydell wrote:
> On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Here is the full series for virtio-refactoring.
>>
>> You can clone that from here :
>> git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring
> This doesn't work as either an HTTP url or a git url. You mean
>   git://git.greensocs.com/qemu_virtio.git virtio_refactoring
>
> -- PMM
>
oops, sorry for that.

You're right :

git://git.greensocs.com/qemu_virtio.git virtio_refactoring

is the good address.

Fred

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-07 19:11 ` [Qemu-devel] [PATCH 00/61] Virtio refactoring Anthony Liguori
  2013-01-08 13:40   ` KONRAD Frédéric
@ 2013-01-08 15:54   ` Peter Maydell
  2013-01-08 16:22     ` Anthony Liguori
  1 sibling, 1 reply; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 15:54 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: kwolf, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber, fred.konrad

On 7 January 2013 19:11, Anthony Liguori <aliguori@us.ibm.com> wrote:
> I appreciate the thoroughness here but 66 patches is too much all at
> once.  Can this be done in chunks or more reasonable patch sizes?  It
> would make review and committing a lot easier.

So do you have any suggestions? The patchset is long but it
is actually in a fairly easily separable set of sections:

I: Initial class definitions and transport level refactoring:

>>   qdev : add a maximum device allowed field for the bus.
>>   virtio-bus : introduce virtio-bus
>>   virtio-pci-bus : introduce virtio-pci-bus.
>>   virtio-pci : refactor virtio-pci device.
>>   virtio-device : refactor virtio-device.
>>   virtio-s390-bus : add virtio-s390-bus.
>>   virtio-s390-device : create a virtio-s390-bus during init.

II: Update virtio-blk:

>>   virtio-blk : show VirtIOBlock structure.
>>   virtio-blk : don't use pointer for configuration.
>>   virtio-blk : add the virtio-blk device.
>>   virtio-blk-pci : switch to new API.
>>   virtio-blk-s390 : switch to the new API.
>>   virtio-blk : cleanup : use QOM cast.
>>   virtio-blk : cleanup : remove qdev field.

III: Update virtio-net:

>>   virtio-net : show the VirtIONet structure.
>>   virtio-net : add the virtio-net device.
>>   virtio-net-pci : switch to the new API.
>>   virtio-net-s390 : switch to the new API.
>>   virtio-net : cleanup : use QOM cast.
>>   virtio-net : cleanup : init and exit function.
>>   virtio-net : cleanup : remove qdev field.

[etc; all the backends are handled in basically the same way]

N: Final cleanup now all backends are converted:

>>   virtio : remove the function pointer.
>>   virtio-pci : cleanup : init, exit and reset functions.
>>   s390-virtio-bus : cleanup
>>   virtio : remove virtiobindings.
>>   virtio : cleanup : init and exit function.

where I guess the interesting bits to review in particular
would be phases I and N and a randomly selected backend.

Perhaps you could squash some of the patches together,
for instance the "virtio-foo: show the VirtIOFoo structure"
(which is just moving a struct from a private .c file to the .h)
could go in with the following "virtio-net : add the virtio-foo
device." patch, which would reduce the patch count by
seven or so -- is that worth doing? (obviously it's the same
amount of actual code just in fewer patches...)

thanks
-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure.
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure fred.konrad
@ 2013-01-08 16:18   ` Peter Maydell
  0 siblings, 0 replies; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 16:18 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
> virtio-blk : show VirtIOBlock structure.

If this survives as a separate patch then this should read
"virtio-blk: make VirtIOBlock structure public"

> As we discuss with anthony and andreas, this structure must be showed to avoid
> two memory allocations for virtio-blk-x.

I don't really like chatty references to mailing list discussions in
commit messages; commit messages should just confidently
say what/why they're making the change. You can always put
in remarks below the '---' line if you want to remind reviewers of
earlier discussion. Similarly, you don't need to say "must be
committed after patches X and Y" in the commit message proper --
as a git commit the order is inherent.

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-08 15:54   ` Peter Maydell
@ 2013-01-08 16:22     ` Anthony Liguori
  2013-01-08 16:25       ` Peter Maydell
  0 siblings, 1 reply; 89+ messages in thread
From: Anthony Liguori @ 2013-01-08 16:22 UTC (permalink / raw)
  To: Peter Maydell
  Cc: kwolf, e.voevodin, mst, mark.burton, agraf, qemu-devel, amit.shah,
	aneesh.kumar, stefanha, cornelia.huck, pbonzini, afaerber,
	fred.konrad

Peter Maydell <peter.maydell@linaro.org> writes:

> On 7 January 2013 19:11, Anthony Liguori <aliguori@us.ibm.com> wrote:
>> I appreciate the thoroughness here but 66 patches is too much all at
>> once.  Can this be done in chunks or more reasonable patch sizes?  It
>> would make review and committing a lot easier.
>
> So do you have any suggestions? The patchset is long but it
> is actually in a fairly easily separable set of sections:
>

Sounds like you have already identified how to break things up...

> I: Initial class definitions and transport level refactoring:
>
>>>   qdev : add a maximum device allowed field for the bus.
>>>   virtio-bus : introduce virtio-bus
>>>   virtio-pci-bus : introduce virtio-pci-bus.
>>>   virtio-pci : refactor virtio-pci device.
>>>   virtio-device : refactor virtio-device.
>>>   virtio-s390-bus : add virtio-s390-bus.
>>>   virtio-s390-device : create a virtio-s390-bus during init.

I would start with the above.

>
> II: Update virtio-blk:
>
>>>   virtio-blk : show VirtIOBlock structure.
>>>   virtio-blk : don't use pointer for configuration.
>>>   virtio-blk : add the virtio-blk device.
>>>   virtio-blk-pci : switch to new API.
>>>   virtio-blk-s390 : switch to the new API.
>>>   virtio-blk : cleanup : use QOM cast.
>>>   virtio-blk : cleanup : remove qdev field.
>
> III: Update virtio-net:
>
>>>   virtio-net : show the VirtIONet structure.
>>>   virtio-net : add the virtio-net device.
>>>   virtio-net-pci : switch to the new API.
>>>   virtio-net-s390 : switch to the new API.
>>>   virtio-net : cleanup : use QOM cast.
>>>   virtio-net : cleanup : init and exit function.
>>>   virtio-net : cleanup : remove qdev field.
>
> [etc; all the backends are handled in basically the same way]

I would do all of the devices at once.

>
> N: Final cleanup now all backends are converted:
>
>>>   virtio : remove the function pointer.
>>>   virtio-pci : cleanup : init, exit and reset functions.
>>>   s390-virtio-bus : cleanup
>>>   virtio : remove virtiobindings.
>>>   virtio : cleanup : init and exit function.

I would do this independently.

Regards,

Anthony Liguori


>
> where I guess the interesting bits to review in particular
> would be phases I and N and a randomly selected backend.
>
> Perhaps you could squash some of the patches together,
> for instance the "virtio-foo: show the VirtIOFoo structure"
> (which is just moving a struct from a private .c file to the .h)
> could go in with the following "virtio-net : add the virtio-foo
> device." patch, which would reduce the patch count by
> seven or so -- is that worth doing? (obviously it's the same
> amount of actual code just in fewer patches...)
>
> thanks
> -- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring.
  2013-01-08 16:22     ` Anthony Liguori
@ 2013-01-08 16:25       ` Peter Maydell
  0 siblings, 0 replies; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 16:25 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: kwolf, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber, fred.konrad

On 8 January 2013 16:22, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> On 7 January 2013 19:11, Anthony Liguori <aliguori@us.ibm.com> wrote:
>>> I appreciate the thoroughness here but 66 patches is too much all at
>>> once.  Can this be done in chunks or more reasonable patch sizes?  It
>>> would make review and committing a lot easier.
>>
>> So do you have any suggestions? The patchset is long but it
>> is actually in a fairly easily separable set of sections:
>>
>
> Sounds like you have already identified how to break things up...

Well, yes, but I'm not sure it makes sense to split it into
literally three different patch series, since it all looks a bit
odd until you get to the end and get to see it with all the
unnecessary old code removed...

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus.
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus fred.konrad
@ 2013-01-08 17:05   ` Peter Maydell
  0 siblings, 0 replies; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 17:05 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Add a max_dev field to BusClass to specify the maximum amount of devices allowed
> on the bus ( have no effect if max_dev=0 )

"has" (also no spacing needed after '(' or before ')'.)

>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

(reminder: if you don't change a patch you should put people's
r-b: tags in when you send out future versions so they know they
don't need to look at patches again)

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 02/61] virtio-bus : introduce virtio-bus
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 02/61] virtio-bus : introduce virtio-bus fred.konrad
@ 2013-01-08 17:09   ` Peter Maydell
  0 siblings, 0 replies; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 17:09 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Introduce virtio-bus. Refactored transport device will create a bus which
> extends virtio-bus.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device fred.konrad
@ 2013-01-08 17:54   ` Peter Maydell
  2013-01-09  8:45     ` KONRAD Frédéric
  0 siblings, 1 reply; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 17:54 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Create the virtio-pci device. This transport device will create a
> virtio-pci-bus, so one VirtIODevice can be connected.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
>  hw/virtio-pci.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  hw/virtio-pci.h |  18 ++++++++
>  2 files changed, 145 insertions(+)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 5ff03e8..1f0ecbe 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -1163,6 +1163,130 @@ static TypeInfo virtio_scsi_info = {
>      .class_init    = virtio_scsi_class_init,
>  };
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.

"has"

> + */
> +
> +/* This is called by virtio-bus just after the device is plugged. */
> +static void virtio_pci_device_plugged(DeviceState *d)
> +{
> +    VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
> +    VirtioBusState *bus = proxy->bus;
> +    uint8_t *config;
> +    uint32_t size;
> +
> +    /* Put the PCI IDs */
> +    switch (virtio_device_get_id(proxy->bus)) {
> +
> +
> +    default:
> +        error_report("unknown device id\n");
> +        break;
> +
> +    }

This doesn't have any code in it yet (it gets added in later patches) but
the final result looks very repetitive. I think you'd be better off just having
some arrays:

uint16_t virtio_pci_device_id[] = {
     [VIRTIO_ID_BLOCK] = PCI_DEVICE_ID_VIRTIO_BLOCK,
     [VIRTIO_ID_NET] = PCI_DEVICE_ID_VIRTIO_NET,
(etc)
};

similarly for the class. Then you can just drop the switch statement.

In fact I think you might as well put in the array entries for all
the virtio devices in this patch rather than adding one in each of the
"add virtio-foo device" patches; it will do no harm for them to be
there early and it makes the later patches a little smaller.


> +
> +    proxy->vdev = proxy->bus->vdev;
> +
> +    config = proxy->pci_dev.config;
> +    if (proxy->class_code) {
> +        pci_config_set_class(config, proxy->class_code);
> +    }
> +    pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
> +                 pci_get_word(config + PCI_VENDOR_ID));
> +    pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_device_get_id(proxy->bus));
> +    config[PCI_INTERRUPT_PIN] = 1;

> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -45,6 +45,22 @@ typedef struct {
>      unsigned int users;
>  } VirtIOIRQFD;
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.

"has"

> + */

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.
  2013-01-07 18:40 ` [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus fred.konrad
@ 2013-01-08 18:08   ` Peter Maydell
  2013-01-09  8:37     ` KONRAD Frédéric
  0 siblings, 1 reply; 89+ messages in thread
From: Peter Maydell @ 2013-01-08 18:08 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci
> transport device.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>

This isn't quite right, I think (somebody correct me if I'm wrong!)
The virtio-pci-bus subclass doesn't have any state of its own, so it
doesn't need a struct, but it does still want a type, so virtio-pci.h should
have a
   typedef VirtioBusClass VirtioPCIBusClass;
   typedef VirtioBusState VirtioPCIBusState;
and we then use VirtioPCIBusClass/State where appropriate
(notably in the typeinfo for class/instance size and in the get-class/
class-check/etc macros).

This lets us easily add state later if we need to by turning the
typedef into a typedef'd struct without having to hunt down all
the places that now need to say 'VirtioPCIBus*' rather than
'VirtioBus*'.

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.
  2013-01-08 18:08   ` Peter Maydell
@ 2013-01-09  8:37     ` KONRAD Frédéric
  2013-01-09  9:14       ` KONRAD Frédéric
  0 siblings, 1 reply; 89+ messages in thread
From: KONRAD Frédéric @ 2013-01-09  8:37 UTC (permalink / raw)
  To: Peter Maydell
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber

On 08/01/2013 19:08, Peter Maydell wrote:
> On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci
>> transport device.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> This isn't quite right, I think (somebody correct me if I'm wrong!)
> The virtio-pci-bus subclass doesn't have any state of its own, so it
> doesn't need a struct, but it does still want a type, so virtio-pci.h should
> have a
>     typedef VirtioBusClass VirtioPCIBusClass;
>     typedef VirtioBusState VirtioPCIBusState;
> and we then use VirtioPCIBusClass/State where appropriate
> (notably in the typeinfo for class/instance size and in the get-class/
> class-check/etc macros).
>
> This lets us easily add state later if we need to by turning the
> typedef into a typedef'd struct without having to hunt down all
> the places that now need to say 'VirtioPCIBus*' rather than
> 'VirtioBus*'.
>
> -- PMM
>
Ok, I'll make the change.

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.
  2013-01-08 17:54   ` Peter Maydell
@ 2013-01-09  8:45     ` KONRAD Frédéric
  2013-01-09 14:33       ` Peter Maydell
  0 siblings, 1 reply; 89+ messages in thread
From: KONRAD Frédéric @ 2013-01-09  8:45 UTC (permalink / raw)
  To: Peter Maydell
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber

On 08/01/2013 18:54, Peter Maydell wrote:
> On 7 January 2013 18:40,  <fred.konrad@greensocs.com> wrote:
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Create the virtio-pci device. This transport device will create a
>> virtio-pci-bus, so one VirtIODevice can be connected.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>>   hw/virtio-pci.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   hw/virtio-pci.h |  18 ++++++++
>>   2 files changed, 145 insertions(+)
>>
>> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
>> index 5ff03e8..1f0ecbe 100644
>> --- a/hw/virtio-pci.c
>> +++ b/hw/virtio-pci.c
>> @@ -1163,6 +1163,130 @@ static TypeInfo virtio_scsi_info = {
>>       .class_init    = virtio_scsi_class_init,
>>   };
>>
>> +/*
>> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
> "has"
>
>> + */
>> +
>> +/* This is called by virtio-bus just after the device is plugged. */
>> +static void virtio_pci_device_plugged(DeviceState *d)
>> +{
>> +    VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
>> +    VirtioBusState *bus = proxy->bus;
>> +    uint8_t *config;
>> +    uint32_t size;
>> +
>> +    /* Put the PCI IDs */
>> +    switch (virtio_device_get_id(proxy->bus)) {
>> +
>> +
>> +    default:
>> +        error_report("unknown device id\n");
>> +        break;
>> +
>> +    }
> This doesn't have any code in it yet (it gets added in later patches) but
> the final result looks very repetitive. I think you'd be better off just having
> some arrays:
>
> uint16_t virtio_pci_device_id[] = {
>       [VIRTIO_ID_BLOCK] = PCI_DEVICE_ID_VIRTIO_BLOCK,
>       [VIRTIO_ID_NET] = PCI_DEVICE_ID_VIRTIO_NET,
> (etc)
> };
>
> similarly for the class. Then you can just drop the switch statement.
>
> In fact I think you might as well put in the array entries for all
> the virtio devices in this patch rather than adding one in each of the
> "add virtio-foo device" patches; it will do no harm for them to be
> there early and it makes the later patches a little smaller.
And what happen when it is a bad ID ?

Fred

>
>> +
>> +    proxy->vdev = proxy->bus->vdev;
>> +
>> +    config = proxy->pci_dev.config;
>> +    if (proxy->class_code) {
>> +        pci_config_set_class(config, proxy->class_code);
>> +    }
>> +    pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
>> +                 pci_get_word(config + PCI_VENDOR_ID));
>> +    pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_device_get_id(proxy->bus));
>> +    config[PCI_INTERRUPT_PIN] = 1;
>> --- a/hw/virtio-pci.h
>> +++ b/hw/virtio-pci.h
>> @@ -45,6 +45,22 @@ typedef struct {
>>       unsigned int users;
>>   } VirtIOIRQFD;
>>
>> +/*
>> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
> "has"
>
>> + */
> -- PMM
>

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.
  2013-01-09  8:37     ` KONRAD Frédéric
@ 2013-01-09  9:14       ` KONRAD Frédéric
  2013-01-09 14:53         ` Peter Maydell
  0 siblings, 1 reply; 89+ messages in thread
From: KONRAD Frédéric @ 2013-01-09  9:14 UTC (permalink / raw)
  To: Peter Maydell
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 09/01/2013 09:37, KONRAD Frédéric wrote:
> On 08/01/2013 19:08, Peter Maydell wrote:
>> On 7 January 2013 18:40, <fred.konrad@greensocs.com> wrote:
>>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>>
>>> Introduce virtio-pci-bus, which extends virtio-bus. It is used with 
>>> virtio-pci
>>> transport device.
>>>
>>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> This isn't quite right, I think (somebody correct me if I'm wrong!)
>> The virtio-pci-bus subclass doesn't have any state of its own, so it
>> doesn't need a struct, but it does still want a type, so virtio-pci.h 
>> should
>> have a
>>     typedef VirtioBusClass VirtioPCIBusClass;
>>     typedef VirtioBusState VirtioPCIBusState;
>> and we then use VirtioPCIBusClass/State where appropriate
>> (notably in the typeinfo for class/instance size and in the get-class/
>> class-check/etc macros).
>>
>> This lets us easily add state later if we need to by turning the
>> typedef into a typedef'd struct without having to hunt down all
>> the places that now need to say 'VirtioPCIBus*' rather than
>> 'VirtioBus*'.
>>
>> -- PMM
>>
> Ok, I'll make the change.
>
>
Though, I'm not really sure we will add something here..
The virtio-pci-bus is only added to implement VirtioBusClass functions.
There are no differences between pci, s390, or mmio.

unless it is mandatory to have another name in the QOM macros ?

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.
  2013-01-09  8:45     ` KONRAD Frédéric
@ 2013-01-09 14:33       ` Peter Maydell
  0 siblings, 0 replies; 89+ messages in thread
From: Peter Maydell @ 2013-01-09 14:33 UTC (permalink / raw)
  To: KONRAD Frédéric
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	cornelia.huck, aneesh.kumar, stefanha, amit.shah, pbonzini,
	afaerber

On 9 January 2013 08:45, KONRAD Frédéric <fred.konrad@greensocs.com> wrote:
> On 08/01/2013 18:54, Peter Maydell wrote:
>> This doesn't have any code in it yet (it gets added in later patches) but
>> the final result looks very repetitive. I think you'd be better off just
>> having
>> some arrays:
>>
>> uint16_t virtio_pci_device_id[] = {
>>       [VIRTIO_ID_BLOCK] = PCI_DEVICE_ID_VIRTIO_BLOCK,
>>       [VIRTIO_ID_NET] = PCI_DEVICE_ID_VIRTIO_NET,
>> (etc)
>> };
>>
>> similarly for the class. Then you can just drop the switch statement.
>>
>> In fact I think you might as well put in the array entries for all
>> the virtio devices in this patch rather than adding one in each of the
>> "add virtio-foo device" patches; it will do no harm for them to be
>> there early and it makes the later patches a little smaller.
>
> And what happen when it is a bad ID ?

Error, same as before. Obviously you protect the array lookup
with a sizeof check for out of range, and you know if the array
entry is 0 it's invalid (0 being neither a valid device id or class).

If you think that looks too ugly then you could keep the switch, but
don't put calls to pci_config_set_device_id() and pci_config_set_class()
in each switch, that's just code duplication.

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.
  2013-01-09  9:14       ` KONRAD Frédéric
@ 2013-01-09 14:53         ` Peter Maydell
  2013-01-09 14:55           ` KONRAD Frédéric
  0 siblings, 1 reply; 89+ messages in thread
From: Peter Maydell @ 2013-01-09 14:53 UTC (permalink / raw)
  To: KONRAD Frédéric
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 9 January 2013 09:14, KONRAD Frédéric <fred.konrad@greensocs.com> wrote:
> On 09/01/2013 09:37, KONRAD Frédéric wrote:
>> On 08/01/2013 19:08, Peter Maydell wrote:
>>> This isn't quite right, I think (somebody correct me if I'm wrong!)
>>> The virtio-pci-bus subclass doesn't have any state of its own, so it
>>> doesn't need a struct, but it does still want a type, so virtio-pci.h
>>> should
>>> have a
>>>     typedef VirtioBusClass VirtioPCIBusClass;
>>>     typedef VirtioBusState VirtioPCIBusState;
>>> and we then use VirtioPCIBusClass/State where appropriate
>>> (notably in the typeinfo for class/instance size and in the get-class/
>>> class-check/etc macros).
>>>
>>> This lets us easily add state later if we need to by turning the
>>> typedef into a typedef'd struct without having to hunt down all
>>> the places that now need to say 'VirtioPCIBus*' rather than
>>> 'VirtioBus*'.

>> Ok, I'll make the change.

> Though, I'm not really sure we will add something here..
> The virtio-pci-bus is only added to implement VirtioBusClass functions.
> There are no differences between pci, s390, or mmio.

It's just consistency, and as I say it avoids surprises later. We're
basically inventing our own object system in C here, which means
that there's no guard preventing you from doing something in a
way which is inconsistent with our object system but still valid
and functioning C; but it's better style not to do that.

-- PMM

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.
  2013-01-09 14:53         ` Peter Maydell
@ 2013-01-09 14:55           ` KONRAD Frédéric
  0 siblings, 0 replies; 89+ messages in thread
From: KONRAD Frédéric @ 2013-01-09 14:55 UTC (permalink / raw)
  To: Peter Maydell
  Cc: kwolf, aliguori, e.voevodin, mst, mark.burton, qemu-devel, agraf,
	amit.shah, aneesh.kumar, stefanha, cornelia.huck, pbonzini,
	afaerber

On 09/01/2013 15:53, Peter Maydell wrote:
> On 9 January 2013 09:14, KONRAD Frédéric <fred.konrad@greensocs.com> wrote:
>> On 09/01/2013 09:37, KONRAD Frédéric wrote:
>>> On 08/01/2013 19:08, Peter Maydell wrote:
>>>> This isn't quite right, I think (somebody correct me if I'm wrong!)
>>>> The virtio-pci-bus subclass doesn't have any state of its own, so it
>>>> doesn't need a struct, but it does still want a type, so virtio-pci.h
>>>> should
>>>> have a
>>>>      typedef VirtioBusClass VirtioPCIBusClass;
>>>>      typedef VirtioBusState VirtioPCIBusState;
>>>> and we then use VirtioPCIBusClass/State where appropriate
>>>> (notably in the typeinfo for class/instance size and in the get-class/
>>>> class-check/etc macros).
>>>>
>>>> This lets us easily add state later if we need to by turning the
>>>> typedef into a typedef'd struct without having to hunt down all
>>>> the places that now need to say 'VirtioPCIBus*' rather than
>>>> 'VirtioBus*'.
>>> Ok, I'll make the change.
>> Though, I'm not really sure we will add something here..
>> The virtio-pci-bus is only added to implement VirtioBusClass functions.
>> There are no differences between pci, s390, or mmio.
> It's just consistency, and as I say it avoids surprises later. We're
> basically inventing our own object system in C here, which means
> that there's no guard preventing you from doing something in a
> way which is inconsistent with our object system but still valid
> and functioning C; but it's better style not to do that.
>
> -- PMM
ok then, I'll change it. And for s390 too.

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer.
  2013-01-07 18:41 ` [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer fred.konrad
@ 2013-01-09 20:40   ` Blue Swirl
  2013-01-09 21:44     ` KONRAD Frédéric
  0 siblings, 1 reply; 89+ messages in thread
From: Blue Swirl @ 2013-01-09 20:40 UTC (permalink / raw)
  To: fred.konrad
  Cc: kwolf, peter.maydell, aliguori, e.voevodin, mst, mark.burton,
	qemu-devel, agraf, cornelia.huck, aneesh.kumar, stefanha,
	amit.shah, pbonzini, afaerber

On Mon, Jan 7, 2013 at 6:41 PM,  <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> This remove the function pointer in VirtIODevice, and use only
> VirtioDeviceClass function pointer. It should be applied after all
> the device have been refactored.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
>  hw/9pfs/virtio-9p-device.c |  2 --
>  hw/virtio-balloon.c        |  8 --------
>  hw/virtio-blk.c            |  5 -----
>  hw/virtio-net.c            |  7 -------
>  hw/virtio-pci.c            |  2 +-
>  hw/virtio-rng.c            |  6 ------
>  hw/virtio-scsi.c           |  6 ------
>  hw/virtio-serial-bus.c     |  6 ------
>  hw/virtio.c                | 41 ++++++++++++++++++++++++++---------------
>  hw/virtio.h                | 11 -----------
>  10 files changed, 27 insertions(+), 67 deletions(-)
>
> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> index a99ff5a..17be320 100644
> --- a/hw/9pfs/virtio-9p-device.c
> +++ b/hw/9pfs/virtio-9p-device.c
> @@ -102,9 +102,7 @@ static int virtio_9p_device_init(VirtIODevice *vdev)
>      s->ctx.uid = -1;
>
>      s->ops = fse->ops;
> -    vdev->get_features = virtio_9p_get_features;
>      s->config_size = sizeof(struct virtio_9p_config) + len;
> -    vdev->get_config = virtio_9p_get_config;
>      s->fid_list = NULL;
>      qemu_co_rwlock_init(&s->rename_lock);
>
> diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
> index e2cb2fc..40d3c15 100644
> --- a/hw/virtio-balloon.c
> +++ b/hw/virtio-balloon.c
> @@ -227,14 +227,6 @@ static int virtio_balloon_device_init(VirtIODevice *vdev)
>
>      virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, 8);
>
> -    /*
> -     * This will disappear later in the serie.
> -     * We will use VirtioDeviceClass instead.
> -     */
> -    vdev->get_config = virtio_balloon_get_config;
> -    vdev->set_config = virtio_balloon_set_config;
> -    vdev->get_features = virtio_balloon_get_features;
> -
>      ret = qemu_add_balloon_handler(virtio_balloon_to_target,
>                                     virtio_balloon_stat, s);
>
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index 74ba97b..14e4543 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -651,11 +651,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
>      virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
>                  sizeof(struct virtio_blk_config));
>
> -    vdev->get_config = virtio_blk_update_config;
> -    vdev->set_config = virtio_blk_set_config;
> -    vdev->get_features = virtio_blk_get_features;
> -    vdev->set_status = virtio_blk_set_status;
> -    vdev->reset = virtio_blk_reset;
>      s->bs = blk->conf.bs;
>      s->conf = &blk->conf;
>      memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
> diff --git a/hw/virtio-net.c b/hw/virtio-net.c
> index 7f87166..3ae0d79 100644
> --- a/hw/virtio-net.c
> +++ b/hw/virtio-net.c
> @@ -999,13 +999,6 @@ static int virtio_net_device_init(VirtIODevice *vdev)
>      virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
>                                    sizeof(struct virtio_net_config));
>
> -    vdev->get_config = virtio_net_get_config;
> -    vdev->set_config = virtio_net_set_config;
> -    vdev->get_features = virtio_net_get_features;
> -    vdev->set_features = virtio_net_set_features;
> -    vdev->bad_features = virtio_net_bad_features;
> -    vdev->reset = virtio_net_reset;
> -    vdev->set_status = virtio_net_set_status;
>      n->rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
>
>      if (n->net_conf.tx && strcmp(n->net_conf.tx, "timer") &&
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 0e45b1a..c47b9b1 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -276,7 +276,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
>      case VIRTIO_PCI_GUEST_FEATURES:
>         /* Guest does not negotiate properly?  We have to assume nothing. */
>         if (val & (1 << VIRTIO_F_BAD_FEATURE)) {
> -            val = vdev->bad_features ? vdev->bad_features(vdev) : 0;
> +            val = virtio_device_get_bad_features(proxy->bus);
>         }
>          virtio_set_features(vdev, val);
>          break;
> diff --git a/hw/virtio-rng.c b/hw/virtio-rng.c
> index 67407a7..57e0dae 100644
> --- a/hw/virtio-rng.c
> +++ b/hw/virtio-rng.c
> @@ -173,12 +173,6 @@ static int virtio_rng_device_init(VirtIODevice *vdev)
>      }
>
>      vrng->vq = virtio_add_queue(vdev, 8, handle_input);
> -    /*
> -     * This will disappear later in the serie.
> -     * We will use VirtioDeviceClass instead.
> -     */
> -    vdev->get_features = get_features;
> -    /**/
>
>      assert(vrng->conf.max_bytes <= INT64_MAX);
>      vrng->quota_remaining = vrng->conf.max_bytes;
> diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
> index 273ca69..0e43230 100644
> --- a/hw/virtio-scsi.c
> +++ b/hw/virtio-scsi.c
> @@ -705,12 +705,6 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
>
>      s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
>
> -    /* TODO set up vdev function pointers */
> -    vdev->get_config = virtio_scsi_get_config;
> -    vdev->set_config = virtio_scsi_set_config;
> -    vdev->get_features = virtio_scsi_get_features;
> -    vdev->reset = virtio_scsi_reset;
> -
>      s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
>                                    virtio_scsi_handle_ctrl);
>      s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE,
> diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
> index d1f47a4..ef74c26 100644
> --- a/hw/virtio-serial-bus.c
> +++ b/hw/virtio-serial-bus.c
> @@ -972,12 +972,6 @@ static int virtio_serial_device_init(VirtIODevice *vdev)
>       */
>      mark_port_added(vser, 0);
>
> -    vdev->get_features = get_features;
> -    vdev->get_config = get_config;
> -    vdev->set_config = set_config;
> -    vdev->set_status = set_status;
> -    vdev->reset = vser_reset;
> -
>      vser->post_load = NULL;
>
>      /*
> diff --git a/hw/virtio.c b/hw/virtio.c
> index ca170c3..d72b84a 100644
> --- a/hw/virtio.c
> +++ b/hw/virtio.c
> @@ -517,10 +517,11 @@ void virtio_update_irq(VirtIODevice *vdev)
>
>  void virtio_set_status(VirtIODevice *vdev, uint8_t val)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      trace_virtio_set_status(vdev, val);
>
> -    if (vdev->set_status) {
> -        vdev->set_status(vdev, val);
> +    if (k->set_status) {
> +        k->set_status(vdev, val);
>      }
>      vdev->status = val;
>  }
> @@ -528,12 +529,14 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
>  void virtio_reset(void *opaque)
>  {
>      VirtIODevice *vdev = opaque;
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      int i;
>
>      virtio_set_status(vdev, 0);
>
> -    if (vdev->reset)
> -        vdev->reset(vdev);
> +    if (k->reset) {
> +        k->reset(vdev);
> +    }
>
>      vdev->guest_features = 0;
>      vdev->queue_sel = 0;
> @@ -557,9 +560,10 @@ void virtio_reset(void *opaque)
>
>  uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      uint8_t val;
>
> -    vdev->get_config(vdev, vdev->config);
> +    k->get_config(vdev, vdev->config);
>
>      if (addr > (vdev->config_len - sizeof(val)))
>          return (uint32_t)-1;
> @@ -570,9 +574,10 @@ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
>
>  uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      uint16_t val;
>
> -    vdev->get_config(vdev, vdev->config);
> +    k->get_config(vdev, vdev->config);
>
>      if (addr > (vdev->config_len - sizeof(val)))
>          return (uint32_t)-1;
> @@ -583,9 +588,10 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
>
>  uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      uint32_t val;
>
> -    vdev->get_config(vdev, vdev->config);
> +    k->get_config(vdev, vdev->config);
>
>      if (addr > (vdev->config_len - sizeof(val)))
>          return (uint32_t)-1;
> @@ -596,6 +602,7 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
>
>  void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      uint8_t val = data;
>
>      if (addr > (vdev->config_len - sizeof(val)))
> @@ -603,12 +610,13 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>
>      stb_p(vdev->config + addr, val);
>
> -    if (vdev->set_config)
> -        vdev->set_config(vdev, vdev->config);
> +    if (k->set_config)

Still this one...

> +        k->set_config(vdev, vdev->config);
>  }
>
>  void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      uint16_t val = data;
>
>      if (addr > (vdev->config_len - sizeof(val)))
> @@ -616,12 +624,13 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>
>      stw_p(vdev->config + addr, val);
>
> -    if (vdev->set_config)
> -        vdev->set_config(vdev, vdev->config);
> +    if (k->set_config)

and here the braces are missing.

> +        k->set_config(vdev, vdev->config);
>  }
>
>  void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      uint32_t val = data;
>
>      if (addr > (vdev->config_len - sizeof(val)))
> @@ -629,8 +638,9 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>
>      stl_p(vdev->config + addr, val);
>
> -    if (vdev->set_config)
> -        vdev->set_config(vdev, vdev->config);
> +    if (k->set_config) {
> +        k->set_config(vdev, vdev->config);
> +    }
>  }
>
>  void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
> @@ -799,13 +809,14 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
>
>  int virtio_set_features(VirtIODevice *vdev, uint32_t val)
>  {
> +    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>      uint32_t supported_features =
>          vdev->binding->get_features(vdev->binding_opaque);
>      bool bad = (val & ~supported_features) != 0;
>
>      val &= supported_features;
> -    if (vdev->set_features) {
> -        vdev->set_features(vdev, val);
> +    if (k->set_features) {
> +        k->set_features(vdev, val);
>      }
>      vdev->guest_features = val;
>      return bad ? -1 : 0;
> diff --git a/hw/virtio.h b/hw/virtio.h
> index c134960..fbbf8e8 100644
> --- a/hw/virtio.h
> +++ b/hw/virtio.h
> @@ -128,17 +128,6 @@ struct VirtIODevice
>      void *config;
>      uint16_t config_vector;
>      int nvectors;
> -    /*
> -     * Function pointers will be removed ( at the end of the series )
> -     * as they are in VirtioDeviceClass.
> -     */
> -    uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
> -    uint32_t (*bad_features)(VirtIODevice *vdev);
> -    void (*set_features)(VirtIODevice *vdev, uint32_t val);
> -    void (*get_config)(VirtIODevice *vdev, uint8_t *config);
> -    void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
> -    void (*reset)(VirtIODevice *vdev);
> -    void (*set_status)(VirtIODevice *vdev, uint8_t val);
>      VirtQueue *vq;
>      const VirtIOBindings *binding;
>      DeviceState *binding_opaque;
> --
> 1.7.11.7
>
>

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer.
  2013-01-09 20:40   ` Blue Swirl
@ 2013-01-09 21:44     ` KONRAD Frédéric
  2013-01-12  9:50       ` Blue Swirl
  0 siblings, 1 reply; 89+ messages in thread
From: KONRAD Frédéric @ 2013-01-09 21:44 UTC (permalink / raw)
  To: Blue Swirl
  Cc: kwolf, peter.maydell, aliguori, e.voevodin, mst, mark.burton,
	qemu-devel, agraf, cornelia.huck, aneesh.kumar, stefanha,
	amit.shah, pbonzini, afaerber

On 09/01/2013 21:40, Blue Swirl wrote:
> On Mon, Jan 7, 2013 at 6:41 PM,  <fred.konrad@greensocs.com> wrote:
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> This remove the function pointer in VirtIODevice, and use only
>> VirtioDeviceClass function pointer. It should be applied after all
>> the device have been refactored.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>>   hw/9pfs/virtio-9p-device.c |  2 --
>>   hw/virtio-balloon.c        |  8 --------
>>
>> -        vdev->set_config(vdev, vdev->config);
>> +    if (k->set_config)
> Still this one...
> and here the braces are missing.
>
yes, I fixed these in the newpatch-set (there are in the 3rd part).

Any idea about why checkpatch.pl didn't spot them ?
Do I use it wrong ?

Thanks,
Fred

^ permalink raw reply	[flat|nested] 89+ messages in thread

* Re: [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer.
  2013-01-09 21:44     ` KONRAD Frédéric
@ 2013-01-12  9:50       ` Blue Swirl
  0 siblings, 0 replies; 89+ messages in thread
From: Blue Swirl @ 2013-01-12  9:50 UTC (permalink / raw)
  To: KONRAD Frédéric
  Cc: kwolf, peter.maydell, aliguori, e.voevodin, mst, mark.burton,
	qemu-devel, agraf, cornelia.huck, aneesh.kumar, stefanha,
	amit.shah, pbonzini, afaerber

On Wed, Jan 9, 2013 at 9:44 PM, KONRAD Frédéric
<fred.konrad@greensocs.com> wrote:
> On 09/01/2013 21:40, Blue Swirl wrote:
>>
>> On Mon, Jan 7, 2013 at 6:41 PM,  <fred.konrad@greensocs.com> wrote:
>>>
>>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>>
>>> This remove the function pointer in VirtIODevice, and use only
>>> VirtioDeviceClass function pointer. It should be applied after all
>>> the device have been refactored.
>>>
>>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>>> ---
>>>   hw/9pfs/virtio-9p-device.c |  2 --
>>>   hw/virtio-balloon.c        |  8 --------
>>>
>>> -        vdev->set_config(vdev, vdev->config);
>>> +    if (k->set_config)
>>
>> Still this one...
>>
>> and here the braces are missing.
>>
> yes, I fixed these in the newpatch-set (there are in the 3rd part).
>
> Any idea about why checkpatch.pl didn't spot them ?
> Do I use it wrong ?

Seems to be a bug in the script, I don't get warnings either.

>
> Thanks,
> Fred

^ permalink raw reply	[flat|nested] 89+ messages in thread

end of thread, other threads:[~2013-01-12 11:50 UTC | newest]

Thread overview: 89+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-07 18:40 [Qemu-devel] [PATCH 00/61] Virtio refactoring fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus fred.konrad
2013-01-08 17:05   ` Peter Maydell
2013-01-07 18:40 ` [Qemu-devel] [PATCH 02/61] virtio-bus : introduce virtio-bus fred.konrad
2013-01-08 17:09   ` Peter Maydell
2013-01-07 18:40 ` [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus fred.konrad
2013-01-08 18:08   ` Peter Maydell
2013-01-09  8:37     ` KONRAD Frédéric
2013-01-09  9:14       ` KONRAD Frédéric
2013-01-09 14:53         ` Peter Maydell
2013-01-09 14:55           ` KONRAD Frédéric
2013-01-07 18:40 ` [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device fred.konrad
2013-01-08 17:54   ` Peter Maydell
2013-01-09  8:45     ` KONRAD Frédéric
2013-01-09 14:33       ` Peter Maydell
2013-01-07 18:40 ` [Qemu-devel] [PATCH 05/61] virtio-device : refactor virtio-device fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 06/61] virtio-s390-bus : add virtio-s390-bus fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 07/61] virtio-s390-device : create a virtio-s390-bus during init fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure fred.konrad
2013-01-08 16:18   ` Peter Maydell
2013-01-07 18:40 ` [Qemu-devel] [PATCH 09/61] virtio-blk : don't use pointer for configuration fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 10/61] virtio-blk : add the virtio-blk device fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 11/61] virtio-blk-pci : switch to new API fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 12/61] virtio-blk-s390 : switch to the " fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 13/61] virtio-blk : cleanup : use QOM cast fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 14/61] virtio-blk : cleanup : remove qdev field fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 15/61] virtio-net : show the VirtIONet structure fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 16/61] virtio-net : add the virtio-net device fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 17/61] virtio-net-pci : switch to the new API fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 18/61] virtio-net-s390 " fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast fred.konrad
2013-01-07 21:16   ` Michael S. Tsirkin
2013-01-07 21:17     ` Anthony Liguori
2013-01-07 21:33       ` Michael S. Tsirkin
2013-01-07 21:53         ` Anthony Liguori
2013-01-07 18:40 ` [Qemu-devel] [PATCH 20/61] virtio-net : cleanup : init and exit function fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 21/61] virtio-net : cleanup : remove qdev field fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 22/61] virtio-scsi : show the VirtIOSCSI structure fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 23/61] virtio-scsi : don't use pointer for configuration fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 24/61] virtio-scsi : allocate cmd_vqs array separately fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 25/61] virtio-scsi : moving host_features from properties to transport properties fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 26/61] virtio-scsi : add the virtio-scsi device fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 27/61] virtio-scsi-pci : switch to new API fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 28/61] virtio-scsi-s390 : switch to the " fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 29/61] virtio-scsi : cleanup : use QOM casts fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 30/61] virtio-scsi : cleanup : init and exit functions fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 31/61] virtio-scsi : cleanup : remove qdev field fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 32/61] virtio-balloon : show the VirtIOBalloon structure fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 33/61] virtio-balloon : add the virtio-balloon device fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 34/61] virtio-balloon-pci : switch to the new API fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 35/61] virtio-balloon : cleanup : init and exit function fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 36/61] virtio-balloon : cleanup : QOM casts fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 37/61] virtio-balloon : cleanup : remove qdev field fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 38/61] virtio-rng : show the VirtIORNG structure fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 39/61] virtio-rng : don't use pointer for configuration fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 40/61] virtio-rng : add virtio-rng device fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 41/61] virtio-rng-s390 : switch to the new API fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 42/61] virtio-rng-pci " fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 43/61] virtio-rng.c : cleanup : init and exit functions fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 44/61] virtio-rng.c : cleanup : remove qdev field fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 45/61] virtio-rng.c : cleanup : use QOM casts fred.konrad
2013-01-07 18:40 ` [Qemu-devel] [PATCH 46/61] virtio-serial : show structures fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 47/61] virtio-serial : add the virtio-serial device fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 48/61] virtio-serial-pci : switch to the new API fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 49/61] virtio-serial-s390 " fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 50/61] virtio-serial : cleanup : init and exit functions fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 51/61] virtio-serial : cleanup : use QOM casts fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 52/61] virtio-serial : cleanup : remove qdev field fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 53/61] virtio-9p : add the virtio-9p device fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 54/61] virtio-9p-pci : switch to the new API fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 55/61] virtio-9p : cleanup : init function fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 56/61] virtio-9p : cleanup : QOM casts fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer fred.konrad
2013-01-09 20:40   ` Blue Swirl
2013-01-09 21:44     ` KONRAD Frédéric
2013-01-12  9:50       ` Blue Swirl
2013-01-07 18:41 ` [Qemu-devel] [PATCH 58/61] virtio-pci : cleanup : init, exit and reset functions fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 59/61] s390-virtio-bus : cleanup fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 60/61] virtio : remove virtiobindings fred.konrad
2013-01-07 18:41 ` [Qemu-devel] [PATCH 61/61] virtio : cleanup : init and exit function fred.konrad
2013-01-07 19:11 ` [Qemu-devel] [PATCH 00/61] Virtio refactoring Anthony Liguori
2013-01-08 13:40   ` KONRAD Frédéric
2013-01-08 15:54   ` Peter Maydell
2013-01-08 16:22     ` Anthony Liguori
2013-01-08 16:25       ` Peter Maydell
2013-01-07 20:04 ` Michael S. Tsirkin
2013-01-07 20:15   ` Anthony Liguori
2013-01-08 14:21 ` Peter Maydell
2013-01-08 14:33   ` KONRAD Frédéric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).