From 67cdaea00cd6ec72dc05386b80525157a9cf2018 Mon Sep 17 00:00:00 2001 From: Xueming Li Date: Thu, 27 Jan 2022 16:45:35 +0800 Subject: [PATCH] vhost: add vDPA resource cleanup callback This patch adds vDPA device cleanup callback to release resources on vhost user connection close. Signed-off-by: Xueming Li Reviewed-by: Maxime Coquelin --- lib/vhost/vdpa_driver.h | 3 +++ lib/vhost/vhost_user.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/vhost/vdpa_driver.h b/lib/vhost/vdpa_driver.h index fc2d6acedd..fddbd50652 100644 --- a/lib/vhost/vdpa_driver.h +++ b/lib/vhost/vdpa_driver.h @@ -34,6 +34,9 @@ struct rte_vdpa_dev_ops { /** Driver close the device (Mandatory) */ int (*dev_close)(int vid); + /** Connection closed, clean up resources */ + int (*dev_cleanup)(int vid); + /** Enable/disable this vring (Mandatory) */ int (*set_vring_state)(int vid, int vring, int state); diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 2e2417b0b9..7a6fd87dd9 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -219,6 +219,12 @@ free_mem_region(struct virtio_net *dev) void vhost_backend_cleanup(struct virtio_net *dev) { + struct rte_vdpa_device *vdpa_dev; + + vdpa_dev = dev->vdpa_dev; + if (vdpa_dev && vdpa_dev->ops->dev_cleanup != NULL) + vdpa_dev->ops->dev_cleanup(dev->vid); + if (dev->mem) { free_mem_region(dev); rte_free(dev->mem); -- 2.20.1