From 6b289143525999ff2b7596a69fbec90c72a2108e Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Mon, 23 Nov 2026 01:43:48 +0300 Subject: [PATCH] Use the epoll-based client in qemu_driver when io_uring isn't available Without io_uring the driver created the client with vitastor_c_create_qemu(), which registers every OSD socket in QEMU's AioContext. It takes no options, so client_exit_on_error=0 couldn't be passed and a client start error (for example an unreachable etcd) did exit(1) in the QEMU process. And the AioContext is level-triggered, while the messenger works with edge-triggered events. Create the client with vitastor_c_create_epoll_json() from the same options instead and register only its epoll descriptor in the AioContext, through the code already used for the io_uring eventfd. Writeback stays disabled in this mode. --- src/client/qemu_driver.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/client/qemu_driver.c b/src/client/qemu_driver.c index b507e552..5a67260d 100644 --- a/src/client/qemu_driver.c +++ b/src/client/qemu_driver.c @@ -76,7 +76,9 @@ typedef struct VitastorRPC VitastorRPC; typedef struct VitastorClient { void *proxy; + // io_uring eventfd, or the epoll descriptor of the client when io_uring isn't available int uring_eventfd; + int use_epoll; int auto_loop; void *watch; @@ -271,6 +273,11 @@ static void vitastor_uring_handler(void *opaque) VitastorClient *client = (VitastorClient*)opaque; qemu_mutex_lock(&client->mutex); client->bh_uring_scheduled = 0; +#if VITASTOR_C_API_VERSION >= 3 + if (client->use_epoll) + vitastor_c_epoll_handle_events(client->proxy, 0); + else +#endif vitastor_c_uring_handle_events(client->proxy); qemu_mutex_unlock(&client->mutex); } @@ -468,6 +475,7 @@ static void universal_aio_set_fd_handler(AioContext *ctx, int fd, IOHandler *fd_ opaque); } +#if !defined VITASTOR_C_API_VERSION || VITASTOR_C_API_VERSION < 3 static void vitastor_aio_set_fd_handler(void *vcli, int fd, int unused1, IOHandler *fd_read, IOHandler *fd_write, void *unused2, void *opaque) { VitastorClient *client = (VitastorClient*)vcli; @@ -514,6 +522,7 @@ static void vitastor_aio_set_fd_handler(void *vcli, int fd, int unused1, IOHandl client->ctx, fd, fd_read ? vitastor_aio_fd_read : NULL, fd_write ? vitastor_aio_fd_write : NULL, fdd ); } +#endif #if defined VITASTOR_C_API_VERSION && VITASTOR_C_API_VERSION >= 2 typedef struct str_array @@ -670,7 +679,6 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E strarray_push_kv(&opt, "__version_check_buffer", version_buffer); client->proxy = vitastor_c_create_uring_json(opt.items, opt.len); client->auto_loop = 0; - strarray_free(&opt); if (client->proxy) { client->uring_eventfd = vitastor_c_uring_register_eventfd(client->proxy); @@ -695,13 +703,24 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E fprintf(stderr, "vitastor: failed to create io_uring: %s - I/O will be slower%s\n", strerror(errno), (flags & BDRV_O_NOCACHE ? "" : " and writeback cache will be disabled")); #endif +#if defined VITASTOR_C_API_VERSION && VITASTOR_C_API_VERSION >= 3 + // The client handles its sockets in its own epoll, QEMU only polls the epoll descriptor + strarray_push_kv(&opt, "client_writeback_allowed", "0"); + client->proxy = vitastor_c_create_epoll_json(opt.items, opt.len); + client->use_epoll = 1; + client->auto_loop = 1; + client->uring_eventfd = vitastor_c_epoll_get_fd(client->proxy); + universal_aio_set_fd_handler(client->ctx, client->uring_eventfd, vitastor_uring_handler, NULL, client); +#else client->uring_eventfd = -1; client->proxy = vitastor_c_create_qemu( vitastor_aio_set_fd_handler, client, client->config_path, client->etcd_host, client->etcd_prefix, client->use_rdma, client->rdma_device, client->rdma_port_num, client->rdma_gid_index, client->rdma_mtu, 0 ); +#endif #if defined VITASTOR_C_API_VERSION && VITASTOR_C_API_VERSION >= 2 } + strarray_free(&opt); #endif image = client->image = g_strdup(qdict_get_try_str(options, "image")); client->readonly = (flags & BDRV_O_RDWR) ? 1 : 0; -- 2.47.3