From nobody Sun Feb 8 05:37:03 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 15053755786221022.6005061699482; Thu, 14 Sep 2017 00:52:58 -0700 (PDT) Received: from localhost ([::1]:46190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOxF-0007oJ-Rc for importer@patchew.org; Thu, 14 Sep 2017 03:52:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOvK-00063v-Md for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:50:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvJ-0006Sf-Mr for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:50:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37266) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvJ-0006Rs-8O for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:50:57 -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 43B6A5F7B0; Thu, 14 Sep 2017 07:50:56 +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 638FD60F9F; Thu, 14 Sep 2017 07:50:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 43B6A5F7B0 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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:22 +0800 Message-Id: <1505375436-28439-2-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> MIME-Version: 1.0 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.39]); Thu, 14 Sep 2017 07:50:56 +0000 (UTC) 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: 209.132.183.28 Subject: [Qemu-devel] [RFC 01/15] char-io: fix possible race on IOWatchPoll 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-Type: text/plain; charset="utf-8" This is not a problem if we are only having one single loop thread like before. However, after per-monitor thread is introduced, this is not true any more, and the race can happen. The race can be triggered with "make check -j8" sometimes: qemu-system-x86_64: /root/git/qemu/chardev/char-io.c:91: io_watch_poll_finalize: Assertion `iwp->src =3D=3D NULL' failed. This patch keeps the reference for the watch object when creating in io_add_watch_poll(), so that the object will never be released in the context main loop, especially when the context loop is running in another standalone thread. Meanwhile, when we want to remove the watch object, we always first detach the watch object from its owner context, then we continue with the cleanup. Without this patch, calling io_remove_watch_poll() in main loop thread is not thread-safe, since the other per-monitor thread may be modifying the watch object at the same time. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu --- chardev/char-io.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/chardev/char-io.c b/chardev/char-io.c index f810524..3828c20 100644 --- a/chardev/char-io.c +++ b/chardev/char-io.c @@ -122,7 +122,6 @@ GSource *io_add_watch_poll(Chardev *chr, g_free(name); =20 g_source_attach(&iwp->parent, context); - g_source_unref(&iwp->parent); return (GSource *)iwp; } =20 @@ -131,12 +130,24 @@ static void io_remove_watch_poll(GSource *source) IOWatchPoll *iwp; =20 iwp =3D io_watch_poll_from_source(source); + + /* + * Here the order of destruction really matters. We need to first + * detach the IOWatchPoll object from the context (which may still + * be running in another loop thread), only after that could we + * continue to operate on iwp->src, or there may be race condition + * between current thread and the context loop thread. + * + * Let's blame the glib bug mentioned in commit 2b3167 (again) for + * this extra complexity. + */ + g_source_destroy(&iwp->parent); if (iwp->src) { g_source_destroy(iwp->src); g_source_unref(iwp->src); iwp->src =3D NULL; } - g_source_destroy(&iwp->parent); + g_source_unref(&iwp->parent); } =20 void remove_fd_in_watch(Chardev *chr) --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505375681858958.062190782591; Thu, 14 Sep 2017 00:54:41 -0700 (PDT) Received: from localhost ([::1]:46196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOyv-00019v-5g for importer@patchew.org; Thu, 14 Sep 2017 03:54:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOvR-0006AK-BA for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvO-0006Wv-5h for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49996) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvN-0006Vy-Vp for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:02 -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 EEA1C7EBD5; Thu, 14 Sep 2017 07:51:00 +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 B3326619BE; Thu, 14 Sep 2017 07:50:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EEA1C7EBD5 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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:23 +0800 Message-Id: <1505375436-28439-3-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.27]); Thu, 14 Sep 2017 07:51:01 +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 02/15] qobject: allow NULL for qstring_get_str() 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" Then I can get NULL rather than crash when calling things like: qstring_get_str(qobject_to_qstring(object)); when key does not exist. CC: Markus Armbruster Signed-off-by: Peter Xu --- qobject/qstring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qobject/qstring.c b/qobject/qstring.c index 5da7b5f..c499fec 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -125,7 +125,7 @@ QString *qobject_to_qstring(const QObject *obj) */ const char *qstring_get_str(const QString *qstring) { - return qstring->string; + return qstring ? qstring->string : NULL; } =20 /** --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505375838597600.774496328057; Thu, 14 Sep 2017 00:57:18 -0700 (PDT) Received: from localhost ([::1]:46209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP1Q-0003mJ-J7 for importer@patchew.org; Thu, 14 Sep 2017 03:57:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOva-0006K7-Gh for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvX-0006iI-E1 for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53670) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvX-0006hh-7m for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:11 -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 2140DC0587E3; Thu, 14 Sep 2017 07:51:10 +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 6CD07619B8; Thu, 14 Sep 2017 07:51:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2140DC0587E3 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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:24 +0800 Message-Id: <1505375436-28439-4-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.32]); Thu, 14 Sep 2017 07:51:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 03/15] qobject: introduce qobject_to_str() 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" A quick way to fetch string from qobject when it's a QString. Signed-off-by: Peter Xu --- include/qapi/qmp/qstring.h | 1 + qobject/qstring.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index 10076b7..bfdfa46 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -27,6 +27,7 @@ QString *qstring_from_str(const char *str); QString *qstring_from_substr(const char *str, int start, int end); size_t qstring_get_length(const QString *qstring); const char *qstring_get_str(const QString *qstring); +const char *qobject_get_str(const QObject *qstring); void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str); void qstring_append_chr(QString *qstring, int c); diff --git a/qobject/qstring.c b/qobject/qstring.c index c499fec..103efaf 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -129,6 +129,17 @@ const char *qstring_get_str(const QString *qstring) } =20 /** + * qstring_get_str(): Return a pointer of the backstore string + * + * NOTE: the string will only be returned if the object is QString, + * otherwise NULL is returned. + */ +const char *qobject_get_str(const QObject *qstring) +{ + return qstring_get_str(qobject_to_qstring(qstring)); +} + +/** * qstring_destroy_obj(): Free all memory allocated by a QString * object */ --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505375734989625.7503228350909; Thu, 14 Sep 2017 00:55:34 -0700 (PDT) Received: from localhost ([::1]:46200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOzm-0002DI-6G for importer@patchew.org; Thu, 14 Sep 2017 03:55:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOvd-0006N0-J0 for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvc-0006pO-SW for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvc-0006of-Ld for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:16 -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 A8998883BC; Thu, 14 Sep 2017 07:51:15 +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 91F9E619B8; Thu, 14 Sep 2017 07:51:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A8998883BC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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:25 +0800 Message-Id: <1505375436-28439-5-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.26]); Thu, 14 Sep 2017 07:51:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 04/15] monitor: move skip_flush into monitor_data_init 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" It's part of the data init. Collect it. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- monitor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 9239f7a..8b32519 100644 --- a/monitor.c +++ b/monitor.c @@ -568,13 +568,14 @@ static void monitor_qapi_event_init(void) =20 static void handle_hmp_command(Monitor *mon, const char *cmdline); =20 -static void monitor_data_init(Monitor *mon) +static void monitor_data_init(Monitor *mon, bool skip_flush) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); mon->outbuf =3D qstring_new(); /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; + mon->skip_flush =3D skip_flush; } =20 static void monitor_data_destroy(Monitor *mon) @@ -594,8 +595,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; Monitor *old_mon, hmp; =20 - monitor_data_init(&hmp); - hmp.skip_flush =3D true; + monitor_data_init(&hmp, true); =20 old_mon =3D cur_mon; cur_mon =3D &hmp; @@ -4098,7 +4098,7 @@ void monitor_init(Chardev *chr, int flags) } =20 mon =3D g_malloc(sizeof(*mon)); - monitor_data_init(mon); + monitor_data_init(mon, false); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505375752448487.7694995309248; Thu, 14 Sep 2017 00:55:52 -0700 (PDT) Received: from localhost ([::1]:46204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP03-0002W6-Li for importer@patchew.org; Thu, 14 Sep 2017 03:55:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOvk-0006T0-FV for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvh-0006tQ-Ar for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29950) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvh-0006sh-0x for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:21 -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 0A3E1356D6; Thu, 14 Sep 2017 07:51:20 +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 2487C756A4; Thu, 14 Sep 2017 07:51:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A3E1356D6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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:26 +0800 Message-Id: <1505375436-28439-6-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.30]); Thu, 14 Sep 2017 07:51:20 +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 05/15] qjson: add "opaque" field to JSONMessageParser 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" It'll be passed to emit() as well when it happens. Signed-off-by: Peter Xu --- include/qapi/qmp/json-streamer.h | 8 ++++++-- monitor.c | 7 ++++--- qga/main.c | 5 +++-- qobject/json-streamer.c | 7 +++++-- qobject/qjson.c | 5 +++-- tests/libqtest.c | 5 +++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/qapi/qmp/json-streamer.h b/include/qapi/qmp/json-strea= mer.h index 00d8a23..b83270c 100644 --- a/include/qapi/qmp/json-streamer.h +++ b/include/qapi/qmp/json-streamer.h @@ -25,16 +25,20 @@ typedef struct JSONToken { =20 typedef struct JSONMessageParser { - void (*emit)(struct JSONMessageParser *parser, GQueue *tokens); + void (*emit)(struct JSONMessageParser *parser, GQueue *tokens, void *o= paque); JSONLexer lexer; int brace_count; int bracket_count; GQueue *tokens; uint64_t token_size; + /* To be passed in when emit(). */ + void *opaque; } JSONMessageParser; =20 void json_message_parser_init(JSONMessageParser *parser, - void (*func)(JSONMessageParser *, GQueue *)); + void (*func)(JSONMessageParser *, GQueue *, + void *opaque), + void *opaque); =20 int json_message_parser_feed(JSONMessageParser *parser, const char *buffer, size_t size); diff --git a/monitor.c b/monitor.c index 8b32519..9096b64 100644 --- a/monitor.c +++ b/monitor.c @@ -3817,7 +3817,8 @@ static int monitor_can_read(void *opaque) return (mon->suspend_cnt =3D=3D 0) ? 1 : 0; } =20 -static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) +static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens, + void *opaque) { QObject *req, *rsp =3D NULL, *id =3D NULL; QDict *qdict =3D NULL; @@ -3964,7 +3965,7 @@ static void monitor_qmp_event(void *opaque, int event) break; case CHR_EVENT_CLOSED: json_message_parser_destroy(&mon->qmp.parser); - json_message_parser_init(&mon->qmp.parser, handle_qmp_command); + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NUL= L); mon_refcount--; monitor_fdsets_cleanup(); break; @@ -4114,7 +4115,7 @@ void monitor_init(Chardev *chr, int flags) qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_= read, monitor_qmp_event, NULL, mon, NULL, true); qemu_chr_fe_set_echo(&mon->chr, true); - json_message_parser_init(&mon->qmp.parser, handle_qmp_command); + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NUL= L); } else { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read, monitor_event, NULL, mon, NULL, true); diff --git a/qga/main.c b/qga/main.c index 62a6275..3b5ebbc 100644 --- a/qga/main.c +++ b/qga/main.c @@ -593,7 +593,8 @@ static void process_command(GAState *s, QDict *req) } =20 /* handle requests/control events coming in over the channel */ -static void process_event(JSONMessageParser *parser, GQueue *tokens) +static void process_event(JSONMessageParser *parser, GQueue *tokens, + void *opaque) { GAState *s =3D container_of(parser, GAState, parser); QDict *qdict; @@ -1320,7 +1321,7 @@ static int run_agent(GAState *s, GAConfig *config, in= t socket_activation) s->command_state =3D ga_command_state_new(); ga_command_state_init(s, s->command_state); ga_command_state_init_all(s->command_state); - json_message_parser_init(&s->parser, process_event); + json_message_parser_init(&s->parser, process_event, NULL); =20 #ifndef _WIN32 if (!register_signal_handlers()) { diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index c51c202..12865d5 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -102,18 +102,21 @@ out_emit: */ tokens =3D parser->tokens; parser->tokens =3D g_queue_new(); - parser->emit(parser, tokens); + parser->emit(parser, tokens, parser->opaque); parser->token_size =3D 0; } =20 void json_message_parser_init(JSONMessageParser *parser, - void (*func)(JSONMessageParser *, GQueue *)) + void (*func)(JSONMessageParser *, + GQueue *, void *opaque), + void *opaque) { parser->emit =3D func; parser->brace_count =3D 0; parser->bracket_count =3D 0; parser->tokens =3D g_queue_new(); parser->token_size =3D 0; + parser->opaque =3D opaque; =20 json_lexer_init(&parser->lexer, json_message_process_token); } diff --git a/qobject/qjson.c b/qobject/qjson.c index 2e09308..f9766fe 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -28,7 +28,8 @@ typedef struct JSONParsingState Error *err; } JSONParsingState; =20 -static void parse_json(JSONMessageParser *parser, GQueue *tokens) +static void parse_json(JSONMessageParser *parser, GQueue *tokens, + void *opaque) { JSONParsingState *s =3D container_of(parser, JSONParsingState, parser); =20 @@ -41,7 +42,7 @@ QObject *qobject_from_jsonv(const char *string, va_list *= ap, Error **errp) =20 state.ap =3D ap; =20 - json_message_parser_init(&state.parser, parse_json); + json_message_parser_init(&state.parser, parse_json, NULL); json_message_parser_feed(&state.parser, string, strlen(string)); json_message_parser_flush(&state.parser); json_message_parser_destroy(&state.parser); diff --git a/tests/libqtest.c b/tests/libqtest.c index 0c12b38..fbd8e12 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -387,7 +387,8 @@ typedef struct { QDict *response; } QMPResponseParser; =20 -static void qmp_response(JSONMessageParser *parser, GQueue *tokens) +static void qmp_response(JSONMessageParser *parser, GQueue *tokens, + void *opaque) { QMPResponseParser *qmp =3D container_of(parser, QMPResponseParser, par= ser); QObject *obj; @@ -409,7 +410,7 @@ QDict *qmp_fd_receive(int fd) bool log =3D getenv("QTEST_LOG") !=3D NULL; =20 qmp.response =3D NULL; - json_message_parser_init(&qmp.parser, qmp_response); + json_message_parser_init(&qmp.parser, qmp_response, NULL); while (!qmp.response) { ssize_t len; char c; --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505375706581940.3714521260428; Thu, 14 Sep 2017 00:55:06 -0700 (PDT) Received: from localhost ([::1]:46197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOzJ-0001Yc-RM for importer@patchew.org; Thu, 14 Sep 2017 03:55:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOvu-0006YQ-42 for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvq-00071H-Vf for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60916) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvq-00070a-MK for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:30 -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 A29F213A43; Thu, 14 Sep 2017 07:51:29 +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 7B1C6619B8; Thu, 14 Sep 2017 07:51:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A29F213A43 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:27 +0800 Message-Id: <1505375436-28439-7-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:51:29 +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 06/15] monitor: move the cur_mon hack deeper for QMP 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" In monitor_qmp_read(), we have the hack to temporarily replace the cur_mon pointer. Now we move this hack deeper inside the QMP dispatcher routine since the Monitor pointer can be passed in to that using the new JSON Parser opaque field now. This does not make much sense as a single patch. However, this will be a big step for the next patch, when the QMP dispatcher routine will be splitted from the QMP parser. Signed-off-by: Peter Xu Reviewed-by: Eric Blake --- monitor.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index 9096b64..d7eb3c2 100644 --- a/monitor.c +++ b/monitor.c @@ -3822,7 +3822,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens, { QObject *req, *rsp =3D NULL, *id =3D NULL; QDict *qdict =3D NULL; - Monitor *mon =3D cur_mon; + Monitor *mon =3D opaque, *old_mon; Error *err =3D NULL; =20 req =3D json_parser_parse_err(tokens, NULL, &err); @@ -3847,8 +3847,13 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens, QDECREF(req_json); } =20 + old_mon =3D cur_mon; + cur_mon =3D mon; + rsp =3D qmp_dispatch(cur_mon->qmp.commands, req); =20 + cur_mon =3D old_mon; + if (mon->qmp.commands =3D=3D &qmp_cap_negotiation_commands) { qdict =3D qdict_get_qdict(qobject_to_qdict(rsp), "error"); if (qdict @@ -3885,13 +3890,9 @@ err_out: =20 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) { - Monitor *old_mon =3D cur_mon; - - cur_mon =3D opaque; - - json_message_parser_feed(&cur_mon->qmp.parser, (const char *) buf, siz= e); + Monitor *mon =3D opaque; =20 - cur_mon =3D old_mon; + json_message_parser_feed(&mon->qmp.parser, (const char *) buf, size); } =20 static void monitor_read(void *opaque, const uint8_t *buf, int size) @@ -3965,7 +3966,7 @@ static void monitor_qmp_event(void *opaque, int event) break; case CHR_EVENT_CLOSED: json_message_parser_destroy(&mon->qmp.parser); - json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NUL= L); + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon= ); mon_refcount--; monitor_fdsets_cleanup(); break; @@ -4115,7 +4116,7 @@ void monitor_init(Chardev *chr, int flags) qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_= read, monitor_qmp_event, NULL, mon, NULL, true); qemu_chr_fe_set_echo(&mon->chr, true); - json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NUL= L); + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon= ); } else { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read, monitor_event, NULL, mon, NULL, true); --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 150537590869883.23781541754556; Thu, 14 Sep 2017 00:58:28 -0700 (PDT) Received: from localhost ([::1]:46212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP2Z-000539-JG for importer@patchew.org; Thu, 14 Sep 2017 03:58:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOvx-0006bj-It for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvw-00079V-K6 for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51070) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvw-00077P-4G for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:36 -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 165AC7E420; Thu, 14 Sep 2017 07:51:35 +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 29C1277EC0; Thu, 14 Sep 2017 07:51:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 165AC7E420 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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:28 +0800 Message-Id: <1505375436-28439-8-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.27]); Thu, 14 Sep 2017 07:51:35 +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 07/15] monitor: unify global init 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" There are many places for monitor init its globals, at least: - monitor_init_qmp_commands() at the very beginning - single function to init monitor_lock - in the first entry of monitor_init() using "is_first_init" Unify them a bit. Signed-off-by: Peter Xu --- include/monitor/monitor.h | 2 +- monitor.c | 25 ++++++++++--------------- vl.c | 3 ++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 83ea4a1..3a5128a 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -16,7 +16,7 @@ extern Monitor *cur_mon; =20 bool monitor_cur_is_qmp(void); =20 -void monitor_init_qmp_commands(void); +void monitor_init_globals(void); void monitor_init(Chardev *chr, int flags); void monitor_cleanup(void); =20 diff --git a/monitor.c b/monitor.c index d7eb3c2..7bd2e90 100644 --- a/monitor.c +++ b/monitor.c @@ -1000,7 +1000,7 @@ static void qmp_unregister_commands_hack(void) #endif } =20 -void monitor_init_qmp_commands(void) +static void monitor_init_qmp_commands(void) { /* * Two command lists: @@ -4043,6 +4043,14 @@ static void sortcmdlist(void) qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); } =20 +void monitor_init_globals(void) +{ + monitor_init_qmp_commands(); + monitor_qapi_event_init(); + sortcmdlist(); + qemu_mutex_init(&monitor_lock); +} + /* These functions just adapt the readline interface in a typesafe way. We * could cast function pointers but that discards compiler checks. */ @@ -4083,23 +4091,10 @@ void error_vprintf_unless_qmp(const char *fmt, va_l= ist ap) } } =20 -static void __attribute__((constructor)) monitor_lock_init(void) -{ - qemu_mutex_init(&monitor_lock); -} - void monitor_init(Chardev *chr, int flags) { - static int is_first_init =3D 1; - Monitor *mon; - - if (is_first_init) { - monitor_qapi_event_init(); - sortcmdlist(); - is_first_init =3D 0; - } + Monitor *mon =3D g_malloc(sizeof(*mon)); =20 - mon =3D g_malloc(sizeof(*mon)); monitor_data_init(mon, false); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); diff --git a/vl.c b/vl.c index fb1f05b..850cf55 100644 --- a/vl.c +++ b/vl.c @@ -3049,7 +3049,6 @@ int main(int argc, char **argv, char **envp) qemu_init_exec_dir(argv[0]); =20 module_call_init(MODULE_INIT_QOM); - monitor_init_qmp_commands(); =20 qemu_add_opts(&qemu_drive_opts); qemu_add_drive_opts(&qemu_legacy_drive_opts); @@ -4587,6 +4586,8 @@ int main(int argc, char **argv, char **envp) =20 parse_numa_opts(current_machine); =20 + monitor_init_globals(); + if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, NULL)) { exit(1); --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505375864471168.4232038136655; Thu, 14 Sep 2017 00:57:44 -0700 (PDT) Received: from localhost ([::1]:46210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP1q-0004BL-Kw for importer@patchew.org; Thu, 14 Sep 2017 03:57:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOw5-0006n8-Mw for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOw2-0007Fe-Ih for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOw2-0007F0-AG for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:42 -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 448EF155E2; Thu, 14 Sep 2017 07:51:41 +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 85AC3619BE; Thu, 14 Sep 2017 07:51:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 448EF155E2 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:29 +0800 Message-Id: <1505375436-28439-9-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:51:41 +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 08/15] monitor: create IO thread 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" Create one IO thread for the monitors, prepared to handle all the input/output IOs. Only adding the thread, loop and context, but doing nothing else yet. Signed-off-by: Peter Xu --- monitor.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/monitor.c b/monitor.c index 7bd2e90..9e9a32e 100644 --- a/monitor.c +++ b/monitor.c @@ -208,6 +208,14 @@ struct Monitor { QLIST_ENTRY(Monitor) entry; }; =20 +struct MonitorGlobal { + QemuThread mon_io_thread; + GMainContext *mon_context; + GMainLoop *mon_loop; +}; + +static struct MonitorGlobal mon_global; + /* QMP checker flags */ #define QMP_ACCEPT_UNKNOWNS 1 =20 @@ -4043,12 +4051,32 @@ static void sortcmdlist(void) qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); } =20 +static void *monitor_io_thread(void *data) +{ + rcu_register_thread(); + + g_main_loop_run(mon_global.mon_loop); + + rcu_unregister_thread(); + + return NULL; +} + +static void monitor_io_thread_init(void) +{ + mon_global.mon_context =3D g_main_context_new(); + mon_global.mon_loop =3D g_main_loop_new(mon_global.mon_context, TRUE); + qemu_thread_create(&mon_global.mon_io_thread, "mon-io-thr", + monitor_io_thread, NULL, QEMU_THREAD_JOINABLE); +} + void monitor_init_globals(void) { monitor_init_qmp_commands(); monitor_qapi_event_init(); sortcmdlist(); qemu_mutex_init(&monitor_lock); + monitor_io_thread_init(); } =20 /* These functions just adapt the readline interface in a typesafe way. We @@ -4122,6 +4150,25 @@ void monitor_init(Chardev *chr, int flags) qemu_mutex_unlock(&monitor_lock); } =20 +static void monitor_io_thread_destroy(void) +{ + /* Notify the monitor IO thread to quit. */ + g_main_loop_quit(mon_global.mon_loop); + /* + * Make sure the context will get the quit message since it's in + * another thread. Without this, it may not be able to respond to + * the quit message immediately. + */ + g_main_context_wakeup(mon_global.mon_context); + qemu_thread_join(&mon_global.mon_io_thread); + + g_main_loop_unref(mon_global.mon_loop); + mon_global.mon_loop =3D NULL; + + g_main_context_unref(mon_global.mon_context); + mon_global.mon_context =3D NULL; +} + void monitor_cleanup(void) { Monitor *mon, *next; @@ -4133,6 +4180,8 @@ void monitor_cleanup(void) g_free(mon); } qemu_mutex_unlock(&monitor_lock); + + monitor_io_thread_destroy(); } =20 QemuOptsList qemu_mon_opts =3D { --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 150537606976946.45664322437767; Thu, 14 Sep 2017 01:01:09 -0700 (PDT) Received: from localhost ([::1]:46229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP5A-0007kV-Us for importer@patchew.org; Thu, 14 Sep 2017 04:01:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwF-00072W-7w for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwC-0007RF-3T for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57800) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwB-0007PF-JJ for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:51 -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 8B1F881DF1; Thu, 14 Sep 2017 07:51:50 +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 B6806619BE; Thu, 14 Sep 2017 07:51:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B1F881DF1 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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:30 +0800 Message-Id: <1505375436-28439-10-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.25]); Thu, 14 Sep 2017 07:51:50 +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 09/15] monitor: allow to use IO thread for parsing 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" For each Monitor, add one field "use_io_thr" to show whether it will be using the dedicated monitor IO thread to handle input/output. When set, monitor IO parsing work will be offloaded to dedicated monitor IO thread, rather than the original main loop thread. This only works for QMP. HMP will always be run on main loop thread. Currently we're still keeping use_io_thr to off always. Will turn it on later at some point. Signed-off-by: Peter Xu --- monitor.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 9e9a32e..83f5e87 100644 --- a/monitor.c +++ b/monitor.c @@ -190,6 +190,7 @@ struct Monitor { int flags; int suspend_cnt; bool skip_flush; + bool use_io_thr; =20 QemuMutex out_lock; QString *outbuf; @@ -576,7 +577,8 @@ static void monitor_qapi_event_init(void) =20 static void handle_hmp_command(Monitor *mon, const char *cmdline); =20 -static void monitor_data_init(Monitor *mon, bool skip_flush) +static void monitor_data_init(Monitor *mon, bool skip_flush, + bool use_io_thr) { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); @@ -584,6 +586,7 @@ static void monitor_data_init(Monitor *mon, bool skip_f= lush) /* Use *mon_cmds by default. */ mon->cmd_table =3D mon_cmds; mon->skip_flush =3D skip_flush; + mon->use_io_thr =3D use_io_thr; } =20 static void monitor_data_destroy(Monitor *mon) @@ -603,7 +606,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, char *output =3D NULL; Monitor *old_mon, hmp; =20 - monitor_data_init(&hmp, true); + monitor_data_init(&hmp, true, false); =20 old_mon =3D cur_mon; cur_mon =3D &hmp; @@ -4122,8 +4125,9 @@ void error_vprintf_unless_qmp(const char *fmt, va_lis= t ap) void monitor_init(Chardev *chr, int flags) { Monitor *mon =3D g_malloc(sizeof(*mon)); + GMainContext *context; =20 - monitor_data_init(mon, false); + monitor_data_init(mon, false, false); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; @@ -4135,9 +4139,22 @@ void monitor_init(Chardev *chr, int flags) monitor_read_command(mon, 0); } =20 + if (mon->use_io_thr) { + /* + * When use_io_thr is set, we use the global shared dedicated + * IO thread for this monitor to handle input/output. + */ + context =3D mon_global.mon_context; + /* We should have inited globals before reaching here. */ + assert(context); + } else { + /* The default main loop, which is the main thread */ + context =3D NULL; + } + if (monitor_is_qmp(mon)) { qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_= read, - monitor_qmp_event, NULL, mon, NULL, true); + monitor_qmp_event, NULL, mon, context, tr= ue); qemu_chr_fe_set_echo(&mon->chr, true); json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon= ); } else { --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505376241829811.7053585280529; Thu, 14 Sep 2017 01:04:01 -0700 (PDT) Received: from localhost ([::1]:46246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP7x-00028l-2R for importer@patchew.org; Thu, 14 Sep 2017 04:04:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwL-0007BD-Nm for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwJ-0007fC-UN for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43284) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwJ-0007d8-LC for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:59 -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 8DB4785546; Thu, 14 Sep 2017 07:51:58 +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 0836260F9F; Thu, 14 Sep 2017 07:51:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8DB4785546 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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:31 +0800 Message-Id: <1505375436-28439-11-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.28]); Thu, 14 Sep 2017 07:51:58 +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 10/15] monitor: introduce monitor_qmp_respond() 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" A tiny refactoring, preparing to split the QMP dispatcher away. Signed-off-by: Peter Xu --- monitor.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/monitor.c b/monitor.c index 83f5e87..aa0c384 100644 --- a/monitor.c +++ b/monitor.c @@ -3828,6 +3828,36 @@ static int monitor_can_read(void *opaque) return (mon->suspend_cnt =3D=3D 0) ? 1 : 0; } =20 +/* + * When rsp/err/id is passed in, the function will be responsible for + * the cleanup. + */ +static void monitor_qmp_respond(Monitor *mon, QObject *rsp, + Error *err, QObject *id) +{ + QDict *qdict =3D NULL; + + if (err) { + qdict =3D qdict_new(); + qdict_put_obj(qdict, "error", qmp_build_error_object(err)); + error_free(err); + rsp =3D QOBJECT(qdict); + } + + if (rsp) { + if (id) { + /* This is for the qdict below. */ + qobject_incref(id); + qdict_put_obj(qobject_to_qdict(rsp), "id", id); + } + + monitor_json_emitter(mon, rsp); + } + + qobject_decref(id); + qobject_decref(rsp); +} + static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens, void *opaque) { @@ -3878,24 +3908,8 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens, } =20 err_out: - if (err) { - qdict =3D qdict_new(); - qdict_put_obj(qdict, "error", qmp_build_error_object(err)); - error_free(err); - rsp =3D QOBJECT(qdict); - } + monitor_qmp_respond(mon, rsp, err, id); =20 - if (rsp) { - if (id) { - qdict_put_obj(qobject_to_qdict(rsp), "id", id); - id =3D NULL; - } - - monitor_json_emitter(mon, rsp); - } - - qobject_decref(id); - qobject_decref(rsp); qobject_decref(req); } =20 --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 150537589257847.46094640954618; Thu, 14 Sep 2017 00:58:12 -0700 (PDT) Received: from localhost ([::1]:46211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP2J-0004pW-Nf for importer@patchew.org; Thu, 14 Sep 2017 03:58:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwQ-0007Ef-Fp for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwO-0007qN-MI for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwO-0007o1-BN for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:04 -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 409F87EA89; Thu, 14 Sep 2017 07:52:03 +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 09CF570132; Thu, 14 Sep 2017 07:51:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 409F87EA89 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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:32 +0800 Message-Id: <1505375436-28439-12-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.28]); Thu, 14 Sep 2017 07:52:03 +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 11/15] monitor: separate QMP parser and dispatcher 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" Originally QMP is going throw these steps: JSON Parser --> QMP Dispatcher --> Respond /|\ (2) (3) | (1) | \|/ (4) +--------- main thread --------+ This patch does this: JSON Parser QMP Dispatcher --> Respond /|\ | /|\ (4) | | | (2) | (3) | (5) (1) | +-----> | \|/ +--------- main thread <-------+ So the parsing job and the dispatching job is isolated now. It gives us a chance in following up patches to totally move the parser outside. The isloation is done using one QEMUBH. Only one dispatcher BH for all the monitors. Signed-off-by: Peter Xu --- monitor.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 99 insertions(+), 23 deletions(-) diff --git a/monitor.c b/monitor.c index aa0c384..f649d6a 100644 --- a/monitor.c +++ b/monitor.c @@ -213,6 +213,10 @@ struct MonitorGlobal { QemuThread mon_io_thread; GMainContext *mon_context; GMainLoop *mon_loop; + /* Bottom half to dispatch the requests received from IO thread */ + QEMUBH *qmp_dispatcher_bh; + /* Input queue that hangs all the parsed QMP requests */ + GQueue *qmp_requests; }; =20 static struct MonitorGlobal mon_global; @@ -3858,29 +3862,31 @@ static void monitor_qmp_respond(Monitor *mon, QObje= ct *rsp, qobject_decref(rsp); } =20 -static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens, - void *opaque) +struct QMPRequest { + /* Owner of the request */ + Monitor *mon; + /* "id" field of the request */ + QObject *id; + /* Request object to be handled */ + QObject *req; +}; +typedef struct QMPRequest QMPRequest; + +/* + * Dispatch one single QMP request. The function will free the req_obj + * and objects inside it before return. + */ +static void monitor_qmp_dispatch_one(QMPRequest *req_obj) { - QObject *req, *rsp =3D NULL, *id =3D NULL; + Monitor *mon, *old_mon; + QObject *req, *rsp =3D NULL, *id; QDict *qdict =3D NULL; - Monitor *mon =3D opaque, *old_mon; - Error *err =3D NULL; =20 - req =3D json_parser_parse_err(tokens, NULL, &err); - if (!req && !err) { - /* json_parser_parse_err() sucks: can fail without setting @err */ - error_setg(&err, QERR_JSON_PARSING); - } - if (err) { - goto err_out; - } + req =3D req_obj->req; + mon =3D req_obj->mon; + id =3D req_obj->id; =20 - qdict =3D qobject_to_qdict(req); - if (qdict) { - id =3D qdict_get(qdict, "id"); - qobject_incref(id); - qdict_del(qdict, "id"); - } /* else will fail qmp_dispatch() */ + g_free(req_obj); =20 if (trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { QString *req_json =3D qobject_to_json(req); @@ -3891,7 +3897,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens, old_mon =3D cur_mon; cur_mon =3D mon; =20 - rsp =3D qmp_dispatch(cur_mon->qmp.commands, req); + rsp =3D qmp_dispatch(mon->qmp.commands, req); =20 cur_mon =3D old_mon; =20 @@ -3907,12 +3913,66 @@ static void handle_qmp_command(JSONMessageParser *p= arser, GQueue *tokens, } } =20 -err_out: - monitor_qmp_respond(mon, rsp, err, id); - + /* Respond if necessary */ + monitor_qmp_respond(mon, rsp, NULL, id); qobject_decref(req); } =20 +static void monitor_qmp_bh_dispatcher(void *data) +{ + QMPRequest *req_obj; + + while (true) { + req_obj =3D g_queue_pop_head(mon_global.qmp_requests); + if (!req_obj) { + break; + } + monitor_qmp_dispatch_one(req_obj); + } +} + +static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens, + void *opaque) +{ + QObject *req, *id =3D NULL; + QDict *qdict =3D NULL; + Monitor *mon =3D opaque; + Error *err =3D NULL; + QMPRequest *req_obj; + + req =3D json_parser_parse_err(tokens, NULL, &err); + if (!req && !err) { + /* json_parser_parse_err() sucks: can fail without setting @err */ + error_setg(&err, QERR_JSON_PARSING); + } + if (err) { + monitor_qmp_respond(mon, NULL, err, NULL); + qobject_decref(req); + } + + qdict =3D qobject_to_qdict(req); + if (qdict) { + id =3D qdict_get(qdict, "id"); + qobject_incref(id); + qdict_del(qdict, "id"); + } /* else will fail qmp_dispatch() */ + + req_obj =3D g_new0(QMPRequest, 1); + req_obj->mon =3D mon; + req_obj->id =3D id; + req_obj->req =3D req; + + /* + * Put the request to the end of queue so that requests will be + * handled in time order. Ownership for req_obj, req, id, + * etc. will be delivered to the handler side. + */ + g_queue_push_tail(mon_global.qmp_requests, req_obj); + + /* Kick the dispatcher routine */ + qemu_bh_schedule(mon_global.qmp_dispatcher_bh); +} + static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) { Monitor *mon =3D opaque; @@ -4085,6 +4145,16 @@ static void monitor_io_thread_init(void) mon_global.mon_loop =3D g_main_loop_new(mon_global.mon_context, TRUE); qemu_thread_create(&mon_global.mon_io_thread, "mon-io-thr", monitor_io_thread, NULL, QEMU_THREAD_JOINABLE); + + /* + * This MUST be on main loop thread since we have commands that + * have assumption to be run on main loop thread (Yeah, we'd + * better remove this assumption in the future). + */ + mon_global.qmp_dispatcher_bh =3D aio_bh_new(qemu_get_aio_context(), + monitor_qmp_bh_dispatcher, + NULL); + mon_global.qmp_requests =3D g_queue_new(); } =20 void monitor_init_globals(void) @@ -4213,6 +4283,12 @@ void monitor_cleanup(void) qemu_mutex_unlock(&monitor_lock); =20 monitor_io_thread_destroy(); + + qemu_bh_delete(mon_global.qmp_dispatcher_bh); + mon_global.qmp_dispatcher_bh =3D NULL; + + g_queue_free(mon_global.qmp_requests); + mon_global.qmp_requests =3D NULL; } =20 QemuOptsList qemu_mon_opts =3D { --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505376389433937.1861848868082; Thu, 14 Sep 2017 01:06:29 -0700 (PDT) Received: from localhost ([::1]:46266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsPAK-0004jp-LK for importer@patchew.org; Thu, 14 Sep 2017 04:06:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwb-0007Pk-Tt for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwY-000884-R9 for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwY-00081T-LS for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:14 -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 7312B7EBD5; Thu, 14 Sep 2017 07:52:11 +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 B0B36619BF; Thu, 14 Sep 2017 07:52:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7312B7EBD5 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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:33 +0800 Message-Id: <1505375436-28439-13-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.27]); Thu, 14 Sep 2017 07:52:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 12/15] monitor: enable IO thread for (qmp & !mux) typed 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" Start to use dedicate IO thread for QMP monitors that are not using MUXed chardev. Signed-off-by: Peter Xu --- monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index f649d6a..599ea36 100644 --- a/monitor.c +++ b/monitor.c @@ -36,6 +36,7 @@ #include "net/net.h" #include "net/slirp.h" #include "chardev/char-fe.h" +#include "chardev/char-mux.h" #include "ui/qemu-spice.h" #include "sysemu/numa.h" #include "monitor/monitor.h" @@ -4211,7 +4212,7 @@ void monitor_init(Chardev *chr, int flags) Monitor *mon =3D g_malloc(sizeof(*mon)); GMainContext *context; =20 - monitor_data_init(mon, false, false); + monitor_data_init(mon, false, !CHARDEV_IS_MUX(chr)); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 1505376053088583.1490164536954; Thu, 14 Sep 2017 01:00:53 -0700 (PDT) Received: from localhost ([::1]:46228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP4u-0007PC-99 for importer@patchew.org; Thu, 14 Sep 2017 04:00:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwe-0007S9-6n for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwb-0008Cg-O1 for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40734) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwb-0008Am-Fm for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:17 -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 71450883AB; Thu, 14 Sep 2017 07:52:16 +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 E3934619BE; Thu, 14 Sep 2017 07:52:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71450883AB Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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:34 +0800 Message-Id: <1505375436-28439-14-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.26]); Thu, 14 Sep 2017 07:52:16 +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 13/15] qapi: introduce new cmd option "allow-oob" 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" Here "oob" stands for "Out-Of-Band". When "allow-oob" is set, it means the command allows out-of-band execution. Please see the spec update for more details. The "oob" idea is proposed by Markus Armbruster in following thread: https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg02057.html This new "allow-oob" boolean will be exposed by "query-qmp-schema" as well for command entries, so that QMP clients can know which command can be used as out-of-band calls. For example the command "migrate" originally looks like: {"name": "migrate", "ret-type": "17", "meta-type": "command", "arg-type": "86"} And it'll be changed into: {"name": "migrate", "ret-type": "17", "allow-oob": false, "meta-type": "command", "arg-type": "86"} This patch only provides the QMP interface level changes. It does not contains the real out-of-band execution implementation yet. Suggested-by: Markus Armbruster Signed-off-by: Peter Xu --- docs/devel/qapi-code-gen.txt | 41 ++++++++++++++++++++++++++++++++++++--= --- include/qapi/qmp/dispatch.h | 1 + qapi/introspect.json | 6 +++++- scripts/qapi-commands.py | 19 ++++++++++++++----- scripts/qapi-introspect.py | 10 ++++++++-- scripts/qapi.py | 15 ++++++++++----- scripts/qapi2texi.py | 2 +- tests/qapi-schema/test-qapi.py | 2 +- 8 files changed, 76 insertions(+), 20 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index f04c63f..61fa167 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -556,7 +556,8 @@ following example objects: =20 Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, '*returns': TYPE-NAME, '*boxed': true, - '*gen': false, '*success-response': false } + '*gen': false, '*success-response': false, + '*allow-oob': false } =20 Commands are defined by using a dictionary containing several members, where three members are most common. The 'command' member is a @@ -636,6 +637,34 @@ possible, the command expression should include the op= tional key 'success-response' with boolean value false. So far, only QGA makes use of this member. =20 +Most of the QMP commands are handled sequentially in such a order. +Firstly, the JSON Parser parses the command request into some internal +message, then it delivers the message to QMP dispatchers; secondly, +the QMP dispatchers will handle the commands one by one in time order, +respond when necessary. For some commands that always complete +"quickly" can instead be executed directly during parsing, at the QMP +client's request. This kind of commands that allow direct execution +is called "out-of-band" ("oob" as shortcut) commands. the response can +overtake prior in-band commands' responses. By default, commands are +always in-band. We need to explicitly specify "allow-oob" to "True" +to show that one command can be run out-of-band. + +One thing to mention is that, although out-of-band execution of +commands benefit from quick and asynchronous execution, it need to +satisfy at least the following: + +(1) It is extremely quick and never blocks, so that its execution will + not block parsing routine of any other monitors. + +(2) It does not need BQL, since the parser can be run without BQL, + while the dispatcher is always with BQL held. + +If not, the command is not suitable to be allowed to run out-of-band, +and it should set its "allow-oob" to "False". Whether a command is +allowed to run out-of-band can also be introspected using +query-qmp-schema command. Please see the section "Client JSON +Protocol introspection" for more information. + =20 =3D=3D=3D Events =3D=3D=3D =20 @@ -739,10 +768,12 @@ references by name. QAPI schema definitions not reachable that way are omitted. =20 The SchemaInfo for a command has meta-type "command", and variant -members "arg-type" and "ret-type". On the wire, the "arguments" -member of a client's "execute" command must conform to the object type -named by "arg-type". The "return" member that the server passes in a -success response conforms to the type named by "ret-type". +members "arg-type", "ret-type" and "allow-oob". On the wire, the +"arguments" member of a client's "execute" command must conform to the +object type named by "arg-type". The "return" member that the server +passes in a success response conforms to the type named by +"ret-type". When "allow-oob" is set, it means the command supports +out-of-band execution. =20 If the command takes no arguments, "arg-type" names an object type without members. Likewise, if the command returns nothing, "ret-type" diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 20578dc..b767988 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -23,6 +23,7 @@ typedef enum QmpCommandOptions { QCO_NO_OPTIONS =3D 0x0, QCO_NO_SUCCESS_RESP =3D 0x1, + QCO_ALLOW_OOB =3D 0x2, } QmpCommandOptions; =20 typedef struct QmpCommand diff --git a/qapi/introspect.json b/qapi/introspect.json index 5b3e6e9..57cc137 100644 --- a/qapi/introspect.json +++ b/qapi/introspect.json @@ -259,12 +259,16 @@ # # @ret-type: the name of the command's result type. # +# @allow-oob: whether the command allows out-of-band execution. +# (Since: 2.11) +# # TODO: @success-response (currently irrelevant, because it's QGA, not QMP) # # Since: 2.5 ## { 'struct': 'SchemaInfoCommand', - 'data': { 'arg-type': 'str', 'ret-type': 'str' } } + 'data': { 'arg-type': 'str', 'ret-type': 'str', + 'allow-oob': 'bool' } } =20 ## # @SchemaInfoEvent: diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 974d0a4..b2b0bc0 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -192,10 +192,18 @@ out: return ret =20 =20 -def gen_register_command(name, success_response): - options =3D 'QCO_NO_OPTIONS' +def gen_register_command(name, success_response, allow_oob): + options =3D [] + if not success_response: - options =3D 'QCO_NO_SUCCESS_RESP' + options +=3D ['QCO_NO_SUCCESS_RESP'] + if allow_oob: + options +=3D ['QCO_ALLOW_OOB'] + + if not options: + options =3D ['QCO_NO_OPTIONS'] + + options =3D " | ".join(options) =20 ret =3D mcgen(''' qmp_register_command(cmds, "%(name)s", @@ -241,7 +249,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._visited_ret_types =3D None =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, allow_oob): if not gen: return self.decl +=3D gen_command_decl(name, arg_type, boxed, ret_type) @@ -250,7 +258,8 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self.defn +=3D gen_marshal_output(ret_type) self.decl +=3D gen_marshal_decl(name) self.defn +=3D gen_marshal(name, arg_type, boxed, ret_type) - self._regy +=3D gen_register_command(name, success_response) + self._regy +=3D gen_register_command(name, success_response, + allow_oob) =20 =20 (input_file, output_dir, do_c, do_h, prefix, opts) =3D parse_command_line() diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 032bcea..9fbf88b 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -28,6 +28,11 @@ def to_json(obj, level=3D0): to_json(obj[key], level + 1)) for key in sorted(obj.keys())] ret =3D '{' + ', '.join(elts) + '}' + elif isinstance(obj, bool): + if obj: + ret =3D 'true' + else: + ret =3D 'false' else: assert False # not implemented if level =3D=3D 1: @@ -154,12 +159,13 @@ const char %(c_name)s[] =3D %(c_string)s; for m in variants.variants]}) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, allow_oob): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type self._gen_json(name, 'command', {'arg-type': self._use_type(arg_type), - 'ret-type': self._use_type(ret_type)}) + 'ret-type': self._use_type(ret_type), + 'allow-oob': allow_oob}) =20 def visit_event(self, name, info, arg_type, boxed): arg_type =3D arg_type or self._schema.the_empty_object_type diff --git a/scripts/qapi.py b/scripts/qapi.py index 62dc52e..f411b8f 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -920,7 +920,8 @@ def check_exprs(exprs): elif 'command' in expr: meta =3D 'command' check_keys(expr_elem, 'command', [], - ['data', 'returns', 'gen', 'success-response', 'box= ed']) + ['data', 'returns', 'gen', 'success-response', + 'boxed', 'allow-oob']) elif 'event' in expr: meta =3D 'event' check_keys(expr_elem, 'event', [], ['data', 'boxed']) @@ -1031,7 +1032,7 @@ class QAPISchemaVisitor(object): pass =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, allow_oob): pass =20 def visit_event(self, name, info, arg_type, boxed): @@ -1398,7 +1399,7 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, doc, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, allow_oob): QAPISchemaEntity.__init__(self, name, info, doc) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) @@ -1409,6 +1410,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.gen =3D gen self.success_response =3D success_response self.boxed =3D boxed + self.allow_oob =3D allow_oob =20 def check(self, schema): if self._arg_type_name: @@ -1432,7 +1434,8 @@ class QAPISchemaCommand(QAPISchemaEntity): def visit(self, visitor): visitor.visit_command(self.name, self.info, self.arg_type, self.ret_type, - self.gen, self.success_response, self.boxed) + self.gen, self.success_response, + self.boxed, self.allow_oob) =20 =20 class QAPISchemaEvent(QAPISchemaEntity): @@ -1640,6 +1643,7 @@ class QAPISchema(object): gen =3D expr.get('gen', True) success_response =3D expr.get('success-response', True) boxed =3D expr.get('boxed', False) + allow_oob =3D expr.get('allow-oob', False) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( name, info, doc, 'arg', self._make_members(data, info)) @@ -1647,7 +1651,8 @@ class QAPISchema(object): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) self._def_entity(QAPISchemaCommand(name, info, doc, data, rets, - gen, success_response, boxed)) + gen, success_response, + boxed, allow_oob)) =20 def _def_event(self, expr, info, doc): name =3D expr['event'] diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index a317526..0ac0df5 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -236,7 +236,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): body=3Dtexi_entity(doc, 'Members')) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, allow_oob): doc =3D self.cur_doc if self.out: self.out +=3D '\n' diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index c7724d3..6749e9e 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -36,7 +36,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): self._print_variants(variants) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, allow_oob): print 'command %s %s -> %s' % \ (name, arg_type and arg_type.name, ret_type and ret_type.name) print ' gen=3D%s success_response=3D%s boxed=3D%s' % \ --=20 2.7.4 From nobody Sun Feb 8 05:37:03 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 From nobody Sun Feb 8 05:37:03 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 1505375997992578.9359958377773; Thu, 14 Sep 2017 00:59:57 -0700 (PDT) Received: from localhost ([::1]:46221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsP41-0006Rk-5n for importer@patchew.org; Thu, 14 Sep 2017 03:59:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOwt-00080D-VZ for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOwq-0000Dg-OY for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOwq-0000Bh-IY for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:52:32 -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 861F4356EC; Thu, 14 Sep 2017 07:52:31 +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 F3B756FA90; Thu, 14 Sep 2017 07:52:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 861F4356EC Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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:36 +0800 Message-Id: <1505375436-28439-16-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.30]); Thu, 14 Sep 2017 07:52:31 +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 15/15] qmp: let migrate-incoming allow out-of-band 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" So it can get rid of being run on main thread. Signed-off-by: Peter Xu --- qapi/migration.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qapi/migration.json b/qapi/migration.json index ee2b3b8..dedc4f8 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -986,7 +986,8 @@ # <- { "return": {} } # ## -{ 'command': 'migrate-incoming', 'data': {'uri': 'str' } } +{ 'command': 'migrate-incoming', 'data': {'uri': 'str' }, + 'allow-oob': true } =20 ## # @xen-save-devices-state: --=20 2.7.4