scsi & virtio: Clean up IORequest usage.
* Use TransferredBytes() instead of assuming length. * Consolidate checks and invoke io hook instead of scheduler directly.
This commit is contained in:
@@ -748,32 +748,35 @@ cd_free(void* cookie)
|
||||
|
||||
|
||||
static status_t
|
||||
cd_read(void* cookie, off_t pos, void* buffer, size_t* _length)
|
||||
cd_io(void* cookie, io_request* request)
|
||||
{
|
||||
cd_handle* handle = (cd_handle*)cookie;
|
||||
size_t length = *_length;
|
||||
|
||||
if (handle->info->capacity == 0)
|
||||
if (handle->info->capacity == 0 || handle->info->io_scheduler == NULL) {
|
||||
notify_io_request(request, B_DEV_NO_MEDIA);
|
||||
return B_DEV_NO_MEDIA;
|
||||
}
|
||||
|
||||
return handle->info->io_scheduler->ScheduleRequest(request);
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
cd_read(void* cookie, off_t pos, void* buffer, size_t* _length)
|
||||
{
|
||||
size_t length = *_length;
|
||||
|
||||
IORequest request;
|
||||
status_t status = request.Init(pos, (addr_t)buffer, length, false, 0);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
if (handle->info->io_scheduler == NULL)
|
||||
return B_DEV_NO_MEDIA;
|
||||
|
||||
status = handle->info->io_scheduler->ScheduleRequest(&request);
|
||||
status = cd_io(cookie, &request);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
status = request.Wait(0, 0);
|
||||
if (status == B_OK)
|
||||
*_length = length;
|
||||
else
|
||||
dprintf("cd_read(): request.Wait() returned: %s\n", strerror(status));
|
||||
|
||||
*_length = request.TransferredBytes();
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -781,48 +784,23 @@ cd_read(void* cookie, off_t pos, void* buffer, size_t* _length)
|
||||
static status_t
|
||||
cd_write(void* cookie, off_t pos, const void* buffer, size_t* _length)
|
||||
{
|
||||
cd_handle* handle = (cd_handle*)cookie;
|
||||
size_t length = *_length;
|
||||
|
||||
if (handle->info->capacity == 0)
|
||||
return B_DEV_NO_MEDIA;
|
||||
|
||||
IORequest request;
|
||||
status_t status = request.Init(pos, (addr_t)buffer, length, true, 0);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
if (handle->info->io_scheduler == NULL)
|
||||
return B_DEV_NO_MEDIA;
|
||||
|
||||
status = handle->info->io_scheduler->ScheduleRequest(&request);
|
||||
status = cd_io(cookie, &request);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
status = request.Wait(0, 0);
|
||||
if (status == B_OK)
|
||||
*_length = length;
|
||||
else
|
||||
dprintf("cd_write(): request.Wait() returned: %s\n", strerror(status));
|
||||
|
||||
*_length = request.TransferredBytes();
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
cd_io(void* cookie, io_request* request)
|
||||
{
|
||||
cd_handle* handle = (cd_handle*)cookie;
|
||||
|
||||
if (handle->info->capacity == 0) {
|
||||
notify_io_request(request, B_DEV_NO_MEDIA);
|
||||
return B_DEV_NO_MEDIA;
|
||||
}
|
||||
|
||||
return handle->info->io_scheduler->ScheduleRequest(request);
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
cd_ioctl(void* cookie, uint32 op, void* buffer, size_t length)
|
||||
{
|
||||
|
||||
@@ -341,10 +341,9 @@ das_read(void* cookie, off_t pos, void* buffer, size_t* _length)
|
||||
return status;
|
||||
|
||||
status = request.Wait(0, 0);
|
||||
if (status == B_OK)
|
||||
*_length = length;
|
||||
else
|
||||
dprintf("das_read(): request.Wait() returned: %s\n", strerror(status));
|
||||
*_length = request.TransferredBytes();
|
||||
if (status != B_OK)
|
||||
dprintf("das_read: request.Wait() returned: %s\n", strerror(status));
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -366,10 +365,9 @@ das_write(void* cookie, off_t pos, const void* buffer, size_t* _length)
|
||||
return status;
|
||||
|
||||
status = request.Wait(0, 0);
|
||||
if (status == B_OK)
|
||||
*_length = length;
|
||||
else
|
||||
dprintf("das_write(): request.Wait() returned: %s\n", strerror(status));
|
||||
*_length = request.TransferredBytes();
|
||||
if (status != B_OK)
|
||||
dprintf("das_write: request.Wait() returned: %s\n", strerror(status));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -352,10 +352,9 @@ virtio_block_read(void* cookie, off_t pos, void* buffer, size_t* _length)
|
||||
return status;
|
||||
|
||||
status = request.Wait(0, 0);
|
||||
if (status == B_OK)
|
||||
*_length = length;
|
||||
else
|
||||
dprintf("read(): request.Wait() returned: %s\n", strerror(status));
|
||||
*_length = request.TransferredBytes();
|
||||
if (status != B_OK)
|
||||
dprintf("virtio_block_read: request.Wait() returned: %s\n", strerror(status));
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -379,10 +378,9 @@ virtio_block_write(void* cookie, off_t pos, const void* buffer,
|
||||
return status;
|
||||
|
||||
status = request.Wait(0, 0);
|
||||
if (status == B_OK)
|
||||
*_length = length;
|
||||
else
|
||||
dprintf("write(): request.Wait() returned: %s\n", strerror(status));
|
||||
*_length = request.TransferredBytes();
|
||||
if (status != B_OK)
|
||||
dprintf("virtio_block_write: request.Wait() returned: %s\n", strerror(status));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user