* [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring.
@ 2013-03-27 9:49 fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 1/6] virtio-balloon: add the virtio-balloon device fred.konrad
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: fred.konrad @ 2013-03-27 9:49 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
This is the next part of virtio-refactoring.
Basically it creates virtio-balloon device which extends virtio-device.
Then a virtio-balloon can be connected on a virtio-bus.
virtio-balloon-pci, virtio-balloon-ccw are created too, they extend
respectively virtio-pci, virtio-ccw-device and have a virtio-balloon.
You can checkout my branch here:
git://project.greensocs.com/qemu-virtio.git virtio-balloon-v3
Note that it is nearly the same series as virtio-blk and virtio-scsi
refactoring.
I made basic tests (with linux guests) on:
* qemu-system-i386
Changes v2 -> v3:
* Added CCW device.
* Rebased.
Thanks,
Fred
KONRAD Frederic (6):
virtio-balloon: add the virtio-balloon device.
virtio-balloon-pci: switch to the new API.
virtio-balloon-ccw: switch to the new API.
virtio-balloon: cleanup: init and exit function.
virtio-balloon: cleanup: QOM casts.
virtio-balloon: cleanup: remove qdev field.
hw/s390x/virtio-ccw.c | 25 +++++++-----
hw/s390x/virtio-ccw.h | 11 +++++
hw/virtio-balloon.c | 110 +++++++++++++++++++++++++++++++------------------
hw/virtio-balloon.h | 7 +++-
hw/virtio-pci.c | 111 +++++++++++++++++++++++++-------------------------
hw/virtio-pci.h | 14 +++++++
6 files changed, 170 insertions(+), 108 deletions(-)
--
1.7.11.7
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v3 1/6] virtio-balloon: add the virtio-balloon device.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
@ 2013-03-27 9:49 ` fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 2/6] virtio-balloon-pci: switch to the new API fred.konrad
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-03-27 9:49 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Create virtio-balloon which extends virtio-device, so it can be connected on
virtio-bus.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-balloon.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++----
hw/virtio-balloon.h | 4 +++
2 files changed, 93 insertions(+), 6 deletions(-)
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 54a4372..7519971 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -29,6 +29,11 @@
#include <sys/mman.h>
#endif
+#include "hw/virtio-bus.h"
+
+/*
+ * Will be modified later in the serie.
+ */
static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev)
{
return (VirtIOBalloon *)vdev;
@@ -334,14 +339,27 @@ 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);
+ }
s->vdev.get_config = virtio_balloon_get_config;
s->vdev.set_config = virtio_balloon_set_config;
@@ -349,10 +367,14 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev)
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);
@@ -373,6 +395,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);
@@ -382,3 +413,55 @@ 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);
+
+ balloon_stats_destroy_timer(s);
+ qemu_remove_balloon_handler(s);
+ unregister_savevm(qdev, "virtio-balloon", s);
+ virtio_common_cleanup(vdev);
+ return 0;
+}
+
+static Property virtio_balloon_properties[] = {
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_balloon_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+ dc->exit = virtio_balloon_device_exit;
+ dc->props = virtio_balloon_properties;
+ vdc->init = virtio_balloon_device_init;
+ vdc->get_config = virtio_balloon_get_config;
+ vdc->set_config = virtio_balloon_set_config;
+ vdc->get_features = virtio_balloon_get_features;
+}
+
+static const TypeInfo virtio_balloon_info = {
+ .name = TYPE_VIRTIO_BALLOON,
+ .parent = TYPE_VIRTIO_DEVICE,
+ .instance_size = sizeof(VirtIOBalloon),
+ .class_init = virtio_balloon_class_init,
+};
+
+static void virtio_register_types(void)
+{
+ type_register_static(&virtio_balloon_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index b007042..139eac3 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -18,6 +18,10 @@
#include "hw/virtio.h"
#include "hw/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 */
--
1.7.11.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v3 2/6] virtio-balloon-pci: switch to the new API.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 1/6] virtio-balloon: add the virtio-balloon device fred.konrad
@ 2013-03-27 9:49 ` fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 3/6] virtio-balloon-ccw: " fred.konrad
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-03-27 9:49 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Here the virtio-balloon-pci is modified for the new API. The device
virtio-balloon-pci extends virtio-pci. It creates and connects a
virtio-balloon during the init. The properties are not changed.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-pci.c | 111 ++++++++++++++++++++++++++++----------------------------
hw/virtio-pci.h | 14 +++++++
2 files changed, 69 insertions(+), 56 deletions(-)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 736a9bf..fb20722 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -22,6 +22,7 @@
#include "hw/virtio-net.h"
#include "hw/virtio-serial.h"
#include "hw/virtio-scsi.h"
+#include "hw/virtio-balloon.h"
#include "hw/pci/pci.h"
#include "qemu/error-report.h"
#include "hw/pci/msi.h"
@@ -1000,33 +1001,6 @@ static void virtio_net_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);
@@ -1127,34 +1101,6 @@ static const 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 const 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);
@@ -1461,6 +1407,59 @@ static const 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);
+ PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+ k->init = virtio_balloon_pci_init;
+ dc->props = virtio_balloon_pci_properties;
+ pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
+ pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+ pcidev_k->class_id = PCI_CLASS_OTHERS;
+}
+
+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 const 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 */
void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev)
@@ -1501,7 +1500,6 @@ 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_rng_info);
type_register_static(&virtio_pci_bus_info);
type_register_static(&virtio_pci_info);
@@ -1510,6 +1508,7 @@ static void virtio_pci_register_types(void)
#endif
type_register_static(&virtio_blk_pci_info);
type_register_static(&virtio_scsi_pci_info);
+ type_register_static(&virtio_balloon_pci_info);
}
type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index bfe7a8e..f99f2eb 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -21,12 +21,14 @@
#include "hw/virtio-rng.h"
#include "hw/virtio-serial.h"
#include "hw/virtio-scsi.h"
+#include "hw/virtio-balloon.h"
#include "hw/virtio-bus.h"
#include "hw/9pfs/virtio-9p-device.h"
typedef struct VirtIOPCIProxy VirtIOPCIProxy;
typedef struct VirtIOBlkPCI VirtIOBlkPCI;
typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
+typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
/* virtio-pci-bus */
@@ -116,6 +118,18 @@ struct VirtIOBlkPCI {
VirtIOBlkConf blk;
};
+/*
+ * 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_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v3 3/6] virtio-balloon-ccw: switch to the new API.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 1/6] virtio-balloon: add the virtio-balloon device fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 2/6] virtio-balloon-pci: switch to the new API fred.konrad
@ 2013-03-27 9:49 ` fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 4/6] virtio-balloon: cleanup: init and exit function fred.konrad
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-03-27 9:49 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Here the virtio-balloon-ccw is modified for the new API. The device
virtio-balloon-ccw extends virtio-ccw-device as before. It creates and
connects a virtio-balloon during the init. The properties are not modified.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/s390x/virtio-ccw.c | 25 ++++++++++++++-----------
hw/s390x/virtio-ccw.h | 11 +++++++++++
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 7e79c57..5dce791 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -608,22 +608,24 @@ static int virtio_ccw_serial_exit(VirtioCcwDevice *dev)
return virtio_ccw_exit(dev);
}
-static int virtio_ccw_balloon_init(VirtioCcwDevice *dev)
+static int virtio_ccw_balloon_init(VirtioCcwDevice *ccw_dev)
{
- VirtIODevice *vdev;
+ VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
+ DeviceState *vdev = DEVICE(&dev->vdev);
- vdev = virtio_balloon_init((DeviceState *)dev);
- if (!vdev) {
+ qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
+ if (qdev_init(vdev) < 0) {
return -1;
}
- return virtio_ccw_device_init(dev, vdev);
+ return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
}
-static int virtio_ccw_balloon_exit(VirtioCcwDevice *dev)
+static void virtio_ccw_balloon_instance_init(Object *obj)
{
- virtio_balloon_exit(dev->vdev);
- return virtio_ccw_exit(dev);
+ VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
+ object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BALLOON);
+ object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
}
static int virtio_ccw_scsi_init(VirtioCcwDevice *ccw_dev)
@@ -820,15 +822,16 @@ static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->init = virtio_ccw_balloon_init;
- k->exit = virtio_ccw_balloon_exit;
+ k->exit = virtio_ccw_exit;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_balloon_properties;
}
static const TypeInfo virtio_ccw_balloon = {
- .name = "virtio-balloon-ccw",
+ .name = TYPE_VIRTIO_BALLOON_CCW,
.parent = TYPE_VIRTIO_CCW_DEVICE,
- .instance_size = sizeof(VirtioCcwDevice),
+ .instance_size = sizeof(VirtIOBalloonCcw),
+ .instance_init = virtio_ccw_balloon_instance_init,
.class_init = virtio_ccw_balloon_class_init,
};
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index d9f7399..d580510 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -16,6 +16,7 @@
#include <hw/virtio-net.h>
#include <hw/virtio-serial.h>
#include <hw/virtio-scsi.h>
+#include "hw/virtio-balloon.h"
#include <hw/virtio-rng.h>
#include <hw/virtio-bus.h>
@@ -115,6 +116,16 @@ typedef struct VirtIOBlkCcw {
VirtIOBlkConf blk;
} VirtIOBlkCcw;
+/* virtio-balloon-ccw */
+
+#define TYPE_VIRTIO_BALLOON_CCW "virtio-balloon-ccw"
+#define VIRTIO_BALLOON_CCW(obj) \
+ OBJECT_CHECK(VirtIOBalloonCcw, (obj), TYPE_VIRTIO_BALLOON_CCW)
+
+typedef struct VirtIOBalloonCcw {
+ VirtioCcwDevice parent_obj;
+ VirtIOBalloon vdev;
+} VirtIOBalloonCcw;
VirtualCssBus *virtual_css_bus_init(void);
void virtio_ccw_device_update_status(SubchDev *sch);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v3 4/6] virtio-balloon: cleanup: init and exit function.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
` (2 preceding siblings ...)
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 3/6] virtio-balloon-ccw: " fred.konrad
@ 2013-03-27 9:49 ` fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 5/6] virtio-balloon: cleanup: QOM casts fred.konrad
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-03-27 9:49 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
This remove old init and exit function as they are no longer needed.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-balloon.c | 73 ++++++++++-------------------------------------------
1 file changed, 13 insertions(+), 60 deletions(-)
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 7519971..87278f5 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -339,27 +339,13 @@ 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);
s->vdev.get_config = virtio_balloon_get_config;
s->vdev.set_config = virtio_balloon_set_config;
@@ -367,60 +353,27 @@ 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);
- 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);
- object_property_add(OBJECT(dev), "guest-stats", "guest statistics",
+ object_property_add(OBJECT(qdev), "guest-stats", "guest statistics",
balloon_stats_get_all, NULL, NULL, s, NULL);
- object_property_add(OBJECT(dev), "guest-stats-polling-interval", "int",
+ object_property_add(OBJECT(qdev), "guest-stats-polling-interval", "int",
balloon_stats_get_poll_interval,
balloon_stats_set_poll_interval,
NULL, s, NULL);
-
- 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);
-
- balloon_stats_destroy_timer(s);
- qemu_remove_balloon_handler(s);
- unregister_savevm(s->qdev, "virtio-balloon", s);
- virtio_cleanup(vdev);
-}
-
-static int virtio_balloon_device_init(VirtIODevice *vdev)
-{
- DeviceState *qdev = DEVICE(vdev);
- VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
- if (virtio_balloon_common_init(qdev, &s) == NULL) {
- return -1;
- }
return 0;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v3 5/6] virtio-balloon: cleanup: QOM casts.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
` (3 preceding siblings ...)
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 4/6] virtio-balloon: cleanup: init and exit function fred.konrad
@ 2013-03-27 9:49 ` fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 6/6] virtio-balloon: cleanup: remove qdev field fred.konrad
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-03-27 9:49 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
As the virtio-balloon-pci is switched to the new API, we can use QOM
casts.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-balloon.c | 43 ++++++++++++++++++++-----------------------
hw/virtio-balloon.h | 2 +-
2 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 87278f5..38d2ee3 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -31,14 +31,6 @@
#include "hw/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__)
@@ -74,7 +66,8 @@ static inline void reset_stats(VirtIOBalloon *dev)
static bool balloon_stats_supported(const VirtIOBalloon *s)
{
- return s->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ);
+ VirtIODevice *vdev = VIRTIO_DEVICE(s);
+ return vdev->guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ);
}
static bool balloon_stats_enabled(const VirtIOBalloon *s)
@@ -100,6 +93,7 @@ static void balloon_stats_change_timer(VirtIOBalloon *s, int secs)
static void balloon_stats_poll_cb(void *opaque)
{
VirtIOBalloon *s = opaque;
+ VirtIODevice *vdev = VIRTIO_DEVICE(s);
if (!balloon_stats_supported(s)) {
/* re-schedule */
@@ -108,7 +102,7 @@ static void balloon_stats_poll_cb(void *opaque)
}
virtqueue_push(s->svq, &s->stats_vq_elem, s->stats_vq_offset);
- virtio_notify(&s->vdev, s->svq);
+ virtio_notify(vdev, s->svq);
}
static void balloon_stats_get_all(Object *obj, struct Visitor *v,
@@ -186,7 +180,7 @@ static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
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;
@@ -220,7 +214,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;
@@ -262,7 +256,7 @@ out:
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);
@@ -274,7 +268,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);
@@ -300,22 +294,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);
@@ -323,13 +319,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;
}
@@ -347,9 +344,9 @@ static int virtio_balloon_device_init(VirtIODevice *vdev)
virtio_init(vdev, "virtio-balloon", VIRTIO_ID_BALLOON, 8);
- s->vdev.get_config = virtio_balloon_get_config;
- s->vdev.set_config = virtio_balloon_set_config;
- s->vdev.get_features = virtio_balloon_get_features;
+ vdev->get_config = virtio_balloon_get_config;
+ vdev->set_config = virtio_balloon_set_config;
+ vdev->get_features = virtio_balloon_get_features;
ret = qemu_add_balloon_handler(virtio_balloon_to_target,
virtio_balloon_stat, s);
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index 139eac3..5f8fe02 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -57,7 +57,7 @@ typedef struct VirtIOBalloonStat {
} QEMU_PACKED VirtIOBalloonStat;
typedef struct VirtIOBalloon {
- VirtIODevice vdev;
+ VirtIODevice parent_obj;
VirtQueue *ivq, *dvq, *svq;
uint32_t num_pages;
uint32_t actual;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH v3 6/6] virtio-balloon: cleanup: remove qdev field.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
` (4 preceding siblings ...)
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 5/6] virtio-balloon: cleanup: QOM casts fred.konrad
@ 2013-03-27 9:49 ` fred.konrad
2013-03-27 12:47 ` [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring Cornelia Huck
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: fred.konrad @ 2013-03-27 9:49 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
The qdev field is no longer needed, just drop it.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-balloon.c | 1 -
hw/virtio-balloon.h | 1 -
2 files changed, 2 deletions(-)
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 38d2ee3..b382bd4 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -360,7 +360,6 @@ static int virtio_balloon_device_init(VirtIODevice *vdev)
s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
- s->qdev = qdev;
register_savevm(qdev, "virtio-balloon", -1, 1,
virtio_balloon_save, virtio_balloon_load, s);
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index 5f8fe02..d898315 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -67,7 +67,6 @@ typedef struct VirtIOBalloon {
QEMUTimer *stats_timer;
int64_t stats_last_update;
int64_t stats_poll_interval;
- DeviceState *qdev;
} VirtIOBalloon;
#endif
--
1.7.11.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
` (5 preceding siblings ...)
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 6/6] virtio-balloon: cleanup: remove qdev field fred.konrad
@ 2013-03-27 12:47 ` Cornelia Huck
2013-03-28 13:29 ` Peter Maydell
2013-04-01 20:36 ` Anthony Liguori
8 siblings, 0 replies; 10+ messages in thread
From: Cornelia Huck @ 2013-03-27 12:47 UTC (permalink / raw)
To: fred.konrad; +Cc: peter.maydell, aliguori, mark.burton, qemu-devel
On Wed, 27 Mar 2013 10:49:09 +0100
fred.konrad@greensocs.com wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> This is the next part of virtio-refactoring.
>
> Basically it creates virtio-balloon device which extends virtio-device.
> Then a virtio-balloon can be connected on a virtio-bus.
> virtio-balloon-pci, virtio-balloon-ccw are created too, they extend
> respectively virtio-pci, virtio-ccw-device and have a virtio-balloon.
>
> You can checkout my branch here:
>
> git://project.greensocs.com/qemu-virtio.git virtio-balloon-v3
>
> Note that it is nearly the same series as virtio-blk and virtio-scsi
> refactoring.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>
> I made basic tests (with linux guests) on:
> * qemu-system-i386
For virtio-ccw on s390:
Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>
> Changes v2 -> v3:
> * Added CCW device.
> * Rebased.
>
> Thanks,
>
> Fred
>
> KONRAD Frederic (6):
> virtio-balloon: add the virtio-balloon device.
> virtio-balloon-pci: switch to the new API.
> virtio-balloon-ccw: switch to the new API.
> virtio-balloon: cleanup: init and exit function.
> virtio-balloon: cleanup: QOM casts.
> virtio-balloon: cleanup: remove qdev field.
>
> hw/s390x/virtio-ccw.c | 25 +++++++-----
> hw/s390x/virtio-ccw.h | 11 +++++
> hw/virtio-balloon.c | 110 +++++++++++++++++++++++++++++++------------------
> hw/virtio-balloon.h | 7 +++-
> hw/virtio-pci.c | 111 +++++++++++++++++++++++++-------------------------
> hw/virtio-pci.h | 14 +++++++
> 6 files changed, 170 insertions(+), 108 deletions(-)
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
` (6 preceding siblings ...)
2013-03-27 12:47 ` [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring Cornelia Huck
@ 2013-03-28 13:29 ` Peter Maydell
2013-04-01 20:36 ` Anthony Liguori
8 siblings, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2013-03-28 13:29 UTC (permalink / raw)
To: fred.konrad; +Cc: cornelia.huck, aliguori, mark.burton, qemu-devel
On 27 March 2013 09:49, <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> This is the next part of virtio-refactoring.
>
> Basically it creates virtio-balloon device which extends virtio-device.
> Then a virtio-balloon can be connected on a virtio-bus.
> virtio-balloon-pci, virtio-balloon-ccw are created too, they extend
> respectively virtio-pci, virtio-ccw-device and have a virtio-balloon.
>
> You can checkout my branch here:
>
> git://project.greensocs.com/qemu-virtio.git virtio-balloon-v3
>
> Note that it is nearly the same series as virtio-blk and virtio-scsi
> refactoring.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring.
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
` (7 preceding siblings ...)
2013-03-28 13:29 ` Peter Maydell
@ 2013-04-01 20:36 ` Anthony Liguori
8 siblings, 0 replies; 10+ messages in thread
From: Anthony Liguori @ 2013-04-01 20:36 UTC (permalink / raw)
To: fred.konrad, qemu-devel, aliguori
Cc: cornelia.huck, peter.maydell, mark.burton
Applied. Thanks.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-04-01 20:43 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 1/6] virtio-balloon: add the virtio-balloon device fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 2/6] virtio-balloon-pci: switch to the new API fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 3/6] virtio-balloon-ccw: " fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 4/6] virtio-balloon: cleanup: init and exit function fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 5/6] virtio-balloon: cleanup: QOM casts fred.konrad
2013-03-27 9:49 ` [Qemu-devel] [PATCH v3 6/6] virtio-balloon: cleanup: remove qdev field fred.konrad
2013-03-27 12:47 ` [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring Cornelia Huck
2013-03-28 13:29 ` Peter Maydell
2013-04-01 20:36 ` Anthony Liguori
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.