From: Fam Zheng <famz@redhat.com>
To: Reda Sallahi <fullmanet@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3] qemu-img: add conv=notrunc option to dd
Date: Mon, 15 Aug 2016 13:27:50 +0800 [thread overview]
Message-ID: <20160815052750.GA25079@al.usersys.redhat.com> (raw)
In-Reply-To: <20160811093105.7606-1-fullmanet@gmail.com>
On Thu, 08/11 11:31, Reda Sallahi wrote:
> This adds the conv=notrunc option to dd which tells dd to not truncate the
> output.
>
> Signed-off-by: Reda Sallahi <fullmanet@gmail.com>
> ---
> Depends on:
> [PATCH v5] qemu-img: add skip option to dd
>
> Changes from v2:
> * Delete the mandatory conv=notrunc
> Changes from v1:
> * Added comment
>
> qemu-img-cmds.hx | 4 ++--
> qemu-img.c | 22 +++++++++++++++++++++-
> qemu-img.texi | 7 +++++--
> tests/qemu-iotests/158 | 2 +-
> tests/qemu-iotests/159 | 3 ++-
> tests/qemu-iotests/160 | 7 ++++---
> 6 files changed, 35 insertions(+), 10 deletions(-)
>
> diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
> index f054599..18685ac 100644
> --- a/qemu-img-cmds.hx
> +++ b/qemu-img-cmds.hx
> @@ -46,9 +46,9 @@ STEXI
> ETEXI
>
> DEF("dd", img_dd,
> - "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] if=input of=output")
> + "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [conv=notrunc] if=input of=output")
> STEXI
> -@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} of=@var{output}
> +@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] [conv=notrunc] if=@var{input} of=@var{output}
> ETEXI
>
> DEF("info", img_info,
> diff --git a/qemu-img.c b/qemu-img.c
> index 3adec86..d08905b 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -174,7 +174,8 @@ static void QEMU_NORETURN help(void)
> " 'count=N' copy only N input blocks\n"
> " 'if=FILE' read from FILE\n"
> " 'of=FILE' write to FILE\n"
> - " 'skip=N' skip N bs-sized blocks at the start of input\n";
> + " 'skip=N' skip N bs-sized blocks at the start of input\n"
> + " 'conv=notrunc' do not truncate the output file\n";
>
> printf("%s\nSupported formats:", help_msg);
> bdrv_iterate_format(format_print, NULL);
> @@ -3807,10 +3808,12 @@ out:
> #define C_IF 04
> #define C_OF 010
> #define C_SKIP 020
> +#define C_CONV 040
>
> struct DdInfo {
> unsigned int flags;
> int64_t count;
> + unsigned int conv;
> };
>
> struct DdIo {
> @@ -3894,6 +3897,21 @@ static int img_dd_skip(const char *arg,
> return 0;
> }
>
> +#define C_NOTRUNC 01
> +
> +static int img_dd_conv(const char *arg,
> + struct DdIo *in, struct DdIo *out,
> + struct DdInfo *dd)
> +{
> + if (!strcmp(arg, "notrunc")) {
> + dd->conv |= C_NOTRUNC;
> + return 0;
> + } else {
> + error_report("invalid conversion: '%s'", arg);
> + return 1;
> + }
> +}
> +
> static int img_dd(int argc, char **argv)
> {
> int ret = 0;
> @@ -3913,6 +3931,7 @@ static int img_dd(int argc, char **argv)
> struct DdInfo dd = {
> .flags = 0,
> .count = 0,
> + .conv = 0
> };
> struct DdIo in = {
> .bsz = 512, /* Block size is by default 512 bytes */
> @@ -3933,6 +3952,7 @@ static int img_dd(int argc, char **argv)
> { "if", img_dd_if, C_IF },
> { "of", img_dd_of, C_OF },
> { "skip", img_dd_skip, C_SKIP },
> + { "conv", img_dd_conv, C_CONV },
> { NULL, NULL, 0 }
> };
> const struct option long_options[] = {
> diff --git a/qemu-img.texi b/qemu-img.texi
> index 174aae3..002dde2 100644
> --- a/qemu-img.texi
> +++ b/qemu-img.texi
> @@ -150,9 +150,12 @@ sets the number of input blocks to copy
> @item if=@var{input}
> sets the input file
> @item of=@var{output}
> -sets the output file
> +sets the output file. dd truncates the output file to zero if 'conv=notrunc'
> +is not specified.
> @item skip=@var{blocks}
> sets the number of input blocks to skip
> +@item conv=notrunc
> +makes dd not truncate output file to zero
> @end table
>
> Command description:
> @@ -326,7 +329,7 @@ skipped. This is useful for formats such as @code{rbd} if the target
> volume has already been created with site specific options that cannot
> be supplied through qemu-img.
>
> -@item dd [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} of=@var{output}
> +@item dd [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] [conv=notrunc] if=@var{input} of=@var{output}
>
> Dd copies from @var{input} file to @var{output} file converting it from
> @var{fmt} format to @var{output_fmt} format.
> diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158
> index 5b335db..63e2a10 100755
> --- a/tests/qemu-iotests/158
> +++ b/tests/qemu-iotests/158
> @@ -53,7 +53,7 @@ $QEMU_IO -c "write -P 0xa 0 $size" "$TEST_IMG" | _filter_qemu_io
> echo
> echo "== Converting the image with dd =="
>
> -$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" -O "$IMGFMT"
> +$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=notrunc -O "$IMGFMT"
> TEST_IMG="$TEST_IMG.out" _check_test_img
>
> echo
> diff --git a/tests/qemu-iotests/159 b/tests/qemu-iotests/159
> index 825f05f..d68a19f 100755
> --- a/tests/qemu-iotests/159
> +++ b/tests/qemu-iotests/159
> @@ -55,7 +55,8 @@ for bs in $TEST_SIZES; do
> echo
> echo "== Converting the image with dd with a block size of $bs =="
>
> - $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" bs=$bs -O "$IMGFMT"
> + $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" bs=$bs conv=notrunc \
> + -O "$IMGFMT"
> TEST_IMG="$TEST_IMG.out" _check_test_img
>
> echo
> diff --git a/tests/qemu-iotests/160 b/tests/qemu-iotests/160
> index 5c910e5..53b3c30 100755
> --- a/tests/qemu-iotests/160
> +++ b/tests/qemu-iotests/160
> @@ -55,10 +55,11 @@ for skip in $TEST_SKIP_BLOCKS; do
> echo
> echo "== Converting the image with dd with skip=$skip =="
>
> - $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" -O "$IMGFMT" \
> - 2> /dev/null
> + $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" conv=notrunc \
> + -O "$IMGFMT" 2> /dev/null
> TEST_IMG="$TEST_IMG.out" _check_test_img
> - dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" status=none
> + dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" conv=notrunc \
> + status=none
>
> echo
> echo "== Compare the images with qemu-img compare =="
> --
> 2.9.2
>
Reviewed-by: Fam Zheng <famz@redhat.com>
prev parent reply other threads:[~2016-08-15 5:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-11 9:31 [Qemu-devel] [PATCH v3] qemu-img: add conv=notrunc option to dd Reda Sallahi
2016-08-15 5:27 ` Fam Zheng [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=20160815052750.GA25079@al.usersys.redhat.com \
--to=famz@redhat.com \
--cc=fullmanet@gmail.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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).