From nobody Mon Feb 9 01:21:12 2026 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=1584041352; cv=none; d=zohomail.com; s=zohoarc; b=kOst06arVZhC0Zvdr97sLxJru18UiwFAztENVbMjATc7SGXKgJ5RKSOVDXCN1zQrOIpcnqqQ8nzVioENDOOy29swpZ0Yg8yosWLKpSz4UOSvhdvLKM+6BuFc3dshU00ZutLjPYP0mESSsUHK1oilc8TQNo0okVxL3NGazhbZvx8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584041352; 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=SM4DqXapyl+nLTWQu/+pgke4fntoLVf9Sz4VN1LyjwU=; b=KbutQZHuTPf2x5eccZPWflhi3v8um3bAD5/qeeyAhJOUPVixnaZx43GaERdsu2qJ8cE+YdZe5NzrlQvikSIUtFFdaynvJbGOljZUuJ9SxEdvEXR9IYo5NwwMD09kiIfs4AoIYIH4lVwcXSqIQ+1SqsT3YwtzPCY5VoC10MY9sUU= 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 158404135215073.59600040348596; Thu, 12 Mar 2020 12:29:12 -0700 (PDT) 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-277-eQ2LviGRPHazYiVFjdUQwA-1; Thu, 12 Mar 2020 15:29:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA7E3107B271; Thu, 12 Mar 2020 19:29:02 +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 8EDBE5C3F8; Thu, 12 Mar 2020 19:29:02 +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 3DEBF18089CD; Thu, 12 Mar 2020 19:29:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02CJT1gl003476 for ; Thu, 12 Mar 2020 15:29:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38B1B5DA83; Thu, 12 Mar 2020 19:29:01 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-177.phx2.redhat.com [10.3.116.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13F1D5DA76; Thu, 12 Mar 2020 19:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584041351; 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=SM4DqXapyl+nLTWQu/+pgke4fntoLVf9Sz4VN1LyjwU=; b=Y7+iQwZHxCKLW5sZ2xqWqluOUQBspP5FlcoC0fMKu8Nr/Vn09tqNMpfQ8zt2coqlnh/0x9 BwMC7bZ5ynfl3sJHGLEN8h74R4j+2ed9ULiY0Gp+xI0/yM9SH/liut79PwaYxfF3bLHWht nkidTock+U4lk4mIygelURc53dkKITM= X-MC-Unique: eQ2LviGRPHazYiVFjdUQwA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 6/7] block: Add support to warn on backing file change without format Date: Thu, 12 Mar 2020 14:28:21 -0500 Message-Id: <20200312192822.3739399-7-eblake@redhat.com> In-Reply-To: <20200312192822.3739399-1-eblake@redhat.com> References: <20200312192822.3739399-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, =?UTF-8?q?J=C3=A1n=20Tomko?= , 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.16 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: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- 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 e569a4d747a0..fe77a62c7284 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 a2542c977b91..cd3277ab86fd 100644 --- a/block.c +++ b/block.c @@ -1317,7 +1317,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"); } @@ -4560,8 +4561,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; @@ -4575,6 +4576,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 97a1757156bb..592112edf379 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3507,7 +3507,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 aa2e7af98e37..310ccbaa4cfd 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 fa8630cb412d..5bc9d78563ab 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3692,7 +3692,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 afddf33f08c6..4ca1d2db7307 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3639,9 +3639,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