From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: jcody@redhat.com, qemu-block@nongnu.org,
Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>,
Liu Yuan <namei.unix@gmail.com>
Subject: [Qemu-devel] [PATCH 5/5] sheepdog: reorganize check for overlapping requests
Date: Fri, 18 Nov 2016 17:42:30 +0100 [thread overview]
Message-ID: <20161118164230.17870-6-pbonzini@redhat.com> (raw)
In-Reply-To: <20161118164230.17870-1-pbonzini@redhat.com>
Wrap the code that was copied repeatedly in the two functions,
sd_aio_setup and sd_aio_complete.
Cc: jcody@redhat.com
Cc: qemu-block@nongnu.org
Cc: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Cc: Liu Yuan <namei.unix@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/sheepdog.c | 66 ++++++++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 36 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index e5ac733..07271bc 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 */
@@ -2187,18 +2207,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,
@@ -2217,18 +2233,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;
}
@@ -2239,17 +2247,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;
}
@@ -2273,6 +2273,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;
}
@@ -2727,17 +2729,9 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset,
assert((count & (BDRV_SECTOR_SIZE - 1)) == 0);
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:[~2016-11-18 16:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-18 16:42 [Qemu-devel] [PATCH for-2.9 v2 0/5] Sheepdog cleanups Paolo Bonzini
2016-11-18 16:42 ` [Qemu-devel] [PATCH 1/5] sheepdog: remove unused cancellation support Paolo Bonzini
2016-11-18 16:42 ` [Qemu-devel] [PATCH 2/5] sheepdog: reorganize coroutine flow Paolo Bonzini
2016-11-18 16:42 ` [Qemu-devel] [PATCH 3/5] sheepdog: do not use BlockAIOCB Paolo Bonzini
2016-11-18 16:42 ` [Qemu-devel] [PATCH 4/5] sheepdog: simplify inflight_aio_head management Paolo Bonzini
2016-11-18 16:42 ` Paolo Bonzini [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-11-29 11:32 [Qemu-devel] [PATCH for-2.9 v3 0/5] Sheepdog cleanups Paolo Bonzini
2016-11-29 11:32 ` [Qemu-devel] [PATCH 5/5] sheepdog: reorganize check for overlapping requests Paolo Bonzini
2016-11-18 15:54 [Qemu-devel] [PATCH for-2.9 0/5] Sheepdog cleanups Paolo Bonzini
2016-11-18 15:55 ` [Qemu-devel] [PATCH 5/5] sheepdog: reorganize check for overlapping requests Paolo Bonzini
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=20161118164230.17870-6-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=jcody@redhat.com \
--cc=mitake.hitoshi@lab.ntt.co.jp \
--cc=namei.unix@gmail.com \
--cc=qemu-block@nongnu.org \
--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).