From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554927785; cv=none; d=zoho.com; s=zohoarc; b=Ctuo56RXNoIutEz5u2fmhgJTmmAOsvXhXKs5VVGM6MVxTfpm4I0hhNAWY5u38KxgTTA4WRWf6mL74KDEpCldAZS0IOEBxvsDwjKwRjOoUax9/0wpA+TQHEMqmuSvtSC7Un7M6YCI8RdDkV4A1WA4hwCiNBmaPMhV6FWVAHHVRCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554927785; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=MKHiQfVPDzEKmINviOAIdTwMdPI+KpVGwpC+l2OcLxs=; b=YNSVu0mmcp7Ewpbc0xCYMekgESa1+GKriA5UL5hdR15nX3r4tah0cUUF3//WknOUF+n6jGoETykwv+WSR0kLwuBhvivC08m2kP6i8gEQsAgy/K++pu9ZYlkMx2PU1w/VH165GzeaSSscR5D15IDqSBuDfiejy6P7wp8HoUD7BmE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554927785698354.3934000719638; Wed, 10 Apr 2019 13:23:05 -0700 (PDT) Received: from localhost ([127.0.0.1]:37318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJkF-00083w-Dd for importer@patchew.org; Wed, 10 Apr 2019 16:22:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiN-0006uM-VE for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiM-0004Lo-Nb for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:20:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJi6-0004E9-F5; Wed, 10 Apr 2019 16:20:44 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47FD387638; Wed, 10 Apr 2019 20:20:38 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D03E819C65; Wed, 10 Apr 2019 20:20:37 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:23 +0200 Message-Id: <20190410202033.28617-2-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 10 Apr 2019 20:20:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 01/11] block: Mark commit and mirror as filter drivers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The commit and mirror block nodes are filters, so they should be marked as such. (Strictly speaking, BDS.is_filter's documentation states that a filter's child must be bs->file. The following patch will relax this restriction, however.) Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- block/commit.c | 2 ++ block/mirror.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/block/commit.c b/block/commit.c index ba60fef58a..02eab34925 100644 --- a/block/commit.c +++ b/block/commit.c @@ -257,6 +257,8 @@ static BlockDriver bdrv_commit_top =3D { .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_commit_top_refresh_filename, .bdrv_child_perm =3D bdrv_commit_top_child_perm, + + .is_filter =3D true, }; =20 void commit_start(const char *job_id, BlockDriverState *bs, diff --git a/block/mirror.c b/block/mirror.c index ff15cfb197..8b2404051f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1489,6 +1489,8 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_mirror_top_refresh_filename, .bdrv_child_perm =3D bdrv_mirror_top_child_perm, + + .is_filter =3D true, }; =20 static void mirror_start_job(const char *job_id, BlockDriverState *bs, --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554928128; cv=none; d=zoho.com; s=zohoarc; b=HZRB1/XSR03EQPHBWT8gv9CyKemZcgoEyCUwxAN34+xKNXvDfNMOmrSSUvMcNyRX+hVUDu5kxXj/PFLEShYcfppHRrIZ3SoKq6rB2XwrxRZuFkrjrblUlfO/Hg5xnaarWjs2U2dTfzqGLe6LLTtONefNX3bLPCqiLu6uI0VW27M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554928128; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=pIXPByopoBBR2mgOXHaSfqUPHSxkRseWrTvSiNNifVg=; b=cxr+9GEBlCqYmTIHXkb7j4SQrhN0CtUc/tKul0kyvfc46mcnlHtajRoVc2wviOrnU7C7Q5XgpUixPwAOAcgHyjX0bDNcmO58OLRnyt+cw1UngkvO7XowYc7qGzV0U5Xl012h6MBDlzQ2Tv/w4+OVqt03UUO7WOvCtohw+wMWR4o= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155492812890160.00474460476573; Wed, 10 Apr 2019 13:28:48 -0700 (PDT) Received: from localhost ([127.0.0.1]:37431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJpp-0005e1-I4 for importer@patchew.org; Wed, 10 Apr 2019 16:28:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJib-00078i-Mp for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiW-0004Uq-N4 for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53592) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJi8-0004FI-Ca; Wed, 10 Apr 2019 16:20: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 mx1.redhat.com (Postfix) with ESMTPS id 5DCAE30B9318; Wed, 10 Apr 2019 20:20:43 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 465B419C65; Wed, 10 Apr 2019 20:20:40 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:24 +0200 Message-Id: <20190410202033.28617-3-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 10 Apr 2019 20:20:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 02/11] block: Filtered children access functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" What bs->file and bs->backing mean depends on the node. For filter nodes, both signify a node that will eventually receive all R/W accesses. For format nodes, bs->file contains metadata and data, and bs->backing will not receive writes -- instead, writes are COWed to bs->file. Usually. In any case, it is not trivial to guess what a child means exactly with our currently limited form of expression. It is better to introduce some functions that actually guarantee a meaning: - bdrv_filtered_cow_child() will return the child that receives requests filtered through COW. That is, reads may or may not be forwarded (depending on the overlay's allocation status), but writes never go to this child. - bdrv_filtered_rw_child() will return the child that receives requests filtered through some very plain process. Reads and writes issued to the parent will go to the child as well (although timing, etc. may be modified). - All drivers but quorum (but quorum is pretty opaque to the general block layer anyway) always only have one of these children: All read requests must be served from the filtered_rw_child (if it exists), so if there was a filtered_cow_child in addition, it would not receive any requests at all. (The closest here is mirror, where all requests are passed on to the source, but with write-blocking, write requests are "COWed" to the target. But that just means that the target is a special child that cannot be introspected by the generic block layer functions, and that source is a filtered_rw_child.) Therefore, we can also add bdrv_filtered_child() which returns that one child (or NULL, if there is no filtered child). Also, many places in the current block layer should be skipping filters (all filters or just the ones added implicitly, it depends) when going through a block node chain. They do not do that currently, but this patch makes them. One example for this is qemu-img map, which should skip filters and only look at the COW elements in the graph. The change to iotest 204's reference output shows how using blkdebug on top of a COW node used to make qemu-img map disregard the rest of the backing chain, but with this patch, the allocation in the base image is reported correctly. Furthermore, a note should be made that sometimes we do want to access bs->backing directly. This is whenever the operation in question is not about accessing the COW child, but the "backing" child, be it COW or not. This is the case in functions such as bdrv_open_backing_file() or whenever we have to deal with the special behavior of @backing as a blockdev option, which is that it does not default to null like all other child references do. Finally, the query functions (query-block and query-named-block-nodes) are modified to 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 of iotest 184, as the throttled node now appears as a backing child. Signed-off-by: Max Reitz --- qapi/block-core.json | 4 + include/block/block.h | 1 + include/block/block_int.h | 40 +++++-- block.c | 210 +++++++++++++++++++++++++++------ block/backup.c | 8 +- block/block-backend.c | 16 ++- block/commit.c | 33 +++--- block/io.c | 45 ++++--- block/mirror.c | 21 ++-- block/qapi.c | 30 +++-- block/stream.c | 13 +- blockdev.c | 88 +++++++++++--- migration/block-dirty-bitmap.c | 4 +- nbd/server.c | 6 +- qemu-img.c | 29 ++--- tests/qemu-iotests/184.out | 7 +- tests/qemu-iotests/204.out | 1 + 17 files changed, 411 insertions(+), 145 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 7ccbfff9d0..dbd9286e4a 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2502,6 +2502,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/include/block/block.h b/include/block/block.h index c7a26199aa..2005664f14 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -467,6 +467,7 @@ BlockDriverState *bdrv_lookup_bs(const char *device, const char *node_name, Error **errp); bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base); +bool bdrv_legacy_chain_contains(BlockDriverState *top, BlockDriverState *b= ase); BlockDriverState *bdrv_next_node(BlockDriverState *bs); BlockDriverState *bdrv_next_all_states(BlockDriverState *bs); =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index 01e855a066..b22b1164f8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -90,9 +90,11 @@ struct BlockDriver { int instance_size; =20 /* set to true if the BlockDriver is a block filter. Block filters pass - * certain callbacks that refer to data (see block.c) to their bs->fil= e if - * the driver doesn't implement them. Drivers that do not wish to forw= ard - * must implement them and return -ENOTSUP. + * certain callbacks that refer to data (see block.c) to their bs->file + * or bs->backing (whichever one exists) if the driver doesn't impleme= nt + * them. Drivers that do not wish to forward must implement them and r= eturn + * -ENOTSUP. + * Note that filters are not allowed to modify data. */ bool is_filter; /* for snapshots block filter like Quorum can implement the @@ -906,11 +908,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() */ @@ -1243,4 +1240,31 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *sr= c, uint64_t src_offset, =20 int refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 +BdrvChild *bdrv_filtered_cow_child(BlockDriverState *bs); +BdrvChild *bdrv_filtered_rw_child(BlockDriverState *bs); +BdrvChild *bdrv_filtered_child(BlockDriverState *bs); +BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs); +BlockDriverState *bdrv_skip_rw_filters(BlockDriverState *bs); +BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs); + +static inline BlockDriverState *child_bs(BdrvChild *child) +{ + return child ? child->bs : NULL; +} + +static inline BlockDriverState *bdrv_filtered_cow_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filtered_cow_child(bs)); +} + +static inline BlockDriverState *bdrv_filtered_rw_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filtered_rw_child(bs)); +} + +static inline BlockDriverState *bdrv_filtered_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_filtered_child(bs)); +} + #endif /* BLOCK_INT_H */ diff --git a/block.c b/block.c index 16615bc876..e8f6febda0 100644 --- a/block.c +++ b/block.c @@ -556,11 +556,12 @@ int bdrv_create_file(const char *filename, QemuOpts *= opts, Error **errp) int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) { BlockDriver *drv =3D bs->drv; + BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); =20 if (drv && drv->bdrv_probe_blocksizes) { return drv->bdrv_probe_blocksizes(bs, bsz); - } else if (drv && drv->is_filter && bs->file) { - return bdrv_probe_blocksizes(bs->file->bs, bsz); + } else if (filtered) { + return bdrv_probe_blocksizes(filtered, bsz); } =20 return -ENOTSUP; @@ -575,11 +576,12 @@ int bdrv_probe_blocksizes(BlockDriverState *bs, Block= Sizes *bsz) int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo) { BlockDriver *drv =3D bs->drv; + BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); =20 if (drv && drv->bdrv_probe_geometry) { return drv->bdrv_probe_geometry(bs, geo); - } else if (drv && drv->is_filter && bs->file) { - return bdrv_probe_geometry(bs->file->bs, geo); + } else if (filtered) { + return bdrv_probe_geometry(filtered, geo); } =20 return -ENOTSUP; @@ -2336,7 +2338,7 @@ static bool bdrv_inherits_from_recursive(BlockDriverS= tate *child, } =20 /* - * Sets the backing file link of a BDS. A new reference is created; callers + * Sets the bs->backing link of a BDS. A new reference is created; callers * which don't need their own reference any more must call bdrv_unref(). */ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_h= d, @@ -2345,7 +2347,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 @@ -3467,14 +3469,17 @@ static int bdrv_reopen_parse_backing(BDRVReopenStat= e *reopen_state, /* * 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 (overlay_bs->backing && bdrv_filtered_bs(overlay_bs)->implicit) { + overlay_bs =3D bdrv_filtered_bs(overlay_bs); } =20 /* If we want to replace the backing file we need some extra checks */ - if (new_backing_bs !=3D backing_bs(overlay_bs)) { + if (new_backing_bs !=3D child_bs(overlay_bs->backing)) { /* 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 " @@ -3482,8 +3487,8 @@ static int bdrv_reopen_parse_backing(BDRVReopenState = *reopen_state, return -EPERM; } /* Check if the backing link that we want to replace is frozen */ - if (bdrv_is_backing_chain_frozen(overlay_bs, backing_bs(overlay_bs= ), - errp)) { + if (bdrv_is_backing_chain_frozen(overlay_bs, + child_bs(overlay_bs->backing), er= rp)) { return -EPERM; } reopen_state->replace_backing_bs =3D true; @@ -3634,7 +3639,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; @@ -3779,7 +3784,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) { @@ -4203,8 +4208,8 @@ 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); + while (active && bs !=3D bdrv_filtered_bs(active)) { + active =3D bdrv_filtered_bs(active); } =20 return active; @@ -4226,11 +4231,11 @@ bool bdrv_is_backing_chain_frozen(BlockDriverState = *bs, BlockDriverState *base, { BlockDriverState *i; =20 - for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { + for (i =3D bs; i !=3D base; i =3D child_bs(i->backing)) { if (i->backing && i->backing->frozen) { error_setg(errp, "Cannot change '%s' link from '%s' to '%s'", i->backing->name, i->node_name, - backing_bs(i)->node_name); + i->backing->bs->node_name); return true; } } @@ -4254,7 +4259,7 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs, B= lockDriverState *base, return -EPERM; } =20 - for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { + for (i =3D bs; i !=3D base; i =3D child_bs(i->backing)) { if (i->backing) { i->backing->frozen =3D true; } @@ -4272,7 +4277,7 @@ void bdrv_unfreeze_backing_chain(BlockDriverState *bs= , BlockDriverState *base) { BlockDriverState *i; =20 - for (i =3D bs; i !=3D base; i =3D backing_bs(i)) { + for (i =3D bs; i !=3D base; i =3D child_bs(i->backing)) { if (i->backing) { assert(i->backing->frozen); i->backing->frozen =3D false; @@ -4342,9 +4347,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= */ @@ -4494,10 +4497,14 @@ bool bdrv_is_sg(BlockDriverState *bs) =20 bool bdrv_is_encrypted(BlockDriverState *bs) { - if (bs->backing && bs->backing->bs->encrypted) { + BlockDriverState *filtered =3D bdrv_filtered_bs(bs); + if (bs->encrypted) { + return true; + } + if (filtered && bdrv_is_encrypted(filtered)) { return true; } - return bs->encrypted; + return false; } =20 const char *bdrv_get_format_name(BlockDriverState *bs) @@ -4794,7 +4801,21 @@ BlockDriverState *bdrv_lookup_bs(const char *device, bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base) { while (top && top !=3D base) { - top =3D backing_bs(top); + top =3D bdrv_filtered_bs(top); + } + + return top !=3D NULL; +} + +/* + * Same as bdrv_chain_contains(), but skip implicitly added R/W filter + * nodes and do not move past explicitly added R/W filters. + */ +bool bdrv_legacy_chain_contains(BlockDriverState *top, BlockDriverState *b= ase) +{ + top =3D bdrv_skip_implicit_filters(top); + while (top && top !=3D base) { + top =3D bdrv_skip_implicit_filters(bdrv_filtered_cow_bs(top)); } =20 return top !=3D NULL; @@ -4866,20 +4887,24 @@ int bdrv_has_zero_init_1(BlockDriverState *bs) =20 int bdrv_has_zero_init(BlockDriverState *bs) { + BlockDriverState *filtered; + if (!bs->drv) { return 0; } =20 /* If BS is a copy on write image, it is initialized to the contents of the base image, which may not be zeroes. */ - if (bs->backing) { + if (bdrv_filtered_cow_child(bs)) { return 0; } if (bs->drv->bdrv_has_zero_init) { return bs->drv->bdrv_has_zero_init(bs); } - if (bs->file && bs->drv->is_filter) { - return bdrv_has_zero_init(bs->file->bs); + + filtered =3D bdrv_filtered_rw_bs(bs); + if (filtered) { + return bdrv_has_zero_init(filtered); } =20 /* safe default */ @@ -4890,7 +4915,7 @@ bool bdrv_unallocated_blocks_are_zero(BlockDriverStat= e *bs) { BlockDriverInfo bdi; =20 - if (bs->backing) { + if (bdrv_filtered_cow_child(bs)) { return false; } =20 @@ -4924,8 +4949,9 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverIn= fo *bdi) return -ENOMEDIUM; } if (!drv->bdrv_get_info) { - if (bs->file && drv->is_filter) { - return bdrv_get_info(bs->file->bs, bdi); + BlockDriverState *filtered =3D bdrv_filtered_rw_bs(bs); + if (filtered) { + return bdrv_get_info(filtered, bdi); } return -ENOTSUP; } @@ -5028,7 +5054,17 @@ BlockDriverState *bdrv_find_backing_image(BlockDrive= rState *bs, =20 is_protocol =3D path_has_protocol(backing_file); =20 - for (curr_bs =3D bs; curr_bs->backing; curr_bs =3D curr_bs->backing->b= s) { + /* + * Being largely a legacy function, skip any filters here + * (because filters do not have normal filenames, so they cannot + * match anyway; and allowing json:{} filenames is a bit out of + * scope). + */ + for (curr_bs =3D bdrv_skip_rw_filters(bs); + bdrv_filtered_cow_child(curr_bs) !=3D NULL; + curr_bs =3D bdrv_backing_chain_next(curr_bs)) + { + BlockDriverState *bs_below =3D bdrv_backing_chain_next(curr_bs); =20 /* If either of the filename paths is actually a protocol, then * compare unmodified paths; otherwise make paths relative */ @@ -5036,7 +5072,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 = */ @@ -5046,7 +5082,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; } } @@ -5072,7 +5108,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; } } @@ -6237,3 +6273,107 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverSta= te *bs, const char *name, =20 return drv->bdrv_can_store_new_dirty_bitmap(bs, name, granularity, err= p); } + +/* + * Return the child that @bs acts as an overlay for, and from which data m= ay be + * copied in COW or COR operations. Usually this is the backing file. + */ +BdrvChild *bdrv_filtered_cow_child(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return NULL; + } + + if (bs->drv->is_filter) { + return NULL; + } + + return bs->backing; +} + +/* + * If @bs acts as a pass-through filter for one of its children, + * return that child. "Pass-through" means that write operations to + * @bs are forwarded to that child instead of triggering COW. + */ +BdrvChild *bdrv_filtered_rw_child(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return NULL; + } + + if (!bs->drv->is_filter) { + return NULL; + } + + return bs->backing ?: bs->file; +} + +/* + * Return any filtered child, independently of how it reacts to write + * accesses and whether data is copied onto this BDS through COR. + */ +BdrvChild *bdrv_filtered_child(BlockDriverState *bs) +{ + BdrvChild *cow_child =3D bdrv_filtered_cow_child(bs); + BdrvChild *rw_child =3D bdrv_filtered_rw_child(bs); + + /* There can only be one filtered child at a time */ + assert(!(cow_child && rw_child)); + + return cow_child ?: rw_child; +} + +static BlockDriverState *bdrv_skip_filters(BlockDriverState *bs, + bool stop_on_explicit_filter) +{ + BdrvChild *filtered; + + if (!bs) { + return NULL; + } + + while (!(stop_on_explicit_filter && !bs->implicit)) { + filtered =3D bdrv_filtered_rw_child(bs); + if (!filtered) { + break; + } + bs =3D filtered->bs; + } + /* + * Note that this treats nodes with bs->drv =3D=3D NULL as not being + * R/W filters (bs->drv =3D=3D NULL should be replaced by something + * else anyway). + * The advantage of this behavior is that this function will thus + * always return a non-NULL value (given a non-NULL @bs). + */ + + return bs; +} + +/* + * Return the first BDS that has not been added implicitly or that + * does not have an RW-filtered child down the chain starting from @bs + * (including @bs itself). + */ +BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs) +{ + return bdrv_skip_filters(bs, true); +} + +/* + * Return the first BDS that does not have an RW-filtered child down + * the chain starting from @bs (including @bs itself). + */ +BlockDriverState *bdrv_skip_rw_filters(BlockDriverState *bs) +{ + return bdrv_skip_filters(bs, false); +} + +/* + * For a backing chain, return the first non-filter backing image. + */ +BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs) +{ + return bdrv_skip_rw_filters(bdrv_filtered_cow_bs(bdrv_skip_rw_filters(= bs))); +} diff --git a/block/backup.c b/block/backup.c index 9988753249..9c08353b23 100644 --- a/block/backup.c +++ b/block/backup.c @@ -577,6 +577,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, int64_t len; BlockDriverInfo bdi; BackupBlockJob *job =3D NULL; + bool target_does_cow; int ret; =20 assert(bs); @@ -671,8 +672,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, /* If there is no backing file on the target, we cannot rely on COW if= our * backup cluster size is smaller than the target cluster size. Even f= or * targets with a backing file, try to avoid COW if possible. */ + target_does_cow =3D bdrv_filtered_cow_child(target); 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 " @@ -681,14 +683,14 @@ BlockJob *backup_job_create(const char *job_id, Block= DriverState *bs, "this default, the backup may be unusable", BACKUP_CLUSTER_SIZE_DEFAULT); job->cluster_size =3D 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"); goto error; - } else if (ret < 0 && target->backing) { + } else if (ret < 0 && target_does_cow) { /* Not fatal; just trudge on ahead. */ job->cluster_size =3D BACKUP_CLUSTER_SIZE_DEFAULT; } else { diff --git a/block/block-backend.c b/block/block-backend.c index f78e82a707..aa9a1d84a6 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2089,11 +2089,17 @@ int blk_commit_all(void) AioContext *aio_context =3D blk_get_aio_context(blk); =20 aio_context_acquire(aio_context); - if (blk_is_inserted(blk) && blk->root->bs->backing) { - int ret =3D bdrv_commit(blk->root->bs); - if (ret < 0) { - aio_context_release(aio_context); - return ret; + if (blk_is_inserted(blk)) { + BlockDriverState *non_filter; + + /* Legacy function, so skip implicit filters */ + non_filter =3D bdrv_skip_implicit_filters(blk->root->bs); + if (bdrv_filtered_cow_child(non_filter)) { + int ret =3D bdrv_commit(non_filter); + if (ret < 0) { + aio_context_release(aio_context); + return ret; + } } } aio_context_release(aio_context); diff --git a/block/commit.c b/block/commit.c index 02eab34925..252007fd57 100644 --- a/block/commit.c +++ b/block/commit.c @@ -113,7 +113,7 @@ static void commit_abort(Job *job) * something to base, the intermediate images aren't valid any more. */ bdrv_child_try_set_perm(s->commit_top_bs->backing, 0, BLK_PERM_ALL, &error_abort); - bdrv_replace_node(s->commit_top_bs, backing_bs(s->commit_top_bs), + bdrv_replace_node(s->commit_top_bs, s->commit_top_bs->backing->bs, &error_abort); =20 bdrv_unref(s->commit_top_bs); @@ -324,10 +324,16 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, s->commit_top_bs =3D commit_top_bs; bdrv_unref(commit_top_bs); =20 - /* Block all nodes between top and base, because they will - * disappear from the chain after this operation. */ + /* + * Block all nodes between top and base, because they will + * disappear from the chain after this operation. + * Note that this assumes that the user is fine with removing all + * nodes (including R/W filters) between top and base. Assuring + * this is the responsibility of the interface (i.e. whoever calls + * commit_start()). + */ assert(bdrv_chain_contains(top, base)); - for (iter =3D top; iter !=3D base; iter =3D backing_bs(iter)) { + for (iter =3D top; iter !=3D base; iter =3D bdrv_filtered_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 @@ -414,19 +420,22 @@ int bdrv_commit(BlockDriverState *bs) if (!drv) return -ENOMEDIUM; =20 - if (!bs->backing) { + backing_file_bs =3D bdrv_filtered_cow_bs(bs); + + if (!backing_file_bs) { return -ENOTSUP; } =20 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT_SOURCE, NULL) || - bdrv_op_is_blocked(bs->backing->bs, BLOCK_OP_TYPE_COMMIT_TARGET, N= ULL)) { + bdrv_op_is_blocked(backing_file_bs, BLOCK_OP_TYPE_COMMIT_TARGET, N= ULL)) + { return -EBUSY; } =20 - ro =3D bs->backing->bs->read_only; + ro =3D backing_file_bs->read_only; =20 if (ro) { - if (bdrv_reopen_set_read_only(bs->backing->bs, false, NULL)) { + if (bdrv_reopen_set_read_only(backing_file_bs, false, NULL)) { return -EACCES; } } @@ -441,8 +450,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) { @@ -528,15 +535,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/io.c b/block/io.c index dfc153b8d8..83c2b6b46a 100644 --- a/block/io.c +++ b/block/io.c @@ -118,8 +118,17 @@ static void bdrv_merge_limits(BlockLimits *dst, const = BlockLimits *src) void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs; + BlockDriverState *cow_bs =3D bdrv_filtered_cow_bs(bs); Error *local_err =3D NULL; =20 + /* + * FIXME: There should be a function for this, and in fact there + * will be as of a follow-up patch. + */ + storage_bs =3D + child_bs(bs->file) ?: bdrv_filtered_rw_bs(bs); + memset(&bs->bl, 0, sizeof(bs->bl)); =20 if (!drv) { @@ -131,13 +140,13 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error = **errp) drv->bdrv_aio_preadv) ? 1 : 512; =20 /* Take some limits from the children as a default */ - if (bs->file) { - bdrv_refresh_limits(bs->file->bs, &local_err); + if (storage_bs) { + bdrv_refresh_limits(storage_bs, &local_err); if (local_err) { error_propagate(errp, local_err); return; } - bdrv_merge_limits(&bs->bl, &bs->file->bs->bl); + bdrv_merge_limits(&bs->bl, &storage_bs->bl); } else { bs->bl.min_mem_alignment =3D 512; bs->bl.opt_mem_alignment =3D getpagesize(); @@ -146,13 +155,13 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error = **errp) bs->bl.max_iov =3D IOV_MAX; } =20 - if (bs->backing) { - bdrv_refresh_limits(bs->backing->bs, &local_err); + if (cow_bs) { + bdrv_refresh_limits(cow_bs, &local_err); if (local_err) { error_propagate(errp, local_err); return; } - bdrv_merge_limits(&bs->bl, &bs->backing->bs->bl); + bdrv_merge_limits(&bs->bl, &cow_bs->bl); } =20 /* Then let the driver override it */ @@ -2139,11 +2148,12 @@ static int coroutine_fn bdrv_co_block_status(BlockD= riverState *bs, if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) { ret |=3D BDRV_BLOCK_ALLOCATED; } else if (want_zero) { + BlockDriverState *cow_bs =3D bdrv_filtered_cow_bs(bs); + if (bdrv_unallocated_blocks_are_zero(bs)) { ret |=3D BDRV_BLOCK_ZERO; - } else if (bs->backing) { - BlockDriverState *bs2 =3D bs->backing->bs; - int64_t size2 =3D bdrv_getlength(bs2); + } else if (cow_bs) { + int64_t size2 =3D bdrv_getlength(cow_bs); =20 if (size2 >=3D 0 && offset >=3D size2) { ret |=3D BDRV_BLOCK_ZERO; @@ -2208,7 +2218,7 @@ static int coroutine_fn bdrv_co_block_status_above(Bl= ockDriverState *bs, bool first =3D true; =20 assert(bs !=3D base); - for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { + for (p =3D bs; p !=3D base; p =3D bdrv_filtered_bs(p)) { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); if (ret < 0) { @@ -2294,7 +2304,7 @@ int bdrv_block_status_above(BlockDriverState *bs, Blo= ckDriverState *base, int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) { - return bdrv_block_status_above(bs, backing_bs(bs), + return bdrv_block_status_above(bs, bdrv_filtered_bs(bs), offset, bytes, pnum, map, file); } =20 @@ -2304,9 +2314,9 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t offset, int ret; int64_t dummy; =20 - ret =3D bdrv_common_block_status_above(bs, backing_bs(bs), false, offs= et, - bytes, pnum ? pnum : &dummy, NULL, - NULL); + ret =3D bdrv_common_block_status_above(bs, bdrv_filtered_bs(bs), false, + offset, bytes, pnum ? pnum : &dum= my, + NULL, NULL); if (ret < 0) { return ret; } @@ -2360,7 +2370,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, n =3D pnum_inter; } =20 - intermediate =3D backing_bs(intermediate); + intermediate =3D bdrv_filtered_bs(intermediate); } =20 *pnum =3D n; @@ -3135,8 +3145,9 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, } =20 if (!drv->bdrv_co_truncate) { - if (bs->file && drv->is_filter) { - ret =3D bdrv_co_truncate(bs->file, offset, prealloc, errp); + BdrvChild *filtered =3D bdrv_filtered_rw_child(bs); + if (filtered) { + ret =3D bdrv_co_truncate(filtered, offset, prealloc, errp); goto out; } error_setg(errp, "Image format driver does not support resize"); diff --git a/block/mirror.c b/block/mirror.c index 8b2404051f..80cef587f0 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -660,8 +660,9 @@ 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); + if (bdrv_backing_chain_next(target_bs) !=3D backing) { + bdrv_set_backing_hd(bdrv_skip_rw_filters(target_bs), backing, + &local_err); if (local_err) { error_report_err(local_err); ret =3D -EPERM; @@ -711,7 +712,7 @@ static int mirror_exit_common(Job *job) block_job_remove_all_bdrv(bjob); bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL, &error_abort); - bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abo= rt); + bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_ab= ort); =20 /* We just changed the BDS the job BB refers to (with either or both o= f the * bdrv_replace_node() calls), so switch the BB back so the cleanup do= es @@ -903,7 +904,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_filtered_cow_child(target_bs) && s->granularity < s->target_cluster_size) { s->buf_size =3D MAX(s->buf_size, s->target_cluster_size); s->cow_bitmap =3D bitmap_new(length); @@ -1083,7 +1084,7 @@ static void mirror_complete(Job *job, Error **errp) if (s->backing_mode =3D=3D MIRROR_OPEN_BACKING_CHAIN) { int ret; =20 - assert(!target->backing); + assert(!bdrv_filtered_cow_child(target)); ret =3D bdrv_open_backing_file(target, NULL, "backing", errp); if (ret < 0) { return; @@ -1650,7 +1651,9 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, * 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)) { + for (iter =3D bdrv_filtered_bs(bs); iter !=3D target; + iter =3D bdrv_filtered_bs(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 @@ -1691,7 +1694,7 @@ fail: =20 bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL, &error_abort); - bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abo= rt); + bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_ab= ort); =20 bdrv_unref(mirror_top_bs); } @@ -1707,14 +1710,14 @@ void mirror_start(const char *job_id, BlockDriverSt= ate *bs, MirrorCopyMode copy_mode, Error **errp) { bool is_none_mode; - BlockDriverState *base; + BlockDriverState *base =3D NULL; =20 if (mode =3D=3D MIRROR_SYNC_MODE_INCREMENTAL) { error_setg(errp, "Sync mode 'incremental' not supported"); return; } is_none_mode =3D mode =3D=3D MIRROR_SYNC_MODE_NONE; - base =3D mode =3D=3D MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL; + base =3D mode =3D=3D MIRROR_SYNC_MODE_TOP ? bdrv_backing_chain_next(bs= ) : NULL; mirror_start_job(job_id, bs, creation_flags, target, replaces, speed, granularity, buf_size, backing_mode, on_source_error, on_target_error, unmap, NULL, NULL, diff --git a/block/qapi.c b/block/qapi.c index 110d05dc57..478c6f5e0d 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -149,9 +149,13 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *= blk, return NULL; } =20 - if (bs0->drv && bs0->backing) { + if (bs0->drv && bdrv_filtered_child(bs0)) { + /* + * Put any filtered child here (for backwards compatibility to= when + * we put bs0->backing here, which might be any filtered child= ). + */ info->backing_file_depth++; - bs0 =3D bs0->backing->bs; + bs0 =3D bdrv_filtered_bs(bs0); (*p_image_info)->has_backing_image =3D true; p_image_info =3D &((*p_image_info)->backing_image); } else { @@ -160,9 +164,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 @@ -347,9 +350,9 @@ static void bdrv_query_info(BlockBackend *blk, BlockInf= o **p_info, BlockDriverState *bs =3D blk_bs(blk); char *qdev; =20 - /* Skip automatically inserted nodes that the user isn't aware of */ - while (bs && bs->drv && bs->implicit) { - bs =3D backing_bs(bs); + if (bs) { + /* Skip automatically inserted nodes that the user isn't aware of = */ + bs =3D bdrv_skip_implicit_filters(bs); } =20 info->device =3D g_strdup(blk_name(blk)); @@ -506,6 +509,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level) { + BlockDriverState *cow_bs; BlockStats *s =3D NULL; =20 s =3D g_malloc0(sizeof(*s)); @@ -518,9 +522,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]) { @@ -535,9 +538,10 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverSta= te *bs, s->parent =3D bdrv_query_bds_stats(bs->file->bs, blk_level); } =20 - if (blk_level && bs->backing) { + cow_bs =3D bdrv_filtered_cow_bs(bs); + if (blk_level && cow_bs) { s->has_backing =3D true; - s->backing =3D bdrv_query_bds_stats(bs->backing->bs, blk_level); + s->backing =3D bdrv_query_bds_stats(cow_bs, blk_level); } =20 return s; diff --git a/block/stream.c b/block/stream.c index bfaebb861a..23d5c890e0 100644 --- a/block/stream.c +++ b/block/stream.c @@ -65,6 +65,7 @@ static int stream_prepare(Job *job) StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockJob *bjob =3D &s->common; BlockDriverState *bs =3D blk_bs(bjob->blk); + BlockDriverState *unfiltered =3D bdrv_skip_rw_filters(bs); BlockDriverState *base =3D s->base; Error *local_err =3D NULL; int ret =3D 0; @@ -72,7 +73,7 @@ static int stream_prepare(Job *job) bdrv_unfreeze_backing_chain(bs, base); s->chain_frozen =3D false; =20 - if (bs->backing) { + if (bdrv_filtered_cow_child(unfiltered)) { const char *base_id =3D NULL, *base_fmt =3D NULL; if (base) { base_id =3D s->backing_file_str; @@ -80,7 +81,7 @@ static int stream_prepare(Job *job) base_fmt =3D base->drv->format_name; } } - ret =3D bdrv_change_backing_file(bs, base_id, base_fmt); + ret =3D bdrv_change_backing_file(unfiltered, base_id, base_fmt); bdrv_set_backing_hd(bs, base, &local_err); if (local_err) { error_report_err(local_err); @@ -121,7 +122,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) int64_t n =3D 0; /* bytes */ void *buf; =20 - if (!bs->backing) { + if (!bdrv_filtered_child(bs)) { goto out; } =20 @@ -162,7 +163,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } else if (ret >=3D 0) { /* Copy if allocated in the intermediate images. Limit to the * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE).= */ - ret =3D bdrv_is_allocated_above(backing_bs(bs), base, + ret =3D bdrv_is_allocated_above(bdrv_filtered_bs(bs), base, offset, n, &n); =20 /* Finish early if end of backing file has been reached */ @@ -268,7 +269,9 @@ void stream_start(const char *job_id, BlockDriverState = *bs, * disappear from the chain after this operation. The streaming job re= ads * every block only once, assuming that it doesn't change, so block wr= ites * and resizes. */ - for (iter =3D backing_bs(bs); iter && iter !=3D base; iter =3D backing= _bs(iter)) { + for (iter =3D bdrv_filtered_bs(bs); iter && iter !=3D base; + iter =3D bdrv_filtered_bs(iter)) + { block_job_add_bdrv(&s->common, "intermediate node", iter, 0, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHA= NGED, &error_abort); diff --git a/blockdev.c b/blockdev.c index 4775a07d93..bb71b8368d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1094,7 +1094,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 @@ -1663,7 +1663,7 @@ static void external_snapshot_prepare(BlkActionState = *common, goto out; } =20 - if (state->new_bs->backing !=3D NULL) { + if (bdrv_filtered_cow_child(state->new_bs)) { error_setg(errp, "The snapshot already has a backing image"); goto out; } @@ -3202,6 +3202,13 @@ void qmp_block_stream(bool has_job_id, const char *j= ob_id, const char *device, if (!base_bs) { goto out; } + /* + * Streaming copies data through COR, so all of the filters + * between the target and the base are considered. Therefore, + * we can use bdrv_chain_contains() and do not have to use + * bdrv_legacy_chain_contains() (which does not go past + * explicitly added filters). + */ if (bs =3D=3D base_bs || !bdrv_chain_contains(bs, base_bs)) { error_setg(errp, "Node '%s' is not a backing image of '%s'", base_node, device); @@ -3213,7 +3220,7 @@ void qmp_block_stream(bool has_job_id, const char *jo= b_id, const char *device, } =20 /* Check for op blockers in the whole chain between bs and base */ - for (iter =3D bs; iter && iter !=3D base_bs; iter =3D backing_bs(iter)= ) { + for (iter =3D bs; iter && iter !=3D base_bs; iter =3D bdrv_filtered_bs= (iter)) { if (bdrv_op_is_blocked(iter, BLOCK_OP_TYPE_STREAM, errp)) { goto out; } @@ -3370,7 +3377,9 @@ void qmp_block_commit(bool has_job_id, const char *jo= b_id, const char *device, =20 assert(bdrv_get_aio_context(base_bs) =3D=3D aio_context); =20 - for (iter =3D top_bs; iter !=3D backing_bs(base_bs); iter =3D backing_= bs(iter)) { + for (iter =3D top_bs; iter !=3D bdrv_filtered_bs(base_bs); + iter =3D bdrv_filtered_bs(iter)) + { if (bdrv_op_is_blocked(iter, BLOCK_OP_TYPE_COMMIT_TARGET, errp)) { goto out; } @@ -3381,6 +3390,11 @@ void qmp_block_commit(bool has_job_id, const char *j= ob_id, const char *device, error_setg(errp, "cannot commit an image into itself"); goto out; } + if (!bdrv_legacy_chain_contains(top_bs, base_bs)) { + /* We have to disallow this until the user can give explicit conse= nt */ + error_setg(errp, "Cannot commit through explicit filter nodes"); + goto out; + } =20 if (top_bs =3D=3D bs) { if (has_backing_file) { @@ -3472,7 +3486,13 @@ static BlockJob *do_drive_backup(DriveBackup *backup= , JobTxn *txn, /* See if we have a backing HD we can use to create our new image * on top of. */ if (backup->sync =3D=3D MIRROR_SYNC_MODE_TOP) { - source =3D backing_bs(bs); + /* + * Backup will not replace the source by the target, so none + * of the filters skipped here will be removed (in contrast to + * mirror). Therefore, we can skip all of them when looking + * for the first COW relationship. + */ + source =3D bdrv_filtered_cow_bs(bdrv_skip_rw_filters(bs)); if (!source) { backup->sync =3D MIRROR_SYNC_MODE_FULL; } @@ -3492,9 +3512,14 @@ static BlockJob *do_drive_backup(DriveBackup *backup= , JobTxn *txn, if (backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { assert(backup->format); if (source) { - bdrv_refresh_filename(source); - bdrv_img_create(backup->target, backup->format, source->filena= me, - source->drv->format_name, NULL, + /* Implicit filters should not appear in the filename */ + BlockDriverState *explicit_backing =3D + bdrv_skip_implicit_filters(source); + + bdrv_refresh_filename(explicit_backing); + bdrv_img_create(backup->target, backup->format, + explicit_backing->filename, + explicit_backing->drv->format_name, NULL, size, flags, false, &local_err); } else { bdrv_img_create(backup->target, backup->format, NULL, NULL, NU= LL, @@ -3752,7 +3777,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, return; } =20 - if (!bs->backing && sync =3D=3D MIRROR_SYNC_MODE_TOP) { + if (!bdrv_backing_chain_next(bs) && sync =3D=3D MIRROR_SYNC_MODE_TOP) { sync =3D MIRROR_SYNC_MODE_FULL; } =20 @@ -3801,7 +3826,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, =20 void qmp_drive_mirror(DriveMirror *arg, Error **errp) { - BlockDriverState *bs; + BlockDriverState *bs, *unfiltered_bs; BlockDriverState *source, *target_bs; AioContext *aio_context; BlockMirrorBackingMode backing_mode; @@ -3810,6 +3835,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) int flags; int64_t size; const char *format =3D arg->format; + const char *replaces_node_name =3D NULL; =20 bs =3D qmp_get_root_bs(arg->device, errp); if (!bs) { @@ -3821,6 +3847,16 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) return; } =20 + /* + * If the user has not instructed us otherwise, we should let the + * block job run from @bs (thus taking into account all filters on + * it) but replace @unfiltered_bs when it finishes (thus not + * removing those filters). + * (And if there are any explicit filters, we should assume the + * user knows how to use the @replaces option.) + */ + unfiltered_bs =3D bdrv_skip_implicit_filters(bs); + aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 @@ -3834,8 +3870,14 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) } =20 flags =3D bs->open_flags | BDRV_O_RDWR; - source =3D backing_bs(bs); + source =3D bdrv_filtered_cow_bs(unfiltered_bs); if (!source && arg->sync =3D=3D MIRROR_SYNC_MODE_TOP) { + if (bdrv_filtered_bs(unfiltered_bs)) { + /* @unfiltered_bs is an explicit filter */ + error_setg(errp, "Cannot perform sync=3Dtop mirror through an " + "explicitly added filter node on the source"); + goto out; + } arg->sync =3D MIRROR_SYNC_MODE_FULL; } if (arg->sync =3D=3D MIRROR_SYNC_MODE_NONE) { @@ -3854,6 +3896,9 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) " named node of the graph"); goto out; } + replaces_node_name =3D arg->replaces; + } else if (unfiltered_bs !=3D bs) { + replaces_node_name =3D unfiltered_bs->node_name; } =20 if (arg->mode =3D=3D NEW_IMAGE_MODE_ABSOLUTE_PATHS) { @@ -3873,6 +3918,9 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) bdrv_img_create(arg->target, format, NULL, NULL, NULL, size, flags, false, &local_err); } else { + /* Implicit filters should not appear in the filename */ + BlockDriverState *explicit_backing =3D bdrv_skip_implicit_filters(= source); + switch (arg->mode) { case NEW_IMAGE_MODE_EXISTING: break; @@ -3880,8 +3928,8 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) /* create new image with backing file */ bdrv_refresh_filename(source); bdrv_img_create(arg->target, format, - source->filename, - source->drv->format_name, + explicit_backing->filename, + explicit_backing->drv->format_name, NULL, size, flags, false, &local_err); break; default: @@ -3913,7 +3961,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) bdrv_set_aio_context(target_bs, 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, arg->has_speed, arg->speed, arg->has_granularity, arg->granularity, arg->has_buf_size, arg->buf_size, @@ -3949,7 +3997,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, bool has_auto_dismiss, bool auto_dismiss, Error **errp) { - BlockDriverState *bs; + BlockDriverState *bs, *unfiltered_bs; BlockDriverState *target_bs; AioContext *aio_context; BlockMirrorBackingMode backing_mode =3D MIRROR_LEAVE_BACKING_CHAIN; @@ -3960,6 +4008,16 @@ void qmp_blockdev_mirror(bool has_job_id, const char= *job_id, return; } =20 + /* + * Same as in qmp_drive_mirror(): We want to run the job from @bs, + * but we want to replace @unfiltered_bs on completion. + */ + unfiltered_bs =3D bdrv_skip_implicit_filters(bs); + if (!has_replaces && unfiltered_bs !=3D bs) { + replaces =3D unfiltered_bs->node_name; + has_replaces =3D true; + } + target_bs =3D bdrv_lookup_bs(target, target, errp); if (!target_bs) { return; diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index d1bb863cb6..f99f753fba 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -285,9 +285,7 @@ static int init_dirty_bitmap_migration(void) const char *drive_name =3D bdrv_get_device_or_node_name(bs); =20 /* skip automatically inserted nodes */ - while (bs && bs->drv && bs->implicit) { - bs =3D backing_bs(bs); - } + bs =3D bdrv_skip_implicit_filters(bs); =20 for (bitmap =3D bdrv_dirty_bitmap_next(bs, NULL); bitmap; bitmap =3D bdrv_dirty_bitmap_next(bs, bitmap)) diff --git a/nbd/server.c b/nbd/server.c index e21bd501dc..e41ae89dbe 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1506,13 +1506,13 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uin= t64_t dev_offset, if (bitmap) { BdrvDirtyBitmap *bm =3D NULL; =20 - while (true) { + while (bs) { bm =3D bdrv_find_dirty_bitmap(bs, bitmap); - if (bm !=3D NULL || bs->backing =3D=3D NULL) { + if (bm !=3D NULL) { break; } =20 - bs =3D bs->backing->bs; + bs =3D bdrv_filtered_bs(bs); } =20 if (bm =3D=3D NULL) { diff --git a/qemu-img.c b/qemu-img.c index aa6f81f1ea..bcfbb743fc 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -982,7 +982,7 @@ static int img_commit(int argc, char **argv) if (!blk) { return 1; } - bs =3D blk_bs(blk); + bs =3D bdrv_skip_implicit_filters(blk_bs(blk)); =20 qemu_progress_init(progress, 1.f); qemu_progress_print(0.f, 100); @@ -999,7 +999,7 @@ static int img_commit(int argc, char **argv) /* This is different from QMP, which by default uses the deepest f= ile in * the backing chain (i.e., the very base); however, the tradition= al * behavior of qemu-img commit is using the immediate backing file= . */ - base_bs =3D backing_bs(bs); + base_bs =3D bdrv_filtered_cow_bs(bs); if (!base_bs) { error_setg(&local_err, "Image does not have a backing file"); goto done; @@ -1616,19 +1616,18 @@ static int convert_iteration_sectors(ImgConvertStat= e *s, int64_t sector_num) =20 if (s->sector_next_status <=3D sector_num) { int64_t count =3D n * BDRV_SECTOR_SIZE; + BlockDriverState *src_bs =3D blk_bs(s->src[src_cur]); + BlockDriverState *base; =20 if (s->target_has_backing) { - - ret =3D bdrv_block_status(blk_bs(s->src[src_cur]), - (sector_num - src_cur_offset) * - BDRV_SECTOR_SIZE, - count, &count, NULL, NULL); + base =3D bdrv_backing_chain_next(src_bs); } else { - ret =3D bdrv_block_status_above(blk_bs(s->src[src_cur]), NULL, - (sector_num - src_cur_offset) * - BDRV_SECTOR_SIZE, - count, &count, NULL, NULL); + base =3D NULL; } + ret =3D bdrv_block_status_above(src_bs, base, + (sector_num - src_cur_offset) * + BDRV_SECTOR_SIZE, + count, &count, NULL, NULL); if (ret < 0) { error_report("error while reading block status of sector %" PR= Id64 ": %s", sector_num, strerror(-ret)); @@ -2434,7 +2433,8 @@ static int img_convert(int argc, char **argv) * s.target_backing_sectors has to be negative, which it will * be automatically). The backing file length is used only * for optimizations, so such a case is not fatal. */ - s.target_backing_sectors =3D bdrv_nb_sectors(out_bs->backing->bs); + s.target_backing_sectors =3D + bdrv_nb_sectors(bdrv_filtered_cow_bs(out_bs)); } else { s.target_backing_sectors =3D -1; } @@ -2797,6 +2797,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, =20 depth =3D 0; for (;;) { + bs =3D bdrv_skip_rw_filters(bs); ret =3D bdrv_block_status(bs, offset, bytes, &bytes, &map, &file); if (ret < 0) { return ret; @@ -2805,7 +2806,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, if (ret & (BDRV_BLOCK_ZERO|BDRV_BLOCK_DATA)) { break; } - bs =3D backing_bs(bs); + bs =3D bdrv_filtered_cow_bs(bs); if (bs =3D=3D NULL) { ret =3D 0; break; @@ -2944,7 +2945,7 @@ static int img_map(int argc, char **argv) if (!blk) { return 1; } - bs =3D blk_bs(blk); + bs =3D bdrv_skip_implicit_filters(blk_bs(blk)); =20 if (output_format =3D=3D OFORMAT_HUMAN) { printf("%-16s%-16s%-16s%s\n", "Offset", "Length", "Mapped to", "Fi= le"); diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out index 3deb3cfb94..1d61f7e224 100644 --- a/tests/qemu-iotests/184.out +++ b/tests/qemu-iotests/184.out @@ -27,6 +27,11 @@ Testing: "iops_rd": 0, "detect_zeroes": "off", "image": { + "backing-image": { + "virtual-size": 1073741824, + "filename": "null-co://", + "format": "null-co" + }, "virtual-size": 1073741824, "filename": "json:{\"throttle-group\": \"group0\", \"drive= r\": \"throttle\", \"file\": {\"driver\": \"null-co\"}}", "format": "throttle" @@ -34,7 +39,7 @@ Testing: "iops_wr": 0, "ro": false, "node-name": "throttle0", - "backing_file_depth": 0, + "backing_file_depth": 1, "drv": "throttle", "iops": 0, "bps_wr": 0, 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.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554927790; cv=none; d=zoho.com; s=zohoarc; b=DiHNHFWZd4da0Z4lhWGc6jMpjO7JudA2eeFQHZfSMumn3KYKAkRzAe1z/NRtgx2xXrsv2FWzRqhmmSN5cGDZ7OPbiLc6+N+HRUH4HOBwxSJq8jDogY8YBHp8wSAYg+qigLZCfrNvQ2fyGrlic3qPJZGgadhRJy4v3CSC5eaFREQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554927790; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=dVoBEijWitONep4fw04kFdFH4FuoohEyiF6BM/BZCIo=; b=FQhUTeRCsFWlMMjy1wxiQ85VLN9tuyrEM17wQfe6FHMeVbQ8lhliHWnUQEZEFyxLiJAOzUW3tcqLU9daJP+vH4N/kTSSw2z337ULvl81AsM+7f/Mnq4qj94BY/j4wXzUkDHWu8UVZp0E2Rcz0mJOQuV/F+gEhH2aTsLBJxtSwc0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554927790909533.2948762873417; Wed, 10 Apr 2019 13:23:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:37320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJkQ-0008Fv-Qp for importer@patchew.org; Wed, 10 Apr 2019 16:23:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiT-0006z7-N3 for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiR-0004QV-FQ for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53044) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiG-0004GX-RQ; Wed, 10 Apr 2019 16:20:57 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A0CA5945C; Wed, 10 Apr 2019 20:20:46 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 480AB19C65; Wed, 10 Apr 2019 20:20:45 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:25 +0200 Message-Id: <20190410202033.28617-4-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 10 Apr 2019 20:20:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 03/11] block: Storage child access function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" For completeness' sake, add a function for accessing a node's storage child, too. For filters, this is their filtered child; for non-filters, this is bs->file. Some places are deliberately left unconverted: - BDS opening/closing functions where bs->file is handled specially (which is basically wrong, but at least simplifies probing) - bdrv_co_block_status_from_file(), because its name implies that it points to ->file - bdrv_snapshot_goto() in one places unrefs bs->file. Such a modification is not covered by this patch and is therefore just safeguarded by an additional assert(), but otherwise kept as-is. Signed-off-by: Max Reitz --- include/block/block_int.h | 6 +++++ block.c | 53 ++++++++++++++++++++++++++++----------- block/io.c | 22 +++++++--------- block/qapi.c | 7 +++--- block/snapshot.c | 40 ++++++++++++++++------------- 5 files changed, 81 insertions(+), 47 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index b22b1164f8..d0309e6307 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1243,6 +1243,7 @@ int refresh_total_sectors(BlockDriverState *bs, int64= _t hint); BdrvChild *bdrv_filtered_cow_child(BlockDriverState *bs); BdrvChild *bdrv_filtered_rw_child(BlockDriverState *bs); BdrvChild *bdrv_filtered_child(BlockDriverState *bs); +BdrvChild *bdrv_storage_child(BlockDriverState *bs); BlockDriverState *bdrv_skip_implicit_filters(BlockDriverState *bs); BlockDriverState *bdrv_skip_rw_filters(BlockDriverState *bs); BlockDriverState *bdrv_backing_chain_next(BlockDriverState *bs); @@ -1267,4 +1268,9 @@ static inline BlockDriverState *bdrv_filtered_bs(Bloc= kDriverState *bs) return child_bs(bdrv_filtered_child(bs)); } =20 +static inline BlockDriverState *bdrv_storage_bs(BlockDriverState *bs) +{ + return child_bs(bdrv_storage_child(bs)); +} + #endif /* BLOCK_INT_H */ diff --git a/block.c b/block.c index e8f6febda0..89cb6de4c3 100644 --- a/block.c +++ b/block.c @@ -4404,15 +4404,21 @@ exit: int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs; + if (!drv) { return -ENOMEDIUM; } + if (drv->bdrv_get_allocated_file_size) { return drv->bdrv_get_allocated_file_size(bs); } - if (bs->file) { - return bdrv_get_allocated_file_size(bs->file->bs); + + storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { + return bdrv_get_allocated_file_size(storage_bs); } + return -ENOTSUP; } =20 @@ -4982,7 +4988,7 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const= char *event, const char *tag) { while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) { - bs =3D bs->file ? bs->file->bs : NULL; + bs =3D bdrv_storage_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_breakpoint) { @@ -4995,7 +5001,7 @@ int bdrv_debug_breakpoint(BlockDriverState *bs, const= char *event, int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag) { while (bs && bs->drv && !bs->drv->bdrv_debug_remove_breakpoint) { - bs =3D bs->file ? bs->file->bs : NULL; + bs =3D bdrv_storage_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_remove_breakpoint) { @@ -5008,7 +5014,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_storage_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_resume) { @@ -5021,7 +5027,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_storage_bs(bs); } =20 if (bs && bs->drv && bs->drv->bdrv_debug_is_suspended) { @@ -6142,14 +6148,23 @@ void bdrv_refresh_filename(BlockDriverState *bs) 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 (bdrv_storage_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). + */ + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); =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: @@ -6158,11 +6173,10 @@ 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 (storage_bs->exact_filename[0] && storage_bs->drv->bdrv_file_op= en && + !drv->is_filter && !generate_json_filename) { - strcpy(bs->exact_filename, bs->file->bs->exact_filename); + strcpy(bs->exact_filename, storage_bs->exact_filename); } } =20 @@ -6179,6 +6193,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) char *bdrv_dirname(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs; =20 if (!drv) { error_setg(errp, "Node '%s' is ejected", bs->node_name); @@ -6189,8 +6204,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); + storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { + return bdrv_dirname(storage_bs, errp); } =20 bdrv_refresh_filename(bs); @@ -6324,6 +6340,15 @@ BdrvChild *bdrv_filtered_child(BlockDriverState *bs) return cow_child ?: rw_child; } =20 +/* + * Return the child that stores the data that is allocated on this + * node. This may or may not include metadata. + */ +BdrvChild *bdrv_storage_child(BlockDriverState *bs) +{ + return bdrv_filtered_rw_child(bs) ?: bs->file; +} + static BlockDriverState *bdrv_skip_filters(BlockDriverState *bs, bool stop_on_explicit_filter) { diff --git a/block/io.c b/block/io.c index 83c2b6b46a..5c33ecc080 100644 --- a/block/io.c +++ b/block/io.c @@ -118,17 +118,10 @@ static void bdrv_merge_limits(BlockLimits *dst, const= BlockLimits *src) void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; - BlockDriverState *storage_bs; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); BlockDriverState *cow_bs =3D bdrv_filtered_cow_bs(bs); Error *local_err =3D NULL; =20 - /* - * FIXME: There should be a function for this, and in fact there - * will be as of a follow-up patch. - */ - storage_bs =3D - child_bs(bs->file) ?: bdrv_filtered_rw_bs(bs); - memset(&bs->bl, 0, sizeof(bs->bl)); =20 if (!drv) { @@ -2390,6 +2383,7 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector= *qiov, int64_t pos, bool is_read) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); int ret =3D -ENOTSUP; =20 bdrv_inc_in_flight(bs); @@ -2402,8 +2396,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 (storage_bs) { + ret =3D bdrv_co_rw_vmstate(storage_bs, qiov, pos, is_read); } =20 bdrv_dec_in_flight(bs); @@ -2530,6 +2524,7 @@ static void coroutine_fn bdrv_flush_co_entry(void *op= aque) =20 int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { + BlockDriverState *storage_bs; int current_gen; int ret =3D 0; =20 @@ -2559,7 +2554,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(bdrv_storage_child(bs), 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) { @@ -2577,7 +2572,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) goto flush_parent; } =20 - BLKDBG_EVENT(bs->file, BLKDBG_FLUSH_TO_DISK); + BLKDBG_EVENT(bdrv_storage_child(bs), BLKDBG_FLUSH_TO_DISK); if (!bs->drv) { /* bs->drv->bdrv_co_flush() might have ejected the BDS * (even in case of apparent success) */ @@ -2622,7 +2617,8 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) * in the case of cache=3Dunsafe, so there are no useless flushes. */ flush_parent: - ret =3D bs->file ? bdrv_co_flush(bs->file->bs) : 0; + storage_bs =3D bdrv_storage_bs(bs); + ret =3D storage_bs ? bdrv_co_flush(storage_bs) : 0; out: /* Notify any pending flushes that we have completed */ if (ret =3D=3D 0) { diff --git a/block/qapi.c b/block/qapi.c index 478c6f5e0d..e026d27077 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -509,7 +509,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level) { - BlockDriverState *cow_bs; + BlockDriverState *storage_bs, *cow_bs; BlockStats *s =3D NULL; =20 s =3D g_malloc0(sizeof(*s)); @@ -533,9 +533,10 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverSta= te *bs, =20 s->stats->wr_highest_offset =3D stat64_get(&bs->wr_highest_offset); =20 - if (bs->file) { + storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { s->has_parent =3D true; - s->parent =3D bdrv_query_bds_stats(bs->file->bs, blk_level); + s->parent =3D bdrv_query_bds_stats(storage_bs, blk_level); } =20 cow_bs =3D bdrv_filtered_cow_bs(bs); diff --git a/block/snapshot.c b/block/snapshot.c index f2f48f926a..3032cd0341 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -154,8 +154,9 @@ int bdrv_can_snapshot(BlockDriverState *bs) } =20 if (!drv->bdrv_snapshot_create) { - if (bs->file !=3D NULL) { - return bdrv_can_snapshot(bs->file->bs); + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { + return bdrv_can_snapshot(storage_bs); } return 0; } @@ -167,14 +168,15 @@ int bdrv_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); if (!drv) { return -ENOMEDIUM; } if (drv->bdrv_snapshot_create) { return drv->bdrv_snapshot_create(bs, sn_info); } - if (bs->file) { - return bdrv_snapshot_create(bs->file->bs, sn_info); + if (storage_bs) { + return bdrv_snapshot_create(storage_bs, sn_info); } return -ENOTSUP; } @@ -184,6 +186,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs; int ret, open_ret; =20 if (!drv) { @@ -204,39 +207,40 @@ int bdrv_snapshot_goto(BlockDriverState *bs, return ret; } =20 - if (bs->file) { - BlockDriverState *file; + storage_bs =3D bdrv_storage_bs(bs); + if (storage_bs) { QDict *options =3D qdict_clone_shallow(bs->options); QDict *file_options; Error *local_err =3D NULL; =20 - file =3D bs->file->bs; /* Prevent it from getting deleted when detached from bs */ - bdrv_ref(file); + bdrv_ref(storage_bs); =20 qdict_extract_subqdict(options, &file_options, "file."); qobject_unref(file_options); - qdict_put_str(options, "file", bdrv_get_node_name(file)); + qdict_put_str(options, "file", bdrv_get_node_name(storage_bs)); =20 if (drv->bdrv_close) { drv->bdrv_close(bs); } + + assert(bs->file->bs =3D=3D storage_bs); bdrv_unref_child(bs, bs->file); bs->file =3D NULL; =20 - ret =3D bdrv_snapshot_goto(file, snapshot_id, errp); + ret =3D bdrv_snapshot_goto(storage_bs, snapshot_id, errp); open_ret =3D drv->bdrv_open(bs, options, bs->open_flags, &local_er= r); qobject_unref(options); if (open_ret < 0) { - bdrv_unref(file); + bdrv_unref(storage_bs); bs->drv =3D NULL; /* A bdrv_snapshot_goto() error takes precedence */ error_propagate(errp, local_err); return ret < 0 ? ret : open_ret; } =20 - assert(bs->file->bs =3D=3D file); - bdrv_unref(file); + assert(bs->file->bs =3D=3D storage_bs); + bdrv_unref(storage_bs); return ret; } =20 @@ -272,6 +276,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs, Error **errp) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); int ret; =20 if (!drv) { @@ -288,8 +293,8 @@ int bdrv_snapshot_delete(BlockDriverState *bs, =20 if (drv->bdrv_snapshot_delete) { ret =3D drv->bdrv_snapshot_delete(bs, snapshot_id, name, errp); - } else if (bs->file) { - ret =3D bdrv_snapshot_delete(bs->file->bs, snapshot_id, name, errp= ); + } else if (storage_bs) { + ret =3D bdrv_snapshot_delete(storage_bs, snapshot_id, name, errp); } else { error_setg(errp, "Block format '%s' used by device '%s' " "does not support internal snapshot deletion", @@ -305,14 +310,15 @@ int bdrv_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_info) { BlockDriver *drv =3D bs->drv; + BlockDriverState *storage_bs =3D bdrv_storage_bs(bs); if (!drv) { return -ENOMEDIUM; } if (drv->bdrv_snapshot_list) { return drv->bdrv_snapshot_list(bs, psn_info); } - if (bs->file) { - return bdrv_snapshot_list(bs->file->bs, psn_info); + if (storage_bs) { + return bdrv_snapshot_list(storage_bs, psn_info); } return -ENOTSUP; } --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) 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=1554928113; cv=none; d=zoho.com; s=zohoarc; b=EIY+eEDH291jCtRvdvDwbdLTIIf3r+ZXQaXr/JRO90ekCeaqC+3u5Y9eyYX1tE0oX6t0UE2ZVtLde4s8KJA/30jzMmlo4vrj1k4rpenploFZU806pm7/438LA2rUAigP8UeKINtqYlM8floJ6GBw/moD8o9/cFoCqHqsKxxBuB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554928113; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=T90RDF9SpXcpy495Ah1bszhdLpvhXPiuZYtslc5u7+I=; b=eCGK2tMvFX3zxOtcemsAxp8yBaD9NhHphwtf4XutihFo/G5wgA8/18wpxtCA94DSrSCzpZ/uU1j2+FU3EETzMmSYl+bJ/58legEVUIkw63qHd4mPSryh+P/TFdndwEjX6d7R2+nTwm8ADgJhBfstvt0qeaQW1cm9RORFjVariGc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554928113501357.21166914126354; Wed, 10 Apr 2019 13:28:33 -0700 (PDT) Received: from localhost ([127.0.0.1]:37429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJpS-0005Mx-3z for importer@patchew.org; Wed, 10 Apr 2019 16:28:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiS-0006y4-Uz for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiR-0004QM-BC for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiL-0004Hm-NP; Wed, 10 Apr 2019 16:20:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B0C6316468C; Wed, 10 Apr 2019 20:20:51 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1007C19C65; Wed, 10 Apr 2019 20:20:47 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:26 +0200 Message-Id: <20190410202033.28617-5-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 10 Apr 2019 20:20:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 04/11] block: Inline bdrv_co_block_status_from_*() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" With bdrv_filtered_rw_bs(), we can easily handle this default filter behavior in bdrv_co_block_status(). blkdebug wants to have an additional assertion, so it keeps its own implementation, except bdrv_co_block_status_from_file() needs to be inlined there. Suggested-by: Eric Blake Signed-off-by: Max Reitz --- include/block/block_int.h | 22 ----------------- block/blkdebug.c | 7 ++++-- block/blklogwrites.c | 1 - block/commit.c | 1 - block/copy-on-read.c | 2 -- block/io.c | 51 +++++++++++++-------------------------- block/mirror.c | 1 - block/throttle.c | 1 - 8 files changed, 22 insertions(+), 64 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index d0309e6307..76c7c0a111 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1187,28 +1187,6 @@ void bdrv_format_default_perms(BlockDriverState *bs,= BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); =20 -/* - * Default implementation for drivers to pass bdrv_co_block_status() to - * their file. - */ -int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file); -/* - * Default implementation for drivers to pass bdrv_co_block_status() to - * their backing file. - */ -int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file= ); const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); bool blk_dev_has_removable_media(BlockBackend *blk); diff --git a/block/blkdebug.c b/block/blkdebug.c index efd9441625..7950ae729c 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -637,8 +637,11 @@ static int coroutine_fn blkdebug_co_block_status(Block= DriverState *bs, BlockDriverState **file) { assert(QEMU_IS_ALIGNED(offset | bytes, bs->bl.request_alignment)); - return bdrv_co_block_status_from_file(bs, want_zero, offset, bytes, - pnum, map, file); + assert(bs->file && bs->file->bs); + *pnum =3D bytes; + *map =3D offset; + *file =3D bs->file->bs; + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 static void blkdebug_close(BlockDriverState *bs) diff --git a/block/blklogwrites.c b/block/blklogwrites.c index eb2b4901a5..1eb4a5c613 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -518,7 +518,6 @@ static BlockDriver bdrv_blk_log_writes =3D { .bdrv_co_pwrite_zeroes =3D blk_log_writes_co_pwrite_zeroes, .bdrv_co_flush_to_disk =3D blk_log_writes_co_flush_to_disk, .bdrv_co_pdiscard =3D blk_log_writes_co_pdiscard, - .bdrv_co_block_status =3D bdrv_co_block_status_from_file, =20 .is_filter =3D true, .strong_runtime_opts =3D blk_log_writes_strong_runtime_opts, diff --git a/block/commit.c b/block/commit.c index 252007fd57..c366ee9655 100644 --- a/block/commit.c +++ b/block/commit.c @@ -254,7 +254,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 53972b1da3..fe9260163c 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -150,8 +150,6 @@ static BlockDriver bdrv_copy_on_read =3D { .bdrv_eject =3D cor_eject, .bdrv_lock_medium =3D cor_lock_medium, =20 - .bdrv_co_block_status =3D bdrv_co_block_status_from_file, - .bdrv_recurse_is_first_non_filter =3D cor_recurse_is_first_non_filte= r, =20 .has_variable_length =3D true, diff --git a/block/io.c b/block/io.c index 5c33ecc080..8d124bae5c 100644 --- a/block/io.c +++ b/block/io.c @@ -1993,36 +1993,6 @@ typedef struct BdrvCoBlockStatusData { bool done; } BdrvCoBlockStatusData; =20 -int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file) -{ - assert(bs->file && bs->file->bs); - *pnum =3D bytes; - *map =3D offset; - *file =3D bs->file->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; -} - -int coroutine_fn bdrv_co_block_status_from_backing(BlockDriverState *bs, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file) -{ - assert(bs->backing && bs->backing->bs); - *pnum =3D bytes; - *map =3D offset; - *file =3D bs->backing->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; -} - /* * Returns the allocation status of the specified sectors. * Drivers not implementing the functionality are assumed to not support @@ -2063,6 +2033,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; @@ -2088,7 +2059,8 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, =20 /* Must be non-NULL or bdrv_getlength() would have failed */ assert(bs->drv); - if (!bs->drv->bdrv_co_block_status) { + has_filtered_child =3D bs->drv->is_filter && bdrv_filtered_rw_child(bs= ); + if (!bs->drv->bdrv_co_block_status && !has_filtered_child) { *pnum =3D bytes; ret =3D BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED; if (offset + bytes =3D=3D total_size) { @@ -2109,9 +2081,20 @@ static int coroutine_fn bdrv_co_block_status(BlockDr= iverState *bs, aligned_offset =3D QEMU_ALIGN_DOWN(offset, align); aligned_bytes =3D ROUND_UP(offset + bytes, align) - aligned_offset; =20 - ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offset, - aligned_bytes, pnum, &local_map, - &local_file); + if (bs->drv->bdrv_co_block_status) { + ret =3D bs->drv->bdrv_co_block_status(bs, want_zero, aligned_offse= t, + aligned_bytes, pnum, &local_ma= p, + &local_file); + } else { + /* Default code for filters */ + + local_file =3D bdrv_filtered_rw_bs(bs); + assert(local_file); + + *pnum =3D aligned_bytes; + local_map =3D aligned_offset; + ret =3D BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; + } if (ret < 0) { *pnum =3D 0; goto out; diff --git a/block/mirror.c b/block/mirror.c index 80cef587f0..2e521c726a 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1487,7 +1487,6 @@ static BlockDriver bdrv_mirror_top =3D { .bdrv_co_pwrite_zeroes =3D bdrv_mirror_top_pwrite_zeroes, .bdrv_co_pdiscard =3D bdrv_mirror_top_pdiscard, .bdrv_co_flush =3D bdrv_mirror_top_flush, - .bdrv_co_block_status =3D bdrv_co_block_status_from_backing, .bdrv_refresh_filename =3D bdrv_mirror_top_refresh_filename, .bdrv_child_perm =3D bdrv_mirror_top_child_perm, =20 diff --git a/block/throttle.c b/block/throttle.c index f64dcc27b9..b6922e734f 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -259,7 +259,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.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554927799; cv=none; d=zoho.com; s=zohoarc; b=IXVS/AOOHLsTvi1uPsCYu5Sp9CQbwbPewj8cYCSokx5yAEGWOkFMzApwU3eYVVYeF1rdA8glguc8b5HgGJvt3vYhMNMEy7X5z1UPTs63hUZXlS5haTHn1kA6sdXIF9z0dwQyU0znEwD95CdZMWJQaFYJrihWN/jglIB/v7NFgl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554927799; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=XJHiHsZmah4PN/yEiKmamXQOS7ct6wfKj8/7RZZ8E8w=; b=Y9OO6yFbQ5Znu6BaQhT1uEdai2nAxwTIU8YPYeGRq/qzsPM1APLzxY3iQUm7wpNxUm3Ix6WbtXErY82QNNu2jqLvAsf8idB39sHI8Rw3tchZVK5Aq4XUEIUuuo8Lkg87Qwda5AMIqgquaVDvifcPKNDE4T0VX879q3MzN33+Y10= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15549277998664.336841868479496; Wed, 10 Apr 2019 13:23:19 -0700 (PDT) Received: from localhost ([127.0.0.1]:37322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJkZ-0008NA-LI for importer@patchew.org; Wed, 10 Apr 2019 16:23:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiS-0006xa-9D for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiQ-0004Pq-Iy for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiL-0004J0-L7; Wed, 10 Apr 2019 16:20:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0D9B9AE78; Wed, 10 Apr 2019 20:20:53 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C4915C666; Wed, 10 Apr 2019 20:20:53 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:27 +0200 Message-Id: <20190410202033.28617-6-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 10 Apr 2019 20:20:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 05/11] block: Fix check_to_replace_node() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, check_to_replace_node() only allows mirror to replace a node in the chain of the source node, and only if it is the first non-filter node below the source. Well, technically, the idea is that you can exactly replace a quorum child by mirroring from quorum. This has (probably) two reasons: (1) We do not want to create loops. (2) @replaces and @device should have exactly the same content so replacing them does not cause visible data to change. This has two issues: (1) It is overly restrictive. It is completely fine for @replaces to be a filter. (2) It is not restrictive enough. You can create loops with this as follows: $ qemu-img create -f qcow2 /tmp/source.qcow2 64M $ qemu-system-x86_64 -qmp stdio {"execute": "qmp_capabilities"} {"execute": "object-add", "arguments": {"qom-type": "throttle-group", "id": "tg0"}} {"execute": "blockdev-add", "arguments": { "node-name": "source", "driver": "throttle", "throttle-group": "tg0", "file": { "node-name": "filtered", "driver": "qcow2", "file": { "driver": "file", "filename": "/tmp/source.qcow2" } } } } {"execute": "drive-mirror", "arguments": { "job-id": "mirror", "device": "source", "target": "/tmp/target.qcow2", "format": "qcow2", "node-name": "target", "sync" :"none", "replaces": "filtered" } } {"execute": "block-job-complete", "arguments": {"device": "mirror"}} And qemu crashes because of a stack overflow due to the loop being created (target's backing file is source, so when it replaces filtered, it points to itself through source). (blockdev-mirror can be broken similarly.) So let us make the checks for the two conditions above explicit, which makes the whole function exactly as restrictive as it needs to be. Signed-off-by: Max Reitz --- include/block/block.h | 1 + block.c | 83 +++++++++++++++++++++++++++++++++++++++---- blockdev.c | 34 ++++++++++++++++-- 3 files changed, 110 insertions(+), 8 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 2005664f14..2878198892 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -402,6 +402,7 @@ bool bdrv_is_first_non_filter(BlockDriverState *candida= te); =20 /* check if a named node can be replaced when doing drive-mirror */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, + BlockDriverState *backing_bs, const char *node_name, Error **err= p); =20 /* async block I/O */ diff --git a/block.c b/block.c index 89cb6de4c3..820244f52e 100644 --- a/block.c +++ b/block.c @@ -5916,7 +5916,59 @@ bool bdrv_is_first_non_filter(BlockDriverState *cand= idate) return false; } =20 +static bool is_child_of(BlockDriverState *child, BlockDriverState *parent) +{ + BdrvChild *c; + + if (!parent) { + return false; + } + + QLIST_FOREACH(c, &parent->children, next) { + if (c->bs =3D=3D child || is_child_of(child, c->bs)) { + return true; + } + } + + return false; +} + +/* + * Return true if there are only filters in [@top, @base). Note that + * this may include quorum (which bdrv_chain_contains() cannot + * handle). + */ +static bool is_filtered_child(BlockDriverState *top, BlockDriverState *bas= e) +{ + BdrvChild *c; + + if (!top) { + return false; + } + + if (top =3D=3D base) { + return true; + } + + if (!top->drv->is_filter) { + return false; + } + + QLIST_FOREACH(c, &top->children, next) { + if (is_filtered_child(c->bs, base)) { + return true; + } + } + + return false; +} + +/* + * @parent_bs is mirror's source BDS, @backing_bs is the BDS which + * will be attached to the target when mirror completes. + */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, + BlockDriverState *backing_bs, const char *node_name, Error **err= p) { BlockDriverState *to_replace_bs =3D bdrv_find_node(node_name); @@ -5935,13 +5987,32 @@ BlockDriverState *check_to_replace_node(BlockDriver= State *parent_bs, goto out; } =20 - /* We don't want arbitrary node of the BDS chain to be replaced only t= he top - * most non filter in order to prevent data corruption. - * Another benefit is that this tests exclude backing files which are - * blocked by the backing blockers. + /* + * If to_replace_bs is (recursively) a child of backing_bs, + * replacing it may create a loop. We cannot allow that. */ - if (!bdrv_recurse_is_first_non_filter(parent_bs, to_replace_bs)) { - error_setg(errp, "Only top most non filter can be replaced"); + if (to_replace_bs =3D=3D backing_bs || is_child_of(to_replace_bs, back= ing_bs)) { + error_setg(errp, "Replacing this node would result in a loop"); + to_replace_bs =3D NULL; + goto out; + } + + /* + * Mirror is designed in such a way that when it completes, the + * source BDS is seamlessly replaced. It is therefore not allowed + * to replace a BDS where this condition would be violated, as that + * would defeat the purpose of mirror and could lead to data + * corruption. + * Therefore, between parent_bs and to_replace_bs there may be + * only filters (and the one on top must be a filter, too), so + * their data always stays in sync and mirror can complete and + * replace to_replace_bs without any possible corruptions. + */ + if (!is_filtered_child(parent_bs, to_replace_bs) && + !is_filtered_child(to_replace_bs, parent_bs)) + { + error_setg(errp, "The node to be replaced must be connected to the= " + "source through filter nodes only"); to_replace_bs =3D NULL; goto out; } diff --git a/blockdev.c b/blockdev.c index bb71b8368d..53d17cc05e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3782,7 +3782,7 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, } =20 if (has_replaces) { - BlockDriverState *to_replace_bs; + BlockDriverState *to_replace_bs, *backing_bs; AioContext *replace_aio_context; int64_t bs_size, replace_size; =20 @@ -3792,7 +3792,37 @@ static void blockdev_mirror_common(const char *job_i= d, BlockDriverState *bs, return; } =20 - to_replace_bs =3D check_to_replace_node(bs, replaces, errp); + if (backing_mode =3D=3D MIRROR_SOURCE_BACKING_CHAIN || + backing_mode =3D=3D MIRROR_OPEN_BACKING_CHAIN) + { + /* + * While we do not quite know what OPEN_BACKING_CHAIN + * (used for mode=3Dexisting) will yield, it is probably + * best to restrict it exactly like SOURCE_BACKING_CHAIN, + * because that is our best guess. + */ + switch (sync) { + case MIRROR_SYNC_MODE_FULL: + backing_bs =3D NULL; + break; + + case MIRROR_SYNC_MODE_TOP: + backing_bs =3D bdrv_filtered_cow_bs(bdrv_skip_rw_filters(b= s)); + break; + + case MIRROR_SYNC_MODE_NONE: + backing_bs =3D bs; + break; + + default: + abort(); + } + } else { + assert(backing_mode =3D=3D MIRROR_LEAVE_BACKING_CHAIN); + backing_bs =3D bdrv_filtered_cow_bs(bdrv_skip_rw_filters(targe= t)); + } + + to_replace_bs =3D check_to_replace_node(bs, backing_bs, replaces, = errp); if (!to_replace_bs) { return; } --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554927960; cv=none; d=zoho.com; s=zohoarc; b=QqrUIpBCavX1hj2DHQGAK/nsxKjALHZBzux2lzFlM7CKJBe+zrFL4/+7rFDp/eq6IiIzKhlbp2ZXPPWCZqvOf8+4BfY06IouZrQMYyRd/uyepc0hTCjXdUd7CX7horWRQtbnbm/DK70DeG8gLqsiyT9IYm2phwRWMaqStpah7DM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554927960; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6VPxNwo6RroMD4WBvZvG+WCWDn7zya3jw8P6wYl6A38=; b=izZ8wknNLA575mdqb7aNwlW6dUyUnMWyRb0cQB43Zjo5gQFIrHoPmnIS4J7gl5EsbLRLwJVQFArxNzymTCJDkwREYrNaqlHAYoXG9mRaeeQSar1GeKpBXGt84VgMlQ2gwqUY7dTnGQ8zccY0Fee9SI0GZwoxW3Vnj3Bg1GHk4JI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554927960400834.7567543791674; Wed, 10 Apr 2019 13:26:00 -0700 (PDT) Received: from localhost ([127.0.0.1]:37401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJnA-0002lh-Cd for importer@patchew.org; Wed, 10 Apr 2019 16:25:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiR-0006wq-QP for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiQ-0004Pc-CA for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiM-0004Js-17; Wed, 10 Apr 2019 16:20:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AE32307CB2F; Wed, 10 Apr 2019 20:20:56 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C71EF608BB; Wed, 10 Apr 2019 20:20:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:28 +0200 Message-Id: <20190410202033.28617-7-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 10 Apr 2019 20:20:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 06/11] iotests: Add tests for mirror @replaces loops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This adds two tests for cases where our old check_to_replace_node() function failed to detect that executing this job with these parameters would result in a cyclic graph. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/041 | 124 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 +- 2 files changed, 126 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 26bf1701eb..0c1432f189 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1067,5 +1067,129 @@ class TestOrphanedSource(iotests.QMPTestCase): target=3D'dest-ro') self.assert_qmp(result, 'error/class', 'GenericError') =20 +# Various tests for the @replaces option (independent of quorum) +class TestReplaces(iotests.QMPTestCase): + def setUp(self): + self.vm =3D iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + + def test_drive_mirror_loop(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, '1M') + + result =3D self.vm.qmp('object-add', qom_type=3D'throttle-group', = id=3D'tg') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'source', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'filtered', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + } + } + }) + self.assert_qmp(result, 'return', {}) + + # Mirror from @source to @target in sync=3Dnone, so that @source + # will be @target's backing file; but replace @filtered. + # Then, @target's backing file will be @source, whose backing + # file is now @target instead of @filtered. That is a loop. + # (But apart from the loop, replacing @filtered instead of + # @source is fine, because both are just filtered versions of + # each other.) + result =3D self.vm.qmp('drive-mirror', + job_id=3D'mirror', + device=3D'source', + target=3Dtarget_img, + format=3Diotests.imgfmt, + node_name=3D'target', + sync=3D'none', + replaces=3D'filtered') + if 'error' in result: + # This is the correct result + self.assert_qmp(result, 'error/class', 'GenericError') + else: + # This is wrong, but let's run it to the bitter conclusion + self.complete_and_wait(drive=3D'mirror') + # Fail for good measure, although qemu should have crashed + # anyway + self.fail('Loop creation was successful') + + os.remove(test_img) + try: + os.remove(target_img) + except OSError: + pass + + def test_blockdev_mirror_loop(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, '1M') + qemu_img('create', '-f', iotests.imgfmt, target_img, '1M') + + result =3D self.vm.qmp('object-add', qom_type=3D'throttle-group', = id=3D'tg') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'source', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'middle', + 'driver': 'throttle', + 'throttle-group': 'tg', + 'file': { + 'node-name': 'bottom', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + } + } + } + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'target', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + }, + 'backing': 'middle' + }) + + # Mirror from @source to @target. With blockdev-mirror, the + # current (old) backing file is retained (which is @middle). + # By replacing @bottom, @middle's file will be @target, whose + # backing file is @middle again. That is a loop. + # (But apart from the loop, replacing @bottom instead of + # @source is fine, because both are just filtered versions of + # each other.) + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + sync=3D'full', + replaces=3D'bottom') + if 'error' in result: + # This is the correct result + self.assert_qmp(result, 'error/class', 'GenericError') + else: + # This is wrong, but let's run it to the bitter conclusion + self.complete_and_wait(drive=3D'mirror') + # Fail for good measure, although qemu should have crashed + # anyway + self.fail('Loop creation was successful') + + os.remove(test_img) + os.remove(target_img) + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index e071d0b261..2c448b4239 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= .............. +..........................................................................= ................ ---------------------------------------------------------------------- -Ran 88 tests +Ran 90 tests =20 OK --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554927951; cv=none; d=zoho.com; s=zohoarc; b=XxEqtCCPhABK0AJLuY8M7hPJJi1L7GadkcaWMmOQ7wogOtMDQwh17wKTjdOF6z1o2bqXZgo1ieGYjuPdFjoK83YzHJWXvJjlWTbcYlcapcHVkBhrATsM/PuToHsHq8I2/yPDQKnoaYHaoeQ7oT//wOR/lfpBDd/CwHaRvilLiNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554927951; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kzfK96G/FZJt+DaKrnF8mCX55Sx+ooXgwpdhrVJ7B0A=; b=guYr0NB2HT/Q9sH71A2tDFXcyIPDc58Ybj5oBhNeDLdivYsy32EVpErUt0k0yEmIklhiobtceOWDrBUq95P43lleGe1mV/8Cbla4mKFGnZgiaeBNT8KqhVeX3VmXie4v12O27+ws2NZBd8wPx3fhdCwJ+4XPqSgHQMAKm2ObVDs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554927951405711.8735928594451; Wed, 10 Apr 2019 13:25:51 -0700 (PDT) Received: from localhost ([127.0.0.1]:37399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJn1-0002d5-7b for importer@patchew.org; Wed, 10 Apr 2019 16:25:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiV-000713-MF for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiT-0004Rw-7B for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34808) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiN-0004Lu-Jh; Wed, 10 Apr 2019 16:20:59 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D16AA3097077; Wed, 10 Apr 2019 20:20:58 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38F3F19C65; Wed, 10 Apr 2019 20:20:58 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:29 +0200 Message-Id: <20190410202033.28617-8-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 10 Apr 2019 20:20:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 07/11] block: Leave BDS.backing_file constant X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Parts of the block layer treat BDS.backing_file as if it were whatever the image header says (i.e., if it is a relative path, it is relative to the overlay), other parts treat it like a cache for bs->backing->bs->filename (relative paths are relative to the CWD). Considering bs->backing->bs->filename exists, let us make it mean the former. Among other things, this now allows the user to specify a base when using qemu-img to commit an image file in a directory that is not the CWD (assuming, everything uses relative filenames). Before this patch: $ ./qemu-img create -f qcow2 foo/bot.qcow2 1M $ ./qemu-img create -f qcow2 -b bot.qcow2 foo/mid.qcow2 $ ./qemu-img create -f qcow2 -b mid.qcow2 foo/top.qcow2 $ ./qemu-img commit -b mid.qcow2 foo/top.qcow2 qemu-img: Did not find 'mid.qcow2' in the backing chain of 'foo/top.qcow2' $ ./qemu-img commit -b foo/mid.qcow2 foo/top.qcow2 qemu-img: Did not find 'foo/mid.qcow2' in the backing chain of 'foo/top.qco= w2' $ ./qemu-img commit -b $PWD/foo/mid.qcow2 foo/top.qcow2 qemu-img: Did not find '[...]/foo/mid.qcow2' in the backing chain of 'foo/t= op.qcow2' After this patch: $ ./qemu-img commit -b mid.qcow2 foo/top.qcow2 Image committed. $ ./qemu-img commit -b foo/mid.qcow2 foo/top.qcow2 qemu-img: Did not find 'foo/mid.qcow2' in the backing chain of 'foo/top.qco= w2' $ ./qemu-img commit -b $PWD/foo/mid.qcow2 foo/top.qcow2 Image committed. With this change, bdrv_find_backing_image() must look at whether the user has overridden a BDS's backing file. If so, it can no longer use bs->backing_file, but must instead compare the given filename against the backing node's filename directly. Note that this changes the QAPI output for a node's backing_file. We had very inconsistent output there (sometimes what the image header said, sometimes the actual filename of the backing image). This inconsistent output was effectively useless, so we have to decide one way or the other. Considering that bs->backing_file usually at runtime contained the path to the image relative to qemu's CWD (or absolute), this patch changes QAPI's backing_file to always report the bs->backing->bs->filename from now on. If you want to receive the image header information, you have to refer to full-backing-filename. This necessitates a change to iotest 228. The interesting information it really wanted is the image header, and it can get that now, but it has to use full-backing-filename instead of backing_file. Because of this patch's changes to bs->backing_file's behavior, we also need some reference output changes. Along with the changes to bs->backing_file, stop updating BDS.backing_format in bdrv_backing_attach() as well. This necessitates a change to the reference output of iotest 191. iotest 245 changes in behavior: With the backing node no longer overriding the parent node's backing_file string, you can now omit the @backing option when reopening a node with neither a default nor a current backing file even if it used to have a backing node at some point. Signed-off-by: Max Reitz --- include/block/block_int.h | 19 ++++++++++++++----- block.c | 35 ++++++++++++++++++++++++++++------- block/qapi.c | 7 ++++--- qemu-img.c | 12 ++++++++++-- tests/qemu-iotests/191.out | 1 - tests/qemu-iotests/228 | 6 +++--- tests/qemu-iotests/228.out | 6 +++--- tests/qemu-iotests/245 | 4 +++- 8 files changed, 65 insertions(+), 25 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 76c7c0a111..69524bc712 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -760,11 +760,20 @@ struct BlockDriverState { bool walking_aio_notifiers; /* to make removal during iteration safe */ =20 char filename[PATH_MAX]; - char backing_file[PATH_MAX]; /* if non zero, the image is a diff of - this file image */ - /* The backing filename indicated by the image header; if we ever - * open this file, then this is replaced by the resulting BDS's - * filename (i.e. after a bdrv_refresh_filename() run). */ + /* + * If not empty, this image is a diff in relation to backing_file. + * Note that this is the name given in the image header and + * therefore may or may not be equal to .backing->bs->filename. + * If this field contains a relative path, it is to be resolved + * relatively to the overlay's location. + */ + char backing_file[PATH_MAX]; + /* + * The backing filename indicated by the image header. Contrary + * to backing_file, if we ever open this file, auto_backing_file + * is replaced by the resulting BDS's filename (i.e. after a + * bdrv_refresh_filename() run). + */ char auto_backing_file[PATH_MAX]; char backing_format[16]; /* if non-zero and backing_file exists */ =20 diff --git a/block.c b/block.c index 820244f52e..a4c2dda039 100644 --- a/block.c +++ b/block.c @@ -78,6 +78,8 @@ static BlockDriverState *bdrv_open_inherit(const char *fi= lename, const BdrvChildRole *child_role, Error **errp); =20 +static bool bdrv_backing_overridden(BlockDriverState *bs); + /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; =20 @@ -1046,10 +1048,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 */ @@ -5048,6 +5046,7 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, char *backing_file_full =3D NULL; char *filename_tmp =3D NULL; int is_protocol =3D 0; + bool filenames_refreshed =3D false; BlockDriverState *curr_bs =3D NULL; BlockDriverState *retval =3D NULL; =20 @@ -5072,9 +5071,31 @@ BlockDriverState *bdrv_find_backing_image(BlockDrive= rState *bs, { BlockDriverState *bs_below =3D bdrv_backing_chain_next(curr_bs); =20 - /* If either of the filename paths is actually a protocol, then - * compare unmodified paths; otherwise make paths relative */ - if (is_protocol || path_has_protocol(curr_bs->backing_file)) { + if (bdrv_backing_overridden(curr_bs)) { + /* + * If the backing file was overridden, we can only compare + * directly against the backing node's filename. + */ + + if (!filenames_refreshed) { + /* + * This will automatically refresh all of the + * filenames in the rest of the backing chain, so we + * only need to do this once. + */ + bdrv_refresh_filename(bs_below); + filenames_refreshed =3D true; + } + + if (strcmp(backing_file, bs_below->filename) =3D=3D 0) { + retval =3D bs_below; + break; + } + } else if (is_protocol || path_has_protocol(curr_bs->backing_file)= ) { + /* + * If either of the filename paths is actually a protocol, then + * compare unmodified paths; otherwise make paths relative. + */ char *backing_file_full_ret; =20 if (strcmp(backing_file, curr_bs->backing_file) =3D=3D 0) { diff --git a/block/qapi.c b/block/qapi.c index e026d27077..d0c895808a 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -43,7 +43,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, BlockDriverState *bs, Error **errp) { ImageInfo **p_image_info; - BlockDriverState *bs0; + BlockDriverState *bs0, *backing; BlockDeviceInfo *info; =20 if (!bs->drv) { @@ -72,9 +72,10 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *bl= k, info->node_name =3D g_strdup(bs->node_name); } =20 - if (bs->backing_file[0]) { + backing =3D bdrv_filtered_cow_bs(bs); + if (backing) { info->has_backing_file =3D true; - info->backing_file =3D g_strdup(bs->backing_file); + info->backing_file =3D g_strdup(backing->filename); } =20 info->detect_zeroes =3D bs->detect_zeroes; diff --git a/qemu-img.c b/qemu-img.c index bcfbb743fc..836e22061c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3305,7 +3305,7 @@ static int img_rebase(int argc, char **argv) =20 /* For safe rebasing we need to compare old and new backing file */ if (!unsafe) { - char backing_name[PATH_MAX]; + char *backing_name; QDict *options =3D NULL; =20 if (bs->backing_format[0] !=3D '\0') { @@ -3319,16 +3319,24 @@ static int img_rebase(int argc, char **argv) } qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true); } - bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name)); + backing_name =3D bdrv_get_full_backing_filename(bs, &local_err); + if (local_err) { + error_reportf_err(local_err, + "Could not resolve old backing file name: "); + ret =3D -1; + goto out; + } blk_old_backing =3D blk_new_open(backing_name, NULL, options, src_flags, &local_err); if (!blk_old_backing) { error_reportf_err(local_err, "Could not open old backing file '%s': ", backing_name); + g_free(backing_name); ret =3D -1; goto out; } + g_free(backing_name); =20 if (out_baseimg[0]) { const char *overlay_filename; diff --git a/tests/qemu-iotests/191.out b/tests/qemu-iotests/191.out index 3fc92bb56e..0b3c216b0c 100644 --- a/tests/qemu-iotests/191.out +++ b/tests/qemu-iotests/191.out @@ -605,7 +605,6 @@ wrote 65536/65536 bytes at offset 1048576 "backing-filename": "TEST_DIR/t.IMGFMT.base", "dirty-flag": false }, - "backing-filename-format": "IMGFMT", "virtual-size": 67108864, "filename": "TEST_DIR/t.IMGFMT.ovl3", "cluster-size": 65536, diff --git a/tests/qemu-iotests/228 b/tests/qemu-iotests/228 index 9a50afd205..a1f3187212 100755 --- a/tests/qemu-iotests/228 +++ b/tests/qemu-iotests/228 @@ -34,7 +34,7 @@ def log_node_info(node): =20 log('bs->filename: ' + node['image']['filename'], filters=3D[filter_testfiles, filter_imgfmt]) - log('bs->backing_file: ' + node['backing_file'], + log('bs->backing_file: ' + node['image']['full-backing-filename'], filters=3D[filter_testfiles, filter_imgfmt]) =20 if 'backing-image' in node['image']: @@ -70,8 +70,8 @@ with iotests.FilePath('base.img') as base_img_path, \ }, filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) =20 - # Filename should be plain, and the backing filename should not - # contain the "file:" prefix + # Filename should be plain, and the backing node filename should + # not contain the "file:" prefix log_node_info(vm.node_info('node0')) =20 vm.qmp_log('blockdev-del', node_name=3D'node0') diff --git a/tests/qemu-iotests/228.out b/tests/qemu-iotests/228.out index 4217df24fe..8c82009abe 100644 --- a/tests/qemu-iotests/228.out +++ b/tests/qemu-iotests/228.out @@ -4,7 +4,7 @@ {"return": {}} =20 bs->filename: TEST_DIR/PID-top.img -bs->backing_file: TEST_DIR/PID-base.img +bs->backing_file: file:TEST_DIR/PID-base.img bs->backing->bs->filename: TEST_DIR/PID-base.img =20 {"execute": "blockdev-del", "arguments": {"node-name": "node0"}} @@ -41,7 +41,7 @@ bs->backing->bs->filename: TEST_DIR/PID-base.img {"return": {}} =20 bs->filename: TEST_DIR/PID-top.img -bs->backing_file: TEST_DIR/PID-base.img +bs->backing_file: file:TEST_DIR/PID-base.img bs->backing->bs->filename: TEST_DIR/PID-base.img =20 {"execute": "blockdev-del", "arguments": {"node-name": "node0"}} @@ -55,7 +55,7 @@ bs->backing->bs->filename: TEST_DIR/PID-base.img {"return": {}} =20 bs->filename: json:{"backing": {"driver": "null-co"}, "driver": "IMGFMT", = "file": {"driver": "file", "filename": "TEST_DIR/PID-top.img"}} -bs->backing_file: null-co:// +bs->backing_file: TEST_DIR/PID-base.img bs->backing->bs->filename: null-co:// =20 {"execute": "blockdev-del", "arguments": {"node-name": "node0"}} diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index a04c6235c1..1b191d4da7 100644 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -722,7 +722,9 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # Detach hd2 from hd0. self.reopen(opts, {'backing': None}) - self.reopen(opts, {}, "backing is missing for 'hd0'") + + # Without a backing file, we can omit 'backing' again + self.reopen(opts) =20 # Remove both hd0 and hd2 result =3D self.vm.qmp('blockdev-del', conv_keys =3D True, node_na= me =3D 'hd0') --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554928232; cv=none; d=zoho.com; s=zohoarc; b=EiTrDOo104XDGdABHzOxFU0JcUKMCwIeKdSTiQ6KKE831z2ogWawgihnyez7IVFVV9YoNqUZZG3MzJUKu0M9OyxvLZqNJExpQUwKOBr1Mkzop1NTm1xceJRU63UN6Wd/B7cig+OpKHO2RvJW0WnSbi2dx6mOdBNuTY1Qj8fPY/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554928232; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=CeEVaw5YvyKqnEJHzm8L1vP3ke8gB7UTp14FbxVLoA0=; b=hoJWYYPNCvf8nrjxLFxRabctGe4clXyWg4fRc8XTfUuVEfmItSqKdBEDYNrW14R0uMbQzyCHAUV1cHzPBLzxVUugm/1ohPJB19jdGaW1XGalpdFwl0/1A4OfLlYBBfAbiTdIaaUuzLi/2z2zrq4ax3VivLaucCv+99NEscrF/fc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554928232153452.8293998426259; Wed, 10 Apr 2019 13:30:32 -0700 (PDT) Received: from localhost ([127.0.0.1]:37472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJrZ-000741-6j for importer@patchew.org; Wed, 10 Apr 2019 16:30:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiV-00070X-4U for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiT-0004SH-Nb for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41864) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiQ-0004O4-0y; Wed, 10 Apr 2019 16:21: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 mx1.redhat.com (Postfix) with ESMTPS id 3DEDB3078AAE; Wed, 10 Apr 2019 20:21:01 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C810F5D9D5; Wed, 10 Apr 2019 20:21:00 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:30 +0200 Message-Id: <20190410202033.28617-9-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 10 Apr 2019 20:21:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 08/11] iotests: Add filter commit test cases X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch adds some tests on how commit copes with filter nodes. Signed-off-by: Max Reitz --- tests/qemu-iotests/040 | 130 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/040.out | 4 +- 2 files changed, 132 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index b81133a474..dc3fe57fbd 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -394,5 +394,135 @@ class TestReopenOverlay(ImageCommitTestCase): def test_reopen_overlay(self): self.run_commit_test(self.img1, self.img0) =20 +class TestCommitWithFilters(iotests.QMPTestCase): + img0 =3D os.path.join(iotests.test_dir, '0.img') + img1 =3D os.path.join(iotests.test_dir, '1.img') + img2 =3D os.path.join(iotests.test_dir, '2.img') + img3 =3D os.path.join(iotests.test_dir, '3.img') + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, self.img0, '1M') + qemu_img('create', '-f', iotests.imgfmt, self.img1, '1M') + qemu_img('create', '-f', iotests.imgfmt, self.img2, '1M') + qemu_img('create', '-f', iotests.imgfmt, self.img3, '1M') + + 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() + 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 for the block-commit parameters + def get_filename(self, node): + return self.vm.node_info(node)['image']['filename'] + + def test_filterless_commit(self): + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + top=3Dself.get_filename('cow-2'), + base=3Dself.get_filename('cow-1')) + self.assert_qmp(result, 'return', {}) + self.wait_until_completed(drive=3D'commit') + + def test_commit_through_filter(self): + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + top=3Dself.get_filename('cow-1'), + base=3Dself.get_filename('cow-0')) + # Cannot commit through explicitly added filters (yet, + # although in the future we probably want to make users use + # blockdev-copy for this) + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Cannot commit through expli= cit filter nodes') + + def test_filtered_active_commit_with_filter(self): + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + base=3Dself.get_filename('cow-2')) + # Not specifying @top means active commit, so including the + # filter on top (which is not allowed right now) + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', 'Cannot commit through expli= cit filter nodes') + + def test_filtered_active_commit_without_filter(self): + cow3_name =3D self.get_filename('cow-3') + + self.assert_no_active_block_jobs() + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top-filter', + top=3Dcow3_name, + base=3Dself.get_filename('cow-2')) + # This is how you'd want to specify committing img3 into img2 + # disregarding the filter on top of img3 -- but that does not + # work, because you can only specify names of backing files + # (and img3 is not a backing file). The solution for this + # would be for block-commit to accept node names. + # Note that even if it did work, the above command would + # result in a non-active commit, because img3 is not the top + # node. Which is wrong, because img3 can still be written to, + # so it should be an active commit, but that is a different + # story. + self.assert_qmp(result, 'error/class', 'GenericError') + self.assert_qmp(result, 'error/desc', + 'Top image file %s not found' % cow3_name) + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 802ffaa0c0..220a5fa82c 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -........................................... +............................................... ---------------------------------------------------------------------- -Ran 43 tests +Ran 47 tests =20 OK --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554927983; cv=none; d=zoho.com; s=zohoarc; b=HCPpo6q8jAcWXFvHMO07s+1R3gNcYpJSHM1ZJgzu5Q2G8vr/pNalPK0fdWg1+8PF9Z5GZmS4K9Z3LuWVGxYlpH6A++r13PiiIkK6oqbW4TLAkNvTL48wFoMcXqgzr+qCiv51P69zQ8ZNxXdIvBd7dqELqY7ERQzPMndsoQxX+xQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554927983; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lUsfYMQQbyoqpKYzK0AceOIDJvt1KPMUSjflLByGapw=; b=nyYocdNCHgZDYAIECpuMG/0yf3esDbs7nnzLDCu6/LicU4BAAwvv6QQnLXtG3x5jljmeY2GU8GxeM7+lRvbUBvlMQW5Go/ceAmlgsmobF8cmDebhzBzPH+PYdWnj/kz6HjWKNdHeS3cIia9U2dSlE3NWWtUuib81M5Rgmdrn0p4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554927983587779.7216628110658; Wed, 10 Apr 2019 13:26:23 -0700 (PDT) Received: from localhost ([127.0.0.1]:37405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJnY-0003bM-Et for importer@patchew.org; Wed, 10 Apr 2019 16:26:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiX-00073S-BV for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiW-0004UP-1N for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60074) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiS-0004Qr-Jp; Wed, 10 Apr 2019 16:21:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D225830A223D; Wed, 10 Apr 2019 20:21:03 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 359DB5D71E; Wed, 10 Apr 2019 20:21:03 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:31 +0200 Message-Id: <20190410202033.28617-10-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 10 Apr 2019 20:21:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 09/11] iotests: Add filter mirror test cases X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch adds some test cases how mirroring relates to filters. One of them tests what happens when you mirror off a filtered COW node, two others use the mirror filter node as basically our only example of an implicitly created filter node so far (besides the commit filter). Signed-off-by: Max Reitz --- tests/qemu-iotests/041 | 146 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/041.out | 4 +- 2 files changed, 147 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 0c1432f189..c2b5299f62 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -20,8 +20,9 @@ =20 import time import os +import json import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_img_pipe, qemu_io =20 backing_img =3D os.path.join(iotests.test_dir, 'backing.img') target_backing_img =3D os.path.join(iotests.test_dir, 'target-backing.img') @@ -1191,5 +1192,148 @@ class TestReplaces(iotests.QMPTestCase): os.remove(test_img) os.remove(target_img) =20 +# Tests for mirror with filters (and how the mirror filter behaves, as +# an example for an implicit filter) +class TestFilters(iotests.QMPTestCase): + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, backing_img, '1M') + qemu_img('create', '-f', iotests.imgfmt, '-b', backing_img, test_i= mg) + qemu_img('create', '-f', iotests.imgfmt, '-b', backing_img, target= _img) + + qemu_io('-c', 'write -P 1 0 512k', backing_img) + qemu_io('-c', 'write -P 2 512k 512k', test_img) + + self.vm =3D iotests.VM() + self.vm.launch() + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'target', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + }, + 'backing': None + }) + self.assert_qmp(result, 'return', {}) + + self.filterless_chain =3D { + 'node-name': 'source', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + }, + 'backing': { + 'node-name': 'backing', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': backing_img + } + } + } + + def tearDown(self): + self.vm.shutdown() + + os.remove(test_img) + os.remove(target_img) + os.remove(backing_img) + + def test_cor(self): + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'filter', + 'driver': 'copy-on-read', + 'file': self.filterless_chain + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'filter', + target=3D'target', + sync=3D'top') + self.assert_qmp(result, 'return', {}) + + self.complete_and_wait('mirror') + + self.vm.qmp('blockdev-del', node_name=3D'target') + + target_map =3D qemu_img_pipe('map', '--output=3Djson', target_img) + target_map =3D json.loads(target_map) + + assert target_map[0]['start'] =3D=3D 0 + assert target_map[0]['length'] =3D=3D 512 * 1024 + assert target_map[0]['depth'] =3D=3D 1 + + assert target_map[1]['start'] =3D=3D 512 * 1024 + assert target_map[1]['length'] =3D=3D 512 * 1024 + assert target_map[1]['depth'] =3D=3D 0 + + def test_implicit_mirror_filter(self): + result =3D self.vm.qmp('blockdev-add', **self.filterless_chain) + self.assert_qmp(result, 'return', {}) + + # We need this so we can query from above the mirror node + result =3D self.vm.qmp('device_add', + driver=3D'virtio-blk', + id=3D'virtio', + bus=3D'pci.0', + drive=3D'source') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + sync=3D'top') + self.assert_qmp(result, 'return', {}) + + # The mirror filter is now an implicit node, so it should be + # invisible when querying the backing chain + device_info =3D self.vm.qmp('query-block')['return'][0] + assert device_info['qdev'] =3D=3D '/machine/peripheral/virtio/virt= io-backend' + + assert device_info['inserted']['node-name'] =3D=3D 'source' + + image_info =3D device_info['inserted']['image'] + assert image_info['filename'] =3D=3D test_img + assert image_info['backing-image']['filename'] =3D=3D backing_img + + self.complete_and_wait('mirror') + + def test_explicit_mirror_filter(self): + # Same test as above, but this time we give the mirror filter + # a node-name so it will not be invisible + result =3D self.vm.qmp('blockdev-add', **self.filterless_chain) + self.assert_qmp(result, 'return', {}) + + # We need this so we can query from above the mirror node + result =3D self.vm.qmp('device_add', + driver=3D'virtio-blk', + id=3D'virtio', + bus=3D'pci.0', + drive=3D'source') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'source', + target=3D'target', + sync=3D'top', + filter_node_name=3D'mirror-filter') + self.assert_qmp(result, 'return', {}) + + # With a node-name given to it, the mirror filter should now + # be visible + device_info =3D self.vm.qmp('query-block')['return'][0] + assert device_info['qdev'] =3D=3D '/machine/peripheral/virtio/virt= io-backend' + + assert device_info['inserted']['node-name'] =3D=3D 'mirror-filter' + + self.complete_and_wait('mirror') + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index 2c448b4239..ffc779b4d1 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= ................ +..........................................................................= ................... ---------------------------------------------------------------------- -Ran 90 tests +Ran 93 tests =20 OK --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1554927980; cv=none; d=zoho.com; s=zohoarc; b=QvPTZpv9/jR52+HwLiyvbJOpXANHsxGiMHdSbKg258XrrRNomphxjLvrGxUdirkwiWzU1Pet7biQ5j+JPx1dSMg9TbqwSyM+SMxq4/SkZnZOcRcskVZY9skfnS1qeG95LI1CkttjyQ6fDdhpNXZ4qFMmUaBJe7Tl9M3jPdmY8EE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554927980; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=s9EnVG25PlDGa2YW8UlmN3TTNKnyP794TJmdvQIRHSw=; b=FWzNcQ20l49GkF/vZbAFnHJiATjJk3//j8dCCV0DxV5xnQH2XbyaBtXrxnAV2ajn2p5PuXA6HVgU4DMwgS6dWxqc0FV5ZNF9lpOddYyqReTKZtSIjfWF3nfIsZViVATQUbt7WuCC7wFMlgmB/YuCFJQkzxeJHVs6E3KqhYSW0WQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554927980751161.54817981537315; Wed, 10 Apr 2019 13:26:20 -0700 (PDT) Received: from localhost ([127.0.0.1]:37403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJnU-0003Jg-M8 for importer@patchew.org; Wed, 10 Apr 2019 16:26:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJiY-000755-TD for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJiX-0004Vc-R5 for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiV-0004Sn-2V; Wed, 10 Apr 2019 16:21:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D07C3007C2F; Wed, 10 Apr 2019 20:21:06 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7A61619A2; Wed, 10 Apr 2019 20:21:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:32 +0200 Message-Id: <20190410202033.28617-11-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 10 Apr 2019 20:21:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 10/11] iotests: Add test for commit in sub directory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add a test for committing an overlay in a sub directory to one of the images in its backing chain, using both relative and absolute filenames. Signed-off-by: Max Reitz --- tests/qemu-iotests/020 | 36 ++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/020.out | 10 ++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 index 71fa753b4e..cfcbc0cf45 100755 --- a/tests/qemu-iotests/020 +++ b/tests/qemu-iotests/020 @@ -31,6 +31,11 @@ _cleanup() _cleanup_test_img rm -f "$TEST_IMG.base" rm -f "$TEST_IMG.orig" + + rm -f "$TEST_DIR/subdir/t.$IMGFMT.base" + rm -f "$TEST_DIR/subdir/t.$IMGFMT.mid" + rm -f "$TEST_DIR/subdir/t.$IMGFMT" + rmdir "$TEST_DIR/subdir" &> /dev/null } trap "_cleanup; exit \$status" 0 1 2 3 15 =20 @@ -134,6 +139,37 @@ $QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_= io $QEMU_IMG commit "$TEST_IMG" _cleanup =20 + +echo +echo 'Testing commit in sub-directory with relative filenames' +echo + +pushd "$TEST_DIR" > /dev/null + +mkdir subdir + +TEST_IMG=3D"subdir/t.$IMGFMT.base" _make_test_img 1M +TEST_IMG=3D"subdir/t.$IMGFMT.mid" _make_test_img -b "t.$IMGFMT.base" +TEST_IMG=3D"subdir/t.$IMGFMT" _make_test_img -b "t.$IMGFMT.mid" + +# Should work +$QEMU_IMG commit -b "t.$IMGFMT.mid" "subdir/t.$IMGFMT" + +# Might theoretically work, but does not in practice (we have to +# decide between this and the above; and since we always represent +# backing file names as relative to the overlay, we go for the above) +$QEMU_IMG commit -b "subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT" 2>&1 | \ + _filter_imgfmt + +# This should work as well +$QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT" + +popd > /dev/null + +# Now let's try with just absolute filenames +$QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" \ + "$TEST_DIR/subdir/t.$IMGFMT" + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/020.out b/tests/qemu-iotests/020.out index 4b722b2dd0..228c37dded 100644 --- a/tests/qemu-iotests/020.out +++ b/tests/qemu-iotests/020.out @@ -1094,4 +1094,14 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D= 1048576 backing_file=3Djson:{'driv wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Block job failed: No space left on device + +Testing commit in sub-directory with relative filenames + +Formatting 'subdir/t.IMGFMT.base', fmt=3DIMGFMT size=3D1048576 +Formatting 'subdir/t.IMGFMT.mid', fmt=3DIMGFMT size=3D1048576 backing_file= =3Dt.IMGFMT.base +Formatting 'subdir/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file=3Dt= .IMGFMT.mid +Image committed. +qemu-img: Did not find 'subdir/t.IMGFMT.mid' in the backing chain of 'subd= ir/t.IMGFMT' +Image committed. +Image committed. *** done --=20 2.20.1 From nobody Sat May 18 17:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) 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=1554928113; cv=none; d=zoho.com; s=zohoarc; b=cEsnkB4mlIxNPsBzbfcOf7Q+/mflkRBlUsRcY1VChJbvFMcyPdU8bxk0BPjDEQ9KuUx1evlevkCdOIo9E4puQOBJhhjCI1X7d3U7RGDKPuIQ3f76KZAgor7ScPjIe2zyCG2244L6/2/HJCx0nE4VNTF+th3yqdIkxzWYt9opzrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1554928113; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=QNTRvjcGf9DTbVCy3A4fNUkgUKLOO9pIAHEMWHXq64I=; b=KbvaWIMUsmoEvM2j0djALYvXZmlby/2242qS0wy965uP04oA80Z8yiPBPvjQSe/AisHWPWIQCd/uDOo8VluDS6KuHLu4PyA98PxnQajpbXsK49fOsp9jm/Mb6koD+1CYyWQsRPgL3dGGQpgXWV+kurk9GAVRGVbJSAT6ip7conY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554928113527733.4147944192066; Wed, 10 Apr 2019 13:28:33 -0700 (PDT) Received: from localhost ([127.0.0.1]:37427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJpR-0005Mv-VB for importer@patchew.org; Wed, 10 Apr 2019 16:28:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEJib-000783-6u for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEJia-0004Wx-3v for qemu-devel@nongnu.org; Wed, 10 Apr 2019 16:21:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEJiX-0004Uw-DA; Wed, 10 Apr 2019 16:21:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB62F89C42; Wed, 10 Apr 2019 20:21:08 +0000 (UTC) Received: from localhost (unknown [10.40.205.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C0F45D9D5; Wed, 10 Apr 2019 20:21:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 10 Apr 2019 22:20:33 +0200 Message-Id: <20190410202033.28617-12-mreitz@redhat.com> In-Reply-To: <20190410202033.28617-1-mreitz@redhat.com> References: <20190410202033.28617-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 10 Apr 2019 20:21:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 11/11] iotests: Test committing to overridden backing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- tests/qemu-iotests/040 | 61 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/040.out | 4 +-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index dc3fe57fbd..155c1d8c23 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -524,5 +524,66 @@ class TestCommitWithFilters(iotests.QMPTestCase): self.assert_qmp(result, 'error/desc', 'Top image file %s not found' % cow3_name) =20 +class TestCommitWithOverriddenBacking(iotests.QMPTestCase): + img_base_a =3D os.path.join(iotests.test_dir, 'base_a.img') + img_base_b =3D os.path.join(iotests.test_dir, 'base_b.img') + img_top =3D os.path.join(iotests.test_dir, 'top.img') + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, self.img_base_a, '1M') + qemu_img('create', '-f', iotests.imgfmt, self.img_base_b, '1M') + qemu_img('create', '-f', iotests.imgfmt, '-b', self.img_base_a, \ + self.img_top) + + self.vm =3D iotests.VM() + self.vm.launch() + + # Use base_b instead of base_a as the backing of top + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'top', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img_top + }, + 'backing': { + 'node-name': 'base', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': self.img_base_b + } + } + }) + self.assert_qmp(result, 'return', {}) + + def tearDown(self): + self.vm.shutdown() + os.remove(self.img_top) + os.remove(self.img_base_a) + os.remove(self.img_base_b) + + def test_commit_to_a(self): + # Try committing to base_a (which should fail, as top's + # backing image is base_b instead) + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top', + base=3Dself.img_base_a) + self.assert_qmp(result, 'error/class', 'GenericError') + + def test_commit_to_b(self): + # Try committing to base_b (which should work, since that is + # actually top's backing image) + result =3D self.vm.qmp('block-commit', + job_id=3D'commit', + device=3D'top', + base=3Dself.img_base_b) + self.assert_qmp(result, 'return', {}) + + self.vm.event_wait('BLOCK_JOB_READY') + self.vm.qmp('block-job-complete', device=3D'commit') + self.vm.event_wait('BLOCK_JOB_COMPLETED') + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 220a5fa82c..bbcbc202a0 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -............................................... +................................................. ---------------------------------------------------------------------- -Ran 47 tests +Ran 49 tests =20 OK --=20 2.20.1