From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/4] block/curl: Don't finish AIOCBs too early
Date: Wed, 21 Sep 2011 15:21:56 +0200 [thread overview]
Message-ID: <1316611316-11773-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1316611316-11773-1-git-send-email-kwolf@redhat.com>
From: Nick Thomas <nick@bytemark.co.uk>
The previous behaviour was to finish AIOCBs inside curl_aio_readv()
if the data was cached. This caused the following failed assertion
at hw/ide/pci.c:314: bmdma_cmd_writeb
"Assertion `bm->bus->dma->aiocb == ((void *)0)' failed."
By scheduling a QEMUBH and performing the completion inside the
callback, we avoid this problem.
Signed-off-by: Nick Thomas <nick@bytemark.co.uk>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/curl.c | 68 +++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 49 insertions(+), 19 deletions(-)
diff --git a/block/curl.c b/block/curl.c
index 21fed93..4209ac8 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -47,7 +47,12 @@ struct BDRVCURLState;
typedef struct CURLAIOCB {
BlockDriverAIOCB common;
+ QEMUBH *bh;
QEMUIOVector *qiov;
+
+ int64_t sector_num;
+ int nb_sectors;
+
size_t start;
size_t end;
} CURLAIOCB;
@@ -440,43 +445,42 @@ static AIOPool curl_aio_pool = {
.cancel = curl_aio_cancel,
};
-static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
- int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
- BlockDriverCompletionFunc *cb, void *opaque)
+
+static void curl_readv_bh_cb(void *p)
{
- BDRVCURLState *s = bs->opaque;
- CURLAIOCB *acb;
- size_t start = sector_num * SECTOR_SIZE;
- size_t end;
CURLState *state;
- acb = qemu_aio_get(&curl_aio_pool, bs, cb, opaque);
- if (!acb)
- return NULL;
+ CURLAIOCB *acb = p;
+ BDRVCURLState *s = acb->common.bs->opaque;
- acb->qiov = qiov;
+ qemu_bh_delete(acb->bh);
+ acb->bh = NULL;
+
+ size_t start = acb->sector_num * SECTOR_SIZE;
+ size_t end;
// In case we have the requested data already (e.g. read-ahead),
// we can just call the callback and be done.
-
- switch (curl_find_buf(s, start, nb_sectors * SECTOR_SIZE, acb)) {
+ switch (curl_find_buf(s, start, acb->nb_sectors * SECTOR_SIZE, acb)) {
case FIND_RET_OK:
qemu_aio_release(acb);
// fall through
case FIND_RET_WAIT:
- return &acb->common;
+ return;
default:
break;
}
// No cache found, so let's start a new request
-
state = curl_init_state(s);
- if (!state)
- return NULL;
+ if (!state) {
+ acb->common.cb(acb->common.opaque, -EIO);
+ qemu_aio_release(acb);
+ return;
+ }
acb->start = 0;
- acb->end = (nb_sectors * SECTOR_SIZE);
+ acb->end = (acb->nb_sectors * SECTOR_SIZE);
state->buf_off = 0;
if (state->orig_buf)
@@ -489,12 +493,38 @@ static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
snprintf(state->range, 127, "%zd-%zd", start, end);
DPRINTF("CURL (AIO): Reading %d at %zd (%s)\n",
- (nb_sectors * SECTOR_SIZE), start, state->range);
+ (acb->nb_sectors * SECTOR_SIZE), start, state->range);
curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range);
curl_multi_add_handle(s->multi, state->curl);
curl_multi_do(s);
+}
+
+static BlockDriverAIOCB *curl_aio_readv(BlockDriverState *bs,
+ int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
+ BlockDriverCompletionFunc *cb, void *opaque)
+{
+ CURLAIOCB *acb;
+
+ acb = qemu_aio_get(&curl_aio_pool, bs, cb, opaque);
+
+ if (!acb) {
+ return NULL;
+ }
+
+ acb->qiov = qiov;
+ acb->sector_num = sector_num;
+ acb->nb_sectors = nb_sectors;
+
+ acb->bh = qemu_bh_new(curl_readv_bh_cb, acb);
+
+ if (!acb->bh) {
+ DPRINTF("CURL: qemu_bh_new failed\n");
+ return NULL;
+ }
+
+ qemu_bh_schedule(acb->bh);
return &acb->common;
}
--
1.7.6.2
next prev parent reply other threads:[~2011-09-21 13:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-21 13:21 [Qemu-devel] [PULL 0/4] Block patches (includes build fix for non-Linux) Kevin Wolf
2011-09-21 13:21 ` [Qemu-devel] [PATCH 1/4] nbd: fix non-Linux build failure Kevin Wolf
2011-09-21 13:21 ` [Qemu-devel] [PATCH 2/4] ahci: add port I/O index-data pair Kevin Wolf
2011-09-21 13:21 ` [Qemu-devel] [PATCH 3/4] block/curl: Implement a flush function on the fd handlers Kevin Wolf
2011-09-21 13:21 ` Kevin Wolf [this message]
2011-09-22 15:58 ` [Qemu-devel] [PULL 0/4] Block patches (includes build fix for non-Linux) 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=1316611316-11773-5-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--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).