From nobody Fri May 3 11:28:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606484465; cv=none; d=zohomail.com; s=zohoarc; b=ZiSd2gID1+pYZW+OPqkZjojgSRbOEQDXwQ0y4TgDWrCUwTC69q0547xPX5G4WQSawlZTwYHPgdg6rzPMSHSXyyce93jSScwKYFvEn2nXY2BQHOJ2OoSHKtx/MQsC/QKRTlwBo1VvOpeNntZWuadrbjWg7Xwsd9Ah9inzS533e/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606484465; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=7HRvo7Sgd0dKrKME9gDNxCAOtzf5nQgETzNkhpMPlhg=; b=nUi6U31WxSz6sTbUBQc7B6MNuDC6EIR4/kRsiAJ/nc8B1eAnO1XeiWf4kwoyEt8fCehqkbidlaQfNaX6fvVBZtA7S/fxu5CZaMbF4RRrsEJojDsaD2hdqXGyqt9UAx1TeG0MDc2qCQbQL6UNnVv4BQNrlIjhL9f86PBvOh1+OSc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606484465661922.4947239998697; Fri, 27 Nov 2020 05:41:05 -0800 (PST) Received: from localhost ([::1]:48152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kidzk-0002Rs-Gu for importer@patchew.org; Fri, 27 Nov 2020 08:41:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvR-0005um-Mx; Fri, 27 Nov 2020 08:36:37 -0500 Received: from relay.sw.ru ([185.231.240.75]:52496 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvP-0003BA-MH; Fri, 27 Nov 2020 08:36:37 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidux-00AfjY-5Y; Fri, 27 Nov 2020 16:36:07 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 1/5] monitor: change function obsolete name in comments Date: Fri, 27 Nov 2020 16:35:42 +0300 Message-Id: <1606484146-913540-2-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich From: Andrey Shinkevich via Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The function name monitor_qmp_bh_dispatcher() has been changed to monitor_qmp_dispatcher_co() since the commit 9ce44e2c. Let's amend the comments. Signed-off-by: Andrey Shinkevich --- monitor/qmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index b42f8c6..7169366 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -80,7 +80,7 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQ= MP *mon) qemu_mutex_lock(&mon->qmp_queue_lock); =20 /* - * Same condition as in monitor_qmp_bh_dispatcher(), but before + * Same condition as in monitor_qmp_dispatcher_co(), but before * removing an element from the queue (hence no `- 1`). * Also, the queue should not be empty either, otherwise the * monitor hasn't been suspended yet (or was already resumed). @@ -343,7 +343,7 @@ static void handle_qmp_command(void *opaque, QObject *r= eq, Error *err) =20 /* * Suspend the monitor when we can't queue more requests after - * this one. Dequeuing in monitor_qmp_bh_dispatcher() or + * this one. Dequeuing in monitor_qmp_dispatcher_co() or * monitor_qmp_cleanup_queue_and_resume() will resume it. * Note that when OOB is disabled, we queue at most one command, * for backward compatibility. --=20 1.8.3.1 From nobody Fri May 3 11:28:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606484530; cv=none; d=zohomail.com; s=zohoarc; b=ZntFwtp/6zzGrVzoln43vLhk28w54xKfptiYs2DR0ly1CahL2TpQbaCfPI7Z7LDJj1kom7MaX4lxVkI47LQYfqIx+MDYjoHwNqtAE8jXZXqwi3DVGgRTpC/VIi0t9nigb83MWOs7+UmLLRYQI56qn73mAtBnpQ8D13LVWb5+HmA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606484530; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=r0zfkwRlqFVPP9PJFq1WNxayK1FpoEY8frHhALsyXg0=; b=jWtBD7cFLQhdLXIh0PPbS8+P4SvnbjEQfSU3IYzRr+kxiddGTrQ1/OBg6FTftse4EW3MroQnxY4009CUYqScscnlmJ1fWiVfh2f1PEe53c3ECKhD16+H28d/IobH03vPC1kW0uMrYx1AhxbqzpWPdHvQHuVw8+r+mYG+hgV0PeQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606484530374365.03370113475546; Fri, 27 Nov 2020 05:42:10 -0800 (PST) Received: from localhost ([::1]:49396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie0n-0002xu-9o for importer@patchew.org; Fri, 27 Nov 2020 08:42:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvp-0006LW-25; Fri, 27 Nov 2020 08:37:02 -0500 Received: from relay.sw.ru ([185.231.240.75]:52608 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidvm-0003I8-SN; Fri, 27 Nov 2020 08:37:00 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidvK-00AfjY-N5; Fri, 27 Nov 2020 16:36:30 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 2/5] monitor: drain requests queue with 'channel closed' event Date: Fri, 27 Nov 2020 16:35:43 +0300 Message-Id: <1606484146-913540-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich From: Andrey Shinkevich via Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When CHR_EVENT_CLOSED comes, the QMP requests queue may still contain unprocessed commands. It can happen with QMP capability OOB enabled. Let the dispatcher complete handling requests rest in the monitor queue. Signed-off-by: Andrey Shinkevich --- monitor/qmp.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index 7169366..a86ed35 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -75,36 +75,32 @@ static void monitor_qmp_cleanup_req_queue_locked(Monito= rQMP *mon) } } =20 -static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon) +/* + * Let unprocessed QMP commands be handled. + */ +static void monitor_qmp_drain_queue(MonitorQMP *mon) { - qemu_mutex_lock(&mon->qmp_queue_lock); + bool q_is_empty =3D false; =20 - /* - * Same condition as in monitor_qmp_dispatcher_co(), but before - * removing an element from the queue (hence no `- 1`). - * Also, the queue should not be empty either, otherwise the - * monitor hasn't been suspended yet (or was already resumed). - */ - bool need_resume =3D (!qmp_oob_enabled(mon) || - mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX) - && !g_queue_is_empty(mon->qmp_requests); + while (!q_is_empty) { + qemu_mutex_lock(&mon->qmp_queue_lock); + q_is_empty =3D g_queue_is_empty(mon->qmp_requests); + qemu_mutex_unlock(&mon->qmp_queue_lock); =20 - monitor_qmp_cleanup_req_queue_locked(mon); + if (!q_is_empty) { + if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) { + /* Kick the dispatcher coroutine */ + aio_co_wake(qmp_dispatcher_co); + } else { + /* Let the dispatcher do its job for a while */ + g_usleep(40); + } + } + } =20 - if (need_resume) { - /* - * handle_qmp_command() suspended the monitor because the - * request queue filled up, to be resumed when the queue has - * space again. We just emptied it; resume the monitor. - * - * Without this, the monitor would remain suspended forever - * when we get here while the monitor is suspended. An - * unfortunately timed CHR_EVENT_CLOSED can do the trick. - */ + if (qatomic_mb_read(&mon->common.suspend_cnt)) { monitor_resume(&mon->common); } - - qemu_mutex_unlock(&mon->qmp_queue_lock); } =20 void qmp_send_response(MonitorQMP *mon, const QDict *rsp) @@ -418,7 +414,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEven= t event) * stdio, it's possible that stdout is still open when stdin * is closed. */ - monitor_qmp_cleanup_queue_and_resume(mon); + monitor_qmp_drain_queue(mon); json_message_parser_destroy(&mon->parser); json_message_parser_init(&mon->parser, handle_qmp_command, mon, NULL); --=20 1.8.3.1 From nobody Fri May 3 11:28:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606484584; cv=none; d=zohomail.com; s=zohoarc; b=Y/TKjOR125C1tQSAjK9EOVEti4U9TSZ1Ti8AMHzO8GHk491IYVMXS6sImtunR/ie2st20TAafnnnoh15Fz9zvNynTb+wfkuq6D/pYrYf8wD54RVqsv2zi0Ybc4kwwQ94LFcYn/SDvi+7bpu3EN1DhEnV2liJyyy+VihpaqKQGdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606484584; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=zNCKD2/LHYqlneV2LJZH/jJKSwWoT7PW2fPpsLd2RUY=; b=dpHx4DqRIZ52zCewCXVU8ME81QcKJkOhOe5RvEbfFj+ZcHbfGWWeFoqmdAfvXoPa/7tk8U+GuSRtoLdD5e7AxANy0te0WEmEJGijy5JKeBjpKSH+i/FkiIWLPDH2/jouWubepGNXZ1csLOJkJlJbuiBFXG4TRfEyum9sw1fPauw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606484584455796.6222484430607; Fri, 27 Nov 2020 05:43:04 -0800 (PST) Received: from localhost ([::1]:53112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie1f-0004Tf-34 for importer@patchew.org; Fri, 27 Nov 2020 08:43:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwD-00075k-HL; Fri, 27 Nov 2020 08:37:25 -0500 Received: from relay.sw.ru ([185.231.240.75]:52764 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwB-0003RG-BQ; Fri, 27 Nov 2020 08:37:25 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidvi-00AfjY-8I; Fri, 27 Nov 2020 16:36:54 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 3/5] monitor: let QMP monitor track JSON message content Date: Fri, 27 Nov 2020 16:35:44 +0300 Message-Id: <1606484146-913540-4-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich From: Andrey Shinkevich via Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are going to allow the QMP monitor reading data from input channel more than one byte at once to increase the performance. With the OOB compatibility disabled, the monitor queues one QMP command at most. It was done for the backward compatibility as stated in the comment before pushing a command into the queue. To keep that concept functional, the monitor should track the end of a single QMP command. It allows the dispatcher handling the command and send a response to client in time. Signed-off-by: Andrey Shinkevich --- include/qapi/qmp/json-parser.h | 5 +++-- monitor/qmp.c | 18 ++++++++++++++++-- qga/main.c | 2 +- qobject/json-lexer.c | 30 +++++++++++++++++++++--------- qobject/json-parser-int.h | 8 +++++--- qobject/json-streamer.c | 15 ++++++++------- qobject/qjson.c | 2 +- tests/qtest/libqtest.c | 2 +- 8 files changed, 56 insertions(+), 26 deletions(-) diff --git a/include/qapi/qmp/json-parser.h b/include/qapi/qmp/json-parser.h index 7345a9b..039addb 100644 --- a/include/qapi/qmp/json-parser.h +++ b/include/qapi/qmp/json-parser.h @@ -36,8 +36,9 @@ void json_message_parser_init(JSONMessageParser *parser, Error *err), void *opaque, va_list *ap); =20 -void json_message_parser_feed(JSONMessageParser *parser, - const char *buffer, size_t size); +size_t json_message_parser_feed(JSONMessageParser *parser, + const char *buffer, size_t size, + bool track_qmp); =20 void json_message_parser_flush(JSONMessageParser *parser); =20 diff --git a/monitor/qmp.c b/monitor/qmp.c index a86ed35..0b39c62 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -367,8 +367,22 @@ static void handle_qmp_command(void *opaque, QObject *= req, Error *err) static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) { MonitorQMP *mon =3D opaque; - - json_message_parser_feed(&mon->parser, (const char *) buf, size); + char *cursor =3D (char *) buf; + size_t len; + + while (size > 0) { + len =3D json_message_parser_feed(&mon->parser, (const char *) curs= or, + size, true); + cursor +=3D len; + size -=3D len; + + if (size > 0) { + /* Let the dispatcher process the QMP command */ + while (qatomic_mb_read(&mon->common.suspend_cnt)) { + g_usleep(20); + } + } + } } =20 static QDict *qmp_greeting(MonitorQMP *mon) diff --git a/qga/main.c b/qga/main.c index dea6a3a..16de642 100644 --- a/qga/main.c +++ b/qga/main.c @@ -605,7 +605,7 @@ static gboolean channel_event_cb(GIOCondition condition= , gpointer data) case G_IO_STATUS_NORMAL: buf[count] =3D 0; g_debug("read data, count: %d, data: %s", (int)count, buf); - json_message_parser_feed(&s->parser, (char *)buf, (int)count); + json_message_parser_feed(&s->parser, (char *)buf, (int)count, fals= e); break; case G_IO_STATUS_EOF: g_debug("received EOF"); diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index 632320d..1fefbae 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -280,10 +280,11 @@ void json_lexer_init(JSONLexer *lexer, bool enable_in= terpolation) lexer->x =3D lexer->y =3D 0; } =20 -static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush) +static JSONTokenType json_lexer_feed_char(JSONLexer *lexer, char ch, bool = flush) { int new_state; bool char_consumed =3D false; + JSONTokenType ret; =20 lexer->x++; if (ch =3D=3D '\n') { @@ -310,16 +311,16 @@ static void json_lexer_feed_char(JSONLexer *lexer, ch= ar ch, bool flush) case JSON_FLOAT: case JSON_KEYWORD: case JSON_STRING: - json_message_process_token(lexer, lexer->token, new_state, - lexer->x, lexer->y); + ret =3D json_message_process_token(lexer, lexer->token, new_st= ate, + lexer->x, lexer->y); /* fall through */ case IN_START: g_string_truncate(lexer->token, 0); new_state =3D lexer->start_state; break; case JSON_ERROR: - json_message_process_token(lexer, lexer->token, JSON_ERROR, - lexer->x, lexer->y); + ret =3D json_message_process_token(lexer, lexer->token, JSON_E= RROR, + lexer->x, lexer->y); new_state =3D IN_RECOVERY; /* fall through */ case IN_RECOVERY: @@ -335,20 +336,31 @@ static void json_lexer_feed_char(JSONLexer *lexer, ch= ar ch, bool flush) * this is a security consideration. */ if (lexer->token->len > MAX_TOKEN_SIZE) { - json_message_process_token(lexer, lexer->token, lexer->state, - lexer->x, lexer->y); + ret =3D json_message_process_token(lexer, lexer->token, lexer->sta= te, + lexer->x, lexer->y); g_string_truncate(lexer->token, 0); lexer->state =3D lexer->start_state; } + return ret; } =20 -void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size) +/* + * Return the number of characters fed until the end of a QMP command or + * the buffer size if not any or else not tracked. + */ +size_t json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size, + bool track) { size_t i; + JSONTokenType type =3D JSON_ERROR; =20 for (i =3D 0; i < size; i++) { - json_lexer_feed_char(lexer, buffer[i], false); + if ((type =3D=3D JSON_QMP_CMD_END) && track) { + break; + } + type =3D json_lexer_feed_char(lexer, buffer[i], false); } + return i; } =20 void json_lexer_flush(JSONLexer *lexer) diff --git a/qobject/json-parser-int.h b/qobject/json-parser-int.h index 16a25d0..904555b 100644 --- a/qobject/json-parser-int.h +++ b/qobject/json-parser-int.h @@ -31,6 +31,7 @@ typedef enum json_token_type { JSON_KEYWORD, JSON_STRING, JSON_INTERP, + JSON_QMP_CMD_END, JSON_END_OF_INPUT, JSON_MAX =3D JSON_END_OF_INPUT } JSONTokenType; @@ -39,13 +40,14 @@ typedef struct JSONToken JSONToken; =20 /* json-lexer.c */ void json_lexer_init(JSONLexer *lexer, bool enable_interpolation); -void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size); +size_t json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size, + bool track); void json_lexer_flush(JSONLexer *lexer); void json_lexer_destroy(JSONLexer *lexer); =20 /* json-streamer.c */ -void json_message_process_token(JSONLexer *lexer, GString *input, - JSONTokenType type, int x, int y); +JSONTokenType json_message_process_token(JSONLexer *lexer, GString *input, + JSONTokenType type, int x, int y); =20 /* json-parser.c */ JSONToken *json_token(JSONTokenType type, int x, int y, GString *tokstr); diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index b93d97b..fe33303 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -28,8 +28,8 @@ static void json_message_free_tokens(JSONMessageParser *p= arser) } } =20 -void json_message_process_token(JSONLexer *lexer, GString *input, - JSONTokenType type, int x, int y) +JSONTokenType json_message_process_token(JSONLexer *lexer, GString *input, + JSONTokenType type, int x, int y) { JSONMessageParser *parser =3D container_of(lexer, JSONMessageParser, l= exer); QObject *json =3D NULL; @@ -54,7 +54,7 @@ void json_message_process_token(JSONLexer *lexer, GString= *input, goto out_emit; case JSON_END_OF_INPUT: if (g_queue_is_empty(&parser->tokens)) { - return; + return type; } json =3D json_parser_parse(&parser->tokens, parser->ap, &err); goto out_emit; @@ -86,7 +86,7 @@ void json_message_process_token(JSONLexer *lexer, GString= *input, =20 if ((parser->brace_count > 0 || parser->bracket_count > 0) && parser->brace_count >=3D 0 && parser->bracket_count >=3D 0) { - return; + return type; } =20 json =3D json_parser_parse(&parser->tokens, parser->ap, &err); @@ -97,6 +97,7 @@ out_emit: json_message_free_tokens(parser); parser->token_size =3D 0; parser->emit(parser->opaque, json, err); + return JSON_QMP_CMD_END; } =20 void json_message_parser_init(JSONMessageParser *parser, @@ -115,10 +116,10 @@ void json_message_parser_init(JSONMessageParser *pars= er, json_lexer_init(&parser->lexer, !!ap); } =20 -void json_message_parser_feed(JSONMessageParser *parser, - const char *buffer, size_t size) +size_t json_message_parser_feed(JSONMessageParser *parser, + const char *buffer, size_t size, bool trac= k_qmp) { - json_lexer_feed(&parser->lexer, buffer, size); + return json_lexer_feed(&parser->lexer, buffer, size, track_qmp); } =20 void json_message_parser_flush(JSONMessageParser *parser) diff --git a/qobject/qjson.c b/qobject/qjson.c index f1f2c69..f85a1ff 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -66,7 +66,7 @@ static QObject *qobject_from_jsonv(const char *string, va= _list *ap, JSONParsingState state =3D {}; =20 json_message_parser_init(&state.parser, consume_json, &state, ap); - json_message_parser_feed(&state.parser, string, strlen(string)); + json_message_parser_feed(&state.parser, string, strlen(string), false); json_message_parser_flush(&state.parser); json_message_parser_destroy(&state.parser); =20 diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index e49f3a1..7e82d9f 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -611,7 +611,7 @@ QDict *qmp_fd_receive(int fd) if (log) { len =3D write(2, &c, 1); } - json_message_parser_feed(&qmp.parser, &c, 1); + json_message_parser_feed(&qmp.parser, &c, 1, false); } json_message_parser_destroy(&qmp.parser); =20 --=20 1.8.3.1 From nobody Fri May 3 11:28:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606484759; cv=none; d=zohomail.com; s=zohoarc; b=B+2AKlvmQQZDhVGHhRkpn3s122ml6PHYBj6xsVwS+oMfC88m7QpgTtK80O0SrIpgg1pSVRhkOQNKgf2NW9w9xyrt/ohbEiqyXpDonU7Q8qd/wisaHm4MKpTdM53gDKcWUpBxW4oqqOayYOXzwRpp8/YaJVSiOUOl9sWXpiJwbi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606484759; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=84JpXhee4V4RepNE99WNdHESYCvsvQlzh98/dWYMhRY=; b=KA6b3d1O3Zb0M8CMoyx97BLoSPK4TbrM9Q2cOiDqNjZVq5RHnpflROPCmh2V24eNhIykgeWDWr5UC9dinTP7HFi8TZxacM/rv6ypq/2Mpv0/JibMYh71Is4hqEpoNQamcoCs5sb9F1/CZtpXJeqdGM3xqlxRrrZqc36xBNFnId8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606484759748574.926862243727; Fri, 27 Nov 2020 05:45:59 -0800 (PST) Received: from localhost ([::1]:60152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie4U-0007O7-NA for importer@patchew.org; Fri, 27 Nov 2020 08:45:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwd-0007V3-Et; Fri, 27 Nov 2020 08:37:51 -0500 Received: from relay.sw.ru ([185.231.240.75]:52908 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwa-0003Yg-82; Fri, 27 Nov 2020 08:37:51 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidw5-00AfjY-Pj; Fri, 27 Nov 2020 16:37:17 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 4/5] iotests: 129 don't check backup "busy" Date: Fri, 27 Nov 2020 16:35:45 +0300 Message-Id: <1606484146-913540-5-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich From: Andrey Shinkevich via Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Busy is racy, job has it's "pause-points" when it's not busy. Drop this check. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- tests/qemu-iotests/129 | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/qemu-iotests/129 b/tests/qemu-iotests/129 index 0e13244..3c22f64 100755 --- a/tests/qemu-iotests/129 +++ b/tests/qemu-iotests/129 @@ -67,7 +67,6 @@ class TestStopWithBlockJob(iotests.QMPTestCase): result =3D self.vm.qmp("stop") self.assert_qmp(result, 'return', {}) result =3D self.vm.qmp("query-block-jobs") - self.assert_qmp(result, 'return[0]/busy', True) self.assert_qmp(result, 'return[0]/ready', False) =20 def test_drive_mirror(self): --=20 1.8.3.1 From nobody Fri May 3 11:28:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1606484715; cv=none; d=zohomail.com; s=zohoarc; b=UTCuXo5rY2aMiC17QFDZLd3BzOKPPgz5wJE2yNHVx6TX+mjyUACDmLtDojlm4g+zY8H1fHsAD4Dqtfg5mJl9WSzwzAM6stOncXzBohImeM9oceN93Cvx6cRxyo2iiZ5oWSTSgkDXYxPiZ1e3lRUUxspgqM2NdjAGlL8G3BK4ANg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606484715; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=jOXefFhDELlQN4xhxHFqsPp2mkZpZe2Uo+aRvJd7BGc=; b=ZRQrmmVlD66rnz7TaC6eyjHQV1Bd5EFU9Q2sMKFx7p6LTCsQfOnvdaig1BmL0eE39hMvk01YDmaPJBWmHvh6IqxqqJoPmfVd9Zrr3rzMVqTOUL2dO1UUbdOt+VHIWVEbBZMEf87ilzlKPZ5dvkcrBWslcUMC+Jol35FxfpKJuTo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606484715521623.6632968681045; Fri, 27 Nov 2020 05:45:15 -0800 (PST) Received: from localhost ([::1]:58406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kie3m-0006ep-7F for importer@patchew.org; Fri, 27 Nov 2020 08:45:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwx-0007rb-M0; Fri, 27 Nov 2020 08:38:11 -0500 Received: from relay.sw.ru ([185.231.240.75]:53020 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kidwv-0003iH-Aj; Fri, 27 Nov 2020 08:38:11 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kidwT-00AfjY-Av; Fri, 27 Nov 2020 16:37:41 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v3 5/5] monitor: increase amount of data for monitor to read Date: Fri, 27 Nov 2020 16:35:46 +0300 Message-Id: <1606484146-913540-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606484146-913540-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich From: Andrey Shinkevich via Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QMP and HMP monitors read one byte at a time from the socket or stdin, which is very inefficient. With 100+ VMs on the host, this results in multiple extra system calls and CPU overuse. This patch increases the amount of read data up to 4096 bytes that fits the buffer size on the channel level. Suggested-by: Denis V. Lunev Signed-off-by: Andrey Shinkevich --- monitor/monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 84222cd..43d2d3b 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -566,7 +566,7 @@ int monitor_can_read(void *opaque) { Monitor *mon =3D opaque; =20 - return !qatomic_mb_read(&mon->suspend_cnt); + return !qatomic_mb_read(&mon->suspend_cnt) ? CHR_READ_BUF_LEN : 0; } =20 void monitor_list_append(Monitor *mon) --=20 1.8.3.1