aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'block.c')
-rw-r--r--block.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/block.c b/block.c
index 3031413..35a372d 100644
--- a/block.c
+++ b/block.c
@@ -1206,7 +1206,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");
}
@@ -4680,8 +4681,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;
@@ -4695,6 +4696,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 {
@@ -6128,18 +6135,30 @@ void bdrv_img_create(const char *filename, const char *fmt,
bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
&local_err);
g_free(full_backing);
- if (!bs && size != -1) {
- /* Couldn't open BS, but we have a size, so it's nonfatal */
- warn_reportf_err(local_err,
- "Could not verify backing image. "
- "This may become an error in future versions.\n");
- local_err = NULL;
- } else if (!bs) {
- /* Couldn't open bs, do not have size */
- error_append_hint(&local_err,
- "Could not open backing image to determine size.\n");
+ if (!bs) {
+ error_append_hint(&local_err, "Could not open backing image.\n");
goto out;
} else {
+ if (!backing_fmt) {
+ warn_report("Deprecated use of backing file without explicit "
+ "backing format (detected format of %s)",
+ bs->drv->format_name);
+ if (bs->drv != &bdrv_raw) {
+ /*
+ * A probe of raw deserves the most attention:
+ * leaving the backing format out of the image
+ * will ensure bs->probed is set (ensuring we
+ * don't accidentally commit into the backing
+ * file), and allow more spots to warn the users
+ * to fix their toolchain when opening this image
+ * later. For other images, we can safely record
+ * the format that we probed.
+ */
+ backing_fmt = bs->drv->format_name;
+ qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, backing_fmt,
+ NULL);
+ }
+ }
if (size == -1) {
/* Opened BS, have no size */
size = bdrv_getlength(bs);
@@ -6153,7 +6172,12 @@ void bdrv_img_create(const char *filename, const char *fmt,
}
bdrv_unref(bs);
}
- } /* (backing_file && !(flags & BDRV_O_NO_BACKING)) */
+ /* (backing_file && !(flags & BDRV_O_NO_BACKING)) */
+ } else if (backing_file && !backing_fmt) {
+ warn_report("Deprecated use of unopened backing file without "
+ "explicit backing format, use of this image requires "
+ "potentially unsafe format probing");
+ }
if (size == -1) {
error_setg(errp, "Image creation needs a size parameter");
@@ -6164,6 +6188,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
printf("Formatting '%s', fmt=%s ", filename, fmt);
qemu_opts_print(opts, " ");
puts("");
+ fflush(stdout);
}
ret = bdrv_create(drv, filename, opts, &local_err);