Skip to content

Commit d043e2d

Browse files
YongjiXiekevmw
authored andcommitted
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 <[email protected]> Message-Id: <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 9e4dea6 commit d043e2d

File tree

3 files changed

+260
-6
lines changed

3 files changed

+260
-6
lines changed

block/export/vduse-blk.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct VduseBlkExport {
3030
VirtioBlkHandler handler;
3131
VduseDev *dev;
3232
uint16_t num_queues;
33+
char *recon_file;
3334
unsigned int inflight;
3435
} VduseBlkExport;
3536

@@ -125,6 +126,8 @@ static void vduse_blk_enable_queue(VduseDev *dev, VduseVirtq *vq)
125126

126127
aio_set_fd_handler(vblk_exp->export.ctx, vduse_queue_get_fd(vq),
127128
true, on_vduse_vq_kick, NULL, NULL, NULL, vq);
129+
/* Make sure we don't miss any kick afer reconnecting */
130+
eventfd_write(vduse_queue_get_fd(vq), 1);
128131
}
129132

130133
static void vduse_blk_disable_queue(VduseDev *dev, VduseVirtq *vq)
@@ -306,6 +309,15 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
306309
return -ENOMEM;
307310
}
308311

312+
vblk_exp->recon_file = g_strdup_printf("%s/vduse-blk-%s",
313+
g_get_tmp_dir(), exp->id);
314+
if (vduse_set_reconnect_log_file(vblk_exp->dev, vblk_exp->recon_file)) {
315+
error_setg(errp, "failed to set reconnect log file");
316+
vduse_dev_destroy(vblk_exp->dev);
317+
g_free(vblk_exp->recon_file);
318+
return -EINVAL;
319+
}
320+
309321
for (i = 0; i < num_queues; i++) {
310322
vduse_dev_setup_queue(vblk_exp->dev, i, queue_size);
311323
}
@@ -324,11 +336,16 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
324336
static void vduse_blk_exp_delete(BlockExport *exp)
325337
{
326338
VduseBlkExport *vblk_exp = container_of(exp, VduseBlkExport, export);
339+
int ret;
327340

328341
blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach,
329342
vblk_exp);
330343
blk_set_dev_ops(exp->blk, NULL, NULL);
331-
vduse_dev_destroy(vblk_exp->dev);
344+
ret = vduse_dev_destroy(vblk_exp->dev);
345+
if (ret != -EBUSY) {
346+
unlink(vblk_exp->recon_file);
347+
}
348+
g_free(vblk_exp->recon_file);
332349
}
333350

334351
static void vduse_blk_exp_request_shutdown(BlockExport *exp)

0 commit comments

Comments
 (0)