From nobody Wed Dec 17 21:48:37 2025 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 1498238536765917.2736965379535; Fri, 23 Jun 2017 10:22:16 -0700 (PDT) Received: from localhost ([::1]:36566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOSHf-00083N-67 for importer@patchew.org; Fri, 23 Jun 2017 13:22:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dORMc-0001x7-S0 for qemu-devel@nongnu.org; Fri, 23 Jun 2017 12:23:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dORMa-0008DG-Ps for qemu-devel@nongnu.org; Fri, 23 Jun 2017 12:23:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34248) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dORMV-00084m-G6; Fri, 23 Jun 2017 12:23:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78C077DCFA; Fri, 23 Jun 2017 16:23:10 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-196.ams2.redhat.com [10.36.117.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7B686EC99; Fri, 23 Jun 2017 16:23:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 78C077DCFA Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 78C077DCFA From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 23 Jun 2017 18:21:49 +0200 Message-Id: <1498234919-27316-52-git-send-email-kwolf@redhat.com> In-Reply-To: <1498234919-27316-1-git-send-email-kwolf@redhat.com> References: <1498234919-27316-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 23 Jun 2017 16:23:10 +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 51/61] qed: Simplify request handling 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: kwolf@redhat.com, qemu-devel@nongnu.org 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" Now that we process a request in the same coroutine from beginning to end and don't drop out of it any more, we can look like a proper coroutine-based driver and simply call qed_aio_next_io() and get a return value from it instead of spawning an additional coroutine that reenters the parent when it's done. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 101 +++++++++++++-------------------------------------------= ---- block/qed.h | 3 +- 2 files changed, 22 insertions(+), 82 deletions(-) diff --git a/block/qed.c b/block/qed.c index cd3ef55..e53f6b5 100644 --- a/block/qed.c +++ b/block/qed.c @@ -21,10 +21,6 @@ #include "qapi/qmp/qerror.h" #include "sysemu/block-backend.h" =20 -static const AIOCBInfo qed_aiocb_info =3D { - .aiocb_size =3D sizeof(QEDAIOCB), -}; - static int bdrv_qed_probe(const uint8_t *buf, int buf_size, const char *filename) { @@ -253,13 +249,6 @@ static CachedL2Table *qed_new_l2_table(BDRVQEDState *s) return l2_table; } =20 -static void qed_aio_next_io(QEDAIOCB *acb); - -static void qed_aio_start_io(QEDAIOCB *acb) -{ - qed_aio_next_io(acb); -} - static void qed_plug_allocating_write_reqs(BDRVQEDState *s) { assert(!s->allocating_write_reqs_plugged); @@ -751,7 +740,7 @@ static int64_t coroutine_fn bdrv_qed_co_get_block_statu= s(BlockDriverState *bs, =20 static BDRVQEDState *acb_to_s(QEDAIOCB *acb) { - return acb->common.bs->opaque; + return acb->bs->opaque; } =20 /** @@ -888,28 +877,10 @@ static void qed_update_l2_table(BDRVQEDState *s, QEDT= able *table, int index, } } =20 -static void qed_aio_complete_bh(void *opaque) -{ - QEDAIOCB *acb =3D opaque; - BDRVQEDState *s =3D acb_to_s(acb); - BlockCompletionFunc *cb =3D acb->common.cb; - void *user_opaque =3D acb->common.opaque; - int ret =3D acb->bh_ret; - - qemu_aio_unref(acb); - - /* Invoke callback */ - qed_acquire(s); - cb(user_opaque, ret); - qed_release(s); -} - -static void qed_aio_complete(QEDAIOCB *acb, int ret) +static void qed_aio_complete(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); =20 - trace_qed_aio_complete(s, acb, ret); - /* Free resources */ qemu_iovec_destroy(&acb->cur_qiov); qed_unref_l2_cache_entry(acb->request.l2_table); @@ -920,11 +891,6 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret) acb->qiov->iov[0].iov_base =3D NULL; } =20 - /* Arrange for a bh to invoke the completion function */ - acb->bh_ret =3D ret; - aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), - qed_aio_complete_bh, acb); - /* Start next allocating write request waiting behind this one. Note = that * requests enqueue themselves when they first hit an unallocated clus= ter * but they wait until the entire request is finished before waking up= the @@ -1172,7 +1138,7 @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uint6= 4_t offset, size_t len) struct iovec *iov =3D acb->qiov->iov; =20 if (!iov->iov_base) { - iov->iov_base =3D qemu_try_blockalign(acb->common.bs, iov->iov= _len); + iov->iov_base =3D qemu_try_blockalign(acb->bs, iov->iov_len); if (iov->iov_base =3D=3D NULL) { return -ENOMEM; } @@ -1231,7 +1197,7 @@ static int qed_aio_read_data(void *opaque, int ret, u= int64_t offset, size_t len) { QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); - BlockDriverState *bs =3D acb->common.bs; + BlockDriverState *bs =3D acb->bs; =20 /* Adjust offset into cluster */ offset +=3D qed_offset_into_cluster(s, acb->cur_pos); @@ -1260,7 +1226,7 @@ static int qed_aio_read_data(void *opaque, int ret, u= int64_t offset, size_t len) /** * Begin next I/O or complete the request */ -static void qed_aio_next_io(QEDAIOCB *acb) +static int qed_aio_next_io(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset; @@ -1282,16 +1248,15 @@ static void qed_aio_next_io(QEDAIOCB *acb) =20 /* Complete request */ if (acb->cur_pos >=3D acb->end_pos) { - qed_aio_complete(acb, 0); - return; + ret =3D 0; + break; } =20 /* Find next cluster and start I/O */ len =3D acb->end_pos - acb->cur_pos; ret =3D qed_find_cluster(s, &acb->request, acb->cur_pos, &len, &of= fset); if (ret < 0) { - qed_aio_complete(acb, ret); - return; + break; } =20 if (acb->flags & QED_AIOCB_WRITE) { @@ -1301,56 +1266,32 @@ static void qed_aio_next_io(QEDAIOCB *acb) } =20 if (ret < 0 && ret !=3D -EAGAIN) { - qed_aio_complete(acb, ret); - return; + break; } } -} =20 -typedef struct QEDRequestCo { - Coroutine *co; - bool done; - int ret; -} QEDRequestCo; - -static void qed_co_request_cb(void *opaque, int ret) -{ - QEDRequestCo *co =3D opaque; - - co->done =3D true; - co->ret =3D ret; - qemu_coroutine_enter_if_inactive(co->co); + trace_qed_aio_complete(s, acb, ret); + qed_aio_complete(acb); + return ret; } =20 static int coroutine_fn qed_co_request(BlockDriverState *bs, int64_t secto= r_num, QEMUIOVector *qiov, int nb_sectors, int flags) { - QEDRequestCo co =3D { - .co =3D qemu_coroutine_self(), - .done =3D false, + QEDAIOCB acb =3D { + .bs =3D bs, + .cur_pos =3D (uint64_t) sector_num * BDRV_SECTOR_SIZE, + .end_pos =3D (sector_num + nb_sectors) * BDRV_SECTOR_SIZE, + .qiov =3D qiov, + .flags =3D flags, }; - QEDAIOCB *acb =3D qemu_aio_get(&qed_aiocb_info, bs, qed_co_request_cb,= &co); - - trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, &co, flag= s); + qemu_iovec_init(&acb.cur_qiov, qiov->niov); =20 - acb->flags =3D flags; - acb->qiov =3D qiov; - acb->qiov_offset =3D 0; - acb->cur_pos =3D (uint64_t)sector_num * BDRV_SECTOR_SIZE; - acb->end_pos =3D acb->cur_pos + nb_sectors * BDRV_SECTOR_SIZE; - acb->backing_qiov =3D NULL; - acb->request.l2_table =3D NULL; - qemu_iovec_init(&acb->cur_qiov, qiov->niov); + trace_qed_aio_setup(bs->opaque, &acb, sector_num, nb_sectors, NULL, fl= ags); =20 /* Start request */ - qed_aio_start_io(acb); - - if (!co.done) { - qemu_coroutine_yield(); - } - - return co.ret; + return qed_aio_next_io(&acb); } =20 static int coroutine_fn bdrv_qed_co_readv(BlockDriverState *bs, diff --git a/block/qed.h b/block/qed.h index 37558e4..fb80943 100644 --- a/block/qed.h +++ b/block/qed.h @@ -129,8 +129,7 @@ enum { }; =20 typedef struct QEDAIOCB { - BlockAIOCB common; - int bh_ret; /* final return status for completion = bh */ + BlockDriverState *bs; QSIMPLEQ_ENTRY(QEDAIOCB) next; /* next request */ int flags; /* QED_AIOCB_* bits ORed together */ uint64_t end_pos; /* request end on block device, in byt= es */ --=20 1.8.3.1