From nobody Mon Apr 29 06:36:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1485927411142637.2461895477302; Tue, 31 Jan 2017 21:36:51 -0800 (PST) Received: from localhost ([::1]:42816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnb5-00057G-Gt for importer@patchew.org; Wed, 01 Feb 2017 00:36:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnZB-00043N-IU for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYnZA-0006Vb-LN for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41538) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cYnZ5-0006Ts-UN; Wed, 01 Feb 2017 00:34:44 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 89C8BC05683F; Wed, 1 Feb 2017 05:34:43 +0000 (UTC) Received: from localhost (ovpn-116-86.phx2.redhat.com [10.3.116.86]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v115YgWW011795 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 1 Feb 2017 00:34:43 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 1 Feb 2017 00:34:36 -0500 Message-Id: <20170201053440.26002-2-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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 01 Feb 2017 05:34:43 +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 1/5] sheepdog: remove unused cancellation support 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini SheepdogAIOCB is internal to sheepdog.c, hence it is never canceled. Signed-off-by: Paolo Bonzini Message-id: 20161129113245.32724-2-pbonzini@redhat.com Signed-off-by: Jeff Cody --- block/sheepdog.c | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 5637e0c..5fde37a 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -347,7 +347,6 @@ struct SheepdogAIOCB { Coroutine *coroutine; void (*aio_done_func)(SheepdogAIOCB *); =20 - bool cancelable; int nr_pending; =20 uint32_t min_affect_data_idx; @@ -486,7 +485,6 @@ static inline void free_aio_req(BDRVSheepdogState *s, A= IOReq *aio_req) { SheepdogAIOCB *acb =3D aio_req->aiocb; =20 - acb->cancelable =3D false; QLIST_REMOVE(aio_req, aio_siblings); g_free(aio_req); =20 @@ -499,57 +497,8 @@ static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB= *acb) qemu_aio_unref(acb); } =20 -/* - * Check whether the specified acb can be canceled - * - * We can cancel aio when any request belonging to the acb is: - * - Not processed by the sheepdog server. - * - Not linked to the inflight queue. - */ -static bool sd_acb_cancelable(const SheepdogAIOCB *acb) -{ - BDRVSheepdogState *s =3D acb->common.bs->opaque; - AIOReq *aioreq; - - if (!acb->cancelable) { - return false; - } - - QLIST_FOREACH(aioreq, &s->inflight_aio_head, aio_siblings) { - if (aioreq->aiocb =3D=3D acb) { - return false; - } - } - - return true; -} - -static void sd_aio_cancel(BlockAIOCB *blockacb) -{ - SheepdogAIOCB *acb =3D (SheepdogAIOCB *)blockacb; - BDRVSheepdogState *s =3D acb->common.bs->opaque; - AIOReq *aioreq, *next; - - if (sd_acb_cancelable(acb)) { - /* Remove outstanding requests from failed queue. */ - QLIST_FOREACH_SAFE(aioreq, &s->failed_aio_head, aio_siblings, - next) { - if (aioreq->aiocb =3D=3D acb) { - free_aio_req(s, aioreq); - } - } - - assert(acb->nr_pending =3D=3D 0); - if (acb->common.cb) { - acb->common.cb(acb->common.opaque, -ECANCELED); - } - sd_finish_aiocb(acb); - } -} - static const AIOCBInfo sd_aiocb_info =3D { .aiocb_size =3D sizeof(SheepdogAIOCB), - .cancel_async =3D sd_aio_cancel, }; =20 static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qio= v, @@ -569,7 +518,6 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs= , QEMUIOVector *qiov, acb->nb_sectors =3D nb_sectors; =20 acb->aio_done_func =3D NULL; - acb->cancelable =3D true; acb->coroutine =3D qemu_coroutine_self(); acb->ret =3D 0; acb->nr_pending =3D 0; --=20 2.9.3 From nobody Mon Apr 29 06:36:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1485927817753765.8608276166324; Tue, 31 Jan 2017 21:43:37 -0800 (PST) Received: from localhost ([::1]:42850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnhf-0003UV-QM for importer@patchew.org; Wed, 01 Feb 2017 00:43:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnZD-00044m-5h 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 1cYnZB-0006WD-KR for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42054) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cYnZ6-0006Tw-CP; Wed, 01 Feb 2017 00:34:44 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 88B94C04B332; Wed, 1 Feb 2017 05:34:44 +0000 (UTC) Received: from localhost (ovpn-116-86.phx2.redhat.com [10.3.116.86]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v115Yhrj006321 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 1 Feb 2017 00:34:44 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 1 Feb 2017 00:34:37 -0500 Message-Id: <20170201053440.26002-3-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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 01 Feb 2017 05:34:44 +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 2/5] sheepdog: reorganize coroutine flow 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Delimit co_recv's lifetime clearly in aio_read_response. Do a simple qemu_coroutine_enter in aio_read_response, letting sd_co_writev call sd_write_done. Handle nr_pending in the same way in sd_co_rw_vector, sd_write_done and sd_co_flush_to_disk. Remove sd_co_rw_vector's return value; just leave with no pending requests. [Jeff: added missing 'return' back, spotted by Paolo after series was applied.] Signed-off-by: Jeff Cody --- block/sheepdog.c | 115 ++++++++++++++++++++-------------------------------= ---- 1 file changed, 42 insertions(+), 73 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 5fde37a..e0985df 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -345,8 +345,6 @@ struct SheepdogAIOCB { enum AIOCBState aiocb_type; =20 Coroutine *coroutine; - void (*aio_done_func)(SheepdogAIOCB *); - int nr_pending; =20 uint32_t min_affect_data_idx; @@ -449,14 +447,13 @@ static const char * sd_strerror(int err) * * 1. In sd_co_rw_vector, we send the I/O requests to the server and * link the requests to the inflight_list in the - * BDRVSheepdogState. The function exits without waiting for + * BDRVSheepdogState. The function yields while waiting for * receiving the response. * * 2. We receive the response in aio_read_response, the fd handler to - * the sheepdog connection. If metadata update is needed, we send - * the write request to the vdi object in sd_write_done, the write - * completion function. We switch back to sd_co_readv/writev after - * all the requests belonging to the AIOCB are finished. + * the sheepdog connection. We switch back to sd_co_readv/sd_writev + * after all the requests belonging to the AIOCB are finished. If + * needed, sd_co_writev will send another requests for the vdi object. */ =20 static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *a= cb, @@ -491,12 +488,6 @@ static inline void free_aio_req(BDRVSheepdogState *s, = AIOReq *aio_req) acb->nr_pending--; } =20 -static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb) -{ - qemu_coroutine_enter(acb->coroutine); - qemu_aio_unref(acb); -} - static const AIOCBInfo sd_aiocb_info =3D { .aiocb_size =3D sizeof(SheepdogAIOCB), }; @@ -517,7 +508,6 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs= , QEMUIOVector *qiov, acb->sector_num =3D sector_num; acb->nb_sectors =3D nb_sectors; =20 - acb->aio_done_func =3D NULL; acb->coroutine =3D qemu_coroutine_self(); acb->ret =3D 0; acb->nr_pending =3D 0; @@ -788,9 +778,6 @@ static void coroutine_fn aio_read_response(void *opaque) =20 switch (acb->aiocb_type) { case AIOCB_WRITE_UDATA: - /* this coroutine context is no longer suitable for co_recv - * because we may send data to update vdi objects */ - s->co_recv =3D NULL; if (!is_data_obj(aio_req->oid)) { break; } @@ -838,6 +825,11 @@ static void coroutine_fn aio_read_response(void *opaqu= e) } } =20 + /* No more data for this aio_req (reload_inode below uses its own file + * descriptor handler which doesn't use co_recv). + */ + s->co_recv =3D NULL; + switch (rsp.result) { case SD_RES_SUCCESS: break; @@ -855,7 +847,7 @@ static void coroutine_fn aio_read_response(void *opaque) aio_req->oid =3D vid_to_vdi_oid(s->inode.vdi_id); } resend_aioreq(s, aio_req); - goto out; + return; default: acb->ret =3D -EIO; error_report("%s", sd_strerror(rsp.result)); @@ -868,13 +860,12 @@ static void coroutine_fn aio_read_response(void *opaq= ue) * We've finished all requests which belong to the AIOCB, so * we can switch back to sd_co_readv/writev now. */ - acb->aio_done_func(acb); + qemu_coroutine_enter(acb->coroutine); } -out: - s->co_recv =3D NULL; + return; + err: - s->co_recv =3D NULL; reconnect_to_sdog(opaque); } =20 @@ -1973,7 +1964,6 @@ static int sd_truncate(BlockDriverState *bs, int64_t = offset) /* * This function is called after writing data objects. If we need to * update metadata, this sends a write request to the vdi object. - * Otherwise, this switches back to sd_co_readv/writev. */ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) { @@ -1986,6 +1976,7 @@ static void coroutine_fn sd_write_done(SheepdogAIOCB = *acb) mx =3D acb->max_dirty_data_idx; if (mn <=3D mx) { /* we need to update the vdi object. */ + ++acb->nr_pending; offset =3D sizeof(s->inode) - sizeof(s->inode.data_vdi_id) + mn * sizeof(s->inode.data_vdi_id[0]); data_len =3D (mx - mn + 1) * sizeof(s->inode.data_vdi_id[0]); @@ -1999,13 +1990,10 @@ static void coroutine_fn sd_write_done(SheepdogAIOC= B *acb) data_len, offset, 0, false, 0, offset); QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA); - - acb->aio_done_func =3D sd_finish_aiocb; - acb->aiocb_type =3D AIOCB_WRITE_UDATA; - return; + if (--acb->nr_pending) { + qemu_coroutine_yield(); + } } - - sd_finish_aiocb(acb); } =20 /* Delete current working VDI on the snapshot chain */ @@ -2117,7 +2105,7 @@ out: * Returns 1 when we need to wait a response, 0 when there is no sent * request and -errno in error cases. */ -static int coroutine_fn sd_co_rw_vector(void *p) +static void coroutine_fn sd_co_rw_vector(void *p) { SheepdogAIOCB *acb =3D p; int ret =3D 0; @@ -2138,7 +2126,7 @@ static int coroutine_fn sd_co_rw_vector(void *p) ret =3D sd_create_branch(s); if (ret) { acb->ret =3D -EIO; - goto out; + return; } } =20 @@ -2212,11 +2200,9 @@ static int coroutine_fn sd_co_rw_vector(void *p) idx++; done +=3D len; } -out: - if (!--acb->nr_pending) { - return acb->ret; + if (--acb->nr_pending) { + qemu_coroutine_yield(); } - return 1; } =20 static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *a= iocb) @@ -2249,7 +2235,6 @@ static coroutine_fn int sd_co_writev(BlockDriverState= *bs, int64_t sector_num, } =20 acb =3D sd_aio_setup(bs, qiov, sector_num, nb_sectors); - acb->aio_done_func =3D sd_write_done; acb->aiocb_type =3D AIOCB_WRITE_UDATA; =20 retry: @@ -2258,20 +2243,14 @@ retry: goto retry; } =20 - ret =3D sd_co_rw_vector(acb); - if (ret <=3D 0) { - QLIST_REMOVE(acb, aiocb_siblings); - qemu_co_queue_restart_all(&s->overlapping_queue); - qemu_aio_unref(acb); - return ret; - } - - qemu_coroutine_yield(); + sd_co_rw_vector(acb); + sd_write_done(acb); =20 QLIST_REMOVE(acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - - return acb->ret; + ret =3D acb->ret; + qemu_aio_unref(acb); + return ret; } =20 static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_n= um, @@ -2283,7 +2262,6 @@ static coroutine_fn int sd_co_readv(BlockDriverState = *bs, int64_t sector_num, =20 acb =3D sd_aio_setup(bs, qiov, sector_num, nb_sectors); acb->aiocb_type =3D AIOCB_READ_UDATA; - acb->aio_done_func =3D sd_finish_aiocb; =20 retry: if (check_overlapping_aiocb(s, acb)) { @@ -2291,25 +2269,20 @@ retry: goto retry; } =20 - ret =3D sd_co_rw_vector(acb); - if (ret <=3D 0) { - QLIST_REMOVE(acb, aiocb_siblings); - qemu_co_queue_restart_all(&s->overlapping_queue); - qemu_aio_unref(acb); - return ret; - } - - qemu_coroutine_yield(); + sd_co_rw_vector(acb); =20 QLIST_REMOVE(acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - return acb->ret; + ret =3D acb->ret; + qemu_aio_unref(acb); + return ret; } =20 static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) { BDRVSheepdogState *s =3D bs->opaque; SheepdogAIOCB *acb; + int ret; AIOReq *aio_req; =20 if (s->cache_flags !=3D SD_FLAG_CMD_CACHE) { @@ -2318,15 +2291,19 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDr= iverState *bs) =20 acb =3D sd_aio_setup(bs, NULL, 0, 0); acb->aiocb_type =3D AIOCB_FLUSH_CACHE; - acb->aio_done_func =3D sd_finish_aiocb; =20 + acb->nr_pending++; aio_req =3D alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), 0, 0, 0, false, 0, 0); QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type); =20 - qemu_coroutine_yield(); - return acb->ret; + if (--acb->nr_pending) { + qemu_coroutine_yield(); + } + ret =3D acb->ret; + qemu_aio_unref(acb); + return ret; } =20 static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_i= nfo) @@ -2783,7 +2760,6 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverSta= te *bs, int64_t offset, acb =3D sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS, count >> BDRV_SECTOR_BITS); acb->aiocb_type =3D AIOCB_DISCARD_OBJ; - acb->aio_done_func =3D sd_finish_aiocb; =20 retry: if (check_overlapping_aiocb(s, acb)) { @@ -2791,20 +2767,13 @@ retry: goto retry; } =20 - ret =3D sd_co_rw_vector(acb); - if (ret <=3D 0) { - QLIST_REMOVE(acb, aiocb_siblings); - qemu_co_queue_restart_all(&s->overlapping_queue); - qemu_aio_unref(acb); - return ret; - } - - qemu_coroutine_yield(); + sd_co_rw_vector(acb); =20 QLIST_REMOVE(acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - - return acb->ret; + ret =3D acb->ret; + qemu_aio_unref(acb); + return ret; } =20 static coroutine_fn int64_t --=20 2.9.3 From nobody Mon Apr 29 06:36:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1485927641235982.2788385591575; Tue, 31 Jan 2017 21:40:41 -0800 (PST) Received: from localhost ([::1]:42837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnep-0000Kc-Fi for importer@patchew.org; Wed, 01 Feb 2017 00:40:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnZC-00044K-J8 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 1cYnZB-0006W2-AK for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cYnZ7-0006UI-DY; Wed, 01 Feb 2017 00:34:45 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 8624C3B722; Wed, 1 Feb 2017 05:34:45 +0000 (UTC) Received: from localhost (ovpn-116-86.phx2.redhat.com [10.3.116.86]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v115Yi8H007938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 1 Feb 2017 00:34:45 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 1 Feb 2017 00:34:38 -0500 Message-Id: <20170201053440.26002-4-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 01 Feb 2017 05:34:45 +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 3/5] sheepdog: do not use BlockAIOCB 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Sheepdog's AIOCB are completely internal entities for a group of requests and do not need dynamic allocation. Signed-off-by: Paolo Bonzini Message-id: 20161129113245.32724-4-pbonzini@redhat.com Signed-off-by: Jeff Cody --- block/sheepdog.c | 99 ++++++++++++++++++++++------------------------------= ---- 1 file changed, 39 insertions(+), 60 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index e0985df..33ded57 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -306,6 +306,7 @@ static inline size_t count_data_objs(const struct Sheep= dogInode *inode) } while (0) =20 typedef struct SheepdogAIOCB SheepdogAIOCB; +typedef struct BDRVSheepdogState BDRVSheepdogState; =20 typedef struct AIOReq { SheepdogAIOCB *aiocb; @@ -334,7 +335,7 @@ enum AIOCBState { || y->max_affect_data_idx < x->min_affect_data_idx)) =20 struct SheepdogAIOCB { - BlockAIOCB common; + BDRVSheepdogState *s; =20 QEMUIOVector *qiov; =20 @@ -362,7 +363,7 @@ struct SheepdogAIOCB { QLIST_ENTRY(SheepdogAIOCB) aiocb_siblings; }; =20 -typedef struct BDRVSheepdogState { +struct BDRVSheepdogState { BlockDriverState *bs; AioContext *aio_context; =20 @@ -389,7 +390,7 @@ typedef struct BDRVSheepdogState { =20 CoQueue overlapping_queue; QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head; -} BDRVSheepdogState; +}; =20 typedef struct BDRVSheepdogReopenState { int fd; @@ -488,20 +489,15 @@ static inline void free_aio_req(BDRVSheepdogState *s,= AIOReq *aio_req) acb->nr_pending--; } =20 -static const AIOCBInfo sd_aiocb_info =3D { - .aiocb_size =3D sizeof(SheepdogAIOCB), -}; - -static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qio= v, - int64_t sector_num, int nb_sectors) +static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, + QEMUIOVector *qiov, int64_t sector_num, int nb_se= ctors, + int type) { - SheepdogAIOCB *acb; uint32_t object_size; - BDRVSheepdogState *s =3D bs->opaque; =20 object_size =3D (UINT32_C(1) << s->inode.block_size_shift); =20 - acb =3D qemu_aio_get(&sd_aiocb_info, bs, NULL, NULL); + acb->s =3D s; =20 acb->qiov =3D qiov; =20 @@ -518,8 +514,7 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs= , QEMUIOVector *qiov, =20 acb->min_dirty_data_idx =3D UINT32_MAX; acb->max_dirty_data_idx =3D 0; - - return acb; + acb->aiocb_type =3D type; } =20 /* Return -EIO in case of error, file descriptor on success */ @@ -1967,7 +1962,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t = offset) */ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) { - BDRVSheepdogState *s =3D acb->common.bs->opaque; + BDRVSheepdogState *s =3D acb->s; struct iovec iov; AIOReq *aio_req; uint32_t offset, data_len, mn, mx; @@ -2105,16 +2100,15 @@ out: * Returns 1 when we need to wait a response, 0 when there is no sent * request and -errno in error cases. */ -static void coroutine_fn sd_co_rw_vector(void *p) +static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) { - SheepdogAIOCB *acb =3D p; int ret =3D 0; unsigned long len, done =3D 0, total =3D acb->nb_sectors * BDRV_SECTOR= _SIZE; unsigned long idx; uint32_t object_size; uint64_t oid; uint64_t offset; - BDRVSheepdogState *s =3D acb->common.bs->opaque; + BDRVSheepdogState *s =3D acb->s; SheepdogInode *inode =3D &s->inode; AIOReq *aio_req; =20 @@ -2222,7 +2216,7 @@ static bool check_overlapping_aiocb(BDRVSheepdogState= *s, SheepdogAIOCB *aiocb) static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_= num, int nb_sectors, QEMUIOVector *qiov) { - SheepdogAIOCB *acb; + SheepdogAIOCB acb; int ret; int64_t offset =3D (sector_num + nb_sectors) * BDRV_SECTOR_SIZE; BDRVSheepdogState *s =3D bs->opaque; @@ -2234,76 +2228,65 @@ static coroutine_fn int sd_co_writev(BlockDriverSta= te *bs, int64_t sector_num, } } =20 - acb =3D sd_aio_setup(bs, qiov, sector_num, nb_sectors); - acb->aiocb_type =3D AIOCB_WRITE_UDATA; + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA); =20 retry: - if (check_overlapping_aiocb(s, acb)) { + if (check_overlapping_aiocb(s, &acb)) { qemu_co_queue_wait(&s->overlapping_queue); goto retry; } =20 - sd_co_rw_vector(acb); - sd_write_done(acb); + sd_co_rw_vector(&acb); + sd_write_done(&acb); =20 - QLIST_REMOVE(acb, aiocb_siblings); + QLIST_REMOVE(&acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - ret =3D acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } =20 static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_n= um, int nb_sectors, QEMUIOVector *qiov) { - SheepdogAIOCB *acb; - int ret; + SheepdogAIOCB acb; BDRVSheepdogState *s =3D bs->opaque; =20 - acb =3D sd_aio_setup(bs, qiov, sector_num, nb_sectors); - acb->aiocb_type =3D AIOCB_READ_UDATA; + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_READ_UDATA); =20 retry: - if (check_overlapping_aiocb(s, acb)) { + if (check_overlapping_aiocb(s, &acb)) { qemu_co_queue_wait(&s->overlapping_queue); goto retry; } =20 - sd_co_rw_vector(acb); + sd_co_rw_vector(&acb); =20 - QLIST_REMOVE(acb, aiocb_siblings); + QLIST_REMOVE(&acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - ret =3D acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } =20 static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) { BDRVSheepdogState *s =3D bs->opaque; - SheepdogAIOCB *acb; - int ret; + SheepdogAIOCB acb; AIOReq *aio_req; =20 if (s->cache_flags !=3D SD_FLAG_CMD_CACHE) { return 0; } =20 - acb =3D sd_aio_setup(bs, NULL, 0, 0); - acb->aiocb_type =3D AIOCB_FLUSH_CACHE; + sd_aio_setup(&acb, s, NULL, 0, 0, AIOCB_FLUSH_CACHE); =20 - acb->nr_pending++; - aio_req =3D alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), + acb.nr_pending++; + aio_req =3D alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id), 0, 0, 0, false, 0, 0); QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); - add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type); + add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type); =20 - if (--acb->nr_pending) { + if (--acb.nr_pending) { qemu_coroutine_yield(); } - ret =3D acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } =20 static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_i= nfo) @@ -2737,9 +2720,8 @@ static int sd_load_vmstate(BlockDriverState *bs, QEMU= IOVector *qiov, static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offse= t, int count) { - SheepdogAIOCB *acb; + SheepdogAIOCB acb; BDRVSheepdogState *s =3D bs->opaque; - int ret; QEMUIOVector discard_iov; struct iovec iov; uint32_t zero =3D 0; @@ -2757,23 +2739,20 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverS= tate *bs, int64_t offset, if (!QEMU_IS_ALIGNED(offset | count, BDRV_SECTOR_SIZE)) { return -ENOTSUP; } - acb =3D sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); - acb->aiocb_type =3D AIOCB_DISCARD_OBJ; + sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS, + count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ); =20 retry: - if (check_overlapping_aiocb(s, acb)) { + if (check_overlapping_aiocb(s, &acb)) { qemu_co_queue_wait(&s->overlapping_queue); goto retry; } =20 - sd_co_rw_vector(acb); + sd_co_rw_vector(&acb); =20 - QLIST_REMOVE(acb, aiocb_siblings); + QLIST_REMOVE(&acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - ret =3D acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } =20 static coroutine_fn int64_t --=20 2.9.3 From nobody Mon Apr 29 06:36:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1485927415506538.5820938828967; Tue, 31 Jan 2017 21:36:55 -0800 (PST) Received: from localhost ([::1]:42817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnbB-0005CB-PD for importer@patchew.org; Wed, 01 Feb 2017 00:36:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnZC-00043h-02 for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYnZB-0006Vm-0Z for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cYnZ8-0006UU-If; Wed, 01 Feb 2017 00:34:46 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 B2CA681F07; Wed, 1 Feb 2017 05:34:46 +0000 (UTC) Received: from localhost (ovpn-116-86.phx2.redhat.com [10.3.116.86]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v115YjBt006349 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 1 Feb 2017 00:34:46 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 1 Feb 2017 00:34:39 -0500 Message-Id: <20170201053440.26002-5-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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 01 Feb 2017 05:34:46 +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 4/5] sheepdog: simplify inflight_aio_head management 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Add to the list in add_aio_request and, indirectly, resend_aioreq. Inline free_aio_req in the caller, it does not simply undo alloc_aio_req's job. Signed-off-by: Paolo Bonzini Message-id: 20161129113245.32724-5-pbonzini@redhat.com Signed-off-by: Jeff Cody --- block/sheepdog.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 33ded57..3ef7601 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -479,16 +479,6 @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState = *s, SheepdogAIOCB *acb, return aio_req; } =20 -static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) -{ - SheepdogAIOCB *acb =3D aio_req->aiocb; - - QLIST_REMOVE(aio_req, aio_siblings); - g_free(aio_req); - - acb->nr_pending--; -} - static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, QEMUIOVector *qiov, int64_t sector_num, int nb_se= ctors, int type) @@ -730,7 +720,6 @@ static coroutine_fn void reconnect_to_sdog(void *opaque) while (!QLIST_EMPTY(&s->failed_aio_head)) { aio_req =3D QLIST_FIRST(&s->failed_aio_head); QLIST_REMOVE(aio_req, aio_siblings); - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); resend_aioreq(s, aio_req); } } @@ -825,6 +814,7 @@ static void coroutine_fn aio_read_response(void *opaque) */ s->co_recv =3D NULL; =20 + QLIST_REMOVE(aio_req, aio_siblings); switch (rsp.result) { case SD_RES_SUCCESS: break; @@ -849,8 +839,9 @@ static void coroutine_fn aio_read_response(void *opaque) break; } =20 - free_aio_req(s, aio_req); - if (!acb->nr_pending) { + g_free(aio_req); + + if (!--acb->nr_pending) { /* * We've finished all requests which belong to the AIOCB, so * we can switch back to sd_co_readv/writev now. @@ -1110,6 +1101,8 @@ static void coroutine_fn add_aio_request(BDRVSheepdog= State *s, AIOReq *aio_req, uint64_t old_oid =3D aio_req->base_oid; bool create =3D aio_req->create; =20 + QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); + if (!nr_copies) { error_report("bug"); } @@ -1983,7 +1976,6 @@ static void coroutine_fn sd_write_done(SheepdogAIOCB = *acb) iov.iov_len =3D sizeof(s->inode); aio_req =3D alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), data_len, offset, 0, false, 0, offset); - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA); if (--acb->nr_pending) { qemu_coroutine_yield(); @@ -2185,8 +2177,6 @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOC= B *acb) old_oid, acb->aiocb_type =3D=3D AIOCB_DISCARD_OBJ ? 0 : done); - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); - add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov, acb->aiocb_type); done: @@ -2280,7 +2270,6 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriv= erState *bs) acb.nr_pending++; aio_req =3D alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id), 0, 0, 0, false, 0, 0); - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type); =20 if (--acb.nr_pending) { --=20 2.9.3 From nobody Mon Apr 29 06:36:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1485927631663269.01799777414635; Tue, 31 Jan 2017 21:40:31 -0800 (PST) Received: from localhost ([::1]:42829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnef-000077-Ms for importer@patchew.org; Wed, 01 Feb 2017 00:40:29 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; } =20 +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_se= ctors, int type) @@ -505,6 +518,13 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheep= dogState *s, acb->min_dirty_data_idx =3D UINT32_MAX; acb->max_dirty_data_idx =3D 0; acb->aiocb_type =3D type; + + if (type =3D=3D AIOCB_FLUSH_CACHE) { + return; + } + + wait_for_overlapping_aiocb(s, acb); + QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings); } =20 /* Return -EIO in case of error, file descriptor on success */ @@ -2189,18 +2209,14 @@ static void coroutine_fn sd_co_rw_vector(SheepdogAI= OCB *acb) } } =20 -static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *a= iocb) +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 =3D=3D AIOCB_FLUSH_CACHE) { + return; } =20 - 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); } =20 static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_= num, @@ -2219,18 +2235,10 @@ static coroutine_fn int sd_co_writev(BlockDriverSta= te *bs, int64_t sector_num, } =20 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); =20 - QLIST_REMOVE(&acb, aiocb_siblings); - qemu_co_queue_restart_all(&s->overlapping_queue); return acb.ret; } =20 @@ -2241,17 +2249,9 @@ static coroutine_fn int sd_co_readv(BlockDriverState= *bs, int64_t sector_num, BDRVSheepdogState *s =3D bs->opaque; =20 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); =20 - QLIST_REMOVE(&acb, aiocb_siblings); - qemu_co_queue_restart_all(&s->overlapping_queue); return acb.ret; } =20 @@ -2275,6 +2275,8 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriv= erState *bs) if (--acb.nr_pending) { qemu_coroutine_yield(); } + + sd_aio_complete(&acb); return acb.ret; } =20 @@ -2730,17 +2732,9 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverSt= ate *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); =20 - QLIST_REMOVE(&acb, aiocb_siblings); - qemu_co_queue_restart_all(&s->overlapping_queue); return acb.ret; } =20 --=20 2.9.3