From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555062; cv=none; d=zohomail.com; s=zohoarc; b=SYgeo8oMTTJ1fsctgzuAml2oiPNnKx6Nn+DE6vjtrQ4y1XAy9xOeUmHYDIr5ZC7aDjZ5WRJ+vo74DHl5gLw5m1nxXAUgDLxUtThzq8GCNEf3GL3wHG0s8VWwd8oxez6yXRFxYgYr2R2ruhsVolYQ3TIs76oBJNQdl377/w48+Gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555062; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dPKIsCcQthcgEF3vGr1fM/jPzSM0CtjEd4BHQRSKfJ4=; b=lanMctFhYYxhkIesnKj/p38LnsePZ7S5BBY8V/UrpSRnQEHorjTxPZCbUC7swOll2gTzyzNUVK4pra7khNmfxlKkVveqLx0A0L8WdFzhrv+J5irSbxVVJh6oLM9BpQpjR/g+1Padeu72OFlG0JcQmRLA88QKDwI1+iE5J5mWRCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555062129228.3547915689411; Mon, 24 Feb 2020 06:37:42 -0800 (PST) Received: from localhost ([::1]:37428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Erc-0005EW-TS for importer@patchew.org; Mon, 24 Feb 2020 09:37:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50589) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Ekl-0001S6-VI for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Ekk-0001vq-Eh for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:35 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:54500 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Ekk-0001vX-BC for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:34 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-31-RJwVTZe1OpCPKLC6K2xmQw-1; Mon, 24 Feb 2020 09:30:30 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4AE918AB2C2; Mon, 24 Feb 2020 14:30:28 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1259191835; Mon, 24 Feb 2020 14:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dPKIsCcQthcgEF3vGr1fM/jPzSM0CtjEd4BHQRSKfJ4=; b=F4vmrqb+Hhq1HFyDvfXbd87IieD5ZG4yCg7Qy4RdJNG1bIhOmBT/XfFgzmOmPTEoKPNYix 5XjzoKrDTNuY8Bmvd4DFWYTGqu4NBl+4+8sY4pHb08V/EKveHG5q9EMNGi8Ecry/HE4ZC/ /+M8ryi41VFD+BSh6kauxOYvG3kP7GE= X-MC-Unique: RJwVTZe1OpCPKLC6K2xmQw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 01/20] qemu-storage-daemon: Add barebone tool Date: Mon, 24 Feb 2020 15:29:49 +0100 Message-Id: <20200224143008.13362-2-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Even though this doesn't add any options yet that create things (like --object or --blockdev), already document that we're planning to process them in the order they are given on the command line rather than trying (and failing, like vl.c) to resolve dependencies between options automatically. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- configure | 2 +- qemu-storage-daemon.c | 127 ++++++++++++++++++++++++++++++++++++++++++ Makefile | 1 + 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 qemu-storage-daemon.c diff --git a/configure b/configure index d57261e3ad..c9ea8cc8fb 100755 --- a/configure +++ b/configure @@ -6257,7 +6257,7 @@ tools=3D"" if test "$want_tools" =3D "yes" ; then tools=3D"qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-edid\$(EXESUF) $tools" if [ "$linux" =3D "yes" -o "$bsd" =3D "yes" -o "$solaris" =3D "yes" ] ; = then - tools=3D"qemu-nbd\$(EXESUF) $tools" + tools=3D"qemu-nbd\$(EXESUF) qemu-storage-daemon\$(EXESUF) $tools" fi if [ "$ivshmem" =3D "yes" ]; then tools=3D"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..fc4aef572b --- /dev/null +++ b/qemu-storage-daemon.c @@ -0,0 +1,127 @@ +/* + * QEMU storage daemon + * + * Copyright (c) 2003-2008 Fabrice Bellard + * 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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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 + +#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" + +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=3D]][,events=3D][,file=3D]\n" +" specify tracing options\n" +" -V, --version output version information and exit\n" +"\n" +QEMU_HELP_BOTTOM "\n", + error_get_progname()); +} + +static void process_options(int argc, char *argv[]) +{ + int c; + + static const struct option long_options[] =3D { + {"help", no_argument, NULL, 'h'}, + {"trace", required_argument, NULL, 'T'}, + {"version", no_argument, NULL, 'V'}, + {0, 0, 0, 0} + }; + + /* + * In contrast to the system emulator, options are processed in the or= der + * they are given on the command lines. This means that things must be + * defined first before they can be referenced in another option. + */ + while ((c =3D getopt_long(argc, argv, "hT:V", long_options, NULL)) != =3D -1) { + switch (c) { + case '?': + exit(EXIT_FAILURE); + case 'h': + help(); + exit(EXIT_SUCCESS); + case 'T': + { + char *trace_file =3D trace_opt_parse(optarg); + trace_init_file(trace_file); + g_free(trace_file); + break; + } + case 'V': + printf("qemu-storage-daemon version " + QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n"); + exit(EXIT_SUCCESS); + default: + g_assert_not_reached(); + } + } + if (optind !=3D argc) { + error_report("Unexpected argument: %s", argv[optind]); + exit(EXIT_FAILURE); + } +} + +int main(int argc, char *argv[]) +{ +#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 (!trace_init_backends()) { + return EXIT_FAILURE; + } + qemu_set_log(LOG_TRACE); + + qemu_init_main_loop(&error_fatal); + process_options(argc, argv); + + return EXIT_SUCCESS; +} diff --git a/Makefile b/Makefile index 146a91bc3e..44b3c8a342 100644 --- a/Makefile +++ b/Makefile @@ -573,6 +573,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) =20 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) =20 --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582554889; cv=none; d=zohomail.com; s=zohoarc; b=CB0dL4CS3s4K9PTqqx99ECq4+RuCWiYij9cMy4m6g/mw2J5B+cToVyGmkyMOx4hGzQzJ5BJ+Hjt5xORc77hqmuYgikJWU8H7JQhRq1mV0YFKbZKHUZJSXHNOxQZJ9vY+jhrhH3DiNXDqHlnZNf0NPJKO2JF9gJfxkSXZDSs+qmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554889; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=njn4UydcJJdeqk/x+jce44/LXqUdnaYJCL4k0nxXV2E=; b=dFbhtchBgfHIoyRHzuIkVlEK6b6xujwHTYUKVeJeT/Wtf6VBgMF0pQT79MroCSJsbFoBMY+bgp/YArAoFkh3uYmExRM3yxQZfmpzgMIpJtVnmBopvYUEzKD9jYikmBO43EAvH/LGbCF1Kp0jZnDCuvHy6j+5HYDpcJJCuJeeMd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582554889981852.3762519610242; Mon, 24 Feb 2020 06:34:49 -0800 (PST) Received: from localhost ([::1]:37360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Eoq-0008BU-Tw for importer@patchew.org; Mon, 24 Feb 2020 09:34:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50584) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Ekl-0001Rq-LM for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Ekk-0001wP-Je for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:35 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:51088 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Ekk-0001vO-Ew for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:34 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-44-nL4NYS83Nv6HGKl4_0c7nQ-1; Mon, 24 Feb 2020 09:30:32 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 27FE7DB60; Mon, 24 Feb 2020 14:30:31 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DF6490F5B; Mon, 24 Feb 2020 14:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=njn4UydcJJdeqk/x+jce44/LXqUdnaYJCL4k0nxXV2E=; b=cc+YdUxFbjw7PSAmgmlVKC0H3yQ2dgLLY7Wq7bQiBhONqgfdyyVEEKMs9AkvU38YDzJTyD tm4rJ+HevqqefvAWHfz9ropJtJpQToM1FEMrgVlrFV/s/dZxRF/OnwZmBeL3BTQr4IBl8p lzPs3zfI7WBc6d7t5xSaAq8puuPencI= X-MC-Unique: nL4NYS83Nv6HGKl4_0c7nQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 02/20] stubs: Add arch_type Date: Mon, 24 Feb 2020 15:29:50 +0100 Message-Id: <20200224143008.13362-3-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Acked-by: Stefan Hajnoczi --- 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 =3D (1 << 17), QEMU_ARCH_HPPA =3D (1 << 18), QEMU_ARCH_RISCV =3D (1 << 19), + + QEMU_ARCH_NONE =3D (1 << 31), }; =20 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 =3D QEMU_ARCH_NONE; diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 7afbe5fb61..24062ce7d9 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,3 +1,4 @@ +stub-obj-y +=3D arch_type.o stub-obj-y +=3D bdrv-next-monitor-owned.o stub-obj-y +=3D blk-commit-all.o stub-obj-y +=3D blockdev-close-all-bdrv-states.o --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582554762; cv=none; d=zohomail.com; s=zohoarc; b=Uw6iQtLXt3bT+5JBgvut8AID/fOA4tWOW/VxXXT7CHXJhJCgAjvKjTQFUBDH/7gCT0vASlpHfmU8L3oJD2EWgyYVcKIrKldPe4/Lc7s2rKkAqmuMIxP0HUClCQR9SYSONYBx8MUA2gdGV9q2VjmHhKoTkLZ9Nz6BxiK+ICE22qY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554762; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T2/0hbSpoE+ICEmK1pQA2wNovYCsVzJTq9+Zk0GKRz8=; b=AgWHDjTgkiYBiQq3L229boyNpm8FlNCdmLk/cr+L8RxAWfBFRH3/cZEn/URE+dHJY0a8ctC3zQCRhWmaIvAjAD4F5MSinJpYJLE605BEMl+ogUnCEWjr1E+R/bena+gOzfxmLty2MpIeLDug3gkxOWNlmCadIjXQzlo0YsQABLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582554762254297.31802768605485; Mon, 24 Feb 2020 06:32:42 -0800 (PST) Received: from localhost ([::1]:37318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Emm-0003ep-KX for importer@patchew.org; Mon, 24 Feb 2020 09:32:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50626) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Ekt-0001db-SC for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Ekp-000201-RH for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:43 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:54390 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Ekp-0001yb-Gv for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:39 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-78-LsOQQIuIN2aXGY_f8lDcvw-1; Mon, 24 Feb 2020 09:30:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C60D3100550E; Mon, 24 Feb 2020 14:30:33 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DAC55C114; Mon, 24 Feb 2020 14:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2/0hbSpoE+ICEmK1pQA2wNovYCsVzJTq9+Zk0GKRz8=; b=fUINM1v4W+nIj1fkXbDCzDBl+dYpjrwm94WlqsUDX0AWVOZrAffoiKubMkIi3R2GTKw9eY /S9tv/VnxhvKSJgw18RwmTnky9ya00omyUyusD85Qe0NSsVct2/l/TUVMkV8z91pNG4/Ae wYiNJ/8SsnJiHd5Mj6dR0pIpD6pdayo= X-MC-Unique: LsOQQIuIN2aXGY_f8lDcvw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 03/20] block: Move system emulator QMP commands to block/qapi-sysemu.c Date: Mon, 24 Feb 2020 15:29:51 +0100 Message-Id: <20200224143008.13362-4-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" These commands make only sense for system emulators and their implementations call functions that don't exist in tools (e.g. to resolve qdev IDs). Move them out so that blockdev.c can be linked to qemu-storage-daemon. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- block/qapi-sysemu.c | 590 ++++++++++++++++++++++++++++++++++++++++++++ blockdev.c | 559 ----------------------------------------- block/Makefile.objs | 2 + 3 files changed, 592 insertions(+), 559 deletions(-) create mode 100644 block/qapi-sysemu.c diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c new file mode 100644 index 0000000000..8498402ad4 --- /dev/null +++ b/block/qapi-sysemu.c @@ -0,0 +1,590 @@ +/* + * QMP command handlers specific to the system emulators + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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 "qapi/error.h" +#include "qapi/qapi-commands-block.h" +#include "qapi/qmp/qdict.h" +#include "sysemu/block-backend.h" +#include "sysemu/blockdev.h" + +static BlockBackend *qmp_get_blk(const char *blk_name, const char *qdev_id, + Error **errp) +{ + BlockBackend *blk; + + if (!blk_name =3D=3D !qdev_id) { + error_setg(errp, "Need exactly one of 'device' and 'id'"); + return NULL; + } + + if (qdev_id) { + blk =3D blk_by_qdev_id(qdev_id, errp); + } else { + blk =3D blk_by_name(blk_name); + if (blk =3D=3D NULL) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", blk_name); + } + } + + return blk; +} + +/* + * Attempt to open the tray of @device. + * If @force, ignore its tray lock. + * Else, if the tray is locked, don't open it, but ask the guest to open i= t. + * On error, store an error through @errp and return -errno. + * If @device does not exist, return -ENODEV. + * If it has no removable media, return -ENOTSUP. + * If it has no tray, return -ENOSYS. + * If the guest was asked to open the tray, return -EINPROGRESS. + * Else, return 0. + */ +static int do_open_tray(const char *blk_name, const char *qdev_id, + bool force, Error **errp) +{ + BlockBackend *blk; + const char *device =3D qdev_id ?: blk_name; + bool locked; + + blk =3D qmp_get_blk(blk_name, qdev_id, errp); + if (!blk) { + return -ENODEV; + } + + if (!blk_dev_has_removable_media(blk)) { + error_setg(errp, "Device '%s' is not removable", device); + return -ENOTSUP; + } + + if (!blk_dev_has_tray(blk)) { + error_setg(errp, "Device '%s' does not have a tray", device); + return -ENOSYS; + } + + if (blk_dev_is_tray_open(blk)) { + return 0; + } + + locked =3D blk_dev_is_medium_locked(blk); + if (locked) { + blk_dev_eject_request(blk, force); + } + + if (!locked || force) { + blk_dev_change_media_cb(blk, false, &error_abort); + } + + if (locked && !force) { + error_setg(errp, "Device '%s' is locked and force was not specifie= d, " + "wait for tray to open and try again", device); + return -EINPROGRESS; + } + + return 0; +} + +void qmp_blockdev_open_tray(bool has_device, const char *device, + bool has_id, const char *id, + bool has_force, bool force, + Error **errp) +{ + Error *local_err =3D NULL; + int rc; + + if (!has_force) { + force =3D false; + } + rc =3D do_open_tray(has_device ? device : NULL, + has_id ? id : NULL, + force, &local_err); + if (rc && rc !=3D -ENOSYS && rc !=3D -EINPROGRESS) { + error_propagate(errp, local_err); + return; + } + error_free(local_err); +} + +void qmp_blockdev_close_tray(bool has_device, const char *device, + bool has_id, const char *id, + Error **errp) +{ + BlockBackend *blk; + Error *local_err =3D NULL; + + device =3D has_device ? device : NULL; + id =3D has_id ? id : NULL; + + blk =3D qmp_get_blk(device, id, errp); + if (!blk) { + return; + } + + if (!blk_dev_has_removable_media(blk)) { + error_setg(errp, "Device '%s' is not removable", device ?: id); + return; + } + + if (!blk_dev_has_tray(blk)) { + /* Ignore this command on tray-less devices */ + return; + } + + if (!blk_dev_is_tray_open(blk)) { + return; + } + + blk_dev_change_media_cb(blk, true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } +} + +static void blockdev_remove_medium(bool has_device, const char *device, + bool has_id, const char *id, Error **er= rp) +{ + BlockBackend *blk; + BlockDriverState *bs; + AioContext *aio_context; + bool has_attached_device; + + device =3D has_device ? device : NULL; + id =3D has_id ? id : NULL; + + blk =3D qmp_get_blk(device, id, errp); + if (!blk) { + return; + } + + /* For BBs without a device, we can exchange the BDS tree at will */ + has_attached_device =3D blk_get_attached_dev(blk); + + if (has_attached_device && !blk_dev_has_removable_media(blk)) { + error_setg(errp, "Device '%s' is not removable", device ?: id); + return; + } + + if (has_attached_device && blk_dev_has_tray(blk) && + !blk_dev_is_tray_open(blk)) + { + error_setg(errp, "Tray of device '%s' is not open", device ?: id); + return; + } + + bs =3D blk_bs(blk); + if (!bs) { + return; + } + + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_EJECT, errp)) { + goto out; + } + + blk_remove_bs(blk); + + if (!blk_dev_has_tray(blk)) { + /* For tray-less devices, blockdev-open-tray is a no-op (or may no= t be + * called at all); therefore, the medium needs to be ejected here. + * Do it after blk_remove_bs() so blk_is_inserted(blk) returns the= @load + * value passed here (i.e. false). */ + blk_dev_change_media_cb(blk, false, &error_abort); + } + +out: + aio_context_release(aio_context); +} + +void qmp_blockdev_remove_medium(const char *id, Error **errp) +{ + blockdev_remove_medium(false, NULL, true, id, errp); +} + +static void qmp_blockdev_insert_anon_medium(BlockBackend *blk, + BlockDriverState *bs, Error **= errp) +{ + Error *local_err =3D NULL; + bool has_device; + int ret; + + /* For BBs without a device, we can exchange the BDS tree at will */ + has_device =3D blk_get_attached_dev(blk); + + if (has_device && !blk_dev_has_removable_media(blk)) { + error_setg(errp, "Device is not removable"); + return; + } + + if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk))= { + error_setg(errp, "Tray of the device is not open"); + return; + } + + if (blk_bs(blk)) { + error_setg(errp, "There already is a medium in the device"); + return; + } + + ret =3D blk_insert_bs(blk, bs, errp); + if (ret < 0) { + return; + } + + if (!blk_dev_has_tray(blk)) { + /* For tray-less devices, blockdev-close-tray is a no-op (or may n= ot be + * called at all); therefore, the medium needs to be pushed into t= he + * slot here. + * Do it after blk_insert_bs() so blk_is_inserted(blk) returns the= @load + * value passed here (i.e. true). */ + blk_dev_change_media_cb(blk, true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + blk_remove_bs(blk); + return; + } + } +} + +static void blockdev_insert_medium(bool has_device, const char *device, + bool has_id, const char *id, + const char *node_name, Error **errp) +{ + BlockBackend *blk; + BlockDriverState *bs; + + blk =3D qmp_get_blk(has_device ? device : NULL, + has_id ? id : NULL, + errp); + if (!blk) { + return; + } + + bs =3D bdrv_find_node(node_name); + if (!bs) { + error_setg(errp, "Node '%s' not found", node_name); + return; + } + + if (bdrv_has_blk(bs)) { + error_setg(errp, "Node '%s' is already in use", node_name); + return; + } + + qmp_blockdev_insert_anon_medium(blk, bs, errp); +} + +void qmp_blockdev_insert_medium(const char *id, const char *node_name, + Error **errp) +{ + blockdev_insert_medium(false, NULL, true, id, node_name, errp); +} + +void qmp_blockdev_change_medium(bool has_device, const char *device, + bool has_id, const char *id, + const char *filename, + bool has_format, const char *format, + bool has_read_only, + BlockdevChangeReadOnlyMode read_only, + Error **errp) +{ + BlockBackend *blk; + BlockDriverState *medium_bs =3D NULL; + int bdrv_flags; + bool detect_zeroes; + int rc; + QDict *options =3D NULL; + Error *err =3D NULL; + + blk =3D qmp_get_blk(has_device ? device : NULL, + has_id ? id : NULL, + errp); + if (!blk) { + goto fail; + } + + if (blk_bs(blk)) { + blk_update_root_state(blk); + } + + bdrv_flags =3D blk_get_open_flags_from_root_state(blk); + bdrv_flags &=3D ~(BDRV_O_TEMPORARY | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKI= NG | + BDRV_O_PROTOCOL | BDRV_O_AUTO_RDONLY); + + if (!has_read_only) { + read_only =3D BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN; + } + + switch (read_only) { + case BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN: + break; + + case BLOCKDEV_CHANGE_READ_ONLY_MODE_READ_ONLY: + bdrv_flags &=3D ~BDRV_O_RDWR; + break; + + case BLOCKDEV_CHANGE_READ_ONLY_MODE_READ_WRITE: + bdrv_flags |=3D BDRV_O_RDWR; + break; + + default: + abort(); + } + + options =3D qdict_new(); + detect_zeroes =3D blk_get_detect_zeroes_from_root_state(blk); + qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off"); + + if (has_format) { + qdict_put_str(options, "driver", format); + } + + medium_bs =3D bdrv_open(filename, NULL, options, bdrv_flags, errp); + if (!medium_bs) { + goto fail; + } + + rc =3D do_open_tray(has_device ? device : NULL, + has_id ? id : NULL, + false, &err); + if (rc && rc !=3D -ENOSYS) { + error_propagate(errp, err); + goto fail; + } + error_free(err); + err =3D NULL; + + blockdev_remove_medium(has_device, device, has_id, id, &err); + if (err) { + error_propagate(errp, err); + goto fail; + } + + qmp_blockdev_insert_anon_medium(blk, medium_bs, &err); + if (err) { + error_propagate(errp, err); + goto fail; + } + + qmp_blockdev_close_tray(has_device, device, has_id, id, errp); + +fail: + /* If the medium has been inserted, the device has its own reference, = so + * ours must be relinquished; and if it has not been inserted successf= ully, + * the reference must be relinquished anyway */ + bdrv_unref(medium_bs); +} + +void qmp_eject(bool has_device, const char *device, + bool has_id, const char *id, + bool has_force, bool force, Error **errp) +{ + Error *local_err =3D NULL; + int rc; + + if (!has_force) { + force =3D false; + } + + rc =3D do_open_tray(has_device ? device : NULL, + has_id ? id : NULL, + force, &local_err); + if (rc && rc !=3D -ENOSYS) { + error_propagate(errp, local_err); + return; + } + error_free(local_err); + + blockdev_remove_medium(has_device, device, has_id, id, errp); +} + +/* throttling disk I/O limits */ +void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) +{ + ThrottleConfig cfg; + BlockDriverState *bs; + BlockBackend *blk; + AioContext *aio_context; + + blk =3D qmp_get_blk(arg->has_device ? arg->device : NULL, + arg->has_id ? arg->id : NULL, + errp); + if (!blk) { + return; + } + + aio_context =3D blk_get_aio_context(blk); + aio_context_acquire(aio_context); + + bs =3D blk_bs(blk); + if (!bs) { + error_setg(errp, "Device has no medium"); + goto out; + } + + throttle_config_init(&cfg); + cfg.buckets[THROTTLE_BPS_TOTAL].avg =3D arg->bps; + cfg.buckets[THROTTLE_BPS_READ].avg =3D arg->bps_rd; + cfg.buckets[THROTTLE_BPS_WRITE].avg =3D arg->bps_wr; + + cfg.buckets[THROTTLE_OPS_TOTAL].avg =3D arg->iops; + cfg.buckets[THROTTLE_OPS_READ].avg =3D arg->iops_rd; + cfg.buckets[THROTTLE_OPS_WRITE].avg =3D arg->iops_wr; + + if (arg->has_bps_max) { + cfg.buckets[THROTTLE_BPS_TOTAL].max =3D arg->bps_max; + } + if (arg->has_bps_rd_max) { + cfg.buckets[THROTTLE_BPS_READ].max =3D arg->bps_rd_max; + } + if (arg->has_bps_wr_max) { + cfg.buckets[THROTTLE_BPS_WRITE].max =3D arg->bps_wr_max; + } + if (arg->has_iops_max) { + cfg.buckets[THROTTLE_OPS_TOTAL].max =3D arg->iops_max; + } + if (arg->has_iops_rd_max) { + cfg.buckets[THROTTLE_OPS_READ].max =3D arg->iops_rd_max; + } + if (arg->has_iops_wr_max) { + cfg.buckets[THROTTLE_OPS_WRITE].max =3D arg->iops_wr_max; + } + + if (arg->has_bps_max_length) { + cfg.buckets[THROTTLE_BPS_TOTAL].burst_length =3D arg->bps_max_leng= th; + } + if (arg->has_bps_rd_max_length) { + cfg.buckets[THROTTLE_BPS_READ].burst_length =3D arg->bps_rd_max_le= ngth; + } + if (arg->has_bps_wr_max_length) { + cfg.buckets[THROTTLE_BPS_WRITE].burst_length =3D arg->bps_wr_max_l= ength; + } + if (arg->has_iops_max_length) { + cfg.buckets[THROTTLE_OPS_TOTAL].burst_length =3D arg->iops_max_len= gth; + } + if (arg->has_iops_rd_max_length) { + cfg.buckets[THROTTLE_OPS_READ].burst_length =3D arg->iops_rd_max_l= ength; + } + if (arg->has_iops_wr_max_length) { + cfg.buckets[THROTTLE_OPS_WRITE].burst_length =3D arg->iops_wr_max_= length; + } + + if (arg->has_iops_size) { + cfg.op_size =3D arg->iops_size; + } + + if (!throttle_is_valid(&cfg, errp)) { + goto out; + } + + if (throttle_enabled(&cfg)) { + /* Enable I/O limits if they're not enabled yet, otherwise + * just update the throttling group. */ + if (!blk_get_public(blk)->throttle_group_member.throttle_state) { + blk_io_limits_enable(blk, + arg->has_group ? arg->group : + arg->has_device ? arg->device : + arg->id); + } else if (arg->has_group) { + blk_io_limits_update_group(blk, arg->group); + } + /* Set the new throttling configuration */ + blk_set_io_limits(blk, &cfg); + } else if (blk_get_public(blk)->throttle_group_member.throttle_state) { + /* If all throttling settings are set to 0, disable I/O limits */ + blk_io_limits_disable(blk); + } + +out: + aio_context_release(aio_context); +} + +void qmp_block_latency_histogram_set( + const char *id, + bool has_boundaries, uint64List *boundaries, + bool has_boundaries_read, uint64List *boundaries_read, + bool has_boundaries_write, uint64List *boundaries_write, + bool has_boundaries_flush, uint64List *boundaries_flush, + Error **errp) +{ + BlockBackend *blk =3D qmp_get_blk(NULL, id, errp); + BlockAcctStats *stats; + int ret; + + if (!blk) { + return; + } + + stats =3D blk_get_stats(blk); + + if (!has_boundaries && !has_boundaries_read && !has_boundaries_write && + !has_boundaries_flush) + { + block_latency_histograms_clear(stats); + return; + } + + if (has_boundaries || has_boundaries_read) { + ret =3D block_latency_histogram_set( + stats, BLOCK_ACCT_READ, + has_boundaries_read ? boundaries_read : boundaries); + if (ret) { + error_setg(errp, "Device '%s' set read boundaries fail", id); + return; + } + } + + if (has_boundaries || has_boundaries_write) { + ret =3D block_latency_histogram_set( + stats, BLOCK_ACCT_WRITE, + has_boundaries_write ? boundaries_write : boundaries); + if (ret) { + error_setg(errp, "Device '%s' set write boundaries fail", id); + return; + } + } + + if (has_boundaries || has_boundaries_flush) { + ret =3D block_latency_histogram_set( + stats, BLOCK_ACCT_FLUSH, + has_boundaries_flush ? boundaries_flush : boundaries); + if (ret) { + error_setg(errp, "Device '%s' set flush boundaries fail", id); + return; + } + } +} diff --git a/blockdev.c b/blockdev.c index 011dcfec27..3e44fa766b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -67,14 +67,6 @@ static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =3D QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states); =20 -static int do_open_tray(const char *blk_name, const char *qdev_id, - bool force, Error **errp); -static void blockdev_remove_medium(bool has_device, const char *device, - bool has_id, const char *id, Error **er= rp); -static void blockdev_insert_medium(bool has_device, const char *device, - bool has_id, const char *id, - const char *node_name, Error **errp); - static const char *const if_name[IF_COUNT] =3D { [IF_NONE] =3D "none", [IF_IDE] =3D "ide", @@ -1047,29 +1039,6 @@ static BlockDriverState *qmp_get_root_bs(const char = *name, Error **errp) return bs; } =20 -static BlockBackend *qmp_get_blk(const char *blk_name, const char *qdev_id, - Error **errp) -{ - BlockBackend *blk; - - if (!blk_name =3D=3D !qdev_id) { - error_setg(errp, "Need exactly one of 'device' and 'id'"); - return NULL; - } - - if (qdev_id) { - blk =3D blk_by_qdev_id(qdev_id, errp); - } else { - blk =3D blk_by_name(blk_name); - if (blk =3D=3D NULL) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", blk_name); - } - } - - return blk; -} - void hmp_commit(Monitor *mon, const QDict *qdict) { const char *device =3D qdict_get_str(qdict, "device"); @@ -2508,29 +2477,6 @@ exit: job_txn_unref(block_job_txn); } =20 -void qmp_eject(bool has_device, const char *device, - bool has_id, const char *id, - bool has_force, bool force, Error **errp) -{ - Error *local_err =3D NULL; - int rc; - - if (!has_force) { - force =3D false; - } - - rc =3D do_open_tray(has_device ? device : NULL, - has_id ? id : NULL, - force, &local_err); - if (rc && rc !=3D -ENOSYS) { - error_propagate(errp, local_err); - return; - } - error_free(local_err); - - blockdev_remove_medium(has_device, device, has_id, id, errp); -} - void qmp_block_passwd(bool has_device, const char *device, bool has_node_name, const char *node_name, const char *password, Error **errp) @@ -2539,455 +2485,6 @@ void qmp_block_passwd(bool has_device, const char *= device, "Setting block passwords directly is no longer supported"); } =20 -/* - * Attempt to open the tray of @device. - * If @force, ignore its tray lock. - * Else, if the tray is locked, don't open it, but ask the guest to open i= t. - * On error, store an error through @errp and return -errno. - * If @device does not exist, return -ENODEV. - * If it has no removable media, return -ENOTSUP. - * If it has no tray, return -ENOSYS. - * If the guest was asked to open the tray, return -EINPROGRESS. - * Else, return 0. - */ -static int do_open_tray(const char *blk_name, const char *qdev_id, - bool force, Error **errp) -{ - BlockBackend *blk; - const char *device =3D qdev_id ?: blk_name; - bool locked; - - blk =3D qmp_get_blk(blk_name, qdev_id, errp); - if (!blk) { - return -ENODEV; - } - - if (!blk_dev_has_removable_media(blk)) { - error_setg(errp, "Device '%s' is not removable", device); - return -ENOTSUP; - } - - if (!blk_dev_has_tray(blk)) { - error_setg(errp, "Device '%s' does not have a tray", device); - return -ENOSYS; - } - - if (blk_dev_is_tray_open(blk)) { - return 0; - } - - locked =3D blk_dev_is_medium_locked(blk); - if (locked) { - blk_dev_eject_request(blk, force); - } - - if (!locked || force) { - blk_dev_change_media_cb(blk, false, &error_abort); - } - - if (locked && !force) { - error_setg(errp, "Device '%s' is locked and force was not specifie= d, " - "wait for tray to open and try again", device); - return -EINPROGRESS; - } - - return 0; -} - -void qmp_blockdev_open_tray(bool has_device, const char *device, - bool has_id, const char *id, - bool has_force, bool force, - Error **errp) -{ - Error *local_err =3D NULL; - int rc; - - if (!has_force) { - force =3D false; - } - rc =3D do_open_tray(has_device ? device : NULL, - has_id ? id : NULL, - force, &local_err); - if (rc && rc !=3D -ENOSYS && rc !=3D -EINPROGRESS) { - error_propagate(errp, local_err); - return; - } - error_free(local_err); -} - -void qmp_blockdev_close_tray(bool has_device, const char *device, - bool has_id, const char *id, - Error **errp) -{ - BlockBackend *blk; - Error *local_err =3D NULL; - - device =3D has_device ? device : NULL; - id =3D has_id ? id : NULL; - - blk =3D qmp_get_blk(device, id, errp); - if (!blk) { - return; - } - - if (!blk_dev_has_removable_media(blk)) { - error_setg(errp, "Device '%s' is not removable", device ?: id); - return; - } - - if (!blk_dev_has_tray(blk)) { - /* Ignore this command on tray-less devices */ - return; - } - - if (!blk_dev_is_tray_open(blk)) { - return; - } - - blk_dev_change_media_cb(blk, true, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } -} - -static void blockdev_remove_medium(bool has_device, const char *device, - bool has_id, const char *id, Error **er= rp) -{ - BlockBackend *blk; - BlockDriverState *bs; - AioContext *aio_context; - bool has_attached_device; - - device =3D has_device ? device : NULL; - id =3D has_id ? id : NULL; - - blk =3D qmp_get_blk(device, id, errp); - if (!blk) { - return; - } - - /* For BBs without a device, we can exchange the BDS tree at will */ - has_attached_device =3D blk_get_attached_dev(blk); - - if (has_attached_device && !blk_dev_has_removable_media(blk)) { - error_setg(errp, "Device '%s' is not removable", device ?: id); - return; - } - - if (has_attached_device && blk_dev_has_tray(blk) && - !blk_dev_is_tray_open(blk)) - { - error_setg(errp, "Tray of device '%s' is not open", device ?: id); - return; - } - - bs =3D blk_bs(blk); - if (!bs) { - return; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_EJECT, errp)) { - goto out; - } - - blk_remove_bs(blk); - - if (!blk_dev_has_tray(blk)) { - /* For tray-less devices, blockdev-open-tray is a no-op (or may no= t be - * called at all); therefore, the medium needs to be ejected here. - * Do it after blk_remove_bs() so blk_is_inserted(blk) returns the= @load - * value passed here (i.e. false). */ - blk_dev_change_media_cb(blk, false, &error_abort); - } - -out: - aio_context_release(aio_context); -} - -void qmp_blockdev_remove_medium(const char *id, Error **errp) -{ - blockdev_remove_medium(false, NULL, true, id, errp); -} - -static void qmp_blockdev_insert_anon_medium(BlockBackend *blk, - BlockDriverState *bs, Error **= errp) -{ - Error *local_err =3D NULL; - bool has_device; - int ret; - - /* For BBs without a device, we can exchange the BDS tree at will */ - has_device =3D blk_get_attached_dev(blk); - - if (has_device && !blk_dev_has_removable_media(blk)) { - error_setg(errp, "Device is not removable"); - return; - } - - if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk))= { - error_setg(errp, "Tray of the device is not open"); - return; - } - - if (blk_bs(blk)) { - error_setg(errp, "There already is a medium in the device"); - return; - } - - ret =3D blk_insert_bs(blk, bs, errp); - if (ret < 0) { - return; - } - - if (!blk_dev_has_tray(blk)) { - /* For tray-less devices, blockdev-close-tray is a no-op (or may n= ot be - * called at all); therefore, the medium needs to be pushed into t= he - * slot here. - * Do it after blk_insert_bs() so blk_is_inserted(blk) returns the= @load - * value passed here (i.e. true). */ - blk_dev_change_media_cb(blk, true, &local_err); - if (local_err) { - error_propagate(errp, local_err); - blk_remove_bs(blk); - return; - } - } -} - -static void blockdev_insert_medium(bool has_device, const char *device, - bool has_id, const char *id, - const char *node_name, Error **errp) -{ - BlockBackend *blk; - BlockDriverState *bs; - - blk =3D qmp_get_blk(has_device ? device : NULL, - has_id ? id : NULL, - errp); - if (!blk) { - return; - } - - bs =3D bdrv_find_node(node_name); - if (!bs) { - error_setg(errp, "Node '%s' not found", node_name); - return; - } - - if (bdrv_has_blk(bs)) { - error_setg(errp, "Node '%s' is already in use", node_name); - return; - } - - qmp_blockdev_insert_anon_medium(blk, bs, errp); -} - -void qmp_blockdev_insert_medium(const char *id, const char *node_name, - Error **errp) -{ - blockdev_insert_medium(false, NULL, true, id, node_name, errp); -} - -void qmp_blockdev_change_medium(bool has_device, const char *device, - bool has_id, const char *id, - const char *filename, - bool has_format, const char *format, - bool has_read_only, - BlockdevChangeReadOnlyMode read_only, - Error **errp) -{ - BlockBackend *blk; - BlockDriverState *medium_bs =3D NULL; - int bdrv_flags; - bool detect_zeroes; - int rc; - QDict *options =3D NULL; - Error *err =3D NULL; - - blk =3D qmp_get_blk(has_device ? device : NULL, - has_id ? id : NULL, - errp); - if (!blk) { - goto fail; - } - - if (blk_bs(blk)) { - blk_update_root_state(blk); - } - - bdrv_flags =3D blk_get_open_flags_from_root_state(blk); - bdrv_flags &=3D ~(BDRV_O_TEMPORARY | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKI= NG | - BDRV_O_PROTOCOL | BDRV_O_AUTO_RDONLY); - - if (!has_read_only) { - read_only =3D BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN; - } - - switch (read_only) { - case BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN: - break; - - case BLOCKDEV_CHANGE_READ_ONLY_MODE_READ_ONLY: - bdrv_flags &=3D ~BDRV_O_RDWR; - break; - - case BLOCKDEV_CHANGE_READ_ONLY_MODE_READ_WRITE: - bdrv_flags |=3D BDRV_O_RDWR; - break; - - default: - abort(); - } - - options =3D qdict_new(); - detect_zeroes =3D blk_get_detect_zeroes_from_root_state(blk); - qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off"); - - if (has_format) { - qdict_put_str(options, "driver", format); - } - - medium_bs =3D bdrv_open(filename, NULL, options, bdrv_flags, errp); - if (!medium_bs) { - goto fail; - } - - rc =3D do_open_tray(has_device ? device : NULL, - has_id ? id : NULL, - false, &err); - if (rc && rc !=3D -ENOSYS) { - error_propagate(errp, err); - goto fail; - } - error_free(err); - err =3D NULL; - - blockdev_remove_medium(has_device, device, has_id, id, &err); - if (err) { - error_propagate(errp, err); - goto fail; - } - - qmp_blockdev_insert_anon_medium(blk, medium_bs, &err); - if (err) { - error_propagate(errp, err); - goto fail; - } - - qmp_blockdev_close_tray(has_device, device, has_id, id, errp); - -fail: - /* If the medium has been inserted, the device has its own reference, = so - * ours must be relinquished; and if it has not been inserted successf= ully, - * the reference must be relinquished anyway */ - bdrv_unref(medium_bs); -} - -/* throttling disk I/O limits */ -void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) -{ - ThrottleConfig cfg; - BlockDriverState *bs; - BlockBackend *blk; - AioContext *aio_context; - - blk =3D qmp_get_blk(arg->has_device ? arg->device : NULL, - arg->has_id ? arg->id : NULL, - errp); - if (!blk) { - return; - } - - aio_context =3D blk_get_aio_context(blk); - aio_context_acquire(aio_context); - - bs =3D blk_bs(blk); - if (!bs) { - error_setg(errp, "Device has no medium"); - goto out; - } - - throttle_config_init(&cfg); - cfg.buckets[THROTTLE_BPS_TOTAL].avg =3D arg->bps; - cfg.buckets[THROTTLE_BPS_READ].avg =3D arg->bps_rd; - cfg.buckets[THROTTLE_BPS_WRITE].avg =3D arg->bps_wr; - - cfg.buckets[THROTTLE_OPS_TOTAL].avg =3D arg->iops; - cfg.buckets[THROTTLE_OPS_READ].avg =3D arg->iops_rd; - cfg.buckets[THROTTLE_OPS_WRITE].avg =3D arg->iops_wr; - - if (arg->has_bps_max) { - cfg.buckets[THROTTLE_BPS_TOTAL].max =3D arg->bps_max; - } - if (arg->has_bps_rd_max) { - cfg.buckets[THROTTLE_BPS_READ].max =3D arg->bps_rd_max; - } - if (arg->has_bps_wr_max) { - cfg.buckets[THROTTLE_BPS_WRITE].max =3D arg->bps_wr_max; - } - if (arg->has_iops_max) { - cfg.buckets[THROTTLE_OPS_TOTAL].max =3D arg->iops_max; - } - if (arg->has_iops_rd_max) { - cfg.buckets[THROTTLE_OPS_READ].max =3D arg->iops_rd_max; - } - if (arg->has_iops_wr_max) { - cfg.buckets[THROTTLE_OPS_WRITE].max =3D arg->iops_wr_max; - } - - if (arg->has_bps_max_length) { - cfg.buckets[THROTTLE_BPS_TOTAL].burst_length =3D arg->bps_max_leng= th; - } - if (arg->has_bps_rd_max_length) { - cfg.buckets[THROTTLE_BPS_READ].burst_length =3D arg->bps_rd_max_le= ngth; - } - if (arg->has_bps_wr_max_length) { - cfg.buckets[THROTTLE_BPS_WRITE].burst_length =3D arg->bps_wr_max_l= ength; - } - if (arg->has_iops_max_length) { - cfg.buckets[THROTTLE_OPS_TOTAL].burst_length =3D arg->iops_max_len= gth; - } - if (arg->has_iops_rd_max_length) { - cfg.buckets[THROTTLE_OPS_READ].burst_length =3D arg->iops_rd_max_l= ength; - } - if (arg->has_iops_wr_max_length) { - cfg.buckets[THROTTLE_OPS_WRITE].burst_length =3D arg->iops_wr_max_= length; - } - - if (arg->has_iops_size) { - cfg.op_size =3D arg->iops_size; - } - - if (!throttle_is_valid(&cfg, errp)) { - goto out; - } - - if (throttle_enabled(&cfg)) { - /* Enable I/O limits if they're not enabled yet, otherwise - * just update the throttling group. */ - if (!blk_get_public(blk)->throttle_group_member.throttle_state) { - blk_io_limits_enable(blk, - arg->has_group ? arg->group : - arg->has_device ? arg->device : - arg->id); - } else if (arg->has_group) { - blk_io_limits_update_group(blk, arg->group); - } - /* Set the new throttling configuration */ - blk_set_io_limits(blk, &cfg); - } else if (blk_get_public(blk)->throttle_group_member.throttle_state) { - /* If all throttling settings are set to 0, disable I/O limits */ - blk_io_limits_disable(blk); - } - -out: - aio_context_release(aio_context); -} - void qmp_block_dirty_bitmap_add(const char *node, const char *name, bool has_granularity, uint32_t granularity, bool has_persistent, bool persistent, @@ -4595,62 +4092,6 @@ void qmp_x_blockdev_set_iothread(const char *node_na= me, StrOrNull *iothread, aio_context_release(old_context); } =20 -void qmp_block_latency_histogram_set( - const char *id, - bool has_boundaries, uint64List *boundaries, - bool has_boundaries_read, uint64List *boundaries_read, - bool has_boundaries_write, uint64List *boundaries_write, - bool has_boundaries_flush, uint64List *boundaries_flush, - Error **errp) -{ - BlockBackend *blk =3D qmp_get_blk(NULL, id, errp); - BlockAcctStats *stats; - int ret; - - if (!blk) { - return; - } - - stats =3D blk_get_stats(blk); - - if (!has_boundaries && !has_boundaries_read && !has_boundaries_write && - !has_boundaries_flush) - { - block_latency_histograms_clear(stats); - return; - } - - if (has_boundaries || has_boundaries_read) { - ret =3D block_latency_histogram_set( - stats, BLOCK_ACCT_READ, - has_boundaries_read ? boundaries_read : boundaries); - if (ret) { - error_setg(errp, "Device '%s' set read boundaries fail", id); - return; - } - } - - if (has_boundaries || has_boundaries_write) { - ret =3D block_latency_histogram_set( - stats, BLOCK_ACCT_WRITE, - has_boundaries_write ? boundaries_write : boundaries); - if (ret) { - error_setg(errp, "Device '%s' set write boundaries fail", id); - return; - } - } - - if (has_boundaries || has_boundaries_flush) { - ret =3D block_latency_histogram_set( - stats, BLOCK_ACCT_FLUSH, - has_boundaries_flush ? boundaries_flush : boundaries); - if (ret) { - error_setg(errp, "Device '%s' set flush boundaries fail", id); - return; - } - } -} - QemuOptsList qemu_common_drive_opts =3D { .name =3D "drive", .head =3D QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head), diff --git a/block/Makefile.objs b/block/Makefile.objs index 3bcb35c81d..e06cf0b284 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -48,6 +48,8 @@ block-obj-y +=3D filter-compress.o =20 common-obj-y +=3D stream.o =20 +common-obj-y +=3D qapi-sysemu.o + nfs.o-libs :=3D $(LIBNFS_LIBS) iscsi.o-cflags :=3D $(LIBISCSI_CFLAGS) iscsi.o-libs :=3D $(LIBISCSI_LIBS) --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582554762; cv=none; d=zohomail.com; s=zohoarc; b=IIwCM2pEhsb1+eSPWiS6Nv9W6ifBzvfNZzxNdYh8Gw3rMN0VYaIRQzPho+opDgdRMhZKLE4GM5QzCOU8nATftdOG5ICbFf3tTp0Ih6lQscceVEopuyUjdkExFimANWnawUIQjIFTcsPRRc9KkIuGwHAG2N9N/03qPZh4yxzbtxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554762; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DZb7DzcEPlo+cSGpzzAtAdjk9yzIV1UddE1y7k/F160=; b=na4ttkkXY75iY9rZF+0R1Du3O+HSQFE8jKiiagG/LHkCzLvknlUh24qPlvCWk5pd0G2BRnA35zKPRofMUIwKTzOzLdn7DFFV9bBX4tldis4GibpSKJ/OHW+IU+mrQYwW1HPsbWNinSj9PoraWWA7FPpzoMBdUl2UiLxCwF9y1Cw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582554762273626.3507760992902; Mon, 24 Feb 2020 06:32:42 -0800 (PST) Received: from localhost ([::1]:37322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Emm-0003gn-8z for importer@patchew.org; Mon, 24 Feb 2020 09:32:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50618) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Eks-0001bg-Gz for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Ekp-000206-RS for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:42 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:40259 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Ekp-0001yj-If for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:39 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-430-fjfJGFpNOamGSMSFnLlSEQ-1; Mon, 24 Feb 2020 09:30:36 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA21218AB2C0; Mon, 24 Feb 2020 14:30:35 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BAA75C114; Mon, 24 Feb 2020 14:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DZb7DzcEPlo+cSGpzzAtAdjk9yzIV1UddE1y7k/F160=; b=S4+kH079Z8McvmdKFNfHBsskS9a47VQ3NDECD6cC3d/mrVmjVha1ktYs0yhNvyyj1d/dAo daedgeWdl8QHqfYmKHZFLdlLURr3bn0BF5AzAZhuRwuyzrxX3N/ugbxMSwWIKrOWXc+iKS 7qn+u/Zbp0Xa9hGLcXas2vKxMiCx8Hc= X-MC-Unique: fjfJGFpNOamGSMSFnLlSEQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 04/20] block: Move common QMP commands to block-core QAPI module Date: Mon, 24 Feb 2020 15:29:52 +0100 Message-Id: <20200224143008.13362-5-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" block-core is for everything that isn't related to the system emulator. Internal snapshots, the NBD server and quorum events make sense in the tools, too, so move them to block-core. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/block-core.json | 283 ++++++++++++++++++++++++++++++++++++++++++ qapi/block.json | 284 ------------------------------------------- 2 files changed, 283 insertions(+), 284 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 85e27bb61f..60860ead68 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5447,3 +5447,286 @@ 'data' : { 'node-name': 'str', 'iothread': 'StrOrNull', '*force': 'bool' } } + +## +# @nbd-server-start: +# +# Start an NBD server listening on the given host and port. Block +# devices can then be exported using @nbd-server-add. The NBD +# server will present them as named exports; for example, another +# QEMU instance could refer to them as "nbd:HOST:PORT:exportname=3DNAME". +# +# @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). +# +# Returns: error if the server is already running. +# +# Since: 1.3.0 +## +{ 'command': 'nbd-server-start', + 'data': { 'addr': 'SocketAddressLegacy', + '*tls-creds': 'str', + '*tls-authz': 'str'} } + +## +# @nbd-server-add: +# +# Export a block node to QEMU's embedded NBD server. +# +# @device: The device name or node name of the node to be exported +# +# @name: Export name. If unspecified, the @device parameter is used as the +# export name. (Since 2.12) +# +# @description: Free-form description of the export, up to 4096 bytes. +# (Since 5.0) +# +# @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) +# +# 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', '*description': 'str', + '*writable': 'bool', '*bitmap': 'str' } } + +## +# @NbdServerRemoveMode: +# +# Mode for removing an NBD export. +# +# @safe: Remove export if there are no existing connections, fail otherwis= e. +# +# @hard: Drop all connections immediately and remove export. +# +# Potential additional modes to be added in the future: +# +# hide: Just hide export from new clients, leave existing connections as i= s. +# Remove export after all clients are disconnected. +# +# soft: Hide export from new clients, answer with ESHUTDOWN for all further +# requests from existing clients. +# +# Since: 2.12 +## +{'enum': 'NbdServerRemoveMode', 'data': ['safe', 'hard']} + +## +# @nbd-server-remove: +# +# Remove NBD export by name. +# +# @name: Export name. +# +# @mode: Mode of command operation. See @NbdServerRemoveMode description. +# Default is 'safe'. +# +# Returns: error if +# - the server is not running +# - export is not found +# - mode is 'safe' and there are existing connections +# +# Since: 2.12 +## +{ 'command': 'nbd-server-remove', + 'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} } + +## +# @nbd-server-stop: +# +# Stop QEMU's embedded NBD server, and unregister all devices previously +# added via @nbd-server-add. +# +# Since: 1.3.0 +## +{ 'command': 'nbd-server-stop' } + +## +# @QuorumOpType: +# +# An enumeration of the quorum operation types +# +# @read: read operation +# +# @write: write operation +# +# @flush: flush operation +# +# Since: 2.6 +## +{ 'enum': 'QuorumOpType', + 'data': [ 'read', 'write', 'flush' ] } + +## +# @QUORUM_FAILURE: +# +# Emitted by the Quorum block driver if it fails to establish a quorum +# +# @reference: device name if defined else node name +# +# @sector-num: number of the first sector of the failed read operation +# +# @sectors-count: failed read operation sector count +# +# Note: This event is rate-limited. +# +# Since: 2.0 +# +# Example: +# +# <- { "event": "QUORUM_FAILURE", +# "data": { "reference": "usr1", "sector-num": 345435, "sectors-count= ": 5 }, +# "timestamp": { "seconds": 1344522075, "microseconds": 745528 } } +# +## +{ 'event': 'QUORUM_FAILURE', + 'data': { 'reference': 'str', 'sector-num': 'int', 'sectors-count': 'int= ' } } + +## +# @QUORUM_REPORT_BAD: +# +# Emitted to report a corruption of a Quorum file +# +# @type: quorum operation type (Since 2.6) +# +# @error: error message. Only present on failure. This field +# contains a human-readable error message. There are no semantics = other +# than that the block layer reported an error and clients should n= ot +# try to interpret the error string. +# +# @node-name: the graph node name of the block driver state +# +# @sector-num: number of the first sector of the failed read operation +# +# @sectors-count: failed read operation sector count +# +# Note: This event is rate-limited. +# +# Since: 2.0 +# +# Example: +# +# 1. Read operation +# +# { "event": "QUORUM_REPORT_BAD", +# "data": { "node-name": "node0", "sector-num": 345435, "sectors-coun= t": 5, +# "type": "read" }, +# "timestamp": { "seconds": 1344522075, "microseconds": 745528 } } +# +# 2. Flush operation +# +# { "event": "QUORUM_REPORT_BAD", +# "data": { "node-name": "node0", "sector-num": 0, "sectors-count": 2= 097120, +# "type": "flush", "error": "Broken pipe" }, +# "timestamp": { "seconds": 1456406829, "microseconds": 291763 } } +# +## +{ 'event': 'QUORUM_REPORT_BAD', + 'data': { 'type': 'QuorumOpType', '*error': 'str', 'node-name': 'str', + 'sector-num': 'int', 'sectors-count': 'int' } } + +## +# @BlockdevSnapshotInternal: +# +# @device: the device name or node-name of a root node to generate the sna= pshot +# from +# +# @name: the name of the internal snapshot to be created +# +# Notes: In transaction, if @name is empty, or any snapshot matching @name +# exists, the operation will fail. Only some image formats support = it, +# for example, qcow2, rbd, and sheepdog. +# +# Since: 1.7 +## +{ 'struct': 'BlockdevSnapshotInternal', + 'data': { 'device': 'str', 'name': 'str' } } + +## +# @blockdev-snapshot-internal-sync: +# +# Synchronously take an internal snapshot of a block device, when the +# format of the image used supports it. If the name is an empty +# string, or a snapshot with name already exists, the operation will +# fail. +# +# For the arguments, see the documentation of BlockdevSnapshotInternal. +# +# Returns: - nothing on success +# - If @device is not a valid block device, GenericError +# - If any snapshot matching @name exists, or @name is empty, +# GenericError +# - If the format of the image used does not support it, +# BlockFormatFeatureNotSupported +# +# Since: 1.7 +# +# Example: +# +# -> { "execute": "blockdev-snapshot-internal-sync", +# "arguments": { "device": "ide-hd0", +# "name": "snapshot0" } +# } +# <- { "return": {} } +# +## +{ 'command': 'blockdev-snapshot-internal-sync', + 'data': 'BlockdevSnapshotInternal' } + +## +# @blockdev-snapshot-delete-internal-sync: +# +# Synchronously delete an internal snapshot of a block device, when the fo= rmat +# of the image used support it. The snapshot is identified by name or id or +# both. One of the name or id is required. Return SnapshotInfo for the +# successfully deleted snapshot. +# +# @device: the device name or node-name of a root node to delete the snaps= hot +# from +# +# @id: optional the snapshot's ID to be deleted +# +# @name: optional the snapshot's name to be deleted +# +# Returns: - SnapshotInfo on success +# - If @device is not a valid block device, GenericError +# - If snapshot not found, GenericError +# - If the format of the image used does not support it, +# BlockFormatFeatureNotSupported +# - If @id and @name are both not specified, GenericError +# +# Since: 1.7 +# +# Example: +# +# -> { "execute": "blockdev-snapshot-delete-internal-sync", +# "arguments": { "device": "ide-hd0", +# "name": "snapshot0" } +# } +# <- { "return": { +# "id": "1", +# "name": "snapshot0", +# "vm-state-size": 0, +# "date-sec": 1000012, +# "date-nsec": 10, +# "vm-clock-sec": 100, +# "vm-clock-nsec": 20 +# } +# } +# +## +{ 'command': 'blockdev-snapshot-delete-internal-sync', + 'data': { 'device': 'str', '*id': 'str', '*name': 'str'}, + 'returns': 'SnapshotInfo' } diff --git a/qapi/block.json b/qapi/block.json index da19834db4..d2f3fc01ed 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -60,23 +60,6 @@ { 'enum': 'FloppyDriveType', 'data': ['144', '288', '120', 'none', 'auto']} =20 -## -# @BlockdevSnapshotInternal: -# -# @device: the device name or node-name of a root node to generate the sna= pshot -# from -# -# @name: the name of the internal snapshot to be created -# -# Notes: In transaction, if @name is empty, or any snapshot matching @name -# exists, the operation will fail. Only some image formats support = it, -# for example, qcow2, rbd, and sheepdog. -# -# Since: 1.7 -## -{ 'struct': 'BlockdevSnapshotInternal', - 'data': { 'device': 'str', 'name': 'str' } } - ## # @PRManagerInfo: # @@ -104,84 +87,6 @@ { 'command': 'query-pr-managers', 'returns': ['PRManagerInfo'], 'allow-preconfig': true } =20 - -## -# @blockdev-snapshot-internal-sync: -# -# Synchronously take an internal snapshot of a block device, when the -# format of the image used supports it. If the name is an empty -# string, or a snapshot with name already exists, the operation will -# fail. -# -# For the arguments, see the documentation of BlockdevSnapshotInternal. -# -# Returns: - nothing on success -# - If @device is not a valid block device, GenericError -# - If any snapshot matching @name exists, or @name is empty, -# GenericError -# - If the format of the image used does not support it, -# BlockFormatFeatureNotSupported -# -# Since: 1.7 -# -# Example: -# -# -> { "execute": "blockdev-snapshot-internal-sync", -# "arguments": { "device": "ide-hd0", -# "name": "snapshot0" } -# } -# <- { "return": {} } -# -## -{ 'command': 'blockdev-snapshot-internal-sync', - 'data': 'BlockdevSnapshotInternal' } - -## -# @blockdev-snapshot-delete-internal-sync: -# -# Synchronously delete an internal snapshot of a block device, when the fo= rmat -# of the image used support it. The snapshot is identified by name or id or -# both. One of the name or id is required. Return SnapshotInfo for the -# successfully deleted snapshot. -# -# @device: the device name or node-name of a root node to delete the snaps= hot -# from -# -# @id: optional the snapshot's ID to be deleted -# -# @name: optional the snapshot's name to be deleted -# -# Returns: - SnapshotInfo on success -# - If @device is not a valid block device, GenericError -# - If snapshot not found, GenericError -# - If the format of the image used does not support it, -# BlockFormatFeatureNotSupported -# - If @id and @name are both not specified, GenericError -# -# Since: 1.7 -# -# Example: -# -# -> { "execute": "blockdev-snapshot-delete-internal-sync", -# "arguments": { "device": "ide-hd0", -# "name": "snapshot0" } -# } -# <- { "return": { -# "id": "1", -# "name": "snapshot0", -# "vm-state-size": 0, -# "date-sec": 1000012, -# "date-nsec": 10, -# "vm-clock-sec": 100, -# "vm-clock-nsec": 20 -# } -# } -# -## -{ 'command': 'blockdev-snapshot-delete-internal-sync', - 'data': { 'device': 'str', '*id': 'str', '*name': 'str'}, - 'returns': 'SnapshotInfo' } - ## # @eject: # @@ -210,111 +115,6 @@ '*id': 'str', '*force': 'bool' } } =20 -## -# @nbd-server-start: -# -# Start an NBD server listening on the given host and port. Block -# devices can then be exported using @nbd-server-add. The NBD -# server will present them as named exports; for example, another -# QEMU instance could refer to them as "nbd:HOST:PORT:exportname=3DNAME". -# -# @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). -# -# Returns: error if the server is already running. -# -# Since: 1.3.0 -## -{ 'command': 'nbd-server-start', - 'data': { 'addr': 'SocketAddressLegacy', - '*tls-creds': 'str', - '*tls-authz': 'str'} } - -## -# @nbd-server-add: -# -# Export a block node to QEMU's embedded NBD server. -# -# @device: The device name or node name of the node to be exported -# -# @name: Export name. If unspecified, the @device parameter is used as the -# export name. (Since 2.12) -# -# @description: Free-form description of the export, up to 4096 bytes. -# (Since 5.0) -# -# @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) -# -# 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', '*description': 'str', - '*writable': 'bool', '*bitmap': 'str' } } - -## -# @NbdServerRemoveMode: -# -# Mode for removing an NBD export. -# -# @safe: Remove export if there are no existing connections, fail otherwis= e. -# -# @hard: Drop all connections immediately and remove export. -# -# Potential additional modes to be added in the future: -# -# hide: Just hide export from new clients, leave existing connections as i= s. -# Remove export after all clients are disconnected. -# -# soft: Hide export from new clients, answer with ESHUTDOWN for all further -# requests from existing clients. -# -# Since: 2.12 -## -{'enum': 'NbdServerRemoveMode', 'data': ['safe', 'hard']} - -## -# @nbd-server-remove: -# -# Remove NBD export by name. -# -# @name: Export name. -# -# @mode: Mode of command operation. See @NbdServerRemoveMode description. -# Default is 'safe'. -# -# Returns: error if -# - the server is not running -# - export is not found -# - mode is 'safe' and there are existing connections -# -# Since: 2.12 -## -{ 'command': 'nbd-server-remove', - 'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} } - -## -# @nbd-server-stop: -# -# Stop QEMU's embedded NBD server, and unregister all devices previously -# added via @nbd-server-add. -# -# Since: 1.3.0 -## -{ 'command': 'nbd-server-stop' } - ## # @DEVICE_TRAY_MOVED: # @@ -367,87 +167,3 @@ ## { 'event': 'PR_MANAGER_STATUS_CHANGED', 'data': { 'id': 'str', 'connected': 'bool' } } - -## -# @QuorumOpType: -# -# An enumeration of the quorum operation types -# -# @read: read operation -# -# @write: write operation -# -# @flush: flush operation -# -# Since: 2.6 -## -{ 'enum': 'QuorumOpType', - 'data': [ 'read', 'write', 'flush' ] } - -## -# @QUORUM_FAILURE: -# -# Emitted by the Quorum block driver if it fails to establish a quorum -# -# @reference: device name if defined else node name -# -# @sector-num: number of the first sector of the failed read operation -# -# @sectors-count: failed read operation sector count -# -# Note: This event is rate-limited. -# -# Since: 2.0 -# -# Example: -# -# <- { "event": "QUORUM_FAILURE", -# "data": { "reference": "usr1", "sector-num": 345435, "sectors-count= ": 5 }, -# "timestamp": { "seconds": 1344522075, "microseconds": 745528 } } -# -## -{ 'event': 'QUORUM_FAILURE', - 'data': { 'reference': 'str', 'sector-num': 'int', 'sectors-count': 'int= ' } } - -## -# @QUORUM_REPORT_BAD: -# -# Emitted to report a corruption of a Quorum file -# -# @type: quorum operation type (Since 2.6) -# -# @error: error message. Only present on failure. This field -# contains a human-readable error message. There are no semantics = other -# than that the block layer reported an error and clients should n= ot -# try to interpret the error string. -# -# @node-name: the graph node name of the block driver state -# -# @sector-num: number of the first sector of the failed read operation -# -# @sectors-count: failed read operation sector count -# -# Note: This event is rate-limited. -# -# Since: 2.0 -# -# Example: -# -# 1. Read operation -# -# { "event": "QUORUM_REPORT_BAD", -# "data": { "node-name": "node0", "sector-num": 345435, "sectors-coun= t": 5, -# "type": "read" }, -# "timestamp": { "seconds": 1344522075, "microseconds": 745528 } } -# -# 2. Flush operation -# -# { "event": "QUORUM_REPORT_BAD", -# "data": { "node-name": "node0", "sector-num": 0, "sectors-count": 2= 097120, -# "type": "flush", "error": "Broken pipe" }, -# "timestamp": { "seconds": 1456406829, "microseconds": 291763 } } -# -## -{ 'event': 'QUORUM_REPORT_BAD', - 'data': { 'type': 'QuorumOpType', '*error': 'str', 'node-name': 'str', - 'sector-num': 'int', 'sectors-count': 'int' } } --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555007; cv=none; d=zohomail.com; s=zohoarc; b=QI4TYk5DReDIJJpyNPow1B/Nmw7RU3ClZnIdrhlS6K4lum2xpxKYBSY6+jJAQhHF+Jv/+PmVD+zMf7Th4Miny2NmvU4+z+O8NQp/1OK9SAzLBCcSnClrMRFplbhfcbe6aUSdiQAhb3AaJfV827Hz3JguGrHVE3z+LRev3w/FdnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555007; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KXLVhq5Xg08Qy3jEwPHWctWezpnHnL5PBF/hm3AuZpc=; b=myRG76dAJ9KB741vXnW6EkFGAxthcEb4W5TSOAz2VRe55PaSzXJXtqMrtL9PzI7vbktepqJ9Ln+C455gXV/FuhWBzfmNigMNBVsWtmymVzF3eMtGnugOaDCr7qjqKRfZWkXLzalzjmGbLTixal9mPfN+WvT/E9aAyqLv8iIcS6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555007671436.3981674542945; Mon, 24 Feb 2020 06:36:47 -0800 (PST) Received: from localhost ([::1]:37418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Eqk-0003Zr-FC for importer@patchew.org; Mon, 24 Feb 2020 09:36:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50679) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Eky-0001hm-E3 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Eku-00026o-OS for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:48 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:31335 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Ekt-00025h-T6 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:44 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-WwI8bmR3OwOk3BSdXwC3Sg-1; Mon, 24 Feb 2020 09:30:39 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 361832EEB; Mon, 24 Feb 2020 14:30:38 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31A5390F5B; Mon, 24 Feb 2020 14:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KXLVhq5Xg08Qy3jEwPHWctWezpnHnL5PBF/hm3AuZpc=; b=TXKslegyw4l0zMjdP7wUBPrMuSCB1oeyA24PqUWDYxBU1tIzP72yMn+y+ovgMHMIEAM4Bb 9nEWplIA9qqeVWDqJUcuiUzXz6du0DfcvK+de/UsRA+l4/ujDs8sHhMtRq9FY6wnm65yYY 3jfqU10Jpv0HKU/VvtXeMiUVWr0ag5I= X-MC-Unique: WwI8bmR3OwOk3BSdXwC3Sg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 05/20] block: Move sysemu QMP commands to QAPI block module Date: Mon, 24 Feb 2020 15:29:53 +0100 Message-Id: <20200224143008.13362-6-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" QMP commands that are related to the system emulator and don't make sense in the context of tools such as qemu-storage-daemon should live in qapi/block.json rather than qapi/block-core.json. Move them there. The associated data types are actually also used in code shared with the tools, so they stay in block-core.json. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/block-core.json | 386 ------------------------------------------- qapi/block.json | 386 +++++++++++++++++++++++++++++++++++++++++++ monitor/qmp-cmds.c | 2 +- 3 files changed, 387 insertions(+), 387 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 60860ead68..b65b6a9f49 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -563,78 +563,6 @@ { 'struct': 'BlockLatencyHistogramInfo', 'data': {'boundaries': ['uint64'], 'bins': ['uint64'] } } =20 -## -# @block-latency-histogram-set: -# -# Manage read, write and flush latency histograms for the device. -# -# If only @id parameter is specified, remove all present latency histograms -# for the device. Otherwise, add/reset some of (or all) latency histograms. -# -# @id: The name or QOM path of the guest device. -# -# @boundaries: list of interval boundary values (see description in -# BlockLatencyHistogramInfo definition). If specified, all -# latency histograms are removed, and empty ones created for = all -# io types with intervals corresponding to @boundaries (excep= t for -# io types, for which specific boundaries are set through the -# following parameters). -# -# @boundaries-read: list of interval boundary values for read latency -# histogram. If specified, old read latency histogram is -# removed, and empty one created with intervals -# corresponding to @boundaries-read. The parameter has h= igher -# priority then @boundaries. -# -# @boundaries-write: list of interval boundary values for write latency -# histogram. -# -# @boundaries-flush: list of interval boundary values for flush latency -# histogram. -# -# Returns: error if device is not found or any boundary arrays are invalid. -# -# Since: 4.0 -# -# Example: set new histograms for all io types with intervals -# [0, 10), [10, 50), [50, 100), [100, +inf): -# -# -> { "execute": "block-latency-histogram-set", -# "arguments": { "id": "drive0", -# "boundaries": [10, 50, 100] } } -# <- { "return": {} } -# -# Example: set new histogram only for write, other histograms will remain -# not changed (or not created): -# -# -> { "execute": "block-latency-histogram-set", -# "arguments": { "id": "drive0", -# "boundaries-write": [10, 50, 100] } } -# <- { "return": {} } -# -# Example: set new histograms with the following intervals: -# read, flush: [0, 10), [10, 50), [50, 100), [100, +inf) -# write: [0, 1000), [1000, 5000), [5000, +inf) -# -# -> { "execute": "block-latency-histogram-set", -# "arguments": { "id": "drive0", -# "boundaries": [10, 50, 100], -# "boundaries-write": [1000, 5000] } } -# <- { "return": {} } -# -# Example: remove all latency histograms: -# -# -> { "execute": "block-latency-histogram-set", -# "arguments": { "id": "drive0" } } -# <- { "return": {} } -## -{ 'command': 'block-latency-histogram-set', - 'data': {'id': 'str', - '*boundaries': ['uint64'], - '*boundaries-read': ['uint64'], - '*boundaries-write': ['uint64'], - '*boundaries-flush': ['uint64'] } } - ## # @BlockInfo: # @@ -2356,78 +2284,6 @@ '*copy-mode': 'MirrorCopyMode', '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } } =20 -## -# @block_set_io_throttle: -# -# Change I/O throttle limits for a block drive. -# -# Since QEMU 2.4, each device with I/O limits is member of a throttle -# group. -# -# If two or more devices are members of the same group, the limits -# will apply to the combined I/O of the whole group in a round-robin -# fashion. Therefore, setting new I/O limits to a device will affect -# the whole group. -# -# The name of the group can be specified using the 'group' parameter. -# If the parameter is unset, it is assumed to be the current group of -# that device. If it's not in any group yet, the name of the device -# will be used as the name for its group. -# -# The 'group' parameter can also be used to move a device to a -# different group. In this case the limits specified in the parameters -# will be applied to the new group only. -# -# I/O limits can be disabled by setting all of them to 0. In this case -# the device will be removed from its group and the rest of its -# members will not be affected. The 'group' parameter is ignored. -# -# Returns: - Nothing on success -# - If @device is not a valid block device, DeviceNotFound -# -# Since: 1.1 -# -# Example: -# -# -> { "execute": "block_set_io_throttle", -# "arguments": { "id": "virtio-blk-pci0/virtio-backend", -# "bps": 0, -# "bps_rd": 0, -# "bps_wr": 0, -# "iops": 512, -# "iops_rd": 0, -# "iops_wr": 0, -# "bps_max": 0, -# "bps_rd_max": 0, -# "bps_wr_max": 0, -# "iops_max": 0, -# "iops_rd_max": 0, -# "iops_wr_max": 0, -# "bps_max_length": 0, -# "iops_size": 0 } } -# <- { "return": {} } -# -# -> { "execute": "block_set_io_throttle", -# "arguments": { "id": "ide0-1-0", -# "bps": 1000000, -# "bps_rd": 0, -# "bps_wr": 0, -# "iops": 0, -# "iops_rd": 0, -# "iops_wr": 0, -# "bps_max": 8000000, -# "bps_rd_max": 0, -# "bps_wr_max": 0, -# "iops_max": 0, -# "iops_rd_max": 0, -# "iops_wr_max": 0, -# "bps_max_length": 60, -# "iops_size": 0 } } -# <- { "return": {} } -## -{ 'command': 'block_set_io_throttle', 'boxed': true, - 'data': 'BlockIOThrottle' } - ## # @BlockIOThrottle: # @@ -4757,248 +4613,6 @@ 'data': { 'job-id': 'str', 'options': 'BlockdevCreateOptions' } } =20 -## -# @blockdev-open-tray: -# -# Opens a block device's tray. If there is a block driver state tree inser= ted as -# a medium, it will become inaccessible to the guest (but it will remain -# associated to the block device, so closing the tray will make it accessi= ble -# again). -# -# If the tray was already open before, this will be a no-op. -# -# Once the tray opens, a DEVICE_TRAY_MOVED event is emitted. There are cas= es in -# which no such event will be generated, these include: -# -# - if the guest has locked the tray, @force is false and the guest does n= ot -# respond to the eject request -# - if the BlockBackend denoted by @device does not have a guest device at= tached -# to it -# - if the guest device does not have an actual tray -# -# @device: Block device name (deprecated, use @id instead) -# -# @id: The name or QOM path of the guest device (since: 2.8) -# -# @force: if false (the default), an eject request will be sent to -# the guest if it has locked the tray (and the tray will not be op= ened -# immediately); if true, the tray will be opened regardless of whe= ther -# it is locked -# -# Since: 2.5 -# -# Example: -# -# -> { "execute": "blockdev-open-tray", -# "arguments": { "id": "ide0-1-0" } } -# -# <- { "timestamp": { "seconds": 1418751016, -# "microseconds": 716996 }, -# "event": "DEVICE_TRAY_MOVED", -# "data": { "device": "ide1-cd0", -# "id": "ide0-1-0", -# "tray-open": true } } -# -# <- { "return": {} } -# -## -{ 'command': 'blockdev-open-tray', - 'data': { '*device': 'str', - '*id': 'str', - '*force': 'bool' } } - -## -# @blockdev-close-tray: -# -# Closes a block device's tray. If there is a block driver state tree asso= ciated -# with the block device (which is currently ejected), that tree will be lo= aded -# as the medium. -# -# If the tray was already closed before, this will be a no-op. -# -# @device: Block device name (deprecated, use @id instead) -# -# @id: The name or QOM path of the guest device (since: 2.8) -# -# Since: 2.5 -# -# Example: -# -# -> { "execute": "blockdev-close-tray", -# "arguments": { "id": "ide0-1-0" } } -# -# <- { "timestamp": { "seconds": 1418751345, -# "microseconds": 272147 }, -# "event": "DEVICE_TRAY_MOVED", -# "data": { "device": "ide1-cd0", -# "id": "ide0-1-0", -# "tray-open": false } } -# -# <- { "return": {} } -# -## -{ 'command': 'blockdev-close-tray', - 'data': { '*device': 'str', - '*id': 'str' } } - -## -# @blockdev-remove-medium: -# -# Removes a medium (a block driver state tree) from a block device. That b= lock -# device's tray must currently be open (unless there is no attached guest -# device). -# -# If the tray is open and there is no medium inserted, this will be a no-o= p. -# -# @id: The name or QOM path of the guest device -# -# Since: 2.12 -# -# Example: -# -# -> { "execute": "blockdev-remove-medium", -# "arguments": { "id": "ide0-1-0" } } -# -# <- { "error": { "class": "GenericError", -# "desc": "Tray of device 'ide0-1-0' is not open" } } -# -# -> { "execute": "blockdev-open-tray", -# "arguments": { "id": "ide0-1-0" } } -# -# <- { "timestamp": { "seconds": 1418751627, -# "microseconds": 549958 }, -# "event": "DEVICE_TRAY_MOVED", -# "data": { "device": "ide1-cd0", -# "id": "ide0-1-0", -# "tray-open": true } } -# -# <- { "return": {} } -# -# -> { "execute": "blockdev-remove-medium", -# "arguments": { "id": "ide0-1-0" } } -# -# <- { "return": {} } -# -## -{ 'command': 'blockdev-remove-medium', - 'data': { 'id': 'str' } } - -## -# @blockdev-insert-medium: -# -# Inserts a medium (a block driver state tree) into a block device. That b= lock -# device's tray must currently be open (unless there is no attached guest -# device) and there must be no medium inserted already. -# -# @id: The name or QOM path of the guest device -# -# @node-name: name of a node in the block driver state graph -# -# Since: 2.12 -# -# Example: -# -# -> { "execute": "blockdev-add", -# "arguments": { -# "node-name": "node0", -# "driver": "raw", -# "file": { "driver": "file", -# "filename": "fedora.iso" } } } -# <- { "return": {} } -# -# -> { "execute": "blockdev-insert-medium", -# "arguments": { "id": "ide0-1-0", -# "node-name": "node0" } } -# -# <- { "return": {} } -# -## -{ 'command': 'blockdev-insert-medium', - 'data': { 'id': 'str', - 'node-name': 'str'} } - - -## -# @BlockdevChangeReadOnlyMode: -# -# Specifies the new read-only mode of a block device subject to the -# @blockdev-change-medium command. -# -# @retain: Retains the current read-only mode -# -# @read-only: Makes the device read-only -# -# @read-write: Makes the device writable -# -# Since: 2.3 -# -## -{ 'enum': 'BlockdevChangeReadOnlyMode', - 'data': ['retain', 'read-only', 'read-write'] } - - -## -# @blockdev-change-medium: -# -# Changes the medium inserted into a block device by ejecting the current = medium -# and loading a new image file which is inserted as the new medium (this c= ommand -# combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-med= ium -# and blockdev-close-tray). -# -# @device: Block device name (deprecated, use @id instead) -# -# @id: The name or QOM path of the guest device -# (since: 2.8) -# -# @filename: filename of the new image to be loaded -# -# @format: format to open the new image with (defaults to -# the probed format) -# -# @read-only-mode: change the read-only mode of the device; defaults -# to 'retain' -# -# Since: 2.5 -# -# Examples: -# -# 1. Change a removable medium -# -# -> { "execute": "blockdev-change-medium", -# "arguments": { "id": "ide0-1-0", -# "filename": "/srv/images/Fedora-12-x86_64-DVD.iso", -# "format": "raw" } } -# <- { "return": {} } -# -# 2. Load a read-only medium into a writable drive -# -# -> { "execute": "blockdev-change-medium", -# "arguments": { "id": "floppyA", -# "filename": "/srv/images/ro.img", -# "format": "raw", -# "read-only-mode": "retain" } } -# -# <- { "error": -# { "class": "GenericError", -# "desc": "Could not open '/srv/images/ro.img': Permission denied" = } } -# -# -> { "execute": "blockdev-change-medium", -# "arguments": { "id": "floppyA", -# "filename": "/srv/images/ro.img", -# "format": "raw", -# "read-only-mode": "read-only" } } -# -# <- { "return": {} } -# -## -{ 'command': 'blockdev-change-medium', - 'data': { '*device': 'str', - '*id': 'str', - 'filename': 'str', - '*format': 'str', - '*read-only-mode': 'BlockdevChangeReadOnlyMode' } } - - ## # @BlockErrorAction: # diff --git a/qapi/block.json b/qapi/block.json index d2f3fc01ed..97bf52b7c7 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -115,6 +115,248 @@ '*id': 'str', '*force': 'bool' } } =20 +## +# @blockdev-open-tray: +# +# Opens a block device's tray. If there is a block driver state tree inser= ted as +# a medium, it will become inaccessible to the guest (but it will remain +# associated to the block device, so closing the tray will make it accessi= ble +# again). +# +# If the tray was already open before, this will be a no-op. +# +# Once the tray opens, a DEVICE_TRAY_MOVED event is emitted. There are cas= es in +# which no such event will be generated, these include: +# +# - if the guest has locked the tray, @force is false and the guest does n= ot +# respond to the eject request +# - if the BlockBackend denoted by @device does not have a guest device at= tached +# to it +# - if the guest device does not have an actual tray +# +# @device: Block device name (deprecated, use @id instead) +# +# @id: The name or QOM path of the guest device (since: 2.8) +# +# @force: if false (the default), an eject request will be sent to +# the guest if it has locked the tray (and the tray will not be op= ened +# immediately); if true, the tray will be opened regardless of whe= ther +# it is locked +# +# Since: 2.5 +# +# Example: +# +# -> { "execute": "blockdev-open-tray", +# "arguments": { "id": "ide0-1-0" } } +# +# <- { "timestamp": { "seconds": 1418751016, +# "microseconds": 716996 }, +# "event": "DEVICE_TRAY_MOVED", +# "data": { "device": "ide1-cd0", +# "id": "ide0-1-0", +# "tray-open": true } } +# +# <- { "return": {} } +# +## +{ 'command': 'blockdev-open-tray', + 'data': { '*device': 'str', + '*id': 'str', + '*force': 'bool' } } + +## +# @blockdev-close-tray: +# +# Closes a block device's tray. If there is a block driver state tree asso= ciated +# with the block device (which is currently ejected), that tree will be lo= aded +# as the medium. +# +# If the tray was already closed before, this will be a no-op. +# +# @device: Block device name (deprecated, use @id instead) +# +# @id: The name or QOM path of the guest device (since: 2.8) +# +# Since: 2.5 +# +# Example: +# +# -> { "execute": "blockdev-close-tray", +# "arguments": { "id": "ide0-1-0" } } +# +# <- { "timestamp": { "seconds": 1418751345, +# "microseconds": 272147 }, +# "event": "DEVICE_TRAY_MOVED", +# "data": { "device": "ide1-cd0", +# "id": "ide0-1-0", +# "tray-open": false } } +# +# <- { "return": {} } +# +## +{ 'command': 'blockdev-close-tray', + 'data': { '*device': 'str', + '*id': 'str' } } + +## +# @blockdev-remove-medium: +# +# Removes a medium (a block driver state tree) from a block device. That b= lock +# device's tray must currently be open (unless there is no attached guest +# device). +# +# If the tray is open and there is no medium inserted, this will be a no-o= p. +# +# @id: The name or QOM path of the guest device +# +# Since: 2.12 +# +# Example: +# +# -> { "execute": "blockdev-remove-medium", +# "arguments": { "id": "ide0-1-0" } } +# +# <- { "error": { "class": "GenericError", +# "desc": "Tray of device 'ide0-1-0' is not open" } } +# +# -> { "execute": "blockdev-open-tray", +# "arguments": { "id": "ide0-1-0" } } +# +# <- { "timestamp": { "seconds": 1418751627, +# "microseconds": 549958 }, +# "event": "DEVICE_TRAY_MOVED", +# "data": { "device": "ide1-cd0", +# "id": "ide0-1-0", +# "tray-open": true } } +# +# <- { "return": {} } +# +# -> { "execute": "blockdev-remove-medium", +# "arguments": { "id": "ide0-1-0" } } +# +# <- { "return": {} } +# +## +{ 'command': 'blockdev-remove-medium', + 'data': { 'id': 'str' } } + +## +# @blockdev-insert-medium: +# +# Inserts a medium (a block driver state tree) into a block device. That b= lock +# device's tray must currently be open (unless there is no attached guest +# device) and there must be no medium inserted already. +# +# @id: The name or QOM path of the guest device +# +# @node-name: name of a node in the block driver state graph +# +# Since: 2.12 +# +# Example: +# +# -> { "execute": "blockdev-add", +# "arguments": { +# "node-name": "node0", +# "driver": "raw", +# "file": { "driver": "file", +# "filename": "fedora.iso" } } } +# <- { "return": {} } +# +# -> { "execute": "blockdev-insert-medium", +# "arguments": { "id": "ide0-1-0", +# "node-name": "node0" } } +# +# <- { "return": {} } +# +## +{ 'command': 'blockdev-insert-medium', + 'data': { 'id': 'str', + 'node-name': 'str'} } + + +## +# @BlockdevChangeReadOnlyMode: +# +# Specifies the new read-only mode of a block device subject to the +# @blockdev-change-medium command. +# +# @retain: Retains the current read-only mode +# +# @read-only: Makes the device read-only +# +# @read-write: Makes the device writable +# +# Since: 2.3 +# +## +{ 'enum': 'BlockdevChangeReadOnlyMode', + 'data': ['retain', 'read-only', 'read-write'] } + + +## +# @blockdev-change-medium: +# +# Changes the medium inserted into a block device by ejecting the current = medium +# and loading a new image file which is inserted as the new medium (this c= ommand +# combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-med= ium +# and blockdev-close-tray). +# +# @device: Block device name (deprecated, use @id instead) +# +# @id: The name or QOM path of the guest device +# (since: 2.8) +# +# @filename: filename of the new image to be loaded +# +# @format: format to open the new image with (defaults to +# the probed format) +# +# @read-only-mode: change the read-only mode of the device; defaults +# to 'retain' +# +# Since: 2.5 +# +# Examples: +# +# 1. Change a removable medium +# +# -> { "execute": "blockdev-change-medium", +# "arguments": { "id": "ide0-1-0", +# "filename": "/srv/images/Fedora-12-x86_64-DVD.iso", +# "format": "raw" } } +# <- { "return": {} } +# +# 2. Load a read-only medium into a writable drive +# +# -> { "execute": "blockdev-change-medium", +# "arguments": { "id": "floppyA", +# "filename": "/srv/images/ro.img", +# "format": "raw", +# "read-only-mode": "retain" } } +# +# <- { "error": +# { "class": "GenericError", +# "desc": "Could not open '/srv/images/ro.img': Permission denied" = } } +# +# -> { "execute": "blockdev-change-medium", +# "arguments": { "id": "floppyA", +# "filename": "/srv/images/ro.img", +# "format": "raw", +# "read-only-mode": "read-only" } } +# +# <- { "return": {} } +# +## +{ 'command': 'blockdev-change-medium', + 'data': { '*device': 'str', + '*id': 'str', + 'filename': 'str', + '*format': 'str', + '*read-only-mode': 'BlockdevChangeReadOnlyMode' } } + + ## # @DEVICE_TRAY_MOVED: # @@ -167,3 +409,147 @@ ## { 'event': 'PR_MANAGER_STATUS_CHANGED', 'data': { 'id': 'str', 'connected': 'bool' } } + +## +# @block_set_io_throttle: +# +# Change I/O throttle limits for a block drive. +# +# Since QEMU 2.4, each device with I/O limits is member of a throttle +# group. +# +# If two or more devices are members of the same group, the limits +# will apply to the combined I/O of the whole group in a round-robin +# fashion. Therefore, setting new I/O limits to a device will affect +# the whole group. +# +# The name of the group can be specified using the 'group' parameter. +# If the parameter is unset, it is assumed to be the current group of +# that device. If it's not in any group yet, the name of the device +# will be used as the name for its group. +# +# The 'group' parameter can also be used to move a device to a +# different group. In this case the limits specified in the parameters +# will be applied to the new group only. +# +# I/O limits can be disabled by setting all of them to 0. In this case +# the device will be removed from its group and the rest of its +# members will not be affected. The 'group' parameter is ignored. +# +# Returns: - Nothing on success +# - If @device is not a valid block device, DeviceNotFound +# +# Since: 1.1 +# +# Example: +# +# -> { "execute": "block_set_io_throttle", +# "arguments": { "id": "virtio-blk-pci0/virtio-backend", +# "bps": 0, +# "bps_rd": 0, +# "bps_wr": 0, +# "iops": 512, +# "iops_rd": 0, +# "iops_wr": 0, +# "bps_max": 0, +# "bps_rd_max": 0, +# "bps_wr_max": 0, +# "iops_max": 0, +# "iops_rd_max": 0, +# "iops_wr_max": 0, +# "bps_max_length": 0, +# "iops_size": 0 } } +# <- { "return": {} } +# +# -> { "execute": "block_set_io_throttle", +# "arguments": { "id": "ide0-1-0", +# "bps": 1000000, +# "bps_rd": 0, +# "bps_wr": 0, +# "iops": 0, +# "iops_rd": 0, +# "iops_wr": 0, +# "bps_max": 8000000, +# "bps_rd_max": 0, +# "bps_wr_max": 0, +# "iops_max": 0, +# "iops_rd_max": 0, +# "iops_wr_max": 0, +# "bps_max_length": 60, +# "iops_size": 0 } } +# <- { "return": {} } +## +{ 'command': 'block_set_io_throttle', 'boxed': true, + 'data': 'BlockIOThrottle' } + +## +# @block-latency-histogram-set: +# +# Manage read, write and flush latency histograms for the device. +# +# If only @id parameter is specified, remove all present latency histograms +# for the device. Otherwise, add/reset some of (or all) latency histograms. +# +# @id: The name or QOM path of the guest device. +# +# @boundaries: list of interval boundary values (see description in +# BlockLatencyHistogramInfo definition). If specified, all +# latency histograms are removed, and empty ones created for = all +# io types with intervals corresponding to @boundaries (excep= t for +# io types, for which specific boundaries are set through the +# following parameters). +# +# @boundaries-read: list of interval boundary values for read latency +# histogram. If specified, old read latency histogram is +# removed, and empty one created with intervals +# corresponding to @boundaries-read. The parameter has h= igher +# priority then @boundaries. +# +# @boundaries-write: list of interval boundary values for write latency +# histogram. +# +# @boundaries-flush: list of interval boundary values for flush latency +# histogram. +# +# Returns: error if device is not found or any boundary arrays are invalid. +# +# Since: 4.0 +# +# Example: set new histograms for all io types with intervals +# [0, 10), [10, 50), [50, 100), [100, +inf): +# +# -> { "execute": "block-latency-histogram-set", +# "arguments": { "id": "drive0", +# "boundaries": [10, 50, 100] } } +# <- { "return": {} } +# +# Example: set new histogram only for write, other histograms will remain +# not changed (or not created): +# +# -> { "execute": "block-latency-histogram-set", +# "arguments": { "id": "drive0", +# "boundaries-write": [10, 50, 100] } } +# <- { "return": {} } +# +# Example: set new histograms with the following intervals: +# read, flush: [0, 10), [10, 50), [50, 100), [100, +inf) +# write: [0, 1000), [1000, 5000), [5000, +inf) +# +# -> { "execute": "block-latency-histogram-set", +# "arguments": { "id": "drive0", +# "boundaries": [10, 50, 100], +# "boundaries-write": [1000, 5000] } } +# <- { "return": {} } +# +# Example: remove all latency histograms: +# +# -> { "execute": "block-latency-histogram-set", +# "arguments": { "id": "drive0" } } +# <- { "return": {} } +## +{ 'command': 'block-latency-histogram-set', + 'data': {'id': 'str', + '*boundaries': ['uint64'], + '*boundaries-read': ['uint64'], + '*boundaries-write': ['uint64'], + '*boundaries-flush': ['uint64'] } } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index da7083087e..864cbfa32e 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -30,7 +30,7 @@ #include "sysemu/blockdev.h" #include "sysemu/block-backend.h" #include "qapi/error.h" -#include "qapi/qapi-commands-block-core.h" +#include "qapi/qapi-commands-block.h" #include "qapi/qapi-commands-control.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-misc.h" --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582554864; cv=none; d=zohomail.com; s=zohoarc; b=a3sNtmW8ySml7msNh8GI8krEfXG0FAe+PF6cOzQysubGcINZGUqyplTAKw78JLOavEKVpzbz27XUPR005yLdI5UttlyO6tOmSB7mMzELPjRtJxDE0MKsPmwTh0hRSWwwAjfNl3u4Mgi5BceAfUW/99k55apnHCRHxrTdhj30U2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554864; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ia38OPTV1CkiYPUVpdttHvJJ8KRirq7hiJmiLqgfnCY=; b=R+Bt2slG9WyTcXqgF2FktuM1dvvF5uV2GoL5YjYUjyiH8bOrP1LkcPz4pb5tuTNNpDDfMOlr+LubI6c34eKtbdDQ+XnH2upVDmGIQlzyAPYOcIG2T9mHtqV+9h+54gxTpMHgtO9pLPriP+4fWSc06XENmETslU8FrU7dyRSz24M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582554864879364.39981436330936; Mon, 24 Feb 2020 06:34:24 -0800 (PST) Received: from localhost ([::1]:37352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6EoR-0007M1-Qz for importer@patchew.org; Mon, 24 Feb 2020 09:34:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50692) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Ekz-0001kJ-Mw for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Eky-0002GA-6C for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:49 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21149 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Eky-0002Ff-2O for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-481-R26ijo80O2yJ2gWnm97PxA-1; Mon, 24 Feb 2020 09:30:46 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C512C107ACC4; Mon, 24 Feb 2020 14:30:40 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95AB1790FF; Mon, 24 Feb 2020 14:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ia38OPTV1CkiYPUVpdttHvJJ8KRirq7hiJmiLqgfnCY=; b=ZXcwwgNP+bKmuRHzdvPI2yIRqYdPaMp6tcYoxYI2Py6I5ZGgB/GjQIpfvDGFaywIyvAOxc QgUO0a1hQOiKXzoYJiLLPu1AVbsZwe1sBjUkFNuSCYXYpW2l30wLtdhXSFXikU45D0YCuf H34iv88CwJkEgLrkbwSGejNVo3GrjRs= X-MC-Unique: R26ijo80O2yJ2gWnm97PxA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 06/20] qemu-storage-daemon: Add --blockdev option Date: Mon, 24 Feb 2020 15:29:54 +0100 Message-Id: <20200224143008.13362-7-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. In contrast to the system emulator, qemu-storage-daemon options will be processed in the order they are given. The user needs to take care to refer to other objects only after defining them. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qemu-storage-daemon.c | 31 +++++++++++++++++++++++++++++++ Makefile | 5 ++++- Makefile.objs | 7 +++++++ block/Makefile.objs | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index fc4aef572b..c30caaf59e 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -31,6 +31,10 @@ #include "crypto/init.h" =20 #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" @@ -52,15 +56,27 @@ static void help(void) " specify tracing options\n" " -V, --version output version information and exit\n" "\n" +" --blockdev [driver=3D][,node-name=3D][,discard=3Dignore|unma= p]\n" +" [,cache.direct=3Don|off][,cache.no-flush=3Don|off]\n" +" [,read-only=3Don|off][,auto-read-only=3Don|off]\n" +" [,force-share=3Don|off][,detect-zeroes=3Don|off|unmap]\n" +" [,driver specific parameters...]\n" +" configure a block backend\n" +"\n" QEMU_HELP_BOTTOM "\n", error_get_progname()); } =20 +enum { + OPTION_BLOCKDEV =3D 256, +}; + static void process_options(int argc, char *argv[]) { int c; =20 static const struct option long_options[] =3D { + {"blockdev", required_argument, NULL, OPTION_BLOCKDEV}, {"help", no_argument, NULL, 'h'}, {"trace", required_argument, NULL, 'T'}, {"version", no_argument, NULL, 'V'}, @@ -90,6 +106,21 @@ static void process_options(int argc, char *argv[]) printf("qemu-storage-daemon version " QEMU_FULL_VERSION "\n" QEMU_COPYRIGHT "\n"); exit(EXIT_SUCCESS); + case OPTION_BLOCKDEV: + { + Visitor *v; + BlockdevOptions *options; + + v =3D 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; + } default: g_assert_not_reached(); } diff --git a/Makefile b/Makefile index 44b3c8a342..750cff8d0a 100644 --- a/Makefile +++ b/Makefile @@ -450,6 +450,8 @@ dummy :=3D $(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 \ qom-obj-y \ io-obj-y \ @@ -482,6 +484,7 @@ TARGET_DIRS_RULES :=3D $(foreach t, all clean install, = $(addsuffix /$(t), $(TARGET SOFTMMU_ALL_RULES=3D$(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) @@ -573,7 +576,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) =20 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) =20 diff --git a/Makefile.objs b/Makefile.objs index 26b9cff954..c7e1b36130 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -27,6 +27,13 @@ io-obj-y =3D io/ =20 endif # CONFIG_SOFTMMU or CONFIG_TOOLS =20 +####################################################################### +# 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 =3D block/ +storage-daemon-obj-y +=3D 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 e06cf0b284..cb36ae2503 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -46,7 +46,7 @@ block-obj-y +=3D aio_task.o block-obj-y +=3D backup-top.o block-obj-y +=3D filter-compress.o =20 -common-obj-y +=3D stream.o +block-obj-y +=3D stream.o =20 common-obj-y +=3D qapi-sysemu.o =20 --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582554871; cv=none; d=zohomail.com; s=zohoarc; b=DAg3zHEFpR36t7WElxHnB/cq1LUkFJgq2iqVISIflgbh5xXZ2fJyb0bJwxHvLhzcbu07yQw0DsOFDLCIlYVp1r3ULsmcbBbiU4ImNTkg80hT6rDv3AluJbMOhp9Fz1ob1g/wH/2bZvnRD3u2NUrEQ5wcokYdeAlIfh/WTaA9Pr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554871; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AZ8c4lv673Ml8nGwmYyEs+bXXK1XOqXwykw2590D9Ao=; b=V/Wv5QPg8G1J1d1GWjvcPLSUo9q9hULnqRCVZQYqgq+te02NYbykAdMFSd4p1TpVV1tI7l1n78wCzCvTlOFJhPO2erC8OqMNlRTKiU2XFM4diQL8L1btu0wAa/gYzxXqLB/nNC5gEnmM6V8FnNQ7ay9dL3u7y8Qi+QATbwTNnxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158255487190388.20301789161431; Mon, 24 Feb 2020 06:34:31 -0800 (PST) Received: from localhost ([::1]:37358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6EoY-0007aa-Oa for importer@patchew.org; Mon, 24 Feb 2020 09:34:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50741) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6El2-0001rA-Sg for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6El1-0002KZ-3F for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:52 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:58346 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6El0-0002KO-UM for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:51 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-414-GbOEeCZsO-mdWM3prZEP_g-1; Mon, 24 Feb 2020 09:30:46 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A24F910509B9; Mon, 24 Feb 2020 14:30:45 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F8E55C114; Mon, 24 Feb 2020 14:30:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZ8c4lv673Ml8nGwmYyEs+bXXK1XOqXwykw2590D9Ao=; b=T3mPpPx0tBpixuVNFXJDhjKE53U2/fj5EjOi34lbdbWJ5uzMbhpgajcZhE/hxEZ9aw7LIw 91YFPm7sH7xvpKITzw5oTxOGVP0GXwMiKOujH8p8hWrsKoHQPHDq87C+N8PVK0MCF+cFVA W7ok4+3n407AewbBDdFyshnvixvjitY= X-MC-Unique: GbOEeCZsO-mdWM3prZEP_g-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 07/20] qapi: Flatten object-add Date: Mon, 24 Feb 2020 15:29:55 +0100 Message-Id: <20200224143008.13362-8-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Mapping object-add to the command line as is doesn't result in nice syntax because of the nesting introduced with 'props'. This becomes nicer and more consistent with device_add and netdev_add when we accept properties for the object on the top level instead. 'props' is still accepted after this patch, but marked as deprecated. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/qom.json | 12 +++++++--- include/qom/object_interfaces.h | 7 ++++++ hw/block/xen-block.c | 11 ++++++++- monitor/misc.c | 2 ++ qom/qom-qmp-cmds.c | 42 +++++++++++++++++++++++++++------ qemu-deprecated.texi | 4 ++++ 6 files changed, 67 insertions(+), 11 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index ecc60c4401..8abe998962 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -210,7 +210,12 @@ # # @id: the name of the new object # -# @props: a dictionary of properties to be passed to the backend +# @props: a dictionary of properties to be passed to the backend. Deprecat= ed +# since 5.0, specify the properties on the top level instead. It i= s an +# error to specify the same option both on the top level and in @p= rops. +# +# Additional arguments depend on qom-type and are passed to the backend +# unchanged. # # Returns: Nothing on success # Error if @qom-type is not a valid class name @@ -221,12 +226,13 @@ # # -> { "execute": "object-add", # "arguments": { "qom-type": "rng-random", "id": "rng1", -# "props": { "filename": "/dev/hwrng" } } } +# "filename": "/dev/hwrng" } } # <- { "return": {} } # ## { 'command': 'object-add', - 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} } + 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'}, + 'gen': false } # so we can get the additional arguments =20 ## # @object-del: diff --git a/include/qom/object_interfaces.h b/include/qom/object_interface= s.h index 3e4e1d928b..6f92f3cebb 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -162,4 +162,11 @@ void user_creatable_del(const char *id, Error **errp); */ void user_creatable_cleanup(void); =20 +/** + * qmp_object_add: + * + * QMP command handler for object-add. See the QAPI schema for documentati= on. + */ +void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp); + #endif diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 686bbc3f0d..3885464513 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -18,6 +18,7 @@ #include "qapi/visitor.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" +#include "qom/object_interfaces.h" #include "hw/xen/xen_common.h" #include "hw/block/xen_blkif.h" #include "hw/qdev-properties.h" @@ -858,10 +859,18 @@ static XenBlockIOThread *xen_block_iothread_create(co= nst char *id, { XenBlockIOThread *iothread =3D g_new(XenBlockIOThread, 1); Error *local_err =3D NULL; + QDict *opts; + QObject *ret_data; =20 iothread->id =3D g_strdup(id); =20 - qmp_object_add(TYPE_IOTHREAD, id, false, NULL, &local_err); + opts =3D qdict_new(); + qdict_put_str(opts, "qom-type", TYPE_IOTHREAD); + qdict_put_str(opts, "id", id); + qmp_object_add(opts, &ret_data, &local_err); + qobject_unref(opts); + qobject_unref(ret_data); + if (local_err) { error_propagate(errp, local_err); =20 diff --git a/monitor/misc.c b/monitor/misc.c index 6c41293102..1748ab3911 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -248,6 +248,8 @@ static void monitor_init_qmp_commands(void) QCO_NO_OPTIONS); qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add, QCO_NO_OPTIONS); + qmp_register_command(&qmp_commands, "object-add", qmp_object_add, + QCO_NO_OPTIONS); =20 QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 6136efec16..49db926fcc 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -14,6 +14,7 @@ */ =20 #include "qemu/osdep.h" +#include "block/qdict.h" #include "hw/qdev-core.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" @@ -240,13 +241,34 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const= char *typename, return prop_list; } =20 -void qmp_object_add(const char *type, const char *id, - bool has_props, QObject *props, Error **errp) +void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp) { + QObject *props; QDict *pdict; Visitor *v; Object *obj; + const char *type; + const char *id; =20 + type =3D qdict_get_try_str(qdict, "qom-type"); + if (!type) { + error_setg(errp, QERR_MISSING_PARAMETER, "qom-type"); + return; + } else { + type =3D g_strdup(type); + qdict_del(qdict, "qom-type"); + } + + id =3D qdict_get_try_str(qdict, "id"); + if (!id) { + error_setg(errp, QERR_MISSING_PARAMETER, "id"); + return; + } else { + id =3D g_strdup(id); + qdict_del(qdict, "id"); + } + + props =3D qdict_get(qdict, "props"); if (props) { pdict =3D qobject_to(QDict, props); if (!pdict) { @@ -254,17 +276,23 @@ void qmp_object_add(const char *type, const char *id, return; } qobject_ref(pdict); - } else { - pdict =3D qdict_new(); + qdict_del(qdict, "props"); + qdict_join(qdict, pdict, false); + if (qdict_size(pdict) !=3D 0) { + error_setg(errp, "Option in 'props' conflicts with top level"); + qobject_unref(pdict); + return; + } + qobject_unref(pdict); } =20 - v =3D qobject_input_visitor_new(QOBJECT(pdict)); - obj =3D user_creatable_add_type(type, id, pdict, v, errp); + v =3D qobject_input_visitor_new(QOBJECT(qdict)); + obj =3D user_creatable_add_type(type, id, qdict, v, errp); visit_free(v); if (obj) { object_unref(obj); } - qobject_unref(pdict); + *ret_data =3D QOBJECT(qdict_new()); } =20 void qmp_object_del(const char *id, Error **errp) diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index 0671c26c80..faf99d3f91 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -167,6 +167,10 @@ Use ``migrate-set-parameters'' instead. =20 Use ``migrate-set-parameters'' and ``query-migrate-parameters'' instead. =20 +@subsection object-add option props (since 5.0) + +Specify the properties for the object as top-level arguments instead. + @subsection query-block result field dirty-bitmaps[i].status (since 4.0) =20 The ``status'' field of the ``BlockDirtyInfo'' structure, returned by --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555027; cv=none; d=zohomail.com; s=zohoarc; b=bSao1RTGj1oGeI7LD5iFFJrolkXPx7bNJM/otvN3xF81UK2K23B7h1gt228wH7wmUIm0g6HF2zvCuPznuCV2YWHyuQgDwjIjS2IXMSEeJ5vid3H8iNhJy1HZMzSF7nM9uom3FYG7MNQf+jTT1wdcmMCzUImCPJnSgMS38aKPkp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555027; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=njL4p+O8e20nCibvaiBgf6Oi+xeoYFNnJeIvfkpwLfc=; b=WalUx45tEk4ZNEajiOxcQ4V0kI7ZdyRvzgDyxz1rN8dGAuRF6unXbj7blWe9eT1qMyo7iXMXUwgs6Vn0jU9BRcnSCXInGqduB0JHPztaDs9ss+cDV4NtXHTHMGPERYnULTzOHsStC0lYi4dwHF4NavhPgDinBFfzz5O8Zp5gTnA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555027071923.2731791508536; Mon, 24 Feb 2020 06:37:07 -0800 (PST) Received: from localhost ([::1]:37420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Er3-00043W-1V for importer@patchew.org; Mon, 24 Feb 2020 09:37:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50775) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6El5-0001wm-AR for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6El3-0002Mi-UG for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:55 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:45566 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6El3-0002Mb-Pa for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-302-uh_IhfU7NL6kaNkgj6045w-1; Mon, 24 Feb 2020 09:30:49 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E3FD8024DF; Mon, 24 Feb 2020 14:30:48 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDD995C114; Mon, 24 Feb 2020 14:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=njL4p+O8e20nCibvaiBgf6Oi+xeoYFNnJeIvfkpwLfc=; b=JCZbpBijVkKPdj3+f0heHL6M5Xh3IrYsSCt9k6Yi+w+d5yntFXbjLPhkyp22FKsk0+bUGS ZbKDBoBTHEywqxbToHrULifzSw0tYrXg22kh8joN5XsyNeU/pky/ygi9dOIkuSk5nV02/8 SqWhdlgOdwbWF/0D0XWtY85F//AZp/Y= X-MC-Unique: uh_IhfU7NL6kaNkgj6045w-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 08/20] qemu-storage-daemon: Add --object option Date: Mon, 24 Feb 2020 15:29:56 +0100 Message-Id: <20200224143008.13362-9-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a command line option to create user-creatable QOM objects. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qemu-storage-daemon.c | 47 +++++++++++++++++++++++++++++++++++++++++++ Makefile.objs | 2 +- qom/Makefile.objs | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index c30caaf59e..0cd8144c81 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -33,15 +33,19 @@ #include "qapi/error.h" #include "qapi/qapi-visit-block-core.h" #include "qapi/qapi-commands-block-core.h" +#include "qapi/qmp/qdict.h" #include "qapi/qobject-input-visitor.h" =20 #include "qemu-common.h" #include "qemu-version.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/help_option.h" #include "qemu/log.h" #include "qemu/main-loop.h" #include "qemu/module.h" +#include "qemu/option.h" +#include "qom/object_interfaces.h" =20 #include "trace/control.h" =20 @@ -63,12 +67,31 @@ static void help(void) " [,driver specific parameters...]\n" " configure a block backend\n" "\n" +" --object help list object types that can be added\n" +" --object ,help list properties for the given object type\n" +" --object [,=3D...]\n" +" create a new object of type , setting\n" +" properties in the order they are specified. Note= \n" +" that the 'id' property must be set.\n" +" See the qemu(1) man page for documentation of th= e\n" +" objects that can be added.\n" +"\n" QEMU_HELP_BOTTOM "\n", error_get_progname()); } =20 enum { OPTION_BLOCKDEV =3D 256, + OPTION_OBJECT, +}; + +static QemuOptsList qemu_object_opts =3D { + .name =3D "object", + .implied_opt_name =3D "qom-type", + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), + .desc =3D { + { } + }, }; =20 static void process_options(int argc, char *argv[]) @@ -78,6 +101,7 @@ static void process_options(int argc, char *argv[]) static const struct option long_options[] =3D { {"blockdev", required_argument, NULL, OPTION_BLOCKDEV}, {"help", no_argument, NULL, 'h'}, + {"object", required_argument, NULL, OPTION_OBJECT}, {"trace", required_argument, NULL, 'T'}, {"version", no_argument, NULL, 'V'}, {0, 0, 0, 0} @@ -121,6 +145,29 @@ static void process_options(int argc, char *argv[]) qapi_free_BlockdevOptions(options); break; } + case OPTION_OBJECT: + { + QemuOpts *opts; + const char *type; + QDict *args; + QObject *ret_data =3D NULL; + + /* FIXME The keyval parser rejects 'help' arguments, so we= must + * unconditionall try QemuOpts first. */ + opts =3D qemu_opts_parse(&qemu_object_opts, + optarg, true, &error_fatal); + type =3D qemu_opt_get(opts, "qom-type"); + if (type && user_creatable_print_help(type, opts)) { + exit(EXIT_SUCCESS); + } + qemu_opts_del(opts); + + args =3D keyval_parse(optarg, "qom-type", &error_fatal); + qmp_object_add(args, &ret_data, &error_fatal); + qobject_unref(args); + qobject_unref(ret_data); + break; + } default: g_assert_not_reached(); } diff --git a/Makefile.objs b/Makefile.objs index c7e1b36130..fa92b00427 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -31,7 +31,7 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS # storage-daemon-obj-y is code used by qemu-storage-daemon (these objects = are # used for system emulation, too, but specified separately there) =20 -storage-daemon-obj-y =3D block/ +storage-daemon-obj-y =3D block/ qom/ storage-daemon-obj-y +=3D blockdev.o iothread.o =20 ###################################################################### 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 =3D object.o container.o qom-qobject.o qom-obj-y +=3D object_interfaces.o =20 common-obj-$(CONFIG_SOFTMMU) +=3D qom-hmp-cmds.o qom-qmp-cmds.o +storage-daemon-obj-y +=3D qom-qmp-cmds.o --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555119; cv=none; d=zohomail.com; s=zohoarc; b=YTPjYUBb9fMizyeHgUuSxOWXt1kBl560D92ur1mnZtJXcK4cXBF489FEfWLrP1PbVMDSyh6TWU/RA1+LciVW7G5+Q3J8L+JxsletncBJvW8Q1al4V9vk3sMKRMzbbBl8dIs0iQnEPi2oRdrep+boc5nlGi9JvSJO+H71CFmQ7L4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555119; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yYfHCSmvHKQJVbaPyMjxeFcUEJwMQfNJRAncsiwZcUk=; b=UMA1ukOOYL+gkawo12aPTCS5oscEPlOFwdDLqDWrfpXnifJ4p3+HbZ5lAziFFUoIwraYJve/1i4t+2HQIfP4+BVDU5pv3QdeSjP+0W2JZmD7MltuAWsmj3Q0X3WzejEz22Ak9h2MWDR1rHxWaDBTLVeOZ3A+bb4tDEBWbe9eOs4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555119965833.1140234534176; Mon, 24 Feb 2020 06:38:39 -0800 (PST) Received: from localhost ([::1]:37462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6EsX-0007dw-Jk for importer@patchew.org; Mon, 24 Feb 2020 09:38:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50790) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6El7-00021D-5T for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6El5-0002NC-GR for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:57 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:23928 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6El5-0002N3-CY for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:55 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-348-wel-zk7_Mvyg-trXnl954g-1; Mon, 24 Feb 2020 09:30:51 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A3A68018B4; Mon, 24 Feb 2020 14:30:50 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A6125C114; Mon, 24 Feb 2020 14:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yYfHCSmvHKQJVbaPyMjxeFcUEJwMQfNJRAncsiwZcUk=; b=f53POqkIiKyv4t4w6dnI65HUCRmZ2/zLH9ULhm+0gIs/ZL1zdb05Y6jt1sWUtKX7vvE+8c KzkGeeBPFPEt5Vo+zfJnR7+3NTOwj2vl7ueBE0stTfiSGsnEvXn5UCLIUp09vTxJlwrRAC FHOZNlLz9mrqn/+/U06QxIyS22an2kM= X-MC-Unique: wel-zk7_Mvyg-trXnl954g-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 09/20] qemu-storage-daemon: Add --nbd-server option Date: Mon, 24 Feb 2020 15:29:57 +0100 Message-Id: <20200224143008.13362-10-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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, with the exception that it uses SocketAddress instead of SocketAddressLegacy: New interfaces shouldn't use legacy types, and the additional nesting would be nasty on the command line. Example (only with required options): --nbd-server addr.type=3Dinet,addr.host=3Dlocalhost,addr.port=3D10809 Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/block-core.json | 24 ++++++++++++++++++++++++ include/block/nbd.h | 1 + blockdev-nbd.c | 5 +++++ qemu-storage-daemon.c | 26 +++++++++++++++++++++++++- Makefile.objs | 2 +- 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index b65b6a9f49..f8888f06c8 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5062,6 +5062,27 @@ 'iothread': 'StrOrNull', '*force': 'bool' } } =20 +## +# @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). +# +# Keep this type consistent with the nbd-server-start arguments. The only +# intended difference is using SocketAddress instead of SocketAddressLegac= y. +# +# Since: 4.2 +## +{ 'struct': 'NbdServerOptions', + 'data': { 'addr': 'SocketAddress', + '*tls-creds': 'str', + '*tls-authz': 'str'} } + ## # @nbd-server-start: # @@ -5080,6 +5101,9 @@ # # Returns: error if the server is already running. # +# Keep this type consistent with the NbdServerOptions type. The only inten= ded +# difference is using SocketAddressLegacy instead of SocketAddress. +# # Since: 1.3.0 ## { 'command': 'nbd-server-start', diff --git a/include/block/nbd.h b/include/block/nbd.h index 7f46932d80..20363280ae 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -353,6 +353,7 @@ void nbd_client_put(NBDClient *client); =20 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); =20 /* nbd_read * Reads @size bytes from @ioc. Returns 0 on success. diff --git a/blockdev-nbd.c b/blockdev-nbd.c index de2f2ff713..d8c892f7da 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 =3D NULL; } =20 +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 0cd8144c81..276a412915 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -28,11 +28,14 @@ #include =20 #include "block/block.h" +#include "block/nbd.h" #include "crypto/init.h" =20 #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/qmp/qdict.h" #include "qapi/qobject-input-visitor.h" =20 @@ -67,6 +70,12 @@ static void help(void) " [,driver specific parameters...]\n" " configure a block backend\n" "\n" +" --nbd-server addr.type=3Dinet,addr.host=3D,addr.port=3D\n" +" [,tls-creds=3D][,tls-authz=3D]\n" +" --nbd-server addr.type=3Dunix,addr.path=3D\n" +" [,tls-creds=3D][,tls-authz=3D]\n" +" start an NBD server for exporting block nodes\n" +"\n" " --object help list object types that can be added\n" " --object ,help list properties for the given object type\n" " --object [,=3D...]\n" @@ -82,6 +91,7 @@ QEMU_HELP_BOTTOM "\n", =20 enum { OPTION_BLOCKDEV =3D 256, + OPTION_NBD_SERVER, OPTION_OBJECT, }; =20 @@ -101,6 +111,7 @@ static void process_options(int argc, char *argv[]) static const struct option long_options[] =3D { {"blockdev", required_argument, NULL, OPTION_BLOCKDEV}, {"help", no_argument, NULL, 'h'}, + {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER}, {"object", required_argument, NULL, OPTION_OBJECT}, {"trace", required_argument, NULL, 'T'}, {"version", no_argument, NULL, 'V'}, @@ -145,6 +156,19 @@ static void process_options(int argc, char *argv[]) qapi_free_BlockdevOptions(options); break; } + case OPTION_NBD_SERVER: + { + Visitor *v; + NbdServerOptions *options; + + v =3D qobject_input_visitor_new_str(optarg, NULL, &error_f= atal); + visit_type_NbdServerOptions(v, NULL, &options, &error_fata= l); + visit_free(v); + + nbd_server_start_options(options, &error_fatal); + qapi_free_NbdServerOptions(options); + break; + } case OPTION_OBJECT: { QemuOpts *opts; diff --git a/Makefile.objs b/Makefile.objs index fa92b00427..25ab313690 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -32,7 +32,7 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS # used for system emulation, too, but specified separately there) =20 storage-daemon-obj-y =3D block/ qom/ -storage-daemon-obj-y +=3D blockdev.o iothread.o +storage-daemon-obj-y +=3D blockdev.o blockdev-nbd.o iothread.o =20 ###################################################################### # Target independent part of system emulation. The long term path is to --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555155; cv=none; d=zohomail.com; s=zohoarc; b=Hlg9FY8kDAH6f5O/sGx4jFYaalWqBjGjcHp12qmCFNHPhhcGw59icKwW4r1LPV51Xz4QhB4wuCUjvwezbgQDGQmA1KNlCuE/zShIuJOj7o867uI/zoj2dG4jPWtT5rz0ObY2I1+OtPGhqURhpOeG+rb6fLWLG9p6gQHaSqIK5gQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555155; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EOyrC+zcpf7vTJ4vhh9JtXzCpCkRLbYX5Cw8tSXypPw=; b=nt+kxV2BBRpzK5se++QeVQP4lkdzp6tsCzkX+yE/HTDrgOXL2incODikFAc/9+pKiLAH6JPrJthJVyinFHMbRXv3eyWpeh+c7Z0dR6//DIdlmlBfoZhefHo9Uw3MwLauZ1khP44dbUISDiIW8Tge+5Sqj/By7YIGyEufCk/WliA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555155705280.9251822924896; Mon, 24 Feb 2020 06:39:15 -0800 (PST) Received: from localhost ([::1]:37484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Et8-0000uu-ML for importer@patchew.org; Mon, 24 Feb 2020 09:39:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50818) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6El8-00025w-Vi for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6El7-0002Nc-9K for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:49687 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6El7-0002NP-4X for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-MhhNe58eOYSA85GrTAAhLQ-1; Mon, 24 Feb 2020 09:30:53 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3FC71106BC24; Mon, 24 Feb 2020 14:30:52 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80BCF91833; Mon, 24 Feb 2020 14:30:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EOyrC+zcpf7vTJ4vhh9JtXzCpCkRLbYX5Cw8tSXypPw=; b=Lj+MnLxKT1SsuOknZkdl4mBVri/8narifskOkR8jEn+cc+BrQE2hbHLD17nisZeDItJ1L3 xb4q5DZOu0KspJPcDCLqjfcYVtLVSKg70XFJ0sI/qtWg4O0/EHh6z3OF6T7c8GDb7mFonj qbtKV5DGyAyD+u6C4bidIUocAclnmFA= X-MC-Unique: MhhNe58eOYSA85GrTAAhLQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 10/20] blockdev-nbd: Boxed argument type for nbd-server-add Date: Mon, 24 Feb 2020 15:29:58 +0100 Message-Id: <20200224143008.13362-11-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Acked-by: Stefan Hajnoczi --- qapi/block-core.json | 18 ++++++++++++++---- blockdev-nbd.c | 35 ++++++++++++++++------------------- monitor/hmp-cmds.c | 21 +++++++++++++++++---- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index f8888f06c8..cdc585385c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5112,9 +5112,9 @@ '*tls-authz': 'str'} } =20 ## -# @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 # @@ -5131,14 +5131,24 @@ # NBD client can use NBD_OPT_SET_META_CONTEXT with # "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0) # +# Since: 5.0 +## +{ 'struct': 'BlockExportNbd', + 'data': {'device': 'str', '*name': 'str', '*description': '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', '*description': 'str', - '*writable': 'bool', '*bitmap': 'str' } } + 'data': 'BlockExportNbd', 'boxed': true } =20 ## # @NbdServerRemoveMode: diff --git a/blockdev-nbd.c b/blockdev-nbd.c index d8c892f7da..1a95d89f00 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -148,10 +148,7 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, qapi_free_SocketAddress(addr_flat); } =20 -void qmp_nbd_server_add(const char *device, bool has_name, const char *nam= e, - bool has_description, const char *description, - bool has_writable, bool writable, - bool has_bitmap, const char *bitmap, Error **errp) +void qmp_nbd_server_add(BlockExportNbd *arg, Error **errp) { BlockDriverState *bs =3D NULL; BlockBackend *on_eject_blk; @@ -164,28 +161,28 @@ void qmp_nbd_server_add(const char *device, bool has_= name, const char *name, return; } =20 - if (!has_name) { - name =3D device; + if (!arg->has_name) { + arg->name =3D arg->device; } =20 - if (strlen(name) > NBD_MAX_STRING_SIZE) { - error_setg(errp, "export name '%s' too long", name); + if (strlen(arg->name) > NBD_MAX_STRING_SIZE) { + error_setg(errp, "export name '%s' too long", arg->name); return; } =20 - if (has_description && strlen(description) > NBD_MAX_STRING_SIZE) { - error_setg(errp, "description '%s' too long", description); + if (arg->description && strlen(arg->description) > NBD_MAX_STRING_SIZE= ) { + error_setg(errp, "description '%s' too long", arg->description); return; } =20 - 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; } =20 - on_eject_blk =3D blk_by_name(device); + on_eject_blk =3D blk_by_name(arg->device); =20 - bs =3D bdrv_lookup_bs(device, device, errp); + bs =3D bdrv_lookup_bs(arg->device, arg->device, errp); if (!bs) { return; } @@ -199,15 +196,15 @@ void qmp_nbd_server_add(const char *device, bool has_= name, const char *name, goto out; } =20 - if (!has_writable) { - writable =3D false; + if (!arg->has_writable) { + arg->writable =3D false; } if (bdrv_is_read_only(bs)) { - writable =3D false; + arg->writable =3D false; } =20 - exp =3D nbd_export_new(bs, 0, len, name, description, bitmap, - !writable, !writable, + exp =3D nbd_export_new(bs, 0, len, arg->name, arg->description, arg->b= itmap, + !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 53bc3f76c4..92d78656a8 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 =3D NULL; BlockInfoList *block_list, *info; SocketAddress *addr; + BlockExportNbd export; =20 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; } =20 - qmp_nbd_server_add(info->value->device, false, NULL, false, NULL, - true, writable, false, NULL, &local_err); + export =3D (BlockExportNbd) { + .device =3D info->value->device, + .has_writable =3D true, + .writable =3D writable, + }; + + qmp_nbd_server_add(&export, &local_err); =20 if (local_err !=3D NULL) { qmp_nbd_server_stop(NULL); @@ -2374,8 +2380,15 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *q= dict) bool writable =3D qdict_get_try_bool(qdict, "writable", false); Error *local_err =3D NULL; =20 - qmp_nbd_server_add(device, !!name, name, false, NULL, true, writable, - false, NULL, &local_err); + BlockExportNbd export =3D { + .device =3D (char *) device, + .has_name =3D !!name, + .name =3D (char *) name, + .has_writable =3D true, + .writable =3D writable, + }; + + qmp_nbd_server_add(&export, &local_err); hmp_handle_error(mon, local_err); } =20 --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555200; cv=none; d=zohomail.com; s=zohoarc; b=YqoL5k49dRpBtZ4slCAfjyDLb3Y2XLboSn6fDYMtzQyJFQSLQucMw4CAYAPsPyJ0KcfC9NRJVXkqQBBWdjF245GZgszXhmtFySJLPjARSx068medx79bKPwarYAuESQnp0/dPsW7MA+6oSA8zugG5LCPyt6Cu666GS+qPHSo1j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555200; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HtxwYe9wqoALQDY+/rt2KNTJq7ic0ScVJgwPX8cZDh8=; b=N3utp+wsTZSJRLjuntzjrnnP9zDqs4p3A9xalAXqU+CQzP7omhXAUcjx4XyRCkT+yuc71tH7BfJmUJc39nv1zXV/cba05K4chcgQZnx2cwEGWVpIikjug1B6zFIXPC2klPV/vzfMK8Inv5zZAJmIsyjVm18+VgwLoPiHQK0vauI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158255520000435.255769495348886; Mon, 24 Feb 2020 06:40:00 -0800 (PST) Received: from localhost ([::1]:37502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Etq-0002PK-VX for importer@patchew.org; Mon, 24 Feb 2020 09:39:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50817) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6El8-00025u-Vj for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6El7-0002Nz-Rm for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:58 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:56708 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6El7-0002Nq-Na for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-243-TZ2ekVYXNLGViWJBPN14eA-1; Mon, 24 Feb 2020 09:30:55 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52EEB800D54; Mon, 24 Feb 2020 14:30:54 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9874F91833; Mon, 24 Feb 2020 14:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HtxwYe9wqoALQDY+/rt2KNTJq7ic0ScVJgwPX8cZDh8=; b=ITaVgM4lQcwEMmkt1EymvAokAS8WYhjt0k8dk0pASBpf7V3zOkm2f68IuiwtfpW9cCw3uQ f5Zg2YREG8V1ewuFkIjtaOQ47H3NB6vOiubhLgU2rmiVZ0g2ovQuIdqUvTjXWWx5kNbxhE ydJHyGVy6w+wz8u1cbZc4htBlrib0cA= X-MC-Unique: TZ2ekVYXNLGViWJBPN14eA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 11/20] qemu-storage-daemon: Add --export option Date: Mon, 24 Feb 2020 15:29:59 +0100 Message-Id: <20200224143008.13362-12-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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=3Ddisk,name=3Dtest-export,writable=3Don Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/block-core.json | 27 +++++++++++++++++++++++++++ qemu-storage-daemon.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index cdc585385c..48631218fa 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5201,6 +5201,33 @@ ## { 'command': 'nbd-server-stop' } =20 +## +# @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' + } } + ## # @QuorumOpType: # diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 276a412915..5904d3c5b4 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -70,6 +70,11 @@ static void help(void) " [,driver specific parameters...]\n" " configure a block backend\n" "\n" +" --export [type=3D]nbd,device=3D[,name=3D]\n" +" [,writable=3Don|off][,bitmap=3D]\n" +" export the specified block node over NBD\n" +" (requires --nbd-server)\n" +"\n" " --nbd-server addr.type=3Dinet,addr.host=3D,addr.port=3D\n" " [,tls-creds=3D][,tls-authz=3D]\n" " --nbd-server addr.type=3Dunix,addr.path=3D\n" @@ -91,6 +96,7 @@ QEMU_HELP_BOTTOM "\n", =20 enum { OPTION_BLOCKDEV =3D 256, + OPTION_EXPORT, OPTION_NBD_SERVER, OPTION_OBJECT, }; @@ -104,12 +110,24 @@ static QemuOptsList qemu_object_opts =3D { }, }; =20 +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 void process_options(int argc, char *argv[]) { int c; =20 static const struct option long_options[] =3D { {"blockdev", required_argument, NULL, OPTION_BLOCKDEV}, + {"export", required_argument, NULL, OPTION_EXPORT}, {"help", no_argument, NULL, 'h'}, {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER}, {"object", required_argument, NULL, OPTION_OBJECT}, @@ -156,6 +174,19 @@ static void process_options(int argc, char *argv[]) qapi_free_BlockdevOptions(options); break; } + case OPTION_EXPORT: + { + Visitor *v; + BlockExport *export; + + v =3D 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; + } case OPTION_NBD_SERVER: { Visitor *v; --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582554989; cv=none; d=zohomail.com; s=zohoarc; b=KJL/y5WMfktnh7kVuSpmVe9nw6bcG86E5O+SRA6o6C1ZVbb31PTnCxhyLmiaXxrj+oqpnRQwBHZyRTI0F6fjuf1vb8hd5DVPQfBcKl1LdWK8Mki15KcoVfcfBBRJxKoSidu6ELj/6zGaxTnaVi6fogLp3nQtoVmbk9qqZZ8n1mA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554989; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vgvMrZAaJrX0VNGwKnG9ok2caqv8FZvIia/6tr1q6bE=; b=ZeAwhwzHKUvMjiZk89tpuLGYpIUXcDJq3XeRHrEC7IZh8NHrUYuKx9tk+ldjtSA619eOzE0BOUOItuAohJ2pbaq39UfKQCo5yo3Out7zCfhgE5ZDkPTn4Wpd6WnMRQM6w0IJjXj1+AADUHC0pj5X2JcFE0aDw4WBtox1EdH+Cwc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582554989473230.36796910994542; Mon, 24 Feb 2020 06:36:29 -0800 (PST) Received: from localhost ([::1]:37406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6EqS-00038D-BO for importer@patchew.org; Mon, 24 Feb 2020 09:36:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50851) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElB-0002As-2m for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElA-0002Om-1C for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:01 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44931 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6El9-0002OU-TC for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:30:59 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-331-yKRUOOUpMuiBudEvYkhhsA-1; Mon, 24 Feb 2020 09:30:57 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DCDFDB6E; Mon, 24 Feb 2020 14:30:56 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D9BE5C114; Mon, 24 Feb 2020 14:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vgvMrZAaJrX0VNGwKnG9ok2caqv8FZvIia/6tr1q6bE=; b=AergLALY3rBnJVIfTTegb0QTgpN9+Bb9L92jY+TYa14V15NUvwuOxkraO6cY+u+4VH8A2X nhSCbHvAg3ghqh6Lkhb3L40y2JHkYAXl4v92OjEHtX1DAs3Mwb8qHlvdCJK5Tq/X/Ebxnr g7soJX4Vnx4FpeRu8s4plfqoqb0ni+Q= X-MC-Unique: yKRUOOUpMuiBudEvYkhhsA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 12/20] qemu-storage-daemon: Add main loop Date: Mon, 24 Feb 2020 15:30:00 +0100 Message-Id: <20200224143008.13362-13-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Acked-by: Stefan Hajnoczi --- 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 5904d3c5b4..14093ac3a0 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -50,8 +50,16 @@ #include "qemu/option.h" #include "qom/object_interfaces.h" =20 +#include "sysemu/runstate.h" #include "trace/control.h" =20 +static volatile bool exit_requested =3D false; + +void qemu_system_killed(int signal, pid_t pid) +{ + exit_requested =3D true; +} + static void help(void) { printf( @@ -241,6 +249,7 @@ int main(int argc, char *argv[]) =20 error_init(argv[0]); qemu_init_exec_dir(argv[0]); + os_setup_signal_handling(); =20 module_call_init(MODULE_INIT_QOM); module_call_init(MODULE_INIT_TRACE); @@ -256,5 +265,9 @@ int main(int argc, char *argv[]) qemu_init_main_loop(&error_fatal); process_options(argc, argv); =20 + while (!exit_requested) { + main_loop_wait(false); + } + return EXIT_SUCCESS; } diff --git a/Makefile.objs b/Makefile.objs index 25ab313690..5b30537fd9 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -33,6 +33,8 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS =20 storage-daemon-obj-y =3D block/ qom/ storage-daemon-obj-y +=3D blockdev.o blockdev-nbd.o iothread.o +storage-daemon-obj-$(CONFIG_WIN32) +=3D os-win32.o +storage-daemon-obj-$(CONFIG_POSIX) +=3D os-posix.o =20 ###################################################################### # Target independent part of system emulation. The long term path is to --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555123; cv=none; d=zohomail.com; s=zohoarc; b=cq9lrlfrUbFP3Rjb+cH1J+lc78/wrv+177ONfXmjBbksaXJL6axFU3v0QlaNfFW1A92FyZt7vd3vk91aTF54QtcKhykbbv8KG+aLX/Erz9b2b4XL/OIRsLomT2TnFhxl5lJGT4WOzr4sC6gxqIA41mDcMM8MMdARnVQ9CeOj5uU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555123; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VLf1ohxhxrG7UCgf08wgp7qss4L3nBVcimNCVx2etEg=; b=QjH/oFcu8k5BCp/HA2JljQCZVR0bteWkx2cGbw19gfdpt2uLMxk/YekNNsBJMn1VF0xTrPbGmbzmzNmicGgCsR0V+dZYYZwLCEfmgUTLcxfNWbCvGQDsmUf1A6kCkrdyihJ/13GhPbpWrU4BiwI6SH7BoRr+tCqdQ37u4kYlmy8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555123987844.6508895119249; Mon, 24 Feb 2020 06:38:43 -0800 (PST) Received: from localhost ([::1]:37464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Esc-0007tN-Tx for importer@patchew.org; Mon, 24 Feb 2020 09:38:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50886) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElM-0002IK-49 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElK-0002Ri-7G for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:11 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:24138 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ElI-0002Qz-VU for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:10 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-105-bRF-Sl3PME2D2DDd_am2eg-1; Mon, 24 Feb 2020 09:31:01 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFF4D800D54; Mon, 24 Feb 2020 14:31:00 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1AE75C114; Mon, 24 Feb 2020 14:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VLf1ohxhxrG7UCgf08wgp7qss4L3nBVcimNCVx2etEg=; b=FX0yYtSW5uX8SH/9ATj7wlhQ8sERRZpgT8zmtE3dqA7x0Dwlu2nQ4t1ZU3PtMulyG+Xbmf 192imihk8a6lhVpHu1AfJ9OouKgDreLy4uEU0gxJ3lVr9SJHK5R4hl1Ru3WbE/NYbyVqoy b+pzwdq5O/2Y9b+8OAmSqT9glVjAMmQ= X-MC-Unique: bRF-Sl3PME2D2DDd_am2eg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 13/20] qemu-storage-daemon: Add --chardev option Date: Mon, 24 Feb 2020 15:30:01 +0100 Message-Id: <20200224143008.13362-14-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This adds a --chardev option to the storage daemon that works the same as the -chardev option of the system emulator. The syntax of the --chardev option is still considered unstable. We want to QAPIfy it and will potentially make changes to its syntax while converting it. However, we haven't decided yet on a design for the QAPIfication, so QemuOpts will have to do for now. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qemu-storage-daemon.c | 24 ++++++++++++++++++++++++ Makefile | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 14093ac3a0..82fe6cd5f2 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -29,6 +29,7 @@ =20 #include "block/block.h" #include "block/nbd.h" +#include "chardev/char.h" #include "crypto/init.h" =20 #include "qapi/error.h" @@ -78,6 +79,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=3D]nbd,device=3D[,name=3D]\n" " [,writable=3Don|off][,bitmap=3D]\n" " export the specified block node over NBD\n" @@ -104,11 +108,14 @@ QEMU_HELP_BOTTOM "\n", =20 enum { OPTION_BLOCKDEV =3D 256, + OPTION_CHARDEV, OPTION_EXPORT, OPTION_NBD_SERVER, OPTION_OBJECT, }; =20 +extern QemuOptsList qemu_chardev_opts; + static QemuOptsList qemu_object_opts =3D { .name =3D "object", .implied_opt_name =3D "qom-type", @@ -135,6 +142,7 @@ static void process_options(int argc, char *argv[]) =20 static const struct option long_options[] =3D { {"blockdev", required_argument, NULL, OPTION_BLOCKDEV}, + {"chardev", required_argument, NULL, OPTION_CHARDEV}, {"export", required_argument, NULL, OPTION_EXPORT}, {"help", no_argument, NULL, 'h'}, {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER}, @@ -182,6 +190,22 @@ static void process_options(int argc, char *argv[]) qapi_free_BlockdevOptions(options); break; } + case OPTION_CHARDEV: + { + /* TODO This interface is not stable until we QAPIfy it */ + QemuOpts *opts =3D qemu_opts_parse_noisily(&qemu_chardev_o= pts, + optarg, true); + if (opts =3D=3D NULL) { + exit(EXIT_FAILURE); + } + + 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_EXPORT: { Visitor *v; diff --git a/Makefile b/Makefile index 750cff8d0a..50056faf52 100644 --- a/Makefile +++ b/Makefile @@ -576,7 +576,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) =20 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) =20 --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555248; cv=none; d=zohomail.com; s=zohoarc; b=clkHAUXAa5weWaI+MGar0FVOLkt6W51Nk2ZPvPaXo6QGlwc0HJDvwICki7iookv7GMgzOimIGC+zFw+3y34PvUTgj2Oi2rwPDSUxe0rOv4I/ODRiT1CPyrEUxQj1BSXb5Ni8kl5Hu9FPiBhAvSJObKR98xz7EbOupIVA/7G+q4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555248; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yfNnYO1oLkgmrV91jsB6j+KtI4ShOblM1z5HrMOp/uM=; b=aacT9FpI+ZLCip2cxG+Rh91E2AmGFT/GOL4J+HjnoLsIw/4zxv2pwGISgTdnDQcoqAQYyQOU61o8KtIct0vfEeLdh1jFIZE9lDcQZcenXGUSuOXF6g7LlniE820ZSSGKk/XpeweHk3Wq7KduUXYKLxFSkezjRSXq++WJdASTQF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555248263882.8203996814652; Mon, 24 Feb 2020 06:40:48 -0800 (PST) Received: from localhost ([::1]:37514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Eud-0003gL-4V for importer@patchew.org; Mon, 24 Feb 2020 09:40:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50911) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElP-0002J0-3d for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElM-0002ZR-3a for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:13 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:29066 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ElL-0002Rd-EX for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:12 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-za4W7Sr8OYaSOX96IYjTIg-1; Mon, 24 Feb 2020 09:31:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48319800053; Mon, 24 Feb 2020 14:31:05 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05C5D90F5B; Mon, 24 Feb 2020 14:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yfNnYO1oLkgmrV91jsB6j+KtI4ShOblM1z5HrMOp/uM=; b=TVZ50xkn08YON+QMEUGDwzEU5TBO4b5q2TAmKqlQgCqDWIUMaVARycWFaQIf8lc2KAAwXr 0Q8iBi3vjTk254tj9px4hAaXQ1/2gyKX4XDc4EHXxz7NyJgoTkWGacq1eIZy4cSQMoX6rN IT7btVTcikbGXHaZkf5yjaRgndGejV8= X-MC-Unique: za4W7Sr8OYaSOX96IYjTIg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 14/20] stubs: Update monitor stubs for qemu-storage-daemon Date: Mon, 24 Feb 2020 15:30:02 +0100 Message-Id: <20200224143008.13362-15-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Before we can add the monitor to qemu-storage-daemon, we need to add a stubs for monitor_fdsets_cleanup(). We also need to make sure that stubs that are actually implemented in the monitor core aren't linked to qemu-storage-daemon so that we don't get linker errors because of duplicate symbols. This is achieved by moving the stubs in question to a new file stubs/monitor-core.c. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- 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" =20 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; } =20 -void monitor_init_qmp(Chardev *chr, bool pretty) -{ -} - void monitor_init_hmp(Chardev *chr, bool use_readline) { } =20 -void qapi_event_emit(QAPIEvent event, QDict *qdict) +void monitor_fdsets_cleanup(void) { } diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 24062ce7d9..45be5dc0ed 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -19,6 +19,7 @@ stub-obj-y +=3D machine-init-done.o stub-obj-y +=3D migr-blocker.o stub-obj-y +=3D change-state-handler.o stub-obj-y +=3D monitor.o +stub-obj-y +=3D monitor-core.o stub-obj-y +=3D notify-event.o stub-obj-y +=3D qtest.o stub-obj-y +=3D replay.o --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555108; cv=none; d=zohomail.com; s=zohoarc; b=IRo3izLx5QlcjTjRL+21FJkwCHY0dZjzzQJbZJX8VFSrL+jbdPyE0BakueQpmjyFqgEP0DjhaxQwlqGxekrnajAwA9DoXON4BtDJPVHZSVn0zgT6GBstHZnwxr+ouMq2LSPNa7Hz831aA7AKc1XP9vHtMnvCCh/pFWhX89mWCIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555108; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7u4qs3ueT+4Mpmqi03JHp/UeUfPAHiXJgxFRvqiBcEU=; b=BfTmJmnbOzUduBNyXRtTranfNUX79FhuscEqTb9TPH2IPk0Zljmvvvy39gkZQnkKzOWDZV/2OaVxpbViOl2biO/pH8X4y3xyExIAFyL50Ai8SA2YYSDaYSW5v2gJ0nAlsz003wFR2QVRq3ahgMMDBvdALD23hyX9gSrtPa2+ZiQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158255510799749.24816828300993; Mon, 24 Feb 2020 06:38:27 -0800 (PST) Received: from localhost ([::1]:37456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6EsM-0007BQ-6h for importer@patchew.org; Mon, 24 Feb 2020 09:38:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50975) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElT-0002Na-P8 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElR-0002kc-NX for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:19 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57565 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ElP-0002d8-S3 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-148-7JvqXm-KMCGgE_2bIdjE6A-1; Mon, 24 Feb 2020 09:31:08 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 41804107ACC4; Mon, 24 Feb 2020 14:31:07 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9289E5C13F; Mon, 24 Feb 2020 14:31:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7u4qs3ueT+4Mpmqi03JHp/UeUfPAHiXJgxFRvqiBcEU=; b=Assj4TIV7kfvDABqrlKJpBRZZVRoMZnaORDaGgLGAJ5uY7UgKANH+MXZYY/5SOOFfRFk3J m+ih5mtbyUlrk2x7GKvMbeVIyvTQT2PL09rnMaajMEp4RNQT7/gORdd0/Cqp6nkfk7Cod0 dm98MWDlPZuCW2qhDnB2t2iyFTh8TVM= X-MC-Unique: 7JvqXm-KMCGgE_2bIdjE6A-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 15/20] qapi: Create 'pragma' module Date: Mon, 24 Feb 2020 15:30:03 +0100 Message-Id: <20200224143008.13362-16-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Acked-by: Stefan Hajnoczi --- 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-osp= m-status + 'CpuInfoMIPS', # PC, visible through query-cpu + 'CpuInfoTricore', # PC, visible through query-cpu + 'BlockdevVmdkSubformat', # all members, to match VMDK spec spel= lings + 'BlockdevVmdkAdapterType', # legacyESX, to match VMDK spec spelli= ngs + 'QapiErrorClass', # all members, visible through errors + 'UuidInfo', # UUID, visible through query-uuid + 'X86CPURegister32', # all members, visible indirectly thro= ugh qom-get + 'CpuInfo' # CPU, visible through query-cpu + ] } } diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index fe980ce437..43b0ba0dea 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -49,30 +49,7 @@ # ## =20 -{ '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-osp= m-status - 'CpuInfoMIPS', # PC, visible through query-cpu - 'CpuInfoTricore', # PC, visible through query-cpu - 'BlockdevVmdkSubformat', # all members, to match VMDK spec spel= lings - 'BlockdevVmdkAdapterType', # legacyESX, to match VMDK spec spelli= ngs - 'QapiErrorClass', # all members, visible through errors - 'UuidInfo', # UUID, visible through query-uuid - 'X86CPURegister32', # all members, visible indirectly thro= ugh qom-get - 'CpuInfo' # CPU, visible through query-cpu - ] } } +{ 'include': 'pragma.json' } =20 # 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 20fcc37c2c..cf33fd9cc0 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -7,7 +7,7 @@ util-obj-y +=3D qapi-util.o =20 QAPI_COMMON_MODULES =3D audio authz block-core block char common control c= rypto QAPI_COMMON_MODULES +=3D dump error introspect job machine migration misc -QAPI_COMMON_MODULES +=3D net qdev qom rdma rocker run-state sockets tpm +QAPI_COMMON_MODULES +=3D net pragma qdev qom rdma rocker run-state sockets= tpm QAPI_COMMON_MODULES +=3D trace transaction ui QAPI_TARGET_MODULES =3D machine-target misc-target QAPI_MODULES =3D $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES) --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555303; cv=none; d=zohomail.com; s=zohoarc; b=PIcIBmHvygGzNUu67tucGzi75kkeuQlCFjg2joRNdUi5LliYSQYXWdukl/2P8vvd7kBE9iUeeE1L4oi9xbRlcF6MfBbTHvVqErWbbOORaDBrkR9nUQeshbvC6CBYMEFSjSt4NRaWlD/fUs678bTISjA/sX5ZpfFvxP0gFRnEHv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555303; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TEVkE58gDi8LcdZVuY33caFAMSeIEoH80hX4xa4PU9w=; b=OVkwiLHc6o0BooC/wimV5X+ZxoS4c4Q9t5XpA377CP4e4ZWOaAV81r7I6mbS7NK5XdAeN0bbs+2IDeXd2hwRZpIgiSfCv+5p5Pz5PHh1XYIwOYCoLAc+IKdzfY7MQwfAWT2mMIrFz8bZbeVvg2qsnguHxYVeISx+bfEMs21C95Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555303964695.045441420552; Mon, 24 Feb 2020 06:41:43 -0800 (PST) Received: from localhost ([::1]:37538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6EvX-0005Ce-0W for importer@patchew.org; Mon, 24 Feb 2020 09:41:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50977) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElT-0002Nd-Pg for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElR-0002lP-QS for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:19 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:27959 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ElR-0002gO-K8 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-cgPQtB1pNhe05DinyGVCTg-1; Mon, 24 Feb 2020 09:31:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3D0DE107B102; Mon, 24 Feb 2020 14:31:09 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A20F5C114; Mon, 24 Feb 2020 14:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TEVkE58gDi8LcdZVuY33caFAMSeIEoH80hX4xa4PU9w=; b=BPZ66lzxvFOsUggKaSGlkluTAdPRiH0v51qSW2d9RWsjgJCDmmHpBTFxxUJ3V4BGkPMd9D 68L+df9NPji0HVb4vrlTXuAX3KPTbLL7dt7P8WMIBvX7yXZ0dUCBwNXnuNXyS/mmLrTn+K SrSL7frfXVVbkBUKxxmv6PNhDa0q3Ts= X-MC-Unique: cgPQtB1pNhe05DinyGVCTg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 16/20] monitor: Create QAPIfied monitor_init() Date: Mon, 24 Feb 2020 15:30:04 +0100 Message-Id: <20200224143008.13362-17-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This adds a new QAPI-based monitor_init() function. The existing monitor_init_opts() is rewritten to simply put its QemuOpts parameter into a visitor and pass the resulting QAPI object to monitor_init(). This will cause some change in those error messages for the monitor options in the system emulator that are now generated by the visitor rather than explicitly checked in monitor_init_opts(). Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/control.json | 36 ++++++++++++++++++ include/monitor/monitor.h | 2 + monitor/monitor.c | 77 +++++++++++++++++++++------------------ 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/qapi/control.json b/qapi/control.json index 759c20e76f..3ee086aec7 100644 --- a/qapi/control.json +++ b/qapi/control.json @@ -216,3 +216,39 @@ # <- { "return": {} } ## { 'command': 'quit' } + +## +# @MonitorMode: +# +# An enumeration of monitor modes. +# +# @readline: HMP monitor (human-oriented command line interface) +# +# @control: QMP monitor (JSON-based machine interface) +# +# Since: 5.0 +## +{ 'enum': 'MonitorMode', 'data': [ 'readline', 'control' ] } + +## +# @MonitorOptions: +# +# Options to be used for adding a new monitor. +# +# @id: Name of the monitor +# +# @mode: Selects the monitor mode (default: readline) +# +# @pretty: Enables pretty printing (QMP only) +# +# @chardev: Name of a character device to expose the monitor on +# +# Since: 5.0 +## +{ 'struct': 'MonitorOptions', + 'data': { + '*id': 'str', + '*mode': 'MonitorMode', + '*pretty': 'bool', + 'chardev': 'str' + } } diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index b7bdd2bb2a..db1112552c 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -7,6 +7,7 @@ =20 extern __thread Monitor *cur_mon; typedef struct MonitorHMP MonitorHMP; +typedef struct MonitorOptions MonitorOptions; =20 #define QMP_REQ_QUEUE_LEN_MAX 8 =20 @@ -18,6 +19,7 @@ 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(MonitorOptions *opts, Error **errp); int monitor_init_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); =20 diff --git a/monitor/monitor.c b/monitor/monitor.c index c1a6c4460f..cc7ee812eb 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -25,7 +25,9 @@ #include "qemu/osdep.h" #include "monitor-internal.h" #include "qapi/error.h" +#include "qapi/opts-visitor.h" #include "qapi/qapi-emit-events.h" +#include "qapi/qapi-visit-control.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" #include "qemu/error-report.h" @@ -609,50 +611,55 @@ void monitor_init_globals_core(void) NULL); } =20 -int monitor_init_opts(QemuOpts *opts, Error **errp) +int monitor_init(MonitorOptions *opts, Error **errp) { Chardev *chr; - bool qmp; - bool pretty =3D false; - const char *chardev; - const char *mode; - - mode =3D qemu_opt_get(opts, "mode"); - if (mode =3D=3D NULL) { - mode =3D "readline"; - } - if (strcmp(mode, "readline") =3D=3D 0) { - qmp =3D false; - } else if (strcmp(mode, "control") =3D=3D 0) { - qmp =3D true; - } else { - error_setg(errp, "unknown monitor mode \"%s\"", mode); + + chr =3D qemu_chr_find(opts->chardev); + if (chr =3D=3D NULL) { + error_setg(errp, "chardev \"%s\" not found", opts->chardev); return -1; } =20 - if (!qmp && qemu_opt_get(opts, "pretty")) { - warn_report("'pretty' is deprecated for HMP monitors, it has no ef= fect " - "and will be removed in future versions"); - } - if (qemu_opt_get_bool(opts, "pretty", 0)) { - pretty =3D true; + switch(opts->mode) { + case MONITOR_MODE_CONTROL: + monitor_init_qmp(chr, opts->pretty); + break; + case MONITOR_MODE_READLINE: + if (opts->pretty) { + warn_report("'pretty' is deprecated for HMP monitors, it has n= o " + "effect and will be removed in future versions"); + } + monitor_init_hmp(chr, true); + break; + default: + g_assert_not_reached(); } =20 - chardev =3D qemu_opt_get(opts, "chardev"); - if (!chardev) { - error_report("chardev is required"); - exit(1); - } - chr =3D qemu_chr_find(chardev); - if (chr =3D=3D NULL) { - error_setg(errp, "chardev \"%s\" not found", chardev); - return -1; + return 0; +} + +int monitor_init_opts(QemuOpts *opts, Error **errp) +{ + Visitor *v; + MonitorOptions *options; + Error *local_err =3D NULL; + + v =3D opts_visitor_new(opts); + visit_type_MonitorOptions(v, NULL, &options, &local_err); + visit_free(v); + + if (local_err) { + goto out; } =20 - if (qmp) { - monitor_init_qmp(chr, pretty); - } else { - monitor_init_hmp(chr, true); + monitor_init(options, &local_err); + qapi_free_MonitorOptions(options); + +out: + if (local_err) { + error_propagate(errp, local_err); + return -1; } return 0; } --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555376; cv=none; d=zohomail.com; s=zohoarc; b=VRWIxq83cGh0GoFW35ojsYJsEmsj0lHVcZ5c2Ho5wUcVgMzm30dS3ljIaMgUz8tm3LRDiAA2bWerBSOdYmcOPlI5l6o5lSBtTmIP2qK25sSDvQIZG06nfpMcYd7If23vJWDZ0TYR15Uglc76gpXPCSEnSS9pkn8IX7CJbdIbhSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555376; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RiMfids/sR91ZkiBpl2SU1m0+fSIaG59Kqm2zJ3hGLs=; b=W0GXWaAli9RlzqzY+oMdUdF6m2ufx2FXeDKdm+daeUs9bdDXt7q3rCs3RizexcRLSRlwpaxXV0A5n4tGTkkeQLVDUR0pZxWqma3N2ZvTv5KHK8QiWIEZHVuRx4Vt5SWt8n3jYSmU81UWaKooFCgfYK5FE3eoBkAJvg4l2EZyaA4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555376630135.96947193487335; Mon, 24 Feb 2020 06:42:56 -0800 (PST) Received: from localhost ([::1]:37556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Ewg-0007UZ-W0 for importer@patchew.org; Mon, 24 Feb 2020 09:42:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50976) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElT-0002Nc-Pe for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElR-0002kr-OX for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:19 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:59207 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ElP-0002es-T1 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-MBhRyV9kOXCk48Qq0IUcaQ-1; Mon, 24 Feb 2020 09:31:12 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3668FDB60; Mon, 24 Feb 2020 14:31:11 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 874B95C114; Mon, 24 Feb 2020 14:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RiMfids/sR91ZkiBpl2SU1m0+fSIaG59Kqm2zJ3hGLs=; b=JAQCce18vJzbBPj/K1ABgTV60SstESbEfBNmSsq6SJUXN2p75ZGLrmaEY0+lXyqHDEjmqd 5xaR6up2zk1Hu/HWIRtocFKKYaBcSHy1YVD1LXX11EVcq13Jcd9renP4565Bg4pUNF8ea6 OKUj9cH/yc99ki0mP1aPdkaM/gjO8Mk= X-MC-Unique: MBhRyV9kOXCk48Qq0IUcaQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 17/20] qmp: Fail gracefully if chardev is already in use Date: Mon, 24 Feb 2020 15:30:05 +0100 Message-Id: <20200224143008.13362-18-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Trying to attach a QMP monitor to a chardev that is already in use results in a crash because monitor_init_qmp() passes &error_abort to qemu_chr_fe_init(): $ ./x86_64-softmmu/qemu-system-x86_64 --chardev stdio,id=3Dfoo --mon foo,mo= de=3Dcontrol --mon foo,mode=3Dcontrol Unexpected error in qemu_chr_fe_init() at chardev/char-fe.c:220: qemu-system-x86_64: --mon foo,mode=3Dcontrol: Device 'foo' is in use Abgebrochen (Speicherabzug geschrieben) Fix this by allowing monitor_init_qmp() to return an error and passing any error in qemu_chr_fe_init() to its caller instead of aborting. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- include/monitor/monitor.h | 2 +- monitor/monitor.c | 7 ++++++- monitor/qmp.c | 11 +++++++---- stubs/monitor-core.c | 2 +- tests/test-util-sockets.c | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index db1112552c..e55a3b57e0 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -17,7 +17,7 @@ bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); -void monitor_init_qmp(Chardev *chr, bool pretty); +void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp); void monitor_init_hmp(Chardev *chr, bool use_readline); int monitor_init(MonitorOptions *opts, Error **errp); int monitor_init_opts(QemuOpts *opts, Error **errp); diff --git a/monitor/monitor.c b/monitor/monitor.c index cc7ee812eb..af84f53dcd 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -614,6 +614,7 @@ void monitor_init_globals_core(void) int monitor_init(MonitorOptions *opts, Error **errp) { Chardev *chr; + Error *local_err =3D NULL; =20 chr =3D qemu_chr_find(opts->chardev); if (chr =3D=3D NULL) { @@ -623,7 +624,7 @@ int monitor_init(MonitorOptions *opts, Error **errp) =20 switch(opts->mode) { case MONITOR_MODE_CONTROL: - monitor_init_qmp(chr, opts->pretty); + monitor_init_qmp(chr, opts->pretty, &local_err); break; case MONITOR_MODE_READLINE: if (opts->pretty) { @@ -636,6 +637,10 @@ int monitor_init(MonitorOptions *opts, Error **errp) g_assert_not_reached(); } =20 + if (local_err) { + error_propagate(errp, local_err); + return -1; + } return 0; } =20 diff --git a/monitor/qmp.c b/monitor/qmp.c index 8379c8f96e..f89e7daf27 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -395,10 +395,16 @@ static void monitor_qmp_setup_handlers_bh(void *opaqu= e) monitor_list_append(&mon->common); } =20 -void monitor_init_qmp(Chardev *chr, bool pretty) +void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) { MonitorQMP *mon =3D g_new0(MonitorQMP, 1); =20 + if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) { + g_free(mon); + return; + } + qemu_chr_fe_set_echo(&mon->common.chr, true); + /* Note: we run QMP monitor in I/O thread when @chr supports that */ monitor_data_init(&mon->common, true, false, qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT= )); @@ -408,9 +414,6 @@ void monitor_init_qmp(Chardev *chr, bool pretty) qemu_mutex_init(&mon->qmp_queue_lock); mon->qmp_requests =3D g_queue_new(); =20 - qemu_chr_fe_init(&mon->common.chr, chr, &error_abort); - qemu_chr_fe_set_echo(&mon->common.chr, true); - json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); if (mon->common.use_io_thread) { /* diff --git a/stubs/monitor-core.c b/stubs/monitor-core.c index 403c00a6d0..6cff1c4e1d 100644 --- a/stubs/monitor-core.c +++ b/stubs/monitor-core.c @@ -5,7 +5,7 @@ =20 __thread Monitor *cur_mon; =20 -void monitor_init_qmp(Chardev *chr, bool pretty) +void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) { } =20 diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 8ce55efe70..2edb4c539d 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -71,7 +71,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Erro= r **errp) */ __thread Monitor *cur_mon; int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } -void monitor_init_qmp(Chardev *chr, bool pretty) {} +void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) {} void monitor_init_hmp(Chardev *chr, bool use_readline) {} =20 =20 --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555349; cv=none; d=zohomail.com; s=zohoarc; b=amXk5pBgu6+sMcnXkSn0xmVr951NGUUhMCU6G8LrXTJbrnmzDFrPSIgaFySyp373Rs6soXqI4SwT9sAjxKgdhMDPw3c5retf/XkuRiQIL6QrSnyOj4U0EZzb6rkINrYvRTXkL6gKVsWqy/wjHxY4RUavn28BeF/jXGW1Xoor/kI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555349; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hvNwBnsqVm686B7EhVMXO5XRUUPWs6SYXf2u5vxfMn0=; b=aURaQCbnpZ0t1c0nXo2tlTk/FqZxXG82YKi87LrqOHRnoFzVnz2FZYYmxUAijUMInddvYhK2kHcatUGXDNoajINg7iCYnvz6JVSrPfwfjUXTSdXEA9r14BqkbME0HfNrkQr0nUblLgAV1wlePpLK2gjXPqJlg1OZhyEJRJrZbf4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555349073213.09769616173082; Mon, 24 Feb 2020 06:42:29 -0800 (PST) Received: from localhost ([::1]:37550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6EwG-0006bg-1j for importer@patchew.org; Mon, 24 Feb 2020 09:42:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51014) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElW-0002S3-WD for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElV-0002tT-KO for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:22 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30754 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ElT-0002rf-O5 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-P7vLH5eyNKa6tnn6Nm_53A-1; Mon, 24 Feb 2020 09:31:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BD409800D53; Mon, 24 Feb 2020 14:31:14 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 814085C114; Mon, 24 Feb 2020 14:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hvNwBnsqVm686B7EhVMXO5XRUUPWs6SYXf2u5vxfMn0=; b=RpSAJdd9/RLdMvficEUfXDdUE16IzXwaQgtrl+wvzdZoVsJuLotW+9O3BbtiS2t/Dtgs2W cv1q7tFn1b2WZT5OCrRSi+rRAjlrbr9j+kPraZ9iBNwu0hmZem48h27FjD1Bxa1ZdvN4Qb cKRXEyqNS5mJrzvly2wkv0zZ+Zt9lQc= X-MC-Unique: P7vLH5eyNKa6tnn6Nm_53A-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 18/20] hmp: Fail gracefully if chardev is already in use Date: Mon, 24 Feb 2020 15:30:06 +0100 Message-Id: <20200224143008.13362-19-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Trying to attach a HMP monitor to a chardev that is already in use results in a crash because monitor_init_hmp() passes &error_abort to qemu_chr_fe_init(): $ ./x86_64-softmmu/qemu-system-x86_64 --chardev stdio,id=3Dfoo --mon foo --= mon foo QEMU 4.2.50 monitor - type 'help' for more information (qemu) Unexpected error in qemu_chr_fe_init() at chardev/char-fe.c:220: qemu-system-x86_64: --mon foo: Device 'foo' is in use Abgebrochen (Speicherabzug geschrieben) Fix this by allowing monitor_init_hmp() to return an error and passing any error in qemu_chr_fe_init() to its caller instead of aborting. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- include/monitor/monitor.h | 2 +- chardev/char.c | 8 +++++++- gdbstub.c | 2 +- monitor/hmp.c | 8 ++++++-- monitor/monitor.c | 2 +- stubs/monitor.c | 2 +- tests/test-util-sockets.c | 2 +- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index e55a3b57e0..ad823b9edb 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -18,7 +18,7 @@ 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, Error **errp); -void monitor_init_hmp(Chardev *chr, bool use_readline); +void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp); int monitor_init(MonitorOptions *opts, Error **errp); int monitor_init_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); diff --git a/chardev/char.c b/chardev/char.c index 87237568df..e77564060d 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -737,7 +737,13 @@ Chardev *qemu_chr_new_noreplay(const char *label, cons= t char *filename, =20 if (qemu_opt_get_bool(opts, "mux", 0)) { assert(permit_mux_mon); - monitor_init_hmp(chr, true); + monitor_init_hmp(chr, true, &err); + if (err) { + error_report_err(err); + object_unparent(OBJECT(chr)); + chr =3D NULL; + goto out; + } } =20 out: diff --git a/gdbstub.c b/gdbstub.c index ce304ff482..22a2d630cd 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -3367,7 +3367,7 @@ int gdbserver_start(const char *device) /* Initialize a monitor terminal for gdb */ mon_chr =3D qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, NULL, NULL, &error_abort); - monitor_init_hmp(mon_chr, false); + monitor_init_hmp(mon_chr, false, &error_abort); } else { qemu_chr_fe_deinit(&s->chr, true); mon_chr =3D s->mon_chr; diff --git a/monitor/hmp.c b/monitor/hmp.c index 944fa9651e..d598dd02bb 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1399,12 +1399,16 @@ static void monitor_readline_flush(void *opaque) monitor_flush(&mon->common); } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline) +void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) { MonitorHMP *mon =3D g_new0(MonitorHMP, 1); =20 + if (!qemu_chr_fe_init(&mon->common.chr, chr, errp)) { + g_free(mon); + return; + } + monitor_data_init(&mon->common, false, false, false); - qemu_chr_fe_init(&mon->common.chr, chr, &error_abort); =20 mon->use_readline =3D use_readline; if (mon->use_readline) { diff --git a/monitor/monitor.c b/monitor/monitor.c index af84f53dcd..4a36107afb 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -631,7 +631,7 @@ int monitor_init(MonitorOptions *opts, Error **errp) warn_report("'pretty' is deprecated for HMP monitors, it has n= o " "effect and will be removed in future versions"); } - monitor_init_hmp(chr, true); + monitor_init_hmp(chr, true, &local_err); break; default: g_assert_not_reached(); diff --git a/stubs/monitor.c b/stubs/monitor.c index 9403f8e72c..20786ac4ff 100644 --- a/stubs/monitor.c +++ b/stubs/monitor.c @@ -9,7 +9,7 @@ int monitor_get_fd(Monitor *mon, const char *name, Error **= errp) return -1; } =20 -void monitor_init_hmp(Chardev *chr, bool use_readline) +void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) { } =20 diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 2edb4c539d..5fd947c7bf 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -72,7 +72,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Erro= r **errp) __thread Monitor *cur_mon; int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) {} -void monitor_init_hmp(Chardev *chr, bool use_readline) {} +void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) {} =20 =20 static void test_socket_fd_pass_name_good(void) --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555447; cv=none; d=zohomail.com; s=zohoarc; b=UKElkQlnmiEuPF5WO8RFpNDTT1AoqLIP9XJ024Kbx9w4VrApIGtuUR3bQPaYBrpJPZ98xOylyCUGZjWQIvlKiAbzrQJDSpxMlyTj64Y1GZaNkkmPZMPkn2+1Ya4ivUcHV+6lx/UknjvJlbyzl3pRfhs5qFi1FDzAV+lBqxv+Znw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555447; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kBa7U5Scjuxiou/Q3JgDAKz4JwgKecQXFncadPgqf34=; b=NigSMbfRbFRk7tXrCkLgrJMG7eUJXxBgIi83LR7qY6TlXJsk97rN/3NJjkyI+jO8PAaGc2eCKcvM1HB+VZYvj8UdVEk9BgIZyR1xQCeHuzDGs4rDsXR70d2e7Fyo1J1wS6PNk3g2SiWQw3sXoUNwkqZZScm1FpOlYXsee+rChbA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555447526766.9156949309416; Mon, 24 Feb 2020 06:44:07 -0800 (PST) Received: from localhost ([::1]:37588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Exp-0000fz-F8 for importer@patchew.org; Mon, 24 Feb 2020 09:44:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51024) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ElX-0002Tl-Lj for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ElW-0002xc-Km for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:23 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:23557 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ElW-0002wJ-Go for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:22 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-158-LI1KSHlMO5203_ARIcwvhg-1; Mon, 24 Feb 2020 09:31:20 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 605191005510; Mon, 24 Feb 2020 14:31:19 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13D7C91835; Mon, 24 Feb 2020 14:31:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kBa7U5Scjuxiou/Q3JgDAKz4JwgKecQXFncadPgqf34=; b=LEYKl1C1ZRLRU4baDuF6ywvhqY15jmaCyYXywYYSSMOrOP68ScR9aFACk5iUIxNiqzPWZp jzJuHuE+wMkcrED2hY5jtVvHkc4ea1q4j+mC5znF+mtFWPPT0XBfjIVW2smEqZ+gBSiD/7 kTzHIPLlMip2+M+NmR7Bfhi0V+NnVUo= X-MC-Unique: LI1KSHlMO5203_ARIcwvhg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 19/20] monitor: Add allow_hmp parameter to monitor_init() Date: Mon, 24 Feb 2020 15:30:07 +0100 Message-Id: <20200224143008.13362-20-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a new parameter allow_hmp to monitor_init() so that the storage daemon can disable HMP. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/control.json | 3 ++- include/monitor/monitor.h | 2 +- monitor/monitor.c | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/qapi/control.json b/qapi/control.json index 3ee086aec7..85b12fe0fb 100644 --- a/qapi/control.json +++ b/qapi/control.json @@ -237,7 +237,8 @@ # # @id: Name of the monitor # -# @mode: Selects the monitor mode (default: readline) +# @mode: Selects the monitor mode (default: readline in the system +# emulator, control in qemu-storage-daemon) # # @pretty: Enables pretty printing (QMP only) # diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index ad823b9edb..1018d754a6 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -19,7 +19,7 @@ void monitor_init_globals(void); void monitor_init_globals_core(void); void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp); void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp); -int monitor_init(MonitorOptions *opts, Error **errp); +int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp); int monitor_init_opts(QemuOpts *opts, Error **errp); void monitor_cleanup(void); =20 diff --git a/monitor/monitor.c b/monitor/monitor.c index 4a36107afb..7e49914626 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -611,7 +611,7 @@ void monitor_init_globals_core(void) NULL); } =20 -int monitor_init(MonitorOptions *opts, Error **errp) +int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp) { Chardev *chr; Error *local_err =3D NULL; @@ -622,11 +622,19 @@ int monitor_init(MonitorOptions *opts, Error **errp) return -1; } =20 + if (!opts->has_mode) { + opts->mode =3D allow_hmp ? MONITOR_MODE_READLINE : MONITOR_MODE_CO= NTROL; + } + switch(opts->mode) { case MONITOR_MODE_CONTROL: monitor_init_qmp(chr, opts->pretty, &local_err); break; case MONITOR_MODE_READLINE: + if (!allow_hmp) { + error_setg(errp, "Only QMP is supported"); + return -1; + } if (opts->pretty) { warn_report("'pretty' is deprecated for HMP monitors, it has n= o " "effect and will be removed in future versions"); @@ -658,7 +666,7 @@ int monitor_init_opts(QemuOpts *opts, Error **errp) goto out; } =20 - monitor_init(options, &local_err); + monitor_init(options, true, &local_err); qapi_free_MonitorOptions(options); =20 out: --=20 2.20.1 From nobody Sat May 18 09:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582555213; cv=none; d=zohomail.com; s=zohoarc; b=THNEwd9+tUdgepSg1NYxm91j7YVPsrWyvuuLAVShHtTbNgxNWBa40EE5ltD5Y8mq+kFEa2IDjRmv56eY4Aq0gmCfnEP1f03a6iDhpz+CC5KACG003Us1lN2KI2CNHl2/0youXkSclFk3Uyf8ss1PCsxQ/XZb5XnQBH1rnPZR6yE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582555213; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=a1PiXaJSVmbx1ulS/jG8WY8v3Np8wI3+5WYAWlKThsY=; b=bGOUB7yyg5zYe8MNEGo6ZoFq9LtbRS+CrYYDjB+bT8uiVNiYcqOfNjWdQD1AlU3MGVogHIX1hr05zdsdHMh6DjhX+qLljKRwbTlsdJLgLCZM9eUWxCOSXE8HijWMq4yp6R4sIgvZm0WKa9qPWNnkb86SYQV3LmCZUF7RW5ouRG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582555213312760.9970384508053; Mon, 24 Feb 2020 06:40:13 -0800 (PST) Received: from localhost ([::1]:37508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Eu4-0002nh-8m for importer@patchew.org; Mon, 24 Feb 2020 09:40:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51093) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Elh-0002jm-9y for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Elf-0003Y7-8H for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:33 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50400 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Elf-0003T7-3o for qemu-devel@nongnu.org; Mon, 24 Feb 2020 09:31:31 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-HRmDJzHYPJGEEd9xnI6B-A-1; Mon, 24 Feb 2020 09:31:25 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02F88DB60; Mon, 24 Feb 2020 14:31:24 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-134.ams2.redhat.com [10.36.117.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABB735C13F; Mon, 24 Feb 2020 14:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a1PiXaJSVmbx1ulS/jG8WY8v3Np8wI3+5WYAWlKThsY=; b=EPJ0DhKOrtQE+7g/Mlh4WR2dj8CAn423MGIcFLLxkZkGGz7RnpSb55i7Hw+YGytknPUWh3 TEj3pcWkpg59GDVZ+rY688O1yEWQ8RYAUh4G/H/X3uzyCvTB2sdQOmizTvcrt4dW7IuiEi NdPmih55fI7uudoGG7yvMdWVFsAqs20= X-MC-Unique: HRmDJzHYPJGEEd9xnI6B-A-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 20/20] qemu-storage-daemon: Add --monitor option Date: Mon, 24 Feb 2020 15:30:08 +0100 Message-Id: <20200224143008.13362-21-kwolf@redhat.com> In-Reply-To: <20200224143008.13362-1-kwolf@redhat.com> References: <20200224143008.13362-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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, qemu-devel@nongnu.org, armbru@redhat.com, coiby.xu@gmail.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. The --monitor options currently allows to create multiple monitors with the same ID. This part of the interface is considered unstable. We will reject such configurations as soon as we have a design for the monitor subsystem to perform these checks. (In the system emulator, we depend on QemuOpts rejecting duplicate IDs.) Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- qapi/transaction.json | 2 +- qemu-storage-daemon.c | 47 ++++++++++++++++++++++++++-- scripts/qapi/gen.py | 5 +++ Makefile | 33 +++++++++++++++++++ Makefile.objs | 4 +-- monitor/Makefile.objs | 2 ++ qapi/Makefile.objs | 5 +++ storage-daemon/Makefile.objs | 1 + storage-daemon/qapi/Makefile.objs | 1 + storage-daemon/qapi/qapi-schema.json | 26 +++++++++++++++ 10 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 storage-daemon/Makefile.objs create mode 100644 storage-daemon/qapi/Makefile.objs create mode 100644 storage-daemon/qapi/qapi-schema.json diff --git a/qapi/transaction.json b/qapi/transaction.json index 04301f1be7..b6c11158f0 100644 --- a/qapi/transaction.json +++ b/qapi/transaction.json @@ -5,7 +5,7 @@ # =3D Transactions ## =20 -{ 'include': 'block.json' } +{ 'include': 'block-core.json' } =20 ## # @Abort: diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 82fe6cd5f2..dd128978cc 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -31,13 +31,15 @@ #include "block/nbd.h" #include "chardev/char.h" #include "crypto/init.h" +#include "monitor/monitor.h" +#include "monitor/monitor-internal.h" =20 #include "qapi/error.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/qapi-visit-control.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" =20 #include "qemu-common.h" @@ -51,6 +53,9 @@ #include "qemu/option.h" #include "qom/object_interfaces.h" =20 +#include "storage-daemon/qapi/qapi-commands.h" +#include "storage-daemon/qapi/qapi-init-commands.h" + #include "sysemu/runstate.h" #include "trace/control.h" =20 @@ -61,6 +66,11 @@ void qemu_system_killed(int signal, pid_t pid) exit_requested =3D true; } =20 +void qmp_quit(Error **errp) +{ + exit_requested =3D true; +} + static void help(void) { printf( @@ -87,6 +97,9 @@ static void help(void) " export the specified block node over NBD\n" " (requires --nbd-server)\n" "\n" +" --monitor [chardev=3D]name[,mode=3Dcontrol][,pretty[=3Don|off]]\n" +" configure a QMP monitor\n" +"\n" " --nbd-server addr.type=3Dinet,addr.host=3D,addr.port=3D\n" " [,tls-creds=3D][,tls-authz=3D]\n" " --nbd-server addr.type=3Dunix,addr.path=3D\n" @@ -110,6 +123,7 @@ enum { OPTION_BLOCKDEV =3D 256, OPTION_CHARDEV, OPTION_EXPORT, + OPTION_MONITOR, OPTION_NBD_SERVER, OPTION_OBJECT, }; @@ -125,6 +139,17 @@ static QemuOptsList qemu_object_opts =3D { }, }; =20 +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) { @@ -145,6 +170,7 @@ static void process_options(int argc, char *argv[]) {"chardev", required_argument, NULL, OPTION_CHARDEV}, {"export", required_argument, NULL, OPTION_EXPORT}, {"help", no_argument, NULL, 'h'}, + {"monitor", required_argument, NULL, OPTION_MONITOR}, {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER}, {"object", required_argument, NULL, OPTION_OBJECT}, {"trace", required_argument, NULL, 'T'}, @@ -219,6 +245,21 @@ static void process_options(int argc, char *argv[]) qapi_free_BlockExport(export); break; } + case OPTION_MONITOR: + { + Visitor *v; + MonitorOptions *monitor; + + v =3D qobject_input_visitor_new_str(optarg, "chardev", + &error_fatal); + visit_type_MonitorOptions(v, NULL, &monitor, &error_fatal); + visit_free(v); + + /* TODO Catch duplicate monitor IDs */ + monitor_init(monitor, false, &error_fatal); + qapi_free_MonitorOptions(monitor); + break; + } case OPTION_NBD_SERVER: { Visitor *v; @@ -280,6 +321,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(); =20 if (!trace_init_backends()) { return EXIT_FAILURE; diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 95afae0615..e20cdbc503 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -45,6 +45,11 @@ class QAPIGen(object): return '' =20 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 =3D os.path.join(output_dir, self.fname) dir =3D os.path.dirname(pathname) if dir: diff --git a/Makefile b/Makefile index 50056faf52..b253ad5863 100644 --- a/Makefile +++ b/Makefile @@ -128,7 +128,28 @@ GENERATED_QAPI_FILES +=3D $(QAPI_MODULES:%=3Dqapi/qapi= -events-%.c) GENERATED_QAPI_FILES +=3D qapi/qapi-introspect.c qapi/qapi-introspect.h GENERATED_QAPI_FILES +=3D qapi/qapi-doc.texi =20 +# The following list considers only the storage daemon main module. All ot= her +# modules are currently shared with the main schema, so we don't actually +# generate additional files. + +GENERATED_STORAGE_DAEMON_QAPI_FILES =3D storage-daemon/qapi/qapi-commands.h +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-commands= .c +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-emit-eve= nts.h +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-emit-eve= nts.c +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-events.h +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-events.c +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-init-com= mands.h +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-init-com= mands.c +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-introspe= ct.h +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-introspe= ct.c +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-types.h +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-types.c +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-visit.h +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-visit.c +GENERATED_STORAGE_DAEMON_QAPI_FILES +=3D storage-daemon/qapi/qapi-doc.texi + generated-files-y +=3D $(GENERATED_QAPI_FILES) +generated-files-y +=3D $(GENERATED_STORAGE_DAEMON_QAPI_FILES) =20 generated-files-y +=3D trace/generated-tcg-tracers.h =20 @@ -638,6 +659,17 @@ qapi-gen-timestamp: $(qapi-modules) $(qapi-py) "GEN","$(@:%-timestamp=3D%)") @>$@ =20 +qapi-modules-storage-daemon =3D \ + $(SRC_PATH)/storage-daemon/qapi/qapi-schema.json \ + $(QAPI_MODULES_STORAGE_DAEMON:%=3D$(SRC_PATH)/qapi/%.json) + +$(GENERATED_STORAGE_DAEMON_QAPI_FILES): storage-daemon/qapi/qapi-gen-times= tamp ; +storage-daemon/qapi/qapi-gen-timestamp: $(qapi-modules-storage-daemon) $(q= api-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-gen.py \ + -o "storage-daemon/qapi" $<, \ + "GEN","$(@:%-timestamp=3D%)") + @>$@ + QGALIB_GEN=3D$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-vi= sit.h qga-qapi-commands.h qga-qapi-init-commands.h) $(qga-obj-y): $(QGALIB_GEN) =20 @@ -736,6 +768,7 @@ clean: recurse-clean rm -f trace/generated-tracers-dtrace.h* rm -f $(foreach f,$(generated-files-y),$(f) $(f)-timestamp) rm -f qapi-gen-timestamp + rm -f storage-daemon/qapi/qapi-gen-timestamp rm -rf qga/qapi-generated rm -f config-all-devices.mak =20 diff --git a/Makefile.objs b/Makefile.objs index 5b30537fd9..9b2b01587d 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -31,8 +31,8 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS # storage-daemon-obj-y is code used by qemu-storage-daemon (these objects = are # used for system emulation, too, but specified separately there) =20 -storage-daemon-obj-y =3D block/ qom/ -storage-daemon-obj-y +=3D blockdev.o blockdev-nbd.o iothread.o +storage-daemon-obj-y =3D block/ monitor/ qapi/ qom/ storage-daemon/ +storage-daemon-obj-y +=3D blockdev.o blockdev-nbd.o iothread.o job-qmp.o storage-daemon-obj-$(CONFIG_WIN32) +=3D os-win32.o storage-daemon-obj-$(CONFIG_POSIX) +=3D os-posix.o =20 diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs index 9244d90859..a8533c9dd7 100644 --- a/monitor/Makefile.objs +++ b/monitor/Makefile.objs @@ -2,3 +2,5 @@ obj-y +=3D misc.o common-obj-y +=3D monitor.o qmp.o hmp.o common-obj-y +=3D qmp-cmds.o qmp-cmds-control.o common-obj-y +=3D hmp-cmds.o + +storage-daemon-obj-y +=3D monitor.o qmp.o qmp-cmds-control.o diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index cf33fd9cc0..4673ab7490 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -31,3 +31,8 @@ obj-y +=3D qapi-events.o obj-y +=3D $(QAPI_TARGET_MODULES:%=3Dqapi-commands-%.o) obj-y +=3D qapi-commands.o obj-y +=3D qapi-init-commands.o + +QAPI_MODULES_STORAGE_DAEMON =3D block-core char common control crypto +QAPI_MODULES_STORAGE_DAEMON +=3D introspect job qom sockets pragma transac= tion + +storage-daemon-obj-y +=3D $(QAPI_MODULES_STORAGE_DAEMON:%=3Dqapi-commands-= %.o) 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 +=3D qapi/ diff --git a/storage-daemon/qapi/Makefile.objs b/storage-daemon/qapi/Makefi= le.objs new file mode 100644 index 0000000000..8a4b220c96 --- /dev/null +++ b/storage-daemon/qapi/Makefile.objs @@ -0,0 +1 @@ +storage-daemon-obj-y +=3D qapi-commands.o qapi-init-commands.o qapi-intros= pect.o diff --git a/storage-daemon/qapi/qapi-schema.json b/storage-daemon/qapi/qap= i-schema.json new file mode 100644 index 0000000000..14f4f8fe61 --- /dev/null +++ b/storage-daemon/qapi/qapi-schema.json @@ -0,0 +1,26 @@ +# -*- Mode: Python -*- + +# Note that modules are shared with the QEMU main schema under the assumpt= ion +# that the storage daemon schema is a subset of the main schema. For the s= hared +# modules, no code is generated here, but we reuse the code files generated +# from the main schema. +# +# If you wish to extend the storage daemon schema to contain things that a= re +# not in the main schema, be aware that array types of types defined in sh= ared +# modules are only generated if an array of the respective type is already= used +# in the main schema. Therefore, if you use such arrays, you may need to d= efine +# the array type in the main schema, even if it is unused outside of the +# storage daemon. + +{ 'include': '../../qapi/pragma.json' } + +{ 'include': '../../qapi/block-core.json' } +{ 'include': '../../qapi/char.json' } +{ 'include': '../../qapi/common.json' } +{ 'include': '../../qapi/control.json' } +{ 'include': '../../qapi/crypto.json' } +{ 'include': '../../qapi/introspect.json' } +{ 'include': '../../qapi/job.json' } +{ 'include': '../../qapi/qom.json' } +{ 'include': '../../qapi/sockets.json' } +{ 'include': '../../qapi/transaction.json' } --=20 2.20.1