From patchwork Fri May 26 20:22:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 767562 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 3wZJ6y4CqPz9s7h for ; Sat, 27 May 2017 06:45:30 +1000 (AEST) Received: from localhost ([::1]:38404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM6y-0004ig-9Q for incoming@patchwork.ozlabs.org; Fri, 26 May 2017 16:45:28 -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) 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 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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" -static const AIOCBInfo qed_aiocb_info = { - .aiocb_size = 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; } -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_status(BlockDriverState *bs, static BDRVQEDState *acb_to_s(QEDAIOCB *acb) { - return acb->common.bs->opaque; + return acb->bs->opaque; } /** @@ -888,27 +877,9 @@ static void qed_update_l2_table(BDRVQEDState *s, QEDTable *table, int index, } } -static void qed_aio_complete_bh(void *opaque) +static void qed_aio_complete(QEDAIOCB *acb) { - QEDAIOCB *acb = opaque; BDRVQEDState *s = acb_to_s(acb); - BlockCompletionFunc *cb = acb->common.cb; - void *user_opaque = acb->common.opaque; - int ret = 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 = acb_to_s(acb); - - trace_qed_aio_complete(s, acb, ret); /* 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 = NULL; } - /* Arrange for a bh to invoke the completion function */ - acb->bh_ret = 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 cluster * 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, uint64_t offset, size_t len) struct iovec *iov = acb->qiov->iov; if (!iov->iov_base) { - iov->iov_base = qemu_try_blockalign(acb->common.bs, iov->iov_len); + iov->iov_base = qemu_try_blockalign(acb->bs, iov->iov_len); if (iov->iov_base == NULL) { return -ENOMEM; } @@ -1235,7 +1201,7 @@ static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len) { QEDAIOCB *acb = opaque; BDRVQEDState *s = acb_to_s(acb); - BlockDriverState *bs = acb->common.bs; + BlockDriverState *bs = acb->bs; /* Adjust offset into cluster */ offset += qed_offset_into_cluster(s, acb->cur_pos); @@ -1264,7 +1230,7 @@ static int qed_aio_read_data(void *opaque, int ret, uint64_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 = acb_to_s(acb); uint64_t offset; @@ -1286,16 +1252,15 @@ static void qed_aio_next_io(QEDAIOCB *acb) /* Complete request */ if (acb->cur_pos >= acb->end_pos) { - qed_aio_complete(acb, 0); - return; + ret = 0; + break; } /* Find next cluster and start I/O */ len = acb->end_pos - acb->cur_pos; ret = qed_find_cluster(s, &acb->request, acb->cur_pos, &len, &offset); if (ret < 0) { - qed_aio_complete(acb, ret); - return; + break; } if (acb->flags & QED_AIOCB_WRITE) { @@ -1305,55 +1270,38 @@ static void qed_aio_next_io(QEDAIOCB *acb) } if (ret < 0 && ret != -EAGAIN) { - qed_aio_complete(acb, ret); - return; + break; } } -} - -typedef struct QEDRequestCo { - Coroutine *co; - bool done; - int ret; -} QEDRequestCo; -static void coroutine_fn qed_co_request_cb(void *opaque, int ret) -{ - QEDRequestCo *co = opaque; - - co->done = true; - co->ret = ret; - qemu_coroutine_enter_if_inactive(co->co); + trace_qed_aio_complete(s, acb, ret); + qed_aio_complete(acb); + return ret; } static int qed_co_request(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, int flags) { - QEDRequestCo co = { - .co = qemu_coroutine_self(), - .done = false, - }; - QEDAIOCB *acb = qemu_aio_get(&qed_aiocb_info, bs, qed_co_request_cb, &co); - - trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, &co, flags); + QEDAIOCB *acb; + int ret; - acb->flags = flags; - acb->qiov = qiov; - acb->qiov_offset = 0; - acb->cur_pos = (uint64_t)sector_num * BDRV_SECTOR_SIZE; - acb->end_pos = acb->cur_pos + nb_sectors * BDRV_SECTOR_SIZE; - acb->backing_qiov = NULL; - acb->request.l2_table = NULL; + acb = g_new(QEDAIOCB, 1); + *acb = (QEDAIOCB) { + .bs = bs, + .cur_pos = (uint64_t) sector_num * BDRV_SECTOR_SIZE, + .end_pos = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE, + .qiov = qiov, + .flags = flags, + }; qemu_iovec_init(&acb->cur_qiov, qiov->niov); - /* Start request */ - qed_aio_start_io(acb); + trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, NULL, flags); - if (!co.done) { - qemu_coroutine_yield(); - } + /* Start request */ + ret = qed_aio_next_io(acb); - return co.ret; + g_free(acb); + return ret; } 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 { }; 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 bytes */