From d043e2db87a3d9725a8cbc86cfee61039df65f77 Mon Sep 17 00:00:00 2001 From: Xie Yongji Date: Mon, 23 May 2022 16:46:11 +0800 Subject: libvduse: Add support for reconnecting To support reconnecting after restart or crash, VDUSE backend might need to resubmit inflight I/Os. This stores the metadata such as the index of inflight I/O's descriptors to a shm file so that VDUSE backend can restore them during reconnecting. Signed-off-by: Xie Yongji Message-Id: <20220523084611.91-9-xieyongji@bytedance.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/export/vduse-blk.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'block') diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c index cab1904..251d73c 100644 --- a/block/export/vduse-blk.c +++ b/block/export/vduse-blk.c @@ -30,6 +30,7 @@ typedef struct VduseBlkExport { VirtioBlkHandler handler; VduseDev *dev; uint16_t num_queues; + char *recon_file; unsigned int inflight; } VduseBlkExport; @@ -125,6 +126,8 @@ static void vduse_blk_enable_queue(VduseDev *dev, VduseVirtq *vq) aio_set_fd_handler(vblk_exp->export.ctx, vduse_queue_get_fd(vq), true, on_vduse_vq_kick, NULL, NULL, NULL, vq); + /* Make sure we don't miss any kick afer reconnecting */ + eventfd_write(vduse_queue_get_fd(vq), 1); } static void vduse_blk_disable_queue(VduseDev *dev, VduseVirtq *vq) @@ -306,6 +309,15 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, return -ENOMEM; } + vblk_exp->recon_file = g_strdup_printf("%s/vduse-blk-%s", + g_get_tmp_dir(), exp->id); + if (vduse_set_reconnect_log_file(vblk_exp->dev, vblk_exp->recon_file)) { + error_setg(errp, "failed to set reconnect log file"); + vduse_dev_destroy(vblk_exp->dev); + g_free(vblk_exp->recon_file); + return -EINVAL; + } + for (i = 0; i < num_queues; i++) { vduse_dev_setup_queue(vblk_exp->dev, i, queue_size); } @@ -324,11 +336,16 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, static void vduse_blk_exp_delete(BlockExport *exp) { VduseBlkExport *vblk_exp = container_of(exp, VduseBlkExport, export); + int ret; blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, vblk_exp); blk_set_dev_ops(exp->blk, NULL, NULL); - vduse_dev_destroy(vblk_exp->dev); + ret = vduse_dev_destroy(vblk_exp->dev); + if (ret != -EBUSY) { + unlink(vblk_exp->recon_file); + } + g_free(vblk_exp->recon_file); } static void vduse_blk_exp_request_shutdown(BlockExport *exp) -- cgit v1.1