From patchwork Thu Jun 2 18:35:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9151085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C4FC60467 for ; Thu, 2 Jun 2016 18:40:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C9BD25E13 for ; Thu, 2 Jun 2016 18:40:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 008F928327; Thu, 2 Jun 2016 18:39:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B40425E13 for ; Thu, 2 Jun 2016 18:39:59 +0000 (UTC) Received: from localhost ([::1]:49742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XXC-0006Ig-LV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 14:39:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTR-00030I-Pd for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8XTG-0006eX-IJ for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:05 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:14644 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTG-0006eE-4C; Thu, 02 Jun 2016 14:35:54 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u52IZjA0004792; Thu, 2 Jun 2016 21:35:48 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 21:35:41 +0300 Message-Id: <1464892545-26544-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464892545-26544-1-git-send-email-den@openvz.org> References: <1464892545-26544-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 1/5] trace: move qemu_trace_opts to trace/control.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , den@openvz.org, Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Eric Blake CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Kevin Wolf --- 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);