On 2017-09-18 14:42, Pavel Butsykin wrote:
> The flag is additional precaution against data loss. Perhaps in the future the
> operation shrink without this flag will be blocked for all formats, but for 
> now
> we need to maintain compatibility with raw.
> 
> Signed-off-by: Pavel Butsykin <pbutsy...@virtuozzo.com>
> Reviewed-by: Max Reitz <mre...@redhat.com>
> Reviewed-by: John Snow <js...@redhat.com>
> ---
>  qemu-img-cmds.hx       |  4 ++--
>  qemu-img.c             | 23 +++++++++++++++++++++++
>  qemu-img.texi          |  6 +++++-
>  tests/qemu-iotests/102 |  4 ++--
>  tests/qemu-iotests/106 |  2 +-
>  5 files changed, 33 insertions(+), 6 deletions(-)

[...]

> diff --git a/qemu-img.c b/qemu-img.c
> index 56ef49e214..b7b2386cbd 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c

[...]

> @@ -3571,6 +3577,23 @@ static int img_resize(int argc, char **argv)
>          goto out;
>      }
>  
> +    if (total_size < current_size && !shrink) {
> +        warn_report("Shrinking an image will delete all data beyond the "
> +                    "shrunken image's end. Before performing such an "
> +                    "operation, make sure there is no important data 
> there.");
> +
> +        if (g_strcmp0(bdrv_get_format_name(blk_bs(blk)), "raw") != 0) {
> +            error_report(
> +              "Use the --shrink option to perform a shrink operation.");
> +            ret = -1;
> +            goto out;
> +        } else {
> +            warn_report("Using the --shrink option will suppress this 
> message."

Still missing a space here.

Max

> +                        "Note that future versions of qemu-img may refuse to 
> "
> +                        "shrink images without this option.");
> +        }
> +    }
> +
>      ret = blk_truncate(blk, total_size, prealloc, &err);
>      if (!ret) {
>          qprintf(quiet, "Image resized.\n");

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to