From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 1/3] Add bdrv_aio_multiwrite
Date: Tue, 1 Sep 2009 15:51:50 +0200 [thread overview]
Message-ID: <1251813112-17408-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1251813112-17408-1-git-send-email-kwolf@redhat.com>
Allows block drivers to handle multiple write requests at once. For drivers not
implementing bdrv_aio_multiwrite a trivial emulation is provided (just call
bdrv_aio_writev for each request).
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 37 +++++++++++++++++++++++++++++++++++++
block.h | 15 +++++++++++++++
block_int.h | 3 +++
3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/block.c b/block.c
index 033957d..c154d78 100644
--- a/block.c
+++ b/block.c
@@ -1354,6 +1354,43 @@ BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
return ret;
}
+/*
+ * Submit multiple AIO write requests at once.
+ *
+ * On success, the function returns 0 and all requests in the reqs array have
+ * been submitted. In error case this function returns -1, and any of the
+ * requests may or may not be submitted yet. In particular, this means that the
+ * callback will be called for some of the requests, for others it won't. The
+ * caller must check the error field of the BlockRequest to wait for the right
+ * callbacks (if error != 0, no callback will be called).
+ *
+ * The implementation may modify the contents of the reqs array, e.g. to merge
+ * requests. However, the fields opaque and error are left unmodified as they
+ * are used to signal failure for a single request to the caller.
+ */
+int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)
+{
+ BlockDriver *drv = bs->drv;
+ BlockDriverAIOCB *acb;
+ int i;
+ int res = 0;
+
+ if (drv->bdrv_aio_multiwrite != NULL) {
+ return drv->bdrv_aio_multiwrite(bs, reqs, num_reqs);
+ }
+
+ for (i = 0; i < num_reqs; i++) {
+ acb = bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov,
+ reqs[i].nb_sectors, reqs[i].cb, reqs[i].opaque);
+ if (acb == NULL) {
+ reqs[i].error = EIO;
+ res = -1;
+ }
+ }
+
+ return res;
+}
+
void bdrv_aio_cancel(BlockDriverAIOCB *acb)
{
acb->pool->cancel(acb);
diff --git a/block.h b/block.h
index 28bf357..ea69052 100644
--- a/block.h
+++ b/block.h
@@ -87,6 +87,21 @@ BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
BlockDriverCompletionFunc *cb, void *opaque);
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
+typedef struct BlockRequest {
+ /* Fields to be filled by multiwrite caller */
+ int64_t sector;
+ int nb_sectors;
+ QEMUIOVector *qiov;
+ BlockDriverCompletionFunc *cb;
+ void *opaque;
+
+ /* Filled by multiwrite implementation */
+ int error;
+} BlockRequest;
+
+int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs,
+ int num_reqs);
+
/* sg packet commands */
int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf);
BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
diff --git a/block_int.h b/block_int.h
index 0902fd4..027b1d8 100644
--- a/block_int.h
+++ b/block_int.h
@@ -70,6 +70,9 @@ struct BlockDriver {
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque);
+ int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs,
+ int num_reqs);
+
const char *protocol_name;
int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
int64_t (*bdrv_getlength)(BlockDriverState *bs);
--
1.6.0.6
next prev parent reply other threads:[~2009-09-01 13:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-01 13:51 [Qemu-devel] [PATCH 0/3] block: Handle multiple write requests at once Kevin Wolf
2009-09-01 13:51 ` Kevin Wolf [this message]
2009-09-01 13:51 ` [Qemu-devel] [PATCH 2/3] virtio-blk: Use bdrv_aio_multiwrite Kevin Wolf
2009-09-01 13:51 ` [Qemu-devel] [PATCH 3/3] qcow2: Add bdrv_aio_multiwrite implementation Kevin Wolf
2009-09-01 15:52 ` [Qemu-devel] [PATCH 0/3] block: Handle multiple write requests at once Christoph Hellwig
2009-09-01 16:08 ` Anthony Liguori
2009-09-01 16:14 ` Christoph Hellwig
2009-09-01 17:00 ` Avi Kivity
2009-09-01 16:59 ` Avi Kivity
2009-09-02 7:27 ` Kevin Wolf
2009-09-02 15:43 ` Christoph Hellwig
2009-09-02 15:50 ` Kevin Wolf
2009-09-02 17:26 ` Christoph Hellwig
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=1251813112-17408-2-git-send-email-kwolf@redhat.com \
--to=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).