summaryrefslogtreecommitdiff
path: root/lib/librte_vhost
diff options
context:
space:
mode:
authorYuanhan Liu <yuanhan.liu@linux.intel.com>2016-04-29 11:59:47 +0800
committerYuanhan Liu <yuanhan.liu@linux.intel.com>2016-06-22 06:10:54 +0200
commit550c9d27d1438c30a657016a0281fe8e7a133e53 (patch)
tree2a156a4fe34797f67c05984f5378aabbb933f3ee /lib/librte_vhost
parent092f1c2c77d1818a2534578379bd439699cc2296 (diff)
downloaddpdk-550c9d27d1438c30a657016a0281fe8e7a133e53.zip
dpdk-550c9d27d1438c30a657016a0281fe8e7a133e53.tar.gz
dpdk-550c9d27d1438c30a657016a0281fe8e7a133e53.tar.xz
vhost: set/reset device flags internally
It does not make sense to ask the application to set/unset the flag VIRTIO_DEV_RUNNING (that used internal only) at new_device()/ destroy_device() callback. Instead, it should be set after new_device() succeeds and reset before destroy_device() is invoked inside vhost lib. This patch fixes it. Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> Tested-by: Rich Lane <rich.lane@bigswitch.com> Acked-by: Rich Lane <rich.lane@bigswitch.com>
Diffstat (limited to 'lib/librte_vhost')
-rw-r--r--lib/librte_vhost/vhost_user/virtio-net-user.c11
-rw-r--r--lib/librte_vhost/virtio-net.c21
2 files changed, 21 insertions, 11 deletions
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index f5248bc..e775e45 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -115,8 +115,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
return -1;
/* Remove from the data plane. */
- if (dev->flags & VIRTIO_DEV_RUNNING)
+ if (dev->flags & VIRTIO_DEV_RUNNING) {
+ dev->flags &= ~VIRTIO_DEV_RUNNING;
notify_ops->destroy_device(dev);
+ }
if (dev->mem) {
free_mem_region(dev);
@@ -286,9 +288,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
"vring kick idx:%d file:%d\n", file.index, file.fd);
vhost_set_vring_kick(ctx, &file);
- if (virtio_is_ready(dev) &&
- !(dev->flags & VIRTIO_DEV_RUNNING))
- notify_ops->new_device(dev);
+ if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
+ if (notify_ops->new_device(dev) == 0)
+ dev->flags |= VIRTIO_DEV_RUNNING;
+ }
}
/*
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 1a6259b..c45ed1c 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -296,8 +296,10 @@ vhost_destroy_device(struct vhost_device_ctx ctx)
if (dev == NULL)
return;
- if (dev->flags & VIRTIO_DEV_RUNNING)
+ if (dev->flags & VIRTIO_DEV_RUNNING) {
+ dev->flags &= ~VIRTIO_DEV_RUNNING;
notify_ops->destroy_device(dev);
+ }
cleanup_device(dev, 1);
free_device(dev);
@@ -353,8 +355,10 @@ vhost_reset_owner(struct vhost_device_ctx ctx)
if (dev == NULL)
return -1;
- if (dev->flags & VIRTIO_DEV_RUNNING)
+ if (dev->flags & VIRTIO_DEV_RUNNING) {
+ dev->flags &= ~VIRTIO_DEV_RUNNING;
notify_ops->destroy_device(dev);
+ }
cleanup_device(dev, 0);
reset_device(dev);
@@ -719,12 +723,15 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
if (dev->virtqueue[VIRTIO_TXQ]->backend != VIRTIO_DEV_STOPPED &&
dev->virtqueue[VIRTIO_RXQ]->backend != VIRTIO_DEV_STOPPED) {
- return notify_ops->new_device(dev);
+ if (notify_ops->new_device(dev) < 0)
+ return -1;
+ dev->flags |= VIRTIO_DEV_RUNNING;
}
- /* Otherwise we remove it. */
- } else
- if (file->fd == VIRTIO_DEV_STOPPED)
- notify_ops->destroy_device(dev);
+ } else if (file->fd == VIRTIO_DEV_STOPPED) {
+ dev->flags &= ~VIRTIO_DEV_RUNNING;
+ notify_ops->destroy_device(dev);
+ }
+
return 0;
}