From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 86CFC69FA for ; Fri, 13 May 2016 07:20:06 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 12 May 2016 22:20:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,612,1455004800"; d="scan'208";a="805314792" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by orsmga003.jf.intel.com with ESMTP; 12 May 2016 22:20:04 -0700 From: Yuanhan Liu To: dev@dpdk.org Cc: Thomas Monjalon , huawei.xie@intel.com, Panu Matilainen , Tetsuya Mukawa , Traynor Kevin , Rich Lane , Yuanhan Liu Date: Thu, 12 May 2016 22:24:54 -0700 Message-Id: <1463117111-27050-3-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1462227927-22853-1-git-send-email-yuanhan.liu@linux.intel.com> <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH v2 02/19] vhost: set/reset dev flags internally X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2016 05:20:07 -0000 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 --- drivers/net/vhost/rte_eth_vhost.c | 2 -- examples/vhost/main.c | 3 --- lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++---- lib/librte_vhost/virtio-net.c | 21 ++++++++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 310cbef..63538c1 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -278,7 +278,6 @@ new_device(struct virtio_net *dev) for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++) rte_vhost_enable_guest_notification(dev, i, 0); - dev->flags |= VIRTIO_DEV_RUNNING; dev->priv = eth_dev; eth_dev->data->dev_link.link_status = ETH_LINK_UP; @@ -341,7 +340,6 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status = ETH_LINK_DOWN; dev->priv = NULL; - dev->flags &= ~VIRTIO_DEV_RUNNING; for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i]; diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 32a79be..ffc7209 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -1179,8 +1179,6 @@ destroy_device (volatile struct virtio_net *dev) struct vhost_dev *vdev; int lcore; - dev->flags &= ~VIRTIO_DEV_RUNNING; - vdev = (struct vhost_dev *)dev->priv; /*set the remove flag. */ vdev->remove = 1; @@ -1257,7 +1255,6 @@ new_device (struct virtio_net *dev) /* Disable notifications. */ rte_vhost_enable_guest_notification(dev, VIRTIO_RXQ, 0); rte_vhost_enable_guest_notification(dev, VIRTIO_TXQ, 0); - dev->flags |= VIRTIO_DEV_RUNNING; RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Device has been added to data core %d\n", dev->device_fh, vdev->coreid); 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; } -- 1.9.0