qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: fullmanet@gmail.com, qemu-block@nongnu.org,
	qemu-stable@nongnu.org, Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 1/2] qemu-img: Fix dd with skip= and count=
Date: Thu, 16 Aug 2018 04:03:48 +0200	[thread overview]
Message-ID: <222b07f8-4a41-04f5-c93c-727244e6d1e8@redhat.com> (raw)
In-Reply-To: <20180815025614.53588-2-eblake@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2359 bytes --]

On 2018-08-15 04:56, Eric Blake wrote:
> When both skip= and count= are active, qemu-img dd was not copying
> enough data. It didn't help that the code made the same check for
> dd.flags & C_SKIP in two separate places. Compute 'size' as the
> amount of bytes to be read, and 'end' as the offset to end at,
> rather than trying to cram both meanings into a single variable
> (which only worked as long as we had at most one of those two
> limiting factors to worry about, but not both).
> 
> Enhance the test to cover more combinations, and expose the problem.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> CC: qemu-stable@nongnu.org
> ---
>  qemu-img.c                 | 39 ++++++++++++++++---------------------
>  tests/qemu-iotests/160     |  9 ++++++---
>  tests/qemu-iotests/160.out | 48 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 70 insertions(+), 26 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 1acddf693c6..d72f0f0ec94 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c

[...]

> @@ -4559,19 +4559,23 @@ static int img_dd(int argc, char **argv)
>          goto out;
>      }
> 
> +    /* Overflow means the specified offset is beyond input image's size */
> +    if (dd.flags & C_SKIP && (in.offset > INT64_MAX / in.bsz ||
> +                              size < in.bsz * in.offset)) {
> +        size = 0;
> +        error_report("%s: cannot skip to specified offset", in.filename);

in_pos should be initialized as well (to "size", I suppose), or my gcc
will continue to complain. :-)

The rest looks good to me.

> +    } else {
> +        size -= in.offset * in.bsz;
> +        in_pos = in.offset * in.bsz;
> +    }
> +

[...]

> diff --git a/tests/qemu-iotests/160 b/tests/qemu-iotests/160
> index 5c910e5bfc1..48380a3aafc 100755
> --- a/tests/qemu-iotests/160
> +++ b/tests/qemu-iotests/160
> @@ -44,6 +44,7 @@ _supported_os Linux
>  TEST_SKIP_BLOCKS="1 2 30 30K"
> 
>  for skip in $TEST_SKIP_BLOCKS; do
> +  for count in '' 'count=1 '; do

Ah, so this is why we indent everything by four spaces!  So you can
squeeze in three more block headers without having to re-indent
everything.  I finally see. O:-)

(Not sure why you put a space after the 'count=1', though, but OK)

Max

>      echo
>      echo "== Creating image =="
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2018-08-16  2:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-15  2:56 [Qemu-devel] [PATCH 0/2] Improve qemu-img dd Eric Blake
2018-08-15  2:56 ` [Qemu-devel] [PATCH 1/2] qemu-img: Fix dd with skip= and count= Eric Blake
2018-08-16  2:03   ` Max Reitz [this message]
2018-08-16  2:17     ` Eric Blake
2018-08-16  2:19       ` Max Reitz
2018-08-15  2:56 ` [Qemu-devel] [PATCH 2/2] qemu-img: Add dd seek= option Eric Blake
2018-08-16  2:20   ` Max Reitz
2018-08-16  2:39     ` Eric Blake
2018-08-16  2:49       ` Eric Blake
2018-08-16  2:49       ` Max Reitz
2018-08-16  2:57         ` Eric Blake
2018-08-16  3:00           ` Max Reitz
2018-08-16  7:15         ` Kevin Wolf
2018-08-17 19:22           ` Max Reitz
2018-08-20  2:07     ` Fam Zheng
2018-08-20 12:20       ` Max Reitz
2018-08-16  2:04 ` [Qemu-devel] [PATCH 0/2] Improve qemu-img dd Eric Blake
2018-08-16  2:12 ` Eric Blake
2018-08-16 19:39 ` no-reply
2018-08-16 20:00 ` no-reply

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=222b07f8-4a41-04f5-c93c-727244e6d1e8@redhat.com \
    --to=mreitz@redhat.com \
    --cc=eblake@redhat.com \
    --cc=fullmanet@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /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).