The -o arg to the convert command allows specification of format/protocol
options for the newly created image. This adds a -o arg to the dd command
to get feature parity.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
qemu-img-cmds.hx | 2 +-
qemu-img.c | 32 +++++++++++++++++++++++++++++++-
qemu-img.texi | 6 ++++--
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index b2c5424..2488cbe 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -46,7 +46,7 @@ STEXI
ETEXI
DEF("dd", img_dd,
- "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [conv=nocreat,notrunc] if=input of=output")
+ "dd [--image-opts] [-f fmt] [-O output_fmt] [-o options] [bs=block_size] [count=blocks] [skip=blocks] [conv=nocreat,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=nocreat,notrunc] if=@var{input} of=@var{output}
ETEXI
diff --git a/qemu-img.c b/qemu-img.c
index c9ab9e5..39fcf09 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3949,6 +3949,7 @@ static int img_dd(int argc, char **argv)
int c, i;
const char *out_fmt = "raw";
const char *fmt = NULL;
+ char *optionstr = NULL;
int64_t size = 0, out_size;
int64_t block_count = 0, out_pos, in_pos;
struct DdInfo dd = {
@@ -3984,7 +3985,7 @@ static int img_dd(int argc, char **argv)
{ 0, 0, 0, 0 }
};
- while ((c = getopt_long(argc, argv, "hnf:O:", long_options, NULL))) {
+ while ((c = getopt_long(argc, argv, "hno:f:O:", long_options, NULL))) {
if (c == EOF) {
break;
}
@@ -3995,6 +3996,20 @@ static int img_dd(int argc, char **argv)
case 'f':
fmt = optarg;
break;
+ case 'o':
+ if (!is_valid_option_list(optarg)) {
+ error_report("Invalid option list: %s", optarg);
+ ret = -1;
+ goto out;
+ }
+ if (!optionstr) {
+ optionstr = g_strdup(optarg);
+ } else {
+ char *old_options = optionstr;
+ optionstr = g_strdup_printf("%s,%s", optionstr, optarg);
+ g_free(old_options);
+ }
+ break;
case '?':
error_report("Try 'qemu-img --help' for more information.");
ret = -1;
@@ -4055,6 +4070,11 @@ static int img_dd(int argc, char **argv)
goto out;
}
+ if (optionstr && has_help_option(optionstr)) {
+ ret = print_block_option_help(out.filename, out_fmt);
+ goto out;
+ }
+
if (qemu_opts_foreach(&qemu_object_opts,
user_creatable_add_opts_foreach,
NULL, NULL)) {
@@ -4099,6 +4119,15 @@ static int img_dd(int argc, char **argv)
create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
+
+ if (optionstr) {
+ qemu_opts_do_parse(opts, optionstr, NULL, &local_err);
+ if (local_err) {
+ error_report_err(local_err);
+ ret = -1;
+ goto out;
+ }
+ }
}
size = blk_getlength(blk1);
@@ -4224,6 +4253,7 @@ static int img_dd(int argc, char **argv)
out:
g_free(arg);
+ g_free(optionstr);
qemu_opts_del(opts);
qemu_opts_free(create_opts);
blk_unref(blk1);
diff --git a/qemu-img.texi b/qemu-img.texi
index 9f10562..01acfb8 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -326,10 +326,12 @@ 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=nocreat,notrunc] if=@var{input} of=@var{output}
+@item dd [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] [conv=nocreat,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.
+@var{fmt} format to @var{output_fmt} format. Depending on the output file
+format, you can add one or more @var{options} that enable additional
+features of this format.
The data is by default read and written using blocks of 512 bytes but can be
modified by specifying @var{block_size}. If count=@var{blocks} is specified
--
2.9.3
On 03.02.2017 13:02, Daniel P. Berrange wrote: > The -o arg to the convert command allows specification of format/protocol > options for the newly created image. This adds a -o arg to the dd command > to get feature parity. > > Signed-off-by: Daniel P. Berrange <berrange@redhat.com> > --- > qemu-img-cmds.hx | 2 +- > qemu-img.c | 32 +++++++++++++++++++++++++++++++- > qemu-img.texi | 6 ++++-- > 3 files changed, 36 insertions(+), 4 deletions(-) I don't like this patch for the same reasons as for patch 3, but I like it a bit better. The code introduced here is exactly the same as for img_convert(), so merging the two would (or "is going to", I hope) be trivial. So a pretty weak Reviewed-by: Max Reitz <mreitz@redhat.com>
On Fri, Feb 03, 2017 at 11:07:13PM +0100, Max Reitz wrote: > On 03.02.2017 13:02, Daniel P. Berrange wrote: > > The -o arg to the convert command allows specification of format/protocol > > options for the newly created image. This adds a -o arg to the dd command > > to get feature parity. > > > > Signed-off-by: Daniel P. Berrange <berrange@redhat.com> > > --- > > qemu-img-cmds.hx | 2 +- > > qemu-img.c | 32 +++++++++++++++++++++++++++++++- > > qemu-img.texi | 6 ++++-- > > 3 files changed, 36 insertions(+), 4 deletions(-) > > I don't like this patch for the same reasons as for patch 3, but I like > it a bit better. The code introduced here is exactly the same as for > img_convert(), so merging the two would (or "is going to", I hope) be > trivial. > > So a pretty weak > > Reviewed-by: Max Reitz <mreitz@redhat.com> Again, I'll drop this patch for now. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
© 2016 - 2026 Red Hat, Inc.