From c42ac841ad1d0094d6f6173e4f8bb4f231f8962b Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 6 Apr 2021 15:55:02 +0100 Subject: call reset callback on losing client connection (#419) Give API users an opportunity to clean up when a client disconnects from the vfio-user socket. Signed-off-by: John Levon Reviewed-by: Thanos Makatos --- lib/libvfio-user.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/libvfio-user.c') diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index d9e58e0..b5c7739 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -567,7 +567,7 @@ handle_device_reset(vfu_ctx_t *vfu_ctx) { vfu_log(vfu_ctx, LOG_DEBUG, "Device reset called by client"); if (vfu_ctx->reset != NULL) { - return vfu_ctx->reset(vfu_ctx); + return vfu_ctx->reset(vfu_ctx, VFU_RESET_DEVICE); } return 0; } @@ -1112,6 +1112,10 @@ vfu_reset_ctx(vfu_ctx_t *vfu_ctx, const char *reason) { vfu_log(vfu_ctx, LOG_INFO, "%s: %s", __func__, reason); + if (vfu_ctx->reset != NULL) { + vfu_ctx->reset(vfu_ctx, VFU_RESET_LOST_CONN); + } + if (vfu_ctx->dma != NULL) { dma_controller_remove_regions(vfu_ctx->dma); } @@ -1413,10 +1417,8 @@ out: int vfu_setup_device_reset_cb(vfu_ctx_t *vfu_ctx, vfu_reset_cb_t *reset) { - assert(vfu_ctx != NULL); vfu_ctx->reset = reset; - return 0; } -- cgit v1.1