From: Paolo Bonzini <pbonzini@redhat.com>
To: Eric Farman <farman@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/3] scsi/virtio-scsi: Properly flush I/Os inflight during an unplug
Date: Tue, 14 Jan 2014 15:45:42 +0100 [thread overview]
Message-ID: <52D54D96.4020909@redhat.com> (raw)
In-Reply-To: <1389709469-15111-2-git-send-email-farman@linux.vnet.ibm.com>
Il 14/01/2014 15:24, Eric Farman ha scritto:
> When an unplug is triggered via QMP, the routine scsi_req_cancel
> is called to cancel any outstanding requests. However, the I/Os
> themselves were instantiated via an asynchronous call that will
> drive scsi_*_complete routines after the unplug call stack finishes.
> As all references to the request have been released by the cancel
> thread, the scsi_*_complete routines experience a range of failures
> when it attempts to manipulate the released storage.
This should never happen. See scsi_req_cancel:
void scsi_req_cancel(SCSIRequest *req)
{
trace_scsi_req_cancel(req->dev->id, req->lun, req->tag);
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);
}
scsi_req_unref(req);
}
After req->ops->cancel_io returns, the following invariant must hold:
Any AIO callbacks will have been called before req->ops->cancel_io
returns, or they never will.
The invariant is also present in bdrv_aio_cancel, and should respected
at all levels: dma_aio_cancel in dma-helpers.c, thread_pool_cancel in
thread-pool.c, laio_cancel in block/linux-aio.c, and so on.
scsi_cancel_io (in hw/scsi/scsi-disk.c) is very careful in its handling
of reference counts and aiocb, with the exact purpose of triggering an
assertion failure if the invariant is not respected.
Now that I look more at the code, at least this patch is needed:
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index bce617c..ee1f5eb 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2306,6 +2306,7 @@ static const SCSIReqOps scsi_disk_emulate_reqops
.send_command = scsi_disk_emulate_command,
.read_data = scsi_disk_emulate_read_data,
.write_data = scsi_disk_emulate_write_data,
+ .cancel_io = scsi_cancel_io,
.get_buf = scsi_get_buf,
};
but it should only have an effect in very special cases, with commands
such as UNMAP, WRITE SAME or MODE SELECT.
Paolo
next prev parent reply other threads:[~2014-01-14 14:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-14 14:24 [Qemu-devel] [PATCH RFC 0/3] virtio-scsi unplug of active device Eric Farman
2014-01-14 14:24 ` [Qemu-devel] [PATCH 1/3] scsi/virtio-scsi: Properly flush I/Os inflight during an unplug Eric Farman
2014-01-14 14:45 ` Paolo Bonzini [this message]
2014-01-14 14:24 ` [Qemu-devel] [PATCH 2/3] scsi/virtio-scsi: Cleanup of I/Os that never started Eric Farman
2014-01-14 14:49 ` Paolo Bonzini
2014-01-14 16:08 ` Eric Farman
2014-01-14 14:24 ` [Qemu-devel] [PATCH 3/3] scsi/virtio-scsi: Prevent assertion on missed events Eric Farman
2014-01-14 14:31 ` Eric Farman
2014-01-14 14:47 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52D54D96.4020909@redhat.com \
--to=pbonzini@redhat.com \
--cc=farman@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).