diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 3cf571eea44ecf42de1b53fa3933cde2cefab299..dfce5fbeeb2b60e6432bb248b7a7ef9be7542166 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1107,8 +1107,12 @@ void scsi_req_continue(SCSIRequest *req) Once it completes, calling scsi_req_continue will restart I/O. */ void scsi_req_data(SCSIRequest *req, int len) { - trace_scsi_req_data(req->dev->id, req->lun, req->tag, len); - req->bus->info->transfer_data(req, len); + if (req->io_canceled) { + trace_scsi_req_data_canceled(req->dev->id, req->lun, req->tag, len); + } else { + trace_scsi_req_data(req->dev->id, req->lun, req->tag, len); + req->bus->info->transfer_data(req, len); + } } void scsi_req_print(SCSIRequest *req) @@ -1173,11 +1177,15 @@ void scsi_req_complete(SCSIRequest *req, int status) void scsi_req_cancel(SCSIRequest *req) { - if (req->ops->cancel_io) { - req->ops->cancel_io(req); + if (!req->enqueued) { + return; } scsi_req_ref(req); scsi_req_dequeue(req); + req->io_canceled = true; + if (req->ops->cancel_io) { + req->ops->cancel_io(req); + } if (req->bus->info->cancel) { req->bus->info->cancel(req); } @@ -1186,10 +1194,17 @@ void scsi_req_cancel(SCSIRequest *req) void scsi_req_abort(SCSIRequest *req, int status) { + if (!req->enqueued) { + return; + } + scsi_req_ref(req); + scsi_req_dequeue(req); + req->io_canceled = true; if (req->ops->cancel_io) { req->ops->cancel_io(req); } scsi_req_complete(req, status); + scsi_req_unref(req); } void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense) diff --git a/hw/scsi.h b/hw/scsi.h index 8ea744a39267ede4def7c25d7729a306998b099d..fcc345581df653d55da3d9214009067bbe870c2f 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -51,6 +51,7 @@ struct SCSIRequest { uint8_t sense[SCSI_SENSE_BUF_SIZE]; uint32_t sense_len; bool enqueued; + bool io_canceled; void *hba_private; QTAILQ_ENTRY(SCSIRequest) next; }; diff --git a/trace-events b/trace-events index a8880550b2d21de5cf9aa5cb7a6c5b353971ae67..56443af7274fb2b906a6dc1b288ba1ab6a05a567 100644 --- a/trace-events +++ b/trace-events @@ -278,6 +278,7 @@ usb_host_claim_port(int bus, int hub, int port) "bus %d, hub addr %d, port %d" # hw/scsi-bus.c scsi_req_alloc(int target, int lun, int tag) "target %d lun %d tag %d" scsi_req_data(int target, int lun, int tag, int len) "target %d lun %d tag %d len %d" +scsi_req_data_canceled(int target, int lun, int tag, int len) "target %d lun %d tag %d len %d" scsi_req_dequeue(int target, int lun, int tag) "target %d lun %d tag %d" scsi_req_continue(int target, int lun, int tag) "target %d lun %d tag %d" scsi_req_parsed(int target, int lun, int tag, int cmd, int mode, int xfer) "target %d lun %d tag %d command %d dir %d length %d"