From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:34538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIedk-0005W9-7i for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:53:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RIedf-0000Bn-Gc for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:53:52 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:49689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIede-0000Bd-UX for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:53:47 -0400 Received: by wyh15 with SMTP id 15so391093wyh.4 for ; Tue, 25 Oct 2011 03:53:46 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 25 Oct 2011 12:53:33 +0200 Message-Id: <1319540020-32484-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1319540020-32484-1-git-send-email-pbonzini@redhat.com> References: <1319540020-32484-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1/8] scsi: do not call transfer_data after canceling a request List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com Otherwise, if cancellation is "faked" by the AIO layer and goes through qemu_aio_flush, the whole request is completed synchronously during scsi_req_cancel. Using the enqueued flag would work here, but not in the next patches, so I'm introducing a new io_canceled flag. That's because scsi_req_data is a synchronous callback and the enqueued flag might be reset by the time it returns. scsi-disk cannot unref the request until after calling scsi_req_data. Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 23 +++++++++++++++++++---- hw/scsi.h | 1 + trace-events | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 72c0dd2..cd0c2cd 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 8ea744a..fcc3455 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 7f9cec4..148084e 100644 --- a/trace-events +++ b/trace-events @@ -277,6 +277,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" -- 1.7.6