From nobody Sat Feb 7 05:57:23 2026 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 1495831568281195.61459186447894; Fri, 26 May 2017 13:46:08 -0700 (PDT) Received: from localhost ([::1]:38413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM7a-0005M0-VL for importer@patchew.org; Fri, 26 May 2017 16:46:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELm3-0005zb-7g for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELm1-0005Zb-Pd for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60382) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlv-0005Xq-LF; Fri, 26 May 2017 16:23:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A302B3D943; Fri, 26 May 2017 20:23:42 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-43.ams2.redhat.com [10.36.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id E92BF17B63; Fri, 26 May 2017 20:23:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A302B3D943 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A302B3D943 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:08 +0200 Message-Id: <1495830130-30611-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1495830130-30611-1-git-send-email-kwolf@redhat.com> References: <1495830130-30611-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 26 May 2017 20:23:42 +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] [PATCH 27/29] 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, pbonzini@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@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" 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 | 106 ++++++++++++++++----------------------------------------= ---- block/qed.h | 3 +- 2 files changed, 28 insertions(+), 81 deletions(-) diff --git a/block/qed.c b/block/qed.c index 2eee451..d3f7d0c 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,27 +877,9 @@ static void qed_update_l2_table(BDRVQEDState *s, QEDTa= ble *table, int index, } } =20 -static void qed_aio_complete_bh(void *opaque) +static void qed_aio_complete(QEDAIOCB *acb) { - 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) -{ - BDRVQEDState *s =3D acb_to_s(acb); - - trace_qed_aio_complete(s, acb, ret); =20 /* Free resources */ qemu_iovec_destroy(&acb->cur_qiov); @@ -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; } @@ -1235,7 +1201,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); @@ -1264,7 +1230,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; @@ -1286,16 +1252,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) { @@ -1305,55 +1270,38 @@ static void qed_aio_next_io(QEDAIOCB *acb) } =20 if (ret < 0 && ret !=3D -EAGAIN) { - qed_aio_complete(acb, ret); - return; + break; } } -} - -typedef struct QEDRequestCo { - Coroutine *co; - bool done; - int ret; -} QEDRequestCo; =20 -static void coroutine_fn 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 qed_co_request(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, int flags) { - QEDRequestCo co =3D { - .co =3D qemu_coroutine_self(), - .done =3D false, - }; - 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); + QEDAIOCB *acb; + int ret; =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; + acb =3D g_new(QEDAIOCB, 1); + *acb =3D (QEDAIOCB) { + .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, + }; qemu_iovec_init(&acb->cur_qiov, qiov->niov); =20 - /* Start request */ - qed_aio_start_io(acb); + trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, NULL, fla= gs); =20 - if (!co.done) { - qemu_coroutine_yield(); - } + /* Start request */ + ret =3D qed_aio_next_io(acb); =20 - return co.ret; + g_free(acb); + return ret; } =20 static int bdrv_qed_co_readv(BlockDriverState *bs, int64_t sector_num, 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