From: Kevin Wolf <kwolf@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: pbonzini@redhat.com, berrange@redhat.com, qemu-devel@nongnu.org,
eblake@redhat.com, ehabkost@redhat.com
Subject: Re: [RFC PATCH 07/12] qapi: Allow defining QOM classes
Date: Fri, 10 Dec 2021 18:53:47 +0100 [thread overview]
Message-ID: <YbOUKw1GhRn5mVuT@redhat.com> (raw)
In-Reply-To: <871r379oku.fsf@dusky.pond.sub.org>
Am 23.11.2021 um 11:02 hat Markus Armbruster geschrieben:
> Kevin Wolf <kwolf@redhat.com> writes:
>
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > ---
> > scripts/qapi/expr.py | 28 +++++++++++++++++-
> > scripts/qapi/schema.py | 66 ++++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 93 insertions(+), 1 deletion(-)
>
> Missing: docs/devel/qapi-code-gen.rst update. I understand why, but it
> does make review harder.
>
> >
> > diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
> > index 3cb389e875..77550629f3 100644
> > --- a/scripts/qapi/expr.py
> > +++ b/scripts/qapi/expr.py
> > @@ -181,6 +181,8 @@ def check_defn_name_str(name: str, info: QAPISourceInfo, meta: str) -> None:
> > """
> > if meta == 'event':
> > check_name_upper(name, info, meta)
> > + elif meta == 'class':
> > + check_name_str(name, info, meta)
>
> This permits arbitrary QAPI names. I figure we'll want to define and
> enforce a suitable naming convention.
It's the QOM type name. So if you want to enforce something stricter, it
needs to be defined for QOM first. I seem to remember that arbitrary
QAPI names is already stricter than arbitrary QOM names, but I was
hoping that it is close enough to what QOM classes actually use in
practice. I fully expect to have a list of exceptions at some point when
converting devices.
> > elif meta == 'command':
> > check_name_lower(
> > name, info, meta,
> > @@ -557,6 +559,24 @@ def check_alternate(expr: _JSONObject, info: QAPISourceInfo) -> None:
> > check_type(value['type'], info, source)
> >
> >
> > +def check_class(expr: _JSONObject, info: QAPISourceInfo) -> None:
> > + """
> > + Normalize and validate this expression as a ``class`` definition.
> > +
> > + :param expr: The expression to validate.
> > + :param info: QAPI schema source file information.
> > +
> > + :raise QAPISemError: When ``expr`` is not a valid ``class``.
> > + :return: None, ``expr`` is normalized in-place as needed.
> > + """
> > + config = expr.get('config')
> > + config_boxed = expr.get('config-boxed', False)
> > +
> > + if config_boxed and config is None:
> > + raise QAPISemError(info, "'boxed': true requires 'config'")
>
> You check 'config-boxed', but the error message talks about 'boxed'.
>
> > + check_type(config, info, "'config'", allow_dict=not config_boxed)
> > +
> > +
> > def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None:
> > """
> > Normalize and validate this expression as a ``command`` definition.
> > @@ -627,7 +647,7 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]:
> > continue
> >
> > metas = expr.keys() & {'enum', 'struct', 'union', 'alternate',
> > - 'command', 'event'}
> > + 'class', 'command', 'event'}
> > if len(metas) != 1:
> > raise QAPISemError(
> > info,
> > @@ -671,6 +691,12 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]:
> > ['struct', 'data'], ['base', 'if', 'features'])
> > normalize_members(expr['data'])
> > check_struct(expr, info)
> > + elif meta == 'class':
> > + check_keys(expr, info, meta,
> > + ['class'], ['if', 'features', 'parent', 'config',
> > + 'config-boxed'])
> > + normalize_members(expr.get('config'))
> > + check_class(expr, info)
> > elif meta == 'command':
> > check_keys(expr, info, meta,
> > ['command'],
> > diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
> > index b7b3fc0ce4..ebf69341d7 100644
> > --- a/scripts/qapi/schema.py
> > +++ b/scripts/qapi/schema.py
> > @@ -155,6 +155,9 @@ def visit_object_type_flat(self, name, info, ifcond, features,
> > def visit_alternate_type(self, name, info, ifcond, features, variants):
> > pass
> >
> > + def visit_class(self, entity):
> > + pass
> > +
> > def visit_command(self, name, info, ifcond, features,
> > arg_type, ret_type, gen, success_response, boxed,
> > allow_oob, allow_preconfig, coroutine):
> > @@ -766,6 +769,50 @@ def __init__(self, name, info, typ, ifcond=None):
> > super().__init__(name, info, typ, False, ifcond)
> >
> >
> > +class QAPISchemaClass(QAPISchemaEntity):
> > + meta = 'class'
> > +
> > + def __init__(self, name, info, doc, ifcond, features, parent,
> > + config_type, config_boxed):
> > + super().__init__(name, info, doc, ifcond, features)
> > +
> > + assert not parent or isinstance(parent, str)
>
> I can't see what ensures this.
Indeed, check_class() fails to check this. You agree that it is the
place where it should be checked?
> > + assert not config_type or isinstance(config_type, str)
> > + self._parent_name = parent
> > + self.parent = None
> > + self._config_type_name = config_type
> > + self.config_type = None
> > + self.config_boxed = config_boxed
> > +
> > + def check(self, schema):
> > + super().check(schema)
> > +
> > + if self._parent_name:
> > + self.parent = schema.lookup_entity(self._parent_name,
> > + QAPISchemaClass)
> > + if not self.parent:
> > + raise QAPISemError(
> > + self.info,
> > + "Unknown parent class '%s'" % self._parent_name)
> > +
> > + if self._config_type_name:
> > + self.config_type = schema.resolve_type(
> > + self._config_type_name, self.info, "class 'config'")
>
> "class's 'config'" for consistency with other uses of .resolve_type().
>
> > + if not isinstance(self.config_type, QAPISchemaObjectType):
> > + raise QAPISemError(
> > + self.info,
> > + "class 'config' cannot take %s"
> > + % self.config_type.describe())
> > + if self.config_type.variants and not self.boxed:
>
> self.config_boxed?
>
> > + raise QAPISemError(
> > + self.info,
> > + "class 'config' can take %s only with 'boxed': true"
>
> 'config-boxed'?
Yes, I renamed it and of course forgot some instances. Can't wait for
the patches that would make mypy catch at least 'self.boxed'.
> > + % self.config_type.describe())
> > +
> > + def visit(self, visitor):
> > + super().visit(visitor)
> > + visitor.visit_class(self)
> > +
> > class QAPISchemaCommand(QAPISchemaEntity):
> > meta = 'command'
> >
> > @@ -1110,6 +1157,23 @@ def _def_alternate_type(self, expr, info, doc):
> > QAPISchemaVariants(
> > None, info, tag_member, variants)))
> >
> > + def _def_class(self, expr, info, doc):
> > + name = expr['class']
> > + ifcond = QAPISchemaIfCond(expr.get('if'))
> > + features = self._make_features(expr.get('features'), info)
> > + parent = expr.get('parent')
> > + config_type = expr.get('config')
> > + config_boxed = expr.get('config-boxed')
> > +
> > + if isinstance(config_type, OrderedDict):
> > + config_type = self._make_implicit_object_type(
> > + name, info, ifcond,
> > + 'config', self._make_members(config_type, info))
>
> Does QAPISchemaMember.describe() need an update for this?
Looks like it.
Kevin
next prev parent reply other threads:[~2021-12-10 17:55 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-03 17:29 [RFC PATCH 00/12] QOM/QAPI integration part 1 Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 01/12] qapi: Add visit_next_struct_member() Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 02/12] qom: Create object_configure() Kevin Wolf
2021-11-23 15:23 ` Markus Armbruster
2021-12-14 9:52 ` Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 03/12] qom: Make object_configure() public Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 04/12] qom: Add instance_config() to TypeInfo Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 05/12] rng-random: Implement .instance_config Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 06/12] rng-backend: " Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 07/12] qapi: Allow defining QOM classes Kevin Wolf
2021-11-23 10:02 ` Markus Armbruster
2021-12-10 17:53 ` Kevin Wolf [this message]
2021-11-03 17:29 ` [RFC PATCH 08/12] qapi: Create qom-config:... type for classes Kevin Wolf
2021-11-23 13:00 ` Markus Armbruster
2021-12-10 17:41 ` Kevin Wolf
2021-11-03 17:29 ` [RFC PATCH 09/12] qapi/qom: Convert rng-backend/random to class Kevin Wolf
2021-11-23 13:15 ` Markus Armbruster
2021-12-10 17:57 ` Kevin Wolf
2021-11-03 17:30 ` [RFC PATCH 10/12] qapi: Generate QOM config marshalling code Kevin Wolf
2021-11-23 14:16 ` Markus Armbruster
2021-12-10 16:50 ` Kevin Wolf
2021-11-03 17:30 ` [RFC PATCH 11/12] qapi/qom: Add class definition for rng-builtin Kevin Wolf
2021-11-03 17:30 ` [RFC PATCH 12/12] qapi/qom: Add class definition for rng-egd Kevin Wolf
2021-11-03 21:26 ` [RFC PATCH 00/12] QOM/QAPI integration part 1 Paolo Bonzini
2021-11-04 9:07 ` Kevin Wolf
2021-11-04 12:39 ` Paolo Bonzini
2021-11-04 14:26 ` Kevin Wolf
2021-11-04 14:49 ` Paolo Bonzini
2021-11-04 15:51 ` Kevin Wolf
2021-11-04 15:52 ` Damien Hedde
2021-11-05 13:55 ` Kevin Wolf
2021-11-23 16:05 ` Markus Armbruster
2021-12-14 10:23 ` Kevin Wolf
2021-12-14 10:40 ` Peter Maydell
2021-12-14 11:52 ` Kevin Wolf
2021-12-14 14:45 ` Markus Armbruster
2021-12-14 16:00 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YbOUKw1GhRn5mVuT@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).