diff options
Diffstat (limited to 'hw')
-rw-r--r-- | hw/net/vhost_net.c | 23 | ||||
-rw-r--r-- | hw/scsi/vhost-scsi.c | 10 | ||||
-rw-r--r-- | hw/virtio/vhost.c | 12 |
3 files changed, 24 insertions, 21 deletions
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 0b45043..7a5523f 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -94,32 +94,34 @@ static int vhost_net_get_fd(NetClientState *backend) } } -struct vhost_net *vhost_net_init(NetClientState *backend, int devfd, - bool force) +struct vhost_net *vhost_net_init(VhostNetOptions *options) { int r; struct vhost_net *net = g_malloc(sizeof *net); - if (!backend) { - fprintf(stderr, "vhost-net requires backend to be setup\n"); + + if (!options->net_backend) { + fprintf(stderr, "vhost-net requires net backend to be setup\n"); goto fail; } - r = vhost_net_get_fd(backend); + + r = vhost_net_get_fd(options->net_backend); if (r < 0) { goto fail; } - net->nc = backend; - net->dev.backend_features = qemu_has_vnet_hdr(backend) ? 0 : + net->nc = options->net_backend; + net->dev.backend_features = qemu_has_vnet_hdr(options->net_backend) ? 0 : (1 << VHOST_NET_F_VIRTIO_NET_HDR); net->backend = r; net->dev.nvqs = 2; net->dev.vqs = net->vqs; - r = vhost_dev_init(&net->dev, devfd, "/dev/vhost-net", force); + r = vhost_dev_init(&net->dev, options->opaque, + options->force); if (r < 0) { goto fail; } - if (!qemu_has_vnet_hdr_len(backend, + if (!qemu_has_vnet_hdr_len(options->net_backend, sizeof(struct virtio_net_hdr_mrg_rxbuf))) { net->dev.features &= ~(1 << VIRTIO_NET_F_MRG_RXBUF); } @@ -311,8 +313,7 @@ VHostNetState *get_vhost_net(NetClientState *nc) return vhost_net; } #else -struct vhost_net *vhost_net_init(NetClientState *backend, int devfd, - bool force) +struct vhost_net *vhost_net_init(VhostNetOptions *options) { error_report("vhost-net support is not compiled in"); return NULL; diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index a12d888..e4c98b4 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -210,6 +210,13 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) error_setg(errp, "vhost-scsi: unable to parse vhostfd"); return; } + } else { + vhostfd = open("/dev/vhost-scsi", O_RDWR); + if (vhostfd < 0) { + error_setg(errp, "vhost-scsi: open vhost char device failed: %s", + strerror(errno)); + return; + } } virtio_scsi_common_realize(dev, &err); @@ -222,7 +229,8 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) s->dev.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs); s->dev.vq_index = 0; - ret = vhost_dev_init(&s->dev, vhostfd, "/dev/vhost-scsi", true); + ret = vhost_dev_init(&s->dev, (void *)(uintptr_t)vhostfd, + true); if (ret < 0) { error_setg(errp, "vhost-scsi: vhost initialization failed: %s", strerror(-ret)); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index a3e872d..0d3b7bb 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -808,19 +808,13 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq) event_notifier_cleanup(&vq->masked_notifier); } -int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath, +int vhost_dev_init(struct vhost_dev *hdev, void *opaque, bool force) { uint64_t features; int i, r; - if (devfd >= 0) { - hdev->control = devfd; - } else { - hdev->control = open(devpath, O_RDWR); - if (hdev->control < 0) { - return -errno; - } - } + hdev->control = (uintptr_t) opaque;; + r = ioctl(hdev->control, VHOST_SET_OWNER, NULL); if (r < 0) { goto fail; |