Begin implementation of enqueue/dequeue
This commit is contained in:
+62
-2
@@ -50,7 +50,7 @@ blockstore::~blockstore()
|
||||
// main event loop - handle requests
|
||||
void blockstore::handle_event(ring_data_t *data)
|
||||
{
|
||||
if (initialized != 0)
|
||||
if (initialized != 10)
|
||||
{
|
||||
if (metadata_init_reader)
|
||||
{
|
||||
@@ -119,6 +119,66 @@ void blockstore::loop()
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// try to submit ops
|
||||
auto op = submit_queue.begin();
|
||||
while (op != submit_queue.end())
|
||||
{
|
||||
auto cur = op++;
|
||||
if (((*cur)->flags & OP_TYPE_MASK) == OP_READ_DIRTY ||
|
||||
((*cur)->flags & OP_TYPE_MASK) == OP_READ)
|
||||
{
|
||||
int dequeue_op = dequeue_read(*cur);
|
||||
if (dequeue_op)
|
||||
{
|
||||
submit_queue.erase(cur);
|
||||
}
|
||||
else if ((*cur)->wait_for == WAIT_SQE)
|
||||
{
|
||||
// ring is full, stop submission
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int blockstore::enqueue_op(blockstore_operation *op)
|
||||
{
|
||||
if (op->offset >= block_size || op->len >= block_size-op->offset)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
submit_queue.push_back(op);
|
||||
if ((op->flags & OP_TYPE_MASK) == OP_WRITE)
|
||||
{
|
||||
// Assign version number
|
||||
auto dirty_it = dirty_queue.find(op->oid);
|
||||
if (dirty_it != dirty_queue.end())
|
||||
{
|
||||
op->version = (*dirty_it).back().version + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto clean_it = object_db.find(op->oid);
|
||||
if (clean_it != object_db.end())
|
||||
{
|
||||
op->version = (*clean_it).version + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
op->version = 1;
|
||||
}
|
||||
dirty_it = dirty_queue.emplace(op->oid, dirty_list()).first;
|
||||
}
|
||||
// Immediately add the operation into the dirty queue, so subsequent reads could see it
|
||||
(*dirty_it).push_back((dirty_entry){
|
||||
.version = op->version,
|
||||
.state = ST_IN_FLIGHT,
|
||||
.flags = 0,
|
||||
.location = 0,
|
||||
.offset = op->offset,
|
||||
.size = op->len,
|
||||
});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user