mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
Kernel: Merge NVME Queue complete_current_request implementations
Most of the actual logic is identical, with the only real difference being that one wraps it with an async work item. Merge the implementations to reduce duplications (which will also require the fixes in the next commits to only be done once).
This commit is contained in:
parent
4fbc701721
commit
a957907f4b
5 changed files with 40 additions and 72 deletions
|
@ -43,40 +43,7 @@ void NVMeInterruptQueue::submit_sqe(NVMeSubmission& sub)
|
|||
void NVMeInterruptQueue::complete_current_request(u16 cmdid, u16 status)
|
||||
{
|
||||
auto work_item_creation_result = g_io_work->try_queue([this, cmdid, status]() {
|
||||
SpinlockLocker lock(m_request_lock);
|
||||
auto& request_pdu = m_requests.get(cmdid).release_value();
|
||||
auto current_request = request_pdu.request;
|
||||
AsyncDeviceRequest::RequestResult req_result = AsyncDeviceRequest::Success;
|
||||
|
||||
ScopeGuard guard = [req_result, status, &request_pdu, &lock] {
|
||||
// FIXME: We should unlock at the end of this function to make sure no new requests is inserted
|
||||
// before we complete the request and calling end_io_handler but that results in a deadlock
|
||||
// For now this is avoided by asserting the `used` field while inserting.
|
||||
lock.unlock();
|
||||
if (request_pdu.request)
|
||||
request_pdu.request->complete(req_result);
|
||||
if (request_pdu.end_io_handler)
|
||||
request_pdu.end_io_handler(status);
|
||||
request_pdu.clear();
|
||||
};
|
||||
|
||||
// There can be submission without any request associated with it such as with
|
||||
// admin queue commands during init. If there is no request, we are done
|
||||
if (!current_request)
|
||||
return;
|
||||
|
||||
if (status) {
|
||||
req_result = AsyncBlockDeviceRequest::Failure;
|
||||
return;
|
||||
}
|
||||
|
||||
if (current_request->request_type() == AsyncBlockDeviceRequest::RequestType::Read) {
|
||||
if (auto result = current_request->write_to_buffer(current_request->buffer(), m_rw_dma_region->vaddr().as_ptr(), current_request->buffer_size()); result.is_error()) {
|
||||
req_result = AsyncBlockDeviceRequest::MemoryFault;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
NVMeQueue::complete_current_request(cmdid, status);
|
||||
});
|
||||
|
||||
if (work_item_creation_result.is_error()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue