From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fam Zheng <famz@redhat.com>
Subject: [Qemu-devel] [PULL 33/39] scsi: Unify request unref in scsi_req_cancel
Date: Tue, 30 Sep 2014 14:25:13 +0200 [thread overview]
Message-ID: <1412079919-18857-34-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1412079919-18857-1-git-send-email-pbonzini@redhat.com>
From: Fam Zheng <famz@redhat.com>
Before, scsi_req_cancel will take ownership of the canceled request and unref
it. We did this because we didn't know whether AIO CB will be called or not
during the cancelling, so we set the io_canceled flag before calling it, and
skip unref in the potentially called callbacks, which is not very nice.
Now, bdrv_aio_cancel has a stricter contract that the completion callbacks are
always called, so we can remove the checks of req->io_canceled and just unref
it in callbacks.
It will also make implementing asynchronous cancellation easier.
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/scsi-disk.c | 37 ++++++++-----------------------------
hw/scsi/scsi-generic.c | 13 ++-----------
2 files changed, 10 insertions(+), 40 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 9645d01..2e45752 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -113,11 +113,6 @@ 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 the moment scsi_req_cancel is called, independent of whether
- * bdrv_aio_cancel completes the request or not. */
- scsi_req_unref(&r->req);
}
r->req.aiocb = NULL;
}
@@ -197,9 +192,7 @@ static void scsi_aio_complete(void *opaque, int ret)
scsi_req_complete(&r->req, GOOD);
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
static bool scsi_is_cmd_fua(SCSICommand *cmd)
@@ -246,9 +239,7 @@ static void scsi_write_do_fua(SCSIDiskReq *r)
scsi_req_complete(&r->req, GOOD);
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
static void scsi_dma_complete_noio(void *opaque, int ret)
@@ -280,9 +271,7 @@ static void scsi_dma_complete_noio(void *opaque, int ret)
}
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
static void scsi_dma_complete(void *opaque, int ret)
@@ -320,9 +309,7 @@ static void scsi_read_complete(void * opaque, int ret)
scsi_req_data(&r->req, r->qiov.size);
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
/* Actually issue a read to the block device. */
@@ -363,9 +350,7 @@ static void scsi_do_read(void *opaque, int ret)
}
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
/* Read more data from scsi device into buffer. */
@@ -481,9 +466,7 @@ static void scsi_write_complete(void * opaque, int ret)
}
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
static void scsi_write_data(SCSIRequest *req)
@@ -1582,9 +1565,7 @@ static void scsi_unmap_complete(void *opaque, int ret)
scsi_req_complete(&r->req, GOOD);
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
g_free(data);
}
@@ -1678,9 +1659,7 @@ static void scsi_write_same_complete(void *opaque, int ret)
scsi_req_complete(&r->req, GOOD);
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
qemu_vfree(data->iov.iov_base);
g_free(data);
}
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 2a73a43..e92b418 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -137,9 +137,7 @@ static void scsi_command_complete(void *opaque, int ret)
scsi_req_complete(&r->req, status);
done:
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
/* Cancel a pending data transfer. */
@@ -150,11 +148,6 @@ 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;
}
@@ -214,9 +207,7 @@ static void scsi_read_complete(void * opaque, int ret)
bdrv_set_guest_block_size(s->conf.bs, s->blocksize);
scsi_req_data(&r->req, len);
- if (!r->req.io_canceled) {
- scsi_req_unref(&r->req);
- }
+ scsi_req_unref(&r->req);
}
}
--
1.8.3.1
next prev parent reply other threads:[~2014-09-30 12:26 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-30 12:24 [Qemu-devel] [PULL 00/39] SCSI changes for 2014-09-23 Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 01/39] scsi: Optimize scsi_req_alloc Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 02/39] virtio-scsi: Optimize virtio_scsi_init_req Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 03/39] vhost-scsi: use virtio_ldl_p Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 04/39] virtio-scsi: clean up virtio_scsi_parse_cdb Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 05/39] virtio-scsi: Split virtio_scsi_handle_cmd_req from virtio_scsi_handle_cmd Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 06/39] virtio-scsi: Split virtio_scsi_handle_ctrl_req from virtio_scsi_handle_ctrl Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 07/39] virtio-scsi: Make virtio_scsi_init_req public Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 08/39] virtio-scsi: Make virtio_scsi_free_req public Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 09/39] virtio-scsi: Make virtio_scsi_push_event public Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 10/39] virtio-net: use aliases instead of duplicate qdev properties Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 11/39] virtio-net: fix virtio-net child refcount in transports Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 12/39] virtio/vhost-scsi: use aliases instead of duplicate qdev properties Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 13/39] virtio/vhost-scsi: fix virtio-scsi/vhost-scsi child refcount in transports Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 14/39] virtio-serial: use aliases instead of duplicate qdev properties Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 15/39] virtio-serial: fix virtio-serial child refcount in transports Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 16/39] virtio-rng: use aliases instead of duplicate qdev properties Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 17/39] virtio-rng: fix virtio-rng child refcount in transports Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 18/39] virtio-balloon: fix virtio-balloon " Paolo Bonzini
2014-09-30 12:24 ` [Qemu-devel] [PULL 19/39] virtio-9p: use aliases instead of duplicate qdev properties Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 20/39] virtio-9p: fix virtio-9p child refcount in transports Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 21/39] virtio: add a wrapper for virtio-backend initialization Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 22/39] virtio-scsi: Add 'iothread' property to virtio-scsi Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 23/39] virtio-scsi: Add VirtIOSCSIVring in VirtIOSCSIReq Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 24/39] virtio-scsi-dataplane: Code to run virtio-scsi on iothread Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 25/39] virtio-scsi: Hook up with dataplane Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 26/39] virtio-scsi: Add migration state notifier for dataplane code Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 27/39] virtio-scsi: Two stages processing of cmd request Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 28/39] virtio-scsi: Batched prepare for cmd reqs Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 29/39] virtio-scsi: Call bdrv_io_plug/bdrv_io_unplug in cmd request handling Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 30/39] virtio-scsi: Process ".iothread" property Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 31/39] scsi: Drop scsi_req_abort Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 32/39] scsi-generic: Handle canceled request in scsi_command_complete Paolo Bonzini
2014-09-30 12:25 ` Paolo Bonzini [this message]
2014-09-30 12:25 ` [Qemu-devel] [PULL 34/39] scsi: Drop SCSIReqOps.cancel_io Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 35/39] scsi: Introduce scsi_req_cancel_complete Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 36/39] scsi: Introduce scsi_req_cancel_async Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 37/39] virtio-scsi: Handle TMF request cancellation asynchronously Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 38/39] util: introduce bitmap_try_new Paolo Bonzini
2014-09-30 12:25 ` [Qemu-devel] [PULL 39/39] block/iscsi: handle failure on malloc of the allocationmap Paolo Bonzini
2014-09-30 17:43 ` [Qemu-devel] [PULL 00/39] SCSI changes for 2014-09-23 Peter Maydell
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=1412079919-18857-34-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=famz@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).