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
|
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;
|
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 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;
|
IORequest request;
|
||||||
status_t status = request.Init(pos, (addr_t)buffer, length, false, 0);
|
status_t status = request.Init(pos, (addr_t)buffer, length, false, 0);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (handle->info->io_scheduler == NULL)
|
status = cd_io(cookie, &request);
|
||||||
return B_DEV_NO_MEDIA;
|
|
||||||
|
|
||||||
status = handle->info->io_scheduler->ScheduleRequest(&request);
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = request.Wait(0, 0);
|
status = request.Wait(0, 0);
|
||||||
if (status == B_OK)
|
*_length = request.TransferredBytes();
|
||||||
*_length = length;
|
|
||||||
else
|
|
||||||
dprintf("cd_read(): request.Wait() returned: %s\n", strerror(status));
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,48 +784,23 @@ cd_read(void* cookie, off_t pos, void* buffer, size_t* _length)
|
|||||||
static status_t
|
static status_t
|
||||||
cd_write(void* cookie, off_t pos, const void* buffer, size_t* _length)
|
cd_write(void* cookie, off_t pos, const void* buffer, size_t* _length)
|
||||||
{
|
{
|
||||||
cd_handle* handle = (cd_handle*)cookie;
|
|
||||||
size_t length = *_length;
|
size_t length = *_length;
|
||||||
|
|
||||||
if (handle->info->capacity == 0)
|
|
||||||
return B_DEV_NO_MEDIA;
|
|
||||||
|
|
||||||
IORequest request;
|
IORequest request;
|
||||||
status_t status = request.Init(pos, (addr_t)buffer, length, true, 0);
|
status_t status = request.Init(pos, (addr_t)buffer, length, true, 0);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (handle->info->io_scheduler == NULL)
|
status = cd_io(cookie, &request);
|
||||||
return B_DEV_NO_MEDIA;
|
|
||||||
|
|
||||||
status = handle->info->io_scheduler->ScheduleRequest(&request);
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = request.Wait(0, 0);
|
status = request.Wait(0, 0);
|
||||||
if (status == B_OK)
|
*_length = request.TransferredBytes();
|
||||||
*_length = length;
|
|
||||||
else
|
|
||||||
dprintf("cd_write(): request.Wait() returned: %s\n", strerror(status));
|
|
||||||
|
|
||||||
return status;
|
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
|
static status_t
|
||||||
cd_ioctl(void* cookie, uint32 op, void* buffer, size_t length)
|
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;
|
return status;
|
||||||
|
|
||||||
status = request.Wait(0, 0);
|
status = request.Wait(0, 0);
|
||||||
if (status == B_OK)
|
*_length = request.TransferredBytes();
|
||||||
*_length = length;
|
if (status != B_OK)
|
||||||
else
|
dprintf("das_read: request.Wait() returned: %s\n", strerror(status));
|
||||||
dprintf("das_read(): request.Wait() returned: %s\n", strerror(status));
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -366,10 +365,9 @@ das_write(void* cookie, off_t pos, const void* buffer, size_t* _length)
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = request.Wait(0, 0);
|
status = request.Wait(0, 0);
|
||||||
if (status == B_OK)
|
*_length = request.TransferredBytes();
|
||||||
*_length = length;
|
if (status != B_OK)
|
||||||
else
|
dprintf("das_write: request.Wait() returned: %s\n", strerror(status));
|
||||||
dprintf("das_write(): request.Wait() returned: %s\n", strerror(status));
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,10 +352,9 @@ virtio_block_read(void* cookie, off_t pos, void* buffer, size_t* _length)
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = request.Wait(0, 0);
|
status = request.Wait(0, 0);
|
||||||
if (status == B_OK)
|
*_length = request.TransferredBytes();
|
||||||
*_length = length;
|
if (status != B_OK)
|
||||||
else
|
dprintf("virtio_block_read: request.Wait() returned: %s\n", strerror(status));
|
||||||
dprintf("read(): request.Wait() returned: %s\n", strerror(status));
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -379,10 +378,9 @@ virtio_block_write(void* cookie, off_t pos, const void* buffer,
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = request.Wait(0, 0);
|
status = request.Wait(0, 0);
|
||||||
if (status == B_OK)
|
*_length = request.TransferredBytes();
|
||||||
*_length = length;
|
if (status != B_OK)
|
||||||
else
|
dprintf("virtio_block_write: request.Wait() returned: %s\n", strerror(status));
|
||||||
dprintf("write(): request.Wait() returned: %s\n", strerror(status));
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user