[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 36/39] scsi: Introduce scsi_req_cancel_async
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 36/39] scsi: Introduce scsi_req_cancel_async |
Date: |
Tue, 30 Sep 2014 14:25:16 +0200 |
From: Fam Zheng <address@hidden>
Devices will call this function to start an asynchronous cancellation. The
bus->info->cancel will be called after the request is canceled.
Devices will probably need to track a separate TMF request that triggers this
cancellation, and wait until the cancellation is done before completing it. So
we store a notifier list in SCSIRequest and in scsi_req_cancel_complete we
notify them.
Signed-off-by: Fam Zheng <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/scsi-bus.c | 26 ++++++++++++++++++++++++++
include/hw/scsi/scsi.h | 3 +++
2 files changed, 29 insertions(+)
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index c91db63..0f3e039 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -566,6 +566,7 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops,
SCSIDevice *d,
req->ops = reqops;
object_ref(OBJECT(d));
object_ref(OBJECT(qbus->parent));
+ notifier_list_init(&req->cancel_notifiers);
trace_scsi_req_alloc(req->dev->id, req->lun, req->tag);
return req;
}
@@ -1715,6 +1716,9 @@ void scsi_req_complete(SCSIRequest *req, int status)
scsi_req_ref(req);
scsi_req_dequeue(req);
req->bus->info->complete(req, req->status, req->resid);
+
+ /* Cancelled requests might end up being completed instead of cancelled */
+ notifier_list_notify(&req->cancel_notifiers, req);
scsi_req_unref(req);
}
@@ -1725,9 +1729,31 @@ void scsi_req_cancel_complete(SCSIRequest *req)
if (req->bus->info->cancel) {
req->bus->info->cancel(req);
}
+ notifier_list_notify(&req->cancel_notifiers, req);
scsi_req_unref(req);
}
+/* Cancel @req asynchronously. @notifier is added to @req's cancellation
+ * notifier list, the bus will be notified the requests cancellation is
+ * completed.
+ * */
+void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier)
+{
+ trace_scsi_req_cancel(req->dev->id, req->lun, req->tag);
+ if (notifier) {
+ notifier_list_add(&req->cancel_notifiers, notifier);
+ }
+ if (req->io_canceled) {
+ return;
+ }
+ scsi_req_ref(req);
+ scsi_req_dequeue(req);
+ req->io_canceled = true;
+ if (req->aiocb) {
+ bdrv_aio_cancel_async(req->aiocb);
+ }
+}
+
void scsi_req_cancel(SCSIRequest *req)
{
trace_scsi_req_cancel(req->dev->id, req->lun, req->tag);
diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
index 2127a33..b61bedb 100644
--- a/include/hw/scsi/scsi.h
+++ b/include/hw/scsi/scsi.h
@@ -5,6 +5,7 @@
#include "block/block.h"
#include "hw/block/block.h"
#include "sysemu/sysemu.h"
+#include "qemu/notify.h"
#define MAX_SCSI_DEVS 255
@@ -53,6 +54,7 @@ struct SCSIRequest {
void *hba_private;
size_t resid;
SCSICommand cmd;
+ NotifierList cancel_notifiers;
/* Note:
* - fields before sense are initialized by scsi_req_alloc;
@@ -266,6 +268,7 @@ uint8_t *scsi_req_get_buf(SCSIRequest *req);
int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
void scsi_req_cancel_complete(SCSIRequest *req);
void scsi_req_cancel(SCSIRequest *req);
+void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier);
void scsi_req_retry(SCSIRequest *req);
void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense);
--
1.8.3.1
- [Qemu-devel] [PULL 28/39] virtio-scsi: Batched prepare for cmd reqs, (continued)
- [Qemu-devel] [PULL 28/39] virtio-scsi: Batched prepare for cmd reqs, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 29/39] virtio-scsi: Call bdrv_io_plug/bdrv_io_unplug in cmd request handling, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 30/39] virtio-scsi: Process ".iothread" property, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 31/39] scsi: Drop scsi_req_abort, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 33/39] scsi: Unify request unref in scsi_req_cancel, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 32/39] scsi-generic: Handle canceled request in scsi_command_complete, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 34/39] scsi: Drop SCSIReqOps.cancel_io, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 35/39] scsi: Introduce scsi_req_cancel_complete, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 38/39] util: introduce bitmap_try_new, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 39/39] block/iscsi: handle failure on malloc of the allocationmap, Paolo Bonzini, 2014/09/30
- [Qemu-devel] [PULL 36/39] scsi: Introduce scsi_req_cancel_async,
Paolo Bonzini <=
- [Qemu-devel] [PULL 37/39] virtio-scsi: Handle TMF request cancellation asynchronously, Paolo Bonzini, 2014/09/30
- Re: [Qemu-devel] [PULL 00/39] SCSI changes for 2014-09-23, Peter Maydell, 2014/09/30