From nobody Tue May 7 19:18:49 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579091270; cv=none; d=zohomail.com; s=zohoarc; b=VItk4s0jcqASxtw5rSJn1wU/bIclE6ZajCNDGNHD3nEB5lt/0lk11JWVjk3H65mSDYyZWt2YYK1c0oP9bs9oQygYLLuWXqG8gJOBLapOZ+HBm47mWiyTpMrz+UYVlJsDZwNXe6Cc/zJy4kAc2x8dptGlBvGArmAApCWm823LByU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579091270; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J2w/2DcENdIkmLagRZbMKk1bIxNNVXR8HB8w42QZ+BQ=; b=Qn/BUb00LLR+sRfB1vPrm1pf/+gzaOsxoO84A+xFE6Mpy5qsJbJvREefxV5+O7spb5jwktD0uK2oBFyPEV9PJkdepYyF6SNeJxvF+G2PyS9AEa2wGvpBBo0yXsuXyYHvhb9VAG2cvdfnasQbGyrBRfwg5qWHFRurVMkzSRE7Cnw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1579091270274135.24806493299025; Wed, 15 Jan 2020 04:27:50 -0800 (PST) Received: from localhost ([::1]:53048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhm1-0002v2-4h for importer@patchew.org; Wed, 15 Jan 2020 07:27:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47601) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhi4-0006M0-QE for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irhi0-00020A-Uw for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:44 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:45712 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irhi0-0001zp-Qx for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-129-r8iydHEGNmaJJjhN2FtoVw-1; Wed, 15 Jan 2020 07:23:37 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16B7597545; Wed, 15 Jan 2020 12:23:36 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-87.ams2.redhat.com [10.36.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7571C5C1D6; Wed, 15 Jan 2020 12:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579091020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J2w/2DcENdIkmLagRZbMKk1bIxNNVXR8HB8w42QZ+BQ=; b=ScktaSw/TFmFNdUdekrQcmdzNLSjDndIYkO8hd93NOH8BvtKtSFXVGPzsBjn0oOP1sZB5t sC48bH1WvEE/A6v+71ub9HnGDfWRJunRF0C6CuGIbBWOL8PuQpDZt6Fa8Jna4La9YFYqJv ylH+ggKpO67DV6zOQnPv1+E34qV30D0= From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v3 1/4] qapi: Add a 'coroutine' flag for commands Date: Wed, 15 Jan 2020 13:23:23 +0100 Message-Id: <20200115122326.26393-2-kwolf@redhat.com> In-Reply-To: <20200115122326.26393-1-kwolf@redhat.com> References: <20200115122326.26393-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: r8iydHEGNmaJJjhN2FtoVw-1 X-Mimecast-Spam-Score: 0 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: 207.211.31.81 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: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch adds a new 'coroutine' flag to QMP command definitions that tells the QMP dispatcher that the command handler is safe to be run in a coroutine. Signed-off-by: Kevin Wolf Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/qapi-schema/qapi-schema-test.json | 1 + docs/devel/qapi-code-gen.txt | 4 ++++ include/qapi/qmp/dispatch.h | 1 + tests/test-qmp-cmds.c | 4 ++++ scripts/qapi/commands.py | 17 +++++++++++------ scripts/qapi/doc.py | 2 +- scripts/qapi/expr.py | 4 ++-- scripts/qapi/introspect.py | 2 +- scripts/qapi/schema.py | 9 ++++++--- tests/qapi-schema/qapi-schema-test.out | 2 ++ tests/qapi-schema/test-qapi.py | 7 ++++--- 11 files changed, 37 insertions(+), 16 deletions(-) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 9abf175fe0..1a850fe171 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -147,6 +147,7 @@ 'returns': 'UserDefTwo' } =20 { 'command': 'cmd-success-response', 'data': {}, 'success-response': false= } +{ 'command': 'coroutine-cmd', 'data': {}, 'coroutine': true } =20 # Returning a non-dictionary requires a name from the whitelist { 'command': 'guest-get-time', 'data': {'a': 'int', '*b': 'int' }, diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 45c93a43cc..753f6711d3 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -457,6 +457,7 @@ Syntax: '*gen': false, '*allow-oob': true, '*allow-preconfig': true, + '*coroutine': true, '*if': COND, '*features': FEATURES } =20 @@ -581,6 +582,9 @@ before the machine is built. It defaults to false. Fo= r example: QMP is available before the machine is built only when QEMU was started with --preconfig. =20 +Member 'coroutine' tells the QMP dispatcher whether the command handler +is safe to be run in a coroutine. It defaults to false. + The optional 'if' member specifies a conditional. See "Configuring the schema" below for more on this. =20 diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 9aa426a398..d6ce9efc8e 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -24,6 +24,7 @@ typedef enum QmpCommandOptions QCO_NO_SUCCESS_RESP =3D (1U << 0), QCO_ALLOW_OOB =3D (1U << 1), QCO_ALLOW_PRECONFIG =3D (1U << 2), + QCO_COROUTINE =3D (1U << 3), } QmpCommandOptions; =20 typedef struct QmpCommand diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index 27b0afe55a..e2f71e42a1 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -34,6 +34,10 @@ void qmp_cmd_success_response(Error **errp) { } =20 +void qmp_coroutine_cmd(Error **errp) +{ +} + Empty2 *qmp_user_def_cmd0(Error **errp) { return g_new0(Empty2, 1); diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index ab98e504f3..97e51401f1 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -15,6 +15,7 @@ See the COPYING file in the top-level directory. =20 from qapi.common import * from qapi.gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext +from typing import List =20 =20 def gen_command_decl(name, arg_type, boxed, ret_type): @@ -194,8 +195,9 @@ out: return ret =20 =20 -def gen_register_command(name, success_response, allow_oob, allow_preconfi= g): - options =3D [] +def gen_register_command(name: str, success_response: bool, allow_oob: boo= l, + allow_preconfig: bool, coroutine: bool) -> str: + options =3D [] # type: List[str] =20 if not success_response: options +=3D ['QCO_NO_SUCCESS_RESP'] @@ -203,18 +205,20 @@ def gen_register_command(name, success_response, allo= w_oob, allow_preconfig): options +=3D ['QCO_ALLOW_OOB'] if allow_preconfig: options +=3D ['QCO_ALLOW_PRECONFIG'] + if coroutine: + options +=3D ['QCO_COROUTINE'] =20 if not options: options =3D ['QCO_NO_OPTIONS'] =20 - options =3D " | ".join(options) + options_str =3D " | ".join(options) =20 ret =3D mcgen(''' qmp_register_command(cmds, "%(name)s", qmp_marshal_%(c_name)s, %(opts)s); ''', name=3Dname, c_name=3Dc_name(name), - opts=3Doptions) + opts=3Doptions_str) return ret =20 =20 @@ -278,7 +282,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, - features): + coroutine, features): if not gen: return # FIXME: If T is a user-defined type, the user is responsible @@ -296,7 +300,8 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); self._genh.add(gen_marshal_decl(name)) self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) self._regy.add(gen_register_command(name, success_response, - allow_oob, allow_preconfig= )) + allow_oob, allow_preconfig, + coroutine)) =20 =20 def gen_commands(schema, output_dir, prefix): diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 6f1c17f71f..8b6978c81e 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -265,7 +265,7 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor): =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, - features): + coroutine, features): doc =3D self.cur_doc self._gen.add(texi_msg('Command', doc, ifcond, texi_arguments(doc, diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index d7a289eded..9dbfa3edf0 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -89,7 +89,7 @@ def check_flags(expr, info): if key in expr and expr[key] is not False: raise QAPISemError( info, "flag '%s' may only use false value" % key) - for key in ['boxed', 'allow-oob', 'allow-preconfig']: + for key in ['boxed', 'allow-oob', 'allow-preconfig', 'coroutine']: if key in expr and expr[key] is not True: raise QAPISemError( info, "flag '%s' may only use true value" % key) @@ -344,7 +344,7 @@ def check_exprs(exprs): ['command'], ['data', 'returns', 'boxed', 'if', 'features', 'gen', 'success-response', 'allow-oob', - 'allow-preconfig']) + 'allow-preconfig', 'coroutine']) normalize_members(expr.get('data')) check_command(expr, info) elif meta =3D=3D 'event': diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b3a463dd8b..8a296a69d6 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -212,7 +212,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, - features): + coroutine, features): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type obj =3D {'arg-type': self._use_type(arg_type), diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index cf0045f34e..753bf233a6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -128,7 +128,7 @@ class QAPISchemaVisitor(object): =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, - features): + coroutine, features): pass =20 def visit_event(self, name, info, ifcond, arg_type, boxed): @@ -678,7 +678,7 @@ class QAPISchemaCommand(QAPISchemaEntity): =20 def __init__(self, name, info, doc, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, - features): + coroutine, features): QAPISchemaEntity.__init__(self, name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) @@ -691,6 +691,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.boxed =3D boxed self.allow_oob =3D allow_oob self.allow_preconfig =3D allow_preconfig + self.coroutine =3D coroutine =20 def check(self, schema): QAPISchemaEntity.check(self, schema) @@ -732,7 +733,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.arg_type, self.ret_type, self.gen, self.success_response, self.boxed, self.allow_oob, - self.allow_preconfig, + self.allow_preconfig, self.coroutine, self.features) =20 =20 @@ -1014,6 +1015,7 @@ class QAPISchema(object): boxed =3D expr.get('boxed', False) allow_oob =3D expr.get('allow-oob', False) allow_preconfig =3D expr.get('allow-preconfig', False) + coroutine =3D expr.get('coroutine', False) ifcond =3D expr.get('if') features =3D expr.get('features', []) if isinstance(data, OrderedDict): @@ -1025,6 +1027,7 @@ class QAPISchema(object): self._def_entity(QAPISchemaCommand(name, info, doc, ifcond, data, = rets, gen, success_response, boxed, allow_oob, allow_preconf= ig, + coroutine, self._make_features(features, i= nfo))) =20 def _def_event(self, expr, info, doc): diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 3660e75a48..51bfe8bfc7 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -217,6 +217,8 @@ command user_def_cmd2 q_obj_user_def_cmd2-arg -> UserDe= fTwo 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 preconfi= g=3DFalse +command coroutine-cmd None -> None + gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse coroutine=3DTrue object q_obj_guest-get-time-arg member a: int optional=3DFalse member b: int optional=3DTrue diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index bad14edb47..7a8e65188d 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -70,12 +70,13 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): =20 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, - features): + coroutine, features): print('command %s %s -> %s' % (name, arg_type and arg_type.name, ret_type and ret_type.name)) - print(' gen=3D%s success_response=3D%s boxed=3D%s oob=3D%s prec= onfig=3D%s' - % (gen, success_response, boxed, allow_oob, allow_preconfig)) + print(' gen=3D%s success_response=3D%s boxed=3D%s oob=3D%s prec= onfig=3D%s%s' + % (gen, success_response, boxed, allow_oob, allow_preconfig, + " coroutine=3DTrue" if coroutine else "")) self._print_if(ifcond) self._print_features(features) =20 --=20 2.20.1 From nobody Tue May 7 19:18:49 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579091167; cv=none; d=zohomail.com; s=zohoarc; b=dX13l4v0AG5Q0MJsUPjv/sQc3BPlihE794ntoblyA0r/VJF0NWrX59hdgnvClYbFVj1FlnPR3GX02AmoYfUNc2Rwyegu1BsYQAIvmh7maw8Np4Tt4htRyThbHy0kBrfF5rMdpUrK/iq5WCXkc7xsT1JfUiomvHQuZzrYaqcCjXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579091167; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2EAeYqTyCbwl3YPJB4hEw/0vE5BAWZVoxyjV4F867KA=; b=KWEoNgvf+MUll1mEUvT1Q8Evou5fbi8iNxD0ngWPK+dstvFJopEhPO8fmEAIXboJxaUl6Q4FEck4XqEUQgSHOVKFFnyc/+k4XrhnN8nnoVUYyV1vgxNoB2evNB++hoOV6dfYp5MEKTl0TiHFyZtkCNlQ6ChW3cHR6+uZZ/3BNnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1579091167801444.9068220653378; Wed, 15 Jan 2020 04:26:07 -0800 (PST) Received: from localhost ([::1]:53010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhkL-0008NW-TI for importer@patchew.org; Wed, 15 Jan 2020 07:26:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47605) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhi4-0006M3-Uc for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irhi0-0001zl-CC for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:44 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45640 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irhi0-0001zV-97 for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-392-dRnEF75vM5-o3Htu6-zNaw-1; Wed, 15 Jan 2020 07:23:38 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBDA218B5F77; Wed, 15 Jan 2020 12:23:37 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-87.ams2.redhat.com [10.36.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DB855C1D6; Wed, 15 Jan 2020 12:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579091019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2EAeYqTyCbwl3YPJB4hEw/0vE5BAWZVoxyjV4F867KA=; b=MhsOGmm8ckwsUvushA2LIZxHPu+VRXNax2C8w+fNiI6UjRcrRoCOGlGWv8H3kRRe0TN3qo smkuP2ZPyjK+xuom1FLUk9Og7Uqcl8kXCQ4QCKIee7JZ2mo8uupwf75JoJDgcxHsNOx5OM mDeyIgaH5o3XgjpQ3czP02yuWIvdSRE= From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v3 2/4] vl: Initialise main loop earlier Date: Wed, 15 Jan 2020 13:23:24 +0100 Message-Id: <20200115122326.26393-3-kwolf@redhat.com> In-Reply-To: <20200115122326.26393-1-kwolf@redhat.com> References: <20200115122326.26393-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: dRnEF75vM5-o3Htu6-zNaw-1 X-Mimecast-Spam-Score: 0 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: 205.139.110.120 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: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We want to be able to use qemu_aio_context in the monitor initialisation. Signed-off-by: Kevin Wolf Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- vl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vl.c b/vl.c index 86474a55c9..4c79a00857 100644 --- a/vl.c +++ b/vl.c @@ -2903,6 +2903,11 @@ int main(int argc, char **argv, char **envp) runstate_init(); precopy_infrastructure_init(); postcopy_infrastructure_init(); + + if (qemu_init_main_loop(&main_loop_err)) { + error_report_err(main_loop_err); + exit(1); + } monitor_init_globals(); =20 if (qcrypto_init(&err) < 0) { @@ -3817,11 +3822,6 @@ int main(int argc, char **argv, char **envp) qemu_unlink_pidfile_notifier.notify =3D qemu_unlink_pidfile; qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); =20 - if (qemu_init_main_loop(&main_loop_err)) { - error_report_err(main_loop_err); - exit(1); - } - #ifdef CONFIG_SECCOMP olist =3D qemu_find_opts_err("sandbox", NULL); if (olist) { --=20 2.20.1 From nobody Tue May 7 19:18:49 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579091171; cv=none; d=zohomail.com; s=zohoarc; b=nStLK7uaTYebHcufBM6IOvIkQgp+1JACHESRO+4RtbfNJvuaoZSV1403EBACHIMUdgpUE0vZuXAwsGcIIt9g2fWY/JX+1J9TE5xXj5G6xH4R7u0TRIpvuk7Gi8HbFvJGP1PifLh2bJft6dVOPctyFLfSqmoqRcxTYHQ/olNAZls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579091171; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nz5pOO94nMMGG/ZH6khEI6BHAY16avpQMT6EWEdfXMc=; b=EjaJ7GR11+DXKHq0ENfQ+oUwLCabjI5agyWTA53VIOylEv4maVobZsOnA858Bbg6frhAwqeeRZtrmhDn0eYDlm6lQ8jcB7oy8Y/HDLZ2keti8/tOT3VgcmunQ6/GzOTgMSOsn2RoRqwWONSyoieIJ+PNKu/zrPN+U38/nx4OErE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1579091171342735.2517789521761; Wed, 15 Jan 2020 04:26:11 -0800 (PST) Received: from localhost ([::1]:53014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhkP-0008V2-O1 for importer@patchew.org; Wed, 15 Jan 2020 07:26:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47636) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhi8-0006PP-5D for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irhi4-00022I-73 for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:48 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:44751 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irhi4-00021q-2T for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:44 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-58-4qS4o6SRPJ2KTSHe0qRD3A-1; Wed, 15 Jan 2020 07:23:40 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EDEC18B5F77; Wed, 15 Jan 2020 12:23:39 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-87.ams2.redhat.com [10.36.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E5845C1D6; Wed, 15 Jan 2020 12:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579091023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nz5pOO94nMMGG/ZH6khEI6BHAY16avpQMT6EWEdfXMc=; b=gbu8I5cMps4YjUlDAlvkCVRR42aniffJvjzOWZdx+24SplVeX9OfStpXQ9AwFdQEghh3mF ZLQQcgSu6+p6T4lYrsKDgLzEkq/q6zaKk2Brgtiv2lXWp93bFh0MfyxA6Un5eHuC21KTv8 i6V9vHK7K/aXTuhusXFLz3ySf43FATc= From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v3 3/4] qmp: Move dispatcher to a coroutine Date: Wed, 15 Jan 2020 13:23:25 +0100 Message-Id: <20200115122326.26393-4-kwolf@redhat.com> In-Reply-To: <20200115122326.26393-1-kwolf@redhat.com> References: <20200115122326.26393-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 4qS4o6SRPJ2KTSHe0qRD3A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: 205.139.110.61 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: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This moves the QMP dispatcher to a coroutine and runs all QMP command handlers that declare 'coroutine': true in coroutine context so they can avoid blocking the main loop while doing I/O or waiting for other events. For commands that are not declared safe to run in a coroutine, the dispatcher drops out of coroutine context by calling the QMP command handler from a bottom half. Signed-off-by: Kevin Wolf Reviewed-by: Marc-Andr=C3=A9 Lureau --- include/qapi/qmp/dispatch.h | 2 + monitor/monitor-internal.h | 5 ++- monitor/monitor.c | 24 +++++++---- monitor/qmp.c | 83 +++++++++++++++++++++++-------------- qapi/qmp-dispatch.c | 38 ++++++++++++++++- 5 files changed, 111 insertions(+), 41 deletions(-) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index d6ce9efc8e..d6d5443391 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -30,6 +30,8 @@ typedef enum QmpCommandOptions typedef struct QmpCommand { const char *name; + /* Runs in coroutine context if QCO_COROUTINE is set, except for OOB + * commands */ QmpCommandFunc *fn; QmpCommandOptions options; QTAILQ_ENTRY(QmpCommand) node; diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index d78f5ca190..7389b6a56c 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -154,7 +154,8 @@ static inline bool monitor_is_qmp(const Monitor *mon) =20 typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList; extern IOThread *mon_iothread; -extern QEMUBH *qmp_dispatcher_bh; +extern Coroutine *qmp_dispatcher_co; +extern bool qmp_dispatcher_co_busy; extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands; extern QemuMutex monitor_lock; extern MonitorList mon_list; @@ -172,7 +173,7 @@ void monitor_fdsets_cleanup(void); =20 void qmp_send_response(MonitorQMP *mon, const QDict *rsp); void monitor_data_destroy_qmp(MonitorQMP *mon); -void monitor_qmp_bh_dispatcher(void *data); +void coroutine_fn monitor_qmp_dispatcher_co(void *data); =20 int get_monitor_def(int64_t *pval, const char *name); void help_cmd(Monitor *mon, const char *name); diff --git a/monitor/monitor.c b/monitor/monitor.c index 12898b6448..c72763fa4e 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -53,8 +53,9 @@ typedef struct { /* Shared monitor I/O thread */ IOThread *mon_iothread; =20 -/* Bottom half to dispatch the requests received from I/O thread */ -QEMUBH *qmp_dispatcher_bh; +/* Coroutine to dispatch the requests received from I/O thread */ +Coroutine *qmp_dispatcher_co; +bool qmp_dispatcher_co_busy; =20 /* Protects mon_list, monitor_qapi_event_state, monitor_destroyed. */ QemuMutex monitor_lock; @@ -579,9 +580,16 @@ void monitor_cleanup(void) } qemu_mutex_unlock(&monitor_lock); =20 - /* QEMUBHs needs to be deleted before destroying the I/O thread */ - qemu_bh_delete(qmp_dispatcher_bh); - qmp_dispatcher_bh =3D NULL; + /* The dispatcher needs to stop before destroying the I/O thread */ + if (!atomic_mb_read(&qmp_dispatcher_co_busy)) { + aio_co_schedule(iohandler_get_aio_context(), qmp_dispatcher_co); + qmp_dispatcher_co =3D NULL; + } + + AIO_WAIT_WHILE(qemu_get_aio_context(), + (aio_bh_poll(iohandler_get_aio_context()), + atomic_mb_read(&qmp_dispatcher_co_busy))); + if (mon_iothread) { iothread_destroy(mon_iothread); mon_iothread =3D NULL; @@ -604,9 +612,9 @@ void monitor_init_globals_core(void) * have commands assuming that context. It would be nice to get * rid of those assumptions. */ - qmp_dispatcher_bh =3D aio_bh_new(iohandler_get_aio_context(), - monitor_qmp_bh_dispatcher, - NULL); + qmp_dispatcher_co =3D qemu_coroutine_create(monitor_qmp_dispatcher_co,= NULL); + atomic_mb_set(&qmp_dispatcher_co_busy, true); + aio_co_schedule(iohandler_get_aio_context(), qmp_dispatcher_co); } =20 QemuOptsList qemu_mon_opts =3D { diff --git a/monitor/qmp.c b/monitor/qmp.c index b67a8e7d1f..f29a8fe497 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -133,6 +133,8 @@ static void monitor_qmp_respond(MonitorQMP *mon, QDict = *rsp) } } =20 +/* Runs outside of coroutine context for OOB commands, but in coroutine co= ntext + * for everything else. */ static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req) { Monitor *old_mon; @@ -211,43 +213,62 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_= lock(void) return req_obj; } =20 -void monitor_qmp_bh_dispatcher(void *data) +void coroutine_fn monitor_qmp_dispatcher_co(void *data) { - QMPRequest *req_obj =3D monitor_qmp_requests_pop_any_with_lock(); + QMPRequest *req_obj =3D NULL; QDict *rsp; bool need_resume; MonitorQMP *mon; =20 - if (!req_obj) { - return; - } + while (true) { + assert(atomic_mb_read(&qmp_dispatcher_co_busy) =3D=3D true); + + while (!(req_obj =3D monitor_qmp_requests_pop_any_with_lock())) { + /* Wait to be reentered from handle_qmp_command, or terminate = if + * qmp_dispatcher_co has been reset to NULL */ + atomic_mb_set(&qmp_dispatcher_co_busy, false); + if (qmp_dispatcher_co) { + qemu_coroutine_yield(); + } + /* qmp_dispatcher_co may have changed if we yielded and were + * reentered from monitor_cleanup() */ + if (!qmp_dispatcher_co) { + return; + } + assert(atomic_mb_read(&qmp_dispatcher_co_busy) =3D=3D true); + } =20 - mon =3D req_obj->mon; - /* qmp_oob_enabled() might change after "qmp_capabilities" */ - need_resume =3D !qmp_oob_enabled(mon) || - mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1; - qemu_mutex_unlock(&mon->qmp_queue_lock); - if (req_obj->req) { - 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(mon, req_obj->req); - } else { - assert(req_obj->err); - rsp =3D qmp_error_response(req_obj->err); - req_obj->err =3D NULL; - monitor_qmp_respond(mon, rsp); - qobject_unref(rsp); - } + aio_co_schedule(qemu_get_aio_context(), qmp_dispatcher_co); + qemu_coroutine_yield(); + + mon =3D req_obj->mon; + /* qmp_oob_enabled() might change after "qmp_capabilities" */ + need_resume =3D !qmp_oob_enabled(mon) || + mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1; + qemu_mutex_unlock(&mon->qmp_queue_lock); + if (req_obj->req) { + 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(mon, req_obj->req); + } else { + assert(req_obj->err); + rsp =3D qmp_error_response(req_obj->err); + req_obj->err =3D NULL; + monitor_qmp_respond(mon, rsp); + qobject_unref(rsp); + } =20 - if (need_resume) { - /* Pairs with the monitor_suspend() in handle_qmp_command() */ - monitor_resume(&mon->common); - } - qmp_request_free(req_obj); + if (need_resume) { + /* Pairs with the monitor_suspend() in handle_qmp_command() */ + monitor_resume(&mon->common); + } + qmp_request_free(req_obj); =20 - /* Reschedule instead of looping so the main loop stays responsive */ - qemu_bh_schedule(qmp_dispatcher_bh); + /* Reschedule instead of looping so the main loop stays responsive= */ + aio_co_schedule(iohandler_get_aio_context(), qmp_dispatcher_co); + qemu_coroutine_yield(); + } } =20 static void handle_qmp_command(void *opaque, QObject *req, Error *err) @@ -308,7 +329,9 @@ static void handle_qmp_command(void *opaque, QObject *r= eq, Error *err) qemu_mutex_unlock(&mon->qmp_queue_lock); =20 /* Kick the dispatcher routine */ - qemu_bh_schedule(qmp_dispatcher_bh); + if (!atomic_xchg(&qmp_dispatcher_co_busy, true)) { + aio_co_wake(qmp_dispatcher_co); + } } =20 static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index bc264b3c9b..6ccf19f2a2 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -12,6 +12,8 @@ */ =20 #include "qemu/osdep.h" + +#include "monitor/monitor-internal.h" #include "qapi/error.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" @@ -75,6 +77,23 @@ static QDict *qmp_dispatch_check_obj(const QObject *requ= est, bool allow_oob, return dict; } =20 +typedef struct QmpDispatchBH { + QmpCommand *cmd; + QDict *args; + QObject **ret; + Error **errp; + Coroutine *co; +} QmpDispatchBH; + +static void do_qmp_dispatch_bh(void *opaque) +{ + QmpDispatchBH *data =3D opaque; + data->cmd->fn(data->args, data->ret, data->errp); + aio_co_wake(data->co); +} + +/* Runs outside of coroutine context for OOB commands, but in coroutine co= ntext + * for everything else. */ static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request, bool allow_oob, Error **errp) { @@ -129,7 +148,22 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, = QObject *request, qobject_ref(args); } =20 - cmd->fn(args, &ret, &local_err); + assert(!(oob && qemu_in_coroutine())); + if ((cmd->options & QCO_COROUTINE) || !qemu_in_coroutine()) { + cmd->fn(args, &ret, &local_err); + } else { + /* Must drop out of coroutine context for this one */ + QmpDispatchBH data =3D { + .cmd =3D cmd, + .args =3D args, + .ret =3D &ret, + .errp =3D &local_err, + .co =3D qemu_coroutine_self(), + }; + aio_bh_schedule_oneshot(qemu_get_aio_context(), do_qmp_dispatch_bh, + &data); + qemu_coroutine_yield(); + } if (local_err) { error_propagate(errp, local_err); } else if (cmd->options & QCO_NO_SUCCESS_RESP) { @@ -164,6 +198,8 @@ bool qmp_is_oob(const QDict *dict) && !qdict_haskey(dict, "execute"); } =20 +/* Runs outside of coroutine context for OOB commands, but in coroutine co= ntext + * for everything else. */ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, bool allow_oob) { --=20 2.20.1 From nobody Tue May 7 19:18:49 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579091335; cv=none; d=zohomail.com; s=zohoarc; b=iDqTg2N+UNvSFojEscFbUZufHHl9SExbGwLLZinVpUT2dm05fkRXxT2XClnrnKIohTvkvEeRWRX35NkPi70tk3H/MwCIk9I+RLMejyIzqGjUc7bbFuXNF06yYrvBxo6xS8EdXAe6UDj50CCz/sDaiZNbBFCBgg87oWtzoZD7ZA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579091335; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=svotTECI5zrSZmuvFDCvoQ7OyS3LuOvNA4K0YneyOdQ=; b=ct/tBrL6CtdCK2zC7yih5lNJaDznswW+56pIm2WJ2MHqvWMwI+l1Z42dw0jm39i4dDa/ShXUoHn7nU3IA/dXs0/Xaju6+HSGi/jrPd38bIsJCom7aawbywxtaEpdpFaWB7nWjwFOAED2Xe/nlxS57PzIznZUUFV/qeA58Tkx7NM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1579091335905797.181912325573; Wed, 15 Jan 2020 04:28:55 -0800 (PST) Received: from localhost ([::1]:53070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhn4-0004Cz-SH for importer@patchew.org; Wed, 15 Jan 2020 07:28:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47656) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irhiA-0006Tt-9i for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irhi6-00023w-Aj for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:50 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:50188 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irhi6-00023V-7Z for qemu-devel@nongnu.org; Wed, 15 Jan 2020 07:23:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-362-cdah8LoOP_CRyYK_ZhKPsA-1; Wed, 15 Jan 2020 07:23:42 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5839E106BF9C; Wed, 15 Jan 2020 12:23:41 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-87.ams2.redhat.com [10.36.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAF655C1D6; Wed, 15 Jan 2020 12:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579091025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=svotTECI5zrSZmuvFDCvoQ7OyS3LuOvNA4K0YneyOdQ=; b=NmKOm+9BA/4yXqd/GpjpJiJNjEmMI8r2ROlcWkCVq8IjhKyGKwgFc//eoZbtQgMoO8qMM8 Ai+L92mYemPLRnOpsIOV8Tw/rEyp6c4U49uJ4vlXsWIxhhPv2QauadL3YNFdbe4KTlAR/n I1/4OrWrl0UFF77vjSrPhL19+88enlI= From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v3 4/4] block: Mark 'block_resize' as coroutine Date: Wed, 15 Jan 2020 13:23:26 +0100 Message-Id: <20200115122326.26393-5-kwolf@redhat.com> In-Reply-To: <20200115122326.26393-1-kwolf@redhat.com> References: <20200115122326.26393-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: cdah8LoOP_CRyYK_ZhKPsA-1 X-Mimecast-Spam-Score: 0 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: 205.139.110.120 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: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, marcandre.lureau@gmail.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" block_resize is safe to run in a coroutine, so use it as an example for the new 'coroutine': true annotation in the QAPI schema. Signed-off-by: Kevin Wolf Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qapi/block-core.json | 3 ++- blockdev.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 7ff5e5edaf..1dbb2a9901 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1341,7 +1341,8 @@ { 'command': 'block_resize', 'data': { '*device': 'str', '*node-name': 'str', - 'size': 'int' } } + 'size': 'int' }, + 'coroutine': true } =20 ## # @NewImageMode: diff --git a/blockdev.c b/blockdev.c index 8e029e9c01..b5e5d1e072 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3161,9 +3161,9 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) aio_context_release(aio_context); } =20 -void qmp_block_resize(bool has_device, const char *device, - bool has_node_name, const char *node_name, - int64_t size, Error **errp) +void coroutine_fn qmp_block_resize(bool has_device, const char *device, + bool has_node_name, const char *node_na= me, + int64_t size, Error **errp) { Error *local_err =3D NULL; BlockBackend *blk =3D NULL; --=20 2.20.1