[dpdk-dev,RFC,v2,11/12] lib/librte_vhost: kick/callfd fix
Commit Message
Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
lib/librte_vhost/vhost_user/virtio-net-user.c | 4 ++--
lib/librte_vhost/virtio-net.c | 13 +++++++++++--
2 files changed, 13 insertions(+), 4 deletions(-)
@@ -274,11 +274,11 @@ user_get_vring_base(struct vhost_device_ctx ctx,
* sent and only sent in vhost_vring_stop.
* TODO: cleanup the vring, it isn't usable since here.
*/
- if (dev->virtqueue[VIRTIO_RXQ]->callfd) {
+ if ((int)dev->virtqueue[VIRTIO_RXQ]->callfd >=0) {
close(dev->virtqueue[VIRTIO_RXQ]->callfd);
dev->virtqueue[VIRTIO_RXQ]->callfd = (eventfd_t)-1;
}
- if (dev->virtqueue[VIRTIO_TXQ]->callfd) {
+ if ((int)dev->virtqueue[VIRTIO_TXQ]->callfd >=0) {
close(dev->virtqueue[VIRTIO_TXQ]->callfd);
dev->virtqueue[VIRTIO_TXQ]->callfd = (eventfd_t)-1;
}
@@ -253,6 +253,11 @@ init_device(struct virtio_net *dev)
memset(dev->virtqueue[VIRTIO_RXQ], 0, sizeof(struct vhost_virtqueue));
memset(dev->virtqueue[VIRTIO_TXQ], 0, sizeof(struct vhost_virtqueue));
+ dev->virtqueue[VIRTIO_RXQ]->kickfd = (eventfd_t)-1;
+ dev->virtqueue[VIRTIO_RXQ]->callfd = (eventfd_t)-1;
+ dev->virtqueue[VIRTIO_TXQ]->kickfd = (eventfd_t)-1;
+ dev->virtqueue[VIRTIO_TXQ]->callfd = (eventfd_t)-1;
+
/* Backends are set to -1 indicating an inactive device. */
dev->virtqueue[VIRTIO_RXQ]->backend = VIRTIO_DEV_STOPPED;
dev->virtqueue[VIRTIO_TXQ]->backend = VIRTIO_DEV_STOPPED;
@@ -615,8 +620,10 @@ set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
/* file->index refers to the queue index. The txq is 1, rxq is 0. */
vq = dev->virtqueue[file->index];
- if (vq->kickfd)
+ if ((int)vq->kickfd >=0) {
+ printf("close %d\n", (int)vq->kickfd);
close((int)vq->kickfd);
+ }
vq->kickfd = file->fd;
@@ -641,8 +648,10 @@ set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
/* file->index refers to the queue index. The txq is 1, rxq is 0. */
vq = dev->virtqueue[file->index];
- if (vq->callfd)
+ if ((int)vq->callfd >= 0) {
+ printf("close callfd %u\n", (int)vq->callfd);
close((int)vq->callfd);
+ }
vq->callfd = file->fd;
return 0;