From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489756623993316.736777985906; Fri, 17 Mar 2017 06:17:03 -0700 (PDT) Received: from localhost ([::1]:48960 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corkc-0004Tt-4g for importer@patchew.org; Fri, 17 Mar 2017 09:17:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corjY-0004S9-2K for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:15:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjX-0000eP-1I for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:15:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57678) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corjU-0000bg-Sm; Fri, 17 Mar 2017 09:15:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E580D6364D; Fri, 17 Mar 2017 13:15:52 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94EB47770F; Fri, 17 Mar 2017 13:15:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E580D6364D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E580D6364D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:39 +0100 Message-Id: <1489756546-27142-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 17 Mar 2017 13:15:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/8] file-posix: clean up max_segments buffer termination X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The following pattern is unsafe: char buf[32]; ret =3D read(fd, buf, sizeof(buf)); ... buf[ret] =3D 0; If read(2) returns 32 then a byte beyond the end of the buffer is zeroed. In practice this buffer overflow does not occur because the sysfs max_segments file only contains an unsigned short + '\n'. The string is always shorter than 32 bytes. Regardless, avoid this pattern because static analysis tools might complain and it could lead to real buffer overflows if copy-pasted elsewhere in the codebase. Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/file-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index c4c0663..ac6bd9f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -686,7 +686,7 @@ static int hdev_get_max_segments(const struct stat *st) goto out; } do { - ret =3D read(fd, buf, sizeof(buf)); + ret =3D read(fd, buf, sizeof(buf) - 1); } while (ret =3D=3D -1 && errno =3D=3D EINTR); if (ret < 0) { ret =3D -errno; --=20 1.8.3.1 From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489756633586696.8573235636355; Fri, 17 Mar 2017 06:17:13 -0700 (PDT) Received: from localhost ([::1]:48963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corkm-0004Yc-AJ for importer@patchew.org; Fri, 17 Mar 2017 09:17:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corje-0004Wm-0s for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjZ-0000hm-T7 for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corjW-0000dV-K1; Fri, 17 Mar 2017 09:15:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2D4E332F71; Fri, 17 Mar 2017 13:15:54 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EA2E17F5F; Fri, 17 Mar 2017 13:15:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A2D4E332F71 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A2D4E332F71 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:40 +0100 Message-Id: <1489756546-27142-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 17 Mar 2017 13:15:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/8] replication: clarify permissions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Changlong Xie Even if hidden_disk, secondary_disk are backing files, they all need write permissions in replication scenario. Otherwise we will encouter below exceptions on secondary side during adding nbd server: {'execute': 'nbd-server-add', 'arguments': {'device': 'colo-disk', 'writabl= e': true } } {"error": {"class": "GenericError", "desc": "Conflicts with use by hidden-q= cow2-driver as 'backing', which does not allow 'write' on sec-qcow2-driver-= for-nbd"}} CC: Zhang Hailiang CC: Zhang Chen CC: Wen Congyang Signed-off-by: Changlong Xie Signed-off-by: Kevin Wolf --- block/replication.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/block/replication.c b/block/replication.c index 22f170f..bf3c395 100644 --- a/block/replication.c +++ b/block/replication.c @@ -155,6 +155,18 @@ static void replication_close(BlockDriverState *bs) replication_remove(s->rs); } =20 +static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + *nperm =3D *nshared =3D BLK_PERM_CONSISTENT_READ \ + | BLK_PERM_WRITE \ + | BLK_PERM_WRITE_UNCHANGED; + + return; +} + static int64_t replication_getlength(BlockDriverState *bs) { return bdrv_getlength(bs->file->bs); @@ -660,7 +672,7 @@ BlockDriver bdrv_replication =3D { =20 .bdrv_open =3D replication_open, .bdrv_close =3D replication_close, - .bdrv_child_perm =3D bdrv_filter_default_perms, + .bdrv_child_perm =3D replication_child_perm, =20 .bdrv_getlength =3D replication_getlength, .bdrv_co_readv =3D replication_co_readv, --=20 1.8.3.1 From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489756642137112.1211026620606; Fri, 17 Mar 2017 06:17:22 -0700 (PDT) Received: from localhost ([::1]:48966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corku-0004hJ-Jj for importer@patchew.org; Fri, 17 Mar 2017 09:17:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corjg-0004Z3-Oo for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjf-0000mV-IO for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53932) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corjY-0000fT-OK; Fri, 17 Mar 2017 09:15:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFAAA89C2A; Fri, 17 Mar 2017 13:15:56 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id F037B77716; Fri, 17 Mar 2017 13:15:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CFAAA89C2A Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CFAAA89C2A From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:41 +0100 Message-Id: <1489756546-27142-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 17 Mar 2017 13:15:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/8] file-posix: Don't leak fd in hdev_get_max_segments X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng This fixes a leaked fd introduced in commit 9103f1ce. Signed-off-by: Fam Zheng Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/file-posix.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index ac6bd9f..53febd3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -703,6 +703,9 @@ static int hdev_get_max_segments(const struct stat *st) } =20 out: + if (fd !=3D -1) { + close(fd); + } g_free(sysfspath); return ret; #else --=20 1.8.3.1 From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489756646153997.4739883915995; Fri, 17 Mar 2017 06:17:26 -0700 (PDT) Received: from localhost ([::1]:48967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corky-0004lE-W7 for importer@patchew.org; Fri, 17 Mar 2017 09:17:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corjo-0004g5-Mc for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjk-0000oz-8u for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corja-0000hN-7l; Fri, 17 Mar 2017 09:15:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B98E445D6; Fri, 17 Mar 2017 13:15:58 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28B6177716; Fri, 17 Mar 2017 13:15:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B98E445D6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2B98E445D6 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:42 +0100 Message-Id: <1489756546-27142-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 17 Mar 2017 13:15:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/8] block: Always call bdrv_child_check_perm first X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng bdrv_child_set_perm alone is not very usable because the caller must call bdrv_child_check_perm first. This is already encapsulated conveniently in bdrv_child_try_set_perm, so remove the other prototypes from the header and fix the one wrong caller, block/mirror.c. Signed-off-by: Fam Zheng Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block.c | 13 +++++++++---- block/mirror.c | 6 ++++-- include/block/block_int.h | 4 ---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index cb57370..a77e8a0 100644 --- a/block.c +++ b/block.c @@ -1393,6 +1393,11 @@ static int bdrv_fill_options(QDict **options, const = char *filename, return 0; } =20 +static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t sha= red, + GSList *ignore_children, Error **errp); +static void bdrv_child_abort_perm_update(BdrvChild *c); +static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shar= ed); + /* * Check whether permissions on this node can be changed in a way that * @cumulative_perms and @cumulative_shared_perms are the new cumulative @@ -1615,8 +1620,8 @@ static int bdrv_check_update_perm(BlockDriverState *b= s, uint64_t new_used_perm, =20 /* Needs to be followed by a call to either bdrv_child_set_perm() or * bdrv_child_abort_perm_update(). */ -int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared, - GSList *ignore_children, Error **errp) +static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t sha= red, + GSList *ignore_children, Error **errp) { int ret; =20 @@ -1627,7 +1632,7 @@ int bdrv_child_check_perm(BdrvChild *c, uint64_t perm= , uint64_t shared, return ret; } =20 -void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared) +static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shar= ed) { uint64_t cumulative_perms, cumulative_shared_perms; =20 @@ -1639,7 +1644,7 @@ void bdrv_child_set_perm(BdrvChild *c, uint64_t perm,= uint64_t shared) bdrv_set_perm(c->bs, cumulative_perms, cumulative_shared_perms); } =20 -void bdrv_child_abort_perm_update(BdrvChild *c) +static void bdrv_child_abort_perm_update(BdrvChild *c) { bdrv_abort_perm_update(c->bs); } diff --git a/block/mirror.c b/block/mirror.c index 4f3a5cb..ca4baa5 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -574,7 +574,8 @@ static void mirror_exit(BlockJob *job, void *opaque) * valid. Also give up permissions on mirror_top_bs->backing, which mi= ght * block the removal. */ block_job_remove_all_bdrv(job); - bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL); + bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL, + &error_abort); bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abo= rt); =20 /* We just changed the BDS the job BB refers to (with either or both o= f the @@ -1245,7 +1246,8 @@ fail: block_job_unref(&s->common); } =20 - bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL); + bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL, + &error_abort); bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abo= rt); } =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index 6c699ac..59400bd 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -889,10 +889,6 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *ch= ild_bs, void *opaque, Error **errp); void bdrv_root_unref_child(BdrvChild *child); =20 -int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared, - GSList *ignore_children, Error **errp); -void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared); -void bdrv_child_abort_perm_update(BdrvChild *c); int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, Error **errp); =20 --=20 1.8.3.1 From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489756776928641.4389527991126; Fri, 17 Mar 2017 06:19:36 -0700 (PDT) Received: from localhost ([::1]:48973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corn5-0006qn-QR for importer@patchew.org; Fri, 17 Mar 2017 09:19:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corjg-0004YO-5j for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjf-0000mL-5I for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corjc-0000jN-6R; Fri, 17 Mar 2017 09:16:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3209D342C6D; Fri, 17 Mar 2017 13:16:00 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A20517F5F; Fri, 17 Mar 2017 13:15:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3209D342C6D Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3209D342C6D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:43 +0100 Message-Id: <1489756546-27142-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 17 Mar 2017 13:16:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/8] blockdev: fix bitmap clear undo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: John Snow Only undo the action if we actually prepared the action. Signed-off-by: John Snow Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- blockdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index f1f49bd..c5b2c2c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2047,7 +2047,9 @@ static void block_dirty_bitmap_clear_abort(BlkActionS= tate *common) BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, common, common); =20 - bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup); + if (state->backup) { + bdrv_undo_clear_dirty_bitmap(state->bitmap, state->backup); + } } =20 static void block_dirty_bitmap_clear_commit(BlkActionState *common) --=20 1.8.3.1 From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148975688140982.77511742976105; Fri, 17 Mar 2017 06:21:21 -0700 (PDT) Received: from localhost ([::1]:48986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corom-0008Qx-8X for importer@patchew.org; Fri, 17 Mar 2017 09:21:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corjh-0004Zq-Gh for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjg-0000mq-NP for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49174) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corjd-0000kr-S5; Fri, 17 Mar 2017 09:16:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2FA5C208063; Fri, 17 Mar 2017 13:16:01 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8070F17F5F; Fri, 17 Mar 2017 13:16:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E2FA5C208063 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E2FA5C208063 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:44 +0100 Message-Id: <1489756546-27142-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 17 Mar 2017 13:16:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/8] block: Propagate error in bdrv_open_backing_file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, 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 Signed-off-by: Fam Zheng Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block.c b/block.c index a77e8a0..e538084 100644 --- a/block.c +++ b/block.c @@ -2030,6 +2030,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, bdrv_set_backing_hd(bs, backing_hd, &local_err); bdrv_unref(backing_hd); if (local_err) { + error_propagate(errp, local_err); ret =3D -EINVAL; goto free_exit; } --=20 1.8.3.1 From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489756940343697.4202466805773; Fri, 17 Mar 2017 06:22:20 -0700 (PDT) Received: from localhost ([::1]:48997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corpi-0000hZ-Qv for importer@patchew.org; Fri, 17 Mar 2017 09:22:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corjo-0004fZ-4R for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjj-0000op-Ms for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39432) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corjg-0000md-Ne; Fri, 17 Mar 2017 09:16:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6C3331B319; Fri, 17 Mar 2017 13:16:04 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2105617F2A; Fri, 17 Mar 2017 13:16:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B6C3331B319 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B6C3331B319 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:45 +0100 Message-Id: <1489756546-27142-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 17 Mar 2017 13:16:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/8] thread-pool: add missing qemu_bh_cancel in completion function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Lieven commit 3c80ca15 fixed a deadlock scenarion with nested aio_poll invocations. However, the rescheduling of the completion BH introcuded unnecessary spinn= ing in the main-loop. On very fast file backends this can even lead to the "WARNING: I/O thread spun for 1000 iterations" message popping up. Callgrind reports about 3-4% less instructions with this patch running qemu-img bench on a ramdisk based VMDK file. Fixes: 3c80ca158c96ff902a30883a8933e755988948b1 Cc: qemu-stable@nongnu.org Signed-off-by: Peter Lieven Signed-off-by: Kevin Wolf --- util/thread-pool.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/thread-pool.c b/util/thread-pool.c index ce6cd30..610646d 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -188,6 +188,13 @@ restart: aio_context_release(pool->ctx); elem->common.cb(elem->common.opaque, elem->ret); aio_context_acquire(pool->ctx); + + /* We can safely cancel the completion_bh here regardless of s= omeone + * else having scheduled it meanwhile because we reenter the + * completion function anyway (goto restart). + */ + qemu_bh_cancel(pool->completion_bh); + qemu_aio_unref(elem); goto restart; } else { --=20 1.8.3.1 From nobody Mon May 6 05:04:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14897567883851014.4801290583698; Fri, 17 Mar 2017 06:19:48 -0700 (PDT) Received: from localhost ([::1]:48975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cornH-00073a-5C for importer@patchew.org; Fri, 17 Mar 2017 09:19:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1corjq-0004hh-T2 for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1corjp-0000qM-OZ for qemu-devel@nongnu.org; Fri, 17 Mar 2017 09:16:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43210) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1corjk-0000ol-1C; Fri, 17 Mar 2017 09:16:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FB6267ECB; Fri, 17 Mar 2017 13:16:08 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E82017F2A; Fri, 17 Mar 2017 13:16:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1FB6267ECB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1FB6267ECB From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 17 Mar 2017 14:15:46 +0100 Message-Id: <1489756546-27142-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1489756546-27142-1-git-send-email-kwolf@redhat.com> References: <1489756546-27142-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 17 Mar 2017 13:16:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 8/8] block: quiesce AioContext when detaching from it X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini While it is true that bdrv_set_aio_context only works on a single BlockDriverState subtree (see commit message for 53ec73e, "block: Use bdrv_drain to replace uncessary bdrv_drain_all", 2015-07-07), it works at the AioContext level rather than the BlockDriverState level. Therefore, it is also necessary to trigger pending bottom halves too, even if no requests are pending. For NBD this ensures that the aio_co_schedule of a previous call to nbd_attach_aio_context is completed before detaching from the old AioContext; it fixes qemu-iotest 094. Another similar bug happens when the VM is stopped and the virtio-blk dataplane irqfd is torn down. In this case it's possible that guest I/O gets stuck if notify_guest_bh was scheduled but doesn't run. Calling aio_poll from another AioContext is safe if non-blocking; races such as the one mentioned in the commit message for c9d1a56 ("block: only call aio_poll on the current thread's AioContext", 2016-10-28) are a concern for blocking calls. I considered other options, including: - moving the bs->wakeup mechanism to AioContext, and letting the caller check. This might work for virtio which has a clear place to wakeup (notify_place_bh) and check the condition (virtio_blk_data_plane_stop). For aio_co_schedule I couldn't find a clear place to check the condition. - adding a dummy oneshot bottom half and waiting for it to trigger. This has the complication that bottom half list is LIFO for historical reasons. There were performance issues caused by bottom half ordering in the past, so I decided against it for 2.9. Fixes: 99723548561978da8ef44cf804fb7912698f5d88 Reported-by: Max Reitz Reported-by: Halil Pasic Tested-by: Halil Pasic Signed-off-by: Paolo Bonzini Message-id: 20170314111157.14464-2-pbonzini@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block.c b/block.c index e538084..6e906ec 100644 --- a/block.c +++ b/block.c @@ -4350,8 +4350,15 @@ void bdrv_attach_aio_context(BlockDriverState *bs, =20 void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) { + AioContext *ctx; + bdrv_drain(bs); /* ensure there are no in-flight requests */ =20 + ctx =3D bdrv_get_aio_context(bs); + while (aio_poll(ctx, false)) { + /* wait for all bottom halves to execute */ + } + bdrv_detach_aio_context(bs); =20 /* This function executes in the old AioContext so acquire the new one= in --=20 1.8.3.1