qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v9] qemu-img: add the 'dd' subcommand


From: Max Reitz
Subject: Re: [Qemu-block] [PATCH v9] qemu-img: add the 'dd' subcommand
Date: Wed, 10 Aug 2016 17:18:10 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 10.08.2016 04:43, Reda Sallahi wrote:
> This patch adds a basic dd subcommand analogous to dd(1) to qemu-img.
> 
> For the start, this implements the bs, if, of and count options and requires
> both if and of to be specified (no stdin/stdout if not specified) and doesn't
> support tty, pipes, etc.
> 
> The image format must be specified with -O for the output if the raw format
> is not the intended one.
> 
> Two tests are added to test qemu-img dd.
> 
> Signed-off-by: Reda Sallahi <address@hidden>
> ---
> Changes from v8:
> * Add an overflow check.
> Changes from v7:
> * Remove a C99-style for loop.
> Changes from v6:
> * Remove get_size() to use qemu_strtosz_suffix() instead.
> * Type changes for some fields in DdIo and DdInfo.
> Changes from v5:
> * Add dd sections on qemu-img.texi.
> Changes from v4:
> * Fix the exit status.
> Changes from v3:
> * Delete an unused (so far) field in DdIo.
> Changes from v2:
> * Add copyright headers to new files.
> Changes from v1:
> * Removal of dead code.
> * Fix a memory leak.
> * Complete the cleanup function in the test cases.
> 
>  qemu-img-cmds.hx                 |   6 +
>  qemu-img.c                       | 303 
> ++++++++++++++++++++++++++++++++++++++-
>  qemu-img.texi                    |  25 ++++
>  tests/qemu-iotests/158           |  67 +++++++++
>  tests/qemu-iotests/158.out       |  15 ++
>  tests/qemu-iotests/159           |  70 +++++++++
>  tests/qemu-iotests/159.out       |  87 +++++++++++
>  tests/qemu-iotests/common.filter |   9 ++
>  tests/qemu-iotests/common.rc     |   5 +-
>  tests/qemu-iotests/group         |   2 +
>  10 files changed, 584 insertions(+), 5 deletions(-)
>  create mode 100755 tests/qemu-iotests/158
>  create mode 100644 tests/qemu-iotests/158.out
>  create mode 100755 tests/qemu-iotests/159
>  create mode 100644 tests/qemu-iotests/159.out

[...]

> diff --git a/qemu-img.c b/qemu-img.c
> index d2865a5..034baf7 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c

[...]

> @@ -3794,6 +3801,300 @@ out:

[...]

> +    size = blk_getlength(blk1);
> +    if (size < 0) {
> +        error_report("Failed to get size for '%s'", in.filename);
> +        ret = -1;
> +        goto out;
> +    }
> +
> +    if (dd.flags & C_COUNT && dd.count <= INT64_MAX / in.bsz &&
> +        dd.count * in.bsz < size) {
> +        size = dd.count * in.bsz;

At first I wanted to object and say that we should throw an error if
dd.count * in.bsz overflows. But you're right, since all bs and count do
is limit the length of the data to copy, we can just consider them
"infinite" (i.e. no limit) if there product overflows. Clever.


Thanks, Reda, I've applied this patch to my block-next branch for the
qemu 2.8 development window:

https://github.com/XanClic/qemu/commits/block-next

Max

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]