* [Qemu-devel] [PATCH v2] opts: produce valid command line in qemu_opts_print
@ 2015-07-03 14:45 Kővágó, Zoltán
2015-07-07 11:49 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Kővágó, Zoltán @ 2015-07-03 14:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-trivial, Kevin Wolf, Markus Armbruster,
open list:Block layer core
This will let us print options in a format that the user would actually
write it on the command line (foo=bar,baz=asd,etc=def), without
prepending a spurious comma at the beginning of the list, or quoting
values unnecessarily. This patch provides the following changes:
* write and id=, if the option has an id
* do not print separator before the first element
* do not quote string arguments
* properly escape commas (,) for QEMU
Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
Change from v1:
* updated escaped_print as suggested by Markus
block.c | 2 +-
util/qemu-option.c | 29 ++++++++++++++++++++++++++---
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/block.c b/block.c
index 7e130cc..78a5304 100644
--- a/block.c
+++ b/block.c
@@ -3813,7 +3813,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
}
if (!quiet) {
- printf("Formatting '%s', fmt=%s", filename, fmt);
+ printf("Formatting '%s', fmt=%s ", filename, fmt);
qemu_opts_print(opts, " ");
puts("");
}
diff --git a/util/qemu-option.c b/util/qemu-option.c
index efe9d27..e54ac0d 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -730,14 +730,35 @@ void qemu_opts_del(QemuOpts *opts)
g_free(opts);
}
-void qemu_opts_print(QemuOpts *opts, const char *sep)
+/* print value, escaping any commas in value */
+static void escaped_print(const char *value)
+{
+ const char *ptr;
+
+ for (ptr = value; *ptr; ++ptr) {
+ if (*ptr == ',') {
+ putchar(',');
+ }
+ putchar(*ptr);
+ }
+}
+
+void qemu_opts_print(QemuOpts *opts, const char *separator)
{
QemuOpt *opt;
QemuOptDesc *desc = opts->list->desc;
+ const char *sep = "";
+
+ if (opts->id) {
+ printf("id=%s", opts->id); /* passed id_wellformed -> no commas */
+ sep = separator;
+ }
if (desc[0].name == NULL) {
QTAILQ_FOREACH(opt, &opts->head, next) {
- printf("%s%s=\"%s\"", sep, opt->name, opt->str);
+ printf("%s%s=", sep, opt->name);
+ escaped_print(opt->str);
+ sep = separator;
}
return;
}
@@ -750,13 +771,15 @@ void qemu_opts_print(QemuOpts *opts, const char *sep)
continue;
}
if (desc->type == QEMU_OPT_STRING) {
- printf("%s%s='%s'", sep, desc->name, value);
+ printf("%s%s=", sep, desc->name);
+ escaped_print(value);
} else if ((desc->type == QEMU_OPT_SIZE ||
desc->type == QEMU_OPT_NUMBER) && opt) {
printf("%s%s=%" PRId64, sep, desc->name, opt->value.uint);
} else {
printf("%s%s=%s", sep, desc->name, value);
}
+ sep = separator;
}
}
--
2.4.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH v2] opts: produce valid command line in qemu_opts_print
2015-07-03 14:45 [Qemu-devel] [PATCH v2] opts: produce valid command line in qemu_opts_print Kővágó, Zoltán
@ 2015-07-07 11:49 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2015-07-07 11:49 UTC (permalink / raw)
To: Kővágó, Zoltán
Cc: qemu-trivial, Kevin Wolf, qemu-devel, open list:Block layer core,
Markus Armbruster
[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]
On Fri, Jul 03, 2015 at 04:45:36PM +0200, Kővágó, Zoltán wrote:
> This will let us print options in a format that the user would actually
> write it on the command line (foo=bar,baz=asd,etc=def), without
> prepending a spurious comma at the beginning of the list, or quoting
> values unnecessarily. This patch provides the following changes:
> * write and id=, if the option has an id
> * do not print separator before the first element
> * do not quote string arguments
> * properly escape commas (,) for QEMU
>
> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> ---
>
> Change from v1:
> * updated escaped_print as suggested by Markus
>
> block.c | 2 +-
> util/qemu-option.c | 29 ++++++++++++++++++++++++++---
> 2 files changed, 27 insertions(+), 4 deletions(-)
Looks good but please fix qemu-iotests so the test suite keeps passing:
$ make && cd tests/qemu-iotests && ./check -qcow2
The test fixes must be in the same commit so the git commit history
remains bisectable.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-07 11:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-03 14:45 [Qemu-devel] [PATCH v2] opts: produce valid command line in qemu_opts_print Kővágó, Zoltán
2015-07-07 11:49 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
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).