From nobody Tue Nov 4 18:52:27 2025 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 153088025918290.5406220425599; Fri, 6 Jul 2018 05:30:59 -0700 (PDT) Received: from localhost ([::1]:57557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPt1-0003I5-BN for importer@patchew.org; Fri, 06 Jul 2018 08:30:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPil-00033K-6q for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPih-00083u-Vu for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41306 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 1fbPih-00082t-JM for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:15 -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 3B63881A4EA8 for ; Fri, 6 Jul 2018 12:13:57 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCBCD2142F20; Fri, 6 Jul 2018 12:13:56 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:43 +0200 Message-Id: <20180706121354.2021-2-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:13:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 06 Jul 2018 12:13:57 +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 01/12] 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, peterx@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.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530880412183557.8466807648938; Fri, 6 Jul 2018 05:33:32 -0700 (PDT) Received: from localhost ([::1]:57580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPvV-000506-By for importer@patchew.org; Fri, 06 Jul 2018 08:33:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPjG-0003TU-BB for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPjD-0008Vw-7A for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39268 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 1fbPjC-0008Uw-Q9 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:46 -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 A9A50E9007 for ; Fri, 6 Jul 2018 12:13:58 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A25C2166BA9; Fri, 6 Jul 2018 12:13:58 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:44 +0200 Message-Id: <20180706121354.2021-3-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:13:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 06 Jul 2018 12:13:58 +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 02/12] 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, peterx@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 3c9c97b73f..fc481d902d 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.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879905672666.8706187818419; Fri, 6 Jul 2018 05:25:05 -0700 (PDT) Received: from localhost ([::1]:57491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPnM-0006OW-Tw for importer@patchew.org; Fri, 06 Jul 2018 08:25:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPjG-0003TR-8v for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPjD-0008Vq-8B for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39270 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 1fbPjC-0008Ux-RS for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:20:46 -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 C1058E9009 for ; Fri, 6 Jul 2018 12:14:04 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6344111DCF3; Fri, 6 Jul 2018 12:13:59 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:45 +0200 Message-Id: <20180706121354.2021-4-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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.1]); Fri, 06 Jul 2018 12:14:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 06 Jul 2018 12:14:04 +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 03/12] 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, peterx@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.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879601025819.0703998294196; Fri, 6 Jul 2018 05:20:01 -0700 (PDT) Received: from localhost ([::1]:57453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPiS-0002AY-5O for importer@patchew.org; Fri, 06 Jul 2018 08:20:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59496) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPcr-0006kM-Md for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPco-0005pI-Cb for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39006 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 1fbPco-0005oz-6z for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:10 -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 AF251E900C for ; Fri, 6 Jul 2018 12:14:09 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4AF579A9; Fri, 6 Jul 2018 12:14:05 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:46 +0200 Message-Id: <20180706121354.2021-5-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:14:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 06 Jul 2018 12:14:09 +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 04/12] 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, peterx@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 fc481d902d..462cf96f7b 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 @@ -4395,7 +4299,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; @@ -4406,7 +4310,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); @@ -4508,15 +4411,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) @@ -4668,12 +4562,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) { @@ -4687,8 +4575,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.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879406704206.31709926745987; Fri, 6 Jul 2018 05:16:46 -0700 (PDT) Received: from localhost ([::1]:57439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPfB-0008CN-PM for importer@patchew.org; Fri, 06 Jul 2018 08:16:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPcr-0006kL-Mb for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPcp-0005pm-RQ for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55844 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 1fbPcp-0005ph-ML for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:11 -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 50C854022414 for ; Fri, 6 Jul 2018 12:14:11 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 016882026D68; Fri, 6 Jul 2018 12:14:10 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:47 +0200 Message-Id: <20180706121354.2021-6-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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.6]); Fri, 06 Jul 2018 12:14:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 06 Jul 2018 12:14:11 +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 05/12] 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, peterx@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 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index 462cf96f7b..ec40a80d81 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,13 @@ 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 + 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); @@ -4094,7 +4090,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); } @@ -4146,7 +4142,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); @@ -4159,7 +4154,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.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879405969326.8321295437479; Fri, 6 Jul 2018 05:16:45 -0700 (PDT) Received: from localhost ([::1]:57440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPfC-0008Cz-UM for importer@patchew.org; Fri, 06 Jul 2018 08:16:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPcs-0006kN-8C for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPcr-0005px-6m for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39010 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 1fbPcr-0005pq-1G for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:13 -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 B0588E900C for ; Fri, 6 Jul 2018 12:14:12 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62A312026D68; Fri, 6 Jul 2018 12:14:12 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:48 +0200 Message-Id: <20180706121354.2021-7-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:14:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 06 Jul 2018 12:14:12 +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 06/12] 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, peterx@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" 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. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qga/main.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/qga/main.c b/qga/main.c index 537cc0e162..0784761605 100644 --- a/qga/main.c +++ b/qga/main.c @@ -600,6 +600,7 @@ static void process_command(GAState *s, QDict *req) static void process_event(JSONMessageParser *parser, GQueue *tokens) { GAState *s =3D container_of(parser, GAState, parser); + QObject *obj; QDict *qdict; Error *err =3D NULL; int ret; @@ -607,35 +608,34 @@ static void process_event(JSONMessageParser *parser, = GQueue *tokens) 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)); - } + qdict =3D qobject_to(QDict, obj); + if (!qdict) { + error_setg(&err, QERR_JSON_PARSING); + goto err; + } + if (!qdict_haskey(qdict, "execute")) { + g_warning("unrecognized payload format"); + error_setg(&err, QERR_UNSUPPORTED); + goto err; } =20 + process_command(s, qdict); + qobject_unref(obj); + return; + +err: + g_warning("failed to parse event: %s", error_get_pretty(err)); + qdict =3D qmp_error_response(err); + ret =3D send_response(s, qdict); + if (ret < 0) { + g_warning("error sending error response: %s", strerror(-ret)); + } qobject_unref(qdict); + qobject_unref(obj); } =20 /* false return signals GAChannel to close the current client connection */ --=20 2.18.0.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879406705992.3293661599948; Fri, 6 Jul 2018 05:16:46 -0700 (PDT) Received: from localhost ([::1]:57441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPfC-0008Dx-44 for importer@patchew.org; Fri, 06 Jul 2018 08:16:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPct-0006kP-Tf for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPcs-0005qQ-Pj for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55100 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 1fbPcs-0005qK-JK for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:14 -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 3CAFE407447D for ; Fri, 6 Jul 2018 12:14:14 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1AB87C26; Fri, 6 Jul 2018 12:14:13 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:49 +0200 Message-Id: <20180706121354.2021-8-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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.7]); Fri, 06 Jul 2018 12:14:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 06 Jul 2018 12:14:14 +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 07/12] json-parser: always set an error if return 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, peterx@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. * qga/main.c process_event() doesn't need further changes after previous cleanup. * 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 - abort, ok ~ tests/test-visitor-serialization.c - abort, ok - 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. Signed-off-by: Marc-Andr=C3=A9 Lureau --- block.c | 5 ----- monitor.c | 4 ---- qapi/qobject-input-visitor.c | 5 ----- qobject/json-parser.c | 8 +++++++- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index ac8b3a3511..9046d66465 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 ec40a80d81..a3efe96d1d 100644 --- a/monitor.c +++ b/monitor.c @@ -4112,10 +4112,6 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) QMPRequest *req_obj; =20 req =3D json_parser_parse_err(tokens, NULL, &err); - if (!req && !err) { - /* json_parser_parse_err() sucks: can fail without setting @err */ - error_setg(&err, QERR_JSON_PARSING); - } =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/qobject/json-parser.c b/qobject/json-parser.c index a5aa790d62..82c3167629 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 { @@ -591,7 +592,12 @@ QObject *json_parser_parse_err(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 parser_context_free(ctxt); =20 --=20 2.18.0.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879405862868.5689592209214; Fri, 6 Jul 2018 05:16:45 -0700 (PDT) Received: from localhost ([::1]:57438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPfC-0008CH-KW for importer@patchew.org; Fri, 06 Jul 2018 08:16:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPcu-0006kQ-TE for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPcu-0005qj-5Z for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39012 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 1fbPcu-0005qZ-0u for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:16 -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 A9598E900C for ; Fri, 6 Jul 2018 12:14:15 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 545E6215688A; Fri, 6 Jul 2018 12:14:15 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:50 +0200 Message-Id: <20180706121354.2021-9-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:14:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 06 Jul 2018 12:14:15 +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 08/12] 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, peterx@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.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879598983409.43422480287836; Fri, 6 Jul 2018 05:19:58 -0700 (PDT) Received: from localhost ([::1]:57451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPiQ-00028T-6r for importer@patchew.org; Fri, 06 Jul 2018 08:19:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPcw-0006kn-Ec for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPcv-0005r3-KI for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51672 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 1fbPcv-0005qx-FR for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:17 -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 191A172651 for ; Fri, 6 Jul 2018 12:14:17 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id C115D111DCF3; Fri, 6 Jul 2018 12:14:16 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:51 +0200 Message-Id: <20180706121354.2021-10-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:14:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 06 Jul 2018 12:14:17 +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 09/12] 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, peterx@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 ceaf4a6789..084c5edff0 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -249,7 +249,39 @@ 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); + + 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); =20 + 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 +511,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); @@ -488,5 +525,6 @@ int main(int argc, char *argv[]) ret =3D g_test_run(); =20 qmp_schema_cleanup(&schema); + return ret; } --=20 2.18.0.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879601466918.1483628628833; Fri, 6 Jul 2018 05:20:01 -0700 (PDT) Received: from localhost ([::1]:57454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPiS-0002BS-JW for importer@patchew.org; Fri, 06 Jul 2018 08:20:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPd0-0006oJ-4k for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPcx-0005rR-0M for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39014 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 1fbPcw-0005rG-R9 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:18 -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 80DACE900C for ; Fri, 6 Jul 2018 12:14:18 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DA82215688A; Fri, 6 Jul 2018 12:14:18 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:52 +0200 Message-Id: <20180706121354.2021-11-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:14:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 06 Jul 2018 12:14:18 +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 10/12] 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, peterx@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.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879598913826.0609838430026; Fri, 6 Jul 2018 05:19:58 -0700 (PDT) Received: from localhost ([::1]:57452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPiQ-0002AP-4h for importer@patchew.org; Fri, 06 Jul 2018 08:19:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPd3-0006qI-Ov for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPd2-0005sN-OV for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51674 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 1fbPd2-0005sG-J8 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:24 -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 3DC4272651 for ; Fri, 6 Jul 2018 12:14:24 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91364111DCF3; Fri, 6 Jul 2018 12:14:19 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:53 +0200 Message-Id: <20180706121354.2021-12-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:14:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 06 Jul 2018 12:14:24 +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 11/12] 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, peterx@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 - rsp/req variable renaming for clarity Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/main.c | 58 ++++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/qga/main.c b/qga/main.c index 0784761605..b0a88ee5cf 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 *qdict; + 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_err(tokens, NULL, &err); + + req =3D json_parser_parse_err(tokens, NULL, &err); if (err) { - goto err; - } - qdict =3D qobject_to(QDict, obj); - if (!qdict) { - error_setg(&err, QERR_JSON_PARSING); - goto err; - } - if (!qdict_haskey(qdict, "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, qdict); - 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)); - qdict =3D qmp_error_response(err); - ret =3D send_response(s, qdict); +end: + ret =3D send_response(s, rsp); if (ret < 0) { g_warning("error sending error response: %s", strerror(-ret)); } - qobject_unref(qdict); - qobject_unref(obj); + qobject_unref(rsp); + qobject_unref(req); } =20 /* false return signals GAChannel to close the current client connection */ --=20 2.18.0.rc1 From nobody Tue Nov 4 18:52:27 2025 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 1530879798914878.0368404870884; Fri, 6 Jul 2018 05:23:18 -0700 (PDT) Received: from localhost ([::1]:57480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPlU-0004sC-H9 for importer@patchew.org; Fri, 06 Jul 2018 08:23:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPdA-00072A-S0 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPd7-0005tf-Lp for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39020 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 1fbPd7-0005tZ-G6 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:29 -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 2A7F4E900C for ; Fri, 6 Jul 2018 12:14:29 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CAA57C4B; Fri, 6 Jul 2018 12:14:25 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:54 +0200 Message-Id: <20180706121354.2021-13-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-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]); Fri, 06 Jul 2018 12:14:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 06 Jul 2018 12:14:29 +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 12/12] RFC: qmp: rework 'id' handling 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, peterx@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 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. Signed-off-by: Marc-Andr=C3=A9 Lureau --- monitor.c | 31 ++++++++++++------------------- qapi/qmp-dispatch.c | 10 ++++++++-- tests/test-qga.c | 13 +++++-------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/monitor.c b/monitor.c index a3efe96d1d..bf192697e4 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 @@ -4081,12 +4074,15 @@ static void monitor_qmp_bh_dispatcher(void *data) =20 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); - monitor_qmp_respond(req_obj->mon, rsp, NULL); + req_obj->err =3D NULL; + monitor_qmp_respond(req_obj->mon, rsp); qobject_unref(rsp); } =20 @@ -4115,8 +4111,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 (trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { @@ -4127,15 +4122,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..acea0fcfcd 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,8 +168,8 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *requ= est, bool allow_oob) { Error *err =3D NULL; - QObject *ret; - QDict *rsp; + QDict *rsp, *dict =3D qobject_to(QDict, request); + QObject *ret, *id =3D dict ? qdict_get(dict, "id") : NULL; =20 ret =3D do_qmp_dispatch(cmds, request, allow_oob, &err); =20 @@ -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.rc1