From nobody Wed Dec 17 21:57:49 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 1498236686269408.4620971302634; Fri, 23 Jun 2017 09:51:26 -0700 (PDT) Received: from localhost ([::1]:36383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dORnl-0003eu-KF for importer@patchew.org; Fri, 23 Jun 2017 12:51:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dORM7-0001MH-IT for qemu-devel@nongnu.org; Fri, 23 Jun 2017 12:22:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dORM4-0007jd-3D for qemu-devel@nongnu.org; Fri, 23 Jun 2017 12:22:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dORM0-0007hp-Sp; Fri, 23 Jun 2017 12:22:41 -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 D7166C01CB60; Fri, 23 Jun 2017 16:22:39 +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 ECB526EC75; Fri, 23 Jun 2017 16:22:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D7166C01CB60 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D7166C01CB60 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 23 Jun 2017 18:21:27 +0200 Message-Id: <1498234919-27316-30-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.32]); Fri, 23 Jun 2017 16:22:40 +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 29/61] qed: Remove callback from qed_find_cluster() 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" Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed-cluster.c | 39 ++++++++++++++++++++++----------------- block/qed.c | 24 +++++++++++------------- block/qed.h | 4 ++-- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/block/qed-cluster.c b/block/qed-cluster.c index d279944..88dc979 100644 --- a/block/qed-cluster.c +++ b/block/qed-cluster.c @@ -67,22 +67,27 @@ static unsigned int qed_count_contiguous_clusters(BDRVQ= EDState *s, * @s: QED state * @request: L2 cache entry * @pos: Byte position in device - * @len: Number of bytes - * @cb: Completion function - * @opaque: User data for completion function + * @len: Number of bytes (may be shortened on return) + * @img_offset: Contains offset in the image file on success * * This function translates a position in the block device to an offset in= the - * image file. It invokes the cb completion callback to report back the - * translated offset or unallocated range in the image file. + * image file. The translated offset or unallocated range in the image fil= e is + * reported back in *img_offset and *len. * * If the L2 table exists, request->l2_table points to the L2 table cache = entry * and the caller must free the reference when they are finished. The cac= he * entry is exposed in this way to avoid callers having to read the L2 tab= le * again later during request processing. If request->l2_table is non-NUL= L it * will be unreferenced before taking on the new cache entry. + * + * On success QED_CLUSTER_FOUND is returned and img_offset/len are a conti= guous + * range in the image file. + * + * On failure QED_CLUSTER_L2 or QED_CLUSTER_L1 is returned for missing L2 = or L1 + * table offset, respectively. len is number of contiguous unallocated byt= es. */ -void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, - size_t len, QEDFindClusterFunc *cb, void *opaque) +int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, + size_t *len, uint64_t *img_offset) { uint64_t l2_offset; uint64_t offset =3D 0; @@ -93,16 +98,16 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *requ= est, uint64_t pos, /* Limit length to L2 boundary. Requests are broken up at the L2 boun= dary * so that a request acts on one L2 table at a time. */ - len =3D MIN(len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos); + *len =3D MIN(*len, (((pos >> s->l1_shift) + 1) << s->l1_shift) - pos); =20 l2_offset =3D s->l1_table->offsets[qed_l1_index(s, pos)]; if (qed_offset_is_unalloc_cluster(l2_offset)) { - cb(opaque, QED_CLUSTER_L1, 0, len); - return; + *img_offset =3D 0; + return QED_CLUSTER_L1; } if (!qed_check_table_offset(s, l2_offset)) { - cb(opaque, -EINVAL, 0, 0); - return; + *img_offset =3D *len =3D 0; + return -EINVAL; } =20 ret =3D qed_read_l2_table(s, request, l2_offset); @@ -112,8 +117,7 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *requ= est, uint64_t pos, } =20 index =3D qed_l2_index(s, pos); - n =3D qed_bytes_to_clusters(s, - qed_offset_into_cluster(s, pos) + len); + n =3D qed_bytes_to_clusters(s, qed_offset_into_cluster(s, pos) + *len); n =3D qed_count_contiguous_clusters(s, request->l2_table->table, index, n, &offset); =20 @@ -127,10 +131,11 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *re= quest, uint64_t pos, ret =3D -EINVAL; } =20 - len =3D MIN(len, - n * s->header.cluster_size - qed_offset_into_cluster(s, pos)= ); + *len =3D MIN(*len, + n * s->header.cluster_size - qed_offset_into_cluster(s, pos= )); =20 out: - cb(opaque, ret, offset, len); + *img_offset =3D offset; qed_release(s); + return ret; } diff --git a/block/qed.c b/block/qed.c index a837a28..290cbcd 100644 --- a/block/qed.c +++ b/block/qed.c @@ -776,14 +776,14 @@ static int64_t coroutine_fn bdrv_qed_co_get_block_sta= tus(BlockDriverState *bs, .file =3D file, }; QEDRequest request =3D { .l2_table =3D NULL }; + uint64_t offset; + int ret; =20 - qed_find_cluster(s, &request, cb.pos, len, qed_is_allocated_cb, &cb); + ret =3D qed_find_cluster(s, &request, cb.pos, &len, &offset); + qed_is_allocated_cb(&cb, ret, offset, len); =20 - /* Now sleep if the callback wasn't invoked immediately */ - while (cb.status =3D=3D BDRV_BLOCK_OFFSET_MASK) { - cb.co =3D qemu_coroutine_self(); - qemu_coroutine_yield(); - } + /* The callback was invoked immediately */ + assert(cb.status !=3D BDRV_BLOCK_OFFSET_MASK); =20 qed_unref_l2_cache_entry(request.l2_table); =20 @@ -1306,8 +1306,6 @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uint= 64_t offset, size_t len) * or -errno * @offset: Cluster offset in bytes * @len: Length in bytes - * - * Callback from qed_find_cluster(). */ static void qed_aio_write_data(void *opaque, int ret, uint64_t offset, size_t len) @@ -1343,8 +1341,6 @@ static void qed_aio_write_data(void *opaque, int ret, * or -errno * @offset: Cluster offset in bytes * @len: Length in bytes - * - * Callback from qed_find_cluster(). */ static void qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len) @@ -1393,6 +1389,8 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret) BDRVQEDState *s =3D acb_to_s(acb); QEDFindClusterFunc *io_fn =3D (acb->flags & QED_AIOCB_WRITE) ? qed_aio_write_data : qed_aio_read_data; + uint64_t offset; + size_t len; =20 trace_qed_aio_next_io(s, acb, ret, acb->cur_pos + acb->cur_qiov.size); =20 @@ -1419,9 +1417,9 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret) } =20 /* Find next cluster and start I/O */ - qed_find_cluster(s, &acb->request, - acb->cur_pos, acb->end_pos - acb->cur_pos, - io_fn, acb); + len =3D acb->end_pos - acb->cur_pos; + ret =3D qed_find_cluster(s, &acb->request, acb->cur_pos, &len, &offset= ); + io_fn(acb, ret, offset, len); } =20 static BlockAIOCB *qed_aio_setup(BlockDriverState *bs, diff --git a/block/qed.h b/block/qed.h index c715058..6ab5702 100644 --- a/block/qed.h +++ b/block/qed.h @@ -247,8 +247,8 @@ int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest= *request, /** * Cluster functions */ -void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, - size_t len, QEDFindClusterFunc *cb, void *opaque); +int qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, + size_t *len, uint64_t *img_offset); =20 /** * Consistency check --=20 1.8.3.1