From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098699; cv=none; d=zohomail.com; s=zohoarc; b=SuoLgf5hcpiZJBQ0I98JN1FnuV0ZfL7wpGERTc5SiZudyob0Bght5diA8GQf1WX2eyrc8yR+tph/joUGL168btpB8T4lEMbKl0bb+0urVqVtzP7Q0LLBKw/m7Ue4XGQe930+TR3wiiF6Mse38x0OzPH1ZVGnxECLCBnL6tg/5EM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098699; h=Content-Type: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; bh=/PfEqA0UCfJfYnevUk13q8CgID2wiYihyO7qiY72z1Q=; b=h2uVos6IIjQyJ/2d+z8O0Fi3yQBY/+yqx/KAvoKgdjBvGjo2cRiphQ5PwEIc16Uf3VIpjdB1xcvCh0u73TS+w5iVAXGZcSoTv+D+/SZ4xJkhz15PwvM5nnS5RdtVo4KV/H4H+ByFOyhXrZt7igjKdXaNDiwLOJqnHgqnDpE+jzg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593098699039421.86665817437483; Thu, 25 Jun 2020 08:24:59 -0700 (PDT) Received: from localhost ([::1]:58618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTkH-0007UP-KF for importer@patchew.org; Thu, 25 Jun 2020 11:24:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joThu-00056p-Qs for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:30 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:43148 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joThs-0000Sj-Vx for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215-0OrKLpWtNJizozD8XGHENw-1; Thu, 25 Jun 2020 11:22:20 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D944C1800D4A; Thu, 25 Jun 2020 15:22:19 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BF22612BA; Thu, 25 Jun 2020 15:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/PfEqA0UCfJfYnevUk13q8CgID2wiYihyO7qiY72z1Q=; b=PTRk2JyQw+O9xGgmtiVIu8gpwLWE/caVcOomcgnVHgachcA7QMpNRY9A9HrEoNVa+aMeuK vYSsyRD/LUVsf/ATfUrtEsiX3ANoIT3iQtKWebzVODS9w6RnUtcf1LIPbGtgQWHQo9qODm ystSZnEZDoBFk3lv3mH5/0wJRe8uGWw= X-MC-Unique: 0OrKLpWtNJizozD8XGHENw-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 01/47] block: Add child access functions Date: Thu, 25 Jun 2020 17:21:29 +0200 Message-Id: <20200625152215.941773-2-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 a filtered child; bs->file can be a 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 functions 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 in a meaningful way. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 44 +++++++++++++++++-- block.c | 90 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 3 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 1b86b59af1..bb3457c5e8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -90,9 +90,17 @@ 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. + * + * Filters generally cannot have more than a single filtered child, + * because the data they present must at all times be the same as + * that on their filtered child. That would be impossible to + * achieve for multiple filtered children. + * (And this filtered child must then be bs->file or bs->backing.) */ bool is_filter; /* @@ -1370,4 +1378,34 @@ BdrvDirtyBitmap *block_dirty_bitmap_remove(const cha= r *node, const char *name, BlockDriverState **bitmap_bs, Error **errp); =20 +BdrvChild *bdrv_cow_child(BlockDriverState *bs); +BdrvChild *bdrv_filter_child(BlockDriverState *bs); +BdrvChild *bdrv_filter_or_cow_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_cow_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_cow_child(bs)); +} + +static inline BlockDriverState *bdrv_filter_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filter_child(bs)); +} + +static inline BlockDriverState *bdrv_filter_or_cow_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filter_or_cow_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 144f52e413..5a42ef49fd 100644 --- a/block.c +++ b/block.c @@ -6918,3 +6918,93 @@ int bdrv_make_empty(BdrvChild *c, Error **errp) =20 return 0; } + +/* + * 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_cow_child(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return NULL; + } + + if (bs->drv->is_filter) { + return NULL; + } + + if (!bs->backing) { + return NULL; + } + + assert(bs->backing->role & BDRV_CHILD_COW); + return bs->backing; +} + +/* + * If @bs acts as a filter for exactly one of its children, return + * that child. + */ +BdrvChild *bdrv_filter_child(BlockDriverState *bs) +{ + BdrvChild *c; + + 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)); + + c =3D bs->backing ?: bs->file; + if (!c) { + return NULL; + } + + assert(c->role & BDRV_CHILD_FILTERED); + return c; +} + +/* + * Return either the result of bdrv_cow_child() or bdrv_filter_child(), + * whichever is non-NULL. + * + * Return NULL if both are NULL. + */ +BdrvChild *bdrv_filter_or_cow_child(BlockDriverState *bs) +{ + BdrvChild *cow_child =3D bdrv_cow_child(bs); + BdrvChild *filter_child =3D bdrv_filter_child(bs); + + /* Filter nodes cannot have COW backing files */ + assert(!(cow_child && filter_child)); + + return cow_child ?: filter_child; +} + +/* + * 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.) + * + * Drivers do not necessarily have a primary child; for example quorum + * does not. + */ +BdrvChild *bdrv_primary_child(BlockDriverState *bs) +{ + BdrvChild *c; + + QLIST_FOREACH(c, &bs->children, next) { + if (c->role & BDRV_CHILD_PRIMARY) { + return c; + } + } + + return NULL; +} --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098690; cv=none; d=zohomail.com; s=zohoarc; b=W9lwuVEWPSkHLeKE6Qk13vI9N4mAbkCW8TKjSOb6Z8iJEMAx3baCaOQahaEbCl2EsgnP9vNbsVTw0thg+7U5ut9btx0AcRg3tdKlezZGRVtkSzucV11Q+tlW03ckfvQR5MXQuCZ88diCrtvqUwtzWxqGTP7qvS0aKTMmFcLNjUw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098690; h=Content-Type: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; bh=/6b5+AhmJqfcAVLzmBshbRXCmakDyehOcVwSaIyUfs8=; b=CVbAqDI1SyD+B0uDY12EUrncuLps6dusry3RpP9entWoA5TlyUWHmLfAYFUPL7VfFIBR85QdmkazNKmABTGZ2b1RN+nfuYVQKzga6H4rK45339T+x9gVjGFyxywiuz22lxr0sAneM2rhPYswDjJq/8oET5/WaQAlC7cMNbfozJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593098690022100.5300836830877; Thu, 25 Jun 2020 08:24:50 -0700 (PDT) Received: from localhost ([::1]:58168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTk8-0007Hu-4v for importer@patchew.org; Thu, 25 Jun 2020 11:24:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joThv-00057L-Vt for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:32 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:38715 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTht-0000TA-61 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-55exWMUNMyG9mehKiC9jwA-1; Thu, 25 Jun 2020 11:22:22 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF581EC1A2; Thu, 25 Jun 2020 15:22:21 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9514F61169; Thu, 25 Jun 2020 15:22:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/6b5+AhmJqfcAVLzmBshbRXCmakDyehOcVwSaIyUfs8=; b=gjz/T1Qe7VlOkwiqc/iZ3EibbjAlegHqt8u22SSsRjeLMUUZaFD7n1+D/APyeAB+dlXpqX FQk9r642tCVzlt/3d2eH9ZxLa5ouqt+SPVr5p/cF55GNydOfmCbnm0PYFcef8oeOYC7+0W hK21QMI96/H53597DAMXwTIpVcSsocM= X-MC-Unique: 55exWMUNMyG9mehKiC9jwA-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 02/47] block: Add chain helper functions Date: Thu, 25 Jun 2020 17:21:30 +0200 Message-Id: <20200625152215.941773-3-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Andrey Shinkevich 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 bb3457c5e8..5da793bfc3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1382,6 +1382,9 @@ BdrvChild *bdrv_cow_child(BlockDriverState *bs); BdrvChild *bdrv_filter_child(BlockDriverState *bs); BdrvChild *bdrv_filter_or_cow_child(BlockDriverState *bs); BdrvChild *bdrv_primary_child(BlockDriverState *bs); +BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs); +BlockDriverState *bdrv_skip_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 5a42ef49fd..0a0b855261 100644 --- a/block.c +++ b/block.c @@ -7008,3 +7008,58 @@ BdrvChild *bdrv_primary_child(BlockDriverState *bs) =20 return NULL; } + +static BlockDriverState *bdrv_do_skip_filters(BlockDriverState *bs, + bool stop_on_explicit_filter) +{ + BdrvChild *c; + + if (!bs) { + return NULL; + } + + while (!(stop_on_explicit_filter && !bs->implicit)) { + c =3D bdrv_filter_child(bs); + if (!c) { + break; + } + bs =3D c->bs; + } + /* + * Note that this treats nodes with bs->drv =3D=3D NULL as not being + * 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 a filtered child down the chain starting from @bs + * (including @bs itself). + */ +BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs) +{ + return bdrv_do_skip_filters(bs, true); +} + +/* + * Return the first BDS that does not have a filtered child down the + * chain starting from @bs (including @bs itself). + */ +BlockDriverState *bdrv_skip_filters(BlockDriverState *bs) +{ + return bdrv_do_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_filters(bdrv_cow_bs(bdrv_skip_filters(bs))); +} --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098690; cv=none; d=zohomail.com; s=zohoarc; b=Xsr3v57gIlNBcBZjQoIJ9dR8MxmhXKD5w3tTG4yA9ptVB5/vtq3NQ/8at+zZQNVU/vHReuz4ZVsCXm1iNv8XeQMlKDbH/c/yOvzsKHZeol+SJst1FMRGIqXlNSCWoTWcu5/aIXwYgGwQk1vnODjWoHnIQ3Wd934lW0CVHd+r/lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098690; h=Content-Type: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; bh=SGreytvX6x6DdPG/somvNhsK9PYRN+q+t2R2x2o2HhU=; b=G/YHvcxb7rsHMveQ/gjuW6y3IhEEHlJjupbtb5s5NZe9szH3a2wqcU7fFLMfpUPjDF55rMW+t4tqSgz5qdq4J2fv6yxQB1z4ZuapQEgPHoTiNiGcWs1R0sXgeU3jk3rzqoEdwHIVyXhp9IE6Y94iVASuFZ5HBr+rThcgkVsqlUA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593098690623110.35607732973278; Thu, 25 Jun 2020 08:24:50 -0700 (PDT) Received: from localhost ([::1]:58144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTk9-0007HK-9m for importer@patchew.org; Thu, 25 Jun 2020 11:24:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joThv-000574-Po for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:31 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:38592 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTht-0000UR-3e for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-Y5SxmXsnMFe3JiAw3VvRiQ-1; Thu, 25 Jun 2020 11:22:25 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38E2D1800D4A; Thu, 25 Jun 2020 15:22:24 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEC987554F; Thu, 25 Jun 2020 15:22:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SGreytvX6x6DdPG/somvNhsK9PYRN+q+t2R2x2o2HhU=; b=dDuDFBfhPRSmlz1O5JegZJRRdgRyRnbl4ZmqWtE0ng3bM9bMw+TIIPyewvh+vfGiWsAW+i efTWFZ7wEUCpt2qksiHWwegM1Ojlub4Qy2aqvk0K3Q8TmGsdsbtnzwqFCfgBBxck/OphB3 KC9OtFlqB2vvGzs9NsZ8MOvJm3ZDTFo= X-MC-Unique: Y5SxmXsnMFe3JiAw3VvRiQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 03/47] block: bdrv_cow_child() for bdrv_has_zero_init() Date: Thu, 25 Jun 2020 17:21:31 +0200 Message-Id: <20200625152215.941773-4-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" bdrv_has_zero_init() and the related bdrv_unallocated_blocks_are_zero() should use bdrv_cow_child() if they want to check whether the given BDS has a COW backing file. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 0a0b855261..f3e2aae49c 100644 --- a/block.c +++ b/block.c @@ -5394,7 +5394,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_cow_child(bs)) { return 0; } if (bs->drv->bdrv_has_zero_init) { @@ -5412,7 +5412,7 @@ bool bdrv_unallocated_blocks_are_zero(BlockDriverStat= e *bs) { BlockDriverInfo bdi; =20 - if (bs->backing) { + if (bdrv_cow_child(bs)) { return false; } =20 --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098858; cv=none; d=zohomail.com; s=zohoarc; b=GOHebpkmmNa7s8X/UylDIl7kQSq9G71GN3nl8Ciw1cnmkOpSu9JUuWh9gESIo71wyLS+jlkeYfJsDwQFjK5R4nCmJjAmPYPvmb2ow6y/DyrNYGSs2DEsPGgy8u1bNljRJeQOqy3LcoqS+04uH9ltKOuMxH6QE8HLEJT5IZspD30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098858; h=Content-Type: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; bh=Ji7G0zt0G0KxlgKq2VBPZoCpafDPwaMPwhlzuu7/hVc=; b=RzxQKtLjJqAE157QtJRKxGQ0hrLMhx8hok0QDDUVIy631pl/Gf9AfwB1FkQo3tzzxj7mFYo0xCuozG1n2X21BEKZTglAt3F+L+lqkxMEHLiJkvyPh/yGv3l47JfcNnpHjkrT3rrp+msgtZpD+Sk0U7xfLyO1YnxbFctDPPyX+T0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 15930988589382.023668239185554; Thu, 25 Jun 2020 08:27:38 -0700 (PDT) Received: from localhost ([::1]:38684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTmr-0002WH-AB for importer@patchew.org; Thu, 25 Jun 2020 11:27:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joThx-00059j-Np for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:33 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:26504 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joThw-0000Wg-4X for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-955LoPfdOxGl9rQrFIt5jg-1; Thu, 25 Jun 2020 11:22:27 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 59CED464; Thu, 25 Jun 2020 15:22:26 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF7DAA09BF; Thu, 25 Jun 2020 15:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ji7G0zt0G0KxlgKq2VBPZoCpafDPwaMPwhlzuu7/hVc=; b=VBhh2AeyEohYSw6qXNk550Exq3CBcLPLrvtKpa/CjkOepMgmxV7ZbybGR9BDKnvIlrWBcY 2D/GqfBnSFkadCPf8f3J18grtSNZHTIpTnD6i1Gv56cx6srsJIX/rsoe4WTHskSlqFDo2t 0GPzSHbNfiSwbf/DsSDBvcxMRnyMdJI= X-MC-Unique: 955LoPfdOxGl9rQrFIt5jg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 04/47] block: bdrv_set_backing_hd() is about bs->backing Date: Thu, 25 Jun 2020 17:21:32 +0200 Message-Id: <20200625152215.941773-5-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Andrey Shinkevich --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index f3e2aae49c..d139ffb57d 100644 --- a/block.c +++ b/block.c @@ -2846,7 +2846,7 @@ static BdrvChildRole bdrv_backing_role(BlockDriverSta= te *bs) } =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, @@ -2855,7 +2855,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098700; cv=none; d=zohomail.com; s=zohoarc; b=Hc3C50fK7lLcAyXfI4qTawlf3KXVA8np0TbXA0GMZJ1T0OtaNNoTgE//MEtrV9NxKMehEA5XJEedr7MSsfw83spbpjduy5LcJTLHVCi3/frhtL1jT3f3d/CFnkSl8whWGUmJmlVXBunz7igTFtUdeDYFcF3NGTQyLZ5Z2vK7Xwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098700; h=Content-Type: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; bh=Dl5gsxaX3h9ydAHzCIHB7Hsfs7PhzxLzH9abiKtx1CE=; b=XPViyUnmvNf60fhisK+g2V1BBUQzKPk6EZ4FMiNprWlWDSJ2nbj0A13BHP0gig4w679mcSvDThvFNNcw6X6P24Cm27Fb9VME5dKkRiufELrv3zrvvOUj7XcHn773TjW935srf1IObaxPpuIac7vQlYVMBEmwFxUDhunMAdSmngI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593098700781386.3382870201174; Thu, 25 Jun 2020 08:25:00 -0700 (PDT) Received: from localhost ([::1]:58846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTkJ-0007aM-FO for importer@patchew.org; Thu, 25 Jun 2020 11:24:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joThz-0005EI-OJ for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:35 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32017 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joThx-0000YX-PG for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-EVTVE8qhNIq93gPD6shcrg-1; Thu, 25 Jun 2020 11:22:29 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BB09EC1A7; Thu, 25 Jun 2020 15:22:28 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DB641DC; Thu, 25 Jun 2020 15:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dl5gsxaX3h9ydAHzCIHB7Hsfs7PhzxLzH9abiKtx1CE=; b=CCQdKi6jYNQm6wUhX7/eQgJZ5caeN85/WByZUqHbQ153u47SUSeAfHwUg2brHYlsaWxTNu AulOdVCf9VeCbU/IrQqraZuHkqb5jVe7jb3j6R2J2HWOwURNuSBRfdmVbDvsiBRd6zKHmY DWqI0D4+nEqPv3XpcbYz+zI1q5a3yYo= X-MC-Unique: EVTVE8qhNIq93gPD6shcrg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 05/47] block: Include filters when freezing backing chain Date: Thu, 25 Jun 2020 17:21:33 +0200 Message-Id: <20200625152215.941773-6-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 both COW and filter child 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: Andrey Shinkevich --- block.c | 60 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index d139ffb57d..b59bd776cd 100644 --- a/block.c +++ b/block.c @@ -2595,12 +2595,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 /* @@ -2761,6 +2764,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; @@ -2798,6 +2802,7 @@ static void bdrv_unset_inherits_from(BlockDriverState= *root, BdrvChild *child) } } =20 +/* Callers must ensure that child->frozen is false. */ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child) { if (child =3D=3D NULL) { @@ -2864,6 +2869,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); bs->backing =3D NULL; } @@ -4372,6 +4378,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; @@ -4741,20 +4748,22 @@ BlockDriverState *bdrv_find_base(BlockDriverState *= bs) } =20 /* - * Return true if at least one of the backing links between @bs and - * @base is frozen. @errp is set if that's the case. + * Return true if at least one of the COW (backing) and filter links + * between @bs and @base is frozen. @errp is set if that's the case. * @base must be reachable from @bs, or NULL. */ 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_filter_or_cow_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; } } @@ -4763,7 +4772,7 @@ bool bdrv_is_backing_chain_frozen(BlockDriverState *b= s, BlockDriverState *base, } =20 /* - * Freeze all backing links between @bs and @base. + * Freeze all COW (backing) and filter links between @bs and @base. * If any of the links is already frozen the operation is aborted and * none of the links are modified. * @base must be reachable from @bs, or NULL. @@ -4773,22 +4782,25 @@ 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 && backing_bs(i)->never_freeze) { + for (i =3D bs; i !=3D base; i =3D child_bs(child)) { + child =3D bdrv_filter_or_cow_child(i); + if (child && child->bs->never_freeze) { error_setg(errp, "Cannot freeze '%s' link to '%s'", - i->backing->name, backing_bs(i)->node_name); + child->name, child->bs->node_name); 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_filter_or_cow_child(i); + if (child) { + child->frozen =3D true; } } =20 @@ -4796,18 +4808,21 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs,= BlockDriverState *base, } =20 /* - * Unfreeze all backing links between @bs and @base. The caller must - * ensure that all links are frozen before using this function. + * Unfreeze all COW (backing) and filter 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. */ 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_filter_or_cow_child(i); + if (child) { + assert(child->frozen); + child->frozen =3D false; } } } @@ -4910,8 +4925,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098875; cv=none; d=zohomail.com; s=zohoarc; b=T/3AstExWWmB60UVNfF9vmNtSg+V73GfuyAhC6d6pyVOVFo2Z37y91QwibKOa+fzvPs4nRMqCKHBhHRFyJzF6GI8RV+O3FnWDCw9rULvr/g2JuXCqH9V//73c53uvQHTxgUdDrhjHKt21d3cjJtV1PYIKgR7eI/8kN6/hgzgIgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098875; h=Content-Type: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; bh=mDZYcGkrIBwQAlRDjG/1NZpJAK8n1D5wtER9Jcis1fE=; b=lrTCyx5kxKriczyCKoThVqylwTJDFVA+DK/GtXJUNE6+m8xsCNI38MDpEhvvV+6Z0VsKfAVFVI1wVKn6TblCGk0K8waUD8Bf/k89PNIOHSbCoNN3g7+Kn8KbbPFAU/Q7WiNJNgw3cF4cmfper6HDROr8sfoGoT//MIiMAva8A48= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 15930988755821014.3564366237566; Thu, 25 Jun 2020 08:27:55 -0700 (PDT) Received: from localhost ([::1]:39834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTn8-0002yb-CM for importer@patchew.org; Thu, 25 Jun 2020 11:27:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTi0-0005FI-2U for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:36 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:41442 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joThy-0000Z5-Di for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-dICCJNrEPBmnCVunF66OFQ-1; Thu, 25 Jun 2020 11:22:31 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A99828015F8; Thu, 25 Jun 2020 15:22:30 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CB1E17DCE; Thu, 25 Jun 2020 15:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mDZYcGkrIBwQAlRDjG/1NZpJAK8n1D5wtER9Jcis1fE=; b=M60m5VkUlvJcEqgXo/2ofZ2b2nTOxLQqEJwulW6AvQ7ZzgJ8GEX7b2UBm0AHIQCZs1xg+m +dvkNxI+xmRkO9aX+B/2D9El/vhlXhg4fFhh5ZYbPtdpp5MaxOxxghwuJfC6i5UYS26Mjp yoFe0mJWalco4EfXfeHtSZRUj+bDBjg= X-MC-Unique: dICCJNrEPBmnCVunF66OFQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 06/47] block: Drop bdrv_is_encrypted() Date: Thu, 25 Jun 2020 17:21:34 +0200 Message-Id: <20200625152215.941773-7-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The original purpose of bdrv_is_encrypted() was to inquire whether a BDS can be used without the user entering a password or not. It has not been used for that purpose for quite some time. Actually, it is not even fit for that purpose, because to answer that question, it would have recursively query all of the given node's children. So now we have to decide in which direction we want to fix bdrv_is_encrypted(): Recursively query all children, or drop it and just use bs->encrypted to get the current node's status? Nowadays, its only purpose is to report through bdrv_query_image_info() whether the given image is encrypted or not. For this purpose, it is probably more interesting to see whether a given node itself is encrypted or not (otherwise, a management application cannot discern for certain which nodes are really encrypted and which just have encrypted children). Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- include/block/block.h | 1 - block.c | 8 -------- block/qapi.c | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 86f9728f00..0080fe1311 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -538,7 +538,6 @@ BlockDriverState *bdrv_next(BdrvNextIterator *it); void bdrv_next_cleanup(BdrvNextIterator *it); =20 BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs); -bool bdrv_is_encrypted(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 b59bd776cd..76277ea4e0 100644 --- a/block.c +++ b/block.c @@ -5044,14 +5044,6 @@ bool bdrv_is_sg(BlockDriverState *bs) return bs->sg; } =20 -bool bdrv_is_encrypted(BlockDriverState *bs) -{ - if (bs->backing && bs->backing->bs->encrypted) { - return true; - } - return bs->encrypted; -} - const char *bdrv_get_format_name(BlockDriverState *bs) { return bs->drv ? bs->drv->format_name : NULL; diff --git a/block/qapi.c b/block/qapi.c index afd9f3b4a7..4807a2b344 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -288,7 +288,7 @@ void bdrv_query_image_info(BlockDriverState *bs, info->virtual_size =3D size; info->actual_size =3D bdrv_get_allocated_file_size(bs); info->has_actual_size =3D info->actual_size >=3D 0; - if (bdrv_is_encrypted(bs)) { + if (bs->encrypted) { info->encrypted =3D true; info->has_encrypted =3D true; } --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099028; cv=none; d=zohomail.com; s=zohoarc; b=Rok4+/x1jjBbsv7bLVeRqfuSEcpCtOFAYrX/cH21LEcgMOOlfxUg6kqdBaFtDx91Jq627eN6IOpiCCblABuE3wOzpeei8xGoWg5l4oa9esPyD8ZMO0PwVW6oV7+nGtxiN71cvWj+Wz4zF+paFJB99fPEp+1mbbFB00xexOW1wQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099028; h=Content-Type: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; bh=RQ1KDRkftLMp1tf7K4zPy2rG4hYbZcHYtRHVLRa3hLA=; b=IAPwvJEfGC9Twk+eBOPtzUgvzu+v8tNIEy5PvI1ghJDxBxfO9Guv/IVI3AhjBU2dnxmIom/BoHhx44iZlHe58UbcdaKT3wdEanh3Ul7etvDZhQN7lef3X/rSbXQjQ5DLF/6133cS+3YLsFItQnBi6xos3Hvy6l6wxqDpohWVIMc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099028017683.8516809329479; Thu, 25 Jun 2020 08:30:28 -0700 (PDT) Received: from localhost ([::1]:48456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTpX-0006Z0-0O for importer@patchew.org; Thu, 25 Jun 2020 11:30:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTi5-0005SP-59 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:41 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:47042 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTi3-0000f1-Cc for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:40 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-85-6LIvz5PNMuqtItEi_F13lw-1; Thu, 25 Jun 2020 11:22:36 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C957910059A5; Thu, 25 Jun 2020 15:22:34 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70EC379303; Thu, 25 Jun 2020 15:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RQ1KDRkftLMp1tf7K4zPy2rG4hYbZcHYtRHVLRa3hLA=; b=iNx14grJ5qBaKp3MPo/g5nZEHjxOb86gzRD5RIms2dQqaknjuOkQhdgJnD4WqEYaXvnqA0 RSkC1AAR+AZEI0VUiop1unqCfNNDGHLTLpTIAMc7i+mOKcKve5rCYVnzdcHXJYOAiqSiFM wBgenp7Uye6yYgMwdseFpP1OAWfTIUE= X-MC-Unique: 6LIvz5PNMuqtItEi_F13lw-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 07/47] block: Add bdrv_supports_compressed_writes() Date: Thu, 25 Jun 2020 17:21:35 +0200 Message-Id: <20200625152215.941773-8-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Andrey Shinkevich --- include/block/block.h | 1 + block.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index 0080fe1311..a905a5ec05 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -538,6 +538,7 @@ BlockDriverState *bdrv_next(BdrvNextIterator *it); void bdrv_next_cleanup(BdrvNextIterator *it); =20 BlockDriverState *bdrv_next_monitor_owned(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 76277ea4e0..6449f3a11d 100644 --- a/block.c +++ b/block.c @@ -5044,6 +5044,29 @@ bool bdrv_is_sg(BlockDriverState *bs) return bs->sg; } =20 +/** + * Return whether the given node supports compressed writes. + */ +bool bdrv_supports_compressed_writes(BlockDriverState *bs) +{ + BlockDriverState *filtered; + + if (!bs->drv || !block_driver_can_compress(bs->drv)) { + return false; + } + + filtered =3D bdrv_filter_bs(bs); + 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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099213; cv=none; d=zohomail.com; s=zohoarc; b=Df2yh/ccKJG8oF0V5FPwdsW1wFo1SzZmzf8+C7IaPcs56rPf3eSS37ZU0Qan/VZyA3bMVuK+V1+xIba1D9vqHpC4SqwOdpJIFiT6XVdWjgaqgQVxfCxPabfxMNzqPae6YKbYbbM1UrjeSfYEjaJXcsxidP4V0Ys+niOOif+oP/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099213; h=Content-Type: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; bh=Srr0ng/3UPLUq5FntmQzOQlZqCsCkFYTEO9BVUzzTW8=; b=kNFrJ4OGe0My6NSHWOjUT9Y76d7vM57GoZ1iO2Xxoi7rm5VCnO1tKGEA1RyWNkq4AOD1Bca21mBl4sAtxu3ByXfMmfB34qOFullNBD5Ur379KXvg41GbFb8EvvKS07ptiSps6Sa809Hhq7MWkUCiGRzm2/Y27YQQGmtBwNTlJzw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099213096918.8593822771182; Thu, 25 Jun 2020 08:33:33 -0700 (PDT) Received: from localhost ([::1]:56880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTsZ-0001mP-Mu for importer@patchew.org; Thu, 25 Jun 2020 11:33:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTi6-0005US-F1 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:43 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34546 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTi4-0000hC-SZ for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-ppkSEOHANju3fH7UEPih1w-1; Thu, 25 Jun 2020 11:22:38 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1221D18A0731; Thu, 25 Jun 2020 15:22:37 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7D7F2DE60; Thu, 25 Jun 2020 15:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Srr0ng/3UPLUq5FntmQzOQlZqCsCkFYTEO9BVUzzTW8=; b=Tu9zr+OG4Vu1Yc1VI39jTAX4drxsbzrXjdcbQIIu8IInoozSVXzLd4Zv8fWvRtqONRr/0z qRXdNUu+4+va30uR45cYAnK4a6M2R3S+4sG1E3ExD7y1odZC/2pAmkWLXj/FtwLFa6YjoB vnCxd+VkYLX9YBG66uCEssicR8YILZU= X-MC-Unique: ppkSEOHANju3fH7UEPih1w-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 08/47] throttle: Support compressed writes Date: Thu, 25 Jun 2020 17:21:36 +0200 Message-Id: <20200625152215.941773-9-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich --- block/throttle.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/throttle.c b/block/throttle.c index 0ebbad0743..f6e619aca2 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -154,6 +154,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); @@ -246,6 +255,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_attach_aio_context =3D throttle_attach_aio_context, .bdrv_detach_aio_context =3D throttle_detach_aio_context, --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099326; cv=none; d=zohomail.com; s=zohoarc; b=cojOLyL/dBoq/+1TNXXpE7hZwympOOwLfvDCyhWjppKwpZDTgITGPBr8ZBDXLIExmWrxbjMthwKmlUapvZa5uXq/sm5n6XQLfquShKsp4xtr2b4YcyW/Vj/vPj6z+ekKxhO32EeHhYHDa61NViImozSLbTwsaQN+YV233fAnaxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099326; h=Content-Type: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; bh=nch8r+sggXc7QgAhHaEZqPwOSLb16dIURCBoBCMI83k=; b=kUJmccm5KDqFbJ0eh9Zs3MiM0+v8JLGVWm4j1gU6kBH1ckLC9k3uNekQtrcM/oLQwqunfrR3Y/u1ndXsvA6WtgX4l9QoBaCFGsHYHUloM862NB0SVrOatl8ECEU84oVWmCYMKrXOacP3QLyxPhwY6J2ug7yFNT4xJvCkjk1cfK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099326489900.3108098463211; Thu, 25 Jun 2020 08:35:26 -0700 (PDT) Received: from localhost ([::1]:37216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTuP-0005I3-6F for importer@patchew.org; Thu, 25 Jun 2020 11:35:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTi9-0005W8-Mo for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38743 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTi6-0000jC-PD for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-153-mWG3ApppNz2twuIjQZzevg-1; Thu, 25 Jun 2020 11:22:40 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29B0764AE9; Thu, 25 Jun 2020 15:22:39 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C24925DD61; Thu, 25 Jun 2020 15:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nch8r+sggXc7QgAhHaEZqPwOSLb16dIURCBoBCMI83k=; b=b1fz9iVBJGkcN3C9+tqJBquDc4X6cYsINsf6D5fChLOJghRBEYyIomcP8OGs0dXok2gWp/ RzgoHWWb4SPL7Fw8iodoqewOUWIVhA0+q7n8IGZqqzrOxoZG2GL72FQ62Sb6i//O9P7JOa MLAi5eZ4AOP8wKaSPMpP+6O9GKuTC2U= X-MC-Unique: mWG3ApppNz2twuIjQZzevg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 09/47] copy-on-read: Support compressed writes Date: Thu, 25 Jun 2020 17:21:37 +0200 Message-Id: <20200625152215.941773-10-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- 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 a6e3c74a68..a6a864f147 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -107,6 +107,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); @@ -131,6 +141,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099228; cv=none; d=zohomail.com; s=zohoarc; b=mCSCuqogEWP8cxMIOm/B7RIUe09POJgkWpH3ELPBNwkNrE05l67da770rstfWB4FhjNdslJOvGgQch1v6I0vkBNxoK5gThpRDcB5PnM+J+6h+Yy66YD9zySdevks3NlOV5L70lSfXouBChF+nhVhc8Pd5UfJ8ObhjCmclRlINFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099228; h=Content-Type: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; bh=MqHimW4Fh8To193wjifBj5GjECNEmUokN+yiC3fNTyE=; b=fQIncFfxNEIyMFTLhG5lyBPsstqtbVRct8XpWQwhuINIFlYMPNRL2OGpdN69WsNy/1n+leS0ACbArQVpNM89AwCeh9LMv70OOtaQ4jOaDx8OhO0g7wFBSnf/Yo18fi0SrvFqAh2+vaG3XIZANWAxaSewTKnuTHVa/0js3yv7Hvk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099228919637.2026474973673; Thu, 25 Jun 2020 08:33:48 -0700 (PDT) Received: from localhost ([::1]:57832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTsp-0002AH-Ee for importer@patchew.org; Thu, 25 Jun 2020 11:33:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiG-0005cn-Hk for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:53 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:57807 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiD-0000kj-0r for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-460-R0OP0uE4OzyvVJrHVAm1fg-1; Thu, 25 Jun 2020 11:22:42 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43F6B64AD9; Thu, 25 Jun 2020 15:22:41 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE8EB1DC; Thu, 25 Jun 2020 15:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MqHimW4Fh8To193wjifBj5GjECNEmUokN+yiC3fNTyE=; b=EkZlaPE9c/q8q/ucSJ+eX/kYfjdBF7u5mBecSMrpFlSK3fdnUSL9Gw/OuhdtpxR94bUeph 4+JjuG4XkHQcGWQflPmRz5tuOBjrZXTfDkPctbwVRNkzIOw9eJ0PwMO2RXkdm+5ybXXaX4 EjORkKhvpsFU05dSzbltBzaXN6GJNgY= X-MC-Unique: R0OP0uE4OzyvVJrHVAm1fg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 10/47] mirror-top: Support compressed writes Date: Thu, 25 Jun 2020 17:21:38 +0200 Message-Id: <20200625152215.941773-11-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/mirror.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/mirror.c b/block/mirror.c index e8e8844afc..469acf4600 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1480,6 +1480,15 @@ static int coroutine_fn bdrv_mirror_top_pdiscard(Blo= ckDriverState *bs, NULL, 0); } =20 +static int coroutine_fn bdrv_mirror_top_pwritev_compressed(BlockDriverStat= e *bs, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *q= iov) +{ + return bdrv_mirror_top_pwritev(bs, offset, bytes, qiov, + BDRV_REQ_WRITE_COMPRESSED); +} + static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) { if (bs->backing =3D=3D NULL) { @@ -1526,6 +1535,7 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_pwritev =3D bdrv_mirror_top_pwritev, .bdrv_co_pwrite_zeroes =3D bdrv_mirror_top_pwrite_zeroes, .bdrv_co_pdiscard =3D bdrv_mirror_top_pdiscard, + .bdrv_co_pwritev_compressed =3D bdrv_mirror_top_pwritev_compressed, .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, --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098863; cv=none; d=zohomail.com; s=zohoarc; b=YQqIIz887u1w8KDvSk77S0BIG/P7W+HQwhiMRv4MrmeVZZoDT8WEH7o1WHEFK48gVwEPLgowJGQ3nKRKDaahO0eDbJfn/iHBP4LKh8m5fwTHbxblbxT0wMP0mboyThXaGqYEVljk1MVnhaTCDCZRr6xncETOa+MC51H1baXWyTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098863; h=Content-Type: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; bh=DUoDCTeAaWcF19+6TO8/N66itLLoNICuvHGOrgyI6zE=; b=hGeALPA9kxHNdCqdAlJS27Ih6m2JldgwU+fubD++2g00IxRXfsgNYwn+TS8Bl7MWyRm8fi7gMpNhSinF2aSxPNCeptb7Ek1vcsG6gxTnDE8e0mDUqAhwlSpq+/IhFJkcyTbOgN0GYGzUPsjYpBX0XCIcidF70lcQ5e/rV/9WApo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593098863923646.1534926116904; Thu, 25 Jun 2020 08:27:43 -0700 (PDT) Received: from localhost ([::1]:39170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTmw-0002iD-MM for importer@patchew.org; Thu, 25 Jun 2020 11:27:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiD-0005aA-Q6 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:49 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:42257 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiC-0000kM-5M for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-402-l1n4uSVEMjaskU0bt4cwjg-1; Thu, 25 Jun 2020 11:22:44 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DBD88015FB; Thu, 25 Jun 2020 15:22:43 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D330579A3; Thu, 25 Jun 2020 15:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DUoDCTeAaWcF19+6TO8/N66itLLoNICuvHGOrgyI6zE=; b=RrPAzH4pkOkRntzoyPBBMam3ZFOqjoh6Yw7mEhemXDCTI7AU2yoHPhjfgYfHD1LatgOrDu prME3KOHCHjP27SToX7/6JjSENKoFUVzO0RPA+QQLZHZejU/G7UqBMYUrLXPenrxFigeUI PBV5NGI8q9FSF0bzyDipwCIOTX4yl6E= X-MC-Unique: l1n4uSVEMjaskU0bt4cwjg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 11/47] backup-top: Support compressed writes Date: Thu, 25 Jun 2020 17:21:39 +0200 Message-Id: <20200625152215.941773-12-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/backup-top.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/backup-top.c b/block/backup-top.c index af2f20f346..f304df8f26 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -99,6 +99,15 @@ static coroutine_fn int backup_top_co_pwritev(BlockDrive= rState *bs, return bdrv_co_pwritev(bs->backing, offset, bytes, qiov, flags); } =20 +static coroutine_fn int backup_top_co_pwritev_compressed(BlockDriverState = *bs, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qio= v) +{ + return backup_top_co_pwritev(bs, offset, bytes, qiov, + BDRV_REQ_WRITE_COMPRESSED); +} + static int coroutine_fn backup_top_co_flush(BlockDriverState *bs) { if (!bs->backing) { @@ -173,6 +182,7 @@ BlockDriver bdrv_backup_top_filter =3D { .bdrv_co_pwritev =3D backup_top_co_pwritev, .bdrv_co_pwrite_zeroes =3D backup_top_co_pwrite_zeroes, .bdrv_co_pdiscard =3D backup_top_co_pdiscard, + .bdrv_co_pwritev_compressed =3D backup_top_co_pwritev_compressed, .bdrv_co_flush =3D backup_top_co_flush, =20 .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593098906; cv=none; d=zohomail.com; s=zohoarc; b=KUWu5VK62ReZhu4/IAlx8FioB+cbtubisiXLnCCLELqAK78vIyog3wXvSXwtnsDFbLs297r+agI9BLutmgwUk6JxeTpNxsIhBLo8OnAyfOWvVH1w7CTTXPWKGArKEjhi/uEPw9rcmgbDvh9jjus5Sf9AYz33yKcUkoYPfR46+kU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593098906; h=Content-Type: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; bh=RLFNTP6hPrIGk+fLU8DhCedPvZOQsvKQ/8DHyYcy8dc=; b=a+Mpp9IoQ06DpFfKknCGjYYxDqtq2gptMf8r1zI8XVJmp9O1/UwVH744RW7g1w0ckhdl+vdoUJAgLoXvSD4EFFU1wA5l0FjbnT/msZege6djDwjaMZdJ2ea/BPbRLtzr+GHAlUHQHgU7RGKZevDWxI9kMYQrhK9c/ceTdZkCnzg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593098906375599.6630663488879; Thu, 25 Jun 2020 08:28:26 -0700 (PDT) Received: from localhost ([::1]:40684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTnd-0003Kt-5O for importer@patchew.org; Thu, 25 Jun 2020 11:28:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiF-0005bD-NY for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:51 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:23557 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiD-0000kq-21 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-477-_zaTl9X3PGedNEoCucYrxA-1; Thu, 25 Jun 2020 11:22: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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD3601005512; Thu, 25 Jun 2020 15:22:45 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BDA45C296; Thu, 25 Jun 2020 15:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RLFNTP6hPrIGk+fLU8DhCedPvZOQsvKQ/8DHyYcy8dc=; b=fSdu1vHmpTFcJskS/jqNd/3V5ElwiO+VmlirotTBJVqz9kKAyoOOBuWKWbn/UU+baaGTwm KYY4TsI26PxD80doe5+lPPUM8kNJso2uBN4ji7L9wdiUxskGTz9G3bddyAR3eujmHG+KP6 lKX+y2WueDHWbfMVubiCre/xMnvvL/I= X-MC-Unique: _zaTl9X3PGedNEoCucYrxA-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 12/47] block: Use bdrv_filter_(bs|child) where obvious Date: Thu, 25 Jun 2020 17:21:40 +0200 Message-Id: <20200625152215.941773-13-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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_filter_bs(bs); if (filtered) { ... something about @filtered ... } instead. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block.c | 31 ++++++++++++++++++++----------- block/io.c | 7 +++++-- migration/block-dirty-bitmap.c | 8 +------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index 6449f3a11d..a44af9c3c1 100644 --- a/block.c +++ b/block.c @@ -710,11 +710,12 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState= *bs, Error **errp) int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) { BlockDriver *drv =3D bs->drv; + BlockDriverState *filtered =3D bdrv_filter_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; @@ -729,11 +730,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_filter_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; @@ -5421,6 +5423,8 @@ int bdrv_has_zero_init_1(BlockDriverState *bs) =20 int bdrv_has_zero_init(BlockDriverState *bs) { + BlockDriverState *filtered; + if (!bs->drv) { return 0; } @@ -5433,8 +5437,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_filter_bs(bs); + if (filtered) { + return bdrv_has_zero_init(filtered); } =20 /* safe default */ @@ -5479,8 +5485,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_filter_bs(bs); + if (filtered) { + return bdrv_get_info(filtered, bdi); } return -ENOTSUP; } @@ -6546,6 +6553,8 @@ int bdrv_amend_options(BlockDriverState *bs, QemuOpts= *opts, bool bdrv_recurse_can_replace(BlockDriverState *bs, BlockDriverState *to_replace) { + BlockDriverState *filtered; + if (!bs || !bs->drv) { return false; } @@ -6560,9 +6569,9 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs, } =20 /* For filters without an own implementation, we can recurse on our ow= n */ - if (bs->drv->is_filter) { - BdrvChild *child =3D bs->file ?: bs->backing; - return bdrv_recurse_can_replace(child->bs, to_replace); + filtered =3D bdrv_filter_bs(bs); + if (filtered) { + return bdrv_recurse_can_replace(filtered, to_replace); } =20 /* Safe default */ diff --git a/block/io.c b/block/io.c index df8f2a98d4..385176b331 100644 --- a/block/io.c +++ b/block/io.c @@ -3307,6 +3307,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, Error **errp) { BlockDriverState *bs =3D child->bs; + BdrvChild *filtered; BlockDriver *drv =3D bs->drv; BdrvTrackedRequest req; int64_t old_size, new_bytes; @@ -3358,6 +3359,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, goto out; } =20 + filtered =3D bdrv_filter_child(bs); + /* * If the image has a backing file that is large enough that it would * provide data for the new area, we cannot leave it unallocated becau= se @@ -3390,8 +3393,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, goto out; } ret =3D drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, = errp); - } else if (bs->file && drv->is_filter) { - ret =3D bdrv_co_truncate(bs->file, offset, exact, prealloc, flags,= errp); + } else if (filtered) { + ret =3D bdrv_co_truncate(filtered, offset, exact, prealloc, flags,= errp); } else { error_setg(errp, "Image format driver does not support resize"); ret =3D -ENOTSUP; diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 47bc0f650c..dec656c074 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -356,13 +356,7 @@ static int init_dirty_bitmap_migration(void) while (bs && bs->drv && bs->drv->is_filter && !bdrv_has_named_bitmaps(bs)) { - if (bs->backing) { - bs =3D bs->backing->bs; - } else if (bs->file) { - bs =3D bs->file->bs; - } else { - bs =3D NULL; - } + bs =3D bdrv_filter_bs(bs); } =20 if (bs && bs->drv && !bs->drv->is_filter) { --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099043; cv=none; d=zohomail.com; s=zohoarc; b=cHbI+XVhTdyNmY+gdoZl5nWvembd83fpzQyKRavGDjZzCErO2tpXXz2pRJ31gczxCUABOGoXRuMqwsYMQ90CHtGIHcoq9pFqxKO6Ft/tN1+r6Ch+DPGD0KmViJiNHKNL8W5pJy92Yo6vfbGC+BB5yWw83egK7Lx5bKCZexQvgQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099043; h=Content-Type: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; bh=rIrPbyY3/n1D6dbiL+f9UqPH10R3oWNqYHhFDDh5Xn4=; b=kCAQM0tomOk+2EWlJVcNIID/j8kAugaOV50BgMekpjLljbOXhmRkdPB6Yip5CZDGrEdIsEcpEjoxFs/QDbN3ZdJy7q9DIjwjw9gAM8bzsH6wf7z1QiyGxBDu9G19DWXHRsTmhOS04bBm3qrJi2tI2WkcSp4zE1N2UQ7GkbGeatM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099043407918.0946535353845; Thu, 25 Jun 2020 08:30:43 -0700 (PDT) Received: from localhost ([::1]:49122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTpn-0006qU-Hv for importer@patchew.org; Thu, 25 Jun 2020 11:30:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiM-0005f8-1b for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:59 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:34988 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiI-0000ny-Mc for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:22:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-UispQZMJMDu3AsywrljdXA-1; Thu, 25 Jun 2020 11:22: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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C86711800D4A; Thu, 25 Jun 2020 15:22:47 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D0B71944D; Thu, 25 Jun 2020 15:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rIrPbyY3/n1D6dbiL+f9UqPH10R3oWNqYHhFDDh5Xn4=; b=MfSY4gR1gvjG++xTiyi8rhW85DGFcWz1GHio5zuZ2NwlEKivUAtrGoTLHLrA7hfT2ODFDV CRnU9V3LxgbfsuJ4+dKs3V01bWuF6E3SldPj/C2OVO8gxQ0IrWyPw4U4MxO0Mhn9i2ovqJ WOz4lm2TIYkHZxjEH1GF2t6JqGDrUxc= X-MC-Unique: UispQZMJMDu3AsywrljdXA-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 13/47] block: Use CAFs in block status functions Date: Thu, 25 Jun 2020 17:21:41 +0200 Message-Id: <20200625152215.941773-14-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Andrey Shinkevich --- block/io.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/block/io.c b/block/io.c index 385176b331..dc9891d6ce 100644 --- a/block/io.c +++ b/block/io.c @@ -2407,11 +2407,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_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; @@ -2477,7 +2478,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_filter_or_cow_bs(p)) { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); if (ret < 0) { @@ -2551,7 +2552,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_filter_or_cow_bs(bs), offset, bytes, pnum, map, file); } =20 @@ -2561,9 +2562,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_filter_or_cow_bs(bs), = false, + offset, bytes, pnum ? pnum : &dum= my, + NULL, NULL); if (ret < 0) { return ret; } @@ -2626,7 +2627,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, break; } =20 - intermediate =3D backing_bs(intermediate); + intermediate =3D bdrv_filter_or_cow_bs(intermediate); } =20 *pnum =3D n; --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099103; cv=none; d=zohomail.com; s=zohoarc; b=oHunWVgHdp1z6Wgr2zHecpJsxJrC3gv+gueUh4bFVqQM3rvgzx9eMbg5Zgmz+Lq05DXzQE3Cdr6Y/rsoW1ntfoOVdIkLoP00LD7BWf8iufPR3MpvQ0p9zQg/ZxEvegDPuGwXqRQUqCuCvKlejLdf6JtGkqH69O294NupGKoYomg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099103; h=Content-Type: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; bh=MjN0VjBNTVyuUssgXdokfrm5GaKIdaT0s290vIvxN4I=; b=IRRy4bnSJUXjrbuYFq2V0Sw78/8Lvhofc/IBGxkDWx+sXArmmZi/xNsFu/qxiEcCvnnt0GFARuiAkQyw9TkZj23D7T73ALnHkyyfFH7gAlR2rPE239f1d/suNbTeLiFZn4/f7nxhz06C/gDD39K+uwEBl2vI2c63Woo3wXpqoEk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099103471385.59260899747926; Thu, 25 Jun 2020 08:31:43 -0700 (PDT) Received: from localhost ([::1]:50692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTqo-0007YM-7V for importer@patchew.org; Thu, 25 Jun 2020 11:31:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiO-0005gm-Jo for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:01 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58242 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiI-0000nl-1v for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-313-jTiX5rGWPdKpsDidUqN_Kg-1; Thu, 25 Jun 2020 11:22:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3391E8031F7; Thu, 25 Jun 2020 15:22:50 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A76351944D; Thu, 25 Jun 2020 15:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098573; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MjN0VjBNTVyuUssgXdokfrm5GaKIdaT0s290vIvxN4I=; b=YKGBQCJdDkgD5XVFki0ohjw7lhgBNU06ObLZo6ZRZMmwWUMhvfocF7FcBDZ/82pTPA+oyv wrg7PNPGwNXlOzNHcr4CDLV2uRqmPxtXWANUhEVhlF+//H93pa4zrDAtV5jfI+dLDi/w7U vntZHLr5ly2UUGkqEJrBpOI2F0Ixlo0= X-MC-Unique: jTiX5rGWPdKpsDidUqN_Kg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 14/47] stream: Deal with filters Date: Thu, 25 Jun 2020 17:21:42 +0200 Message-Id: <20200625152215.941773-15-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Because of the (not so recent anymore) changes that make the stream job independent of the base node and instead track the node above it, we have to split that "bottom" node into two cases: The bottom COW node, and the node directly above the base node (which may be an R/W filter or the bottom COW node). Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- qapi/block-core.json | 4 +++ block/stream.c | 63 ++++++++++++++++++++++++++++++++------------ blockdev.c | 4 ++- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index b20332e592..df87855429 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2486,6 +2486,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 aa2e7af98e..b9c1141656 100644 --- a/block/stream.c +++ b/block/stream.c @@ -31,7 +31,8 @@ enum { =20 typedef struct StreamBlockJob { BlockJob common; - BlockDriverState *bottom; + BlockDriverState *base_overlay; /* COW overlay (stream from this) */ + BlockDriverState *above_base; /* Node directly above the base */ BlockdevOnError on_error; char *backing_file_str; bool bs_read_only; @@ -53,7 +54,7 @@ static void stream_abort(Job *job) =20 if (s->chain_frozen) { BlockJob *bjob =3D &s->common; - bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->bottom); + bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->above_base); } } =20 @@ -62,14 +63,15 @@ 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 *base =3D backing_bs(s->bottom); + BlockDriverState *unfiltered_bs =3D bdrv_skip_filters(bs); + BlockDriverState *base =3D bdrv_filter_or_cow_bs(s->above_base); Error *local_err =3D NULL; int ret =3D 0; =20 - bdrv_unfreeze_backing_chain(bs, s->bottom); + bdrv_unfreeze_backing_chain(bs, s->above_base); s->chain_frozen =3D false; =20 - if (bs->backing) { + if (bdrv_cow_child(unfiltered_bs)) { const char *base_id =3D NULL, *base_fmt =3D NULL; if (base) { base_id =3D s->backing_file_str; @@ -77,8 +79,8 @@ static int stream_prepare(Job *job) base_fmt =3D base->drv->format_name; } } - bdrv_set_backing_hd(bs, base, &local_err); - ret =3D bdrv_change_backing_file(bs, base_id, base_fmt); + bdrv_set_backing_hd(unfiltered_bs, base, &local_err); + ret =3D bdrv_change_backing_file(unfiltered_bs, base_id, base_fmt); if (local_err) { error_report_err(local_err); return -EPERM; @@ -109,14 +111,15 @@ static int coroutine_fn stream_run(Job *job, Error **= errp) StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockBackend *blk =3D s->common.blk; BlockDriverState *bs =3D blk_bs(blk); - bool enable_cor =3D !backing_bs(s->bottom); + BlockDriverState *unfiltered_bs =3D bdrv_skip_filters(bs); + bool enable_cor =3D !bdrv_cow_child(s->base_overlay); int64_t len; int64_t offset =3D 0; uint64_t delay_ns =3D 0; int error =3D 0; int64_t n =3D 0; /* bytes */ =20 - if (bs =3D=3D s->bottom) { + if (unfiltered_bs =3D=3D s->base_overlay) { /* Nothing to stream */ return 0; } @@ -150,13 +153,14 @@ static int coroutine_fn stream_run(Job *job, Error **= errp) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(bs, offset, STREAM_CHUNK, &n); + ret =3D bdrv_is_allocated(unfiltered_bs, offset, STREAM_CHUNK, &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), s->bottom, tru= e, + ret =3D bdrv_is_allocated_above(bdrv_cow_bs(unfiltered_bs), + s->base_overlay, true, offset, n, &n); /* Finish early if end of backing file has been reached */ if (ret =3D=3D 0 && n =3D=3D 0) { @@ -223,9 +227,29 @@ void stream_start(const char *job_id, BlockDriverState= *bs, BlockDriverState *iter; bool bs_read_only; int basic_flags =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGE= D; - BlockDriverState *bottom =3D bdrv_find_overlay(bs, base); + BlockDriverState *base_overlay =3D bdrv_find_overlay(bs, base); + BlockDriverState *above_base; =20 - if (bdrv_freeze_backing_chain(bs, bottom, errp) < 0) { + if (!base_overlay) { + error_setg(errp, "'%s' is not in the backing chain of '%s'", + base->node_name, bs->node_name); + return; + } + + /* + * Find the node directly above @base. @base_overlay is a COW overlay= , so + * it must have a bdrv_cow_child(), but it is the immediate overlay of + * @base, so between the two there can only be filters. + */ + above_base =3D base_overlay; + if (bdrv_cow_bs(above_base) !=3D base) { + above_base =3D bdrv_cow_bs(above_base); + while (bdrv_filter_bs(above_base) !=3D base) { + above_base =3D bdrv_filter_bs(above_base); + } + } + + if (bdrv_freeze_backing_chain(bs, above_base, errp) < 0) { return; } =20 @@ -255,14 +279,19 @@ void stream_start(const char *job_id, BlockDriverStat= e *bs, * and resizes. Reassign the base node pointer because the backing BS = of the * bottom node might change after the call to bdrv_reopen_set_read_onl= y() * due to parallel block jobs running. + * above_base node might change after the call to + * bdrv_reopen_set_read_only() due to parallel block jobs running. */ - base =3D backing_bs(bottom); - for (iter =3D backing_bs(bs); iter && iter !=3D base; iter =3D backing= _bs(iter)) { + base =3D bdrv_filter_or_cow_bs(above_base); + for (iter =3D bdrv_filter_or_cow_bs(bs); iter !=3D base; + iter =3D bdrv_filter_or_cow_bs(iter)) + { block_job_add_bdrv(&s->common, "intermediate node", iter, 0, basic_flags, &error_abort); } =20 - s->bottom =3D bottom; + s->base_overlay =3D base_overlay; + s->above_base =3D above_base; s->backing_file_str =3D g_strdup(backing_file_str); s->bs_read_only =3D bs_read_only; s->chain_frozen =3D true; @@ -276,5 +305,5 @@ fail: if (bs_read_only) { bdrv_reopen_set_read_only(bs, true, NULL); } - bdrv_unfreeze_backing_chain(bs, bottom); + bdrv_unfreeze_backing_chain(bs, above_base); } diff --git a/blockdev.c b/blockdev.c index 72df193ca7..1eb0fcdea2 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2515,7 +2515,9 @@ 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_filter_or_cow_bs(iter)) + { if (bdrv_op_is_blocked(iter, BLOCK_OP_TYPE_STREAM, errp)) { goto out; } --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099537; cv=none; d=zohomail.com; s=zohoarc; b=XU6nZEivIQbsZhEq0tqFjMuEVDiIVPAfTbL8uO4SwihX6xA9NJSa2oTYos7iIp6H4A2ZV3WoNLYPEWGowTeYq6oGJ6NlScAiUkCdLgWCBAuJKqGD4EcpDhRM/lZPWzvr0zEbm8p1zIBfrhQKJS+pop2ndkoQM+r0qyNpk2Sdxak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099537; h=Content-Type: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; bh=2yEX1cwu7AhSnNJ+xZkL8DLXxlRL6pDn3Gj2dmxQeiE=; b=YBKX4U46RiUrbdveW4HFodvISP9z8euIfsZ9qMQJFE+ZsJgDryRbGWF6OKpi6IDmJPUSyg8FimwkKzWDqcnyumju1McVozP5M1zOjPwYD63rGELJ8aAZCGIKKHg8FO+37c+SRcYZX+PKq6eOZ4bZFsnOZxt4X5hXyP7IbgoLcJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099537236839.436888025064; Thu, 25 Jun 2020 08:38:57 -0700 (PDT) Received: from localhost ([::1]:50222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTxn-0003Ws-S6 for importer@patchew.org; Thu, 25 Jun 2020 11:38:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiO-0005gn-KE for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:01 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47375 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiK-0000oM-3e for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-b62nW2fXOOuSiKDzXYfpiQ-1; Thu, 25 Jun 2020 11:22:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 53AA61009455; Thu, 25 Jun 2020 15:22:52 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA47C7C214; Thu, 25 Jun 2020 15:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2yEX1cwu7AhSnNJ+xZkL8DLXxlRL6pDn3Gj2dmxQeiE=; b=DB8HRouuBcvjLrPUmppzH3hDjtKrtXGZ13RDHzZvRf9RcRlx7YCCZkIDCCECmM/U7wlc9a bRK73rspUxioLbjxePz6WAX41noz6lXbvzH3pYLb61LbI8P2gDyn2bHTQ1O205ZT2P8UJY /bcmH8MCxf5QncXdYdoVxnFDXiYJ/xw= X-MC-Unique: b62nW2fXOOuSiKDzXYfpiQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 15/47] block: Use CAFs when working with backing chains Date: Thu, 25 Jun 2020 17:21:43 +0200 Message-Id: <20200625152215.941773-16-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use child access functions when iterating through backing chains so filters do not break the chain. In addition, bdrv_find_overlay() will now always return the actual overlay; that is, it will never return a filter node but only one with a COW backing file (there may be filter nodes between that node and @bs). Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index a44af9c3c1..712230ef5c 100644 --- a/block.c +++ b/block.c @@ -4724,7 +4724,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. * @@ -4736,11 +4737,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_filters(bs); + active =3D bdrv_skip_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. */ @@ -4892,9 +4900,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= */ @@ -5351,7 +5357,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_filter_or_cow_bs(top); } =20 return top !=3D NULL; @@ -5607,6 +5613,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, int is_protocol =3D 0; BlockDriverState *curr_bs =3D NULL; BlockDriverState *retval =3D NULL; + BlockDriverState *bs_below; =20 if (!bs || !bs->drv || !backing_file) { return NULL; @@ -5617,7 +5624,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_filters(bs); + bdrv_cow_child(curr_bs) !=3D NULL; + curr_bs =3D bs_below) + { + 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 */ @@ -5625,7 +5642,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 = */ @@ -5635,7 +5652,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; } } @@ -5661,7 +5678,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099724; cv=none; d=zohomail.com; s=zohoarc; b=Fr8C/9cwjPv6Y1MZZa77C7GeVgKfsjIpFSckDQ4fkPs07OIJLU9+elHbkQ9ykKqGAKPxNfOSLIbH2P9iyDYZ6ovLfP/64QcSYU8E15bLuEKddCI0aMt6BaLcWwdsm/jAy/bn5KhMCZrB9ThYAEMO8nvdtwM+e+glIkdY8jlnx3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099724; h=Content-Type: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; bh=sLtShjaBLZarYjMFYpOtzf8DGl/cdiY036TpaXA36N0=; b=OmBbu+Tt9wOelwhcNoeBVhBuQ966vrc8f/M0rAccd6mZkQctS7ojDU1FS3uhybsuHD5FM+K5X5FPuq/BjkEo6HYgpvZzLHYcyZj8uOy4VeKHHcwSHS+lQ+ofIFp88iSrzMh19brv3EDzSnvy5cXm1q1tu8FhtRmp53Yp0PAuQjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 15930997244691019.2177304393306; Thu, 25 Jun 2020 08:42:04 -0700 (PDT) Received: from localhost ([::1]:58926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU0p-0007df-0I for importer@patchew.org; Thu, 25 Jun 2020 11:42:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiQ-0005iI-RT for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:03 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:20985 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiO-0000tz-1d for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-bxdB9b8aOE69Ng3v53KQZg-1; Thu, 25 Jun 2020 11:22:55 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 998AA1009456; Thu, 25 Jun 2020 15:22:54 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 276E15DD61; Thu, 25 Jun 2020 15:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098579; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sLtShjaBLZarYjMFYpOtzf8DGl/cdiY036TpaXA36N0=; b=Zu323QG28iUGsZ6XUU+OLiKU0tAxjUJdBAPlKsBgwRQbWIkOSl0ZZrYkhYt8ryzBJFZ5Rh BmEhlomEzL9DUxwNOjlwYzYDjLiXQnH1ygDpHG6THXZ0j1Azp2Ft0stMUdkakk+bJp/1lP npZTxXZulRqZNqCIxAUqh48Yg6zMwro= X-MC-Unique: bxdB9b8aOE69Ng3v53KQZg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 16/47] block: Use bdrv_cow_child() in bdrv_co_truncate() Date: Thu, 25 Jun 2020 17:21:44 +0200 Message-Id: <20200625152215.941773-17-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The condition modified here is not about potentially filtered children, but only about COW sources (i.e. traditional backing files). Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/io.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index dc9891d6ce..097a3861d8 100644 --- a/block/io.c +++ b/block/io.c @@ -3308,7 +3308,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, Error **errp) { BlockDriverState *bs =3D child->bs; - BdrvChild *filtered; + BdrvChild *filtered, *backing; BlockDriver *drv =3D bs->drv; BdrvTrackedRequest req; int64_t old_size, new_bytes; @@ -3361,6 +3361,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, } =20 filtered =3D bdrv_filter_child(bs); + backing =3D bdrv_cow_child(bs); =20 /* * If the image has a backing file that is large enough that it would @@ -3372,10 +3373,10 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child,= int64_t offset, bool exact, * backing file, taking care of keeping things consistent with that ba= cking * file is the user's responsibility. */ - if (new_bytes && bs->backing) { + if (new_bytes && backing) { int64_t backing_len; =20 - backing_len =3D bdrv_getlength(backing_bs(bs)); + backing_len =3D bdrv_getlength(backing->bs); if (backing_len < 0) { ret =3D backing_len; error_setg_errno(errp, -ret, "Could not get backing file size"= ); --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099222; cv=none; d=zohomail.com; s=zohoarc; b=fc3ZgF+H9NULXxmyYt6d0PyTviTuBAYLaxeMskBvJh8vp0EyiHkptki6aTQhh65CLeZQadn8I472vU9Rsez2JNuNl8xAozolpjyinCYRV42z6sBHNp/AtnSea4VmuDTsFsT4HaTAsVhQF323p1iXZnKoh7EVpXUSogF3vB71dko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099222; h=Content-Type: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; bh=Na6LFAxvfpAY3dT78yZFmDnKhomLwTA8w3U/O1UEuR4=; b=gnAwCEBXjtSFKtuF+zkmtFMGszdHt151e2ZVLO60xqTesQ3VHws760L+AfZUf2iGJOREWpUQqQgrqjH8G66ic1s/XrBu8maHNtMclN2t7hpPQsRCKUrnoFUijxZT59VVCFzXUdwJrrXm+FOqkbHjwbWSgNSTAieH8awhjTTEzf0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099222898757.9161913016627; Thu, 25 Jun 2020 08:33:42 -0700 (PDT) Received: from localhost ([::1]:57796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTsj-00029T-Na for importer@patchew.org; Thu, 25 Jun 2020 11:33:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiR-0005jM-LN for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:03 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:43644 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiP-0000uW-Bd for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:03 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-nLdUukXOOaC-dWG1HBoezg-1; Thu, 25 Jun 2020 11:22:57 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C47D31005512; Thu, 25 Jun 2020 15:22:56 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 653D8579A3; Thu, 25 Jun 2020 15:22:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Na6LFAxvfpAY3dT78yZFmDnKhomLwTA8w3U/O1UEuR4=; b=ES9ST0bia5A/JwgIz9Z9506JVWiM5R/Sjt+rL6NBNu/IgrSLJew0L55JI6W3Thv1D2ouZv VewcpolPaSCqbX+kCI+3Sqf85VeZftc/B8tNv9aY2k1E6URlU2qcc6yonFbdKr3s28k2W6 UeVjNARbFWSP172e++ZUMto5Myi2Yss= X-MC-Unique: nLdUukXOOaC-dWG1HBoezg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 17/47] block: Re-evaluate backing file handling in reopen Date: Thu, 25 Jun 2020 17:21:45 +0200 Message-Id: <20200625152215.941773-18-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/block.c b/block.c index 712230ef5c..8131d0b5eb 100644 --- a/block.c +++ b/block.c @@ -4026,26 +4026,56 @@ 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_filter_or_cow_bs(overlay_bs) && + bdrv_filter_or_cow_bs(overlay_bs)->implicit) + { + overlay_bs =3D bdrv_filter_or_cow_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_filter_or_cow_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 " "an implicit backing file", bs->node_name); 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)) { + /* + * Check if the backing link that we want to replace is frozen. + * Note that + * bdrv_filter_or_cow_child(overlay_bs) =3D=3D overlay_bs->backing, + * because we know that overlay_bs =3D=3D bs, and that @bs + * either is a filter that uses ->backing or a COW format BDS + * with bs->drv->supports_backing =3D=3D true. + */ + if (bdrv_is_backing_chain_frozen(overlay_bs, + child_bs(overlay_bs->backing), er= rp)) + { return -EPERM; } reopen_state->replace_backing_bs =3D true; @@ -4196,7 +4226,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; @@ -4337,7 +4367,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099350; cv=none; d=zohomail.com; s=zohoarc; b=Pu1e19vTKnDOw18OSlqnXo0ioKP/j6IVReKvHw8AP9q6ggh70TVcseR5V4rfXzKuIdEjHIZTVsdtdzm8cN8f8V3vsMwaV5woPVciW1pgXFGpwtzw/kZERgctj6JCwJvkHPavixH1tiTliBNsLi60lI8+/d+8CMWAChs+f8HHZ/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099350; h=Content-Type: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; bh=Lsugp79RAMNcHG74w7ZGLRAAjt0YELvG0KbMAv1dqUk=; b=PKohEXIPhkQ7JsmNQKgUx/b7q2ZG16rfHyXsjdysCQoZniaoWNJORc2Vjli0pSTHTD3aZ6RYWonCXoe4wO9VF+4Q0Qv3006I2kloxMxohKrt4T321tVwLybDlBlbKuJWIBTewzRHhvTMUJvvaIA1Qf5ElC9n6LSqHxc0C9513ZY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099350497591.882957593458; Thu, 25 Jun 2020 08:35:50 -0700 (PDT) Received: from localhost ([::1]:38736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTum-0005xz-RD for importer@patchew.org; Thu, 25 Jun 2020 11:35:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37396) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiV-0005pX-SA for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:07 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:45277 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiU-00010O-5s for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:07 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-150-uKKlE8xoNJe1IIbDriV24A-1; Thu, 25 Jun 2020 11:23:00 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8638107ACCD; Thu, 25 Jun 2020 15:22:58 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C91F2B4A8; Thu, 25 Jun 2020 15:22:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lsugp79RAMNcHG74w7ZGLRAAjt0YELvG0KbMAv1dqUk=; b=Zid1OHS+8I/f8UBdlYAhdcllNfzMgn7l+rRVhGJSl8XwMQABK8ELBgv7JCPYzuy/PU7DEa HDxtw1IXPEhgIX2bpa/fyaB9zH77ZrZuJYN0TFjn76Nnaa3hKnNWEW5GKxmXd4jIwFQePj GA2JOtkG0Jv9X25Ee98qap6KqiD5q/M= X-MC-Unique: uKKlE8xoNJe1IIbDriV24A-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 18/47] block: Flush all children in generic code Date: Thu, 25 Jun 2020 17:21:46 +0200 Message-Id: <20200625152215.941773-19-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 all children that might have been written to (judging from the permissions taken on them). This is a bug fix for qcow2 images with an external data file, as they so far did not flush that data_file node. 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. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/io.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/block/io.c b/block/io.c index 097a3861d8..c2af7711d6 100644 --- a/block/io.c +++ b/block/io.c @@ -2769,6 +2769,8 @@ static int coroutine_fn bdrv_flush_co_entry(void *opa= que) =20 int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { + BdrvChild *primary_child =3D bdrv_primary_child(bs); + BdrvChild *child; int current_gen; int ret =3D 0; =20 @@ -2798,7 +2800,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) { @@ -2808,15 +2810,15 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) =20 /* But don't actually force it to the disk with cache=3Dunsafe */ if (bs->open_flags & BDRV_O_NO_FLUSH) { - goto flush_parent; + goto flush_children; } =20 /* Check if we really need to flush anything */ if (bs->flushed_gen =3D=3D current_gen) { - goto flush_parent; + goto flush_children; } =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) */ @@ -2860,8 +2862,17 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) /* Now flush the underlying protocol. It will also have BDRV_O_NO_FLU= SH * 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; +flush_children: + ret =3D 0; + QLIST_FOREACH(child, &bs->children, next) { + if (child->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) { + int this_child_ret =3D bdrv_co_flush(child->bs); + if (!ret) { + ret =3D this_child_ret; + } + } + } + out: /* Notify any pending flushes that we have completed */ if (ret =3D=3D 0) { --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099337; cv=none; d=zohomail.com; s=zohoarc; b=QRmK5qY8L3csDz00zAe4yARrSvnw/yXJBj/9H/+kxO+cdLgIrUeQpOvzzCdJBjUbfgevgfnM1erC06kuiWncmxFpI0OUp0YJQHqCax/crZDesjE9TZ2Xz1ZXu+YGDwcmVLoTofEQ1FeATv2tO/OXubzUw2xIAlSWn2YtYn12V00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099337; h=Content-Type: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; bh=Rlozvh1JefoYwHhG98f7k+4WjYRuc6ZDe5vc/mVckIQ=; b=b7iPgqqozx9SPw9pUDqJI9vsYz6HxpvxEZEtefZgWtKaLjXxgr1b0e1InHGPhE5d84H8EadkTdFfjsAOcgi+d5kpuCb/V4OD+CWl3IVe2mPHtEWAhF6/trDAs/LINDbkJM/F2gcMsqivsrPh2sF4R/SNXSlPS9M7yosavmnKkpY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099337960184.2001854520321; Thu, 25 Jun 2020 08:35:37 -0700 (PDT) Received: from localhost ([::1]:38158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTua-0005iQ-N1 for importer@patchew.org; Thu, 25 Jun 2020 11:35:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiU-0005nV-Fd for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:06 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47476 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiS-0000zQ-MM for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:06 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-458-ZQbqtHwVOsqeR4XIABQghg-1; Thu, 25 Jun 2020 11:23:02 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C3B7800C60; Thu, 25 Jun 2020 15:23:01 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A78365DAA0; Thu, 25 Jun 2020 15:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098584; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rlozvh1JefoYwHhG98f7k+4WjYRuc6ZDe5vc/mVckIQ=; b=REEk348EZ65plUlW6n3ZXXCiFhEaoJ/c1Zk1z+aTtPCY/2BSlXRc93e966QKUNcW9W7ize mO9d3o43PsoxBWsP9ae3qRj9+7R4jcc+3eHwqLb/UL9fJxud6LlEEps+bWozqDFNo9WUvp uKurTclkfn4rQKedgeU0LF2iNv7PHHk= X-MC-Unique: ZQbqtHwVOsqeR4XIABQghg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 19/47] vmdk: Drop vmdk_co_flush() Date: Thu, 25 Jun 2020 17:21:47 +0200 Message-Id: <20200625152215.941773-20-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Before HEAD^, we needed this because bdrv_co_flush() by itself would only flush bs->file. With HEAD^, bdrv_co_flush() will flush all children on which a WRITE or WRITE_UNCHANGED permission has been taken. Thus, vmdk no longer needs to do it itself. Signed-off-by: Max Reitz --- block/vmdk.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 62da465126..a23890e6ec 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2802,21 +2802,6 @@ static void vmdk_close(BlockDriverState *bs) error_free(s->migration_blocker); } =20 -static coroutine_fn int vmdk_co_flush(BlockDriverState *bs) -{ - BDRVVmdkState *s =3D bs->opaque; - int i, err; - int ret =3D 0; - - for (i =3D 0; i < s->num_extents; i++) { - err =3D bdrv_co_flush(s->extents[i].file->bs); - if (err < 0) { - ret =3D err; - } - } - return ret; -} - static int64_t vmdk_get_allocated_file_size(BlockDriverState *bs) { int i; @@ -3075,7 +3060,6 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_close =3D vmdk_close, .bdrv_co_create_opts =3D vmdk_co_create_opts, .bdrv_co_create =3D vmdk_co_create, - .bdrv_co_flush_to_disk =3D vmdk_co_flush, .bdrv_co_block_status =3D vmdk_co_block_status, .bdrv_get_allocated_file_size =3D vmdk_get_allocated_file_size, .bdrv_has_zero_init =3D vmdk_has_zero_init, --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099490; cv=none; d=zohomail.com; s=zohoarc; b=dxP50/c17HXe7pBx3tE/vhUYFAaFByYKea4Yd7Pz97tiky64ph1zBnyw6vwUZj/fAFzAVvhrHyixXpKqV1JEqMu/ZCQ+20b7QYcftMblouQoBe3CeQLncTcueuVkdGzcTLQi0+9kYtQlxGn4hLsvMRZmhm7WaHRysgRyi2QqXcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099490; h=Content-Type: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; bh=7GdG7y/uVIjtA/pzRCXGa+y8uc64e6boF3Zk7jcxT44=; b=amCl8IaU2oYTC8uQOqYct7JhTL1OzXW4Dd9U18ZNZZp/jXXVDYgrVhZClJp2wxd2i5i/8a1KOxfddB2lkAjg6HyCqX+cJABYv+9Oc9+hBgvMJ2+iWOmiMekw21QTWwyjFGrBr8XCayh28RNrKp2vzv7gAHo5cWDV6IVDC+wGzBE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 159309949048953.15838519951296; Thu, 25 Jun 2020 08:38:10 -0700 (PDT) Received: from localhost ([::1]:47450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTx3-0002Js-3k for importer@patchew.org; Thu, 25 Jun 2020 11:38:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiW-0005sR-UR for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:08 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30685 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiU-00010s-P9 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-dX8h4n6SMQ-qJoeN3JS1Wg-1; Thu, 25 Jun 2020 11:23:04 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44104804002; Thu, 25 Jun 2020 15:23:03 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DECC460BE1; Thu, 25 Jun 2020 15:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7GdG7y/uVIjtA/pzRCXGa+y8uc64e6boF3Zk7jcxT44=; b=EJSnR19mzGY+jGUoY0cj7IrBlfMWc21Z6D3P4G/J1lIyvdtWJCfNjxVk+MTuXpuM3KOYi6 /LGm4oVpOaVoDZpz4YdIKcRNHxP5o8QcVsXpzxBTj38hHKdTb4un1S+o2WfExM/bXUmwvD 0l7otA8938zoMrdqf7RZ1l08BcXi7bU= X-MC-Unique: dX8h4n6SMQ-qJoeN3JS1Wg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 20/47] block: Iterate over children in refresh_limits Date: Thu, 25 Jun 2020 17:21:48 +0200 Message-Id: <20200625152215.941773-21-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of looking at just bs->file and bs->backing, we should look at all children that could end up receiving forwarded requests. Signed-off-by: Max Reitz --- block/io.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index c2af7711d6..37057f13e0 100644 --- a/block/io.c +++ b/block/io.c @@ -135,6 +135,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; + BdrvChild *c; + bool have_limits; Error *local_err =3D NULL; =20 memset(&bs->bl, 0, sizeof(bs->bl)); @@ -149,14 +151,21 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error = **errp) drv->bdrv_co_preadv_part) ? 1 : 512; =20 /* Take some limits from the children as a default */ - if (bs->file) { - bdrv_refresh_limits(bs->file->bs, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; + have_limits =3D false; + QLIST_FOREACH(c, &bs->children, next) { + if (c->role & (BDRV_CHILD_DATA | BDRV_CHILD_FILTERED | BDRV_CHILD_= COW)) + { + bdrv_refresh_limits(c->bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + bdrv_merge_limits(&bs->bl, &c->bs->bl); + have_limits =3D true; } - bdrv_merge_limits(&bs->bl, &bs->file->bs->bl); - } else { + } + + if (!have_limits) { bs->bl.min_mem_alignment =3D 512; bs->bl.opt_mem_alignment =3D qemu_real_host_page_size; =20 @@ -164,15 +173,6 @@ 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 (local_err) { - error_propagate(errp, local_err); - return; - } - bdrv_merge_limits(&bs->bl, &bs->backing->bs->bl); - } - /* Then let the driver override it */ if (drv->bdrv_refresh_limits) { drv->bdrv_refresh_limits(bs, errp); --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099912; cv=none; d=zohomail.com; s=zohoarc; b=Qq0lWvVVkmyqGSMda1ZRgVK5oYrXcogiAAi86UtYK54shXZLHE2LlA/1UeJtCCkrYZc1zOd2SlBpgKOB3MTtcvdI1YSIQ+wgeHZr5EQ5V0D/yBnngs44k2evb9Rt/0elUkjNj4C2S9xT0CKsXPrW93p3viiMhNugoO4efSWRqp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099912; h=Content-Type: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; bh=f/8zhymTzIASkGBdt7o/w7A64dbu+ST4wSjovqOs2p0=; b=eBqyDxw89VToNiQLYDaMTbwIp48z4WNGS0HSp0PByVYOzajIx6sq92VtgXdezNjHH5GvwrCG2W6X4mlPI5wCwG0KAe0fN5KjxU11BpBoj1ZP9FWRsPLZ6HYUMw1QpnouzM72N+jDve7uN5dnwbhwQvd6R/vR0EF2XuBof5D7vtc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099912109443.8780357662232; Thu, 25 Jun 2020 08:45:12 -0700 (PDT) Received: from localhost ([::1]:40858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU3q-0004Ox-ML for importer@patchew.org; Thu, 25 Jun 2020 11:45:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTia-00061s-SI for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:12 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:28353 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiZ-00017M-7Y for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-iM2jqbcWMeykjgOw5lKfYQ-1; Thu, 25 Jun 2020 11:23:06 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6121D800C60; Thu, 25 Jun 2020 15:23:05 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 044325C296; Thu, 25 Jun 2020 15:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f/8zhymTzIASkGBdt7o/w7A64dbu+ST4wSjovqOs2p0=; b=eTOCY0iLwueBPqGuXCHcXuwyD5z2PpHTChQ+xPrVvqqB0kgrjElOBbzJQoHh7mGFpuOsz5 brcsd5DPfGZr44ulXBX7018hH82o9kJ29s2Qacv6krQoPtP0u6YHPfJPcSUo30vpectJ5g g+sWAZePkLxD4mKuaMQ58WlLwbjkKHM= X-MC-Unique: iM2jqbcWMeykjgOw5lKfYQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 21/47] block: Use CAFs in bdrv_refresh_filename() Date: Thu, 25 Jun 2020 17:21:49 +0200 Message-Id: <20200625152215.941773-22-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 8131d0b5eb..7c827fefa0 100644 --- a/block.c +++ b/block.c @@ -6797,6 +6797,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 @@ -6866,20 +6867,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: @@ -6888,11 +6899,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 @@ -6912,6 +6923,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); @@ -6922,8 +6934,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100122; cv=none; d=zohomail.com; s=zohoarc; b=mGWicO+o6LphgEFHvIgTEmj+hg+gGTwiqpECTebZREsL8KwoSe1MgUDA5kWlrzYa8B2uazutGOydMqlBBGdSSUrdj9x3CNu26IPIynZcPac2d90k3RfKIy2AFSNG0F6YITrjUr5vxD/AZVv3beXlyCbLLdvALNFHKJRKBKAdG9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100122; h=Content-Type: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; bh=COIIgdm+cG+aFY3vcWT6Kff8jAuy0uDhItEPKwtBJ9A=; b=Y5UDhf0F7QXOg6vRJxEJpIdqEVc5+qFY2bBxG1c41soU7ZqeyMRjYcvW3YOYAw+uRrlAD55io/tRjQ38TH122X22GSmXjTuXWzlMC5dE2FkkB/foBZamK88MlHjg1JiAeushZnSy/ct5vKtBvMdiybA4bCeGh/WWdoOUV7CyVhE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100122897957.773693503518; Thu, 25 Jun 2020 08:48:42 -0700 (PDT) Received: from localhost ([::1]:49146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU7F-0008M5-Lb for importer@patchew.org; Thu, 25 Jun 2020 11:48:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTic-00065V-DB for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:14 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:60680 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTia-00018v-Vm for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-ifVUW_C6MzOzhPg9mLaHjg-1; Thu, 25 Jun 2020 11:23:08 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C9F3800C60; Thu, 25 Jun 2020 15:23:07 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E70E5DAA0; Thu, 25 Jun 2020 15:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=COIIgdm+cG+aFY3vcWT6Kff8jAuy0uDhItEPKwtBJ9A=; b=fEs0SqozpVzmNeuCDd2EuWdkCXPRZkpJa3bugqNyYKXmQnQRMpiYhb5tsePj5AXLkbt+Fu t6hfU18SWbJZ+5iXwOZndWzXYLsamceaDBROGIdYIhFv+qWmQka6FOb0AMLwJaxfsKl0gE eghzH0kbMDIrEc8a9oJzDUVygrXfpD0= X-MC-Unique: ifVUW_C6MzOzhPg9mLaHjg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 22/47] block: Use CAF in bdrv_co_rw_vmstate() Date: Thu, 25 Jun 2020 17:21:50 +0200 Message-Id: <20200625152215.941773-23-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Andrey Shinkevich --- block/io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 37057f13e0..9e802804bb 100644 --- a/block/io.c +++ b/block/io.c @@ -2646,6 +2646,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); @@ -2658,8 +2659,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099484; cv=none; d=zohomail.com; s=zohoarc; b=VQ5+ng5tku2gebQJOq2RHqjKjeNLlRTMs7wTLT8yS2+2CdjXlqdSa/72bK3J0FR9z1A1og/M04odSxtFFKc9SQ/OfP1+hGcuLB/nTKwczg088CILWqaP/9IMF2w0kDAdpNSb9gasfhdb4/Mel7uQ/AxOMxNEALL3SNrclOhonlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099484; h=Content-Type: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; bh=lvmiJZRro3+Y6TfnnqmHWQAENhuKSBh+pkc6ZF5JGsE=; b=kWk0DAmRINBFIttrY+WVLx4lGzPJjN+QsPE8T7YbBqoFVorxRpdD9AP9jy/dCn0bb0jnqbPOYlIFNbVOZ6uPAkXY581YBQZiRfXUOu69Y72U5I5R6lL4fYIbgL2INjAkzJDyOvYZ1zLAcYRGvRzUzK6PIeTZWP+fPLZWlgN2Kw8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099484209451.4430397596569; Thu, 25 Jun 2020 08:38:04 -0700 (PDT) Received: from localhost ([::1]:46896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTww-0001yj-QJ for importer@patchew.org; Thu, 25 Jun 2020 11:38:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTid-00068u-TV for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:15 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:58467 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTib-00019U-DC for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-m2TR2a4oM8uqGthmbGkhMg-1; Thu, 25 Jun 2020 11:23:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D6D471009613; Thu, 25 Jun 2020 15:23:09 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BDA77FEA0; Thu, 25 Jun 2020 15:23:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lvmiJZRro3+Y6TfnnqmHWQAENhuKSBh+pkc6ZF5JGsE=; b=SRCRXf1GgBfA7Su4Ep9LeGtWL1yO9fXmkRJdukdFI8xWdWiRqmEs9xALVATlBt4DLSi9Vj TpG3LnlT1+eq17QW1kpTCkOT1UWvqdt1MeNPd+lZWFVMnc0y/rnnEXh08PmTE/CZB4PYfw tZ6MXYPpv2WM3YxBBbv3GzW20JvX+Ms= X-MC-Unique: m2TR2a4oM8uqGthmbGkhMg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 23/47] block/snapshot: Fix fallback Date: Thu, 25 Jun 2020 17:21:51 +0200 Message-Id: <20200625152215.941773-24-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If the top node's driver does not provide snapshot functionality and we want to fall back to a node down the chain, we need to snapshot all non-COW children. For simplicity's sake, just do not fall back if there is more than one such child. Furthermore, we really only can fall back to bs->file and bs->backing, because bdrv_snapshot_goto() has to modify the child link (notably, set it to NULL). Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/snapshot.c | 104 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index bd9fb01817..a2bf3a54eb 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -147,6 +147,56 @@ bool bdrv_snapshot_find_by_id_and_name(BlockDriverStat= e *bs, return ret; } =20 +/** + * Return a pointer to the child BDS pointer to which we can fall + * back if the given BDS does not support snapshots. + * Return NULL if there is no BDS to (safely) fall back to. + * + * We need to return an indirect pointer because bdrv_snapshot_goto() + * has to modify the BdrvChild pointer. + */ +static BdrvChild **bdrv_snapshot_fallback_ptr(BlockDriverState *bs) +{ + BdrvChild **fallback; + BdrvChild *child; + + /* + * The only BdrvChild pointers that are safe to modify (and which + * we can thus return a reference to) are bs->file and + * bs->backing. + */ + fallback =3D &bs->file; + if (!*fallback && bs->drv && bs->drv->is_filter) { + fallback =3D &bs->backing; + } + + if (!*fallback) { + return NULL; + } + + /* + * Check that there are no other children that would need to be + * snapshotted. If there are, it is not safe to fall back to + * *fallback. + */ + QLIST_FOREACH(child, &bs->children, next) { + if (child->role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | + BDRV_CHILD_FILTERED) && + child !=3D *fallback) + { + return NULL; + } + } + + return fallback; +} + +static BlockDriverState *bdrv_snapshot_fallback(BlockDriverState *bs) +{ + BdrvChild **child_ptr =3D bdrv_snapshot_fallback_ptr(bs); + return child_ptr ? (*child_ptr)->bs : NULL; +} + int bdrv_can_snapshot(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; @@ -155,8 +205,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 *fallback_bs =3D bdrv_snapshot_fallback(bs); + if (fallback_bs) { + return bdrv_can_snapshot(fallback_bs); } return 0; } @@ -168,14 +219,15 @@ int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { BlockDriver *drv =3D bs->drv; + BlockDriverState *fallback_bs =3D bdrv_snapshot_fallback(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 (fallback_bs) { + return bdrv_snapshot_create(fallback_bs, sn_info); } return -ENOTSUP; } @@ -185,6 +237,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BdrvChild **fallback_ptr; int ret, open_ret; =20 if (!drv) { @@ -205,39 +258,46 @@ int bdrv_snapshot_goto(BlockDriverState *bs, return ret; } =20 - if (bs->file) { - BlockDriverState *file; - QDict *options =3D qdict_clone_shallow(bs->options); + fallback_ptr =3D bdrv_snapshot_fallback_ptr(bs); + if (fallback_ptr) { + QDict *options; QDict *file_options; Error *local_err =3D NULL; + BlockDriverState *fallback_bs =3D (*fallback_ptr)->bs; + char *subqdict_prefix =3D g_strdup_printf("%s.", (*fallback_ptr)->= name); + + 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(fallback_bs); =20 - qdict_extract_subqdict(options, &file_options, "file."); + qdict_extract_subqdict(options, &file_options, subqdict_prefix); qobject_unref(file_options); - qdict_put_str(options, "file", bdrv_get_node_name(file)); + g_free(subqdict_prefix); + + qdict_put_str(options, (*fallback_ptr)->name, + bdrv_get_node_name(fallback_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); + bdrv_unref_child(bs, *fallback_ptr); + *fallback_ptr =3D NULL; + + ret =3D bdrv_snapshot_goto(fallback_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(fallback_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(fallback_bs =3D=3D (*fallback_ptr)->bs); + bdrv_unref(fallback_bs); return ret; } =20 @@ -273,6 +333,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *fallback_bs =3D bdrv_snapshot_fallback(bs); int ret; =20 if (!drv) { @@ -289,8 +350,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 (fallback_bs) { + ret =3D bdrv_snapshot_delete(fallback_bs, snapshot_id, name, errp); } else { error_setg(errp, "Block format '%s' used by device '%s' " "does not support internal snapshot deletion", @@ -306,14 +367,15 @@ int bdrv_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_info) { BlockDriver *drv =3D bs->drv; + BlockDriverState *fallback_bs =3D bdrv_snapshot_fallback(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 (fallback_bs) { + return bdrv_snapshot_list(fallback_bs, psn_info); } return -ENOTSUP; } --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099258; cv=none; d=zohomail.com; s=zohoarc; b=P2sNUF/OSq+xA/siRiHC/So9NvbUkBQ1Hnr0C9+QPukxQD8hiMfM1YFDLYBe5MT6ye95VV2NTlPzTuRR68T5OM9GtiLRpbt1UwyGpT/atTFmui8csdslzjo0oYeiyzEYEWPm9kJlvAbVGPkuG5GZRHF84yZ84AEeXeh4z+j6cQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099258; h=Content-Type: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; bh=v37fGsfrbuTQ9Bcll76bYjO7V2TcbCWlPhGmGpDfgdw=; b=aSeegyJFeDa7JxufPWnbJ6KrQOZ+BPch5l3BLqTIFdMDuqyUe13CCVM9tmmeyS4Lv0/m5ZwSzhZxZ0RPRKqz68+oV6++0kyh0ZQmuY9fXHiHhjrD5QKoEbJh9i7KXtn32IBO/hIO/cO8oEDpu1MRqc6Omt9RD0Tx2mVa8VeU/E4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099258634254.47438424170946; Thu, 25 Jun 2020 08:34:18 -0700 (PDT) Received: from localhost ([::1]:59724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTtJ-0002vo-D9 for importer@patchew.org; Thu, 25 Jun 2020 11:34:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTii-0006Fn-Ah for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42194 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTig-0001C4-CA for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-167-xJW0KKM4MXWFkOG_4mG3Iw-1; Thu, 25 Jun 2020 11:23:13 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2629100960F; Thu, 25 Jun 2020 15:23:11 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 994EC79334; Thu, 25 Jun 2020 15:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v37fGsfrbuTQ9Bcll76bYjO7V2TcbCWlPhGmGpDfgdw=; b=ZAFIxWWwKNkpEHdK9qqypKnREtczwkRxG6wqFbov5pH6zDIqwNiLnJozgcRVVh97Oy54vY r1XDkp1A7qhFO8HNExwKtROa7yIeC5Z2HLCZpC7C058IZ6M4t7cEDqSqHnoKTNTwffWaym FJqd+q0hKFWs/FGSHGomOjDCc/NbDNQ= X-MC-Unique: xJW0KKM4MXWFkOG_4mG3Iw-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 24/47] block: Use CAFs for debug breakpoints Date: Thu, 25 Jun 2020 17:21:52 +0200 Message-Id: <20200625152215.941773-25-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Andrey Shinkevich --- block.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 7c827fefa0..1c71ecab7c 100644 --- a/block.c +++ b/block.c @@ -5562,17 +5562,7 @@ void bdrv_debug_event(BlockDriverState *bs, Blkdebug= Event event) static BlockDriverState *bdrv_find_debug_node(BlockDriverState *bs) { while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) { - if (bs->file) { - bs =3D bs->file->bs; - continue; - } - - if (bs->drv->is_filter && bs->backing) { - bs =3D bs->backing->bs; - continue; - } - - break; + bs =3D bdrv_primary_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_breakpoint) { @@ -5607,7 +5597,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) { @@ -5620,7 +5610,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100253; cv=none; d=zohomail.com; s=zohoarc; b=VdvGhbdzK/oH7K4L3kHZuTUHz9AS4UsOhhQ1HwH4crbfcojXq0gMMH7BMSm7su0pjtQ3K90CH0p/W9FWJNtRAXNYSykgceKh2T66cR0jiGNKcsc8ikIYOKDie6gRIsTA+YqVCUDqiYysqa+jUUjrLsv8iU44xrqkBp2SlVOL1Nc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100253; h=Content-Type: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; bh=9QmBfs5FX6J9CjRRQI7njgqzGGsTngnzcY0UQi6M6EE=; b=L8QaH2N4Lv6MmXXk1CYoo5WiA4VTt05gzKbAhWAjOSOjanPG+XhryrPX1vU7oJ3gHbaIdw956B+QoGNS/JF8v3lnDzZS2lS7uzPQPQKyTWzeCSn6ZiptOPFQVUBgQea6J/r8tKRoeNTDTyaLCeJF5GAZe+4QXsZkkGSAYyNlxnM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100253514193.10069848733815; Thu, 25 Jun 2020 08:50:53 -0700 (PDT) Received: from localhost ([::1]:57272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU9M-0003rR-6R for importer@patchew.org; Thu, 25 Jun 2020 11:50:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTih-0006Eu-8S for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:19 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59646 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTif-0001Bg-Ih for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-9cIZ3t_zOLeItderSWTTNg-1; Thu, 25 Jun 2020 11:23:15 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2679B1009600; Thu, 25 Jun 2020 15:23:14 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB4882B4AC; Thu, 25 Jun 2020 15:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9QmBfs5FX6J9CjRRQI7njgqzGGsTngnzcY0UQi6M6EE=; b=jMfJ7Y5mE/s7dmTRGVO0LSZdJyJKMYp4JRKNW7OY5+CC7oFjWoKVJ+eZu6qkfP9Vl9s0pp FPykQ8gUABNXb5I7SZk6qNapn/viQw3jXCUpvGxp+oOXS0ue3gxbguwjmHpFptO6Q+9fR+ LhlYaKthhgSZm0dcMRPMfJ5pBYt0ajQ= X-MC-Unique: 9cIZ3t_zOLeItderSWTTNg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 25/47] block: Def. impl.s for get_allocated_file_size Date: Thu, 25 Jun 2020 17:21:53 +0200 Message-Id: <20200625152215.941773-26-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If every BlockDriver were to implement bdrv_get_allocated_file_size(), there are basically three ways it would be handled: (1) For protocol drivers: Figure out the actual allocated file size in some protocol-specific way (2) For protocol drivers: If that is not possible (or we just have not bothered to implement it yet), return -ENOTSUP (3) For drivers with children: Return the sum of some or all their children's sizes For the drivers we have, case (3) boils down to either: (a) The sum of all children's sizes (b) The size of the primary child (2), (3a) and (3b) can be implemented generically, so this patch adds such generic implementations for drivers to use. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- include/block/block_int.h | 5 ++++ block.c | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 5da793bfc3..c963ee9f28 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1318,6 +1318,11 @@ int coroutine_fn bdrv_co_block_status_from_backing(B= lockDriverState *bs, int64_t *pnum, int64_t *map, BlockDriverState **file= ); + +int64_t bdrv_sum_allocated_file_size(BlockDriverState *bs); +int64_t bdrv_primary_allocated_file_size(BlockDriverState *bs); +int64_t bdrv_notsup_allocated_file_size(BlockDriverState *bs); + 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.c b/block.c index 1c71ecab7c..fc01ce90b3 100644 --- a/block.c +++ b/block.c @@ -5003,6 +5003,57 @@ int64_t bdrv_get_allocated_file_size(BlockDriverStat= e *bs) return -ENOTSUP; } =20 +/** + * Implementation of BlockDriver.bdrv_get_allocated_file_size() for + * block drivers that want it to sum all children they store data on. + * (This excludes backing children.) + */ +int64_t bdrv_sum_allocated_file_size(BlockDriverState *bs) +{ + BdrvChild *child; + int64_t child_size, sum =3D 0; + + QLIST_FOREACH(child, &bs->children, next) { + if (child->role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | + BDRV_CHILD_FILTERED)) + { + child_size =3D bdrv_get_allocated_file_size(child->bs); + if (child_size < 0) { + return child_size; + } + sum +=3D child_size; + } + } + + return sum; +} + +/** + * Implementation of BlockDriver.bdrv_get_allocated_file_size() for + * block drivers that want it to return only the size of a node's + * primary child. + */ +int64_t bdrv_primary_allocated_file_size(BlockDriverState *bs) +{ + BlockDriverState *primary_bs; + + primary_bs =3D bdrv_primary_bs(bs); + if (!primary_bs) { + return -ENOTSUP; + } + + return bdrv_get_allocated_file_size(primary_bs); +} + +/** + * Implementation of BlockDriver.bdrv_get_allocated_file_size() for + * protocol block drivers that just do not support it. + */ +int64_t bdrv_notsup_allocated_file_size(BlockDriverState *bs) +{ + return -ENOTSUP; +} + /* * bdrv_measure: * @drv: Format driver --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099363; cv=none; d=zohomail.com; s=zohoarc; b=F6EVIQH+YQ4KodGM611WjEWhS8I8gd9Ci1nY0mLL72P1cFGPE+1bhVorO3SAw1MjBziy1sInHSyTRSXKEiWwnI8LxE6nD/gAdOaGmOcJcAuEdxEEeDcGnyItG3MTvi2hAppLOtAONBclY0JLlsfRkBTnptwKfZxLxMgAXMI55Yw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099363; h=Content-Type: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; bh=b5StjsjJhsZsnZZzQfDp+9DI9Lw+3xyP1G23UeZlOeE=; b=Us0voZA9hlpMGjzBAf78EssR5Bia9pAtUWdGMPh5pLve/286oZTgHVWWYKNU2WNC7F6X6S8JhuwzylcKeGUwtyY3NK00rP6rT/djsrRg0mJ04kcOKdmYOcL5vpg9z+uFrw0E2cdcRQK88YOPyg7IR4D88Y0vBtFzTXZ2hoMdhto= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099363316489.6885462042259; Thu, 25 Jun 2020 08:36:03 -0700 (PDT) Received: from localhost ([::1]:39924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTv0-0006Ze-25 for importer@patchew.org; Thu, 25 Jun 2020 11:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiq-0006Hg-92 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:29 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:27173 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTio-0001EL-2r for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-iJ_gJPFAPeWReI4mfxLjig-1; Thu, 25 Jun 2020 11:23:17 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B19A80400F; Thu, 25 Jun 2020 15:23:16 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1002779310; Thu, 25 Jun 2020 15:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b5StjsjJhsZsnZZzQfDp+9DI9Lw+3xyP1G23UeZlOeE=; b=I1yBLMjXiAyVIf1Ur8rigNots4Pn1y9w6HRwWZ9Yb5H61QH7VddAeu2NNofRkZwPMy8nps /l28p0MLmybpX7R5z66bi7rkC3N9vG1LNW7DKrnd3ooKbiBar3q4PhBX8fcxDiq9gr4vZy jE8XuLXDHMuJJc29A30L1Qq4qvH1af4= X-MC-Unique: iJ_gJPFAPeWReI4mfxLjig-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 26/47] block: Improve get_allocated_file_size's default Date: Thu, 25 Jun 2020 17:21:54 +0200 Message-Id: <20200625152215.941773-27-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There are two practical problems with bdrv_get_allocated_file_size()'s default right now: (1) For drivers with children, we should generally sum all their sizes instead of just passing the request through to bs->file. The latter is good for filters, but not so much for format drivers. (2) Filters need not have bs->file, so we should actually go to the filtered child instead of hard-coding bs->file. And we can make the whole default implementation more idiomatic by using the three generic functions added by the previous patch. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index fc01ce90b3..a19f243997 100644 --- a/block.c +++ b/block.c @@ -4997,10 +4997,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverSta= te *bs) 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); + + if (drv->bdrv_file_open) { + /* + * Protocol drivers default to -ENOTSUP (most of their data is + * not stored in any of their children (if they even have any), + * so there is no generic way to figure it out). + */ + return bdrv_notsup_allocated_file_size(bs); + } else if (drv->is_filter) { + /* Filter drivers default to the size of their primary child */ + return bdrv_primary_allocated_file_size(bs); + } else { + /* Other drivers default to summing their children's sizes */ + return bdrv_sum_allocated_file_size(bs); } - return -ENOTSUP; } =20 /** --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099543; cv=none; d=zohomail.com; s=zohoarc; b=SvQTAcRxlq+Fep06APY0wLOgadhwNXz0bHtwcWv5GDh7LrSeOf/3nEoEB0OJxlzT1ckQxAgmRirhcGNHMHgUwv3vX21uXlXhq21+GTcU0SoTU9dgkT87mHiVcNI0R8f6ufpOmMbAUy/oGrTmM7IKypzL2fSwgyer0fhairFLR6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099543; h=Content-Type: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; bh=seVMBTfbgS6bXS9g7xb1XnqpuEC3VigQJIdmNrRL7xo=; b=BrAFPLm+PJVDZr/6L3pD7XVGxI15exGvqf21K2eu/sr5gs8NB6u29UH52DDFaQJzlu4Up6a0WvIQLKcGb1zQbWLVUTSKsM41ZrhOL2jtyDEx2hpJ6pKxPk1jU2iBgT97xPimEO4UieqqLgMeTf0BQI7ZH4jREI1neTHT97ct+kw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099543876607.5227502058067; Thu, 25 Jun 2020 08:39:03 -0700 (PDT) Received: from localhost ([::1]:50786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joTxu-0003mP-DM for importer@patchew.org; Thu, 25 Jun 2020 11:39:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTit-0006J0-1c for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:31 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25800 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTio-0001Eb-4f for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-483-wABsiDm6MYuuA5FFb8YI9w-1; Thu, 25 Jun 2020 11:23:19 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91D651009600; Thu, 25 Jun 2020 15:23:18 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38A12579A3; Thu, 25 Jun 2020 15:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=seVMBTfbgS6bXS9g7xb1XnqpuEC3VigQJIdmNrRL7xo=; b=i6KS6wJ/lv0KsalBH3i79QgHfg215ssawNnvPYyWEnngXclvUnqlfHGdgWHGy/DQJAM7Zp EwUn1fJS3j3gX5gtBXouDceQ0aGR0aB0sGO8aG/iHgEdLTHf1GuKvA/XM0EDFw6Ka9Tag7 BS6Df7zO0vbU8EhLOm/MV26rj3sHjSs= X-MC-Unique: wABsiDm6MYuuA5FFb8YI9w-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 27/47] blkverify: Use bdrv_sum_allocated_file_size() Date: Thu, 25 Jun 2020 17:21:55 +0200 Message-Id: <20200625152215.941773-28-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" blkverify is a filter, so bdrv_get_allocated_file_size()'s default implementation will return only the size of its filtered child. However, because both of its children are disk images, it makes more sense to sum both of their allocated sizes. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/blkverify.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/blkverify.c b/block/blkverify.c index 2f261de24b..64858c8df0 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -323,6 +323,7 @@ static BlockDriver bdrv_blkverify =3D { .bdrv_getlength =3D blkverify_getlength, .bdrv_refresh_filename =3D blkverify_refresh_filename, .bdrv_dirname =3D blkverify_dirname, + .bdrv_get_allocated_file_size =3D bdrv_sum_allocated_file_size, =20 .bdrv_co_preadv =3D blkverify_co_preadv, .bdrv_co_pwritev =3D blkverify_co_pwritev, --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100369; cv=none; d=zohomail.com; s=zohoarc; b=XhILlwq42dmPa9d5tb1hKxXtFSFzoq3jUSJ+Eq0Kl/Hw3k5H3acrvTaITIttPeYNdQNzwidSLyPjr2mn4Bz9cV0voLHD5yZdWkfSeMxUKkg20D/oFvLvWikZYLHHSfOvzhsOepDKi95Vf+QORWVaoQJP3S7i9bCFup4NFOFQrvE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100369; h=Content-Type: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; bh=lQUia8OoMgalBsALIOPf4VeyZUKjuCFth09x2HxRiII=; b=bvI9t6E1C3kzApkKmQjoxtmrYF5NBo160YlIROaXeaN8Mm7yiOQus/JQpr0crd1ENloyTfLQSdR9323Z9jzbAUggRbgaYFqsWq+hjLZUSkj3HBKea9J4tjfehVzp9bgismAj7AITk1d1qepw5axPSk5DGDealIYzhk5D/hbQGy4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 159310036930249.114483711727075; Thu, 25 Jun 2020 08:52:49 -0700 (PDT) Received: from localhost ([::1]:38150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joUBD-0007e4-TM for importer@patchew.org; Thu, 25 Jun 2020 11:52:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTit-0006Iy-0s for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:39144 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTio-0001Gk-4x for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-qWKZUqPcONCRpvIXjNfdeA-1; Thu, 25 Jun 2020 11:23:21 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC9B6A0BD7; Thu, 25 Jun 2020 15:23:20 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52F7F5C296; Thu, 25 Jun 2020 15:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQUia8OoMgalBsALIOPf4VeyZUKjuCFth09x2HxRiII=; b=XoUds5HgMKdV99GlGMkdtT/XZyKUCagjdKwXWE+xX0Y8M34mr1u5/aR2urt/TCHh1nD4Bl xLpg3K1/COH2fthFphxtLUFDfYDuIdP31JA9AsOn17CR6ruwmUy5Av+PFr3fpwcV6579mY UWOPqdkN5tB4PhYVvX5chd9p518VxGQ= X-MC-Unique: qWKZUqPcONCRpvIXjNfdeA-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 28/47] block/null: Implement bdrv_get_allocated_file_size Date: Thu, 25 Jun 2020 17:21:56 +0200 Message-Id: <20200625152215.941773-29-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It is trivial, so we might as well do it. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/null.c | 7 +++++++ tests/qemu-iotests/153.out | 2 +- tests/qemu-iotests/184.out | 6 ++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block/null.c b/block/null.c index 15e1d56746..cc9b1d4ea7 100644 --- a/block/null.c +++ b/block/null.c @@ -262,6 +262,11 @@ static void null_refresh_filename(BlockDriverState *bs) bs->drv->format_name); } =20 +static int64_t null_allocated_file_size(BlockDriverState *bs) +{ + return 0; +} + static const char *const null_strong_runtime_opts[] =3D { BLOCK_OPT_SIZE, NULL_OPT_ZEROES, @@ -277,6 +282,7 @@ static BlockDriver bdrv_null_co =3D { .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_co_parse_filename, .bdrv_getlength =3D null_getlength, + .bdrv_get_allocated_file_size =3D null_allocated_file_size, =20 .bdrv_co_preadv =3D null_co_preadv, .bdrv_co_pwritev =3D null_co_pwritev, @@ -297,6 +303,7 @@ static BlockDriver bdrv_null_aio =3D { .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_aio_parse_filename, .bdrv_getlength =3D null_getlength, + .bdrv_get_allocated_file_size =3D null_allocated_file_size, =20 .bdrv_aio_preadv =3D null_aio_preadv, .bdrv_aio_pwritev =3D null_aio_pwritev, diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index b2a90caa6b..8659e6463b 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -461,7 +461,7 @@ No conflict: image: null-co:// file format: null-co virtual size: 1 GiB (1073741824 bytes) -disk size: unavailable +disk size: 0 B =20 Conflict: qemu-img: --force-share/-U conflicts with image options diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out index 3deb3cfb94..28b104da89 100644 --- a/tests/qemu-iotests/184.out +++ b/tests/qemu-iotests/184.out @@ -29,7 +29,8 @@ Testing: "image": { "virtual-size": 1073741824, "filename": "json:{\"throttle-group\": \"group0\", \"drive= r\": \"throttle\", \"file\": {\"driver\": \"null-co\"}}", - "format": "throttle" + "format": "throttle", + "actual-size": SIZE }, "iops_wr": 0, "ro": false, @@ -56,7 +57,8 @@ Testing: "image": { "virtual-size": 1073741824, "filename": "null-co://", - "format": "null-co" + "format": "null-co", + "actual-size": SIZE }, "iops_wr": 0, "ro": false, --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099722; cv=none; d=zohomail.com; s=zohoarc; b=J23JhEpFAsk3VSpSgMk4yS38X41qE7Q3j08DvNIFTPUB7Ysme8OVbDplGP2T1swnf3H995LiBNtiTHkIDc6tKNK4bsxA2QZSqidxKoykpA0TncfPKIqcD9czZq4mvVL7QdHcS3Quub7O+VwQ3r21qPtq0nzuEtx85R78P8CbLYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099722; h=Content-Type: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; bh=RoOduJqwAcCCbtswbUqZ/O4h3JjrgT0wbvxEWac1X0U=; b=RzAQuTmUKQugyIEC0Zs+avVkNs6OS/CFcZlF1k5z91KWqU5rPlXc24rtt77hQPzCDsnmCxnw7j/TS7fOw8tm2mORmvTGjDtab49qlmy9f20imMhsacUpLKi8e/l6BWNk+k8l1XeaRjwoTMu2NUQuq8S1/q1Ee/NaD9NkZsXopDQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099722415375.23325156359294; Thu, 25 Jun 2020 08:42:02 -0700 (PDT) Received: from localhost ([::1]:58776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU0m-0007Z2-Qe for importer@patchew.org; Thu, 25 Jun 2020 11:42:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiz-0006L9-G6 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:37 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:54821 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTip-0001Hw-Uu for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-eAV4fmnfNiGvwElwWwlIPQ-1; Thu, 25 Jun 2020 11:23:23 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA68F107ACCD; Thu, 25 Jun 2020 15:23:22 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A7C51A913; Thu, 25 Jun 2020 15:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RoOduJqwAcCCbtswbUqZ/O4h3JjrgT0wbvxEWac1X0U=; b=DqV/pA/VqtP1OKmhek2HNzgQDwRlHQAe2RtDAMZPlz78fWE9CKbilIt28bV/WpMfoDwXpB afYtX9em70WdLnwrh54ijgi3Xo9qJBj8mcB3cqyOqvCAZ87KLkDdtH0lIUERTcjDhjFbGs z5lKz7ThOdyNM/huoLcnTZWG7+TT5BM= X-MC-Unique: eAV4fmnfNiGvwElwWwlIPQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 29/47] blockdev: Use CAF in external_snapshot_prepare() Date: Thu, 25 Jun 2020 17:21:57 +0200 Message-Id: <20200625152215.941773-30-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Andrey Shinkevich --- blockdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 1eb0fcdea2..aabe51036d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1549,7 +1549,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_cow_child(state->new_bs)) { error_setg(errp, "The overlay already has a backing image"); goto out; } --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099681; cv=none; d=zohomail.com; s=zohoarc; b=O0oU+xI5lF8pmsGPIhYXCgJRUwrviAGRlD7TtJVsjSIeZsmOyOpAkymqWyNVuViO5TI8B2aPL7JeluA+pGigrG4d/Ekd8Iv2RCXpngSk3Bf0d3bgc2gvMybZGxoqPJXLrEAVPm4cEGcm6yWm8S7zs/L3E3By6iYNgJ9ynfuBRxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099681; h=Content-Type: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; bh=WZMbkc5VZ61WfI8sHwP9l3v+/qyZcXZQkq67wAktK/U=; b=XqlofC3NoXAeQ1OhLc/ZV+kqkMtyf64PIbmsz1dkLBScfl1ahDGmv0vmVnMF4LH55+/sPzACvKsavGJcV3grq+TCNiWGcx6bl2BhAk8qKAL4b6X4PyPIUEtHf3hefSAaPmLVzY4DcnthbStGaRE9ygXgSzrsReOVqSOEjqWn/cU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099681740872.5460313926645; Thu, 25 Jun 2020 08:41:21 -0700 (PDT) Received: from localhost ([::1]:56256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU06-0006F8-Nt for importer@patchew.org; Thu, 25 Jun 2020 11:41:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTiz-0006LK-IU for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:37 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:24708 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTir-0001Ie-Nm for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-D_3RBdSHObWINP7HvHxY-A-1; Thu, 25 Jun 2020 11:23:26 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16FC3804003; Thu, 25 Jun 2020 15:23:25 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD6CD5C662; Thu, 25 Jun 2020 15:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WZMbkc5VZ61WfI8sHwP9l3v+/qyZcXZQkq67wAktK/U=; b=ah1FXdPBPKyhNGVwuqY9fLOrau9mmInVK44826DelHOHdHO3rCWJFNsPknsVUE1/CzS91R FuerZdWUdCOSZyawKItYWhj448uT3WGqtxj8sFoianvujemlupuqAnIBKNlhblxRsh5fHO ZMDfStuIEiS7CYL1cr4Jv4R6HIGrm9Q= X-MC-Unique: D_3RBdSHObWINP7HvHxY-A-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 30/47] block: Report data child for query-blockstats Date: Thu, 25 Jun 2020 17:21:58 +0200 Message-Id: <20200625152215.941773-31-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It makes no sense to report the block stats of a purely metadata-storing child in query-blockstats. So if the primary child does not have any data, try to find a unique data-storing child. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/qapi.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index 4807a2b344..c57b42d86d 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -526,6 +526,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level) { + BdrvChild *parent_child; BlockStats *s =3D NULL; =20 s =3D g_malloc0(sizeof(*s)); @@ -555,9 +556,35 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverSta= te *bs, s->has_driver_specific =3D true; } =20 - if (bs->file) { + parent_child =3D bdrv_primary_child(bs); + if (!parent_child || + !(parent_child->role & (BDRV_CHILD_DATA | BDRV_CHILD_FILTERED))) + { + BdrvChild *c; + + /* + * Look for a unique data-storing child. We do not need to look f= or + * filtered children, as there would be only one and it would have= been + * the primary child. + */ + parent_child =3D NULL; + QLIST_FOREACH(c, &bs->children, next) { + if (c->role & BDRV_CHILD_DATA) { + if (parent_child) { + /* + * There are multiple data-storing children and we can= not + * choose between them. + */ + parent_child =3D NULL; + break; + } + parent_child =3D c; + } + } + } + if (parent_child) { s->has_parent =3D true; - s->parent =3D bdrv_query_bds_stats(bs->file->bs, blk_level); + s->parent =3D bdrv_query_bds_stats(parent_child->bs, blk_level); } =20 if (blk_level && bs->backing) { --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099841; cv=none; d=zohomail.com; s=zohoarc; b=aY358lEC1C2BaZSbQ6vt+bjp51EuNEIoVbVR+zb7hpa6m93FI9u9CgW/IpuAWY/4/WUDGtVKqDCW21k5b/8azpYcioDnSEHQzFUNLcpKLnyfv81kSNisv4EaMLC8HXMIWjRaJbZLikaFmGbbaKvivi9QAHwVcUF6+cWojzSEL5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099841; h=Content-Type: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; bh=FB19Qj2AUohd7rqYzKLrRfmZ5gpIPG6T/O/SJkRBUV8=; b=Hy13pYIFrd4qHnVreiY/TfOiKK9K5cl5BI0tVey6Hw8uf7Z/0fttnLYVBnbwU6hagxJDLFDLw2NqoOTpVBgjPzxwzyOgxXgvwtPeXE2ciCo82220he1MbWnE4LeQpAohD6SgE5mGxjxr8IPRVB2HXxcIYP7zCEnKDSEVDAfngvM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099841720799.9109623514539; Thu, 25 Jun 2020 08:44:01 -0700 (PDT) Received: from localhost ([::1]:36020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU2i-0001w8-BI for importer@patchew.org; Thu, 25 Jun 2020 11:44:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTj0-0006Lh-4V for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:38 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38791 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTit-0001Ja-0i for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-St_404s-NKq9tqOmiTF3qQ-1; Thu, 25 Jun 2020 11:23:28 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 337B68064B6; Thu, 25 Jun 2020 15:23:27 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CE531579A3; Thu, 25 Jun 2020 15:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FB19Qj2AUohd7rqYzKLrRfmZ5gpIPG6T/O/SJkRBUV8=; b=e4JaEz57RjL+RhEJf8uA4oKCaWMZn2iQURKallNk64uFm66uMxfBxw6HnqVajlXEwa1qAU rRDfeQU++Fzb8zQ2LhmYhtH4cyXQXvDdmhjICPI7PllF/6Kk7SwmWGl79Jx+qa/vDVXJFx sl0Sr3gXtd6UBTiFNNRtlhTflwb/o20= X-MC-Unique: St_404s-NKq9tqOmiTF3qQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 31/47] block: Use child access functions for QAPI queries Date: Thu, 25 Jun 2020 17:21:59 +0200 Message-Id: <20200625152215.941773-32-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" query-block, query-named-block-nodes, and query-blockstats 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: Andrey Shinkevich --- block/qapi.c | 33 ++++++++++++++++++++------------- tests/qemu-iotests/184.out | 8 +++++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index c57b42d86d..2628323b63 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -163,9 +163,13 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *= blk, break; } =20 - if (bs0->drv && bs0->backing) { + if (bs0->drv && bdrv_filter_or_cow_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_filter_or_cow_bs(bs0); (*p_image_info)->has_backing_image =3D true; p_image_info =3D &((*p_image_info)->backing_image); } else { @@ -174,9 +178,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 @@ -362,9 +365,7 @@ static void bdrv_query_info(BlockBackend *blk, BlockInf= o **p_info, 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); - } + bs =3D bdrv_skip_implicit_filters(bs); =20 info->device =3D g_strdup(blk_name(blk)); info->type =3D g_strdup("unknown"); @@ -527,6 +528,7 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverStat= e *bs, bool blk_level) { BdrvChild *parent_child; + BlockDriverState *filter_or_cow_bs; BlockStats *s =3D NULL; =20 s =3D g_malloc0(sizeof(*s)); @@ -539,9 +541,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]) { @@ -587,9 +588,15 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverSta= te *bs, s->parent =3D bdrv_query_bds_stats(parent_child->bs, blk_level); } =20 - if (blk_level && bs->backing) { + filter_or_cow_bs =3D bdrv_filter_or_cow_bs(bs); + if (blk_level && filter_or_cow_bs) { + /* + * Put any filtered or COW child here (for backwards + * compatibility to when we put bs0->backing here, which might + * be either) + */ s->has_backing =3D true; - s->backing =3D bdrv_query_bds_stats(bs->backing->bs, blk_level); + s->backing =3D bdrv_query_bds_stats(filter_or_cow_bs, blk_level); } =20 return s; diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out index 28b104da89..4e92fcfb51 100644 --- a/tests/qemu-iotests/184.out +++ b/tests/qemu-iotests/184.out @@ -27,6 +27,12 @@ Testing: "iops_rd": 0, "detect_zeroes": "off", "image": { + "backing-image": { + "virtual-size": 1073741824, + "filename": "null-co://", + "format": "null-co", + "actual-size": SIZE + }, "virtual-size": 1073741824, "filename": "json:{\"throttle-group\": \"group0\", \"drive= r\": \"throttle\", \"file\": {\"driver\": \"null-co\"}}", "format": "throttle", @@ -35,7 +41,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100499; cv=none; d=zohomail.com; s=zohoarc; b=We4dt5sejBGTX8LHjSQzb+PwB2u7HieHFdP8c+iT5bd0OEhA3Qg6ufo38qoDJ0Tx53uYRm2GlsYecmjsV89ijC9+voGZ6I6aTfztEJkBeVKb5raPhr1LXit3XKFP1mXh/GeGkD0joBNtewigveMZcB4XheFHicao0feFjKg4hJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100499; h=Content-Type: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; bh=1bohRTXKhs8SJ9joqAmiNiJmiKVo3BQhl+UvgYAoY8g=; b=QnC04aVxh+eSw1tFLgxYfouecw+Bgqx7cteuX/PsxVxISQqGxlNQu5L7ZS+JcOhPDGZxRuJF2sHBlSXIG69kvdoKOSiAxItVkjLYCDO315fKdw1pIpnn8ERy70D5o5/OifaS4+4Tda6Wo7tEEsx7VFjnGD+BoJ2+/WhN6uYmeFQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100499320137.16882335353068; Thu, 25 Jun 2020 08:54:59 -0700 (PDT) Received: from localhost ([::1]:48204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joUDK-0003Gz-0h for importer@patchew.org; Thu, 25 Jun 2020 11:54:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTj1-0006OR-At for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:39 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:36073 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiz-0001Ki-Cn for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:38 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-fJ1pyAUaMtaMxm57fc6l1w-1; Thu, 25 Jun 2020 11:23:30 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75307A0BE4; Thu, 25 Jun 2020 15:23:29 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 103077FEA0; Thu, 25 Jun 2020 15:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1bohRTXKhs8SJ9joqAmiNiJmiKVo3BQhl+UvgYAoY8g=; b=HpQ12+Gl6Xlp4i6RmLy/usqAvT9yZ9v+pIHPHpWsqcgbGnMW/rJEondQdyP2JdjeO73IEr SZtu3ZT9DKKXSFR7NhmmfwC4GW8APHGGbHeJNfyzmNuZAAVG3MGngcLiQjt5VnVvNMRXhy uiyTc/puitsgmKR8d2LWpA4BwhmXMEc= X-MC-Unique: fJ1pyAUaMtaMxm57fc6l1w-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 32/47] block-copy: Use CAF to find sync=top base Date: Thu, 25 Jun 2020 17:22:00 +0200 Message-Id: <20200625152215.941773-33-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/block-copy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index f7428a7c08..5e80569bb8 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -437,8 +437,8 @@ static int block_copy_block_status(BlockCopyState *s, i= nt64_t offset, BlockDriverState *base; int ret; =20 - if (s->skip_unallocated && s->source->bs->backing) { - base =3D s->source->bs->backing->bs; + if (s->skip_unallocated) { + base =3D bdrv_backing_chain_next(s->source->bs); } else { base =3D NULL; } --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100050; cv=none; d=zohomail.com; s=zohoarc; b=Y3F1P8xqVYYWBbfuTon0CdOKgfQqMWaUU6cM/X2FQSbCrxVP7lmzNx6aXHT+hBhrTjRv/mdJdWKu095EPfF/nz5HWInsAtTfdkShEq41LkP+vfZBRDfri+CRWN4DHlaPQX0470dDIiH/W+nTdkXyH4ETsFbCx7czlCnN2B8WLYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100050; h=Content-Type: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; bh=O8QNsiR0l36jYvWMXswYAxOYUuWM3tZzPZmV8UYTVek=; b=gYEW1cJ6NVIsoSasPHxjIQ2lA03nEusgOxbovzYE1cWA/LSTxuYTi+mke8vyze7yQpz+oHeDU8gzEJ+uYLQwXTsFxg7gG96qW0ke0hNOWVGf9gFhjmgmzC7Mo6K3L9GV1ShjLCJHLz9nSGjvnJB2Cz1vdKKTs4t/IySkFFtnu1w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100049992109.17508219848776; Thu, 25 Jun 2020 08:47:29 -0700 (PDT) Received: from localhost ([::1]:45132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU64-0006Vc-DV for importer@patchew.org; Thu, 25 Jun 2020 11:47:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTj2-0006Rn-8b for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:40 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38357 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTiz-0001Kl-O7 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-41-MjFpIaUdP9OXJQv_QPGDyg-1; Thu, 25 Jun 2020 11:23:32 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C149718A8221; Thu, 25 Jun 2020 15:23:31 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3751C1DC; Thu, 25 Jun 2020 15:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O8QNsiR0l36jYvWMXswYAxOYUuWM3tZzPZmV8UYTVek=; b=CMXY7BJaiMmcoQFUbqDpv2xJP2Nrs0Kr5VXvCRDB/LpVGt+ZTUtAk26P1wdcm/zwDFMzEJ p397CoGeikM2COWuZDGbR1kQeyhoKI94se7Xa6J3H0szadft3mbkTzaquOscl4GY8OW37D 00RYlSfj+pQPjK2FnQhOU23EOJYdhNI= X-MC-Unique: MjFpIaUdP9OXJQv_QPGDyg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 33/47] mirror: Deal with filters Date: Thu, 25 Jun 2020 17:22:01 +0200 Message-Id: <20200625152215.941773-34-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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). Use this opportunity to rename qmp_drive_mirror()'s "source" BDS to "target_backing_bs", because that is what it really refers to. Signed-off-by: Max Reitz --- qapi/block-core.json | 6 ++- block/mirror.c | 118 +++++++++++++++++++++++++++++++++---------- blockdev.c | 36 +++++++++---- 3 files changed, 121 insertions(+), 39 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index df87855429..0b8ccd30aa 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1943,7 +1943,8 @@ # # @replaces: with sync=3Dfull graph node name to be replaced by the new # image when a whole image copy is done. This can be used to re= pair -# broken Quorum files. (Since 2.1) +# broken Quorum files. By default, @device is replaced, althou= gh +# implicitly created filters on it are kept. (Since 2.1) # # @mode: whether and how QEMU should create a new image, default is # 'absolute-paths'. @@ -2254,7 +2255,8 @@ # # @replaces: with sync=3Dfull graph node name to be replaced by the new # image when a whole image copy is done. This can be used to re= pair -# broken Quorum files. +# broken Quorum files. By default, @device is replaced, althou= gh +# implicitly created filters on it are kept. # # @speed: the maximum speed, in bytes per second # diff --git a/block/mirror.c b/block/mirror.c index 469acf4600..770de3b34e 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -42,6 +42,7 @@ typedef struct MirrorBlockJob { BlockBackend *target; BlockDriverState *mirror_top_bs; BlockDriverState *base; + BlockDriverState *base_overlay; =20 /* The name of the graph node to replace */ char *replaces; @@ -677,8 +678,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_filters(target_b= s); + + if (bdrv_cow_bs(unfiltered_target) !=3D backing) { + bdrv_set_backing_hd(unfiltered_target, backing, &local_err); if (local_err) { error_report_err(local_err); local_err =3D NULL; @@ -740,7 +743,7 @@ static int mirror_exit_common(Job *job) * valid. */ block_job_remove_all_bdrv(bjob); - 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 @@ -786,7 +789,6 @@ static void coroutine_fn mirror_throttle(MirrorBlockJob= *s) static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) { int64_t offset; - BlockDriverState *base =3D s->base; BlockDriverState *bs =3D s->mirror_top_bs->backing->bs; BlockDriverState *target_bs =3D blk_bs(s->target); int ret; @@ -837,7 +839,8 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) return 0; } =20 - ret =3D bdrv_is_allocated_above(bs, base, false, offset, bytes, &c= ount); + ret =3D bdrv_is_allocated_above(bs, s->base_overlay, true, offset,= bytes, + &count); if (ret < 0) { return ret; } @@ -936,7 +939,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); @@ -1116,8 +1119,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_filters(target), NULL, + "backing", errp); if (ret < 0) { return; } @@ -1565,8 +1569,8 @@ static BlockJob *mirror_start_job( 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 @@ -1585,7 +1589,7 @@ static BlockJob *mirror_start_job( buf_size =3D DEFAULT_MIRROR_BUF_SIZE; } =20 - if (bs =3D=3D target) { + if (bdrv_skip_filters(bs) =3D=3D bdrv_skip_filters(target)) { error_setg(errp, "Can't mirror node into itself"); return NULL; } @@ -1649,15 +1653,50 @@ static BlockJob *mirror_start_job( * 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; + } else if (bdrv_chain_contains(bs, bdrv_skip_filters(target))) { + /* + * We may want to allow this in the future, but it would + * require taking some extra care. + */ + error_setg(errp, "Cannot mirror to a filter on top of a node in th= e " + "source's backing chain"); + goto fail; + } + + 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; @@ -1682,6 +1721,7 @@ static BlockJob *mirror_start_job( s->zero_target =3D zero_target; s->copy_mode =3D copy_mode; s->base =3D base; + s->base_overlay =3D bdrv_find_overlay(bs, base); s->granularity =3D granularity; s->buf_size =3D ROUND_UP(buf_size, granularity); s->unmap =3D unmap; @@ -1712,15 +1752,39 @@ static BlockJob *mirror_start_job( /* 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_filters(filtered_target) =3D=3D bdrv_skip_filters(tar= get) + */ + filtered_target =3D bdrv_cow_bs(bdrv_find_overlay(bs, target)); + + assert(bdrv_skip_filters(filtered_target) =3D=3D + bdrv_skip_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_filter_or_cow_bs(bs); iter !=3D target; + iter =3D bdrv_filter_or_cow_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; } @@ -1756,7 +1820,7 @@ fail: bs_opaque->stop =3D true; bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing, &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); =20 @@ -1784,7 +1848,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, zero_targ= et, on_source_error, on_target_error, unmap, NULL, NULL, diff --git a/blockdev.c b/blockdev.c index aabe51036d..6ca9b19779 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2886,6 +2886,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, bool has_auto_dismiss, bool auto_dismis= s, Error **errp) { + BlockDriverState *unfiltered_bs; int job_flags =3D JOB_DEFAULT; =20 if (!has_speed) { @@ -2937,10 +2938,19 @@ 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 + if (!has_replaces) { + /* We want to mirror from @bs, but keep implicit filters on top */ + unfiltered_bs =3D bdrv_skip_implicit_filters(bs); + if (unfiltered_bs !=3D bs) { + replaces =3D unfiltered_bs->node_name; + has_replaces =3D true; + } + } + if (has_replaces) { BlockDriverState *to_replace_bs; AioContext *replace_aio_context; @@ -2987,7 +2997,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, void qmp_drive_mirror(DriveMirror *arg, Error **errp) { BlockDriverState *bs; - BlockDriverState *source, *target_bs; + BlockDriverState *target_backing_bs, *target_bs; AioContext *aio_context; AioContext *old_context; BlockMirrorBackingMode backing_mode; @@ -2996,6 +3006,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; bool zero_target; int ret; =20 @@ -3022,12 +3033,12 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) } =20 flags =3D bs->open_flags | BDRV_O_RDWR; - source =3D backing_bs(bs); - if (!source && arg->sync =3D=3D MIRROR_SYNC_MODE_TOP) { + target_backing_bs =3D bdrv_cow_bs(bdrv_skip_filters(bs)); + if (!target_backing_bs && arg->sync =3D=3D MIRROR_SYNC_MODE_TOP) { arg->sync =3D MIRROR_SYNC_MODE_FULL; } if (arg->sync =3D=3D MIRROR_SYNC_MODE_NONE) { - source =3D bs; + target_backing_bs =3D bs; } =20 size =3D bdrv_getlength(bs); @@ -3042,6 +3053,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) " named node of the graph"); goto out; } + replaces_node_name =3D arg->replaces; } =20 if (arg->mode =3D=3D NEW_IMAGE_MODE_ABSOLUTE_PATHS) { @@ -3053,7 +3065,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) /* Don't open backing image in create() */ flags |=3D BDRV_O_NO_BACKING; =20 - if ((arg->sync =3D=3D MIRROR_SYNC_MODE_FULL || !source) + if ((arg->sync =3D=3D MIRROR_SYNC_MODE_FULL || !target_backing_bs) && arg->mode !=3D NEW_IMAGE_MODE_EXISTING) { /* create new image w/o backing file */ @@ -3061,15 +3073,19 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) 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(target_backing_bs); + switch (arg->mode) { case NEW_IMAGE_MODE_EXISTING: break; case NEW_IMAGE_MODE_ABSOLUTE_PATHS: /* create new image with backing file */ - bdrv_refresh_filename(source); + bdrv_refresh_filename(explicit_backing); 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: @@ -3119,7 +3135,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) aio_context_acquire(aio_context); =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, zero_target, arg->has_speed, arg->speed, arg->has_granularity, arg->granularity, --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100612; cv=none; d=zohomail.com; s=zohoarc; b=RT1ogz34H8C/57EJ/F/qwqxW1mhEKZD8kfc2kHK0WoOIQYz6O4bfMH+b/Fqy3gMXMjpD/ib9SbMRdY9DbRVfebpcdWvbuDue9ng3r8LXZ2BCzt+LjVlDWCEtmHjKgIYhiiLWoSmAcvBAaDkpQ0HeTL6YFIwJ5pDCXzL2M1khK64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100612; h=Content-Type: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; bh=qU6f31lDyHMBZh0c3uwIiBtG/8pYMX9RJW67yj7Fn20=; b=jjyNlDGN8aMtoUiw/px4s5afekXtQFxDG+vjml5PPfLuxYWwwnSaRn8HEgnbrTpZHvb7+egUH6I0GzrpIKQl0tXJxb7zhvDHJD41Dwy3mPSJGyGyU8Csc1QpbLN2tuG2Unqsq1DByc8LZ+xT68089NhzRac2Xxk47STgN5TYMzs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100612241652.3523446412541; Thu, 25 Jun 2020 08:56:52 -0700 (PDT) Received: from localhost ([::1]:57114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joUF9-0006x7-0h for importer@patchew.org; Thu, 25 Jun 2020 11:56:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTj3-0006UB-FA for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:41 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59835 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTj1-0001MA-Hp for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-388-nurc67ZTPu6wAtYgyI-7bQ-1; Thu, 25 Jun 2020 11:23:34 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D8E70107ACF2; Thu, 25 Jun 2020 15:23:33 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D1FD7CCC0; Thu, 25 Jun 2020 15:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qU6f31lDyHMBZh0c3uwIiBtG/8pYMX9RJW67yj7Fn20=; b=WLw9HlQgkMIWAdYqWxMJ6Jz3+ldTX7fuxP2Bd3CRRCGsfsBvF3LgtrJUrAEsHCM98cmxhi Jrb3r+HMCfSToqcmZy7HbUanCC0MECGwLsy77lYrxR0hUl2pJgQ6kgtdB0uFWPnXbzcq2z 2BKX1KrYRNe2hdQWbLmpDztMbFdwZUU= X-MC-Unique: nurc67ZTPu6wAtYgyI-7bQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 34/47] backup: Deal with filters Date: Thu, 25 Jun 2020 17:22:02 +0200 Message-Id: <20200625152215.941773-35-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- block/backup-top.c | 2 +- block/backup.c | 9 +++++---- blockdev.c | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/block/backup-top.c b/block/backup-top.c index f304df8f26..89bd3937d0 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -291,7 +291,7 @@ void bdrv_backup_top_drop(BlockDriverState *bs) =20 s->active =3D false; bdrv_child_refresh_perms(bs, bs->backing, &error_abort); - bdrv_replace_node(bs, backing_bs(bs), &error_abort); + bdrv_replace_node(bs, bs->backing->bs, &error_abort); bdrv_set_backing_hd(bs, NULL, &error_abort); =20 bdrv_drained_end(bs); diff --git a/block/backup.c b/block/backup.c index 4f13bb20a5..9afa0bf3b4 100644 --- a/block/backup.c +++ b/block/backup.c @@ -297,6 +297,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 @@ -304,7 +305,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 " @@ -313,14 +314,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; } @@ -371,7 +372,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, return NULL; } =20 - if (compress && !block_driver_can_compress(target->drv)) { + 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 6ca9b19779..9ce99b9cbc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1728,7 +1728,13 @@ static void drive_backup_prepare(BlkActionState *com= mon, Error **errp) * 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_cow_bs(bdrv_skip_filters(bs)); if (!source) { backup->sync =3D MIRROR_SYNC_MODE_FULL; } @@ -1748,9 +1754,14 @@ static void drive_backup_prepare(BlkActionState *com= mon, Error **errp) 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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099850; cv=none; d=zohomail.com; s=zohoarc; b=GfY2hZo+1zzhMc8B10FWI2GwJY83a22vCVG53FOZQ+NvbVIzAmJC/1kMe44FkQJZ4wkPtZOJptpglEw5B/caFTY4kRVPcd+DzMZr05iPe9kulT7fBnQvzQFCbIVXtWa4NrH/3vUJMmhoRMdUg1xML/+ou4lOXA5fFKs3n6qoQh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099850; h=Content-Type: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; bh=pfZPe2A0gMy19xNoNvyJo6Hg83Fvr4rLDGbzuj1bsDg=; b=mdHQL4EfvidFjh4LpcO6Aq0XO/xjXuxjIBpBjWp0e8629psZlRfPAclIMyUaFHzOM5KMYQCkb9BAYR35XNbqRxfFJSks1sfbfqledJzw2m4fIcrKW+pCYUjuaadtbkUL+TnCJY3utks2pt0iwWwU7YgHv1gOznhaM11mLi6rcxw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099850890972.3633876729609; Thu, 25 Jun 2020 08:44:10 -0700 (PDT) Received: from localhost ([::1]:36764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU2r-0002VU-Gu for importer@patchew.org; Thu, 25 Jun 2020 11:44:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTj9-0006hW-41 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:47 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:27852 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTj7-0001Pc-AZ for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-349--APkIY4yOJi1zkscek-RaA-1; Thu, 25 Jun 2020 11:23:39 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 46C40464; Thu, 25 Jun 2020 15:23:36 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3A961DC; Thu, 25 Jun 2020 15:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pfZPe2A0gMy19xNoNvyJo6Hg83Fvr4rLDGbzuj1bsDg=; b=DF6OJmWg0PD1Q/3HaD1T/dMMiIKgId/NczHkuKT+wEO1p6aFqBBZAUXWmW33Pf/KcUMZ81 OzWGW8OB/KmvZ+O81zENhbk/WbGu1ZjkI7V0di7cB9+o+pddHQkFUWqQ1BGDaxdB1si+3s /X8pm5oGeDfuET8nmPhgSSMR54sblKQ= X-MC-Unique: -APkIY4yOJi1zkscek-RaA-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 35/47] commit: Deal with filters Date: Thu, 25 Jun 2020 17:22:03 +0200 Message-Id: <20200625152215.941773-36-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Andrey Shinkevich --- block/block-backend.c | 9 +++- block/commit.c | 96 +++++++++++++++++++++++++--------- block/monitor/block-hmp-cmds.c | 2 +- blockdev.c | 4 +- 4 files changed, 81 insertions(+), 30 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 6936b25c83..7f2c7dbccc 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2271,8 +2271,13 @@ 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 (blk_is_inserted(blk)) { + BlockDriverState *non_filter; + int ret; + + /* Legacy function, so skip implicit filters */ + non_filter =3D bdrv_skip_implicit_filters(blk->root->bs); + ret =3D bdrv_commit(non_filter); if (ret < 0) { aio_context_release(aio_context); return ret; diff --git a/block/commit.c b/block/commit.c index 7732d02dfe..4122b6736d 100644 --- a/block/commit.c +++ b/block/commit.c @@ -37,6 +37,7 @@ typedef struct CommitBlockJob { BlockBackend *top; BlockBackend *base; BlockDriverState *base_bs; + BlockDriverState *base_overlay; BlockdevOnError on_error; bool base_read_only; bool chain_frozen; @@ -89,7 +90,7 @@ static void commit_abort(Job *job) * XXX Can (or should) we somehow keep 'consistent read' blocked even * after the failed/cancelled commit job is gone? If we already wrote * something to base, the intermediate images aren't valid any more. */ - 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); @@ -153,7 +154,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), f= alse, + ret =3D bdrv_is_allocated_above(blk_bs(s->top), s->base_overlay, t= rue, offset, COMMIT_BUFFER_SIZE, &n); copy =3D (ret =3D=3D 1); trace_commit_one_iteration(s, offset, n, ret); @@ -253,15 +254,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_filters(top) =3D=3D bdrv_skip_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) { @@ -301,17 +322,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. */ - 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. */ + /* + * 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()). + */ + s->base_overlay =3D bdrv_find_overlay(top, base); + assert(s->base_overlay); + + /* + * The topmost node with + * bdrv_skip_filters(filtered_base) =3D=3D bdrv_skip_filters(base) + */ + filtered_base =3D bdrv_cow_bs(s->base_overlay); + assert(bdrv_skip_filters(filtered_base) =3D=3D bdrv_skip_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_filter_or_cow_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; } @@ -328,9 +375,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); @@ -398,19 +443,22 @@ int bdrv_commit(BlockDriverState *bs) if (!drv) return -ENOMEDIUM; =20 - if (!bs->backing) { + backing_file_bs =3D bdrv_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; } } @@ -428,8 +476,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) { @@ -515,15 +561,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/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 4c8c375172..4d3db5ed3c 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -217,7 +217,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 diff --git a/blockdev.c b/blockdev.c index 9ce99b9cbc..402f1d1df1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2690,7 +2690,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_filter_or_cow_bs(base_bs); + iter =3D bdrv_filter_or_cow_bs(iter)) + { if (bdrv_op_is_blocked(iter, BLOCK_OP_TYPE_COMMIT_TARGET, errp)) { goto out; } --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099698; cv=none; d=zohomail.com; s=zohoarc; b=GleUw5DbUf52SS+TmohbmXgH3fSxIOXEVYzblyCsvSmaIxUoH/sAYAUqMcgJx+F+LYnL/aEy7kmP2ZMPIGNT5dLu8Daal0KpGsQc5ZSA6/5rQhMGGfNA4NoYv5J0gYrbG8DW5LLUga5cGR5rD3gpx1GyXB4mCu4UoFl1L2vbRNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099698; h=Content-Type: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; bh=X/Sm9/+V7odEAygyWQbSMGVl2dEggt5ex5dhsjIDTtI=; b=KnHziTcjgEMTTBvVLfMFGoMsw+sUGEWDFDKwn38zvW0H23GkcqXJ1XpDM+NONiZf2bgMp5+yp8tnnA7a4KQxWsG3QXWzWfQOgac8hzqzSwGlwWz9cRzRpgVZQyztvRX89CHac6uDcJy0P9dxJvRBnB4QgqLSF4GhogwCw6BqDdg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099698798903.8489554912894; Thu, 25 Jun 2020 08:41:38 -0700 (PDT) Received: from localhost ([::1]:56912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU0P-0006XS-EO for importer@patchew.org; Thu, 25 Jun 2020 11:41:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTj6-0006c6-Lb for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:44 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:42932 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTj3-0001O0-RA for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-Bht4TWFsPBywXSBU4SoOqg-1; Thu, 25 Jun 2020 11:23:39 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67986800C64; Thu, 25 Jun 2020 15:23:38 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F1366109F; Thu, 25 Jun 2020 15:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X/Sm9/+V7odEAygyWQbSMGVl2dEggt5ex5dhsjIDTtI=; b=Z87qJdwzKCyerdZsDu6pkfmoqB/eVuE7zU0AnBec7HOkrKpSHDiQcyqDXf3wetN9AH8EXr 9cIrFzD4+LkYy6DVGHjwQUMnd5+iA6sR1WECUQVnY3oL/poTHfOFHqOV0wxuOJRT9ZCfZ0 evmnlmet2v9yEk1Csvk6b+fJf5pLTjU= X-MC-Unique: Bht4TWFsPBywXSBU4SoOqg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 36/47] nbd: Use CAF when looking for dirty bitmap Date: Thu, 25 Jun 2020 17:22:04 +0200 Message-Id: <20200625152215.941773-37-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 02:30:11 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Andrey Shinkevich --- nbd/server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 20754e9ebc..b504a79435 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1561,13 +1561,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_filter_or_cow_bs(bs); } =20 if (bm =3D=3D NULL) { --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593099919; cv=none; d=zohomail.com; s=zohoarc; b=NpxPYKs0BO783G4JnzbGLyAFH7EYODC/Qywd8WmR4g2YIfzcJUsqATTR3cy7a9qgXL9Qo3JTBGzaRbuys49VEy7XbI/xIiyM2sNv87AI8M1cBs5mzcfJoLJvIcWNiL367MqolBoDzsEVxekw6p7nCMJOujlLRudiuu8vws5n37o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593099919; h=Content-Type: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; bh=h/Yl/2jRZhZlPGJGP9AJRvFe0734mYF3oEnNfao89Xs=; b=nkMV0y5Fw26mVSd/+0W6fhxqX192Tl+3zEJ5aJyi0MFYwM4iPGPmpoDfoEmzK8XmbSnalZWU2rE4m9ujNNrCei25SHrYl6u98uSsWj1DDGvB/bgiKuVRut8KXUDkZ6nhjjY+9+nbIdr/lQL9FmZ0njrGLfyZJfvjlMUHuwuGh4w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593099919285559.1283953478386; Thu, 25 Jun 2020 08:45:19 -0700 (PDT) Received: from localhost ([::1]:41310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU3y-0004aG-05 for importer@patchew.org; Thu, 25 Jun 2020 11:45:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTj9-0006hO-2I for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:47 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23412 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTj7-0001Pa-62 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-egdhuAkLONOMRPTUYL5e8w-1; Thu, 25 Jun 2020 11:23:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 99F3D100960F; Thu, 25 Jun 2020 15:23:40 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3AAC21944D; Thu, 25 Jun 2020 15:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h/Yl/2jRZhZlPGJGP9AJRvFe0734mYF3oEnNfao89Xs=; b=f4lv+4lYqU7NiAzB5UgVk03PIhg5TbIdFiLOQZGidYkhyPq1MayOCl4/l8w3B/4/tvaL+p BU+T5jm1EOYy+47dE9ktIsz4Tta3G+l7Q6gv7cw76pEmbeHi+tvei2DovT0CS9yFszYOAF mipyMd64OX6TjDsk850Z7LMnH2zsNfQ= X-MC-Unique: egdhuAkLONOMRPTUYL5e8w-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 37/47] qemu-img: Use child access functions Date: Thu, 25 Jun 2020 17:22:05 +0200 Message-Id: <20200625152215.941773-38-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Andrey Shinkevich --- qemu-img.c | 36 ++++++++++++++++++++++-------------- tests/qemu-iotests/204.out | 1 + 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 381271a74e..947be6ffac 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1089,7 +1089,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_backing_chain_next(bs); if (!base_bs) { error_setg(&local_err, "Image does not have a backing file"); goto done; @@ -1737,18 +1737,20 @@ static int convert_iteration_sectors(ImgConvertStat= e *s, int64_t sector_num) if (s->sector_next_status <=3D sector_num) { uint64_t offset =3D (sector_num - src_cur_offset) * BDRV_SECTOR_SI= ZE; int64_t count; + BlockDriverState *src_bs =3D blk_bs(s->src[src_cur]); + BlockDriverState *base; + + if (s->target_has_backing) { + base =3D bdrv_cow_bs(bdrv_skip_filters(src_bs)); + } else { + base =3D NULL; + } =20 do { count =3D n * BDRV_SECTOR_SIZE; =20 - if (s->target_has_backing) { - ret =3D bdrv_block_status(blk_bs(s->src[src_cur]), offset, - count, &count, NULL, NULL); - } else { - ret =3D bdrv_block_status_above(blk_bs(s->src[src_cur]), N= ULL, - offset, count, &count, NULL, - NULL); - } + ret =3D bdrv_block_status_above(src_bs, base, offset, count, &= count, + NULL, NULL); =20 if (ret < 0) { if (s->salvage) { @@ -2673,7 +2675,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_backing_chain_next(out_bs)); } else { s.target_backing_sectors =3D -1; } @@ -3044,6 +3047,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, =20 depth =3D 0; for (;;) { + bs =3D bdrv_skip_filters(bs); ret =3D bdrv_block_status(bs, offset, bytes, &bytes, &map, &file); if (ret < 0) { return ret; @@ -3052,7 +3056,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_cow_bs(bs); if (bs =3D=3D NULL) { ret =3D 0; break; @@ -3437,6 +3441,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; @@ -3571,6 +3576,8 @@ static int img_rebase(int argc, char **argv) } bs =3D blk_bs(blk); =20 + unfiltered_bs =3D bdrv_skip_filters(bs); + if (out_basefmt !=3D NULL) { if (bdrv_find_format(out_basefmt) =3D=3D NULL) { error_report("Invalid format name: '%s'", out_basefmt); @@ -3582,7 +3589,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_cow_bs(unfiltered_bs); =20 if (base_bs) { blk_old_backing =3D blk_new(qemu_get_aio_context(), @@ -3738,8 +3745,9 @@ 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, - false, offset, n, &n); + ret =3D bdrv_is_allocated_above(bdrv_cow_bs(unfiltered_bs), + prefix_chain_bs, false, + offset, n, &n); if (ret < 0) { error_report("error while reading image metadata: %s", strerror(-ret)); 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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100044; cv=none; d=zohomail.com; s=zohoarc; b=fS5K4HEuJZYXfcX/TtpHFQWfOp/aWmT7BMF5cBp39kXGTfARk/QGJLeA+S9c+9prZzimAMVDDhupVZqweI4cHTJs3bEaAXXBuwfBNbp6DivYq/4Ay7WAB64xHiCXHm3Krc0k9WTw8aIZtQjx/FaydtrNxK9x4997hfW9ZPsZb9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100044; h=Content-Type: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; bh=+IEs/J5V97t+K7qXqSnYOoZJv1OiExIbkpNL2hKSuJU=; b=kTLOwIJImL66+KBB9iIU9sCVUZUkEnxy+2qB3jEB8qeXY+KCkPY9vGPntF29ZcaGzB3y+ygdcO/TFIWRpVGEAYjOqL9nnETVacS2kmUkkDRHX9/iTnx6QPh8i1VygBV7/rjUjNOukFq5mPoSsKM8H6+tW8RnoAr9zD7V6NPe/2s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100044069648.1166719174242; Thu, 25 Jun 2020 08:47:24 -0700 (PDT) Received: from localhost ([::1]:45124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU5w-0006VM-Tv for importer@patchew.org; Thu, 25 Jun 2020 11:47:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjA-0006kh-Hb for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:48 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:37876 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTj8-0001Px-BG for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-452-mqWUYolmMuaqDH1nTFhnHw-1; Thu, 25 Jun 2020 11:23:43 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D64C0464; Thu, 25 Jun 2020 15:23:42 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BD4E579A3; Thu, 25 Jun 2020 15:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+IEs/J5V97t+K7qXqSnYOoZJv1OiExIbkpNL2hKSuJU=; b=OqGKHS9PnZL2yjVnAbiAlxYntu9/5o3T/4sk2VDyrY3GQwV5zJQLKtQgNrXMx/+VDDp2gY nJORgeXCzMFG7NFmzbNTiO53GVO6ZdqrQ3Til5skvtCtmW5en3SO3N9HqBz/y58VAaXRAR oA64fl4Oljf3kh6UjG8MQc7qZoxUrBw= X-MC-Unique: mqWUYolmMuaqDH1nTFhnHw-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 38/47] block: Drop backing_bs() Date: Thu, 25 Jun 2020 17:22:06 +0200 Message-Id: <20200625152215.941773-39-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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_cow_bs(). Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich --- 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 c963ee9f28..6e09e15ed4 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -991,11 +991,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100733; cv=none; d=zohomail.com; s=zohoarc; b=Z8TsOrvb7LDEQ2ce2nDFxvZ/2q7UOyE+bNZTb5OruMAyxodWqLnTpDLM3yB+tVf0VQXsuMXOdMQM1q5Y6q+S4bo0XS0pfYRyBKN2/dDlf+IDBHIUVCojWoAqDAmT+i3/kMNAUe0XWimEI5Eg/RNRsllmQUealt62Ufbiyud2JDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100733; h=Content-Type: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; bh=eXRCbxWHdhFdTk379StqcMbCRmexSIRMFz/qo0e8ItE=; b=djpaaZM5JE+g5xkFpo11egPBbgPAoJGND/YtBL7ZbPz+jdlhwVENx5SI1/nSHi3qaeGqmjqvRGOoSxn6VuwT7ve1ckx1MJunDMldWHsyBbMkxkCW/t78ZoTnH4dXLK52qrWM0tGCijlngvoqz9jHLzIeN9toX2OhWCWrWX3tYkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100733450896.5864649967925; Thu, 25 Jun 2020 08:58:53 -0700 (PDT) Received: from localhost ([::1]:36556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joUH6-0001oT-9O for importer@patchew.org; Thu, 25 Jun 2020 11:58:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjF-0006m4-Ut for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59030 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjA-0001Qx-Ia for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-xFmB7LR-MeaySYcHJMWDHg-1; Thu, 25 Jun 2020 11:23:46 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2E1B800C60; Thu, 25 Jun 2020 15:23:44 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96A721A913; Thu, 25 Jun 2020 15:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eXRCbxWHdhFdTk379StqcMbCRmexSIRMFz/qo0e8ItE=; b=AZndKzlKHmsaRcDHBBAGrwo3ZGVrkf0WUjcAMB61v5IlOC24GVkx3ZcJKUlAtkeCF8Scvw rl2URCAoLLOG1r/7FF3LNpaH2ic9YZFiRD5HejU+eicwV++vtTEl8ADFeYZBjxlskmcLwv tuTme2Bz7VcZUSwjjkA2zjlYFB918ls= X-MC-Unique: xFmB7LR-MeaySYcHJMWDHg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 39/47] blockdev: Fix active commit choice Date: Thu, 25 Jun 2020 17:22:07 +0200 Message-Id: <20200625152215.941773-40-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 402f1d1df1..237fffbe53 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2589,6 +2589,7 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, AioContext *aio_context; Error *local_err =3D NULL; int job_flags =3D JOB_DEFAULT; + uint64_t top_perm, top_shared; =20 if (!has_speed) { speed =3D 0; @@ -2704,14 +2705,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_filters(top_bs) =3D=3D bdrv_skip_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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100150; cv=none; d=zohomail.com; s=zohoarc; b=Oo0s48DaSk6kdf0FVExVLsdl8joWpGHuBCVy1ITHd8U+RwVItGGW4J/Rt1mcvlhhHcScK/HF+O8YbLrmoxbIFRYDAhc571VsTJOP+OW+K9Pk3vL5lbXicS4pTBYzu3TMCwBHGDuJqc3Dz5JjfcQxxtPK2/hdIatuG0FsX+MBdHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100150; h=Content-Type: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; bh=2JioenUdI+5OpAM119kCaxHuOngeUa/Dn7gYWfjNr8I=; b=SMzb3lWrYziwpCqGl3j91F2po4w81Wy3OUpqyW0IeWLXsDQyaajLHimrB/WhCBiov5RQWIdtLXEgF8YDSXtiRKHhtqN/xi0bnDQvtdgl66pBbn5HEjz/CbJEu92KHDGJo+ZAB1twbeEuetpeFuHSiAbWaKijxoSdyl0CWXGVNWg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100150058725.3698402614378; Thu, 25 Jun 2020 08:49:10 -0700 (PDT) Received: from localhost ([::1]:51046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU7g-0000ot-H3 for importer@patchew.org; Thu, 25 Jun 2020 11:49:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjJ-0006sq-Tk for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:46506 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjF-0001Rr-KX for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-y8TOBTMcNHOsiT4S7L5t7g-1; Thu, 25 Jun 2020 11:23:48 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 492951005513; Thu, 25 Jun 2020 15:23:47 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B03562B4A8; Thu, 25 Jun 2020 15:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2JioenUdI+5OpAM119kCaxHuOngeUa/Dn7gYWfjNr8I=; b=Nrrav72jjFjzVWLLdDdt9qyCL1ao8g9+phBKfSC9Wkw98YQuxzZGAONANOHH/LpvZl4Oyr plc4LTbhnR/IEFMmuW/f3pa5FJlHL0s6yAgsxxLioRaAtZEf0PgA7+dvgvfk6tJj4/tjrD fA1HMIH2StScBgVxtZFTm1wXdAu872Q= X-MC-Unique: y8TOBTMcNHOsiT4S7L5t7g-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 40/47] block: Inline bdrv_co_block_status_from_*() Date: Thu, 25 Jun 2020 17:22:08 +0200 Message-Id: <20200625152215.941773-41-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" With bdrv_filter_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: Andrey Shinkevich --- include/block/block_int.h | 23 ------------------ block/backup-top.c | 2 -- block/blkdebug.c | 7 ++++-- block/blklogwrites.c | 1 - block/commit.c | 1 - block/copy-on-read.c | 2 -- block/filter-compress.c | 2 -- block/io.c | 51 +++++++++++++-------------------------- block/mirror.c | 1 - block/throttle.c | 1 - 10 files changed, 22 insertions(+), 69 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 6e09e15ed4..e5a328c389 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1291,29 +1291,6 @@ void bdrv_default_perms(BlockDriverState *bs, BdrvCh= ild *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= ); - int64_t bdrv_sum_allocated_file_size(BlockDriverState *bs); int64_t bdrv_primary_allocated_file_size(BlockDriverState *bs); int64_t bdrv_notsup_allocated_file_size(BlockDriverState *bs); diff --git a/block/backup-top.c b/block/backup-top.c index 89bd3937d0..bf5fc22fc7 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -185,8 +185,6 @@ BlockDriver bdrv_backup_top_filter =3D { .bdrv_co_pwritev_compressed =3D backup_top_co_pwritev_compressed, .bdrv_co_flush =3D backup_top_co_flush, =20 - .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, - .bdrv_refresh_filename =3D backup_top_refresh_filename, =20 .bdrv_child_perm =3D backup_top_child_perm, diff --git a/block/blkdebug.c b/block/blkdebug.c index 7194bc7f06..cf78d8809e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -757,8 +757,11 @@ static int coroutine_fn blkdebug_co_block_status(Block= DriverState *bs, return err; } =20 - 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 6753bd9a3e..c6b2711fe5 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -517,7 +517,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 4122b6736d..ea9282daea 100644 --- a/block/commit.c +++ b/block/commit.c @@ -238,7 +238,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 a6a864f147..2816e61afe 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -146,8 +146,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, - .has_variable_length =3D true, .is_filter =3D true, }; diff --git a/block/filter-compress.c b/block/filter-compress.c index 8ec1991c1f..5136371bf8 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -146,8 +146,6 @@ static BlockDriver bdrv_compress =3D { .bdrv_eject =3D compress_eject, .bdrv_lock_medium =3D compress_lock_medium, =20 - .bdrv_co_block_status =3D bdrv_co_block_status_from_file, - .has_variable_length =3D true, .is_filter =3D true, }; diff --git a/block/io.c b/block/io.c index 9e802804bb..e2196d438c 100644 --- a/block/io.c +++ b/block/io.c @@ -2253,36 +2253,6 @@ typedef struct BdrvCoBlockStatusData { BlockDriverState **file; } 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 @@ -2323,6 +2293,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; @@ -2348,7 +2319,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 bdrv_filter_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) { @@ -2369,9 +2341,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_filter_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 770de3b34e..5a9e42e488 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1541,7 +1541,6 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_pdiscard =3D bdrv_mirror_top_pdiscard, .bdrv_co_pwritev_compressed =3D bdrv_mirror_top_pwritev_compressed, .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 f6e619aca2..473ea758df 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -263,7 +263,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100187; cv=none; d=zohomail.com; s=zohoarc; b=UWN6wI/juVzlqiQYN+w7JeAP5UaFYXxkCJsz6Xd/hyzsslKwqB5eHQfKf0gXb4uwYLXsYaDJaAWyT1s/TJ5Yee1KxDE7t7olU6mywHwyROVHDETcqpu8S9J6cvsIVtZXypZVRsZRoTivJIkbnIQOufr2jnJw9MHgnlDlK9wgn8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100187; h=Content-Type: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; bh=l0p1Y32ov7w5zxhMPPmCe1IkJ7BaMhdsxK94Oj7LLh4=; b=lZV4TZhtOn7eaO0Yy2KEdO35V0PedXGDqswfCyX5ngL+GD0s0+FuCXKKhG37I4TC0LNw0PRVZhoY8WgRM52y+TGePxchqnmaDSsPH7bTIPd4XLnhgTaZrc1F20/bWVwdMsVL/KpV0On/xthwrJ3zynOGqGkxyUYdvw8D0392ZxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100187192338.8403606577177; Thu, 25 Jun 2020 08:49:47 -0700 (PDT) Received: from localhost ([::1]:53930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU8H-00025p-Kj for importer@patchew.org; Thu, 25 Jun 2020 11:49:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjJ-0006sU-RH for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:57 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:51338 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjF-0001Sa-JZ for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-460-p_MAEfi_NjCra6Ayp2hSOA-1; Thu, 25 Jun 2020 11:23:50 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A842AA0BD9; Thu, 25 Jun 2020 15:23:49 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F15E10013D9; Thu, 25 Jun 2020 15:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l0p1Y32ov7w5zxhMPPmCe1IkJ7BaMhdsxK94Oj7LLh4=; b=Lm/bHpmInW5mq7fZB6w1xLMlv4MIfBU6HX//+JXawTkxCukGYLsGW1N/vILZc8bvLT/Ojh K10KcvSP7kJf46I8tKBBY341xLqTPdxbVFguO0jnu3kmGu718rzd5ttSi5QjSmVCDqx2ep 2RQdjKU7k8+dijcXschTdHhI7NH8ASA= X-MC-Unique: p_MAEfi_NjCra6Ayp2hSOA-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 41/47] block: Leave BDS.backing_file constant Date: Thu, 25 Jun 2020 17:22:09 +0200 Message-Id: <20200625152215.941773-42-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. In order not to change our externally visible behavior (incompatibly), we have to let bdrv_query_image_info() try to get the image format from bs->backing if bs->backing_format is unset. (The QAPI schema describes backing-filename-format as "the format of the backing file", so it is not necessarily what the image header says, but just the format of the file referenced by backing-filename (if known).) 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 Reviewed-by: Andrey Shinkevich --- include/block/block_int.h | 21 ++++++++++++++++----- block.c | 35 +++++++++++++++++++++++++++-------- block/qapi.c | 17 +++++++++++++---- tests/qemu-iotests/228 | 6 +++--- tests/qemu-iotests/228.out | 6 +++--- tests/qemu-iotests/245 | 4 +++- 6 files changed, 65 insertions(+), 24 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index e5a328c389..465a601955 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -835,11 +835,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 @@ -1041,6 +1050,8 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int b= uf_size, void bdrv_parse_filename_strip_prefix(const char *filename, const char *pr= efix, QDict *options); =20 +bool bdrv_backing_overridden(BlockDriverState *bs); + =20 /** * bdrv_add_before_write_notifier: diff --git a/block.c b/block.c index a19f243997..af8d85bcf2 100644 --- a/block.c +++ b/block.c @@ -1153,10 +1153,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 */ @@ -5693,6 +5689,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; BlockDriverState *bs_below; @@ -5718,9 +5715,31 @@ BlockDriverState *bdrv_find_backing_image(BlockDrive= rState *bs, { 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) { @@ -6821,7 +6840,7 @@ static bool append_strong_runtime_options(QDict *d, B= lockDriverState *bs) /* Note: This function may return false positives; it may return true * even if opening the backing file specified by bs's image header * would result in exactly bs->backing. */ -static bool bdrv_backing_overridden(BlockDriverState *bs) +bool bdrv_backing_overridden(BlockDriverState *bs) { if (bs->backing) { return strcmp(bs->auto_backing_file, diff --git a/block/qapi.c b/block/qapi.c index 2628323b63..5da6d7e6e0 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -47,7 +47,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, Error **errp) { ImageInfo **p_image_info; - BlockDriverState *bs0; + BlockDriverState *bs0, *backing; BlockDeviceInfo *info; =20 if (!bs->drv) { @@ -76,9 +76,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_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 if (!QLIST_EMPTY(&bs->dirty_bitmaps)) { @@ -314,6 +315,8 @@ void bdrv_query_image_info(BlockDriverState *bs, backing_filename =3D bs->backing_file; if (backing_filename[0] !=3D '\0') { char *backing_filename2; + const char *backing_format =3D NULL; + info->backing_filename =3D g_strdup(backing_filename); info->has_backing_filename =3D true; backing_filename2 =3D bdrv_get_full_backing_filename(bs, NULL); @@ -326,7 +329,13 @@ void bdrv_query_image_info(BlockDriverState *bs, } =20 if (bs->backing_format[0]) { - info->backing_filename_format =3D g_strdup(bs->backing_format); + backing_format =3D bs->backing_format; + } else if (bs->backing && bs->backing->bs->drv && + !bdrv_backing_overridden(bs)) { + backing_format =3D bs->backing->bs->drv->format_name; + } + if (backing_format) { + info->backing_filename_format =3D g_strdup(backing_format); info->has_backing_filename_format =3D true; } g_free(backing_filename2); diff --git a/tests/qemu-iotests/228 b/tests/qemu-iotests/228 index da0900fb82..90800ecc6a 100755 --- a/tests/qemu-iotests/228 +++ b/tests/qemu-iotests/228 @@ -36,7 +36,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']: @@ -72,8 +72,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 4f5f0bb901..5035763765 100755 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -724,7 +724,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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593101015; cv=none; d=zohomail.com; s=zohoarc; b=Mr/P4ab2apGs0dgkBIwoZCtzhys7OyDX+lZN9bbmDGgYg72UbYSgI0b3A1m/tCB2EhLwOolCDwYg3+B62pkSV8Xr0shojbsjKm9bHw/ENn00wnVRLoExhAFtKsQQceAPHc81VPRA0CjyHm9rywtzhR4WUFe9g/oPA/LW/pLkzac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593101015; h=Content-Type: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; bh=h/3P/pJh6MgN6QjYFEd5x6ZBKYhy9ocY18yRFiiMzpg=; b=OCLTkKdf20cue6OZrLqt6jpSD1jos3O1dHetxWF5eRSYrVZ8kvb2uWpIKt+tnx+cnKQAwpuE8tYgMJ3M3RctNyI7lreGklTQxCDm+OSeMh4o0u2V2NJA9OhGcsBhG7Lbb6GBttgkkKASNDudVMSn8Sv11vUIAx+FGg794rmYHYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593101015273988.3205784358237; Thu, 25 Jun 2020 09:03:35 -0700 (PDT) Received: from localhost ([::1]:51916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joULd-0000Bo-Tk for importer@patchew.org; Thu, 25 Jun 2020 12:03:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjL-0006wW-Jr for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:45805 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjJ-0001Wc-NX for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411--YiuQWcONr-fWckjp39ILg-1; Thu, 25 Jun 2020 11:23:52 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C65C618A8220; Thu, 25 Jun 2020 15:23:51 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 695801DC; Thu, 25 Jun 2020 15:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h/3P/pJh6MgN6QjYFEd5x6ZBKYhy9ocY18yRFiiMzpg=; b=DoElT5gJMNO7p9nc8cwZ4MaRfpmoYqW4+lGUIKpDg9v6Y7y4BJquOmrmwjWRQrXgjCzxTU CX9B6/wwUiStJsdl8D4BHyMtuQIL7QtLhvoR0SbzLs44VL7QSIkNb8DZkpo6424i5PmxhH +Qq+nkNSnTJ03mhuKiuPv5dOKsy7SDE= X-MC-Unique: -YiuQWcONr-fWckjp39ILg-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 42/47] iotests: Test that qcow2's data-file is flushed Date: Thu, 25 Jun 2020 17:22:10 +0200 Message-Id: <20200625152215.941773-43-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Flushing a qcow2 node must lead to the data-file node being flushed as well. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- tests/qemu-iotests/244 | 49 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/244.out | 7 ++++++ 2 files changed, 56 insertions(+) diff --git a/tests/qemu-iotests/244 b/tests/qemu-iotests/244 index efe3c0428b..f2b2dddf1c 100755 --- a/tests/qemu-iotests/244 +++ b/tests/qemu-iotests/244 @@ -217,6 +217,55 @@ $QEMU_IMG amend -f $IMGFMT -o "data_file=3Dblkdebug::$= TEST_IMG.data" "$TEST_IMG" $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n -C "$TEST_IMG.src" "$TEST_IMG" $QEMU_IMG compare -f $IMGFMT -F $IMGFMT "$TEST_IMG.src" "$TEST_IMG" =20 +echo +echo "=3D=3D=3D Flushing should flush the data file =3D=3D=3D" +echo + +# We are going to flush a qcow2 file with a blkdebug node inserted +# between the qcow2 node and its data file node. The blkdebug node +# will return an error for all flushes and so we if the data file is +# flushed, we will see qemu-io return an error. + +# We need to write something or the flush will not do anything; we +# also need -t writeback so the write is not done as a FUA write +# (which would then fail thanks to the implicit flush) +$QEMU_IO -c 'write 0 512' -c flush \ + -t writeback \ + "json:{ + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': '$TEST_IMG' + }, + 'data-file': { + 'driver': 'blkdebug', + 'inject-error': [{ + 'event': 'none', + 'iotype': 'flush' + }], + 'image': { + 'driver': 'file', + 'filename': '$TEST_IMG.data' + } + } + }" \ + | _filter_qemu_io + +result=3D${PIPESTATUS[0]} +echo + +case $result in + 0) + echo "ERROR: qemu-io succeeded, so the data file was not flushed" + ;; + 1) + echo "Success: qemu-io failed, so the data file was flushed" + ;; + *) + echo "ERROR: qemu-io returned unknown exit code $result" + ;; +esac + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/244.out b/tests/qemu-iotests/244.out index dbab7359a9..7269b4295a 100644 --- a/tests/qemu-iotests/244.out +++ b/tests/qemu-iotests/244.out @@ -131,4 +131,11 @@ Offset Length Mapped to File Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 data_file=3DT= EST_DIR/t.IMGFMT.data Images are identical. Images are identical. + +=3D=3D=3D Flushing should flush the data file =3D=3D=3D + +wrote 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +Success: qemu-io failed, so the data file was flushed *** done --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100898; cv=none; d=zohomail.com; s=zohoarc; b=j88np7tSW0t2pYymuIq36l0TD7RYyM23u8AjKXUjUC8GnVeIAmFw8U509eLennjpepbHyCnCvX2umVe8Zdl3x3BvE1MXq5mgqhVyVozbZipeL+OgDtFS48KuNtupH3sg4YEkDcspOO3CU4JCEC8O6GwnUTUOypTGZWLgu2oiaWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100898; h=Content-Type: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; bh=5tNmvsX0enHZpWlhX9xUzW41+hKt4XBVUHLN3u9eAeI=; b=iS4z0zcdDuVe7krBFtritqvA4bVIPmokYWsD3bENqtBbAC8wUzhRgpAykHRKbp2buZLY2nbit3Tneb6mDonN8TRD4JLX+wBGzA/Q4RJTnkq9Od0wrtX+koDj0gK39vl9RWP6vrG679eftChNAp+Onq2Nm2GHNq4xIMqqMBmOc0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100898587412.2165077547842; Thu, 25 Jun 2020 09:01:38 -0700 (PDT) Received: from localhost ([::1]:45006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joUJk-0005Yb-G5 for importer@patchew.org; Thu, 25 Jun 2020 12:01:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjL-0006vL-6A for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:59 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:39630 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjJ-0001WI-9C for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:23:58 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-Thtf0bSMNxugvEjrlyqX9w-1; Thu, 25 Jun 2020 11:23:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2BB0800C64; Thu, 25 Jun 2020 15:23:53 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82759D01E7; Thu, 25 Jun 2020 15:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5tNmvsX0enHZpWlhX9xUzW41+hKt4XBVUHLN3u9eAeI=; b=eCQ5YHtnFbCTPme8EUluOsOPiOrfxkCtwyMwwf3AcIOf4ZPQ+kDMa/n0tw61lrpxQZMCEQ WZJ5lrK5WBXBL5Sv0sEIMyfQQThiH0fO6Qy6glSHCD9cHfvNJ7wLYvNQJ93sK/vX2Y7SJo WuZHEICsolXUYDFcjRgJnM8w7ocunpE= X-MC-Unique: Thtf0bSMNxugvEjrlyqX9w-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 43/47] iotests: Let complete_and_wait() work with commit Date: Thu, 25 Jun 2020 17:22:11 +0200 Message-Id: <20200625152215.941773-44-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Andrey Shinkevich --- 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 5ea4c4df8b..57b32d8ad3 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -932,8 +932,12 @@ class QMPTestCase(unittest.TestCase): =20 def wait_ready(self, drive=3D'drive0'): """Wait until a BLOCK_JOB_READY event, and return the event.""" - f =3D {'data': {'type': 'mirror', 'device': drive}} - return self.vm.event_wait(name=3D'BLOCK_JOB_READY', match=3Df) + return 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) @@ -952,7 +956,7 @@ class QMPTestCase(unittest.TestCase): self.assert_qmp(result, 'return', {}) =20 event =3D self.wait_until_completed(drive=3Ddrive, error=3Dcomplet= ion_error) - 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(3, "Timeout waiting for job to pause"): --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100290; cv=none; d=zohomail.com; s=zohoarc; b=WfI236FjK8N94V0Su5McXYnNQMV8mBYSqq2nfo1pPLFIDcLQP8FtlR7MCVSdjAJmiU9JFGaP4nPAkylchB3zyEQSRXi4xnsKm9/zZIVE9yGgc5QEgF692NCEuuQpDTDyl/pwGuew5y14LRr3u4R6QBiE/6zLB2Gno5KdgY+veo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100290; h=Content-Type: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; bh=m8B92WjrExLEMrCAW5AW2cnw2+Wtezd3CD14wIf7oGo=; b=Aa/AxY1xRA/BreS+GQvAcexmcxPHDaogq4/caQGMtf23ekgS4sWVMtP4ufJpQcFg1GNiXGRGuF2bq0ZB8MDksVu9QlVqKc9kdPyECcvcG43ZGOVeXDHZoRZhIkQ9I25b7snai2eruhpb2+S6Xdv0UCZvocqxPGLeLaH0FEhZmIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100290609458.70794518000923; Thu, 25 Jun 2020 08:51:30 -0700 (PDT) Received: from localhost ([::1]:60102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU9x-00055m-7p for importer@patchew.org; Thu, 25 Jun 2020 11:51:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjO-00073r-Tg for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:06 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:20230 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjL-0001Yi-Ul for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-HksOnrBYPwG08QDxt1vEpQ-1; Thu, 25 Jun 2020 11:23:57 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CB7C8015FD; Thu, 25 Jun 2020 15:23:56 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C121917D9C; Thu, 25 Jun 2020 15:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8B92WjrExLEMrCAW5AW2cnw2+Wtezd3CD14wIf7oGo=; b=FeQTAgR2cl9Javnz5iLYkxz57H1NGTwp5IoohTpMuP3X4+IHXtxf74VZAq95m3TugmBG8R FdigDYoY6xHj1s/7W2eXrnmsmnNcIAjzhi5LiZury5vUfsxFDWFemBC0Z3PBfKkn82EziP fQsLBgGECUxJ0+01wumarRX+75JVgeE= X-MC-Unique: HksOnrBYPwG08QDxt1vEpQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 44/47] iotests: Add filter commit test cases Date: Thu, 25 Jun 2020 17:22:12 +0200 Message-Id: <20200625152215.941773-45-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch adds some tests on how commit copes with filter nodes. Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- 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 32c82b4ec6..e7fa244738 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -713,6 +713,183 @@ class TestErrorHandling(iotests.QMPTestCase): self.assertTrue(iotests.compare_images(mid_img, backing_img, fmt2= =3D'raw'), 'target image does not match source after commit') =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 do_test_io(self, read_or_write): + for index, pattern_file in enumerate(self.pattern_files): + result =3D qemu_io('-f', iotests.imgfmt, + '-c', '{} -P {} {}M 1M'.format(read_or_write, + index + 1, ind= ex), + pattern_file) + self.assertFalse('Pattern verification failed' in result) + + 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') + + # 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.do_test_io('write') + + self.vm =3D iotests.VM() + self.vm.launch() + + 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() + self.do_test_io('read') + + 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): + 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): + 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') + + 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')) + + # Check that drv0 is now connected to cow-2 + blockdevs =3D self.vm.qmp('query-block')['return'] + drv0 =3D next(dev for dev in blockdevs if '/drv0' in dev['qdev']) + self.assertEqual(drv0['inserted']['node-name'], 'cow-2') + + # 3 has been comitted into 2 + self.pattern_files[3] =3D self.img2 + + def test_filtered_active_commit_without_filter(self): + 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'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 6a917130b6..4823c113d5 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -........................................................... +............................................................... ---------------------------------------------------------------------- -Ran 59 tests +Ran 63 tests =20 OK --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100233; cv=none; d=zohomail.com; s=zohoarc; b=LfVaPoN6j4/eFNaS3s6iNjq7Ht7SdF71dsQf0c7l/tSRWnU6uIl7eWfOaBCAieE4YUQNO+Z3mg5RPkKa4azzXcElk2LwvMEmcOhJs5TlZQ3RbwgBu7Wm7YN7qqG/nLqwRi3EpCyPF+tIJ4+s7P3eK/Ds11G7g7+7Fo9Qqnhf6Sw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100233; h=Content-Type: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; bh=fZqU6OKIKVuM7S4OBfB9tkserSvEzSWHObc2msGEIOk=; b=W1AnYyU02IjiwKDd0bXmj433J27H+vfHljr5a+0cQZAZkpWJACCbWtpm85+8i65TOJHoYn0lnViyOc2yAe6LGrvMW13SM4sU1l4bVtEDpF6RUCfUBnw57u6pskNRpwrasQPfyw82HeY1bEL/lhJMIUmzzQHM5VATLL/M1B4C76A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100233515559.549312257269; Thu, 25 Jun 2020 08:50:33 -0700 (PDT) Received: from localhost ([::1]:55960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joU92-0002zR-6V for importer@patchew.org; Thu, 25 Jun 2020 11:50:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjV-0007AS-GX for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:09 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45016 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjT-0001dB-3C for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-7BuHWV-yPXW6j2DiMuUV5g-1; Thu, 25 Jun 2020 11:23:59 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F236464; Thu, 25 Jun 2020 15:23:58 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0E02B612BA; Thu, 25 Jun 2020 15:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fZqU6OKIKVuM7S4OBfB9tkserSvEzSWHObc2msGEIOk=; b=hLdef352H/o8uco1Y1xDjfN3+PhLQF1G/948fL+szGLJ1HtQTSKILiC08ubVUdnlWd4Fkc xw39irwNs1vurMH9Q5FdeOJPXcEYYORBlGEKXgxztEkWd6PLkiJmYmv2b1ScIduVOBnH3J 3DMevNEeam+c+r3tmUyfCYKvWwpHPP8= X-MC-Unique: 7BuHWV-yPXW6j2DiMuUV5g-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 45/47] iotests: Add filter mirror test cases Date: Thu, 25 Jun 2020 17:22:13 +0200 Message-Id: <20200625152215.941773-46-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 00:45:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Andrey Shinkevich --- 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 b843f88a66..588bb76626 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -21,8 +21,9 @@ import time import os import re +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') @@ -1275,6 +1276,149 @@ class TestReplaces(iotests.QMPTestCase): =20 self.vm.assert_block_path('filter0', '/file', 'target') =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'], supported_protocols=3D['file'], diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index 53abe11d73..46651953e8 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= .............................. +..........................................................................= ................................. ---------------------------------------------------------------------- -Ran 104 tests +Ran 107 tests =20 OK --=20 2.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100400; cv=none; d=zohomail.com; s=zohoarc; b=QOp4mBtO4PnVSXn7EHNQF3sFq9OBN6o10WpGIklEC35KwPP4LSMOnP28uzF+FqP1Dj8RDhG4L/coD8ba5dBNvKAuTq5dKI77uhpjXaRIRQTrHF8wmTlwp356UHT4ijCEXPewFZCvg8IZkErhV6PORLCXKfjOGOAno8+ibYswcLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100400; h=Content-Type: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; bh=gOsCU0ZB3WqmX998CoRcC04iyDuhkn2FLcrzX97G6yI=; b=VEWyMM9oyqmIoVSyIFGjxZ6L6IUp4YwatoGxbdlWVKPad9urUjv6iAyXAPC6SGgBjX1fGqaifpZmTtKiB6cVVJIWP67cSOI85sqPzZ2zQU1MGgUT6oWtYXIbg3/TPKMsN3eIjF/35gERNxxIJGKaJNIyEHzb4ZsDgMs2kJM55w0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100400843379.3204618138982; Thu, 25 Jun 2020 08:53:20 -0700 (PDT) Received: from localhost ([::1]:40350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joUBj-00005i-KN for importer@patchew.org; Thu, 25 Jun 2020 11:53:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjX-0007F0-Bk for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:11 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42211 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjT-0001dh-41 for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:11 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-181-LxlPylEuOlyp3Qgif0HbtQ-1; Thu, 25 Jun 2020 11:24:01 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B198F804002; Thu, 25 Jun 2020 15:24:00 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 543C21A913; Thu, 25 Jun 2020 15:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gOsCU0ZB3WqmX998CoRcC04iyDuhkn2FLcrzX97G6yI=; b=CUaRXi+5EVNpOiII+pmSw9bSzxtkxpRbJZUhSHDFuw0gdrYUR23u2xnLNGGm85qmenE24e CP0QUVannLS5KRxu/IU1hqpp8ZLLHHXxvpYuL74jAOv1LZm7EziYtELEsr7/oxTThZpxFp jhOMfbExTId+K0Z+2IbEAAYhj9dqh3E= X-MC-Unique: LxlPylEuOlyp3Qgif0HbtQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 46/47] iotests: Add test for commit in sub directory Date: Thu, 25 Jun 2020 17:22:14 +0200 Message-Id: <20200625152215.941773-47-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Andrey Shinkevich --- tests/qemu-iotests/020 | 44 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/020.out | 10 +++++++++ 2 files changed, 54 insertions(+) diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 index 20f8f185d0..d5b5d34058 100755 --- a/tests/qemu-iotests/020 +++ b/tests/qemu-iotests/020 @@ -31,6 +31,11 @@ _cleanup() _cleanup_test_img _rm_test_img "$TEST_IMG.base" _rm_test_img "$TEST_IMG.orig" + + _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.base" + _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.mid" + _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT" + rmdir "$TEST_DIR/subdir" &> /dev/null } trap "_cleanup; exit \$status" 0 1 2 3 15 =20 @@ -134,6 +139,45 @@ $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 +# (This will not work with external data files, though, because when +# using relative paths for those, qemu will always resolve them +# relative to its CWD. Therefore, it cannot find those data files now +# that we left $TEST_DIR.) +if _get_data_file '' > /dev/null; then + echo 'Image committed.' # Skip test +else + $QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" \ + "$TEST_DIR/subdir/t.$IMGFMT" +fi + # 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.26.2 From nobody Sun May 5 20:07:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1593100317; cv=none; d=zohomail.com; s=zohoarc; b=TudEWyngR8QNe88YexaJPA63n4l7zGWubDvKLfQ/GilNjNk3QKqi47OksbEMX6dFmhs0VZNITUm7dCnwOSXdGyMdY+TwTySudBIcJUdk033LuyhHAPl4Gv4aQz3NhHgz4TKe762H92icfRwasuDdsfUJ2AE75UWAIXvVOk7vevQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593100317; h=Content-Type: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; bh=px690KZXEVCO252pekmpFFy39zpeKmqhd0SmMuE62dc=; b=cjpxbSNVZwiRKr8awzXupCzQ1UvshQqA0goeFHaLzs8I049lHFcpmK4IajsE4lJJ4aRcNGjV/vxzuO5AsOlk+ECQG87JGIhSKq7gclf/My67xK0UXLOnupDxGBsr+m25CiHNyzURHlKBNYEl5T1pro4uhqkWoMGC6rbQrCdbGhA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1593100317844713.251775615069; Thu, 25 Jun 2020 08:51:57 -0700 (PDT) Received: from localhost ([::1]:34072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joUAO-000602-GB for importer@patchew.org; Thu, 25 Jun 2020 11:51:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joTjW-0007Cq-Gd for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:10 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40738 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1joTjU-0001fp-2A for qemu-devel@nongnu.org; Thu, 25 Jun 2020 11:24:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-mcU7tWIsNjObie9vJ_9h8g-1; Thu, 25 Jun 2020 11:24:04 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED29B804002; Thu, 25 Jun 2020 15:24:02 +0000 (UTC) Received: from localhost (ovpn-113-182.ams2.redhat.com [10.36.113.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E9FE79334; Thu, 25 Jun 2020 15:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593098647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=px690KZXEVCO252pekmpFFy39zpeKmqhd0SmMuE62dc=; b=JUEW0OCMXoRqSRj4n/pBbpkFgJ0ZkuqTZ+17i4EKuU4FOEsWQv5ix5GY17kILfK662xWhT AyrBa06tVKQqpvRZHVUr2NDWmH4S514l0sOWw8/9HOqlg0iZiQzuSCjm5FiU268uCMY8go lGtndGsEB6gVojyQTY7hF+2yfaMhppk= X-MC-Unique: mcU7tWIsNjObie9vJ_9h8g-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v7 47/47] iotests: Test committing to overridden backing Date: Thu, 25 Jun 2020 17:22:15 +0200 Message-Id: <20200625152215.941773-48-mreitz@redhat.com> In-Reply-To: <20200625152215.941773-1-mreitz@redhat.com> References: <20200625152215.941773-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 01:47:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Andrey Shinkevich --- 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 e7fa244738..dfd46ddcbe 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -890,6 +890,67 @@ 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'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 4823c113d5..1bb1dc5f0e 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -............................................................... +................................................................. ---------------------------------------------------------------------- -Ran 63 tests +Ran 65 tests =20 OK --=20 2.26.2