[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH v2] qemu-img: add the simplest form
From: |
Eric Blake |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH v2] qemu-img: add the simplest format recognition |
Date: |
Fri, 1 Dec 2017 17:28:29 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 |
On 12/01/2017 04:49 PM, Klim Kireev wrote:
> Now, if you type something like
>
> qemu-img create disk.qcow2 1G
> or
> qemu-img dd if=/dev/sda of=disk.qcow2
>
> it creates a raw image and if you need you should
> manually specify an image format with -f qcow2. It would
> be more convenient if it could be detected from an extension.
>
> This patch adds a simple heuristic to recognize the image format
> for qcow, qcow2, vmdk, vhdx, vdi
>
> It warns users about guessed format and informs them about '-f' option.
>
> Signed-off-by: Klim Kireev <address@hidden>
> ---
> qemu-img.c | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 02a6e27beb..ac1adf1582 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -421,11 +421,22 @@ static int64_t cvtnum(const char *s)
> return value;
> }
>
> +static const char *get_format(const char *filename)
> +{
> + const char *fmt = strrchr(filename, '.');
> + if (fmt == NULL || bdrv_find_format(++fmt) == NULL) {
> + fmt = "raw";
> + }
> + printf("!!! %s format was detected.\n"
Assumed, not detected. (We didn't read the file, because we're creating
it; we're assuming a format based on the file name, not its contents,
and detection tends to imply a contents-based check).
> + "!!! If you meant another format, specify it with -f.\n", fmt);
Not our usual error reporting style; the !!! is yelling at the user, and
we tend to avoid trailing '.'. printf() goes to stdout, but the message
should go to stderr(); you really want to use warn_report().
I suggest:
warn_report("No format specified with -f, assuming %s.", fmt);
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature