mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Make Device request creation return KResultOr
This allows us to propagate errors in a bunch of new places.
This commit is contained in:
parent
a01b19c878
commit
9669bf29f6
Notes:
sideshowbarker
2024-07-18 04:30:53 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9669bf29f61
4 changed files with 24 additions and 11 deletions
|
@ -30,7 +30,12 @@ BlockDevice::~BlockDevice()
|
|||
|
||||
bool BlockDevice::read_block(u64 index, UserOrKernelBuffer& buffer)
|
||||
{
|
||||
auto read_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index, 1, buffer, 512);
|
||||
auto read_request_or_error = try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index, 1, buffer, 512);
|
||||
if (read_request_or_error.is_error()) {
|
||||
dbgln("BlockDevice::read_block({}): try_make_request failed", index);
|
||||
return false;
|
||||
}
|
||||
auto read_request = read_request_or_error.release_value();
|
||||
switch (read_request->wait().request_result()) {
|
||||
case AsyncDeviceRequest::Success:
|
||||
return true;
|
||||
|
@ -51,7 +56,12 @@ bool BlockDevice::read_block(u64 index, UserOrKernelBuffer& buffer)
|
|||
|
||||
bool BlockDevice::write_block(u64 index, const UserOrKernelBuffer& buffer)
|
||||
{
|
||||
auto write_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index, 1, buffer, 512);
|
||||
auto write_request_or_error = try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index, 1, buffer, 512);
|
||||
if (write_request_or_error.is_error()) {
|
||||
dbgln("BlockDevice::write_block({}): try_make_request failed", index);
|
||||
return false;
|
||||
}
|
||||
auto write_request = write_request_or_error.release_value();
|
||||
switch (write_request->wait().request_result()) {
|
||||
case AsyncDeviceRequest::Success:
|
||||
return true;
|
||||
|
|
|
@ -48,9 +48,9 @@ public:
|
|||
void process_next_queued_request(Badge<AsyncDeviceRequest>, const AsyncDeviceRequest&);
|
||||
|
||||
template<typename AsyncRequestType, typename... Args>
|
||||
NonnullRefPtr<AsyncRequestType> make_request(Args&&... args)
|
||||
KResultOr<NonnullRefPtr<AsyncRequestType>> try_make_request(Args&&... args)
|
||||
{
|
||||
auto request = adopt_ref(*new AsyncRequestType(*this, forward<Args>(args)...));
|
||||
auto request = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AsyncRequestType(*this, forward<Args>(args)...)));
|
||||
SpinlockLocker lock(m_requests_lock);
|
||||
bool was_empty = m_requests.is_empty();
|
||||
m_requests.append(request);
|
||||
|
|
|
@ -33,8 +33,11 @@ const DiskPartitionMetadata& DiskPartition::metadata() const
|
|||
|
||||
void DiskPartition::start_request(AsyncBlockDeviceRequest& request)
|
||||
{
|
||||
request.add_sub_request(m_device->make_request<AsyncBlockDeviceRequest>(request.request_type(),
|
||||
request.block_index() + m_metadata.start_block(), request.block_count(), request.buffer(), request.buffer_size()));
|
||||
auto sub_request_or_error = m_device->try_make_request<AsyncBlockDeviceRequest>(request.request_type(),
|
||||
request.block_index() + m_metadata.start_block(), request.block_count(), request.buffer(), request.buffer_size());
|
||||
if (sub_request_or_error.is_error())
|
||||
TODO();
|
||||
request.add_sub_request(sub_request_or_error.release_value());
|
||||
}
|
||||
|
||||
KResultOr<size_t> DiskPartition::read(OpenFileDescription& fd, u64 offset, UserOrKernelBuffer& outbuf, size_t len)
|
||||
|
|
|
@ -55,7 +55,7 @@ KResultOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKe
|
|||
dbgln_if(STORAGE_DEVICE_DEBUG, "StorageDevice::read() index={}, whole_blocks={}, remaining={}", index, whole_blocks, remaining);
|
||||
|
||||
if (whole_blocks > 0) {
|
||||
auto read_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index, whole_blocks, outbuf, whole_blocks * block_size());
|
||||
auto read_request = TRY(try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index, whole_blocks, outbuf, whole_blocks * block_size()));
|
||||
auto result = read_request->wait();
|
||||
if (result.wait_result().was_interrupted())
|
||||
return EINTR;
|
||||
|
@ -78,7 +78,7 @@ KResultOr<size_t> StorageDevice::read(OpenFileDescription&, u64 offset, UserOrKe
|
|||
return ENOMEM;
|
||||
auto data = data_result.release_value();
|
||||
auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(data.data());
|
||||
auto read_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index + whole_blocks, 1, data_buffer, block_size());
|
||||
auto read_request = TRY(try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index + whole_blocks, 1, data_buffer, block_size()));
|
||||
auto result = read_request->wait();
|
||||
if (result.wait_result().was_interrupted())
|
||||
return EINTR;
|
||||
|
@ -122,7 +122,7 @@ KResultOr<size_t> StorageDevice::write(OpenFileDescription&, u64 offset, const U
|
|||
dbgln_if(STORAGE_DEVICE_DEBUG, "StorageDevice::write() index={}, whole_blocks={}, remaining={}", index, whole_blocks, remaining);
|
||||
|
||||
if (whole_blocks > 0) {
|
||||
auto write_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index, whole_blocks, inbuf, whole_blocks * block_size());
|
||||
auto write_request = TRY(try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index, whole_blocks, inbuf, whole_blocks * block_size()));
|
||||
auto result = write_request->wait();
|
||||
if (result.wait_result().was_interrupted())
|
||||
return EINTR;
|
||||
|
@ -148,7 +148,7 @@ KResultOr<size_t> StorageDevice::write(OpenFileDescription&, u64 offset, const U
|
|||
auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(data.data());
|
||||
|
||||
{
|
||||
auto read_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index + whole_blocks, 1, data_buffer, block_size());
|
||||
auto read_request = TRY(try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Read, index + whole_blocks, 1, data_buffer, block_size()));
|
||||
auto result = read_request->wait();
|
||||
if (result.wait_result().was_interrupted())
|
||||
return EINTR;
|
||||
|
@ -168,7 +168,7 @@ KResultOr<size_t> StorageDevice::write(OpenFileDescription&, u64 offset, const U
|
|||
TRY(inbuf.read(data.data(), pos, remaining));
|
||||
|
||||
{
|
||||
auto write_request = make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index + whole_blocks, 1, data_buffer, block_size());
|
||||
auto write_request = TRY(try_make_request<AsyncBlockDeviceRequest>(AsyncBlockDeviceRequest::Write, index + whole_blocks, 1, data_buffer, block_size()));
|
||||
auto result = write_request->wait();
|
||||
if (result.wait_result().was_interrupted())
|
||||
return EINTR;
|
||||
|
|
Loading…
Reference in a new issue