On 12.04.2017 18:44, Daniel P. Berrange wrote: > The qemu-img dd/convert commands will create a image file and > then try to open it. Historically it has been possible to open > new files without passing any options. With encrypted files > though, the *key-secret options are mandatory, so we need to > provide those options when opening the newly created file. > > Signed-off-by: Daniel P. Berrange <berra...@redhat.com> > --- > qemu-img.c | 41 +++++++++++++++++++++++++++++++++++------ > 1 file changed, 35 insertions(+), 6 deletions(-)
Thanks! > diff --git a/qemu-img.c b/qemu-img.c > index 31c4923..3d9e7b3 100644 > --- a/qemu-img.c > +++ b/qemu-img.c [...] > @@ -332,6 +334,33 @@ static BlockBackend *img_open_file(const char *filename, > } > > > +static int img_add_key_secrets(void *opaque, > + const char *name, const char *value, > + Error **errp) > +{ > + QDict *options = opaque; > + > + if (g_str_has_suffix(name, "key-secret")) { > + qdict_put(options, name, qstring_from_str(value)); > + } > + > + return 0; > +} > + > +static BlockBackend *img_open_new_file(const char *filename, > + QemuOpts *create_opts, > + const char *fmt, int flags, > + bool writethrough, bool quiet) > +{ > + QDict *options = NULL; > + > + options = qdict_new(); > + qemu_opt_foreach(create_opts, img_add_key_secrets, options, NULL); I'd prefer &error_abort instead of NULL there. Not a hard requirement, but I don't see a reason not to use it. Max > + > + return img_open_file(filename, options, fmt, flags, writethrough, quiet); > +} > + > + > static BlockBackend *img_open(bool image_opts, > const char *filename, > const char *fmt, int flags, bool writethrough, > @@ -351,7 +380,7 @@ static BlockBackend *img_open(bool image_opts, [...]
signature.asc
Description: OpenPGP digital signature