From nobody Sun Feb 8 18:43:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505376017152566.0689434638233; Thu, 14 Sep 2017 01:00:17 -0700 (PDT) Received: from localhost ([::1]:46222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP4K-0006m0-Cj for importer@patchew.org; Thu, 14 Sep 2017 04:00:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwk-0007fq-TC for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwh-0008SV-Oy for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwh-0008RE-HE for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 843FFA78C; Thu, 14 Sep 2017 07:52:22 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD511619B8; Thu, 14 Sep 2017 07:52:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 843FFA78C Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 14 Sep 2017 15:50:35 +0800 Message-Id: <1505375436-28439-15-git-send-email-peterx@redhat.com> In-Reply-To: <1505375436-28439-1-git-send-email-peterx@redhat.com> References: <1505375436-28439-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 14 Sep 2017 07:52:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 14/15] qmp: support out-of-band (oob) execution X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , Juan Quintela , Markus Armbruster , peterx@redhat.com, mdroth@linux.vnet.ibm.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Having "allow-oob" to true for a command does not mean that this command will always be run in out-of-band mode. The out-of-band quick path will only be executed if we specify the extra "run-oob" flag when sending the QMP request: { "execute": "command-that-allows-oob", "arguments": { ... }, "control": { "run-oob": true } } The "control" key is introduced to store this extra flag. "control" field is used to store arguments that are shared by all the commands, rather than command specific arguments. Let "run-oob" be the first. Signed-off-by: Peter Xu --- docs/devel/qapi-code-gen.txt | 10 ++++++++++ include/qapi/qmp/dispatch.h | 1 + monitor.c | 11 +++++++++++ qapi/qmp-dispatch.c | 34 ++++++++++++++++++++++++++++++++++ trace-events | 2 ++ 5 files changed, 58 insertions(+) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 61fa167..47d16bb 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -665,6 +665,16 @@ allowed to run out-of-band can also be introspected us= ing query-qmp-schema command. Please see the section "Client JSON Protocol introspection" for more information. =20 +To execute a command in out-of-band way, we need to specify the +"control" field in the request, with "run-oob" set to true. Example: + + =3D> { "execute": "command-support-oob", + "arguments": { ... }, + "control": { "run-oob": true } } + <=3D { "return": { } } + +Without it, even the commands that supports out-of-band execution will +still be run in-band. =20 =3D=3D=3D Events =3D=3D=3D =20 diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index b767988..ee2b8ce 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -49,6 +49,7 @@ bool qmp_command_is_enabled(const QmpCommand *cmd); const char *qmp_command_name(const QmpCommand *cmd); bool qmp_has_success_response(const QmpCommand *cmd); QObject *qmp_build_error_object(Error *err); +bool qmp_is_oob(const QObject *request); =20 typedef void (*qmp_cmd_callback_fn)(QmpCommand *cmd, void *opaque); =20 diff --git a/monitor.c b/monitor.c index 599ea36..cb96204 100644 --- a/monitor.c +++ b/monitor.c @@ -3928,6 +3928,7 @@ static void monitor_qmp_bh_dispatcher(void *data) if (!req_obj) { break; } + trace_monitor_qmp_cmd_in_band(qobject_get_str(req_obj->id)); monitor_qmp_dispatch_one(req_obj); } } @@ -3963,6 +3964,16 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens, req_obj->id =3D id; req_obj->req =3D req; =20 + if (qmp_is_oob(req)) { + /* + * Trigger fast-path to handle the out-of-band request, by + * executing the command directly in parser. + */ + trace_monitor_qmp_cmd_out_of_band(qobject_get_str(req_obj->id)); + monitor_qmp_dispatch_one(req_obj); + return; + } + /* * Put the request to the end of queue so that requests will be * handled in time order. Ownership for req_obj, req, id, diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index b41fa17..9a05dfa 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -52,6 +52,12 @@ static QDict *qmp_dispatch_check_obj(const QObject *requ= est, Error **errp) "QMP input member 'arguments' must be an object= "); return NULL; } + } else if (!strcmp(arg_name, "control")) { + if (qobject_type(arg_obj) !=3D QTYPE_QDICT) { + error_setg(errp, + "QMP input member 'control' must be an object"); + return NULL; + } } else { error_setg(errp, "QMP input member '%s' is unexpected", arg_name); @@ -122,6 +128,34 @@ QObject *qmp_build_error_object(Error *err) error_get_pretty(err)); } =20 +/* + * Detect whether a request should be run out-of-band, by quickly + * peeking at whether we have: { "control": { "run-oob": True } }. By + * default commands are run in-band. + */ +bool qmp_is_oob(const QObject *request) +{ + QDict *dict; + QBool *bool_obj; + + dict =3D qobject_to_qdict(request); + if (!dict) { + return false; + } + + dict =3D qdict_get_qdict(dict, "control"); + if (!dict) { + return false; + } + + bool_obj =3D qobject_to_qbool(qdict_get(dict, "run-oob")); + if (!bool_obj) { + return false; + } + + return qbool_get_bool(bool_obj); +} + QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request) { Error *err =3D NULL; diff --git a/trace-events b/trace-events index 1f50f56..f7900a6 100644 --- a/trace-events +++ b/trace-events @@ -47,6 +47,8 @@ monitor_protocol_event_emit(uint32_t event, void *data) "= event=3D%d data=3D%p" monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "= event=3D%d data=3D%p rate=3D%" PRId64 handle_hmp_command(void *mon, const char *cmdline) "mon %p cmdline: %s" handle_qmp_command(void *mon, const char *req) "mon %p req: %s" +monitor_qmp_cmd_in_band(const char *id) "%s" +monitor_qmp_cmd_out_of_band(const char *id) "%s" =20 # dma-helpers.c dma_blk_io(void *dbs, void *bs, int64_t offset, bool to_dev) "dbs=3D%p bs= =3D%p offset=3D%" PRId64 " to_dev=3D%d" --=20 2.7.4