From: Jeff Cody <jcody@redhat.com>
To: qemu-block@nongnu.org
Cc: peter.maydell@linaro.org, jcody@redhat.com,
qemu-devel@nongnu.org, stefanha@redhat.com
Subject: [Qemu-devel] [PULL 5/5] sheepdog: reorganize check for overlapping requests
Date: Wed, 1 Feb 2017 00:34:40 -0500 [thread overview]
Message-ID: <20170201053440.26002-6-jcody@redhat.com> (raw)
In-Reply-To: <20170201053440.26002-1-jcody@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
Wrap the code that was copied repeatedly in the two functions,
sd_aio_setup and sd_aio_complete.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20161129113245.32724-6-pbonzini@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
block/sheepdog.c | 66 ++++++++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 36 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 3ef7601..f757157 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -479,6 +479,19 @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb,
return aio_req;
}
+static void wait_for_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *acb)
+{
+ SheepdogAIOCB *cb;
+
+retry:
+ QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) {
+ if (AIOCBOverlapping(acb, cb)) {
+ qemu_co_queue_wait(&s->overlapping_queue);
+ goto retry;
+ }
+ }
+}
+
static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
QEMUIOVector *qiov, int64_t sector_num, int nb_sectors,
int type)
@@ -505,6 +518,13 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
acb->min_dirty_data_idx = UINT32_MAX;
acb->max_dirty_data_idx = 0;
acb->aiocb_type = type;
+
+ if (type == AIOCB_FLUSH_CACHE) {
+ return;
+ }
+
+ wait_for_overlapping_aiocb(s, acb);
+ QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings);
}
/* Return -EIO in case of error, file descriptor on success */
@@ -2189,18 +2209,14 @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb)
}
}
-static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb)
+static void sd_aio_complete(SheepdogAIOCB *acb)
{
- SheepdogAIOCB *cb;
-
- QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) {
- if (AIOCBOverlapping(aiocb, cb)) {
- return true;
- }
+ if (acb->aiocb_type == AIOCB_FLUSH_CACHE) {
+ return;
}
- QLIST_INSERT_HEAD(&s->inflight_aiocb_head, aiocb, aiocb_siblings);
- return false;
+ QLIST_REMOVE(acb, aiocb_siblings);
+ qemu_co_queue_restart_all(&acb->s->overlapping_queue);
}
static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
@@ -2219,18 +2235,10 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
}
sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA);
-
-retry:
- if (check_overlapping_aiocb(s, &acb)) {
- qemu_co_queue_wait(&s->overlapping_queue);
- goto retry;
- }
-
sd_co_rw_vector(&acb);
sd_write_done(&acb);
+ sd_aio_complete(&acb);
- QLIST_REMOVE(&acb, aiocb_siblings);
- qemu_co_queue_restart_all(&s->overlapping_queue);
return acb.ret;
}
@@ -2241,17 +2249,9 @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num,
BDRVSheepdogState *s = bs->opaque;
sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_READ_UDATA);
-
-retry:
- if (check_overlapping_aiocb(s, &acb)) {
- qemu_co_queue_wait(&s->overlapping_queue);
- goto retry;
- }
-
sd_co_rw_vector(&acb);
+ sd_aio_complete(&acb);
- QLIST_REMOVE(&acb, aiocb_siblings);
- qemu_co_queue_restart_all(&s->overlapping_queue);
return acb.ret;
}
@@ -2275,6 +2275,8 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
if (--acb.nr_pending) {
qemu_coroutine_yield();
}
+
+ sd_aio_complete(&acb);
return acb.ret;
}
@@ -2730,17 +2732,9 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset,
}
sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ);
-
-retry:
- if (check_overlapping_aiocb(s, &acb)) {
- qemu_co_queue_wait(&s->overlapping_queue);
- goto retry;
- }
-
sd_co_rw_vector(&acb);
+ sd_aio_complete(&acb);
- QLIST_REMOVE(&acb, aiocb_siblings);
- qemu_co_queue_restart_all(&s->overlapping_queue);
return acb.ret;
}
--
2.9.3
next prev parent reply other threads:[~2017-02-01 5:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-01 5:34 [Qemu-devel] [PULL 0/5] Block patches Jeff Cody
2017-02-01 5:34 ` [Qemu-devel] [PULL 1/5] sheepdog: remove unused cancellation support Jeff Cody
2017-02-01 5:34 ` [Qemu-devel] [PULL 2/5] sheepdog: reorganize coroutine flow Jeff Cody
2017-02-01 5:34 ` [Qemu-devel] [PULL 3/5] sheepdog: do not use BlockAIOCB Jeff Cody
2017-02-01 5:34 ` [Qemu-devel] [PULL 4/5] sheepdog: simplify inflight_aio_head management Jeff Cody
2017-02-01 5:34 ` Jeff Cody [this message]
2017-02-02 15:14 ` [Qemu-devel] [PULL 0/5] Block patches 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=20170201053440.26002-6-jcody@redhat.com \
--to=jcody@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).