Skip to contentSkip to conversation

qemu-img: add the 'dd' subcommand

PATCH Superseded Reda Sallahi 1 participant 1 message Jul 21, 2016

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 qemu-img: add the 'dd' subcommand

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.

---
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                       | 363 ++++++++++++++++++++++++++++++++++++++-
 tests/qemu-iotests/158           |  68 ++++++++
 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/group         |   2 +
 8 files changed, 619 insertions(+), 1 deletion(-)
 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
qemu-img-cmds.hx +6 -0
index 7e95b2d..03bdd7a 100644
@@ -45,6 +45,12 @@ STEXI
 @item convert [--object @var{objectdef}] [--image-opts] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 ETEXI
 
+DEF("dd", img_dd,
+    "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] if=input of=output")
+STEXI
+@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] if=@var{input} of=@var{output}
+ETEXI
+
 DEF("info", img_info,
     "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [--backing-chain] filename")
 STEXI
qemu-img.c +362 -1

375 lines not on this page · raw message

tests/qemu-iotests/158 new file +68 -0

68 lines not on this page · raw message

tests/qemu-iotests/158.out new file +15 -0
new file mode 100644
index 0000000..58bfd85
@@ -0,0 +1,15 @@
+QA output created by 158
+
+== Creating image ==
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
+No errors were found on the image.
+wrote 1048576/1048576 bytes at offset 0
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+== Converting the image with dd ==
+No errors were found on the image.
+
+== Compare the images with qemu-img compare ==
+Images are identical.
+
+*** done
tests/qemu-iotests/159 new file +70 -0

70 lines not on this page · raw message

tests/qemu-iotests/159.out new file +87 -0

87 lines not on this page · raw message

tests/qemu-iotests/common.filter +9 -0
index 7853dbb..79d322a 100644
@@ -44,6 +44,15 @@ _filter_imgfmt()
     sed -e "s#$IMGFMT#IMGFMT#g"
 }
 
+# replace error message when the format is not supported and delete
+# the output lines after the first one
+_filter_qemu_img_check()
+{
+    sed -e '/allocated.*fragmented.*compressed clusters/d' \
+        -e 's/qemu-img: This image format does not support checks/No errors were found on the image./' \
+        -e '/Image end offset: [0-9]\+/d'
+}
+
 # Removes \r from messages
 _filter_win32()
 {
tests/qemu-iotests/group +2 -0
index 3a3973e..ec712bc 100644
@@ -157,3 +157,5 @@
 155 rw auto
 156 rw auto quick
 157 auto
+158 rw auto quick
+159 rw auto quick
Signature · 1 line
2.9.0