From nobody Sun May 12 05:25:54 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 1539066675591428.3596355647311; Mon, 8 Oct 2018 23:31:15 -0700 (PDT) Received: from localhost ([::1]:49835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lY2-0002Ss-EP for importer@patchew.org; Tue, 09 Oct 2018 02:31:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lUZ-0000Av-Ao for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9lUY-0006bS-1h for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37782) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9lUX-0006aV-Oq for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1504A356CE for ; Tue, 9 Oct 2018 06:27:37 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DDB265963; Tue, 9 Oct 2018 06:27:34 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 14:27:13 +0800 Message-Id: <20181009062718.1914-2-peterx@redhat.com> In-Reply-To: <20181009062718.1914-1-peterx@redhat.com> References: <20181009062718.1914-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 09 Oct 2018 06:27:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 1/6] monitor: Suspend monitor instead dropping commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Dr . David Alan Gilbert" , peterx@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When a QMP client sends in-band commands more quickly that we can process them, we can either queue them without limit (QUEUE), drop commands when the queue is full (DROP), or suspend receiving commands when the queue is full (SUSPEND). None of them is ideal: * QUEUE lets a misbehaving client make QEMU eat memory without bounds. Not such a hot idea. * With DROP, the client has to cope with dropped in-band commands. To inform the client, we send a COMMAND_DROPPED event then. The event is flawed by design in two ways: it's ambiguous (see commit d621cfe0a17), and it brings back the "eat memory without bounds" problem. * With SUSPEND, the client has to manage the flow of in-band commands to keep the monitor available for out-of-band commands. We currently DROP. Switch to SUSPEND. Managing the flow of in-band commands to keep the monitor available for out-of-band commands isn't really hard: just count the number of "outstanding" in-band commands (commands sent minus replies received), and if it exceeds the limit, hold back additional ones until it drops below the limit again. Note that we need to be careful pairing the suspend with a resume, or else the monitor will hang, possibly forever. And here since we need to make sure both: (1) popping request from the req queue, and (2) reading length of the req queue will be in the same critical section, we let the pop function take the corresponding queue lock when there is a request, then we release the lock from the caller. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu --- docs/interop/qmp-spec.txt | 5 ++-- include/monitor/monitor.h | 2 ++ monitor.c | 52 +++++++++++++++++---------------------- qapi/misc.json | 40 ------------------------------ 4 files changed, 28 insertions(+), 71 deletions(-) diff --git a/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt index 8f7da0245d..67e44a8120 100644 --- a/docs/interop/qmp-spec.txt +++ b/docs/interop/qmp-spec.txt @@ -130,8 +130,9 @@ to pass "id" with out-of-band commands. Passing it wit= h all commands is recommended for clients that accept capability "oob". =20 If the client sends in-band commands faster than the server can -execute them, the server will eventually drop commands to limit the -queue length. The sever sends event COMMAND_DROPPED then. +execute them, the server will stop reading the requests from the QMP +channel until the request queue length is reduced to an acceptable +range. =20 Only a few commands support out-of-band execution. The ones that do have "allow-oob": true in output of query-qmp-schema. diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 6fd2c53b09..0c0a37d8cb 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -15,6 +15,8 @@ extern __thread Monitor *cur_mon; #define MONITOR_USE_PRETTY 0x08 #define MONITOR_USE_OOB 0x10 =20 +#define QMP_REQ_QUEUE_LEN_MAX 8 + bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); diff --git a/monitor.c b/monitor.c index b9258a7438..1f83775fff 100644 --- a/monitor.c +++ b/monitor.c @@ -4097,8 +4097,12 @@ static void monitor_qmp_dispatch(Monitor *mon, QObje= ct *req, QObject *id) * processing commands only on a very busy monitor. To achieve that, * when we process one request on a specific monitor, we put that * monitor to the end of mon_list queue. + * + * Note: if the function returned with non-NULL, then the caller will + * be with mon->qmp.qmp_queue_lock held, and the caller is responsible + * to release it. */ -static QMPRequest *monitor_qmp_requests_pop_any(void) +static QMPRequest *monitor_qmp_requests_pop_any_with_lock(void) { QMPRequest *req_obj =3D NULL; Monitor *mon; @@ -4108,10 +4112,11 @@ static QMPRequest *monitor_qmp_requests_pop_any(voi= d) QTAILQ_FOREACH(mon, &mon_list, entry) { qemu_mutex_lock(&mon->qmp.qmp_queue_lock); req_obj =3D g_queue_pop_head(mon->qmp.qmp_requests); - qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); if (req_obj) { + /* With the lock of corresponding queue held */ break; } + qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); } =20 if (req_obj) { @@ -4130,30 +4135,34 @@ static QMPRequest *monitor_qmp_requests_pop_any(voi= d) =20 static void monitor_qmp_bh_dispatcher(void *data) { - QMPRequest *req_obj =3D monitor_qmp_requests_pop_any(); + QMPRequest *req_obj =3D monitor_qmp_requests_pop_any_with_lock(); QDict *rsp; bool need_resume; + Monitor *mon; =20 if (!req_obj) { return; } =20 + mon =3D req_obj->mon; /* qmp_oob_enabled() might change after "qmp_capabilities" */ - need_resume =3D !qmp_oob_enabled(req_obj->mon); + need_resume =3D !qmp_oob_enabled(mon) || + mon->qmp.qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1; + qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); 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); + monitor_qmp_dispatch(mon, req_obj->req, req_obj->id); } 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(mon, rsp, NULL); qobject_unref(rsp); } =20 if (need_resume) { /* Pairs with the monitor_suspend() in handle_qmp_command() */ - monitor_resume(req_obj->mon); + monitor_resume(mon); } qmp_request_free(req_obj); =20 @@ -4161,8 +4170,6 @@ static void monitor_qmp_bh_dispatcher(void *data) qemu_bh_schedule(qmp_dispatcher_bh); } =20 -#define QMP_REQ_QUEUE_LEN_MAX (8) - static void handle_qmp_command(void *opaque, QObject *req, Error *err) { Monitor *mon =3D opaque; @@ -4204,28 +4211,14 @@ static void handle_qmp_command(void *opaque, QObjec= t *req, Error *err) qemu_mutex_lock(&mon->qmp.qmp_queue_lock); =20 /* - * If OOB is not enabled on the current monitor, we'll emulate the - * old behavior that we won't process the current monitor any more - * until it has responded. This helps make sure that as long as - * OOB is not enabled, the server will never drop any command. + * Suspend the monitor when we can't queue more requests after + * this one. Dequeuing in monitor_qmp_bh_dispatcher() will resume + * it. Note that when OOB is disabled, we queue at most one + * command, for backward compatibility. */ - if (!qmp_oob_enabled(mon)) { + if (!qmp_oob_enabled(mon) || + mon->qmp.qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1) { monitor_suspend(mon); - } else { - /* Drop the request if queue is full. */ - if (mon->qmp.qmp_requests->length >=3D QMP_REQ_QUEUE_LEN_MAX) { - qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); - /* - * FIXME @id's scope is just @mon, and broadcasting it is - * wrong. If another monitor's client has a command with - * the same ID in flight, the event will incorrectly claim - * that command was dropped. - */ - qapi_event_send_command_dropped(id, - COMMAND_DROP_REASON_QUEUE_FULL= ); - qmp_request_free(req_obj); - return; - } } =20 /* @@ -4233,6 +4226,7 @@ static void handle_qmp_command(void *opaque, QObject = *req, Error *err) * handled in time order. Ownership for req_obj, req, id, * etc. will be delivered to the handler side. */ + assert(mon->qmp.qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX); g_queue_push_tail(mon->qmp.qmp_requests, req_obj); qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); =20 diff --git a/qapi/misc.json b/qapi/misc.json index ada9af5add..f149651a98 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -3437,46 +3437,6 @@ ## { 'command': 'query-sev-capabilities', 'returns': 'SevCapability' } =20 -## -# @CommandDropReason: -# -# Reasons that caused one command to be dropped. -# -# @queue-full: the command queue is full. This can only occur when -# the client sends a new non-oob command before the -# response to the previous non-oob command has been -# received. -# -# Since: 2.12 -## -{ 'enum': 'CommandDropReason', - 'data': [ 'queue-full' ] } - -## -# @COMMAND_DROPPED: -# -# Emitted when a command is dropped due to some reason. Commands can -# only be dropped when the oob capability is enabled. -# -# @id: The dropped command's "id" field. -# FIXME Broken by design. Events are broadcast to all monitors. If -# another monitor's client has a command with the same ID in flight, -# the event will incorrectly claim that command was dropped. -# -# @reason: The reason why the command is dropped. -# -# Since: 2.12 -# -# Example: -# -# { "event": "COMMAND_DROPPED", -# "data": {"result": {"id": "libvirt-102", -# "reason": "queue-full" } } } -# -## -{ 'event': 'COMMAND_DROPPED' , - 'data': { 'id': 'any', 'reason': 'CommandDropReason' } } - ## # @set-numa-node: # --=20 2.17.1 From nobody Sun May 12 05:25:54 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 1539066546656533.5553501580466; Mon, 8 Oct 2018 23:29:06 -0700 (PDT) Received: from localhost ([::1]:49821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lVs-0000oQ-GK for importer@patchew.org; Tue, 09 Oct 2018 02:29:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lUc-0000C4-28 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9lUb-0006ec-CR for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9lUb-0006dU-6K for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1032D5D66B for ; Tue, 9 Oct 2018 06:27:40 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D5586595C; Tue, 9 Oct 2018 06:27:37 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 14:27:14 +0800 Message-Id: <20181009062718.1914-3-peterx@redhat.com> In-Reply-To: <20181009062718.1914-1-peterx@redhat.com> References: <20181009062718.1914-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 09 Oct 2018 06:27:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 2/6] monitor: resume the monitor earlier if needed 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: "Dr . David Alan Gilbert" , peterx@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently when QMP request queue full we won't resume the monitor until we have completely handled the current command. It's not necessary since even before it's handled the queue is already non-full. Moving the resume logic earlier before the command execution. Note that now monitor_resume() is heavy weighted after 8af6bb14a3a8 and it's even possible (as pointed out by Marc-Andr=C3=A9) that the function itself may try to take the monitor lock again, so let's do the resume after the monitor lock is released to avoid possible dead lock. Signed-off-by: Peter Xu --- monitor.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 1f83775fff..f5911399d8 100644 --- a/monitor.c +++ b/monitor.c @@ -4149,6 +4149,12 @@ static void monitor_qmp_bh_dispatcher(void *data) need_resume =3D !qmp_oob_enabled(mon) || mon->qmp.qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1; qemu_mutex_unlock(&mon->qmp.qmp_queue_lock); + + if (need_resume) { + /* Pairs with the monitor_suspend() in handle_qmp_command() */ + monitor_resume(mon); + } + if (req_obj->req) { trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: = ""); monitor_qmp_dispatch(mon, req_obj->req, req_obj->id); @@ -4160,10 +4166,6 @@ static void monitor_qmp_bh_dispatcher(void *data) qobject_unref(rsp); } =20 - if (need_resume) { - /* Pairs with the monitor_suspend() in handle_qmp_command() */ - monitor_resume(mon); - } qmp_request_free(req_obj); =20 /* Reschedule instead of looping so the main loop stays responsive */ --=20 2.17.1 From nobody Sun May 12 05:25:54 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 1539066685835386.61385919038116; Mon, 8 Oct 2018 23:31:25 -0700 (PDT) Received: from localhost ([::1]:49836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lYC-0002bt-RH for importer@patchew.org; Tue, 09 Oct 2018 02:31:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lUh-0000Fp-3R for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9lUd-0006gu-Tt for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35586) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9lUd-0006gA-LF for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E9033084219 for ; Tue, 9 Oct 2018 06:27:43 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A28117243; Tue, 9 Oct 2018 06:27:40 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 14:27:15 +0800 Message-Id: <20181009062718.1914-4-peterx@redhat.com> In-Reply-To: <20181009062718.1914-1-peterx@redhat.com> References: <20181009062718.1914-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 09 Oct 2018 06:27:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 3/6] monitor: remove "x-oob", turn oob on by default 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: "Dr . David Alan Gilbert" , peterx@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" OOB commands were introduced in commit cf869d53172. Unfortunately, we ran into a regression, and had to disable them by default for 2.12 (commit be933ffc23). http://lists.gnu.org/archive/html/qemu-devel/2018-03/msg06231.html The regression has since been fixed (commit 951702f39c7 "monitor: bind dispatch bh to iohandler context"). Time to re-enable OOB. This patch partly reverts be933ffc23 (monitor: new parameter "x-oob"), and turns it on again for non-MUX QMPs. Note that we can't enable Out-Of-Band for monitors with MUX-typed chardev backends, because not all the chardev frontends can run without main thread, or can run in multiple threads. Some trivial touch-up in the test code is required to make sure qmp-test won't break. Reviewed-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu --- include/monitor/monitor.h | 1 - monitor.c | 22 ++++++---------------- tests/libqtest.c | 2 +- tests/qmp-test.c | 2 +- vl.c | 5 ----- 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 0c0a37d8cb..c1b40a9cac 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -13,7 +13,6 @@ extern __thread Monitor *cur_mon; #define MONITOR_USE_READLINE 0x02 #define MONITOR_USE_CONTROL 0x04 #define MONITOR_USE_PRETTY 0x08 -#define MONITOR_USE_OOB 0x10 =20 #define QMP_REQ_QUEUE_LEN_MAX 8 =20 diff --git a/monitor.c b/monitor.c index f5911399d8..65a5e5f41a 100644 --- a/monitor.c +++ b/monitor.c @@ -4545,19 +4545,12 @@ void monitor_init(Chardev *chr, int flags) { Monitor *mon =3D g_malloc(sizeof(*mon)); bool use_readline =3D flags & MONITOR_USE_READLINE; - bool use_oob =3D flags & MONITOR_USE_OOB; - - if (use_oob) { - if (CHARDEV_IS_MUX(chr)) { - error_report("Monitor out-of-band is not supported with " - "MUX typed chardev backend"); - exit(1); - } - if (use_readline) { - error_report("Monitor out-of-band is only supported by QMP"); - exit(1); - } - } + /* + * Note: we can't enable Out-Of-Band for monitors with MUX-typed + * chardev backends, because not all the chardev frontends can run + * without main thread, or can run in multiple threads. + */ + bool use_oob =3D (flags & MONITOR_USE_CONTROL) && !CHARDEV_IS_MUX(chr); =20 monitor_data_init(mon, false, use_oob); =20 @@ -4647,9 +4640,6 @@ QemuOptsList qemu_mon_opts =3D { },{ .name =3D "pretty", .type =3D QEMU_OPT_BOOL, - },{ - .name =3D "x-oob", - .type =3D QEMU_OPT_BOOL, }, { /* end of list */ } }, diff --git a/tests/libqtest.c b/tests/libqtest.c index 2cd5736642..8bf9fd1ae3 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -231,7 +231,7 @@ QTestState *qtest_init_without_qmp_handshake(bool use_o= ob, "-display none " "%s", qemu_binary, socket_path, getenv("QTEST_LOG") ? "/dev/fd/2" : "/de= v/null", - qmp_socket_path, use_oob ? ",x-oob=3Don"= : "", + qmp_socket_path, "", extra_args ?: ""); execlp("/bin/sh", "sh", "-c", command, NULL); exit(1); diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 6c419f6023..030d813f77 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -116,7 +116,7 @@ static void test_qmp_protocol(void) g_assert(q); test_version(qdict_get(q, "version")); capabilities =3D qdict_get_qlist(q, "capabilities"); - g_assert(capabilities && qlist_empty(capabilities)); + g_assert(capabilities); qobject_unref(resp); =20 /* Test valid command before handshake */ diff --git a/vl.c b/vl.c index 4e25c78bff..db766f5295 100644 --- a/vl.c +++ b/vl.c @@ -2282,11 +2282,6 @@ static int mon_init_func(void *opaque, QemuOpts *opt= s, Error **errp) if (qemu_opt_get_bool(opts, "pretty", 0)) flags |=3D MONITOR_USE_PRETTY; =20 - /* OOB is off by default */ - if (qemu_opt_get_bool(opts, "x-oob", 0)) { - flags |=3D MONITOR_USE_OOB; - } - chardev =3D qemu_opt_get(opts, "chardev"); chr =3D qemu_chr_find(chardev); if (chr =3D=3D NULL) { --=20 2.17.1 From nobody Sun May 12 05:25:54 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 1539066835296450.67556048615177; Mon, 8 Oct 2018 23:33:55 -0700 (PDT) Received: from localhost ([::1]:49849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lac-0004PF-60 for importer@patchew.org; Tue, 09 Oct 2018 02:33:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lUr-0000O8-6I for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9lUo-0006qm-1x for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48826) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9lUn-0006q6-Pt for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28611C04BD42 for ; Tue, 9 Oct 2018 06:27:53 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 883AE17243; Tue, 9 Oct 2018 06:27:43 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 14:27:16 +0800 Message-Id: <20181009062718.1914-5-peterx@redhat.com> In-Reply-To: <20181009062718.1914-1-peterx@redhat.com> References: <20181009062718.1914-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 09 Oct 2018 06:27:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 4/6] Revert "tests: Add parameter to qtest_init_without_qmp_handshake" 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: "Dr . David Alan Gilbert" , peterx@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This reverts commit ddee57e0176f6ab53b13c6c97605b62737a8fd7a. Meanwhile, revert one line from fa198ad9bdef to make sure qtest_init_without_qmp_handshake() will only pass in one parameter. Reviewed-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu --- tests/libqtest.c | 10 ++++------ tests/libqtest.h | 4 +--- tests/qmp-test.c | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 8bf9fd1ae3..e0bb032c5e 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -191,8 +191,7 @@ static const char *qtest_qemu_binary(void) return qemu_bin; } =20 -QTestState *qtest_init_without_qmp_handshake(bool use_oob, - const char *extra_args) +QTestState *qtest_init_without_qmp_handshake(const char *extra_args) { QTestState *s; int sock, qmpsock, i; @@ -225,13 +224,12 @@ QTestState *qtest_init_without_qmp_handshake(bool use= _oob, command =3D g_strdup_printf("exec %s " "-qtest unix:%s,nowait " "-qtest-log %s " - "-chardev socket,path=3D%s,nowait,id=3Dc= har0 " - "-mon chardev=3Dchar0,mode=3Dcontrol%s " + "-qmp unix:%s,nowait " "-machine accel=3Dqtest " "-display none " "%s", qemu_binary, socket_path, getenv("QTEST_LOG") ? "/dev/fd/2" : "/de= v/null", - qmp_socket_path, "", + qmp_socket_path, extra_args ?: ""); execlp("/bin/sh", "sh", "-c", command, NULL); exit(1); @@ -266,7 +264,7 @@ QTestState *qtest_init_without_qmp_handshake(bool use_o= ob, =20 QTestState *qtest_init(const char *extra_args) { - QTestState *s =3D qtest_init_without_qmp_handshake(false, extra_args); + QTestState *s =3D qtest_init_without_qmp_handshake(extra_args); QDict *greeting; =20 /* Read the QMP greeting and then do the handshake */ diff --git a/tests/libqtest.h b/tests/libqtest.h index ed88ff99d5..96a6c01352 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -55,14 +55,12 @@ QTestState *qtest_init(const char *extra_args); =20 /** * qtest_init_without_qmp_handshake: - * @use_oob: true to have the server advertise OOB support * @extra_args: other arguments to pass to QEMU. CAUTION: these * arguments are subject to word splitting and shell evaluation. * * Returns: #QTestState instance. */ -QTestState *qtest_init_without_qmp_handshake(bool use_oob, - const char *extra_args); +QTestState *qtest_init_without_qmp_handshake(const char *extra_args); =20 /** * qtest_quit: diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 030d813f77..cc9907b525 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -108,7 +108,7 @@ static void test_qmp_protocol(void) QList *capabilities; QTestState *qts; =20 - qts =3D qtest_init_without_qmp_handshake(false, common_args); + qts =3D qtest_init_without_qmp_handshake(common_args); =20 /* Test greeting */ resp =3D qtest_qmp_receive(qts); @@ -219,7 +219,7 @@ static void test_qmp_oob(void) QList *capabilities; QString *qstr; =20 - qts =3D qtest_init_without_qmp_handshake(true, common_args); + qts =3D qtest_init_without_qmp_handshake(common_args); =20 /* Check the greeting message. */ resp =3D qtest_qmp_receive(qts); --=20 2.17.1 From nobody Sun May 12 05:25:54 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 1539066829810879.269345853764; Mon, 8 Oct 2018 23:33:49 -0700 (PDT) Received: from localhost ([::1]:49848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9laW-0004Iw-PF for importer@patchew.org; Tue, 09 Oct 2018 02:33:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lUs-0000PG-MR for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9lUr-0006vG-Uj for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34222) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9lUr-0006uP-P1 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:27:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A0B530832CD for ; Tue, 9 Oct 2018 06:27:57 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id A21D565968; Tue, 9 Oct 2018 06:27:53 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 14:27:17 +0800 Message-Id: <20181009062718.1914-6-peterx@redhat.com> In-Reply-To: <20181009062718.1914-1-peterx@redhat.com> References: <20181009062718.1914-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 09 Oct 2018 06:27:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 5/6] tests: add oob functional test for test-qmp-cmds 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: "Dr . David Alan Gilbert" , peterx@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Straightforward test just to let the test-qmp-cmds be complete. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu --- tests/test-qmp-cmds.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 4ab2b6e5ce..481cb069ca 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -126,6 +126,21 @@ static void test_dispatch_cmd(void) qobject_unref(req); } =20 +static void test_dispatch_cmd_oob(void) +{ + QDict *req =3D qdict_new(); + QDict *resp; + + qdict_put_str(req, "exec-oob", "test-flags-command"); + + resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req), true); + assert(resp !=3D NULL); + assert(!qdict_haskey(resp, "error")); + + qobject_unref(resp); + qobject_unref(req); +} + /* test commands that return an error due to invalid parameters */ static void test_dispatch_cmd_failure(void) { @@ -302,6 +317,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); =20 g_test_add_func("/qmp/dispatch_cmd", test_dispatch_cmd); + g_test_add_func("/qmp/dispatch_cmd_oob", test_dispatch_cmd_oob); 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", --=20 2.17.1 From nobody Sun May 12 05:25:54 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 1539066925621963.135157951536; Mon, 8 Oct 2018 23:35:25 -0700 (PDT) Received: from localhost ([::1]:49862 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lc4-0005Lg-LD for importer@patchew.org; Tue, 09 Oct 2018 02:35:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9lUv-0000Rr-Md for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:28:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9lUv-0006ys-2L for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:28:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37878) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9lUu-0006xz-QG for qemu-devel@nongnu.org; Tue, 09 Oct 2018 02:28:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A2D2356D3 for ; Tue, 9 Oct 2018 06:28:00 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F58317243; Tue, 9 Oct 2018 06:27:57 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 14:27:18 +0800 Message-Id: <20181009062718.1914-7-peterx@redhat.com> In-Reply-To: <20181009062718.1914-1-peterx@redhat.com> References: <20181009062718.1914-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 09 Oct 2018 06:28:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 6/6] tests: qmp-test: add queue full 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: "Dr . David Alan Gilbert" , peterx@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We'll need to include "monitor/monitor.h" for the queue length macro, then we don't need to hard code it. Suggested-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu --- tests/qmp-test.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/qmp-test.c b/tests/qmp-test.c index cc9907b525..6989acbca4 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -18,6 +18,7 @@ #include "qapi/qmp/qlist.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qmp/qstring.h" +#include "monitor/monitor.h" =20 const char common_args[] =3D "-nodefaults -machine none"; =20 @@ -218,6 +219,8 @@ static void test_qmp_oob(void) const QListEntry *entry; QList *capabilities; QString *qstr; + gchar *id; + int i; =20 qts =3D qtest_init_without_qmp_handshake(common_args); =20 @@ -272,6 +275,29 @@ static void test_qmp_oob(void) unblock_blocked_cmd(); recv_cmd_id(qts, "blocks-2"); recv_cmd_id(qts, "err-2"); + + /* + * Test queue full. When that happens, the out-of-band command + * will only be able to be handled after the queue is shrinked, so + * it'll be processed only after one existing in-band command + * finishes. + */ + for (i =3D 1; i <=3D QMP_REQ_QUEUE_LEN_MAX; i++) { + id =3D g_strdup_printf("queue-blocks-%d", i); + send_cmd_that_blocks(qts, id); + g_free(id); + } + send_oob_cmd_that_fails(qts, "oob-1"); + unblock_blocked_cmd(); + recv_cmd_id(qts, "queue-blocks-1"); + recv_cmd_id(qts, "oob-1"); + for (i =3D 2; i <=3D QMP_REQ_QUEUE_LEN_MAX; i++) { + unblock_blocked_cmd(); + id =3D g_strdup_printf("queue-blocks-%d", i); + recv_cmd_id(qts, id); + g_free(id); + } + cleanup_blocking_cmd(); =20 qtest_quit(qts); --=20 2.17.1