scsi: always call notifier on async cancellation
PATCH 1/1 scsi: always call notifier on async cancellation
This was found by code inspection. If the request is cancelled twice, the notifier is never called on the second cancellation request, and hence for example a TMF might never finish.
--- hw/scsi/scsi-bus.c | 3 --- 1 file changed, 3 deletions(-)
hw/scsi/scsi-bus.c +0 -3
@@ -1759,9 +1759,6 @@ void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier)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;
Signature · 1 line
2.5.0
Quoted 14 lines · Paolo Bonzini
This was found by code inspection. If the request is cancelled twice, the notifier is never called on the second cancellation request, and hence for example a TMF might never finish.
Signed-off-by Paolo Bonzini <[email protected]>--- hw/scsi/scsi-bus.c | 3 --- 1 file changed, 3 deletions(-)hw/scsi/scsi-bus.c +0
-0
hw/scsi/scsi-bus.c void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier) · line 1764
Quoted 9 lines
hw/scsi/scsi-bus.c +0
-3@@ -1759,9 +1759,6 @@ void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier)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) {
blk_aio_cancel_async(req->aiocb);
} else {
scsi_req_cancel_complete(req);
}A second TMF must be blk_aio_cancel_async case, otherwise the first one would have already completed the request synchronously in scsi_req_cancel_complete. With that in mind, I think returning early is not a problem. But I suppose these are also idempotent so this change is not breaking anything, either.
Fam
Quoted 9 lines · Fam Zheng
Quoted 9 lines
hw/scsi/scsi-bus.c void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier) · line 1764
Quoted 9 lines
if (notifier) { notifier_list_add(&req->cancel_notifiers, notifier); }hw/scsi/scsi-bus.c +0
-3-if (req->io_canceled) { -return ; - }scsi_req_ref (req);scsi_req_dequeue (req); req->io_canceled = true;
Quoted 8 lines
if (req->aiocb) { blk_aio_cancel_async(req->aiocb); } else { scsi_req_cancel_complete(req); }A second TMF must be
blk_aio_cancel_asynccase, otherwise the first one would have already completed the request synchronously inscsi_req_cancel_complete.
Good point.
Quoted 2 lines
With that in mind, I think returning early is not a problem. But I suppose these are also idempotent so this change is not breaking anything, either.
Right, the issue is that all these calls are idempotent, but the notifier may not; that is why I prefer to be safe and ensure that all notifier additions are matched by a notify. But you explained well why this should be safe, I'll add a note to the commit message.
Paolo
Fam Zheng
Reviewed-byQuoted 23 lines · Paolo Bonzini
Quoted 9 lines · Fam Zheng
Quoted 9 lines
hw/scsi/scsi-bus.c void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier) · line 1764
Quoted 9 lines
if (notifier) { notifier_list_add(&req->cancel_notifiers, notifier); }hw/scsi/scsi-bus.c +0
-3-if (req->io_canceled) { -return ; - }scsi_req_ref (req);scsi_req_dequeue (req); req->io_canceled = true;Quoted 8 lines
if (req->aiocb) { blk_aio_cancel_async(req->aiocb); } else { scsi_req_cancel_complete(req); }A second TMF must be
blk_aio_cancel_asynccase, otherwise the first one would have already completed the request synchronously inscsi_req_cancel_complete.Good point.
Quoted 8 lines
Quoted 2 lines
With that in mind, I think returning early is not a problem. But I suppose these are also idempotent so this change is not breaking anything, either.
Right, the issue is that all these calls are idempotent, but the notifier may not; that is why I prefer to be safe and ensure that all notifier additions are matched by a notify. But you explained well why this should be safe, I'll add a note to the commit message.
Thanks, please add my