From bac9e3483637357dedf3374d7449ac705eb41c8e Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 26 Oct 2023 18:06:56 +0300 Subject: [PATCH] Allow to create vitastor_c with plain epoll without uring :-) --- src/vitastor_c.cpp | 26 +++++++++++++++++++++++++- src/vitastor_c.h | 5 ++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/vitastor_c.cpp b/src/vitastor_c.cpp index 6e23bf49..a7397b35 100644 --- a/src/vitastor_c.cpp +++ b/src/vitastor_c.cpp @@ -186,12 +186,26 @@ vitastor_c *vitastor_c_create_uring_json(const char **options, int options_len) return self; } +vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len) +{ + json11::Json::object cfg; + for (int i = 0; i < options_len-1; i += 2) + { + cfg[options[i]] = std::string(options[i+1]); + } + json11::Json cfg_json(cfg); + vitastor_c *self = new vitastor_c; + self->epmgr = new epoll_manager_t(NULL); + self->cli = new cluster_client_t(NULL, self->epmgr->tfd, cfg_json); + return self; +} + void vitastor_c_destroy(vitastor_c *client) { delete client->cli; if (client->epmgr) delete client->epmgr; - else + else if (client->tfd) delete client->tfd; if (client->ringloop) delete client->ringloop; @@ -229,6 +243,16 @@ int vitastor_c_uring_has_work(vitastor_c *client) return client->ringloop->has_work(); } +int vitastor_c_epoll_get_fd(vitastor_c *client) +{ + return !client->ringloop && client->epmgr ? client->epmgr->get_fd() : -1; +} + +void vitastor_c_epoll_handle_events(vitastor_c *client, int timeout) +{ + return client->epmgr->handle_events(timeout); +} + void vitastor_c_read(vitastor_c *client, uint64_t inode, uint64_t offset, uint64_t len, struct iovec *iov, int iovcnt, VitastorReadHandler cb, void *opaque) { diff --git a/src/vitastor_c.h b/src/vitastor_c.h index 5cd8e8a4..258fdf85 100644 --- a/src/vitastor_c.h +++ b/src/vitastor_c.h @@ -7,7 +7,7 @@ #define VITASTOR_QEMU_PROXY_H // C API wrapper version -#define VITASTOR_C_API_VERSION 2 +#define VITASTOR_C_API_VERSION 3 #ifndef POOL_ID_BITS #define POOL_ID_BITS 16 @@ -40,6 +40,7 @@ vitastor_c *vitastor_c_create_qemu_uring(QEMUSetFDHandler *aio_set_fd_handler, v vitastor_c *vitastor_c_create_uring(const char *config_path, const char *etcd_host, const char *etcd_prefix, int use_rdma, const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu, int log_level); vitastor_c *vitastor_c_create_uring_json(const char **options, int options_len); +vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len); void vitastor_c_destroy(vitastor_c *client); int vitastor_c_is_ready(vitastor_c *client); int vitastor_c_uring_register_eventfd(vitastor_c *client); @@ -47,6 +48,8 @@ void vitastor_c_uring_wait_ready(vitastor_c *client); void vitastor_c_uring_handle_events(vitastor_c *client); void vitastor_c_uring_wait_events(vitastor_c *client); int vitastor_c_uring_has_work(vitastor_c *client); +int vitastor_c_epoll_get_fd(vitastor_c *client); +void vitastor_c_epoll_handle_events(vitastor_c *client, int timeout); void vitastor_c_read(vitastor_c *client, uint64_t inode, uint64_t offset, uint64_t len, struct iovec *iov, int iovcnt, VitastorReadHandler cb, void *opaque); void vitastor_c_write(vitastor_c *client, uint64_t inode, uint64_t offset, uint64_t len, uint64_t check_version,