qemu-trivial.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: "Tomáš Golembiovský" <tgolembi@redhat.com>,
	qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
	qemu-block@nongnu.org
Subject: Re: [Qemu-trivial] [PATCH v2] curl: Operate on zero-length file
Date: Wed, 14 Sep 2016 10:13:11 +0300	[thread overview]
Message-ID: <96ed9f00-3edc-1c5d-abdb-c7e6619da244@msgid.tls.msk.ru> (raw)
In-Reply-To: <20160708131809.07a8e7dc@fiorina>

08.07.2016 14:18, Tomáš Golembiovský wrote:
> Another attempt to fix the bug 1596870.
>
> When creating new disk backed by remote file accessed via HTTPS and the
> backing file has zero length, qemu-img terminates with uniformative
> error message:
>
>     qemu-img: disk.qcow2: CURL: Error opening file:
>
> While it may not make much sense to operate on empty file, other block
> backends (e.g. raw backend for regular files) seem to allow it. This
> patch fixes it for the curl backend and improves the reported error.
>
> Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
> ---
>  block/curl.c | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/block/curl.c b/block/curl.c
> index da9f5e8..a8cdb44 100644
> --- a/block/curl.c
> +++ b/block/curl.c
> @@ -675,11 +675,28 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
>      curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
>      if (curl_easy_perform(state->curl))
>          goto out;
> -    curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
> -    if (d)
> -        s->len = (size_t)d;
> -    else if(!s->len)
> +    if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
>          goto out;
> +    }
> +    /* Prior CURL 7.19.4 return value of 0 could mean that the file size is not
> +     * know or the size is zero. From 7.19.4 CURL returns -1 if size is not
> +     * known and zero if it is realy zero-length file. */
> +#if LIBCURL_VERSION_NUM >= 0x071304
> +    if (d < 0) {
> +        pstrcpy(state->errmsg, CURL_ERROR_SIZE,
> +                "Server didn't report file size.");
> +        goto out;
> +    }
> +#else
> +    if (d <= 0) {
> +        pstrcpy(state->errmsg, CURL_ERROR_SIZE,
> +                "Unknown file size or zero-length file.");
> +        goto out;
> +    }
> +#endif

This is somewhat ugly ifdeffery, but ohwell..

> +    s->len = (size_t)d;
> +
>      if ((!strncasecmp(s->url, "http://", strlen("http://"))
>          || !strncasecmp(s->url, "https://", strlen("https://")))
>          && !s->accept_range) {
>


Applied to -trivial, thank you!

/mjt


      reply	other threads:[~2016-09-14  7:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-08 11:18 [Qemu-trivial] [PATCH v2] curl: Operate on zero-length file Tomáš Golembiovský
2016-09-14  7:13 ` Michael Tokarev [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=96ed9f00-3edc-1c5d-abdb-c7e6619da244@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=tgolembi@redhat.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).