From: Ryan Harper <ryanh@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Ryan Harper <ryanh@us.ibm.com>, Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] [STABLE][PATCH 1/3] Refactor aio callback allocation to use an aiocb pool
Date: Mon, 20 Apr 2009 17:13:18 -0500 [thread overview]
Message-ID: <1240265600-9469-2-git-send-email-ryanh@us.ibm.com> (raw)
In-Reply-To: <1240265600-9469-1-git-send-email-ryanh@us.ibm.com>
Re-based against qemu-stable 0.10 branch
Move the AIOCB allocation code to use a dedicate structure, AIOPool. AIOCB
specific information, such as the AIOCB size and cancellation routine, is
moved into the pool.
At present, there is exactly one pool per block format driver, maintaining
the status quo.
Signed-off-by: Avi Kivity <avi@redhat.com>
diff --git a/block.c b/block.c
index 3f262fa..1aa3de5 100644
--- a/block.c
+++ b/block.c
@@ -141,6 +141,7 @@ static void bdrv_register(BlockDriver *bdrv)
bdrv->bdrv_read = bdrv_read_em;
bdrv->bdrv_write = bdrv_write_em;
}
+ aio_pool_init(&bdrv->aio_pool, bdrv->aiocb_size, bdrv->bdrv_aio_cancel);
bdrv->next = first_drv;
first_drv = bdrv;
}
@@ -1443,14 +1444,12 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
void bdrv_aio_cancel(BlockDriverAIOCB *acb)
{
- BlockDriver *drv = acb->bs->drv;
-
if (acb->cb == bdrv_aio_rw_vector_cb) {
VectorTranslationState *s = acb->opaque;
acb = s->aiocb;
}
- drv->bdrv_aio_cancel(acb);
+ acb->pool->cancel(acb);
}
@@ -1568,18 +1567,25 @@ void bdrv_init(void)
bdrv_register(&bdrv_nbd);
}
-void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
- void *opaque)
+void aio_pool_init(AIOPool *pool, int aiocb_size,
+ void (*cancel)(BlockDriverAIOCB *acb))
+{
+ pool->aiocb_size = aiocb_size;
+ pool->cancel = cancel;
+ pool->free_aiocb = NULL;
+}
+
+void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
+ BlockDriverCompletionFunc *cb, void *opaque)
{
- BlockDriver *drv;
BlockDriverAIOCB *acb;
- drv = bs->drv;
- if (drv->free_aiocb) {
- acb = drv->free_aiocb;
- drv->free_aiocb = acb->next;
+ if (pool->free_aiocb) {
+ acb = pool->free_aiocb;
+ pool->free_aiocb = acb->next;
} else {
- acb = qemu_mallocz(drv->aiocb_size);
+ acb = qemu_mallocz(pool->aiocb_size);
+ acb->pool = pool;
}
acb->bs = bs;
acb->cb = cb;
@@ -1587,12 +1593,18 @@ void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
return acb;
}
+void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
+ void *opaque)
+{
+ return qemu_aio_get_pool(&bs->drv->aio_pool, bs, cb, opaque);
+}
+
void qemu_aio_release(void *p)
{
- BlockDriverAIOCB *acb = p;
- BlockDriver *drv = acb->bs->drv;
- acb->next = drv->free_aiocb;
- drv->free_aiocb = acb;
+ BlockDriverAIOCB *acb = (BlockDriverAIOCB *)p;
+ AIOPool *pool = acb->pool;
+ acb->next = pool->free_aiocb;
+ pool->free_aiocb = acb;
}
/**************************************************************/
diff --git a/block_int.h b/block_int.h
index c6af1c6..e581637 100644
--- a/block_int.h
+++ b/block_int.h
@@ -30,6 +30,12 @@
#define BLOCK_FLAG_COMPRESS 2
#define BLOCK_FLAG_COMPAT6 4
+typedef struct AIOPool {
+ void (*cancel)(BlockDriverAIOCB *acb);
+ int aiocb_size;
+ BlockDriverAIOCB *free_aiocb;
+} AIOPool;
+
struct BlockDriver {
const char *format_name;
int instance_size;
@@ -90,7 +96,7 @@ struct BlockDriver {
/* to control generic scsi devices */
int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
- BlockDriverAIOCB *free_aiocb;
+ AIOPool aio_pool;
struct BlockDriver *next;
};
@@ -140,6 +146,7 @@ struct BlockDriverState {
};
struct BlockDriverAIOCB {
+ AIOPool *pool;
BlockDriverState *bs;
BlockDriverCompletionFunc *cb;
void *opaque;
@@ -148,8 +155,13 @@ struct BlockDriverAIOCB {
void get_tmp_filename(char *filename, int size);
+void aio_pool_init(AIOPool *pool, int aiocb_size,
+ void (*cancel)(BlockDriverAIOCB *acb));
+
void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
void *opaque);
+void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
+ BlockDriverCompletionFunc *cb, void *opaque);
void qemu_aio_release(void *p);
extern BlockDriverState *bdrv_first;
next prev parent reply other threads:[~2009-04-20 22:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-20 22:13 [Qemu-devel] [STABLE][PATCH 0/3] Rebase aio dma cancellation work Ryan Harper
2009-04-20 22:13 ` Ryan Harper [this message]
2009-04-20 22:13 ` [Qemu-devel] [STABLE][PATCH 2/3] Convert vectored aio emulation to use a dedicated pool Ryan Harper
2009-04-20 22:13 ` [Qemu-devel] [STABLE][PATCH 3/3] Implement cancellation method for dma async I/O Ryan Harper
2009-04-21 21:35 ` [Qemu-devel] Re: [STABLE][PATCH 0/3] Rebase aio dma cancellation work Anthony Liguori
2009-04-22 11:03 ` Avi Kivity
2009-05-14 10:56 ` [Qemu-devel] [STABLE][PATCH 0/4] Rebase more " Mark McLoughlin
2009-05-14 10:56 ` [Qemu-devel] [STABLE][PATCH 1/4] Use vectored aiocb storage to store vector translation state Mark McLoughlin
2009-05-14 10:56 ` [Qemu-devel] [STABLE][PATCH 2/4] Move block dma helpers aiocb to store dma state Mark McLoughlin
2009-05-14 10:56 ` [Qemu-devel] [STABLE][PATCH 3/4] Fix vectored aio bounce handling immediate errors Mark McLoughlin
2009-05-14 10:56 ` [Qemu-devel] [STABLE][PATCH 4/4] Fix DMA API when handling an immediate error from block layer Mark McLoughlin
2009-05-14 11:39 ` Mark McLoughlin
2009-05-14 11:39 ` [Qemu-devel] [STABLE][PATCH 3/4] Fix vectored aio bounce handling immediate errors Mark McLoughlin
2009-05-14 11:39 ` [Qemu-devel] [STABLE][PATCH 2/4] Move block dma helpers aiocb to store dma state Mark McLoughlin
2009-05-14 11:38 ` [Qemu-devel] [STABLE][PATCH 1/4] Use vectored aiocb storage to store vector translation state Mark McLoughlin
2009-05-14 11:28 ` [Qemu-devel] Re: [STABLE][PATCH 0/4] Rebase more aio dma cancellation work Avi Kivity
2009-05-14 14:38 ` [Qemu-devel] " Anthony Liguori
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=1240265600-9469-2-git-send-email-ryanh@us.ibm.com \
--to=ryanh@us.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=avi@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).