From: Maxime Coquelin Date: Wed, 13 Dec 2017 08:51:08 +0000 (+0100) Subject: vhost: extract virtqueue cleaning and freeing functions X-Git-Tag: spdx-start~513 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=467fe22df94b85d2df67b9be3ccbfb3dd72cdd6d;p=dpdk.git vhost: extract virtqueue cleaning and freeing functions This patch extracts needed code for vhost_user.c to be able to clean and free virtqueues unitary. Signed-off-by: Maxime Coquelin Acked-by: Laszlo Ersek Acked-by: Yuanhan Liu --- diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 4eb450cf17..5cc7cad60d 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -74,7 +74,7 @@ get_device(int vid) return dev; } -static void +void cleanup_vq(struct vhost_virtqueue *vq, int destroy) { if ((vq->callfd >= 0) && (destroy != 0)) @@ -98,6 +98,15 @@ cleanup_device(struct virtio_net *dev, int destroy) cleanup_vq(dev->virtqueue[i], destroy); } +void +free_vq(struct vhost_virtqueue *vq) +{ + rte_free(vq->shadow_used_ring); + rte_free(vq->batch_copy_elems); + rte_mempool_free(vq->iotlb_pool); + rte_free(vq); +} + /* * Release virtqueues and device memory. */ @@ -105,16 +114,9 @@ static void free_device(struct virtio_net *dev) { uint32_t i; - struct vhost_virtqueue *vq; - - for (i = 0; i < dev->nr_vring; i++) { - vq = dev->virtqueue[i]; - rte_free(vq->shadow_used_ring); - rte_free(vq->batch_copy_elems); - rte_mempool_free(vq->iotlb_pool); - rte_free(vq); - } + for (i = 0; i < dev->nr_vring; i++) + free_vq(dev->virtqueue[i]); rte_free(dev); } diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 8afb4265de..487aeddc4a 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -338,6 +338,9 @@ void cleanup_device(struct virtio_net *dev, int destroy); void reset_device(struct virtio_net *dev); void vhost_destroy_device(int); +void cleanup_vq(struct vhost_virtqueue *vq, int destroy); +void free_vq(struct vhost_virtqueue *vq); + int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx); void vhost_set_ifname(int, const char *if_name, unsigned int if_len);