From 2396806765e4b797dd30bc265126c2bbc1a879cc Mon Sep 17 00:00:00 2001 From: Tonghao Zhang Date: Wed, 13 Jun 2018 04:54:18 -0700 Subject: [PATCH] vhost: introduce new function helper Introduce an new common helper to avoid redundancy. Signed-off-by: Tonghao Zhang Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 27 +++++++++++++++++---------- lib/librte_vhost/vhost.h | 1 + lib/librte_vhost/vhost_user.c | 23 ++--------------------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 2f190d3ca3..13ce864db3 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -296,6 +296,22 @@ vhost_new_device(void) return i; } +void +vhost_destroy_device_notify(struct virtio_net *dev) +{ + struct rte_vdpa_device *vdpa_dev; + int did; + + if (dev->flags & VIRTIO_DEV_RUNNING) { + did = dev->vdpa_dev_id; + vdpa_dev = rte_vdpa_get_device(did); + if (vdpa_dev && vdpa_dev->ops->dev_close) + vdpa_dev->ops->dev_close(dev->vid); + dev->flags &= ~VIRTIO_DEV_RUNNING; + dev->notify_ops->destroy_device(dev->vid); + } +} + /* * Invoked when there is the vhost-user connection is broken (when * the virtio device is being detached). @@ -304,20 +320,11 @@ void vhost_destroy_device(int vid) { struct virtio_net *dev = get_device(vid); - struct rte_vdpa_device *vdpa_dev; - int did = -1; if (dev == NULL) return; - if (dev->flags & VIRTIO_DEV_RUNNING) { - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); - if (vdpa_dev && vdpa_dev->ops->dev_close) - vdpa_dev->ops->dev_close(dev->vid); - dev->flags &= ~VIRTIO_DEV_RUNNING; - dev->notify_ops->destroy_device(vid); - } + vhost_destroy_device_notify(dev); cleanup_device(dev, 1); free_device(dev); diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index b10ac124b8..588b7cf9a7 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -536,6 +536,7 @@ int vhost_new_device(void); void cleanup_device(struct virtio_net *dev, int destroy); void reset_device(struct virtio_net *dev); void vhost_destroy_device(int); +void vhost_destroy_device_notify(struct virtio_net *dev); void cleanup_vq(struct vhost_virtqueue *vq, int destroy); void free_vq(struct vhost_virtqueue *vq); diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index a28fc3495e..26cfebec07 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -135,17 +135,7 @@ vhost_user_set_owner(void) static int vhost_user_reset_owner(struct virtio_net *dev) { - struct rte_vdpa_device *vdpa_dev; - int did = -1; - - if (dev->flags & VIRTIO_DEV_RUNNING) { - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); - if (vdpa_dev && vdpa_dev->ops->dev_close) - vdpa_dev->ops->dev_close(dev->vid); - dev->flags &= ~VIRTIO_DEV_RUNNING; - dev->notify_ops->destroy_device(dev->vid); - } + vhost_destroy_device_notify(dev); cleanup_device(dev, 0); reset_device(dev); @@ -996,18 +986,9 @@ vhost_user_get_vring_base(struct virtio_net *dev, VhostUserMsg *msg) { struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index]; - struct rte_vdpa_device *vdpa_dev; - int did = -1; /* We have to stop the queue (virtio) if it is running. */ - if (dev->flags & VIRTIO_DEV_RUNNING) { - did = dev->vdpa_dev_id; - vdpa_dev = rte_vdpa_get_device(did); - if (vdpa_dev && vdpa_dev->ops->dev_close) - vdpa_dev->ops->dev_close(dev->vid); - dev->flags &= ~VIRTIO_DEV_RUNNING; - dev->notify_ops->destroy_device(dev->vid); - } + vhost_destroy_device_notify(dev); dev->flags &= ~VIRTIO_DEV_READY; dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED; -- 2.20.1