From nobody Sun Oct 5 21:16:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582771205; cv=none; d=zohomail.com; s=zohoarc; b=e6KF9cowt8kPZ2P80pkbEb5XNnSUkSzLkJn/3DTmi8KLsH4Gn0PEJbHzILCXer0TkTqmg3I3p7S90VEKaYmhh3ejmVgmKM6MWTha0XotdIvlgC2p9TrozWAB9wU+qXOhZk+3dZ7DrHwtCKmunyeZFJFFMBaBweFDs/2NG6IhNuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582771205; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=THhGaWkj5GESw6EjHQZMczADkbmjRWoKDgfeYscvOyg=; b=J06xu0kj3LNLF978KRQwOhNiHaDtthIWADuOJq9gJis/pZbLnuyiTBYkhCjgj/+m9pL909clvtHXuE9DFfpo+TRrTQM3Kn0R3masQWxbhQ4HuX6h0zr99U08wsmT47/4gFs6l0tJ5tL9/sf0LQGVP7SfigGEHDbWDC6XG73hCZo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1582771205585615.8339604314357; Wed, 26 Feb 2020 18:40:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-37-nmVj1iV7MHutLPAFkdQJ7g-1; Wed, 26 Feb 2020 21:40:02 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C1CF1902EA0; Thu, 27 Feb 2020 02:39:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1175460BE1; Thu, 27 Feb 2020 02:39:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9646E18089CF; Thu, 27 Feb 2020 02:39:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01R2db7v023496 for ; Wed, 26 Feb 2020 21:39:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7E0728C066; Thu, 27 Feb 2020 02:39:37 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1DE58AC4D; Thu, 27 Feb 2020 02:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582771204; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=THhGaWkj5GESw6EjHQZMczADkbmjRWoKDgfeYscvOyg=; b=XsbtAcTCSzRc+Vj/RygXYdHvnwp0yZttJHvW2y6obhkyOANy+pzjbAVWd6jVGvYcZHOEWh 3d0pyQIHVETkzmCTHCaNshMkcR/b60cM2WsAjh8lYWQvE4ZV9CR3qu1Oc6yIUgK67vI7An yFS9xkk1mV+PMptiekvM1ne8rq6H1LI= X-MC-Unique: nmVj1iV7MHutLPAFkdQJ7g-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] block: Add support to warn on backing file change without format Date: Wed, 26 Feb 2020 20:39:27 -0600 Message-Id: <20200227023928.1021959-3-eblake@redhat.com> In-Reply-To: <20200227023928.1021959-1-eblake@redhat.com> References: <20200227023928.1021959-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , pkrempa@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, mreitz@redhat.com, John Snow X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" For now, this is a mechanical addition; all callers pass false. But the next patch will use it to improve 'qemu-img rebase -u' when selecting a backing file with no format. Signed-off-by: Eric Blake Reviewed-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- include/block/block.h | 4 ++-- block.c | 13 ++++++++++--- block/qcow2.c | 2 +- block/stream.c | 2 +- blockdev.c | 3 ++- qemu-img.c | 4 ++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index cd6b5b95aad2..8b1dd94f7629 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -350,8 +350,8 @@ BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOp= ts *opts, void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); void bdrv_refresh_limits(BlockDriverState *bs, Error **errp); int bdrv_commit(BlockDriverState *bs); -int bdrv_change_backing_file(BlockDriverState *bs, - const char *backing_file, const char *backing_fmt); +int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_fil= e, + const char *backing_fmt, bool warn); void bdrv_register(BlockDriver *bdrv); int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, const char *backing_file_str); diff --git a/block.c b/block.c index 1bdb9c679d77..10c2a34e7c00 100644 --- a/block.c +++ b/block.c @@ -1290,7 +1290,8 @@ static int bdrv_backing_update_filename(BdrvChild *c,= BlockDriverState *base, } ret =3D bdrv_change_backing_file(parent, filename, - base->drv ? base->drv->format_name : ""= ); + base->drv ? base->drv->format_name : "", + false); if (ret < 0) { error_setg_errno(errp, -ret, "Could not update backing file link"); } @@ -4505,8 +4506,8 @@ int bdrv_check(BlockDriverState *bs, * image file header * -ENOTSUP - format driver doesn't support changing the backing file */ -int bdrv_change_backing_file(BlockDriverState *bs, - const char *backing_file, const char *backing_fmt) +int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_fil= e, + const char *backing_fmt, bool warn) { BlockDriver *drv =3D bs->drv; int ret; @@ -4520,6 +4521,12 @@ int bdrv_change_backing_file(BlockDriverState *bs, return -EINVAL; } + if (warn && backing_file && !backing_fmt) { + warn_report("Deprecated use of backing file without explicit " + "backing format, use of this image requires " + "potentially unsafe format probing"); + } + if (drv->bdrv_change_backing_file !=3D NULL) { ret =3D drv->bdrv_change_backing_file(bs, backing_file, backing_fm= t); } else { diff --git a/block/qcow2.c b/block/qcow2.c index 3c754f616bf8..05a2973a3086 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3502,7 +3502,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) } ret =3D bdrv_change_backing_file(blk_bs(blk), qcow2_opts->backing_= file, - backing_format); + backing_format, false); if (ret < 0) { error_setg_errno(errp, -ret, "Could not assign backing file '%= s' " "with format '%s'", qcow2_opts->backing_file, diff --git a/block/stream.c b/block/stream.c index 5562ccbf577a..7c4d8ee0bcf1 100644 --- a/block/stream.c +++ b/block/stream.c @@ -78,7 +78,7 @@ static int stream_prepare(Job *job) } } bdrv_set_backing_hd(bs, base, &local_err); - ret =3D bdrv_change_backing_file(bs, base_id, base_fmt); + ret =3D bdrv_change_backing_file(bs, base_id, base_fmt, false); if (local_err) { error_report_err(local_err); return -EPERM; diff --git a/blockdev.c b/blockdev.c index 011dcfec2770..c88f27941d46 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4299,7 +4299,8 @@ void qmp_change_backing_file(const char *device, } ret =3D bdrv_change_backing_file(image_bs, backing_file, - image_bs->drv ? image_bs->drv->format_name = : ""); + image_bs->drv ? image_bs->drv->format_n= ame : "", + false); if (ret < 0) { error_setg_errno(errp, -ret, "Could not change backing file to '%s= '", diff --git a/qemu-img.c b/qemu-img.c index 804630a368d6..b9375427404d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3637,9 +3637,9 @@ static int img_rebase(int argc, char **argv) * doesn't change when we switch the backing file. */ if (out_baseimg && *out_baseimg) { - ret =3D bdrv_change_backing_file(bs, out_baseimg, out_basefmt); + ret =3D bdrv_change_backing_file(bs, out_baseimg, out_basefmt, fal= se); } else { - ret =3D bdrv_change_backing_file(bs, NULL, NULL); + ret =3D bdrv_change_backing_file(bs, NULL, NULL, false); } if (ret =3D=3D -ENOSPC) { --=20 2.25.1