From patchwork Thu Oct 17 13:01:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195843 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5E0E17E1 for ; Thu, 17 Oct 2019 13:05:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4F3120640 for ; Thu, 17 Oct 2019 13:05:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4F3120640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5TU-0002LQ-GB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:05:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59763) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5Rt-0000OL-C4 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5Rs-0008J7-1S for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48966) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5Ro-0008Hc-VK; Thu, 17 Oct 2019 09:04:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BC4A796ED; Thu, 17 Oct 2019 13:04:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD2F11001938; Thu, 17 Oct 2019 13:04:06 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 01/18] qemu-storage-daemon: Add barebone tool Date: Thu, 17 Oct 2019 15:01:47 +0200 Message-Id: <20191017130204.16131-2-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 17 Oct 2019 13:04:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This adds a new binary qemu-storage-daemon that doesn't yet do more than some typical initialisation for tools and parsing the basic command options --version, --help and --trace. Signed-off-by: Kevin Wolf --- configure | 2 +- qemu-storage-daemon.c | 141 ++++++++++++++++++++++++++++++++++++++++++ Makefile | 1 + 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 qemu-storage-daemon.c diff --git a/configure b/configure index 08ca4bcb46..bb3d55fb25 100755 --- a/configure +++ b/configure @@ -6034,7 +6034,7 @@ tools="" if test "$want_tools" = "yes" ; then tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-edid\$(EXESUF) $tools" if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then - tools="qemu-nbd\$(EXESUF) $tools" + tools="qemu-nbd\$(EXESUF) qemu-storage-daemon\$(EXESUF) $tools" fi if [ "$ivshmem" = "yes" ]; then tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools" diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c new file mode 100644 index 0000000000..a251dc255c --- /dev/null +++ b/qemu-storage-daemon.c @@ -0,0 +1,141 @@ +/* + * QEMU storage daemon + * + * Copyright (c) 2019 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" + +#include "block/block.h" +#include "crypto/init.h" + +#include "qapi/error.h" +#include "qemu-common.h" +#include "qemu-version.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/main-loop.h" +#include "qemu/module.h" + +#include "trace/control.h" + +#include + +static void help(void) +{ + printf( +"Usage: %s [options]\n" +"QEMU storage daemon\n" +"\n" +" -h, --help display this help and exit\n" +" -T, --trace [[enable=]][,events=][,file=]\n" +" specify tracing options\n" +" -V, --version output version information and exit\n" +"\n" +QEMU_HELP_BOTTOM "\n", + error_get_progname()); +} + +static int process_options(int argc, char *argv[], Error **errp) +{ + int c; + char *trace_file = NULL; + int ret = -EINVAL; + + 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} + }; + + while ((c = getopt_long(argc, argv, ":hT:V", long_options, NULL)) != -1) { + switch (c) { + case '?': + error_setg(errp, "Unknown option '%s'", argv[optind - 1]); + goto out; + case ':': + error_setg(errp, "Missing option argument for '%s'", + argv[optind - 1]); + goto out; + case 'h': + help(); + exit(EXIT_SUCCESS); + case 'V': + printf("qemu-storage-daemon version " + QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n"); + exit(EXIT_SUCCESS); + case 'T': + g_free(trace_file); + trace_file = trace_opt_parse(optarg); + break; + } + } + if (optind != argc) { + error_setg(errp, "Unexpected argument: %s", argv[optind]); + goto out; + } + + if (!trace_init_backends()) { + error_setg(errp, "Could not initialize trace backends"); + goto out; + } + trace_init_file(trace_file); + qemu_set_log(LOG_TRACE); + + ret = 0; +out: + g_free(trace_file); + return ret; +} + +int main(int argc, char *argv[]) +{ + Error *local_err = NULL; + int ret; + +#ifdef CONFIG_POSIX + signal(SIGPIPE, SIG_IGN); +#endif + + error_init(argv[0]); + qemu_init_exec_dir(argv[0]); + + module_call_init(MODULE_INIT_QOM); + module_call_init(MODULE_INIT_TRACE); + qemu_add_opts(&qemu_trace_opts); + qcrypto_init(&error_fatal); + bdrv_init(); + + if (qemu_init_main_loop(&local_err)) { + error_report_err(local_err); + return EXIT_FAILURE; + } + + ret = process_options(argc, argv, &local_err); + if (ret < 0) { + error_report_err(local_err); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Makefile b/Makefile index 30f0abfb42..76338d0ab4 100644 --- a/Makefile +++ b/Makefile @@ -558,6 +558,7 @@ qemu-img.o: qemu-img-cmds.h qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) From patchwork Thu Oct 17 13:01:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1206D15AB for ; Thu, 17 Oct 2019 13:05:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E61FD20640 for ; Thu, 17 Oct 2019 13:05:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E61FD20640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5TY-0002Rz-IW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:05:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59812) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5Ry-0000Vp-2c for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5Rx-0008MY-0M for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5Rq-0008IM-Q6; Thu, 17 Oct 2019 09:04:10 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 136B7C050DFF; Thu, 17 Oct 2019 13:04:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85E621001938; Thu, 17 Oct 2019 13:04:08 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 02/18] qemu-storage-daemon: Add --object option Date: Thu, 17 Oct 2019 15:01:48 +0200 Message-Id: <20191017130204.16131-3-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 17 Oct 2019 13:04:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Add a command line option to create user-creatable QOM objects. Signed-off-by: Kevin Wolf --- qemu-storage-daemon.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index a251dc255c..48d6af43a6 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -35,6 +35,8 @@ #include "qemu/log.h" #include "qemu/main-loop.h" #include "qemu/module.h" +#include "qemu/option.h" +#include "qom/object_interfaces.h" #include "trace/control.h" @@ -51,10 +53,26 @@ static void help(void) " specify tracing options\n" " -V, --version output version information and exit\n" "\n" +" --object define a QOM object such as 'secret' for\n" +" passwords and/or encryption keys\n" +"\n" QEMU_HELP_BOTTOM "\n", error_get_progname()); } +enum { + OPTION_OBJECT = 256, +}; + +static QemuOptsList qemu_object_opts = { + .name = "object", + .implied_opt_name = "qom-type", + .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), + .desc = { + { } + }, +}; + static int process_options(int argc, char *argv[], Error **errp) { int c; @@ -63,6 +81,7 @@ static int process_options(int argc, char *argv[], Error **errp) static const struct option long_options[] = { {"help", no_argument, 0, 'h'}, + {"object", required_argument, 0, OPTION_OBJECT}, {"version", no_argument, 0, 'V'}, {"trace", required_argument, NULL, 'T'}, {0, 0, 0, 0} @@ -88,6 +107,22 @@ static int process_options(int argc, char *argv[], Error **errp) g_free(trace_file); trace_file = trace_opt_parse(optarg); break; + case OPTION_OBJECT: + { + QemuOpts *opts; + const char *type; + + opts = qemu_opts_parse(&qemu_object_opts, + optarg, true, &error_fatal); + type = qemu_opt_get(opts, "qom-type"); + + if (user_creatable_print_help(type, opts)) { + exit(EXIT_SUCCESS); + } + user_creatable_add_opts(opts, &error_fatal); + qemu_opts_del(opts); + break; + } } } if (optind != argc) { From patchwork Thu Oct 17 13:01:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195851 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9247B912 for ; Thu, 17 Oct 2019 13:06:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7279520640 for ; Thu, 17 Oct 2019 13:06:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7279520640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5Tk-0002lz-6J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:06:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59897) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5S3-0000d2-Mf for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5Ry-0008NU-JQ for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5Rs-0008JC-Kz; Thu, 17 Oct 2019 09:04:12 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE74D10F2E84; Thu, 17 Oct 2019 13:04:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DA421001B11; Thu, 17 Oct 2019 13:04:10 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 03/18] stubs: Add arch_type Date: Thu, 17 Oct 2019 15:01:49 +0200 Message-Id: <20191017130204.16131-4-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 17 Oct 2019 13:04:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" blockdev.c uses the arch_type constant, so before we can use the file in tools (i.e. outside of the system emulator), we need to add a stub for it. A new QEMU_ARCH_NONE is introduced for this case. Signed-off-by: Kevin Wolf --- include/sysemu/arch_init.h | 2 ++ stubs/arch_type.c | 4 ++++ stubs/Makefile.objs | 1 + 3 files changed, 7 insertions(+) create mode 100644 stubs/arch_type.c diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index 62c6fe4cf1..01392dc945 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -24,6 +24,8 @@ enum { QEMU_ARCH_NIOS2 = (1 << 17), QEMU_ARCH_HPPA = (1 << 18), QEMU_ARCH_RISCV = (1 << 19), + + QEMU_ARCH_NONE = (1 << 31), }; extern const uint32_t arch_type; diff --git a/stubs/arch_type.c b/stubs/arch_type.c new file mode 100644 index 0000000000..fc5423bc98 --- /dev/null +++ b/stubs/arch_type.c @@ -0,0 +1,4 @@ +#include "qemu/osdep.h" +#include "sysemu/arch_init.h" + +const uint32_t arch_type = QEMU_ARCH_NONE; diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 4a50e95ec3..9f4eb25e02 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,3 +1,4 @@ +stub-obj-y += arch_type.o stub-obj-y += bdrv-next-monitor-owned.o stub-obj-y += blk-commit-all.o stub-obj-y += blockdev-close-all-bdrv-states.o From patchwork Thu Oct 17 13:01:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195853 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1177615AB for ; Thu, 17 Oct 2019 13:06:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5F8620640 for ; Thu, 17 Oct 2019 13:06:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5F8620640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5UP-0003z6-LS for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:06:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59868) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5S1-0000aI-D6 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5S0-0008OY-D3 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41118) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5Ru-0008Ks-EZ; Thu, 17 Oct 2019 09:04:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3D9F308429D; Thu, 17 Oct 2019 13:04:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 342B51001B11; Thu, 17 Oct 2019 13:04:12 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 04/18] stubs: Add blk_by_qdev_id() Date: Thu, 17 Oct 2019 15:01:50 +0200 Message-Id: <20191017130204.16131-5-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 17 Oct 2019 13:04:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" blockdev.c uses the blk_by_qdev_id() function, so before we can use the file in tools (i.e. outside of the system emulator), we need to add a stub for it. The function always returns an error. Signed-off-by: Kevin Wolf --- stubs/blk-by-qdev-id.c | 9 +++++++++ stubs/Makefile.objs | 1 + 2 files changed, 10 insertions(+) create mode 100644 stubs/blk-by-qdev-id.c diff --git a/stubs/blk-by-qdev-id.c b/stubs/blk-by-qdev-id.c new file mode 100644 index 0000000000..0b6160fefa --- /dev/null +++ b/stubs/blk-by-qdev-id.c @@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "sysemu/block-backend.h" + +BlockBackend *blk_by_qdev_id(const char *id, Error **errp) +{ + error_setg(errp, "qdev IDs/QOM paths exist only in the system emulator"); + return NULL; +} diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 9f4eb25e02..77fbf72576 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,5 +1,6 @@ stub-obj-y += arch_type.o stub-obj-y += bdrv-next-monitor-owned.o +stub-obj-y += blk-by-qdev-id.o stub-obj-y += blk-commit-all.o stub-obj-y += blockdev-close-all-bdrv-states.o stub-obj-y += clock-warp.o From patchwork Thu Oct 17 13:01:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195859 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA53217E1 for ; Thu, 17 Oct 2019 13:09:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8AAC82089C for ; Thu, 17 Oct 2019 13:09:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8AAC82089C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5Wh-0007Tz-Dr for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:09:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59857) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5S0-0000ZQ-Ra for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5Rz-0008Nu-Dk for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39872) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5Rw-0008Lb-AL; Thu, 17 Oct 2019 09:04:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89F7C19D04A; Thu, 17 Oct 2019 13:04:15 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 097521001B11; Thu, 17 Oct 2019 13:04:13 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 05/18] qemu-storage-daemon: Add --blockdev option Date: Thu, 17 Oct 2019 15:01:51 +0200 Message-Id: <20191017130204.16131-6-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 17 Oct 2019 13:04:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This adds a --blockdev option to the storage daemon that works the same as the -blockdev option of the system emulator. In order to be able to link with blockdev.o, we also need to change stream.o from common-obj to block-obj, which is where all other block jobs already are. Signed-off-by: Kevin Wolf --- qemu-storage-daemon.c | 29 +++++++++++++++++++++++++++++ Makefile | 5 ++++- Makefile.objs | 7 +++++++ block/Makefile.objs | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 48d6af43a6..904e3c3a46 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -28,6 +28,10 @@ #include "crypto/init.h" #include "qapi/error.h" +#include "qapi/qapi-visit-block-core.h" +#include "qapi/qapi-commands-block-core.h" +#include "qapi/qobject-input-visitor.h" + #include "qemu-common.h" #include "qemu-version.h" #include "qemu/config-file.h" @@ -53,6 +57,13 @@ static void help(void) " specify tracing options\n" " -V, --version output version information and exit\n" "\n" +" --blockdev [driver=][,node-name=][,discard=ignore|unmap]\n" +" [,cache.direct=on|off][,cache.no-flush=on|off]\n" +" [,read-only=on|off][,auto-read-only=on|off]\n" +" [,force-share=on|off][,detect-zeroes=on|off|unmap]\n" +" [,driver specific parameters...]\n" +" configure a block backend\n" +"\n" " --object define a QOM object such as 'secret' for\n" " passwords and/or encryption keys\n" "\n" @@ -62,6 +73,7 @@ QEMU_HELP_BOTTOM "\n", enum { OPTION_OBJECT = 256, + OPTION_BLOCKDEV, }; static QemuOptsList qemu_object_opts = { @@ -82,6 +94,7 @@ static int process_options(int argc, char *argv[], Error **errp) static const struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"blockdev", required_argument, 0, OPTION_BLOCKDEV}, {"version", no_argument, 0, 'V'}, {"trace", required_argument, NULL, 'T'}, {0, 0, 0, 0} @@ -123,6 +136,22 @@ static int process_options(int argc, char *argv[], Error **errp) qemu_opts_del(opts); break; } + break; + case OPTION_BLOCKDEV: + { + Visitor *v; + BlockdevOptions *options; + + v = qobject_input_visitor_new_str(optarg, "driver", + &error_fatal); + + visit_type_BlockdevOptions(v, NULL, &options, &error_fatal); + visit_free(v); + + qmp_blockdev_add(options, &error_fatal); + qapi_free_BlockdevOptions(options); + break; + } } } if (optind != argc) { diff --git a/Makefile b/Makefile index 76338d0ab4..b913d4d736 100644 --- a/Makefile +++ b/Makefile @@ -432,6 +432,8 @@ dummy := $(call unnest-vars,, \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \ + storage-daemon-obj-y \ + storage-daemon-obj-m \ crypto-obj-y \ crypto-user-obj-y \ qom-obj-y \ @@ -469,6 +471,7 @@ TARGET_DIRS_RULES := $(foreach t, all clean install, $(addsuffix /$(t), $(TARGET SOFTMMU_ALL_RULES=$(filter %-softmmu/all, $(TARGET_DIRS_RULES)) $(SOFTMMU_ALL_RULES): $(authz-obj-y) $(SOFTMMU_ALL_RULES): $(block-obj-y) +$(SOFTMMU_ALL_RULES): $(storage-daemon-obj-y) $(SOFTMMU_ALL_RULES): $(chardev-obj-y) $(SOFTMMU_ALL_RULES): $(crypto-obj-y) $(SOFTMMU_ALL_RULES): $(io-obj-y) @@ -558,7 +561,7 @@ qemu-img.o: qemu-img-cmds.h qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(storage-daemon-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) diff --git a/Makefile.objs b/Makefile.objs index abcbd89654..00fdf54500 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -37,6 +37,13 @@ qom-obj-y = qom/ io-obj-y = io/ +####################################################################### +# storage-daemon-obj-y is code used by qemu-storage-daemon (these objects are +# used for system emulation, too, but specified separately there) + +storage-daemon-obj-y = block/ +storage-daemon-obj-y += blockdev.o iothread.o + ###################################################################### # Target independent part of system emulation. The long term path is to # suppress *all* target specific code in case of system emulation, i.e. a diff --git a/block/Makefile.objs b/block/Makefile.objs index e394fe0b6c..d24fc93b7f 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -44,7 +44,7 @@ block-obj-y += crypto.o block-obj-y += aio_task.o block-obj-y += backup-top.o -common-obj-y += stream.o +block-obj-y += stream.o nfs.o-libs := $(LIBNFS_LIBS) iscsi.o-cflags := $(LIBISCSI_CFLAGS) From patchwork Thu Oct 17 13:01:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EBD1912 for ; Thu, 17 Oct 2019 13:08:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E4582089C for ; Thu, 17 Oct 2019 13:08:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E4582089C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5W1-0006UC-1d for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:08:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59961) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5S6-0000hK-M8 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5S5-0008RV-5p for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5Ry-0008Mm-4U; Thu, 17 Oct 2019 09:04:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62B4E307C64C; Thu, 17 Oct 2019 13:04:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id D623010027AB; Thu, 17 Oct 2019 13:04:15 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 06/18] qemu-storage-daemon: Add --nbd-server option Date: Thu, 17 Oct 2019 15:01:52 +0200 Message-Id: <20191017130204.16131-7-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 17 Oct 2019 13:04:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Add a --nbd-server option to qemu-storage-daemon to start the built-in NBD server right away. It maps the arguments for nbd-server-start to the command line. Example (only with required options): --nbd-server addr.type=inet,addr.host=localhost,addr.port=10809 Signed-off-by: Kevin Wolf --- qapi/block.json | 18 ++++++++++++++++++ include/block/nbd.h | 1 + blockdev-nbd.c | 5 +++++ qemu-storage-daemon.c | 26 +++++++++++++++++++++++++- Makefile.objs | 2 +- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/qapi/block.json b/qapi/block.json index 145c268bb6..7fe0cf6538 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -215,6 +215,24 @@ '*id': 'str', '*force': 'bool' } } +## +# @NbdServerOptions: +# +# @addr: Address on which to listen. +# @tls-creds: ID of the TLS credentials object (since 2.6). +# @tls-authz: ID of the QAuthZ authorization object used to validate +# the client's x509 distinguished name. This object is +# is only resolved at time of use, so can be deleted and +# recreated on the fly while the NBD server is active. +# If missing, it will default to denying access (since 4.0). +# +# Since: 4.2 +## +{ 'struct': 'NbdServerOptions', + 'data': { 'addr': 'SocketAddress', + '*tls-creds': 'str', + '*tls-authz': 'str'} } + ## # @nbd-server-start: # diff --git a/include/block/nbd.h b/include/block/nbd.h index 316fd705a9..2a7441491a 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -353,6 +353,7 @@ void nbd_client_put(NBDClient *client); void nbd_server_start(SocketAddress *addr, const char *tls_creds, const char *tls_authz, Error **errp); +void nbd_server_start_options(NbdServerOptions *arg, Error **errp); /* nbd_read * Reads @size bytes from @ioc. Returns 0 on success. diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 6a8b206e1d..d4c1fd4166 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -132,6 +132,11 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds, nbd_server = NULL; } +void nbd_server_start_options(NbdServerOptions *arg, Error **errp) +{ + nbd_server_start(arg->addr, arg->tls_creds, arg->tls_authz, errp); +} + void qmp_nbd_server_start(SocketAddressLegacy *addr, bool has_tls_creds, const char *tls_creds, bool has_tls_authz, const char *tls_authz, diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 904e3c3a46..51882452f3 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -25,11 +25,14 @@ #include "qemu/osdep.h" #include "block/block.h" +#include "block/nbd.h" #include "crypto/init.h" #include "qapi/error.h" -#include "qapi/qapi-visit-block-core.h" +#include "qapi/qapi-commands-block.h" #include "qapi/qapi-commands-block-core.h" +#include "qapi/qapi-visit-block.h" +#include "qapi/qapi-visit-block-core.h" #include "qapi/qobject-input-visitor.h" #include "qemu-common.h" @@ -64,6 +67,12 @@ static void help(void) " [,driver specific parameters...]\n" " configure a block backend\n" "\n" +" --nbd-server addr.type=inet,addr.host=,addr.port=\n" +" [,tls-creds=][,tls-authz=]\n" +" --nbd-server addr.type=unix,addr.path=\n" +" [,tls-creds=][,tls-authz=]\n" +" start an NBD server for exporting block nodes\n" +"\n" " --object define a QOM object such as 'secret' for\n" " passwords and/or encryption keys\n" "\n" @@ -74,6 +83,7 @@ QEMU_HELP_BOTTOM "\n", enum { OPTION_OBJECT = 256, OPTION_BLOCKDEV, + OPTION_NBD_SERVER, }; static QemuOptsList qemu_object_opts = { @@ -95,6 +105,7 @@ static int process_options(int argc, char *argv[], Error **errp) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"blockdev", required_argument, 0, OPTION_BLOCKDEV}, + {"nbd-server", required_argument, 0, OPTION_NBD_SERVER}, {"version", no_argument, 0, 'V'}, {"trace", required_argument, NULL, 'T'}, {0, 0, 0, 0} @@ -152,6 +163,19 @@ static int process_options(int argc, char *argv[], Error **errp) qapi_free_BlockdevOptions(options); break; } + case OPTION_NBD_SERVER: + { + Visitor *v; + NbdServerOptions *options; + + v = qobject_input_visitor_new_str(optarg, NULL, &error_fatal); + visit_type_NbdServerOptions(v, NULL, &options, &error_fatal); + visit_free(v); + + nbd_server_start_options(options, &error_fatal); + qapi_free_NbdServerOptions(options); + break; + } } } if (optind != argc) { diff --git a/Makefile.objs b/Makefile.objs index 00fdf54500..cc262e445f 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -42,7 +42,7 @@ io-obj-y = io/ # used for system emulation, too, but specified separately there) storage-daemon-obj-y = block/ -storage-daemon-obj-y += blockdev.o iothread.o +storage-daemon-obj-y += blockdev.o blockdev-nbd.o iothread.o ###################################################################### # Target independent part of system emulation. The long term path is to From patchwork Thu Oct 17 13:01:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195877 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93EC0912 for ; Thu, 17 Oct 2019 13:13:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73B3520640 for ; Thu, 17 Oct 2019 13:13:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73B3520640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5aY-00047i-UQ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:13:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59987) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5S8-0000jc-8U for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5S6-0008Sg-St for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58108) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5Rz-0008Nr-Vs; Thu, 17 Oct 2019 09:04:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D624300BCE9; Thu, 17 Oct 2019 13:04:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE9CD1001B11; Thu, 17 Oct 2019 13:04:17 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 07/18] blockdev-nbd: Boxed argument type for nbd-server-add Date: Thu, 17 Oct 2019 15:01:53 +0200 Message-Id: <20191017130204.16131-8-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 17 Oct 2019 13:04:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Move the arguments of nbd-server-add to a new struct BlockExportNbd and convert the command to 'boxed': true. This makes it easier to share code with the storage daemon. Signed-off-by: Kevin Wolf --- qapi/block.json | 20 +++++++++++++++----- blockdev-nbd.c | 25 ++++++++++++------------- monitor/hmp-cmds.c | 21 +++++++++++++++++---- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/qapi/block.json b/qapi/block.json index 7fe0cf6538..567f116875 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -259,9 +259,9 @@ '*tls-authz': 'str'} } ## -# @nbd-server-add: +# @BlockExportNbd: # -# Export a block node to QEMU's embedded NBD server. +# An NBD block export. # # @device: The device name or node name of the node to be exported # @@ -270,19 +270,29 @@ # # @writable: Whether clients should be able to write to the device via the # NBD connection (default false). - +# # @bitmap: Also export the dirty bitmap reachable from @device, so the # NBD client can use NBD_OPT_SET_META_CONTEXT with # "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0) # +# Since: 4.2 +## +{ 'struct': 'BlockExportNbd', + 'data': {'device': 'str', '*name': 'str', '*writable': 'bool', + '*bitmap': 'str' } } + +## +# @nbd-server-add: +# +# Export a block node to QEMU's embedded NBD server. +# # Returns: error if the server is not running, or export with the same name # already exists. # # Since: 1.3.0 ## { 'command': 'nbd-server-add', - 'data': {'device': 'str', '*name': 'str', '*writable': 'bool', - '*bitmap': 'str' } } + 'data': 'BlockExportNbd', 'boxed': true } ## # @NbdServerRemoveMode: diff --git a/blockdev-nbd.c b/blockdev-nbd.c index d4c1fd4166..ee8262cd4c 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -148,9 +148,7 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, qapi_free_SocketAddress(addr_flat); } -void qmp_nbd_server_add(const char *device, bool has_name, const char *name, - bool has_writable, bool writable, - bool has_bitmap, const char *bitmap, Error **errp) +void qmp_nbd_server_add(BlockExportNbd *arg, Error **errp) { BlockDriverState *bs = NULL; BlockBackend *on_eject_blk; @@ -163,18 +161,18 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name, return; } - if (!has_name) { - name = device; + if (!arg->has_name) { + arg->name = arg->device; } - if (nbd_export_find(name)) { - error_setg(errp, "NBD server already has export named '%s'", name); + if (nbd_export_find(arg->name)) { + error_setg(errp, "NBD server already has export named '%s'", arg->name); return; } - on_eject_blk = blk_by_name(device); + on_eject_blk = blk_by_name(arg->device); - bs = bdrv_lookup_bs(device, device, errp); + bs = bdrv_lookup_bs(arg->device, arg->device, errp); if (!bs) { return; } @@ -188,14 +186,15 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name, goto out; } - if (!has_writable) { - writable = false; + if (!arg->has_writable) { + arg->writable = false; } if (bdrv_is_read_only(bs)) { - writable = false; + arg->writable = false; } - exp = nbd_export_new(bs, 0, len, name, NULL, bitmap, !writable, !writable, + exp = nbd_export_new(bs, 0, len, arg->name, NULL, arg->bitmap, + !arg->writable, !arg->writable, NULL, false, on_eject_blk, errp); if (!exp) { goto out; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index b2551c16d1..22d7e6e222 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -2320,6 +2320,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) Error *local_err = NULL; BlockInfoList *block_list, *info; SocketAddress *addr; + BlockExportNbd export; if (writable && !all) { error_setg(&local_err, "-w only valid together with -a"); @@ -2352,8 +2353,13 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) continue; } - qmp_nbd_server_add(info->value->device, false, NULL, - true, writable, false, NULL, &local_err); + export = (BlockExportNbd) { + .device = info->value->device, + .has_writable = true, + .writable = writable, + }; + + qmp_nbd_server_add(&export, &local_err); if (local_err != NULL) { qmp_nbd_server_stop(NULL); @@ -2374,8 +2380,15 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) bool writable = qdict_get_try_bool(qdict, "writable", false); Error *local_err = NULL; - qmp_nbd_server_add(device, !!name, name, true, writable, - false, NULL, &local_err); + BlockExportNbd export = { + .device = (char *) device, + .has_name = !!name, + .name = (char *) name, + .has_writable = true, + .writable = writable, + }; + + qmp_nbd_server_add(&export, &local_err); hmp_handle_error(mon, &local_err); } From patchwork Thu Oct 17 13:01:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E93815AB for ; Thu, 17 Oct 2019 13:09:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6F3A920640 for ; Thu, 17 Oct 2019 13:09:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F3A920640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5XO-0000Ci-8l for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:09:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60026) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SA-0000md-DU for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5S8-0008Ti-Q3 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58124) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5S1-0008PA-V0; Thu, 17 Oct 2019 09:04:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17D3D3082E72; Thu, 17 Oct 2019 13:04:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87CE91001B11; Thu, 17 Oct 2019 13:04:19 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 08/18] qemu-storage-daemon: Add --export option Date: Thu, 17 Oct 2019 15:01:54 +0200 Message-Id: <20191017130204.16131-9-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 17 Oct 2019 13:04:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Add a --export option to qemu-storage-daemon to export a block node. For now, only NBD exports are implemented. Apart from the 'type' option (which is the implied key), it maps the arguments for nbd-server-add to the command line. Example: --export nbd,device=disk,name=test-export,writable=on Signed-off-by: Kevin Wolf --- qapi/block.json | 27 +++++++++++++++++++++++++++ qemu-storage-daemon.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/qapi/block.json b/qapi/block.json index 567f116875..d9b1f16fbf 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -481,3 +481,30 @@ { 'event': 'QUORUM_REPORT_BAD', 'data': { 'type': 'QuorumOpType', '*error': 'str', 'node-name': 'str', 'sector-num': 'int', 'sectors-count': 'int' } } + +## +# @BlockExportType: +# +# An enumeration of block export types +# +# @nbd: NBD export +# +# Since: 4.2 +## +{ 'enum': 'BlockExportType', + 'data': [ 'nbd' ] } + +## +# @BlockExport: +# +# Describes a block export, i.e. how single node should be exported on an +# external interface. +# +# Since: 4.2 +## +{ 'union': 'BlockExport', + 'base': { 'type': 'BlockExportType' }, + 'discriminator': 'type', + 'data': { + 'nbd': 'BlockExportNbd' + } } diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 51882452f3..9e5f474fd0 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -67,6 +67,11 @@ static void help(void) " [,driver specific parameters...]\n" " configure a block backend\n" "\n" +" --export [type=]nbd,device=[,name=]\n" +" [,writable=on|off][,bitmap=]\n" +" export the specified block node over NBD\n" +" (requires --nbd-server)\n" +"\n" " --nbd-server addr.type=inet,addr.host=,addr.port=\n" " [,tls-creds=][,tls-authz=]\n" " --nbd-server addr.type=unix,addr.path=\n" @@ -84,6 +89,7 @@ enum { OPTION_OBJECT = 256, OPTION_BLOCKDEV, OPTION_NBD_SERVER, + OPTION_EXPORT, }; static QemuOptsList qemu_object_opts = { @@ -95,6 +101,17 @@ static QemuOptsList qemu_object_opts = { }, }; +static void init_export(BlockExport *export, Error **errp) +{ + switch (export->type) { + case BLOCK_EXPORT_TYPE_NBD: + qmp_nbd_server_add(&export->u.nbd, errp); + break; + default: + g_assert_not_reached(); + } +} + static int process_options(int argc, char *argv[], Error **errp) { int c; @@ -106,6 +123,7 @@ static int process_options(int argc, char *argv[], Error **errp) {"object", required_argument, 0, OPTION_OBJECT}, {"blockdev", required_argument, 0, OPTION_BLOCKDEV}, {"nbd-server", required_argument, 0, OPTION_NBD_SERVER}, + {"export", required_argument, 0, OPTION_EXPORT}, {"version", no_argument, 0, 'V'}, {"trace", required_argument, NULL, 'T'}, {0, 0, 0, 0} @@ -176,6 +194,19 @@ static int process_options(int argc, char *argv[], Error **errp) qapi_free_NbdServerOptions(options); break; } + case OPTION_EXPORT: + { + Visitor *v; + BlockExport *export; + + v = qobject_input_visitor_new_str(optarg, "type", &error_fatal); + visit_type_BlockExport(v, NULL, &export, &error_fatal); + visit_free(v); + + init_export(export, &error_fatal); + qapi_free_BlockExport(export); + break; + } } } if (optind != argc) { From patchwork Thu Oct 17 13:01:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE8CA912 for ; Thu, 17 Oct 2019 13:17:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E45F20869 for ; Thu, 17 Oct 2019 13:17:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E45F20869 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5f3-0000vn-44 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:17:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60049) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SB-0000o3-HN for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SA-0008UU-9L for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5S3-0008Q0-LT; Thu, 17 Oct 2019 09:04:23 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFC9FC0546D5; Thu, 17 Oct 2019 13:04:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ED4D1001938; Thu, 17 Oct 2019 13:04:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 09/18] qemu-storage-daemon: Add main loop Date: Thu, 17 Oct 2019 15:01:55 +0200 Message-Id: <20191017130204.16131-10-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 17 Oct 2019 13:04:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Instead of exiting after processing all command line options, start a main loop and keep processing events until exit is requested with a signal (e.g. SIGINT). Now qemu-storage-daemon can be used as an alternative for qemu-nbd that provides a few features that were previously only available from QMP, such as access to options only available with -blockdev and the socket types 'vsock' and 'fd'. Signed-off-by: Kevin Wolf --- qemu-storage-daemon.c | 13 +++++++++++++ Makefile.objs | 2 ++ 2 files changed, 15 insertions(+) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 9e5f474fd0..099388f645 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -45,10 +45,18 @@ #include "qemu/option.h" #include "qom/object_interfaces.h" +#include "sysemu/runstate.h" #include "trace/control.h" #include +static bool exit_requested = false; + +void qemu_system_killed(int signal, pid_t pid) +{ + exit_requested = true; +} + static void help(void) { printf( @@ -238,6 +246,7 @@ int main(int argc, char *argv[]) error_init(argv[0]); qemu_init_exec_dir(argv[0]); + os_setup_signal_handling(); module_call_init(MODULE_INIT_QOM); module_call_init(MODULE_INIT_TRACE); @@ -256,5 +265,9 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } + while (!exit_requested) { + main_loop_wait(false); + } + return EXIT_SUCCESS; } diff --git a/Makefile.objs b/Makefile.objs index cc262e445f..b667d3f07b 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -43,6 +43,8 @@ io-obj-y = io/ storage-daemon-obj-y = block/ storage-daemon-obj-y += blockdev.o blockdev-nbd.o iothread.o +storage-daemon-obj-$(CONFIG_WIN32) += os-win32.o +storage-daemon-obj-$(CONFIG_POSIX) += os-posix.o ###################################################################### # Target independent part of system emulation. The long term path is to From patchwork Thu Oct 17 13:01:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0732A912 for ; Thu, 17 Oct 2019 13:10:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC2F520640 for ; Thu, 17 Oct 2019 13:10:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC2F520640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5YG-0001R1-EH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:10:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60083) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SD-0000qy-CW for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5S8-0008TN-9n for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5S5-0008RL-Ez; Thu, 17 Oct 2019 09:04:25 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7DDF18C4287; Thu, 17 Oct 2019 13:04:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 374AA10098FB; Thu, 17 Oct 2019 13:04:23 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 10/18] qemu-storage-daemon: Add --chardev option Date: Thu, 17 Oct 2019 15:01:56 +0200 Message-Id: <20191017130204.16131-11-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 17 Oct 2019 13:04:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This adds a --chardev option to the storage daemon that works the same as the -chardev option of the system emulator. Signed-off-by: Kevin Wolf --- qemu-storage-daemon.c | 19 +++++++++++++++++++ Makefile | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 099388f645..46e0a6ea56 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -26,6 +26,7 @@ #include "block/block.h" #include "block/nbd.h" +#include "chardev/char.h" #include "crypto/init.h" #include "qapi/error.h" @@ -75,6 +76,9 @@ static void help(void) " [,driver specific parameters...]\n" " configure a block backend\n" "\n" +" --chardev configure a character device backend\n" +" (see the qemu(1) man page for possible options)\n" +"\n" " --export [type=]nbd,device=[,name=]\n" " [,writable=on|off][,bitmap=]\n" " export the specified block node over NBD\n" @@ -96,10 +100,13 @@ QEMU_HELP_BOTTOM "\n", enum { OPTION_OBJECT = 256, OPTION_BLOCKDEV, + OPTION_CHARDEV, OPTION_NBD_SERVER, OPTION_EXPORT, }; +extern QemuOptsList qemu_chardev_opts; + static QemuOptsList qemu_object_opts = { .name = "object", .implied_opt_name = "qom-type", @@ -130,6 +137,7 @@ static int process_options(int argc, char *argv[], Error **errp) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"blockdev", required_argument, 0, OPTION_BLOCKDEV}, + {"chardev", required_argument, 0, OPTION_CHARDEV}, {"nbd-server", required_argument, 0, OPTION_NBD_SERVER}, {"export", required_argument, 0, OPTION_EXPORT}, {"version", no_argument, 0, 'V'}, @@ -189,6 +197,17 @@ static int process_options(int argc, char *argv[], Error **errp) qapi_free_BlockdevOptions(options); break; } + case OPTION_CHARDEV: + { + QemuOpts *opts = qemu_opts_parse(&qemu_chardev_opts, + optarg, true, &error_fatal); + if (!qemu_chr_new_from_opts(opts, NULL, &error_fatal)) { + /* No error, but NULL returned means help was printed */ + exit(EXIT_SUCCESS); + } + qemu_opts_del(opts); + break; + } case OPTION_NBD_SERVER: { Visitor *v; diff --git a/Makefile b/Makefile index b913d4d736..0e3e98582d 100644 --- a/Makefile +++ b/Makefile @@ -561,7 +561,7 @@ qemu-img.o: qemu-img-cmds.h qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(storage-daemon-obj-y) $(COMMON_LDADDS) +qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(chardev-obj-y) $(io-obj-y) $(qom-obj-y) $(storage-daemon-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) From patchwork Thu Oct 17 13:01:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195873 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F7B215AB for ; Thu, 17 Oct 2019 13:11:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5EE5B20640 for ; Thu, 17 Oct 2019 13:11:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5EE5B20640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5YR-0001m2-TC for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:11:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60060) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SB-0000ol-V4 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SA-0008Uk-Gm for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5S7-0008SW-Br; Thu, 17 Oct 2019 09:04:27 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93D5910F14; Thu, 17 Oct 2019 13:04:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EE641000232; Thu, 17 Oct 2019 13:04:24 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 11/18] monitor: Move monitor option parsing to monitor/monitor.c Date: Thu, 17 Oct 2019 15:01:57 +0200 Message-Id: <20191017130204.16131-12-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 17 Oct 2019 13:04:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Both the system emulators and the storage daemon will need to parse monitor options, so move that code to monitor/monitor.c, which can be linked into binaries that aren't a system emulator. This patch moves the monitor option parsing from vl.c and adds an allow_hmp parameter so that callers can support QMP without HMP. Signed-off-by: Kevin Wolf --- include/monitor/monitor.h | 4 +++ include/sysemu/sysemu.h | 1 - monitor/monitor.c | 52 +++++++++++++++++++++++++++++++++++++++ vl.c | 45 +-------------------------------- 4 files changed, 57 insertions(+), 45 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index a81eeff5f8..d3e8da36a5 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -3,6 +3,7 @@ #include "block/block.h" #include "qapi/qapi-types-misc.h" +#include "qemu/option.h" #include "qemu/readline.h" extern __thread Monitor *cur_mon; @@ -10,12 +11,15 @@ typedef struct MonitorHMP MonitorHMP; #define QMP_REQ_QUEUE_LEN_MAX 8 +extern QemuOptsList qemu_mon_opts; + bool monitor_cur_is_qmp(void); void monitor_init_globals(void); void monitor_init_globals_core(void); void monitor_init_qmp(Chardev *chr, bool pretty); void monitor_init_hmp(Chardev *chr, bool use_readline); +int monitor_init_opts(QemuOpts *opts, bool allow_hmp, Error **errp); void monitor_cleanup(void); int monitor_suspend(Monitor *mon); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 44f18eb739..e54934c311 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -124,7 +124,6 @@ extern QemuOptsList qemu_netdev_opts; extern QemuOptsList qemu_nic_opts; extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_global_opts; -extern QemuOptsList qemu_mon_opts; extern QemuOptsList qemu_semihosting_config_opts; #endif diff --git a/monitor/monitor.c b/monitor/monitor.c index 12898b6448..316b71b928 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -609,6 +609,58 @@ void monitor_init_globals_core(void) NULL); } +int monitor_init_opts(QemuOpts *opts, bool allow_hmp, Error **errp) +{ + Chardev *chr; + bool qmp; + bool pretty = false; + const char *chardev; + const char *mode; + + mode = qemu_opt_get(opts, "mode"); + if (mode == NULL) { + mode = allow_hmp ? "readline" : "control"; + } + if (strcmp(mode, "readline") == 0) { + qmp = false; + } else if (strcmp(mode, "control") == 0) { + qmp = true; + } else { + error_setg(errp, "unknown monitor mode \"%s\"", mode); + return -1; + } + if (!allow_hmp && !qmp) { + error_setg(errp, "Only QMP is supported"); + return -1; + } + + if (!qmp && qemu_opt_get(opts, "pretty")) { + warn_report("'pretty' is deprecated for HMP monitors, it has no effect " + "and will be removed in future versions"); + } + if (qemu_opt_get_bool(opts, "pretty", 0)) { + pretty = true; + } + + chardev = qemu_opt_get(opts, "chardev"); + if (!chardev) { + error_report("chardev is required"); + exit(1); + } + chr = qemu_chr_find(chardev); + if (chr == NULL) { + error_setg(errp, "chardev \"%s\" not found", chardev); + return -1; + } + + if (qmp) { + monitor_init_qmp(chr, pretty); + } else { + monitor_init_hmp(chr, true); + } + return 0; +} + QemuOptsList qemu_mon_opts = { .name = "mon", .implied_opt_name = "chardev", diff --git a/vl.c b/vl.c index 4489cfb2bb..e9d9a44acf 100644 --- a/vl.c +++ b/vl.c @@ -2234,50 +2234,7 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) { - Chardev *chr; - bool qmp; - bool pretty = false; - const char *chardev; - const char *mode; - - mode = qemu_opt_get(opts, "mode"); - if (mode == NULL) { - mode = "readline"; - } - if (strcmp(mode, "readline") == 0) { - qmp = false; - } else if (strcmp(mode, "control") == 0) { - qmp = true; - } else { - error_setg(errp, "unknown monitor mode \"%s\"", mode); - return -1; - } - - if (!qmp && qemu_opt_get(opts, "pretty")) { - warn_report("'pretty' is deprecated for HMP monitors, it has no effect " - "and will be removed in future versions"); - } - if (qemu_opt_get_bool(opts, "pretty", 0)) { - pretty = true; - } - - chardev = qemu_opt_get(opts, "chardev"); - if (!chardev) { - error_report("chardev is required"); - exit(1); - } - chr = qemu_chr_find(chardev); - if (chr == NULL) { - error_setg(errp, "chardev \"%s\" not found", chardev); - return -1; - } - - if (qmp) { - monitor_init_qmp(chr, pretty); - } else { - monitor_init_hmp(chr, true); - } - return 0; + return monitor_init_opts(opts, true, errp); } static void monitor_parse(const char *optarg, const char *mode, bool pretty) From patchwork Thu Oct 17 13:01:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1917415AB for ; Thu, 17 Oct 2019 13:14:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EE45D20640 for ; Thu, 17 Oct 2019 13:14:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE45D20640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5bl-0005Mg-Im for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:14:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60109) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SG-0000vq-J1 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SB-0008VY-MT for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53008) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5S9-0008Tc-5x; Thu, 17 Oct 2019 09:04:29 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D2E03082B6D; Thu, 17 Oct 2019 13:04:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF5181001B23; Thu, 17 Oct 2019 13:04:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 12/18] stubs: Update monitor stubs for qemu-storage-daemon Date: Thu, 17 Oct 2019 15:01:58 +0200 Message-Id: <20191017130204.16131-13-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 17 Oct 2019 13:04:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Before we can add the monitor to qemu-storage-daemon, we need to add a few monitor stubs, and we need to make sure that stubs that are actually implemented in the monitor core aren't linked so that we don't get linker errors because of duplicate symbols. Signed-off-by: Kevin Wolf --- stubs/monitor-core.c | 21 +++++++++++++++++++++ stubs/monitor.c | 15 ++------------- stubs/Makefile.objs | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 stubs/monitor-core.c diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c new file mode 100644 index 0000000000..403c00a6d0 --- /dev/null +++ b/stubs/monitor-core.c @@ -0,0 +1,21 @@ +#include "qemu/osdep.h" +#include "monitor/monitor.h" +#include "qemu-common.h" +#include "qapi/qapi-emit-events.h" + +__thread Monitor *cur_mon; + +void monitor_init_qmp(Chardev *chr, bool pretty) +{ +} + +void qapi_event_emit(QAPIEvent event, QDict *qdict) +{ +} + +int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) +{ + abort(); +} + + diff --git a/stubs/monitor.c b/stubs/monitor.c index c3e9a2e4dc..9403f8e72c 100644 --- a/stubs/monitor.c +++ b/stubs/monitor.c @@ -1,14 +1,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" -#include "qapi/qapi-emit-events.h" #include "monitor/monitor.h" - -__thread Monitor *cur_mon; - -int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) -{ - abort(); -} +#include "../monitor/monitor-internal.h" int monitor_get_fd(Monitor *mon, const char *name, Error **errp) { @@ -16,14 +9,10 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **errp) return -1; } -void monitor_init_qmp(Chardev *chr, bool pretty) -{ -} - void monitor_init_hmp(Chardev *chr, bool use_readline) { } -void qapi_event_emit(QAPIEvent event, QDict *qdict) +void monitor_fdsets_cleanup(void) { } diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 77fbf72576..ad4515ac70 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -19,6 +19,7 @@ stub-obj-y += machine-init-done.o stub-obj-y += migr-blocker.o stub-obj-y += change-state-handler.o stub-obj-y += monitor.o +stub-obj-y += monitor-core.o stub-obj-y += notify-event.o stub-obj-y += qtest.o stub-obj-y += replay.o From patchwork Thu Oct 17 13:01:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195899 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94B0014DB for ; Thu, 17 Oct 2019 13:21:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6357320869 for ; Thu, 17 Oct 2019 13:21:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6357320869 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5iP-0004ZW-T9 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60231) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5ST-0001IL-Ta for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SN-00008y-LG for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46062) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5SB-0008Uf-2H; Thu, 17 Oct 2019 09:04:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4ABA2307D976; Thu, 17 Oct 2019 13:04:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id B873710001BC; Thu, 17 Oct 2019 13:04:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 13/18] qapi: Create module 'monitor' Date: Thu, 17 Oct 2019 15:01:59 +0200 Message-Id: <20191017130204.16131-14-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 17 Oct 2019 13:04:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" misc.json contains definitions that are related to the system emulator, so it can't be used for the storage daemon. This patch moves basic functionality that is related to the monitor itself into a new monitor.json, which could be used in tools as well. Signed-off-by: Kevin Wolf --- qapi/misc.json | 212 ------------------------------------ qapi/monitor.json | 218 +++++++++++++++++++++++++++++++++++++ qapi/qapi-schema.json | 1 + monitor/monitor-internal.h | 1 + monitor/hmp-cmds.c | 1 + monitor/qmp-cmds.c | 1 + monitor/qmp.c | 2 +- tests/qmp-test.c | 2 +- ui/gtk.c | 1 + qapi/Makefile.objs | 4 +- 10 files changed, 227 insertions(+), 216 deletions(-) create mode 100644 qapi/monitor.json diff --git a/qapi/misc.json b/qapi/misc.json index 6bd11f50e6..7a05c286d5 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -7,159 +7,6 @@ { 'include': 'common.json' } -## -# @qmp_capabilities: -# -# Enable QMP capabilities. -# -# Arguments: -# -# @enable: An optional list of QMPCapability values to enable. The -# client must not enable any capability that is not -# mentioned in the QMP greeting message. If the field is not -# provided, it means no QMP capabilities will be enabled. -# (since 2.12) -# -# Example: -# -# -> { "execute": "qmp_capabilities", -# "arguments": { "enable": [ "oob" ] } } -# <- { "return": {} } -# -# Notes: This command is valid exactly when first connecting: it must be -# issued before any other command will be accepted, and will fail once the -# monitor is accepting other commands. (see qemu docs/interop/qmp-spec.txt) -# -# The QMP client needs to explicitly enable QMP capabilities, otherwise -# all the QMP capabilities will be turned off by default. -# -# Since: 0.13 -# -## -{ 'command': 'qmp_capabilities', - 'data': { '*enable': [ 'QMPCapability' ] }, - 'allow-preconfig': true } - -## -# @QMPCapability: -# -# Enumeration of capabilities to be advertised during initial client -# connection, used for agreeing on particular QMP extension behaviors. -# -# @oob: QMP ability to support out-of-band requests. -# (Please refer to qmp-spec.txt for more information on OOB) -# -# Since: 2.12 -# -## -{ 'enum': 'QMPCapability', - 'data': [ 'oob' ] } - -## -# @VersionTriple: -# -# A three-part version number. -# -# @major: The major version number. -# -# @minor: The minor version number. -# -# @micro: The micro version number. -# -# Since: 2.4 -## -{ 'struct': 'VersionTriple', - 'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} } - - -## -# @VersionInfo: -# -# A description of QEMU's version. -# -# @qemu: The version of QEMU. By current convention, a micro -# version of 50 signifies a development branch. A micro version -# greater than or equal to 90 signifies a release candidate for -# the next minor version. A micro version of less than 50 -# signifies a stable release. -# -# @package: QEMU will always set this field to an empty string. Downstream -# versions of QEMU should set this to a non-empty string. The -# exact format depends on the downstream however it highly -# recommended that a unique name is used. -# -# Since: 0.14.0 -## -{ 'struct': 'VersionInfo', - 'data': {'qemu': 'VersionTriple', 'package': 'str'} } - -## -# @query-version: -# -# Returns the current version of QEMU. -# -# Returns: A @VersionInfo object describing the current version of QEMU. -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "query-version" } -# <- { -# "return":{ -# "qemu":{ -# "major":0, -# "minor":11, -# "micro":5 -# }, -# "package":"" -# } -# } -# -## -{ 'command': 'query-version', 'returns': 'VersionInfo', - 'allow-preconfig': true } - -## -# @CommandInfo: -# -# Information about a QMP command -# -# @name: The command name -# -# Since: 0.14.0 -## -{ 'struct': 'CommandInfo', 'data': {'name': 'str'} } - -## -# @query-commands: -# -# Return a list of supported QMP commands by this server -# -# Returns: A list of @CommandInfo for all supported commands -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "query-commands" } -# <- { -# "return":[ -# { -# "name":"query-balloon" -# }, -# { -# "name":"system_powerdown" -# } -# ] -# } -# -# Note: This example has been shortened as the real response is too long. -# -## -{ 'command': 'query-commands', 'returns': ['CommandInfo'], - 'allow-preconfig': true } - ## # @LostTickPolicy: # @@ -300,48 +147,6 @@ ## { 'command': 'query-uuid', 'returns': 'UuidInfo', 'allow-preconfig': true } -## -# @EventInfo: -# -# Information about a QMP event -# -# @name: The event name -# -# Since: 1.2.0 -## -{ 'struct': 'EventInfo', 'data': {'name': 'str'} } - -## -# @query-events: -# -# Return information on QMP events. -# -# Returns: A list of @EventInfo. -# -# Since: 1.2.0 -# -# Note: This command is deprecated, because its output doesn't reflect -# compile-time configuration. Use query-qmp-schema instead. -# -# Example: -# -# -> { "execute": "query-events" } -# <- { -# "return": [ -# { -# "name":"SHUTDOWN" -# }, -# { -# "name":"RESET" -# } -# ] -# } -# -# Note: This example has been shortened as the real response is too long. -# -## -{ 'command': 'query-events', 'returns': ['EventInfo'] } - ## # @IOThreadInfo: # @@ -764,23 +569,6 @@ ## { 'command': 'query-pci', 'returns': ['PciInfo'] } -## -# @quit: -# -# This command will cause the QEMU process to exit gracefully. While every -# attempt is made to send the QMP response before terminating, this is not -# guaranteed. When using this interface, a premature EOF would not be -# unexpected. -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "quit" } -# <- { "return": {} } -## -{ 'command': 'quit' } - ## # @stop: # diff --git a/qapi/monitor.json b/qapi/monitor.json new file mode 100644 index 0000000000..a82a18da1a --- /dev/null +++ b/qapi/monitor.json @@ -0,0 +1,218 @@ +# -*- Mode: Python -*- +# + +## +# = Monitor definitions (shared between system emulator and tools) +## + +## +# @qmp_capabilities: +# +# Enable QMP capabilities. +# +# Arguments: +# +# @enable: An optional list of QMPCapability values to enable. The +# client must not enable any capability that is not +# mentioned in the QMP greeting message. If the field is not +# provided, it means no QMP capabilities will be enabled. +# (since 2.12) +# +# Example: +# +# -> { "execute": "qmp_capabilities", +# "arguments": { "enable": [ "oob" ] } } +# <- { "return": {} } +# +# Notes: This command is valid exactly when first connecting: it must be +# issued before any other command will be accepted, and will fail once the +# monitor is accepting other commands. (see qemu docs/interop/qmp-spec.txt) +# +# The QMP client needs to explicitly enable QMP capabilities, otherwise +# all the QMP capabilities will be turned off by default. +# +# Since: 0.13 +# +## +{ 'command': 'qmp_capabilities', + 'data': { '*enable': [ 'QMPCapability' ] }, + 'allow-preconfig': true } + +## +# @QMPCapability: +# +# Enumeration of capabilities to be advertised during initial client +# connection, used for agreeing on particular QMP extension behaviors. +# +# @oob: QMP ability to support out-of-band requests. +# (Please refer to qmp-spec.txt for more information on OOB) +# +# Since: 2.12 +# +## +{ 'enum': 'QMPCapability', + 'data': [ 'oob' ] } + +## +# @VersionTriple: +# +# A three-part version number. +# +# @major: The major version number. +# +# @minor: The minor version number. +# +# @micro: The micro version number. +# +# Since: 2.4 +## +{ 'struct': 'VersionTriple', + 'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} } + + +## +# @VersionInfo: +# +# A description of QEMU's version. +# +# @qemu: The version of QEMU. By current convention, a micro +# version of 50 signifies a development branch. A micro version +# greater than or equal to 90 signifies a release candidate for +# the next minor version. A micro version of less than 50 +# signifies a stable release. +# +# @package: QEMU will always set this field to an empty string. Downstream +# versions of QEMU should set this to a non-empty string. The +# exact format depends on the downstream however it highly +# recommended that a unique name is used. +# +# Since: 0.14.0 +## +{ 'struct': 'VersionInfo', + 'data': {'qemu': 'VersionTriple', 'package': 'str'} } + +## +# @query-version: +# +# Returns the current version of QEMU. +# +# Returns: A @VersionInfo object describing the current version of QEMU. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-version" } +# <- { +# "return":{ +# "qemu":{ +# "major":0, +# "minor":11, +# "micro":5 +# }, +# "package":"" +# } +# } +# +## +{ 'command': 'query-version', 'returns': 'VersionInfo', + 'allow-preconfig': true } + +## +# @CommandInfo: +# +# Information about a QMP command +# +# @name: The command name +# +# Since: 0.14.0 +## +{ 'struct': 'CommandInfo', 'data': {'name': 'str'} } + +## +# @query-commands: +# +# Return a list of supported QMP commands by this server +# +# Returns: A list of @CommandInfo for all supported commands +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-commands" } +# <- { +# "return":[ +# { +# "name":"query-balloon" +# }, +# { +# "name":"system_powerdown" +# } +# ] +# } +# +# Note: This example has been shortened as the real response is too long. +# +## +{ 'command': 'query-commands', 'returns': ['CommandInfo'], + 'allow-preconfig': true } + +## +# @EventInfo: +# +# Information about a QMP event +# +# @name: The event name +# +# Since: 1.2.0 +## +{ 'struct': 'EventInfo', 'data': {'name': 'str'} } + +## +# @query-events: +# +# Return information on QMP events. +# +# Returns: A list of @EventInfo. +# +# Since: 1.2.0 +# +# Note: This command is deprecated, because its output doesn't reflect +# compile-time configuration. Use query-qmp-schema instead. +# +# Example: +# +# -> { "execute": "query-events" } +# <- { +# "return": [ +# { +# "name":"SHUTDOWN" +# }, +# { +# "name":"RESET" +# } +# ] +# } +# +# Note: This example has been shortened as the real response is too long. +# +## +{ 'command': 'query-events', 'returns': ['EventInfo'] } + +## +# @quit: +# +# This command will cause the QEMU process to exit gracefully. While every +# attempt is made to send the QMP response before terminating, this is not +# guaranteed. When using this interface, a premature EOF would not be +# unexpected. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "quit" } +# <- { "return": {} } +## +{ 'command': 'quit' } diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 9751b11f8f..be90422ffe 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -103,6 +103,7 @@ { 'include': 'qdev.json' } { 'include': 'machine.json' } { 'include': 'machine-target.json' } +{ 'include': 'monitor.json' } { 'include': 'misc.json' } { 'include': 'misc-target.json' } { 'include': 'audio.json' } diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index d78f5ca190..451aa64c1a 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -27,6 +27,7 @@ #include "chardev/char-fe.h" #include "monitor/monitor.h" +#include "qapi/qapi-types-monitor.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/json-parser.h" #include "qemu/readline.h" diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 22d7e6e222..ccdfb547d6 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -33,6 +33,7 @@ #include "qapi/qapi-commands-char.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qapi/qapi-commands-net.h" #include "qapi/qapi-commands-rocker.h" #include "qapi/qapi-commands-run-state.h" diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 0880341a2d..b40a9b74de 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -34,6 +34,7 @@ #include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qerror.h" #include "hw/mem/memory-device.h" diff --git a/monitor/qmp.c b/monitor/qmp.c index 9d9e5d8b27..6605f35048 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -27,7 +27,7 @@ #include "chardev/char-io.h" #include "monitor-internal.h" #include "qapi/error.h" -#include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 1b0eb69832..7fc646ffc2 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -13,7 +13,7 @@ #include "qemu/osdep.h" #include "libqtest.h" #include "qapi/error.h" -#include "qapi/qapi-visit-misc.h" +#include "qapi/qapi-visit-monitor.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qapi/qobject-input-visitor.h" diff --git a/ui/gtk.c b/ui/gtk.c index 2f23922afc..d96a11deea 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -33,6 +33,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qemu/cutils.h" #include "ui/console.h" diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index dd3f5e6f94..519b6f1a8e 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -6,8 +6,8 @@ util-obj-y += qmp-event.o util-obj-y += qapi-util.o QAPI_COMMON_MODULES = audio authz block-core block char common crypto -QAPI_COMMON_MODULES += dump error introspect job machine migration misc net -QAPI_COMMON_MODULES += qdev qom rdma rocker run-state sockets tpm +QAPI_COMMON_MODULES += dump error introspect job machine migration misc monitor +QAPI_COMMON_MODULES += net qdev qom rdma rocker run-state sockets tpm QAPI_COMMON_MODULES += trace transaction ui QAPI_TARGET_MODULES = machine-target misc-target QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES) From patchwork Thu Oct 17 13:02:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195883 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F870912 for ; Thu, 17 Oct 2019 13:17:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C143214E0 for ; Thu, 17 Oct 2019 13:17:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C143214E0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5ee-0000h3-6B for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:17:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60201) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SQ-0001CC-Ga for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SK-00007N-OE for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5SC-0008Vn-RO; Thu, 17 Oct 2019 09:04:33 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 207D63078468; Thu, 17 Oct 2019 13:04:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9285D1001B28; Thu, 17 Oct 2019 13:04:30 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 14/18] monitor: Create monitor/qmp-cmds-monitor.c Date: Thu, 17 Oct 2019 15:02:00 +0200 Message-Id: <20191017130204.16131-15-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 17 Oct 2019 13:04:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Move all of the QMP commands handlers to implement the 'monitor' module (qapi/monitor.json) that can be shared between the system emulator and the storage daemon to a new file monitor/qmp-cmds-monitor.c. Signed-off-by: Kevin Wolf --- monitor/misc.c | 110 -------------------------- monitor/qmp-cmds-monitor.c | 153 +++++++++++++++++++++++++++++++++++++ monitor/qmp-cmds.c | 14 ---- monitor/Makefile.objs | 3 +- 4 files changed, 155 insertions(+), 125 deletions(-) create mode 100644 monitor/qmp-cmds-monitor.c diff --git a/monitor/misc.c b/monitor/misc.c index aef16f6cfb..95c87df09b 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -67,7 +67,6 @@ #include "qemu/thread.h" #include "block/qapi.h" #include "qapi/qapi-commands.h" -#include "qapi/qapi-emit-events.h" #include "qapi/error.h" #include "qapi/qmp-event.h" #include "qapi/qapi-introspect.h" @@ -230,58 +229,6 @@ static void hmp_info_help(Monitor *mon, const QDict *qdict) help_cmd(mon, "info"); } -static void query_commands_cb(QmpCommand *cmd, void *opaque) -{ - CommandInfoList *info, **list = opaque; - - if (!cmd->enabled) { - return; - } - - info = g_malloc0(sizeof(*info)); - info->value = g_malloc0(sizeof(*info->value)); - info->value->name = g_strdup(cmd->name); - info->next = *list; - *list = info; -} - -CommandInfoList *qmp_query_commands(Error **errp) -{ - CommandInfoList *list = NULL; - MonitorQMP *mon; - - assert(monitor_is_qmp(cur_mon)); - mon = container_of(cur_mon, MonitorQMP, common); - - qmp_for_each_command(mon->commands, query_commands_cb, &list); - - return list; -} - -EventInfoList *qmp_query_events(Error **errp) -{ - /* - * TODO This deprecated command is the only user of - * QAPIEvent_str() and QAPIEvent_lookup[]. When the command goes, - * they should go, too. - */ - EventInfoList *info, *ev_list = NULL; - QAPIEvent e; - - for (e = 0 ; e < QAPI_EVENT__MAX ; e++) { - const char *event_name = QAPIEvent_str(e); - assert(event_name != NULL); - info = g_malloc0(sizeof(*info)); - info->value = g_malloc0(sizeof(*info->value)); - info->value->name = g_strdup(event_name); - - info->next = ev_list; - ev_list = info; - } - - return ev_list; -} - /* * Minor hack: generated marshalling suppressed for this command * ('gen': false in the schema) so we can parse the JSON string @@ -320,63 +267,6 @@ static void monitor_init_qmp_commands(void) qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG); } -/* - * Accept QMP capabilities in @list for @mon. - * On success, set mon->qmp.capab[], and return true. - * On error, set @errp, and return false. - */ -static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list, - Error **errp) -{ - GString *unavailable = NULL; - bool capab[QMP_CAPABILITY__MAX]; - - memset(capab, 0, sizeof(capab)); - - for (; list; list = list->next) { - if (!mon->capab_offered[list->value]) { - if (!unavailable) { - unavailable = g_string_new(QMPCapability_str(list->value)); - } else { - g_string_append_printf(unavailable, ", %s", - QMPCapability_str(list->value)); - } - } - capab[list->value] = true; - } - - if (unavailable) { - error_setg(errp, "Capability %s not available", unavailable->str); - g_string_free(unavailable, true); - return false; - } - - memcpy(mon->capab, capab, sizeof(capab)); - return true; -} - -void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, - Error **errp) -{ - MonitorQMP *mon; - - assert(monitor_is_qmp(cur_mon)); - mon = container_of(cur_mon, MonitorQMP, common); - - if (mon->commands == &qmp_commands) { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, - "Capabilities negotiation is already complete, command " - "ignored"); - return; - } - - if (!qmp_caps_accept(mon, enable, errp)) { - return; - } - - mon->commands = &qmp_commands; -} - /* Set the current CPU defined by the user. Callers must hold BQL. */ int monitor_set_cpu(int cpu_index) { diff --git a/monitor/qmp-cmds-monitor.c b/monitor/qmp-cmds-monitor.c new file mode 100644 index 0000000000..acebfd3716 --- /dev/null +++ b/monitor/qmp-cmds-monitor.c @@ -0,0 +1,153 @@ +/* + * QMP commands related to the monitor (common functions for sysemu and tools) + * + * Copyright (c) 2003-2004 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" + +#include "monitor-internal.h" +#include "qemu-version.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-monitor.h" +#include "qapi/qapi-emit-events.h" + +/* + * Accept QMP capabilities in @list for @mon. + * On success, set mon->qmp.capab[], and return true. + * On error, set @errp, and return false. + */ +static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list, + Error **errp) +{ + GString *unavailable = NULL; + bool capab[QMP_CAPABILITY__MAX]; + + memset(capab, 0, sizeof(capab)); + + for (; list; list = list->next) { + if (!mon->capab_offered[list->value]) { + if (!unavailable) { + unavailable = g_string_new(QMPCapability_str(list->value)); + } else { + g_string_append_printf(unavailable, ", %s", + QMPCapability_str(list->value)); + } + } + capab[list->value] = true; + } + + if (unavailable) { + error_setg(errp, "Capability %s not available", unavailable->str); + g_string_free(unavailable, true); + return false; + } + + memcpy(mon->capab, capab, sizeof(capab)); + return true; +} + +void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, + Error **errp) +{ + MonitorQMP *mon; + + assert(monitor_is_qmp(cur_mon)); + mon = container_of(cur_mon, MonitorQMP, common); + + if (mon->commands == &qmp_commands) { + error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, + "Capabilities negotiation is already complete, command " + "ignored"); + return; + } + + if (!qmp_caps_accept(mon, enable, errp)) { + return; + } + + mon->commands = &qmp_commands; +} + +VersionInfo *qmp_query_version(Error **errp) +{ + VersionInfo *info = g_new0(VersionInfo, 1); + + info->qemu = g_new0(VersionTriple, 1); + info->qemu->major = QEMU_VERSION_MAJOR; + info->qemu->minor = QEMU_VERSION_MINOR; + info->qemu->micro = QEMU_VERSION_MICRO; + info->package = g_strdup(QEMU_PKGVERSION); + + return info; +} + +static void query_commands_cb(QmpCommand *cmd, void *opaque) +{ + CommandInfoList *info, **list = opaque; + + if (!cmd->enabled) { + return; + } + + info = g_malloc0(sizeof(*info)); + info->value = g_malloc0(sizeof(*info->value)); + info->value->name = g_strdup(cmd->name); + info->next = *list; + *list = info; +} + +CommandInfoList *qmp_query_commands(Error **errp) +{ + CommandInfoList *list = NULL; + MonitorQMP *mon; + + assert(monitor_is_qmp(cur_mon)); + mon = container_of(cur_mon, MonitorQMP, common); + + qmp_for_each_command(mon->commands, query_commands_cb, &list); + + return list; +} + +EventInfoList *qmp_query_events(Error **errp) +{ + /* + * TODO This deprecated command is the only user of + * QAPIEvent_str() and QAPIEvent_lookup[]. When the command goes, + * they should go, too. + */ + EventInfoList *info, *ev_list = NULL; + QAPIEvent e; + + for (e = 0 ; e < QAPI_EVENT__MAX ; e++) { + const char *event_name = QAPIEvent_str(e); + assert(event_name != NULL); + info = g_malloc0(sizeof(*info)); + info->value = g_malloc0(sizeof(*info->value)); + info->value->name = g_strdup(event_name); + + info->next = ev_list; + ev_list = info; + } + + return ev_list; +} diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index b40a9b74de..22a3375194 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -15,7 +15,6 @@ #include "qemu/osdep.h" #include "qemu-common.h" -#include "qemu-version.h" #include "qemu/cutils.h" #include "qemu/option.h" #include "monitor/monitor.h" @@ -52,19 +51,6 @@ NameInfo *qmp_query_name(Error **errp) return info; } -VersionInfo *qmp_query_version(Error **errp) -{ - VersionInfo *info = g_new0(VersionInfo, 1); - - info->qemu = g_new0(VersionTriple, 1); - info->qemu->major = QEMU_VERSION_MAJOR; - info->qemu->minor = QEMU_VERSION_MINOR; - info->qemu->micro = QEMU_VERSION_MICRO; - info->package = g_strdup(QEMU_PKGVERSION); - - return info; -} - KvmInfo *qmp_query_kvm(Error **errp) { KvmInfo *info = g_malloc0(sizeof(*info)); diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs index e91a8581cd..15eb6380c5 100644 --- a/monitor/Makefile.objs +++ b/monitor/Makefile.objs @@ -1,3 +1,4 @@ obj-y += misc.o common-obj-y += monitor.o qmp.o hmp.o -common-obj-y += qmp-cmds.o hmp-cmds.o +common-obj-y += qmp-cmds.o qmp-cmds-monitor.o +common-obj-y += hmp-cmds.o From patchwork Thu Oct 17 13:02:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195875 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E611912 for ; Thu, 17 Oct 2019 13:12:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F11DB2089C for ; Thu, 17 Oct 2019 13:12:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F11DB2089C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5aH-0003e3-9o for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:12:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60151) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SN-00017L-HR for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SI-00006g-4g for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5SE-00004r-Nf; Thu, 17 Oct 2019 09:04:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0459307D976; Thu, 17 Oct 2019 13:04:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B8CE1001B11; Thu, 17 Oct 2019 13:04:32 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 15/18] qapi: Support empty modules Date: Thu, 17 Oct 2019 15:02:01 +0200 Message-Id: <20191017130204.16131-16-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 17 Oct 2019 13:04:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" If you added an include file that doesn't contain any definitions, no source files would be generated for it. However, in other source files, you would still get an #include for the header files of the empty module. The intended behaviour is that empty source files are created for empty modules. This patch makes QAPISchema keep a list of all modules (including empty ones) and modifies visit() to first visit all modules in that list. Some test reference outputs need to be updated due to the additional visitor calls. Signed-off-by: Kevin Wolf --- scripts/qapi/schema.py | 9 +++++++++ tests/qapi-schema/comments.out | 2 ++ tests/qapi-schema/doc-bad-section.out | 2 ++ tests/qapi-schema/doc-good.out | 2 ++ tests/qapi-schema/empty.out | 2 ++ tests/qapi-schema/event-case.out | 2 ++ tests/qapi-schema/include-repetition.out | 4 ++++ tests/qapi-schema/include-simple.out | 3 +++ tests/qapi-schema/indented-expr.out | 2 ++ tests/qapi-schema/qapi-schema-test.out | 4 ++++ 10 files changed, 32 insertions(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 38041098bd..e1b034d67d 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -749,6 +749,7 @@ class QAPISchema(object): self.docs = parser.docs self._entity_list = [] self._entity_dict = {} + self._modules = [os.path.basename(fname)] self._predefining = True self._def_predefineds() self._predefining = False @@ -800,6 +801,8 @@ class QAPISchema(object): main_info = main_info.parent fname = os.path.relpath(include, os.path.dirname(main_info.fname)) self._def_entity(QAPISchemaInclude(fname, info)) + if fname not in self._modules: + self._modules.append(fname) def _def_builtin_type(self, name, json_type, c_type): self._def_entity(QAPISchemaBuiltinType(name, json_type, c_type)) @@ -1033,6 +1036,12 @@ class QAPISchema(object): visitor.visit_begin(self) module = None visitor.visit_module(module) + + # Make sure that all modules are visited, even if they contain no + # entities + for module in self._modules: + visitor.visit_module(module) + for entity in self._entity_list: if visitor.visit_needed(entity): if entity.module != module: diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out index 273f0f54e1..fa7e95d1cc 100644 --- a/tests/qapi-schema/comments.out +++ b/tests/qapi-schema/comments.out @@ -1,4 +1,6 @@ module None +module comments.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/doc-bad-section.out b/tests/qapi-schema/doc-bad-section.out index 367e2a1c3e..331237cfbe 100644 --- a/tests/qapi-schema/doc-bad-section.out +++ b/tests/qapi-schema/doc-bad-section.out @@ -1,4 +1,6 @@ module None +module doc-bad-section.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index d3bca343eb..8f3577bb21 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -1,4 +1,6 @@ module None +module doc-good.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out index 5b53d00702..3671cbbe59 100644 --- a/tests/qapi-schema/empty.out +++ b/tests/qapi-schema/empty.out @@ -1,4 +1,6 @@ module None +module empty.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-case.out index ec8a1406e4..2b2d8548e9 100644 --- a/tests/qapi-schema/event-case.out +++ b/tests/qapi-schema/event-case.out @@ -1,4 +1,6 @@ module None +module event-case.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-repetition.out b/tests/qapi-schema/include-repetition.out index 5423983239..ebaac1813d 100644 --- a/tests/qapi-schema/include-repetition.out +++ b/tests/qapi-schema/include-repetition.out @@ -1,4 +1,8 @@ module None +module include-repetition.json +module comments.json +module include-repetition-sub.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-simple.out b/tests/qapi-schema/include-simple.out index 061f81e509..dea51f9738 100644 --- a/tests/qapi-schema/include-simple.out +++ b/tests/qapi-schema/include-simple.out @@ -1,4 +1,7 @@ module None +module include-simple.json +module include-simple-sub.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indented-expr.out index bffdf6756d..d4cffb9c1b 100644 --- a/tests/qapi-schema/indented-expr.out +++ b/tests/qapi-schema/indented-expr.out @@ -1,4 +1,6 @@ module None +module indented-expr.json +module None object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 98031da96f..93c944a2fb 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -1,4 +1,8 @@ module None +module qapi-schema-test.json +module include/sub-module.json +module sub-sub-module.json +module None object q_empty enum QType prefix QTYPE From patchwork Thu Oct 17 13:02:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2E0815AB for ; Thu, 17 Oct 2019 13:14:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D218B20640 for ; Thu, 17 Oct 2019 13:14:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D218B20640 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5bi-0005HU-GO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:14:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60196) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SP-0001BJ-R2 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SO-00009K-FN for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46114) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5SL-00007T-DL; Thu, 17 Oct 2019 09:04:41 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7E1A307D976; Thu, 17 Oct 2019 13:04:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4457D1001B11; Thu, 17 Oct 2019 13:04:34 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 16/18] qapi: Create 'pragma' module Date: Thu, 17 Oct 2019 15:02:02 +0200 Message-Id: <20191017130204.16131-17-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 17 Oct 2019 13:04:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We want to share the whitelists between the system emulator schema and the storage daemon schema, so move all the pragmas from the main schema file into a separate file that can be included from both. Signed-off-by: Kevin Wolf --- qapi/pragma.json | 24 ++++++++++++++++++++++++ qapi/qapi-schema.json | 25 +------------------------ qapi/Makefile.objs | 2 +- 3 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 qapi/pragma.json diff --git a/qapi/pragma.json b/qapi/pragma.json new file mode 100644 index 0000000000..cffae27666 --- /dev/null +++ b/qapi/pragma.json @@ -0,0 +1,24 @@ +{ 'pragma': { 'doc-required': true } } + +# Whitelists to permit QAPI rule violations; think twice before you +# add to them! +{ 'pragma': { + # Commands allowed to return a non-dictionary: + 'returns-whitelist': [ + 'human-monitor-command', + 'qom-get', + 'query-migrate-cache-size', + 'query-tpm-models', + 'query-tpm-types', + 'ringbuf-read' ], + 'name-case-whitelist': [ + 'ACPISlotType', # DIMM, visible through query-acpi-ospm-status + 'CpuInfoMIPS', # PC, visible through query-cpu + 'CpuInfoTricore', # PC, visible through query-cpu + 'BlockdevVmdkSubformat', # all members, to match VMDK spec spellings + 'BlockdevVmdkAdapterType', # legacyESX, to match VMDK spec spellings + 'QapiErrorClass', # all members, visible through errors + 'UuidInfo', # UUID, visible through query-uuid + 'X86CPURegister32', # all members, visible indirectly through qom-get + 'CpuInfo' # CPU, visible through query-cpu + ] } } diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index be90422ffe..85b4048535 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -49,30 +49,7 @@ # ## -{ 'pragma': { 'doc-required': true } } - -# Whitelists to permit QAPI rule violations; think twice before you -# add to them! -{ 'pragma': { - # Commands allowed to return a non-dictionary: - 'returns-whitelist': [ - 'human-monitor-command', - 'qom-get', - 'query-migrate-cache-size', - 'query-tpm-models', - 'query-tpm-types', - 'ringbuf-read' ], - 'name-case-whitelist': [ - 'ACPISlotType', # DIMM, visible through query-acpi-ospm-status - 'CpuInfoMIPS', # PC, visible through query-cpu - 'CpuInfoTricore', # PC, visible through query-cpu - 'BlockdevVmdkSubformat', # all members, to match VMDK spec spellings - 'BlockdevVmdkAdapterType', # legacyESX, to match VMDK spec spellings - 'QapiErrorClass', # all members, visible through errors - 'UuidInfo', # UUID, visible through query-uuid - 'X86CPURegister32', # all members, visible indirectly through qom-get - 'CpuInfo' # CPU, visible through query-cpu - ] } } +{ 'include': 'pragma.json' } # Documentation generated with qapi-gen.py is in source order, with # included sub-schemas inserted at the first include directive diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index 519b6f1a8e..3e04e299ed 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -7,7 +7,7 @@ util-obj-y += qapi-util.o QAPI_COMMON_MODULES = audio authz block-core block char common crypto QAPI_COMMON_MODULES += dump error introspect job machine migration misc monitor -QAPI_COMMON_MODULES += net qdev qom rdma rocker run-state sockets tpm +QAPI_COMMON_MODULES += net pragma qdev qom rdma rocker run-state sockets tpm QAPI_COMMON_MODULES += trace transaction ui QAPI_TARGET_MODULES = machine-target misc-target QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES) From patchwork Thu Oct 17 13:02:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195923 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EDB714DB for ; Thu, 17 Oct 2019 13:23:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0EB6520869 for ; Thu, 17 Oct 2019 13:23:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EB6520869 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5kg-0008Et-Qw for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:23:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60245) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SV-0001KL-3z for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5SQ-0000AO-2L for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32956) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5SN-00008E-8W; Thu, 17 Oct 2019 09:04:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 803553090FDF; Thu, 17 Oct 2019 13:04:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id F267610098FB; Thu, 17 Oct 2019 13:04:40 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 17/18] monitor: Move qmp_query_qmp_schema to qmp-cmds-monitor.c Date: Thu, 17 Oct 2019 15:02:03 +0200 Message-Id: <20191017130204.16131-18-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 17 Oct 2019 13:04:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" monitor/misc.c contains code that works only in the system emulator, so it can't be linked to the storage daemon. In order to make schema introspection available for the storage daemon, move the function to monitor/qmp-cmds-monitor.c, which can be linked into the storage daemon. Signed-off-by: Kevin Wolf --- monitor/monitor-internal.h | 3 +++ monitor/misc.c | 16 ---------------- monitor/qmp-cmds-monitor.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 451aa64c1a..b91cb09ee5 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -180,4 +180,7 @@ void help_cmd(Monitor *mon, const char *name); void handle_hmp_command(MonitorHMP *mon, const char *cmdline); int hmp_compare_cmd(const char *name, const char *list); +void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, + Error **errp); + #endif diff --git a/monitor/misc.c b/monitor/misc.c index 95c87df09b..4c90c6813e 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -69,7 +69,6 @@ #include "qapi/qapi-commands.h" #include "qapi/error.h" #include "qapi/qmp-event.h" -#include "qapi/qapi-introspect.h" #include "sysemu/cpus.h" #include "qemu/cutils.h" #include "tcg/tcg.h" @@ -229,21 +228,6 @@ static void hmp_info_help(Monitor *mon, const QDict *qdict) help_cmd(mon, "info"); } -/* - * Minor hack: generated marshalling suppressed for this command - * ('gen': false in the schema) so we can parse the JSON string - * directly into QObject instead of first parsing it with - * visit_type_SchemaInfoList() into a SchemaInfoList, then marshal it - * to QObject with generated output marshallers, every time. Instead, - * we do it in test-qobject-input-visitor.c, just to make sure - * qapi-gen.py's output actually conforms to the schema. - */ -static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, - Error **errp) -{ - *ret_data = qobject_from_qlit(&qmp_schema_qlit); -} - static void monitor_init_qmp_commands(void) { /* diff --git a/monitor/qmp-cmds-monitor.c b/monitor/qmp-cmds-monitor.c index acebfd3716..7215392f3e 100644 --- a/monitor/qmp-cmds-monitor.c +++ b/monitor/qmp-cmds-monitor.c @@ -29,6 +29,7 @@ #include "qapi/error.h" #include "qapi/qapi-commands-monitor.h" #include "qapi/qapi-emit-events.h" +#include "qapi/qapi-introspect.h" /* * Accept QMP capabilities in @list for @mon. @@ -151,3 +152,18 @@ EventInfoList *qmp_query_events(Error **errp) return ev_list; } + +/* + * Minor hack: generated marshalling suppressed for this command + * ('gen': false in the schema) so we can parse the JSON string + * directly into QObject instead of first parsing it with + * visit_type_SchemaInfoList() into a SchemaInfoList, then marshal it + * to QObject with generated output marshallers, every time. Instead, + * we do it in test-qobject-input-visitor.c, just to make sure + * qapi-gen.py's output actually conforms to the schema. + */ +void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, + Error **errp) +{ + *ret_data = qobject_from_qlit(&qmp_schema_qlit); +} From patchwork Thu Oct 17 13:02:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11195887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08D421668 for ; Thu, 17 Oct 2019 13:21:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC0FD20869 for ; Thu, 17 Oct 2019 13:21:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC0FD20869 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5iC-0004IA-Lo for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Oct 2019 09:21:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60242) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5SU-0001K2-SE for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5ST-0000Bn-2J for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:04:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51782) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iL5SP-00009R-4D; Thu, 17 Oct 2019 09:04:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C07310F2E84; Thu, 17 Oct 2019 13:04:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC1D01001B28; Thu, 17 Oct 2019 13:04:42 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 18/18] qemu-storage-daemon: Add --monitor option Date: Thu, 17 Oct 2019 15:02:04 +0200 Message-Id: <20191017130204.16131-19-kwolf@redhat.com> In-Reply-To: <20191017130204.16131-1-kwolf@redhat.com> References: <20191017130204.16131-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 17 Oct 2019 13:04:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This adds and parses the --monitor option, so that a QMP monitor can be used in the storage daemon. The monitor offers commands defined in the QAPI schema at storage-daemon/qapi/qapi-schema.json. Signed-off-by: Kevin Wolf --- storage-daemon/qapi/qapi-schema.json | 15 ++++++++++++ qemu-storage-daemon.c | 34 ++++++++++++++++++++++++++++ Makefile | 30 ++++++++++++++++++++++++ Makefile.objs | 4 ++-- monitor/Makefile.objs | 2 ++ qapi/Makefile.objs | 5 ++++ qom/Makefile.objs | 1 + scripts/qapi/gen.py | 5 ++++ storage-daemon/Makefile.objs | 1 + storage-daemon/qapi/Makefile.objs | 1 + 10 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 storage-daemon/qapi/qapi-schema.json create mode 100644 storage-daemon/Makefile.objs create mode 100644 storage-daemon/qapi/Makefile.objs diff --git a/storage-daemon/qapi/qapi-schema.json b/storage-daemon/qapi/qapi-schema.json new file mode 100644 index 0000000000..58c561ebea --- /dev/null +++ b/storage-daemon/qapi/qapi-schema.json @@ -0,0 +1,15 @@ +# -*- Mode: Python -*- + +{ 'include': '../../qapi/pragma.json' } + +{ 'include': '../../qapi/block.json' } +{ 'include': '../../qapi/block-core.json' } +{ 'include': '../../qapi/char.json' } +{ 'include': '../../qapi/common.json' } +{ 'include': '../../qapi/crypto.json' } +{ 'include': '../../qapi/introspect.json' } +{ 'include': '../../qapi/job.json' } +{ 'include': '../../qapi/monitor.json' } +{ 'include': '../../qapi/qom.json' } +{ 'include': '../../qapi/sockets.json' } +{ 'include': '../../qapi/transaction.json' } diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 46e0a6ea56..4939e6b41f 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -28,12 +28,16 @@ #include "block/nbd.h" #include "chardev/char.h" #include "crypto/init.h" +#include "monitor/monitor.h" +#include "monitor/monitor-internal.h" #include "qapi/error.h" #include "qapi/qapi-commands-block.h" #include "qapi/qapi-commands-block-core.h" +#include "qapi/qapi-commands-monitor.h" #include "qapi/qapi-visit-block.h" #include "qapi/qapi-visit-block-core.h" +#include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" #include "qemu-common.h" @@ -46,6 +50,8 @@ #include "qemu/option.h" #include "qom/object_interfaces.h" +#include "storage-daemon/qapi/qapi-commands.h" + #include "sysemu/runstate.h" #include "trace/control.h" @@ -58,6 +64,11 @@ void qemu_system_killed(int signal, pid_t pid) exit_requested = true; } +void qmp_quit(Error **errp) +{ + exit_requested = true; +} + static void help(void) { printf( @@ -101,6 +112,7 @@ enum { OPTION_OBJECT = 256, OPTION_BLOCKDEV, OPTION_CHARDEV, + OPTION_MONITOR, OPTION_NBD_SERVER, OPTION_EXPORT, }; @@ -116,6 +128,17 @@ static QemuOptsList qemu_object_opts = { }, }; +static void init_qmp_commands(void) +{ + qmp_init_marshal(&qmp_commands); + qmp_register_command(&qmp_commands, "query-qmp-schema", + qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG); + + QTAILQ_INIT(&qmp_cap_negotiation_commands); + qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", + qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG); +} + static void init_export(BlockExport *export, Error **errp) { switch (export->type) { @@ -138,6 +161,7 @@ static int process_options(int argc, char *argv[], Error **errp) {"object", required_argument, 0, OPTION_OBJECT}, {"blockdev", required_argument, 0, OPTION_BLOCKDEV}, {"chardev", required_argument, 0, OPTION_CHARDEV}, + {"monitor", required_argument, 0, OPTION_MONITOR}, {"nbd-server", required_argument, 0, OPTION_NBD_SERVER}, {"export", required_argument, 0, OPTION_EXPORT}, {"version", no_argument, 0, 'V'}, @@ -208,6 +232,14 @@ static int process_options(int argc, char *argv[], Error **errp) qemu_opts_del(opts); break; } + case OPTION_MONITOR: + { + QemuOpts *opts = qemu_opts_parse(&qemu_mon_opts, + optarg, true, &error_fatal); + monitor_init_opts(opts, false, &error_fatal); + qemu_opts_del(opts); + break; + } case OPTION_NBD_SERVER: { Visitor *v; @@ -272,6 +304,8 @@ int main(int argc, char *argv[]) qemu_add_opts(&qemu_trace_opts); qcrypto_init(&error_fatal); bdrv_init(); + monitor_init_globals_core(); + init_qmp_commands(); if (qemu_init_main_loop(&local_err)) { error_report_err(local_err); diff --git a/Makefile b/Makefile index 0e3e98582d..e367d2b28a 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,26 @@ GENERATED_QAPI_FILES += $(QAPI_MODULES:%=qapi/qapi-events-%.c) GENERATED_QAPI_FILES += qapi/qapi-introspect.c qapi/qapi-introspect.h GENERATED_QAPI_FILES += qapi/qapi-doc.texi +GENERATED_STORAGE_DAEMON_QAPI_FILES = storage-daemon/qapi/qapi-builtin-types.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-builtin-types.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-builtin-visit.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-builtin-visit.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-commands.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-commands.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-emit-events.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-emit-events.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-events.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-events.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-introspect.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-introspect.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-types.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-types.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-visit.h +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-visit.c +GENERATED_STORAGE_DAEMON_QAPI_FILES += storage-daemon/qapi/qapi-doc.texi + generated-files-y += $(GENERATED_QAPI_FILES) +generated-files-y += $(GENERATED_STORAGE_DAEMON_QAPI_FILES) generated-files-y += trace/generated-tcg-tracers.h @@ -616,6 +635,17 @@ qapi-gen-timestamp: $(qapi-modules) $(qapi-py) "GEN","$(@:%-timestamp=%)") @>$@ +qapi-modules-storage-daemon = \ + $(SRC_PATH)/storage-daemon/qapi/qapi-schema.json \ + $(QAPI_MODULES_STORAGE_DAEMON:%=$(SRC_PATH)/qapi/%.json) + +$(GENERATED_STORAGE_DAEMON_QAPI_FILES): storage-daemon/qapi/qapi-gen-timestamp ; +storage-daemon/qapi/qapi-gen-timestamp: $(qapi-modules-storage-daemon) $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-gen.py \ + -o "storage-daemon/qapi" -b $<, \ + "GEN","$(@:%-timestamp=%)") + @>$@ + QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qapi-commands.h) $(qga-obj-y): $(QGALIB_GEN) diff --git a/Makefile.objs b/Makefile.objs index b667d3f07b..d4e0daddee 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -41,8 +41,8 @@ io-obj-y = io/ # storage-daemon-obj-y is code used by qemu-storage-daemon (these objects are # used for system emulation, too, but specified separately there) -storage-daemon-obj-y = block/ -storage-daemon-obj-y += blockdev.o blockdev-nbd.o iothread.o +storage-daemon-obj-y = block/ monitor/ qapi/ qom/ storage-daemon/ +storage-daemon-obj-y += blockdev.o blockdev-nbd.o iothread.o job-qmp.o storage-daemon-obj-$(CONFIG_WIN32) += os-win32.o storage-daemon-obj-$(CONFIG_POSIX) += os-posix.o diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs index 15eb6380c5..6e4ef60601 100644 --- a/monitor/Makefile.objs +++ b/monitor/Makefile.objs @@ -2,3 +2,5 @@ obj-y += misc.o common-obj-y += monitor.o qmp.o hmp.o common-obj-y += qmp-cmds.o qmp-cmds-monitor.o common-obj-y += hmp-cmds.o + +storage-daemon-obj-y += monitor.o qmp.o qmp-cmds-monitor.o diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index 3e04e299ed..03d256f0a4 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -30,3 +30,8 @@ obj-y += $(QAPI_TARGET_MODULES:%=qapi-events-%.o) obj-y += qapi-events.o obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o) obj-y += qapi-commands.o + +QAPI_MODULES_STORAGE_DAEMON = block block-core char common crypto introspect +QAPI_MODULES_STORAGE_DAEMON += job monitor qom sockets pragma transaction + +storage-daemon-obj-y += $(QAPI_MODULES_STORAGE_DAEMON:%=qapi-commands-%.o) diff --git a/qom/Makefile.objs b/qom/Makefile.objs index f9d77350ac..1b45d104ba 100644 --- a/qom/Makefile.objs +++ b/qom/Makefile.objs @@ -2,3 +2,4 @@ qom-obj-y = object.o container.o qom-qobject.o qom-obj-y += object_interfaces.o common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o +storage-daemon-obj-y += qom-qmp-cmds.o diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 796c17c38a..c25634f673 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -44,6 +44,11 @@ class QAPIGen(object): return '' def write(self, output_dir): + # Include paths starting with ../ are used to reuse modules of the main + # schema in specialised schemas. Don't overwrite the files that are + # already generated for the main schema. + if self.fname.startswith('../'): + return pathname = os.path.join(output_dir, self.fname) dir = os.path.dirname(pathname) if dir: diff --git a/storage-daemon/Makefile.objs b/storage-daemon/Makefile.objs new file mode 100644 index 0000000000..cfe6beee52 --- /dev/null +++ b/storage-daemon/Makefile.objs @@ -0,0 +1 @@ +storage-daemon-obj-y += qapi/ diff --git a/storage-daemon/qapi/Makefile.objs b/storage-daemon/qapi/Makefile.objs new file mode 100644 index 0000000000..df8946bdae --- /dev/null +++ b/storage-daemon/qapi/Makefile.objs @@ -0,0 +1 @@ +storage-daemon-obj-y += qapi-commands.o qapi-introspect.o