From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530281748013453.23793803458955; Fri, 29 Jun 2018 07:15:48 -0700 (PDT) Received: from localhost ([::1]:42482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuBf-0008Nq-7J for importer@patchew.org; Fri, 29 Jun 2018 10:15:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6N-0003pp-TD for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6J-0003i2-Hf for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35738 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu67-0003Ik-L7; Fri, 29 Jun 2018 10:10:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B84D4010222; Fri, 29 Jun 2018 14:10:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BC301102E29; Fri, 29 Jun 2018 14:10:02 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:31 +0200 Message-Id: <20180629140959.6690-2-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 29 Jun 2018 14:10:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 29 Jun 2018 14:10:03 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 01/29] block-qdict: Pacify Coverity after commit f1b34a248e9 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Commit f1b34a248e9 replaced less-than-obvious test in qdict_flatten_qdict() by the obvious one. Sadly, it made something else non-obvious: the fact that @new_key passed to qdict_put_obj() can't be null, because that depends on the function's precondition (target =3D=3D qdict) =3D=3D !prefix. Tweak the function some more to help Coverity and human readers alike. Fixes: CID 1393620 Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- qobject/block-qdict.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c index 36129e7379..80c653013f 100644 --- a/qobject/block-qdict.c +++ b/qobject/block-qdict.c @@ -97,7 +97,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *targ= et, const char *prefix) const QDictEntry *entry, *next; QDict *dict_val; QList *list_val; - char *new_key; + char *key, *new_key; =20 entry =3D qdict_first(qdict); =20 @@ -106,10 +106,12 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *= target, const char *prefix) value =3D qdict_entry_value(entry); dict_val =3D qobject_to(QDict, value); list_val =3D qobject_to(QList, value); - new_key =3D NULL; =20 if (prefix) { - new_key =3D g_strdup_printf("%s.%s", prefix, entry->key); + key =3D new_key =3D g_strdup_printf("%s.%s", prefix, entry->ke= y); + } else { + key =3D entry->key; + new_key =3D NULL; } =20 /* @@ -125,19 +127,17 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *= target, const char *prefix) * well advised not to modify them altogether.) */ if (dict_val && qdict_size(dict_val)) { - qdict_flatten_qdict(dict_val, target, - new_key ? new_key : entry->key); + qdict_flatten_qdict(dict_val, target, key); if (target =3D=3D qdict) { qdict_del(qdict, entry->key); } } else if (list_val && !qlist_empty(list_val)) { - qdict_flatten_qlist(list_val, target, - new_key ? new_key : entry->key); + qdict_flatten_qlist(list_val, target, key); if (target =3D=3D qdict) { qdict_del(qdict, entry->key); } } else if (target !=3D qdict) { - qdict_put_obj(target, new_key, qobject_ref(value)); + qdict_put_obj(target, key, qobject_ref(value)); } =20 g_free(new_key); --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530281644342772.4733620772865; Fri, 29 Jun 2018 07:14:04 -0700 (PDT) Received: from localhost ([::1]:42464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu9z-0006Xs-I2 for importer@patchew.org; Fri, 29 Jun 2018 10:14:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6H-0003hL-Ac for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6F-0003bk-Rh for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51336 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6A-0003NO-8M; Fri, 29 Jun 2018 10:10:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBA72401EF1D; Fri, 29 Jun 2018 14:10:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85DD61102E29; Fri, 29 Jun 2018 14:10:03 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:32 +0200 Message-Id: <20180629140959.6690-3-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:05 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 02/29] block/crypto: Pacify Coverity after commit f853465aacb 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Coverity can't see that qobject_input_visitor_new_flat_confused() returns non-null when it doesn't set @local_err. Check the return value instead, like all the other callers do. Fixes: CID 1393615 Fixes: CID 1393616 Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- block/crypto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 82091c5f70..aaa8fb7530 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -160,7 +160,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, ret->format =3D format; =20 v =3D qobject_input_visitor_new_flat_confused(opts, &local_err); - if (local_err) { + if (!v) { goto out; } =20 @@ -214,7 +214,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, ret->format =3D format; =20 v =3D qobject_input_visitor_new_flat_confused(opts, &local_err); - if (local_err) { + if (!v) { goto out; } =20 --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530281898216677.8166644945815; Fri, 29 Jun 2018 07:18:18 -0700 (PDT) Received: from localhost ([::1]:42493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuE5-0002AT-Dc for importer@patchew.org; Fri, 29 Jun 2018 10:18:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6F-0003ef-Lv for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6E-0003XD-BZ for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44832 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6B-0003Pu-8a; Fri, 29 Jun 2018 10:10:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8A0CF043D; Fri, 29 Jun 2018 14:10:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 240291102E29; Fri, 29 Jun 2018 14:10:06 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:33 +0200 Message-Id: <20180629140959.6690-4-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:06 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 03/29] qapi/job: The next release will be 3.0 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit 51f63ec7d tried to change all references to 2.13 into 3.0, but it failed to achieve this because it was not properly rebased on top of the series introducing qapi/job.json. Change the references now. Signed-off-by: Kevin Wolf Reviewed-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/job.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/qapi/job.json b/qapi/job.json index 9d074eb8d2..a121b615fb 100644 --- a/qapi/job.json +++ b/qapi/job.json @@ -104,7 +104,7 @@ # @id: The job identifier # @status: The new job status # -# Since: 2.13 +# Since: 3.0 ## { 'event': 'JOB_STATUS_CHANGE', 'data': { 'id': 'str', @@ -126,7 +126,7 @@ # # @id: The job identifier. # -# Since: 2.13 +# Since: 3.0 ## { 'command': 'job-pause', 'data': { 'id': 'str' } } =20 @@ -140,7 +140,7 @@ # # @id : The job identifier. # -# Since: 2.13 +# Since: 3.0 ## { 'command': 'job-resume', 'data': { 'id': 'str' } } =20 @@ -159,7 +159,7 @@ # # @id: The job identifier. # -# Since: 2.13 +# Since: 3.0 ## { 'command': 'job-cancel', 'data': { 'id': 'str' } } =20 @@ -171,7 +171,7 @@ # # @id: The job identifier. # -# Since: 2.13 +# Since: 3.0 ## { 'command': 'job-complete', 'data': { 'id': 'str' } } =20 @@ -187,7 +187,7 @@ # # @id: The job identifier. # -# Since: 2.13 +# Since: 3.0 ## { 'command': 'job-dismiss', 'data': { 'id': 'str' } } =20 @@ -205,7 +205,7 @@ # @id: The identifier of any job in the transaction, or of a job that is n= ot # part of any transaction. # -# Since: 2.13 +# Since: 3.0 ## { 'command': 'job-finalize', 'data': { 'id': 'str' } } =20 @@ -237,7 +237,7 @@ # the reason for the job failure. It should not be p= arsed # by applications. # -# Since: 2.13 +# Since: 3.0 ## { 'struct': 'JobInfo', 'data': { 'id': 'str', 'type': 'JobType', 'status': 'JobStatus', @@ -251,6 +251,6 @@ # # Returns: a list with a @JobInfo for each active job # -# Since: 2.13 +# Since: 3.0 ## { 'command': 'query-jobs', 'returns': ['JobInfo'] } --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282107452261.6499844112693; Fri, 29 Jun 2018 07:21:47 -0700 (PDT) Received: from localhost ([::1]:42516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuHS-0004zW-CN for importer@patchew.org; Fri, 29 Jun 2018 10:21:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6G-0003gy-RS for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6F-0003b2-Jy for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51340 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6C-0003SI-BF; Fri, 29 Jun 2018 10:10:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0064E401EF1D; Fri, 29 Jun 2018 14:10:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FAEB1102E29; Fri, 29 Jun 2018 14:10:07 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:34 +0200 Message-Id: <20180629140959.6690-5-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:08 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 04/29] usb-storage: Add rerror/werror properties 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The error handling policy was traditionally set with -drive, but with -blockdev it is no longer possible to set frontend options. scsi-disk (and other block devices) have long supported qdev properties to configure the error handling policy, so let's add these options to usb-storage as well and just forward them to the internal scsi-disk instance. Signed-off-by: Kevin Wolf Reviewed-by: Markus Armbruster --- include/hw/scsi/scsi.h | 2 ++ hw/scsi/scsi-bus.c | 11 ++++++++++- hw/usb/dev-storage.c | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index e35137ea78..1a7290d563 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -154,6 +154,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice = *d) SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, int unit, bool removable, int bootin= dex, bool share_rw, + BlockdevOnError rerror, + BlockdevOnError werror, const char *serial, Error **errp); void scsi_bus_legacy_handle_cmdline(SCSIBus *bus); void scsi_legacy_handle_cmdline(void); diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 9646743a7d..5905f6bf29 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -226,6 +226,8 @@ static void scsi_qdev_unrealize(DeviceState *qdev, Erro= r **errp) SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, int unit, bool removable, int bootin= dex, bool share_rw, + BlockdevOnError rerror, + BlockdevOnError werror, const char *serial, Error **errp) { const char *driver; @@ -262,6 +264,10 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, Bl= ockBackend *blk, object_unparent(OBJECT(dev)); return NULL; } + + qdev_prop_set_enum(dev, "rerror", rerror); + qdev_prop_set_enum(dev, "werror", werror); + object_property_set_bool(OBJECT(dev), true, "realized", &err); if (err !=3D NULL) { error_propagate(errp, err); @@ -285,7 +291,10 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus) } qemu_opts_loc_restore(dinfo->opts); scsi_bus_legacy_add_drive(bus, blk_by_legacy_dinfo(dinfo), - unit, false, -1, false, NULL, &error_fat= al); + unit, false, -1, false, + BLOCKDEV_ON_ERROR_AUTO, + BLOCKDEV_ON_ERROR_AUTO, + NULL, &error_fatal); } loc_pop(&loc); } diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index c99398b7f6..cd5551d94f 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -625,6 +625,7 @@ static void usb_msd_storage_realize(USBDevice *dev, Err= or **errp) &usb_msd_scsi_info_storage, NULL); scsi_dev =3D scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable, s->conf.bootindex, s->conf.share_= rw, + s->conf.rerror, s->conf.werror, dev->serial, errp); blk_unref(blk); @@ -671,6 +672,7 @@ static const VMStateDescription vmstate_usb_msd =3D { =20 static Property msd_properties[] =3D { DEFINE_BLOCK_PROPERTIES(MSDState, conf), + DEFINE_BLOCK_ERROR_PROPERTIES(MSDState, conf), DEFINE_PROP_BIT("removable", MSDState, removable, 0, false), DEFINE_PROP_END_OF_LIST(), }; --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530281577894783.5498766460629; Fri, 29 Jun 2018 07:12:57 -0700 (PDT) Received: from localhost ([::1]:42456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu8v-0005fR-1s for importer@patchew.org; Fri, 29 Jun 2018 10:12:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6M-0003oY-Mi for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6J-0003iL-IT for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44836 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6D-0003Tl-Dc; Fri, 29 Jun 2018 10:10:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BFA2C12C9; Fri, 29 Jun 2018 14:10:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3ACB41102E29; Fri, 29 Jun 2018 14:10:08 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:35 +0200 Message-Id: <20180629140959.6690-6-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:09 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 05/29] hw/block/nvme: add optional parameter num_queues for nvme device 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Weiping Zhang Add an optional paramter num_queues for device, and set it to 64 by default. Signed-off-by: Weiping Zhang Acked-by: Keith Busch Signed-off-by: Kevin Wolf --- hw/block/nvme.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index d5bf95b79b..156ecf3c41 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -18,7 +18,8 @@ * Usage: add options: * -drive file=3D,if=3Dnone,id=3D * -device nvme,drive=3D,serial=3D,id=3D, \ - * cmb_size_mb=3D + * cmb_size_mb=3D, \ + * num_queues=3D * * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at * offset 0 in BAR2 and supports only WDS, RDS and SQS for now. @@ -1232,7 +1233,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) pcie_endpoint_cap_init(&n->parent_obj, 0x80); =20 n->num_namespaces =3D 1; - n->num_queues =3D 64; n->reg_size =3D pow2ceil(0x1004 + 2 * (n->num_queues + 1) * 4); n->ns_size =3D bs_size / (uint64_t)n->num_namespaces; =20 @@ -1341,6 +1341,7 @@ static Property nvme_props[] =3D { DEFINE_BLOCK_PROPERTIES(NvmeCtrl, conf), DEFINE_PROP_STRING("serial", NvmeCtrl, serial), DEFINE_PROP_UINT32("cmb_size_mb", NvmeCtrl, cmb_size_mb, 0), + DEFINE_PROP_UINT32("num_queues", NvmeCtrl, num_queues, 64), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282043104672.976035279189; Fri, 29 Jun 2018 07:20:43 -0700 (PDT) Received: from localhost ([::1]:42501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuGQ-0003m1-C3 for importer@patchew.org; Fri, 29 Jun 2018 10:20:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6N-0003q7-WF for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6M-0003nS-MX for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44840 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6E-0003WY-Cp; Fri, 29 Jun 2018 10:10:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16A7FC12C9; Fri, 29 Jun 2018 14:10:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46DE61102E29; Fri, 29 Jun 2018 14:10:09 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:36 +0200 Message-Id: <20180629140959.6690-7-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:10 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 06/29] qcow2: Fix qcow2_truncate() error return value 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If qcow2_alloc_clusters_at() returns an error, we do need to negate it to get back the positive errno code for error_setg_errno(), but we still need to return the negative error code. Fixes: 772d1f973f87269f6a4a4ea4b880680f3779bbdf Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index a3a3aa2a97..6b2e1e1058 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3597,7 +3597,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, if (clusters_allocated < 0) { error_setg_errno(errp, -clusters_allocated, "Failed to allocate data clusters"); - return -clusters_allocated; + return clusters_allocated; } =20 assert(clusters_allocated =3D=3D nb_new_data_clusters); --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282200865734.1547502705844; Fri, 29 Jun 2018 07:23:20 -0700 (PDT) Received: from localhost ([::1]:42521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuIx-0006Lr-Vo for importer@patchew.org; Fri, 29 Jun 2018 10:23:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6S-0003wA-Og for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6N-0003qK-Qe for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44844 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6F-0003Zl-Jp; Fri, 29 Jun 2018 10:10:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4388FC12C9; Fri, 29 Jun 2018 14:10:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51B191102E29; Fri, 29 Jun 2018 14:10:10 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:37 +0200 Message-Id: <20180629140959.6690-8-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:11 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 07/29] block: Convert .bdrv_truncate callback to coroutine_fn 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_truncate() is an operation that can block (even for a quite long time, depending on the PreallocMode) in I/O paths that shouldn't block. Convert it to a coroutine_fn so that we have the infrastructure for drivers to make their .bdrv_co_truncate implementation asynchronous. This change could potentially introduce new race conditions because bdrv_truncate() isn't necessarily executed atomically any more. Whether this is a problem needs to be evaluated for each block driver that supports truncate: * file-posix/win32, gluster, iscsi, nfs, rbd, ssh, sheepdog: The protocol drivers are trivially safe because they don't actually yield yet, so there is no change in behaviour. * copy-on-read, crypto, raw-format: Essentially just filter drivers that pass the request to a child node, no problem. * qcow2: The implementation modifies metadata, so it needs to hold s->lock to be safe with concurrent I/O requests. In order to avoid double locking, this requires pulling the locking out into preallocate_co() and using qcow2_write_caches() instead of bdrv_flush(). * qed: Does a single header update, this is fine without locking. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- include/block/block.h | 4 +++ include/block/block_int.h | 4 +-- block.c | 63 +++++++++++++++++++++++++++++++++++----- block/copy-on-read.c | 8 ++--- block/crypto.c | 9 +++--- block/file-posix.c | 12 ++++---- block/file-win32.c | 6 ++-- block/gluster.c | 14 +++++---- block/iscsi.c | 8 ++--- block/nfs.c | 7 +++-- block/qcow2.c | 74 ++++++++++++++++++++++++++++---------------= ---- block/qed.c | 8 +++-- block/raw-format.c | 8 ++--- block/rbd.c | 8 +++-- block/sheepdog.c | 12 ++++---- block/ssh.c | 6 ++-- 16 files changed, 162 insertions(+), 89 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index b1d6fdb97a..42e59ff585 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -300,8 +300,12 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *chil= d, int64_t offset, BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *backing_file); void bdrv_refresh_filename(BlockDriverState *bs); + +int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, + PreallocMode prealloc, Error **errp); int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, Error **errp); + int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 74646ed722..c653ee663a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -289,8 +289,8 @@ struct BlockDriver { * bdrv_parse_filename. */ const char *protocol_name; - int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp); + int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t off= set, + PreallocMode prealloc, Error **er= rp); =20 int64_t (*bdrv_getlength)(BlockDriverState *bs); bool has_variable_length; diff --git a/block.c b/block.c index 1b8147c1b3..f761bc85d5 100644 --- a/block.c +++ b/block.c @@ -3788,8 +3788,8 @@ exit: /** * Truncate file to 'offset' bytes (needed only for file protocols) */ -int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, - Error **errp) +int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, + PreallocMode prealloc, Error **errp) { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; @@ -3807,23 +3807,28 @@ int bdrv_truncate(BdrvChild *child, int64_t offset,= PreallocMode prealloc, return -EINVAL; } =20 - if (!drv->bdrv_truncate) { + bdrv_inc_in_flight(bs); + + if (!drv->bdrv_co_truncate) { if (bs->file && drv->is_filter) { - return bdrv_truncate(bs->file, offset, prealloc, errp); + ret =3D bdrv_co_truncate(bs->file, offset, prealloc, errp); + goto out; } error_setg(errp, "Image format driver does not support resize"); - return -ENOTSUP; + ret =3D -ENOTSUP; + goto out; } if (bs->read_only) { error_setg(errp, "Image is read-only"); - return -EACCES; + ret =3D -EACCES; + goto out; } =20 assert(!(bs->open_flags & BDRV_O_INACTIVE)); =20 - ret =3D drv->bdrv_truncate(bs, offset, prealloc, errp); + ret =3D drv->bdrv_co_truncate(bs, offset, prealloc, errp); if (ret < 0) { - return ret; + goto out; } ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); if (ret < 0) { @@ -3834,9 +3839,51 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, = PreallocMode prealloc, bdrv_dirty_bitmap_truncate(bs, offset); bdrv_parent_cb_resize(bs); atomic_inc(&bs->write_gen); + +out: + bdrv_dec_in_flight(bs); return ret; } =20 +typedef struct TruncateCo { + BdrvChild *child; + int64_t offset; + PreallocMode prealloc; + Error **errp; + int ret; +} TruncateCo; + +static void coroutine_fn bdrv_truncate_co_entry(void *opaque) +{ + TruncateCo *tco =3D opaque; + tco->ret =3D bdrv_co_truncate(tco->child, tco->offset, tco->prealloc, + tco->errp); +} + +int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, + Error **errp) +{ + Coroutine *co; + TruncateCo tco =3D { + .child =3D child, + .offset =3D offset, + .prealloc =3D prealloc, + .errp =3D errp, + .ret =3D NOT_DONE, + }; + + if (qemu_in_coroutine()) { + /* Fast-path if already in coroutine context */ + bdrv_truncate_co_entry(&tco); + } else { + co =3D qemu_coroutine_create(bdrv_truncate_co_entry, &tco); + qemu_coroutine_enter(co); + BDRV_POLL_WHILE(child->bs, tco.ret =3D=3D NOT_DONE); + } + + return tco.ret; +} + /** * Length of a allocated file in bytes. Sparse files are counted by actual * allocated space. Return < 0 if error or unknown. diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 6a97208888..1dcdaeed69 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -80,10 +80,10 @@ static int64_t cor_getlength(BlockDriverState *bs) } =20 =20 -static int cor_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn cor_co_truncate(BlockDriverState *bs, int64_t offs= et, + PreallocMode prealloc, Error **err= p) { - return bdrv_truncate(bs->file, offset, prealloc, errp); + return bdrv_co_truncate(bs->file, offset, prealloc, errp); } =20 =20 @@ -147,7 +147,7 @@ BlockDriver bdrv_copy_on_read =3D { .bdrv_child_perm =3D cor_child_perm, =20 .bdrv_getlength =3D cor_getlength, - .bdrv_truncate =3D cor_truncate, + .bdrv_co_truncate =3D cor_co_truncate, =20 .bdrv_co_preadv =3D cor_co_preadv, .bdrv_co_pwritev =3D cor_co_pwritev, diff --git a/block/crypto.c b/block/crypto.c index aaa8fb7530..210c80d5c7 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -357,8 +357,9 @@ static int block_crypto_co_create_generic(BlockDriverSt= ate *bs, return ret; } =20 -static int block_crypto_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn +block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BlockCrypto *crypto =3D bs->opaque; uint64_t payload_offset =3D @@ -371,7 +372,7 @@ static int block_crypto_truncate(BlockDriverState *bs, = int64_t offset, =20 offset +=3D payload_offset; =20 - return bdrv_truncate(bs->file, offset, prealloc, errp); + return bdrv_co_truncate(bs->file, offset, prealloc, errp); } =20 static void block_crypto_close(BlockDriverState *bs) @@ -700,7 +701,7 @@ BlockDriver bdrv_crypto_luks =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_co_create =3D block_crypto_co_create_luks, .bdrv_co_create_opts =3D block_crypto_co_create_opts_luks, - .bdrv_truncate =3D block_crypto_truncate, + .bdrv_co_truncate =3D block_crypto_co_truncate, .create_opts =3D &block_crypto_create_opts_luks, =20 .bdrv_reopen_prepare =3D block_crypto_reopen_prepare, diff --git a/block/file-posix.c b/block/file-posix.c index 43b963b13e..53c5833659 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1878,8 +1878,8 @@ out: return result; } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, + PreallocMode prealloc, Error **err= p) { BDRVRawState *s =3D bs->opaque; struct stat st; @@ -2625,7 +2625,7 @@ BlockDriver bdrv_file =3D { .bdrv_io_unplug =3D raw_aio_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 - .bdrv_truncate =3D raw_truncate, + .bdrv_co_truncate =3D raw_co_truncate, .bdrv_getlength =3D raw_getlength, .bdrv_get_info =3D raw_get_info, .bdrv_get_allocated_file_size @@ -3105,7 +3105,7 @@ static BlockDriver bdrv_host_device =3D { .bdrv_io_plug =3D raw_aio_plug, .bdrv_io_unplug =3D raw_aio_unplug, =20 - .bdrv_truncate =3D raw_truncate, + .bdrv_co_truncate =3D raw_co_truncate, .bdrv_getlength =3D raw_getlength, .bdrv_get_info =3D raw_get_info, .bdrv_get_allocated_file_size @@ -3227,7 +3227,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_io_plug =3D raw_aio_plug, .bdrv_io_unplug =3D raw_aio_unplug, =20 - .bdrv_truncate =3D raw_truncate, + .bdrv_co_truncate =3D raw_co_truncate, .bdrv_getlength =3D raw_getlength, .has_variable_length =3D true, .bdrv_get_allocated_file_size @@ -3357,7 +3357,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_io_plug =3D raw_aio_plug, .bdrv_io_unplug =3D raw_aio_unplug, =20 - .bdrv_truncate =3D raw_truncate, + .bdrv_co_truncate =3D raw_co_truncate, .bdrv_getlength =3D raw_getlength, .has_variable_length =3D true, .bdrv_get_allocated_file_size diff --git a/block/file-win32.c b/block/file-win32.c index 3c67db4336..0411fe80fd 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -467,8 +467,8 @@ static void raw_close(BlockDriverState *bs) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, + PreallocMode prealloc, Error **err= p) { BDRVRawState *s =3D bs->opaque; LONG low, high; @@ -640,7 +640,7 @@ BlockDriver bdrv_file =3D { .bdrv_aio_pwritev =3D raw_aio_pwritev, .bdrv_aio_flush =3D raw_aio_flush, =20 - .bdrv_truncate =3D raw_truncate, + .bdrv_co_truncate =3D raw_co_truncate, .bdrv_getlength =3D raw_getlength, .bdrv_get_allocated_file_size =3D raw_get_allocated_file_size, diff --git a/block/gluster.c b/block/gluster.c index b5fe7f3e87..a4e1c8ecd8 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1177,8 +1177,10 @@ static coroutine_fn int qemu_gluster_co_rw(BlockDriv= erState *bs, return acb.ret; } =20 -static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static coroutine_fn int qemu_gluster_co_truncate(BlockDriverState *bs, + int64_t offset, + PreallocMode prealloc, + Error **errp) { BDRVGlusterState *s =3D bs->opaque; return qemu_gluster_do_truncate(s->fd, offset, prealloc, errp); @@ -1499,7 +1501,7 @@ static BlockDriver bdrv_gluster =3D { .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, - .bdrv_truncate =3D qemu_gluster_truncate, + .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, @@ -1528,7 +1530,7 @@ static BlockDriver bdrv_gluster_tcp =3D { .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, - .bdrv_truncate =3D qemu_gluster_truncate, + .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, @@ -1557,7 +1559,7 @@ static BlockDriver bdrv_gluster_unix =3D { .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, - .bdrv_truncate =3D qemu_gluster_truncate, + .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, @@ -1592,7 +1594,7 @@ static BlockDriver bdrv_gluster_rdma =3D { .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_getlength =3D qemu_gluster_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, - .bdrv_truncate =3D qemu_gluster_truncate, + .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, .bdrv_co_flush_to_disk =3D qemu_gluster_co_flush_to_disk, diff --git a/block/iscsi.c b/block/iscsi.c index 9f00fb47a5..bc84b14e20 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2085,8 +2085,8 @@ static void iscsi_reopen_commit(BDRVReopenState *reop= en_state) } } =20 -static int iscsi_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn iscsi_co_truncate(BlockDriverState *bs, int64_t of= fset, + PreallocMode prealloc, Error **e= rrp) { IscsiLun *iscsilun =3D bs->opaque; Error *local_err =3D NULL; @@ -2431,7 +2431,7 @@ static BlockDriver bdrv_iscsi =3D { =20 .bdrv_getlength =3D iscsi_getlength, .bdrv_get_info =3D iscsi_get_info, - .bdrv_truncate =3D iscsi_truncate, + .bdrv_co_truncate =3D iscsi_co_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, =20 .bdrv_co_block_status =3D iscsi_co_block_status, @@ -2468,7 +2468,7 @@ static BlockDriver bdrv_iser =3D { =20 .bdrv_getlength =3D iscsi_getlength, .bdrv_get_info =3D iscsi_get_info, - .bdrv_truncate =3D iscsi_truncate, + .bdrv_co_truncate =3D iscsi_co_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, =20 .bdrv_co_block_status =3D iscsi_co_block_status, diff --git a/block/nfs.c b/block/nfs.c index 743ca0450e..eab1a2c408 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -743,8 +743,9 @@ static int64_t nfs_get_allocated_file_size(BlockDriverS= tate *bs) return (task.ret < 0 ? task.ret : st.st_blocks * 512); } =20 -static int nfs_file_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn +nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { NFSClient *client =3D bs->opaque; int ret; @@ -873,7 +874,7 @@ static BlockDriver bdrv_nfs =3D { =20 .bdrv_has_zero_init =3D nfs_has_zero_init, .bdrv_get_allocated_file_size =3D nfs_get_allocated_file_size, - .bdrv_truncate =3D nfs_file_truncate, + .bdrv_co_truncate =3D nfs_file_co_truncate, =20 .bdrv_file_open =3D nfs_file_open, .bdrv_close =3D nfs_file_close, diff --git a/block/qcow2.c b/block/qcow2.c index 6b2e1e1058..9e0ccbbfaf 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2543,15 +2543,12 @@ static void coroutine_fn preallocate_co(void *opaqu= e) BlockDriverState *bs =3D params->bs; uint64_t offset =3D params->offset; uint64_t new_length =3D params->new_length; - BDRVQcow2State *s =3D bs->opaque; uint64_t bytes; uint64_t host_offset =3D 0; unsigned int cur_bytes; int ret; QCowL2Meta *meta; =20 - qemu_co_mutex_lock(&s->lock); - assert(offset <=3D new_length); bytes =3D new_length - offset; =20 @@ -2604,7 +2601,6 @@ static void coroutine_fn preallocate_co(void *opaque) ret =3D 0; =20 done: - qemu_co_mutex_unlock(&s->lock); params->ret =3D ret; } =20 @@ -3041,7 +3037,11 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) =20 /* And if we're supposed to preallocate metadata, do that now */ if (qcow2_opts->preallocation !=3D PREALLOC_MODE_OFF) { + BDRVQcow2State *s =3D blk_bs(blk)->opaque; + qemu_co_mutex_lock(&s->lock); ret =3D preallocate(blk_bs(blk), 0, qcow2_opts->size); + qemu_co_mutex_unlock(&s->lock); + if (ret < 0) { error_setg_errno(errp, -ret, "Could not preallocate metadata"); goto out; @@ -3437,8 +3437,8 @@ fail: return ret; } =20 -static int qcow2_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t of= fset, + PreallocMode prealloc, Error **e= rrp) { BDRVQcow2State *s =3D bs->opaque; uint64_t old_length; @@ -3458,17 +3458,21 @@ static int qcow2_truncate(BlockDriverState *bs, int= 64_t offset, return -EINVAL; } =20 + qemu_co_mutex_lock(&s->lock); + /* cannot proceed if image has snapshots */ if (s->nb_snapshots) { error_setg(errp, "Can't resize an image which has snapshots"); - return -ENOTSUP; + ret =3D -ENOTSUP; + goto fail; } =20 /* cannot proceed if image has bitmaps */ if (s->nb_bitmaps) { /* TODO: resize bitmaps in the image */ error_setg(errp, "Can't resize an image which has bitmaps"); - return -ENOTSUP; + ret =3D -ENOTSUP; + goto fail; } =20 old_length =3D bs->total_sectors * 512; @@ -3479,7 +3483,8 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Preallocation can't be used for shrinking an image= "); - return -EINVAL; + ret =3D -EINVAL; + goto fail; } =20 ret =3D qcow2_cluster_discard(bs, ROUND_UP(offset, s->cluster_size= ), @@ -3488,40 +3493,42 @@ static int qcow2_truncate(BlockDriverState *bs, int= 64_t offset, QCOW2_DISCARD_ALWAYS, true); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to discard cropped cluste= rs"); - return ret; + goto fail; } =20 ret =3D qcow2_shrink_l1_table(bs, new_l1_size); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to reduce the number of L2 tables"); - return ret; + goto fail; } =20 ret =3D qcow2_shrink_reftable(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to discard unused refblocks"); - return ret; + goto fail; } =20 old_file_size =3D bdrv_getlength(bs->file->bs); if (old_file_size < 0) { error_setg_errno(errp, -old_file_size, "Failed to inquire current file length"); - return old_file_size; + ret =3D old_file_size; + goto fail; } last_cluster =3D qcow2_get_last_cluster(bs, old_file_size); if (last_cluster < 0) { error_setg_errno(errp, -last_cluster, "Failed to find the last cluster"); - return last_cluster; + ret =3D last_cluster; + goto fail; } if ((last_cluster + 1) * s->cluster_size < old_file_size) { Error *local_err =3D NULL; =20 - bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size, - PREALLOC_MODE_OFF, &local_err); + bdrv_co_truncate(bs->file, (last_cluster + 1) * s->cluster_siz= e, + PREALLOC_MODE_OFF, &local_err); if (local_err) { warn_reportf_err(local_err, "Failed to truncate the tail of the image= : "); @@ -3531,7 +3538,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, ret =3D qcow2_grow_l1_table(bs, new_l1_size, true); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to grow the L1 table"); - return ret; + goto fail; } } =20 @@ -3543,7 +3550,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, ret =3D preallocate(bs, old_length, offset); if (ret < 0) { error_setg_errno(errp, -ret, "Preallocation failed"); - return ret; + goto fail; } break; =20 @@ -3559,7 +3566,8 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, if (old_file_size < 0) { error_setg_errno(errp, -old_file_size, "Failed to inquire current file length"); - return old_file_size; + ret =3D old_file_size; + goto fail; } old_file_size =3D ROUND_UP(old_file_size, s->cluster_size); =20 @@ -3589,7 +3597,8 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, if (allocation_start < 0) { error_setg_errno(errp, -allocation_start, "Failed to resize refcount structures"); - return allocation_start; + ret =3D allocation_start; + goto fail; } =20 clusters_allocated =3D qcow2_alloc_clusters_at(bs, allocation_star= t, @@ -3597,7 +3606,8 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, if (clusters_allocated < 0) { error_setg_errno(errp, -clusters_allocated, "Failed to allocate data clusters"); - return clusters_allocated; + ret =3D clusters_allocated; + goto fail; } =20 assert(clusters_allocated =3D=3D nb_new_data_clusters); @@ -3605,13 +3615,13 @@ static int qcow2_truncate(BlockDriverState *bs, int= 64_t offset, /* Allocate the data area */ new_file_size =3D allocation_start + nb_new_data_clusters * s->cluster_size; - ret =3D bdrv_truncate(bs->file, new_file_size, prealloc, errp); + ret =3D bdrv_co_truncate(bs->file, new_file_size, prealloc, errp); if (ret < 0) { error_prepend(errp, "Failed to resize underlying file: "); qcow2_free_clusters(bs, allocation_start, nb_new_data_clusters * s->cluster_size, QCOW2_DISCARD_OTHER); - return ret; + goto fail; } =20 /* Create the necessary L2 entries */ @@ -3634,7 +3644,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, qcow2_free_clusters(bs, host_offset, nb_new_data_clusters * s->cluster_size, QCOW2_DISCARD_OTHER); - return ret; + goto fail; } =20 guest_offset +=3D nb_clusters * s->cluster_size; @@ -3650,11 +3660,11 @@ static int qcow2_truncate(BlockDriverState *bs, int= 64_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { /* Flush metadata before actually changing the image size */ - ret =3D bdrv_flush(bs); + ret =3D qcow2_write_caches(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to flush the preallocated area to dis= k"); - return ret; + goto fail; } } =20 @@ -3664,11 +3674,14 @@ static int qcow2_truncate(BlockDriverState *bs, int= 64_t offset, &offset, sizeof(uint64_t)); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to update the image size"); - return ret; + goto fail; } =20 s->l1_vm_state_index =3D new_l1_size; - return 0; + ret =3D 0; +fail: + qemu_co_mutex_unlock(&s->lock); + return ret; } =20 /* XXX: put compressed sectors first, then all the cluster aligned @@ -3692,7 +3705,8 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, if (cluster_offset < 0) { return cluster_offset; } - return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, = NULL); + return bdrv_co_truncate(bs->file, cluster_offset, PREALLOC_MODE_OF= F, + NULL); } =20 if (offset_into_cluster(s, offset)) { @@ -4696,7 +4710,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_co_pdiscard =3D qcow2_co_pdiscard, .bdrv_co_copy_range_from =3D qcow2_co_copy_range_from, .bdrv_co_copy_range_to =3D qcow2_co_copy_range_to, - .bdrv_truncate =3D qcow2_truncate, + .bdrv_co_truncate =3D qcow2_co_truncate, .bdrv_co_pwritev_compressed =3D qcow2_co_pwritev_compressed, .bdrv_make_empty =3D qcow2_make_empty, =20 diff --git a/block/qed.c b/block/qed.c index 2363814538..689ea9d4d5 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1467,8 +1467,10 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Bl= ockDriverState *bs, QED_AIOCB_WRITE | QED_AIOCB_ZERO); } =20 -static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn bdrv_qed_co_truncate(BlockDriverState *bs, + int64_t offset, + PreallocMode prealloc, + Error **errp) { BDRVQEDState *s =3D bs->opaque; uint64_t old_image_size; @@ -1678,7 +1680,7 @@ static BlockDriver bdrv_qed =3D { .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_co_truncate =3D bdrv_qed_co_truncate, .bdrv_getlength =3D bdrv_qed_getlength, .bdrv_get_info =3D bdrv_qed_get_info, .bdrv_refresh_limits =3D bdrv_qed_refresh_limits, diff --git a/block/raw-format.c b/block/raw-format.c index f2e468df6f..b78da564d4 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -366,8 +366,8 @@ static void raw_refresh_limits(BlockDriverState *bs, Er= ror **errp) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, + PreallocMode prealloc, Error **err= p) { BDRVRawState *s =3D bs->opaque; =20 @@ -383,7 +383,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t o= ffset, =20 s->size =3D offset; offset +=3D s->offset; - return bdrv_truncate(bs->file, offset, prealloc, errp); + return bdrv_co_truncate(bs->file, offset, prealloc, errp); } =20 static void raw_eject(BlockDriverState *bs, bool eject_flag) @@ -545,7 +545,7 @@ BlockDriver bdrv_raw =3D { .bdrv_co_block_status =3D &raw_co_block_status, .bdrv_co_copy_range_from =3D &raw_co_copy_range_from, .bdrv_co_copy_range_to =3D &raw_co_copy_range_to, - .bdrv_truncate =3D &raw_truncate, + .bdrv_co_truncate =3D &raw_co_truncate, .bdrv_getlength =3D &raw_getlength, .has_variable_length =3D true, .bdrv_measure =3D &raw_measure, diff --git a/block/rbd.c b/block/rbd.c index f2c6965418..ca8e5bbace 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -990,8 +990,10 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs) return info.size; } =20 -static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs, + int64_t offset, + PreallocMode prealloc, + Error **errp) { BDRVRBDState *s =3D bs->opaque; int r; @@ -1184,7 +1186,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_get_info =3D qemu_rbd_getinfo, .create_opts =3D &qemu_rbd_create_opts, .bdrv_getlength =3D qemu_rbd_getlength, - .bdrv_truncate =3D qemu_rbd_truncate, + .bdrv_co_truncate =3D qemu_rbd_co_truncate, .protocol_name =3D "rbd", =20 .bdrv_aio_preadv =3D qemu_rbd_aio_preadv, diff --git a/block/sheepdog.c b/block/sheepdog.c index 665b1763eb..b229a664d9 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2292,8 +2292,8 @@ static int64_t sd_getlength(BlockDriverState *bs) return s->inode.vdi_size; } =20 -static int sd_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn sd_co_truncate(BlockDriverState *bs, int64_t offse= t, + PreallocMode prealloc, Error **errp) { BDRVSheepdogState *s =3D bs->opaque; int ret, fd; @@ -2609,7 +2609,7 @@ static coroutine_fn int sd_co_writev(BlockDriverState= *bs, int64_t sector_num, =20 assert(!flags); if (offset > s->inode.vdi_size) { - ret =3D sd_truncate(bs, offset, PREALLOC_MODE_OFF, NULL); + ret =3D sd_co_truncate(bs, offset, PREALLOC_MODE_OFF, NULL); if (ret < 0) { return ret; } @@ -3231,7 +3231,7 @@ static BlockDriver bdrv_sheepdog =3D { .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, - .bdrv_truncate =3D sd_truncate, + .bdrv_co_truncate =3D sd_co_truncate, =20 .bdrv_co_readv =3D sd_co_readv, .bdrv_co_writev =3D sd_co_writev, @@ -3268,7 +3268,7 @@ static BlockDriver bdrv_sheepdog_tcp =3D { .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, - .bdrv_truncate =3D sd_truncate, + .bdrv_co_truncate =3D sd_co_truncate, =20 .bdrv_co_readv =3D sd_co_readv, .bdrv_co_writev =3D sd_co_writev, @@ -3305,7 +3305,7 @@ static BlockDriver bdrv_sheepdog_unix =3D { .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, - .bdrv_truncate =3D sd_truncate, + .bdrv_co_truncate =3D sd_co_truncate, =20 .bdrv_co_readv =3D sd_co_readv, .bdrv_co_writev =3D sd_co_writev, diff --git a/block/ssh.c b/block/ssh.c index da7bbf73e2..7fbc27abdf 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1243,8 +1243,8 @@ static int64_t ssh_getlength(BlockDriverState *bs) return length; } =20 -static int ssh_truncate(BlockDriverState *bs, int64_t offset, - PreallocMode prealloc, Error **errp) +static int coroutine_fn ssh_co_truncate(BlockDriverState *bs, int64_t offs= et, + PreallocMode prealloc, Error **err= p) { BDRVSSHState *s =3D bs->opaque; =20 @@ -1279,7 +1279,7 @@ static BlockDriver bdrv_ssh =3D { .bdrv_co_readv =3D ssh_co_readv, .bdrv_co_writev =3D ssh_co_writev, .bdrv_getlength =3D ssh_getlength, - .bdrv_truncate =3D ssh_truncate, + .bdrv_co_truncate =3D ssh_co_truncate, .bdrv_co_flush_to_disk =3D ssh_co_flush, .create_opts =3D &ssh_create_opts, }; --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530281771518924.8981579467011; Fri, 29 Jun 2018 07:16:11 -0700 (PDT) Received: from localhost ([::1]:42484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuC2-0000Oj-84 for importer@patchew.org; Fri, 29 Jun 2018 10:16:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6R-0003ut-Tq for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6M-0003nQ-MB for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60240 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6G-0003d8-Lv; Fri, 29 Jun 2018 10:10:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F5057264E; Fri, 29 Jun 2018 14:10:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E93C1102E29; Fri, 29 Jun 2018 14:10:11 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:38 +0200 Message-Id: <20180629140959.6690-9-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 29 Jun 2018 14:10:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 29 Jun 2018 14:10:12 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 08/29] qcow2: Remove coroutine trampoline for preallocate_co() 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" All callers are coroutine_fns now, so we can just directly call preallocate_co(). Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qcow2.c | 51 ++++++++------------------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 9e0ccbbfaf..4a0d92860d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2521,15 +2521,6 @@ static int qcow2_set_up_encryption(BlockDriverState = *bs, return ret; } =20 - -typedef struct PreallocCo { - BlockDriverState *bs; - uint64_t offset; - uint64_t new_length; - - int ret; -} PreallocCo; - /** * Preallocates metadata structures for data clusters between @offset (in = the * guest disk) and @new_length (which is thus generally the new guest disk @@ -2537,12 +2528,9 @@ typedef struct PreallocCo { * * Returns: 0 on success, -errno on failure. */ -static void coroutine_fn preallocate_co(void *opaque) +static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offs= et, + uint64_t new_length) { - PreallocCo *params =3D opaque; - BlockDriverState *bs =3D params->bs; - uint64_t offset =3D params->offset; - uint64_t new_length =3D params->new_length; uint64_t bytes; uint64_t host_offset =3D 0; unsigned int cur_bytes; @@ -2557,7 +2545,7 @@ static void coroutine_fn preallocate_co(void *opaque) ret =3D qcow2_alloc_cluster_offset(bs, offset, &cur_bytes, &host_offset, &meta); if (ret < 0) { - goto done; + return ret; } =20 while (meta) { @@ -2567,7 +2555,7 @@ static void coroutine_fn preallocate_co(void *opaque) if (ret < 0) { qcow2_free_any_clusters(bs, meta->alloc_offset, meta->nb_clusters, QCOW2_DISCARD_N= EVER); - goto done; + return ret; } =20 /* There are no dependent requests, but we need to remove our @@ -2594,34 +2582,11 @@ static void coroutine_fn preallocate_co(void *opaqu= e) ret =3D bdrv_pwrite(bs->file, (host_offset + cur_bytes) - 1, &data, 1); if (ret < 0) { - goto done; + return ret; } } =20 - ret =3D 0; - -done: - params->ret =3D ret; -} - -static int preallocate(BlockDriverState *bs, - uint64_t offset, uint64_t new_length) -{ - PreallocCo params =3D { - .bs =3D bs, - .offset =3D offset, - .new_length =3D new_length, - .ret =3D -EINPROGRESS, - }; - - if (qemu_in_coroutine()) { - preallocate_co(¶ms); - } else { - Coroutine *co =3D qemu_coroutine_create(preallocate_co, ¶ms); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, params.ret =3D=3D -EINPROGRESS); - } - return params.ret; + return 0; } =20 /* qcow2_refcount_metadata_size: @@ -3039,7 +3004,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) if (qcow2_opts->preallocation !=3D PREALLOC_MODE_OFF) { BDRVQcow2State *s =3D blk_bs(blk)->opaque; qemu_co_mutex_lock(&s->lock); - ret =3D preallocate(blk_bs(blk), 0, qcow2_opts->size); + ret =3D preallocate_co(blk_bs(blk), 0, qcow2_opts->size); qemu_co_mutex_unlock(&s->lock); =20 if (ret < 0) { @@ -3547,7 +3512,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriver= State *bs, int64_t offset, break; =20 case PREALLOC_MODE_METADATA: - ret =3D preallocate(bs, old_length, offset); + ret =3D preallocate_co(bs, old_length, offset); if (ret < 0) { error_setg_errno(errp, -ret, "Preallocation failed"); goto fail; --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15302819760721022.774478262899; Fri, 29 Jun 2018 07:19:36 -0700 (PDT) Received: from localhost ([::1]:42498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuFL-00031L-7d for importer@patchew.org; Fri, 29 Jun 2018 10:19:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6R-0003uy-Uu for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6P-0003tT-KB for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44848 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6H-0003ek-LP; Fri, 29 Jun 2018 10:10:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57EBCC12C9; Fri, 29 Jun 2018 14:10:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 888891102E29; Fri, 29 Jun 2018 14:10:12 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:39 +0200 Message-Id: <20180629140959.6690-10-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:13 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 09/29] block: Move bdrv_truncate() implementation to io.c 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This moves the bdrv_truncate() implementation from block.c to block/io.c so it can have access to the tracked requests infrastructure. This involves making refresh_total_sectors() public (in block_int.h). Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 2 + block.c | 111 +-----------------------------------------= ---- block/io.c | 109 ++++++++++++++++++++++++++++++++++++++++++= +++ 3 files changed, 112 insertions(+), 110 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index c653ee663a..740166a996 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1157,4 +1157,6 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, BdrvRequestFlags fl= ags); =20 +int refresh_total_sectors(BlockDriverState *bs, int64_t hint); + #endif /* BLOCK_INT_H */ diff --git a/block.c b/block.c index f761bc85d5..70a46fdd84 100644 --- a/block.c +++ b/block.c @@ -725,7 +725,7 @@ static int find_image_format(BlockBackend *file, const = char *filename, * Set the current 'total_sectors' value * Return 0 on success, -errno on error. */ -static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) +int refresh_total_sectors(BlockDriverState *bs, int64_t hint) { BlockDriver *drv =3D bs->drv; =20 @@ -2226,16 +2226,6 @@ static void bdrv_parent_cb_change_media(BlockDriverS= tate *bs, bool load) } } =20 -static void bdrv_parent_cb_resize(BlockDriverState *bs) -{ - BdrvChild *c; - QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c->role->resize) { - c->role->resize(c); - } - } -} - /* * Sets the backing file link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref(). @@ -3786,105 +3776,6 @@ exit: } =20 /** - * Truncate file to 'offset' bytes (needed only for file protocols) - */ -int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, - PreallocMode prealloc, Error **errp) -{ - BlockDriverState *bs =3D child->bs; - BlockDriver *drv =3D bs->drv; - int ret; - - assert(child->perm & BLK_PERM_RESIZE); - - /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ - if (!drv) { - error_setg(errp, "No medium inserted"); - return -ENOMEDIUM; - } - if (offset < 0) { - error_setg(errp, "Image size cannot be negative"); - return -EINVAL; - } - - bdrv_inc_in_flight(bs); - - if (!drv->bdrv_co_truncate) { - if (bs->file && drv->is_filter) { - ret =3D bdrv_co_truncate(bs->file, offset, prealloc, errp); - goto out; - } - error_setg(errp, "Image format driver does not support resize"); - ret =3D -ENOTSUP; - goto out; - } - if (bs->read_only) { - error_setg(errp, "Image is read-only"); - ret =3D -EACCES; - goto out; - } - - assert(!(bs->open_flags & BDRV_O_INACTIVE)); - - ret =3D drv->bdrv_co_truncate(bs, offset, prealloc, errp); - if (ret < 0) { - goto out; - } - ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); - if (ret < 0) { - error_setg_errno(errp, -ret, "Could not refresh total sector count= "); - } else { - offset =3D bs->total_sectors * BDRV_SECTOR_SIZE; - } - bdrv_dirty_bitmap_truncate(bs, offset); - bdrv_parent_cb_resize(bs); - atomic_inc(&bs->write_gen); - -out: - bdrv_dec_in_flight(bs); - return ret; -} - -typedef struct TruncateCo { - BdrvChild *child; - int64_t offset; - PreallocMode prealloc; - Error **errp; - int ret; -} TruncateCo; - -static void coroutine_fn bdrv_truncate_co_entry(void *opaque) -{ - TruncateCo *tco =3D opaque; - tco->ret =3D bdrv_co_truncate(tco->child, tco->offset, tco->prealloc, - tco->errp); -} - -int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, - Error **errp) -{ - Coroutine *co; - TruncateCo tco =3D { - .child =3D child, - .offset =3D offset, - .prealloc =3D prealloc, - .errp =3D errp, - .ret =3D NOT_DONE, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_truncate_co_entry(&tco); - } else { - co =3D qemu_coroutine_create(bdrv_truncate_co_entry, &tco); - qemu_coroutine_enter(co); - BDRV_POLL_WHILE(child->bs, tco.ret =3D=3D NOT_DONE); - } - - return tco.ret; -} - -/** * Length of a allocated file in bytes. Sparse files are counted by actual * allocated space. Return < 0 if error or unknown. */ diff --git a/block/io.c b/block/io.c index ef4fedd364..7e87a42b8e 100644 --- a/block/io.c +++ b/block/io.c @@ -3020,3 +3020,112 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src,= uint64_t src_offset, bdrv_dec_in_flight(dst_bs); return ret; } + +static void bdrv_parent_cb_resize(BlockDriverState *bs) +{ + BdrvChild *c; + QLIST_FOREACH(c, &bs->parents, next_parent) { + if (c->role->resize) { + c->role->resize(c); + } + } +} + +/** + * Truncate file to 'offset' bytes (needed only for file protocols) + */ +int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, + PreallocMode prealloc, Error **errp) +{ + BlockDriverState *bs =3D child->bs; + BlockDriver *drv =3D bs->drv; + int ret; + + assert(child->perm & BLK_PERM_RESIZE); + + /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ + if (!drv) { + error_setg(errp, "No medium inserted"); + return -ENOMEDIUM; + } + if (offset < 0) { + error_setg(errp, "Image size cannot be negative"); + return -EINVAL; + } + + bdrv_inc_in_flight(bs); + + if (!drv->bdrv_co_truncate) { + if (bs->file && drv->is_filter) { + ret =3D bdrv_co_truncate(bs->file, offset, prealloc, errp); + goto out; + } + error_setg(errp, "Image format driver does not support resize"); + ret =3D -ENOTSUP; + goto out; + } + if (bs->read_only) { + error_setg(errp, "Image is read-only"); + ret =3D -EACCES; + goto out; + } + + assert(!(bs->open_flags & BDRV_O_INACTIVE)); + + ret =3D drv->bdrv_co_truncate(bs, offset, prealloc, errp); + if (ret < 0) { + goto out; + } + ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not refresh total sector count= "); + } else { + offset =3D bs->total_sectors * BDRV_SECTOR_SIZE; + } + bdrv_dirty_bitmap_truncate(bs, offset); + bdrv_parent_cb_resize(bs); + atomic_inc(&bs->write_gen); + +out: + bdrv_dec_in_flight(bs); + return ret; +} + +typedef struct TruncateCo { + BdrvChild *child; + int64_t offset; + PreallocMode prealloc; + Error **errp; + int ret; +} TruncateCo; + +static void coroutine_fn bdrv_truncate_co_entry(void *opaque) +{ + TruncateCo *tco =3D opaque; + tco->ret =3D bdrv_co_truncate(tco->child, tco->offset, tco->prealloc, + tco->errp); +} + +int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, + Error **errp) +{ + Coroutine *co; + TruncateCo tco =3D { + .child =3D child, + .offset =3D offset, + .prealloc =3D prealloc, + .errp =3D errp, + .ret =3D NOT_DONE, + }; + + if (qemu_in_coroutine()) { + /* Fast-path if already in coroutine context */ + bdrv_truncate_co_entry(&tco); + } else { + co =3D qemu_coroutine_create(bdrv_truncate_co_entry, &tco); + qemu_coroutine_enter(co); + BDRV_POLL_WHILE(child->bs, tco.ret =3D=3D NOT_DONE); + } + + return tco.ret; +} --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530281834744639.3875772435426; Fri, 29 Jun 2018 07:17:14 -0700 (PDT) Received: from localhost ([::1]:42487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuD3-0001Pg-Vt for importer@patchew.org; Fri, 29 Jun 2018 10:17:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6Q-0003ss-5e for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6O-0003rL-H6 for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51346 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6J-0003gP-1y; Fri, 29 Jun 2018 10:10:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6642C401EF1D; Fri, 29 Jun 2018 14:10:14 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92A021102E29; Fri, 29 Jun 2018 14:10:13 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:40 +0200 Message-Id: <20180629140959.6690-11-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:14 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 10/29] block: Use tracked request for truncate 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When growing an image, block drivers (especially protocol drivers) may initialise the newly added area. I/O requests to the same area need to wait for this initialisation to be completed so that data writes don't get overwritten and reads don't read uninitialised data. To avoid overhead in the fast I/O path by adding new locking in the protocol drivers and to restrict the impact to requests that actually touch the new area, reuse the existing tracked request infrastructure in block/io.c and mark all discard requests as serialising. With this change, it is safe for protocol drivers to make .bdrv_co_truncate actually asynchronous. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 1 + block/io.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 740166a996..af71b414be 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -63,6 +63,7 @@ enum BdrvTrackedRequestType { BDRV_TRACKED_READ, BDRV_TRACKED_WRITE, BDRV_TRACKED_DISCARD, + BDRV_TRACKED_TRUNCATE, }; =20 typedef struct BdrvTrackedRequest { diff --git a/block/io.c b/block/io.c index 7e87a42b8e..01a3c4eac5 100644 --- a/block/io.c +++ b/block/io.c @@ -3039,6 +3039,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; + BdrvTrackedRequest req; + int64_t old_size, new_bytes; int ret; =20 assert(child->perm & BLK_PERM_RESIZE); @@ -3053,7 +3055,28 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, return -EINVAL; } =20 + old_size =3D bdrv_getlength(bs); + if (old_size < 0) { + error_setg_errno(errp, -old_size, "Failed to get old image size"); + return old_size; + } + + if (offset > old_size) { + new_bytes =3D offset - old_size; + } else { + new_bytes =3D 0; + } + bdrv_inc_in_flight(bs); + tracked_request_begin(&req, bs, offset, new_bytes, BDRV_TRACKED_TRUNCA= TE); + + /* If we are growing the image and potentially using preallocation for= the + * new area, we need to make sure that no write requests are made to it + * concurrently or they might be overwritten by preallocation. */ + if (new_bytes) { + mark_request_serialising(&req, 1); + wait_serialising_requests(&req); + } =20 if (!drv->bdrv_co_truncate) { if (bs->file && drv->is_filter) { @@ -3087,7 +3110,9 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, atomic_inc(&bs->write_gen); =20 out: + tracked_request_end(&req); bdrv_dec_in_flight(bs); + return ret; } =20 --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282367005512.5286349223891; Fri, 29 Jun 2018 07:26:07 -0700 (PDT) Received: from localhost ([::1]:42547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuLW-0008Rn-RC for importer@patchew.org; Fri, 29 Jun 2018 10:25:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6S-0003v8-0A for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6P-0003tO-Kb for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44852 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6J-0003i8-Pl; Fri, 29 Jun 2018 10:10:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 734F8C12C9; Fri, 29 Jun 2018 14:10:15 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id A142E1102E29; Fri, 29 Jun 2018 14:10:14 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:41 +0200 Message-Id: <20180629140959.6690-12-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:15 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 11/29] file-posix: Make .bdrv_co_truncate asynchronous 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This moves the code to resize an image file to the thread pool to avoid blocking. Creating large images with preallocation with blockdev-create is now actually a background job instead of blocking the monitor (and most other things) until the preallocation has completed. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- include/block/raw-aio.h | 4 +- block/file-posix.c | 266 +++++++++++++++++++++++++++-----------------= ---- 2 files changed, 154 insertions(+), 116 deletions(-) diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index 8d698ccd31..6799614e56 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -26,6 +26,7 @@ #define QEMU_AIO_DISCARD 0x0010 #define QEMU_AIO_WRITE_ZEROES 0x0020 #define QEMU_AIO_COPY_RANGE 0x0040 +#define QEMU_AIO_TRUNCATE 0x0080 #define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \ @@ -33,7 +34,8 @@ QEMU_AIO_FLUSH | \ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ - QEMU_AIO_COPY_RANGE) + QEMU_AIO_COPY_RANGE | \ + QEMU_AIO_TRUNCATE) =20 /* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000 diff --git a/block/file-posix.c b/block/file-posix.c index 53c5833659..639265d53b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -188,8 +188,16 @@ typedef struct RawPosixAIOData { #define aio_ioctl_cmd aio_nbytes /* for QEMU_AIO_IOCTL */ off_t aio_offset; int aio_type; - int aio_fd2; - off_t aio_offset2; + union { + struct { + int aio_fd2; + off_t aio_offset2; + }; + struct { + PreallocMode prealloc; + Error **errp; + }; + }; } RawPosixAIOData; =20 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -1539,6 +1547,122 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData= *aiocb) return ret; } =20 +static int handle_aiocb_truncate(RawPosixAIOData *aiocb) +{ + int result =3D 0; + int64_t current_length =3D 0; + char *buf =3D NULL; + struct stat st; + int fd =3D aiocb->aio_fildes; + int64_t offset =3D aiocb->aio_offset; + Error **errp =3D aiocb->errp; + + if (fstat(fd, &st) < 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not stat file"); + return result; + } + + current_length =3D st.st_size; + if (current_length > offset && aiocb->prealloc !=3D PREALLOC_MODE_OFF)= { + error_setg(errp, "Cannot use preallocation for shrinking files"); + return -ENOTSUP; + } + + switch (aiocb->prealloc) { +#ifdef CONFIG_POSIX_FALLOCATE + case PREALLOC_MODE_FALLOC: + /* + * Truncating before posix_fallocate() makes it about twice slower= on + * file systems that do not support fallocate(), trying to check i= f a + * block is allocated before allocating it, so don't do that here. + */ + if (offset !=3D current_length) { + result =3D -posix_fallocate(fd, current_length, + offset - current_length); + if (result !=3D 0) { + /* posix_fallocate() doesn't set errno. */ + error_setg_errno(errp, -result, + "Could not preallocate new data"); + } + } else { + result =3D 0; + } + goto out; +#endif + case PREALLOC_MODE_FULL: + { + int64_t num =3D 0, left =3D offset - current_length; + off_t seek_result; + + /* + * Knowing the final size from the beginning could allow the file + * system driver to do less allocations and possibly avoid + * fragmentation of the file. + */ + if (ftruncate(fd, offset) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + goto out; + } + + buf =3D g_malloc0(65536); + + seek_result =3D lseek(fd, current_length, SEEK_SET); + if (seek_result < 0) { + result =3D -errno; + error_setg_errno(errp, -result, + "Failed to seek to the old end of file"); + goto out; + } + + while (left > 0) { + num =3D MIN(left, 65536); + result =3D write(fd, buf, num); + if (result < 0) { + result =3D -errno; + error_setg_errno(errp, -result, + "Could not write zeros for preallocation"= ); + goto out; + } + left -=3D result; + } + if (result >=3D 0) { + result =3D fsync(fd); + if (result < 0) { + result =3D -errno; + error_setg_errno(errp, -result, + "Could not flush file to disk"); + goto out; + } + } + goto out; + } + case PREALLOC_MODE_OFF: + if (ftruncate(fd, offset) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + } + return result; + default: + result =3D -ENOTSUP; + error_setg(errp, "Unsupported preallocation mode: %s", + PreallocMode_str(aiocb->prealloc)); + return result; + } + +out: + if (result < 0) { + if (ftruncate(fd, current_length) < 0) { + error_report("Failed to restore old file length: %s", + strerror(errno)); + } + } + + g_free(buf); + return result; +} + static int aio_worker(void *arg) { RawPosixAIOData *aiocb =3D arg; @@ -1582,6 +1706,9 @@ static int aio_worker(void *arg) case QEMU_AIO_COPY_RANGE: ret =3D handle_aiocb_copy_range(aiocb); break; + case QEMU_AIO_TRUNCATE: + ret =3D handle_aiocb_truncate(aiocb); + break; default: fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type); ret =3D -EINVAL; @@ -1765,117 +1892,25 @@ static void raw_close(BlockDriverState *bs) * * Returns: 0 on success, -errno on failure. */ -static int raw_regular_truncate(int fd, int64_t offset, PreallocMode preal= loc, - Error **errp) +static int coroutine_fn +raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, + PreallocMode prealloc, Error **errp) { - int result =3D 0; - int64_t current_length =3D 0; - char *buf =3D NULL; - struct stat st; - - if (fstat(fd, &st) < 0) { - result =3D -errno; - error_setg_errno(errp, -result, "Could not stat file"); - return result; - } - - current_length =3D st.st_size; - if (current_length > offset && prealloc !=3D PREALLOC_MODE_OFF) { - error_setg(errp, "Cannot use preallocation for shrinking files"); - return -ENOTSUP; - } - - switch (prealloc) { -#ifdef CONFIG_POSIX_FALLOCATE - case PREALLOC_MODE_FALLOC: - /* - * Truncating before posix_fallocate() makes it about twice slower= on - * file systems that do not support fallocate(), trying to check i= f a - * block is allocated before allocating it, so don't do that here. - */ - if (offset !=3D current_length) { - result =3D -posix_fallocate(fd, current_length, offset - curre= nt_length); - if (result !=3D 0) { - /* posix_fallocate() doesn't set errno. */ - error_setg_errno(errp, -result, - "Could not preallocate new data"); - } - } else { - result =3D 0; - } - goto out; -#endif - case PREALLOC_MODE_FULL: - { - int64_t num =3D 0, left =3D offset - current_length; - off_t seek_result; - - /* - * Knowing the final size from the beginning could allow the file - * system driver to do less allocations and possibly avoid - * fragmentation of the file. - */ - if (ftruncate(fd, offset) !=3D 0) { - result =3D -errno; - error_setg_errno(errp, -result, "Could not resize file"); - goto out; - } - - buf =3D g_malloc0(65536); - - seek_result =3D lseek(fd, current_length, SEEK_SET); - if (seek_result < 0) { - result =3D -errno; - error_setg_errno(errp, -result, - "Failed to seek to the old end of file"); - goto out; - } - - while (left > 0) { - num =3D MIN(left, 65536); - result =3D write(fd, buf, num); - if (result < 0) { - result =3D -errno; - error_setg_errno(errp, -result, - "Could not write zeros for preallocation"= ); - goto out; - } - left -=3D result; - } - if (result >=3D 0) { - result =3D fsync(fd); - if (result < 0) { - result =3D -errno; - error_setg_errno(errp, -result, - "Could not flush file to disk"); - goto out; - } - } - goto out; - } - case PREALLOC_MODE_OFF: - if (ftruncate(fd, offset) !=3D 0) { - result =3D -errno; - error_setg_errno(errp, -result, "Could not resize file"); - } - return result; - default: - result =3D -ENOTSUP; - error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_str(prealloc)); - return result; - } + RawPosixAIOData *acb =3D g_new(RawPosixAIOData, 1); + ThreadPool *pool; =20 -out: - if (result < 0) { - if (ftruncate(fd, current_length) < 0) { - error_report("Failed to restore old file length: %s", - strerror(errno)); - } - } + *acb =3D (RawPosixAIOData) { + .bs =3D bs, + .aio_fildes =3D fd, + .aio_type =3D QEMU_AIO_TRUNCATE, + .aio_offset =3D offset, + .prealloc =3D prealloc, + .errp =3D errp, + }; =20 - g_free(buf); - return result; + /* @bs can be NULL, bdrv_get_aio_context() returns the main context th= en */ + pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); + return thread_pool_submit_co(pool, aio_worker, acb); } =20 static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, @@ -1892,7 +1927,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverSt= ate *bs, int64_t offset, } =20 if (S_ISREG(st.st_mode)) { - return raw_regular_truncate(s->fd, offset, prealloc, errp); + return raw_regular_truncate(bs, s->fd, offset, prealloc, errp); } =20 if (prealloc !=3D PREALLOC_MODE_OFF) { @@ -2094,7 +2129,8 @@ static int64_t raw_get_allocated_file_size(BlockDrive= rState *bs) return (int64_t)st.st_blocks * 512; } =20 -static int raw_co_create(BlockdevCreateOptions *options, Error **errp) +static int coroutine_fn +raw_co_create(BlockdevCreateOptions *options, Error **errp) { BlockdevCreateOptionsFile *file_opts; int fd; @@ -2146,7 +2182,7 @@ static int raw_co_create(BlockdevCreateOptions *optio= ns, Error **errp) } =20 /* Clear the file by truncating it to 0 */ - result =3D raw_regular_truncate(fd, 0, PREALLOC_MODE_OFF, errp); + result =3D raw_regular_truncate(NULL, fd, 0, PREALLOC_MODE_OFF, errp); if (result < 0) { goto out_close; } @@ -2168,8 +2204,8 @@ static int raw_co_create(BlockdevCreateOptions *optio= ns, Error **errp) =20 /* Resize and potentially preallocate the file to the desired * final size */ - result =3D raw_regular_truncate(fd, file_opts->size, file_opts->preall= ocation, - errp); + result =3D raw_regular_truncate(NULL, fd, file_opts->size, + file_opts->preallocation, errp); if (result < 0) { goto out_close; } --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530281949402703.4133112889679; Fri, 29 Jun 2018 07:19:09 -0700 (PDT) Received: from localhost ([::1]:42497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuEq-0002iD-J9 for importer@patchew.org; Fri, 29 Jun 2018 10:19:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6Q-0003sp-4d for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6O-0003r9-Dx for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51350 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6K-0003jn-Qz; Fri, 29 Jun 2018 10:10:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CF9840583DD; Fri, 29 Jun 2018 14:10:16 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD2311102E29; Fri, 29 Jun 2018 14:10:15 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:42 +0200 Message-Id: <20180629140959.6690-13-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:16 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 12/29] qcow2: Remove dead check on !ret 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng In the beginning of the function, we initialize the local variable to 0, and in the body of the function, we check the assigned values and exit the loop immediately. So here it can never be non-zero. Reported-by: Kevin Wolf Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Kevin Wolf --- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 4a0d92860d..2d190aa00b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1772,7 +1772,7 @@ static coroutine_fn int qcow2_handle_l2meta(BlockDriv= erState *bs, while (l2meta !=3D NULL) { QCowL2Meta *next; =20 - if (!ret && link_l2) { + if (link_l2) { ret =3D qcow2_alloc_cluster_link_l2(bs, l2meta); if (ret) { goto out; --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282241709164.30034886895123; Fri, 29 Jun 2018 07:24:01 -0700 (PDT) Received: from localhost ([::1]:42528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuJd-0006rs-1I for importer@patchew.org; Fri, 29 Jun 2018 10:24:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6S-0003vA-0C for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Q-0003ue-5N for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44858 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6L-0003lv-T3; Fri, 29 Jun 2018 10:10:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87A0AC12C9; Fri, 29 Jun 2018 14:10:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id B864E1102E29; Fri, 29 Jun 2018 14:10:16 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:43 +0200 Message-Id: <20180629140959.6690-14-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:17 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 13/29] block: Move request tracking to children in copy offloading 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng in_flight and tracked requests need to be tracked in every layer during recursion. For now the only user is qemu-img convert where overlapping requests and IOThreads don't exist, therefore this change doesn't make much difference form user point of view, but it is incorrect as part of the API. Fix it. Reported-by: Kevin Wolf Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/io.c | 59 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/block/io.c b/block/io.c index 01a3c4eac5..b63822280a 100644 --- a/block/io.c +++ b/block/io.c @@ -2932,6 +2932,9 @@ static int coroutine_fn bdrv_co_copy_range_internal(B= drvChild *src, BdrvRequestFlags flags, bool recurse_src) { + BdrvTrackedRequest src_req, dst_req; + BlockDriverState *src_bs =3D src->bs; + BlockDriverState *dst_bs =3D dst->bs; int ret; =20 if (!src || !dst || !src->bs || !dst->bs) { @@ -2955,17 +2958,31 @@ static int coroutine_fn bdrv_co_copy_range_internal= (BdrvChild *src, || src->bs->encrypted || dst->bs->encrypted) { return -ENOTSUP; } + bdrv_inc_in_flight(src_bs); + bdrv_inc_in_flight(dst_bs); + tracked_request_begin(&src_req, src_bs, src_offset, + bytes, BDRV_TRACKED_READ); + tracked_request_begin(&dst_req, dst_bs, dst_offset, + bytes, BDRV_TRACKED_WRITE); + + wait_serialising_requests(&src_req); + wait_serialising_requests(&dst_req); if (recurse_src) { - return src->bs->drv->bdrv_co_copy_range_from(src->bs, - src, src_offset, - dst, dst_offset, - bytes, flags); + ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, + src, src_offset, + dst, dst_offset, + bytes, flags); } else { - return dst->bs->drv->bdrv_co_copy_range_to(dst->bs, - src, src_offset, - dst, dst_offset, - bytes, flags); + ret =3D dst->bs->drv->bdrv_co_copy_range_to(dst->bs, + src, src_offset, + dst, dst_offset, + bytes, flags); } + tracked_request_end(&src_req); + tracked_request_end(&dst_req); + bdrv_dec_in_flight(src_bs); + bdrv_dec_in_flight(dst_bs); + return ret; } =20 /* Copy range from @src to @dst. @@ -2996,29 +3013,9 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, = uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, BdrvRequestFlags flags) { - BdrvTrackedRequest src_req, dst_req; - BlockDriverState *src_bs =3D src->bs; - BlockDriverState *dst_bs =3D dst->bs; - int ret; - - bdrv_inc_in_flight(src_bs); - bdrv_inc_in_flight(dst_bs); - tracked_request_begin(&src_req, src_bs, src_offset, - bytes, BDRV_TRACKED_READ); - tracked_request_begin(&dst_req, dst_bs, dst_offset, - bytes, BDRV_TRACKED_WRITE); - - wait_serialising_requests(&src_req); - wait_serialising_requests(&dst_req); - ret =3D bdrv_co_copy_range_from(src, src_offset, - dst, dst_offset, - bytes, flags); - - tracked_request_end(&src_req); - tracked_request_end(&dst_req); - bdrv_dec_in_flight(src_bs); - bdrv_dec_in_flight(dst_bs); - return ret; + return bdrv_co_copy_range_from(src, src_offset, + dst, dst_offset, + bytes, flags); } =20 static void bdrv_parent_cb_resize(BlockDriverState *bs) --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282411054976.5688854783562; Fri, 29 Jun 2018 07:26:51 -0700 (PDT) Received: from localhost ([::1]:42549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuMM-0000gS-7G for importer@patchew.org; Fri, 29 Jun 2018 10:26:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49657) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6X-0003yr-7b for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6S-0003zI-OD for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51354 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6M-0003nZ-Vm; Fri, 29 Jun 2018 10:10:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90FEE40583DD; Fri, 29 Jun 2018 14:10:18 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2AF11102E29; Fri, 29 Jun 2018 14:10:17 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:44 +0200 Message-Id: <20180629140959.6690-15-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:18 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 14/29] block/crypto: Simplify block_crypto_{open, create}_opts_init() 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster block_crypto_open_opts_init() and block_crypto_create_opts_init() contain a virtual visit of QCryptoBlockOptions and QCryptoBlockCreateOptions less member "format", respectively. Change their callers to put member "format" in the QDict, so they can use the generated visitors for these types instead. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/crypto.h | 8 ++--- block/crypto.c | 99 +++++++++---------------------------------------------= ---- block/qcow.c | 5 ++- block/qcow2.c | 10 +++--- 4 files changed, 22 insertions(+), 100 deletions(-) diff --git a/block/crypto.h b/block/crypto.h index 0f985ea4e2..dd7d47903c 100644 --- a/block/crypto.h +++ b/block/crypto.h @@ -89,13 +89,9 @@ } =20 QCryptoBlockCreateOptions * -block_crypto_create_opts_init(QCryptoBlockFormat format, - QDict *opts, - Error **errp); +block_crypto_create_opts_init(QDict *opts, Error **errp); =20 QCryptoBlockOpenOptions * -block_crypto_open_opts_init(QCryptoBlockFormat format, - QDict *opts, - Error **errp); +block_crypto_open_opts_init(QDict *opts, Error **errp); =20 #endif /* BLOCK_CRYPTO_H__ */ diff --git a/block/crypto.c b/block/crypto.c index 210c80d5c7..994172a3de 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -148,108 +148,36 @@ static QemuOptsList block_crypto_create_opts_luks = =3D { =20 =20 QCryptoBlockOpenOptions * -block_crypto_open_opts_init(QCryptoBlockFormat format, - QDict *opts, - Error **errp) +block_crypto_open_opts_init(QDict *opts, Error **errp) { Visitor *v; - QCryptoBlockOpenOptions *ret =3D NULL; - Error *local_err =3D NULL; - - ret =3D g_new0(QCryptoBlockOpenOptions, 1); - ret->format =3D format; + QCryptoBlockOpenOptions *ret; =20 - v =3D qobject_input_visitor_new_flat_confused(opts, &local_err); + v =3D qobject_input_visitor_new_flat_confused(opts, errp); if (!v) { - goto out; - } - - visit_start_struct(v, NULL, NULL, 0, &local_err); - if (local_err) { - goto out; - } - - switch (format) { - case Q_CRYPTO_BLOCK_FORMAT_LUKS: - visit_type_QCryptoBlockOptionsLUKS_members( - v, &ret->u.luks, &local_err); - break; - - case Q_CRYPTO_BLOCK_FORMAT_QCOW: - visit_type_QCryptoBlockOptionsQCow_members( - v, &ret->u.qcow, &local_err); - break; - - default: - error_setg(&local_err, "Unsupported block format %d", format); - break; - } - if (!local_err) { - visit_check_struct(v, &local_err); + return NULL; } =20 - visit_end_struct(v, NULL); + visit_type_QCryptoBlockOpenOptions(v, NULL, &ret, errp); =20 - out: - if (local_err) { - error_propagate(errp, local_err); - qapi_free_QCryptoBlockOpenOptions(ret); - ret =3D NULL; - } visit_free(v); return ret; } =20 =20 QCryptoBlockCreateOptions * -block_crypto_create_opts_init(QCryptoBlockFormat format, - QDict *opts, - Error **errp) +block_crypto_create_opts_init(QDict *opts, Error **errp) { Visitor *v; - QCryptoBlockCreateOptions *ret =3D NULL; - Error *local_err =3D NULL; - - ret =3D g_new0(QCryptoBlockCreateOptions, 1); - ret->format =3D format; + QCryptoBlockCreateOptions *ret; =20 - v =3D qobject_input_visitor_new_flat_confused(opts, &local_err); + v =3D qobject_input_visitor_new_flat_confused(opts, errp); if (!v) { - goto out; - } - - visit_start_struct(v, NULL, NULL, 0, &local_err); - if (local_err) { - goto out; - } - - switch (format) { - case Q_CRYPTO_BLOCK_FORMAT_LUKS: - visit_type_QCryptoBlockCreateOptionsLUKS_members( - v, &ret->u.luks, &local_err); - break; - - case Q_CRYPTO_BLOCK_FORMAT_QCOW: - visit_type_QCryptoBlockOptionsQCow_members( - v, &ret->u.qcow, &local_err); - break; - - default: - error_setg(&local_err, "Unsupported block format %d", format); - break; - } - if (!local_err) { - visit_check_struct(v, &local_err); + return NULL; } =20 - visit_end_struct(v, NULL); + visit_type_QCryptoBlockCreateOptions(v, NULL, &ret, errp); =20 - out: - if (local_err) { - error_propagate(errp, local_err); - qapi_free_QCryptoBlockCreateOptions(ret); - ret =3D NULL; - } visit_free(v); return ret; } @@ -287,8 +215,9 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, } =20 cryptoopts =3D qemu_opts_to_qdict(opts, NULL); + qdict_put_str(cryptoopts, "format", QCryptoBlockFormat_str(format)); =20 - open_opts =3D block_crypto_open_opts_init(format, cryptoopts, errp); + open_opts =3D block_crypto_open_opts_init(cryptoopts, errp); if (!open_opts) { goto cleanup; } @@ -612,8 +541,8 @@ static int coroutine_fn block_crypto_co_create_opts_luk= s(const char *filename, &block_crypto_create_opts_luk= s, true); =20 - create_opts =3D block_crypto_create_opts_init(Q_CRYPTO_BLOCK_FORMAT_LU= KS, - cryptoopts, errp); + qdict_put_str(cryptoopts, "format", "luks"); + create_opts =3D block_crypto_create_opts_init(cryptoopts, errp); if (!create_opts) { ret =3D -EINVAL; goto fail; diff --git a/block/qcow.c b/block/qcow.c index 5532731b9f..8546fe5bb7 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -203,9 +203,8 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, ret =3D -EINVAL; goto fail; } - qdict_del(encryptopts, "format"); - crypto_opts =3D block_crypto_open_opts_init( - Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); + qdict_put_str(encryptopts, "format", "qcow"); + crypto_opts =3D block_crypto_open_opts_init(encryptopts, errp); if (!crypto_opts) { ret =3D -EINVAL; goto fail; diff --git a/block/qcow2.c b/block/qcow2.c index 2d190aa00b..78aeb1f9ea 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1040,9 +1040,8 @@ static int qcow2_update_options_prepare(BlockDriverSt= ate *bs, ret =3D -EINVAL; goto fail; } - qdict_del(encryptopts, "format"); - r->crypto_opts =3D block_crypto_open_opts_init( - Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); + qdict_put_str(encryptopts, "format", "qcow"); + r->crypto_opts =3D block_crypto_open_opts_init(encryptopts, errp); break; =20 case QCOW_CRYPT_LUKS: @@ -1053,9 +1052,8 @@ static int qcow2_update_options_prepare(BlockDriverSt= ate *bs, ret =3D -EINVAL; goto fail; } - qdict_del(encryptopts, "format"); - r->crypto_opts =3D block_crypto_open_opts_init( - Q_CRYPTO_BLOCK_FORMAT_LUKS, encryptopts, errp); + qdict_put_str(encryptopts, "format", "luks"); + r->crypto_opts =3D block_crypto_open_opts_init(encryptopts, errp); break; =20 default: --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282593855922.93203627814; Fri, 29 Jun 2018 07:29:53 -0700 (PDT) Received: from localhost ([::1]:42566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuPJ-0003L5-3W for importer@patchew.org; Fri, 29 Jun 2018 10:29:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6Z-00042i-Pm for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Y-0004AL-7A for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51358 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6O-0003qA-0y; Fri, 29 Jun 2018 10:10:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C566405A000; Fri, 29 Jun 2018 14:10:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC0E91102E29; Fri, 29 Jun 2018 14:10:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:45 +0200 Message-Id: <20180629140959.6690-16-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:19 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 15/29] qemu-iotests: Update 026.out.nocache reference output 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit abf754fe406 updated 026.out, but forgot to also update 026.out.nocache. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/026.out.nocache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/026.out.nocache b/tests/qemu-iotests/026.ou= t.nocache index ea2e166a4e..650ccd8b01 100644 --- a/tests/qemu-iotests/026.out.nocache +++ b/tests/qemu-iotests/026.out.nocache @@ -541,7 +541,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -11 leaked clusters were found on the image. +10 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -569,7 +569,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -11 leaked clusters were found on the image. +10 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 @@ -597,7 +597,7 @@ Failed to flush the L2 table cache: No space left on de= vice Failed to flush the refcount block cache: No space left on device write failed: No space left on device =20 -11 leaked clusters were found on the image. +10 leaked clusters were found on the image. This means waste of disk space, but no harm to data. Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1073741824=20 =20 --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282648004456.55110212381965; Fri, 29 Jun 2018 07:30:48 -0700 (PDT) Received: from localhost ([::1]:42570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuQB-00044W-7E for importer@patchew.org; Fri, 29 Jun 2018 10:30:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6Z-000428-Gk for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Y-0004AQ-5Y for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44868 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6P-0003tA-In; Fri, 29 Jun 2018 10:10:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10265CB9F7; Fri, 29 Jun 2018 14:10:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 402941102E29; Fri, 29 Jun 2018 14:10:19 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:46 +0200 Message-Id: <20180629140959.6690-17-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:21 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 16/29] qcow2: Free allocated clusters on write error 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If we managed to allocate the clusters, but then failed to write the data, there's a good chance that we'll still be able to free the clusters again in order to avoid cluster leaks (the refcounts are cached, so even if we can't write them out right now, we may be able to do so when the VM is resumed after a werror=3Dstop/enospc pause). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake Tested-by: Eric Blake --- block/qcow2.h | 1 + block/qcow2-cluster.c | 11 +++++++++++ block/qcow2.c | 2 ++ 3 files changed, 14 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 01b5250415..1c9c0d3631 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -614,6 +614,7 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDri= verState *bs, int compressed_size); =20 int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m); +void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m); int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes, enum qcow2_discard_type type, bool full_discard); diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 0d74584c9b..d37fe08b3d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -994,6 +994,17 @@ err: return ret; } =20 +/** + * Frees the allocated clusters because the request failed and they won't + * actually be linked. + */ +void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m) +{ + BDRVQcow2State *s =3D bs->opaque; + qcow2_free_clusters(bs, m->alloc_offset, m->nb_clusters << s->cluster_= bits, + QCOW2_DISCARD_NEVER); +} + /* * Returns the number of contiguous clusters that can be used for an alloc= ating * write, but require COW to be performed (this includes yet unallocated s= pace, diff --git a/block/qcow2.c b/block/qcow2.c index 78aeb1f9ea..286640c0e3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1775,6 +1775,8 @@ static coroutine_fn int qcow2_handle_l2meta(BlockDriv= erState *bs, if (ret) { goto out; } + } else { + qcow2_alloc_cluster_abort(bs, l2meta); } =20 /* Take the request off the list of running requests */ --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282565707746.8498467899483; Fri, 29 Jun 2018 07:29:25 -0700 (PDT) Received: from localhost ([::1]:42565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuOq-0002ws-T0 for importer@patchew.org; Fri, 29 Jun 2018 10:29:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6Z-00042c-Ol for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Y-0004A9-1x for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51362 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6Q-0003uk-Ey; Fri, 29 Jun 2018 10:10:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C3FD40583DD; Fri, 29 Jun 2018 14:10:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B5281102E29; Fri, 29 Jun 2018 14:10:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:47 +0200 Message-Id: <20180629140959.6690-18-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:22 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 17/29] qemu-iotests: Test qcow2 not leaking clusters on write error 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This adds a test for a temporary write failure, which simulates the situation after werror=3Dstop/enospc has stopped the VM. We shouldn't leave leaked clusters behind in such cases. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/026 | 17 +++++++++++++++++ tests/qemu-iotests/026.out | 8 ++++++++ tests/qemu-iotests/026.out.nocache | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026 index 7fadfbace5..582d254195 100755 --- a/tests/qemu-iotests/026 +++ b/tests/qemu-iotests/026 @@ -200,6 +200,23 @@ done done done =20 +echo +echo =3D=3D=3D Avoid cluster leaks after temporary failure =3D=3D=3D +echo + +cat > "$TEST_DIR/blkdebug.conf" < Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282617951692.3352027217242; Fri, 29 Jun 2018 07:30:17 -0700 (PDT) Received: from localhost ([::1]:42567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuPh-0003g9-2h for importer@patchew.org; Fri, 29 Jun 2018 10:30:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6c-00045j-6z for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Z-0004Cm-8w for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44872 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6R-0003wr-Qs; Fri, 29 Jun 2018 10:10:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 278D5CB9F7; Fri, 29 Jun 2018 14:10:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 558DD1102E29; Fri, 29 Jun 2018 14:10:22 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:48 +0200 Message-Id: <20180629140959.6690-19-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:23 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 18/29] file-posix: Implement co versions of discard/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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This simplifies file-posix by implementing the coroutine variants of the discard and flush BlockDriver callbacks. These were the last remaining users of paio_submit(), which can be removed now. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/file-posix.c | 72 ++++++++++++++++++--------------------------------= ---- 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 639265d53b..e3f1b045d1 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1754,31 +1754,6 @@ static inline int paio_submit_co(BlockDriverState *b= s, int fd, return paio_submit_co_full(bs, fd, offset, -1, 0, qiov, bytes, type); } =20 -static BlockAIOCB *paio_submit(BlockDriverState *bs, int fd, - int64_t offset, QEMUIOVector *qiov, int bytes, - BlockCompletionFunc *cb, void *opaque, int type) -{ - RawPosixAIOData *acb =3D g_new(RawPosixAIOData, 1); - ThreadPool *pool; - - acb->bs =3D bs; - acb->aio_type =3D type; - acb->aio_fildes =3D fd; - - acb->aio_nbytes =3D bytes; - acb->aio_offset =3D offset; - - if (qiov) { - acb->aio_iov =3D qiov->iov; - acb->aio_niov =3D qiov->niov; - assert(qiov->size =3D=3D acb->aio_nbytes); - } - - trace_paio_submit(acb, opaque, offset, bytes, type); - pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); -} - static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int= type) { @@ -1845,15 +1820,17 @@ static void raw_aio_unplug(BlockDriverState *bs) #endif } =20 -static BlockAIOCB *raw_aio_flush(BlockDriverState *bs, - BlockCompletionFunc *cb, void *opaque) +static int raw_co_flush_to_disk(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; + int ret; =20 - if (fd_open(bs) < 0) - return NULL; + ret =3D fd_open(bs); + if (ret < 0) { + return ret; + } =20 - return paio_submit(bs, s->fd, 0, NULL, 0, cb, opaque, QEMU_AIO_FLUSH); + return paio_submit_co(bs, s->fd, 0, NULL, 0, QEMU_AIO_FLUSH); } =20 static void raw_aio_attach_aio_context(BlockDriverState *bs, @@ -2526,14 +2503,12 @@ static void coroutine_fn raw_co_invalidate_cache(Bl= ockDriverState *bs, #endif /* !__linux__ */ } =20 -static coroutine_fn BlockAIOCB *raw_aio_pdiscard(BlockDriverState *bs, - int64_t offset, int bytes, - BlockCompletionFunc *cb, void *opaque) +static coroutine_fn int +raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { BDRVRawState *s =3D bs->opaque; =20 - return paio_submit(bs, s->fd, offset, NULL, bytes, - cb, opaque, QEMU_AIO_DISCARD); + return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD= ); } =20 static int coroutine_fn raw_co_pwrite_zeroes( @@ -2652,8 +2627,8 @@ BlockDriver bdrv_file =3D { =20 .bdrv_co_preadv =3D raw_co_preadv, .bdrv_co_pwritev =3D raw_co_pwritev, - .bdrv_aio_flush =3D raw_aio_flush, - .bdrv_aio_pdiscard =3D raw_aio_pdiscard, + .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, + .bdrv_co_pdiscard =3D raw_co_pdiscard, .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, @@ -3019,17 +2994,18 @@ static int fd_open(BlockDriverState *bs) return -EIO; } =20 -static coroutine_fn BlockAIOCB *hdev_aio_pdiscard(BlockDriverState *bs, - int64_t offset, int bytes, - BlockCompletionFunc *cb, void *opaque) +static coroutine_fn int +hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { BDRVRawState *s =3D bs->opaque; + int ret; =20 - if (fd_open(bs) < 0) { - return NULL; + ret =3D fd_open(bs); + if (ret < 0) { + return ret; } - return paio_submit(bs, s->fd, offset, NULL, bytes, - cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV); + return paio_submit_co(bs, s->fd, offset, NULL, bytes, + QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV); } =20 static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, @@ -3133,8 +3109,8 @@ static BlockDriver bdrv_host_device =3D { =20 .bdrv_co_preadv =3D raw_co_preadv, .bdrv_co_pwritev =3D raw_co_pwritev, - .bdrv_aio_flush =3D raw_aio_flush, - .bdrv_aio_pdiscard =3D hdev_aio_pdiscard, + .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, + .bdrv_co_pdiscard =3D hdev_co_pdiscard, .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, @@ -3258,7 +3234,7 @@ static BlockDriver bdrv_host_cdrom =3D { =20 .bdrv_co_preadv =3D raw_co_preadv, .bdrv_co_pwritev =3D raw_co_pwritev, - .bdrv_aio_flush =3D raw_aio_flush, + .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_io_plug =3D raw_aio_plug, .bdrv_io_unplug =3D raw_aio_unplug, @@ -3388,7 +3364,7 @@ static BlockDriver bdrv_host_cdrom =3D { =20 .bdrv_co_preadv =3D raw_co_preadv, .bdrv_co_pwritev =3D raw_co_pwritev, - .bdrv_aio_flush =3D raw_aio_flush, + .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_io_plug =3D raw_aio_plug, .bdrv_io_unplug =3D raw_aio_unplug, --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282436569837.6807533412267; Fri, 29 Jun 2018 07:27:16 -0700 (PDT) Received: from localhost ([::1]:42550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuMl-00013s-RD for importer@patchew.org; Fri, 29 Jun 2018 10:27:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6b-00044A-3L for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Z-0004Cu-Aj for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51366 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6S-0003yL-Jv; Fri, 29 Jun 2018 10:10:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3209640583DD; Fri, 29 Jun 2018 14:10:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 619111102E29; Fri, 29 Jun 2018 14:10:23 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:49 +0200 Message-Id: <20180629140959.6690-20-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:24 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 19/29] qcow2: Fix src_offset in copy offloading 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Not updating src_offset will result in wrong data being written to dst image. Reported-by: Max Reitz Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/qcow2.c | 1 + tests/qemu-iotests/063 | 9 +++++++++ tests/qemu-iotests/063.out | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 286640c0e3..2f9e58e0c4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3387,6 +3387,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, } =20 bytes -=3D cur_bytes; + src_offset +=3D cur_bytes; dst_offset +=3D cur_bytes; } ret =3D 0; diff --git a/tests/qemu-iotests/063 b/tests/qemu-iotests/063 index e4f6ea9385..adc037c1f5 100755 --- a/tests/qemu-iotests/063 +++ b/tests/qemu-iotests/063 @@ -91,6 +91,15 @@ if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG= .orig" "$TEST_IMG" >/dev exit 1 fi =20 +echo "=3D=3D Regression testing for copy offloading bug =3D=3D" + +_make_test_img 1M +TEST_IMG=3D"$TEST_IMG.target" _make_test_img 1M +$QEMU_IO -c 'write -P 1 0 512k' -c 'write -P 2 512k 512k' "$TEST_IMG" | _f= ilter_qemu_io +$QEMU_IO -c 'write -P 4 512k 512k' -c 'write -P 3 0 512k' "$TEST_IMG.targe= t" | _filter_qemu_io +$QEMU_IMG convert -n -O $IMGFMT "$TEST_IMG" "$TEST_IMG.target" +$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.target" + echo "*** done" rm -f $seq.full status=3D0 diff --git a/tests/qemu-iotests/063.out b/tests/qemu-iotests/063.out index de1c99afd8..7b691b2c9e 100644 --- a/tests/qemu-iotests/063.out +++ b/tests/qemu-iotests/063.out @@ -7,4 +7,16 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D4194304 No errors were found on the image. =3D=3D Testing conversion to a smaller file fails =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2097152 +=3D=3D Regression testing for copy offloading bug =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +Formatting 'TEST_DIR/t.IMGFMT.target', fmt=3DIMGFMT size=3D1048576 +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 524288 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 524288 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 524288/524288 bytes at offset 0 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Images are identical. *** done --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282379972607.144754073601; Fri, 29 Jun 2018 07:26:19 -0700 (PDT) Received: from localhost ([::1]:42548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuLr-0000IQ-81 for importer@patchew.org; Fri, 29 Jun 2018 10:26:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6b-000449-2d for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Z-0004DU-HO for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44876 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6T-00040Z-IM; Fri, 29 Jun 2018 10:10:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3ECDCCB9F7; Fri, 29 Jun 2018 14:10:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D7641102E29; Fri, 29 Jun 2018 14:10:24 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:50 +0200 Message-Id: <20180629140959.6690-21-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 20/29] iscsi: Don't blindly use designator length in response for memcpy 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Per SCSI definition the designator_length we receive from INQUIRY is 8, 12 or at most 16, but we should be careful because the remote iscsi target may misbehave, otherwise we could have a buffer overflow. Reported-by: Max Reitz Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/iscsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/iscsi.c b/block/iscsi.c index bc84b14e20..9beb06d498 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2226,7 +2226,7 @@ static void iscsi_populate_target_desc(unsigned char = *desc, IscsiLun *lun) desc[5] =3D (dd->designator_type & 0xF) | ((dd->association & 3) << 4); desc[7] =3D dd->designator_length; - memcpy(desc + 8, dd->designator, dd->designator_length); + memcpy(desc + 8, dd->designator, MIN(dd->designator_length, 20)); =20 desc[28] =3D 0; desc[29] =3D (lun->block_size >> 16) & 0xFF; --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282194465851.0223278346867; Fri, 29 Jun 2018 07:23:14 -0700 (PDT) Received: from localhost ([::1]:42520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuIr-0006JX-NR for importer@patchew.org; Fri, 29 Jun 2018 10:23:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6a-000444-UN for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Z-0004Cp-9P for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51370 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6U-00042T-Ka; Fri, 29 Jun 2018 10:10:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48F6E40583DD; Fri, 29 Jun 2018 14:10:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 788AC1102E29; Fri, 29 Jun 2018 14:10:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:51 +0200 Message-Id: <20180629140959.6690-22-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:26 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 21/29] file-posix: Fix EINTR 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng EINTR should be checked against errno, not ret. While fixing the bug, collect the branches with a switch block. Also, change the return value from -ENOSTUP to -ENOSPC when the actual issue is request range passes EOF, which should be distinguishable from the case of error =3D=3D ENOSYS by the caller, so that it could still retry with other byte ranges, whereas it shouldn't retry anymore upon ENOSYS. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/file-posix.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index e3f1b045d1..829ee538d8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1488,20 +1488,21 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIOD= ata *aiocb) ssize_t ret =3D copy_file_range(aiocb->aio_fildes, &in_off, aiocb->aio_fd2, &out_off, bytes, 0); - if (ret =3D=3D -EINTR) { - continue; + if (ret =3D=3D 0) { + /* No progress (e.g. when beyond EOF), let the caller fall bac= k to + * buffer I/O. */ + return -ENOSPC; } if (ret < 0) { - if (errno =3D=3D ENOSYS) { + switch (errno) { + case ENOSYS: return -ENOTSUP; - } else { + case EINTR: + continue; + default: return -errno; } } - if (!ret) { - /* No progress (e.g. when beyond EOF), fall back to buffer I/O= . */ - return -ENOTSUP; - } bytes -=3D ret; } return 0; --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282824408353.35633957108234; Fri, 29 Jun 2018 07:33:44 -0700 (PDT) Received: from localhost ([::1]:42590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuT1-0006CP-Le for importer@patchew.org; Fri, 29 Jun 2018 10:33:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6c-00045a-3V for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6Z-0004ET-Se for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44894 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6V-00044Q-LM; Fri, 29 Jun 2018 10:10:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52482CB9F7; Fri, 29 Jun 2018 14:10:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 838721102E29; Fri, 29 Jun 2018 14:10:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:52 +0200 Message-Id: <20180629140959.6690-23-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 29 Jun 2018 14:10:27 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 22/29] parallels: Switch to byte-based calls 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based calls into the block layer from the parallels driver. Ideally, the parallels driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi Reviewed-by: Denis V. Lunev Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/parallels.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index fd215e202a..cc9445879d 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -227,14 +227,15 @@ static int64_t allocate_clusters(BlockDriverState *bs= , int64_t sector_num, }; qemu_iovec_init_external(&qiov, &iov, 1); =20 - ret =3D bdrv_co_readv(bs->backing, idx * s->tracks, nb_cow_sectors, - &qiov); + ret =3D bdrv_co_preadv(bs->backing, idx * s->tracks * BDRV_SECTOR_= SIZE, + nb_cow_bytes, &qiov, 0); if (ret < 0) { qemu_vfree(iov.iov_base); return ret; } =20 - ret =3D bdrv_co_writev(bs->file, s->data_end, nb_cow_sectors, &qio= v); + ret =3D bdrv_co_pwritev(bs->file, s->data_end * BDRV_SECTOR_SIZE, + nb_cow_bytes, &qiov, 0); qemu_vfree(iov.iov_base); if (ret < 0) { return ret; @@ -340,7 +341,8 @@ static coroutine_fn int parallels_co_writev(BlockDriver= State *bs, qemu_iovec_reset(&hd_qiov); qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes); =20 - ret =3D bdrv_co_writev(bs->file, position, n, &hd_qiov); + ret =3D bdrv_co_pwritev(bs->file, position * BDRV_SECTOR_SIZE, nby= tes, + &hd_qiov, 0); if (ret < 0) { break; } @@ -379,7 +381,8 @@ static coroutine_fn int parallels_co_readv(BlockDriverS= tate *bs, =20 if (position < 0) { if (bs->backing) { - ret =3D bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov= ); + ret =3D bdrv_co_preadv(bs->backing, sector_num * BDRV_SECT= OR_SIZE, + nbytes, &hd_qiov, 0); if (ret < 0) { break; } @@ -387,7 +390,8 @@ static coroutine_fn int parallels_co_readv(BlockDriverS= tate *bs, qemu_iovec_memset(&hd_qiov, 0, 0, nbytes); } } else { - ret =3D bdrv_co_readv(bs->file, position, n, &hd_qiov); + ret =3D bdrv_co_preadv(bs->file, position * BDRV_SECTOR_SIZE, = nbytes, + &hd_qiov, 0); if (ret < 0) { break; } --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530283013673700.169394160715; Fri, 29 Jun 2018 07:36:53 -0700 (PDT) Received: from localhost ([::1]:42612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuW5-0000QR-07 for importer@patchew.org; Fri, 29 Jun 2018 10:36:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6h-0004CX-7j for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6c-0004JV-5s for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51374 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6W-00046j-N8; Fri, 29 Jun 2018 10:10:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61E2240770C3; Fri, 29 Jun 2018 14:10:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D1531102E29; Fri, 29 Jun 2018 14:10:27 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:53 +0200 Message-Id: <20180629140959.6690-24-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:28 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 23/29] qcow: Switch get_cluster_offset to be byte-based 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the internal helper function get_cluster_offset(), by changing n_start and n_end to be byte offsets rather than sector indices within the cluster being allocated. However, assert that these values are still sector-aligned (at least qcrypto_block_encrypt() still wants that). For now we get that alignment for free because we still use sector-based driver callbacks. A later patch will then switch the qcow driver as a whole over to byte-based operation; but will still leave things at sector alignments as it is not worth auditing the qcow image format to worry about sub-sector requests. Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/qcow.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 8546fe5bb7..d7c385a91d 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -345,8 +345,8 @@ static int qcow_reopen_prepare(BDRVReopenState *state, * * 0 to not allocate. * - * 1 to allocate a normal cluster (for sector indexes 'n_start' to - * 'n_end') + * 1 to allocate a normal cluster (for sector-aligned byte offsets 'n_star= t' + * to 'n_end' within the cluster) * * 2 to allocate a compressed cluster of size * 'compressed_size'. 'compressed_size' must be > 0 and < @@ -440,9 +440,10 @@ static int get_cluster_offset(BlockDriverState *bs, if (!allocate) return 0; BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC); + assert(QEMU_IS_ALIGNED(n_start | n_end, BDRV_SECTOR_SIZE)); /* allocate a new cluster */ if ((cluster_offset & QCOW_OFLAG_COMPRESSED) && - (n_end - n_start) < s->cluster_sectors) { + (n_end - n_start) < s->cluster_size) { /* if the cluster is already compressed, we must decompress it in the case it is not completely overwritten */ @@ -480,16 +481,15 @@ static int get_cluster_offset(BlockDriverState *bs, /* if encrypted, we must initialize the cluster content which won't be written */ if (bs->encrypted && - (n_end - n_start) < s->cluster_sectors) { - uint64_t start_sect; + (n_end - n_start) < s->cluster_size) { + uint64_t start_offset; assert(s->crypto); - start_sect =3D (offset & ~(s->cluster_size - 1)) >> 9; - for(i =3D 0; i < s->cluster_sectors; i++) { + start_offset =3D offset & ~(s->cluster_size - 1); + for (i =3D 0; i < s->cluster_size; i +=3D BDRV_SECTOR_= SIZE) { if (i < n_start || i >=3D n_end) { - memset(s->cluster_data, 0x00, 512); + memset(s->cluster_data, 0x00, BDRV_SECTOR_SIZE= ); if (qcrypto_block_encrypt(s->crypto, - (start_sect + i) * - BDRV_SECTOR_SIZE, + start_offset + i, s->cluster_data, BDRV_SECTOR_SIZE, NULL) < 0) { @@ -497,8 +497,9 @@ static int get_cluster_offset(BlockDriverState *bs, } BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); ret =3D bdrv_pwrite(bs->file, - cluster_offset + i * 512, - s->cluster_data, 512); + cluster_offset + i, + s->cluster_data, + BDRV_SECTOR_SIZE); if (ret < 0) { return ret; } @@ -758,8 +759,8 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, n =3D nb_sectors; } ret =3D get_cluster_offset(bs, sector_num << 9, 1, 0, - index_in_cluster, - index_in_cluster + n, &cluster_offset); + index_in_cluster << 9, + (index_in_cluster + n) << 9, &cluster_off= set); if (ret < 0) { break; } --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282839039605.5647483998266; Fri, 29 Jun 2018 07:33:59 -0700 (PDT) Received: from localhost ([::1]:42591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuTG-0006NL-6f for importer@patchew.org; Fri, 29 Jun 2018 10:33:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6h-0004CZ-9b for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6c-0004KN-BW for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48316 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6X-00048q-R4; Fri, 29 Jun 2018 10:10:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C41981A7CED; Fri, 29 Jun 2018 14:10:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CC331102E29; Fri, 29 Jun 2018 14:10:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:54 +0200 Message-Id: <20180629140959.6690-25-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 29 Jun 2018 14:10:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 29 Jun 2018 14:10:29 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 24/29] qcow: Switch qcow_co_readv to byte-based calls 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the internals of the qcow driver read function, by iterating over offset/bytes instead of sector_num/nb_sectors, and with a rename of index_in_cluster and repurposing of n to track bytes instead of sectors. A later patch will then switch the qcow driver as a whole over to byte-based operation. Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/qcow.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index d7c385a91d..436ad518be 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -617,13 +617,15 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVQcowState *s =3D bs->opaque; - int index_in_cluster; + int offset_in_cluster; int ret =3D 0, n; uint64_t cluster_offset; struct iovec hd_iov; QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; + int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; + int64_t bytes =3D nb_sectors * BDRV_SECTOR_SIZE; =20 if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); @@ -637,36 +639,35 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, =20 qemu_co_mutex_lock(&s->lock); =20 - while (nb_sectors !=3D 0) { + while (bytes !=3D 0) { /* prepare next request */ - ret =3D get_cluster_offset(bs, sector_num << 9, - 0, 0, 0, 0, &cluster_offset); + ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset= ); if (ret < 0) { break; } - index_in_cluster =3D sector_num & (s->cluster_sectors - 1); - n =3D s->cluster_sectors - index_in_cluster; - if (n > nb_sectors) { - n =3D nb_sectors; + offset_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - offset_in_cluster; + if (n > bytes) { + n =3D bytes; } =20 if (!cluster_offset) { if (bs->backing) { /* read from the base image */ hd_iov.iov_base =3D (void *)buf; - hd_iov.iov_len =3D n * 512; + hd_iov.iov_len =3D n; qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); /* qcow2 emits this on bs->file instead of bs->backing */ BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); - ret =3D bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov= ); + ret =3D bdrv_co_preadv(bs->backing, offset, n, &hd_qiov, 0= ); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; } } else { /* Note: in this case, no need to wait */ - memset(buf, 0, 512 * n); + memset(buf, 0, n); } } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { /* add AIO support for compressed blocks ? */ @@ -674,21 +675,19 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, ret =3D -EIO; break; } - memcpy(buf, - s->cluster_cache + index_in_cluster * 512, 512 * n); + memcpy(buf, s->cluster_cache + offset_in_cluster, n); } else { if ((cluster_offset & 511) !=3D 0) { ret =3D -EIO; break; } hd_iov.iov_base =3D (void *)buf; - hd_iov.iov_len =3D n * 512; + hd_iov.iov_len =3D n; qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_co_readv(bs->file, - (cluster_offset >> 9) + index_in_cluster, - n, &hd_qiov); + ret =3D bdrv_co_preadv(bs->file, cluster_offset + offset_in_cl= uster, + n, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; @@ -696,8 +695,7 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, if (bs->encrypted) { assert(s->crypto); if (qcrypto_block_decrypt(s->crypto, - sector_num * BDRV_SECTOR_SIZE, b= uf, - n * BDRV_SECTOR_SIZE, NULL) < 0)= { + offset, buf, n, NULL) < 0) { ret =3D -EIO; break; } @@ -705,9 +703,9 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, } ret =3D 0; =20 - nb_sectors -=3D n; - sector_num +=3D n; - buf +=3D n * 512; + bytes -=3D n; + offset +=3D n; + buf +=3D n; } =20 qemu_co_mutex_unlock(&s->lock); --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282793066181.4017995469775; Fri, 29 Jun 2018 07:33:13 -0700 (PDT) Received: from localhost ([::1]:42589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuSR-0005lb-H9 for importer@patchew.org; Fri, 29 Jun 2018 10:33:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6i-0004EM-Jf for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6h-0004Tq-C0 for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51382 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6Z-0004BM-0b; Fri, 29 Jun 2018 10:10:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7576D4112650; Fri, 29 Jun 2018 14:10:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6DEE1102E29; Fri, 29 Jun 2018 14:10:29 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:55 +0200 Message-Id: <20180629140959.6690-26-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 29 Jun 2018 14:10:30 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 25/29] qcow: Switch qcow_co_writev to byte-based calls 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the internals of the qcow driver write function, by iterating over offset/bytes instead of sector_num/nb_sectors, and with a rename of index_in_cluster and repurposing of n to track bytes instead of sectors. A later patch will then switch the qcow driver as a whole over to byte-based operation. Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/qcow.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 436ad518be..8fe82ed58d 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -723,13 +723,15 @@ static coroutine_fn int qcow_co_writev(BlockDriverSta= te *bs, int64_t sector_num, int flags) { BDRVQcowState *s =3D bs->opaque; - int index_in_cluster; + int offset_in_cluster; uint64_t cluster_offset; int ret =3D 0, n; struct iovec hd_iov; QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; + int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; + int64_t bytes =3D nb_sectors * BDRV_SECTOR_SIZE; =20 assert(!flags); s->cluster_cache_offset =3D -1; /* disable compressed cache */ @@ -749,16 +751,14 @@ static coroutine_fn int qcow_co_writev(BlockDriverSta= te *bs, int64_t sector_num, =20 qemu_co_mutex_lock(&s->lock); =20 - while (nb_sectors !=3D 0) { - - index_in_cluster =3D sector_num & (s->cluster_sectors - 1); - n =3D s->cluster_sectors - index_in_cluster; - if (n > nb_sectors) { - n =3D nb_sectors; + while (bytes !=3D 0) { + offset_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - offset_in_cluster; + if (n > bytes) { + n =3D bytes; } - ret =3D get_cluster_offset(bs, sector_num << 9, 1, 0, - index_in_cluster << 9, - (index_in_cluster + n) << 9, &cluster_off= set); + ret =3D get_cluster_offset(bs, offset, 1, 0, offset_in_cluster, + offset_in_cluster + n, &cluster_offset); if (ret < 0) { break; } @@ -768,30 +768,28 @@ static coroutine_fn int qcow_co_writev(BlockDriverSta= te *bs, int64_t sector_num, } if (bs->encrypted) { assert(s->crypto); - if (qcrypto_block_encrypt(s->crypto, sector_num * BDRV_SECTOR_= SIZE, - buf, n * BDRV_SECTOR_SIZE, NULL) < 0= ) { + if (qcrypto_block_encrypt(s->crypto, offset, buf, n, NULL) < 0= ) { ret =3D -EIO; break; } } =20 hd_iov.iov_base =3D (void *)buf; - hd_iov.iov_len =3D n * 512; + hd_iov.iov_len =3D n; qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); - ret =3D bdrv_co_writev(bs->file, - (cluster_offset >> 9) + index_in_cluster, - n, &hd_qiov); + ret =3D bdrv_co_pwritev(bs->file, cluster_offset + offset_in_clust= er, + n, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; } ret =3D 0; =20 - nb_sectors -=3D n; - sector_num +=3D n; - buf +=3D n * 512; + bytes -=3D n; + offset +=3D n; + buf +=3D n; } qemu_co_mutex_unlock(&s->lock); =20 --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530283056280101.94358015844432; Fri, 29 Jun 2018 07:37:36 -0700 (PDT) Received: from localhost ([::1]:42613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuWh-0000v1-Kf for importer@patchew.org; Fri, 29 Jun 2018 10:37:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6i-0004EV-Mu for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6h-0004Td-At for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35752 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6a-0004Dk-1r; Fri, 29 Jun 2018 10:10:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F9D54010222; Fri, 29 Jun 2018 14:10:31 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id B03571102E29; Fri, 29 Jun 2018 14:10:30 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:56 +0200 Message-Id: <20180629140959.6690-27-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 29 Jun 2018 14:10:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 29 Jun 2018 14:10:31 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 26/29] qcow: Switch to a byte-based driver 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. The qcow driver is now ready to fully utilize the byte-based callback interface, as long as we override the default alignment to still be 512 (needed at least for asserts present because of encryption, but easier to do everywhere than to audit which sub-sector requests are handled correctly, especially since we no longer recommend qcow for new disk images). Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/qcow.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 8fe82ed58d..102d058d1c 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -70,7 +70,6 @@ typedef struct QCowHeader { typedef struct BDRVQcowState { int cluster_bits; int cluster_size; - int cluster_sectors; int l2_bits; int l2_size; unsigned int l1_size; @@ -235,7 +234,6 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, } s->cluster_bits =3D header.cluster_bits; s->cluster_size =3D 1 << s->cluster_bits; - s->cluster_sectors =3D 1 << (s->cluster_bits - 9); s->l2_bits =3D header.l2_bits; s->l2_size =3D 1 << s->l2_bits; bs->total_sectors =3D header.size / 512; @@ -613,8 +611,18 @@ static int decompress_cluster(BlockDriverState *bs, ui= nt64_t cluster_offset) return 0; } =20 -static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector= _num, - int nb_sectors, QEMUIOVector *qiov) +static void qcow_refresh_limits(BlockDriverState *bs, Error **errp) +{ + /* At least encrypted images require 512-byte alignment. Apply the + * limit universally, rather than just on encrypted images, as + * it's easier to let the block layer handle rounding than to + * audit this code further. */ + bs->bl.request_alignment =3D BDRV_SECTOR_SIZE; +} + +static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, uint64_t offs= et, + uint64_t bytes, QEMUIOVector *qiov, + int flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -624,9 +632,8 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; - int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; - int64_t bytes =3D nb_sectors * BDRV_SECTOR_SIZE; =20 + assert(!flags); if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { @@ -718,9 +725,9 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, return ret; } =20 -static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t secto= r_num, - int nb_sectors, QEMUIOVector *qiov, - int flags) +static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, uint64_t off= set, + uint64_t bytes, QEMUIOVector *qiov, + int flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -730,8 +737,6 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; - int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; - int64_t bytes =3D nb_sectors * BDRV_SECTOR_SIZE; =20 assert(!flags); s->cluster_cache_offset =3D -1; /* disable compressed cache */ @@ -1104,8 +1109,7 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uint= 64_t offset, =20 if (ret !=3D Z_STREAM_END || out_len >=3D s->cluster_size) { /* could not compress: write normal cluster */ - ret =3D qcow_co_writev(bs, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, qiov, 0); + ret =3D qcow_co_pwritev(bs, offset, bytes, qiov, 0); if (ret < 0) { goto fail; } @@ -1190,9 +1194,10 @@ static BlockDriver bdrv_qcow =3D { .bdrv_co_create_opts =3D qcow_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .supports_backing =3D true, + .bdrv_refresh_limits =3D qcow_refresh_limits, =20 - .bdrv_co_readv =3D qcow_co_readv, - .bdrv_co_writev =3D qcow_co_writev, + .bdrv_co_preadv =3D qcow_co_preadv, + .bdrv_co_pwritev =3D qcow_co_pwritev, .bdrv_co_block_status =3D qcow_co_block_status, =20 .bdrv_make_empty =3D qcow_make_empty, --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282864870639.6766427775882; Fri, 29 Jun 2018 07:34:24 -0700 (PDT) Received: from localhost ([::1]:42592 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuTg-0006i0-5V for importer@patchew.org; Fri, 29 Jun 2018 10:34:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6i-0004EQ-LK for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6h-0004U2-Eo for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48320 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6a-0004GN-UV; Fri, 29 Jun 2018 10:10:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A69C81A7CED; Fri, 29 Jun 2018 14:10:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA51E1102E29; Fri, 29 Jun 2018 14:10:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:57 +0200 Message-Id: <20180629140959.6690-28-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 29 Jun 2018 14:10:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 29 Jun 2018 14:10:32 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 27/29] replication: Switch to byte-based calls 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based calls into the block layer from the replication driver. Ideally, the replication driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/replication.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/replication.c b/block/replication.c index 826db7b304..6349d6958e 100644 --- a/block/replication.c +++ b/block/replication.c @@ -246,13 +246,14 @@ static coroutine_fn int replication_co_readv(BlockDri= verState *bs, backup_cow_request_begin(&req, child->bs->job, sector_num * BDRV_SECTOR_SIZE, remaining_bytes); - ret =3D bdrv_co_readv(bs->file, sector_num, remaining_sectors, - qiov); + ret =3D bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE, + remaining_bytes, qiov, 0); backup_cow_request_end(&req); goto out; } =20 - ret =3D bdrv_co_readv(bs->file, sector_num, remaining_sectors, qiov); + ret =3D bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE, + remaining_sectors * BDRV_SECTOR_SIZE, qiov, 0); out: return replication_return_value(s, ret); } @@ -279,8 +280,8 @@ static coroutine_fn int replication_co_writev(BlockDriv= erState *bs, } =20 if (ret =3D=3D 0) { - ret =3D bdrv_co_writev(top, sector_num, - remaining_sectors, qiov); + ret =3D bdrv_co_pwritev(top, sector_num * BDRV_SECTOR_SIZE, + remaining_sectors * BDRV_SECTOR_SIZE, qiov, = 0); return replication_return_value(s, ret); } =20 @@ -306,7 +307,8 @@ static coroutine_fn int replication_co_writev(BlockDriv= erState *bs, qemu_iovec_concat(&hd_qiov, qiov, bytes_done, count); =20 target =3D ret ? top : base; - ret =3D bdrv_co_writev(target, sector_num, n, &hd_qiov); + ret =3D bdrv_co_pwritev(target, sector_num * BDRV_SECTOR_SIZE, + n * BDRV_SECTOR_SIZE, &hd_qiov, 0); if (ret < 0) { goto out1; } --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530282982184896.8951710277707; Fri, 29 Jun 2018 07:36:22 -0700 (PDT) Received: from localhost ([::1]:42609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuVW-0008M5-Qz for importer@patchew.org; Fri, 29 Jun 2018 10:36:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6j-0004FR-DA for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6i-0004VV-Ec for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33890 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6c-0004It-45; Fri, 29 Jun 2018 10:10:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93CBE410FBC6; Fri, 29 Jun 2018 14:10:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4BF01102E29; Fri, 29 Jun 2018 14:10:32 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:58 +0200 Message-Id: <20180629140959.6690-29-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 29 Jun 2018 14:10:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 29 Jun 2018 14:10:33 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 28/29] vhdx: Switch to byte-based calls 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based calls into the block layer from the vhdx driver. Ideally, the vhdx driver should switch to doing everything byte-based, but that's a more invasive change that requires a bit more auditing. Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- block/vhdx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index a677703a9e..4d0819750f 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1127,9 +1127,9 @@ static coroutine_fn int vhdx_co_readv(BlockDriverStat= e *bs, int64_t sector_num, break; case PAYLOAD_BLOCK_FULLY_PRESENT: qemu_co_mutex_unlock(&s->lock); - ret =3D bdrv_co_readv(bs->file, - sinfo.file_offset >> BDRV_SECTOR_BITS, - sinfo.sectors_avail, &hd_qiov); + ret =3D bdrv_co_preadv(bs->file, sinfo.file_offset, + sinfo.sectors_avail * BDRV_SECTOR_SIZ= E, + &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto exit; @@ -1349,9 +1349,9 @@ static coroutine_fn int vhdx_co_writev(BlockDriverSta= te *bs, int64_t sector_num, } /* block exists, so we can just overwrite it */ qemu_co_mutex_unlock(&s->lock); - ret =3D bdrv_co_writev(bs->file, - sinfo.file_offset >> BDRV_SECTOR_BITS, - sectors_to_write, &hd_qiov); + ret =3D bdrv_co_pwritev(bs->file, sinfo.file_offset, + sectors_to_write * BDRV_SECTOR_SIZE, + &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto error_bat_restore; --=20 2.13.6 From nobody Thu Dec 18 17:48:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530283247775786.5102684785732; Fri, 29 Jun 2018 07:40:47 -0700 (PDT) Received: from localhost ([::1]:42639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuZr-00041L-12 for importer@patchew.org; Fri, 29 Jun 2018 10:40:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6j-0004Fo-PT for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6i-0004Vh-HP for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60300 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYu6c-0004LA-VP; Fri, 29 Jun 2018 10:10:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A01A3859AA; Fri, 29 Jun 2018 14:10:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE8E21102E29; Fri, 29 Jun 2018 14:10:33 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:59 +0200 Message-Id: <20180629140959.6690-30-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 29 Jun 2018 14:10:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 29 Jun 2018 14:10:34 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 29/29] block: Remove unused sector-based vectored I/O 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. Now that all callers of vectored I/O have been converted to use our preferred byte-based bdrv_co_p{read,write}v(), we can delete the unused bdrv_co_{read,write}v(). Furthermore, this gets rid of the signature difference between the public bdrv_co_writev() and the callback .bdrv_co_writev (the latter still exists, because some drivers still need more work before they are fully byte-based). Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi Reviewed-by: Jeff Cody Signed-off-by: Kevin Wolf --- include/block/block.h | 4 ---- block/io.c | 36 ------------------------------------ 2 files changed, 40 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 42e59ff585..2ffc1c64c6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -285,10 +285,6 @@ int bdrv_pwrite(BdrvChild *child, int64_t offset, cons= t void *buf, int bytes); int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, const void *buf, int count); -int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov); -int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov); /* * Efficiently zero a region of the disk image. Note that this is a regul= ar * I/O request like read or write and should have a reasonable size. This diff --git a/block/io.c b/block/io.c index b63822280a..7035b78a20 100644 --- a/block/io.c +++ b/block/io.c @@ -1429,24 +1429,6 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, return ret; } =20 -static int coroutine_fn bdrv_co_do_readv(BdrvChild *child, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, - BdrvRequestFlags flags) -{ - if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { - return -EINVAL; - } - - return bdrv_co_preadv(child, sector_num << BDRV_SECTOR_BITS, - nb_sectors << BDRV_SECTOR_BITS, qiov, flags); -} - -int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov) -{ - return bdrv_co_do_readv(child, sector_num, nb_sectors, qiov, 0); -} - static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { @@ -1889,24 +1871,6 @@ out: return ret; } =20 -static int coroutine_fn bdrv_co_do_writev(BdrvChild *child, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, - BdrvRequestFlags flags) -{ - if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { - return -EINVAL; - } - - return bdrv_co_pwritev(child, sector_num << BDRV_SECTOR_BITS, - nb_sectors << BDRV_SECTOR_BITS, qiov, flags); -} - -int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num, - int nb_sectors, QEMUIOVector *qiov) -{ - return bdrv_co_do_writev(child, sector_num, nb_sectors, qiov, 0); -} - int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { --=20 2.13.6