diff mbox

[dpdk-dev,RFC,v2,11/12] lib/librte_vhost: kick/callfd fix

Message ID 1418247477-13920-12-git-send-email-huawei.xie@intel.com (mailing list archive)
State RFC, archived
Headers show

Commit Message

Huawei Xie Dec. 10, 2014, 9:37 p.m. UTC
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(-)
diff mbox

Patch

diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 3aecb17..4e49e9b 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -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;
 	}
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 0b49f1b..f37fed0 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -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;