vhost_net_init will use VhostNetOptions to get all its arguments
vhost_dev_init will replace devfd and devpath with a single opaque argument. This is initialised with a file descriptor. When TAP is used (through vhost_net), open /dev/vhost-net and pass the fd as an opaque parameter in VhostNetOptions. The same applies to vhost-scsi - open /dev/vhost-scsi and pass the fd. Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com> Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
ed8b4afe5f
commit
81647a655f
@ -94,32 +94,34 @@ static int vhost_net_get_fd(NetClientState *backend)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
|
struct vhost_net *vhost_net_init(VhostNetOptions *options)
|
||||||
bool force)
|
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
struct vhost_net *net = g_malloc(sizeof *net);
|
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;
|
goto fail;
|
||||||
}
|
}
|
||||||
r = vhost_net_get_fd(backend);
|
|
||||||
|
r = vhost_net_get_fd(options->net_backend);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
net->nc = backend;
|
net->nc = options->net_backend;
|
||||||
net->dev.backend_features = qemu_has_vnet_hdr(backend) ? 0 :
|
net->dev.backend_features = qemu_has_vnet_hdr(options->net_backend) ? 0 :
|
||||||
(1 << VHOST_NET_F_VIRTIO_NET_HDR);
|
(1 << VHOST_NET_F_VIRTIO_NET_HDR);
|
||||||
net->backend = r;
|
net->backend = r;
|
||||||
|
|
||||||
net->dev.nvqs = 2;
|
net->dev.nvqs = 2;
|
||||||
net->dev.vqs = net->vqs;
|
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) {
|
if (r < 0) {
|
||||||
goto fail;
|
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))) {
|
sizeof(struct virtio_net_hdr_mrg_rxbuf))) {
|
||||||
net->dev.features &= ~(1 << VIRTIO_NET_F_MRG_RXBUF);
|
net->dev.features &= ~(1 << VIRTIO_NET_F_MRG_RXBUF);
|
||||||
}
|
}
|
||||||
@ -311,8 +313,7 @@ VHostNetState *get_vhost_net(NetClientState *nc)
|
|||||||
return vhost_net;
|
return vhost_net;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
|
struct vhost_net *vhost_net_init(VhostNetOptions *options)
|
||||||
bool force)
|
|
||||||
{
|
{
|
||||||
error_report("vhost-net support is not compiled in");
|
error_report("vhost-net support is not compiled in");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -210,6 +210,13 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
|
|||||||
error_setg(errp, "vhost-scsi: unable to parse vhostfd");
|
error_setg(errp, "vhost-scsi: unable to parse vhostfd");
|
||||||
return;
|
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);
|
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.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs);
|
||||||
s->dev.vq_index = 0;
|
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) {
|
if (ret < 0) {
|
||||||
error_setg(errp, "vhost-scsi: vhost initialization failed: %s",
|
error_setg(errp, "vhost-scsi: vhost initialization failed: %s",
|
||||||
strerror(-ret));
|
strerror(-ret));
|
||||||
|
@ -808,19 +808,13 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq)
|
|||||||
event_notifier_cleanup(&vq->masked_notifier);
|
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)
|
bool force)
|
||||||
{
|
{
|
||||||
uint64_t features;
|
uint64_t features;
|
||||||
int i, r;
|
int i, r;
|
||||||
if (devfd >= 0) {
|
hdev->control = (uintptr_t) opaque;;
|
||||||
hdev->control = devfd;
|
|
||||||
} else {
|
|
||||||
hdev->control = open(devpath, O_RDWR);
|
|
||||||
if (hdev->control < 0) {
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r = ioctl(hdev->control, VHOST_SET_OWNER, NULL);
|
r = ioctl(hdev->control, VHOST_SET_OWNER, NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -51,7 +51,7 @@ struct vhost_dev {
|
|||||||
hwaddr mem_changed_end_addr;
|
hwaddr mem_changed_end_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
bool force);
|
||||||
void vhost_dev_cleanup(struct vhost_dev *hdev);
|
void vhost_dev_cleanup(struct vhost_dev *hdev);
|
||||||
bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev);
|
bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev);
|
||||||
|
@ -6,7 +6,13 @@
|
|||||||
struct vhost_net;
|
struct vhost_net;
|
||||||
typedef struct vhost_net VHostNetState;
|
typedef struct vhost_net VHostNetState;
|
||||||
|
|
||||||
VHostNetState *vhost_net_init(NetClientState *backend, int devfd, bool force);
|
typedef struct VhostNetOptions {
|
||||||
|
NetClientState *net_backend;
|
||||||
|
void *opaque;
|
||||||
|
bool force;
|
||||||
|
} VhostNetOptions;
|
||||||
|
|
||||||
|
struct vhost_net *vhost_net_init(VhostNetOptions *options);
|
||||||
|
|
||||||
bool vhost_net_query(VHostNetState *net, VirtIODevice *dev);
|
bool vhost_net_query(VHostNetState *net, VirtIODevice *dev);
|
||||||
int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues);
|
int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues);
|
||||||
|
17
net/tap.c
17
net/tap.c
@ -594,6 +594,7 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
|||||||
int vnet_hdr, int fd)
|
int vnet_hdr, int fd)
|
||||||
{
|
{
|
||||||
TAPState *s;
|
TAPState *s;
|
||||||
|
int vhostfd;
|
||||||
|
|
||||||
s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
|
s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
@ -624,7 +625,10 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
|||||||
|
|
||||||
if (tap->has_vhost ? tap->vhost :
|
if (tap->has_vhost ? tap->vhost :
|
||||||
vhostfdname || (tap->has_vhostforce && tap->vhostforce)) {
|
vhostfdname || (tap->has_vhostforce && tap->vhostforce)) {
|
||||||
int vhostfd;
|
VhostNetOptions options;
|
||||||
|
|
||||||
|
options.net_backend = &s->nc;
|
||||||
|
options.force = tap->has_vhostforce && tap->vhostforce;
|
||||||
|
|
||||||
if (tap->has_vhostfd || tap->has_vhostfds) {
|
if (tap->has_vhostfd || tap->has_vhostfds) {
|
||||||
vhostfd = monitor_handle_fd_param(cur_mon, vhostfdname);
|
vhostfd = monitor_handle_fd_param(cur_mon, vhostfdname);
|
||||||
@ -632,11 +636,16 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vhostfd = -1;
|
vhostfd = open("/dev/vhost-net", O_RDWR);
|
||||||
|
if (vhostfd < 0) {
|
||||||
|
error_report("tap: open vhost char device failed: %s",
|
||||||
|
strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
options.opaque = (void *)(uintptr_t)vhostfd;
|
||||||
|
|
||||||
s->vhost_net = vhost_net_init(&s->nc, vhostfd,
|
s->vhost_net = vhost_net_init(&options);
|
||||||
tap->has_vhostforce && tap->vhostforce);
|
|
||||||
if (!s->vhost_net) {
|
if (!s->vhost_net) {
|
||||||
error_report("vhost-net requested but could not be initialized");
|
error_report("vhost-net requested but could not be initialized");
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user