Skip to content

Commit

Permalink
virtio: remove virtiobindings.
Browse files Browse the repository at this point in the history
This remove virtio-bindings, and use class instead.

Signed-off-by: KONRAD Frederic <[email protected]>
Message-id: [email protected]
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
konrad-fred authored and Anthony Liguori committed Apr 24, 2013
1 parent 181103c commit 1c81944
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 122 deletions.
15 changes: 9 additions & 6 deletions hw/block/dataplane/virtio-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "hw/virtio/virtio-blk.h"
#include "virtio-blk.h"
#include "block/aio.h"
#include "hw/virtio/virtio-bus.h"

enum {
SEG_MAX = 126, /* maximum number of I/O segments */
Expand Down Expand Up @@ -455,6 +456,8 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)

void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
{
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VirtQueue *vq;
int i;

Expand All @@ -470,17 +473,15 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
s->ctx = aio_context_new();

/* Set up guest notifier (irq) */
if (s->vdev->binding->set_guest_notifiers(s->vdev->binding_opaque, 1,
true) != 0) {
if (k->set_guest_notifiers(qbus->parent, 1, true) != 0) {
fprintf(stderr, "virtio-blk failed to set guest notifier, "
"ensure -enable-kvm is set\n");
exit(1);
}
s->guest_notifier = virtio_queue_get_guest_notifier(vq);

/* Set up virtqueue notify */
if (s->vdev->binding->set_host_notifier(s->vdev->binding_opaque,
0, true) != 0) {
if (k->set_host_notifier(qbus->parent, 0, true) != 0) {
fprintf(stderr, "virtio-blk failed to set host notifier\n");
exit(1);
}
Expand Down Expand Up @@ -508,6 +509,8 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)

void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
{
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
if (!s->started || s->stopping) {
return;
}
Expand All @@ -527,12 +530,12 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
ioq_cleanup(&s->ioqueue);

aio_set_event_notifier(s->ctx, &s->host_notifier, NULL, NULL);
s->vdev->binding->set_host_notifier(s->vdev->binding_opaque, 0, false);
k->set_host_notifier(qbus->parent, 0, false);

aio_context_unref(s->ctx);

/* Clean up guest notifier (irq) */
s->vdev->binding->set_guest_notifiers(s->vdev->binding_opaque, 1, false);
k->set_guest_notifiers(qbus->parent, 1, false);

vring_teardown(&s->vring);
s->started = false;
Expand Down
17 changes: 10 additions & 7 deletions hw/net/vhost_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <stdio.h>

#include "hw/virtio/vhost.h"
#include "hw/virtio/virtio-bus.h"

struct vhost_net {
struct vhost_dev dev;
Expand Down Expand Up @@ -211,9 +212,12 @@ static void vhost_net_stop_one(struct vhost_net *net,
int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
int total_queues)
{
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
int r, i = 0;

if (!dev->binding->set_guest_notifiers) {
if (!k->set_guest_notifiers) {
error_report("binding does not support guest notifiers");
r = -ENOSYS;
goto err;
Expand All @@ -227,9 +231,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
}
}

r = dev->binding->set_guest_notifiers(dev->binding_opaque,
total_queues * 2,
true);
r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
if (r < 0) {
error_report("Error binding guest notifier: %d", -r);
goto err;
Expand All @@ -247,11 +249,12 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
int total_queues)
{
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
int i, r;

r = dev->binding->set_guest_notifiers(dev->binding_opaque,
total_queues * 2,
false);
r = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
if (r < 0) {
fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
fflush(stderr);
Expand Down
8 changes: 0 additions & 8 deletions hw/s390x/s390-virtio-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,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 */
Expand Down Expand Up @@ -140,7 +138,6 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)

bus->dev_offs += dev_len;

virtio_bind_device(vdev, &virtio_s390_bindings, DEVICE(dev));
dev->host_features = virtio_bus_get_vdev_features(&dev->bus,
dev->host_features);
s390_virtio_device_sync(dev);
Expand Down Expand Up @@ -466,11 +463,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, vdev.nic_conf),
DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device, host_features),
Expand Down
8 changes: 0 additions & 8 deletions hw/s390x/virtio-ccw.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ static const TypeInfo virtual_css_bus_info = {
.class_init = virtual_css_bus_class_init,
};

static const VirtIOBindings virtio_ccw_bindings;

VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
{
VirtIODevice *vdev = NULL;
Expand Down Expand Up @@ -521,7 +519,6 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
sch->id.cu_model = dev->vdev->device_id;

virtio_bind_device(vdev, &virtio_ccw_bindings, DEVICE(dev));
/* Only the first 32 feature bits are used. */
dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
dev->host_features[0]);
Expand Down Expand Up @@ -777,11 +774,6 @@ static void virtio_ccw_reset(DeviceState *d)

/**************** Virtio-ccw Bus Device Descriptions *******************/

static const VirtIOBindings virtio_ccw_bindings = {
.notify = virtio_ccw_notify,
.get_features = virtio_ccw_get_features,
};

static Property virtio_ccw_net_properties[] = {
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice, host_features[0]),
Expand Down
14 changes: 9 additions & 5 deletions hw/scsi/vhost-scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "hw/virtio/vhost-scsi.h"
#include "hw/virtio/vhost.h"
#include "hw/virtio/virtio-scsi.h"
#include "hw/virtio/virtio-bus.h"

static int vhost_scsi_set_endpoint(VHostSCSI *s)
{
Expand Down Expand Up @@ -52,8 +53,10 @@ static int vhost_scsi_start(VHostSCSI *s)
{
int ret, abi_version, i;
VirtIODevice *vdev = VIRTIO_DEVICE(s);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);

if (!vdev->binding->set_guest_notifiers) {
if (!k->set_guest_notifiers) {
error_report("binding does not support guest notifiers");
return -ENOSYS;
}
Expand Down Expand Up @@ -88,7 +91,7 @@ static int vhost_scsi_start(VHostSCSI *s)
goto err_vhost_stop;
}

ret = vdev->binding->set_guest_notifiers(vdev->binding_opaque, s->dev.nvqs, true);
ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true);
if (ret < 0) {
error_report("Error binding guest notifier");
goto err_endpoint;
Expand Down Expand Up @@ -116,11 +119,12 @@ static int vhost_scsi_start(VHostSCSI *s)
static void vhost_scsi_stop(VHostSCSI *s)
{
VirtIODevice *vdev = VIRTIO_DEVICE(s);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int ret = 0;

if (!vdev->binding->set_guest_notifiers) {
ret = vdev->binding->set_guest_notifiers(vdev->binding_opaque,
s->dev.nvqs, false);
if (!k->set_guest_notifiers) {
ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
if (ret < 0) {
error_report("vhost guest notifier cleanup failed: %d\n", ret);
}
Expand Down
31 changes: 18 additions & 13 deletions hw/virtio/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qemu/range.h"
#include <linux/vhost.h>
#include "exec/address-spaces.h"
#include "hw/virtio/virtio-bus.h"

static void vhost_dev_sync_region(struct vhost_dev *dev,
MemoryRegionSection *section,
Expand Down Expand Up @@ -892,27 +893,32 @@ 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.
* Start processing them in vhost in kernel.
*/
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,
hdev->vq_index + i,
true);
r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true);
if (r < 0) {
fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r);
goto fail_vq;
Expand All @@ -922,9 +928,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,
hdev->vq_index + i,
false);
r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false);
if (r < 0) {
fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r);
fflush(stderr);
Expand All @@ -942,12 +946,13 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
*/
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,
hdev->vq_index + i,
false);
r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false);
if (r < 0) {
fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r);
fflush(stderr);
Expand Down
17 changes: 0 additions & 17 deletions hw/virtio/virtio-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 0 additions & 13 deletions hw/virtio/virtio-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,19 +879,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,
};

#ifdef CONFIG_VIRTFS
static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
{
Expand Down
Loading

0 comments on commit 1c81944

Please sign in to comment.