[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/13] scsi-disk: Use positive return value for status in dma_read
From: |
Kevin Wolf |
Subject: |
[PULL 04/13] scsi-disk: Use positive return value for status in dma_readv/writev |
Date: |
Mon, 5 Aug 2024 23:08:42 +0200 |
In some error cases, scsi_block_sgio_complete() never calls the passed
callback, but directly completes the request. This leads to bugs because
its error paths are not exact copies of what the callback would normally
do.
In preparation to fix this, allow passing positive return values to the
callbacks that represent the status code that should be used to complete
the request.
scsi_handle_rw_error() already handles positive values for its ret
parameter because scsi_block_sgio_complete() calls directly into it.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20240731123207.27636-2-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/scsi/scsi-disk.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index a67092db6a..3ff6798bde 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -65,6 +65,10 @@ OBJECT_DECLARE_TYPE(SCSIDiskState, SCSIDiskClass,
SCSI_DISK_BASE)
struct SCSIDiskClass {
SCSIDeviceClass parent_class;
+ /*
+ * Callbacks receive ret == 0 for success. Errors are represented either as
+ * negative errno values, or as positive SAM status codes.
+ */
DMAIOFunc *dma_readv;
DMAIOFunc *dma_writev;
bool (*need_fua_emulation)(SCSICommand *cmd);
@@ -283,7 +287,7 @@ static bool scsi_disk_req_check_error(SCSIDiskReq *r, int
ret, bool acct_failed)
return true;
}
- if (ret < 0) {
+ if (ret != 0) {
return scsi_handle_rw_error(r, ret, acct_failed);
}
@@ -360,7 +364,7 @@ static void scsi_write_do_fua(SCSIDiskReq *r)
static void scsi_dma_complete_noio(SCSIDiskReq *r, int ret)
{
assert(r->req.aiocb == NULL);
- if (scsi_disk_req_check_error(r, ret, false)) {
+ if (scsi_disk_req_check_error(r, ret, ret > 0)) {
goto done;
}
@@ -385,9 +389,10 @@ static void scsi_dma_complete(void *opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
+ /* ret > 0 is accounted for in scsi_disk_req_check_error() */
if (ret < 0) {
block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct);
- } else {
+ } else if (ret == 0) {
block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
}
scsi_dma_complete_noio(r, ret);
@@ -403,7 +408,7 @@ static void scsi_read_complete_noio(SCSIDiskReq *r, int ret)
qemu_get_current_aio_context());
assert(r->req.aiocb == NULL);
- if (scsi_disk_req_check_error(r, ret, false)) {
+ if (scsi_disk_req_check_error(r, ret, ret > 0)) {
goto done;
}
@@ -424,9 +429,10 @@ static void scsi_read_complete(void *opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
+ /* ret > 0 is accounted for in scsi_disk_req_check_error() */
if (ret < 0) {
block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct);
- } else {
+ } else if (ret == 0) {
block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
trace_scsi_disk_read_complete(r->req.tag, r->qiov.size);
}
@@ -534,7 +540,7 @@ static void scsi_write_complete_noio(SCSIDiskReq *r, int
ret)
qemu_get_current_aio_context());
assert (r->req.aiocb == NULL);
- if (scsi_disk_req_check_error(r, ret, false)) {
+ if (scsi_disk_req_check_error(r, ret, ret > 0)) {
goto done;
}
@@ -562,9 +568,10 @@ static void scsi_write_complete(void * opaque, int ret)
assert (r->req.aiocb != NULL);
r->req.aiocb = NULL;
+ /* ret > 0 is accounted for in scsi_disk_req_check_error() */
if (ret < 0) {
block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct);
- } else {
+ } else if (ret == 0) {
block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
}
scsi_write_complete_noio(r, ret);
--
2.45.2
- [PULL 00/13] Block layer patches, Kevin Wolf, 2024/08/05
- [PULL 01/13] qapi-block-core: Clean up blockdev-snapshot-internal-sync doc, Kevin Wolf, 2024/08/05
- [PULL 02/13] block-copy: Fix missing graph lock, Kevin Wolf, 2024/08/05
- [PULL 05/13] scsi-block: Don't skip callback for sgio error status/driver_status, Kevin Wolf, 2024/08/05
- [PULL 06/13] scsi-disk: Add warning comments that host_status errors take a shortcut, Kevin Wolf, 2024/08/05
- [PULL 03/13] block/graph-lock: Make WITH_GRAPH_RDLOCK_GUARD() fully checked, Kevin Wolf, 2024/08/05
- [PULL 04/13] scsi-disk: Use positive return value for status in dma_readv/writev,
Kevin Wolf <=
- [PULL 08/13] vvfat: Fix bug in writing to middle of file, Kevin Wolf, 2024/08/05
- [PULL 07/13] scsi-disk: Always report RESERVATION_CONFLICT to guest, Kevin Wolf, 2024/08/05
- [PULL 10/13] vvfat: Fix wrong checks for cluster mappings invariant, Kevin Wolf, 2024/08/05
- [PULL 09/13] vvfat: Fix usage of `info.file.offset`, Kevin Wolf, 2024/08/05
- [PULL 13/13] iotests/024: exclude 'backing file format' field from the output, Kevin Wolf, 2024/08/05
- [PULL 11/13] vvfat: Fix reading files with non-continuous clusters, Kevin Wolf, 2024/08/05
- [PULL 12/13] iotests: Add `vvfat` tests, Kevin Wolf, 2024/08/05
- Re: [PULL 00/13] Block layer patches, Richard Henderson, 2024/08/06