Add ring_loop

This commit is contained in:
Vitaliy Filippov
2019-11-05 02:12:04 +03:00
parent c959948c82
commit 351366d228
8 changed files with 190 additions and 23 deletions
+36
View File
@@ -3,6 +3,7 @@
blockstore::blockstore(spp::sparse_hash_map<std::string, std::string> & config, io_uring *ring)
{
this->ring = ring;
ring_data = (struct ring_data_t*)malloc(sizeof(ring_data_t) * ring->sq.ring_sz);
initialized = 0;
block_order = stoull(config["block_size_order"]);
block_size = 1 << block_order;
@@ -35,6 +36,7 @@ blockstore::blockstore(spp::sparse_hash_map<std::string, std::string> & config,
blockstore::~blockstore()
{
free(ring_data);
if (data_fd >= 0)
close(data_fd);
if (meta_fd >= 0 && meta_fd != data_fd)
@@ -43,6 +45,16 @@ blockstore::~blockstore()
close(journal_fd);
}
struct io_uring_sqe* blockstore::get_sqe()
{
struct io_uring_sqe* sqe = io_uring_get_sqe(ring);
if (sqe)
{
io_uring_sqe_set_data(sqe, ring_data + (sqe - ring->sq.sqes));
}
return sqe;
}
// must be called in the event loop until it returns 0
int blockstore::init_loop()
{
@@ -74,3 +86,27 @@ int blockstore::init_loop()
journal_init_reader = NULL;
return 0;
}
// main event loop
int blockstore::main_loop()
{
while (true)
{
struct io_uring_cqe *cqe;
io_uring_peek_cqe(ring, &cqe);
if (cqe)
{
struct ring_data *d = cqe->user_data;
if (d->source == SRC_BLOCKSTORE)
{
handle_event();
}
else
{
// someone else
}
io_uring_cqe_seen(ring, cqe);
}
}
return 0;
}