From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pkrempa@redhat.com,
"Ján Tomko" <jtomko@redhat.com>,
qemu-block@nongnu.org, kchamart@redhat.com,
libvir-list@redhat.com, "Markus Armbruster" <armbru@redhat.com>,
mreitz@redhat.com, "John Snow" <jsnow@redhat.com>
Subject: [PATCH v5 6/7] block: Add support to warn on backing file change without format
Date: Fri, 3 Apr 2020 12:58:58 -0500 [thread overview]
Message-ID: <20200403175859.863248-7-eblake@redhat.com> (raw)
In-Reply-To: <20200403175859.863248-1-eblake@redhat.com>
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 <eblake@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
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 b05995fe9c5b..098fc635e865 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -351,8 +351,8 @@ BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *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_file,
+ 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 2e3905c99e8c..70cc6123dd91 100644
--- a/block.c
+++ b/block.c
@@ -1322,7 +1322,8 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,
}
ret = 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");
}
@@ -4566,8 +4567,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_file,
+ const char *backing_fmt, bool warn)
{
BlockDriver *drv = bs->drv;
int ret;
@@ -4581,6 +4582,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 != NULL) {
ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt);
} else {
diff --git a/block/qcow2.c b/block/qcow2.c
index e4b772726010..0a7e70bdf879 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3526,7 +3526,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
ret = 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 = bdrv_change_backing_file(bs, base_id, base_fmt);
+ ret = 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 = bdrv_change_backing_file(image_bs, backing_file,
- image_bs->drv ? image_bs->drv->format_name : "");
+ image_bs->drv ? image_bs->drv->format_name : "",
+ 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 b167376bd72e..cb8fa5a0ee8b 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3644,9 +3644,9 @@ static int img_rebase(int argc, char **argv)
* doesn't change when we switch the backing file.
*/
if (out_baseimg && *out_baseimg) {
- ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt);
+ ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt, false);
} else {
- ret = bdrv_change_backing_file(bs, NULL, NULL);
+ ret = bdrv_change_backing_file(bs, NULL, NULL, false);
}
if (ret == -ENOSPC) {
--
2.26.0.rc2
next prev parent reply other threads:[~2020-04-03 18:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-03 17:58 [PATCH v5 for-5.0? 0/7] Tighten qemu-img rules on missing backing format Eric Blake
2020-04-03 17:58 ` [PATCH v5 1/7] sheepdog: Add trivial backing_fmt support Eric Blake
2020-04-03 17:58 ` [PATCH v5 2/7] vmdk: " Eric Blake
2020-04-03 17:58 ` [PATCH v5 3/7] qcow: Tolerate backing_fmt=, but warn on backing_fmt=raw Eric Blake
2020-05-05 7:35 ` Kevin Wolf
2020-05-05 15:30 ` Eric Blake
2020-06-22 21:58 ` Eric Blake
2020-06-23 10:40 ` Kevin Wolf
2020-04-03 17:58 ` [PATCH v5 4/7] qcow2: Deprecate use of qemu-img amend to change backing file Eric Blake
2020-05-05 7:50 ` Kevin Wolf
2020-04-03 17:58 ` [PATCH v5 5/7] iotests: Specify explicit backing format where sensible Eric Blake
2020-04-03 17:58 ` Eric Blake [this message]
2020-04-03 17:58 ` [PATCH v5 7/7] qemu-img: Deprecate use of -b without -F Eric Blake
2020-05-05 8:11 ` Kevin Wolf
2020-05-05 8:43 ` Peter Krempa
2020-05-04 20:02 ` [PATCH v5 for-5.0? 0/7] Tighten qemu-img rules on missing backing format Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200403175859.863248-7-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=jsnow@redhat.com \
--cc=jtomko@redhat.com \
--cc=kchamart@redhat.com \
--cc=kwolf@redhat.com \
--cc=libvir-list@redhat.com \
--cc=mreitz@redhat.com \
--cc=pkrempa@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).