From nobody Wed Dec 17 21:47:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507307259509538.410612348079; Fri, 6 Oct 2017 09:27:39 -0700 (PDT) Received: from localhost ([::1]:45779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0VTE-0003k6-IR for importer@patchew.org; Fri, 06 Oct 2017 12:27:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0UyF-00010Y-6u for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0UyA-0003fL-Tx for qemu-devel@nongnu.org; Fri, 06 Oct 2017 11:55:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37850) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e0Uy7-0003Zp-NV; Fri, 06 Oct 2017 11:55:19 -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 A1465C047B70; Fri, 6 Oct 2017 15:55:18 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.118.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5138167588; Fri, 6 Oct 2017 15:55:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A1465C047B70 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 6 Oct 2017 17:54:01 +0200 Message-Id: <20171006155422.10135-34-kwolf@redhat.com> In-Reply-To: <20171006155422.10135-1-kwolf@redhat.com> References: <20171006155422.10135-1-kwolf@redhat.com> 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.31]); Fri, 06 Oct 2017 15:55:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 33/54] block: Introduce BdrvChildRole.update_filename X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There is no good reason for bdrv_drop_intermediate() to know the active layer above the subchain it is operating on - even more so, because the assumption that there is a single active layer above it is not generally true. In order to prepare removal of the active parameter, use a BdrvChildRole callback to update the backing file string in the overlay image instead of directly calling bdrv_change_backing_file(). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/block_int.h | 6 ++++++ block.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 79366b94b5..7e8a206239 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -544,6 +544,12 @@ struct BdrvChildRole { =20 void (*attach)(BdrvChild *child); void (*detach)(BdrvChild *child); + + /* Notifies the parent that the filename of its child has changed (e.g. + * because the direct child was removed from the backing chain), so th= at it + * can update its reference. */ + int (*update_filename)(BdrvChild *child, BlockDriverState *new_base, + const char *filename, Error **errp); }; =20 extern const BdrvChildRole child_file; diff --git a/block.c b/block.c index ef5af81f66..ab354ba82a 100644 --- a/block.c +++ b/block.c @@ -981,6 +981,21 @@ static void bdrv_backing_options(int *child_flags, QDi= ct *child_options, *child_flags =3D flags; } =20 +static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *ba= se, + const char *filename, Error **errp) +{ + BlockDriverState *parent =3D c->opaque; + int ret; + + ret =3D bdrv_change_backing_file(parent, filename, + base->drv ? base->drv->format_name : ""= ); + if (ret < 0) { + error_setg_errno(errp, ret, "Could not update backing file link"); + } + + return ret; +} + const BdrvChildRole child_backing =3D { .get_parent_desc =3D bdrv_child_get_parent_desc, .attach =3D bdrv_backing_attach, @@ -989,6 +1004,7 @@ const BdrvChildRole child_backing =3D { .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, .inactivate =3D bdrv_child_cb_inactivate, + .update_filename =3D bdrv_backing_update_filename, }; =20 static int bdrv_open_flags(BlockDriverState *bs, int flags) @@ -3470,6 +3486,8 @@ int bdrv_drop_intermediate(BlockDriverState *active, = BlockDriverState *top, Error *local_err =3D NULL; int ret =3D -EIO; =20 + bdrv_ref(top); + if (!top->drv || !base->drv) { goto exit; } @@ -3494,11 +3512,15 @@ int bdrv_drop_intermediate(BlockDriverState *active= , BlockDriverState *top, } =20 /* success - we can delete the intermediate states, and link top->base= */ - backing_file_str =3D backing_file_str ? backing_file_str : base->filen= ame; - ret =3D bdrv_change_backing_file(new_top_bs, backing_file_str, - base->drv ? base->drv->format_name : ""= ); - if (ret) { - goto exit; + if (new_top_bs->backing->role->update_filename) { + backing_file_str =3D backing_file_str ? backing_file_str : base->f= ilename; + ret =3D new_top_bs->backing->role->update_filename(new_top_bs->bac= king, + base, backing_fil= e_str, + &local_err); + if (ret < 0) { + bdrv_set_backing_hd(new_top_bs, top, &error_abort); + goto exit; + } } =20 bdrv_set_backing_hd(new_top_bs, base, &local_err); @@ -3510,6 +3532,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, = BlockDriverState *top, =20 ret =3D 0; exit: + bdrv_unref(top); return ret; } =20 --=20 2.13.6