From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532025820521332.26331931412017; Thu, 19 Jul 2018 11:43:40 -0700 (PDT) Received: from localhost ([::1]:44672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDtj-0002lc-Gv for importer@patchew.org; Thu, 19 Jul 2018 14:43:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrh-0001YH-Nx for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDre-0007mR-Pi for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54772 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrb-0007lX-9c for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7A1D81A806E for ; Thu, 19 Jul 2018 18:41:18 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D23F3111AF0C; Thu, 19 Jul 2018 18:41:16 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:40:54 +0200 Message-Id: <20180719184111.5129-2-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:18 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 01/18] tests: change /0.15/* tests to /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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Presumably 0.15 was the version it was first introduced, but qmp keeps evolving. There is no point in having that version as test prefix, 'qmp' makes more sense here. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake Message-Id: <20180326150916.9602-12-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- tests/test-qmp-cmds.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index ba41a6161e..ab414fa0c9 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -286,11 +286,11 @@ int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); =20 - g_test_add_func("/0.15/dispatch_cmd", test_dispatch_cmd); - g_test_add_func("/0.15/dispatch_cmd_failure", test_dispatch_cmd_failur= e); - g_test_add_func("/0.15/dispatch_cmd_io", test_dispatch_cmd_io); - g_test_add_func("/0.15/dealloc_types", test_dealloc_types); - g_test_add_func("/0.15/dealloc_partial", test_dealloc_partial); + g_test_add_func("/qmp/dispatch_cmd", test_dispatch_cmd); + g_test_add_func("/qmp/dispatch_cmd_failure", test_dispatch_cmd_failure= ); + g_test_add_func("/qmp/dispatch_cmd_io", test_dispatch_cmd_io); + g_test_add_func("/qmp/dealloc_types", test_dealloc_types); + g_test_add_func("/qmp/dealloc_partial", test_dealloc_partial); =20 test_qmp_init_marshal(&qmp_commands); g_test_run(); --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532025820528166.90461452471595; Thu, 19 Jul 2018 11:43:40 -0700 (PDT) Received: from localhost ([::1]:44673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDtl-0002nV-NQ for importer@patchew.org; Thu, 19 Jul 2018 14:43:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrh-0001YG-F1 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDre-0007me-TR for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34418 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrd-0007lq-2o for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A030C407539D for ; Thu, 19 Jul 2018 18:41:20 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 000C92156897; Thu, 19 Jul 2018 18:41:19 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:40:55 +0200 Message-Id: <20180719184111.5129-3-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 19 Jul 2018 18:41:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 19 Jul 2018 18:41:20 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 02/18] monitor: consitify qmp_send_response() QDict argument 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor.c b/monitor.c index be29634a00..adc04a01d3 100644 --- a/monitor.c +++ b/monitor.c @@ -504,9 +504,9 @@ int monitor_fprintf(FILE *stream, const char *fmt, ...) return 0; } =20 -static void qmp_send_response(Monitor *mon, QDict *rsp) +static void qmp_send_response(Monitor *mon, const QDict *rsp) { - QObject *data =3D QOBJECT(rsp); + const QObject *data =3D QOBJECT(rsp); QString *json; =20 json =3D mon->flags & MONITOR_USE_PRETTY ? qobject_to_json_pretty(data= ) : --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532025820521708.5808804364611; Thu, 19 Jul 2018 11:43:40 -0700 (PDT) Received: from localhost ([::1]:44671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDth-0002jR-QS for importer@patchew.org; Thu, 19 Jul 2018 14:43:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrh-0001YJ-OP for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrf-0007mq-28 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34424 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDre-0007mI-T3 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E27A40753A4 for ; Thu, 19 Jul 2018 18:41:22 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02536111AF0C; Thu, 19 Jul 2018 18:41:21 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:40:56 +0200 Message-Id: <20180719184111.5129-4-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 19 Jul 2018 18:41:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 19 Jul 2018 18:41:22 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 03/18] qmp: constify qmp_is_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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/dispatch.h | 2 +- qapi/qmp-dispatch.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 4e2e749faf..68a528a9aa 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -50,7 +50,7 @@ bool qmp_has_success_response(const QmpCommand *cmd); QDict *qmp_error_response(Error *err); QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, bool allow_oob); -bool qmp_is_oob(QDict *dict); +bool qmp_is_oob(const QDict *dict); =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 6f2d466596..90ba5e3074 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -156,7 +156,7 @@ QDict *qmp_error_response(Error *err) /* * Does @qdict look like a command to be run out-of-band? */ -bool qmp_is_oob(QDict *dict) +bool qmp_is_oob(const QDict *dict) { return qdict_haskey(dict, "exec-oob") && !qdict_haskey(dict, "execute"); --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15320259985641012.6688633028517; Thu, 19 Jul 2018 11:46:38 -0700 (PDT) Received: from localhost ([::1]:44692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDwj-0005eZ-Fk for importer@patchew.org; Thu, 19 Jul 2018 14:46:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDri-0001YK-61 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrg-0007nH-NT for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54306 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrg-0007n5-G0 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F76B40583DB for ; Thu, 19 Jul 2018 18:41:24 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9ECEA2156897; Thu, 19 Jul 2018 18:41:23 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:40:57 +0200 Message-Id: <20180719184111.5129-5-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:24 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 04/18] Revert "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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This reverts commit abe3cd0ff7f774966da6842620806ab7576fe4f3. There is no need to add an additional queue to send the reply to the IOThread, because QMP response is thread safe, and chardev write path is thread safe. It will schedule the watcher in the associated IOThread. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- monitor.c | 120 ++---------------------------------------------------- 1 file changed, 3 insertions(+), 117 deletions(-) diff --git a/monitor.c b/monitor.c index adc04a01d3..46d98010f7 100644 --- a/monitor.c +++ b/monitor.c @@ -183,8 +183,6 @@ 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 /* @@ -248,9 +246,6 @@ IOThread *mon_iothread; /* Bottom half to dispatch the requests received from I/O thread */ QEMUBH *qmp_dispatcher_bh; =20 -/* Bottom half to deliver the responses back to clients */ -QEMUBH *qmp_respond_bh; - struct QMPRequest { /* Owner of the request */ Monitor *mon; @@ -376,19 +371,10 @@ static void monitor_qmp_cleanup_req_queue_locked(Moni= tor *mon) } } =20 -/* Caller must hold the mon->qmp.qmp_queue_lock */ -static void monitor_qmp_cleanup_resp_queue_locked(Monitor *mon) -{ - while (!g_queue_is_empty(mon->qmp.qmp_responses)) { - qobject_unref((QDict *)g_queue_pop_head(mon->qmp.qmp_responses)); - } -} - static void monitor_qmp_cleanup_queues(Monitor *mon) { qemu_mutex_lock(&mon->qmp.qmp_queue_lock); monitor_qmp_cleanup_req_queue_locked(mon); - monitor_qmp_cleanup_resp_queue_locked(mon); qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); } =20 @@ -519,85 +505,6 @@ static void qmp_send_response(Monitor *mon, const QDic= t *rsp) qobject_unref(json); } =20 -static void qmp_queue_response(Monitor *mon, QDict *rsp) -{ - if (mon->use_io_thread) { - /* - * Push a reference to the response queue. The I/O thread - * drains that queue and emits. - */ - qemu_mutex_lock(&mon->qmp.qmp_queue_lock); - g_queue_push_tail(mon->qmp.qmp_responses, qobject_ref(rsp)); - qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); - qemu_bh_schedule(qmp_respond_bh); - } else { - /* - * Not using monitor I/O thread, i.e. we are in the main thread. - * Emit right away. - */ - qmp_send_response(mon, rsp); - } -} - -struct QMPResponse { - Monitor *mon; - QDict *data; -}; -typedef struct QMPResponse QMPResponse; - -static QDict *monitor_qmp_response_pop_one(Monitor *mon) -{ - QDict *data; - - 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); - - return data; -} - -static void monitor_qmp_response_flush(Monitor *mon) -{ - QDict *data; - - while ((data =3D monitor_qmp_response_pop_one(mon))) { - qmp_send_response(mon, data); - qobject_unref(data); - } -} - -/* - * Pop a QMPResponse from any monitor's response queue into @response. - * Return false if all the queues are empty; else true. - */ -static bool monitor_qmp_response_pop_any(QMPResponse *response) -{ - Monitor *mon; - QDict *data =3D NULL; - - qemu_mutex_lock(&monitor_lock); - QTAILQ_FOREACH(mon, &mon_list, entry) { - data =3D monitor_qmp_response_pop_one(mon); - if (data) { - response->mon =3D mon; - response->data =3D data; - break; - } - } - qemu_mutex_unlock(&monitor_lock); - return data !=3D NULL; -} - -static void monitor_qmp_bh_responder(void *opaque) -{ - QMPResponse response; - - while (monitor_qmp_response_pop_any(&response)) { - qmp_send_response(response.mon, response.data); - qobject_unref(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 }, @@ -621,7 +528,7 @@ static void monitor_qapi_event_emit(QAPIEvent event, QD= ict *qdict) QTAILQ_FOREACH(mon, &mon_list, entry) { if (monitor_is_qmp(mon) && mon->qmp.commands !=3D &qmp_cap_negotiation_commands) { - qmp_queue_response(mon, qdict); + qmp_send_response(mon, qdict); } } } @@ -777,7 +684,6 @@ static void monitor_data_init(Monitor *mon, bool skip_f= lush, mon->skip_flush =3D skip_flush; mon->use_io_thread =3D use_io_thread; mon->qmp.qmp_requests =3D g_queue_new(); - mon->qmp.qmp_responses =3D g_queue_new(); } =20 static void monitor_data_destroy(Monitor *mon) @@ -792,9 +698,7 @@ static void monitor_data_destroy(Monitor *mon) qemu_mutex_destroy(&mon->mon_lock); qemu_mutex_destroy(&mon->qmp.qmp_queue_lock); monitor_qmp_cleanup_req_queue_locked(mon); - monitor_qmp_cleanup_resp_queue_locked(mon); 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, @@ -4100,7 +4004,7 @@ static void monitor_qmp_respond(Monitor *mon, QDict *= rsp, QObject *id) qdict_put_obj(rsp, "id", qobject_ref(id)); } =20 - qmp_queue_response(mon, rsp); + qmp_send_response(mon, rsp); } } =20 @@ -4396,7 +4300,7 @@ static void monitor_qmp_event(void *opaque, int event) mon->qmp.commands =3D &qmp_cap_negotiation_commands; monitor_qmp_caps_reset(mon); data =3D qmp_greeting(mon); - qmp_queue_response(mon, data); + qmp_send_response(mon, data); qobject_unref(data); mon_refcount++; break; @@ -4407,7 +4311,6 @@ static void monitor_qmp_event(void *opaque, int event) * stdio, it's possible that stdout is still open when stdin * is closed. */ - monitor_qmp_response_flush(mon); monitor_qmp_cleanup_queues(mon); json_message_parser_destroy(&mon->qmp.parser); json_message_parser_init(&mon->qmp.parser, handle_qmp_command); @@ -4509,15 +4412,6 @@ static void monitor_iothread_init(void) qmp_dispatcher_bh =3D aio_bh_new(iohandler_get_aio_context(), monitor_qmp_bh_dispatcher, NULL); - - /* - * The responder BH must be run in the monitor I/O thread, so that - * monitors that are using the I/O thread have their output - * written by the I/O thread. - */ - qmp_respond_bh =3D aio_bh_new(monitor_get_aio_context(), - monitor_qmp_bh_responder, - NULL); } =20 void monitor_init_globals(void) @@ -4669,12 +4563,6 @@ void monitor_cleanup(void) */ iothread_stop(mon_iothread); =20 - /* - * Flush all response queues. Note that even after this flush, - * data may remain in output buffers. - */ - monitor_qmp_bh_responder(NULL); - /* Flush output buffers and destroy monitors */ qemu_mutex_lock(&monitor_lock); QTAILQ_FOREACH_SAFE(mon, &mon_list, entry, next) { @@ -4688,8 +4576,6 @@ void monitor_cleanup(void) /* QEMUBHs needs to be deleted before destroying the I/O thread */ qemu_bh_delete(qmp_dispatcher_bh); qmp_dispatcher_bh =3D NULL; - qemu_bh_delete(qmp_respond_bh); - qmp_respond_bh =3D NULL; =20 iothread_destroy(mon_iothread); mon_iothread =3D NULL; --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532025992616982.7576747957914; Thu, 19 Jul 2018 11:46:32 -0700 (PDT) Received: from localhost ([::1]:44690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDwd-0005aA-Hp for importer@patchew.org; Thu, 19 Jul 2018 14:46:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrp-0001gM-RI for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDri-0007oN-L4 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55266 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDri-0007ny-FV for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DF0587A84 for ; Thu, 19 Jul 2018 18:41:26 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B4B32026D6B; Thu, 19 Jul 2018 18:41:25 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:40:58 +0200 Message-Id: <20180719184111.5129-6-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 19 Jul 2018 18:41:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 19 Jul 2018 18:41:26 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 05/18] monitor: no need to save need_resume 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There is no need for per-command need_resume granularity, it should resume after running an non-oob command on oob-disabled monitor. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- monitor.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index 46d98010f7..961779032a 100644 --- a/monitor.c +++ b/monitor.c @@ -257,12 +257,6 @@ struct QMPRequest { */ QObject *req; Error *err; - /* - * Whether we need to resume the monitor afterward. This flag is - * used to emulate the old QMP server behavior that the current - * command must be completed before execution of the next one. - */ - bool need_resume; }; typedef struct QMPRequest QMPRequest; =20 @@ -4079,11 +4073,14 @@ static void monitor_qmp_bh_dispatcher(void *data) { QMPRequest *req_obj =3D monitor_qmp_requests_pop_any(); QDict *rsp; + bool need_resume; =20 if (!req_obj) { return; } =20 + /* qmp_oob_enabled() might change after "qmp_capabilities" */ + need_resume =3D !qmp_oob_enabled(req_obj->mon); if (req_obj->req) { trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: = ""); monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); @@ -4095,7 +4092,7 @@ static void monitor_qmp_bh_dispatcher(void *data) qobject_unref(rsp); } =20 - if (req_obj->need_resume) { + if (need_resume) { /* Pairs with the monitor_suspend() in handle_qmp_command() */ monitor_resume(req_obj->mon); } @@ -4147,7 +4144,6 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) req_obj->id =3D id; req_obj->req =3D req; req_obj->err =3D err; - req_obj->need_resume =3D false; =20 /* Protect qmp_requests and fetching its length. */ qemu_mutex_lock(&mon->qmp.qmp_queue_lock); @@ -4160,7 +4156,6 @@ static void handle_qmp_command(JSONMessageParser *par= ser, 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) { --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026442671375.00770941096346; Thu, 19 Jul 2018 11:54:02 -0700 (PDT) Received: from localhost ([::1]:44727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE3t-0003Bz-J7 for importer@patchew.org; Thu, 19 Jul 2018 14:54:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrs-0001ia-IW for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrp-0007rX-Sk for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55270 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrk-0007om-3a for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2C1187A84; Thu, 19 Jul 2018 18:41:27 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 513CC1C640; Thu, 19 Jul 2018 18:41:27 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:40:59 +0200 Message-Id: <20180719184111.5129-7-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 19 Jul 2018 18:41:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 19 Jul 2018 18:41:27 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 06/18] qga: process_event() simplification and leak fix 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" json_parser_parse_err() may return something else than a QDict, in which case we loose the object. Let's keep track of the original object to avoid leaks. When an error occurs, "qdict" contains the response, but we still check the "execute" key there. Untangle a bit this code, by having a clear error path. CC: Michael Roth Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qga/main.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/qga/main.c b/qga/main.c index 537cc0e162..87372d40ef 100644 --- a/qga/main.c +++ b/qga/main.c @@ -600,42 +600,42 @@ static void process_command(GAState *s, QDict *req) static void process_event(JSONMessageParser *parser, GQueue *tokens) { GAState *s =3D container_of(parser, GAState, parser); - QDict *qdict; + QObject *obj; + QDict *req, *rsp; Error *err =3D NULL; int ret; =20 g_assert(s && parser); =20 g_debug("process_event: called"); - qdict =3D qobject_to(QDict, json_parser_parse_err(tokens, NULL, &err)); - if (err || !qdict) { - qobject_unref(qdict); - if (!err) { - g_warning("failed to parse event: unknown error"); - error_setg(&err, QERR_JSON_PARSING); - } else { - g_warning("failed to parse event: %s", error_get_pretty(err)); - } - qdict =3D qmp_error_response(err); + obj =3D json_parser_parse_err(tokens, NULL, &err); + if (err) { + goto err; } - - /* handle host->guest commands */ - if (qdict_haskey(qdict, "execute")) { - process_command(s, qdict); - } else { - if (!qdict_haskey(qdict, "error")) { - qobject_unref(qdict); - g_warning("unrecognized payload format"); - error_setg(&err, QERR_UNSUPPORTED); - qdict =3D qmp_error_response(err); - } - ret =3D send_response(s, qdict); - if (ret < 0) { - g_warning("error sending error response: %s", strerror(-ret)); - } + req =3D qobject_to(QDict, obj); + if (!req) { + error_setg(&err, QERR_JSON_PARSING); + goto err; + } + if (!qdict_haskey(req, "execute")) { + g_warning("unrecognized payload format"); + error_setg(&err, QERR_UNSUPPORTED); + goto err; } =20 - qobject_unref(qdict); + process_command(s, req); + qobject_unref(obj); + return; + +err: + g_warning("failed to parse event: %s", error_get_pretty(err)); + rsp =3D qmp_error_response(err); + ret =3D send_response(s, rsp); + if (ret < 0) { + g_warning("error sending error response: %s", strerror(-ret)); + } + qobject_unref(rsp); + qobject_unref(obj); } =20 /* false return signals GAChannel to close the current client connection */ --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153202601817969.51089881513963; Thu, 19 Jul 2018 11:46:58 -0700 (PDT) Received: from localhost ([::1]:44693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDx2-0005sV-L3 for importer@patchew.org; Thu, 19 Jul 2018 14:46:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrs-0001ib-Il for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrp-0007rR-Tc for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40732 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrl-0007pE-OI for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58F8E7263A for ; Thu, 19 Jul 2018 18:41:29 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id EED31111AF0C; Thu, 19 Jul 2018 18:41:28 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:00 +0200 Message-Id: <20180719184111.5129-8-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 18:41:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 18:41:29 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 07/18] qmp: drop json_parser_parse() wrapper 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Stupid wrapper that's used exactly once, in libqtest.c. Let's use json_parser_parse_err() there, and drop the wrapper. Let's rename json_parser_parse_err() to json_parser_parse() then. Suggested-by: Markus Armbruster Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/json-parser.h | 3 +-- monitor.c | 4 ++-- qga/main.c | 2 +- qobject/json-parser.c | 7 +------ qobject/qjson.c | 2 +- tests/libqtest.c | 2 +- 6 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/qapi/qmp/json-parser.h b/include/qapi/qmp/json-parser.h index 102f5c0068..a34209db7a 100644 --- a/include/qapi/qmp/json-parser.h +++ b/include/qapi/qmp/json-parser.h @@ -16,7 +16,6 @@ =20 #include "qemu-common.h" =20 -QObject *json_parser_parse(GQueue *tokens, va_list *ap); -QObject *json_parser_parse_err(GQueue *tokens, va_list *ap, Error **errp); +QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp); =20 #endif diff --git a/monitor.c b/monitor.c index 961779032a..2abb3c2fc7 100644 --- a/monitor.c +++ b/monitor.c @@ -4113,9 +4113,9 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) Error *err =3D NULL; QMPRequest *req_obj; =20 - req =3D json_parser_parse_err(tokens, NULL, &err); + req =3D json_parser_parse(tokens, NULL, &err); if (!req && !err) { - /* json_parser_parse_err() sucks: can fail without setting @err */ + /* json_parser_parse() sucks: can fail without setting @err */ error_setg(&err, QERR_JSON_PARSING); } =20 diff --git a/qga/main.c b/qga/main.c index 87372d40ef..043f7c3ead 100644 --- a/qga/main.c +++ b/qga/main.c @@ -608,7 +608,7 @@ static void process_event(JSONMessageParser *parser, GQ= ueue *tokens) g_assert(s && parser); =20 g_debug("process_event: called"); - obj =3D json_parser_parse_err(tokens, NULL, &err); + obj =3D json_parser_parse(tokens, NULL, &err); if (err) { goto err; } diff --git a/qobject/json-parser.c b/qobject/json-parser.c index a5aa790d62..9a7004e680 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -575,12 +575,7 @@ static QObject *parse_value(JSONParserContext *ctxt, v= a_list *ap) } } =20 -QObject *json_parser_parse(GQueue *tokens, va_list *ap) -{ - return json_parser_parse_err(tokens, ap, NULL); -} - -QObject *json_parser_parse_err(GQueue *tokens, va_list *ap, Error **errp) +QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp) { JSONParserContext *ctxt =3D parser_context_new(tokens); QObject *result; diff --git a/qobject/qjson.c b/qobject/qjson.c index 2f6a590e44..ee04e61096 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -36,7 +36,7 @@ static void parse_json(JSONMessageParser *parser, GQueue = *tokens) { JSONParsingState *s =3D container_of(parser, JSONParsingState, parser); =20 - s->result =3D json_parser_parse_err(tokens, s->ap, &s->err); + s->result =3D json_parser_parse(tokens, s->ap, &s->err); } =20 QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) diff --git a/tests/libqtest.c b/tests/libqtest.c index 098af6aec4..3826b8baf3 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -432,7 +432,7 @@ static void qmp_response(JSONMessageParser *parser, GQu= eue *tokens) QMPResponseParser *qmp =3D container_of(parser, QMPResponseParser, par= ser); QObject *obj; =20 - obj =3D json_parser_parse(tokens, NULL); + obj =3D json_parser_parse(tokens, NULL, NULL); if (!obj) { fprintf(stderr, "QMP JSON response parsing failed\n"); exit(1); --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026260175792.0481077597091; Thu, 19 Jul 2018 11:51:00 -0700 (PDT) Received: from localhost ([::1]:44715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE0x-0000WS-6C for importer@patchew.org; Thu, 19 Jul 2018 14:50:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrs-0001ie-JM for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrp-0007rF-RH for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54782 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrn-0007ph-MD for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 247B281663E7 for ; Thu, 19 Jul 2018 18:41:31 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C00912156897; Thu, 19 Jul 2018 18:41:30 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:01 +0200 Message-Id: <20180719184111.5129-9-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:31 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 08/18] json-parser: simplify and avoid JSONParserContext allocation 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" parser_context_new/free() are only used from json_parser_parse(). We can fold the code there and avoid an allocation altogether. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qobject/json-parser.c | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 9a7004e680..6baf73b4b9 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -244,33 +244,6 @@ static JSONToken *parser_context_peek_token(JSONParser= Context *ctxt) return g_queue_peek_head(ctxt->buf); } =20 -static JSONParserContext *parser_context_new(GQueue *tokens) -{ - JSONParserContext *ctxt; - - if (!tokens) { - return NULL; - } - - ctxt =3D g_malloc0(sizeof(JSONParserContext)); - ctxt->buf =3D tokens; - - return ctxt; -} - -/* to support error propagation, ctxt->err must be freed separately */ -static void parser_context_free(JSONParserContext *ctxt) -{ - if (ctxt) { - while (!g_queue_is_empty(ctxt->buf)) { - parser_context_pop_token(ctxt); - } - g_free(ctxt->current); - g_queue_free(ctxt->buf); - g_free(ctxt); - } -} - /** * Parsing rules */ @@ -577,18 +550,22 @@ static QObject *parse_value(JSONParserContext *ctxt, = va_list *ap) =20 QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp) { - JSONParserContext *ctxt =3D parser_context_new(tokens); + JSONParserContext ctxt =3D { .buf =3D tokens }; QObject *result; =20 - if (!ctxt) { + if (!tokens) { return NULL; } =20 - result =3D parse_value(ctxt, ap); + result =3D parse_value(&ctxt, ap); =20 - error_propagate(errp, ctxt->err); + error_propagate(errp, ctxt.err); =20 - parser_context_free(ctxt); + while (!g_queue_is_empty(ctxt.buf)) { + parser_context_pop_token(&ctxt); + } + g_free(ctxt.current); + g_queue_free(ctxt.buf); =20 return result; } --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532025833872325.988350257579; Thu, 19 Jul 2018 11:43:53 -0700 (PDT) Received: from localhost ([::1]:44674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDu1-0002yo-5g for importer@patchew.org; Thu, 19 Jul 2018 14:43:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrs-0001iW-I4 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrp-0007rK-SI for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54790 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDro-0007qs-UX for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E6CD8182D0F for ; Thu, 19 Jul 2018 18:41:32 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 329642026D6B; Thu, 19 Jul 2018 18:41:32 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:02 +0200 Message-Id: <20180719184111.5129-10-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 09/18] json-parser: further simplify freeing JSONParserContext 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use g_queue_free_full() directly. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qobject/json-parser.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 6baf73b4b9..0c0b478149 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -561,11 +561,8 @@ QObject *json_parser_parse(GQueue *tokens, va_list *ap= , Error **errp) =20 error_propagate(errp, ctxt.err); =20 - while (!g_queue_is_empty(ctxt.buf)) { - parser_context_pop_token(&ctxt); - } + g_queue_free_full(ctxt.buf, g_free); g_free(ctxt.current); - g_queue_free(ctxt.buf); =20 return result; } --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026236112800.7011493002982; Thu, 19 Jul 2018 11:50:36 -0700 (PDT) Received: from localhost ([::1]:44709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE0V-0008RG-7p for importer@patchew.org; Thu, 19 Jul 2018 14:50:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrs-0001ic-Ig for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrq-0007sW-NV for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40744 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrq-0007rv-FW for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E89507263A for ; Thu, 19 Jul 2018 18:41:33 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 976712156897; Thu, 19 Jul 2018 18:41:33 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:03 +0200 Message-Id: <20180719184111.5129-11-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 18:41:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 18:41:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 10/18] qjson: report an error if there are multiple results 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qobject_from_jsonv() returns a single object. Let's make sure that during parsing we don't leak an intermediary object. Instead of returning the last object, set a parsing error. Also, the lexer/parser keeps consuming all the data. There might be an error set earlier. Let's keep it and not call json_parser_parse() with the remaining data. Eventually, we may teach the message parser to stop consuming the data. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qobject/qjson.c | 16 +++++++++++++++- tests/check-qjson.c | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/qobject/qjson.c b/qobject/qjson.c index ee04e61096..8a9d116150 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -22,6 +22,7 @@ #include "qapi/qmp/qlist.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" +#include "qapi/qmp/qerror.h" #include "qemu/unicode.h" =20 typedef struct JSONParsingState @@ -36,7 +37,20 @@ static void parse_json(JSONMessageParser *parser, GQueue= *tokens) { JSONParsingState *s =3D container_of(parser, JSONParsingState, parser); =20 - s->result =3D json_parser_parse(tokens, s->ap, &s->err); + if (s->result || s->err) { + if (s->result) { + qobject_unref(s->result); + s->result =3D NULL; + if (!s->err) { + error_setg(&s->err, QERR_JSON_PARSING); + } + } + if (tokens) { + g_queue_free_full(tokens, g_free); + } + } else { + s->result =3D json_parser_parse(tokens, s->ap, &s->err); + } } =20 QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index da582df3e9..7d3547e0cc 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1417,6 +1417,16 @@ static void limits_nesting(void) g_assert(obj =3D=3D NULL); } =20 +static void multiple_objects(void) +{ + Error *err =3D NULL; + QObject *obj; + + obj =3D qobject_from_json("{} {}", &err); + g_assert(obj =3D=3D NULL); + error_free_or_abort(&err); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -1454,6 +1464,7 @@ int main(int argc, char **argv) g_test_add_func("/errors/invalid_dict_comma", invalid_dict_comma); g_test_add_func("/errors/unterminated/literal", unterminated_literal); g_test_add_func("/errors/limits/nesting", limits_nesting); + g_test_add_func("/errors/multiple_objects", multiple_objects); =20 return g_test_run(); } --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026199929162.52305675939158; Thu, 19 Jul 2018 11:49:59 -0700 (PDT) Received: from localhost ([::1]:44707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDzo-0007rn-C4 for importer@patchew.org; Thu, 19 Jul 2018 14:49:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDrt-0001jI-In for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDrs-0007tC-52 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54320 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrs-0007t7-0S for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83D2D401C090 for ; Thu, 19 Jul 2018 18:41:35 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35B9C2026D6B; Thu, 19 Jul 2018 18:41:35 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:04 +0200 Message-Id: <20180719184111.5129-12-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:35 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 11/18] qjson: report error on unterminated string 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" An unterminated string will make parser emit an error (tokens =3D=3D NULL). Let's report it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qobject/qjson.c | 3 +++ tests/check-qjson.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/qobject/qjson.c b/qobject/qjson.c index 8a9d116150..01218c9ad6 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -37,6 +37,9 @@ static void parse_json(JSONMessageParser *parser, GQueue = *tokens) { JSONParsingState *s =3D container_of(parser, JSONParsingState, parser); =20 + if (!tokens && !s->err) { + error_setg(&s->err, QERR_JSON_PARSING); + } if (s->result || s->err) { if (s->result) { qobject_unref(s->result); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 7d3547e0cc..e602abda11 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1315,7 +1315,7 @@ static void unterminated_string(void) { Error *err =3D NULL; QObject *obj =3D qobject_from_json("\"abc", &err); - g_assert(!err); /* BUG */ + error_free_or_abort(&err); g_assert(obj =3D=3D NULL); } =20 @@ -1323,7 +1323,7 @@ static void unterminated_sq_string(void) { Error *err =3D NULL; QObject *obj =3D qobject_from_json("'abc", &err); - g_assert(!err); /* BUG */ + error_free_or_abort(&err); g_assert(obj =3D=3D NULL); } =20 @@ -1331,7 +1331,7 @@ static void unterminated_escape(void) { Error *err =3D NULL; QObject *obj =3D qobject_from_json("\"abc\\\"", &err); - g_assert(!err); /* BUG */ + error_free_or_abort(&err); g_assert(obj =3D=3D NULL); } =20 --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026211329552.4322490925268; Thu, 19 Jul 2018 11:50:11 -0700 (PDT) Received: from localhost ([::1]:44708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE0A-0008Dx-8u for importer@patchew.org; Thu, 19 Jul 2018 14:50:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDs0-0001of-Ms for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDry-0007vD-26 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40750 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrv-0007ud-7b for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C81887263A for ; Thu, 19 Jul 2018 18:41:38 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D13701C640; Thu, 19 Jul 2018 18:41:36 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:05 +0200 Message-Id: <20180719184111.5129-13-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 18:41:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 18:41:38 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 12/18] qjson: return parsing error if unterminated input 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- qobject/json-streamer.c | 4 +++- qobject/qjson.c | 5 ++++- tests/check-qjson.c | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index c51c2021f9..065c551332 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -126,7 +126,9 @@ int json_message_parser_feed(JSONMessageParser *parser, =20 int json_message_parser_flush(JSONMessageParser *parser) { - return json_lexer_flush(&parser->lexer); + int ret =3D json_lexer_flush(&parser->lexer); + + return ret ?: g_queue_get_length(parser->tokens); } =20 void json_message_parser_destroy(JSONMessageParser *parser) diff --git a/qobject/qjson.c b/qobject/qjson.c index 01218c9ad6..8afdc1e06a 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -64,7 +64,10 @@ QObject *qobject_from_jsonv(const char *string, va_list = *ap, Error **errp) =20 json_message_parser_init(&state.parser, parse_json); json_message_parser_feed(&state.parser, string, strlen(string)); - json_message_parser_flush(&state.parser); + if (json_message_parser_flush(&state.parser) !=3D 0 && + !state.err) { + error_setg(&state.err, QERR_JSON_PARSING); + } json_message_parser_destroy(&state.parser); =20 error_propagate(errp, state.err); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index e602abda11..d0144ba93c 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1339,7 +1339,7 @@ static void unterminated_array(void) { Error *err =3D NULL; QObject *obj =3D qobject_from_json("[32", &err); - g_assert(!err); /* BUG */ + error_free_or_abort(&err); g_assert(obj =3D=3D NULL); } =20 @@ -1347,7 +1347,7 @@ static void unterminated_array_comma(void) { Error *err =3D NULL; QObject *obj =3D qobject_from_json("[32,", &err); - g_assert(!err); /* BUG */ + error_free_or_abort(&err); g_assert(obj =3D=3D NULL); } =20 @@ -1363,7 +1363,7 @@ static void unterminated_dict(void) { Error *err =3D NULL; QObject *obj =3D qobject_from_json("{'abc':32", &err); - g_assert(!err); /* BUG */ + error_free_or_abort(&err); g_assert(obj =3D=3D NULL); } =20 @@ -1371,7 +1371,7 @@ static void unterminated_dict_comma(void) { Error *err =3D NULL; QObject *obj =3D qobject_from_json("{'abc':32,", &err); - g_assert(!err); /* BUG */ + error_free_or_abort(&err); g_assert(obj =3D=3D NULL); } =20 --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026393711858.6023328555546; Thu, 19 Jul 2018 11:53:13 -0700 (PDT) Received: from localhost ([::1]:44725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE36-0002bl-Lb for importer@patchew.org; Thu, 19 Jul 2018 14:53:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDs0-0001oc-MX for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDry-0007vd-LT for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54796 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDry-0007vH-GF for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DB8281663E7 for ; Thu, 19 Jul 2018 18:41:42 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD882111AF0C; Thu, 19 Jul 2018 18:41:39 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:06 +0200 Message-Id: <20180719184111.5129-14-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:42 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 13/18] json-parser: set an error if parsing returned NULL 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let's make json_parser_parse_err() suck less, and simplify caller error handling. * monitor.c handle_qmp_command(): drop workaround * qga/main.c process_event(): improve error report, QERR_JSON_PARSING case is handled by json_parser_parse_err() now. * qobject/json-parser.c json_parser_parse(): Ignores the error. * qobject/qjson.c qobject_from_jsonv() via parse_json() - qobject_from_json() ~ block.c parse_json_filename() - removed workaround ~ block/rbd.c - abort (generated json - should never fail) ~ qapi/qobject-input-visitor.c - removed workaround ~ tests/check-qjson.c - assert or crash ~ tests/test-visitor-serialization.c - assert or crash - qobject_from_jsonf() Now dies in error_handle_fatal() instead of the assertion. Only used in tests, ok. - tests/test-qobject-input-visitor.c - tests/libqtest.c qmp_fd_sendv() Passes &error_abort, does nothing when qobject_from_jsonv() returns null. The fix makes this catch invalid JSON instead of silently ignoring it. Update the function documentation for possible return values. Signed-off-by: Marc-Andr=C3=A9 Lureau --- block.c | 5 ----- monitor.c | 4 ---- qapi/qobject-input-visitor.c | 5 ----- qga/main.c | 2 +- qobject/json-parser.c | 16 +++++++++++++++- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index a2fe05ea96..42eaa8b7dc 100644 --- a/block.c +++ b/block.c @@ -1478,11 +1478,6 @@ static QDict *parse_json_filename(const char *filena= me, Error **errp) =20 options_obj =3D qobject_from_json(filename, errp); if (!options_obj) { - /* Work around qobject_from_json() lossage TODO fix that */ - if (errp && !*errp) { - error_setg(errp, "Could not parse the JSON options"); - return NULL; - } error_prepend(errp, "Could not parse the JSON options: "); return NULL; } diff --git a/monitor.c b/monitor.c index 2abb3c2fc7..5a41a230b9 100644 --- a/monitor.c +++ b/monitor.c @@ -4114,10 +4114,6 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) QMPRequest *req_obj; =20 req =3D json_parser_parse(tokens, NULL, &err); - if (!req && !err) { - /* json_parser_parse() sucks: can fail without setting @err */ - error_setg(&err, QERR_JSON_PARSING); - } =20 qdict =3D qobject_to(QDict, req); if (qdict) { diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index da57f4cc24..3e88b27f9e 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -725,11 +725,6 @@ Visitor *qobject_input_visitor_new_str(const char *str, if (is_json) { obj =3D qobject_from_json(str, errp); if (!obj) { - /* Work around qobject_from_json() lossage TODO fix that */ - if (errp && !*errp) { - error_setg(errp, "JSON parse error"); - return NULL; - } return NULL; } args =3D qobject_to(QDict, obj); diff --git a/qga/main.c b/qga/main.c index 043f7c3ead..9032bb0c7a 100644 --- a/qga/main.c +++ b/qga/main.c @@ -614,7 +614,7 @@ static void process_event(JSONMessageParser *parser, GQ= ueue *tokens) } req =3D qobject_to(QDict, obj); if (!req) { - error_setg(&err, QERR_JSON_PARSING); + error_setg(&err, "Input must be a JSON object"); goto err; } if (!qdict_haskey(req, "execute")) { diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 0c0b478149..c3b0c216cf 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -24,6 +24,7 @@ #include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-lexer.h" #include "qapi/qmp/json-streamer.h" +#include "qapi/qmp/qerror.h" =20 typedef struct JSONParserContext { @@ -548,6 +549,14 @@ static QObject *parse_value(JSONParserContext *ctxt, v= a_list *ap) } } =20 +/** + * json_parser_parse: + * + * If @tokens is null, return null. + * Else if @tokens parse okay, return the parse tree. + * Else set an error and return null. + * + **/ QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp) { JSONParserContext ctxt =3D { .buf =3D tokens }; @@ -559,7 +568,12 @@ QObject *json_parser_parse(GQueue *tokens, va_list *ap= , Error **errp) =20 result =3D parse_value(&ctxt, ap); =20 - error_propagate(errp, ctxt.err); + if (!result && !ctxt.err) { + /* TODO: improve error reporting */ + error_setg(errp, QERR_JSON_PARSING); + } else { + error_propagate(errp, ctxt.err); + } =20 g_queue_free_full(ctxt.buf, g_free); g_free(ctxt.current); --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15320264128931020.4787579689888; Thu, 19 Jul 2018 11:53:32 -0700 (PDT) Received: from localhost ([::1]:44726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE3P-0002qc-Qb for importer@patchew.org; Thu, 19 Jul 2018 14:53:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDs0-0001ob-M7 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDs0-0007wC-2N for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54798 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDrz-0007vy-Tb for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:43 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F60481663E7 for ; Thu, 19 Jul 2018 18:41:43 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31FF12026D6B; Thu, 19 Jul 2018 18:41:43 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:07 +0200 Message-Id: <20180719184111.5129-15-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:43 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 14/18] json-lexer: make it safe to call multiple times 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We can easily avoid the burden of checking if the lexer was initialized prior to calling destroy by the caller, let's do it. This allows simplification in state tracking in later patches of the qmp-async RFC series. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qobject/json-lexer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index 980ba159d6..0eaba43a2c 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -386,5 +386,8 @@ int json_lexer_flush(JSONLexer *lexer) =20 void json_lexer_destroy(JSONLexer *lexer) { - g_string_free(lexer->token, true); + if (lexer->token) { + g_string_free(lexer->token, true); + lexer->token =3D NULL; + } } --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026589753800.2324249008175; Thu, 19 Jul 2018 11:56:29 -0700 (PDT) Received: from localhost ([::1]:44752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE6G-0005nU-Hc for importer@patchew.org; Thu, 19 Jul 2018 14:56:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDs2-0001qe-Mg for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDs1-0007xt-NB for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55282 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDs1-0007xO-HX for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:45 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18FC687A76 for ; Thu, 19 Jul 2018 18:41:45 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A05942156897; Thu, 19 Jul 2018 18:41:44 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:08 +0200 Message-Id: <20180719184111.5129-16-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 19 Jul 2018 18:41:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 19 Jul 2018 18:41:45 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 15/18] tests: add a few qemu-qmp tests 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" These 2 tests exhibited two qmp bugs that were fixed in 2.7 (series from commit e64c75a9752c5d0fd64eb2e684c656a5ea7d03c6 to commit 1382d4abdf9619985e4078e37e49e487cea9935e) Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/qmp-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qmp-test.c b/tests/qmp-test.c index b9774084f8..54611e587f 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -249,7 +249,40 @@ static void test_qmp_oob(void) recv_cmd_id(qts, "blocks-2"); recv_cmd_id(qts, "err-2"); cleanup_blocking_cmd(); +} + +static void test_object_add_without_props(void) +{ + QTestState *qts; + QDict *ret; + + qts =3D qtest_init(common_args); =20 + ret =3D qtest_qmp(qts, + "{'execute': 'object-add', 'arguments':" + " {'qom-type': 'memory-backend-ram', 'id': 'ram1' } }"= ); + g_assert_nonnull(ret); + + g_assert_cmpstr(get_error_class(ret), =3D=3D, "GenericError"); + + qobject_unref(ret); + qtest_quit(qts); +} + +static void test_qom_set_without_value(void) +{ + QTestState *qts; + QDict *ret; + + qts =3D qtest_init(common_args); + + ret =3D qtest_qmp(qts, "{'execute': 'qom-set', 'arguments':" + " { 'path': '/machine', 'property': 'rtc-time' } }"); + g_assert_nonnull(ret); + + g_assert_cmpstr(get_error_class(ret), =3D=3D, "GenericError"); + + qobject_unref(ret); qtest_quit(qts); } =20 @@ -479,8 +512,13 @@ int main(int argc, char *argv[]) =20 g_test_init(&argc, &argv, NULL); =20 + qtest_add_func("qmp/object-add-without-props", + test_object_add_without_props); + qtest_add_func("qmp/qom-set-without-value", + test_qom_set_without_value); qtest_add_func("qmp/protocol", test_qmp_protocol); qtest_add_func("qmp/oob", test_qmp_oob); + qmp_schema_init(&schema); add_query_tests(&schema); qtest_add_func("qmp/preconfig", test_qmp_preconfig); --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026743280915.4475084767605; Thu, 19 Jul 2018 11:59:03 -0700 (PDT) Received: from localhost ([::1]:44762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE8k-0007GN-Df for importer@patchew.org; Thu, 19 Jul 2018 14:59:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDs5-0001sB-V1 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDs3-0007zw-EB for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54812 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDs3-0007zX-7K for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB41981663E7 for ; Thu, 19 Jul 2018 18:41:46 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75DC21C640; Thu, 19 Jul 2018 18:41:46 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:09 +0200 Message-Id: <20180719184111.5129-17-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Jul 2018 18:41:46 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 16/18] tests: add a qmp success-response 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Verify the usage of this schema feature and the API behaviour. This should be the only case where qmp_dispatch() returns NULL without error. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- tests/test-qmp-cmds.c | 17 +++++++++++++++++ tests/qapi-schema/qapi-schema-test.json | 2 ++ tests/qapi-schema/qapi-schema-test.out | 2 ++ 3 files changed, 21 insertions(+) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index ab414fa0c9..8d5100a324 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -32,6 +32,10 @@ void qmp_test_flags_command(Error **errp) { } =20 +void qmp_cmd_success_response(Error **errp) +{ +} + Empty2 *qmp_user_def_cmd0(Error **errp) { return g_new0(Empty2, 1); @@ -153,6 +157,17 @@ static void test_dispatch_cmd_failure(void) qobject_unref(req); } =20 +static void test_dispatch_cmd_success_response(void) +{ + QDict *req =3D qdict_new(); + QDict *resp; + + qdict_put_str(req, "execute", "cmd-success-response"); + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), false); + assert(resp =3D=3D NULL); + qobject_unref(req); +} + static QObject *test_qmp_dispatch(QDict *req) { QDict *resp; @@ -289,6 +304,8 @@ int main(int argc, char **argv) g_test_add_func("/qmp/dispatch_cmd", test_dispatch_cmd); g_test_add_func("/qmp/dispatch_cmd_failure", test_dispatch_cmd_failure= ); g_test_add_func("/qmp/dispatch_cmd_io", test_dispatch_cmd_io); + g_test_add_func("/qmp/dispatch_cmd_success_response", + test_dispatch_cmd_success_response); g_test_add_func("/qmp/dealloc_types", test_dealloc_types); g_test_add_func("/qmp/dealloc_partial", test_dealloc_partial); =20 diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 11aa4c8f8d..fb03163430 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -137,6 +137,8 @@ 'data': {'ud1a': 'UserDefOne', '*ud1b': 'UserDefOne'}, 'returns': 'UserDefTwo' } =20 +{ 'command': 'cmd-success-response', 'data': {}, 'success-response': false= } + # Returning a non-dictionary requires a name from the whitelist { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' }, 'returns': 'int' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 0da92455da..218ac7d556 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -156,6 +156,8 @@ object q_obj_user_def_cmd2-arg member ud1b: UserDefOne optional=3DTrue command user_def_cmd2 q_obj_user_def_cmd2-arg -> UserDefTwo gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse +command cmd-success-response None -> None + gen=3DTrue success_response=3DFalse boxed=3DFalse oob=3DFalse preconfig= =3DFalse object q_obj_guest-get-time-arg member a: int optional=3DFalse member b: int optional=3DTrue --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532026674128342.9996476365252; Thu, 19 Jul 2018 11:57:54 -0700 (PDT) Received: from localhost ([::1]:44758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE7d-0006gm-8y for importer@patchew.org; Thu, 19 Jul 2018 14:57:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDs5-0001sD-VI for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDs4-00080V-S1 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54334 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDs4-00080L-M3 for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 416EB401C090 for ; Thu, 19 Jul 2018 18:41:48 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFEB12156897; Thu, 19 Jul 2018 18:41:47 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:10 +0200 Message-Id: <20180719184111.5129-18-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:48 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 17/18] qga: process_event() simplification 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Simplify the code around qmp_dispatch(): - rely on qmp_dispatch/check_obj() for message checking - have a single send_response() point - constify send_response() argument It changes a couple of error messages: * When @req isn't a dictionary, from Invalid JSON syntax to QMP input must be a JSON object * When @req lacks member "execute", from this feature or command is not currently supported to QMP input lacks member 'execute' Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/main.c | 54 +++++++++++++----------------------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/qga/main.c b/qga/main.c index 9032bb0c7a..f5c772314f 100644 --- a/qga/main.c +++ b/qga/main.c @@ -545,15 +545,15 @@ fail: #endif } =20 -static int send_response(GAState *s, QDict *payload) +static int send_response(GAState *s, const QDict *rsp) { const char *buf; QString *payload_qstr, *response_qstr; GIOStatus status; =20 - g_assert(payload && s->channel); + g_assert(rsp && s->channel); =20 - payload_qstr =3D qobject_to_json(QOBJECT(payload)); + payload_qstr =3D qobject_to_json(QOBJECT(rsp)); if (!payload_qstr) { return -EINVAL; } @@ -579,63 +579,35 @@ static int send_response(GAState *s, QDict *payload) return 0; } =20 -static void process_command(GAState *s, QDict *req) -{ - QDict *rsp; - int ret; - - g_assert(req); - g_debug("processing command"); - rsp =3D qmp_dispatch(&ga_commands, QOBJECT(req), false); - if (rsp) { - ret =3D send_response(s, rsp); - if (ret < 0) { - g_warning("error sending response: %s", strerror(-ret)); - } - qobject_unref(rsp); - } -} - /* handle requests/control events coming in over the channel */ static void process_event(JSONMessageParser *parser, GQueue *tokens) { GAState *s =3D container_of(parser, GAState, parser); - QObject *obj; - QDict *req, *rsp; + QObject *req; + QDict *rsp =3D NULL; Error *err =3D NULL; int ret; =20 g_assert(s && parser); =20 g_debug("process_event: called"); - obj =3D json_parser_parse(tokens, NULL, &err); + + req =3D json_parser_parse(tokens, NULL, &err); if (err) { - goto err; - } - req =3D qobject_to(QDict, obj); - if (!req) { - error_setg(&err, "Input must be a JSON object"); - goto err; - } - if (!qdict_haskey(req, "execute")) { - g_warning("unrecognized payload format"); - error_setg(&err, QERR_UNSUPPORTED); - goto err; + rsp =3D qmp_error_response(err); + goto end; } =20 - process_command(s, req); - qobject_unref(obj); - return; + g_debug("processing command"); + rsp =3D qmp_dispatch(&ga_commands, req, false); =20 -err: - g_warning("failed to parse event: %s", error_get_pretty(err)); - rsp =3D qmp_error_response(err); +end: ret =3D send_response(s, rsp); if (ret < 0) { g_warning("error sending error response: %s", strerror(-ret)); } qobject_unref(rsp); - qobject_unref(obj); + qobject_unref(req); } =20 /* false return signals GAChannel to close the current client connection */ --=20 2.18.0.129.ge3331758f1 From nobody Sun May 5 09:30:34 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153202637215395.13628845412813; Thu, 19 Jul 2018 11:52:52 -0700 (PDT) Received: from localhost ([::1]:44724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgE2l-0002Jt-0k for importer@patchew.org; Thu, 19 Jul 2018 14:52:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgDs8-0001vV-Nd for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgDs6-00081N-BL for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54336 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fgDs6-00080z-6G for qemu-devel@nongnu.org; Thu, 19 Jul 2018 14:41:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD518401C090; Thu, 19 Jul 2018 18:41:49 +0000 (UTC) Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56BE72026D6B; Thu, 19 Jul 2018 18:41:49 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 19 Jul 2018 20:41:11 +0200 Message-Id: <20180719184111.5129-19-marcandre.lureau@redhat.com> In-Reply-To: <20180719184111.5129-1-marcandre.lureau@redhat.com> References: <20180719184111.5129-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Jul 2018 18:41:49 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 18/18] RFC: qmp: common 'id' handling & make QGA conform to QMP spec 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let qmp_dispatch() copy the 'id' field. That way any qmp client will conform to the specification, including QGA. Furthermore, it simplifies the work for qemu monitor. CC: Michael Roth Signed-off-by: Marc-Andr=C3=A9 Lureau --- monitor.c | 30 +++++++++++------------------- qapi/qmp-dispatch.c | 12 +++++++++--- tests/test-qga.c | 13 +++++-------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/monitor.c b/monitor.c index 5a41a230b9..11249e7018 100644 --- a/monitor.c +++ b/monitor.c @@ -249,8 +249,6 @@ QEMUBH *qmp_dispatcher_bh; struct QMPRequest { /* Owner of the request */ Monitor *mon; - /* "id" field of the request */ - QObject *id; /* * Request object to be handled or Error to be reported * (exactly one of them is non-null) @@ -351,7 +349,6 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *r= eadline_func, =20 static void qmp_request_free(QMPRequest *req) { - qobject_unref(req->id); qobject_unref(req->req); error_free(req->err); g_free(req); @@ -3991,18 +3988,14 @@ static int monitor_can_read(void *opaque) * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP. * Nothing is emitted then. */ -static void monitor_qmp_respond(Monitor *mon, QDict *rsp, QObject *id) +static void monitor_qmp_respond(Monitor *mon, QDict *rsp) { if (rsp) { - if (id) { - qdict_put_obj(rsp, "id", qobject_ref(id)); - } - qmp_send_response(mon, rsp); } } =20 -static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id) +static void monitor_qmp_dispatch(Monitor *mon, QObject *req) { Monitor *old_mon; QDict *rsp; @@ -4027,7 +4020,7 @@ static void monitor_qmp_dispatch(Monitor *mon, QObjec= t *req, QObject *id) } } =20 - monitor_qmp_respond(mon, rsp, id); + monitor_qmp_respond(mon, rsp); qobject_unref(rsp); } =20 @@ -4082,13 +4075,15 @@ static void monitor_qmp_bh_dispatcher(void *data) /* qmp_oob_enabled() might change after "qmp_capabilities" */ need_resume =3D !qmp_oob_enabled(req_obj->mon); if (req_obj->req) { - trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: = ""); - monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); + QDict *qdict =3D qobject_to(QDict, req_obj->req); + QObject *id =3D qdict ? qdict_get(qdict, "id") : NULL; + trace_monitor_qmp_cmd_in_band(qobject_get_try_str(id) ?: ""); + monitor_qmp_dispatch(req_obj->mon, req_obj->req); } else { assert(req_obj->err); rsp =3D qmp_error_response(req_obj->err); req_obj->err =3D NULL; - monitor_qmp_respond(req_obj->mon, rsp, NULL); + monitor_qmp_respond(req_obj->mon, rsp); qobject_unref(rsp); } =20 @@ -4117,8 +4112,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) =20 qdict =3D qobject_to(QDict, req); if (qdict) { - id =3D qobject_ref(qdict_get(qdict, "id")); - qdict_del(qdict, "id"); + id =3D qdict_get(qdict, "id"); } /* else will fail qmp_dispatch() */ =20 if (req && trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { @@ -4129,15 +4123,13 @@ static void handle_qmp_command(JSONMessageParser *p= arser, GQueue *tokens) =20 if (qdict && qmp_is_oob(qdict)) { /* OOB commands are executed immediately */ - trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) - ?: ""); - monitor_qmp_dispatch(mon, req, id); + trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) ?: ""); + monitor_qmp_dispatch(mon, req); return; } =20 req_obj =3D g_new0(QMPRequest, 1); req_obj->mon =3D mon; - req_obj->id =3D id; req_obj->req =3D req; req_obj->err =3D err; =20 diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 90ba5e3074..e714cfb8ff 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -59,6 +59,8 @@ static QDict *qmp_dispatch_check_obj(const QObject *reque= st, bool allow_oob, "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); @@ -166,11 +168,11 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *re= quest, bool allow_oob) { Error *err =3D NULL; - QObject *ret; + QDict *dict =3D qobject_to(QDict, request); + QObject *id =3D dict ? qdict_get(dict, "id") : NULL; + QObject *ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); QDict *rsp; =20 - ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); - if (err) { rsp =3D qmp_error_response(err); } else if (ret) { @@ -181,5 +183,9 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *requ= est, rsp =3D NULL; } =20 + if (rsp && id) { + qdict_put_obj(rsp, "id", qobject_ref(id)); + } + return rsp; } diff --git a/tests/test-qga.c b/tests/test-qga.c index d638b1571a..4ee8b405f4 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -227,18 +227,15 @@ static void test_qga_ping(gconstpointer fix) qobject_unref(ret); } =20 -static void test_qga_invalid_id(gconstpointer fix) +static void test_qga_id(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *error; - const char *class; + QDict *ret; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); g_assert_nonnull(ret); - - error =3D qdict_get_qdict(ret, "error"); - class =3D qdict_get_try_str(error, "class"); - g_assert_cmpstr(class, =3D=3D, "GenericError"); + qmp_assert_no_error(ret); + g_assert_cmpint(qdict_get_int(ret, "id"), =3D=3D, 1); =20 qobject_unref(ret); } @@ -1014,7 +1011,7 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops); g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write= _read); g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time); - g_test_add_data_func("/qga/invalid-id", &fix, test_qga_invalid_id); + g_test_add_data_func("/qga/id", &fix, test_qga_id); g_test_add_data_func("/qga/invalid-oob", &fix, test_qga_invalid_oob); g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd); g_test_add_data_func("/qga/invalid-args", &fix, test_qga_invalid_args); --=20 2.18.0.129.ge3331758f1