From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH 3/8] scsi-generic: bump SCSIRequest reference count until aio completion runs
Date: Tue, 25 Oct 2011 12:53:35 +0200 [thread overview]
Message-ID: <1319540020-32484-4-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1319540020-32484-1-git-send-email-pbonzini@redhat.com>
Same as before, but for scsi-generic.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-generic.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index b30cf09..ff738fd 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -113,6 +113,9 @@ static void scsi_command_complete(void *opaque, int ret)
r, r->req.tag, status);
scsi_req_complete(&r->req, status);
+ if (!r->req.io_canceled) {
+ scsi_req_unref(&r->req);
+ }
}
/* Cancel a pending data transfer. */
@@ -123,6 +126,11 @@ static void scsi_cancel_io(SCSIRequest *req)
DPRINTF("Cancel tag=0x%x\n", req->tag);
if (r->req.aiocb) {
bdrv_aio_cancel(r->req.aiocb);
+
+ /* This reference was left in by scsi_*_data. We take ownership of
+ * it independent of whether bdrv_aio_cancel completes the request
+ * or not. */
+ scsi_req_unref(&r->req);
}
r->req.aiocb = NULL;
}
@@ -183,6 +191,9 @@ static void scsi_read_complete(void * opaque, int ret)
bdrv_set_buffer_alignment(s->conf.bs, s->blocksize);
scsi_req_data(&r->req, len);
+ if (!r->req.io_canceled) {
+ scsi_req_unref(&r->req);
+ }
}
}
@@ -194,6 +205,9 @@ static void scsi_read_data(SCSIRequest *req)
int ret;
DPRINTF("scsi_read_data 0x%x\n", req->tag);
+
+ /* The request is used as the AIO opaque value, so add a ref. */
+ scsi_req_ref(&r->req);
if (r->len == -1) {
scsi_command_complete(r, 0);
return;
@@ -242,6 +256,8 @@ static void scsi_write_data(SCSIRequest *req)
return;
}
+ /* The request is used as the AIO opaque value, so add a ref. */
+ scsi_req_ref(&r->req);
ret = execute_command(s->conf.bs, r, SG_DXFER_TO_DEV, scsi_write_complete);
if (ret < 0) {
scsi_command_complete(r, ret);
@@ -285,6 +301,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *cmd)
g_free(r->buf);
r->buflen = 0;
r->buf = NULL;
+ /* The request is used as the AIO opaque value, so add a ref. */
+ scsi_req_ref(&r->req);
ret = execute_command(s->conf.bs, r, SG_DXFER_NONE, scsi_command_complete);
if (ret < 0) {
scsi_command_complete(r, ret);
--
1.7.6
next prev parent reply other threads:[~2011-10-25 10:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-25 10:53 [Qemu-devel] [PATCH 0/5] My remaining block/SCSI patches for 1.0 Paolo Bonzini
2011-10-25 10:53 ` [Qemu-devel] [PATCH 1/8] scsi: do not call transfer_data after canceling a request Paolo Bonzini
2011-10-25 10:53 ` [Qemu-devel] [PATCH 2/8] scsi-disk: bump SCSIRequest reference count until aio completion runs Paolo Bonzini
2011-10-25 10:53 ` Paolo Bonzini [this message]
2011-10-25 10:53 ` [Qemu-devel] [PATCH 4/8] scsi: push request restart to SCSIDevice Paolo Bonzini
2011-10-25 10:53 ` [Qemu-devel] [PATCH 5/8] scsi-disk: add scsi-block for device passthrough Paolo Bonzini
2011-10-28 17:04 ` Kevin Wolf
2011-10-25 10:53 ` [Qemu-devel] [PATCH 6/8] block: add eject request callback Paolo Bonzini
2011-10-28 17:21 ` Kevin Wolf
2011-10-29 7:46 ` Paolo Bonzini
2011-11-07 13:21 ` Markus Armbruster
2011-11-07 13:36 ` Paolo Bonzini
2011-11-07 13:49 ` Kevin Wolf
2011-11-07 13:56 ` Paolo Bonzini
2011-11-07 14:12 ` Kevin Wolf
2011-11-07 15:23 ` Markus Armbruster
2011-11-07 16:14 ` Paolo Bonzini
2011-11-07 16:50 ` [Qemu-devel] [PATCH 6/8 v2] " Paolo Bonzini
2011-11-08 13:18 ` Kevin Wolf
2011-10-25 10:53 ` [Qemu-devel] [PATCH 7/8] atapi: implement eject requests Paolo Bonzini
2011-10-25 10:53 ` [Qemu-devel] [PATCH 8/8] scsi-disk: " Paolo Bonzini
2011-10-27 11:45 ` [Qemu-devel] ping Re: [PATCH 0/5] My remaining block/SCSI patches for 1.0 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=1319540020-32484-4-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kwolf@redhat.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).