From patchwork Wed Feb 1 05:34:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 722349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vCsQs5v9Xz9sxS for ; Wed, 1 Feb 2017 16:40:05 +1100 (AEDT) Received: from localhost ([::1]:42829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYneF-000077-Bl for incoming@patchwork.ozlabs.org; Wed, 01 Feb 2017 00:40:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnZD-00044x-Ch for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYnZC-0006WU-Bl for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49780) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cYnZ9-0006Ut-F4; Wed, 01 Feb 2017 00:34:47 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CB3B3A7689; Wed, 1 Feb 2017 05:34:47 +0000 (UTC) Received: from localhost (ovpn-116-86.phx2.redhat.com [10.3.116.86]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v115Yk5T009196 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 1 Feb 2017 00:34:47 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 1 Feb 2017 00:34:40 -0500 Message-Id: <20170201053440.26002-6-jcody@redhat.com> In-Reply-To: <20170201053440.26002-1-jcody@redhat.com> References: <20170201053440.26002-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 01 Feb 2017 05:34:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/5] sheepdog: reorganize check for overlapping requests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paolo Bonzini Wrap the code that was copied repeatedly in the two functions, sd_aio_setup and sd_aio_complete. Signed-off-by: Paolo Bonzini Message-id: 20161129113245.32724-6-pbonzini@redhat.com Signed-off-by: Jeff Cody --- 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; }