From nobody Sun Oct 5 21:17:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1582370687; cv=none; d=zohomail.com; s=zohoarc; b=ZWDjFZ/GdhWh8h7p/xhcOhCebBUO0DQjNozikek/Uc+I9HxWnnPDRGtIprVDezNeMJlP+yZH+rCVu5yHWtI6JZBegoAH1nsJzfdv860ox5eA0jiUut817gYTgMGfhXugUSRGj4/MNIaiaW8L4nYK94rrpwZ3xsMYE0EsaT9XUu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582370687; 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=VrXGXtnXK6Hxc8b/BQqLxgdKmKhYKWOociGZEiH8ieI=; b=E1/pq9bsY0urcTJW16F2oDMPTH+XvTyIS2Ya90Jl1zN4DARL1sTrz3kPbPB1JHfykeE5bxBLnxKkjapBxkVoGcFQ26yP5R5Wo0Xw0d/KRjbqu41fFafAIPhaG7BTZ6T7PrxdR5/L/bDJVLvIoYRjgnimcKbdX1DQhqM5Pq6tyvM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1582370687452386.16093801019076; Sat, 22 Feb 2020 03:24:47 -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-290-LMTpO4vOPfySDVDv6J25tg-1; Sat, 22 Feb 2020 06:24:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 676D718C35A0; Sat, 22 Feb 2020 11:24:37 +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 0CDD887B0A; Sat, 22 Feb 2020 11:24:37 +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 C3E0118089CD; Sat, 22 Feb 2020 11:24:36 +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 01MBNnCW032485 for ; Sat, 22 Feb 2020 06:23:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id C424C89A9C; Sat, 22 Feb 2020 11:23:49 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-90.phx2.redhat.com [10.3.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 249D784BCC; Sat, 22 Feb 2020 11:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582370686; 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=VrXGXtnXK6Hxc8b/BQqLxgdKmKhYKWOociGZEiH8ieI=; b=KOa7hPsmluwBd8G06o+1Jy7/M/QlA3fqKZC8+HeRT8hU1XSMgI+3hg/e6mInmxJgewV+Zk +WQQA+FZq5JNz8h+ibiXRLWqOHSlK6KutMxMl+PJ9qkebnCp14CW6X+5TuSpo2sgdLaK3+ tSXw1pq8LEX+V9VSe2h8fAPIPPaJAoA= X-MC-Unique: LMTpO4vOPfySDVDv6J25tg-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH 2/3] block: Add support to warn on backing file change without format Date: Sat, 22 Feb 2020 05:23:40 -0600 Message-Id: <20200222112341.4170045-3-eblake@redhat.com> In-Reply-To: <20200222112341.4170045-1-eblake@redhat.com> References: <20200222112341.4170045-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.13 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 --- block.c | 14 +++++++++++--- block/qcow2.c | 2 +- block/stream.c | 2 +- blockdev.c | 3 ++- include/block/block.h | 4 ++-- qemu-img.c | 4 ++-- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 308a91c96bde..695decbfd7b7 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"); } @@ -4508,8 +4509,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; @@ -4523,6 +4524,13 @@ int bdrv_change_backing_file(BlockDriverState *bs, return -EINVAL; } + if (warn && backing_file && !backing_fmt && + !strstart(backing_file, "json:", NULL)) { + 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/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/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.24.1