virtio-balloon: cleanup: QOM casts.

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>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Message-id: 1364377755-15508-6-git-send-email-fred.konrad@greensocs.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
KONRAD Frederic 2013-03-27 10:49:14 +01:00 committed by Anthony Liguori
parent 5c7d0962f6
commit c96caced3f
2 changed files with 21 additions and 24 deletions

View File

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

View File

@ -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;