From: Eric Blake <eblake@redhat.com>
To: Klim Kireev <klim.kireev@virtuozzo.com>,
kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org,
qemu-devel@nongnu.org
Cc: den@openvz.org, vsementsov@virtuozzo.com
Subject: Re: [Qemu-devel] [PATCH v2] qemu-img: add the simplest format recognition
Date: Fri, 1 Dec 2017 17:28:29 -0600 [thread overview]
Message-ID: <c18c4367-e605-9deb-cbf9-d3fea4b631f5@redhat.com> (raw)
In-Reply-To: <20171201224909.9373-1-klim.kireev@virtuozzo.com>
[-- Attachment #1: Type: text/plain, Size: 1877 bytes --]
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 <klim.kireev@virtuozzo.com>
> ---
> 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
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
prev parent reply other threads:[~2017-12-01 23:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-01 22:49 [Qemu-devel] [PATCH v2] qemu-img: add the simplest format recognition Klim Kireev
2017-12-01 23:28 ` Eric Blake [this message]
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=c18c4367-e605-9deb-cbf9-d3fea4b631f5@redhat.com \
--to=eblake@redhat.com \
--cc=den@openvz.org \
--cc=klim.kireev@virtuozzo.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/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).