From nobody Sun May 5 19:45:33 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 1495830428337686.5709680277723; Fri, 26 May 2017 13:27:08 -0700 (PDT) Received: from localhost ([::1]:38293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELpC-0008OZ-Po for importer@patchew.org; Fri, 26 May 2017 16:27:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELkk-0004ER-JR for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELkj-0005Av-Qn for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELkh-0005A4-H9; Fri, 26 May 2017 16:22:27 -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 78D6919CBD1; Fri, 26 May 2017 20:22:26 +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 1B9F61713B; Fri, 26 May 2017 20:22:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 78D6919CBD1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 78D6919CBD1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:42 +0200 Message-Id: <1495830130-30611-2-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.29]); Fri, 26 May 2017 20:22:26 +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 01/29] qed: Use bottom half to resume waiting 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: 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" The qed driver serialises allocating write requests. When the active allocation is finished, the AIO callback is called, but after this, the next allocating request is immediately processed instead of leaving the coroutine. Resuming another allocation request in the same request coroutine means that the request now runs in the wrong coroutine. The following is one of the possible effects of this: The completed request will generally reenter its request coroutine in a bottom half, expecting that it completes the request in bdrv_driver_pwritev(). However, if the second request actually yielded before leaving the coroutine, the reused request coroutine is in an entirely different place and is reentered prematurely. Not a good idea. Let's make sure that we exit the coroutine after completing the first request by resuming the next allocating request only with a bottom half. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/block/qed.c b/block/qed.c index 8d899fd..a837a28 100644 --- a/block/qed.c +++ b/block/qed.c @@ -967,6 +967,11 @@ static void qed_aio_complete_bh(void *opaque) qed_release(s); } =20 +static void qed_resume_alloc_bh(void *opaque) +{ + qed_aio_start_io(opaque); +} + static void qed_aio_complete(QEDAIOCB *acb, int ret) { BDRVQEDState *s =3D acb_to_s(acb); @@ -995,10 +1000,12 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret) * requests multiple times but rather finish one at a time completely. */ if (acb =3D=3D QSIMPLEQ_FIRST(&s->allocating_write_reqs)) { + QEDAIOCB *next_acb; QSIMPLEQ_REMOVE_HEAD(&s->allocating_write_reqs, next); - acb =3D QSIMPLEQ_FIRST(&s->allocating_write_reqs); - if (acb) { - qed_aio_start_io(acb); + next_acb =3D QSIMPLEQ_FIRST(&s->allocating_write_reqs); + if (next_acb) { + aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), + qed_resume_alloc_bh, next_acb); } else if (s->header.features & QED_F_NEED_CHECK) { qed_start_need_check_timer(s); } --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830591886247.27070758422394; Fri, 26 May 2017 13:29:51 -0700 (PDT) Received: from localhost ([::1]:38309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELrq-0003vt-Fb for importer@patchew.org; Fri, 26 May 2017 16:29:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELkp-0004L9-9u for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELkm-0005Bn-4t for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELkj-0005Aj-NF; Fri, 26 May 2017 16:22:29 -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 B1A1E80045; Fri, 26 May 2017 20:22:28 +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 DBB1F1748C; Fri, 26 May 2017 20:22:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B1A1E80045 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 B1A1E80045 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:43 +0200 Message-Id: <1495830130-30611-3-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.27]); Fri, 26 May 2017 20:22:28 +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 02/29] qed: Make qed_read_table() synchronous 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" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed-table.c | 56 ++++++++++++++++++---------------------------------= ---- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/block/qed-table.c b/block/qed-table.c index b12c298..f330538 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -18,59 +18,39 @@ #include "qed.h" #include "qemu/bswap.h" =20 -typedef struct { - GenericCB gencb; - BDRVQEDState *s; - QEDTable *table; - - struct iovec iov; +static void qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *tab= le, + BlockCompletionFunc *cb, void *opaque) +{ QEMUIOVector qiov; -} QEDReadTableCB; + int noffsets; + int i, ret; =20 -static void qed_read_table_cb(void *opaque, int ret) -{ - QEDReadTableCB *read_table_cb =3D opaque; - QEDTable *table =3D read_table_cb->table; - BDRVQEDState *s =3D read_table_cb->s; - int noffsets =3D read_table_cb->qiov.size / sizeof(uint64_t); - int i; + struct iovec iov =3D { + .iov_base =3D table->offsets, + .iov_len =3D s->header.cluster_size * s->header.table_size, + }; + qemu_iovec_init_external(&qiov, &iov, 1); =20 - /* Handle I/O error */ - if (ret) { + trace_qed_read_table(s, offset, table); + + ret =3D bdrv_preadv(s->bs->file, offset, &qiov); + if (ret < 0) { goto out; } =20 /* Byteswap offsets */ qed_acquire(s); + noffsets =3D qiov.size / sizeof(uint64_t); for (i =3D 0; i < noffsets; i++) { table->offsets[i] =3D le64_to_cpu(table->offsets[i]); } qed_release(s); =20 + ret =3D 0; out: /* Completion */ - trace_qed_read_table_cb(s, read_table_cb->table, ret); - gencb_complete(&read_table_cb->gencb, ret); -} - -static void qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *tab= le, - BlockCompletionFunc *cb, void *opaque) -{ - QEDReadTableCB *read_table_cb =3D gencb_alloc(sizeof(*read_table_cb), - cb, opaque); - QEMUIOVector *qiov =3D &read_table_cb->qiov; - - trace_qed_read_table(s, offset, table); - - read_table_cb->s =3D s; - read_table_cb->table =3D table; - read_table_cb->iov.iov_base =3D table->offsets, - read_table_cb->iov.iov_len =3D s->header.cluster_size * s->header.tabl= e_size, - - qemu_iovec_init_external(qiov, &read_table_cb->iov, 1); - bdrv_aio_readv(s->bs->file, offset / BDRV_SECTOR_SIZE, qiov, - qiov->size / BDRV_SECTOR_SIZE, - qed_read_table_cb, read_table_cb); + trace_qed_read_table_cb(s, table, ret); + cb(opaque, ret); } =20 typedef struct { --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830285716857.9055065129223; Fri, 26 May 2017 13:24:45 -0700 (PDT) Received: from localhost ([::1]:38280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELmu-0006Ob-BH for importer@patchew.org; Fri, 26 May 2017 16:24:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELkr-0004P9-GJ for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELkq-0005Cv-KV for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELkm-0005Bc-2J; Fri, 26 May 2017 16:22:32 -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 1726AC04BD2B; Fri, 26 May 2017 20:22:31 +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 1EB151713B; Fri, 26 May 2017 20:22:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1726AC04BD2B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1726AC04BD2B From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:44 +0200 Message-Id: <1495830130-30611-4-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.31]); Fri, 26 May 2017 20:22:31 +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 03/29] qed: Remove callback from qed_read_table() 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" Instead of passing the return value to a callback, return it to the caller so that the callback can be inlined there. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed-table.c | 79 ++++++++++++++++++---------------------------------= ---- 1 file changed, 25 insertions(+), 54 deletions(-) diff --git a/block/qed-table.c b/block/qed-table.c index f330538..4270003 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -18,8 +18,7 @@ #include "qed.h" #include "qemu/bswap.h" =20 -static void qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *tab= le, - BlockCompletionFunc *cb, void *opaque) +static int qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *tabl= e) { QEMUIOVector qiov; int noffsets; @@ -50,7 +49,7 @@ static void qed_read_table(BDRVQEDState *s, uint64_t offs= et, QEDTable *table, out: /* Completion */ trace_qed_read_table_cb(s, table, ret); - cb(opaque, ret); + return ret; } =20 typedef struct { @@ -156,13 +155,7 @@ static void qed_sync_cb(void *opaque, int ret) =20 int qed_read_l1_table_sync(BDRVQEDState *s) { - int ret =3D -EINPROGRESS; - - qed_read_table(s, s->header.l1_table_offset, - s->l1_table, qed_sync_cb, &ret); - BDRV_POLL_WHILE(s->bs, ret =3D=3D -EINPROGRESS); - - return ret; + return qed_read_table(s, s->header.l1_table_offset, s->l1_table); } =20 void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int = n, @@ -184,46 +177,10 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned= int index, return ret; } =20 -typedef struct { - GenericCB gencb; - BDRVQEDState *s; - uint64_t l2_offset; - QEDRequest *request; -} QEDReadL2TableCB; - -static void qed_read_l2_table_cb(void *opaque, int ret) -{ - QEDReadL2TableCB *read_l2_table_cb =3D opaque; - QEDRequest *request =3D read_l2_table_cb->request; - BDRVQEDState *s =3D read_l2_table_cb->s; - CachedL2Table *l2_table =3D request->l2_table; - uint64_t l2_offset =3D read_l2_table_cb->l2_offset; - - qed_acquire(s); - if (ret) { - /* can't trust loaded L2 table anymore */ - qed_unref_l2_cache_entry(l2_table); - request->l2_table =3D NULL; - } else { - l2_table->offset =3D l2_offset; - - qed_commit_l2_cache_entry(&s->l2_cache, l2_table); - - /* This is guaranteed to succeed because we just committed the ent= ry - * to the cache. - */ - request->l2_table =3D qed_find_l2_cache_entry(&s->l2_cache, l2_off= set); - assert(request->l2_table !=3D NULL); - } - qed_release(s); - - gencb_complete(&read_l2_table_cb->gencb, ret); -} - void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offs= et, BlockCompletionFunc *cb, void *opaque) { - QEDReadL2TableCB *read_l2_table_cb; + int ret; =20 qed_unref_l2_cache_entry(request->l2_table); =20 @@ -237,14 +194,28 @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *r= equest, uint64_t offset, request->l2_table =3D qed_alloc_l2_cache_entry(&s->l2_cache); request->l2_table->table =3D qed_alloc_table(s); =20 - read_l2_table_cb =3D gencb_alloc(sizeof(*read_l2_table_cb), cb, opaque= ); - read_l2_table_cb->s =3D s; - read_l2_table_cb->l2_offset =3D offset; - read_l2_table_cb->request =3D request; - BLKDBG_EVENT(s->bs->file, BLKDBG_L2_LOAD); - qed_read_table(s, offset, request->l2_table->table, - qed_read_l2_table_cb, read_l2_table_cb); + ret =3D qed_read_table(s, offset, request->l2_table->table); + + qed_acquire(s); + if (ret) { + /* can't trust loaded L2 table anymore */ + qed_unref_l2_cache_entry(request->l2_table); + request->l2_table =3D NULL; + } else { + request->l2_table->offset =3D offset; + + qed_commit_l2_cache_entry(&s->l2_cache, request->l2_table); + + /* This is guaranteed to succeed because we just committed the ent= ry + * to the cache. + */ + request->l2_table =3D qed_find_l2_cache_entry(&s->l2_cache, offset= ); + assert(request->l2_table !=3D NULL); + } + qed_release(s); + + cb(opaque, ret); } =20 int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t = offset) --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 149583028158571.91478302371752; Fri, 26 May 2017 13:24:41 -0700 (PDT) Received: from localhost ([::1]:38279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELmp-0006Ji-ON for importer@patchew.org; Fri, 26 May 2017 16:24:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELks-0004Sf-DB for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELkr-0005D9-Ad for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58764) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELko-0005C9-F2; Fri, 26 May 2017 16:22:34 -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 6E7BC368E6; Fri, 26 May 2017 20:22:33 +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 7C69F1713B; Fri, 26 May 2017 20:22:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6E7BC368E6 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 6E7BC368E6 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:45 +0200 Message-Id: <1495830130-30611-5-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:22:33 +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 04/29] qed: Remove callback from qed_read_l2_table() 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" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed-cluster.c | 94 ++++++++++++++++++-------------------------------= ---- block/qed-table.c | 15 +++------ block/qed.h | 3 +- 3 files changed, 36 insertions(+), 76 deletions(-) diff --git a/block/qed-cluster.c b/block/qed-cluster.c index 8f5da74..d279944 100644 --- a/block/qed-cluster.c +++ b/block/qed-cluster.c @@ -61,59 +61,6 @@ static unsigned int qed_count_contiguous_clusters(BDRVQE= DState *s, return i - index; } =20 -typedef struct { - BDRVQEDState *s; - uint64_t pos; - size_t len; - - QEDRequest *request; - - /* User callback */ - QEDFindClusterFunc *cb; - void *opaque; -} QEDFindClusterCB; - -static void qed_find_cluster_cb(void *opaque, int ret) -{ - QEDFindClusterCB *find_cluster_cb =3D opaque; - BDRVQEDState *s =3D find_cluster_cb->s; - QEDRequest *request =3D find_cluster_cb->request; - uint64_t offset =3D 0; - size_t len =3D 0; - unsigned int index; - unsigned int n; - - qed_acquire(s); - if (ret) { - goto out; - } - - index =3D qed_l2_index(s, find_cluster_cb->pos); - n =3D qed_bytes_to_clusters(s, - qed_offset_into_cluster(s, find_cluster_cb->= pos) + - find_cluster_cb->len); - n =3D qed_count_contiguous_clusters(s, request->l2_table->table, - index, n, &offset); - - if (qed_offset_is_unalloc_cluster(offset)) { - ret =3D QED_CLUSTER_L2; - } else if (qed_offset_is_zero_cluster(offset)) { - ret =3D QED_CLUSTER_ZERO; - } else if (qed_check_cluster_offset(s, offset)) { - ret =3D QED_CLUSTER_FOUND; - } else { - ret =3D -EINVAL; - } - - len =3D MIN(find_cluster_cb->len, n * s->header.cluster_size - - qed_offset_into_cluster(s, find_cluster_cb->pos)); - -out: - find_cluster_cb->cb(find_cluster_cb->opaque, ret, offset, len); - qed_release(s); - g_free(find_cluster_cb); -} - /** * Find the offset of a data cluster * @@ -137,8 +84,11 @@ out: void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, size_t len, QEDFindClusterFunc *cb, void *opaque) { - QEDFindClusterCB *find_cluster_cb; uint64_t l2_offset; + uint64_t offset =3D 0; + unsigned int index; + unsigned int n; + int ret; =20 /* 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. @@ -155,14 +105,32 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *re= quest, uint64_t pos, return; } =20 - find_cluster_cb =3D g_malloc(sizeof(*find_cluster_cb)); - find_cluster_cb->s =3D s; - find_cluster_cb->pos =3D pos; - find_cluster_cb->len =3D len; - find_cluster_cb->cb =3D cb; - find_cluster_cb->opaque =3D opaque; - find_cluster_cb->request =3D request; + ret =3D qed_read_l2_table(s, request, l2_offset); + qed_acquire(s); + if (ret) { + goto out; + } + + index =3D qed_l2_index(s, pos); + 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); + + if (qed_offset_is_unalloc_cluster(offset)) { + ret =3D QED_CLUSTER_L2; + } else if (qed_offset_is_zero_cluster(offset)) { + ret =3D QED_CLUSTER_ZERO; + } else if (qed_check_cluster_offset(s, offset)) { + ret =3D QED_CLUSTER_FOUND; + } else { + ret =3D -EINVAL; + } + + len =3D MIN(len, + n * s->header.cluster_size - qed_offset_into_cluster(s, pos)= ); =20 - qed_read_l2_table(s, request, l2_offset, - qed_find_cluster_cb, find_cluster_cb); +out: + cb(opaque, ret, offset, len); + qed_release(s); } diff --git a/block/qed-table.c b/block/qed-table.c index 4270003..ffecbea 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -177,8 +177,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned i= nt index, return ret; } =20 -void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offs= et, - BlockCompletionFunc *cb, void *opaque) +int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offse= t) { int ret; =20 @@ -187,8 +186,7 @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *req= uest, uint64_t offset, /* Check for cached L2 entry */ request->l2_table =3D qed_find_l2_cache_entry(&s->l2_cache, offset); if (request->l2_table) { - cb(opaque, 0); - return; + return 0; } =20 request->l2_table =3D qed_alloc_l2_cache_entry(&s->l2_cache); @@ -215,17 +213,12 @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *r= equest, uint64_t offset, } qed_release(s); =20 - cb(opaque, ret); + return ret; } =20 int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t = offset) { - int ret =3D -EINPROGRESS; - - qed_read_l2_table(s, request, offset, qed_sync_cb, &ret); - BDRV_POLL_WHILE(s->bs, ret =3D=3D -EINPROGRESS); - - return ret; + return qed_read_l2_table(s, request, offset); } =20 void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, diff --git a/block/qed.h b/block/qed.h index ce8c314..c715058 100644 --- a/block/qed.h +++ b/block/qed.h @@ -237,8 +237,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned i= nt index, unsigned int n); int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset); -void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offs= et, - BlockCompletionFunc *cb, void *opaque); +int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offse= t); void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int index, unsigned int n, bool flush, BlockCompletionFunc *cb, void *opaque); --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830431487251.32221153373973; Fri, 26 May 2017 13:27:11 -0700 (PDT) Received: from localhost ([::1]:38294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELpG-0008Rp-2X for importer@patchew.org; Fri, 26 May 2017 16:27:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELku-0004aw-Mo for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELkt-0005Du-IQ for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELkq-0005Ce-M4; Fri, 26 May 2017 16:22:36 -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 A727161BA1; Fri, 26 May 2017 20:22:35 +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 CF9D91713B; Fri, 26 May 2017 20:22:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A727161BA1 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A727161BA1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:46 +0200 Message-Id: <1495830130-30611-6-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.39]); Fri, 26 May 2017 20:22:35 +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 05/29] 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, 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" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/qed-cluster.c | 39 ++++++++++++++++++++++----------------- block/qed.c | 20 +++++++++++--------- block/qed.h | 4 ++-- 3 files changed, 35 insertions(+), 28 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..031bb0a 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 @@ -1393,6 +1393,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 +1421,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 From nobody Sun May 5 19:45:33 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 1495830443531847.8768842644527; Fri, 26 May 2017 13:27:23 -0700 (PDT) Received: from localhost ([::1]:38295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELpS-0000BU-8O for importer@patchew.org; Fri, 26 May 2017 16:27:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELky-0004oz-Ju for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELkv-0005EK-H2 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELks-0005DQ-Qo; Fri, 26 May 2017 16:22:39 -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 CADC57D4E0; Fri, 26 May 2017 20:22:37 +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 11C5B1713B; Fri, 26 May 2017 20:22:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CADC57D4E0 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CADC57D4E0 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:47 +0200 Message-Id: <1495830130-30611-7-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.28]); Fri, 26 May 2017 20:22:37 +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 06/29] qed: Make qed_read_backing_file() synchronous 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" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/block/qed.c b/block/qed.c index 031bb0a..507e051 100644 --- a/block/qed.c +++ b/block/qed.c @@ -808,13 +808,13 @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb) * This function reads qiov->size bytes starting at pos from the backing f= ile. * If there is no backing file then zeroes are read. */ -static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos, - QEMUIOVector *qiov, - QEMUIOVector **backing_qiov, - BlockCompletionFunc *cb, void *opaque) +static int qed_read_backing_file(BDRVQEDState *s, uint64_t pos, + QEMUIOVector *qiov, + QEMUIOVector **backing_qiov) { uint64_t backing_length =3D 0; size_t size; + int ret; =20 /* If there is a backing file, get its length. Treat the absence of a * backing file like a zero length backing file. @@ -822,8 +822,7 @@ static void qed_read_backing_file(BDRVQEDState *s, uint= 64_t pos, if (s->bs->backing) { int64_t l =3D bdrv_getlength(s->bs->backing->bs); if (l < 0) { - cb(opaque, l); - return; + return l; } backing_length =3D l; } @@ -836,8 +835,7 @@ static void qed_read_backing_file(BDRVQEDState *s, uint= 64_t pos, =20 /* Complete now if there are no backing file sectors to read */ if (pos >=3D backing_length) { - cb(opaque, 0); - return; + return 0; } =20 /* If the read straddles the end of the backing file, shorten it */ @@ -849,8 +847,11 @@ static void qed_read_backing_file(BDRVQEDState *s, uin= t64_t pos, qemu_iovec_concat(*backing_qiov, qiov, 0, size); =20 BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO); - bdrv_aio_readv(s->bs->backing, pos / BDRV_SECTOR_SIZE, - *backing_qiov, size / BDRV_SECTOR_SIZE, cb, opaque); + ret =3D bdrv_preadv(s->bs->backing, pos, *backing_qiov); + if (ret < 0) { + return ret; + } + return 0; } =20 typedef struct { @@ -907,6 +908,7 @@ static void qed_copy_from_backing_file(BDRVQEDState *s,= uint64_t pos, void *opaque) { CopyFromBackingFileCB *copy_cb; + int ret; =20 /* Skip copy entirely if there is no work to do */ if (len =3D=3D 0) { @@ -922,8 +924,9 @@ static void qed_copy_from_backing_file(BDRVQEDState *s,= uint64_t pos, copy_cb->iov.iov_len =3D len; qemu_iovec_init_external(©_cb->qiov, ©_cb->iov, 1); =20 - qed_read_backing_file(s, pos, ©_cb->qiov, ©_cb->backing_qiov, - qed_copy_from_backing_file_write, copy_cb); + ret =3D qed_read_backing_file(s, pos, ©_cb->qiov, + ©_cb->backing_qiov); + qed_copy_from_backing_file_write(copy_cb, ret); } =20 /** @@ -1370,8 +1373,9 @@ static void qed_aio_read_data(void *opaque, int ret, qed_aio_start_io(acb); return; } else if (ret !=3D QED_CLUSTER_FOUND) { - qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, - &acb->backing_qiov, qed_aio_next_io_cb, acb); + ret =3D qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, + &acb->backing_qiov); + qed_aio_next_io(acb, ret); return; } =20 --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830588162141.45706886485414; Fri, 26 May 2017 13:29:48 -0700 (PDT) Received: from localhost ([::1]:38308 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELrm-0003sS-6C for importer@patchew.org; Fri, 26 May 2017 16:29:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELl1-0004y4-4M for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELl0-0005FI-4B for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50450) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELkw-0005ES-N2; Fri, 26 May 2017 16:22:42 -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 AFAD8C04BD2B; Fri, 26 May 2017 20:22:41 +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 35B5A17B8C; Fri, 26 May 2017 20:22:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AFAD8C04BD2B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AFAD8C04BD2B From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:48 +0200 Message-Id: <1495830130-30611-8-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.31]); Fri, 26 May 2017 20:22:41 +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 07/29] qed: Make qed_copy_from_backing_file() synchronous 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" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed.c | 78 +++++++++++++++++++++++----------------------------------= ---- 1 file changed, 29 insertions(+), 49 deletions(-) diff --git a/block/qed.c b/block/qed.c index 507e051..584a5ba 100644 --- a/block/qed.c +++ b/block/qed.c @@ -854,44 +854,6 @@ static int qed_read_backing_file(BDRVQEDState *s, uint= 64_t pos, return 0; } =20 -typedef struct { - GenericCB gencb; - BDRVQEDState *s; - QEMUIOVector qiov; - QEMUIOVector *backing_qiov; - struct iovec iov; - uint64_t offset; -} CopyFromBackingFileCB; - -static void qed_copy_from_backing_file_cb(void *opaque, int ret) -{ - CopyFromBackingFileCB *copy_cb =3D opaque; - qemu_vfree(copy_cb->iov.iov_base); - gencb_complete(©_cb->gencb, ret); -} - -static void qed_copy_from_backing_file_write(void *opaque, int ret) -{ - CopyFromBackingFileCB *copy_cb =3D opaque; - BDRVQEDState *s =3D copy_cb->s; - - if (copy_cb->backing_qiov) { - qemu_iovec_destroy(copy_cb->backing_qiov); - g_free(copy_cb->backing_qiov); - copy_cb->backing_qiov =3D NULL; - } - - if (ret) { - qed_copy_from_backing_file_cb(copy_cb, ret); - return; - } - - BLKDBG_EVENT(s->bs->file, BLKDBG_COW_WRITE); - bdrv_aio_writev(s->bs->file, copy_cb->offset / BDRV_SECTOR_SIZE, - ©_cb->qiov, copy_cb->qiov.size / BDRV_SECTOR_SIZE, - qed_copy_from_backing_file_cb, copy_cb); -} - /** * Copy data from backing file into the image * @@ -907,7 +869,9 @@ static void qed_copy_from_backing_file(BDRVQEDState *s,= uint64_t pos, BlockCompletionFunc *cb, void *opaque) { - CopyFromBackingFileCB *copy_cb; + QEMUIOVector qiov; + QEMUIOVector *backing_qiov =3D NULL; + struct iovec iov; int ret; =20 /* Skip copy entirely if there is no work to do */ @@ -916,17 +880,33 @@ static void qed_copy_from_backing_file(BDRVQEDState *= s, uint64_t pos, return; } =20 - copy_cb =3D gencb_alloc(sizeof(*copy_cb), cb, opaque); - copy_cb->s =3D s; - copy_cb->offset =3D offset; - copy_cb->backing_qiov =3D NULL; - copy_cb->iov.iov_base =3D qemu_blockalign(s->bs, len); - copy_cb->iov.iov_len =3D len; - qemu_iovec_init_external(©_cb->qiov, ©_cb->iov, 1); + iov =3D (struct iovec) { + .iov_base =3D qemu_blockalign(s->bs, len), + .iov_len =3D len, + }; + qemu_iovec_init_external(&qiov, &iov, 1); + + ret =3D qed_read_backing_file(s, pos, &qiov, &backing_qiov); + + if (backing_qiov) { + qemu_iovec_destroy(backing_qiov); + g_free(backing_qiov); + backing_qiov =3D NULL; + } + + if (ret) { + goto out; + } =20 - ret =3D qed_read_backing_file(s, pos, ©_cb->qiov, - ©_cb->backing_qiov); - qed_copy_from_backing_file_write(copy_cb, ret); + BLKDBG_EVENT(s->bs->file, BLKDBG_COW_WRITE); + ret =3D bdrv_pwritev(s->bs->file, offset, &qiov); + if (ret < 0) { + goto out; + } + ret =3D 0; +out: + qemu_vfree(iov.iov_base); + cb(opaque, ret); } =20 /** --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830741663517.2705893367654; Fri, 26 May 2017 13:32:21 -0700 (PDT) Received: from localhost ([::1]:38322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELuF-00060K-71 for importer@patchew.org; Fri, 26 May 2017 16:32:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELl2-00052w-Df for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELl1-0005Fm-DE for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELky-0005Em-Qs; Fri, 26 May 2017 16:22:45 -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 CA4F53DE3D; Fri, 26 May 2017 20:22:43 +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 1AB161713B; Fri, 26 May 2017 20:22:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA4F53DE3D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CA4F53DE3D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:49 +0200 Message-Id: <1495830130-30611-9-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.29]); Fri, 26 May 2017 20:22: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] [PATCH 08/29] qed: Remove callback from qed_copy_from_backing_file() 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" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed.c | 57 +++++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/block/qed.c b/block/qed.c index 584a5ba..61ef732 100644 --- a/block/qed.c +++ b/block/qed.c @@ -861,13 +861,9 @@ static int qed_read_backing_file(BDRVQEDState *s, uint= 64_t pos, * @pos: Byte position in device * @len: Number of bytes * @offset: Byte offset in image file - * @cb: Completion function - * @opaque: User data for completion function */ -static void qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, - uint64_t len, uint64_t offset, - BlockCompletionFunc *cb, - void *opaque) +static int qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, + uint64_t len, uint64_t offset) { QEMUIOVector qiov; QEMUIOVector *backing_qiov =3D NULL; @@ -876,8 +872,7 @@ static void qed_copy_from_backing_file(BDRVQEDState *s,= uint64_t pos, =20 /* Skip copy entirely if there is no work to do */ if (len =3D=3D 0) { - cb(opaque, 0); - return; + return 0; } =20 iov =3D (struct iovec) { @@ -906,7 +901,7 @@ static void qed_copy_from_backing_file(BDRVQEDState *s,= uint64_t pos, ret =3D 0; out: qemu_vfree(iov.iov_base); - cb(opaque, ret); + return ret; } =20 /** @@ -1133,42 +1128,36 @@ static void qed_aio_write_main(void *opaque, int re= t) } =20 /** - * Populate back untouched region of new data cluster + * Populate untouched regions of new data cluster */ -static void qed_aio_write_postfill(void *opaque, int ret) +static void qed_aio_write_cow(void *opaque, int ret) { QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); - uint64_t start =3D acb->cur_pos + acb->cur_qiov.size; - uint64_t len =3D - qed_start_of_cluster(s, start + s->header.cluster_size - 1) - star= t; - uint64_t offset =3D acb->cur_cluster + - qed_offset_into_cluster(s, acb->cur_pos) + - acb->cur_qiov.size; + uint64_t start, len, offset; + + /* Populate front untouched region of new data cluster */ + start =3D qed_start_of_cluster(s, acb->cur_pos); + len =3D qed_offset_into_cluster(s, acb->cur_pos); =20 + trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster); + ret =3D qed_copy_from_backing_file(s, start, len, acb->cur_cluster); if (ret) { qed_aio_complete(acb, ret); return; } =20 - trace_qed_aio_write_postfill(s, acb, start, len, offset); - qed_copy_from_backing_file(s, start, len, offset, - qed_aio_write_main, acb); -} + /* Populate back untouched region of new data cluster */ + start =3D acb->cur_pos + acb->cur_qiov.size; + len =3D qed_start_of_cluster(s, start + s->header.cluster_size - 1) - = start; + offset =3D acb->cur_cluster + + qed_offset_into_cluster(s, acb->cur_pos) + + acb->cur_qiov.size; =20 -/** - * Populate front untouched region of new data cluster - */ -static void qed_aio_write_prefill(void *opaque, int ret) -{ - QEDAIOCB *acb =3D opaque; - BDRVQEDState *s =3D acb_to_s(acb); - uint64_t start =3D qed_start_of_cluster(s, acb->cur_pos); - uint64_t len =3D qed_offset_into_cluster(s, acb->cur_pos); + trace_qed_aio_write_postfill(s, acb, start, len, offset); + ret =3D qed_copy_from_backing_file(s, start, len, offset); =20 - trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster); - qed_copy_from_backing_file(s, start, len, acb->cur_cluster, - qed_aio_write_postfill, acb); + qed_aio_write_main(acb, ret); } =20 /** @@ -1236,7 +1225,7 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) =20 cb =3D qed_aio_write_zero_cluster; } else { - cb =3D qed_aio_write_prefill; + cb =3D qed_aio_write_cow; acb->cur_cluster =3D qed_alloc_clusters(s, acb->cur_nclusters); } =20 --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830756112418.2322449061321; Fri, 26 May 2017 13:32:36 -0700 (PDT) Received: from localhost ([::1]:38323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELuT-0006Bi-PG for importer@patchew.org; Fri, 26 May 2017 16:32:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELl4-00059r-9J for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELl3-0005GR-Af for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60664) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELl1-0005FR-1d; Fri, 26 May 2017 16:22:47 -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 10A866549; Fri, 26 May 2017 20:22:46 +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 345311713B; Fri, 26 May 2017 20:22:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 10A866549 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 10A866549 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:50 +0200 Message-Id: <1495830130-30611-10-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.39]); Fri, 26 May 2017 20:22: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] [PATCH 09/29] qed: Make qed_write_header() synchronous 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" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed.c | 76 +++++++++++++++++++++++----------------------------------= ---- 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/block/qed.c b/block/qed.c index 61ef732..5548475 100644 --- a/block/qed.c +++ b/block/qed.c @@ -92,41 +92,6 @@ int qed_write_header_sync(BDRVQEDState *s) return 0; } =20 -typedef struct { - GenericCB gencb; - BDRVQEDState *s; - struct iovec iov; - QEMUIOVector qiov; - int nsectors; - uint8_t *buf; -} QEDWriteHeaderCB; - -static void qed_write_header_cb(void *opaque, int ret) -{ - QEDWriteHeaderCB *write_header_cb =3D opaque; - - qemu_vfree(write_header_cb->buf); - gencb_complete(write_header_cb, ret); -} - -static void qed_write_header_read_cb(void *opaque, int ret) -{ - QEDWriteHeaderCB *write_header_cb =3D opaque; - BDRVQEDState *s =3D write_header_cb->s; - - if (ret) { - qed_write_header_cb(write_header_cb, ret); - return; - } - - /* Update header */ - qed_header_cpu_to_le(&s->header, (QEDHeader *)write_header_cb->buf); - - bdrv_aio_writev(s->bs->file, 0, &write_header_cb->qiov, - write_header_cb->nsectors, qed_write_header_cb, - write_header_cb); -} - /** * Update header in-place (does not rewrite backing filename or other stri= ngs) * @@ -144,18 +109,35 @@ static void qed_write_header(BDRVQEDState *s, BlockCo= mpletionFunc cb, =20 int nsectors =3D DIV_ROUND_UP(sizeof(QEDHeader), BDRV_SECTOR_SIZE); size_t len =3D nsectors * BDRV_SECTOR_SIZE; - QEDWriteHeaderCB *write_header_cb =3D gencb_alloc(sizeof(*write_header= _cb), - cb, opaque); - - write_header_cb->s =3D s; - write_header_cb->nsectors =3D nsectors; - write_header_cb->buf =3D qemu_blockalign(s->bs, len); - write_header_cb->iov.iov_base =3D write_header_cb->buf; - write_header_cb->iov.iov_len =3D len; - qemu_iovec_init_external(&write_header_cb->qiov, &write_header_cb->iov= , 1); - - bdrv_aio_readv(s->bs->file, 0, &write_header_cb->qiov, nsectors, - qed_write_header_read_cb, write_header_cb); + uint8_t *buf; + struct iovec iov; + QEMUIOVector qiov; + int ret; + + buf =3D qemu_blockalign(s->bs, len); + iov =3D (struct iovec) { + .iov_base =3D buf, + .iov_len =3D len, + }; + qemu_iovec_init_external(&qiov, &iov, 1); + + ret =3D bdrv_preadv(s->bs->file, 0, &qiov); + if (ret < 0) { + goto out; + } + + /* Update header */ + qed_header_cpu_to_le(&s->header, (QEDHeader *) buf); + + ret =3D bdrv_pwritev(s->bs->file, 0, &qiov); + if (ret < 0) { + goto out; + } + + ret =3D 0; +out: + qemu_vfree(buf); + cb(opaque, ret); } =20 static uint64_t qed_max_image_size(uint32_t cluster_size, uint32_t table_s= ize) --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830317185423.5827472482256; Fri, 26 May 2017 13:25:17 -0700 (PDT) Received: from localhost ([::1]:38281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELnO-0006mI-92 for importer@patchew.org; Fri, 26 May 2017 16:25:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlC-0005FQ-EN for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlB-0005IA-I9 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELl4-0005GV-6O; Fri, 26 May 2017 16:22:50 -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 2DDA23B3C0; Fri, 26 May 2017 20:22:49 +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 6F272176C6; Fri, 26 May 2017 20:22:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2DDA23B3C0 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 2DDA23B3C0 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:51 +0200 Message-Id: <1495830130-30611-11-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:22:49 +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 10/29] qed: Remove callback from qed_write_header() 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" Signed-off-by: Kevin Wolf --- block/qed.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/block/qed.c b/block/qed.c index 5548475..134c98a 100644 --- a/block/qed.c +++ b/block/qed.c @@ -98,8 +98,7 @@ int qed_write_header_sync(BDRVQEDState *s) * This function only updates known header fields in-place and does not af= fect * extra data after the QED header. */ -static void qed_write_header(BDRVQEDState *s, BlockCompletionFunc cb, - void *opaque) +static int qed_write_header(BDRVQEDState *s) { /* We must write full sectors for O_DIRECT but cannot necessarily gene= rate * the data following the header if an unrecognized compat feature is @@ -137,7 +136,7 @@ static void qed_write_header(BDRVQEDState *s, BlockComp= letionFunc cb, ret =3D 0; out: qemu_vfree(buf); - cb(opaque, ret); + return ret; } =20 static uint64_t qed_max_image_size(uint32_t cluster_size, uint32_t table_s= ize) @@ -289,32 +288,23 @@ static void qed_unplug_allocating_write_reqs(BDRVQEDS= tate *s) } } =20 -static void qed_finish_clear_need_check(void *opaque, int ret) -{ - /* Do nothing */ -} - -static void qed_flush_after_clear_need_check(void *opaque, int ret) -{ - BDRVQEDState *s =3D opaque; - - bdrv_aio_flush(s->bs, qed_finish_clear_need_check, s); - - /* No need to wait until flush completes */ - qed_unplug_allocating_write_reqs(s); -} - static void qed_clear_need_check(void *opaque, int ret) { BDRVQEDState *s =3D opaque; =20 if (ret) { - qed_unplug_allocating_write_reqs(s); - return; + goto out; } =20 s->header.features &=3D ~QED_F_NEED_CHECK; - qed_write_header(s, qed_flush_after_clear_need_check, s); + ret =3D qed_write_header(s); + (void) ret; + + ret =3D bdrv_flush(s->bs); + (void) ret; + +out: + qed_unplug_allocating_write_reqs(s); } =20 static void qed_need_check_timer_cb(void *opaque) @@ -1179,6 +1169,7 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) { BDRVQEDState *s =3D acb_to_s(acb); BlockCompletionFunc *cb; + int ret; =20 /* Cancel timer when the first allocating request comes in */ if (QSIMPLEQ_EMPTY(&s->allocating_write_reqs)) { @@ -1213,7 +1204,8 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) =20 if (qed_should_set_need_check(s)) { s->header.features |=3D QED_F_NEED_CHECK; - qed_write_header(s, cb, acb); + ret =3D qed_write_header(s); + cb(acb, ret); } else { cb(acb, 0); } --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831072333878.7368601328606; Fri, 26 May 2017 13:37:52 -0700 (PDT) Received: from localhost ([::1]:38355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELza-0004SN-0Z for importer@patchew.org; Fri, 26 May 2017 16:37:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlC-0005Fb-Jn for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlB-0005I1-HN for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47188) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELl6-0005H0-FF; Fri, 26 May 2017 16:22:52 -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 79A3883F45; Fri, 26 May 2017 20:22:51 +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 871E91713B; Fri, 26 May 2017 20:22:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 79A3883F45 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 79A3883F45 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:52 +0200 Message-Id: <1495830130-30611-12-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.27]); Fri, 26 May 2017 20:22:51 +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 11/29] qed: Make qed_write_table() synchronous 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" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed-table.c | 84 ++++++++++++++++++++-------------------------------= ---- 1 file changed, 30 insertions(+), 54 deletions(-) diff --git a/block/qed-table.c b/block/qed-table.c index ffecbea..0cc93a7 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -52,46 +52,6 @@ out: return ret; } =20 -typedef struct { - GenericCB gencb; - BDRVQEDState *s; - QEDTable *orig_table; - QEDTable *table; - bool flush; /* flush after write? */ - - struct iovec iov; - QEMUIOVector qiov; -} QEDWriteTableCB; - -static void qed_write_table_cb(void *opaque, int ret) -{ - QEDWriteTableCB *write_table_cb =3D opaque; - BDRVQEDState *s =3D write_table_cb->s; - - trace_qed_write_table_cb(s, - write_table_cb->orig_table, - write_table_cb->flush, - ret); - - if (ret) { - goto out; - } - - if (write_table_cb->flush) { - /* We still need to flush first */ - write_table_cb->flush =3D false; - qed_acquire(s); - bdrv_aio_flush(write_table_cb->s->bs, qed_write_table_cb, - write_table_cb); - qed_release(s); - return; - } - -out: - qemu_vfree(write_table_cb->table); - gencb_complete(&write_table_cb->gencb, ret); -} - /** * Write out an updated part or all of a table * @@ -108,10 +68,13 @@ static void qed_write_table(BDRVQEDState *s, uint64_t = offset, QEDTable *table, unsigned int index, unsigned int n, bool flush, BlockCompletionFunc *cb, void *opaque) { - QEDWriteTableCB *write_table_cb; unsigned int sector_mask =3D BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1; unsigned int start, end, i; + QEDTable *new_table; + struct iovec iov; + QEMUIOVector qiov; size_t len_bytes; + int ret; =20 trace_qed_write_table(s, offset, table, index, n); =20 @@ -121,28 +84,41 @@ static void qed_write_table(BDRVQEDState *s, uint64_t = offset, QEDTable *table, =20 len_bytes =3D (end - start) * sizeof(uint64_t); =20 - write_table_cb =3D gencb_alloc(sizeof(*write_table_cb), cb, opaque); - write_table_cb->s =3D s; - write_table_cb->orig_table =3D table; - write_table_cb->flush =3D flush; - write_table_cb->table =3D qemu_blockalign(s->bs, len_bytes); - write_table_cb->iov.iov_base =3D write_table_cb->table->offsets; - write_table_cb->iov.iov_len =3D len_bytes; - qemu_iovec_init_external(&write_table_cb->qiov, &write_table_cb->iov, = 1); + new_table =3D qemu_blockalign(s->bs, len_bytes); + iov =3D (struct iovec) { + .iov_base =3D new_table->offsets, + .iov_len =3D len_bytes, + }; + qemu_iovec_init_external(&qiov, &iov, 1); =20 /* Byteswap table */ for (i =3D start; i < end; i++) { uint64_t le_offset =3D cpu_to_le64(table->offsets[i]); - write_table_cb->table->offsets[i - start] =3D le_offset; + new_table->offsets[i - start] =3D le_offset; } =20 /* Adjust for offset into table */ offset +=3D start * sizeof(uint64_t); =20 - bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE, - &write_table_cb->qiov, - write_table_cb->qiov.size / BDRV_SECTOR_SIZE, - qed_write_table_cb, write_table_cb); + ret =3D bdrv_pwritev(s->bs->file, offset, &qiov); + trace_qed_write_table_cb(s, table, flush, ret); + if (ret < 0) { + goto out; + } + + if (flush) { + qed_acquire(s); + ret =3D bdrv_flush(s->bs); + qed_release(s); + if (ret < 0) { + goto out; + } + } + + ret =3D 0; +out: + qemu_vfree(new_table); + cb(opaque, ret); } =20 /** --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830922327456.01175549507866; Fri, 26 May 2017 13:35:22 -0700 (PDT) Received: from localhost ([::1]:38336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELx8-0001cD-LV for importer@patchew.org; Fri, 26 May 2017 16:35:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlC-0005FJ-B7 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlB-0005I3-Hg for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50744) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELl8-0005HR-No; Fri, 26 May 2017 16:22:54 -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 B4F67C04BD38; Fri, 26 May 2017 20:22:53 +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 D8D1F1713B; Fri, 26 May 2017 20:22:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B4F67C04BD38 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B4F67C04BD38 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:53 +0200 Message-Id: <1495830130-30611-13-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.31]); Fri, 26 May 2017 20:22:53 +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 12/29] qed: Remove GenericCB 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" The GenericCB infrastructure isn't used any more. Remove it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/Makefile.objs | 2 +- block/qed-gencb.c | 33 --------------------------------- block/qed.h | 11 ----------- 3 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 block/qed-gencb.c diff --git a/block/Makefile.objs b/block/Makefile.objs index ea95530..f9368b5 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -1,6 +1,6 @@ block-obj-y +=3D raw-format.o qcow.o vdi.o vmdk.o cloop.o bochs.o vpc.o vv= fat.o dmg.o block-obj-y +=3D qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o= qcow2-cache.o -block-obj-y +=3D qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o +block-obj-y +=3D qed.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y +=3D qed-check.o block-obj-y +=3D vhdx.o vhdx-endian.o vhdx-log.o block-obj-y +=3D quorum.o diff --git a/block/qed-gencb.c b/block/qed-gencb.c deleted file mode 100644 index faf8ecc..0000000 --- a/block/qed-gencb.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * QEMU Enhanced Disk Format - * - * Copyright IBM, Corp. 2010 - * - * Authors: - * Stefan Hajnoczi - * - * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. - * See the COPYING.LIB file in the top-level directory. - * - */ - -#include "qemu/osdep.h" -#include "qed.h" - -void *gencb_alloc(size_t len, BlockCompletionFunc *cb, void *opaque) -{ - GenericCB *gencb =3D g_malloc(len); - gencb->cb =3D cb; - gencb->opaque =3D opaque; - return gencb; -} - -void gencb_complete(void *opaque, int ret) -{ - GenericCB *gencb =3D opaque; - BlockCompletionFunc *cb =3D gencb->cb; - void *user_opaque =3D gencb->opaque; - - g_free(gencb); - cb(user_opaque, ret); -} diff --git a/block/qed.h b/block/qed.h index 6ab5702..46843c4 100644 --- a/block/qed.h +++ b/block/qed.h @@ -202,17 +202,6 @@ void qed_acquire(BDRVQEDState *s); void qed_release(BDRVQEDState *s); =20 /** - * Generic callback for chaining async callbacks - */ -typedef struct { - BlockCompletionFunc *cb; - void *opaque; -} GenericCB; - -void *gencb_alloc(size_t len, BlockCompletionFunc *cb, void *opaque); -void gencb_complete(void *opaque, int ret); - -/** * Header functions */ int qed_write_header_sync(BDRVQEDState *s); --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830472190104.90248467593312; Fri, 26 May 2017 13:27:52 -0700 (PDT) Received: from localhost ([::1]:38296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELpu-0001Cb-PL for importer@patchew.org; Fri, 26 May 2017 16:27:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlN-0005Np-3C for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlL-0005L7-S1 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60930) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlF-0005K6-Sm; Fri, 26 May 2017 16:23:02 -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 C445F17AC5A; Fri, 26 May 2017 20:23:00 +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 1F87A1713B; Fri, 26 May 2017 20:22:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C445F17AC5A Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C445F17AC5A From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:54 +0200 Message-Id: <1495830130-30611-14-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.39]); Fri, 26 May 2017 20:23:00 +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 13/29] qed: Remove callback from qed_write_table() 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" Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed-table.c | 47 ++++++++++++----------------------------------- block/qed.c | 12 +++++++----- block/qed.h | 8 +++----- 3 files changed, 22 insertions(+), 45 deletions(-) diff --git a/block/qed-table.c b/block/qed-table.c index 0cc93a7..ebee2c5 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -61,12 +61,9 @@ out: * @index: Index of first element * @n: Number of elements * @flush: Whether or not to sync to disk - * @cb: Completion function - * @opaque: Argument for completion function */ -static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *ta= ble, - unsigned int index, unsigned int n, bool flush, - BlockCompletionFunc *cb, void *opaque) +static int qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *tab= le, + unsigned int index, unsigned int n, bool flush) { unsigned int sector_mask =3D BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1; unsigned int start, end, i; @@ -118,15 +115,7 @@ static void qed_write_table(BDRVQEDState *s, uint64_t = offset, QEDTable *table, ret =3D 0; out: qemu_vfree(new_table); - cb(opaque, ret); -} - -/** - * Propagate return value from async callback - */ -static void qed_sync_cb(void *opaque, int ret) -{ - *(int *)opaque =3D ret; + return ret; } =20 int qed_read_l1_table_sync(BDRVQEDState *s) @@ -134,23 +123,17 @@ int qed_read_l1_table_sync(BDRVQEDState *s) return qed_read_table(s, s->header.l1_table_offset, s->l1_table); } =20 -void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int = n, - BlockCompletionFunc *cb, void *opaque) +int qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n) { BLKDBG_EVENT(s->bs->file, BLKDBG_L1_UPDATE); - qed_write_table(s, s->header.l1_table_offset, - s->l1_table, index, n, false, cb, opaque); + return qed_write_table(s, s->header.l1_table_offset, + s->l1_table, index, n, false); } =20 int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int n) { - int ret =3D -EINPROGRESS; - - qed_write_l1_table(s, index, n, qed_sync_cb, &ret); - BDRV_POLL_WHILE(s->bs, ret =3D=3D -EINPROGRESS); - - return ret; + return qed_write_l1_table(s, index, n); } =20 int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offse= t) @@ -197,22 +180,16 @@ int qed_read_l2_table_sync(BDRVQEDState *s, QEDReques= t *request, uint64_t offset return qed_read_l2_table(s, request, offset); } =20 -void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, - unsigned int index, unsigned int n, bool flush, - BlockCompletionFunc *cb, void *opaque) +int qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, + unsigned int index, unsigned int n, bool flush) { BLKDBG_EVENT(s->bs->file, BLKDBG_L2_UPDATE); - qed_write_table(s, request->l2_table->offset, - request->l2_table->table, index, n, flush, cb, opaque); + return qed_write_table(s, request->l2_table->offset, + request->l2_table->table, index, n, flush); } =20 int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, unsigned int index, unsigned int n, bool flush) { - int ret =3D -EINPROGRESS; - - qed_write_l2_table(s, request, index, n, flush, qed_sync_cb, &ret); - BDRV_POLL_WHILE(s->bs, ret =3D=3D -EINPROGRESS); - - return ret; + return qed_write_l2_table(s, request, index, n, flush); } diff --git a/block/qed.c b/block/qed.c index 134c98a..e9417d0 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1000,7 +1000,8 @@ static void qed_aio_write_l1_update(void *opaque, int= ret) index =3D qed_l1_index(s, acb->cur_pos); s->l1_table->offsets[index] =3D acb->request.l2_table->offset; =20 - qed_write_l1_table(s, index, 1, qed_commit_l2_update, acb); + ret =3D qed_write_l1_table(s, index, 1); + qed_commit_l2_update(acb, ret); } =20 /** @@ -1027,12 +1028,13 @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, = int ret, uint64_t offset) =20 if (need_alloc) { /* Write out the whole new L2 table */ - qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true, - qed_aio_write_l1_update, acb); + ret =3D qed_write_l2_table(s, &acb->request, 0, s->table_nelems, t= rue); + qed_aio_write_l1_update(acb, ret); } else { /* Write out only the updated part of the L2 table */ - qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters, fa= lse, - qed_aio_next_io_cb, acb); + ret =3D qed_write_l2_table(s, &acb->request, index, acb->cur_nclus= ters, + false); + qed_aio_next_io(acb, ret); } return; =20 diff --git a/block/qed.h b/block/qed.h index 46843c4..51443fa 100644 --- a/block/qed.h +++ b/block/qed.h @@ -220,16 +220,14 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache= , CachedL2Table *l2_table); * Table I/O functions */ int qed_read_l1_table_sync(BDRVQEDState *s); -void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int = n, - BlockCompletionFunc *cb, void *opaque); +int qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n= ); int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int n); int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset); int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offse= t); -void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, - unsigned int index, unsigned int n, bool flush, - BlockCompletionFunc *cb, void *opaque); +int qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, + unsigned int index, unsigned int n, bool flush); int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, unsigned int index, unsigned int n, bool flush= ); =20 --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830917119705.5306326121932; Fri, 26 May 2017 13:35:17 -0700 (PDT) Received: from localhost ([::1]:38335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELx5-0001Zg-LY for importer@patchew.org; Fri, 26 May 2017 16:35:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlM-0005NR-Mn for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlL-0005L2-Qz for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39074) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlI-0005KP-6r; Fri, 26 May 2017 16:23:04 -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 2C5CC80B56; Fri, 26 May 2017 20:23:03 +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 3536C173A7; Fri, 26 May 2017 20:23:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2C5CC80B56 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2C5CC80B56 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:55 +0200 Message-Id: <1495830130-30611-15-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.28]); Fri, 26 May 2017 20:23:03 +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 14/29] qed: Make qed_aio_read_data() synchronous 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" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/qed.c b/block/qed.c index e9417d0..0972936 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1325,9 +1325,11 @@ static void qed_aio_read_data(void *opaque, int ret, } =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - bdrv_aio_readv(bs->file, offset / BDRV_SECTOR_SIZE, - &acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE, - qed_aio_next_io_cb, acb); + ret =3D bdrv_preadv(bs->file, offset, &acb->cur_qiov); + if (ret < 0) { + goto err; + } + qed_aio_next_io(acb, 0); return; =20 err: --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 14958312092301.0825597897568286; Fri, 26 May 2017 13:40:09 -0700 (PDT) Received: from localhost ([::1]:38368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM1n-0007Hv-Vn for importer@patchew.org; Fri, 26 May 2017 16:40:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlP-0005Qn-Mm for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlO-0005M2-OF for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50062) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlM-0005Kx-1o; Fri, 26 May 2017 16:23:08 -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 08CDB80C10; Fri, 26 May 2017 20:23:07 +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 9092A17B63; Fri, 26 May 2017 20:23:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 08CDB80C10 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 08CDB80C10 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:56 +0200 Message-Id: <1495830130-30611-16-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.26]); Fri, 26 May 2017 20:23:07 +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 15/29] qed: Make qed_aio_write_main() synchronous 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" Note that this code is generally not running in coroutine context, so this is an actual blocking synchronous operation. We'll fix this in a moment. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 61 +++++++++++++++++++--------------------------------------= ---- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/block/qed.c b/block/qed.c index 0972936..a596c4d 100644 --- a/block/qed.c +++ b/block/qed.c @@ -260,13 +260,6 @@ static void qed_aio_start_io(QEDAIOCB *acb) qed_aio_next_io(acb, 0); } =20 -static void qed_aio_next_io_cb(void *opaque, int ret) -{ - QEDAIOCB *acb =3D opaque; - - qed_aio_next_io(acb, ret); -} - static void qed_plug_allocating_write_reqs(BDRVQEDState *s) { assert(!s->allocating_write_reqs_plugged); @@ -1042,31 +1035,6 @@ err: qed_aio_complete(acb, ret); } =20 -static void qed_aio_write_l2_update_cb(void *opaque, int ret) -{ - QEDAIOCB *acb =3D opaque; - qed_aio_write_l2_update(acb, ret, acb->cur_cluster); -} - -/** - * Flush new data clusters before updating the L2 table - * - * This flush is necessary when a backing file is in use. A crash during = an - * allocating write could result in empty clusters in the image. If the w= rite - * only touched a subregion of the cluster, then backing image sectors have - * been lost in the untouched region. The solution is to flush after writ= ing a - * new data cluster and before updating the L2 table. - */ -static void qed_aio_write_flush_before_l2_update(void *opaque, int ret) -{ - QEDAIOCB *acb =3D opaque; - BDRVQEDState *s =3D acb_to_s(acb); - - if (!bdrv_aio_flush(s->bs->file->bs, qed_aio_write_l2_update_cb, opaqu= e)) { - qed_aio_complete(acb, -EIO); - } -} - /** * Write data to the image file */ @@ -1076,7 +1044,6 @@ static void qed_aio_write_main(void *opaque, int ret) BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset =3D acb->cur_cluster + qed_offset_into_cluster(s, acb->cur_pos); - BlockCompletionFunc *next_fn; =20 trace_qed_aio_write_main(s, acb, ret, offset, acb->cur_qiov.size); =20 @@ -1085,20 +1052,30 @@ static void qed_aio_write_main(void *opaque, int re= t) return; } =20 + BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO); + ret =3D bdrv_pwritev(s->bs->file, offset, &acb->cur_qiov); + if (ret >=3D 0) { + ret =3D 0; + } + if (acb->find_cluster_ret =3D=3D QED_CLUSTER_FOUND) { - next_fn =3D qed_aio_next_io_cb; + qed_aio_next_io(acb, ret); } else { if (s->bs->backing) { - next_fn =3D qed_aio_write_flush_before_l2_update; - } else { - next_fn =3D qed_aio_write_l2_update_cb; + /* + * Flush new data clusters before updating the L2 table + * + * This flush is necessary when a backing file is in use. A c= rash + * during an allocating write could result in empty clusters i= n the + * image. If the write only touched a subregion of the cluste= r, + * then backing image sectors have been lost in the untouched + * region. The solution is to flush after writing a new data + * cluster and before updating the L2 table. + */ + ret =3D bdrv_flush(s->bs->file->bs); } + qed_aio_write_l2_update(acb, ret, acb->cur_cluster); } - - BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO); - bdrv_aio_writev(s->bs->file, offset / BDRV_SECTOR_SIZE, - &acb->cur_qiov, acb->cur_qiov.size / BDRV_SECTOR_SIZE, - next_fn, acb); } =20 /** --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831089609843.5327931569739; Fri, 26 May 2017 13:38:09 -0700 (PDT) Received: from localhost ([::1]:38356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELzs-0005NS-7A for importer@patchew.org; Fri, 26 May 2017 16:38:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlV-0005Ui-P5 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlU-0005NQ-U3 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlO-0005Ll-5e; Fri, 26 May 2017 16:23:10 -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 34DD8369CB; Fri, 26 May 2017 20:23:09 +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 6B1371713B; Fri, 26 May 2017 20:23:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 34DD8369CB 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 34DD8369CB From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:57 +0200 Message-Id: <1495830130-30611-17-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:09 +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 16/29] qed: Inline qed_commit_l2_update() 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" qed_commit_l2_update() is unconditionally called at the end of qed_aio_write_l1_update(). Inline it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/block/qed.c b/block/qed.c index a596c4d..3b1cce4 100644 --- a/block/qed.c +++ b/block/qed.c @@ -956,15 +956,27 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret) } =20 /** - * Commit the current L2 table to the cache + * Update L1 table with new L2 table offset and write it out */ -static void qed_commit_l2_update(void *opaque, int ret) +static void qed_aio_write_l1_update(void *opaque, int ret) { QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); CachedL2Table *l2_table =3D acb->request.l2_table; uint64_t l2_offset =3D l2_table->offset; + int index; + + if (ret) { + qed_aio_complete(acb, ret); + return; + } =20 + index =3D qed_l1_index(s, acb->cur_pos); + s->l1_table->offsets[index] =3D l2_table->offset; + + ret =3D qed_write_l1_table(s, index, 1); + + /* Commit the current L2 table to the cache */ qed_commit_l2_cache_entry(&s->l2_cache, l2_table); =20 /* This is guaranteed to succeed because we just committed the entry t= o the @@ -976,26 +988,6 @@ static void qed_commit_l2_update(void *opaque, int ret) qed_aio_next_io(acb, ret); } =20 -/** - * Update L1 table with new L2 table offset and write it out - */ -static void qed_aio_write_l1_update(void *opaque, int ret) -{ - QEDAIOCB *acb =3D opaque; - BDRVQEDState *s =3D acb_to_s(acb); - int index; - - if (ret) { - qed_aio_complete(acb, ret); - return; - } - - index =3D qed_l1_index(s, acb->cur_pos); - s->l1_table->offsets[index] =3D acb->request.l2_table->offset; - - ret =3D qed_write_l1_table(s, index, 1); - qed_commit_l2_update(acb, ret); -} =20 /** * Update L2 table with new cluster offsets and write them out --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830601855250.45412613097653; Fri, 26 May 2017 13:30:01 -0700 (PDT) Received: from localhost ([::1]:38310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELs0-00043v-A4 for importer@patchew.org; Fri, 26 May 2017 16:30:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlV-0005Up-UR for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlV-0005NX-20 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39252) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlQ-0005MI-Cm; Fri, 26 May 2017 16:23:12 -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 6322A8048D; Fri, 26 May 2017 20:23:11 +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 957D71713B; Fri, 26 May 2017 20:23:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6322A8048D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6322A8048D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:58 +0200 Message-Id: <1495830130-30611-18-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.28]); Fri, 26 May 2017 20:23:11 +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 17/29] qed: Add return value to qed_aio_write_l1_update() 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" Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but just return an error code and let the caller handle it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/block/qed.c b/block/qed.c index 3b1cce4..2034b58 100644 --- a/block/qed.c +++ b/block/qed.c @@ -958,18 +958,12 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret) /** * Update L1 table with new L2 table offset and write it out */ -static void qed_aio_write_l1_update(void *opaque, int ret) +static int qed_aio_write_l1_update(QEDAIOCB *acb) { - QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); CachedL2Table *l2_table =3D acb->request.l2_table; uint64_t l2_offset =3D l2_table->offset; - int index; - - if (ret) { - qed_aio_complete(acb, ret); - return; - } + int index, ret; =20 index =3D qed_l1_index(s, acb->cur_pos); s->l1_table->offsets[index] =3D l2_table->offset; @@ -985,7 +979,7 @@ static void qed_aio_write_l1_update(void *opaque, int r= et) acb->request.l2_table =3D qed_find_l2_cache_entry(&s->l2_cache, l2_off= set); assert(acb->request.l2_table !=3D NULL); =20 - qed_aio_next_io(acb, ret); + return ret; } =20 =20 @@ -1014,7 +1008,12 @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, i= nt ret, uint64_t offset) if (need_alloc) { /* Write out the whole new L2 table */ ret =3D qed_write_l2_table(s, &acb->request, 0, s->table_nelems, t= rue); - qed_aio_write_l1_update(acb, ret); + if (ret) { + goto err; + } + ret =3D qed_aio_write_l1_update(acb); + qed_aio_next_io(acb, ret); + } else { /* Write out only the updated part of the L2 table */ ret =3D qed_write_l2_table(s, &acb->request, index, acb->cur_nclus= ters, --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831218690737.6120375681668; Fri, 26 May 2017 13:40:18 -0700 (PDT) Received: from localhost ([::1]:38369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM1v-0007OT-Nf for importer@patchew.org; Fri, 26 May 2017 16:40:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlX-0005Wm-BO for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlW-0005OH-Ef for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59792) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlT-0005Mz-Qq; Fri, 26 May 2017 16:23:16 -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 CFBBE3D943; Fri, 26 May 2017 20:23:14 +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 C14AA1713B; Fri, 26 May 2017 20:23:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CFBBE3D943 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 CFBBE3D943 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:59 +0200 Message-Id: <1495830130-30611-19-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:15 +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 18/29] qed: Add return value to qed_aio_write_l2_update() 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" Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but just return an error code and let the caller handle it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/block/qed.c b/block/qed.c index 2034b58..259abb2 100644 --- a/block/qed.c +++ b/block/qed.c @@ -986,15 +986,11 @@ static int qed_aio_write_l1_update(QEDAIOCB *acb) /** * Update L2 table with new cluster offsets and write them out */ -static void qed_aio_write_l2_update(QEDAIOCB *acb, int ret, uint64_t offse= t) +static int qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset) { BDRVQEDState *s =3D acb_to_s(acb); bool need_alloc =3D acb->find_cluster_ret =3D=3D QED_CLUSTER_L1; - int index; - - if (ret) { - goto err; - } + int index, ret; =20 if (need_alloc) { qed_unref_l2_cache_entry(acb->request.l2_table); @@ -1009,21 +1005,18 @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, = int ret, uint64_t offset) /* Write out the whole new L2 table */ ret =3D qed_write_l2_table(s, &acb->request, 0, s->table_nelems, t= rue); if (ret) { - goto err; + return ret; } - ret =3D qed_aio_write_l1_update(acb); - qed_aio_next_io(acb, ret); - + return qed_aio_write_l1_update(acb); } else { /* Write out only the updated part of the L2 table */ ret =3D qed_write_l2_table(s, &acb->request, index, acb->cur_nclus= ters, false); - qed_aio_next_io(acb, ret); + if (ret) { + return ret; + } } - return; - -err: - qed_aio_complete(acb, ret); + return 0; } =20 /** @@ -1065,8 +1058,19 @@ static void qed_aio_write_main(void *opaque, int ret) */ ret =3D bdrv_flush(s->bs->file->bs); } - qed_aio_write_l2_update(acb, ret, acb->cur_cluster); + if (ret) { + goto err; + } + ret =3D qed_aio_write_l2_update(acb, acb->cur_cluster); + if (ret) { + goto err; + } + qed_aio_next_io(acb, 0); } + return; + +err: + qed_aio_complete(acb, ret); } =20 /** @@ -1124,7 +1128,12 @@ static void qed_aio_write_zero_cluster(void *opaque,= int ret) return; } =20 - qed_aio_write_l2_update(acb, 0, 1); + ret =3D qed_aio_write_l2_update(acb, 1); + if (ret < 0) { + qed_aio_complete(acb, ret); + return; + } + qed_aio_next_io(acb, 0); } =20 /** --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831459989414.94559898804073; Fri, 26 May 2017 13:44:19 -0700 (PDT) Received: from localhost ([::1]:38392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM5o-0003wK-Dw for importer@patchew.org; Fri, 26 May 2017 16:44:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58856) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELld-0005e8-Kd for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlc-0005Qf-Ks for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlX-0005Oa-VR; Fri, 26 May 2017 16:23:20 -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 ED2E397831; Fri, 26 May 2017 20:23:18 +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 4004D1713B; Fri, 26 May 2017 20:23:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ED2E397831 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ED2E397831 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:00 +0200 Message-Id: <1495830130-30611-20-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.39]); Fri, 26 May 2017 20:23:19 +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 19/29] qed: Add return value to qed_aio_write_main() 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" Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but just return an error code and let the caller handle it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/block/qed.c b/block/qed.c index 259abb2..e6d1b0d 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1022,29 +1022,22 @@ static int qed_aio_write_l2_update(QEDAIOCB *acb, u= int64_t offset) /** * Write data to the image file */ -static void qed_aio_write_main(void *opaque, int ret) +static int qed_aio_write_main(QEDAIOCB *acb) { - QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset =3D acb->cur_cluster + qed_offset_into_cluster(s, acb->cur_pos); + int ret; =20 - trace_qed_aio_write_main(s, acb, ret, offset, acb->cur_qiov.size); - - if (ret) { - qed_aio_complete(acb, ret); - return; - } + trace_qed_aio_write_main(s, acb, 0, offset, acb->cur_qiov.size); =20 BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO); ret =3D bdrv_pwritev(s->bs->file, offset, &acb->cur_qiov); - if (ret >=3D 0) { - ret =3D 0; + if (ret < 0) { + return ret; } =20 - if (acb->find_cluster_ret =3D=3D QED_CLUSTER_FOUND) { - qed_aio_next_io(acb, ret); - } else { + if (acb->find_cluster_ret !=3D QED_CLUSTER_FOUND) { if (s->bs->backing) { /* * Flush new data clusters before updating the L2 table @@ -1057,20 +1050,16 @@ static void qed_aio_write_main(void *opaque, int re= t) * cluster and before updating the L2 table. */ ret =3D bdrv_flush(s->bs->file->bs); - } - if (ret) { - goto err; + if (ret < 0) { + return ret; + } } ret =3D qed_aio_write_l2_update(acb, acb->cur_cluster); - if (ret) { - goto err; + if (ret < 0) { + return ret; } - qed_aio_next_io(acb, 0); } - return; - -err: - qed_aio_complete(acb, ret); + return 0; } =20 /** @@ -1102,8 +1091,17 @@ static void qed_aio_write_cow(void *opaque, int ret) =20 trace_qed_aio_write_postfill(s, acb, start, len, offset); ret =3D qed_copy_from_backing_file(s, start, len, offset); + if (ret) { + qed_aio_complete(acb, ret); + return; + } =20 - qed_aio_write_main(acb, ret); + ret =3D qed_aio_write_main(acb); + if (ret < 0) { + qed_aio_complete(acb, ret); + return; + } + qed_aio_next_io(acb, 0); } =20 /** @@ -1201,6 +1199,8 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) */ static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t l= en) { + int ret; + /* Allocate buffer for zero writes */ if (acb->flags & QED_AIOCB_ZERO) { struct iovec *iov =3D acb->qiov->iov; @@ -1220,7 +1220,12 @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uin= t64_t offset, size_t len) qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len); =20 /* Do the actual write */ - qed_aio_write_main(acb, 0); + ret =3D qed_aio_write_main(acb); + if (ret < 0) { + qed_aio_complete(acb, ret); + return; + } + qed_aio_next_io(acb, 0); } =20 /** --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831561543757.3134935689467; Fri, 26 May 2017 13:46:01 -0700 (PDT) Received: from localhost ([::1]:38412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM7U-0005HX-5I for importer@patchew.org; Fri, 26 May 2017 16:46:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELld-0005eX-TR for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlc-0005Qw-VI for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50316) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELla-0005PL-7f; Fri, 26 May 2017 16:23:22 -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 42D2B8A003; Fri, 26 May 2017 20:23:21 +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 5EB731713B; Fri, 26 May 2017 20:23:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 42D2B8A003 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 42D2B8A003 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:01 +0200 Message-Id: <1495830130-30611-21-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.26]); Fri, 26 May 2017 20:23:21 +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 20/29] qed: Add return value to qed_aio_write_cow() 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" Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but just return an error code and let the caller handle it. While refactoring qed_aio_write_alloc() to accomodate the change, qed_aio_write_zero_cluster() ended up with a single line, so I chose to inline that line and remove the function completely. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 58 +++++++++++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/block/qed.c b/block/qed.c index e6d1b0d..66332f0 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1065,11 +1065,11 @@ static int qed_aio_write_main(QEDAIOCB *acb) /** * Populate untouched regions of new data cluster */ -static void qed_aio_write_cow(void *opaque, int ret) +static int qed_aio_write_cow(QEDAIOCB *acb) { - QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); uint64_t start, len, offset; + int ret; =20 /* Populate front untouched region of new data cluster */ start =3D qed_start_of_cluster(s, acb->cur_pos); @@ -1077,9 +1077,8 @@ static void qed_aio_write_cow(void *opaque, int ret) =20 trace_qed_aio_write_prefill(s, acb, start, len, acb->cur_cluster); ret =3D qed_copy_from_backing_file(s, start, len, acb->cur_cluster); - if (ret) { - qed_aio_complete(acb, ret); - return; + if (ret < 0) { + return ret; } =20 /* Populate back untouched region of new data cluster */ @@ -1091,17 +1090,11 @@ static void qed_aio_write_cow(void *opaque, int ret) =20 trace_qed_aio_write_postfill(s, acb, start, len, offset); ret =3D qed_copy_from_backing_file(s, start, len, offset); - if (ret) { - qed_aio_complete(acb, ret); - return; - } - - ret =3D qed_aio_write_main(acb); if (ret < 0) { - qed_aio_complete(acb, ret); - return; + return ret; } - qed_aio_next_io(acb, 0); + + return qed_aio_write_main(acb); } =20 /** @@ -1117,23 +1110,6 @@ static bool qed_should_set_need_check(BDRVQEDState *= s) return !(s->header.features & QED_F_NEED_CHECK); } =20 -static void qed_aio_write_zero_cluster(void *opaque, int ret) -{ - QEDAIOCB *acb =3D opaque; - - if (ret) { - qed_aio_complete(acb, ret); - return; - } - - ret =3D qed_aio_write_l2_update(acb, 1); - if (ret < 0) { - qed_aio_complete(acb, ret); - return; - } - qed_aio_next_io(acb, 0); -} - /** * Write new data cluster * @@ -1145,7 +1121,6 @@ static void qed_aio_write_zero_cluster(void *opaque, = int ret) static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len) { BDRVQEDState *s =3D acb_to_s(acb); - BlockCompletionFunc *cb; int ret; =20 /* Cancel timer when the first allocating request comes in */ @@ -1172,20 +1147,29 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size= _t len) qed_aio_start_io(acb); return; } - - cb =3D qed_aio_write_zero_cluster; } else { - cb =3D qed_aio_write_cow; acb->cur_cluster =3D qed_alloc_clusters(s, acb->cur_nclusters); } =20 if (qed_should_set_need_check(s)) { s->header.features |=3D QED_F_NEED_CHECK; ret =3D qed_write_header(s); - cb(acb, ret); + if (ret < 0) { + qed_aio_complete(acb, ret); + return; + } + } + + if (acb->flags & QED_AIOCB_ZERO) { + ret =3D qed_aio_write_l2_update(acb, 1); } else { - cb(acb, 0); + ret =3D qed_aio_write_cow(acb); } + if (ret < 0) { + qed_aio_complete(acb, ret); + return; + } + qed_aio_next_io(acb, 0); } =20 /** --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831330830333.8231827637695; Fri, 26 May 2017 13:42:10 -0700 (PDT) Received: from localhost ([::1]:38380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM3l-0000Wg-DC for importer@patchew.org; Fri, 26 May 2017 16:42:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlf-0005gm-Pw for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELle-0005S8-VJ for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlc-0005QC-GE; Fri, 26 May 2017 16:23:24 -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 7BF9C19CBD1; Fri, 26 May 2017 20:23:23 +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 A6E3C176C7; Fri, 26 May 2017 20:23:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7BF9C19CBD1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7BF9C19CBD1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:02 +0200 Message-Id: <1495830130-30611-22-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.29]); Fri, 26 May 2017 20:23:23 +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 21/29] qed: Add return value to qed_aio_write_inplace/alloc() 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" Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but just return an error code and let the caller handle it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/block/qed.c b/block/qed.c index 66332f0..7880df8 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1118,7 +1118,7 @@ static bool qed_should_set_need_check(BDRVQEDState *s) * * This path is taken when writing to previously unallocated clusters. */ -static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len) +static int qed_aio_write_alloc(QEDAIOCB *acb, size_t len) { BDRVQEDState *s =3D acb_to_s(acb); int ret; @@ -1134,7 +1134,7 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) } if (acb !=3D QSIMPLEQ_FIRST(&s->allocating_write_reqs) || s->allocating_write_reqs_plugged) { - return; /* wait for existing request to finish */ + return -EINPROGRESS; /* wait for existing request to finish */ } =20 acb->cur_nclusters =3D qed_bytes_to_clusters(s, @@ -1144,8 +1144,7 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) if (acb->flags & QED_AIOCB_ZERO) { /* Skip ahead if the clusters are already zero */ if (acb->find_cluster_ret =3D=3D QED_CLUSTER_ZERO) { - qed_aio_start_io(acb); - return; + return 0; } } else { acb->cur_cluster =3D qed_alloc_clusters(s, acb->cur_nclusters); @@ -1155,8 +1154,7 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t= len) s->header.features |=3D QED_F_NEED_CHECK; ret =3D qed_write_header(s); if (ret < 0) { - qed_aio_complete(acb, ret); - return; + return ret; } } =20 @@ -1166,10 +1164,9 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_= t len) ret =3D qed_aio_write_cow(acb); } if (ret < 0) { - qed_aio_complete(acb, ret); - return; + return ret; } - qed_aio_next_io(acb, 0); + return 0; } =20 /** @@ -1181,10 +1178,8 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_= t len) * * This path is taken when writing to already allocated clusters. */ -static void qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t l= en) +static int qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t le= n) { - int ret; - /* Allocate buffer for zero writes */ if (acb->flags & QED_AIOCB_ZERO) { struct iovec *iov =3D acb->qiov->iov; @@ -1192,8 +1187,7 @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uint= 64_t offset, size_t len) if (!iov->iov_base) { iov->iov_base =3D qemu_try_blockalign(acb->common.bs, iov->iov= _len); if (iov->iov_base =3D=3D NULL) { - qed_aio_complete(acb, -ENOMEM); - return; + return -ENOMEM; } memset(iov->iov_base, 0, iov->iov_len); } @@ -1204,12 +1198,7 @@ static void qed_aio_write_inplace(QEDAIOCB *acb, uin= t64_t offset, size_t len) qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len); =20 /* Do the actual write */ - ret =3D qed_aio_write_main(acb); - if (ret < 0) { - qed_aio_complete(acb, ret); - return; - } - qed_aio_next_io(acb, 0); + return qed_aio_write_main(acb); } =20 /** @@ -1234,19 +1223,27 @@ static void qed_aio_write_data(void *opaque, int re= t, =20 switch (ret) { case QED_CLUSTER_FOUND: - qed_aio_write_inplace(acb, offset, len); + ret =3D qed_aio_write_inplace(acb, offset, len); break; =20 case QED_CLUSTER_L2: case QED_CLUSTER_L1: case QED_CLUSTER_ZERO: - qed_aio_write_alloc(acb, len); + ret =3D qed_aio_write_alloc(acb, len); break; =20 default: - qed_aio_complete(acb, ret); + assert(ret < 0); break; } + + if (ret < 0) { + if (ret !=3D -EINPROGRESS) { + qed_aio_complete(acb, ret); + } + return; + } + qed_aio_next_io(acb, 0); } =20 /** --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831663882839.5659240954561; Fri, 26 May 2017 13:47:43 -0700 (PDT) Received: from localhost ([::1]:38417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM97-0006RW-I3 for importer@patchew.org; Fri, 26 May 2017 16:47:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELln-0005ov-21 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELll-0005VA-SE for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45198) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlh-0005Sq-1B; Fri, 26 May 2017 16:23:29 -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 0A481C056789; Fri, 26 May 2017 20:23:28 +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 DE7451713B; Fri, 26 May 2017 20:23:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A481C056789 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 0A481C056789 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:03 +0200 Message-Id: <1495830130-30611-23-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.32]); Fri, 26 May 2017 20:23:28 +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 22/29] qed: Add return value to qed_aio_read/write_data() 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" Don't recurse into qed_aio_next_io() and qed_aio_complete() here, but just return an error code and let the caller handle it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 72 ++++++++++++++++++++++++++-------------------------------= ---- block/qed.h | 21 ------------------ 2 files changed, 31 insertions(+), 62 deletions(-) diff --git a/block/qed.c b/block/qed.c index 7880df8..3a26fdf 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1205,15 +1205,14 @@ static int qed_aio_write_inplace(QEDAIOCB *acb, uin= t64_t offset, size_t len) * Write data cluster * * @opaque: Write request - * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2, QED_CLUSTER_L1, - * or -errno + * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1 * @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) +static int qed_aio_write_data(void *opaque, int ret, + uint64_t offset, size_t len) { QEDAIOCB *acb =3D opaque; =20 @@ -1223,42 +1222,29 @@ static void qed_aio_write_data(void *opaque, int re= t, =20 switch (ret) { case QED_CLUSTER_FOUND: - ret =3D qed_aio_write_inplace(acb, offset, len); - break; + return qed_aio_write_inplace(acb, offset, len); =20 case QED_CLUSTER_L2: case QED_CLUSTER_L1: case QED_CLUSTER_ZERO: - ret =3D qed_aio_write_alloc(acb, len); - break; + return qed_aio_write_alloc(acb, len); =20 default: - assert(ret < 0); - break; - } - - if (ret < 0) { - if (ret !=3D -EINPROGRESS) { - qed_aio_complete(acb, ret); - } - return; + g_assert_not_reached(); } - qed_aio_next_io(acb, 0); } =20 /** * Read data cluster * * @opaque: Read request - * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2, QED_CLUSTER_L1, - * or -errno + * @ret: QED_CLUSTER_FOUND, QED_CLUSTER_L2 or QED_CLUSTER_L1 * @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) +static int qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_= t len) { QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); @@ -1269,34 +1255,23 @@ static void qed_aio_read_data(void *opaque, int ret, =20 trace_qed_aio_read_data(s, acb, ret, offset, len); =20 - if (ret < 0) { - goto err; - } - qemu_iovec_concat(&acb->cur_qiov, acb->qiov, acb->qiov_offset, len); =20 /* Handle zero cluster and backing file reads */ if (ret =3D=3D QED_CLUSTER_ZERO) { qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size); - qed_aio_start_io(acb); - return; + return 0; } else if (ret !=3D QED_CLUSTER_FOUND) { - ret =3D qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, - &acb->backing_qiov); - qed_aio_next_io(acb, ret); - return; + return qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, + &acb->backing_qiov); } =20 BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); ret =3D bdrv_preadv(bs->file, offset, &acb->cur_qiov); if (ret < 0) { - goto err; + return ret; } - qed_aio_next_io(acb, 0); - return; - -err: - qed_aio_complete(acb, ret); + return 0; } =20 /** @@ -1305,8 +1280,6 @@ err: 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 @@ -1337,7 +1310,24 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret) /* 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, &offset= ); - io_fn(acb, ret, offset, len); + if (ret < 0) { + qed_aio_complete(acb, ret); + return; + } + + if (acb->flags & QED_AIOCB_WRITE) { + ret =3D qed_aio_write_data(acb, ret, offset, len); + } else { + ret =3D qed_aio_read_data(acb, ret, offset, len); + } + + if (ret < 0) { + if (ret !=3D -EINPROGRESS) { + qed_aio_complete(acb, ret); + } + return; + } + qed_aio_next_io(acb, 0); } =20 static BlockAIOCB *qed_aio_setup(BlockDriverState *bs, diff --git a/block/qed.h b/block/qed.h index 51443fa..8644fed 100644 --- a/block/qed.h +++ b/block/qed.h @@ -177,27 +177,6 @@ enum { QED_CLUSTER_L1, /* cluster missing in L1 */ }; =20 -/** - * qed_find_cluster() completion callback - * - * @opaque: User data for completion callback - * @ret: QED_CLUSTER_FOUND Success - * QED_CLUSTER_L2 Data cluster unallocated in L2 - * QED_CLUSTER_L1 L2 unallocated in L1 - * -errno POSIX error occurred - * @offset: Data cluster offset - * @len: Contiguous bytes starting from cluster offset - * - * This function is invoked when qed_find_cluster() completes. - * - * On success ret is QED_CLUSTER_FOUND and offset/len are a contiguous ran= ge - * in the image file. - * - * On failure ret is QED_CLUSTER_L2 or QED_CLUSTER_L1 for missing L2 or L1 - * table offset, respectively. len is number of contiguous unallocated by= tes. - */ -typedef void QEDFindClusterFunc(void *opaque, int ret, uint64_t offset, si= ze_t len); - void qed_acquire(BDRVQEDState *s); void qed_release(BDRVQEDState *s); =20 --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495830853945907.460984638182; Fri, 26 May 2017 13:34:13 -0700 (PDT) Received: from localhost ([::1]:38333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELw3-0000jf-Kc for importer@patchew.org; Fri, 26 May 2017 16:34:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlm-0005od-JR for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELll-0005Uu-Ht for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47850) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlj-0005Tk-8p; Fri, 26 May 2017 16:23:31 -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 3AB2E80064; Fri, 26 May 2017 20:23:30 +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 6C2911713B; Fri, 26 May 2017 20:23:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3AB2E80064 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 3AB2E80064 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:04 +0200 Message-Id: <1495830130-30611-24-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.27]); Fri, 26 May 2017 20:23:30 +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 23/29] qed: Remove ret argument from qed_aio_next_io() 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" All callers pass ret =3D 0, so we can just remove it. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/block/qed.c b/block/qed.c index 3a26fdf..078591b 100644 --- a/block/qed.c +++ b/block/qed.c @@ -253,11 +253,11 @@ static CachedL2Table *qed_new_l2_table(BDRVQEDState *= s) return l2_table; } =20 -static void qed_aio_next_io(QEDAIOCB *acb, int ret); +static void qed_aio_next_io(QEDAIOCB *acb); =20 static void qed_aio_start_io(QEDAIOCB *acb) { - qed_aio_next_io(acb, 0); + qed_aio_next_io(acb); } =20 static void qed_plug_allocating_write_reqs(BDRVQEDState *s) @@ -1277,13 +1277,14 @@ 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, int ret) +static void qed_aio_next_io(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset; size_t len; + int ret; =20 - trace_qed_aio_next_io(s, acb, ret, acb->cur_pos + acb->cur_qiov.size); + trace_qed_aio_next_io(s, acb, 0, acb->cur_pos + acb->cur_qiov.size); =20 if (acb->backing_qiov) { qemu_iovec_destroy(acb->backing_qiov); @@ -1291,12 +1292,6 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret) acb->backing_qiov =3D NULL; } =20 - /* Handle I/O error */ - if (ret) { - qed_aio_complete(acb, ret); - return; - } - acb->qiov_offset +=3D acb->cur_qiov.size; acb->cur_pos +=3D acb->cur_qiov.size; qemu_iovec_reset(&acb->cur_qiov); @@ -1327,7 +1322,7 @@ static void qed_aio_next_io(QEDAIOCB *acb, int ret) } return; } - qed_aio_next_io(acb, 0); + qed_aio_next_io(acb); } =20 static BlockAIOCB *qed_aio_setup(BlockDriverState *bs, --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831068424777.1272720872222; Fri, 26 May 2017 13:37:48 -0700 (PDT) Received: from localhost ([::1]:38354 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELzW-0004JW-Vr for importer@patchew.org; Fri, 26 May 2017 16:37:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELlw-0005ve-1L for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELlp-0005Wf-VD for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlm-0005VE-Mj; Fri, 26 May 2017 16:23:34 -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 A00037F4A4; Fri, 26 May 2017 20:23:33 +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 98CF31713B; Fri, 26 May 2017 20:23:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A00037F4A4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A00037F4A4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:05 +0200 Message-Id: <1495830130-30611-25-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.26]); Fri, 26 May 2017 20:23:33 +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 24/29] qed: Remove recursion in qed_aio_next_io() 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" Instead of calling itself recursively as the last thing, just convert qed_aio_next_io() into a loop. This patch is best reviewed with 'git show -w' because most of it is just whitespace changes. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 63 +++++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/block/qed.c b/block/qed.c index 078591b..6a83df2 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1284,45 +1284,46 @@ static void qed_aio_next_io(QEDAIOCB *acb) size_t len; int ret; =20 - trace_qed_aio_next_io(s, acb, 0, acb->cur_pos + acb->cur_qiov.size); + while (1) { + trace_qed_aio_next_io(s, acb, 0, acb->cur_pos + acb->cur_qiov.size= ); =20 - if (acb->backing_qiov) { - qemu_iovec_destroy(acb->backing_qiov); - g_free(acb->backing_qiov); - acb->backing_qiov =3D NULL; - } + if (acb->backing_qiov) { + qemu_iovec_destroy(acb->backing_qiov); + g_free(acb->backing_qiov); + acb->backing_qiov =3D NULL; + } =20 - acb->qiov_offset +=3D acb->cur_qiov.size; - acb->cur_pos +=3D acb->cur_qiov.size; - qemu_iovec_reset(&acb->cur_qiov); + acb->qiov_offset +=3D acb->cur_qiov.size; + acb->cur_pos +=3D acb->cur_qiov.size; + qemu_iovec_reset(&acb->cur_qiov); =20 - /* Complete request */ - if (acb->cur_pos >=3D acb->end_pos) { - qed_aio_complete(acb, 0); - return; - } + /* Complete request */ + if (acb->cur_pos >=3D acb->end_pos) { + qed_aio_complete(acb, 0); + return; + } =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, &offset= ); - if (ret < 0) { - qed_aio_complete(acb, ret); - return; - } + /* 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; + } =20 - if (acb->flags & QED_AIOCB_WRITE) { - ret =3D qed_aio_write_data(acb, ret, offset, len); - } else { - ret =3D qed_aio_read_data(acb, ret, offset, len); - } + if (acb->flags & QED_AIOCB_WRITE) { + ret =3D qed_aio_write_data(acb, ret, offset, len); + } else { + ret =3D qed_aio_read_data(acb, ret, offset, len); + } =20 - if (ret < 0) { - if (ret !=3D -EINPROGRESS) { - qed_aio_complete(acb, ret); + if (ret < 0) { + if (ret !=3D -EINPROGRESS) { + qed_aio_complete(acb, ret); + } + return; } - return; } - qed_aio_next_io(acb); } =20 static BlockAIOCB *qed_aio_setup(BlockDriverState *bs, --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831475207930.9255324586228; Fri, 26 May 2017 13:44:35 -0700 (PDT) Received: from localhost ([::1]:38393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM64-00049S-NN for importer@patchew.org; Fri, 26 May 2017 16:44:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELm2-0005yv-NI for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELm1-0005ZM-H5 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58458) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlr-0005Wr-DM; Fri, 26 May 2017 16:23:39 -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 61E6037EEB; Fri, 26 May 2017 20:23:38 +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 03976176C6; Fri, 26 May 2017 20:23:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 61E6037EEB Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 61E6037EEB From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:06 +0200 Message-Id: <1495830130-30611-26-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.29]); Fri, 26 May 2017 20:23:38 +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 25/29] qed: Implement .bdrv_co_readv/writev 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" Most of the qed code is now synchronous and matches the coroutine model. One notable exception is the serialisation between requests which can still schedule a callback. Before we can replace this with coroutine locks, let's convert the driver's external interfaces to the coroutine versions. We need to be careful to handle both requests that call the completion callback directly from the calling coroutine (i.e. fully synchronous code) and requests that involve some callback, so that we need to yield and wait for the completion callback coming from outside the coroutine. Signed-off-by: Kevin Wolf --- block/qed.c | 94 +++++++++++++++++++++++++--------------------------------= ---- 1 file changed, 39 insertions(+), 55 deletions(-) diff --git a/block/qed.c b/block/qed.c index 6a83df2..29c3dc5 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1326,16 +1326,31 @@ static void qed_aio_next_io(QEDAIOCB *acb) } } =20 -static BlockAIOCB *qed_aio_setup(BlockDriverState *bs, - int64_t sector_num, - QEMUIOVector *qiov, int nb_sectors, - BlockCompletionFunc *cb, - void *opaque, int flags) +typedef struct QEDRequestCo { + Coroutine *co; + bool done; + int ret; +} QEDRequestCo; + +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); +} + +static int qed_co_request(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *qiov, int nb_sectors, int flags) { - QEDAIOCB *acb =3D qemu_aio_get(&qed_aiocb_info, bs, cb, opaque); + 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); =20 - trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, - opaque, flags); + trace_qed_aio_setup(bs->opaque, acb, sector_num, nb_sectors, &co, flag= s); =20 acb->flags =3D flags; acb->qiov =3D qiov; @@ -1348,43 +1363,24 @@ static BlockAIOCB *qed_aio_setup(BlockDriverState *= bs, =20 /* Start request */ qed_aio_start_io(acb); - return &acb->common; -} =20 -static BlockAIOCB *bdrv_qed_aio_readv(BlockDriverState *bs, - int64_t sector_num, - QEMUIOVector *qiov, int nb_sectors, - BlockCompletionFunc *cb, - void *opaque) -{ - return qed_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque, 0); + if (!co.done) { + qemu_coroutine_yield(); + } + + return co.ret; } =20 -static BlockAIOCB *bdrv_qed_aio_writev(BlockDriverState *bs, - int64_t sector_num, - QEMUIOVector *qiov, int nb_sectors, - BlockCompletionFunc *cb, - void *opaque) +static int bdrv_qed_co_readv(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, QEMUIOVector *qiov) { - return qed_aio_setup(bs, sector_num, qiov, nb_sectors, cb, - opaque, QED_AIOCB_WRITE); + return qed_co_request(bs, sector_num, qiov, nb_sectors, 0); } =20 -typedef struct { - Coroutine *co; - int ret; - bool done; -} QEDWriteZeroesCB; - -static void coroutine_fn qed_co_pwrite_zeroes_cb(void *opaque, int ret) +static int bdrv_qed_co_writev(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, QEMUIOVector *qiov) { - QEDWriteZeroesCB *cb =3D opaque; - - cb->done =3D true; - cb->ret =3D ret; - if (cb->co) { - aio_co_wake(cb->co); - } + return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRIT= E); } =20 static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, @@ -1392,9 +1388,7 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Blo= ckDriverState *bs, int count, BdrvRequestFlags flags) { - BlockAIOCB *blockacb; BDRVQEDState *s =3D bs->opaque; - QEDWriteZeroesCB cb =3D { .done =3D false }; QEMUIOVector qiov; struct iovec iov; =20 @@ -1411,19 +1405,9 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Bl= ockDriverState *bs, iov.iov_len =3D count; =20 qemu_iovec_init_external(&qiov, &iov, 1); - blockacb =3D qed_aio_setup(bs, offset >> BDRV_SECTOR_BITS, &qiov, - count >> BDRV_SECTOR_BITS, - qed_co_pwrite_zeroes_cb, &cb, - QED_AIOCB_WRITE | QED_AIOCB_ZERO); - if (!blockacb) { - return -EIO; - } - if (!cb.done) { - cb.co =3D qemu_coroutine_self(); - qemu_coroutine_yield(); - } - assert(cb.done); - return cb.ret; + return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov, + count >> BDRV_SECTOR_BITS, + QED_AIOCB_WRITE | QED_AIOCB_ZERO); } =20 static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) @@ -1619,8 +1603,8 @@ static BlockDriver bdrv_qed =3D { .bdrv_create =3D bdrv_qed_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_get_block_status =3D bdrv_qed_co_get_block_status, - .bdrv_aio_readv =3D bdrv_qed_aio_readv, - .bdrv_aio_writev =3D bdrv_qed_aio_writev, + .bdrv_co_readv =3D bdrv_qed_co_readv, + .bdrv_co_writev =3D bdrv_qed_co_writev, .bdrv_co_pwrite_zeroes =3D bdrv_qed_co_pwrite_zeroes, .bdrv_truncate =3D bdrv_qed_truncate, .bdrv_getlength =3D bdrv_qed_getlength, --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831205226605.6631334411101; Fri, 26 May 2017 13:40:05 -0700 (PDT) Received: from localhost ([::1]:38367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM1h-0007Fs-SU for importer@patchew.org; Fri, 26 May 2017 16:40:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELm2-0005yw-No 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-0005ZN-Gu for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELlt-0005XL-Ia; Fri, 26 May 2017 16:23:41 -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 87997C04BD36; Fri, 26 May 2017 20:23:40 +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 C48421713B; Fri, 26 May 2017 20:23:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 87997C04BD36 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 87997C04BD36 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:07 +0200 Message-Id: <1495830130-30611-27-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.31]); Fri, 26 May 2017 20:23: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] [PATCH 26/29] qed: Use CoQueue for serialising allocations 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're running in coroutine context, the ad-hoc serialisation code (which drops a request that has to wait out of coroutine context) can be replaced by a CoQueue. This means that when we resume a serialised request, it is running in coroutine context again and its I/O isn't blocking any more. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qed.c | 49 +++++++++++++++++-------------------------------- block/qed.h | 3 ++- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/block/qed.c b/block/qed.c index 29c3dc5..2eee451 100644 --- a/block/qed.c +++ b/block/qed.c @@ -269,16 +269,10 @@ static void qed_plug_allocating_write_reqs(BDRVQEDSta= te *s) =20 static void qed_unplug_allocating_write_reqs(BDRVQEDState *s) { - QEDAIOCB *acb; - assert(s->allocating_write_reqs_plugged); =20 s->allocating_write_reqs_plugged =3D false; - - acb =3D QSIMPLEQ_FIRST(&s->allocating_write_reqs); - if (acb) { - qed_aio_start_io(acb); - } + qemu_co_enter_next(&s->allocating_write_reqs); } =20 static void qed_clear_need_check(void *opaque, int ret) @@ -305,7 +299,7 @@ static void qed_need_check_timer_cb(void *opaque) BDRVQEDState *s =3D opaque; =20 /* The timer should only fire when allocating writes have drained */ - assert(!QSIMPLEQ_FIRST(&s->allocating_write_reqs)); + assert(!s->allocating_acb); =20 trace_qed_need_check_timer_cb(s); =20 @@ -388,7 +382,7 @@ static int bdrv_qed_do_open(BlockDriverState *bs, QDict= *options, int flags, int ret; =20 s->bs =3D bs; - QSIMPLEQ_INIT(&s->allocating_write_reqs); + qemu_co_queue_init(&s->allocating_write_reqs); =20 ret =3D bdrv_pread(bs->file, 0, &le_header, sizeof(le_header)); if (ret < 0) { @@ -910,11 +904,6 @@ static void qed_aio_complete_bh(void *opaque) qed_release(s); } =20 -static void qed_resume_alloc_bh(void *opaque) -{ - qed_aio_start_io(opaque); -} - static void qed_aio_complete(QEDAIOCB *acb, int ret) { BDRVQEDState *s =3D acb_to_s(acb); @@ -942,13 +931,10 @@ static void qed_aio_complete(QEDAIOCB *acb, int ret) * next request in the queue. This ensures that we don't cycle through * requests multiple times but rather finish one at a time completely. */ - if (acb =3D=3D QSIMPLEQ_FIRST(&s->allocating_write_reqs)) { - QEDAIOCB *next_acb; - QSIMPLEQ_REMOVE_HEAD(&s->allocating_write_reqs, next); - next_acb =3D QSIMPLEQ_FIRST(&s->allocating_write_reqs); - if (next_acb) { - aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), - qed_resume_alloc_bh, next_acb); + if (acb =3D=3D s->allocating_acb) { + s->allocating_acb =3D NULL; + if (!qemu_co_queue_empty(&s->allocating_write_reqs)) { + qemu_co_enter_next(&s->allocating_write_reqs); } else if (s->header.features & QED_F_NEED_CHECK) { qed_start_need_check_timer(s); } @@ -1124,17 +1110,18 @@ static int qed_aio_write_alloc(QEDAIOCB *acb, size_= t len) int ret; =20 /* Cancel timer when the first allocating request comes in */ - if (QSIMPLEQ_EMPTY(&s->allocating_write_reqs)) { + if (s->allocating_acb =3D=3D NULL) { qed_cancel_need_check_timer(s); } =20 /* Freeze this request if another allocating write is in progress */ - if (acb !=3D QSIMPLEQ_FIRST(&s->allocating_write_reqs)) { - QSIMPLEQ_INSERT_TAIL(&s->allocating_write_reqs, acb, next); - } - if (acb !=3D QSIMPLEQ_FIRST(&s->allocating_write_reqs) || - s->allocating_write_reqs_plugged) { - return -EINPROGRESS; /* wait for existing request to finish */ + if (s->allocating_acb !=3D acb || s->allocating_write_reqs_plugged) { + if (s->allocating_acb !=3D NULL) { + qemu_co_queue_wait(&s->allocating_write_reqs, NULL); + assert(s->allocating_acb =3D=3D NULL); + } + s->allocating_acb =3D acb; + return -EAGAIN; /* start over with looking up table entries */ } =20 acb->cur_nclusters =3D qed_bytes_to_clusters(s, @@ -1317,10 +1304,8 @@ static void qed_aio_next_io(QEDAIOCB *acb) ret =3D qed_aio_read_data(acb, ret, offset, len); } =20 - if (ret < 0) { - if (ret !=3D -EINPROGRESS) { - qed_aio_complete(acb, ret); - } + if (ret < 0 && ret !=3D -EAGAIN) { + qed_aio_complete(acb, ret); return; } } diff --git a/block/qed.h b/block/qed.h index 8644fed..37558e4 100644 --- a/block/qed.h +++ b/block/qed.h @@ -163,7 +163,8 @@ typedef struct { uint32_t l2_mask; =20 /* Allocating write request queue */ - QSIMPLEQ_HEAD(, QEDAIOCB) allocating_write_reqs; + QEDAIOCB *allocating_acb; + CoQueue allocating_write_reqs; bool allocating_write_reqs_plugged; =20 /* Periodic flush and clear need check flag */ --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 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 From nobody Sun May 5 19:45:33 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 1495831326327734.5013653389698; Fri, 26 May 2017 13:42:06 -0700 (PDT) Received: from localhost ([::1]:38379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM3g-0000TN-KO for importer@patchew.org; Fri, 26 May 2017 16:42:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELm4-000613-IF for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELm3-0005aO-J4 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48340) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELm1-0005Z8-Bc; Fri, 26 May 2017 16:23:49 -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 552E980F6D; Fri, 26 May 2017 20:23:48 +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 0B0FC173A7; Fri, 26 May 2017 20:23:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 552E980F6D 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 552E980F6D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:09 +0200 Message-Id: <1495830130-30611-29-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.27]); Fri, 26 May 2017 20:23:48 +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 28/29] qed: Use a coroutine for need_check_timer 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" This fixes the last place where we degraded from AIO to actual blocking synchronous I/O requests. Putting it into a coroutine means that instead of blocking, the coroutine simply yields while doing I/O. Signed-off-by: Kevin Wolf --- block/qed.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/block/qed.c b/block/qed.c index d3f7d0c..20e81a0 100644 --- a/block/qed.c +++ b/block/qed.c @@ -264,11 +264,23 @@ static void qed_unplug_allocating_write_reqs(BDRVQEDS= tate *s) qemu_co_enter_next(&s->allocating_write_reqs); } =20 -static void qed_clear_need_check(void *opaque, int ret) +static void qed_need_check_timer_entry(void *opaque) { BDRVQEDState *s =3D opaque; + int ret; =20 - if (ret) { + /* The timer should only fire when allocating writes have drained */ + assert(!s->allocating_acb); + + trace_qed_need_check_timer_cb(s); + + qed_acquire(s); + qed_plug_allocating_write_reqs(s); + + /* Ensure writes are on disk before clearing flag */ + ret =3D bdrv_co_flush(s->bs->file->bs); + qed_release(s); + if (ret < 0) { goto out; } =20 @@ -276,7 +288,7 @@ static void qed_clear_need_check(void *opaque, int ret) ret =3D qed_write_header(s); (void) ret; =20 - ret =3D bdrv_flush(s->bs); + ret =3D bdrv_co_flush(s->bs); (void) ret; =20 out: @@ -285,19 +297,8 @@ out: =20 static void qed_need_check_timer_cb(void *opaque) { - BDRVQEDState *s =3D opaque; - - /* The timer should only fire when allocating writes have drained */ - assert(!s->allocating_acb); - - trace_qed_need_check_timer_cb(s); - - qed_acquire(s); - qed_plug_allocating_write_reqs(s); - - /* Ensure writes are on disk before clearing flag */ - bdrv_aio_flush(s->bs->file->bs, qed_clear_need_check, s); - qed_release(s); + Coroutine *co =3D qemu_coroutine_create(qed_need_check_timer_entry, op= aque); + qemu_coroutine_enter(co); } =20 void qed_acquire(BDRVQEDState *s) --=20 1.8.3.1 From nobody Sun May 5 19:45:33 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 1495831669359883.9466373672309; Fri, 26 May 2017 13:47:49 -0700 (PDT) Received: from localhost ([::1]:38418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEM9D-0006YE-01 for importer@patchew.org; Fri, 26 May 2017 16:47:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELmB-00066p-K7 for qemu-devel@nongnu.org; Fri, 26 May 2017 16:24:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELm6-0005bI-Mo for qemu-devel@nongnu.org; Fri, 26 May 2017 16:23:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33718) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELm3-0005aA-Et; Fri, 26 May 2017 16:23:51 -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 78E9C61BA1; Fri, 26 May 2017 20:23:50 +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 B60F8173A7; Fri, 26 May 2017 20:23:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 78E9C61BA1 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 78E9C61BA1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:22:10 +0200 Message-Id: <1495830130-30611-30-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.39]); Fri, 26 May 2017 20:23:50 +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 29/29] block: Remove bdrv_aio_readv/writev_flush() 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" These functions are unused now. Signed-off-by: Kevin Wolf --- block/io.c | 171 ----------------------------------------------= ---- include/block/block.h | 8 --- 2 files changed, 179 deletions(-) diff --git a/block/io.c b/block/io.c index fdd7485..1fec424 100644 --- a/block/io.c +++ b/block/io.c @@ -33,14 +33,6 @@ =20 #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progr= ess */ =20 -static BlockAIOCB *bdrv_co_aio_prw_vector(BdrvChild *child, - int64_t offset, - QEMUIOVector *qiov, - BdrvRequestFlags flags, - BlockCompletionFunc *cb, - void *opaque, - bool is_write); -static void coroutine_fn bdrv_co_do_rw(void *opaque); static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int count, BdrvRequestFlags flags); =20 @@ -2083,28 +2075,6 @@ int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOV= ector *qiov, int64_t pos) /**************************************************************/ /* async I/Os */ =20 -BlockAIOCB *bdrv_aio_readv(BdrvChild *child, int64_t sector_num, - QEMUIOVector *qiov, int nb_sectors, - BlockCompletionFunc *cb, void *opaque) -{ - trace_bdrv_aio_readv(child->bs, sector_num, nb_sectors, opaque); - - assert(nb_sectors << BDRV_SECTOR_BITS =3D=3D qiov->size); - return bdrv_co_aio_prw_vector(child, sector_num << BDRV_SECTOR_BITS, q= iov, - 0, cb, opaque, false); -} - -BlockAIOCB *bdrv_aio_writev(BdrvChild *child, int64_t sector_num, - QEMUIOVector *qiov, int nb_sectors, - BlockCompletionFunc *cb, void *opaque) -{ - trace_bdrv_aio_writev(child->bs, sector_num, nb_sectors, opaque); - - assert(nb_sectors << BDRV_SECTOR_BITS =3D=3D qiov->size); - return bdrv_co_aio_prw_vector(child, sector_num << BDRV_SECTOR_BITS, q= iov, - 0, cb, opaque, true); -} - void bdrv_aio_cancel(BlockAIOCB *acb) { qemu_aio_ref(acb); @@ -2137,147 +2107,6 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb) } =20 /**************************************************************/ -/* async block device emulation */ - -typedef struct BlockRequest { - union { - /* Used during read, write, trim */ - struct { - int64_t offset; - int bytes; - int flags; - QEMUIOVector *qiov; - }; - /* Used during ioctl */ - struct { - int req; - void *buf; - }; - }; - BlockCompletionFunc *cb; - void *opaque; - - int error; -} BlockRequest; - -typedef struct BlockAIOCBCoroutine { - BlockAIOCB common; - BdrvChild *child; - BlockRequest req; - bool is_write; - bool need_bh; - bool *done; -} BlockAIOCBCoroutine; - -static const AIOCBInfo bdrv_em_co_aiocb_info =3D { - .aiocb_size =3D sizeof(BlockAIOCBCoroutine), -}; - -static void bdrv_co_complete(BlockAIOCBCoroutine *acb) -{ - if (!acb->need_bh) { - bdrv_dec_in_flight(acb->common.bs); - acb->common.cb(acb->common.opaque, acb->req.error); - qemu_aio_unref(acb); - } -} - -static void bdrv_co_em_bh(void *opaque) -{ - BlockAIOCBCoroutine *acb =3D opaque; - - assert(!acb->need_bh); - bdrv_co_complete(acb); -} - -static void bdrv_co_maybe_schedule_bh(BlockAIOCBCoroutine *acb) -{ - acb->need_bh =3D false; - if (acb->req.error !=3D -EINPROGRESS) { - BlockDriverState *bs =3D acb->common.bs; - - aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), bdrv_co_em_bh, a= cb); - } -} - -/* Invoke bdrv_co_do_readv/bdrv_co_do_writev */ -static void coroutine_fn bdrv_co_do_rw(void *opaque) -{ - BlockAIOCBCoroutine *acb =3D opaque; - - if (!acb->is_write) { - acb->req.error =3D bdrv_co_preadv(acb->child, acb->req.offset, - acb->req.qiov->size, acb->req.qiov, acb->req.flags); - } else { - acb->req.error =3D bdrv_co_pwritev(acb->child, acb->req.offset, - acb->req.qiov->size, acb->req.qiov, acb->req.flags); - } - - bdrv_co_complete(acb); -} - -static BlockAIOCB *bdrv_co_aio_prw_vector(BdrvChild *child, - int64_t offset, - QEMUIOVector *qiov, - BdrvRequestFlags flags, - BlockCompletionFunc *cb, - void *opaque, - bool is_write) -{ - Coroutine *co; - BlockAIOCBCoroutine *acb; - - /* Matched by bdrv_co_complete's bdrv_dec_in_flight. */ - bdrv_inc_in_flight(child->bs); - - acb =3D qemu_aio_get(&bdrv_em_co_aiocb_info, child->bs, cb, opaque); - acb->child =3D child; - acb->need_bh =3D true; - acb->req.error =3D -EINPROGRESS; - acb->req.offset =3D offset; - acb->req.qiov =3D qiov; - acb->req.flags =3D flags; - acb->is_write =3D is_write; - - co =3D qemu_coroutine_create(bdrv_co_do_rw, acb); - bdrv_coroutine_enter(child->bs, co); - - bdrv_co_maybe_schedule_bh(acb); - return &acb->common; -} - -static void coroutine_fn bdrv_aio_flush_co_entry(void *opaque) -{ - BlockAIOCBCoroutine *acb =3D opaque; - BlockDriverState *bs =3D acb->common.bs; - - acb->req.error =3D bdrv_co_flush(bs); - bdrv_co_complete(acb); -} - -BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs, - BlockCompletionFunc *cb, void *opaque) -{ - trace_bdrv_aio_flush(bs, opaque); - - Coroutine *co; - BlockAIOCBCoroutine *acb; - - /* Matched by bdrv_co_complete's bdrv_dec_in_flight. */ - bdrv_inc_in_flight(bs); - - acb =3D qemu_aio_get(&bdrv_em_co_aiocb_info, bs, cb, opaque); - acb->need_bh =3D true; - acb->req.error =3D -EINPROGRESS; - - co =3D qemu_coroutine_create(bdrv_aio_flush_co_entry, acb); - bdrv_coroutine_enter(bs, co); - - bdrv_co_maybe_schedule_bh(acb); - return &acb->common; -} - -/**************************************************************/ /* Coroutine block device emulation */ =20 typedef struct FlushCo { diff --git a/include/block/block.h b/include/block/block.h index 9b355e9..c2dc243 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -353,14 +353,6 @@ BlockDriverState *check_to_replace_node(BlockDriverSta= te *parent_bs, const char *node_name, Error **err= p); =20 /* async block I/O */ -BlockAIOCB *bdrv_aio_readv(BdrvChild *child, int64_t sector_num, - QEMUIOVector *iov, int nb_sectors, - BlockCompletionFunc *cb, void *opaque); -BlockAIOCB *bdrv_aio_writev(BdrvChild *child, int64_t sector_num, - QEMUIOVector *iov, int nb_sectors, - BlockCompletionFunc *cb, void *opaque); -BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs, - BlockCompletionFunc *cb, void *opaque); void bdrv_aio_cancel(BlockAIOCB *acb); void bdrv_aio_cancel_async(BlockAIOCB *acb); =20 --=20 1.8.3.1