From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560377950; cv=none; d=zoho.com; s=zohoarc; b=WLtlP8ywz3I+qHafbSIW2latJ3GpXcTL9LtQz5x/ORObbCqvRIh1Nj8iyDviLyqTQlbazptGRPE7/Ny7RL3m6ExYgxBwpbSjUNvMnv/WmFmwqEyPXM/8nyOQ+FaIh7069ag4xCw4IA7qulVupgoeptlbK6qo7otFS2IgNPW93mo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560377950; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=tL6WMd/bXmAAGC4e8JaTsx1wA84PU/ydd/XnpaPBEag=; b=hWkPkwPaMoDaOv37PLvX3qzCNug+Ow783eB+TFju/aqPJ0wkI1vi7kZuZK739anz+hlQnWYpol7olgru1uNE9t4k6rKfzhWcCq0h783IbNTNH8r6dqU7mvm7MsBUHyV3geJupJ/SKVCyITNoLBgY7aQBzosTswmuJMzS6l7myUQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560377950276922.6724664876655; Wed, 12 Jun 2019 15:19:10 -0700 (PDT) Received: from localhost ([::1]:35428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBa9-0004nL-UV for importer@patchew.org; Wed, 12 Jun 2019 18:19:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45123) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBRe-0006zh-Aa for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBRd-0007GV-4s for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43664) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBRa-0007D9-CT; Wed, 12 Jun 2019 18:10:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E52B30F1BA5; Wed, 12 Jun 2019 22:10:09 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69D5D5ED2F; Wed, 12 Jun 2019 22:10:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:23 +0200 Message-Id: <20190612221004.2317-2-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Jun 2019 22:10:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 01/42] block: Mark commit and mirror as filter drivers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The commit and mirror block nodes are filters, so they should be marked as such. (Strictly speaking, BDS.is_filter's documentation states that a filter's child must be bs->file. The following patch will relax this restriction, however.) Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/commit.c | 2 ++ block/mirror.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/block/commit.c b/block/commit.c index c815def89a..f20a26fecd 100644 --- a/block/commit.c +++ b/block/commit.c @@ -256,6 +256,8 @@ static BlockDriver bdrv_commit_top =3D { .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_commit_top_refresh_filename, .bdrv_child_perm =3D bdrv_commit_top_child_perm, + + .is_filter =3D true, }; =20 void commit_start(const char *job_id, BlockDriverState *bs, diff --git a/block/mirror.c b/block/mirror.c index f8bdb5b21b..4fa8f57c80 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1480,6 +1480,8 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_mirror_top_refresh_filename, .bdrv_child_perm =3D bdrv_mirror_top_child_perm, + + .is_filter =3D true, }; =20 static void mirror_start_job(const char *job_id, BlockDriverState *bs, --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378106; cv=none; d=zoho.com; s=zohoarc; b=FIHbSBwPNXV6FORPjRrZQeIVZMwkepOhS5WX6j7Q4Pg0+7j4uqR9l446OorlmtZjijWveRu/kMFa4lgc6WkCQQtmEN/EmdJed0xNJTeYN7sbcnoivWujIK98z71gzrcWQ0YxxvqtrdkF9JSY8SqXRNF393J6wk1BD2iEsvAU9cM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378106; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=XcRvzfSJ6rV2DgHUdSEeF6CJyXrJjbtEVSecck+z48g=; b=bGWisoD7icaYWc0SK72CaO4PCwC6rCoF29BSKSGbnCbEsQDyTlK6DVZvJ9yjYlQx8leHSPfmRkn/GWI8RwL5T9wZXw9U8xouURQm1Qjo4D6VYl8JhniQxAkRbbRCYddHXEbOCGX0h+MPM39R4AqHxYXxm/q+IXvdZZhqMC00p7c= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378106230687.124670762979; Wed, 12 Jun 2019 15:21:46 -0700 (PDT) Received: from localhost ([::1]:35438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBcn-00061K-8k for importer@patchew.org; Wed, 12 Jun 2019 18:21:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45156) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBRg-00075u-94 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBRf-0007I6-7h for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBRc-0007Fv-Vs; Wed, 12 Jun 2019 18:10:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 362A13003A4D; Wed, 12 Jun 2019 22:10:12 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B94247E672; Wed, 12 Jun 2019 22:10:11 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:24 +0200 Message-Id: <20190612221004.2317-3-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 12 Jun 2019 22:10:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 02/42] copy-on-read: Support compressed writes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/copy-on-read.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 53972b1da3..88e1c1f538 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -114,6 +114,16 @@ static int coroutine_fn cor_co_pdiscard(BlockDriverSta= te *bs, } =20 =20 +static int coroutine_fn cor_co_pwritev_compressed(BlockDriverState *bs, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov) +{ + return bdrv_co_pwritev(bs->file, offset, bytes, qiov, + BDRV_REQ_WRITE_COMPRESSED); +} + + static void cor_eject(BlockDriverState *bs, bool eject_flag) { bdrv_eject(bs->file->bs, eject_flag); @@ -146,6 +156,7 @@ static BlockDriver bdrv_copy_on_read =3D { .bdrv_co_pwritev =3D cor_co_pwritev, .bdrv_co_pwrite_zeroes =3D cor_co_pwrite_zeroes, .bdrv_co_pdiscard =3D cor_co_pdiscard, + .bdrv_co_pwritev_compressed =3D cor_co_pwritev_compressed, =20 .bdrv_eject =3D cor_eject, .bdrv_lock_medium =3D cor_lock_medium, --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560377620; cv=none; d=zoho.com; s=zohoarc; b=XNoYO4QtreYkllW4Q7mLheRAT2TE6eka/ACARt9zt/3JkDLrjxyOZdNKRacduNxsnuE5CqXH6P6UmJaywKlGg509UNBGmfJ6jszBVvLHxFwgzE1yBFObC+XMbxMZMtvDIvYdUnpE8p4aDtkWPWEdHM6OAC8IuaIXY7dKn7ZUq2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560377620; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=rktNofkK3f6r2p2+WEPR9B9twi3gliCuxey1IFrugPA=; b=LKhKhflcCM7MSwDkw+aXrXDAeVRhLV1/LIwkWLx7F+h0RnYxq987w5btpc0OvB/Uqt26/ue9drPsfrzpK1NxMftgmYwMyNmwiNLIMKqnHRBlddGU5qiPK3lk+QlcWjkRsHq2ZGDqkLy0ygEsFw6WZY8Bp2/MIbblscf7zGZ/8J0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560377620713841.5896635847014; Wed, 12 Jun 2019 15:13:40 -0700 (PDT) Received: from localhost ([::1]:35388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBUs-0001Gm-Iw for importer@patchew.org; Wed, 12 Jun 2019 18:13:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45212) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBRk-0007Ao-Jf for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBRj-0007P2-8z for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBRf-0007Hl-Er; Wed, 12 Jun 2019 18:10:15 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5CC430860B8; Wed, 12 Jun 2019 22:10:14 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 461905DEDF; Wed, 12 Jun 2019 22:10:14 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:25 +0200 Message-Id: <20190612221004.2317-4-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 12 Jun 2019 22:10:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 03/42] throttle: Support compressed writes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/throttle.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/throttle.c b/block/throttle.c index f64dcc27b9..de1b6bd7e8 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -152,6 +152,15 @@ static int coroutine_fn throttle_co_pdiscard(BlockDriv= erState *bs, return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 +static int coroutine_fn throttle_co_pwritev_compressed(BlockDriverState *b= s, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov) +{ + return throttle_co_pwritev(bs, offset, bytes, qiov, + BDRV_REQ_WRITE_COMPRESSED); +} + static int throttle_co_flush(BlockDriverState *bs) { return bdrv_co_flush(bs->file->bs); @@ -250,6 +259,7 @@ static BlockDriver bdrv_throttle =3D { =20 .bdrv_co_pwrite_zeroes =3D throttle_co_pwrite_zeroes, .bdrv_co_pdiscard =3D throttle_co_pdiscard, + .bdrv_co_pwritev_compressed =3D throttle_co_pwritev_compress= ed, =20 .bdrv_recurse_is_first_non_filter =3D throttle_recurse_is_first_no= n_filter, =20 --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378293; cv=none; d=zoho.com; s=zohoarc; b=DW2NggWVw96+KB6yC+2qzh/PEN5A3oaWx5ZE9aKgyV9tMJYYLlE7DeP4i2KE6+AUj9+bhMzyIjn14U8lLFrLCaAXsq3lNXKEGswew7VrvygONdvHd5Lfg8gakVFvyEtXWWaFPe7eXBDnzbKYc24y6pgoLHXeYG7+rlCMyJHsnJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378293; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=G7Hfhs74XtOajvUgfDPvF90LZMuc3+KLYbCa1yIaae4=; b=ZseVnP+6OeGRQh/3XhTWfzhLH+CICVJGrfdLdFdkVd7G9tmcX+Z4tk28gyLvO9SyAmI/xlHOP6GA9P8ruKKQL2JcBdfJuuAgWFcGxU4rOXXIBFT5YLjsuKwm2l4+S2PHuEIbl6cQYQqXxe8aZUK3N7j7LAkQr06Hc99mTzF6KpQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378293094186.0235938445112; Wed, 12 Jun 2019 15:24:53 -0700 (PDT) Received: from localhost ([::1]:35474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBfc-0001LJ-3s for importer@patchew.org; Wed, 12 Jun 2019 18:24:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45278) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBRs-0007HO-BL for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBRo-0007Si-Jj for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43716) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBRi-0007N1-8X; Wed, 12 Jun 2019 18:10:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 764EC30992B3; Wed, 12 Jun 2019 22:10:17 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA1FC7E692; Wed, 12 Jun 2019 22:10:16 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:26 +0200 Message-Id: <20190612221004.2317-5-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Jun 2019 22:10:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 04/42] block: Add child access functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" There are BDS children that the general block layer code can access, namely bs->file and bs->backing. Since the introduction of filters and external data files, their meaning is not quite clear. bs->backing can be a COW source, or it can be an R/W-filtered child; bs->file can be an R/W-filtered child, it can be data and metadata storage, or it can be just metadata storage. This overloading really is not helpful. This patch adds function that retrieve the correct child for each exact purpose. Later patches in this series will make use of them. Doing so will allow us to handle filter nodes and external data files in a meaningful way. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 57 ++++++++++++++++++++-- block.c | 99 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 3 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 58fca37ba3..7ce71623f8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -90,9 +90,11 @@ struct BlockDriver { int instance_size; =20 /* set to true if the BlockDriver is a block filter. Block filters pass - * certain callbacks that refer to data (see block.c) to their bs->fil= e if - * the driver doesn't implement them. Drivers that do not wish to forw= ard - * must implement them and return -ENOTSUP. + * certain callbacks that refer to data (see block.c) to their bs->file + * or bs->backing (whichever one exists) if the driver doesn't impleme= nt + * them. Drivers that do not wish to forward must implement them and r= eturn + * -ENOTSUP. + * Note that filters are not allowed to modify data. */ bool is_filter; /* for snapshots block filter like Quorum can implement the @@ -562,6 +564,13 @@ struct BlockDriver { * If this pointer is NULL, the array is considered empty. * "filename" and "driver" are always considered strong. */ const char *const *strong_runtime_opts; + + /** + * Return the data storage child, if there is exactly one. If + * this function is not implemented, the block layer will assume + * bs->file to be this child. + */ + BdrvChild *(*bdrv_storage_child)(BlockDriverState *bs); }; =20 typedef struct BlockLimits { @@ -1249,4 +1258,46 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *sr= c, uint64_t src_offset, =20 int refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 +BdrvChild *bdrv_filtered_cow_child(BlockDriverState *bs); +BdrvChild *bdrv_filtered_rw_child(BlockDriverState *bs); +BdrvChild *bdrv_filtered_child(BlockDriverState *bs); +BdrvChild *bdrv_metadata_child(BlockDriverState *bs); +BdrvChild *bdrv_storage_child(BlockDriverState *bs); +BdrvChild *bdrv_primary_child(BlockDriverState *bs); + +static inline BlockDriverState *child_bs(BdrvChild *child) +{ + return child ? child->bs : NULL; +} + +static inline BlockDriverState *bdrv_filtered_cow_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filtered_cow_child(bs)); +} + +static inline BlockDriverState *bdrv_filtered_rw_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filtered_rw_child(bs)); +} + +static inline BlockDriverState *bdrv_filtered_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filtered_child(bs)); +} + +static inline BlockDriverState *bdrv_metadata_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_metadata_child(bs)); +} + +static inline BlockDriverState *bdrv_storage_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_storage_child(bs)); +} + +static inline BlockDriverState *bdrv_primary_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_primary_child(bs)); +} + #endif /* BLOCK_INT_H */ diff --git a/block.c b/block.c index 6bc51e371f..724d8889a6 100644 --- a/block.c +++ b/block.c @@ -6395,3 +6395,102 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverSta= te *bs, const char *name, =20 return drv->bdrv_can_store_new_dirty_bitmap(bs, name, granularity, err= p); } + +/* + * Return the child that @bs acts as an overlay for, and from which data m= ay be + * copied in COW or COR operations. Usually this is the backing file. + */ +BdrvChild *bdrv_filtered_cow_child(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return NULL; + } + + if (bs->drv->is_filter) { + return NULL; + } + + return bs->backing; +} + +/* + * If @bs acts as a pass-through filter for one of its children, + * return that child. "Pass-through" means that write operations to + * @bs are forwarded to that child instead of triggering COW. + */ +BdrvChild *bdrv_filtered_rw_child(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return NULL; + } + + if (!bs->drv->is_filter) { + return NULL; + } + + /* Only one of @backing or @file may be used */ + assert(!(bs->backing && bs->file)); + + return bs->backing ?: bs->file; +} + +/* + * Return any filtered child, independently of how it reacts to write + * accesses and whether data is copied onto this BDS through COR. + */ +BdrvChild *bdrv_filtered_child(BlockDriverState *bs) +{ + BdrvChild *cow_child =3D bdrv_filtered_cow_child(bs); + BdrvChild *rw_child =3D bdrv_filtered_rw_child(bs); + + /* There can only be one filtered child at a time */ + assert(!(cow_child && rw_child)); + + return cow_child ?: rw_child; +} + +/* + * Return the child that stores the metadata for this node. + */ +BdrvChild *bdrv_metadata_child(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return NULL; + } + + /* Filters do not have metadata */ + if (bs->drv->is_filter) { + return NULL; + } + + return bs->file; +} + +/* + * Return the child that stores the data that is allocated on this + * node. This may or may not include metadata. + */ +BdrvChild *bdrv_storage_child(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return NULL; + } + + if (bs->drv->bdrv_storage_child) { + return bs->drv->bdrv_storage_child(bs); + } + + return bdrv_filtered_rw_child(bs) ?: bs->file; +} + +/* + * Return the primary child of this node: For filters, that is the + * filtered child. For other nodes, that is usually the child storing + * metadata. + * (A generally more helpful description is that this is (usually) the + * child that has the same filename as @bs.) + */ +BdrvChild *bdrv_primary_child(BlockDriverState *bs) +{ + return bdrv_filtered_rw_child(bs) ?: bs->file; +} --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378478; cv=none; d=zoho.com; s=zohoarc; b=NcYp2XlrdbKGbbU3xoB7C/RpA4t9CJtZ8JVI3uvEtAyPrkfhYyHrnD3UY2N4oTRPQ6+gkF7dR+7pY1+K/6oCI/H5V4BZb8pl0BYvYOdSY8Jpu3iDGXNCRKdWJ9TxrZC2rgRnNtvVy4iDVf9iEfZlSOiRsh0WnhXHHgt8TKgkeF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378478; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VEKVgb/WNq8GZW6iR6E7hfJVjWqs+Yss2F6t3KzSjwA=; b=FBvkeDnpILHtvVc1c1xQFE1GCl9sk/5aVQhCdl/7Sc7uYz01co7VTnMPJHQUxyZ3EvyBdS2hU0X3JSr7Q7N66DjSKRh1CQLoJo9UcWyWO9ZT2Bln5Igm+ymx8LpUlk1nEmYLbhKl2n84R0xAflm7nBEyTBHi2HJcpgmPx+g5JiA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378478210798.6494152275537; Wed, 12 Jun 2019 15:27:58 -0700 (PDT) Received: from localhost ([::1]:35502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBik-0005Bt-8c for importer@patchew.org; Wed, 12 Jun 2019 18:27:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45320) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBRw-0007Iq-88 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBRu-0007WS-E0 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40826) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBRm-0007QJ-DF; Wed, 12 Jun 2019 18:10:24 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07DBC7FDFF; Wed, 12 Jun 2019 22:10:20 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B8131001B0F; Wed, 12 Jun 2019 22:10:19 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:27 +0200 Message-Id: <20190612221004.2317-6-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Jun 2019 22:10:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 05/42] block: Add chain helper functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add some helper functions for skipping filters in a chain of block nodes. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 3 +++ block.c | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 7ce71623f8..875a33f255 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1264,6 +1264,9 @@ BdrvChild *bdrv_filtered_child(BlockDriverState *bs); BdrvChild *bdrv_metadata_child(BlockDriverState *bs); BdrvChild *bdrv_storage_child(BlockDriverState *bs); BdrvChild *bdrv_primary_child(BlockDriverState *bs); +BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs); +BlockDriverState *bdrv_skip_rw_filters(BlockDriverState *bs); +BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs); =20 static inline BlockDriverState *child_bs(BdrvChild *child) { diff --git a/block.c b/block.c index 724d8889a6..be18130944 100644 --- a/block.c +++ b/block.c @@ -6494,3 +6494,58 @@ BdrvChild *bdrv_primary_child(BlockDriverState *bs) { return bdrv_filtered_rw_child(bs) ?: bs->file; } + +static BlockDriverState *bdrv_skip_filters(BlockDriverState *bs, + bool stop_on_explicit_filter) +{ + BdrvChild *filtered; + + if (!bs) { + return NULL; + } + + while (!(stop_on_explicit_filter && !bs->implicit)) { + filtered =3D bdrv_filtered_rw_child(bs); + if (!filtered) { + break; + } + bs =3D filtered->bs; + } + /* + * Note that this treats nodes with bs->drv =3D=3D NULL as not being + * R/W filters (bs->drv =3D=3D NULL should be replaced by something + * else anyway). + * The advantage of this behavior is that this function will thus + * always return a non-NULL value (given a non-NULL @bs). + */ + + return bs; +} + +/* + * Return the first BDS that has not been added implicitly or that + * does not have an RW-filtered child down the chain starting from @bs + * (including @bs itself). + */ +BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs) +{ + return bdrv_skip_filters(bs, true); +} + +/* + * Return the first BDS that does not have an RW-filtered child down + * the chain starting from @bs (including @bs itself). + */ +BlockDriverState *bdrv_skip_rw_filters(BlockDriverState *bs) +{ + return bdrv_skip_filters(bs, false); +} + +/* + * For a backing chain, return the first non-filter backing image of + * the first non-filter image. + */ +BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs) +{ + return bdrv_skip_rw_filters(bdrv_filtered_cow_bs(bdrv_skip_rw_filters(= bs))); +} --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378689; cv=none; d=zoho.com; s=zohoarc; b=F7Hs1uXaG8+qBakChNFOktOgc3e5QmIPXXyLkPFCnWPYp2s1OKdZuwCmt7tViV3MMKpXmoK6f7QXbh/AqPz6f8YiIystHcA/MDrFkjtcrtfVRUHzCpxQxdkd+Xww6uGZha4AkNc7ry4rI1bl6DWWYQPtwkpBSfarfHfXGvoG6s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378689; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=TT8+1id/gU5W47qYK1byR3X5QZnMFKrmnS2H2vUMXpc=; b=VSCmpYO2BrPY5ZyTfJZTImZ79WttuR0Is9fkX+ReP3KU9rLI5XS86cQvPtiaPGdUxIiPTL5dDMikgx0WzR+UFc12B1EF7KMTRQl+C7uNs1WEXstPd9MukCwhNWS21wLlZqTpiexyKDIxTkpXIF4mfyZPQiv+TgKVet6Av1hfo74= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378689798916.4306656463501; Wed, 12 Jun 2019 15:31:29 -0700 (PDT) Received: from localhost ([::1]:35532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBmA-0001E4-RA for importer@patchew.org; Wed, 12 Jun 2019 18:31:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45336) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBRx-0007Ir-7w for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBRu-0007WR-EN for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35110) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBRo-0007Ru-JT; Wed, 12 Jun 2019 18:10:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8785930BBE84; Wed, 12 Jun 2019 22:10:22 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17A7460192; Wed, 12 Jun 2019 22:10:21 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:28 +0200 Message-Id: <20190612221004.2317-7-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 12 Jun 2019 22:10:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 06/42] qcow2: Implement .bdrv_storage_child() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 9396d490d5..57675c9416 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5085,6 +5085,13 @@ void qcow2_signal_corruption(BlockDriverState *bs, b= ool fatal, int64_t offset, s->signaled_corruption =3D true; } =20 +static BdrvChild *qcow2_storage_child(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + + return s->data_file; +} + static QemuOptsList qcow2_create_opts =3D { .name =3D "qcow2-create-opts", .head =3D QTAILQ_HEAD_INITIALIZER(qcow2_create_opts.head), @@ -5231,6 +5238,8 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_reopen_bitmaps_rw =3D qcow2_reopen_bitmaps_rw, .bdrv_can_store_new_dirty_bitmap =3D qcow2_can_store_new_dirty_bitmap, .bdrv_remove_persistent_dirty_bitmap =3D qcow2_remove_persistent_dirty= _bitmap, + + .bdrv_storage_child =3D qcow2_storage_child, }; =20 static void bdrv_qcow2_init(void) --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379079; cv=none; d=zoho.com; s=zohoarc; b=C8ZEbGFXxcpp6yjV80zvQtsE9bD3eKhTzCuUDy9t5PyC5Y0fPeZpl71dF/TgYXgNZqnyqntgmCozT+6LjQw8S8FjIph0ND73yw79oeRWPTLVwC8rCJCLvjQYau0vjzEfcsjF7+HQFKAIVV9CtM/QIBa0XxV28do3yz+eNr/PJC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379079; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=JdeiEocSbSxaXI1Zi1svlWbdQWmNH+lTLxW/rTJ+d4s=; b=lObz5viIxfEBzXMau5HS4kyaGZXVfUEcJuMCEeCJhEpnhZMYWklRXekLP6o21v+cgEZjVZrObahAfnfrtrVhaHR0qHW7VK5itTb0evFd3lrRzCF7pm+QcOQWKMEYQWTdobpezdcXvteI27zcKo+udiY6H1wnVWACIrFTPDWhlqY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379079943307.7231020687972; Wed, 12 Jun 2019 15:37:59 -0700 (PDT) Received: from localhost ([::1]:35566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBsU-000603-Qj for importer@patchew.org; Wed, 12 Jun 2019 18:37:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45475) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBS4-0007Ss-6i for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBS3-0007eQ-0b for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32832) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS0-0007T7-65; Wed, 12 Jun 2019 18:10:36 -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 156303082126; Wed, 12 Jun 2019 22:10:25 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9937E64036; Wed, 12 Jun 2019 22:10:24 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:29 +0200 Message-Id: <20190612221004.2317-8-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 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.42]); Wed, 12 Jun 2019 22:10:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 07/42] block: *filtered_cow_child() for *has_zero_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_has_zero_init() and the related bdrv_unallocated_blocks_are_zero() should use bdrv_filtered_cow_child() if they want to check whether the given BDS has a COW backing file. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index be18130944..64d6190984 100644 --- a/block.c +++ b/block.c @@ -4933,7 +4933,7 @@ int bdrv_has_zero_init(BlockDriverState *bs) =20 /* If BS is a copy on write image, it is initialized to the contents of the base image, which may not be zeroes. */ - if (bs->backing) { + if (bdrv_filtered_cow_child(bs)) { return 0; } if (bs->drv->bdrv_has_zero_init) { @@ -4951,7 +4951,7 @@ bool bdrv_unallocated_blocks_are_zero(BlockDriverStat= e *bs) { BlockDriverInfo bdi; =20 - if (bs->backing) { + if (bdrv_filtered_cow_child(bs)) { return false; } =20 --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378351; cv=none; d=zoho.com; s=zohoarc; b=Lx6zKcQbs17Vgi+FikRbQL11kPVPRXYYhl7S1qPMw/HWBdo6Q06qnciVHGmN7vecfPhliG01JWDNQCztMbcfRMOjAkYx7tIouSyFXVgYcac5Aczh2Qk/JH4ZVhrMpnIbRI66pzFuFbvrPoZG1EKb8dWOzSobZLrq/HWdbKrOAFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378351; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=146+ZpXWUeTxMQ2/KY2XJB5tCaHjy2TWVY/tYgZjBoA=; b=A4jaq3Lz/SfzN4n/5xweX83E0J3iIjlVBTAbH6HAemLUhx/UbX7GyCqgjES9pUQtbyZKmWOzMK+jYWAor5+O1je6l09jYqEiNPOY/A1HpZojvzKp9FptFua6LfkgzgfL1ZWnwD1kmxgb5hD5gvcU+iX8hHCalo8M3bbMSMvqGSE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378351244882.8246817831367; Wed, 12 Jun 2019 15:25:51 -0700 (PDT) Received: from localhost ([::1]:35480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBgk-0002C9-AQ for importer@patchew.org; Wed, 12 Jun 2019 18:25:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45511) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBS5-0007Uf-GE for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBS2-0007e7-NH for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBRx-0007Ug-7d; Wed, 12 Jun 2019 18:10:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 916FB2CE945; Wed, 12 Jun 2019 22:10:27 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 229DB60185; Wed, 12 Jun 2019 22:10:26 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:30 +0200 Message-Id: <20190612221004.2317-9-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 12 Jun 2019 22:10:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 08/42] block: bdrv_set_backing_hd() is about bs->backing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_set_backing_hd() is a function that explicitly cares about the bs->backing child. Highlight that in its description and use child_bs(bs->backing) instead of backing_bs(bs) to make it more obvious. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy ] --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 64d6190984..8438b0699e 100644 --- a/block.c +++ b/block.c @@ -2417,7 +2417,7 @@ static bool bdrv_inherits_from_recursive(BlockDriverS= tate *child, } =20 /* - * Sets the backing file link of a BDS. A new reference is created; callers + * Sets the bs->backing link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref(). */ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d, @@ -2426,7 +2426,7 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd, bool update_inherits_from =3D bdrv_chain_contains(bs, backing_hd) && bdrv_inherits_from_recursive(backing_hd, bs); =20 - if (bdrv_is_backing_chain_frozen(bs, backing_bs(bs), errp)) { + if (bdrv_is_backing_chain_frozen(bs, child_bs(bs->backing), errp)) { return; } =20 --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378497; cv=none; d=zoho.com; s=zohoarc; b=hVQYyOK0PeBaX1wnE8Z8qPDhvFR1xx+p9daA8aAWEz9a50XNxaFE3nlaGgu+KUWAQerUyl+XKG/975YRBBq25rQT2HYnziq00MwLlssQ8dCD9t7p/vAmds0cNExeoIg2OVJuRQY2qjGCavLtqp6GtOYP2rdVEzZ43CnyUMoUT6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378497; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ga3Hux4e2POCjLE9uf6KgC8RNmFxtRe2yl/IpkRLXIg=; b=dmbqawDdZKLMXP44PQhB9A3Lbij+QjVt+g7WTGuwk/AvjG1QFy9Vk2d5sDgv0kXbkkx9X/fhsr8vUV65s8Sj12fslB2Wns5qCVxzM1U8/LsDa9H1l470JT0qy7q/NqWOJLW+B3ZNgF0Zt7sQdgQnPXBHyAVijf3XXvAI0SVOeFg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378497163782.1815971647745; Wed, 12 Jun 2019 15:28:17 -0700 (PDT) Received: from localhost ([::1]:35506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBj4-00067x-4l for importer@patchew.org; Wed, 12 Jun 2019 18:28:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45532) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBS6-0007WF-5n for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBS4-0007ff-Mt for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS0-0007W8-3g; Wed, 12 Jun 2019 18:10:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D9C2C04AC69; Wed, 12 Jun 2019 22:10:30 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A11D05DEDF; Wed, 12 Jun 2019 22:10:29 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:31 +0200 Message-Id: <20190612221004.2317-10-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Jun 2019 22:10:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 09/42] block: Include filters when freezing backing chain X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In order to make filters work in backing chains, the associated functions must be able to deal with them and freeze all filter links, be they COW or R/W filter links. While at it, add some comments that note which functions require their caller to ensure that a given child link is not frozen, and how the callers do so. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 8438b0699e..45882a3470 100644 --- a/block.c +++ b/block.c @@ -2214,12 +2214,15 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, * If @new_bs is not NULL, bdrv_check_perm() must be called beforehand, as= this * function uses bdrv_set_perm() to update the permissions according to th= e new * reference that @new_bs gets. + * + * Callers must ensure that child->frozen is false. */ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) { BlockDriverState *old_bs =3D child->bs; uint64_t perm, shared_perm; =20 + /* Asserts that child->frozen =3D=3D false */ bdrv_replace_child_noperm(child, new_bs); =20 if (old_bs) { @@ -2360,6 +2363,7 @@ static void bdrv_detach_child(BdrvChild *child) g_free(child); } =20 +/* Callers must ensure that child->frozen is false. */ void bdrv_root_unref_child(BdrvChild *child) { BlockDriverState *child_bs; @@ -2369,6 +2373,7 @@ void bdrv_root_unref_child(BdrvChild *child) bdrv_unref(child_bs); } =20 +/* Callers must ensure that child->frozen is false. */ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child) { if (child =3D=3D NULL) { @@ -2435,6 +2440,7 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd, } =20 if (bs->backing) { + /* Cannot be frozen, we checked that above */ bdrv_unref_child(bs, bs->backing); } =20 @@ -3908,6 +3914,7 @@ static void bdrv_close(BlockDriverState *bs) =20 if (bs->drv) { if (bs->drv->bdrv_close) { + /* Must unfreeze all children, so bdrv_unref_child() works */ bs->drv->bdrv_close(bs); } bs->drv =3D NULL; @@ -4281,17 +4288,20 @@ BlockDriverState *bdrv_find_base(BlockDriverState *= bs) * Return true if at least one of the backing links between @bs and * @base is frozen. @errp is set if that's the case. * @base must be reachable from @bs, or NULL. + * (Filters are treated as normal elements of the backing chain.) */ bool bdrv_is_backing_chain_frozen(BlockDriverState *bs, BlockDriverState *= base, Error **errp) { BlockDriverState *i; + BdrvChild *child; =20 - for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { - if (i->backing && i->backing->frozen) { + for (i =3D bs; i !=3D base; i =3D child_bs(child)) { + child =3D bdrv_filtered_child(i); + + if (child && child->frozen) { error_setg(errp, "Cannot change '%s' link from '%s' to '%s'", - i->backing->name, i->node_name, - backing_bs(i)->node_name); + child->name, i->node_name, child->bs->node_name); return true; } } @@ -4305,19 +4315,22 @@ bool bdrv_is_backing_chain_frozen(BlockDriverState = *bs, BlockDriverState *base, * none of the links are modified. * @base must be reachable from @bs, or NULL. * Returns 0 on success. On failure returns < 0 and sets @errp. + * (Filters are treated as normal elements of the backing chain.) */ int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base, Error **errp) { BlockDriverState *i; + BdrvChild *child; =20 if (bdrv_is_backing_chain_frozen(bs, base, errp)) { return -EPERM; } =20 - for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { - if (i->backing) { - i->backing->frozen =3D true; + for (i =3D bs; i !=3D base; i =3D child_bs(child)) { + child =3D bdrv_filtered_child(i); + if (child) { + child->frozen =3D true; } } =20 @@ -4328,15 +4341,18 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs,= BlockDriverState *base, * Unfreeze all backing links between @bs and @base. The caller must * ensure that all links are frozen before using this function. * @base must be reachable from @bs, or NULL. + * (Filters are treated as normal elements of the backing chain.) */ void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *b= ase) { BlockDriverState *i; + BdrvChild *child; =20 - for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { - if (i->backing) { - assert(i->backing->frozen); - i->backing->frozen =3D false; + for (i =3D bs; i !=3D base; i =3D child_bs(child)) { + child =3D bdrv_filtered_child(i); + if (child) { + assert(child->frozen); + child->frozen =3D false; } } } @@ -4438,8 +4454,11 @@ int bdrv_drop_intermediate(BlockDriverState *top, Bl= ockDriverState *base, } } =20 - /* Do the actual switch in the in-memory graph. - * Completes bdrv_check_update_perm() transaction internally. */ + /* + * Do the actual switch in the in-memory graph. + * Completes bdrv_check_update_perm() transaction internally. + * c->frozen is false, we have checked that above. + */ bdrv_ref(base); bdrv_replace_child(c, base); bdrv_unref(top); --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378232; cv=none; d=zoho.com; s=zohoarc; b=TB7MFpOcQhOxALgkEMYy7AmF19KFu+ubmGllIcwWh7SZLE4WTTwN1+ZB9UU6ZbKb7WsJtTlQy09LHx9gEeNA6U5MNXistJJY35FZn6c7nUZBEux6IMhWlRJXmefwbxmcHHZb6fKIjbH5YRCnF9WhDXKSpclEHI+Tgqh0cuslMBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378232; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0NDPl1kBubFjrF8Wy6k2tc25rsdeP+iKePq7b3nxYe8=; b=eiUz+Dh7eoiToz3gyNVxDrLUE74CMTHPC3fh/u0w+rS61i7klZA3Jt6+C8ZUQPKdSMBMX/STZ4M0mbLeJ8eNoJL9B/exv5EG7Wr97NAKZWImV1sZe8kjqRLu6B0UX7NbJxnUqHUp1yehj7V6e4t1DvsHxxjemL3k5VdyAifo8Rk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378232174770.5379048694477; Wed, 12 Jun 2019 15:23:52 -0700 (PDT) Received: from localhost ([::1]:35472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBem-0000f8-Pd for importer@patchew.org; Wed, 12 Jun 2019 18:23:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45476) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBS4-0007Sv-98 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBS2-0007eF-Pv for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS0-0007YS-3K; Wed, 12 Jun 2019 18:10:36 -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 A5B2C81E0E; Wed, 12 Jun 2019 22:10:32 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32FC7608A6; Wed, 12 Jun 2019 22:10:32 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:32 +0200 Message-Id: <20190612221004.2317-11-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 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.25]); Wed, 12 Jun 2019 22:10:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 10/42] block: Use CAF in bdrv_is_encrypted() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_is_encrypted() should not only check the BDS's backing child, but any filtered child: If a filter's child is encrypted, the filter node itself naturally is encrypted, too. Furthermore, we need to recurse down the chain. (CAF means child access function.) Signed-off-by: Max Reitz --- block.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 45882a3470..567a0f82c8 100644 --- a/block.c +++ b/block.c @@ -4574,10 +4574,14 @@ bool bdrv_is_sg(BlockDriverState *bs) =20 bool bdrv_is_encrypted(BlockDriverState *bs) { - if (bs->backing && bs->backing->bs->encrypted) { + BlockDriverState *filtered =3D bdrv_filtered_bs(bs); + if (bs->encrypted) { return true; } - return bs->encrypted; + if (filtered && bdrv_is_encrypted(filtered)) { + return true; + } + return false; } =20 const char *bdrv_get_format_name(BlockDriverState *bs) --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378144; cv=none; d=zoho.com; s=zohoarc; b=KlwbiCjaTGH30AQWCVadi/mH9TDqD9cVZ7WVLBkq7yCWm9vsRTER+ZJKajZbefK+THfO4r8kawBwvRAsdITBbVRzV3EON42R0EcBSt/DH/sYBQ4bKjva/at8c5WEA2S9L98is6tVlUFdc1spHe4XUJa8uibLMJw/UqoGs6yIE2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378144; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vEznUzoRNrS5WxEnmt4CoSZzMItxwSLSx2vMRwrvtyY=; b=ZPVLM/BTst7AP58PFywAET5qGULtk99b4t6syA2rt4mikzuQ23jYOHmql0t9Mvz0wpVzBFmFgkUYs8scyRlxhJlWGDRUMXG/IkLDArN38ZQjUCWgXy7QWc+uBS3ECJlQK8sAz3mIBAiJawkYdHr8BTxXFL+TVgQcjt0NOksjGls= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378144641187.75526138905195; Wed, 12 Jun 2019 15:22:24 -0700 (PDT) Received: from localhost ([::1]:35454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBdM-0007Bm-Ca for importer@patchew.org; Wed, 12 Jun 2019 18:22:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45496) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBS4-0007Tn-S1 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBS3-0007el-Hj for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43036) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS0-0007aC-AL; Wed, 12 Jun 2019 18:10:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FAD52F8BE8; Wed, 12 Jun 2019 22:10:35 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B19EE1710F; Wed, 12 Jun 2019 22:10:34 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:33 +0200 Message-Id: <20190612221004.2317-12-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 12 Jun 2019 22:10:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 11/42] block: Add bdrv_supports_compressed_writes() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Filters cannot compress data themselves but they have to implement .bdrv_co_pwritev_compressed() still (or they cannot forward compressed writes). Therefore, checking whether bs->drv->bdrv_co_pwritev_compressed is non-NULL is not sufficient to know whether the node can actually handle compressed writes. This function looks down the filter chain to see whether there is a non-filter that can actually convert the compressed writes into compressed data (and thus normal writes). Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block.h | 1 + block.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index 687c03b275..7835c5b370 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -487,6 +487,7 @@ void bdrv_next_cleanup(BdrvNextIterator *it); =20 BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs); bool bdrv_is_encrypted(BlockDriverState *bs); +bool bdrv_supports_compressed_writes(BlockDriverState *bs); void bdrv_iterate_format(void (*it)(void *opaque, const char *name), void *opaque, bool read_only); const char *bdrv_get_node_name(const BlockDriverState *bs); diff --git a/block.c b/block.c index 567a0f82c8..97774b7b06 100644 --- a/block.c +++ b/block.c @@ -4584,6 +4584,28 @@ bool bdrv_is_encrypted(BlockDriverState *bs) return false; } =20 +/** + * Return whether the given node supports compressed writes. + */ +bool bdrv_supports_compressed_writes(BlockDriverState *bs) +{ + BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); + + if (!bs->drv || !bs->drv->bdrv_co_pwritev_compressed) { + return false; + } + + if (filtered) { + /* + * Filters can only forward compressed writes, so we have to + * check the child. + */ + return bdrv_supports_compressed_writes(filtered); + } + + return true; +} + const char *bdrv_get_format_name(BlockDriverState *bs) { return bs->drv ? bs->drv->format_name : NULL; --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378431; cv=none; d=zoho.com; s=zohoarc; b=ciFmaQrYzxdREVk0MNyPpP9gN2AEUnW5m4R8s119skpGEz3V6z2gCeTT1xFpI7OpXpPuh+NepiLG0yNUNSmt3L5Ww+f9gp1pgp59VMGJo3wsCUrNezM+/A8d1TclztOYNjYMilNnGemTfVzPuhjm2qRM7CnqD5BR+WJkaT1PyHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378431; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=uxHUv21U7F6r3D+cPAmo4CAM8hSAFX5uf4bo/A/8uQY=; b=NHHNe/sC8KZrqmFIFRGbZLo/dley0XSr0vikUKL10bQNbmYhXYgw3/bdkGQN3ynB3dwULyyLooUMDbbbGfqewuXnlHaqS7Wgn9IlEJbZ83jz/17Xwf2eCnM+kS1Mvlh6JFgbKAv6155w5b4ZWSCMCmjVjVlXTFxX7qaqMdc0p3M= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378431417392.88127681044307; Wed, 12 Jun 2019 15:27:11 -0700 (PDT) Received: from localhost ([::1]:35500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBi0-0004XR-Cj for importer@patchew.org; Wed, 12 Jun 2019 18:27:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45549) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBS7-0007Yk-3g for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBS5-0007gd-Ue for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48868) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS2-0007dD-GQ; Wed, 12 Jun 2019 18:10:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD17EC18B2F3; Wed, 12 Jun 2019 22:10:37 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3DF8A5C236; Wed, 12 Jun 2019 22:10:37 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:34 +0200 Message-Id: <20190612221004.2317-13-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Jun 2019 22:10:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 12/42] block: Use bdrv_filtered_rw* where obvious X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Places that use patterns like if (bs->drv->is_filter && bs->file) { ... something about bs->file->bs ... } should be BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); if (filtered) { ... something about @filtered ... } instead. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 23 +++++++++++++++-------- block/io.c | 5 +++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 97774b7b06..11f37983d9 100644 --- a/block.c +++ b/block.c @@ -556,11 +556,12 @@ int bdrv_create_file(const char *filename, QemuOpts *= opts, Error **errp) int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) { BlockDriver *drv =3D bs->drv; + BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); =20 if (drv && drv->bdrv_probe_blocksizes) { return drv->bdrv_probe_blocksizes(bs, bsz); - } else if (drv && drv->is_filter && bs->file) { - return bdrv_probe_blocksizes(bs->file->bs, bsz); + } else if (filtered) { + return bdrv_probe_blocksizes(filtered, bsz); } =20 return -ENOTSUP; @@ -575,11 +576,12 @@ int bdrv_probe_blocksizes(BlockDriverState *bs, Block= Sizes *bsz) int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo) { BlockDriver *drv =3D bs->drv; + BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); =20 if (drv && drv->bdrv_probe_geometry) { return drv->bdrv_probe_geometry(bs, geo); - } else if (drv && drv->is_filter && bs->file) { - return bdrv_probe_geometry(bs->file->bs, geo); + } else if (filtered) { + return bdrv_probe_geometry(filtered, geo); } =20 return -ENOTSUP; @@ -4972,6 +4974,8 @@ int bdrv_has_zero_init_1(BlockDriverState *bs) =20 int bdrv_has_zero_init(BlockDriverState *bs) { + BlockDriverState *filtered; + if (!bs->drv) { return 0; } @@ -4984,8 +4988,10 @@ int bdrv_has_zero_init(BlockDriverState *bs) if (bs->drv->bdrv_has_zero_init) { return bs->drv->bdrv_has_zero_init(bs); } - if (bs->file && bs->drv->is_filter) { - return bdrv_has_zero_init(bs->file->bs); + + filtered =3D bdrv_filtered_rw_bs(bs); + if (filtered) { + return bdrv_has_zero_init(filtered); } =20 /* safe default */ @@ -5030,8 +5036,9 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverIn= fo *bdi) return -ENOMEDIUM; } if (!drv->bdrv_get_info) { - if (bs->file && drv->is_filter) { - return bdrv_get_info(bs->file->bs, bdi); + BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); + if (filtered) { + return bdrv_get_info(filtered, bdi); } return -ENOTSUP; } diff --git a/block/io.c b/block/io.c index 2408abffd9..73ade04834 100644 --- a/block/io.c +++ b/block/io.c @@ -3147,8 +3147,9 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, } =20 if (!drv->bdrv_co_truncate) { - if (bs->file && drv->is_filter) { - ret =3D bdrv_co_truncate(bs->file, offset, prealloc, errp); + BdrvChild *filtered =3D bdrv_filtered_rw_child(bs); + if (filtered) { + ret =3D bdrv_co_truncate(filtered, offset, prealloc, errp); goto out; } error_setg(errp, "Image format driver does not support resize"); --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378202; cv=none; d=zoho.com; s=zohoarc; b=SHa9dgIHi671uORTTZzprEhA8YsNFpSC1KUXTSnvQaRdccLkE77i+eIZSX9NaWPkqAAh42FMSCiJeT/YvBBXflxAouWSUkIHmLRGpNu1YHATBXlrivpV14CaCkh1EGdoQJJY3BV/l7vkE35NLim9nKeL3mlJyqkpc3lCnqnPLfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378202; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=s7TSZqyAxd1uKHN9P8llmemmcc+h+/g8mMtRp9/5Jks=; b=J+PwIwFdU/uEbubR/xNK3kh1foALNpOijUcOAENi9ok6aL26O75DBI1/vgSIb08tIAVrk7s1w7wklaXGyKuyIeHkRpF9gpIw8Oab5LRC/TTQCT2EmyKCAk5jqipjZg719J60ZLweZFsKpg7UBNjvqfnntJb034sCekRwmbrIR8A= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378202068849.863190255574; Wed, 12 Jun 2019 15:23:22 -0700 (PDT) Received: from localhost ([::1]:35466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBeK-000075-Tb for importer@patchew.org; Wed, 12 Jun 2019 18:23:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45570) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBS8-0007dc-O7 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBS7-0007hh-Kc for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS5-0007fY-2p; Wed, 12 Jun 2019 18:10:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 398762EF170; Wed, 12 Jun 2019 22:10:40 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC0CD6014E; Wed, 12 Jun 2019 22:10:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:35 +0200 Message-Id: <20190612221004.2317-14-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 12 Jun 2019 22:10:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 13/42] block: Use CAFs in block status functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use the child access functions in the block status inquiry functions as appropriate. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/block/io.c b/block/io.c index 73ade04834..53aabf86b5 100644 --- a/block/io.c +++ b/block/io.c @@ -2150,11 +2150,12 @@ static int coroutine_fn bdrv_co_block_status(BlockD= riverState *bs, if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) { ret |=3D BDRV_BLOCK_ALLOCATED; } else if (want_zero) { + BlockDriverState *cow_bs =3D bdrv_filtered_cow_bs(bs); + if (bdrv_unallocated_blocks_are_zero(bs)) { ret |=3D BDRV_BLOCK_ZERO; - } else if (bs->backing) { - BlockDriverState *bs2 =3D bs->backing->bs; - int64_t size2 =3D bdrv_getlength(bs2); + } else if (cow_bs) { + int64_t size2 =3D bdrv_getlength(cow_bs); =20 if (size2 >=3D 0 && offset >=3D size2) { ret |=3D BDRV_BLOCK_ZERO; @@ -2220,7 +2221,7 @@ static int coroutine_fn bdrv_co_block_status_above(Bl= ockDriverState *bs, bool first =3D true; =20 assert(bs !=3D base); - for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { + for (p =3D bs; p !=3D base; p =3D bdrv_filtered_bs(p)) { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); if (ret < 0) { @@ -2306,7 +2307,7 @@ int bdrv_block_status_above(BlockDriverState *bs, Blo= ckDriverState *base, int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) { - return bdrv_block_status_above(bs, backing_bs(bs), + return bdrv_block_status_above(bs, bdrv_filtered_bs(bs), offset, bytes, pnum, map, file); } =20 @@ -2316,9 +2317,9 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t offset, int ret; int64_t dummy; =20 - ret =3D bdrv_common_block_status_above(bs, backing_bs(bs), false, offs= et, - bytes, pnum ? pnum : &dummy, NULL, - NULL); + ret =3D bdrv_common_block_status_above(bs, bdrv_filtered_bs(bs), false, + offset, bytes, pnum ? pnum : &dum= my, + NULL, NULL); if (ret < 0) { return ret; } @@ -2372,7 +2373,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, n =3D pnum_inter; } =20 - intermediate =3D backing_bs(intermediate); + intermediate =3D bdrv_filtered_bs(intermediate); } =20 *pnum =3D n; --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378760; cv=none; d=zoho.com; s=zohoarc; b=lfT7kev9PQLudH/LoA5R4VlRe9Hg7NUqP4V43lfw/GojCgIvdlXmPMhY7r2fEvhlgaVcgZM2Sg1MlXLGfE0QAmEWnMyh7tnAiB8A4h/UjepGfVeqEouJBwAIuA1Z2BAnVB5ZSEQnwcYVyIIJu1jj9mDgyKQAn68J4cNjAgfRul8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378760; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=j8aiekTVxhuNqUGg3jatHqIztkIR0/EJ4M+XABb7K/w=; b=JguDStz1X+NznFhsbf/W2dSWFp5XfA/e2CnrrzSGGg5AxdUINg24q8+RtApD+CdeUfWcc5/7JUgdzDWgbrv+e+c3LTSroqKxS/079WUms+8yrx4XsgHVg3jl/MUld+SFy6jKLjwaPS6N+XU2kRct/YHD3uKGoNawon7J/5KnH00= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378759998139.22425420208776; Wed, 12 Jun 2019 15:32:39 -0700 (PDT) Received: from localhost ([::1]:35538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBnI-00028W-Sv for importer@patchew.org; Wed, 12 Jun 2019 18:32:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45607) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSB-0007kA-DV for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSA-0007iz-2x for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37240) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS7-0007hF-Dz; Wed, 12 Jun 2019 18:10:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B778780461; Wed, 12 Jun 2019 22:10:42 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 468887E692; Wed, 12 Jun 2019 22:10:42 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:36 +0200 Message-Id: <20190612221004.2317-15-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 12 Jun 2019 22:10:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 14/42] block: Use CAFs when working with backing chains X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use child access functions when iterating through backing chains so filters do not break the chain. Signed-off-by: Max Reitz --- block.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index 11f37983d9..505b3e9a01 100644 --- a/block.c +++ b/block.c @@ -4261,7 +4261,8 @@ int bdrv_change_backing_file(BlockDriverState *bs, } =20 /* - * Finds the image layer in the chain that has 'bs' as its backing file. + * Finds the image layer in the chain that has 'bs' (or a filter on + * top of it) as its backing file. * * active is the current topmost image. * @@ -4273,11 +4274,18 @@ int bdrv_change_backing_file(BlockDriverState *bs, BlockDriverState *bdrv_find_overlay(BlockDriverState *active, BlockDriverState *bs) { - while (active && bs !=3D backing_bs(active)) { - active =3D backing_bs(active); + bs =3D bdrv_skip_rw_filters(bs); + active =3D bdrv_skip_rw_filters(active); + + while (active) { + BlockDriverState *next =3D bdrv_backing_chain_next(active); + if (bs =3D=3D next) { + return active; + } + active =3D next; } =20 - return active; + return NULL; } =20 /* Given a BDS, searches for the base layer. */ @@ -4421,9 +4429,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, Blo= ckDriverState *base, * other intermediate nodes have been dropped. * If 'top' is an implicit node (e.g. "commit_top") we should skip * it because no one inherits from it. We use explicit_top for that. */ - while (explicit_top && explicit_top->implicit) { - explicit_top =3D backing_bs(explicit_top); - } + explicit_top =3D bdrv_skip_implicit_filters(explicit_top); update_inherits_from =3D bdrv_inherits_from_recursive(base, explicit_t= op); =20 /* success - we can delete the intermediate states, and link top->base= */ @@ -4902,7 +4908,7 @@ BlockDriverState *bdrv_lookup_bs(const char *device, bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base) { while (top && top !=3D base) { - top =3D backing_bs(top); + top =3D bdrv_filtered_bs(top); } =20 return top !=3D NULL; @@ -5141,7 +5147,17 @@ BlockDriverState *bdrv_find_backing_image(BlockDrive= rState *bs, =20 is_protocol =3D path_has_protocol(backing_file); =20 - for (curr_bs =3D bs; curr_bs->backing; curr_bs =3D curr_bs->backing->b= s) { + /* + * Being largely a legacy function, skip any filters here + * (because filters do not have normal filenames, so they cannot + * match anyway; and allowing json:{} filenames is a bit out of + * scope). + */ + for (curr_bs =3D bdrv_skip_rw_filters(bs); + bdrv_filtered_cow_child(curr_bs) !=3D NULL; + curr_bs =3D bdrv_backing_chain_next(curr_bs)) + { + BlockDriverState *bs_below =3D bdrv_backing_chain_next(curr_bs); =20 /* If either of the filename paths is actually a protocol, then * compare unmodified paths; otherwise make paths relative */ @@ -5149,7 +5165,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, char *backing_file_full_ret; =20 if (strcmp(backing_file, curr_bs->backing_file) =3D=3D 0) { - retval =3D curr_bs->backing->bs; + retval =3D bs_below; break; } /* Also check against the full backing filename for the image = */ @@ -5159,7 +5175,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, bool equal =3D strcmp(backing_file, backing_file_full_ret)= =3D=3D 0; g_free(backing_file_full_ret); if (equal) { - retval =3D curr_bs->backing->bs; + retval =3D bs_below; break; } } @@ -5185,7 +5201,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, g_free(filename_tmp); =20 if (strcmp(backing_file_full, filename_full) =3D=3D 0) { - retval =3D curr_bs->backing->bs; + retval =3D bs_below; break; } } --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378662; cv=none; d=zoho.com; s=zohoarc; b=dExYFdFEHQZg6X98Lzuuv6fPVL/CZQ4rqcZdqnJnmcWjaUyydHn8aWFtppAO0VEOLw2m7L4dsfobUdG5keE0pALKDmQiKgF7PRlHGNNeVhV9P/+p69xd+bRJTgsk1uUEneu0UWSBgGAeWGnk0aepUwm7j4cMVs8PL1I+v7ztK5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378662; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HFIeKHDcY87m482E3kT/fHsCIfj2+nJ+/uX79WPxzHY=; b=jH4WrrK6rD/htm+5dIfmzFMjyjNmkv4e3dmdiRRStIgi3bhfEekdGUGBf/UdjunOte8WN//xPeBJx7lofAZ+IAPz0mDduLl7MhD3W+0DboFga/pte4OdOEAryJXuESOCABDQFiBoMvlaslfrtNqarbAgpTHUVXbzsyeWCJY7omU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378662948467.96834316736965; Wed, 12 Jun 2019 15:31:02 -0700 (PDT) Received: from localhost ([::1]:35524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBll-00005H-OK for importer@patchew.org; Wed, 12 Jun 2019 18:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45654) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSE-0007qR-At for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSC-0007ks-UG for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBS9-0007id-VX; Wed, 12 Jun 2019 18:10:46 -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 3E9518F927; Wed, 12 Jun 2019 22:10:45 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4B8B60BF0; Wed, 12 Jun 2019 22:10:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:37 +0200 Message-Id: <20190612221004.2317-16-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 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.26]); Wed, 12 Jun 2019 22:10:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 15/42] block: Re-evaluate backing file handling in reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Reopening a node's backing child needs a bit of special handling because the "backing" child has different defaults than all other children (among other things). Adding filter support here is a bit more difficult than just using the child access functions. In fact, we often have to directly use bs->backing because these functions are about the "backing" child (which may or may not be the COW backing file). Signed-off-by: Max Reitz --- block.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 505b3e9a01..db2759c10d 100644 --- a/block.c +++ b/block.c @@ -3542,17 +3542,39 @@ static int bdrv_reopen_parse_backing(BDRVReopenStat= e *reopen_state, } } =20 + /* + * Ensure that @bs can really handle backing files, because we are + * about to give it one (or swap the existing one) + */ + if (bs->drv->is_filter) { + /* Filters always have a file or a backing child */ + if (!bs->backing) { + error_setg(errp, "'%s' is a %s filter node that does not suppo= rt a " + "backing child", bs->node_name, bs->drv->format_nam= e); + return -EINVAL; + } + } else if (!bs->drv->supports_backing) { + error_setg(errp, "Driver '%s' of node '%s' does not support backin= g " + "files", bs->drv->format_name, bs->node_name); + return -EINVAL; + } + /* * Find the "actual" backing file by skipping all links that point * to an implicit node, if any (e.g. a commit filter node). + * We cannot use any of the bdrv_skip_*() functions here because + * those return the first explicit node, while we are looking for + * its overlay here. */ overlay_bs =3D bs; - while (backing_bs(overlay_bs) && backing_bs(overlay_bs)->implicit) { - overlay_bs =3D backing_bs(overlay_bs); + while (bdrv_filtered_bs(overlay_bs) && + bdrv_filtered_bs(overlay_bs)->implicit) + { + overlay_bs =3D bdrv_filtered_bs(overlay_bs); } =20 /* If we want to replace the backing file we need some extra checks */ - if (new_backing_bs !=3D backing_bs(overlay_bs)) { + if (new_backing_bs !=3D bdrv_filtered_bs(overlay_bs)) { /* Check for implicit nodes between bs and its backing file */ if (bs !=3D overlay_bs) { error_setg(errp, "Cannot change backing link if '%s' has " @@ -3560,8 +3582,8 @@ static int bdrv_reopen_parse_backing(BDRVReopenState = *reopen_state, return -EPERM; } /* Check if the backing link that we want to replace is frozen */ - if (bdrv_is_backing_chain_frozen(overlay_bs, backing_bs(overlay_bs= ), - errp)) { + if (bdrv_is_backing_chain_frozen(overlay_bs, + child_bs(overlay_bs->backing), er= rp)) { return -EPERM; } reopen_state->replace_backing_bs =3D true; @@ -3712,7 +3734,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state= , BlockReopenQueue *queue, * its metadata. Otherwise the 'backing' option can be omitted. */ if (drv->supports_backing && reopen_state->backing_missing && - (backing_bs(reopen_state->bs) || reopen_state->bs->backing_file[0]= )) { + (reopen_state->bs->backing || reopen_state->bs->backing_file[0])) { error_setg(errp, "backing is missing for '%s'", reopen_state->bs->node_name); ret =3D -EINVAL; @@ -3857,7 +3879,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) * from bdrv_set_backing_hd()) has the new values. */ if (reopen_state->replace_backing_bs) { - BlockDriverState *old_backing_bs =3D backing_bs(bs); + BlockDriverState *old_backing_bs =3D child_bs(bs->backing); assert(!old_backing_bs || !old_backing_bs->implicit); /* Abort the permission update on the backing bs we're detaching */ if (old_backing_bs) { --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378415; cv=none; d=zoho.com; s=zohoarc; b=WtcznEZosuxNDoDT95uiJFlrIl7upOdQ3vdO9sBXmUtcQlxclKeXyk1v7BJ0OkBR5mTeSpd8yt2FOmtNDVGRqUq80ZbSzW+tFoCtJA5ONRpjkl1zKOIglsrBoulCw8EfZdYsw3fqjgLf1KKKTLmUPn76hbpVquA78kMNGLLmx28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378415; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VjdnHhwsK5jqfyDrNci+5WZwok/cX7jTDVMAKIifmqE=; b=nGrsQZodeVLmk90NZBGCT1kmdT2ZXpSuul+/DVCwujwYLtaN3pMzCOovRWSkKzH0+dmFLcAn968kQiTX8fAofnxtVmq3rCoRsZ5A1fVi1VP9TtKI+OD7E2yZvB7s6oVw79NPNUfDI35w2oFptmWBDTAO+JtHp1SAh9nE398zznU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378415281211.8654226414718; Wed, 12 Jun 2019 15:26:55 -0700 (PDT) Received: from localhost ([::1]:35496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBhj-0004Hg-2V for importer@patchew.org; Wed, 12 Jun 2019 18:26:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45694) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSG-0007uc-AD for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSF-0007mW-3x for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40926) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSC-0007k9-Fr; Wed, 12 Jun 2019 18:10:48 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF1267EBBD; Wed, 12 Jun 2019 22:10:47 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5070A7E672; Wed, 12 Jun 2019 22:10:47 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:38 +0200 Message-Id: <20190612221004.2317-17-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Jun 2019 22:10:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 16/42] block: Use child access functions when flushing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If the driver does not support .bdrv_co_flush() so bdrv_co_flush() itself has to flush the children of the given node, it should not flush just bs->file->bs, but in fact both the child that stores data, and the one that stores metadata (if they are separate). In any case, the BLKDBG_EVENT() should be emitted on the primary child, because that is where a blkdebug node would be if there is any. Signed-off-by: Max Reitz --- block/io.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 53aabf86b5..64408cf19a 100644 --- a/block/io.c +++ b/block/io.c @@ -2533,6 +2533,8 @@ static void coroutine_fn bdrv_flush_co_entry(void *op= aque) =20 int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { + BdrvChild *primary_child =3D bdrv_primary_child(bs); + BlockDriverState *storage_bs, *metadata_bs; int current_gen; int ret =3D 0; =20 @@ -2562,7 +2564,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) } =20 /* Write back cached data to the OS even with cache=3Dunsafe */ - BLKDBG_EVENT(bs->file, BLKDBG_FLUSH_TO_OS); + BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_OS); if (bs->drv->bdrv_co_flush_to_os) { ret =3D bs->drv->bdrv_co_flush_to_os(bs); if (ret < 0) { @@ -2580,7 +2582,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) goto flush_parent; } =20 - BLKDBG_EVENT(bs->file, BLKDBG_FLUSH_TO_DISK); + BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_DISK); if (!bs->drv) { /* bs->drv->bdrv_co_flush() might have ejected the BDS * (even in case of apparent success) */ @@ -2625,7 +2627,20 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) * in the case of cache=3Dunsafe, so there are no useless flushes. */ flush_parent: - ret =3D bs->file ? bdrv_co_flush(bs->file->bs) : 0; + storage_bs =3D bdrv_storage_bs(bs); + metadata_bs =3D bdrv_metadata_bs(bs); + + ret =3D 0; + if (storage_bs) { + ret =3D bdrv_co_flush(storage_bs); + } + if (metadata_bs && metadata_bs !=3D storage_bs) { + int ret_metadata =3D bdrv_co_flush(metadata_bs); + if (!ret) { + ret =3D ret_metadata; + } + } + out: /* Notify any pending flushes that we have completed */ if (ret =3D=3D 0) { --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379155; cv=none; d=zoho.com; s=zohoarc; b=BvT3cdmEEVeV5iS4rNom2tIpYONu92YV7n9DB909Z2zEyXKR3pA+5dg7hxUcJt0IdIfq93bqQ6L6IDQ6sCk6e5XurPZrCoxP8MOtoBmgIOCb96c+9OMKbjOtD0hNssvur1e35k18SGKqkjXEyNE2L0d4GWOGajcQ0VIFO6PmHV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379155; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=dw6rf+w79E9eiMIRn8jJSqfEuZojn54msgfuGr0xZtw=; b=mm15LmpyyYNtDZxuHZuQ3B8iVAEipup5bJYrPDiO1vTCCgT5iGkUI2HQGKOVjXVUypnp2zMLvzMCilrMb9/tZZ2rime2DfgxeL2RwrtwQr9FurppAM/ie14OSwBrP3PExfQTsFn/HJmh6Fw0an4MRUkpmQKY7K76TuiYWwx24hk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379155637442.4640073257374; Wed, 12 Jun 2019 15:39:15 -0700 (PDT) Received: from localhost ([::1]:35570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBtg-0006q3-Ko for importer@patchew.org; Wed, 12 Jun 2019 18:39:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45774) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSN-0007xA-8S for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSL-0007qn-7f for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:10:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33926) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSF-0007mD-B2; Wed, 12 Jun 2019 18:10:51 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83A62307C947; Wed, 12 Jun 2019 22:10:50 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D04606014E; Wed, 12 Jun 2019 22:10:49 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:39 +0200 Message-Id: <20190612221004.2317-18-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 12 Jun 2019 22:10:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 17/42] block: Use CAFs in bdrv_refresh_limits() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/io.c b/block/io.c index 64408cf19a..659ea0c52a 100644 --- a/block/io.c +++ b/block/io.c @@ -151,6 +151,8 @@ static void bdrv_merge_limits(BlockLimits *dst, const B= lockLimits *src) void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); + BlockDriverState *cow_bs =3D bdrv_filtered_cow_bs(bs); Error *local_err =3D NULL; =20 memset(&bs->bl, 0, sizeof(bs->bl)); @@ -164,13 +166,13 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error = **errp) drv->bdrv_aio_preadv) ? 1 : 512; =20 /* Take some limits from the children as a default */ - if (bs->file) { - bdrv_refresh_limits(bs->file->bs, &local_err); + if (storage_bs) { + bdrv_refresh_limits(storage_bs, &local_err); if (local_err) { error_propagate(errp, local_err); return; } - bdrv_merge_limits(&bs->bl, &bs->file->bs->bl); + bdrv_merge_limits(&bs->bl, &storage_bs->bl); } else { bs->bl.min_mem_alignment =3D 512; bs->bl.opt_mem_alignment =3D getpagesize(); @@ -179,13 +181,13 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error = **errp) bs->bl.max_iov =3D IOV_MAX; } =20 - if (bs->backing) { - bdrv_refresh_limits(bs->backing->bs, &local_err); + if (cow_bs) { + bdrv_refresh_limits(cow_bs, &local_err); if (local_err) { error_propagate(errp, local_err); return; } - bdrv_merge_limits(&bs->bl, &bs->backing->bs->bl); + bdrv_merge_limits(&bs->bl, &cow_bs->bl); } =20 /* Then let the driver override it */ --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379322; cv=none; d=zoho.com; s=zohoarc; b=PfxAIatWVc6kchPObyuBcbdj1Hh84C4jTkDjVVdA6Ac7v2Ij6N8OSViPJOHtgI7Jh2fIwNiHUMVHovSGnpD6RHcrGOvbrh1kAifq2y7ogFBA2kGk4ksYbXmoTD5rkt5eoJRrp00UZnC4+5ZDJxHBT8xYNZ3cKohrM1RrrO2RXn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379322; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=yTZ1SmFuqFYOR/bF2NLSjbYfmHdObQileSDLPb5tvrs=; b=OXHsdlOhbYu0L0GmttY4PTLkJ9p5/hLdDRxa44xaNvP3BLHECet78c56OIk0KUApWmmc/AbTP/5zPBHiDTKAM5UyEcpPJnZUKE1yDzs7CdVSuq8gV/J0zCItF6SVZVS3Z8LFSmXLruOTJKKzs2uernfSmhPHD+VcctPJY0mLvNI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379322571577.978098016006; Wed, 12 Jun 2019 15:42:02 -0700 (PDT) Received: from localhost ([::1]:35612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBwM-0002no-DW for importer@patchew.org; Wed, 12 Jun 2019 18:41:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45808) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSR-0007zC-EF for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSP-0007sr-9z for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSJ-0007oe-Cd; Wed, 12 Jun 2019 18:10:55 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C79BA96F1; Wed, 12 Jun 2019 22:10:53 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 918E660FD6; Wed, 12 Jun 2019 22:10:52 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:40 +0200 Message-Id: <20190612221004.2317-19-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 12 Jun 2019 22:10:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 18/42] block: Use CAFs in bdrv_refresh_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_refresh_filename() and the kind of related bdrv_dirname() should look to the primary child when they wish to copy the underlying file's filename. Signed-off-by: Max Reitz --- block.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/block.c b/block.c index db2759c10d..797bec0326 100644 --- a/block.c +++ b/block.c @@ -6280,6 +6280,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; BdrvChild *child; + BlockDriverState *primary_child_bs; QDict *opts; bool backing_overridden; bool generate_json_filename; /* Whether our default implementation sho= uld @@ -6348,20 +6349,30 @@ void bdrv_refresh_filename(BlockDriverState *bs) qobject_unref(bs->full_open_options); bs->full_open_options =3D opts; =20 + primary_child_bs =3D bdrv_primary_bs(bs); + if (drv->bdrv_refresh_filename) { /* Obsolete information is of no use here, so drop the old file na= me * information before refreshing it */ bs->exact_filename[0] =3D '\0'; =20 drv->bdrv_refresh_filename(bs); - } else if (bs->file) { - /* Try to reconstruct valid information from the underlying file */ + } else if (primary_child_bs) { + /* + * Try to reconstruct valid information from the underlying + * file -- this only works for format nodes (filter nodes + * cannot be probed and as such must be selected by the user + * either through an options dict, or through a special + * filename which the filter driver must construct in its + * .bdrv_refresh_filename() implementation). + */ =20 bs->exact_filename[0] =3D '\0'; =20 /* * We can use the underlying file's filename if: * - it has a filename, + * - the current BDS is not a filter, * - the file is a protocol BDS, and * - opening that file (as this BDS's format) will automatically c= reate * the BDS tree we have right now, that is: @@ -6370,11 +6381,11 @@ void bdrv_refresh_filename(BlockDriverState *bs) * - no non-file child of this BDS has been overridden by the us= er * Both of these conditions are represented by generate_json_fil= ename. */ - if (bs->file->bs->exact_filename[0] && - bs->file->bs->drv->bdrv_file_open && - !generate_json_filename) + if (primary_child_bs->exact_filename[0] && + primary_child_bs->drv->bdrv_file_open && + !drv->is_filter && !generate_json_filename) { - strcpy(bs->exact_filename, bs->file->bs->exact_filename); + strcpy(bs->exact_filename, primary_child_bs->exact_filename); } } =20 @@ -6391,6 +6402,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) char *bdrv_dirname(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *child_bs; =20 if (!drv) { error_setg(errp, "Node '%s' is ejected", bs->node_name); @@ -6401,8 +6413,9 @@ char *bdrv_dirname(BlockDriverState *bs, Error **errp) return drv->bdrv_dirname(bs, errp); } =20 - if (bs->file) { - return bdrv_dirname(bs->file->bs, errp); + child_bs =3D bdrv_primary_bs(bs); + if (child_bs) { + return bdrv_dirname(child_bs, errp); } =20 bdrv_refresh_filename(bs); --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560380141; cv=none; d=zoho.com; s=zohoarc; b=M/aiJ6QXFzm3caCRZkh7hbw9Bvf9QQQQkbSaNh/LWI5gZzklljHD2RN+0K1mYP6qljH2lmuCOWByijTcS/nuhtqtHA18SqKMg+8g37D8RbmJq92ejm0T3RKOyMNiuaAUMncPIUl0oYO/q+ykQeZIZFAy/9H2wtLPoJAOKcgR4X0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560380141; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=CnSq/TnsgR30xYnQ/0/e6I7YGo0dcFJ6ywCy36YhPOs=; b=mGyZL4bSHcBcAoft3Ns/EMQP9xLqjARNNPAyKSfQjIaZKzZa/f7JZkCE1+og/Wfi1EyXQ4nr/2NXMVGEU56WMtUWrgLvtee3NuRs4pb6qveqAOeuTCwcM1Bcz+0eEMYW3E3c7nzeTrNsUWqCpZ2TiSXc2bHoIhw+EIwGMJFvYKI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560380141601319.55304061195307; Wed, 12 Jun 2019 15:55:41 -0700 (PDT) Received: from localhost ([::1]:35764 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC9c-0000ky-Mg for importer@patchew.org; Wed, 12 Jun 2019 18:55:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49885) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBkq-0007eF-NZ for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:30:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBXI-0002UM-3b for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:16:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33960) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSL-0007qB-8B; Wed, 12 Jun 2019 18:10:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B1F6307C940; Wed, 12 Jun 2019 22:10:55 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2050119744; Wed, 12 Jun 2019 22:10:54 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:41 +0200 Message-Id: <20190612221004.2317-20-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 12 Jun 2019 22:10:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 19/42] block: Use CAF in bdrv_co_rw_vmstate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If a node whose driver does not provide VM state functions has a metadata child, the VM state should probably go there; if it is a filter, the VM state should probably go there. It follows that we should generally go down to the primary child. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 659ea0c52a..14f99e1c00 100644 --- a/block/io.c +++ b/block/io.c @@ -2395,6 +2395,7 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector= *qiov, int64_t pos, bool is_read) { BlockDriver *drv =3D bs->drv; + BlockDriverState *child_bs =3D bdrv_primary_bs(bs); int ret =3D -ENOTSUP; =20 bdrv_inc_in_flight(bs); @@ -2407,8 +2408,8 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector= *qiov, int64_t pos, } else { ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); } - } else if (bs->file) { - ret =3D bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read); + } else if (child_bs) { + ret =3D bdrv_co_rw_vmstate(child_bs, qiov, pos, is_read); } =20 bdrv_dec_in_flight(bs); --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379073; cv=none; d=zoho.com; s=zohoarc; b=ODjAc66o+q+O1WZtCazEmRN3dEol/nn02z0W8zX+5ZhEk2rlgigDiXt25RgPoytBcgUvgweByBS2OUW3sc8UIS8s8Dx140fWzjrXZQOYZ7IulXWQ1ODtf04GcwOI9qXnE3EvywOpTGLmuh2rV7PcARvwoXzPqF42xdNFyWXuIOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379073; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=avvMur7qevmzFLTuJ5h+GytRP7k+/Y3w8ig7rybPZ4g=; b=Z/dCxymmpfed2d1ElQ+CEfuosMlwASJBsul5lX9I7BVWIA4L1VJY9EZpCCcmaEUo5v91nbAlps88EL7aCfCCXQiO1yrPYCjGca6GcjHqRn3YJfePAGg8kAs7ABrxPuQfWImiHOmeJSnUU18S+yMZCtqvKNcQD9CV4usTzxELfjc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379073033832.9624229075642; Wed, 12 Jun 2019 15:37:53 -0700 (PDT) Received: from localhost ([::1]:35564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBsF-0005K5-Ic for importer@patchew.org; Wed, 12 Jun 2019 18:37:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45908) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSY-00083z-0G for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSV-0007w8-Lm for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSN-0007rJ-6p; Wed, 12 Jun 2019 18:11:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 157FD30F1BA5; Wed, 12 Jun 2019 22:10:58 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C2825F9A7; Wed, 12 Jun 2019 22:10:57 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:42 +0200 Message-Id: <20190612221004.2317-21-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Jun 2019 22:10:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 20/42] block/snapshot: Fall back to storage child X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If the top node's driver does not provide snapshot functionality and we want to go down the chain, we should go towards the child which stores the data, i.e. the storage child. bdrv_snapshot_goto() becomes a bit weird because we may have to redirect the actual child pointer, so it only works if the storage child is bs->file or bs->backing (and then we have to find out which it is). Signed-off-by: Max Reitz --- block/snapshot.c | 74 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index f2f48f926a..58cd667f3a 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -154,8 +154,9 @@ int bdrv_can_snapshot(BlockDriverState *bs) } =20 if (!drv->bdrv_snapshot_create) { - if (bs->file !=3D NULL) { - return bdrv_can_snapshot(bs->file->bs); + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { + return bdrv_can_snapshot(storage_bs); } return 0; } @@ -167,14 +168,15 @@ int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); if (!drv) { return -ENOMEDIUM; } if (drv->bdrv_snapshot_create) { return drv->bdrv_snapshot_create(bs, sn_info); } - if (bs->file) { - return bdrv_snapshot_create(bs->file->bs, sn_info); + if (storage_bs) { + return bdrv_snapshot_create(storage_bs, sn_info); } return -ENOTSUP; } @@ -184,6 +186,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs; int ret, open_ret; =20 if (!drv) { @@ -204,39 +207,66 @@ int bdrv_snapshot_goto(BlockDriverState *bs, return ret; } =20 - if (bs->file) { - BlockDriverState *file; - QDict *options =3D qdict_clone_shallow(bs->options); + storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { + QDict *options; QDict *file_options; Error *local_err =3D NULL; + bool is_backing_child; + BdrvChild **child_pointer; + + /* + * Filters may reference the storage child through + * bs->backing. We need to know whether we are dealing with + * bs->backing or bs->file, so we check it here. + */ + if (storage_bs =3D=3D bs->file->bs) { + is_backing_child =3D false; + child_pointer =3D &bs->file; + } else if (storage_bs =3D=3D bs->backing->bs) { + is_backing_child =3D true; + child_pointer =3D &bs->backing; + } else { + /* + * The storage child is not referenced by a field in the + * BDS object. We cannot go on then. + */ + error_setg(errp, "Block driver does not support snapshots"); + return -ENOTSUP; + } + + options =3D qdict_clone_shallow(bs->options); =20 - file =3D bs->file->bs; /* Prevent it from getting deleted when detached from bs */ - bdrv_ref(file); + bdrv_ref(storage_bs); =20 - qdict_extract_subqdict(options, &file_options, "file."); + qdict_extract_subqdict(options, &file_options, + is_backing_child ? "backing." : "file."); qobject_unref(file_options); - qdict_put_str(options, "file", bdrv_get_node_name(file)); + qdict_put_str(options, is_backing_child ? "backing" : "file", + bdrv_get_node_name(storage_bs)); =20 if (drv->bdrv_close) { drv->bdrv_close(bs); } - bdrv_unref_child(bs, bs->file); - bs->file =3D NULL; =20 - ret =3D bdrv_snapshot_goto(file, snapshot_id, errp); + assert(storage_bs =3D=3D (*child_pointer)->bs); + bdrv_unref_child(bs, *child_pointer); + *child_pointer =3D NULL; + + ret =3D bdrv_snapshot_goto(storage_bs, snapshot_id, errp); open_ret =3D drv->bdrv_open(bs, options, bs->open_flags, &local_er= r); qobject_unref(options); if (open_ret < 0) { - bdrv_unref(file); + bdrv_unref(storage_bs); bs->drv =3D NULL; /* A bdrv_snapshot_goto() error takes precedence */ error_propagate(errp, local_err); return ret < 0 ? ret : open_ret; } =20 - assert(bs->file->bs =3D=3D file); - bdrv_unref(file); + assert(storage_bs =3D=3D (*child_pointer)->bs); + bdrv_unref(storage_bs); return ret; } =20 @@ -272,6 +302,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); int ret; =20 if (!drv) { @@ -288,8 +319,8 @@ int bdrv_snapshot_delete(BlockDriverState *bs, =20 if (drv->bdrv_snapshot_delete) { ret =3D drv->bdrv_snapshot_delete(bs, snapshot_id, name, errp); - } else if (bs->file) { - ret =3D bdrv_snapshot_delete(bs->file->bs, snapshot_id, name, errp= ); + } else if (storage_bs) { + ret =3D bdrv_snapshot_delete(storage_bs, snapshot_id, name, errp); } else { error_setg(errp, "Block format '%s' used by device '%s' " "does not support internal snapshot deletion", @@ -305,14 +336,15 @@ int bdrv_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_info) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); if (!drv) { return -ENOMEDIUM; } if (drv->bdrv_snapshot_list) { return drv->bdrv_snapshot_list(bs, psn_info); } - if (bs->file) { - return bdrv_snapshot_list(bs->file->bs, psn_info); + if (storage_bs) { + return bdrv_snapshot_list(storage_bs, psn_info); } return -ENOTSUP; } --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560378643; cv=none; d=zoho.com; s=zohoarc; b=aePGRzj/Al6v5mQBt3RdTRY9ugvqfHfvVyKF0M4IxlIFYWIUYAC4soAlrG/BmD+/zIF9zaPF4C7b94j2RUgWaKNK/MjDJuo13RBTgt4iEQPkyZQrRlz1p+646+XZTYwqR9+OjpZAyoj+R+Uu5abkOeGxfgL9zif6hbSGeY771sY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560378643; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7oCouIO45rshgBgDkUBRpVJ8/V34kgSxEPXiIHWZN8E=; b=jMsnP+rgcfHJIC3WRe66koqmfaYCVP2ds2knXiu91YDc/zCAYmObjZKJNa67+uIdpbaEOCfjM9DB/HO9/HVXYbhrB2pnglsbSDyyBWefZo4dvVSduVv2lF1dkkbvGL1OfzY3dhjAJCx3LyxJuNqo4sNgvVnwgeyGlrY1WOac1hE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560378643265604.2125446892404; Wed, 12 Jun 2019 15:30:43 -0700 (PDT) Received: from localhost ([::1]:35520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBlH-0008Bu-1z for importer@patchew.org; Wed, 12 Jun 2019 18:30:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45893) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSX-00083b-7U for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSV-0007wY-SH for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47212) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSR-0007sv-Co; Wed, 12 Jun 2019 18:11:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 258DC307D93E; Wed, 12 Jun 2019 22:11:01 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27F1F60476; Wed, 12 Jun 2019 22:10:59 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:43 +0200 Message-Id: <20190612221004.2317-22-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 12 Jun 2019 22:11:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 21/42] block: Use CAFs for debug breakpoints X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When looking for a blkdebug node (which implements debug breakpoints), use bdrv_primary_bs() to iterate through the graph, because that is where a blkdebug node would be. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 797bec0326..11b7ba8cf6 100644 --- a/block.c +++ b/block.c @@ -5097,7 +5097,7 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const= char *event, const char *tag) { while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) { - bs =3D bs->file ? bs->file->bs : NULL; + bs =3D bdrv_primary_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_breakpoint) { @@ -5110,7 +5110,7 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const= char *event, int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag) { while (bs && bs->drv && !bs->drv->bdrv_debug_remove_breakpoint) { - bs =3D bs->file ? bs->file->bs : NULL; + bs =3D bdrv_primary_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_remove_breakpoint) { @@ -5123,7 +5123,7 @@ int bdrv_debug_remove_breakpoint(BlockDriverState *bs= , const char *tag) int bdrv_debug_resume(BlockDriverState *bs, const char *tag) { while (bs && (!bs->drv || !bs->drv->bdrv_debug_resume)) { - bs =3D bs->file ? bs->file->bs : NULL; + bs =3D bdrv_primary_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_resume) { @@ -5136,7 +5136,7 @@ int bdrv_debug_resume(BlockDriverState *bs, const cha= r *tag) bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag) { while (bs && bs->drv && !bs->drv->bdrv_debug_is_suspended) { - bs =3D bs->file ? bs->file->bs : NULL; + bs =3D bdrv_primary_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_is_suspended) { --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379080; cv=none; d=zoho.com; s=zohoarc; b=gWaBdwlb++XaM3k6nPHy/5rGuhpEP6MNK4hxDLr2fsd7xgvgELSJ6NQYA6ktxOpUeGoVIB2Fl0e22lRomZP2M9ygtQHvIaAHZdYaJu1ZPSzaTS6KaJqyy4g+25mkiL01asArT0bwYdRWIGBVTyQVnnwTSS55oGqbokyLZ23NzH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379080; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=o0tJ5apCmMk6KVdFxUzzv9vvintnWW4Bh2bzHaCxUss=; b=OzXuHoOsAYKgkSatFLKOtVjo8ic9Z6B6dF0Qa711L8INOxHvAJu+Q7Odg8oo8fvk1lPG+NGHxUL8iIs34euImrhYXUc+SnJPFa53GJoyoMvDhDFPTF39jSdMaRO7xuuKUCi9947JrhdYpBhfHPk6otUB5fG2KRwzQVqz6ylYPo8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379080803301.73662059136166; Wed, 12 Jun 2019 15:38:00 -0700 (PDT) Received: from localhost ([::1]:35568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBsV-00063h-Mx for importer@patchew.org; Wed, 12 Jun 2019 18:37:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45977) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSc-00087A-UL for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSa-00080o-Tx for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSV-0007uI-PS; Wed, 12 Jun 2019 18:11:07 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0F7B307D93E; Wed, 12 Jun 2019 22:11:03 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32ECF1001B17; Wed, 12 Jun 2019 22:11:03 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:44 +0200 Message-Id: <20190612221004.2317-23-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 12 Jun 2019 22:11:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 22/42] block: Use CAFs in bdrv_get_allocated_file_size() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- block.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 11b7ba8cf6..856d9b58be 100644 --- a/block.c +++ b/block.c @@ -4511,15 +4511,37 @@ exit: int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs, *metadata_bs; + if (!drv) { return -ENOMEDIUM; } + if (drv->bdrv_get_allocated_file_size) { return drv->bdrv_get_allocated_file_size(bs); } - if (bs->file) { - return bdrv_get_allocated_file_size(bs->file->bs); + + storage_bs =3D bdrv_storage_bs(bs); + metadata_bs =3D bdrv_metadata_bs(bs); + + if (storage_bs) { + int64_t data_size, metadata_size =3D 0; + + data_size =3D bdrv_get_allocated_file_size(storage_bs); + if (data_size < 0) { + return data_size; + } + + if (storage_bs !=3D metadata_bs) { + metadata_size =3D bdrv_get_allocated_file_size(metadata_bs); + if (metadata_size < 0) { + return metadata_size; + } + } + + return data_size + metadata_size; } + return -ENOTSUP; } =20 --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379210; cv=none; d=zoho.com; s=zohoarc; b=QYIeeBq5ets94jdl5ZCcIXpkjfrQdINCvkVPQRGOAUcAUj831g/rnFSuMhdawr2qW7tWduxtKaKoqT+thmFsCaKaBQEhWIdVxeYsuXPAwtwfEgZvidwAAbErZgwYAKn1475zB1nMX5szU0DHC93hsiHxgtK0jETEmQHzqbKlSjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379210; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FJHs/Mz/9xTxj8bYOk8p97ri2Udhtc0gwpAqy6Ydlvs=; b=GFGbXWyQ5GWFhtZV6IGdJtQiefWL2ApULayFOJLhxoQA5tsLlYAqg8oHkdOI9SA/MSzVBY0Wd9mJidhWqoBjkTElT2ailOf2KFMF/Ow9PPFlKk9xd0NuyqFObW4kiAC1wB7ZZrl5o+AEP4K08iFaX4p8lGXcbGzDKMRd98V/E8g= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379210136834.3935852989629; Wed, 12 Jun 2019 15:40:10 -0700 (PDT) Received: from localhost ([::1]:35601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBuZ-0000sD-0P for importer@patchew.org; Wed, 12 Jun 2019 18:40:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45976) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSc-000872-U1 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSa-00080h-SZ for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSV-0007vY-PY; Wed, 12 Jun 2019 18:11:07 -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 37C9930C0DE0; Wed, 12 Jun 2019 22:11:06 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCCBD614C8; Wed, 12 Jun 2019 22:11:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:45 +0200 Message-Id: <20190612221004.2317-24-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 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.45]); Wed, 12 Jun 2019 22:11:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 23/42] blockdev: Use CAF in external_snapshot_prepare() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This allows us to differentiate between filters and nodes with COW backing files: Filters cannot be used as overlays at all (for this function). Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- blockdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index b5c0fd3c49..0f0cf0d9ae 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1665,7 +1665,12 @@ static void external_snapshot_prepare(BlkActionState= *common, goto out; } =20 - if (state->new_bs->backing !=3D NULL) { + if (state->new_bs->drv->is_filter) { + error_setg(errp, "Filters cannot be used as overlays"); + goto out; + } + + if (bdrv_filtered_cow_child(state->new_bs)) { error_setg(errp, "The overlay already has a backing image"); goto out; } --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379266; cv=none; d=zoho.com; s=zohoarc; b=DKtdo5RUlnrC6lKFd3CW0abHKyv9Z+b2iX2pWgPrSXUdEuImCH19RnEhdJ4uNMCRRRTBhKiQDq2f/2esUUA8hWmFvfZqZ0hltWc2fDmcfmnuBzcplrlfp6ZZKO+YSUngJPbe0TfxEBeFEdASEaLXPyMT+d806947NF81/FnQST0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379266; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=cPr6NWxxPDKSjpSTW/g0PxXEvfr0ImQ+04+d7vRmTX4=; b=SSP0ffw931hyNetZt3B2lZSFsoVWMCqO06MCku+7tLJA01WHrt0eLdbCDod3nvIBjML2wXgdXr1aECgPNwgSpXg0GaycLYTVE9N6HRJI0MPicocfIoQ4z+XvHxO8ZW/Eaa/12SlytLZzzqlBw8cYVKdLtJCcklFjlhC0NTPup2I= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379266034954.999181677511; Wed, 12 Jun 2019 15:41:06 -0700 (PDT) Received: from localhost ([::1]:35606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBvV-0002Ff-3Y for importer@patchew.org; Wed, 12 Jun 2019 18:41:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46001) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSg-00088P-PY for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSc-00082G-VW for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSX-0007xz-Jk; Wed, 12 Jun 2019 18:11:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B91AE30860B9; Wed, 12 Jun 2019 22:11:08 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47F5160185; Wed, 12 Jun 2019 22:11:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:46 +0200 Message-Id: <20190612221004.2317-25-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 12 Jun 2019 22:11:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 24/42] block: Use child access functions for QAPI queries X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" query-block and query-named-block-nodes now return any filtered child under "backing", not just bs->backing or COW children. This is so that filters do not interrupt the reported backing chain. This changes the output for iotest 184, as the throttled node now appears as a backing child. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qapi.c | 35 ++++++++++++++++++++--------------- tests/qemu-iotests/184.out | 7 ++++++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index 0c13c86f4e..1fd2937abc 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -150,9 +150,13 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *= blk, return NULL; } =20 - if (bs0->drv && bs0->backing) { + if (bs0->drv && bdrv_filtered_child(bs0)) { + /* + * Put any filtered child here (for backwards compatibility to= when + * we put bs0->backing here, which might be any filtered child= ). + */ info->backing_file_depth++; - bs0 =3D bs0->backing->bs; + bs0 =3D bdrv_filtered_bs(bs0); (*p_image_info)->has_backing_image =3D true; p_image_info =3D &((*p_image_info)->backing_image); } else { @@ -161,9 +165,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *b= lk, =20 /* Skip automatically inserted nodes that the user isn't aware of = for * query-block (blk !=3D NULL), but not for query-named-block-node= s */ - while (blk && bs0->drv && bs0->implicit) { - bs0 =3D backing_bs(bs0); - assert(bs0); + if (blk) { + bs0 =3D bdrv_skip_implicit_filters(bs0); } } =20 @@ -348,9 +351,9 @@ static void bdrv_query_info(BlockBackend *blk, BlockInf= o **p_info, BlockDriverState *bs =3D blk_bs(blk); char *qdev; =20 - /* Skip automatically inserted nodes that the user isn't aware of */ - while (bs && bs->drv && bs->implicit) { - bs =3D backing_bs(bs); + if (bs) { + /* Skip automatically inserted nodes that the user isn't aware of = */ + bs =3D bdrv_skip_implicit_filters(bs); } =20 info->device =3D g_strdup(blk_name(blk)); @@ -507,6 +510,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level) { + BlockDriverState *storage_bs, *cow_bs; BlockStats *s =3D NULL; =20 s =3D g_malloc0(sizeof(*s)); @@ -519,9 +523,8 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverStat= e *bs, /* Skip automatically inserted nodes that the user isn't aware of in * a BlockBackend-level command. Stay at the exact node for a node-lev= el * command. */ - while (blk_level && bs->drv && bs->implicit) { - bs =3D backing_bs(bs); - assert(bs); + if (blk_level) { + bs =3D bdrv_skip_implicit_filters(bs); } =20 if (bdrv_get_node_name(bs)[0]) { @@ -531,14 +534,16 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverSt= ate *bs, =20 s->stats->wr_highest_offset =3D stat64_get(&bs->wr_highest_offset); =20 - if (bs->file) { + storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { s->has_parent =3D true; - s->parent =3D bdrv_query_bds_stats(bs->file->bs, blk_level); + s->parent =3D bdrv_query_bds_stats(storage_bs, blk_level); } =20 - if (blk_level && bs->backing) { + cow_bs =3D bdrv_filtered_cow_bs(bs); + if (blk_level && cow_bs) { s->has_backing =3D true; - s->backing =3D bdrv_query_bds_stats(bs->backing->bs, blk_level); + s->backing =3D bdrv_query_bds_stats(cow_bs, blk_level); } =20 return s; diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out index 3deb3cfb94..1d61f7e224 100644 --- a/tests/qemu-iotests/184.out +++ b/tests/qemu-iotests/184.out @@ -27,6 +27,11 @@ Testing: "iops_rd": 0, "detect_zeroes": "off", "image": { + "backing-image": { + "virtual-size": 1073741824, + "filename": "null-co://", + "format": "null-co" + }, "virtual-size": 1073741824, "filename": "json:{\"throttle-group\": \"group0\", \"drive= r\": \"throttle\", \"file\": {\"driver\": \"null-co\"}}", "format": "throttle" @@ -34,7 +39,7 @@ Testing: "iops_wr": 0, "ro": false, "node-name": "throttle0", - "backing_file_depth": 0, + "backing_file_depth": 1, "drv": "throttle", "iops": 0, "bps_wr": 0, --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379580; cv=none; d=zoho.com; s=zohoarc; b=hRKTmTvviHfD47WVfeZMOjeA5fwmF1geBu88HF+a3XbK2TUSj1tIwmu7d6+4lOBzjW8e/HXlHrK3RqVWfbb7Z9XFIoSCNPHzQYbYdVsk70DcJPqnkJa9Ncv6vtsoVClHLPJh2qZnWsS5CT8AK+aFXBl6MZsVkAt6fHaRKPu+0gg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379580; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FRxEk5sFDvX7zDD9iM+ooU0V2+7d1gROU0LQaTwbvdo=; b=hBZ+slq/v6Ejs/ku3Ub+jSrMNyzyinD2m/pX1QM8o05Sia7JtWdQdOqAoYUqrqZt8HMfh1TgbP0hMwy1jtpqgD/+f0j2qMIp+imKL6IoVHfLSLlu/paWIHtvVNwhu3I81uiPftnPASyhGzE5PA9JJQhB+SB0uAh6MBh8wfAjHqQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379580810681.4724849605659; Wed, 12 Jun 2019 15:46:20 -0700 (PDT) Received: from localhost ([::1]:35670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC0W-0007mR-Mk for importer@patchew.org; Wed, 12 Jun 2019 18:46:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46022) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSl-0008Bs-3h for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSg-00085Q-Rw for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41016) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSa-00080G-RO; Wed, 12 Jun 2019 18:11:13 -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 AF5067E424; Wed, 12 Jun 2019 22:11:11 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D182060BF0; Wed, 12 Jun 2019 22:11:10 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:47 +0200 Message-Id: <20190612221004.2317-26-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 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]); Wed, 12 Jun 2019 22:11:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 25/42] mirror: Deal with filters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This includes some permission limiting (for example, we only need to take the RESIZE permission for active commits where the base is smaller than the top). Signed-off-by: Max Reitz --- block/mirror.c | 110 +++++++++++++++++++++++++++++++++++++------------ blockdev.c | 47 +++++++++++++++++---- 2 files changed, 124 insertions(+), 33 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 4fa8f57c80..3d767e3030 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -660,8 +660,10 @@ static int mirror_exit_common(Job *job) &error_abort); if (!abort && s->backing_mode =3D=3D MIRROR_SOURCE_BACKING_CHAIN) { BlockDriverState *backing =3D s->is_none_mode ? src : s->base; - if (backing_bs(target_bs) !=3D backing) { - bdrv_set_backing_hd(target_bs, backing, &local_err); + BlockDriverState *unfiltered_target =3D bdrv_skip_rw_filters(targe= t_bs); + + if (bdrv_filtered_cow_bs(unfiltered_target) !=3D backing) { + bdrv_set_backing_hd(unfiltered_target, backing, &local_err); if (local_err) { error_report_err(local_err); ret =3D -EPERM; @@ -711,7 +713,7 @@ static int mirror_exit_common(Job *job) block_job_remove_all_bdrv(bjob); 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); + bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_ab= ort); =20 /* We just changed the BDS the job BB refers to (with either or both o= f the * bdrv_replace_node() calls), so switch the BB back so the cleanup do= es @@ -757,6 +759,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) { int64_t offset; BlockDriverState *base =3D s->base; + BlockDriverState *filtered_base; BlockDriverState *bs =3D s->mirror_top_bs->backing->bs; BlockDriverState *target_bs =3D blk_bs(s->target); int ret; @@ -795,6 +798,9 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) s->initial_zeroing_ongoing =3D false; } =20 + /* Will be NULL if @base is not in @bs's chain */ + filtered_base =3D bdrv_filtered_cow_bs(bdrv_find_overlay(bs, base)); + /* First part, loop on the sectors and initialize the dirty bitmap. */ for (offset =3D 0; offset < s->bdev_length; ) { /* Just to make sure we are not exceeding int limit. */ @@ -807,7 +813,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) return 0; } =20 - ret =3D bdrv_is_allocated_above(bs, base, offset, bytes, &count); + ret =3D bdrv_is_allocated_above(bs, filtered_base, offset, bytes, = &count); if (ret < 0) { return ret; } @@ -903,7 +909,7 @@ static int coroutine_fn mirror_run(Job *job, Error **er= rp) } else { s->target_cluster_size =3D BDRV_SECTOR_SIZE; } - if (backing_filename[0] && !target_bs->backing && + if (backing_filename[0] && !bdrv_backing_chain_next(target_bs) && s->granularity < s->target_cluster_size) { s->buf_size =3D MAX(s->buf_size, s->target_cluster_size); s->cow_bitmap =3D bitmap_new(length); @@ -1083,8 +1089,9 @@ static void mirror_complete(Job *job, Error **errp) if (s->backing_mode =3D=3D MIRROR_OPEN_BACKING_CHAIN) { int ret; =20 - assert(!target->backing); - ret =3D bdrv_open_backing_file(target, NULL, "backing", errp); + assert(!bdrv_backing_chain_next(target)); + ret =3D bdrv_open_backing_file(bdrv_skip_rw_filters(target), NULL, + "backing", errp); if (ret < 0) { return; } @@ -1503,8 +1510,8 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, MirrorBlockJob *s; MirrorBDSOpaque *bs_opaque; BlockDriverState *mirror_top_bs; - bool target_graph_mod; bool target_is_backing; + uint64_t target_perms, target_shared_perms; Error *local_err =3D NULL; int ret; =20 @@ -1523,7 +1530,7 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, buf_size =3D DEFAULT_MIRROR_BUF_SIZE; } =20 - if (bs =3D=3D target) { + if (bdrv_skip_rw_filters(bs) =3D=3D bdrv_skip_rw_filters(target)) { error_setg(errp, "Can't mirror node into itself"); return; } @@ -1583,15 +1590,42 @@ static void mirror_start_job(const char *job_id, Bl= ockDriverState *bs, * In the case of active commit, things look a bit different, though, * because the target is an already populated backing file in active u= se. * We can allow anything except resize there.*/ + + target_perms =3D BLK_PERM_WRITE; + target_shared_perms =3D BLK_PERM_WRITE_UNCHANGED; + target_is_backing =3D bdrv_chain_contains(bs, target); - target_graph_mod =3D (backing_mode !=3D MIRROR_LEAVE_BACKING_CHAIN); + if (target_is_backing) { + int64_t bs_size, target_size; + bs_size =3D bdrv_getlength(bs); + if (bs_size < 0) { + error_setg_errno(errp, -bs_size, + "Could not inquire top image size"); + goto fail; + } + + target_size =3D bdrv_getlength(target); + if (target_size < 0) { + error_setg_errno(errp, -target_size, + "Could not inquire base image size"); + goto fail; + } + + if (target_size < bs_size) { + target_perms |=3D BLK_PERM_RESIZE; + } + + target_shared_perms |=3D BLK_PERM_CONSISTENT_READ + | BLK_PERM_WRITE + | BLK_PERM_GRAPH_MOD; + } + + if (backing_mode !=3D MIRROR_LEAVE_BACKING_CHAIN) { + target_perms |=3D BLK_PERM_GRAPH_MOD; + } + s->target =3D blk_new(s->common.job.aio_context, - BLK_PERM_WRITE | BLK_PERM_RESIZE | - (target_graph_mod ? BLK_PERM_GRAPH_MOD : 0), - BLK_PERM_WRITE_UNCHANGED | - (target_is_backing ? BLK_PERM_CONSISTENT_READ | - BLK_PERM_WRITE | - BLK_PERM_GRAPH_MOD : 0)); + target_perms, target_shared_perms); ret =3D blk_insert_bs(s->target, target, errp); if (ret < 0) { goto fail; @@ -1641,15 +1675,39 @@ static void mirror_start_job(const char *job_id, Bl= ockDriverState *bs, /* In commit_active_start() all intermediate nodes disappear, so * any jobs in them must be blocked */ if (target_is_backing) { - BlockDriverState *iter; - for (iter =3D backing_bs(bs); iter !=3D target; iter =3D backing_b= s(iter)) { - /* XXX BLK_PERM_WRITE needs to be allowed so we don't block - * ourselves at s->base (if writes are blocked for a node, the= y are - * also blocked for its backing file). The other options would= be a - * second filter driver above s->base (=3D=3D target). */ + BlockDriverState *iter, *filtered_target; + uint64_t iter_shared_perms; + + /* + * The topmost node with + * bdrv_skip_rw_filters(filtered_target) =3D=3D bdrv_skip_rw_filte= rs(target) + */ + filtered_target =3D bdrv_filtered_cow_bs(bdrv_find_overlay(bs, tar= get)); + + assert(bdrv_skip_rw_filters(filtered_target) =3D=3D + bdrv_skip_rw_filters(target)); + + /* + * XXX BLK_PERM_WRITE needs to be allowed so we don't block + * ourselves at s->base (if writes are blocked for a node, they are + * also blocked for its backing file). The other options would be a + * second filter driver above s->base (=3D=3D target). + */ + iter_shared_perms =3D BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE; + + for (iter =3D bdrv_filtered_bs(bs); iter !=3D target; + iter =3D bdrv_filtered_bs(iter)) + { + if (iter =3D=3D filtered_target) { + /* + * From here on, all nodes are filters on the base. + * This allows us to share BLK_PERM_CONSISTENT_READ. + */ + iter_shared_perms |=3D BLK_PERM_CONSISTENT_READ; + } + ret =3D block_job_add_bdrv(&s->common, "intermediate node", it= er, 0, - BLK_PERM_WRITE_UNCHANGED | BLK_PERM_W= RITE, - errp); + iter_shared_perms, errp); if (ret < 0) { goto fail; } @@ -1683,7 +1741,7 @@ fail: =20 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); + bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_ab= ort); =20 bdrv_unref(mirror_top_bs); } @@ -1706,7 +1764,7 @@ void mirror_start(const char *job_id, BlockDriverStat= e *bs, return; } is_none_mode =3D mode =3D=3D MIRROR_SYNC_MODE_NONE; - base =3D mode =3D=3D MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL; + base =3D mode =3D=3D MIRROR_SYNC_MODE_TOP ? bdrv_backing_chain_next(bs= ) : NULL; mirror_start_job(job_id, bs, creation_flags, target, replaces, speed, granularity, buf_size, backing_mode, on_source_error, on_target_error, unmap, NULL, NULL, diff --git a/blockdev.c b/blockdev.c index 0f0cf0d9ae..68e8d33447 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3777,7 +3777,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, return; } =20 - if (!bs->backing && sync =3D=3D MIRROR_SYNC_MODE_TOP) { + if (!bdrv_backing_chain_next(bs) && sync =3D=3D MIRROR_SYNC_MODE_TOP) { sync =3D MIRROR_SYNC_MODE_FULL; } =20 @@ -3826,7 +3826,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, =20 void qmp_drive_mirror(DriveMirror *arg, Error **errp) { - BlockDriverState *bs; + BlockDriverState *bs, *unfiltered_bs; BlockDriverState *source, *target_bs; AioContext *aio_context; BlockMirrorBackingMode backing_mode; @@ -3835,6 +3835,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) int flags; int64_t size; const char *format =3D arg->format; + const char *replaces_node_name =3D NULL; int ret; =20 bs =3D qmp_get_root_bs(arg->device, errp); @@ -3847,6 +3848,16 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) return; } =20 + /* + * If the user has not instructed us otherwise, we should let the + * block job run from @bs (thus taking into account all filters on + * it) but replace @unfiltered_bs when it finishes (thus not + * removing those filters). + * (And if there are any explicit filters, we should assume the + * user knows how to use the @replaces option.) + */ + unfiltered_bs =3D bdrv_skip_implicit_filters(bs); + aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 @@ -3860,8 +3871,14 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) } =20 flags =3D bs->open_flags | BDRV_O_RDWR; - source =3D backing_bs(bs); + source =3D bdrv_filtered_cow_bs(unfiltered_bs); if (!source && arg->sync =3D=3D MIRROR_SYNC_MODE_TOP) { + if (bdrv_filtered_bs(unfiltered_bs)) { + /* @unfiltered_bs is an explicit filter */ + error_setg(errp, "Cannot perform sync=3Dtop mirror through an " + "explicitly added filter node on the source"); + goto out; + } arg->sync =3D MIRROR_SYNC_MODE_FULL; } if (arg->sync =3D=3D MIRROR_SYNC_MODE_NONE) { @@ -3880,6 +3897,9 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) " named node of the graph"); goto out; } + replaces_node_name =3D arg->replaces; + } else if (unfiltered_bs !=3D bs) { + replaces_node_name =3D unfiltered_bs->node_name; } =20 if (arg->mode =3D=3D NEW_IMAGE_MODE_ABSOLUTE_PATHS) { @@ -3899,6 +3919,9 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) bdrv_img_create(arg->target, format, NULL, NULL, NULL, size, flags, false, &local_err); } else { + /* Implicit filters should not appear in the filename */ + BlockDriverState *explicit_backing =3D bdrv_skip_implicit_filters(= source); + switch (arg->mode) { case NEW_IMAGE_MODE_EXISTING: break; @@ -3906,8 +3929,8 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) /* create new image with backing file */ bdrv_refresh_filename(source); bdrv_img_create(arg->target, format, - source->filename, - source->drv->format_name, + explicit_backing->filename, + explicit_backing->drv->format_name, NULL, size, flags, false, &local_err); break; default: @@ -3943,7 +3966,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) } =20 blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, targe= t_bs, - arg->has_replaces, arg->replaces, arg->sync, + !!replaces_node_name, replaces_node_name, arg->= sync, backing_mode, arg->has_speed, arg->speed, arg->has_granularity, arg->granularity, arg->has_buf_size, arg->buf_size, @@ -3979,7 +4002,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, bool has_auto_dismiss, bool auto_dismiss, Error **errp) { - BlockDriverState *bs; + BlockDriverState *bs, *unfiltered_bs; BlockDriverState *target_bs; AioContext *aio_context; BlockMirrorBackingMode backing_mode =3D MIRROR_LEAVE_BACKING_CHAIN; @@ -3991,6 +4014,16 @@ void qmp_blockdev_mirror(bool has_job_id, const char= *job_id, return; } =20 + /* + * Same as in qmp_drive_mirror(): We want to run the job from @bs, + * but we want to replace @unfiltered_bs on completion. + */ + unfiltered_bs =3D bdrv_skip_implicit_filters(bs); + if (!has_replaces && unfiltered_bs !=3D bs) { + replaces =3D unfiltered_bs->node_name; + has_replaces =3D true; + } + target_bs =3D bdrv_lookup_bs(target, target, errp); if (!target_bs) { return; --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379221; cv=none; d=zoho.com; s=zohoarc; b=XAVqpLCPuJFEPc5TNmFgYIwB7acw/qy24gv5oa1+aQeomm9Pke6dbDdHl6oBvfgjooLavzcElrMKnqLUFKZzPE/l8UinQRjAe7JV9hTCQ0ZnPqKDyHHsKlTSypGZOqlaLge51A1mqJZUBA5iS9J2RLMRORM8Bxm4z3IpvACl8Tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379221; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7iFfqEaM87ciQ9oChKx75Dt0sy5R3ORqUerqSQYr95o=; b=KbZMbbo5V4eqrSJ/PviqD+PtYJhE0n1Op75brGHOoajH58BuESBJ8ipxEhd9AtRG2i0MLemH7pYAcJg5VYOM8QmYFP+q+5ApLk0soKT70i91Jh44oXpPYnhlN6tr2MXFfFvjXIrhrMU/HF/QjtHgG+PXHsakuSemSJtFE8r0yY0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379221807210.83975241403698; Wed, 12 Jun 2019 15:40:21 -0700 (PDT) Received: from localhost ([::1]:35604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBum-0001GX-TN for importer@patchew.org; Wed, 12 Jun 2019 18:40:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46086) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSq-0008O0-ID for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSo-00089H-BB for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34084) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSc-00081q-Ue; Wed, 12 Jun 2019 18:11:16 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AE44300414E; Wed, 12 Jun 2019 22:11:14 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC5F860185; Wed, 12 Jun 2019 22:11:13 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:48 +0200 Message-Id: <20190612221004.2317-27-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 12 Jun 2019 22:11:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 26/42] backup: Deal with filters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/backup.c | 9 +++++---- blockdev.c | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/block/backup.c b/block/backup.c index 715e1d3be8..88435f883d 100644 --- a/block/backup.c +++ b/block/backup.c @@ -502,6 +502,7 @@ static int64_t backup_calculate_cluster_size(BlockDrive= rState *target, { int ret; BlockDriverInfo bdi; + bool target_does_cow =3D bdrv_backing_chain_next(target); =20 /* * If there is no backing file on the target, we cannot rely on COW if= our @@ -509,7 +510,7 @@ static int64_t backup_calculate_cluster_size(BlockDrive= rState *target, * targets with a backing file, try to avoid COW if possible. */ ret =3D bdrv_get_info(target, &bdi); - if (ret =3D=3D -ENOTSUP && !target->backing) { + if (ret =3D=3D -ENOTSUP && !target_does_cow) { /* Cluster size is not defined */ warn_report("The target block device doesn't provide " "information about the block size and it doesn't have = a " @@ -518,14 +519,14 @@ static int64_t backup_calculate_cluster_size(BlockDri= verState *target, "this default, the backup may be unusable", BACKUP_CLUSTER_SIZE_DEFAULT); return BACKUP_CLUSTER_SIZE_DEFAULT; - } else if (ret < 0 && !target->backing) { + } else if (ret < 0 && !target_does_cow) { error_setg_errno(errp, -ret, "Couldn't determine the cluster size of the target image, " "which has no backing file"); error_append_hint(errp, "Aborting, since this may create an unusable destination image= \n"); return ret; - } else if (ret < 0 && target->backing) { + } else if (ret < 0 && target_does_cow) { /* Not fatal; just trudge on ahead. */ return BACKUP_CLUSTER_SIZE_DEFAULT; } @@ -569,7 +570,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, return NULL; } =20 - if (compress && target->drv->bdrv_co_pwritev_compressed =3D=3D NULL) { + if (compress && !bdrv_supports_compressed_writes(target)) { error_setg(errp, "Compression is not supported for this drive %s", bdrv_get_device_name(target)); return NULL; diff --git a/blockdev.c b/blockdev.c index 68e8d33447..605e7b0994 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3500,7 +3500,13 @@ static BlockJob *do_drive_backup(DriveBackup *backup= , JobTxn *txn, /* See if we have a backing HD we can use to create our new image * on top of. */ if (backup->sync =3D=3D MIRROR_SYNC_MODE_TOP) { - source =3D backing_bs(bs); + /* + * Backup will not replace the source by the target, so none + * of the filters skipped here will be removed (in contrast to + * mirror). Therefore, we can skip all of them when looking + * for the first COW relationship. + */ + source =3D bdrv_filtered_cow_bs(bdrv_skip_rw_filters(bs)); if (!source) { backup->sync =3D MIRROR_SYNC_MODE_FULL; } @@ -3520,9 +3526,14 @@ static BlockJob *do_drive_backup(DriveBackup *backup= , JobTxn *txn, if (backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { assert(backup->format); if (source) { - bdrv_refresh_filename(source); - bdrv_img_create(backup->target, backup->format, source->filena= me, - source->drv->format_name, NULL, + /* Implicit filters should not appear in the filename */ + BlockDriverState *explicit_backing =3D + bdrv_skip_implicit_filters(source); + + bdrv_refresh_filename(explicit_backing); + bdrv_img_create(backup->target, backup->format, + explicit_backing->filename, + explicit_backing->drv->format_name, NULL, size, flags, false, &local_err); } else { bdrv_img_create(backup->target, backup->format, NULL, NULL, NU= LL, --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379459; cv=none; d=zoho.com; s=zohoarc; b=EgxQlr3UuwfuKKaAq0UuhM38pyt6bHIu6piX36i/9Wx5uf7lnfrkoBIhruWhjhsdpg834twwyU/Lhlp+ebpMj+J2d5A3RSGbm4/X8QUdEkAexl3JaTzUPFsGVdpXCeWOQWefU226EMqy160GGj4YPLPHBIIxT+Xd2s4mX5UdbcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379459; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1cPJGnVo4Myub+MIx32tADj2wfxb4cefQ1G8Y7/ZkgA=; b=k2iiwxN0uEvUVt2Pct9NVFDe5xFDcoL4ir7TL8d0hu4dGpdeo253I/SbIceon/2Tc9QQEi6+gP5O8TBvHmH/xdMsyx6lniQFQbYFKwG96hW1BrL4MZWF4TQ/SwbOAc9A2YI/eIJdl4oRvhvPm1X06kFftPqGypQCOVVRGa3rchQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379459436383.04560107339876; Wed, 12 Jun 2019 15:44:19 -0700 (PDT) Received: from localhost ([::1]:35636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbByB-000589-JM for importer@patchew.org; Wed, 12 Jun 2019 18:43:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46082) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSq-0008Nt-HY for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSo-00089J-BR for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSg-00083M-Ql; Wed, 12 Jun 2019 18:11:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC67030C31A4; Wed, 12 Jun 2019 22:11:16 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4ABF75DEDF; Wed, 12 Jun 2019 22:11:16 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:49 +0200 Message-Id: <20190612221004.2317-28-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 12 Jun 2019 22:11:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 27/42] commit: Deal with filters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This includes some permission limiting (for example, we only need to take the RESIZE permission if the base is smaller than the top). Signed-off-by: Max Reitz --- block/block-backend.c | 16 ++++--- block/commit.c | 97 ++++++++++++++++++++++++++++++++----------- blockdev.c | 6 ++- 3 files changed, 87 insertions(+), 32 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index f5d9407d20..227a6951a0 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2156,11 +2156,17 @@ int blk_commit_all(void) AioContext *aio_context =3D blk_get_aio_context(blk); =20 aio_context_acquire(aio_context); - if (blk_is_inserted(blk) && blk->root->bs->backing) { - int ret =3D bdrv_commit(blk->root->bs); - if (ret < 0) { - aio_context_release(aio_context); - return ret; + if (blk_is_inserted(blk)) { + BlockDriverState *non_filter; + + /* Legacy function, so skip implicit filters */ + non_filter =3D bdrv_skip_implicit_filters(blk->root->bs); + if (bdrv_filtered_cow_child(non_filter)) { + int ret =3D bdrv_commit(non_filter); + if (ret < 0) { + aio_context_release(aio_context); + return ret; + } } } aio_context_release(aio_context); diff --git a/block/commit.c b/block/commit.c index f20a26fecd..ec5a8c8edf 100644 --- a/block/commit.c +++ b/block/commit.c @@ -112,7 +112,7 @@ static void commit_abort(Job *job) * something to base, the intermediate images aren't valid any more. */ bdrv_child_try_set_perm(s->commit_top_bs->backing, 0, BLK_PERM_ALL, &error_abort); - bdrv_replace_node(s->commit_top_bs, backing_bs(s->commit_top_bs), + bdrv_replace_node(s->commit_top_bs, s->commit_top_bs->backing->bs, &error_abort); =20 bdrv_unref(s->commit_top_bs); @@ -137,6 +137,7 @@ static void commit_clean(Job *job) static int coroutine_fn commit_run(Job *job, Error **errp) { CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); + BlockDriverState *filtered_base; int64_t offset; uint64_t delay_ns =3D 0; int ret =3D 0; @@ -163,6 +164,9 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) } } =20 + filtered_base =3D bdrv_filtered_cow_bs(bdrv_find_overlay(blk_bs(s->top= ), + blk_bs(s->base)= )); + buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); =20 for (offset =3D 0; offset < len; offset +=3D n) { @@ -176,7 +180,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) break; } /* Copy if allocated above the base */ - ret =3D bdrv_is_allocated_above(blk_bs(s->top), blk_bs(s->base), + ret =3D bdrv_is_allocated_above(blk_bs(s->top), filtered_base, offset, COMMIT_BUFFER_SIZE, &n); copy =3D (ret =3D=3D 1); trace_commit_one_iteration(s, offset, n, ret); @@ -269,15 +273,35 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, CommitBlockJob *s; BlockDriverState *iter; BlockDriverState *commit_top_bs =3D NULL; + BlockDriverState *filtered_base; Error *local_err =3D NULL; + int64_t base_size, top_size; + uint64_t perms, iter_shared_perms; int ret; =20 assert(top !=3D bs); - if (top =3D=3D base) { + if (bdrv_skip_rw_filters(top) =3D=3D bdrv_skip_rw_filters(base)) { error_setg(errp, "Invalid files for merge: top and base are the sa= me"); return; } =20 + base_size =3D bdrv_getlength(base); + if (base_size < 0) { + error_setg_errno(errp, -base_size, "Could not inquire base image s= ize"); + return; + } + + top_size =3D bdrv_getlength(top); + if (top_size < 0) { + error_setg_errno(errp, -top_size, "Could not inquire top image siz= e"); + return; + } + + perms =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE; + if (base_size < top_size) { + perms |=3D BLK_PERM_RESIZE; + } + s =3D block_job_create(job_id, &commit_job_driver, NULL, bs, 0, BLK_PE= RM_ALL, speed, creation_flags, NULL, NULL, errp); if (!s) { @@ -313,17 +337,43 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, =20 s->commit_top_bs =3D commit_top_bs; =20 - /* Block all nodes between top and base, because they will - * disappear from the chain after this operation. */ + /* + * Block all nodes between top and base, because they will + * disappear from the chain after this operation. + * Note that this assumes that the user is fine with removing all + * nodes (including R/W filters) between top and base. Assuring + * this is the responsibility of the interface (i.e. whoever calls + * commit_start()). + */ assert(bdrv_chain_contains(top, base)); - for (iter =3D top; iter !=3D base; iter =3D backing_bs(iter)) { - /* XXX BLK_PERM_WRITE needs to be allowed so we don't block oursel= ves - * at s->base (if writes are blocked for a node, they are also blo= cked - * for its backing file). The other options would be a second filt= er - * driver above s->base. */ + + /* + * The topmost node with + * bdrv_skip_rw_filters(filtered_base) =3D=3D bdrv_skip_rw_filters(bas= e) + */ + filtered_base =3D bdrv_filtered_cow_bs(bdrv_find_overlay(top, base)); + + assert(bdrv_skip_rw_filters(filtered_base) =3D=3D bdrv_skip_rw_filters= (base)); + + /* + * XXX BLK_PERM_WRITE needs to be allowed so we don't block ourselves + * at s->base (if writes are blocked for a node, they are also blocked + * for its backing file). The other options would be a second filter + * driver above s->base. + */ + iter_shared_perms =3D BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE; + + for (iter =3D top; iter !=3D base; iter =3D bdrv_filtered_bs(iter)) { + if (iter =3D=3D filtered_base) { + /* + * From here on, all nodes are filters on the base. This + * allows us to share BLK_PERM_CONSISTENT_READ. + */ + iter_shared_perms |=3D BLK_PERM_CONSISTENT_READ; + } + ret =3D block_job_add_bdrv(&s->common, "intermediate node", iter, = 0, - BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE, - errp); + iter_shared_perms, errp); if (ret < 0) { goto fail; } @@ -340,9 +390,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, } =20 s->base =3D blk_new(s->common.job.aio_context, - BLK_PERM_CONSISTENT_READ - | BLK_PERM_WRITE - | BLK_PERM_RESIZE, + perms, BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD | BLK_PERM_WRITE_UNCHANGED); @@ -408,19 +456,22 @@ int bdrv_commit(BlockDriverState *bs) if (!drv) return -ENOMEDIUM; =20 - if (!bs->backing) { + backing_file_bs =3D bdrv_filtered_cow_bs(bs); + + if (!backing_file_bs) { return -ENOTSUP; } =20 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT_SOURCE, NULL) || - bdrv_op_is_blocked(bs->backing->bs, BLOCK_OP_TYPE_COMMIT_TARGET, N= ULL)) { + bdrv_op_is_blocked(backing_file_bs, BLOCK_OP_TYPE_COMMIT_TARGET, N= ULL)) + { return -EBUSY; } =20 - ro =3D bs->backing->bs->read_only; + ro =3D backing_file_bs->read_only; =20 if (ro) { - if (bdrv_reopen_set_read_only(bs->backing->bs, false, NULL)) { + if (bdrv_reopen_set_read_only(backing_file_bs, false, NULL)) { return -EACCES; } } @@ -436,8 +487,6 @@ int bdrv_commit(BlockDriverState *bs) } =20 /* Insert commit_top block node above backing, so we can write to it */ - backing_file_bs =3D backing_bs(bs); - commit_top_bs =3D bdrv_new_open_driver(&bdrv_commit_top, NULL, BDRV_O_= RDWR, &local_err); if (commit_top_bs =3D=3D NULL) { @@ -522,15 +571,13 @@ ro_cleanup: qemu_vfree(buf); =20 blk_unref(backing); - if (backing_file_bs) { - bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); - } + bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); bdrv_unref(commit_top_bs); blk_unref(src); =20 if (ro) { /* ignoring error return here */ - bdrv_reopen_set_read_only(bs->backing->bs, true, NULL); + bdrv_reopen_set_read_only(backing_file_bs, true, NULL); } =20 return ret; diff --git a/blockdev.c b/blockdev.c index 605e7b0994..5036d064d4 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1095,7 +1095,7 @@ void hmp_commit(Monitor *mon, const QDict *qdict) return; } =20 - bs =3D blk_bs(blk); + bs =3D bdrv_skip_implicit_filters(blk_bs(blk)); aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 @@ -3392,7 +3392,9 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, =20 assert(bdrv_get_aio_context(base_bs) =3D=3D aio_context); =20 - for (iter =3D top_bs; iter !=3D backing_bs(base_bs); iter =3D backing_= bs(iter)) { + for (iter =3D top_bs; iter !=3D bdrv_filtered_bs(base_bs); + iter =3D bdrv_filtered_bs(iter)) + { if (bdrv_op_is_blocked(iter, BLOCK_OP_TYPE_COMMIT_TARGET, errp)) { goto out; } --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560380195; cv=none; d=zoho.com; s=zohoarc; b=ctcW3iC6wrzYY7scL4zSh0cj8SfkdT4JTH9PaJA1W9ZZFr8Ug6ROM+KnV5IjJlPkxRHEdnwgJnWpw8u8hdhZtox6hAXaLhDE/zAgKO70/7WtBcHD/m6M+okUN1+HvnU05+5xoyX0JQRRFdTg8FyYl8j6AvlVm2/Nq5lTO1abXfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560380195; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=hxfjV82+RRMUADeGMUiFM5Q3Ls/vN+T7pDRCiVVaWC8=; b=SRkH1q38kQVlkdQgVSkbTetrJ5+isBspXodUpNsFwJvIjs7ANCLKR0lXXH45BES6CV9D7mls6TTI/D5kpOqxImDXbusTkrzGRyNVMobOL1e0gY5duepyJ1cnnJY6BgK3dEi2LXqVOtYHpo/FCQ1JxQ96PsvfNMAifWAU2up32lI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560380195618951.4705962810199; Wed, 12 Jun 2019 15:56:35 -0700 (PDT) Received: from localhost ([::1]:35766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbCAS-0001ik-Kh for importer@patchew.org; Wed, 12 Jun 2019 18:56:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46212) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSz-000071-0P for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSx-0008F5-35 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSo-00085n-Fb; Wed, 12 Jun 2019 18:11:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79DEA30C31A6; Wed, 12 Jun 2019 22:11:19 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 08F7A1710F; Wed, 12 Jun 2019 22:11:18 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:50 +0200 Message-Id: <20190612221004.2317-29-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 12 Jun 2019 22:11:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 28/42] stream: Deal with filters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- qapi/block-core.json | 4 ++++ block/stream.c | 23 +++++++++++++++-------- blockdev.c | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index df52a90736..a3c5298cf5 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2518,6 +2518,10 @@ # On successful completion the image file is updated to drop the backing f= ile # and the BLOCK_JOB_COMPLETED event is emitted. # +# In case @device is a filter node, block-stream modifies the first non-fi= lter +# overlay node below it to point to base's backing node (or NULL if @base = was +# not specified) instead of modifying @device itself. +# # @job-id: identifier for the newly-created block job. If # omitted, the device name will be used. (Since 2.7) # diff --git a/block/stream.c b/block/stream.c index 1a906fd860..9271e1821a 100644 --- a/block/stream.c +++ b/block/stream.c @@ -63,6 +63,7 @@ static int stream_prepare(Job *job) StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockJob *bjob =3D &s->common; BlockDriverState *bs =3D blk_bs(bjob->blk); + BlockDriverState *unfiltered_bs =3D bdrv_skip_rw_filters(bs); BlockDriverState *base =3D s->base; Error *local_err =3D NULL; int ret =3D 0; @@ -70,7 +71,7 @@ static int stream_prepare(Job *job) bdrv_unfreeze_backing_chain(bs, base); s->chain_frozen =3D false; =20 - if (bs->backing) { + if (bdrv_filtered_cow_child(unfiltered_bs)) { const char *base_id =3D NULL, *base_fmt =3D NULL; if (base) { base_id =3D s->backing_file_str; @@ -78,8 +79,8 @@ static int stream_prepare(Job *job) base_fmt =3D base->drv->format_name; } } - ret =3D bdrv_change_backing_file(bs, base_id, base_fmt); - bdrv_set_backing_hd(bs, base, &local_err); + ret =3D bdrv_change_backing_file(unfiltered_bs, base_id, base_fmt); + bdrv_set_backing_hd(unfiltered_bs, base, &local_err); if (local_err) { error_report_err(local_err); return -EPERM; @@ -110,7 +111,9 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockBackend *blk =3D s->common.blk; BlockDriverState *bs =3D blk_bs(blk); + BlockDriverState *unfiltered_bs =3D bdrv_skip_rw_filters(bs); BlockDriverState *base =3D s->base; + BlockDriverState *filtered_base; int64_t len; int64_t offset =3D 0; uint64_t delay_ns =3D 0; @@ -119,10 +122,12 @@ static int coroutine_fn stream_run(Job *job, Error **= errp) int64_t n =3D 0; /* bytes */ void *buf; =20 - if (!bs->backing) { + if (!bdrv_filtered_cow_child(unfiltered_bs)) { goto out; } =20 + filtered_base =3D bdrv_filtered_cow_bs(bdrv_find_overlay(bs, base)); + len =3D bdrv_getlength(bs); if (len < 0) { ret =3D len; @@ -154,14 +159,14 @@ static int coroutine_fn stream_run(Job *job, Error **= errp) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n); + ret =3D bdrv_is_allocated(unfiltered_bs, offset, STREAM_BUFFER_SIZ= E, &n); if (ret =3D=3D 1) { /* Allocated in the top, no need to copy. */ } else if (ret >=3D 0) { /* Copy if allocated in the intermediate images. Limit to the * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE).= */ - ret =3D bdrv_is_allocated_above(backing_bs(bs), base, - offset, n, &n); + ret =3D bdrv_is_allocated_above(bdrv_filtered_cow_bs(unfiltere= d_bs), + filtered_base, offset, n, &n); =20 /* Finish early if end of backing file has been reached */ if (ret =3D=3D 0 && n =3D=3D 0) { @@ -266,7 +271,9 @@ void stream_start(const char *job_id, BlockDriverState = *bs, * disappear from the chain after this operation. The streaming job re= ads * every block only once, assuming that it doesn't change, so block wr= ites * and resizes. */ - for (iter =3D backing_bs(bs); iter && iter !=3D base; iter =3D backing= _bs(iter)) { + for (iter =3D bdrv_filtered_bs(bs); iter && iter !=3D base; + iter =3D bdrv_filtered_bs(iter)) + { block_job_add_bdrv(&s->common, "intermediate node", iter, 0, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHA= NGED, &error_abort); diff --git a/blockdev.c b/blockdev.c index 5036d064d4..a464cabf9e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3235,7 +3235,7 @@ void qmp_block_stream(bool has_job_id, const char *jo= b_id, const char *device, } =20 /* Check for op blockers in the whole chain between bs and base */ - for (iter =3D bs; iter && iter !=3D base_bs; iter =3D backing_bs(iter)= ) { + for (iter =3D bs; iter && iter !=3D base_bs; iter =3D bdrv_filtered_bs= (iter)) { if (bdrv_op_is_blocked(iter, BLOCK_OP_TYPE_STREAM, errp)) { goto out; } --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379443; cv=none; d=zoho.com; s=zohoarc; b=Hr9H2IwRLljyvKO+zf6Qf0h2pKtsR7uswGN7A1bcsbW8UgXhJ3A3iQzgeVEpKRwx64diinkPXkBskYnt7Q67ql7BOq5ckePqNc1bT62slOT1lkfvNc3lv4negAWJUUober3N3PwyzTMru9j1/dWffbluQeQltECeDwLbIDWAWrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379443; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=qit8q+wS8F5RUdgLwSHbtXbaB+gLzyn20a9M8qZyRx8=; b=X76NPD2rZADOXJfSQ/4Mls0iNeHrm3HXkuINXsyL5qOWHvtm5f0wo0YM7BAYp5SFrxUxommPJvT5SbWpELURhhxPwFhRmRT8Ge4RKKUpGtSWL3z3vT2FyYwENIaOxVBoyVltNNvTpKfUQ3CuOQcnYU+Vr1Asy/OYK7EMUu8S3kg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379443782313.05694403653854; Wed, 12 Jun 2019 15:44:03 -0700 (PDT) Received: from localhost ([::1]:35644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbByJ-0005cj-Nw for importer@patchew.org; Wed, 12 Jun 2019 18:43:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46152) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSt-0008U0-EG for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSs-0008D2-HS for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSm-00086h-EH; Wed, 12 Jun 2019 18:11:26 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F17D4223873; Wed, 12 Jun 2019 22:11:21 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84D0719C67; Wed, 12 Jun 2019 22:11:21 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:51 +0200 Message-Id: <20190612221004.2317-30-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 12 Jun 2019 22:11:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 29/42] nbd: Use CAF when looking for dirty bitmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When looking for a dirty bitmap to share, we should handle filters by just including them in the search (so they do not break backing chains). Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index aeca3893fe..0d51d46b81 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1508,13 +1508,13 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uin= t64_t dev_offset, if (bitmap) { BdrvDirtyBitmap *bm =3D NULL; =20 - while (true) { + while (bs) { bm =3D bdrv_find_dirty_bitmap(bs, bitmap); - if (bm !=3D NULL || bs->backing =3D=3D NULL) { + if (bm !=3D NULL) { break; } =20 - bs =3D bs->backing->bs; + bs =3D bdrv_filtered_bs(bs); } =20 if (bm =3D=3D NULL) { --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379985; cv=none; d=zoho.com; s=zohoarc; b=FaoKHWm5BsNTFOMOJyek5yQ6QoCkYdZEVOCuLyVG7/+uzeWWdlyIeoJUtpqHTSh2WH1wm3Lnulr/jn0uILZHVonaGZvJky6zm3W38qHudemWK0y+Ds9oKKkuU5u0t4bQ7p67perP1Pm7El4ZTGUHQnCaL55l6LzfWjBmwfeLbOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379985; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Vy7Ajr6001XyN1z1W/iKzsM9rCrdcmS3LJUnixYhb5s=; b=dAJ+WBXGSUbvurDBhFtj+qq6zUPO/FMP0CavFppxSnT73oVtGhWpkQlIAIlo2XXI9y6ib3UR0aSRiyIx7YA6hXXLU7FifE4gAjXfTIRp5T77puPj457rSBH9x5TQtjSZX9ehzOmBaCpxtRsVxVxadztzPSRxN0J6TWo5hscGnSg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379985069541.1363378500884; Wed, 12 Jun 2019 15:53:05 -0700 (PDT) Received: from localhost ([::1]:35748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC73-00076o-3N for importer@patchew.org; Wed, 12 Jun 2019 18:53:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46218) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSz-00007K-7Z for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSx-0008F6-3H for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSo-00088Q-CP; Wed, 12 Jun 2019 18:11:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 771E8C049D67; Wed, 12 Jun 2019 22:11:24 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 097B260CCD; Wed, 12 Jun 2019 22:11:23 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:52 +0200 Message-Id: <20190612221004.2317-31-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Jun 2019 22:11:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 30/42] qemu-img: Use child access functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This changes iotest 204's output, because blkdebug on top of a COW node used to make qemu-img map disregard the rest of the backing chain (the backing chain was broken by the filter). With this patch, the allocation in the base image is reported correctly. Signed-off-by: Max Reitz --- qemu-img.c | 36 ++++++++++++++++++++---------------- tests/qemu-iotests/204.out | 1 + 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 07b6e2a808..7bfa6e5d40 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -992,7 +992,7 @@ static int img_commit(int argc, char **argv) if (!blk) { return 1; } - bs =3D blk_bs(blk); + bs =3D bdrv_skip_implicit_filters(blk_bs(blk)); =20 qemu_progress_init(progress, 1.f); qemu_progress_print(0.f, 100); @@ -1009,7 +1009,7 @@ static int img_commit(int argc, char **argv) /* This is different from QMP, which by default uses the deepest f= ile in * the backing chain (i.e., the very base); however, the tradition= al * behavior of qemu-img commit is using the immediate backing file= . */ - base_bs =3D backing_bs(bs); + base_bs =3D bdrv_filtered_cow_bs(bs); if (!base_bs) { error_setg(&local_err, "Image does not have a backing file"); goto done; @@ -1626,19 +1626,18 @@ static int convert_iteration_sectors(ImgConvertStat= e *s, int64_t sector_num) =20 if (s->sector_next_status <=3D sector_num) { int64_t count =3D n * BDRV_SECTOR_SIZE; + BlockDriverState *src_bs =3D blk_bs(s->src[src_cur]); + BlockDriverState *base; =20 if (s->target_has_backing) { - - ret =3D bdrv_block_status(blk_bs(s->src[src_cur]), - (sector_num - src_cur_offset) * - BDRV_SECTOR_SIZE, - count, &count, NULL, NULL); + base =3D bdrv_backing_chain_next(src_bs); } else { - ret =3D bdrv_block_status_above(blk_bs(s->src[src_cur]), NULL, - (sector_num - src_cur_offset) * - BDRV_SECTOR_SIZE, - count, &count, NULL, NULL); + base =3D NULL; } + ret =3D bdrv_block_status_above(src_bs, base, + (sector_num - src_cur_offset) * + BDRV_SECTOR_SIZE, + count, &count, NULL, NULL); if (ret < 0) { error_report("error while reading block status of sector %" PR= Id64 ": %s", sector_num, strerror(-ret)); @@ -2439,7 +2438,8 @@ static int img_convert(int argc, char **argv) * s.target_backing_sectors has to be negative, which it will * be automatically). The backing file length is used only * for optimizations, so such a case is not fatal. */ - s.target_backing_sectors =3D bdrv_nb_sectors(out_bs->backing->bs); + s.target_backing_sectors =3D + bdrv_nb_sectors(bdrv_filtered_cow_bs(out_bs)); } else { s.target_backing_sectors =3D -1; } @@ -2802,6 +2802,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, =20 depth =3D 0; for (;;) { + bs =3D bdrv_skip_rw_filters(bs); ret =3D bdrv_block_status(bs, offset, bytes, &bytes, &map, &file); if (ret < 0) { return ret; @@ -2810,7 +2811,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, if (ret & (BDRV_BLOCK_ZERO|BDRV_BLOCK_DATA)) { break; } - bs =3D backing_bs(bs); + bs =3D bdrv_filtered_cow_bs(bs); if (bs =3D=3D NULL) { ret =3D 0; break; @@ -2949,7 +2950,7 @@ static int img_map(int argc, char **argv) if (!blk) { return 1; } - bs =3D blk_bs(blk); + bs =3D bdrv_skip_implicit_filters(blk_bs(blk)); =20 if (output_format =3D=3D OFORMAT_HUMAN) { printf("%-16s%-16s%-16s%s\n", "Offset", "Length", "Mapped to", "Fi= le"); @@ -3165,6 +3166,7 @@ static int img_rebase(int argc, char **argv) uint8_t *buf_old =3D NULL; uint8_t *buf_new =3D NULL; BlockDriverState *bs =3D NULL, *prefix_chain_bs =3D NULL; + BlockDriverState *unfiltered_bs; char *filename; const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg; int c, flags, src_flags, ret; @@ -3299,6 +3301,8 @@ static int img_rebase(int argc, char **argv) } bs =3D blk_bs(blk); =20 + unfiltered_bs =3D bdrv_skip_rw_filters(bs); + if (out_basefmt !=3D NULL) { if (bdrv_find_format(out_basefmt) =3D=3D NULL) { error_report("Invalid format name: '%s'", out_basefmt); @@ -3310,7 +3314,7 @@ static int img_rebase(int argc, char **argv) /* For safe rebasing we need to compare old and new backing file */ if (!unsafe) { QDict *options =3D NULL; - BlockDriverState *base_bs =3D backing_bs(bs); + BlockDriverState *base_bs =3D bdrv_filtered_cow_bs(unfiltered_bs); =20 if (base_bs) { blk_old_backing =3D blk_new(qemu_get_aio_context(), @@ -3463,7 +3467,7 @@ static int img_rebase(int argc, char **argv) * If cluster wasn't changed since prefix_chain, we don't = need * to take action */ - ret =3D bdrv_is_allocated_above(backing_bs(bs), prefix_cha= in_bs, + ret =3D bdrv_is_allocated_above(unfiltered_bs, prefix_chai= n_bs, offset, n, &n); if (ret < 0) { error_report("error while reading image metadata: %s", diff --git a/tests/qemu-iotests/204.out b/tests/qemu-iotests/204.out index f3a10fbe90..684774d763 100644 --- a/tests/qemu-iotests/204.out +++ b/tests/qemu-iotests/204.out @@ -59,5 +59,6 @@ Offset Length File 0x900000 0x2400000 TEST_DIR/t.IMGFMT 0x3c00000 0x1100000 TEST_DIR/t.IMGFMT 0x6a00000 0x400000 TEST_DIR/t.IMGFMT +0x6e00000 0x1200000 TEST_DIR/t.IMGFMT.base No errors were found on the image. *** done --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379799; cv=none; d=zoho.com; s=zohoarc; b=daSn8rTWVxFE40ff6dDkh+acjdgXRs/BrCZUsOUjet/IdJbivrFXpf9HEdFk28q0wtZ8P3JCA/9hXNaRxPlnNO0jmOTjZruM++PeVHBHGBY/s4TEkfbTmci/nHDi+GnwcO4ZtjvQbPmOtEvUcPmczGdPSyiKJt1PHkUd3Tw208g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379799; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9JylQLQx9l8Z24f1hOYreDxVjcsHLD5apesXgXXl7uY=; b=dnrCoeikR9Dkfs8FF72phtJL/laKcNNgB5fEr8sE6ucIlZtgXrQnBGyn0ga7UmrDCVjDD024f43/29HIXJja9GoYyf5gxk5bnluTRRt0On4LHAyt304WgP6G3OIwoYaqfZAMwx8PVLDpAGZxoPVrUhDAIT0G+cbfgA12Ep3ZLpA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379799281400.68319017669376; Wed, 12 Jun 2019 15:49:59 -0700 (PDT) Received: from localhost ([::1]:35716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC44-0003qn-7w for importer@patchew.org; Wed, 12 Jun 2019 18:49:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46195) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBSy-00005S-4k for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSx-0008F3-3N for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:36 -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 1hbBSq-0008AH-9L; Wed, 12 Jun 2019 18:11:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3E1FC18B2EE; Wed, 12 Jun 2019 22:11:26 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88C2C5C298; Wed, 12 Jun 2019 22:11:26 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:53 +0200 Message-Id: <20190612221004.2317-32-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Jun 2019 22:11:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 31/42] block: Drop backing_bs() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We want to make it explicit where bs->backing is used, and we have done so. The old role of backing_bs() is now effectively taken by bdrv_filtered_cow_bs(). Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 875a33f255..c0a05beec3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -925,11 +925,6 @@ typedef enum BlockMirrorBackingMode { MIRROR_LEAVE_BACKING_CHAIN, } BlockMirrorBackingMode; =20 -static inline BlockDriverState *backing_bs(BlockDriverState *bs) -{ - return bs->backing ? bs->backing->bs : NULL; -} - =20 /* Essential block drivers which must always be statically linked into qem= u, and * which therefore can be accessed without using bdrv_find_format() */ --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379483; cv=none; d=zoho.com; s=zohoarc; b=P8YNVpDis8j3GuMjZBYQN9egZmNSrFXAvT7OrNgyBQTazxXUtCAnDK/zUVUB7wAmx1lflG+ONAotudiX6rVItG1IFwD7tDx62roFCRUEKYX0+P+XUa896dFjAyah//2X9Xl671P+oXGITaCNYsNQnTw6XjKnrk2OQjha+QcDkSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379483; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=dnKR82aKIHXA0WCHrLjHl1INwx+x5cYlzP3YBOOQjO0=; b=hzrT6AKfpToloPKr3yUln7Mi4URu6WSIKCza0jDvZDzrnJV/gtMaDRzSIMKJicCUoa0oKqefX1silKyRY3EkJf+6fArLuTokY1Nhwfba0XYDApnLcj6Z/vvwAXx/HrfZg8BneqNnbQzMP4D8nyeAf4mJ+hnJnMX5HRtauh+/DEY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379483544604.7517506456076; Wed, 12 Jun 2019 15:44:43 -0700 (PDT) Received: from localhost ([::1]:35650 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbByy-0006c1-V8 for importer@patchew.org; Wed, 12 Jun 2019 18:44:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46240) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBT1-00007V-14 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBSz-0008GS-2E for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSs-0008C4-Ar; Wed, 12 Jun 2019 18:11:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86AFE30F1BD6; Wed, 12 Jun 2019 22:11:29 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 123CB60CCD; Wed, 12 Jun 2019 22:11:28 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:54 +0200 Message-Id: <20190612221004.2317-33-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Jun 2019 22:11:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 32/42] block: Make bdrv_get_cumulative_perm() public X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is useful in other files like blockdev.c to determine for example whether a node can be written to or not. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 3 +++ block.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index c0a05beec3..cfefb00104 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1181,6 +1181,9 @@ void bdrv_root_unref_child(BdrvChild *child); int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, Error **errp); =20 +void bdrv_get_cumulative_perm(BlockDriverState *bs, + uint64_t *perm, uint64_t *shared_perm); + /* Default implementation for BlockDriver.bdrv_child_perm() that can be us= ed by * block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESI= ZE to * all children */ diff --git a/block.c b/block.c index 856d9b58be..59d1d4b2b1 100644 --- a/block.c +++ b/block.c @@ -1711,8 +1711,6 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockR= eopenQueue *q, 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); -static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, - uint64_t *shared_perm); =20 typedef struct BlockReopenQueueEntry { bool prepared; @@ -1904,8 +1902,8 @@ static void bdrv_set_perm(BlockDriverState *bs, uint6= 4_t cumulative_perms, } } =20 -static void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, - uint64_t *shared_perm) +void bdrv_get_cumulative_perm(BlockDriverState *bs, + uint64_t *perm, uint64_t *shared_perm) { BdrvChild *c; uint64_t cumulative_perms =3D 0; --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560380337; cv=none; d=zoho.com; s=zohoarc; b=bTjpVwpvh+7HsrTxKYt610mn7MWiIvTCZ3pdi47J/aebNOIAIJgYeR5Nwq+YEgrk8COLkhUbnlsK9di1DfKvSg9SuyC5YSuVbh7q5UMV+9ds0tHvLXSMDbMfZsCKCarUpmqU5XoY3+0SUptf7JEPcuP/Lwv7aYagpfxYt8Woz94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560380337; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=V2dlv7wJgiGZFPpppMf38koP8HUK85AQpqD4DJlNd10=; b=Ay2rijWVSeuExFeeQ9fblrJS4eBIYX2S7X/P+Ahq3q6F4U1+ywrpzdlSNdFcUdYImMvDultd4eujK8qfw1ahVOHMLc4g2L09BUypPIoiRkraADQScaBgUAnAFifF0wtNIJTV4yrCQA6clRJoqJAB1lMRxVQdtQkDhryjnsSWSlc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560380337916884.9750022229481; Wed, 12 Jun 2019 15:58:57 -0700 (PDT) Received: from localhost ([::1]:35800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbCCh-00056s-T9 for importer@patchew.org; Wed, 12 Jun 2019 18:58:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46282) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBT4-0000Cl-V5 for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBT2-0008Ih-RE for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSx-0008E4-5K; Wed, 12 Jun 2019 18:11:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22DDEA3B6F; Wed, 12 Jun 2019 22:11:32 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A37B75DEDF; Wed, 12 Jun 2019 22:11:31 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:55 +0200 Message-Id: <20190612221004.2317-34-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 12 Jun 2019 22:11:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 33/42] blockdev: Fix active commit choice X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We have to perform an active commit whenever the top node has a parent that has taken the WRITE permission on it. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- blockdev.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index a464cabf9e..5370f3b738 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3294,6 +3294,7 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, */ BlockdevOnError on_error =3D BLOCKDEV_ON_ERROR_REPORT; int job_flags =3D JOB_DEFAULT; + uint64_t top_perm, top_shared; =20 if (!has_speed) { speed =3D 0; @@ -3406,14 +3407,31 @@ void qmp_block_commit(bool has_job_id, const char *= job_id, const char *device, goto out; } =20 - if (top_bs =3D=3D bs) { + /* + * Active commit is required if and only if someone has taken a + * WRITE permission on the top node. Historically, we have always + * used active commit for top nodes, so continue that practice. + * (Active commit is never really wrong.) + */ + bdrv_get_cumulative_perm(top_bs, &top_perm, &top_shared); + if (top_perm & BLK_PERM_WRITE || + bdrv_skip_rw_filters(top_bs) =3D=3D bdrv_skip_rw_filters(bs)) + { if (has_backing_file) { error_setg(errp, "'backing-file' specified," " but 'top' is the active layer"); goto out; } - commit_active_start(has_job_id ? job_id : NULL, bs, base_bs, - job_flags, speed, on_error, + if (!has_job_id) { + /* + * Emulate here what block_job_create() does, because it + * is possible that @bs !=3D @top_bs (the block job should + * be named after @bs, even if @top_bs is the actual + * source) + */ + job_id =3D bdrv_get_device_name(bs); + } + commit_active_start(job_id, top_bs, base_bs, job_flags, speed, on_= error, filter_node_name, NULL, NULL, false, &local_er= r); } else { BlockDriverState *overlay_bs =3D bdrv_find_overlay(bs, top_bs); --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379755; cv=none; d=zoho.com; s=zohoarc; b=Z1j56uVR4mebh72Ujjs54X2atdrcEAaEZcxJ/RJ6anELBB7oRsq/vuxCEiWUO7QcDim8H760z+KWWgWHI7aIxH3sJVp9jrWDPJtZ0Lh3ff6OAA+COJUoC1Ma0/usmERcfF0wz1jLrboa/oDGs5yyhsFNGQwCGUZpIT8WkBHm8iM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379755; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=rsAeW2d9K1Vt948MNRStQ3YrqjYh4ksuQEpNw0hJp6c=; b=KwQalmzDl0CJX77LZURGgW9VbL2YveF2xzQXot0K/DSj8PoYOoje4MzLrCwMlSnFFxhYEjjtqS1iw+BlVaaYpIcr2ODS1ZJbEi+KvAYCHsgsxv2vfpi7+cgcb7vd/k6y8TQbxu6QOX9BZnQt/p6jBpWN4dLNBWwlQ4+pI3O1Z64= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379755852381.2642931474119; Wed, 12 Jun 2019 15:49:15 -0700 (PDT) Received: from localhost ([::1]:35704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC3N-0002Vk-NL for importer@patchew.org; Wed, 12 Jun 2019 18:49:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46323) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBT6-0000DU-PY for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBT4-0008Jh-Oi for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBSx-0008Ex-Qt; Wed, 12 Jun 2019 18:11:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8D0880B2C; Wed, 12 Jun 2019 22:11:34 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 306205ED35; Wed, 12 Jun 2019 22:11:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:56 +0200 Message-Id: <20190612221004.2317-35-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 12 Jun 2019 22:11:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 34/42] block: Inline bdrv_co_block_status_from_*() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" With bdrv_filtered_rw_bs(), we can easily handle this default filter behavior in bdrv_co_block_status(). blkdebug wants to have an additional assertion, so it keeps its own implementation, except bdrv_co_block_status_from_file() needs to be inlined there. Suggested-by: Eric Blake Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 22 ----------------- block/blkdebug.c | 7 ++++-- block/blklogwrites.c | 1 - block/commit.c | 1 - block/copy-on-read.c | 2 -- block/io.c | 51 +++++++++++++-------------------------- block/mirror.c | 1 - block/throttle.c | 1 - 8 files changed, 22 insertions(+), 64 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index cfefb00104..431fa38ea0 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1203,28 +1203,6 @@ void bdrv_format_default_perms(BlockDriverState *bs,= BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); =20 -/* - * Default implementation for drivers to pass bdrv_co_block_status() to - * their file. - */ -int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file); -/* - * Default implementation for drivers to pass bdrv_co_block_status() to - * their backing file. - */ -int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file= ); const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); bool blk_dev_has_removable_media(BlockBackend *blk); diff --git a/block/blkdebug.c b/block/blkdebug.c index efd9441625..7950ae729c 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -637,8 +637,11 @@ static int coroutine_fn blkdebug_co_block_status(Block= DriverState *bs, BlockDriverState **file) { assert(QEMU_IS_ALIGNED(offset | bytes, bs->bl.request_alignment)); - return bdrv_co_block_status_from_file(bs, want_zero, offset, bytes, - pnum, map, file); + assert(bs->file && bs->file->bs); + *pnum =3D bytes; + *map =3D offset; + *file =3D bs->file->bs; + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 static void blkdebug_close(BlockDriverState *bs) diff --git a/block/blklogwrites.c b/block/blklogwrites.c index eb2b4901a5..1eb4a5c613 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -518,7 +518,6 @@ static BlockDriver bdrv_blk_log_writes =3D { .bdrv_co_pwrite_zeroes =3D blk_log_writes_co_pwrite_zeroes, .bdrv_co_flush_to_disk =3D blk_log_writes_co_flush_to_disk, .bdrv_co_pdiscard =3D blk_log_writes_co_pdiscard, - .bdrv_co_block_status =3D bdrv_co_block_status_from_file, =20 .is_filter =3D true, .strong_runtime_opts =3D blk_log_writes_strong_runtime_opts, diff --git a/block/commit.c b/block/commit.c index ec5a8c8edf..a5b58eadeb 100644 --- a/block/commit.c +++ b/block/commit.c @@ -257,7 +257,6 @@ static void bdrv_commit_top_child_perm(BlockDriverState= *bs, BdrvChild *c, static BlockDriver bdrv_commit_top =3D { .format_name =3D "commit_top", .bdrv_co_preadv =3D bdrv_commit_top_preadv, - .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_commit_top_refresh_filename, .bdrv_child_perm =3D bdrv_commit_top_child_perm, =20 diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 88e1c1f538..5a292de000 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -161,8 +161,6 @@ static BlockDriver bdrv_copy_on_read =3D { .bdrv_eject =3D cor_eject, .bdrv_lock_medium =3D cor_lock_medium, =20 - .bdrv_co_block_status =3D bdrv_co_block_status_from_file, - .bdrv_recurse_is_first_non_filter =3D cor_recurse_is_first_non_filte= r, =20 .has_variable_length =3D true, diff --git a/block/io.c b/block/io.c index 14f99e1c00..0a832e30a3 100644 --- a/block/io.c +++ b/block/io.c @@ -1998,36 +1998,6 @@ typedef struct BdrvCoBlockStatusData { bool done; } BdrvCoBlockStatusData; =20 -int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file) -{ - assert(bs->file && bs->file->bs); - *pnum =3D bytes; - *map =3D offset; - *file =3D bs->file->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; -} - -int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file) -{ - assert(bs->backing && bs->backing->bs); - *pnum =3D bytes; - *map =3D offset; - *file =3D bs->backing->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; -} - /* * Returns the allocation status of the specified sectors. * Drivers not implementing the functionality are assumed to not support @@ -2068,6 +2038,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, BlockDriverState *local_file =3D NULL; int64_t aligned_offset, aligned_bytes; uint32_t align; + bool has_filtered_child; =20 assert(pnum); *pnum =3D 0; @@ -2093,7 +2064,8 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, =20 /* Must be non-NULL or bdrv_getlength() would have failed */ assert(bs->drv); - if (!bs->drv->bdrv_co_block_status) { + has_filtered_child =3D bs->drv->is_filter && bdrv_filtered_rw_child(bs= ); + if (!bs->drv->bdrv_co_block_status && !has_filtered_child) { *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; if (offset + bytes =3D=3D total_size) { @@ -2114,9 +2086,20 @@ static int coroutine_fn bdrv_co_block_status(BlockDr= iverState *bs, aligned_offset =3D QEMU_ALIGN_DOWN(offset, align); aligned_bytes =3D ROUND_UP(offset + bytes, align) - aligned_offset; =20 - ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offset, - aligned_bytes, pnum, &local_map, - &local_file); + if (bs->drv->bdrv_co_block_status) { + ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offse= t, + aligned_bytes, pnum, &local_ma= p, + &local_file); + } else { + /* Default code for filters */ + + local_file =3D bdrv_filtered_rw_bs(bs); + assert(local_file); + + *pnum =3D aligned_bytes; + local_map =3D aligned_offset; + ret =3D BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; + } if (ret < 0) { *pnum =3D 0; goto out; diff --git a/block/mirror.c b/block/mirror.c index 3d767e3030..71bd7f7625 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1484,7 +1484,6 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_pwrite_zeroes =3D bdrv_mirror_top_pwrite_zeroes, .bdrv_co_pdiscard =3D bdrv_mirror_top_pdiscard, .bdrv_co_flush =3D bdrv_mirror_top_flush, - .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_mirror_top_refresh_filename, .bdrv_child_perm =3D bdrv_mirror_top_child_perm, =20 diff --git a/block/throttle.c b/block/throttle.c index de1b6bd7e8..32ec56db0f 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -269,7 +269,6 @@ static BlockDriver bdrv_throttle =3D { .bdrv_reopen_prepare =3D throttle_reopen_prepare, .bdrv_reopen_commit =3D throttle_reopen_commit, .bdrv_reopen_abort =3D throttle_reopen_abort, - .bdrv_co_block_status =3D bdrv_co_block_status_from_fi= le, =20 .bdrv_co_drain_begin =3D throttle_co_drain_begin, .bdrv_co_drain_end =3D throttle_co_drain_end, --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379918; cv=none; d=zoho.com; s=zohoarc; b=Pre/qrEkQHan8lW2I2jjZz2ib/0IBr8pMt2z87Lkx/r3xSTBkZzY7R5v73jDJd2obtIEaUEodWEiwRe+YxnRtnPVfjfsJL9tfcuWOOU2W+JjxmgXdvLACPrcbpd624RsVaJN0306QkVwwoICV+GrqSSIaGuwelvvOyAaQ9gA3mA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379918; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=EIANTEhF/cjPqEWy1zVdq2Z2+SlLfHhdUXIZIpX2e/I=; b=ldIHgnXSfXJglY+n0HDBEmsVb5PtI5nDJJV4uq90wYRmuTnVR/u/YyG72P7cmiRROaVJRKJ60NWUNXfKSgYgnvee0NRO7hwi7UcOI2z6tRIBJqGTzukuliaEndzVsbamqLPVkprvF8CUk97mRk3PIXVFOzvGe5Iwp0rliU+6oYw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379918354948.2386067568717; Wed, 12 Jun 2019 15:51:58 -0700 (PDT) Received: from localhost ([::1]:35736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC5z-0005r8-Cc for importer@patchew.org; Wed, 12 Jun 2019 18:51:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46388) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTC-0000Kp-9y for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTA-0008Nh-KU for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59012) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBT1-0008H7-1I; Wed, 12 Jun 2019 18:11:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9137064A72; Wed, 12 Jun 2019 22:11:37 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7ADB5C236; Wed, 12 Jun 2019 22:11:36 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:57 +0200 Message-Id: <20190612221004.2317-36-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 12 Jun 2019 22:11:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 35/42] block: Fix check_to_replace_node() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, check_to_replace_node() only allows mirror to replace a node in the chain of the source node, and only if it is the first non-filter node below the source. Well, technically, the idea is that you can exactly replace a quorum child by mirroring from quorum. This has (probably) two reasons: (1) We do not want to create loops. (2) @replaces and @device should have exactly the same content so replacing them does not cause visible data to change. This has two issues: (1) It is overly restrictive. It is completely fine for @replaces to be a filter. (2) It is not restrictive enough. You can create loops with this as follows: $ qemu-img create -f qcow2 /tmp/source.qcow2 64M $ qemu-system-x86_64 -qmp stdio {"execute": "qmp_capabilities"} {"execute": "object-add", "arguments": {"qom-type": "throttle-group", "id": "tg0"}} {"execute": "blockdev-add", "arguments": { "node-name": "source", "driver": "throttle", "throttle-group": "tg0", "file": { "node-name": "filtered", "driver": "qcow2", "file": { "driver": "file", "filename": "/tmp/source.qcow2" } } } } {"execute": "drive-mirror", "arguments": { "job-id": "mirror", "device": "source", "target": "/tmp/target.qcow2", "format": "qcow2", "node-name": "target", "sync" :"none", "replaces": "filtered" } } {"execute": "block-job-complete", "arguments": {"device": "mirror"}} And qemu crashes because of a stack overflow due to the loop being created (target's backing file is source, so when it replaces filtered, it points to itself through source). (blockdev-mirror can be broken similarly.) So let us make the checks for the two conditions above explicit, which makes the whole function exactly as restrictive as it needs to be. Signed-off-by: Max Reitz --- include/block/block.h | 1 + block.c | 83 +++++++++++++++++++++++++++++++++++++++---- blockdev.c | 34 ++++++++++++++++-- 3 files changed, 110 insertions(+), 8 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 7835c5b370..484c0af766 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -404,6 +404,7 @@ bool bdrv_is_first_non_filter(BlockDriverState *candida= te); =20 /* check if a named node can be replaced when doing drive-mirror */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, + BlockDriverState *backing_bs, const char *node_name, Error **err= p); =20 /* async block I/O */ diff --git a/block.c b/block.c index 59d1d4b2b1..e129869a7e 100644 --- a/block.c +++ b/block.c @@ -6142,7 +6142,59 @@ bool bdrv_is_first_non_filter(BlockDriverState *cand= idate) return false; } =20 +static bool is_child_of(BlockDriverState *child, BlockDriverState *parent) +{ + BdrvChild *c; + + if (!parent) { + return false; + } + + QLIST_FOREACH(c, &parent->children, next) { + if (c->bs =3D=3D child || is_child_of(child, c->bs)) { + return true; + } + } + + return false; +} + +/* + * Return true if there are only filters in [@top, @base). Note that + * this may include quorum (which bdrv_chain_contains() cannot + * handle). + */ +static bool is_filtered_child(BlockDriverState *top, BlockDriverState *bas= e) +{ + BdrvChild *c; + + if (!top) { + return false; + } + + if (top =3D=3D base) { + return true; + } + + if (!top->drv->is_filter) { + return false; + } + + QLIST_FOREACH(c, &top->children, next) { + if (is_filtered_child(c->bs, base)) { + return true; + } + } + + return false; +} + +/* + * @parent_bs is mirror's source BDS, @backing_bs is the BDS which + * will be attached to the target when mirror completes. + */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, + BlockDriverState *backing_bs, const char *node_name, Error **err= p) { BlockDriverState *to_replace_bs =3D bdrv_find_node(node_name); @@ -6161,13 +6213,32 @@ BlockDriverState *check_to_replace_node(BlockDriver= State *parent_bs, goto out; } =20 - /* We don't want arbitrary node of the BDS chain to be replaced only t= he top - * most non filter in order to prevent data corruption. - * Another benefit is that this tests exclude backing files which are - * blocked by the backing blockers. + /* + * If to_replace_bs is (recursively) a child of backing_bs, + * replacing it may create a loop. We cannot allow that. */ - if (!bdrv_recurse_is_first_non_filter(parent_bs, to_replace_bs)) { - error_setg(errp, "Only top most non filter can be replaced"); + if (to_replace_bs =3D=3D backing_bs || is_child_of(to_replace_bs, back= ing_bs)) { + error_setg(errp, "Replacing this node would result in a loop"); + to_replace_bs =3D NULL; + goto out; + } + + /* + * Mirror is designed in such a way that when it completes, the + * source BDS is seamlessly replaced. It is therefore not allowed + * to replace a BDS where this condition would be violated, as that + * would defeat the purpose of mirror and could lead to data + * corruption. + * Therefore, between parent_bs and to_replace_bs there may be + * only filters (and the one on top must be a filter, too), so + * their data always stays in sync and mirror can complete and + * replace to_replace_bs without any possible corruptions. + */ + if (!is_filtered_child(parent_bs, to_replace_bs) && + !is_filtered_child(to_replace_bs, parent_bs)) + { + error_setg(errp, "The node to be replaced must be connected to the= " + "source through filter nodes only"); to_replace_bs =3D NULL; goto out; } diff --git a/blockdev.c b/blockdev.c index 5370f3b738..6f9f75327e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3813,7 +3813,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, } =20 if (has_replaces) { - BlockDriverState *to_replace_bs; + BlockDriverState *to_replace_bs, *backing_bs; AioContext *replace_aio_context; int64_t bs_size, replace_size; =20 @@ -3823,7 +3823,37 @@ static void blockdev_mirror_common(const char *job_i= d, BlockDriverState *bs, return; } =20 - to_replace_bs =3D check_to_replace_node(bs, replaces, errp); + if (backing_mode =3D=3D MIRROR_SOURCE_BACKING_CHAIN || + backing_mode =3D=3D MIRROR_OPEN_BACKING_CHAIN) + { + /* + * While we do not quite know what OPEN_BACKING_CHAIN + * (used for mode=3Dexisting) will yield, it is probably + * best to restrict it exactly like SOURCE_BACKING_CHAIN, + * because that is our best guess. + */ + switch (sync) { + case MIRROR_SYNC_MODE_FULL: + backing_bs =3D NULL; + break; + + case MIRROR_SYNC_MODE_TOP: + backing_bs =3D bdrv_filtered_cow_bs(bdrv_skip_rw_filters(b= s)); + break; + + case MIRROR_SYNC_MODE_NONE: + backing_bs =3D bs; + break; + + default: + abort(); + } + } else { + assert(backing_mode =3D=3D MIRROR_LEAVE_BACKING_CHAIN); + backing_bs =3D bdrv_filtered_cow_bs(bdrv_skip_rw_filters(targe= t)); + } + + to_replace_bs =3D check_to_replace_node(bs, backing_bs, replaces, = errp); if (!to_replace_bs) { return; } --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560380723; cv=none; d=zoho.com; s=zohoarc; b=bMl32JI+UWnW2sCo1P8jAttocxGwLQy51duja7WZsVuxNBuREwMSHR49F/4PjH9npmqifBGRn1wIqYz8KIvU+88SZ7613Ykzw78vFZ9j6IipvBXfYMRLqJa5+Ca+urVu8pDCg2ClCdiKnXnUQ9hiE+m1DNm0SZIIPLAiFHkDhhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560380723; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0KUuZJj0bTjQ/htLbWj1/S5HxIYgFiyZr8Rc0mI7w08=; b=bJX4uq/ZUhpfqG8NGDOp7iHb7vn9ZYR3UNVAxxuArOUk85Cj6YEYp906yksm/t3MI53aTEOW6JCohmFl7cgfZUxRpOwtwLk+rC3u9AV3miuKyBceJAjuGu9C8B2PLqI8lqn5q18scoHxY/RQ+qfwq6JiZwLObEzZ97FWMxDP5fc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560380723872230.28392688737313; Wed, 12 Jun 2019 16:05:23 -0700 (PDT) Received: from localhost ([::1]:35852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbCIu-0000ae-RJ for importer@patchew.org; Wed, 12 Jun 2019 19:05:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46383) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTC-0000Kf-8F for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTA-0008Nu-Nw for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44004) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBT3-0008IX-3Q; Wed, 12 Jun 2019 18:11:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 223D73001445; Wed, 12 Jun 2019 22:11:40 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A434A5DEDF; Wed, 12 Jun 2019 22:11:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:58 +0200 Message-Id: <20190612221004.2317-37-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Jun 2019 22:11:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 36/42] iotests: Add tests for mirror @replaces loops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This adds two tests for cases where our old check_to_replace_node() function failed to detect that executing this job with these parameters would result in a cyclic graph. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/041 | 124 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 +- 2 files changed, 126 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 26bf1701eb..0c1432f189 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1067,5 +1067,129 @@ class TestOrphanedSource(iotests.QMPTestCase): target=3D'dest-ro') self.assert_qmp(result, 'error/class', 'GenericError') =20 +# Various tests for the @replaces option (independent of quorum) +class TestReplaces(iotests.QMPTestCase): + def setUp(self): + self.vm =3D iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + + def test_drive_mirror_loop(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, '1M') + + result =3D self.vm.qmp('object-add', qom_type=3D'throttle-group', = id=3D'tg') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'source', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'filtered', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + } + } + }) + self.assert_qmp(result, 'return', {}) + + # Mirror from @source to @target in sync=3Dnone, so that @source + # will be @target's backing file; but replace @filtered. + # Then, @target's backing file will be @source, whose backing + # file is now @target instead of @filtered. That is a loop. + # (But apart from the loop, replacing @filtered instead of + # @source is fine, because both are just filtered versions of + # each other.) + result =3D self.vm.qmp('drive-mirror', + job_id=3D'mirror', + device=3D'source', + target=3Dtarget_img, + format=3Diotests.imgfmt, + node_name=3D'target', + sync=3D'none', + replaces=3D'filtered') + if 'error' in result: + # This is the correct result + self.assert_qmp(result, 'error/class', 'GenericError') + else: + # This is wrong, but let's run it to the bitter conclusion + self.complete_and_wait(drive=3D'mirror') + # Fail for good measure, although qemu should have crashed + # anyway + self.fail('Loop creation was successful') + + os.remove(test_img) + try: + os.remove(target_img) + except OSError: + pass + + def test_blockdev_mirror_loop(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, '1M') + qemu_img('create', '-f', iotests.imgfmt, target_img, '1M') + + result =3D self.vm.qmp('object-add', qom_type=3D'throttle-group', = id=3D'tg') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'source', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'middle', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'bottom', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + } + } + } + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'target', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + }, + 'backing': 'middle' + }) + + # Mirror from @source to @target. With blockdev-mirror, the + # current (old) backing file is retained (which is @middle). + # By replacing @bottom, @middle's file will be @target, whose + # backing file is @middle again. That is a loop. + # (But apart from the loop, replacing @bottom instead of + # @source is fine, because both are just filtered versions of + # each other.) + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + sync=3D'full', + replaces=3D'bottom') + if 'error' in result: + # This is the correct result + self.assert_qmp(result, 'error/class', 'GenericError') + else: + # This is wrong, but let's run it to the bitter conclusion + self.complete_and_wait(drive=3D'mirror') + # Fail for good measure, although qemu should have crashed + # anyway + self.fail('Loop creation was successful') + + os.remove(test_img) + os.remove(target_img) + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index e071d0b261..2c448b4239 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= .............. +..........................................................................= ................ ---------------------------------------------------------------------- -Ran 88 tests +Ran 90 tests =20 OK --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379861; cv=none; d=zoho.com; s=zohoarc; b=UfbQD7p5S+BkLn4uHFNg2Yky/BESYrv5UsKdBzoZ6PZo4YU0k5jC/HJ+H0wa/kXAA3YNliPQPTm00BQvM+I9aCyze6uHQOSHal0pnSGq5VpotN7DcvIOF/kcFOSWefguGlzu9fQ8lA0YVuvEJHc1GALrxOBImKhp+u8dBWSKcJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379861; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Z/OjhLPSX6GpCiUvtvZOYzjD+7k9ueI0lLDPDaYQPvQ=; b=fDgyWj845bYc1ZESVEuFazP6KYiMzhXlIm8FysyaTBRFZ9w5kObgf1Rmn07evxxZAd0iZAcKqM4dX4lSk2Pb8mS2OZMgIytZzNsBXzo2mTTBK8W4yMLfO68+kJG0K0ft699AyhXubwKi6ye+saxp6ZdOd9Yk6xgg1P8wqdVgAQE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379861783217.48473699873227; Wed, 12 Jun 2019 15:51:01 -0700 (PDT) Received: from localhost ([::1]:35730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC53-0005Q6-WE for importer@patchew.org; Wed, 12 Jun 2019 18:50:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46474) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTH-0000YL-Ax for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTF-0008RJ-0x for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34878) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBT6-0008KT-L6; Wed, 12 Jun 2019 18:11:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB769A3B69; Wed, 12 Jun 2019 22:11:42 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E9795C236; Wed, 12 Jun 2019 22:11:41 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:09:59 +0200 Message-Id: <20190612221004.2317-38-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 12 Jun 2019 22:11:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 37/42] block: Leave BDS.backing_file constant X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Parts of the block layer treat BDS.backing_file as if it were whatever the image header says (i.e., if it is a relative path, it is relative to the overlay), other parts treat it like a cache for bs->backing->bs->filename (relative paths are relative to the CWD). Considering bs->backing->bs->filename exists, let us make it mean the former. Among other things, this now allows the user to specify a base when using qemu-img to commit an image file in a directory that is not the CWD (assuming, everything uses relative filenames). Before this patch: $ ./qemu-img create -f qcow2 foo/bot.qcow2 1M $ ./qemu-img create -f qcow2 -b bot.qcow2 foo/mid.qcow2 $ ./qemu-img create -f qcow2 -b mid.qcow2 foo/top.qcow2 $ ./qemu-img commit -b mid.qcow2 foo/top.qcow2 qemu-img: Did not find 'mid.qcow2' in the backing chain of 'foo/top.qcow2' $ ./qemu-img commit -b foo/mid.qcow2 foo/top.qcow2 qemu-img: Did not find 'foo/mid.qcow2' in the backing chain of 'foo/top.qco= w2' $ ./qemu-img commit -b $PWD/foo/mid.qcow2 foo/top.qcow2 qemu-img: Did not find '[...]/foo/mid.qcow2' in the backing chain of 'foo/t= op.qcow2' After this patch: $ ./qemu-img commit -b mid.qcow2 foo/top.qcow2 Image committed. $ ./qemu-img commit -b foo/mid.qcow2 foo/top.qcow2 qemu-img: Did not find 'foo/mid.qcow2' in the backing chain of 'foo/top.qco= w2' $ ./qemu-img commit -b $PWD/foo/mid.qcow2 foo/top.qcow2 Image committed. With this change, bdrv_find_backing_image() must look at whether the user has overridden a BDS's backing file. If so, it can no longer use bs->backing_file, but must instead compare the given filename against the backing node's filename directly. Note that this changes the QAPI output for a node's backing_file. We had very inconsistent output there (sometimes what the image header said, sometimes the actual filename of the backing image). This inconsistent output was effectively useless, so we have to decide one way or the other. Considering that bs->backing_file usually at runtime contained the path to the image relative to qemu's CWD (or absolute), this patch changes QAPI's backing_file to always report the bs->backing->bs->filename from now on. If you want to receive the image header information, you have to refer to full-backing-filename. This necessitates a change to iotest 228. The interesting information it really wanted is the image header, and it can get that now, but it has to use full-backing-filename instead of backing_file. Because of this patch's changes to bs->backing_file's behavior, we also need some reference output changes. Along with the changes to bs->backing_file, stop updating BDS.backing_format in bdrv_backing_attach() as well. This necessitates a change to the reference output of iotest 191. iotest 245 changes in behavior: With the backing node no longer overriding the parent node's backing_file string, you can now omit the @backing option when reopening a node with neither a default nor a current backing file even if it used to have a backing node at some point. Signed-off-by: Max Reitz --- include/block/block_int.h | 19 ++++++++++++++----- block.c | 35 ++++++++++++++++++++++++++++------- block/qapi.c | 7 ++++--- tests/qemu-iotests/191.out | 1 - tests/qemu-iotests/228 | 6 +++--- tests/qemu-iotests/228.out | 6 +++--- tests/qemu-iotests/245 | 4 +++- 7 files changed, 55 insertions(+), 23 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 431fa38ea0..02b55cff91 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -777,11 +777,20 @@ struct BlockDriverState { bool walking_aio_notifiers; /* to make removal during iteration safe */ =20 char filename[PATH_MAX]; - char backing_file[PATH_MAX]; /* if non zero, the image is a diff of - this file image */ - /* The backing filename indicated by the image header; if we ever - * open this file, then this is replaced by the resulting BDS's - * filename (i.e. after a bdrv_refresh_filename() run). */ + /* + * If not empty, this image is a diff in relation to backing_file. + * Note that this is the name given in the image header and + * therefore may or may not be equal to .backing->bs->filename. + * If this field contains a relative path, it is to be resolved + * relatively to the overlay's location. + */ + char backing_file[PATH_MAX]; + /* + * The backing filename indicated by the image header. Contrary + * to backing_file, if we ever open this file, auto_backing_file + * is replaced by the resulting BDS's filename (i.e. after a + * bdrv_refresh_filename() run). + */ char auto_backing_file[PATH_MAX]; char backing_format[16]; /* if non-zero and backing_file exists */ =20 diff --git a/block.c b/block.c index e129869a7e..a962e346ab 100644 --- a/block.c +++ b/block.c @@ -78,6 +78,8 @@ static BlockDriverState *bdrv_open_inherit(const char *fi= lename, const BdrvChildRole *child_role, Error **errp); =20 +static bool bdrv_backing_overridden(BlockDriverState *bs); + /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; =20 @@ -1064,10 +1066,6 @@ static void bdrv_backing_attach(BdrvChild *c) bdrv_refresh_filename(backing_hd); =20 parent->open_flags &=3D ~BDRV_O_NO_BACKING; - pstrcpy(parent->backing_file, sizeof(parent->backing_file), - backing_hd->filename); - pstrcpy(parent->backing_format, sizeof(parent->backing_format), - backing_hd->drv ? backing_hd->drv->format_name : ""); =20 bdrv_op_block_all(backing_hd, parent->backing_blocker); /* Otherwise we won't be able to commit or stream */ @@ -5177,6 +5175,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, char *backing_file_full =3D NULL; char *filename_tmp =3D NULL; int is_protocol =3D 0; + bool filenames_refreshed =3D false; BlockDriverState *curr_bs =3D NULL; BlockDriverState *retval =3D NULL; =20 @@ -5201,9 +5200,31 @@ BlockDriverState *bdrv_find_backing_image(BlockDrive= rState *bs, { BlockDriverState *bs_below =3D bdrv_backing_chain_next(curr_bs); =20 - /* If either of the filename paths is actually a protocol, then - * compare unmodified paths; otherwise make paths relative */ - if (is_protocol || path_has_protocol(curr_bs->backing_file)) { + if (bdrv_backing_overridden(curr_bs)) { + /* + * If the backing file was overridden, we can only compare + * directly against the backing node's filename. + */ + + if (!filenames_refreshed) { + /* + * This will automatically refresh all of the + * filenames in the rest of the backing chain, so we + * only need to do this once. + */ + bdrv_refresh_filename(bs_below); + filenames_refreshed =3D true; + } + + if (strcmp(backing_file, bs_below->filename) =3D=3D 0) { + retval =3D bs_below; + break; + } + } else if (is_protocol || path_has_protocol(curr_bs->backing_file)= ) { + /* + * If either of the filename paths is actually a protocol, then + * compare unmodified paths; otherwise make paths relative. + */ char *backing_file_full_ret; =20 if (strcmp(backing_file, curr_bs->backing_file) =3D=3D 0) { diff --git a/block/qapi.c b/block/qapi.c index 1fd2937abc..3586c09516 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -44,7 +44,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, BlockDriverState *bs, Error **errp) { ImageInfo **p_image_info; - BlockDriverState *bs0; + BlockDriverState *bs0, *backing; BlockDeviceInfo *info; =20 if (!bs->drv) { @@ -73,9 +73,10 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *bl= k, info->node_name =3D g_strdup(bs->node_name); } =20 - if (bs->backing_file[0]) { + backing =3D bdrv_filtered_cow_bs(bs); + if (backing) { info->has_backing_file =3D true; - info->backing_file =3D g_strdup(bs->backing_file); + info->backing_file =3D g_strdup(backing->filename); } =20 info->detect_zeroes =3D bs->detect_zeroes; diff --git a/tests/qemu-iotests/191.out b/tests/qemu-iotests/191.out index 3fc92bb56e..0b3c216b0c 100644 --- a/tests/qemu-iotests/191.out +++ b/tests/qemu-iotests/191.out @@ -605,7 +605,6 @@ wrote 65536/65536 bytes at offset 1048576 "backing-filename": "TEST_DIR/t.IMGFMT.base", "dirty-flag": false }, - "backing-filename-format": "IMGFMT", "virtual-size": 67108864, "filename": "TEST_DIR/t.IMGFMT.ovl3", "cluster-size": 65536, diff --git a/tests/qemu-iotests/228 b/tests/qemu-iotests/228 index 9a50afd205..a1f3187212 100755 --- a/tests/qemu-iotests/228 +++ b/tests/qemu-iotests/228 @@ -34,7 +34,7 @@ def log_node_info(node): =20 log('bs->filename: ' + node['image']['filename'], filters=3D[filter_testfiles, filter_imgfmt]) - log('bs->backing_file: ' + node['backing_file'], + log('bs->backing_file: ' + node['image']['full-backing-filename'], filters=3D[filter_testfiles, filter_imgfmt]) =20 if 'backing-image' in node['image']: @@ -70,8 +70,8 @@ with iotests.FilePath('base.img') as base_img_path, \ }, filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) =20 - # Filename should be plain, and the backing filename should not - # contain the "file:" prefix + # Filename should be plain, and the backing node filename should + # not contain the "file:" prefix log_node_info(vm.node_info('node0')) =20 vm.qmp_log('blockdev-del', node_name=3D'node0') diff --git a/tests/qemu-iotests/228.out b/tests/qemu-iotests/228.out index 4217df24fe..8c82009abe 100644 --- a/tests/qemu-iotests/228.out +++ b/tests/qemu-iotests/228.out @@ -4,7 +4,7 @@ {"return": {}} =20 bs->filename: TEST_DIR/PID-top.img -bs->backing_file: TEST_DIR/PID-base.img +bs->backing_file: file:TEST_DIR/PID-base.img bs->backing->bs->filename: TEST_DIR/PID-base.img =20 {"execute": "blockdev-del", "arguments": {"node-name": "node0"}} @@ -41,7 +41,7 @@ bs->backing->bs->filename: TEST_DIR/PID-base.img {"return": {}} =20 bs->filename: TEST_DIR/PID-top.img -bs->backing_file: TEST_DIR/PID-base.img +bs->backing_file: file:TEST_DIR/PID-base.img bs->backing->bs->filename: TEST_DIR/PID-base.img =20 {"execute": "blockdev-del", "arguments": {"node-name": "node0"}} @@ -55,7 +55,7 @@ bs->backing->bs->filename: TEST_DIR/PID-base.img {"return": {}} =20 bs->filename: json:{"backing": {"driver": "null-co"}, "driver": "IMGFMT", = "file": {"driver": "file", "filename": "TEST_DIR/PID-top.img"}} -bs->backing_file: null-co:// +bs->backing_file: TEST_DIR/PID-base.img bs->backing->bs->filename: null-co:// =20 {"execute": "blockdev-del", "arguments": {"node-name": "node0"}} diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index 349b94aace..80c3e1b92d 100644 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -722,7 +722,9 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # Detach hd2 from hd0. self.reopen(opts, {'backing': None}) - self.reopen(opts, {}, "backing is missing for 'hd0'") + + # Without a backing file, we can omit 'backing' again + self.reopen(opts) =20 # Remove both hd0 and hd2 result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560379699; cv=none; d=zoho.com; s=zohoarc; b=nZsp5qtyKuZZwdYNd4iXdjR6mFR+f/D+QZVIWQb20Jru2HVjgOZIFV8xKwHj9ibLY3CCKO0h2eSEIZb/cRwOf2Dx/dB4miyllHp0w0xg+dTUuNxUTGcVIXuVZz/qS8VtUt/ghi3SOBJPXw8FdgoVVps8B4ZqoB51CfYiTh3dhjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560379699; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=JlJ67KRzMkOR4p+FhHUfGWcS8KRmrMvuPxmj0rNjXXk=; b=mo6DPnDLUw39SPzD6/FHAWQIxpBspfZ40b/f67TL3eSQZwNEUAA5PBeKLg2M4tbOSvflvWOC2qJSvwll/MYYWbUpNxuXtCv3+LhmQqgfCDfVcaZEmfGoJ3NxxCDk4q0gTKExyR5UbFdsakMjFbVOpUlvz4KLiUO6+bWbDRzD7vI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560379699775892.8904182207907; Wed, 12 Jun 2019 15:48:19 -0700 (PDT) Received: from localhost ([::1]:35696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC2U-000193-OU for importer@patchew.org; Wed, 12 Jun 2019 18:48:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46426) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTE-0000QH-7O for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTD-0008Pt-4W for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBTA-0008MA-NA; Wed, 12 Jun 2019 18:11:48 -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 592B4C024920; Wed, 12 Jun 2019 22:11:45 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEA52614C8; Wed, 12 Jun 2019 22:11:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:10:00 +0200 Message-Id: <20190612221004.2317-39-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 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]); Wed, 12 Jun 2019 22:11:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 38/42] iotests: Let complete_and_wait() work with commit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" complete_and_wait() and wait_ready() currently only work for mirror jobs. Let them work for active commit jobs, too. Signed-off-by: Max Reitz --- tests/qemu-iotests/iotests.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index dc77d3fba0..55066d62bb 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -697,8 +697,12 @@ class QMPTestCase(unittest.TestCase): =20 def wait_ready(self, drive=3D'drive0'): '''Wait until a block job BLOCK_JOB_READY event''' - f =3D {'data': {'type': 'mirror', 'device': drive } } - event =3D self.vm.event_wait(name=3D'BLOCK_JOB_READY', match=3Df) + event =3D self.vm.events_wait([ + ('BLOCK_JOB_READY', + {'data': {'type': 'mirror', 'device': drive } }), + ('BLOCK_JOB_READY', + {'data': {'type': 'commit', 'device': drive } }) + ]) =20 def wait_ready_and_cancel(self, drive=3D'drive0'): self.wait_ready(drive=3Ddrive) @@ -716,7 +720,7 @@ class QMPTestCase(unittest.TestCase): self.assert_qmp(result, 'return', {}) =20 event =3D self.wait_until_completed(drive=3Ddrive) - self.assert_qmp(event, 'data/type', 'mirror') + self.assertTrue(event['data']['type'] in ['mirror', 'commit']) =20 def pause_wait(self, job_id=3D'job0'): with Timeout(1, "Timeout waiting for job to pause"): --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560380860; cv=none; d=zoho.com; s=zohoarc; b=ZdpPwykYWZtTrumna8QptYwBjfEsY+5E72tYM8xDSD6TXbxS7qeYjoBiT7Z0ERbksFZ+kbvu8cuzzQVeRoPsyxjmq3Y9hQNZtnb0Id6mH9hGef1S2c0VkH47rIbLiFAGU54KDUwoGOUqZ4P3J1u8CxLUUknHHYQajDF/wPFF8P8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560380860; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1xyd8EZBOsSUYpTSeDzj1yC5pwf97kJQLhT9NVtLTyw=; b=Jy0bwpkAyFYBSWY3iXCL5dtlbcbSs4LZbuDkXKCi+n+CYInzUQ2XA3EBQDFdTslRO5OgGAYm9c5v0svFDTBL3mpi5t4pyCIvMAYOl/eO/xGT8ju0w6Q/lGezk8BWeCdqblGqgrzC2EAohrZPLhzFCta3R4bYHCiySFW6mrdVDRM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560380860183535.6989313495263; Wed, 12 Jun 2019 16:07:40 -0700 (PDT) Received: from localhost ([::1]:35888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbCL8-0003gg-7g for importer@patchew.org; Wed, 12 Jun 2019 19:07:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46453) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTF-0000V8-Tn for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTE-0008Qh-9x for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBTA-0008NZ-Pg; Wed, 12 Jun 2019 18:11:48 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12B8D7FDF8; Wed, 12 Jun 2019 22:11:48 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 666006046B; Wed, 12 Jun 2019 22:11:47 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:10:01 +0200 Message-Id: <20190612221004.2317-40-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Jun 2019 22:11:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 39/42] iotests: Add filter commit test cases X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch adds some tests on how commit copes with filter nodes. Signed-off-by: Max Reitz --- tests/qemu-iotests/040 | 177 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/040.out | 4 +- 2 files changed, 179 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index aa0b1847e3..31c2a8da3b 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -432,5 +432,182 @@ class TestReopenOverlay(ImageCommitTestCase): def test_reopen_overlay(self): self.run_commit_test(self.img1, self.img0) =20 +class TestCommitWithFilters(iotests.QMPTestCase): + img0 =3D os.path.join(iotests.test_dir, '0.img') + img1 =3D os.path.join(iotests.test_dir, '1.img') + img2 =3D os.path.join(iotests.test_dir, '2.img') + img3 =3D os.path.join(iotests.test_dir, '3.img') + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, self.img0, '64M') + qemu_img('create', '-f', iotests.imgfmt, self.img1, '64M') + qemu_img('create', '-f', iotests.imgfmt, self.img2, '64M') + qemu_img('create', '-f', iotests.imgfmt, self.img3, '64M') + + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 1 0M 1M', self.img0) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 2 1M 1M', self.img1) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 3 2M 1M', self.img2) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 4 3M 1M', self.img3) + + # Distributions of the patterns in the files; this is checked + # by tearDown() and should be changed by the test cases as is + # necessary + self.pattern_files =3D [self.img0, self.img1, self.img2, self.img3] + + self.vm =3D iotests.VM() + self.vm.launch() + self.has_quit =3D False + + result =3D self.vm.qmp('object-add', qom_type=3D'throttle-group', = id=3D'tg') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'top-filter', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'cow-3', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img3 + }, + 'backing': { + 'node-name': 'cow-2', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img2 + }, + 'backing': { + 'node-name': 'cow-1', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img1 + }, + 'backing': { + 'node-name': 'bottom-filter', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'cow-0', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img0 + } + } + } + } + } + } + }) + self.assert_qmp(result, 'return', {}) + + def tearDown(self): + self.vm.shutdown(has_quit=3Dself.has_quit) + + for index in range(len(self.pattern_files)): + result =3D qemu_io('-f', iotests.imgfmt, + '-c', 'read -P %i %iM 1M' % (index + 1, index= ), + self.pattern_files[index]) + self.assertFalse('Pattern verification failed' in result) + + os.remove(self.img3) + os.remove(self.img2) + os.remove(self.img1) + os.remove(self.img0) + + # Filters make for funny filenames, so we cannot just use + # self.imgX to get them + def get_filename(self, node): + return self.vm.node_info(node)['image']['filename'] + + def test_filterless_commit(self): + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + top_node=3D'cow-2', + base_node=3D'cow-1') + self.assert_qmp(result, 'return', {}) + self.wait_until_completed(drive=3D'commit') + + self.assertIsNotNone(self.vm.node_info('cow-3')) + self.assertIsNone(self.vm.node_info('cow-2')) + self.assertIsNotNone(self.vm.node_info('cow-1')) + + # 2 has been comitted into 1 + self.pattern_files[2] =3D self.img1 + + def test_commit_through_filter(self): + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + top_node=3D'cow-1', + base_node=3D'cow-0') + self.assert_qmp(result, 'return', {}) + self.wait_until_completed(drive=3D'commit') + + self.assertIsNotNone(self.vm.node_info('cow-2')) + self.assertIsNone(self.vm.node_info('cow-1')) + self.assertIsNone(self.vm.node_info('bottom-filter')) + self.assertIsNotNone(self.vm.node_info('cow-0')) + + # 1 has been comitted into 0 + self.pattern_files[1] =3D self.img0 + + def test_filtered_active_commit_with_filter(self): + # Add a device, so the commit job finds a parent it can change + # to point to the base node (so we can test that top-filter is + # dropped from the graph) + result =3D self.vm.qmp('device_add', id=3D'drv0', driver=3D'virtio= -blk', + drive=3D'top-filter') + self.assert_qmp(result, 'return', {}) + + # Try to release our reference to top-filter; that should not + # work because drv0 uses it + result =3D self.vm.qmp('blockdev-del', node_name=3D'top-filter') + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Node top-filter is in use') + + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + base_node=3D'cow-2') + self.assert_qmp(result, 'return', {}) + self.complete_and_wait(drive=3D'commit') + + # Try to release our reference to top-filter again + result =3D self.vm.qmp('blockdev-del', node_name=3D'top-filter') + self.assert_qmp(result, 'return', {}) + + self.assertIsNone(self.vm.node_info('top-filter')) + self.assertIsNone(self.vm.node_info('cow-3')) + self.assertIsNotNone(self.vm.node_info('cow-2')) + + # 3 has been comitted into 2 + self.pattern_files[3] =3D self.img2 + + def test_filtered_active_commit_without_filter(self): + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + top_node=3D'cow-3', + base_node=3D'cow-2') + self.assert_qmp(result, 'return', {}) + self.complete_and_wait(drive=3D'commit') + + self.assertIsNotNone(self.vm.node_info('top-filter')) + self.assertIsNone(self.vm.node_info('cow-3')) + self.assertIsNotNone(self.vm.node_info('cow-2')) + + # 3 has been comitted into 2 + self.pattern_files[3] =3D self.img2 + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 220a5fa82c..fe58934d7a 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -............................................... +................................................... ---------------------------------------------------------------------- -Ran 47 tests +Ran 51 tests =20 OK --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560380102; cv=none; d=zoho.com; s=zohoarc; b=LIbZ83ux6oP0UI9yp4kE/8mRn/M8wocP6ISL2QUSnqH/0PnxQB3Czda42j1ebOko8zWyUsr9zr4lUgxzuPUogHPoYTYZ2TXgkb9MBOyisWKa3obqxqbBXWieEDE9HC+Ge4Msl3boSe8kKvzTY37C8qithVlXwll8Kd2yX4aMcE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560380102; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=cCqCTD88k+/c2DrfN7WLygOJFuFA7c4p6hWaJv5zJxo=; b=UL+1xVsOBBBAdwVi7m5HPPTjqv80zRGmEqCPrKldBqofa/ECBrCoGjHJ3NxbAVH9/SD2udpaKI3qRqajrTSrDHBBXNw8Mh8dUOt4fSWPvJfPF/BaLrOaocyblQPbYEJ/O+0ndU8bqH71yVHsdVJwhhBm9KFcYHOWdiezqzPr38E= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560380102087170.0919411730879; Wed, 12 Jun 2019 15:55:02 -0700 (PDT) Received: from localhost ([::1]:35762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbC8u-0000KP-0p for importer@patchew.org; Wed, 12 Jun 2019 18:54:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46497) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTI-0000bH-Pi for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTG-0008Sq-SL for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBTD-0008Po-GO; Wed, 12 Jun 2019 18:11:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C461B301E3D2; Wed, 12 Jun 2019 22:11:50 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26B2460FA3; Wed, 12 Jun 2019 22:11:49 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:10:02 +0200 Message-Id: <20190612221004.2317-41-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 12 Jun 2019 22:11:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 40/42] iotests: Add filter mirror test cases X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch adds some test cases how mirroring relates to filters. One of them tests what happens when you mirror off a filtered COW node, two others use the mirror filter node as basically our only example of an implicitly created filter node so far (besides the commit filter). Signed-off-by: Max Reitz --- tests/qemu-iotests/041 | 146 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/041.out | 4 +- 2 files changed, 147 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 0c1432f189..c2b5299f62 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -20,8 +20,9 @@ =20 import time import os +import json import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_img_pipe, qemu_io =20 backing_img =3D os.path.join(iotests.test_dir, 'backing.img') target_backing_img =3D os.path.join(iotests.test_dir, 'target-backing.img') @@ -1191,5 +1192,148 @@ class TestReplaces(iotests.QMPTestCase): os.remove(test_img) os.remove(target_img) =20 +# Tests for mirror with filters (and how the mirror filter behaves, as +# an example for an implicit filter) +class TestFilters(iotests.QMPTestCase): + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, backing_img, '1M') + qemu_img('create', '-f', iotests.imgfmt, '-b', backing_img, test_i= mg) + qemu_img('create', '-f', iotests.imgfmt, '-b', backing_img, target= _img) + + qemu_io('-c', 'write -P 1 0 512k', backing_img) + qemu_io('-c', 'write -P 2 512k 512k', test_img) + + self.vm =3D iotests.VM() + self.vm.launch() + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'target', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + }, + 'backing': None + }) + self.assert_qmp(result, 'return', {}) + + self.filterless_chain =3D { + 'node-name': 'source', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + }, + 'backing': { + 'node-name': 'backing', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': backing_img + } + } + } + + def tearDown(self): + self.vm.shutdown() + + os.remove(test_img) + os.remove(target_img) + os.remove(backing_img) + + def test_cor(self): + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'filter', + 'driver': 'copy-on-read', + 'file': self.filterless_chain + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'filter', + target=3D'target', + sync=3D'top') + self.assert_qmp(result, 'return', {}) + + self.complete_and_wait('mirror') + + self.vm.qmp('blockdev-del', node_name=3D'target') + + target_map =3D qemu_img_pipe('map', '--output=3Djson', target_img) + target_map =3D json.loads(target_map) + + assert target_map[0]['start'] =3D=3D 0 + assert target_map[0]['length'] =3D=3D 512 * 1024 + assert target_map[0]['depth'] =3D=3D 1 + + assert target_map[1]['start'] =3D=3D 512 * 1024 + assert target_map[1]['length'] =3D=3D 512 * 1024 + assert target_map[1]['depth'] =3D=3D 0 + + def test_implicit_mirror_filter(self): + result =3D self.vm.qmp('blockdev-add', **self.filterless_chain) + self.assert_qmp(result, 'return', {}) + + # We need this so we can query from above the mirror node + result =3D self.vm.qmp('device_add', + driver=3D'virtio-blk', + id=3D'virtio', + bus=3D'pci.0', + drive=3D'source') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + sync=3D'top') + self.assert_qmp(result, 'return', {}) + + # The mirror filter is now an implicit node, so it should be + # invisible when querying the backing chain + device_info =3D self.vm.qmp('query-block')['return'][0] + assert device_info['qdev'] =3D=3D '/machine/peripheral/virtio/virt= io-backend' + + assert device_info['inserted']['node-name'] =3D=3D 'source' + + image_info =3D device_info['inserted']['image'] + assert image_info['filename'] =3D=3D test_img + assert image_info['backing-image']['filename'] =3D=3D backing_img + + self.complete_and_wait('mirror') + + def test_explicit_mirror_filter(self): + # Same test as above, but this time we give the mirror filter + # a node-name so it will not be invisible + result =3D self.vm.qmp('blockdev-add', **self.filterless_chain) + self.assert_qmp(result, 'return', {}) + + # We need this so we can query from above the mirror node + result =3D self.vm.qmp('device_add', + driver=3D'virtio-blk', + id=3D'virtio', + bus=3D'pci.0', + drive=3D'source') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + sync=3D'top', + filter_node_name=3D'mirror-filter') + self.assert_qmp(result, 'return', {}) + + # With a node-name given to it, the mirror filter should now + # be visible + device_info =3D self.vm.qmp('query-block')['return'][0] + assert device_info['qdev'] =3D=3D '/machine/peripheral/virtio/virt= io-backend' + + assert device_info['inserted']['node-name'] =3D=3D 'mirror-filter' + + self.complete_and_wait('mirror') + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index 2c448b4239..ffc779b4d1 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= ................ +..........................................................................= ................... ---------------------------------------------------------------------- -Ran 90 tests +Ran 93 tests =20 OK --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560380252; cv=none; d=zoho.com; s=zohoarc; b=XbWmjrnai9eWr49HdgJRLe/7qNe95SI5f3GAnZgA0BFUhs2ZUjl02tsCyN7pb7D6tt9I3KYg0jVtzmu5KSDUrN5atzWMkdTIv28qzkQ7KC8rq4C+kO0vgQivMWpeWOMOAkfHFjT/6HZsmxej6iV2ZIekW/BzvmxcQNV+3lOjapo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560380252; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=C8Vk4eR54TXAsT5OIvdntYbOt1JBskSAxgzTMm/uHOw=; b=WnzMZZ7QYwD9IMH2fuxqBO/DZa8fAAWXdnjlHduV1U2yCyHskkm36b7nJUQCdI7ZuQANz+poSszLbf/I9D2H5pBKCizi2+ew71OsIgngqQYjTEZdX3kebskt31U5h8gNz5lKEE0I10Jhiyu66J2FjhWLwFrrOPRLucpcyIuXrrw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560380252638803.3066336112522; Wed, 12 Jun 2019 15:57:32 -0700 (PDT) Received: from localhost ([::1]:35796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbCBP-0003rp-Ek for importer@patchew.org; Wed, 12 Jun 2019 18:57:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46532) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTK-0000f4-Cz for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTJ-0008UI-2x for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:11:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45588) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBTG-0008Rh-0I; Wed, 12 Jun 2019 18:11:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4908030C31A4; Wed, 12 Jun 2019 22:11:53 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0DF25C298; Wed, 12 Jun 2019 22:11:52 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:10:03 +0200 Message-Id: <20190612221004.2317-42-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 12 Jun 2019 22:11:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 41/42] iotests: Add test for commit in sub directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add a test for committing an overlay in a sub directory to one of the images in its backing chain, using both relative and absolute filenames. Signed-off-by: Max Reitz --- tests/qemu-iotests/020 | 36 ++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/020.out | 10 ++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 index 6b0ebb37d2..94633c3a32 100755 --- a/tests/qemu-iotests/020 +++ b/tests/qemu-iotests/020 @@ -31,6 +31,11 @@ _cleanup() _cleanup_test_img rm -f "$TEST_IMG.base" rm -f "$TEST_IMG.orig" + + rm -f "$TEST_DIR/subdir/t.$IMGFMT.base" + rm -f "$TEST_DIR/subdir/t.$IMGFMT.mid" + rm -f "$TEST_DIR/subdir/t.$IMGFMT" + rmdir "$TEST_DIR/subdir" &> /dev/null } trap "_cleanup; exit \$status" 0 1 2 3 15 =20 @@ -133,6 +138,37 @@ $QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_= io $QEMU_IMG commit "$TEST_IMG" _cleanup =20 + +echo +echo 'Testing commit in sub-directory with relative filenames' +echo + +pushd "$TEST_DIR" > /dev/null + +mkdir subdir + +TEST_IMG=3D"subdir/t.$IMGFMT.base" _make_test_img 1M +TEST_IMG=3D"subdir/t.$IMGFMT.mid" _make_test_img -b "t.$IMGFMT.base" +TEST_IMG=3D"subdir/t.$IMGFMT" _make_test_img -b "t.$IMGFMT.mid" + +# Should work +$QEMU_IMG commit -b "t.$IMGFMT.mid" "subdir/t.$IMGFMT" + +# Might theoretically work, but does not in practice (we have to +# decide between this and the above; and since we always represent +# backing file names as relative to the overlay, we go for the above) +$QEMU_IMG commit -b "subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT" 2>&1 | \ + _filter_imgfmt + +# This should work as well +$QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT" + +popd > /dev/null + +# Now let's try with just absolute filenames +$QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" \ + "$TEST_DIR/subdir/t.$IMGFMT" + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/020.out b/tests/qemu-iotests/020.out index 4b722b2dd0..228c37dded 100644 --- a/tests/qemu-iotests/020.out +++ b/tests/qemu-iotests/020.out @@ -1094,4 +1094,14 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D= 1048576 backing_file=3Djson:{'driv wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Block job failed: No space left on device + +Testing commit in sub-directory with relative filenames + +Formatting 'subdir/t.IMGFMT.base', fmt=3DIMGFMT size=3D1048576 +Formatting 'subdir/t.IMGFMT.mid', fmt=3DIMGFMT size=3D1048576 backing_file= =3Dt.IMGFMT.base +Formatting 'subdir/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file=3Dt= .IMGFMT.mid +Image committed. +qemu-img: Did not find 'subdir/t.IMGFMT.mid' in the backing chain of 'subd= ir/t.IMGFMT' +Image committed. +Image committed. *** done --=20 2.21.0 From nobody Fri Apr 19 13:19:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560381017; cv=none; d=zoho.com; s=zohoarc; b=SsGc9r+5Nod1q1dANvkSL/6siaFHNgPC1JJmbnoy1b/mcAU7ScJrzv0JGr/STD8uLRDBBor3WOFtyg0FchOuPJIcOOUKJ0zgbVGO++oWlmtEkQudH5GxI5411dvrDSpcEcjdJdPniU1Y8rzvEg6BCMY/rpFAqwEQB2JoYxhTw88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560381017; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9ETf7/DrFGdiavvJP69+UzLMz0MkZ5471Mgw98ab61M=; b=jEGPkgc/ZJEweMJaaXl/AAVir3/TzHjxHFPouWwNN1fohHX2uxoMwrd/CBgUq4Nr3fKtWNW/mINaOvSMivt3RCoLmzvAjxZQ9WmiFMH3QXfgISvO/Xr84RZe33Fzy5lCaRT3k/HAHDiFpOu4EOl270CQWJyw5l0qRHqSOGnA2LU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560381017492827.5027975270907; Wed, 12 Jun 2019 16:10:17 -0700 (PDT) Received: from localhost ([::1]:35942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbCNk-0005ol-BL for importer@patchew.org; Wed, 12 Jun 2019 19:10:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46588) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbBTN-0000kh-Ga for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:12:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbBTM-00004y-6l for qemu-devel@nongnu.org; Wed, 12 Jun 2019 18:12:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hbBTJ-0008Ts-6y; Wed, 12 Jun 2019 18:11:57 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 795C06EB83; Wed, 12 Jun 2019 22:11:56 +0000 (UTC) Received: from localhost (unknown [10.40.205.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53B4060CCD; Wed, 12 Jun 2019 22:11:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 13 Jun 2019 00:10:04 +0200 Message-Id: <20190612221004.2317-43-mreitz@redhat.com> In-Reply-To: <20190612221004.2317-1-mreitz@redhat.com> References: <20190612221004.2317-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 12 Jun 2019 22:11:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 42/42] iotests: Test committing to overridden backing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- tests/qemu-iotests/040 | 61 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/040.out | 4 +-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index 31c2a8da3b..5cbbd30ee3 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -609,5 +609,66 @@ class TestCommitWithFilters(iotests.QMPTestCase): # 3 has been comitted into 2 self.pattern_files[3] =3D self.img2 =20 +class TestCommitWithOverriddenBacking(iotests.QMPTestCase): + img_base_a =3D os.path.join(iotests.test_dir, 'base_a.img') + img_base_b =3D os.path.join(iotests.test_dir, 'base_b.img') + img_top =3D os.path.join(iotests.test_dir, 'top.img') + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, self.img_base_a, '1M') + qemu_img('create', '-f', iotests.imgfmt, self.img_base_b, '1M') + qemu_img('create', '-f', iotests.imgfmt, '-b', self.img_base_a, \ + self.img_top) + + self.vm =3D iotests.VM() + self.vm.launch() + + # Use base_b instead of base_a as the backing of top + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'top', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img_top + }, + 'backing': { + 'node-name': 'base', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img_base_b + } + } + }) + self.assert_qmp(result, 'return', {}) + + def tearDown(self): + self.vm.shutdown() + os.remove(self.img_top) + os.remove(self.img_base_a) + os.remove(self.img_base_b) + + def test_commit_to_a(self): + # Try committing to base_a (which should fail, as top's + # backing image is base_b instead) + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top', + base=3Dself.img_base_a) + self.assert_qmp(result, 'error/class', 'GenericError') + + def test_commit_to_b(self): + # Try committing to base_b (which should work, since that is + # actually top's backing image) + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top', + base=3Dself.img_base_b) + self.assert_qmp(result, 'return', {}) + + self.vm.event_wait('BLOCK_JOB_READY') + self.vm.qmp('block-job-complete', device=3D'commit') + self.vm.event_wait('BLOCK_JOB_COMPLETED') + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index fe58934d7a..499af0e2ff 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -................................................... +..................................................... ---------------------------------------------------------------------- -Ran 51 tests +Ran 53 tests =20 OK --=20 2.21.0