Use the epoll-based client in qemu_driver when io_uring isn't available #151
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user