qemu-img dd
cover qemu-img dd
Hi everyone,
This patchset adds additional options to qemu-img dd.
Depends on:
[PATCH v4] qemu-img: change opening method for the output in dd
Reda Sallahi (7):
qemu-img: add seek option to dd
qemu-img: add iflag and oflag options to dd
qemu-img: add more conv= conversions to dd
qemu-img: delete not used variable and an unecessary check
qemu-img: add status option to dd
qemu-img: clean up dd documentation
qemu-img: add a test suite for the count option
qemu-img-cmds.hx | 4 +- qemu-img.c | 431 ++++++++++++++++++++++++++++++++++++++++----- qemu-img.texi | 69 +++++++- tests/qemu-iotests/159 | 2 +- tests/qemu-iotests/160 | 2 +- tests/qemu-iotests/161 | 73 ++++++++ tests/qemu-iotests/161.out | 51 ++++++ tests/qemu-iotests/163 | 103 +++++++++++ tests/qemu-iotests/163.out | 135 ++++++++++++++ tests/qemu-iotests/164 | 100 +++++++++++ tests/qemu-iotests/164.out | 75 ++++++++ tests/qemu-iotests/165 | 110 ++++++++++++ tests/qemu-iotests/165.out | 33 ++++ tests/qemu-iotests/166 | 73 ++++++++ tests/qemu-iotests/166.out | 19 ++ tests/qemu-iotests/167 | 77 ++++++++ tests/qemu-iotests/167.out | 17 ++ tests/qemu-iotests/168 | 75 ++++++++ tests/qemu-iotests/168.out | 51 ++++++ tests/qemu-iotests/group | 7 + 20 files changed, 1449 insertions(+), 58 deletions(-) create mode 100755 tests/qemu-iotests/161 create mode 100644 tests/qemu-iotests/161.out create mode 100755 tests/qemu-iotests/163 create mode 100644 tests/qemu-iotests/163.out create mode 100755 tests/qemu-iotests/164 create mode 100644 tests/qemu-iotests/164.out create mode 100755 tests/qemu-iotests/165 create mode 100644 tests/qemu-iotests/165.out create mode 100755 tests/qemu-iotests/166 create mode 100644 tests/qemu-iotests/166.out create mode 100755 tests/qemu-iotests/167 create mode 100644 tests/qemu-iotests/167.out create mode 100755 tests/qemu-iotests/168 create mode 100644 tests/qemu-iotests/168.out
Signature · 1 line
2.9.3
PATCH 1/7 qemu-img: add seek option to dd
This patch adds the seek option which allows qemu-img dd to skip a number of blocks on the output before copying the input.
A test case was added to test the seek option.
--- qemu-img-cmds.hx | 4 +-- qemu-img.c | 45 +++++++++++++++++++++++----- qemu-img.texi | 4 ++- tests/qemu-iotests/161 | 73 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/161.out | 51 ++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 6 files changed, 167 insertions(+), 11 deletions(-) create mode 100755 tests/qemu-iotests/161 create mode 100644 tests/qemu-iotests/161.out
qemu-img-cmds.hx +2 -2
@@ -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] [conv=notrunc] if=input of=output") + "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [seek=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}] [conv=notrunc] 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}] [seek=@var{blocks}] [conv=notrunc] if=@var{input} of=@var{output} ETEXI DEF("info", img_info,
qemu-img.c +37 -8
101 lines not on this page · raw message
qemu-img.texi +3 -1
@@ -154,6 +154,8 @@ 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 seek=@var{blocks} +sets the number of output blocks to skip @item conv=notrunc makes dd not truncate output file to zero @end table
@@ -329,7 +331,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}] [conv=notrunc] 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}] [seek=@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.
tests/qemu-iotests/161 new file +73 -0
73 lines not on this page · raw message
tests/qemu-iotests/161.out new file +51 -0
51 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -160,4 +160,5 @@ 158 rw auto quick 159 rw auto quick 160 rw auto quick +161 rw auto quick 162 auto quick
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 1/7] qemu-img: add seek option to dd
Quoted 6 lines · Reda Sallahi
This patch adds the seek option which allows qemu-img dd to skip a number of blocks on the output before copying the input.
A test case was added to test the seek option.
Signed-off-by Reda Sallahi <[email protected]>
Quoted 10 lines
--- qemu-img-cmds.hx | 4 +-- qemu-img.c | 45 +++++++++++++++++++++++----- qemu-img.texi | 4 ++- tests/qemu-iotests/161 | 73 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/161.out | 51 ++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 6 files changed, 167 insertions(+), 11 deletions(-) create mode 100755 tests/qemu-iotests/161 create mode 100644 tests/qemu-iotests/161.out
PATCH 2/7 qemu-img: add iflag and oflag options to dd
In reply to Reda SallahiThis adds the iflag and oflag options which defines the list of flags used for reading and writing respectively. The list is comma-separated.
The iflag option supports direct, dsync, sync, count_bytes and skip_bytes and oflag supports direct, dsync, sync and seek_bytes. They are similar to their counterparts on GNU dd(1).
Two tests were added to test iflag and oflag.
--- qemu-img-cmds.hx | 4 +- qemu-img.c | 185 ++++++++++++++++++++++++++++++++++++++++----- qemu-img.texi | 32 +++++++- tests/qemu-iotests/163 | 103 +++++++++++++++++++++++++ tests/qemu-iotests/163.out | 135 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/164 | 100 ++++++++++++++++++++++++ tests/qemu-iotests/164.out | 75 ++++++++++++++++++ tests/qemu-iotests/group | 2 + 8 files changed, 609 insertions(+), 27 deletions(-) create mode 100755 tests/qemu-iotests/163 create mode 100644 tests/qemu-iotests/163.out create mode 100755 tests/qemu-iotests/164 create mode 100644 tests/qemu-iotests/164.out
qemu-img-cmds.hx +2 -2
@@ -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] [seek=blocks] [conv=notrunc] if=input of=output") + "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [seek=blocks] [conv=notrunc] [iflag=flags] [oflag=flags] 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}] [seek=@var{blocks}] [conv=notrunc] 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}] [seek=@var{blocks}] [conv=notrunc] [iflag=@var{flags}] [oflag=@var{flags}] if=@var{input} of=@var{output} ETEXI DEF("info", img_info,
qemu-img.c +164 -21
308 lines not on this page · raw message
qemu-img.texi +28 -4
@@ -146,18 +146,42 @@ Parameters to dd subcommand: @item bs=@var{block_size} defines the block size @item count=@var{blocks} -sets the number of input blocks to copy +sets the number of input blocks to copy. In case 'iflags=count_bytes' is +specified, 'blocks' is interpreted as a byte count instead of a block count. @item if=@var{input} sets the input file @item of=@var{output} 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 +sets the number of input blocks to skip. In case 'iflags=skip_bytes' is +specified, 'blocks' is interpreted as a byte count instead of a block count. @item seek=@var{blocks} -sets the number of output blocks to skip +sets the number of output blocks to skip. In case 'oflags=seek_bytes' is +specified, 'blocks' is interpreted as a byte count instead of a block count. @item conv=notrunc makes dd not truncate output file to zero +@item iflag=@var{flags} +defines the flags used to read the input file. The flag list is seprated using +commas. +@item oflag=@var{flags} +defines the flags used to write the output file. The flag list is seprated +using commas. + +The flag list: +@item direct +direct I/O for data. +@item dsync +synchronised I/O for data. +@item sync +synchronised I/O for data. +@item count_bytes +interpret 'count=blocks' as a byte count. Only iflag. +@item skip_bytes +interpret 'skip=blocks' as a byte count. Only iflag. +@item seek_bytes +interpret 'seek=blocks' as a byte count. Only oflag. + @end table Command description:
@@ -331,7 +355,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}] [seek=@var{blocks}] [conv=notrunc] 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}] [seek=@var{blocks}] [conv=notrunc] [iflag=@var{flags}] [oflag=@var{flags}] 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.
tests/qemu-iotests/163 new file +103 -0
103 lines not on this page · raw message
tests/qemu-iotests/163.out new file +135 -0
135 lines not on this page · raw message
tests/qemu-iotests/164 new file +100 -0
100 lines not on this page · raw message
tests/qemu-iotests/164.out new file +75 -0
75 lines not on this page · raw message
tests/qemu-iotests/group +2 -0
@@ -162,3 +162,5 @@ 160 rw auto quick 161 rw auto quick 162 auto quick +163 rw auto quick +164 rw auto quick
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 2/7] qemu-img: add iflag and oflag options to dd
Quoted 25 lines · Reda Sallahi
qemu-img.c +25
-0+static int img_dd_oflag (const char *arg, +struct DdIo *in,struct DdIo *out, +struct DdInfo *dd) +{ +const char *tok; +char *str, *tmp; +int ret =0 ; +const struct DdSymbols flags[] = { + {"direct" ,C_DIRECT }, + {"dsync" ,C_DSYNC }, + {"sync" ,C_IOFLAG_SYNC }, + {"seek_bytes" ,C_SEEK_BYTES }, + {NULL ,0 } + }; + + tmp = str =g_strdup (arg); + +while (tmp !=NULL && !ret) { + tok =qemu_strsep (&tmp,"," ); +int j; +for (j =0 ; flags[j].name !=NULL ; j++) { +if (!strcmp (tok, flags[j].name)) { + out->flags |= flags[j].value; +break ; + }
qemu-img.c static int img_dd_conv(const char *arg, · line 4028
Quoted 10 lines
qemu-img.c +10
-0+ } +if (flags[j].name ==NULL ) { +error_report ("invalid output flag: '%s'" , tok); + ret =1 ; + } + } + +g_free (str); +return ret; +}
img_dd_iflag()/img_dd_oflag() are duplicated code. I suggest a single helper function that parses a DdSymbols array into a DdIo->flags field. Then you can pass in either the iflag or the oflag DdSymbols arrays.
static int img_dd_oflag(const char *arg,
struct DdIo *in, struct DdIo *out, struct DdInfo *dd)
{
return img_dd_xflag(arg, (DdSymbols[]){
{ "direct", C_DIRECT },
{ "dsync", C_DSYNC },
...
}, in);
}static int img_dd_oflag(const char *arg,
struct DdIo *in, struct DdIo *out, struct DdInfo *dd)
{
return img_dd_xflag(arg, (DdSymbols[]){
{ "direct", C_DIRECT },
{ "dsync", C_DSYNC },
...
}, out);
}PATCH 3/7 qemu-img: add more conv= conversions to dd
In reply to Reda SallahiThis patch adds excl, nocreat, noerror, sync, fsync, fdatasync and sparse to the conversion list. They have the same meaning as the ones on GNU dd(1).
Two tests were added to test the conv= option.
--- qemu-img-cmds.hx | 4 +- qemu-img.c | 122 +++++++++++++++++++++++++++++++++++++++------ qemu-img.texi | 26 ++++++++-- tests/qemu-iotests/165 | 109 ++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/165.out | 33 ++++++++++++ tests/qemu-iotests/166 | 73 +++++++++++++++++++++++++++ tests/qemu-iotests/166.out | 19 +++++++ tests/qemu-iotests/group | 2 + 8 files changed, 367 insertions(+), 21 deletions(-) create mode 100755 tests/qemu-iotests/165 create mode 100644 tests/qemu-iotests/165.out create mode 100755 tests/qemu-iotests/166 create mode 100644 tests/qemu-iotests/166.out
qemu-img-cmds.hx +2 -2
@@ -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] [seek=blocks] [conv=notrunc] [iflag=flags] [oflag=flags] if=input of=output") + "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [seek=blocks] [conv=convs] [iflag=flags] [oflag=flags] 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}] [seek=@var{blocks}] [conv=notrunc] [iflag=@var{flags}] [oflag=@var{flags}] 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}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] if=@var{input} of=@var{output} ETEXI DEF("info", img_info,
qemu-img.c +106 -16
191 lines not on this page · raw message
qemu-img.texi +23 -3
@@ -159,8 +159,28 @@ specified, 'blocks' is interpreted as a byte count instead of a block count. @item seek=@var{blocks} sets the number of output blocks to skip. In case 'oflags=seek_bytes' is specified, 'blocks' is interpreted as a byte count instead of a block count. -@item conv=notrunc -makes dd not truncate output file to zero +@item conv=@var{convs} +Converts the input according to the conversions specified. The conversion list +is separated using commas. + +The conversion list: +@item notrunc +Make dd not truncate output file to zero. +@item sync +Fill every input block size with trailing zero bytes. +@item noerror +Continue after read failures. +@item fdatasync +Synchronize output data just before finishing. This forces a physical write of output data. +@item fsync +Synchronize output data just before finishing. This forces a physical write of output data. +@item excl +Err if the output file already exists. +@item nocreat +Do not create the output file; the output file must already exist. +@item sparse +Seek rather than write NUL output blocks. + @item iflag=@var{flags} defines the flags used to read the input file. The flag list is seprated using commas.
@@ -355,7 +375,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}] [seek=@var{blocks}] [conv=notrunc] [iflag=@var{flags}] [oflag=@var{flags}] 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}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] 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.
tests/qemu-iotests/165 new file +109 -0
109 lines not on this page · raw message
tests/qemu-iotests/165.out new file +33 -0
@@ -0,0 +1,33 @@ +QA output created by 165 + +== Creating image == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +No errors were found on the image. +wrote 217088/217088 bytes at offset 220160 +212 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== Converting the image with dd with conv=excl == +No errors were found on the image. + +== Compare the images with qemu-img compare == +Images are identical. + +== Converting the image with dd with conv=excl == +qemu-img: failed to open 'TEST_DIR/t.IMGFMT.out': File exists + +== Creating image == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +No errors were found on the image. +wrote 336896/336896 bytes at offset 492544 +329 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== Converting the image with dd with conv=nocreat == +No errors were found on the image. + +== Compare the images with qemu-img compare == +Images are identical. + +== Converting the image with dd with conv=nocreat == +qemu-img: Could not open 'TEST_DIR/t.IMGFMT.out': No such file or directory + +*** done
tests/qemu-iotests/166 new file +73 -0
73 lines not on this page · raw message
tests/qemu-iotests/166.out new file +19 -0
@@ -0,0 +1,19 @@ +QA output created by 166 + +== Creating image == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +No errors were found on the image. +wrote 262144/262144 bytes at offset 0 +256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 2048/2048 bytes at offset 16384 +2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== Converting the image with dd with conv=sparse == +No errors were found on the image. + +== Compare the images with qemu-img compare == +Images are identical. + +*** done
tests/qemu-iotests/group +2 -0
@@ -164,3 +164,5 @@ 162 auto quick 163 rw auto quick 164 rw auto quick +165 rw auto quick +166 rw auto quick
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 3/7] qemu-img: add more conv= conversions to dd
Quoted 41 lines · Reda Sallahi
static int img_dd_conv(const char *arg,
struct DdIo *in, struct DdIo *out, struct DdInfo *dd)
{qemu-img.c +31
-6-if (!strcmp (arg,"notrunc" )) { - dd->conv |=C_NOTRUNC ; -return 0 ; - }else { -error_report ("invalid conversion: '%s'" , arg); -return 1 ; +const char *tok; +char *str, *tmp; +int ret =0 ; +const struct DdSymbols conv[] = { + {"notrunc" ,C_NOTRUNC }, + {"sync" ,C_SYNC }, + {"noerror" ,C_NOERROR }, + {"fdatasync" ,C_FDATASYNC }, + {"fsync" ,C_FSYNC }, + {"excl" ,C_EXCL }, + {"nocreat" ,C_NOCREAT }, + {"sparse" ,C_SPARSE }, + {NULL ,0 } + }; + + tmp = str =g_strdup (arg); + +while (tmp !=NULL && !ret) { + tok =qemu_strsep (&tmp,"," ); +int j; +for (j =0 ; conv[j].name !=NULL ; j++) { +if (!strcmp (tok, conv[j].name)) { +if ((dd->conv | conv[j].value) &C_EXCL && + (dd->conv | conv[j].value) &C_NOCREAT ) { +error_report ("cannot combine excl and nocreat" ); + ret =1 ; +break ; + } + dd->conv |= conv[j].value; +break ; + }
qemu-img.c static int img_dd_seek(const char *arg, · line 3998
Quoted 10 lines
qemu-img.c +8
-0+ } +if (conv[j].name ==NULL ) { +error_report ("invalid conversion: '%s'" , tok); + ret =1 ; + } } + +g_free (str); +return ret; }
This function is very similar to img_dd_iflag/oflag. The code duplication can be avoided if you perform the (dd->conv | conv[j].value) & C_EXCL && (dd->conv | conv[j].value) & C_NOCREAT later.
Quoted 6 lines
qemu-img.c +1
-0@@ -4325,20 +4388,43 @@ static int img_dd(int argc, char **argv)for (out_pos = out.offset * obsz; in_pos < size; block_count++) {int in_ret, out_ret; + bsz = in.bsz;
qemu-img.c static int img_dd(int argc, char **argv) · line 4399
Quoted 10 lines
qemu-img.c +5
-3if (in_pos + in.bsz > size) { - in_ret =blk_pread (blk1, in_pos, in.buf, size - in_pos); - }else { - in_ret =blk_pread (blk1, in_pos, in.buf, in.bsz); + bsz = size - in_pos; + } + +if (dd.conv &C_SYNC ) { +memset (in.buf,0 , in.bsz); }
Why is memset necessary?
Re: [Qemu-devel] [PATCH 3/7] qemu-img: add more conv= conversions to dd
Quoted 7 lines · Stefan Hajnoczi
Quoted 6 lines · Reda Sallahi
qemu-img.c +1
-0@@ -4325,20 +4388,43 @@ static int img_dd(int argc, char **argv)for (out_pos = out.offset * obsz; in_pos < size; block_count++) {int in_ret, out_ret; + bsz = in.bsz;
Quoted 12 lines
qemu-img.c static int img_dd(int argc, char **argv) · line 4399
Quoted 10 lines
qemu-img.c +5
-3if (in_pos + in.bsz > size) { - in_ret =blk_pread (blk1, in_pos, in.buf, size - in_pos); - }else { - in_ret =blk_pread (blk1, in_pos, in.buf, in.bsz); + bsz = size - in_pos; + } + +if (dd.conv &C_SYNC ) { +memset (in.buf,0 , in.bsz); }Why is memset necessary?
When we set conv=noerror,sync sync tells dd to pad each block with NULs so that if there is an error it preserves the size of the input read.
Signature · 1 line
Reda
Re: [Qemu-devel] [PATCH 3/7] qemu-img: add more conv= conversions to dd
Quoted 21 lines · Reda Sallahi
Quoted 7 lines · Stefan Hajnoczi
Quoted 6 lines · Reda Sallahi
qemu-img.c +1
-0@@ -4325,20 +4388,43 @@ static int img_dd(int argc, char **argv)for (out_pos = out.offset * obsz; in_pos < size; block_count++) {int in_ret, out_ret; + bsz = in.bsz;Quoted 12 lines
qemu-img.c static int img_dd(int argc, char **argv) · line 4399
Quoted 10 lines
qemu-img.c +5
-3if (in_pos + in.bsz > size) { - in_ret =blk_pread (blk1, in_pos, in.buf, size - in_pos); - }else { - in_ret =blk_pread (blk1, in_pos, in.buf, in.bsz); + bsz = size - in_pos; + } + +if (dd.conv &C_SYNC ) { +memset (in.buf,0 , in.bsz); }Why is memset necessary?
Quoted 2 lines
When we set conv=noerror,sync sync tells dd to pad each block with NULs so that if there is an error it preserves the size of the input read.
Ah, I see.
Stefan
PATCH 4/7 qemu-img: delete not used variable and an unecessary check
In reply to Reda Sallahiblock_count is not used in img_dd() and the C_SKIP check is unecessary so this patch removes both of them.
--- qemu-img.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
qemu-img.c +3 -4
@@ -4093,7 +4093,7 @@ static int img_dd(int argc, char **argv)const char *out_fmt ="raw" ;const char *fmt =NULL ;int64_t size =0 , out_size =0 ; -int64_t block_count =0 , out_pos, in_pos, sparse_count =0 ; +int64_t out_pos, in_pos, sparse_count =0 ;bool writethrough = false;int flags =0 ;int ibsz =0 , obsz =0 , bsz;
@@ -4373,8 +4373,7 @@ static int img_dd(int argc, char **argv) } } -if (dd.flags &C_SKIP && (in.offset >INT64_MAX / ibsz || - size < in.offset * ibsz)) { +if (in.offset >INT64_MAX / ibsz || size < in.offset * ibsz) {/* We give a warning if the skip option is bigger than the input * size and create an empty output disk image (i.e. like dd(1)). */
@@ -4386,7 +4385,7 @@ static int img_dd(int argc, char **argv) in.buf =g_new (uint8_t, in.bsz); -for (out_pos = out.offset * obsz; in_pos < size; block_count++) { +for (out_pos = out.offset * obsz; in_pos < size;) {int in_ret, out_ret; bsz = in.bsz;
Signature · 1 line
2.9.3
Re: [Qemu-devel] [Qemu-block] [PATCH 4/7] qemu-img: delete not used variable and an unecessary check
Quoted 7 lines · Reda Sallahi
block_countis not used inimg_dd()and theC_SKIPcheck is unecessary so this patch removes both of them.Signed-off-by Reda Sallahi <[email protected]>--- qemu-img.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
PATCH 5/7 qemu-img: add status option to dd
In reply to Reda SallahiThis patch adds the status option to the subcommand dd. With this dd will display by default the number of blocks read/written, the transfer rate, etc. like dd(1).
The noxfer and none levels will allow the user to surpress the final transfer statistics and everything except error messages respectively.
A test case was added to test the status option.
--- qemu-img-cmds.hx | 4 +-- qemu-img.c | 90 ++++++++++++++++++++++++++++++++++++++++++---- qemu-img.texi | 9 ++++- tests/qemu-iotests/159 | 2 +- tests/qemu-iotests/160 | 2 +- tests/qemu-iotests/161 | 2 +- tests/qemu-iotests/163 | 4 +-- tests/qemu-iotests/164 | 4 +-- tests/qemu-iotests/165 | 11 +++--- tests/qemu-iotests/166 | 2 +- tests/qemu-iotests/167 | 77 +++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/167.out | 17 +++++++++ tests/qemu-iotests/group | 1 + 13 files changed, 202 insertions(+), 23 deletions(-) create mode 100755 tests/qemu-iotests/167 create mode 100644 tests/qemu-iotests/167.out
qemu-img-cmds.hx +2 -2
@@ -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] [seek=blocks] [conv=convs] [iflag=flags] [oflag=flags] if=input of=output") + "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [seek=blocks] [conv=convs] [iflag=flags] [oflag=flags] [status=level] 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}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] 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}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] [status=@var{level}] if=@var{input} of=@var{output} ETEXI DEF("info", img_info,
qemu-img.c +83 -7
164 lines not on this page · raw message
qemu-img.texi +8 -1
@@ -202,6 +202,13 @@ interpret 'skip=blocks' as a byte count. Only iflag. @item seek_bytes interpret 'seek=blocks' as a byte count. Only oflag. +@item status=@var{level} +Define the level of information to print to stderr. +@item none +Only error messages are printed. +@item noxfer +Do not print the final transfer rate. + @end table Command description:
@@ -375,7 +382,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}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] 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}] [seek=@var{blocks}] [conv=@var{convs}] [iflag=@var{flags}] [oflag=@var{flags}] [status=@var{level}] 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.
tests/qemu-iotests/159 +1 -1
@@ -56,7 +56,7 @@ for bs in $TEST_SIZES; do echo "== Converting the image with dd with a block size of $bs ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" bs=$bs conv=notrunc \ - -O "$IMGFMT" + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img echo
tests/qemu-iotests/160 +1 -1
@@ -56,7 +56,7 @@ for skip in $TEST_SKIP_BLOCKS; do echo "== Converting the image with dd with skip=$skip ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" conv=notrunc \ - -O "$IMGFMT" 2> /dev/null + -O "$IMGFMT" 2> /dev/null status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" conv=notrunc \ status=none
tests/qemu-iotests/161 +1 -1
@@ -56,7 +56,7 @@ for seek in $TEST_SEEK_BLOCKS; do echo "== Converting the image with dd with seek=$seek ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" seek="$seek" conv=notrunc \ - -O "$IMGFMT" 2> /dev/null + -O "$IMGFMT" 2> /dev/null status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" seek="$seek" conv=notrunc \ status=none
tests/qemu-iotests/163 +2 -2
@@ -58,7 +58,7 @@ for skip in $TEST_SKIP_BLOCKS; do echo "== Converting the image with dd with skip=$skip iflag=skip_bytes ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" skip="$skip" \ - iflag=skip_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + iflag=skip_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" skip="$skip" iflag=skip_bytes \ conv=notrunc status=none
@@ -86,7 +86,7 @@ for count in $TEST_COUNT_BLOCKS; do "iflag=count_bytes ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" count="$skip" \ - iflag=count_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + iflag=count_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" count="$skip" iflag=count_bytes \ conv=notrunc status=none
tests/qemu-iotests/164 +2 -2
@@ -57,7 +57,7 @@ for seek in $TEST_SEEK_BLOCKS; do echo "== Converting the image with dd with seek=$seek oflag=seek_bytes ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" seek="$seek" \ - oflag=seek_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + oflag=seek_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" seek="$seek" \ oflag=seek_bytes status=none
@@ -83,7 +83,7 @@ echo "== Converting the image with dd with seek=$seek" \ "oflag=seek_bytes,direct ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" seek="$seek" \ - oflag=seek_bytes conv=notrunc -O "$IMGFMT" 2> /dev/null + oflag=seek_bytes conv=notrunc -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img dd if="$TEST_IMG" of="$TEST_IMG.out.dd" seek="$seek" \ oflag=seek_bytes,direct conv=notrunc status=none
tests/qemu-iotests/165 +6 -5
@@ -53,7 +53,8 @@ $QEMU_IO -c "write -P 0xa 215k 212k" "$TEST_IMG" | _filter_qemu_io echo echo "== Converting the image with dd with conv=excl ==" -$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc -O "$IMGFMT" +$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc \ + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img
@@ -67,7 +68,7 @@ $QEMU_IMG compare "$TEST_IMG.out.dd" "$TEST_IMG.out" echo echo "== Converting the image with dd with conv=excl ==" -$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc \ +$QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=excl,notrunc status=none \ -O "$IMGFMT" 2>&1 | sed -e "s#$TEST_DIR#TEST_DIR#g" \ -e "s#$IMGFMT#IMGFMT#g"
@@ -83,7 +84,7 @@ echo echo "== Converting the image with dd with conv=nocreat ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=nocreat,notrunc \ - -O "$IMGFMT" + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img
@@ -100,8 +101,8 @@ echo echo "== Converting the image with dd with conv=nocreat ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=nocreat,notrunc \ - -O "$IMGFMT" 2>&1 | sed -e "s#$TEST_DIR#TEST_DIR#g" \ - -e "s#$IMGFMT#IMGFMT#g" + -O "$IMGFMT" 2>&1 status=none | sed -e "s#$TEST_DIR#TEST_DIR#g" \ + -e "s#$IMGFMT#IMGFMT#g" echo echo "*** done"
tests/qemu-iotests/166 +1 -1
@@ -56,7 +56,7 @@ echo echo "== Converting the image with dd with conv=sparse ==" $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" conv=sparse,notrunc \ - -O "$IMGFMT" + -O "$IMGFMT" status=none TEST_IMG="$TEST_IMG.out" _check_test_img
tests/qemu-iotests/167 new file +77 -0
77 lines not on this page · raw message
tests/qemu-iotests/167.out new file +17 -0
@@ -0,0 +1,17 @@ +QA output created by 167 + +== Creating image == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +No errors were found on the image. +wrote 524288/524288 bytes at offset 152576 +512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== Converting the image with dd status=noxfer == +No errors were found on the image. + +== Compare the images with qemu-img compare == +Images are identical. + +== Compare the stat output == + +*** done
tests/qemu-iotests/group +1 -0
@@ -166,3 +166,4 @@ 164 rw auto quick 165 rw auto quick 166 rw auto quick +167 rw auto quick
Signature · 1 line
2.9.3
Re: [Qemu-devel] [Qemu-block] [PATCH 5/7] qemu-img: add status option to dd
Quoted 5 lines · Reda Sallahi
struct DdInfo { unsigned int flags; int64_t count; unsigned int conv;+ unsigned status;
For consistency please use "unsigned int" like you used for the flags and conv fields above.
qemu-img.c static int img_dd(int argc, char **argv) · line 4425
Quoted 3 lines
in.buf = g_new(uint8_t, in.bsz);qemu-img.c +2
-0+if (dd.status &C_STATUS_DEFAULT ) { +gettimeofday (&starttv,NULL );
Please use qemu_gettimeofday() for portability.
Re: [Qemu-devel] [PATCH 5/7] qemu-img: add status option to dd
In reply to Reda SallahiI should have checked the previous test suites because :
Quoted 4 lines · Reda Sallahi
if (in.offset > INT64_MAX / ibsz || size < in.offset * ibsz) {qemu-img.c +0
-2-/* We give a warning if the skip option is bigger than the input -* size and create an empty output disk image (i.e. like dd(1)).
qemu-img.c static int img_dd(int argc, char **argv) · line 4418
Quoted 10 lines
qemu-img.c +7
-3-*/ -error_report ("%s: cannot skip to specified offset" , in.filename); - in_pos = size; +if (!(dd.status &C_STATUS_NONE )) { +/* We give a warning if the skip option is bigger than the input +* size and create an empty output disk image (i.e. like dd(1)). +*/ +error_report ("%s: cannot skip to specified offset" , in.filename); + in_pos = size; + }
in_pos = size should have gone outside of this last block. This means in_pos is set to size only if dd.status != C_STATUS_NONE.
Quoted 1 line
+$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.out"
And also this should have been $TEST_IMG.out.dd.
I fixed this just now (and with a test file that also adds in skip and seek) and will send it in the next version.
Signature · 1 line
Reda
PATCH 6/7 qemu-img: clean up dd documentation
In reply to Reda SallahiThe dd section on qemu-img --help was a bit hard to read since it was not well aligned. This patch fixes the display problem and also makes the sentences on the .texi file more consistent with one another (uppercase and conjugasion).
--- qemu-img.c | 48 +++++++++++++++++++++++++----------------------- qemu-img.texi | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 47 deletions(-)
qemu-img.c +25 -23
@@ -169,37 +169,39 @@ static void QEMU_NORETURN help(void)" '-s' run in Strict mode - fail on different image size or sector allocation\n" "\n" "Parameters to dd subcommand:\n" -" 'bs=BYTES' read and write up to BYTES bytes at a time " +" 'bs=BYTES' read and write up to BYTES bytes at a time " "(default: 512)\n" -" '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" -" 'seek=N' seek N bs-sized blocks at the start of output\n" -" 'conv=CONVS' do not truncate the output file\n" +" '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" +" 'seek=N' seek N bs-sized blocks at the start of output\n" +" 'conv=CONVS' do not truncate the output file\n" " 'iflags=FLAGS' read using the comma-separated flags list\n" " 'oflags=FLAGS' read using the comma-separated flags list\n" " 'status=LEVEL' the LEVEL of information to print to stderr\n\n" "List of LEVELS for dd:\n" -" 'none' surpresses everything but error messages\n" -" 'noxfer' surpresses the final transfer statistics\n\n" +" 'none' surpress everything but error messages\n" +" 'noxfer' surpress the final transfer statistics\n\n" "List of CONVS for dd:\n" -" 'notrunc' do not truncate the output file\n" -" 'noerror' continue in the event of read errors\n" -" 'excl' fail if output already exists\n" -" 'nocreat' do not create the output file\n" -" 'fsync' physically write output file data before finishing\n" -" 'fdatasync' physically write output file data before finishing\n" -" 'sync' pad every input block with NULs\n" -" 'sparse' seek rather than write the output for NUL input" +" 'notrunc' do not truncate the output file\n" +" 'noerror' continue in the event of read errors\n" +" 'excl' fail if output already exists\n" +" 'nocreat' do not create the output file\n" +" 'fsync' physically write output file data before" +" finishing\n" +" 'fdatasync' physically write output file data before" +" finishing\n" +" 'sync' pad every input block with NULs\n" +" 'sparse' seek rather than write the output for NUL input" " blocks\n\n" "List of FLAGS for dd:\n" -" 'direct' use direct I/O for data\n" -" 'dsync' use synchronized I/O for data\n" -" 'sync' use synchronized I/O for data\n" -" 'count_bytes' use 'count=N' as a byte count (iflag only)\n" -" 'skip_bytes' use 'skip=N' as a byte count (iflag only)\n" -" 'seek_bytes' use 'seek=N' as a byte count (oflag only)\n" ; +" 'direct' use direct I/O for data\n" +" 'dsync' use synchronized I/O for data\n" +" 'sync' use synchronized I/O for data\n" +" 'count_bytes' use 'count=N' as a byte count (iflag only)\n" +" 'skip_bytes' use 'skip=N' as a byte count (iflag only)\n" +" 'seek_bytes' use 'seek=N' as a byte count (oflag only)\n" ;printf ("%s\nSupported formats:" , help_msg);bdrv_iterate_format (format_print,NULL );
qemu-img.texi +24 -24
93 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 6/7] qemu-img: clean up dd documentation
Quoted 10 lines · Reda Sallahi
The dd section on qemu-img --help was a bit hard to read since it was not well aligned. This patch fixes the display problem and also makes the sentences on the .texi file more consistent with one another (uppercase and conjugasion).
Signed-off-by Reda Sallahi <[email protected]>--- qemu-img.c | 48 +++++++++++++++++++++++++----------------------- qemu-img.texi | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 47 deletions(-)
PATCH 7/7 qemu-img: add a test suite for the count option
In reply to Reda SallahiThe count option for dd lacked a test suite so this adds one with four test cases.
--- tests/qemu-iotests/168 | 75 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/168.out | 51 +++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 127 insertions(+) create mode 100755 tests/qemu-iotests/168 create mode 100644 tests/qemu-iotests/168.out
tests/qemu-iotests/168 new file +75 -0
@@ -0,0 +1,75 @@ +#! /bin/bash +# +# qemu-img dd test for count option +# +# Copyright (C) 2016 Reda Sallahi +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + [email protected] + +seq="$(basename $0)" +echo "QA output created by $seq" + +here="$PWD" +status=1 + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.out" "$TEST_IMG.out.dd" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +. ./common.rc +. ./common.filter +. ./common.pattern + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +TEST_COUNT_BLOCKS="1 4 19 43K" + +for count in $TEST_COUNT_BLOCKS; do + echo + echo "== Creating image ==" + + size=1M + _make_test_img $size + _check_test_img + + $QEMU_IO -c "write -P 0xa 565k 384k" "$TEST_IMG" | _filter_qemu_io + + echo + echo "== Converting the image with dd with count=$count ==" + + $QEMU_IMG dd if="$TEST_IMG" of="$TEST_IMG.out" count=$count \ + -O "$IMGFMT" status=none conv=notrunc + + TEST_IMG="$TEST_IMG.out" _check_test_img + + dd if="$TEST_IMG" of="$TEST_IMG.out.dd" count=$count status=none + + echo + echo "== Compare the images with qemu-img compare ==" + + $QEMU_IMG compare "$TEST_IMG.out.dd" "$TEST_IMG.out" +done + +echo +echo "*** done" +rm -f "$seq.full" +status=0
tests/qemu-iotests/168.out new file +51 -0
51 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -167,3 +167,4 @@ 165 rw auto quick 166 rw auto quick 167 rw auto quick +168 rw auto quick
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 7/7] qemu-img: add a test suite for the count option
Quoted 11 lines · Reda Sallahi
The count option for dd lacked a test suite so this adds one with four test cases.
Signed-off-by Reda Sallahi <[email protected]>--- tests/qemu-iotests/168 | 75 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/168.out | 51 +++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 127 insertions(+) create mode 100755 tests/qemu-iotests/168 create mode 100644 tests/qemu-iotests/168.out