From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673291889320.2831692290532; Tue, 19 Dec 2017 00:48:11 -0800 (PST) Received: from localhost ([::1]:59684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDZ5-0000jN-4E for importer@patchew.org; Tue, 19 Dec 2017 03:47:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDXX-0008Mo-Ds for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDXW-0008Hw-Pv for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDXW-0008HO-Ih for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:18 -0500 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 852F85D68B; Tue, 19 Dec 2017 08:46:17 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A0B560C80; Tue, 19 Dec 2017 08:46:10 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:31 +0800 Message-Id: <20171219084557.9801-2-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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.39]); Tue, 19 Dec 2017 08:46:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v6 01/27] chardev: use backend chr context when watch for fe 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 commit 6bbb6c0644 ("chardev: use per-dev context for io_add_watch_poll", 2017-09-22) all the chardev watches are converted to use per-chardev gcontext to support chardev to be run outside default main thread. However that's still missing one call from the frontend code. Touch that up. Signed-off-by: Peter Xu Reviewed-by: Stefan Hajnoczi --- chardev/char-fe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index ee6d596100..462c529f19 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -356,7 +356,7 @@ guint qemu_chr_fe_add_watch(CharBackend *be, GIOConditi= on cond, } =20 g_source_set_callback(src, (GSourceFunc)func, user_data, NULL); - tag =3D g_source_attach(src, NULL); + tag =3D g_source_attach(src, be->chr->gcontext); g_source_unref(src); =20 return tag; --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673306013732.639163225284; Tue, 19 Dec 2017 00:48:26 -0800 (PST) Received: from localhost ([::1]:59685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDZT-00015y-U9 for importer@patchew.org; Tue, 19 Dec 2017 03:48:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDXi-0008TP-5E for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDXd-0008N3-Ar for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDXd-0008Mj-4W for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:25 -0500 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 4500183F46; Tue, 19 Dec 2017 08:46:24 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 078696EE21; Tue, 19 Dec 2017 08:46:17 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:32 +0800 Message-Id: <20171219084557.9801-3-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:46:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v6 02/27] qobject: introduce qstring_get_try_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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" The only difference from qstring_get_str() is that it allows the qstring to be NULL. If so, NULL is returned. CC: Eric Blake CC: Markus Armbruster Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu Reviewed-by: Eric Blake --- include/qapi/qmp/qstring.h | 1 + qobject/qstring.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index 65c05a9be5..a145c8ca00 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 *qstring_get_try_str(const QString *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 74182a1c02..7638ab990d 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -128,6 +128,16 @@ const char *qstring_get_str(const QString *qstring) return qstring->string; } =20 +/** + * qstring_get_try_str(): Return a pointer to the stored string + * + * NOTE: will return NULL if qstring is not provided. + */ +const char *qstring_get_try_str(const QString *qstring) +{ + return qstring ? qstring_get_str(qstring) : NULL; +} + /** * qstring_is_equal(): Test whether the two QStrings are equal */ --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1513673489686326.0501032567089; Tue, 19 Dec 2017 00:51:29 -0800 (PST) Received: from localhost ([::1]:59707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDcA-0003gM-G3 for importer@patchew.org; Tue, 19 Dec 2017 03:51:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDXo-00005v-32 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDXn-0008SW-Do for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDXn-0008Rt-6l for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:35 -0500 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 543C95D68B; Tue, 19 Dec 2017 08:46:34 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id B85446EE21; Tue, 19 Dec 2017 08:46:24 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:33 +0800 Message-Id: <20171219084557.9801-4-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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.39]); Tue, 19 Dec 2017 08:46:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v6 03/27] qobject: introduce qobject_get_try_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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 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. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi 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 a145c8ca00..6517d8e377 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -28,6 +28,7 @@ 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 *qstring_get_try_str(const QString *qstring); +const char *qobject_get_try_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 7638ab990d..fc6834baa6 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -138,6 +138,17 @@ const char *qstring_get_try_str(const QString *qstring) return qstring ? qstring_get_str(qstring) : NULL; } =20 +/** + * qobject_get_try_str(): Return a pointer of the backstore string + * + * NOTE: the string will only be returned if the object is valid, and + * its type is QString, otherwise NULL is returned. + */ +const char *qobject_get_try_str(const QObject *qstring) +{ + return qstring_get_try_str(qobject_to_qstring(qstring)); +} + /** * qstring_is_equal(): Test whether the two QStrings are equal */ --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673335435125.68313106200685; Tue, 19 Dec 2017 00:48:55 -0800 (PST) Received: from localhost ([::1]:59686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDZm-0001Or-8g for importer@patchew.org; Tue, 19 Dec 2017 03:48:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDXt-00009U-6P for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDXr-0008Uh-Pv for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58146) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDXr-0008UJ-J4 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:39 -0500 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 ACCF9883AE; Tue, 19 Dec 2017 08:46:38 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7CA06EE21; Tue, 19 Dec 2017 08:46:34 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:34 +0800 Message-Id: <20171219084557.9801-5-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:46:38 +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 v6 04/27] qobject: let object_property_get_str() use new API 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We can simplify object_property_get_str() using the new qobject_get_try_str(). Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu Reviewed-by: Eric Blake --- qom/object.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/qom/object.c b/qom/object.c index c58c52d518..9cbeb51f0b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1116,18 +1116,15 @@ char *object_property_get_str(Object *obj, const ch= ar *name, Error **errp) { QObject *ret =3D object_property_get_qobject(obj, name, errp); - QString *qstring; char *retval; =20 if (!ret) { return NULL; } - qstring =3D qobject_to_qstring(ret); - if (!qstring) { + + retval =3D g_strdup(qobject_get_try_str(ret)); + if (!retval) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "string"); - retval =3D NULL; - } else { - retval =3D g_strdup(qstring_get_str(qstring)); } =20 qobject_decref(ret); --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151367350679579.5297984734483; Tue, 19 Dec 2017 00:51:46 -0800 (PST) Received: from localhost ([::1]:59708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDcT-00041a-Lk for importer@patchew.org; Tue, 19 Dec 2017 03:51:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDXy-0000Du-WD for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDXy-00007t-79 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41114) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDXy-00007H-0a for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:46 -0500 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 22440804E3; Tue, 19 Dec 2017 08:46:45 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C23D6EE21; Tue, 19 Dec 2017 08:46:38 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:35 +0800 Message-Id: <20171219084557.9801-6-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:46:45 +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 v6 05/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- monitor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index d682eee2d8..0030ded8f1 100644 --- a/monitor.c +++ b/monitor.c @@ -567,13 +567,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; @@ -4088,7 +4088,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.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151367334293546.14239236979881; Tue, 19 Dec 2017 00:49:02 -0800 (PST) Received: from localhost ([::1]:59687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDa2-0001ck-Q3 for importer@patchew.org; Tue, 19 Dec 2017 03:48:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDY7-0000NH-O3 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDY6-0000Cf-NM for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDY6-0000C1-Gh for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:54 -0500 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 A0DEDC059B6E; Tue, 19 Dec 2017 08:46:53 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96C756EE21; Tue, 19 Dec 2017 08:46:45 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:36 +0800 Message-Id: <20171219084557.9801-7-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:46:53 +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 v6 06/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 actually obtained using container_of() upon the parser object, just like most of the other JSON parser users do. 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 split from the QMP parser. Signed-off-by: Peter Xu Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- monitor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/monitor.c b/monitor.c index 0030ded8f1..35a2aef0fe 100644 --- a/monitor.c +++ b/monitor.c @@ -3811,7 +3811,9 @@ 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; + MonitorQMP *mon_qmp =3D container_of(parser, MonitorQMP, parser); + Monitor *old_mon, *mon =3D container_of(mon_qmp, Monitor, qmp); + Error *err =3D NULL; =20 req =3D json_parser_parse_err(tokens, NULL, &err); @@ -3836,8 +3838,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 @@ -3874,13 +3881,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) --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673510653588.6778081834618; Tue, 19 Dec 2017 00:51:50 -0800 (PST) Received: from localhost ([::1]:59709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDch-0004EC-HD for importer@patchew.org; Tue, 19 Dec 2017 03:51:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDYF-0000Tg-4Q for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDYB-0000FE-E9 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDYB-0000Ee-5E for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:46:59 -0500 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 3C450C05972B; Tue, 19 Dec 2017 08:46:58 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2496A60C80; Tue, 19 Dec 2017 08:46:53 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:37 +0800 Message-Id: <20171219084557.9801-8-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:46: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 v6 07/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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. Reviewed-by: Fam Zheng Signed-off-by: Peter Xu Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/monitor/monitor.h | 2 +- monitor.c | 25 ++++++++++--------------- vl.c | 7 ++++++- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 83ea4a1aaf..3a5128ab1b 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 35a2aef0fe..bc0cb9f223 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: @@ -4034,6 +4034,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. */ @@ -4074,23 +4082,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 e9012bb009..2d89391351 100644 --- a/vl.c +++ b/vl.c @@ -3099,7 +3099,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); @@ -4645,6 +4644,12 @@ int main(int argc, char **argv, char **envp) default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); =20 + /* + * Note: qtest_enabled() (which used in monitor_qapi_event_init()) + * depend on configure_accelerator() above. + */ + monitor_init_globals(); + if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, NULL)) { exit(1); --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673659839826.1448498802757; Tue, 19 Dec 2017 00:54:19 -0800 (PST) Received: from localhost ([::1]:59781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDf9-0006WT-5X for importer@patchew.org; Tue, 19 Dec 2017 03:54:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDYJ-0000XB-4d for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDYI-0000Ii-Eh for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40818) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDYI-0000I9-7n for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:06 -0500 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 5930F2D5A0A; Tue, 19 Dec 2017 08:47:05 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id B10A460C80; Tue, 19 Dec 2017 08:46:58 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:38 +0800 Message-Id: <20171219084557.9801-9-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:47:05 +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 v6 08/27] monitor: let mon_list be tail queue 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It was QLIST. I want to use this list to do monitor priority job later, which need tail insertion ability. So switching to a tail queue. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- monitor.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/monitor.c b/monitor.c index bc0cb9f223..95fc54d97f 100644 --- a/monitor.c +++ b/monitor.c @@ -204,7 +204,7 @@ struct Monitor { void *password_opaque; mon_cmd_t *cmd_table; QLIST_HEAD(,mon_fd_t) fds; - QLIST_ENTRY(Monitor) entry; + QTAILQ_ENTRY(Monitor) entry; }; =20 /* QMP checker flags */ @@ -213,7 +213,7 @@ struct Monitor { /* Protects mon_list, monitor_event_state. */ static QemuMutex monitor_lock; =20 -static QLIST_HEAD(mon_list, Monitor) mon_list; +static QTAILQ_HEAD(mon_list, Monitor) mon_list; static QLIST_HEAD(mon_fdsets, MonFdset) mon_fdsets; static int mon_refcount; =20 @@ -414,7 +414,7 @@ static void monitor_qapi_event_emit(QAPIEvent event, QD= ict *qdict) Monitor *mon; =20 trace_monitor_protocol_event_emit(event, qdict); - QLIST_FOREACH(mon, &mon_list, entry) { + QTAILQ_FOREACH(mon, &mon_list, entry) { if (monitor_is_qmp(mon) && mon->qmp.commands !=3D &qmp_cap_negotiation_commands) { monitor_json_emitter(mon, QOBJECT(qdict)); @@ -4118,8 +4118,8 @@ void monitor_cleanup(void) Monitor *mon, *next; =20 qemu_mutex_lock(&monitor_lock); - QLIST_FOREACH_SAFE(mon, &mon_list, entry, next) { - QLIST_REMOVE(mon, entry); + QTAILQ_FOREACH_SAFE(mon, &mon_list, entry, next) { + QTAILQ_REMOVE(&mon_list, mon, entry); monitor_data_destroy(mon); g_free(mon); } --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673618620184.96043478386537; Tue, 19 Dec 2017 00:53:38 -0800 (PST) Received: from localhost ([::1]:59779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDeW-0005xu-Aj for importer@patchew.org; Tue, 19 Dec 2017 03:53:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDYa-0000nF-Am for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDYV-0000Yh-FF for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDYV-0000Wx-8r for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:19 -0500 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 4F3C9400E7; Tue, 19 Dec 2017 08:47:18 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id C967460C80; Tue, 19 Dec 2017 08:47:05 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:39 +0800 Message-Id: <20171219084557.9801-10-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:47:18 +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 v6 09/27] monitor: create monitor dedicate iothread 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 IOThread for the monitors, prepared to handle all the input/output IOs using existing iothread framework. Signed-off-by: Peter Xu Reviewed-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- monitor.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/monitor.c b/monitor.c index 95fc54d97f..4ebd83fd94 100644 --- a/monitor.c +++ b/monitor.c @@ -75,6 +75,7 @@ #include "qmp-introspect.h" #include "sysemu/qtest.h" #include "sysemu/cpus.h" +#include "sysemu/iothread.h" #include "qemu/cutils.h" #include "qapi/qmp/dispatch.h" =20 @@ -207,6 +208,11 @@ struct Monitor { QTAILQ_ENTRY(Monitor) entry; }; =20 +/* Let's add monitor global variables to this struct. */ +static struct { + IOThread *mon_iothread; +} mon_global; + /* QMP checker flags */ #define QMP_ACCEPT_UNKNOWNS 1 =20 @@ -4034,12 +4040,24 @@ static void sortcmdlist(void) qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd); } =20 +static GMainContext *monitor_io_context_get(void) +{ + return iothread_get_g_main_context(mon_global.mon_iothread); +} + +static void monitor_iothread_init(void) +{ + mon_global.mon_iothread =3D iothread_create("mon_iothread", + &error_abort); +} + void monitor_init_globals(void) { monitor_init_qmp_commands(); monitor_qapi_event_init(); sortcmdlist(); qemu_mutex_init(&monitor_lock); + monitor_iothread_init(); } =20 /* These functions just adapt the readline interface in a typesafe way. We @@ -4117,6 +4135,14 @@ void monitor_cleanup(void) { Monitor *mon, *next; =20 + /* + * We need to explicitly stop the iothread (but not destroy it), + * cleanup the monitor resources, then destroy the iothread since + * we need to unregister from chardev below in + * monitor_data_destroy(), and chardev is not thread-safe yet + */ + iothread_stop(mon_global.mon_iothread); + qemu_mutex_lock(&monitor_lock); QTAILQ_FOREACH_SAFE(mon, &mon_list, entry, next) { QTAILQ_REMOVE(&mon_list, mon, entry); @@ -4124,6 +4150,9 @@ void monitor_cleanup(void) g_free(mon); } qemu_mutex_unlock(&monitor_lock); + + iothread_destroy(mon_global.mon_iothread); + mon_global.mon_iothread =3D NULL; } =20 QemuOptsList qemu_mon_opts =3D { --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673654864710.664593630047; Tue, 19 Dec 2017 00:54:14 -0800 (PST) Received: from localhost ([::1]:59780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDer-0006FV-NH for importer@patchew.org; Tue, 19 Dec 2017 03:53:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDYg-0000sC-IZ for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDYf-0000oY-FP for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDYf-0000o6-5J for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:29 -0500 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 44474C049E39; Tue, 19 Dec 2017 08:47:28 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF67360C8E; Tue, 19 Dec 2017 08:47:18 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:40 +0800 Message-Id: <20171219084557.9801-11-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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.31]); Tue, 19 Dec 2017 08:47:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v6 10/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 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. One thing to mention is that we cannot set use_io_thr for every QMP monitors. The problem is that MUXed typed chardevs may not work well with it now. When MUX is used, frontend of chardev can be the monitor plus something else. The only thing we know would be safe to be run outside main thread so far is the monitor frontend. All the rest of the frontends should still be run in main thread only. Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- monitor.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index 4ebd83fd94..4b2bee773f 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; @@ -573,7 +574,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); @@ -581,6 +583,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) @@ -601,7 +604,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; @@ -4103,8 +4106,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; @@ -4116,19 +4120,38 @@ 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 monitor_io_context_get(); + /* We should have inited globals before reaching here. */ + assert(context); + } else { + /* The default main loop, which is the main thread */ + context =3D NULL; + } + + /* + * Add the monitor before running it (which is triggered by + * qemu_chr_fe_set_handlers), otherwise one monitor may find + * itself not on the mon_list when running. + */ + qemu_mutex_lock(&monitor_lock); + QTAILQ_INSERT_HEAD(&mon_list, mon, entry); + qemu_mutex_unlock(&monitor_lock); + 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); qemu_chr_fe_set_echo(&mon->chr, true); json_message_parser_init(&mon->qmp.parser, handle_qmp_command); + qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_= read, + monitor_qmp_event, NULL, mon, context, tr= ue); } else { + assert(!context); /* HMP does not support IOThreads */ qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read, monitor_event, NULL, mon, NULL, true); } - - qemu_mutex_lock(&monitor_lock); - QLIST_INSERT_HEAD(&mon_list, mon, entry); - qemu_mutex_unlock(&monitor_lock); } =20 void monitor_cleanup(void) --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513673801977379.4232640756138; Tue, 19 Dec 2017 00:56:41 -0800 (PST) Received: from localhost ([::1]:59831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDhU-0000VB-Uu for importer@patchew.org; Tue, 19 Dec 2017 03:56:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDYq-000113-Pf for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDYp-0000uY-VQ for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31286) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDYp-0000ti-NB for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:39 -0500 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 C0F8D83F40; Tue, 19 Dec 2017 08:47:38 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8C8E6EE21; Tue, 19 Dec 2017 08:47:28 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:41 +0800 Message-Id: <20171219084557.9801-12-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:47:38 +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 v6 11/27] qmp: introduce QMPCapability 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 was no QMP capabilities defined. Define the first "oob" as capability to allow out-of-band messages. Also, touch up qmp-test.c to test the new bits. Signed-off-by: Peter Xu Reviewed-by: Stefan Hajnoczi --- monitor.c | 10 ++++++++-- qapi-schema.json | 13 +++++++++++++ tests/qmp-test.c | 10 +++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/monitor.c b/monitor.c index 4b2bee773f..81fb0a42b4 100644 --- a/monitor.c +++ b/monitor.c @@ -3943,12 +3943,18 @@ void monitor_resume(Monitor *mon) =20 static QObject *get_qmp_greeting(void) { + QList *cap_list =3D qlist_new(); QObject *ver =3D NULL; + QMPCapability cap; =20 qmp_marshal_query_version(NULL, &ver, NULL); =20 - return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': []}= }", - ver); + for (cap =3D 0; cap < QMP_CAPABILITY__MAX; cap++) { + qlist_append(cap_list, qstring_from_str(QMPCapability_str(cap))); + } + + return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': %p}= }", + ver, cap_list); } =20 static void monitor_qmp_event(void *opaque, int event) diff --git a/qapi-schema.json b/qapi-schema.json index 18457954a8..03201578b4 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -118,6 +118,19 @@ ## { 'command': 'qmp_capabilities' } =20 +## +# @QMPCapability: +# +# QMP supported capabilities to be broadcasted to the clients. +# +# @oob: QMP ability to support Out-Of-Band requests. +# +# Since: 2.12 +# +## +{ 'enum': 'QMPCapability', + 'data': [ 'oob' ] } + ## # @VersionTriple: # diff --git a/tests/qmp-test.c b/tests/qmp-test.c index c5a5c10b41..292c5f135a 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -17,6 +17,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/util.h" #include "qapi/visitor.h" +#include "qapi/qmp/qstring.h" =20 const char common_args[] =3D "-nodefaults -machine none"; =20 @@ -75,6 +76,8 @@ static void test_qmp_protocol(void) { QDict *resp, *q, *ret; QList *capabilities; + const QListEntry *entry; + QString *qstr; =20 global_qtest =3D qtest_init_without_qmp_handshake(common_args); =20 @@ -84,7 +87,12 @@ static void test_qmp_protocol(void) g_assert(q); test_version(qdict_get(q, "version")); capabilities =3D qdict_get_qlist(q, "capabilities"); - g_assert(capabilities && qlist_empty(capabilities)); + g_assert(capabilities); + entry =3D qlist_first(capabilities); + g_assert(entry); + qstr =3D qobject_to_qstring(entry->value); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "oob"); QDECREF(resp); =20 /* Test valid command before handshake */ --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513673963393357.80328040728125; Tue, 19 Dec 2017 00:59:23 -0800 (PST) Received: from localhost ([::1]:59846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDk6-0002ub-9O for importer@patchew.org; Tue, 19 Dec 2017 03:59:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDYy-00019J-Ph for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDYx-00011J-JK for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35706) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDYx-00010n-AW for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:47 -0500 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 6AF35356DE; Tue, 19 Dec 2017 08:47:46 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B1876EE21; Tue, 19 Dec 2017 08:47:38 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:42 +0800 Message-Id: <20171219084557.9801-13-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:47:46 +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 v6 12/27] qmp: negotiate QMP capabilities 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" After this patch, we will allow QMP clients to enable QMP capabilities when sending the first "qmp_capabilities" command. Originally we are starting QMP session with no arguments like: { "execute": "qmp_capabilities" } Now we can enable some QMP capabilities using (take OOB as example, which is the only one capability that we support): { "execute": "qmp_capabilities", "argument": { "enable": [ "oob" ] } } When the "argument" key is not provided, no capability is enabled. For capability "oob", the monitor needs to be run on dedicated IO thread, otherwise the command will fail. For example, trying to enable OOB on a MUXed typed QMP monitor will fail. One thing to mention is that, QMP capabilities are per-monitor, and also when the connection is closed due to some reason, the capabilities will be reset. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Stefan Hajnoczi --- monitor.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- qapi-schema.json | 15 ++++++++++--- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/monitor.c b/monitor.c index 81fb0a42b4..c88a11cd69 100644 --- a/monitor.c +++ b/monitor.c @@ -166,6 +166,7 @@ typedef struct { * mode. */ QmpCommandList *commands; + bool qmp_caps[QMP_CAPABILITY__MAX]; } MonitorQMP; =20 /* @@ -1035,8 +1036,42 @@ static void monitor_init_qmp_commands(void) qmp_marshal_qmp_capabilities, QCO_NO_OPTIONS); } =20 -void qmp_qmp_capabilities(Error **errp) +static void qmp_caps_check(Monitor *mon, QMPCapabilityList *list, + Error **errp) +{ + for (; list; list =3D list->next) { + assert(list->value < QMP_CAPABILITY__MAX); + switch (list->value) { + case QMP_CAPABILITY_OOB: + if (!mon->use_io_thr) { + /* + * Out-Of-Band only works with monitors that are + * running on dedicated IOThread. + */ + error_setg(errp, "This monitor does not support " + "Out-Of-Band (OOB)"); + return; + } + break; + default: + break; + } + } +} + +/* This function should only be called after capabilities are checked. */ +static void qmp_caps_apply(Monitor *mon, QMPCapabilityList *list) +{ + for (; list; list =3D list->next) { + mon->qmp.qmp_caps[list->value] =3D true; + } +} + +void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, + Error **errp) { + Error *local_err =3D NULL; + if (cur_mon->qmp.commands =3D=3D &qmp_commands) { error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, "Capabilities negotiation is already complete, command " @@ -1044,6 +1079,20 @@ void qmp_qmp_capabilities(Error **errp) return; } =20 + /* Enable QMP capabilities provided by the guest if applicable. */ + if (has_enable) { + qmp_caps_check(cur_mon, enable, &local_err); + if (local_err) { + /* + * Failed check on either of the capabilities will fail + * the apply of all. + */ + error_propagate(errp, local_err); + return; + } + qmp_caps_apply(cur_mon, enable); + } + cur_mon->qmp.commands =3D &qmp_commands; } =20 @@ -3941,7 +3990,7 @@ void monitor_resume(Monitor *mon) readline_show_prompt(mon->rs); } =20 -static QObject *get_qmp_greeting(void) +static QObject *get_qmp_greeting(Monitor *mon) { QList *cap_list =3D qlist_new(); QObject *ver =3D NULL; @@ -3950,6 +3999,10 @@ static QObject *get_qmp_greeting(void) qmp_marshal_query_version(NULL, &ver, NULL); =20 for (cap =3D 0; cap < QMP_CAPABILITY__MAX; cap++) { + if (!mon->use_io_thr && cap =3D=3D QMP_CAPABILITY_OOB) { + /* Monitors that are not using IOThread won't support OOB */ + continue; + } qlist_append(cap_list, qstring_from_str(QMPCapability_str(cap))); } =20 @@ -3957,6 +4010,11 @@ static QObject *get_qmp_greeting(void) ver, cap_list); } =20 +static void monitor_qmp_caps_reset(Monitor *mon) +{ + memset(mon->qmp.qmp_caps, 0, sizeof(mon->qmp.qmp_caps)); +} + static void monitor_qmp_event(void *opaque, int event) { QObject *data; @@ -3965,7 +4023,8 @@ static void monitor_qmp_event(void *opaque, int event) switch (event) { case CHR_EVENT_OPENED: mon->qmp.commands =3D &qmp_cap_negotiation_commands; - data =3D get_qmp_greeting(); + monitor_qmp_caps_reset(mon); + data =3D get_qmp_greeting(mon); monitor_json_emitter(mon, data); qobject_decref(data); mon_refcount++; diff --git a/qapi-schema.json b/qapi-schema.json index 03201578b4..531fd4c0db 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -102,21 +102,30 @@ # # Enable QMP capabilities. # -# Arguments: None. +# Arguments: +# +# @enable: List of QMPCapabilities to enable, which is optional. +# If not provided, it means no QMP capabilities will be +# enabled. (since 2.12) # # Example: # -# -> { "execute": "qmp_capabilities" } +# -> { "execute": "qmp_capabilities", +# "arguments": { "enable": [ "oob" ] } } # <- { "return": {} } # # Notes: This command is valid exactly when first connecting: it must be # issued before any other command will be accepted, and will fail once the # monitor is accepting other commands. (see qemu docs/interop/qmp-spec.txt) # +# QMP client needs to explicitly enable QMP capabilities, otherwise +# all the QMP capabilities will be turned off by default. +# # Since: 0.13 # ## -{ 'command': 'qmp_capabilities' } +{ 'command': 'qmp_capabilities', + 'data': { '*enable': [ 'QMPCapability' ] } } =20 ## # @QMPCapability: --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513674150169152.1196680787516; Tue, 19 Dec 2017 01:02:30 -0800 (PST) Received: from localhost ([::1]:59893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDn2-0005UK-4M for importer@patchew.org; Tue, 19 Dec 2017 04:02:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37670) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDZ7-0001HC-5F for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDZ2-00014R-9S for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDZ2-000146-2d for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:47:52 -0500 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 2E87EC047B6D; Tue, 19 Dec 2017 08:47:51 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF1466EE21; Tue, 19 Dec 2017 08:47:46 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:43 +0800 Message-Id: <20171219084557.9801-14-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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.31]); Tue, 19 Dec 2017 08:47:51 +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 v6 13/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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. Reviewed-by: Fam Zheng Signed-off-by: Peter Xu Reviewed-by: Stefan Hajnoczi --- monitor.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/monitor.c b/monitor.c index c88a11cd69..cf1e5d881c 100644 --- a/monitor.c +++ b/monitor.c @@ -3865,6 +3865,38 @@ static int monitor_can_read(void *opaque) return (mon->suspend_cnt =3D=3D 0) ? 1 : 0; } =20 +/* + * 1. This function takes ownership of rsp, err, and id. + * 2. rsp, err, and id may be NULL. + * 3. If err !=3D NULL then rsp must be NULL. + */ +static void monitor_qmp_respond(Monitor *mon, QObject *rsp, + Error *err, QObject *id) +{ + QDict *qdict =3D NULL; + + if (err) { + assert(!rsp); + 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) { QObject *req, *rsp =3D NULL, *id =3D NULL; @@ -3916,24 +3948,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.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673790147205.8855687505304; Tue, 19 Dec 2017 00:56:30 -0800 (PST) Received: from localhost ([::1]:59830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDh8-0000BH-Q2 for importer@patchew.org; Tue, 19 Dec 2017 03:56:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDZI-0001R0-PF for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:48:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDZD-0001Bp-U8 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:48:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDZD-0001BI-N6 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:48:03 -0500 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 CF421806A8; Tue, 19 Dec 2017 08:48:02 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id A684018A67; Tue, 19 Dec 2017 08:47:51 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:44 +0800 Message-Id: <20171219084557.9801-15-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:48:02 +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 v6 14/27] monitor: let suspend_cnt be thread safe 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" Monitor code now can be run in more than one thread. Let it be thread safe when accessing suspend_cnt counter. Signed-off-by: Peter Xu Reviewed-by: Eric Blake --- monitor.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/monitor.c b/monitor.c index cf1e5d881c..844508d134 100644 --- a/monitor.c +++ b/monitor.c @@ -3862,7 +3862,7 @@ static int monitor_can_read(void *opaque) { Monitor *mon =3D opaque; =20 - return (mon->suspend_cnt =3D=3D 0) ? 1 : 0; + return (atomic_mb_read(&mon->suspend_cnt) =3D=3D 0) ? 1 : 0; } =20 /* @@ -3994,7 +3994,7 @@ int monitor_suspend(Monitor *mon) { if (!mon->rs) return -ENOTTY; - mon->suspend_cnt++; + atomic_inc(&mon->suspend_cnt); return 0; } =20 @@ -4002,8 +4002,9 @@ void monitor_resume(Monitor *mon) { if (!mon->rs) return; - if (--mon->suspend_cnt =3D=3D 0) + if (atomic_dec_fetch(&mon->suspend_cnt) =3D=3D 0) { readline_show_prompt(mon->rs); + } } =20 static QObject *get_qmp_greeting(Monitor *mon) @@ -4068,19 +4069,19 @@ static void monitor_event(void *opaque, int event) monitor_resume(mon); monitor_flush(mon); } else { - mon->suspend_cnt =3D 0; + atomic_mb_set(&mon->suspend_cnt, 0); } break; =20 case CHR_EVENT_MUX_OUT: if (mon->reset_seen) { - if (mon->suspend_cnt =3D=3D 0) { + if (atomic_mb_read(&mon->suspend_cnt) =3D=3D 0) { monitor_printf(mon, "\n"); } monitor_flush(mon); monitor_suspend(mon); } else { - mon->suspend_cnt++; + atomic_inc(&mon->suspend_cnt); } qemu_mutex_lock(&mon->out_lock); mon->mux_out =3D 1; --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673946535380.03558954235996; Tue, 19 Dec 2017 00:59:06 -0800 (PST) Received: from localhost ([::1]:59845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDjj-0002cr-1W for importer@patchew.org; Tue, 19 Dec 2017 03:58:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDZl-0001qY-9N for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:48:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDZk-0001UZ-Au for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:48:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56960) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDZk-0001U1-4D for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:48:36 -0500 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 340BF5D68B; Tue, 19 Dec 2017 08:48:35 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D4916EE21; Tue, 19 Dec 2017 08:48:03 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:45 +0800 Message-Id: <20171219084557.9801-16-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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.39]); Tue, 19 Dec 2017 08:48: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 v6 15/27] monitor: let suspend/resume work even with QMPs 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" One thing to mention is that for QMPs that are using IOThreads, we need an explicit kick for the IOThread in case it is sleeping. Since at it, add traces for the operations. Signed-off-by: Peter Xu --- monitor.c | 26 +++++++++++++++++++++----- trace-events | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/monitor.c b/monitor.c index 844508d134..5f05f2e9da 100644 --- a/monitor.c +++ b/monitor.c @@ -3992,19 +3992,35 @@ static void monitor_command_cb(void *opaque, const = char *cmdline, =20 int monitor_suspend(Monitor *mon) { - if (!mon->rs) - return -ENOTTY; atomic_inc(&mon->suspend_cnt); + if (monitor_is_qmp(mon)) { + /* + * Kick iothread to make sure this takes effect. It'll be + * evaluated again in prepare() of the watch object. + */ + aio_notify(iothread_get_aio_context(mon_global.mon_iothread)); + } + trace_monitor_suspend(mon, 1); return 0; } =20 void monitor_resume(Monitor *mon) { - if (!mon->rs) - return; if (atomic_dec_fetch(&mon->suspend_cnt) =3D=3D 0) { - readline_show_prompt(mon->rs); + if (monitor_is_qmp(mon)) { + /* + * For QMP monitors that are running in IOThread, let's + * kick the thread in case it's sleeping. + */ + if (mon->use_io_thr) { + aio_notify(iothread_get_aio_context(mon_global.mon_iothrea= d)); + } + } else { + assert(mon->rs); + readline_show_prompt(mon->rs); + } } + trace_monitor_suspend(mon, -1); } =20 static QObject *get_qmp_greeting(Monitor *mon) diff --git a/trace-events b/trace-events index 1d2eb5d3e4..2646241a0f 100644 --- a/trace-events +++ b/trace-events @@ -47,6 +47,7 @@ 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_suspend(void *ptr, int cnt) "mon %p: %d" =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.14.3 From nobody Mon Apr 29 06:38:23 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1513673835715346.646006010685; Tue, 19 Dec 2017 00:57:15 -0800 (PST) Received: from localhost ([::1]:59832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDhr-0000pB-Df for importer@patchew.org; Tue, 19 Dec 2017 03:56:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDaD-0002Id-Ek for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDa8-0001qu-GP for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDa8-0001pM-5e for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:00 -0500 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 3D15E40255; Tue, 19 Dec 2017 08:48:59 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id A97C46EE21; Tue, 19 Dec 2017 08:48:36 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:46 +0800 Message-Id: <20171219084557.9801-17-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:48:59 +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 v6 16/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Originally QMP goes 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 QEMUBH is used for all the monitors. Signed-off-by: Peter Xu --- monitor.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---= ---- 1 file changed, 178 insertions(+), 23 deletions(-) diff --git a/monitor.c b/monitor.c index 5f05f2e9da..ed9a741d06 100644 --- a/monitor.c +++ b/monitor.c @@ -167,6 +167,13 @@ typedef struct { */ QmpCommandList *commands; bool qmp_caps[QMP_CAPABILITY__MAX]; + /* + * Protects qmp request/response queue. Please take monitor_lock + * first when used together. + */ + QemuMutex qmp_queue_lock; + /* Input queue that holds all the parsed QMP requests */ + GQueue *qmp_requests; } MonitorQMP; =20 /* @@ -213,6 +220,8 @@ struct Monitor { /* Let's add monitor global variables to this struct. */ static struct { IOThread *mon_iothread; + /* Bottom half to dispatch the requests received from IO thread */ + QEMUBH *qmp_dispatcher_bh; } mon_global; =20 /* QMP checker flags */ @@ -580,11 +589,13 @@ static void monitor_data_init(Monitor *mon, bool skip= _flush, { memset(mon, 0, sizeof(Monitor)); qemu_mutex_init(&mon->out_lock); + qemu_mutex_init(&mon->qmp.qmp_queue_lock); mon->outbuf =3D qstring_new(); /* 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; + mon->qmp.qmp_requests =3D g_queue_new(); } =20 static void monitor_data_destroy(Monitor *mon) @@ -597,6 +608,8 @@ static void monitor_data_destroy(Monitor *mon) g_free(mon->rs); QDECREF(mon->outbuf); qemu_mutex_destroy(&mon->out_lock); + qemu_mutex_destroy(&mon->qmp.qmp_queue_lock); + g_queue_free(mon->qmp.qmp_requests); } =20 char *qmp_human_monitor_command(const char *command_line, bool has_cpu_ind= ex, @@ -1036,6 +1049,16 @@ static void monitor_init_qmp_commands(void) qmp_marshal_qmp_capabilities, QCO_NO_OPTIONS); } =20 +static bool qmp_cap_enabled(Monitor *mon, QMPCapability cap) +{ + return mon->qmp.qmp_caps[cap]; +} + +static bool qmp_oob_enabled(Monitor *mon) +{ + return qmp_cap_enabled(mon, QMP_CAPABILITY_OOB); +} + static void qmp_caps_check(Monitor *mon, QMPCapabilityList *list, Error **errp) { @@ -3897,30 +3920,39 @@ static void monitor_qmp_respond(Monitor *mon, QObje= ct *rsp, qobject_decref(rsp); } =20 -static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) +struct QMPRequest { + /* Owner of the request */ + Monitor *mon; + /* "id" field of the request */ + QObject *id; + /* Request object to be handled */ + QObject *req; + /* + * Whether we need to resume the monitor afterward. This flag is + * used to emulate the old QMP server behavior that only one + * command is executed for each time. + */ + bool need_resume; +}; +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; - MonitorQMP *mon_qmp =3D container_of(parser, MonitorQMP, parser); - Monitor *old_mon, *mon =3D container_of(mon_qmp, Monitor, qmp); - - Error *err =3D NULL; + bool need_resume; =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; + need_resume =3D req_obj->need_resume; =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); @@ -3931,7 +3963,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 @@ -3947,12 +3979,122 @@ static void handle_qmp_command(JSONMessageParser *= parser, GQueue *tokens) } } =20 -err_out: - monitor_qmp_respond(mon, rsp, err, id); + /* Respond if necessary */ + monitor_qmp_respond(mon, rsp, NULL, id); + + /* This pairs with the monitor_suspend() in handle_qmp_command(). */ + if (need_resume) { + monitor_resume(mon); + } =20 qobject_decref(req); } =20 +/* + * Pop one QMP request from monitor queues, return NULL if not found. + * We are using round-robin fasion to pop the request, to avoid + * processing command only on a very busy monitor. To achieve that, + * when we processed one request on specific monitor, we put that + * monitor to the end of mon_list queue. + */ +static QMPRequest *monitor_qmp_requests_pop_one(void) +{ + QMPRequest *req_obj =3D NULL; + Monitor *mon; + + qemu_mutex_lock(&monitor_lock); + + QTAILQ_FOREACH(mon, &mon_list, entry) { + qemu_mutex_lock(&mon->qmp.qmp_queue_lock); + req_obj =3D g_queue_pop_head(mon->qmp.qmp_requests); + qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); + if (req_obj) { + break; + } + } + + if (req_obj) { + /* + * We found one request on the monitor. Degrade this monitor's + * priority to lowest by re-inserting it to end of queue. + */ + QTAILQ_REMOVE(&mon_list, mon, entry); + QTAILQ_INSERT_TAIL(&mon_list, mon, entry); + } + + qemu_mutex_unlock(&monitor_lock); + + return req_obj; +} + +static void monitor_qmp_bh_dispatcher(void *data) +{ + QMPRequest *req_obj =3D monitor_qmp_requests_pop_one(); + + if (req_obj) { + monitor_qmp_dispatch_one(req_obj); + /* Reschedule instead of looping so the main loop stays responsive= */ + qemu_bh_schedule(mon_global.qmp_dispatcher_bh); + } +} + +static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) +{ + QObject *req, *id =3D NULL; + QDict *qdict =3D NULL; + MonitorQMP *mon_qmp =3D container_of(parser, MonitorQMP, parser); + Monitor *mon =3D container_of(mon_qmp, Monitor, qmp); + 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); + return; + } + + 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; + req_obj->need_resume =3D false; + + /* + * If OOB is not enabled on current monitor, we'll emulate the old + * behavior that we won't process current monitor any more until + * it is responded. This helps make sure that as long as OOB is + * not enabled, the server will never drop any command. + */ + if (!qmp_oob_enabled(mon)) { + monitor_suspend(mon); + req_obj->need_resume =3D true; + } + + /* + * 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. + */ + qemu_mutex_lock(&mon->qmp.qmp_queue_lock); + g_queue_push_tail(mon->qmp.qmp_requests, req_obj); + qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); + + /* 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; @@ -4150,6 +4292,15 @@ static void monitor_iothread_init(void) { mon_global.mon_iothread =3D iothread_create("mon_iothread", &error_abort); + + /* + * 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); } =20 void monitor_init_globals(void) @@ -4272,6 +4423,10 @@ void monitor_cleanup(void) } qemu_mutex_unlock(&monitor_lock); =20 + /* QEMUBHs needs to be deleted before destroying the IOThread. */ + qemu_bh_delete(mon_global.qmp_dispatcher_bh); + mon_global.qmp_dispatcher_bh =3D NULL; + iothread_destroy(mon_global.mon_iothread); mon_global.mon_iothread =3D NULL; } --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673984097442.8691763506573; Tue, 19 Dec 2017 00:59:44 -0800 (PST) Received: from localhost ([::1]:59848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDkQ-0003Ft-0z for importer@patchew.org; Tue, 19 Dec 2017 03:59:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDaE-0002Je-GW for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDaD-0001uv-HS for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56700) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDaD-0001uF-CD for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:05 -0500 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 8063781DE3; Tue, 19 Dec 2017 08:49:04 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4B9360C8E; Tue, 19 Dec 2017 08:48:59 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:47 +0800 Message-Id: <20171219084557.9801-18-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:49:04 +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 v6 17/27] qmp: add new event "command-dropped" 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" This event will be emitted if one QMP command is dropped. Along, declare an enum for the reasons. Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- qapi-schema.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 531fd4c0db..447ab25572 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3222,3 +3222,40 @@ # Since: 2.11 ## { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} } + +## +# @CommandDropReason: +# +# Reasons that caused one command to be dropped. +# +# @queue-full: the queue of command is full. This can only occur when +# the client sends a new non-oob command before the +# response to the previous non-oob command has been +# received. +# +# Since: 2.12 +## +{ 'enum': 'CommandDropReason', + 'data': [ 'queue-full' ] } + +## +# @COMMAND_DROPPED: +# +# Emitted when a command is dropped due to some reason. Commands can +# only be dropped when the oob capability is enabled. +# +# @id: The dropped command's "id" field. +# +# @reason: The reason why the command is dropped. +# +# Since: 2.12 +# +# Example: +# +# { "event": "COMMAND_DROPPED", +# "data": {"result": {"id": "libvirt-102", +# "reason": "queue-full" } } } +# +## +{ 'event': 'COMMAND_DROPPED' , + 'data': { 'id': 'any', 'reason': 'CommandDropReason' } } --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513673685264465.02115679778683; Tue, 19 Dec 2017 00:54:45 -0800 (PST) Received: from localhost ([::1]:59782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDfS-0006r6-Gi for importer@patchew.org; Tue, 19 Dec 2017 03:54:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDaS-0002WO-Qk for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDaN-00020k-UZ for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDaN-0001zx-P5 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:15 -0500 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 DA039883C0; Tue, 19 Dec 2017 08:49:14 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 000686EE21; Tue, 19 Dec 2017 08:49:04 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:48 +0800 Message-Id: <20171219084557.9801-19-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:49:14 +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 v6 18/27] monitor: send event when command queue full 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , Paolo Bonzini , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Set maximum QMP command queue length to 8. If queue full, instead of queue the command, we directly return a "command-dropped" event, telling client that specific command is dropped. Note that this flow control mechanism is only valid if OOB is enabled. If it's not, the effective queue length will always be 1, which strictly follows original behavior of QMP command handling (which never drop messages). Signed-off-by: Peter Xu --- monitor.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index ed9a741d06..b571866659 100644 --- a/monitor.c +++ b/monitor.c @@ -4038,6 +4038,8 @@ static void monitor_qmp_bh_dispatcher(void *data) } } =20 +#define QMP_REQ_QUEUE_LEN_MAX (8) + static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) { QObject *req, *id =3D NULL; @@ -4071,6 +4073,9 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) req_obj->req =3D req; req_obj->need_resume =3D false; =20 + /* Protect qmp_requests and fetching its length. */ + qemu_mutex_lock(&mon->qmp.qmp_queue_lock); + /* * If OOB is not enabled on current monitor, we'll emulate the old * behavior that we won't process current monitor any more until @@ -4080,6 +4085,17 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) if (!qmp_oob_enabled(mon)) { monitor_suspend(mon); req_obj->need_resume =3D true; + } else { + /* Drop the request if queue is full. */ + if (mon->qmp.qmp_requests->length >=3D QMP_REQ_QUEUE_LEN_MAX) { + qapi_event_send_command_dropped(id, + COMMAND_DROP_REASON_QUEUE_FULL, + NULL); + qobject_decref(id); + qobject_decref(req); + g_free(req_obj); + return; + } } =20 /* @@ -4087,7 +4103,6 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) * handled in time order. Ownership for req_obj, req, id, * etc. will be delivered to the handler side. */ - qemu_mutex_lock(&mon->qmp.qmp_queue_lock); g_queue_push_tail(mon->qmp.qmp_requests, req_obj); qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); =20 --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513673842072456.2759600005654; Tue, 19 Dec 2017 00:57:22 -0800 (PST) Received: from localhost ([::1]:59833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDi9-00013B-0V for importer@patchew.org; Tue, 19 Dec 2017 03:57:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDaX-0002bJ-T7 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDaW-00025y-J2 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDaW-00025P-8W for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:24 -0500 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 550D87F7DA; Tue, 19 Dec 2017 08:49:23 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BBD36EE21; Tue, 19 Dec 2017 08:49:15 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:49 +0800 Message-Id: <20171219084557.9801-20-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:49:23 +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 v6 19/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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. 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 Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- 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 +- 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 20578dcd48..b76798800c 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 5b3e6e9d78..c7f67b7d78 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.12) +# # 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 974d0a4a80..b2b0bc0510 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 032bcea491..9fbf88b644 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 62dc52ed6e..f411b8fc91 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 a317526e51..0ac0df517a 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 c7724d3437..6749e9e397 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.14.3 From nobody Mon Apr 29 06:38:23 2024 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 151367413763627.898917066652302; Tue, 19 Dec 2017 01:02:17 -0800 (PST) Received: from localhost ([::1]:59891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDma-00059I-3H for importer@patchew.org; Tue, 19 Dec 2017 04:01:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDap-0002pl-63 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDak-0002DE-BD for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:19772) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDak-0002CV-4S for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:38 -0500 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 35F3B2C973B; Tue, 19 Dec 2017 08:49:37 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id C97FB6EE21; Tue, 19 Dec 2017 08:49:23 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:50 +0800 Message-Id: <20171219084557.9801-21-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:49:37 +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 v6 20/27] qmp: export qmp_dispatch_check_obj and allow "id" 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" We need this for earlier check for OOB, before reaching do_qmp_dispatch(). Meanwhile, a small touch-up to allow "id" field, after all we allow that for sure in the spec (in any form). Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-dispatch.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index b76798800c..cf2657b5c9 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); +QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp); =20 typedef void (*qmp_cmd_callback_fn)(QmpCommand *cmd, void *opaque); =20 diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index b41fa174fe..b16f2f1d3f 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -20,7 +20,7 @@ #include "qapi-types.h" #include "qapi/qmp/qerror.h" =20 -static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) +QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) { const QDictEntry *ent; const char *arg_name; @@ -52,6 +52,8 @@ static QDict *qmp_dispatch_check_obj(const QObject *reque= st, Error **errp) "QMP input member 'arguments' must be an object= "); return NULL; } + } else if (!strcmp(arg_name, "id")) { + continue; } else { error_setg(errp, "QMP input member '%s' is unexpected", arg_name); --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513674172229768.5725245727745; Tue, 19 Dec 2017 01:02:52 -0800 (PST) Received: from localhost ([::1]:59909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDnV-0005sh-3S for importer@patchew.org; Tue, 19 Dec 2017 04:02:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDat-0002tw-E0 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDas-0002Id-2c for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42706) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDar-0002I3-QU for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:46 -0500 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 DD1F9745; Tue, 19 Dec 2017 08:49:44 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB97E6EE21; Tue, 19 Dec 2017 08:49:37 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:51 +0800 Message-Id: <20171219084557.9801-22-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:49:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v6 21/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 Reviewed-by: Fam Zheng --- include/qapi/qmp/dispatch.h | 1 + monitor.c | 83 ++++++++++++++++++++++++++++++++++++++++-= ---- qapi/qmp-dispatch.c | 28 +++++++++++++++ trace-events | 2 ++ 4 files changed, 105 insertions(+), 9 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index cf2657b5c9..d8d913b338 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -50,6 +50,7 @@ const char *qmp_command_name(const QmpCommand *cmd); bool qmp_has_success_response(const QmpCommand *cmd); QObject *qmp_build_error_object(Error *err); QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp); +bool qmp_is_oob(QDict *dict); =20 typedef void (*qmp_cmd_callback_fn)(QmpCommand *cmd, void *opaque); =20 diff --git a/monitor.c b/monitor.c index b571866659..505db439d8 100644 --- a/monitor.c +++ b/monitor.c @@ -1090,6 +1090,44 @@ static void qmp_caps_apply(Monitor *mon, QMPCapabili= tyList *list) } } =20 +/* + * Return true if check successful, or false otherwise. When false is + * returned, detailed error will be in errp if provided. + */ +static bool qmp_cmd_oob_check(Monitor *mon, QDict *req, Error **errp) +{ + const char *command; + QmpCommand *cmd; + + command =3D qdict_get_try_str(req, "execute"); + if (!command) { + error_setg(errp, "Command field 'execute' missing"); + return false; + } + + cmd =3D qmp_find_command(mon->qmp.commands, command); + if (!cmd) { + error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, + "The command %s has not been found", command); + return false; + } + + if (qmp_is_oob(req)) { + if (!qmp_oob_enabled(mon)) { + error_setg(errp, "Please enable Out-Of-Band first " + "for the session during handshake"); + return false; + } + if (!(cmd->options & QCO_ALLOW_OOB)) { + error_setg(errp, "The command %s does not support OOB", + command); + return false; + } + } + + return true; +} + void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, Error **errp) { @@ -4032,6 +4070,7 @@ static void monitor_qmp_bh_dispatcher(void *data) QMPRequest *req_obj =3D monitor_qmp_requests_pop_one(); =20 if (req_obj) { + trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id)); monitor_qmp_dispatch_one(req_obj); /* Reschedule instead of looping so the main loop stays responsive= */ qemu_bh_schedule(mon_global.qmp_dispatcher_bh); @@ -4055,17 +4094,31 @@ static void handle_qmp_command(JSONMessageParser *p= arser, GQueue *tokens) error_setg(&err, QERR_JSON_PARSING); } if (err) { - monitor_qmp_respond(mon, NULL, err, NULL); - qobject_decref(req); - return; + goto err; + } + + /* Check against the request in general layout */ + qdict =3D qmp_dispatch_check_obj(req, &err); + if (!qdict) { + goto err; } =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() */ + /* Check against OOB specific */ + if (!qmp_cmd_oob_check(mon, qdict, &err)) { + goto err; + } + + id =3D qdict_get(qdict, "id"); + + /* When OOB is enabled, the "id" field is mandatory. */ + if (qmp_oob_enabled(mon) && !id) { + error_setg(&err, "Out-Of-Band capability requires that " + "every command contains an 'id' field."); + goto err; + } + + qobject_incref(id); + qdict_del(qdict, "id"); =20 req_obj =3D g_new0(QMPRequest, 1); req_obj->mon =3D mon; @@ -4073,6 +4126,13 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) req_obj->req =3D req; req_obj->need_resume =3D false; =20 + if (qmp_is_oob(qdict)) { + /* Out-Of-Band (OOB) requests are executed directly in parser. */ + trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(req_obj->id)= ); + monitor_qmp_dispatch_one(req_obj); + return; + } + /* Protect qmp_requests and fetching its length. */ qemu_mutex_lock(&mon->qmp.qmp_queue_lock); =20 @@ -4108,6 +4168,11 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) =20 /* Kick the dispatcher routine */ qemu_bh_schedule(mon_global.qmp_dispatcher_bh); + return; + +err: + monitor_qmp_respond(mon, NULL, err, NULL); + qobject_decref(req); } =20 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index b16f2f1d3f..675223e0ec 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -54,6 +54,12 @@ QDict *qmp_dispatch_check_obj(const QObject *request, Er= ror **errp) } } else if (!strcmp(arg_name, "id")) { continue; + } else if (!strcmp(arg_name, "control")) { + if (qobject_type(arg_obj) !=3D QTYPE_QDICT) { + error_setg(errp, + "QMP input member 'control' must be a dict"); + return NULL; + } } else { error_setg(errp, "QMP input member '%s' is unexpected", arg_name); @@ -124,6 +130,28 @@ 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(QDict *dict) +{ + QBool *bool_obj; + + 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 2646241a0f..1fb9ea7df2 100644 --- a/trace-events +++ b/trace-events @@ -48,6 +48,8 @@ monitor_protocol_event_queue(uint32_t event, void *qdict,= uint64_t rate) "event=3D 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_suspend(void *ptr, int cnt) "mon %p: %d" +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.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513674310943281.3822032330536; Tue, 19 Dec 2017 01:05:10 -0800 (PST) Received: from localhost ([::1]:60193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDpg-00085s-Tk for importer@patchew.org; Tue, 19 Dec 2017 04:05:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDb7-00038m-Ii for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDb2-0002O4-KO for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDb2-0002Nb-A6 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:49:56 -0500 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 5A9BC80460; Tue, 19 Dec 2017 08:49:55 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D60560C80; Tue, 19 Dec 2017 08:49:45 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:52 +0800 Message-Id: <20171219084557.9801-23-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:49:55 +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 v6 22/27] qmp: isolate responses into 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 those monitors who has enabled IO thread, we'll offload the responding procedure into IO thread. The main reason is that chardev is not thread safe, and we need to do all the read/write IOs in the same thread. For use_io_thr=3Dtrue monitors, that thread is the IO thread. We do this isolation in similar pattern as what we have done to the request queue: we first create one response queue for each monitor, then instead of reply directly in main thread, we queue the responses and kick the IO thread to do the rest of the job for us. A funny thing after doing this is that, when the QMP clients send "quit" to QEMU, it's possible that we close the IOThread even earlier than replying to that "quit". So another thing we need to do before cleaning up the monitors is that we need to flush the response queue (we don't need to do that for command queue; after all we are quitting) to make sure replies for handled commands are always flushed back to clients. Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- monitor.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index 505db439d8..0c6403bc65 100644 --- a/monitor.c +++ b/monitor.c @@ -174,6 +174,8 @@ typedef struct { QemuMutex qmp_queue_lock; /* Input queue that holds all the parsed QMP requests */ GQueue *qmp_requests; + /* Output queue contains all the QMP responses in order */ + GQueue *qmp_responses; } MonitorQMP; =20 /* @@ -222,6 +224,8 @@ static struct { IOThread *mon_iothread; /* Bottom half to dispatch the requests received from IO thread */ QEMUBH *qmp_dispatcher_bh; + /* Bottom half to deliver the responses back to clients */ + QEMUBH *qmp_respond_bh; } mon_global; =20 /* QMP checker flags */ @@ -396,7 +400,8 @@ int monitor_fprintf(FILE *stream, const char *fmt, ...) return 0; } =20 -static void monitor_json_emitter(Monitor *mon, const QObject *data) +static void monitor_json_emitter_raw(Monitor *mon, + QObject *data) { QString *json; =20 @@ -410,6 +415,71 @@ static void monitor_json_emitter(Monitor *mon, const Q= Object *data) QDECREF(json); } =20 +static void monitor_json_emitter(Monitor *mon, QObject *data) +{ + if (mon->use_io_thr) { + /* + * If using IO thread, we need to queue the item so that IO + * thread will do the rest for us. Take refcount so that + * caller won't free the data (which will be finally freed in + * responder thread). + */ + qobject_incref(data); + qemu_mutex_lock(&mon->qmp.qmp_queue_lock); + g_queue_push_tail(mon->qmp.qmp_responses, (void *)data); + qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); + qemu_bh_schedule(mon_global.qmp_respond_bh); + } else { + /* + * If not using monitor IO thread, then we are in main thread. + * Do the emission right away. + */ + monitor_json_emitter_raw(mon, data); + } +} + +struct QMPResponse { + Monitor *mon; + QObject *data; +}; +typedef struct QMPResponse QMPResponse; + +/* + * Return one QMPResponse. The response is only valid if + * response.data is not NULL. + */ +static QMPResponse monitor_qmp_response_pop_one(void) +{ + Monitor *mon; + QObject *data =3D NULL; + + qemu_mutex_lock(&monitor_lock); + QTAILQ_FOREACH(mon, &mon_list, entry) { + qemu_mutex_lock(&mon->qmp.qmp_queue_lock); + data =3D g_queue_pop_head(mon->qmp.qmp_responses); + qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); + if (data) { + break; + } + } + qemu_mutex_unlock(&monitor_lock); + return (QMPResponse) { .mon =3D mon, .data =3D data }; +} + +static void monitor_qmp_bh_responder(void *opaque) +{ + QMPResponse response; + + while (true) { + response =3D monitor_qmp_response_pop_one(); + if (!response.data) { + break; + } + monitor_json_emitter_raw(response.mon, response.data); + qobject_decref(response.data); + } +} + static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] =3D { /* Limit guest-triggerable events to 1 per second */ [QAPI_EVENT_RTC_CHANGE] =3D { 1000 * SCALE_MS }, @@ -596,6 +666,7 @@ static void monitor_data_init(Monitor *mon, bool skip_f= lush, mon->skip_flush =3D skip_flush; mon->use_io_thr =3D use_io_thr; mon->qmp.qmp_requests =3D g_queue_new(); + mon->qmp.qmp_responses =3D g_queue_new(); } =20 static void monitor_data_destroy(Monitor *mon) @@ -610,6 +681,7 @@ static void monitor_data_destroy(Monitor *mon) qemu_mutex_destroy(&mon->out_lock); qemu_mutex_destroy(&mon->qmp.qmp_queue_lock); g_queue_free(mon->qmp.qmp_requests); + g_queue_free(mon->qmp.qmp_responses); } =20 char *qmp_human_monitor_command(const char *command_line, bool has_cpu_ind= ex, @@ -4368,6 +4440,11 @@ static GMainContext *monitor_io_context_get(void) return iothread_get_g_main_context(mon_global.mon_iothread); } =20 +static AioContext *monitor_aio_context_get(void) +{ + return iothread_get_aio_context(mon_global.mon_iothread); +} + static void monitor_iothread_init(void) { mon_global.mon_iothread =3D iothread_create("mon_iothread", @@ -4381,6 +4458,15 @@ static void monitor_iothread_init(void) mon_global.qmp_dispatcher_bh =3D aio_bh_new(qemu_get_aio_context(), monitor_qmp_bh_dispatcher, NULL); + + /* + * Unlike the dispatcher BH, this must be run on the monitor IO + * thread, so that monitors that are using IO thread will make + * sure read/write operations are all done on the IO thread. + */ + mon_global.qmp_respond_bh =3D aio_bh_new(monitor_aio_context_get(), + monitor_qmp_bh_responder, + NULL); } =20 void monitor_init_globals(void) @@ -4495,9 +4581,19 @@ void monitor_cleanup(void) */ iothread_stop(mon_global.mon_iothread); =20 + /* + * After we have IOThread to send responses, it's possible that + * when we stop the IOThread there are still replies queued in the + * responder queue. Flush all of them. Note that even after this + * flush it's still possible that out buffer is not flushed. + * It'll be done in below monitor_flush() as the last resort. + */ + monitor_qmp_bh_responder(NULL); + qemu_mutex_lock(&monitor_lock); QTAILQ_FOREACH_SAFE(mon, &mon_list, entry, next) { QTAILQ_REMOVE(&mon_list, mon, entry); + monitor_flush(mon); monitor_data_destroy(mon); g_free(mon); } @@ -4506,6 +4602,8 @@ void monitor_cleanup(void) /* QEMUBHs needs to be deleted before destroying the IOThread. */ qemu_bh_delete(mon_global.qmp_dispatcher_bh); mon_global.qmp_dispatcher_bh =3D NULL; + qemu_bh_delete(mon_global.qmp_respond_bh); + mon_global.qmp_respond_bh =3D NULL; =20 iothread_destroy(mon_global.mon_iothread); mon_global.mon_iothread =3D NULL; --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513674069828856.8258527750219; Tue, 19 Dec 2017 01:01:09 -0800 (PST) Received: from localhost ([::1]:59877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDln-0004VG-PX for importer@patchew.org; Tue, 19 Dec 2017 04:01:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDbP-0003RD-9L for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDbO-0002dj-BZ for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37058) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDbN-0002b8-Qt for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:18 -0500 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 E7BD9C00ADE0; Tue, 19 Dec 2017 08:50:16 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE396619AF; Tue, 19 Dec 2017 08:49:55 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:53 +0800 Message-Id: <20171219084557.9801-24-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:50: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 v6 23/27] 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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 Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- monitor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/monitor.c b/monitor.c index 0c6403bc65..7183061c2b 100644 --- a/monitor.c +++ b/monitor.c @@ -35,6 +35,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" @@ -4522,8 +4523,10 @@ void monitor_init(Chardev *chr, int flags) { Monitor *mon =3D g_malloc(sizeof(*mon)); GMainContext *context; + /* Enable IOThread for QMPs that are not using MUX chardev backends. */ + bool use_io_thr =3D (!CHARDEV_IS_MUX(chr)) && (flags & MONITOR_USE_CON= TROL); =20 - monitor_data_init(mon, false, false); + monitor_data_init(mon, false, use_io_thr); =20 qemu_chr_fe_init(&mon->chr, chr, &error_abort); mon->flags =3D flags; --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513674499658686.1571739728591; Tue, 19 Dec 2017 01:08:19 -0800 (PST) Received: from localhost ([::1]:60297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDsb-0002YB-Mq for importer@patchew.org; Tue, 19 Dec 2017 04:08:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDbj-0003mI-A2 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDbe-0002ps-CV for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDbe-0002oF-6d for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:34 -0500 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 4BFD4C0601E1; Tue, 19 Dec 2017 08:50:33 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67C6660C80; Tue, 19 Dec 2017 08:50:17 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:54 +0800 Message-Id: <20171219084557.9801-25-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:50:33 +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 v6 24/27] qmp: add command "x-oob-test" 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" This command is only used to test OOB functionality. It should not be used for any other purposes. Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- qapi-schema.json | 18 ++++++++++++++++++ qmp.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 447ab25572..a63cd42cdd 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3259,3 +3259,21 @@ ## { 'event': 'COMMAND_DROPPED' , 'data': { 'id': 'any', 'reason': 'CommandDropReason' } } + +## +# @x-oob-test: +# +# Test OOB functionality. When send this command with lock=3Dtrue, +# it'll try to hang the dispatcher. When send it with lock=3Dfalse, +# it'll try to notify the locked thread to continue. Note: it should +# only be used by QMP test program rather than anything else. +# +# Since: 2.12 +# +# Example: +# +# { "execute": "x-oob-test", +# "arguments": { "lock": true } } +## +{ 'command': 'x-oob-test', 'data' : { 'lock': 'bool' }, + 'allow-oob': true } diff --git a/qmp.c b/qmp.c index e8c303116a..ca2968aad2 100644 --- a/qmp.c +++ b/qmp.c @@ -722,3 +722,19 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp) =20 return mem_info; } + +static QemuSemaphore x_oob_test_sem; + +static void __attribute__((constructor)) x_oob_test_init(void) +{ + qemu_sem_init(&x_oob_test_sem, 0); +} + +void qmp_x_oob_test(bool lock, Error **errp) +{ + if (lock) { + qemu_sem_wait(&x_oob_test_sem); + } else { + qemu_sem_post(&x_oob_test_sem); + } +} --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 151367436810357.425134413712726; Tue, 19 Dec 2017 01:06:08 -0800 (PST) Received: from localhost ([::1]:60200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDqc-0000d6-Qa for importer@patchew.org; Tue, 19 Dec 2017 04:06:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDbk-0003o8-SP for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDbj-0002v0-EZ for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57892) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDbj-0002uL-5e for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:39 -0500 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 4EAE985363; Tue, 19 Dec 2017 08:50:38 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id C20C160C80; Tue, 19 Dec 2017 08:50:33 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:55 +0800 Message-Id: <20171219084557.9801-26-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:50:38 +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 v6 25/27] docs: update QMP documents for OOB commands 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" Update both the developer and spec for the new QMP OOB (Out-Of-Band) command. Signed-off-by: Peter Xu --- docs/devel/qapi-code-gen.txt | 70 ++++++++++++++++++++++++++++++++++++++++= ---- docs/interop/qmp-spec.txt | 30 ++++++++++++++++--- 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index f04c63fe82..02cc1a4075 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -554,9 +554,12 @@ following example objects: =20 =3D=3D=3D Commands =3D=3D=3D =20 +--- General Command Layout --- + 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 +639,61 @@ 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 +A command can be declared to support Out-Of-Band (OOB) execution. By +default, commands do not support OOB. To declare a command to support +it, we need an extra 'allow-oob' field. For example: + + { 'command': 'migrate_recover', + 'data': { 'uri': 'str' }, 'allow-oob': true } + +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 support out-of-band execution will +still be run In-Band. + +Please read the "Out-Of-Band Command Execution" section below for more +information on how OOB execution works. + +--- About Out-Of-Band (OOB) Command Execution --- + +Out-Of-Band does not mean a special kind of command. Instead, it's a +special way to execute the command. One normal command can be +declared to support Out-Of-Band execution when 'allow-oob' field is +set to true when defining the command. With that, it can be run in an +Out-Of-Band way if 'run-oob' is specified in 'control' field of +command request. + +When we say normal QMP command executions, it means basically the +following: + +- They are executed in order, +- They run only in main thread of QEMU, +- They have the BQL taken during execution. + +For OOB command executions, they differ in the following: + +- They can be executed before an existing command, +- They run in a monitor dedicated thread, +- They do not take the BQL during execution. + +To add OOB execution support for a command, we need to make sure the +command handler satisfies at least the following: + +- It executes extremely fast, +- It does not take any lock (or, it can take very small locks, but in + very predictable ways), +- It does not invoke system calls that may block, +- It does not access guest RAM that may block when userfaultfd is + enabled for postcopy live migration. + +If someone is unsure about whether a command handler can be run in OOB +way, then it possibly means that it does not suite for OOB execution. =20 =3D=3D=3D Events =3D=3D=3D =20 @@ -739,10 +797,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/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt index f8b5356015..e20163c138 100644 --- a/docs/interop/qmp-spec.txt +++ b/docs/interop/qmp-spec.txt @@ -83,16 +83,27 @@ The greeting message format is: 2.2.1 Capabilities ------------------ =20 -As of the date this document was last revised, no server or client -capability strings have been defined. +Currently supported capabilities are: =20 +- "oob": it means the QMP server supports "Out-Of-Band" command + execution. For more detail, please see "run-oob" parameter in + "Issuing Commands" section below. Not all commands allow this "oob" + execution. One can know whether one command supports "oob" by + "query-qmp-schema" command. + +QMP clients can get a list of supported QMP capabilities of the QMP +server in the greeting message mentioned above. By default, all the +capabilities are off. To enable a specific or multiple of QMP +capabilities, QMP client needs to send "qmp_capabilities" command with +extra parameter for the capabilities. =20 2.3 Issuing Commands -------------------- =20 The format for command execution is: =20 -{ "execute": json-string, "arguments": json-object, "id": json-value } +{ "execute": json-string, "arguments": json-object, "id": json-value, + "control": json-dict } =20 Where, =20 @@ -102,10 +113,16 @@ The format for command execution is: required. Each command documents what contents will be considered valid when handling the json-argument - The "id" member is a transaction identification associated with the - command execution, it is optional and will be part of the response if + command execution. It is required if OOB is enabled, and optional + if not. The same "id" field will be part of the response if provided. The "id" member can be any json-value, although most clients merely use a json-number incremented for each successive command +- The "control" member is optional, and currently only used for + "out-of-band" execution ("oob" as shortcut). The handling or + response of an "oob" command can overtake prior in-band commands. + To enable "oob" feature, just provide a control field with: { + "control": { "run-oob": true } } =20 2.4 Commands Responses ---------------------- @@ -113,6 +130,11 @@ The format for command execution is: There are two possible responses which the Server will issue as the result of a command execution: success or error. =20 +As long as the commands were issued with a proper "id" field, then the +same "id" field will be attached in the corresponding response message +so that requests and responses can match. Clients should drop all the +responses that are with unknown "id" field. + 2.4.1 success ------------- =20 --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513674637885203.49383832464366; Tue, 19 Dec 2017 01:10:37 -0800 (PST) Received: from localhost ([::1]:60491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDus-00051e-9l for importer@patchew.org; Tue, 19 Dec 2017 04:10:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDc8-0004BT-Vj for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:51:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDc3-00039x-ML for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:51:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58210) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDc3-00039V-Fw for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:50:59 -0500 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 8C6EE81DE3; Tue, 19 Dec 2017 08:50:58 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFB3F60C80; Tue, 19 Dec 2017 08:50:38 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:56 +0800 Message-Id: <20171219084557.9801-27-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:50: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 v6 26/27] tests: qmp-test: verify command batching 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" OOB introduced DROP event for flow control. This should not affect old QMP clients. Add a command batching check to make sure of it. Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- tests/qmp-test.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 292c5f135a..6bc66b0a01 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -78,6 +78,7 @@ static void test_qmp_protocol(void) QList *capabilities; const QListEntry *entry; QString *qstr; + int i; =20 global_qtest =3D qtest_init_without_qmp_handshake(common_args); =20 @@ -135,6 +136,27 @@ static void test_qmp_protocol(void) g_assert_cmpint(qdict_get_int(resp, "id"), =3D=3D, 2); QDECREF(resp); =20 + /* + * Test command batching. In current test OOB is not enabled, we + * should be able to run as many commands in batch as we like. + * Using 16 (>8, which is OOB queue length) to make sure OOB won't + * break existing clients. Note: this test does not control the + * scheduling of QEMU's QMP command processing threads so it may + * not really trigger batching inside QEMU. This is just a + * best-effort test. + */ + for (i =3D 0; i < 16; i++) { + qmp_async("{ 'execute': 'query-version' }"); + } + /* Verify the replies to make sure no command is dropped. */ + for (i =3D 0; i < 16; i++) { + resp =3D qmp_receive(); + /* It should never be dropped. Each of them should be a reply. */ + g_assert(qdict_haskey(resp, "return")); + g_assert(!qdict_haskey(resp, "event")); + QDECREF(resp); + } + qtest_end(); } =20 --=20 2.14.3 From nobody Mon Apr 29 06:38:23 2024 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 1513674535736654.5618527444682; Tue, 19 Dec 2017 01:08:55 -0800 (PST) Received: from localhost ([::1]:60315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDtI-0003IP-Ih for importer@patchew.org; Tue, 19 Dec 2017 04:08:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRDcT-0004TQ-5t for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:51:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRDcP-0003Uj-8s for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:51:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37706) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRDcO-0003U4-Vs for qemu-devel@nongnu.org; Tue, 19 Dec 2017 03:51:21 -0500 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 2A24D7EAA0; Tue, 19 Dec 2017 08:51:19 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C6836EE21; Tue, 19 Dec 2017 08:50:58 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 19 Dec 2017 16:45:57 +0800 Message-Id: <20171219084557.9801-28-peterx@redhat.com> In-Reply-To: <20171219084557.9801-1-peterx@redhat.com> References: <20171219084557.9801-1-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]); Tue, 19 Dec 2017 08:51:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v6 27/27] tests: qmp-test: add oob test 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 , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Markus Armbruster , marcandre.lureau@redhat.com, Stefan Hajnoczi , 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" Test the new OOB capability. Here we used the new "x-oob-test" command. Firstly, we send a lock=3Dtrue and oob=3Dfalse command to hang the main thread. Then send another lock=3Dfalse and oob=3Dtrue command (which will be run inside parser this time) to free that hanged command. Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- tests/qmp-test.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 65 insertions(+) diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 6bc66b0a01..6165911aca 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -160,6 +160,70 @@ static void test_qmp_protocol(void) qtest_end(); } =20 +/* Tests for Out-Of-Band support. */ +static void test_qmp_oob(void) +{ + QDict *resp; + int acks =3D 0; + const char *cmd_id; + + global_qtest =3D qtest_init_without_qmp_handshake(common_args); + + /* Ignore the greeting message. */ + resp =3D qmp_receive(); + g_assert(qdict_get_qdict(resp, "QMP")); + QDECREF(resp); + + /* Try a fake capability, it should fail. */ + resp =3D qmp("{ 'execute': 'qmp_capabilities', " + " 'arguments': { 'enable': [ 'cap-does-not-exist' ] } }"); + g_assert(qdict_haskey(resp, "error")); + QDECREF(resp); + + /* Now, enable OOB in current QMP session, it should success. */ + resp =3D qmp("{ 'execute': 'qmp_capabilities', " + " 'arguments': { 'enable': [ 'oob' ] } }"); + g_assert(qdict_haskey(resp, "return")); + QDECREF(resp); + + /* + * Try any command that does not support OOB but with OOB flag. We + * should get failure. + */ + resp =3D qmp("{ 'execute': 'query-cpus'," + " 'control': { 'run-oob': true } }"); + g_assert(qdict_haskey(resp, "error")); + QDECREF(resp); + + /* + * Firstly send the "x-oob-test" command with lock=3Dtrue and + * oob=3Dfalse, it should hang the dispatcher and main thread; + * later, we send another lock=3Dfalse with oob=3Dtrue to continue + * that thread processing. Finally we should receive replies from + * both commands. + */ + qmp_async("{ 'execute': 'x-oob-test'," + " 'arguments': { 'lock': true }, " + " 'id': 'lock-cmd'}"); + qmp_async("{ 'execute': 'x-oob-test', " + " 'arguments': { 'lock': false }, " + " 'control': { 'run-oob': true }, " + " 'id': 'unlock-cmd' }"); + + /* Ignore all events. Wait for 2 acks */ + while (acks < 2) { + resp =3D qmp_receive(); + cmd_id =3D qdict_get_str(resp, "id"); + if (!g_strcmp0(cmd_id, "lock-cmd") || + !g_strcmp0(cmd_id, "unlock-cmd")) { + acks++; + } + QDECREF(resp); + } + + qtest_end(); +} + static int query_error_class(const char *cmd) { static struct { @@ -338,6 +402,7 @@ int main(int argc, char *argv[]) g_test_init(&argc, &argv, NULL); =20 qtest_add_func("qmp/protocol", test_qmp_protocol); + qtest_add_func("qmp/oob", test_qmp_oob); qmp_schema_init(&schema); add_query_tests(&schema); =20 --=20 2.14.3