From: fred.konrad@greensocs.com
To: qemu-devel@nongnu.org, aliguori@us.ibm.com
Cc: cornelia.huck@de.ibm.com, peter.maydell@linaro.org,
mark.burton@greensocs.com, fred.konrad@greensocs.com
Subject: [Qemu-devel] [PATCH v3 1/6] virtio-balloon: add the virtio-balloon device.
Date: Wed, 27 Mar 2013 10:49:10 +0100 [thread overview]
Message-ID: <1364377755-15508-2-git-send-email-fred.konrad@greensocs.com> (raw)
In-Reply-To: <1364377755-15508-1-git-send-email-fred.konrad@greensocs.com>
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
next prev parent reply other threads:[~2013-03-27 9:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-27 9:49 [Qemu-devel] [PATCH v3 0/6] virtio-balloon refactoring fred.konrad
2013-03-27 9:49 ` fred.konrad [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364377755-15508-2-git-send-email-fred.konrad@greensocs.com \
--to=fred.konrad@greensocs.com \
--cc=aliguori@us.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=mark.burton@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).