* [Qemu-devel] [PATCH 1/5] trace: move qemu_trace_opts to trace/control.c
2016-06-02 18:35 [Qemu-devel] [PATCH v3 0/5] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
@ 2016-06-02 18:35 ` Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 2/5] trace: enable tracing in qemu-io Denis V. Lunev
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Denis V. Lunev @ 2016-06-02 18:35 UTC (permalink / raw)
To: qemu-block, qemu-devel; +Cc: den, Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
The patch also creates trace_opt_parse() helper in trace/control.c to reuse
this code in next patches for qemu-nbd and qemu-io.
The patch also makes trace_init_events() static, as this call is not used
outside the module anymore.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
trace/control.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
trace/control.h | 24 +++++++++++++-----------
vl.c | 37 +------------------------------------
3 files changed, 57 insertions(+), 48 deletions(-)
diff --git a/trace/control.c b/trace/control.c
index d099f73..75fc731 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -20,11 +20,33 @@
#include "qemu/log.h"
#endif
#include "qemu/error-report.h"
+#include "qemu/config-file.h"
#include "monitor/monitor.h"
int trace_events_enabled_count;
bool trace_events_dstate[TRACE_EVENT_COUNT];
+QemuOptsList qemu_trace_opts = {
+ .name = "trace",
+ .implied_opt_name = "enable",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
+ .desc = {
+ {
+ .name = "enable",
+ .type = QEMU_OPT_STRING,
+ },
+ {
+ .name = "events",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "file",
+ .type = QEMU_OPT_STRING,
+ },
+ { /* end of list */ }
+ },
+};
+
+
TraceEvent *trace_event_name(const char *name)
{
assert(name != NULL);
@@ -141,7 +163,7 @@ void trace_enable_events(const char *line_buf)
}
}
-void trace_init_events(const char *fname)
+static void trace_init_events(const char *fname)
{
Location loc;
FILE *fp;
@@ -216,3 +238,23 @@ bool trace_init_backends(void)
return true;
}
+
+char *trace_opt_parse(const char *optarg, char *trace_file)
+{
+ QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("trace"),
+ optarg, true);
+ if (!opts) {
+ exit(1);
+ }
+ if (qemu_opt_get(opts, "enable")) {
+ trace_enable_events(qemu_opt_get(opts, "enable"));
+ }
+ trace_init_events(qemu_opt_get(opts, "events"));
+ if (trace_file) {
+ g_free(trace_file);
+ }
+ trace_file = g_strdup(qemu_opt_get(opts, "file"));
+ qemu_opts_del(opts);
+
+ return trace_file;
+}
diff --git a/trace/control.h b/trace/control.h
index e2ba6d4..942f9f5 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -160,17 +160,6 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);
bool trace_init_backends(void);
/**
- * trace_init_events:
- * @events: Name of file with events to be enabled at startup; may be NULL.
- * Corresponds to commandline option "-trace events=...".
- *
- * Read the list of enabled tracing events.
- *
- * Returns: Whether the backends could be successfully initialized.
- */
-void trace_init_events(const char *file);
-
-/**
* trace_init_file:
* @file: Name of trace output file; may be NULL.
* Corresponds to commandline option "-trace file=...".
@@ -197,6 +186,19 @@ void trace_list_events(void);
*/
void trace_enable_events(const char *line_buf);
+/**
+ * Definition of QEMU options describing trace subsystem configuration
+ */
+extern QemuOptsList qemu_trace_opts;
+
+/**
+ * trace_opt_parse:
+ * @optarg: A string argument of --trace command line argument
+ * @trace_file: current filename to save traces to
+ *
+ * Initialize tracing subsystem.
+ */
+char *trace_opt_parse(const char *optarg, char *trace_file);
#include "trace/control-internal.h"
diff --git a/vl.c b/vl.c
index 2f74fe8..f715acf 100644
--- a/vl.c
+++ b/vl.c
@@ -262,26 +262,6 @@ static QemuOptsList qemu_sandbox_opts = {
},
};
-static QemuOptsList qemu_trace_opts = {
- .name = "trace",
- .implied_opt_name = "enable",
- .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
- .desc = {
- {
- .name = "enable",
- .type = QEMU_OPT_STRING,
- },
- {
- .name = "events",
- .type = QEMU_OPT_STRING,
- },{
- .name = "file",
- .type = QEMU_OPT_STRING,
- },
- { /* end of list */ }
- },
-};
-
static QemuOptsList qemu_option_rom_opts = {
.name = "option-rom",
.implied_opt_name = "romfile",
@@ -3872,23 +3852,8 @@ int main(int argc, char **argv, char **envp)
xen_mode = XEN_ATTACH;
break;
case QEMU_OPTION_trace:
- {
- opts = qemu_opts_parse_noisily(qemu_find_opts("trace"),
- optarg, true);
- if (!opts) {
- exit(1);
- }
- if (qemu_opt_get(opts, "enable")) {
- trace_enable_events(qemu_opt_get(opts, "enable"));
- }
- trace_init_events(qemu_opt_get(opts, "events"));
- if (trace_file) {
- g_free(trace_file);
- }
- trace_file = g_strdup(qemu_opt_get(opts, "file"));
- qemu_opts_del(opts);
+ trace_file = trace_opt_parse(optarg, trace_file);
break;
- }
case QEMU_OPTION_readconfig:
{
int ret = qemu_read_config_file(optarg);
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH 2/5] trace: enable tracing in qemu-io
2016-06-02 18:35 [Qemu-devel] [PATCH v3 0/5] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 1/5] trace: move qemu_trace_opts to trace/control.c Denis V. Lunev
@ 2016-06-02 18:35 ` Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 3/5] trace: enable tracing in qemu-nbd Denis V. Lunev
` (2 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Denis V. Lunev @ 2016-06-02 18:35 UTC (permalink / raw)
To: qemu-block, qemu-devel; +Cc: den, Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
Moving trace_init_backends() into trace_opt_parse() is not possible. This
should be called after daemonize() in vl.c.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
qemu-io.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index d977a6e..6b5700f 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -18,6 +18,7 @@
#include "qemu/option.h"
#include "qemu/config-file.h"
#include "qemu/readline.h"
+#include "qemu/log.h"
#include "qapi/qmp/qstring.h"
#include "qom/object_interfaces.h"
#include "sysemu/block-backend.h"
@@ -253,7 +254,9 @@ static void usage(const char *name)
" -k, --native-aio use kernel AIO implementation (on Linux only)\n"
" -t, --cache=MODE use the given cache mode for the image\n"
" -d, --discard=MODE use the given discard mode for the image\n"
-" -T, --trace FILE enable trace events listed in the given file\n"
+" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
+" specify tracing options\n"
+" see qemu(1) man page for full description\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"
"\n"
@@ -458,6 +461,7 @@ int main(int argc, char **argv)
Error *local_error = NULL;
QDict *opts = NULL;
const char *format = NULL;
+ char *trace_file = NULL;
#ifdef CONFIG_POSIX
signal(SIGPIPE, SIG_IGN);
@@ -470,6 +474,7 @@ int main(int argc, char **argv)
module_call_init(MODULE_INIT_QOM);
qemu_add_opts(&qemu_object_opts);
+ qemu_add_opts(&qemu_trace_opts);
bdrv_init();
while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) {
@@ -509,9 +514,7 @@ int main(int argc, char **argv)
}
break;
case 'T':
- if (!trace_init_backends()) {
- exit(1); /* error message will have been printed */
- }
+ trace_file = trace_opt_parse(optarg, trace_file);
break;
case 'V':
printf("%s version %s\n", progname, QEMU_VERSION);
@@ -557,6 +560,12 @@ int main(int argc, char **argv)
exit(1);
}
+ if (!trace_init_backends()) {
+ exit(1);
+ }
+ trace_init_file(trace_file);
+ qemu_set_log(LOG_TRACE);
+
/* initialize commands */
qemuio_add_command(&quit_cmd);
qemuio_add_command(&open_cmd);
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH 3/5] trace: enable tracing in qemu-nbd
2016-06-02 18:35 [Qemu-devel] [PATCH v3 0/5] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 1/5] trace: move qemu_trace_opts to trace/control.c Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 2/5] trace: enable tracing in qemu-io Denis V. Lunev
@ 2016-06-02 18:35 ` Denis V. Lunev
2016-06-03 14:46 ` Eric Blake
2016-06-02 18:35 ` [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing Denis V. Lunev
2016-06-02 18:35 ` [Qemu-devel] [PATCH 5/5] trace: enable tracing in qemu-img Denis V. Lunev
4 siblings, 1 reply; 11+ messages in thread
From: Denis V. Lunev @ 2016-06-02 18:35 UTC (permalink / raw)
To: qemu-block, qemu-devel
Cc: den, Eric Blake, Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
Please note, trace_init_backends() must be called in the final process,
i.e. after daemonization. This is necessary to keep tracing thread in
the proper process.
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Eric Blake <eblake@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
qemu-nbd.c | 18 +++++++++++++++++-
qemu-nbd.texi | 28 ++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 6554f0a..cd29164 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -27,12 +27,14 @@
#include "qemu/error-report.h"
#include "qemu/config-file.h"
#include "qemu/bswap.h"
+#include "qemu/log.h"
#include "block/snapshot.h"
#include "qapi/util.h"
#include "qapi/qmp/qstring.h"
#include "qom/object_interfaces.h"
#include "io/channel-socket.h"
#include "crypto/init.h"
+#include "trace/control.h"
#include <getopt.h>
#include <libgen.h>
@@ -88,6 +90,8 @@ static void usage(const char *name)
"General purpose options:\n"
" --object type,id=ID,... define an object such as 'secret' for providing\n"
" passwords and/or encryption keys\n"
+" --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
+" specify tracing options\n"
#ifdef __linux__
"Kernel NBD client support:\n"
" -c, --connect=DEV connect FILE to the local NBD device DEV\n"
@@ -470,7 +474,7 @@ int main(int argc, char **argv)
off_t fd_size;
QemuOpts *sn_opts = NULL;
const char *sn_id_or_name = NULL;
- const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:x:";
+ const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:x:T:";
struct option lopt[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
@@ -498,6 +502,7 @@ int main(int argc, char **argv)
{ "export-name", required_argument, NULL, 'x' },
{ "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS },
{ "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
+ { "trace", required_argument, NULL, 'T' },
{ NULL, 0, NULL, 0 }
};
int ch;
@@ -518,6 +523,7 @@ int main(int argc, char **argv)
const char *tlscredsid = NULL;
bool imageOpts = false;
bool writethrough = true;
+ char *trace_file = NULL;
/* The client thread uses SIGTERM to interrupt the server. A signal
* handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -531,6 +537,7 @@ int main(int argc, char **argv)
module_call_init(MODULE_INIT_QOM);
qemu_add_opts(&qemu_object_opts);
+ qemu_add_opts(&qemu_trace_opts);
qemu_init_exec_dir(argv[0]);
while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
@@ -703,6 +710,9 @@ int main(int argc, char **argv)
case QEMU_NBD_OPT_IMAGE_OPTS:
imageOpts = true;
break;
+ case 'T':
+ trace_file = trace_opt_parse(optarg, trace_file);
+ break;
}
}
@@ -718,6 +728,12 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ if (!trace_init_backends()) {
+ exit(1);
+ }
+ trace_init_file(trace_file);
+ qemu_set_log(LOG_TRACE);
+
if (tlscredsid) {
if (sockpath) {
error_report("TLS is only supported with IPv4/IPv6");
diff --git a/qemu-nbd.texi b/qemu-nbd.texi
index 9f23343..e6943ad 100644
--- a/qemu-nbd.texi
+++ b/qemu-nbd.texi
@@ -92,6 +92,34 @@ Display extra debugging information
Display this help and exit
@item -V, --version
Display version information and exit
+@item -T, --trace [events=@var{file}][,file=@var{file}]
+@findex --trace
+
+Specify tracing options.
+
+@table @option
+@item [enable=]@var{pattern}
+Immediately enable events matching @var{pattern}.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too. This option is only
+available if QEMU NBD has been compiled with the @var{simple}, @var{stderr}
+or @var{ftrace} tracing backend. To specify multiple events or patterns,
+specify the @option{--trace} option multiple times.
+
+Use @code{--trace help} to print a list of names of trace points.
+
+@item events=@var{file}
+Immediately enable events listed in @var{file}.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too. This option is only
+available if QEMU NBD has been compiled with the @var{simple}, @var{stderr} or
+@var{ftrace} tracing backend.
+
+@item file=@var{file}
+Log output traces to @var{file}.
+This option is only available if QEMU NBD has been compiled with
+the @var{simple} tracing backend.
+@end table
@end table
@c man end
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 3/5] trace: enable tracing in qemu-nbd
2016-06-02 18:35 ` [Qemu-devel] [PATCH 3/5] trace: enable tracing in qemu-nbd Denis V. Lunev
@ 2016-06-03 14:46 ` Eric Blake
2016-06-03 14:48 ` Denis V. Lunev
0 siblings, 1 reply; 11+ messages in thread
From: Eric Blake @ 2016-06-03 14:46 UTC (permalink / raw)
To: Denis V. Lunev, qemu-block, qemu-devel
Cc: Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]
On 06/02/2016 12:35 PM, Denis V. Lunev wrote:
> Please note, trace_init_backends() must be called in the final process,
> i.e. after daemonization. This is necessary to keep tracing thread in
> the proper process.
>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Eric Blake <eblake@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> CC: Kevin Wolf <kwolf@redhat.com>
> ---
> qemu-nbd.c | 18 +++++++++++++++++-
> qemu-nbd.texi | 28 ++++++++++++++++++++++++++++
> 2 files changed, 45 insertions(+), 1 deletion(-)
>
> +" --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
> +" specify tracing options\n"
> +++ b/qemu-nbd.texi
> @@ -92,6 +92,34 @@ Display extra debugging information
> Display this help and exit
> @item -V, --version
> Display version information and exit
> +@item -T, --trace [events=@var{file}][,file=@var{file}]
Why do these two descriptions differ?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 3/5] trace: enable tracing in qemu-nbd
2016-06-03 14:46 ` Eric Blake
@ 2016-06-03 14:48 ` Denis V. Lunev
0 siblings, 0 replies; 11+ messages in thread
From: Denis V. Lunev @ 2016-06-03 14:48 UTC (permalink / raw)
To: Eric Blake, qemu-block, qemu-devel
Cc: Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
On 06/03/2016 05:46 PM, Eric Blake wrote:
> On 06/02/2016 12:35 PM, Denis V. Lunev wrote:
>> Please note, trace_init_backends() must be called in the final process,
>> i.e. after daemonization. This is necessary to keep tracing thread in
>> the proper process.
>>
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> CC: Eric Blake <eblake@redhat.com>
>> CC: Paolo Bonzini <pbonzini@redhat.com>
>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>> CC: Kevin Wolf <kwolf@redhat.com>
>> ---
>> qemu-nbd.c | 18 +++++++++++++++++-
>> qemu-nbd.texi | 28 ++++++++++++++++++++++++++++
>> 2 files changed, 45 insertions(+), 1 deletion(-)
>>
>> +" --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
>> +" specify tracing options\n"
>> +++ b/qemu-nbd.texi
>> @@ -92,6 +92,34 @@ Display extra debugging information
>> Display this help and exit
>> @item -V, --version
>> Display version information and exit
>> +@item -T, --trace [events=@var{file}][,file=@var{file}]
> Why do these two descriptions differ?
>
my fault. I have changed description several times. Man is correct
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing
2016-06-02 18:35 [Qemu-devel] [PATCH v3 0/5] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
` (2 preceding siblings ...)
2016-06-02 18:35 ` [Qemu-devel] [PATCH 3/5] trace: enable tracing in qemu-nbd Denis V. Lunev
@ 2016-06-02 18:35 ` Denis V. Lunev
2016-06-03 14:50 ` Eric Blake
2016-06-02 18:35 ` [Qemu-devel] [PATCH 5/5] trace: enable tracing in qemu-img Denis V. Lunev
4 siblings, 1 reply; 11+ messages in thread
From: Denis V. Lunev @ 2016-06-02 18:35 UTC (permalink / raw)
To: qemu-block, qemu-devel
Cc: den, Eric Blake, Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
This is necessary to enable creation of common qemu-img options which will
be specified before command.
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Eric Blake <eblake@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
qemu-img.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 4b56ad3..aa85b6c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3499,26 +3499,33 @@ int main(int argc, char **argv)
if (argc < 2) {
error_exit("Not enough arguments");
}
- cmdname = argv[1];
qemu_add_opts(&qemu_object_opts);
qemu_add_opts(&qemu_source_opts);
- /* find the command */
- for (cmd = img_cmds; cmd->name != NULL; cmd++) {
- if (!strcmp(cmdname, cmd->name)) {
- return cmd->handler(argc - 1, argv + 1);
+ while ((c = getopt_long(argc, argv, "+h", long_options, NULL)) != -1) {
+ switch (c) {
+ case 'h':
+ help();
+ return 0;
+ case 'v':
+ printf(QEMU_IMG_VERSION);
+ return 0;
}
}
- c = getopt_long(argc, argv, "h", long_options, NULL);
+ cmdname = argv[optind];
- if (c == 'h') {
- help();
- }
- if (c == 'v') {
- printf(QEMU_IMG_VERSION);
- return 0;
+ /* reset getopt_long scanning */
+ argc -= optind;
+ argv += optind;
+ optind = 1;
+
+ /* find the command */
+ for (cmd = img_cmds; cmd->name != NULL; cmd++) {
+ if (!strcmp(cmdname, cmd->name)) {
+ return cmd->handler(argc, argv);
+ }
}
/* not found */
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing
2016-06-02 18:35 ` [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing Denis V. Lunev
@ 2016-06-03 14:50 ` Eric Blake
0 siblings, 0 replies; 11+ messages in thread
From: Eric Blake @ 2016-06-03 14:50 UTC (permalink / raw)
To: Denis V. Lunev, qemu-block, qemu-devel
Cc: Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]
On 06/02/2016 12:35 PM, Denis V. Lunev wrote:
> This is necessary to enable creation of common qemu-img options which will
> be specified before command.
>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Eric Blake <eblake@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> CC: Kevin Wolf <kwolf@redhat.com>
> ---
> qemu-img.c | 31 +++++++++++++++++++------------
> 1 file changed, 19 insertions(+), 12 deletions(-)
>
> - /* find the command */
> - for (cmd = img_cmds; cmd->name != NULL; cmd++) {
> - if (!strcmp(cmdname, cmd->name)) {
> - return cmd->handler(argc - 1, argv + 1);
> + while ((c = getopt_long(argc, argv, "+h", long_options, NULL)) != -1) {
> + switch (c) {
> + case 'h':
> + help();
> + return 0;
> + case 'v':
Umm, how is 'v' supposed to be hit if it is not passed in the short
option string summary? That is, 'qemu-img --version' will work, but
'qemu-img -v' won't; while both 'qemu-img --help' and 'qemu-img -h' work.
> + printf(QEMU_IMG_VERSION);
> + return 0;
> }
> }
>
> - c = getopt_long(argc, argv, "h", long_options, NULL);
> + cmdname = argv[optind];
>
> - if (c == 'h') {
> - help();
> - }
> - if (c == 'v') {
On the other hand, it seems to be a pre-existing bug. Still, it's worth
fixing while you're touching this.
In addition to moving the option processing, you should also update the
documentation (both --help and man page).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH 5/5] trace: enable tracing in qemu-img
2016-06-02 18:35 [Qemu-devel] [PATCH v3 0/5] trace: enable tracing in qemu-io/qemu-nbd/qemu-img Denis V. Lunev
` (3 preceding siblings ...)
2016-06-02 18:35 ` [Qemu-devel] [PATCH 4/5] qemu-img: move common options parsing before commands processing Denis V. Lunev
@ 2016-06-02 18:35 ` Denis V. Lunev
2016-06-03 14:55 ` Eric Blake
4 siblings, 1 reply; 11+ messages in thread
From: Denis V. Lunev @ 2016-06-02 18:35 UTC (permalink / raw)
To: qemu-block, qemu-devel
Cc: den, Eric Blake, Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
The command will work this way:
qemu-img --trace qcow2* create -f qcow2 1.img 64G
Signed-off-by: Denis V. Lunev <den@openvz.org>
Suggested by: Daniel P. Berrange <berrange@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
qemu-img.c | 24 +++++++++++++++++++++---
qemu-img.texi | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index aa85b6c..3b069d8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -31,6 +31,7 @@
#include "qemu/config-file.h"
#include "qemu/option.h"
#include "qemu/error-report.h"
+#include "qemu/log.h"
#include "qom/object_interfaces.h"
#include "sysemu/sysemu.h"
#include "sysemu/block-backend.h"
@@ -38,6 +39,7 @@
#include "block/blockjob.h"
#include "block/qapi.h"
#include "crypto/init.h"
+#include "trace/control.h"
#include <getopt.h>
#define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION QEMU_PKGVERSION \
@@ -87,7 +89,7 @@ static void QEMU_NORETURN help(void)
{
const char *help_msg =
QEMU_IMG_VERSION
- "usage: qemu-img command [command options]\n"
+ "usage: qemu-img [common options] command [command options]\n"
"QEMU disk image utility\n"
"\n"
"Command syntax:\n"
@@ -156,10 +158,14 @@ static void QEMU_NORETURN help(void)
" '-f' first image format\n"
" '-F' second image format\n"
" '-s' run in Strict mode - fail on different image size or sector allocation\n";
+ const char *help_msg2 =
+ "Common options:\n"
+ " '-T', --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
+ " specify tracing options\n";
printf("%s\nSupported formats:", help_msg);
bdrv_iterate_format(format_print, NULL);
- printf("\n");
+ printf("\n\n%s", help_msg2);
exit(EXIT_SUCCESS);
}
@@ -3473,10 +3479,12 @@ int main(int argc, char **argv)
const img_cmd_t *cmd;
const char *cmdname;
Error *local_error = NULL;
+ char *trace_file = NULL;
int c;
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
+ {"trace", required_argument, NULL, 'T'},
{0, 0, 0, 0}
};
@@ -3502,8 +3510,9 @@ int main(int argc, char **argv)
qemu_add_opts(&qemu_object_opts);
qemu_add_opts(&qemu_source_opts);
+ qemu_add_opts(&qemu_trace_opts);
- while ((c = getopt_long(argc, argv, "+h", long_options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "+hT:", long_options, NULL)) != -1) {
switch (c) {
case 'h':
help();
@@ -3511,6 +3520,9 @@ int main(int argc, char **argv)
case 'v':
printf(QEMU_IMG_VERSION);
return 0;
+ case 'T':
+ trace_file = trace_opt_parse(optarg, trace_file);
+ break;
}
}
@@ -3521,6 +3533,12 @@ int main(int argc, char **argv)
argv += optind;
optind = 1;
+ if (!trace_init_backends()) {
+ exit(1);
+ }
+ trace_init_file(trace_file);
+ qemu_set_log(LOG_TRACE);
+
/* find the command */
for (cmd = img_cmds; cmd->name != NULL; cmd++) {
if (!strcmp(cmdname, cmd->name)) {
diff --git a/qemu-img.texi b/qemu-img.texi
index afaebdd..36f4240 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -1,6 +1,6 @@
@example
@c man begin SYNOPSIS
-@command{qemu-img} @var{command} [@var{command} @var{options}]
+@command{qemu-img} [@var{common} @var{options}] @var{command} [@var{command} @var{options}]
@c man end
@end example
@@ -16,6 +16,38 @@ inconsistent state.
@c man begin OPTIONS
+Common options:
+@table @option
+@item -T, --trace [events=@var{file}][,file=@var{file}]
+@findex --trace
+
+Specify tracing options.
+
+@table @option
+@item [enable=]@var{pattern}
+Immediately enable events matching @var{pattern}.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too. This option is only
+available if QEMU IMG has been compiled with the @var{simple}, @var{stderr}
+or @var{ftrace} tracing backend. To specify multiple events or patterns,
+specify the @option{--trace} option multiple times.
+
+Use @code{--trace help} to print a list of names of trace points.
+
+@item events=@var{file}
+Immediately enable events listed in @var{file}.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too. This option is only
+available if QEMU IMG has been compiled with the @var{simple}, @var{stderr} or
+@var{ftrace} tracing backend.
+
+@item file=@var{file}
+Log output traces to @var{file}.
+This option is only available if QEMU IMG has been compiled with
+the @var{simple} tracing backend.
+@end table
+@end table
+
The following commands are supported:
@include qemu-img-cmds.texi
--
2.1.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 5/5] trace: enable tracing in qemu-img
2016-06-02 18:35 ` [Qemu-devel] [PATCH 5/5] trace: enable tracing in qemu-img Denis V. Lunev
@ 2016-06-03 14:55 ` Eric Blake
2016-06-03 14:58 ` Denis V. Lunev
0 siblings, 1 reply; 11+ messages in thread
From: Eric Blake @ 2016-06-03 14:55 UTC (permalink / raw)
To: Denis V. Lunev, qemu-block, qemu-devel
Cc: Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
[-- Attachment #1: Type: text/plain, Size: 2641 bytes --]
On 06/02/2016 12:35 PM, Denis V. Lunev wrote:
> The command will work this way:
> qemu-img --trace qcow2* create -f qcow2 1.img 64G
>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> Suggested by: Daniel P. Berrange <berrange@redhat.com>
> CC: Eric Blake <eblake@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> CC: Kevin Wolf <kwolf@redhat.com>
> ---
> qemu-img.c | 24 +++++++++++++++++++++---
> qemu-img.texi | 34 +++++++++++++++++++++++++++++++++-
> 2 files changed, 54 insertions(+), 4 deletions(-)
>
> @@ -87,7 +89,7 @@ static void QEMU_NORETURN help(void)
> {
> const char *help_msg =
> QEMU_IMG_VERSION
> - "usage: qemu-img command [command options]\n"
> + "usage: qemu-img [common options] command [command options]\n"
> "QEMU disk image utility\n"
This hunk belongs in the previous patch
> "\n"
> "Command syntax:\n"
> @@ -156,10 +158,14 @@ static void QEMU_NORETURN help(void)
> " '-f' first image format\n"
> " '-F' second image format\n"
> " '-s' run in Strict mode - fail on different image size or sector allocation\n";
> + const char *help_msg2 =
> + "Common options:\n"
> + " '-T', --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
> + " specify tracing options\n";
Part of this hunk belongs in the previous patch, along with mention of
-h/--help as a common option moved up to this area, and adding mention
of -v/--version (once you fix -v to actually work).
> +++ b/qemu-img.texi
> @@ -1,6 +1,6 @@
> @example
> @c man begin SYNOPSIS
> -@command{qemu-img} @var{command} [@var{command} @var{options}]
> +@command{qemu-img} [@var{common} @var{options}] @var{command} [@var{command} @var{options}]
Again, this hunk belongs in the previous commit.
> @c man end
> @end example
>
> @@ -16,6 +16,38 @@ inconsistent state.
>
> @c man begin OPTIONS
>
> +Common options:
> +@table @option
> +@item -T, --trace [events=@var{file}][,file=@var{file}]
As in patch 3, why does this synopsis vary from the --help output?
Rather than duplicating the same text in multiple .texi files, should we
put the text in a single sub-file then use inclusion to pull it in? That
way, if we ever tweak the common option parsing for --trace, updating
the one sub-file will update all 3 man pages (qemu, qemu-img, qemu-nbd).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH 5/5] trace: enable tracing in qemu-img
2016-06-03 14:55 ` Eric Blake
@ 2016-06-03 14:58 ` Denis V. Lunev
0 siblings, 0 replies; 11+ messages in thread
From: Denis V. Lunev @ 2016-06-03 14:58 UTC (permalink / raw)
To: Eric Blake, qemu-block, qemu-devel
Cc: Paolo Bonzini, Stefan Hajnoczi, Kevin Wolf
On 06/03/2016 05:55 PM, Eric Blake wrote:
> On 06/02/2016 12:35 PM, Denis V. Lunev wrote:
>> The command will work this way:
>> qemu-img --trace qcow2* create -f qcow2 1.img 64G
>>
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> Suggested by: Daniel P. Berrange <berrange@redhat.com>
>> CC: Eric Blake <eblake@redhat.com>
>> CC: Paolo Bonzini <pbonzini@redhat.com>
>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>> CC: Kevin Wolf <kwolf@redhat.com>
>> ---
>> qemu-img.c | 24 +++++++++++++++++++++---
>> qemu-img.texi | 34 +++++++++++++++++++++++++++++++++-
>> 2 files changed, 54 insertions(+), 4 deletions(-)
>>
>> @@ -87,7 +89,7 @@ static void QEMU_NORETURN help(void)
>> {
>> const char *help_msg =
>> QEMU_IMG_VERSION
>> - "usage: qemu-img command [command options]\n"
>> + "usage: qemu-img [common options] command [command options]\n"
>> "QEMU disk image utility\n"
> This hunk belongs in the previous patch
>
>> "\n"
>> "Command syntax:\n"
>> @@ -156,10 +158,14 @@ static void QEMU_NORETURN help(void)
>> " '-f' first image format\n"
>> " '-F' second image format\n"
>> " '-s' run in Strict mode - fail on different image size or sector allocation\n";
>> + const char *help_msg2 =
>> + "Common options:\n"
>> + " '-T', --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
>> + " specify tracing options\n";
> Part of this hunk belongs in the previous patch, along with mention of
> -h/--help as a common option moved up to this area, and adding mention
> of -v/--version (once you fix -v to actually work).
>
>
>> +++ b/qemu-img.texi
>> @@ -1,6 +1,6 @@
>> @example
>> @c man begin SYNOPSIS
>> -@command{qemu-img} @var{command} [@var{command} @var{options}]
>> +@command{qemu-img} [@var{common} @var{options}] @var{command} [@var{command} @var{options}]
> Again, this hunk belongs in the previous commit.
>
>> @c man end
>> @end example
>>
>> @@ -16,6 +16,38 @@ inconsistent state.
>>
>> @c man begin OPTIONS
>>
>> +Common options:
>> +@table @option
>> +@item -T, --trace [events=@var{file}][,file=@var{file}]
> As in patch 3, why does this synopsis vary from the --help output?
same mistake, have tossed these bits several times. Will fix.
> Rather than duplicating the same text in multiple .texi files, should we
> put the text in a single sub-file then use inclusion to pull it in? That
> way, if we ever tweak the common option parsing for --trace, updating
> the one sub-file will update all 3 man pages (qemu, qemu-img, qemu-nbd).
>
thanks a lot for a review!
^ permalink raw reply [flat|nested] 11+ messages in thread