From patchwork Tue Sep 12 21:29:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 813087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xsHyd56GSz9s81 for ; Wed, 13 Sep 2017 07:30:33 +1000 (AEST) Received: from localhost ([::1]:38696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drslL-0000va-Rj for incoming@patchwork.ozlabs.org; Tue, 12 Sep 2017 17:30:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drsl3-0000vB-Kn for qemu-devel@nongnu.org; Tue, 12 Sep 2017 17:30:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drskz-0002XW-Am for qemu-devel@nongnu.org; Tue, 12 Sep 2017 17:30:13 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:42121) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drsky-0002WC-SB for qemu-devel@nongnu.org; Tue, 12 Sep 2017 17:30:09 -0400 Received: from correu-2.ac.upc.es (correu-2.ac.upc.es [147.83.30.92]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id v8CLU5ug022360; Tue, 12 Sep 2017 23:30:05 +0200 Received: from localhost (unknown [31.210.187.58]) by correu-2.ac.upc.es (Postfix) with ESMTPSA id 20DBF25B; Tue, 12 Sep 2017 23:29:59 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Wed, 13 Sep 2017 00:29:58 +0300 Message-Id: <150525179869.15988.10803736017266867796.stgit@frigg.lan> X-Mailer: git-send-email 2.14.1 In-Reply-To: <150525010239.15988.8172586618197849619.stgit@frigg.lan> References: <150525010239.15988.8172586618197849619.stgit@frigg.lan> User-Agent: StGit/0.18 MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id v8CLU5ug022360 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH v5 07/22] instrument: [qapi] Add library loader 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: "Dr. David Alan Gilbert" , Markus Armbruster , "Emilio G. Cota" , Stefan Hajnoczi , Paolo Bonzini , =?utf-8?q?Llu=C3=ADs_Vilanova?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Lluís Vilanova --- MAINTAINERS | 1 + Makefile | 1 + instrument/Makefile.objs | 1 + instrument/qmp.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++ monitor.c | 4 ++ qapi-schema.json | 3 ++ qapi/instrument.json | 49 +++++++++++++++++++++++++++ stubs/instrument.c | 26 +++++++++++++++ 8 files changed, 167 insertions(+) create mode 100644 instrument/qmp.c create mode 100644 qapi/instrument.json diff --git a/MAINTAINERS b/MAINTAINERS index 6c0b12a69a..edddab0502 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1492,6 +1492,7 @@ M: Stefan Hajnoczi S: Maintained F: docs/instrument.txt F: instrument/ +F: qapi/instrument.json TPM S: Orphan diff --git a/Makefile b/Makefile index 337a1f6f9b..3861b3f49c 100644 --- a/Makefile +++ b/Makefile @@ -412,6 +412,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \ $(SRC_PATH)/qapi/char.json \ $(SRC_PATH)/qapi/crypto.json \ + $(SRC_PATH)/qapi/instrument.json \ $(SRC_PATH)/qapi/introspect.json \ $(SRC_PATH)/qapi/migration.json \ $(SRC_PATH)/qapi/net.json \ diff --git a/instrument/Makefile.objs b/instrument/Makefile.objs index 71994a4c85..7bf4e27e3c 100644 --- a/instrument/Makefile.objs +++ b/instrument/Makefile.objs @@ -2,3 +2,4 @@ target-obj-$(CONFIG_INSTRUMENT) += cmdline.o target-obj-$(CONFIG_INSTRUMENT) += load.o +target-obj-$(CONFIG_INSTRUMENT) += qmp.o diff --git a/instrument/qmp.c b/instrument/qmp.c new file mode 100644 index 0000000000..e4464aa5eb --- /dev/null +++ b/instrument/qmp.c @@ -0,0 +1,82 @@ +/* + * QMP interface for instrumentation control commands. + * + * Copyright (C) 2012-2017 Lluís Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include + +#include "instrument/load.h" +#include "qemu-common.h" +#include "qapi/qmp/qerror.h" +#include "qmp-commands.h" + + +InstrLoadResult *qmp_instr_load(const char *path, + bool has_id, const char *id, + bool have_args, strList *args, + Error **errp) +{ + InstrLoadResult *res = g_malloc0(sizeof(*res)); + int argc = 0; + const char **argv = NULL; + InstrLoadError code; + + if (!has_id) { + id = NULL; + } + + strList *entry = have_args ? args : NULL; + while (entry != NULL) { + argv = realloc(argv, sizeof(*argv) * (argc + 1)); + argv[argc] = entry->value; + argc++; + entry = entry->next; + } + + code = instr_load(path, argc, argv, &id); + switch (code) { + case INSTR_LOAD_OK: + res->id = g_strdup(id); + break; + case INSTR_LOAD_ID_EXISTS: + error_setg(errp, "Library ID exists"); + break; + case INSTR_LOAD_TOO_MANY: + error_setg(errp, "Tried to load too many libraries"); + break; + case INSTR_LOAD_ERROR: + error_setg(errp, "Library initialization returned non-zero"); + break; + case INSTR_LOAD_DLERROR: + error_setg(errp, "Error loading library: %s", + dlerror()); + break; + } + + if (*errp) { + g_free(res); + res = NULL; + } + + return res; +} + +void qmp_instr_unload(const char *id, Error **errp) +{ + InstrUnloadError code = instr_unload(id); + switch (code) { + case INSTR_UNLOAD_OK: + break; + case INSTR_UNLOAD_INVALID: + error_setg(errp, "Unknown library ID"); + break; + case INSTR_UNLOAD_DLERROR: + error_setg(errp, "Error unloading library: %s", dlerror()); + break; + } +} diff --git a/monitor.c b/monitor.c index 9239f7adde..e031aa2687 100644 --- a/monitor.c +++ b/monitor.c @@ -978,6 +978,10 @@ static void qmp_unregister_commands_hack(void) qmp_unregister_command(&qmp_commands, "query-xen-replication-status"); qmp_unregister_command(&qmp_commands, "xen-colo-do-checkpoint"); #endif +#ifndef CONFIG_INSTRUMENT + qmp_unregister_command(&qmp_commands, "instr-load"); + qmp_unregister_command(&qmp_commands, "instr-unload"); +#endif #ifndef TARGET_I386 qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection"); #endif diff --git a/qapi-schema.json b/qapi-schema.json index f3af2cb851..706c64659f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -93,6 +93,9 @@ { 'include': 'qapi/trace.json' } { 'include': 'qapi/introspect.json' } +# Instrumentation commands +{ 'include': 'qapi/instrument.json' } + ## # = Miscellanea ## diff --git a/qapi/instrument.json b/qapi/instrument.json new file mode 100644 index 0000000000..c59bee74cb --- /dev/null +++ b/qapi/instrument.json @@ -0,0 +1,49 @@ +# *-*- Mode: Python -*-* +# +# Copyright (C) 2012-2017 Lluís Vilanova +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. + +## +# QAPI instrumentation control commands. +## + +## +# @InstrLoadResult: +# +# Result of an 'instr-load' command. +# +# @id: instrumentation library ID +# +# Since: 2.11 +## +{ 'struct': 'InstrLoadResult', + 'data': { 'id': 'str' } } + +## +# @instr-load: +# +# Load an instrumentation library. +# +# @path: path to the dynamic instrumentation library +# @id: unique ID for the loaded library +# @args: arguments to the dynamic instrumentation library +# +# Since: 2.11 +## +{ 'command': 'instr-load', + 'data': { 'path': 'str', '*id': 'str', '*args': ['str'] }, + 'returns': 'InstrLoadResult' } + +## +# @instr-unload: +# +# Unload an instrumentation library. +# +# @id: unique ID passed to instr-load(). +# +# Since: 2.11 +## +{ 'command': 'instr-unload', + 'data': { 'id': 'str' } } diff --git a/stubs/instrument.c b/stubs/instrument.c index 7d66f75454..79cd0fd2d1 100644 --- a/stubs/instrument.c +++ b/stubs/instrument.c @@ -7,7 +7,15 @@ * See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" + #include "instrument/cmdline.h" +#include "qapi/error.h" +#include "qapi/qmp/qerror.h" + + +/* Declare missing types */ +typedef struct strList strList; void instr_init(const char *path, int argc, const char **argv) @@ -16,3 +24,21 @@ void instr_init(const char *path, int argc, const char **argv) void instr_fini(void) { } + +InstrLoadResult *qmp_instr_load(const char *path, + bool has_id, const char *id, + bool have_args, strList *args, + Error **errp); +InstrLoadResult *qmp_instr_load(const char *path, + bool has_id, const char *id, + bool have_args, strList *args, + Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} +void qmp_instr_unload(const char *id, Error **errp); +void qmp_instr_unload(const char *id, Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); +}