From patchwork Tue Jun 28 21:27:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9204029 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 8F79F6074E for ; Tue, 28 Jun 2016 21:32:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 846FA285FE for ; Tue, 28 Jun 2016 21:32:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78CE12861C; Tue, 28 Jun 2016 21:32:49 +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 E59F8285FE for ; Tue, 28 Jun 2016 21:32:48 +0000 (UTC) Received: from localhost ([::1]:40028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bI0ci-0004LH-1p for patchwork-qemu-devel@patchwork.kernel.org; Tue, 28 Jun 2016 17:32:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bI0Xm-00083T-Qb for qemu-devel@nongnu.org; Tue, 28 Jun 2016 17:27:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bI0Xk-0005Ql-NA for qemu-devel@nongnu.org; Tue, 28 Jun 2016 17:27:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bI0Xk-0005Qg-Ev for qemu-devel@nongnu.org; Tue, 28 Jun 2016 17:27:40 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10487C049D67; Tue, 28 Jun 2016 21:27:40 +0000 (UTC) Received: from localhost (ovpn-112-80.ams2.redhat.com [10.36.112.80]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5SLRcJp006224; Tue, 28 Jun 2016 17:27:39 -0400 From: Stefan Hajnoczi To: Date: Tue, 28 Jun 2016 22:27:25 +0100 Message-Id: <1467149250-31165-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1467149250-31165-1-git-send-email-stefanha@redhat.com> References: <1467149250-31165-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 28 Jun 2016 21:27:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/8] 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 , Peter Maydell , Paolo Bonzini , Stefan Hajnoczi , "Denis V. Lunev" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Denis V. Lunev" 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 Reviewed-by: Stefan Hajnoczi Message-id: 1466174654-30130-4-git-send-email-den@openvz.org CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- trace/control.c | 42 +++++++++++++++++++++++++++++++++++++++++- trace/control.h | 25 ++++++++++++++----------- vl.c | 38 ++------------------------------------ 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/trace/control.c b/trace/control.c index e1556a3..86de8b9 100644 --- a/trace/control.c +++ b/trace/control.c @@ -21,11 +21,33 @@ #endif #include "qapi/error.h" #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); @@ -142,7 +164,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; @@ -217,3 +239,21 @@ 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")); + 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..a2dd3ea 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,20 @@ 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 + * + * Initialize tracing subsystem. + * + * Returns the filename to save trace to. It must be freed with g_free(). + */ +char *trace_opt_parse(const char *optarg); #include "trace/control-internal.h" diff --git a/vl.c b/vl.c index 4c1f9ae..90cf638 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", @@ -3864,23 +3844,9 @@ 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); + g_free(trace_file); + trace_file = trace_opt_parse(optarg); break; - } case QEMU_OPTION_readconfig: { int ret = qemu_read_config_file(optarg);