Skip to contentSkip to conversation

Virtio refactoring.

PATCH Superseded [email protected] 5 participants 89 messages Jan 7, 2013 – Jan 12, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Virtio refactoring.

From: KONRAD Frederic <[email protected]>

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
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/61 qdev : add a maximum device allowed field for the bus.

From: KONRAD Frederic <[email protected]>

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 )

---
 hw/qdev-core.h    |  2 ++
 hw/qdev-monitor.c | 12 ++++++++++++
 2 files changed, 14 insertions(+)
hw/qdev-core.h +2 -0
index fdf14ec..8bcaeac 100644
@@ -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 {
hw/qdev-monitor.c +12 -0
index b739867..9e9d840 100644
@@ -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;
     }
Signature · 1 line
1.7.11.7
Reviewed-by on v1 1/61
#2 lore raw

Re: [Qemu-devel] [PATCH 01/61] qdev : add a maximum device allowed field for the bus.

Quoted 4 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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 ')'.)

Quoted 2 lines

(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

#3 lore raw

PATCH 2/61 virtio-bus : introduce virtio-bus

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 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
hw/Makefile.objs +1 -0
index b8bbed3..6011a66 100644
@@ -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
hw/virtio-bus.c new file +178 -0

178 lines not on this page · raw message

hw/virtio-bus.h new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#5 lore raw

PATCH 3/61 virtio-pci-bus : introduce virtio-pci-bus.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h | 18 ++++++++++++++++--
 2 files changed, 53 insertions(+), 2 deletions(-)
hw/virtio-pci.c +37 -0
index c7f0c4d..5ff03e8 100644
@@ -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)
hw/virtio-pci.h +16 -2
index b58d9a2..2ac18b3 100644
@@ -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);
Signature · 1 line
1.7.11.7
#6 lore raw

Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.

Quoted 6 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

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

#7 lore raw

Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.

Quoted 17 lines · Peter Maydell
Quoted 6 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

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).

Quoted 7 lines

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.

#8 lore raw

Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.

Quoted 18 lines · KONRAD Frédéric
Quoted 17 lines · Peter Maydell
Quoted 6 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

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).

Quoted 10 lines
Quoted 7 lines

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 ?

#9 lore raw

Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.

Quoted 18 lines · KONRAD Frédéric
Quoted 16 lines · KONRAD Frédéric
Quoted 15 lines · Peter Maydell

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*'.

Quoted 5 lines
Quoted 1 line

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

#10 lore raw

Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus.

Quoted 22 lines · Peter Maydell
Quoted 13 lines · KONRAD Frédéric
Quoted 12 lines · KONRAD Frédéric
Quoted 11 lines · Peter Maydell

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).

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

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.

Quoted 7 lines

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.

#11 lore raw

PATCH 4/61 virtio-pci : refactor virtio-pci device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-pci.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h |  18 ++++++++
 2 files changed, 145 insertions(+)
hw/virtio-pci.c +127 -0
index 5ff03e8..1f0ecbe 100644
@@ -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)
hw/virtio-pci.h +18 -0
index 2ac18b3..05d52cb 100644
@@ -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);
Signature · 1 line
1.7.11.7
#12 lore raw

Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.

Quoted 16 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-pci.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h |  18 ++++++++
 2 files changed, 145 insertions(+)
hw/virtio-pci.c +0 -0
index 5ff03e8..1f0ecbe 100644

hw/virtio-pci.c static TypeInfo virtio_scsi_info = { · line 1167

Quoted 5 lines
hw/virtio-pci.c +2 -0
@@ -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"

Quoted 9 lines
hw/virtio-pci.c +9 -0
+ */
+
+/* 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;

hw/virtio-pci.c static TypeInfo virtio_scsi_info = { · line 1186

Quoted 10 lines
hw/virtio-pci.c +10 -0
+
+    /* 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.

Quoted 15 lines
hw/virtio-pci.c +11 -0
+
+    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;
 

hw/virtio-pci.h typedef struct { · line 49

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

"has"

hw/virtio-pci.h typedef struct { · line 50

Quoted 1 line
hw/virtio-pci.h +1 -0
+ */

-- PMM

#13 lore raw

Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.

Quoted 53 lines · Peter Maydell
Quoted 16 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

---
  hw/virtio-pci.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  hw/virtio-pci.h |  18 ++++++++
  2 files changed, 145 insertions(+)
hw/virtio-pci.c +0 -0
index 5ff03e8..1f0ecbe 100644

hw/virtio-pci.c static TypeInfo virtio_scsi_info = { · line 1167

Quoted 5 lines
hw/virtio-pci.c +2 -0
@@ -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"

Quoted 9 lines
hw/virtio-pci.c +9 -0
+ */
+
+/* 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;

hw/virtio-pci.c static TypeInfo virtio_scsi_info = { · line 1186

Quoted 10 lines
hw/virtio-pci.c +10 -0
+
+    /* 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)
};

Quoted 6 lines

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

Quoted 25 lines
Quoted 15 lines
hw/virtio-pci.c +11 -0
+
+    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;

hw/virtio-pci.h typedef struct { · line 49

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

"has"

hw/virtio-pci.h typedef struct { · line 50

Quoted 1 line
hw/virtio-pci.h +1 -0
+ */

-- PMM

#14 lore raw

Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.

Quoted 12 lines · KONRAD Frédéric
Quoted 11 lines · Peter Maydell

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)
};

Quoted 8 lines
Quoted 6 lines

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

#15 lore raw

PATCH 5/61 virtio-device : refactor virtio-device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
 hw/virtio.h | 30 ++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 12 deletions(-)
hw/virtio.c +58 -12
index 77b53a9..ca170c3 100644
@@ -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)
hw/virtio.h +30 -0
index 1dec9dc..c134960 100644
@@ -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 *));
Signature · 1 line
1.7.11.7
#16 lore raw

PATCH 6/61 virtio-s390-bus : add virtio-s390-bus.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/s390-virtio-bus.c | 29 +++++++++++++++++++++++++++++
 hw/s390-virtio-bus.h | 13 +++++++++++++
 2 files changed, 42 insertions(+)
hw/s390-virtio-bus.c +29 -0
index 7e99175..0fa0a74 100644
@@ -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);
hw/s390-virtio-bus.h +13 -0
index 23fedd5..81af7a0 100644
@@ -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);
Signature · 1 line
1.7.11.7
#17 lore raw

PATCH 7/61 virtio-s390-device : create a virtio-s390-bus during init.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/s390-virtio-bus.c | 2 ++
 hw/s390-virtio-bus.h | 1 +
 2 files changed, 3 insertions(+)
hw/s390-virtio-bus.c +2 -0
index 0fa0a74..946de31 100644
@@ -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);
 }
 
hw/s390-virtio-bus.h +1 -0
index 81af7a0..178e281 100644
@@ -92,6 +92,7 @@ struct VirtIOS390Device {
     virtio_net_conf net;
     VirtIOSCSIConf scsi;
     VirtIORNGConf rng;
+    VirtioBusState *bus;
 };
 
 typedef struct VirtIOS390Bus {
Signature · 1 line
1.7.11.7
#18 lore raw

PATCH 8/61 virtio-blk : show VirtIOBlock structure.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-blk.c | 16 ----------------
 hw/virtio-blk.h | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 16 deletions(-)
hw/virtio-blk.c +0 -16
index df57b35..38a53e9 100644
@@ -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;
hw/virtio-blk.h +15 -0
index 43ca492..2a7aef2 100644
@@ -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)
 
Signature · 1 line
1.7.11.7
#19 lore raw

Re: [Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure.

Quoted 1 line · On 7 January 2013 18:40, <[email protected]> wrote:

virtio-blk : show VirtIOBlock structure.

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

Quoted 2 lines

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

#20 lore raw

PATCH 9/61 virtio-blk : don't use pointer for configuration.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-blk.c | 8 ++++----
 hw/virtio-blk.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
hw/virtio-blk.c +4 -4
index 38a53e9..93a52b5 100644
@@ -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;
 
hw/virtio-blk.h +1 -1
index 2a7aef2..df07419 100644
@@ -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
Signature · 1 line
1.7.11.7
#21 lore raw

PATCH 10/61 virtio-blk : add the virtio-blk device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-blk.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 hw/virtio-blk.h | 28 +++++++++++++++++
 hw/virtio-pci.c | 18 ++++-------
 3 files changed, 126 insertions(+), 17 deletions(-)
hw/virtio-blk.c +92 -5
index 93a52b5..8ed1a96 100644
@@ -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)
hw/virtio-blk.h +28 -0
index df07419..4a65ef6 100644
@@ -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
hw/virtio-pci.c +6 -12
index 1f0ecbe..919d3e7 100644
@@ -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;
Signature · 1 line
1.7.11.7
#22 lore raw

PATCH 11/61 virtio-blk-pci : switch to new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-pci.c | 109 +++++++++++++++++++++++++-------------------------------
 hw/virtio-pci.h |  15 +++++++-
 2 files changed, 62 insertions(+), 62 deletions(-)
hw/virtio-pci.c +48 -61
index 919d3e7..6043ee4 100644
@@ -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)
hw/virtio-pci.h +14 -1
index 05d52cb..9f22f79 100644
@@ -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);
 
Signature · 1 line
1.7.11.7
#23 lore raw

PATCH 12/61 virtio-blk-s390 : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/s390-virtio-bus.c | 30 +++++++++++++++++++-----------
 hw/s390-virtio-bus.h | 13 ++++++++++++-
 2 files changed, 31 insertions(+), 12 deletions(-)
hw/s390-virtio-bus.c +19 -11
index 946de31..d40fb8b 100644
@@ -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,
 };
 
hw/s390-virtio-bus.h +12 -1
index 178e281..f5d0b94 100644
@@ -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
Signature · 1 line
1.7.11.7
#24 lore raw

PATCH 13/61 virtio-blk : cleanup : use QOM cast.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-blk.c | 123 +++++++++++++++++---------------------------------------
 hw/virtio-blk.h |   2 +-
 2 files changed, 39 insertions(+), 86 deletions(-)
hw/virtio-blk.c +38 -85
index 8ed1a96..c19d347 100644
@@ -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;
 }
 
hw/virtio-blk.h +1 -1
index 4a65ef6..2b3c99a 100644
@@ -113,7 +113,7 @@ struct VirtIOBlkConf
 };
 
 typedef struct VirtIOBlock {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
     BlockDriverState *bs;
     VirtQueue *vq;
     void *rq;
Signature · 1 line
1.7.11.7
#25 lore raw

PATCH 14/61 virtio-blk : cleanup : remove qdev field.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-blk.c | 3 +--
 hw/virtio-blk.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)
hw/virtio-blk.c +1 -2
index c19d347..74ba97b 100644
@@ -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;
hw/virtio-blk.h +0 -1
index 2b3c99a..f281ac3 100644
@@ -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
Signature · 1 line
1.7.11.7
#26 lore raw

PATCH 15/61 virtio-net : show the VirtIONet structure.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-net.c | 41 -----------------------------------------
 hw/virtio-net.h | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 41 deletions(-)
hw/virtio-net.c +0 -41
index 5d03b31..4ece6c2 100644
@@ -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.
  */
hw/virtio-net.h +41 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#27 lore raw

PATCH 16/61 virtio-net : add the virtio-net device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 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(-)
hw/virtio-net.c +109 -6
index 4ece6c2..6fe7e58 100644
@@ -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)
hw/virtio-net.h +18 -0
index f6ff85d..2bdc8fd 100644
@@ -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
hw/virtio-pci.c +7 -5
index 6043ee4..8ed6a08 100644
@@ -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;
hw/virtio-pci.h +2 -2
index 9f22f79..e6647e2 100644
@@ -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;
Signature · 1 line
1.7.11.7
#28 lore raw

PATCH 17/61 virtio-net-pci : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-pci.c | 108 +++++++++++++++++++++++++++-----------------------------
 hw/virtio-pci.h |  17 +++++++--
 2 files changed, 67 insertions(+), 58 deletions(-)
hw/virtio-pci.c +52 -56
index 8ed6a08..06bdbe1 100644
@@ -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)
hw/virtio-pci.h +15 -2
index e6647e2..b8cf743 100644
@@ -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);
 
Signature · 1 line
1.7.11.7
#29 lore raw

PATCH 18/61 virtio-net-s390 : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/s390-virtio-bus.c | 32 ++++++++++++++++++++------------
 hw/s390-virtio-bus.h | 15 +++++++++++++--
 2 files changed, 33 insertions(+), 14 deletions(-)
hw/s390-virtio-bus.c +20 -12
index d40fb8b..8a2c8b3 100644
@@ -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,
 };
 
hw/s390-virtio-bus.h +13 -2
index f5d0b94..f67ca51 100644
@@ -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
Signature · 1 line
1.7.11.7
#30 lore raw

PATCH 19/61 virtio-net : cleanup : use QOM cast.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-net.c | 147 ++++++++++++++++++++++++++++++--------------------------
 hw/virtio-net.h |   2 +-
 2 files changed, 80 insertions(+), 69 deletions(-)
hw/virtio-net.c +79 -68
index 6fe7e58..9cf549a 100644
@@ -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)
hw/virtio-net.h +1 -1
index 2bdc8fd..3246a28 100644
@@ -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;
Signature · 1 line
1.7.11.7
#31 lore raw

Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.

hw/virtio-net.c static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) · line 132

Quoted 11 lines · On Mon, Jan 07, 2013 at 07:40:32PM +0100, [email protected] wrote:
hw/virtio-net.c +3 -1
@@ -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.

Signature · 1 line
MST
#32 lore raw

Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.

Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · On Mon, Jan 07, 2013 at 07:40:32PM +0100, [email protected] wrote:
hw/virtio-net.c +3 -1
@@ -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;
 
Quoted 6 lines

hw/virtio-net.c static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) · line 132

Quoted 1 line
hw/virtio-net.c +0 -0
     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

Quoted 3 lines
Signature · 2 lines
-- 
MST
#33 lore raw

Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.

Quoted 20 lines · Anthony Liguori
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · On Mon, Jan 07, 2013 at 07:40:32PM +0100, [email protected] wrote:
hw/virtio-net.c +3 -1
@@ -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;
 
Quoted 6 lines

hw/virtio-net.c static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) · line 132

Quoted 1 line
hw/virtio-net.c +0 -0
     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.

Quoted 2 lines

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?

Quoted 5 lines

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.

Quoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 
MST
#34 lore raw

Re: [Qemu-devel] [PATCH 19/61] virtio-net : cleanup : use QOM cast.

Quoted 28 lines · Michael S. Tsirkin
Quoted 20 lines · Anthony Liguori
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · On Mon, Jan 07, 2013 at 07:40:32PM +0100, [email protected] wrote:
hw/virtio-net.c +3 -1
@@ -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;
 
Quoted 6 lines

hw/virtio-net.c static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status) · line 132

Quoted 1 line
hw/virtio-net.c +0 -0
     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.

Quoted 2 lines

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?

Quoted 2 lines

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

Quoted 7 lines
Quoted 3 lines

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

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Signature · 2 lines
-- 
MST
#35 lore raw

PATCH 20/61 virtio-net : cleanup : init and exit function.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-net.c | 95 ++++++++++++---------------------------------------------
 1 file changed, 20 insertions(+), 75 deletions(-)
hw/virtio-net.c +20 -75
index 9cf549a..263ca46 100644
@@ -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;
 }
 
Signature · 1 line
1.7.11.7
#36 lore raw

PATCH 21/61 virtio-net : cleanup : remove qdev field.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-net.c | 1 -
 hw/virtio-net.h | 1 -
 2 files changed, 2 deletions(-)
hw/virtio-net.c +0 -1
index 263ca46..7f87166 100644
@@ -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);
 
hw/virtio-net.h +0 -1
index 3246a28..a01416b 100644
@@ -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
Signature · 1 line
1.7.11.7
#37 lore raw

PATCH 22/61 virtio-scsi : show the VirtIOSCSI structure.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-scsi.c | 15 ---------------
 hw/virtio-scsi.h | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 15 deletions(-)
hw/virtio-scsi.c +0 -15
index bfe1860..4e2d884 100644
@@ -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;
hw/virtio-scsi.h +16 -0
index 8d9d15f..38b9c0f 100644
@@ -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), \
Signature · 1 line
1.7.11.7
#38 lore raw

PATCH 23/61 virtio-scsi : don't use pointer for configuration.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-scsi.c | 14 +++++++-------
 hw/virtio-scsi.h |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)
hw/virtio-scsi.c +7 -7
index 4e2d884..1bd689c 100644
@@ -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);
     }
hw/virtio-scsi.h +1 -1
index 38b9c0f..6e027be 100644
@@ -35,7 +35,7 @@ struct VirtIOSCSIConf {
 typedef struct {
     VirtIODevice vdev;
     DeviceState *qdev;
-    VirtIOSCSIConf *conf;
+    VirtIOSCSIConf conf;
 
     SCSIBus bus;
     uint32_t sense_size;
Signature · 1 line
1.7.11.7
#39 lore raw

PATCH 24/61 virtio-scsi : allocate cmd_vqs array separately.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-scsi.c | 6 +++---
 hw/virtio-scsi.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/virtio-scsi.c +3 -3
index 1bd689c..7b922ab 100644
@@ -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));
hw/virtio-scsi.h +1 -1
index 6e027be..c659ba1 100644
@@ -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) \
Signature · 1 line
1.7.11.7
#40 lore raw

PATCH 25/61 virtio-scsi : moving host_features from properties to transport properties.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/s390-virtio-bus.c | 7 ++++++-
 hw/virtio-pci.c      | 7 ++++++-
 hw/virtio-scsi.h     | 9 +++------
 3 files changed, 15 insertions(+), 8 deletions(-)
hw/s390-virtio-bus.c +6 -1
index 8a2c8b3..283b7b6 100644
@@ -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(),
 };
 
hw/virtio-pci.c +6 -1
index 06bdbe1..8955b73 100644
@@ -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(),
 };
 
hw/virtio-scsi.h +3 -6
index c659ba1..197a7b5 100644
@@ -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 */
Signature · 1 line
1.7.11.7
#41 lore raw

PATCH 26/61 virtio-scsi : add the virtio-scsi device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-pci.c  |  5 ++++
 hw/virtio-scsi.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-scsi.h |  7 +++++
 3 files changed, 98 insertions(+), 5 deletions(-)
hw/virtio-pci.c +5 -0
index 8955b73..be382c0 100644
@@ -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;
hw/virtio-scsi.c +86 -5

116 lines not on this page · raw message

hw/virtio-scsi.h +7 -0
index 197a7b5..67d9067 100644
@@ -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 */
Signature · 1 line
1.7.11.7
#42 lore raw

PATCH 27/61 virtio-scsi-pci : switch to new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-pci.c | 121 +++++++++++++++++++++++++++-----------------------------
 hw/virtio-pci.h |  15 ++++++-
 2 files changed, 72 insertions(+), 64 deletions(-)
hw/virtio-pci.c +58 -63
index be382c0..bbdb576 100644
@@ -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)
hw/virtio-pci.h +14 -1
index b8cf743..4114240 100644
@@ -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);
 
Signature · 1 line
1.7.11.7
#43 lore raw

PATCH 28/61 virtio-scsi-s390 : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/s390-virtio-bus.c | 26 +++++++++++++++++---------
 hw/s390-virtio-bus.h | 13 ++++++++++++-
 2 files changed, 29 insertions(+), 10 deletions(-)
hw/s390-virtio-bus.c +17 -9
index 283b7b6..569cac2 100644
@@ -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,
 };
 
hw/s390-virtio-bus.h +12 -1
index f67ca51..62c2b1c 100644
@@ -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
Signature · 1 line
1.7.11.7
#44 lore raw

PATCH 29/61 virtio-scsi : cleanup : use QOM casts.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-scsi.c | 46 ++++++++++++++++++++++++++--------------------
 hw/virtio-scsi.h |  2 +-
 2 files changed, 27 insertions(+), 21 deletions(-)
hw/virtio-scsi.c +26 -20
index ad07a65..d81df9c 100644
@@ -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)
hw/virtio-scsi.h +1 -1
index 67d9067..50fa6c5 100644
@@ -38,7 +38,7 @@ struct VirtIOSCSIConf {
 };
 
 typedef struct {
-    VirtIODevice vdev;
+    VirtIODevice parent_obj;
     DeviceState *qdev;
     VirtIOSCSIConf conf;
 
Signature · 1 line
1.7.11.7
#45 lore raw

PATCH 30/61 virtio-scsi : cleanup : init and exit functions.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-scsi.c | 59 ++++++++++----------------------------------------------
 1 file changed, 10 insertions(+), 49 deletions(-)
hw/virtio-scsi.c +10 -49
index d81df9c..b2e0d70 100644
@@ -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;
 }
 
Signature · 1 line
1.7.11.7
#46 lore raw

PATCH 31/61 virtio-scsi : cleanup : remove qdev field.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-scsi.c | 2 --
 hw/virtio-scsi.h | 1 -
 2 files changed, 3 deletions(-)
hw/virtio-scsi.c +0 -2
index b2e0d70..273ca69 100644
@@ -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;
hw/virtio-scsi.h +0 -1
index 50fa6c5..d945d4c 100644
@@ -39,7 +39,6 @@ struct VirtIOSCSIConf {
 
 typedef struct {
     VirtIODevice parent_obj;
-    DeviceState *qdev;
     VirtIOSCSIConf conf;
 
     SCSIBus bus;
Signature · 1 line
1.7.11.7
#47 lore raw

PATCH 32/61 virtio-balloon : show the VirtIOBalloon structure.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-balloon.c | 12 ------------
 hw/virtio-balloon.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 12 deletions(-)
hw/virtio-balloon.c +0 -12
index 3040bc6..3ea1790 100644
@@ -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;
hw/virtio-balloon.h +11 -0
index b1828f4..0cd211e 100644
@@ -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
Signature · 1 line
1.7.11.7
#48 lore raw

PATCH 33/61 virtio-balloon : add the virtio-balloon device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-balloon.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-balloon.h |  4 +++
 hw/virtio-pci.c     |  6 ++++
 3 files changed, 102 insertions(+), 7 deletions(-)
hw/virtio-balloon.c +92 -7
index 3ea1790..fc94e3e 100644
@@ -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)
hw/virtio-balloon.h +4 -0
index 0cd211e..c106026 100644
@@ -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 */
hw/virtio-pci.c +6 -0
index bbdb576..7c48eab 100644
@@ -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;
Signature · 1 line
1.7.11.7
#49 lore raw

PATCH 34/61 virtio-balloon-pci : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-pci.c | 106 ++++++++++++++++++++++++++------------------------------
 hw/virtio-pci.h |  14 ++++++++
 2 files changed, 64 insertions(+), 56 deletions(-)
hw/virtio-pci.c +50 -56
index 7c48eab..6dc7732 100644
@@ -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)
hw/virtio-pci.h +14 -0
index 4114240..d67e945 100644
@@ -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);
 
Signature · 1 line
1.7.11.7
#50 lore raw

PATCH 35/61 virtio-balloon : cleanup : init and exit function.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-balloon.c | 68 ++++++++++-------------------------------------------
 1 file changed, 12 insertions(+), 56 deletions(-)
hw/virtio-balloon.c +12 -56
index fc94e3e..3990a6b 100644
@@ -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;
 }
 
Signature · 1 line
1.7.11.7
#51 lore raw

PATCH 36/61 virtio-balloon : cleanup : QOM casts.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-balloon.c | 39 +++++++++++++++++----------------------
 hw/virtio-balloon.h |  2 +-
 2 files changed, 18 insertions(+), 23 deletions(-)
hw/virtio-balloon.c +17 -22
index 3990a6b..2cb57b2 100644
@@ -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);
hw/virtio-balloon.h +1 -1
index c106026..96327e6 100644
@@ -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;
Signature · 1 line
1.7.11.7
#52 lore raw

PATCH 37/61 virtio-balloon : cleanup : remove qdev field.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-balloon.c | 1 -
 hw/virtio-balloon.h | 1 -
 2 files changed, 2 deletions(-)
hw/virtio-balloon.c +0 -1
index 2cb57b2..e2cb2fc 100644
@@ -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);
 
hw/virtio-balloon.h +0 -1
index 96327e6..9284f16 100644
@@ -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
Signature · 1 line
1.7.11.7
#53 lore raw

PATCH 38/61 virtio-rng : show the VirtIORNG structure.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-rng.c | 19 -------------------
 hw/virtio-rng.h | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 19 deletions(-)
hw/virtio-rng.c +0 -19
index e063127..d79aa46 100644
@@ -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)
hw/virtio-rng.h +19 -0
index f42d748..3711c97 100644
@@ -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
Signature · 1 line
1.7.11.7
#54 lore raw

PATCH 39/61 virtio-rng : don't use pointer for configuration.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-rng.c | 12 ++++++------
 hw/virtio-rng.h |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
hw/virtio-rng.c +6 -6
index d79aa46..e672c40 100644
@@ -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);
hw/virtio-rng.h +1 -1
index 3711c97..3deb283 100644
@@ -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;
 
Signature · 1 line
1.7.11.7
#55 lore raw

PATCH 40/61 virtio-rng : add virtio-rng device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-pci.c |  13 +++----
 hw/virtio-rng.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-rng.h |  16 ++++++++
 3 files changed, 133 insertions(+), 14 deletions(-)
hw/virtio-pci.c +6 -7
index 6dc7732..4e35e04 100644
@@ -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;
hw/virtio-rng.c +111 -7

145 lines not on this page · raw message

hw/virtio-rng.h +16 -0
index 3deb283..fd6d01f 100644
@@ -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
Signature · 1 line
1.7.11.7
#56 lore raw

PATCH 41/61 virtio-rng-s390 : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/s390-virtio-bus.c | 35 ++++++++++++++++++-----------------
 hw/s390-virtio-bus.h | 13 ++++++++++++-
 2 files changed, 30 insertions(+), 18 deletions(-)
hw/s390-virtio-bus.c +18 -17
index 569cac2..f3e1f07 100644
@@ -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,
 };
 
hw/s390-virtio-bus.h +12 -1
index 62c2b1c..3eb9b69 100644
@@ -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
Signature · 1 line
1.7.11.7
#57 lore raw

PATCH 42/61 virtio-rng-pci : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-pci.c | 134 ++++++++++++++++++++++++++------------------------------
 hw/virtio-pci.h |  15 ++++++-
 2 files changed, 75 insertions(+), 74 deletions(-)
hw/virtio-pci.c +61 -73
index 4e35e04..8b89758 100644
@@ -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)
hw/virtio-pci.h +14 -1
index d67e945..8f418b4 100644
@@ -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);
 
Signature · 1 line
1.7.11.7
#58 lore raw

PATCH 43/61 virtio-rng.c : cleanup : init and exit functions.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-rng.c | 88 ++++++++++++++-------------------------------------------
 1 file changed, 21 insertions(+), 67 deletions(-)
hw/virtio-rng.c +21 -67
index 98adef1..646bcf3 100644
@@ -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;
 }
 
Signature · 1 line
1.7.11.7
#59 lore raw

PATCH 44/61 virtio-rng.c : cleanup : remove qdev field.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-rng.c | 1 -
 hw/virtio-rng.h | 2 --
 2 files changed, 3 deletions(-)
hw/virtio-rng.c +0 -1
index 646bcf3..4e84f9e 100644
@@ -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;
hw/virtio-rng.h +0 -2
index fd6d01f..ae0c56da 100644
@@ -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;
 
Signature · 1 line
1.7.11.7
#60 lore raw

PATCH 45/61 virtio-rng.c : cleanup : use QOM casts.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-rng.c | 31 +++++++++++++++++--------------
 hw/virtio-rng.h |  2 +-
 2 files changed, 18 insertions(+), 15 deletions(-)
hw/virtio-rng.c +17 -14
index 4e84f9e..67407a7 100644
@@ -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);
hw/virtio-rng.h +1 -1
index ae0c56da..ee0847a 100644
@@ -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;
Signature · 1 line
1.7.11.7
#61 lore raw

PATCH 46/61 virtio-serial : show structures.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-serial-bus.c | 41 -----------------------------------------
 hw/virtio-serial.h     | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 41 deletions(-)
hw/virtio-serial-bus.c +0 -41
index 7272bfd..b7cce7a 100644
@@ -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;
hw/virtio-serial.h +41 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#62 lore raw

PATCH 47/61 virtio-serial : add the virtio-serial device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-pci.c        |   8 +++-
 hw/virtio-serial-bus.c | 100 +++++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-serial.h     |  11 ++++++
 3 files changed, 111 insertions(+), 8 deletions(-)
hw/virtio-pci.c +7 -1
index 8b89758..3aa96fc 100644
@@ -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;
hw/virtio-serial-bus.c +93 -7

130 lines not on this page · raw message

hw/virtio-serial.h +11 -0
index 722d01b..f5960f9 100644
@@ -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
Signature · 1 line
1.7.11.7
#63 lore raw

PATCH 48/61 virtio-serial-pci : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-pci.c | 123 +++++++++++++++++++++++++++-----------------------------
 hw/virtio-pci.h |  15 ++++++-
 2 files changed, 74 insertions(+), 64 deletions(-)
hw/virtio-pci.c +60 -63
index 3aa96fc..7d66c51 100644
@@ -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)
hw/virtio-pci.h +14 -1
index 8f418b4..98b51d8 100644
@@ -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);
 
Signature · 1 line
1.7.11.7
#64 lore raw

PATCH 49/61 virtio-serial-s390 : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/s390-virtio-bus.c | 31 +++++++++++++++++++++----------
 hw/s390-virtio-bus.h | 10 +++++++++-
 2 files changed, 30 insertions(+), 11 deletions(-)
hw/s390-virtio-bus.c +21 -10
index f3e1f07..52978b3 100644
@@ -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,
 };
 
hw/s390-virtio-bus.h +9 -1
index 3eb9b69..c9ca5a1 100644
@@ -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
Signature · 1 line
1.7.11.7
#65 lore raw

PATCH 50/61 virtio-serial : cleanup : init and exit functions.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-serial-bus.c | 94 ++++++++++++--------------------------------------
 1 file changed, 22 insertions(+), 72 deletions(-)
hw/virtio-serial-bus.c +22 -72
index 5186191..f1c7d75 100644
@@ -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);
Signature · 1 line
1.7.11.7
#66 lore raw

PATCH 51/61 virtio-serial : cleanup : use QOM casts.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-serial-bus.c | 50 ++++++++++++++++++++++++++------------------------
 hw/virtio-serial.h     |  2 +-
 2 files changed, 27 insertions(+), 25 deletions(-)
hw/virtio-serial-bus.c +26 -24
index f1c7d75..3bcb2d7 100644
@@ -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;
 
hw/virtio-serial.h +1 -1
index f5960f9..7517e8c 100644
@@ -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 */
Signature · 1 line
1.7.11.7
#67 lore raw

PATCH 52/61 virtio-serial : cleanup : remove qdev field.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio-serial-bus.c | 2 --
 hw/virtio-serial.h     | 2 --
 2 files changed, 4 deletions(-)
hw/virtio-serial-bus.c +0 -2
index 3bcb2d7..d1f47a4 100644
@@ -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;
 
     /*
hw/virtio-serial.h +0 -2
index 7517e8c..42f9b7c 100644
@@ -202,8 +202,6 @@ struct VirtIOSerial {
 
     VirtIOSerialBus bus;
 
-    DeviceState *qdev;
-
     QTAILQ_HEAD(, VirtIOSerialPort) ports;
 
     /* bitmap for identifying active ports */
Signature · 1 line
1.7.11.7
#68 lore raw

PATCH 53/61 virtio-9p : add the virtio-9p device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 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(-)
hw/9pfs/virtio-9p-device.c +71 -13
index 6761bce..8a88739 100644
@@ -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();
 }
hw/9pfs/virtio-9p.h +11 -0
index 406fe52..3be634f 100644
@@ -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
hw/virtio-pci.c +5 -0
index 7d66c51..0e45b1a 100644
@@ -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;
Signature · 1 line
1.7.11.7
#69 lore raw

PATCH 54/61 virtio-9p-pci : switch to the new API.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 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(-)
hw/9pfs/virtio-9p-device.c +26 -22
index 8a88739..7e4b239 100644
@@ -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();
 }
 
hw/9pfs/virtio-9p.h +14 -0
index 3be634f..9b342dc 100644
@@ -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
hw/virtio-pci.h +0 -3
index 98b51d8..e251d93 100644
@@ -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;
Signature · 1 line
1.7.11.7
#70 lore raw

PATCH 55/61 virtio-9p : cleanup : init function.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/9pfs/virtio-9p-device.c | 75 ++++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 52 deletions(-)
hw/9pfs/virtio-9p-device.c +23 -52
index 7e4b239..02f01ae 100644
@@ -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(),
Signature · 1 line
1.7.11.7
#71 lore raw

PATCH 56/61 virtio-9p : cleanup : QOM casts.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 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(-)
hw/9pfs/virtio-9p-device.c +3 -8
index 02f01ae..a99ff5a 100644
@@ -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);
 
hw/9pfs/virtio-9p.c +1 -1
index 0aaf0d2..aedea0c 100644
@@ -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);
hw/9pfs/virtio-9p.h +1 -1
index 9b342dc..f21e33f 100644
@@ -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;
Signature · 1 line
1.7.11.7
#72 lore raw

PATCH 57/61 virtio : remove the function pointer.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 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(-)
hw/9pfs/virtio-9p-device.c +0 -2
index a99ff5a..17be320 100644
@@ -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);
 
hw/virtio-balloon.c +0 -8
index e2cb2fc..40d3c15 100644
@@ -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);
 
hw/virtio-blk.c +0 -5
index 74ba97b..14e4543 100644
@@ -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));
hw/virtio-net.c +0 -7
index 7f87166..3ae0d79 100644
@@ -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") &&
hw/virtio-pci.c +1 -1
index 0e45b1a..c47b9b1 100644
@@ -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;
hw/virtio-rng.c +0 -6
index 67407a7..57e0dae 100644
@@ -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;
hw/virtio-scsi.c +0 -6
index 273ca69..0e43230 100644
@@ -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,
hw/virtio-serial-bus.c +0 -6
index d1f47a4..ef74c26 100644
@@ -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;
 
     /*
hw/virtio.c +26 -15

126 lines not on this page · raw message

hw/virtio.h +0 -11
index c134960..fbbf8e8 100644
@@ -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;
Signature · 1 line
1.7.11.7
#73 lore raw

Re: [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer.

Quoted 231 lines · On Mon, Jan 7, 2013 at 6:41 PM, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

---
 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(-)
hw/9pfs/virtio-9p-device.c +0 -2
index a99ff5a..17be320 100644
@@ -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);
 
hw/virtio-balloon.c +0 -8
index e2cb2fc..40d3c15 100644
@@ -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);
 
hw/virtio-blk.c +0 -5
index 74ba97b..14e4543 100644
@@ -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));
hw/virtio-net.c +0 -7
index 7f87166..3ae0d79 100644
@@ -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") &&
hw/virtio-pci.c +1 -1
index 0e45b1a..c47b9b1 100644
@@ -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;
hw/virtio-rng.c +0 -6
index 67407a7..57e0dae 100644
@@ -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;
hw/virtio-scsi.c +0 -6
index 273ca69..0e43230 100644
@@ -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,
hw/virtio-serial-bus.c +0 -6
index d1f47a4..ef74c26 100644
@@ -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;
 
     /*
hw/virtio.c +14 -7
index ca170c3..d72b84a 100644
@@ -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)))

hw/virtio.c void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data) · line 613

Quoted 6 lines
hw/virtio.c +1 -2
@@ -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...

Quoted 10 lines
hw/virtio.c +2 -0
+        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)))

hw/virtio.c void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data) · line 627

Quoted 6 lines
hw/virtio.c +1 -2
@@ -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.

Quoted 64 lines
hw/virtio.c +8 -4
+        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;
hw/virtio.h +0 -12
index c134960..fbbf8e8 100644
@@ -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

#74 lore raw

Re: [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer.

Quoted 12 lines · Blue Swirl
Quoted 11 lines · On Mon, Jan 7, 2013 at 6:41 PM, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

---
  hw/9pfs/virtio-9p-device.c |  2 --
  hw/virtio-balloon.c        |  8 --------
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-        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

#75 lore raw

Re: [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer.

Quoted 18 lines · KONRAD Frédéric
Quoted 17 lines · Blue Swirl
Quoted 14 lines · On Mon, Jan 7, 2013 at 6:41 PM, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

---
  hw/9pfs/virtio-9p-device.c |  2 --
  hw/virtio-balloon.c        |  8 --------
(quoted diff) +1 -1
-        vdev->set_config(vdev, vdev->config);
+    if (k->set_config)
Quoted 8 lines
Quoted 4 lines

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.

Quoted 3 lines

Thanks,
Fred

#76 lore raw

PATCH 58/61 virtio-pci : cleanup : init, exit and reset functions.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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.

---
 hw/virtio-pci.c | 71 ++++-----------------------------------------------------
 hw/virtio-pci.h |  3 ---
 2 files changed, 4 insertions(+), 70 deletions(-)
hw/virtio-pci.c +4 -67
index c47b9b1..4588073 100644
@@ -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 = {
hw/virtio-pci.h +0 -3
index e251d93..4acddfd 100644
@@ -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
 
Signature · 1 line
1.7.11.7
#77 lore raw

PATCH 59/61 s390-virtio-bus : cleanup

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/s390-virtio-bus.c | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)
hw/s390-virtio-bus.c +16 -22
index 52978b3..017fc0d 100644
@@ -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 = {
Signature · 1 line
1.7.11.7
#78 lore raw

PATCH 60/61 virtio : remove virtiobindings.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

---
 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(-)
hw/s390-virtio-bus.c +0 -7
index 017fc0d..7b9cb60 100644
@@ -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,
hw/vhost.c +27 -11
index 4e1cb47..7e9171d 100644
@@ -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);
hw/virtio-bus.c +0 -17
index c5e67b0..ff93997 100644
@@ -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);
     }
hw/virtio-bus.h +0 -4
index 7bea64a..9a43728 100644
@@ -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);
hw/virtio-pci.c +0 -13
index 4588073..581ab76 100644
@@ -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.
  */
hw/virtio.c +32 -22

117 lines not on this page · raw message

hw/virtio.h +0 -19
index fbbf8e8..3199676 100644
@@ -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);
Signature · 1 line
1.7.11.7
#79 lore raw

PATCH 61/61 virtio : cleanup : init and exit function.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

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

---
 hw/virtio.c | 15 ---------------
 hw/virtio.h |  4 ----
 2 files changed, 19 deletions(-)
hw/virtio.c +0 -15
index a852adf..7214aa0 100644
@@ -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;
hw/virtio.h +0 -4
index 3199676..c37f8f1 100644
@@ -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);
Signature · 1 line
1.7.11.7
#80 lore raw
In reply to [email protected]
Quoted 7 lines · [email protected] writes:

From: KONRAD Frederic <[email protected]>

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

Quoted 7 lines

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

Quoted 184 lines

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
Signature · 1 line
1.7.11.7
#81 lore raw
Quoted 12 lines · Anthony Liguori
Quoted 10 lines · [email protected] writes:

From: KONRAD Frederic <[email protected]>

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

Quoted 7 lines
Quoted 4 lines

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

Quoted 187 lines

Regards,

Anthony Liguori

Quoted 183 lines

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

Signature · 1 line
1.7.11.7
#82 lore raw
In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

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:

Quoted 7 lines
Quoted 7 lines

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:

Quoted 7 lines
Quoted 7 lines

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:

Quoted 7 lines
Quoted 7 lines

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:

Quoted 5 lines
Quoted 5 lines

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

#83 lore raw
Quoted 8 lines · Peter Maydell
Quoted 3 lines · Anthony Liguori

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...

Quoted 9 lines

I: Initial class definitions and transport level refactoring:

Quoted 7 lines
Quoted 7 lines

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.

Quoted 21 lines

II: Update virtio-blk:

Quoted 7 lines
Quoted 7 lines

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:

Quoted 7 lines
Quoted 7 lines

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.

Quoted 1 line

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

I would do all of the devices at once.

Quoted 8 lines

N: Final cleanup now all backends are converted:

Quoted 5 lines
Quoted 5 lines

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

Quoted 14 lines

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

#84 lore raw
Quoted 7 lines · Anthony Liguori
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Anthony Liguori

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.

Quoted 5 lines
Quoted 3 lines

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

#85 lore raw
In reply to [email protected]
Quoted 10 lines · On Mon, Jan 07, 2013 at 07:40:13PM +0100, [email protected] wrote:

From: KONRAD Frederic <[email protected]>

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

Quoted 8 lines

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.

Quoted 2 lines
Signature · 1 line
1.7.11.7
#86 lore raw
Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · On Mon, Jan 07, 2013 at 07:40:13PM +0100, [email protected] wrote:

From: KONRAD Frederic <[email protected]>

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.

Quoted 7 lines
Quoted 3 lines

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

Quoted 6 lines

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

Quoted 2 lines
Signature · 1 line
1.7.11.7
#87 lore raw
In reply to [email protected]
Quoted 6 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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

#88 lore raw
Quoted 12 lines · Peter Maydell
Quoted 6 lines · On 7 January 2013 18:40, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

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