Finish journal reader

This commit is contained in:
Vitaliy Filippov
2019-11-04 20:18:52 +03:00
parent e1c92d2227
commit c959948c82
5 changed files with 157 additions and 97 deletions
+47 -54
View File
@@ -1,5 +1,46 @@
#include "blockstore.h"
int blockstore::fulfill_read_push(blockstore_operation & read_op, uint32_t item_start,
uint32_t item_state, uint64_t item_version, uint64_t item_location, uint32_t cur_start, uint32_t cur_end)
{
if (cur_end > cur_start)
{
if (item_state == ST_IN_FLIGHT)
{
// Pause until it's written somewhere
read_op.wait_for = WAIT_IN_FLIGHT;
read_op.wait_version = item_version;
return -1;
}
else if (item_state == ST_DEL_WRITTEN || item_state == ST_DEL_SYNCED || item_state == ST_DEL_MOVED)
{
// item is unallocated - return zeroes
memset(read_op.buf + cur_start - read_op.offset, 0, cur_end - cur_start);
return 0;
}
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
if (!sqe)
{
// Pause until there are more requests available
read_op.wait_for = WAIT_SQE;
return -1;
}
read_op.read_vec[cur_start] = (struct iovec){
read_op.buf + cur_start - read_op.offset,
cur_end - cur_start
};
io_uring_prep_readv(
sqe,
IS_JOURNAL(item_state) ? journal_fd : data_fd,
// FIXME: &read_op.read_vec is forbidden
&read_op.read_vec[cur_start], 1,
(IS_JOURNAL(item_state) ? journal_offset : data_offset) + item_location + cur_start - item_start
);
io_uring_sqe_set_data(sqe, 0/*read op link*/);
}
return 0;
}
int blockstore::fulfill_read(blockstore_operation & read_op, uint32_t item_start, uint32_t item_end,
uint32_t item_state, uint64_t item_version, uint64_t item_location)
{
@@ -19,65 +60,16 @@ int blockstore::fulfill_read(blockstore_operation & read_op, uint32_t item_start
}
while (fulfill_near != read_op.read_vec.end() && fulfill_near->first < item_end)
{
if (fulfill_near->first > cur_start)
if (fulfill_read_push(read_op, item_start, item_state, item_version, item_location, cur_start, fulfill_near->first) < 0)
{
if (item_state == ST_IN_FLIGHT)
{
// Pause until it's written somewhere
read_op.wait_for = WAIT_IN_FLIGHT;
read_op.wait_version = item_version;
return -1;
}
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
if (!sqe)
{
// Pause until there are more requests available
read_op.wait_for = WAIT_SQE;
return -1;
}
read_op.read_vec[cur_start] = (struct iovec){
read_op.buf + cur_start - read_op.offset,
fulfill_near->first - cur_start
};
io_uring_prep_readv(
sqe,
IS_JOURNAL(item_state) ? journal_fd : data_fd,
// FIXME: &read_op.read_vec is forbidden
&read_op.read_vec[cur_start], 1,
(IS_JOURNAL(item_state) ? journal_offset : data_offset) + item_location + cur_start - item_start
);
io_uring_sqe_set_data(sqe, 0/*read op link*/);
return -1;
}
cur_start = fulfill_near->first + fulfill_near->second.iov_len;
fulfill_near++;
}
if (cur_start < item_end)
if (fulfill_read_push(read_op, item_start, item_state, item_version, item_location, cur_start, item_end) < 0)
{
if (item_state == ST_IN_FLIGHT)
{
// Pause until it's written somewhere
read_op.wait_for = WAIT_IN_FLIGHT;
read_op.wait_version = item_version;
return -1;
}
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
if (!sqe)
{
// Pause until there are more requests available
read_op.wait_for = WAIT_SQE;
return -1;
}
read_op.read_vec[cur_start] = (struct iovec){
read_op.buf + cur_start - read_op.offset,
item_end - cur_start
};
io_uring_prep_readv(
sqe,
IS_JOURNAL(item_state) ? journal_fd : data_fd,
&read_op.read_vec[cur_start], 1,
(IS_JOURNAL(item_state) ? journal_offset : data_offset) + item_location + cur_start - item_start
);
io_uring_sqe_set_data(sqe, 0/*read op link*/);
return -1;
}
}
return 0;
@@ -121,6 +113,7 @@ int blockstore::read(blockstore_operation *read_op)
// need to wait for something, undo added requests and requeue op
ring->sq.sqe_tail = prev_sqe_pos;
read_op->read_vec.clear();
// FIXME: bad implementation
submit_queue.push_front(read_op);
return 0;
}
@@ -128,11 +121,11 @@ int blockstore::read(blockstore_operation *read_op)
if (!read_op->read_vec.size())
{
// region is not allocated - return zeroes
free(read_op);
memset(read_op->buf, 0, read_op->len);
read_op->callback(read_op);
return 0;
}
// FIXME reap events!
int ret = io_uring_submit(ring);
if (ret < 0)
{