All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Eric Blake" <eblake@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@gmail.com>,
	qemu-devel@nongnu.org, "Beraldo Leal" <bleal@redhat.com>,
	"Stefan Weil" <sw@weilnetz.de>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	"Wainer dos Santos Moschetta" <wainersm@redhat.com>
Subject: Re: [PATCH v3 07/10] qapi: implement conditional command arguments
Date: Wed, 01 Mar 2023 14:16:27 +0100	[thread overview]
Message-ID: <875ybkwr10.fsf@pond.sub.org> (raw)
In-Reply-To: <Y/8Zy/Lk8i9RCOdc@redhat.com> ("Daniel P. Berrangé"'s message of "Wed, 1 Mar 2023 09:24:27 +0000")

Daniel P. Berrangé <berrange@redhat.com> writes:

> On Tue, Feb 28, 2023 at 09:58:01AM -0600, Eric Blake wrote:
>> On Wed, Feb 22, 2023 at 11:23:03AM +0100, Markus Armbruster wrote:
>> > > However, I think it would be simpler, and better, if we piped the
>> > > generated code to clang-format (when available). I made a simple patch
>> > > for that too.
>> > 
>> > Piping through indent or clang-format may well give us neater results
>> > for less effort.
>> > 
>> > We might want to dumb down generator code then.
>> 
>> Indeed, this approach seems like it might be worth pursuing (our
>> generator doesn't have to worry about spacing, because we do that in a
>> second pass with something that will still produce human-legible final
>> results).
>> 
>> > >> > So I would rather assert that we don't introduce such a schema, until we
>> > >> > fix the code generator. Or we acknowledge the limitation, and treat it as a
>> > >> > schema error. Other ideas?
>> > >>
>> > >> Yes: throw an error.  Assertions are for programming errors.  This isn't
>> > >> a programming error, it's a limitation of the current implementation.
>> > >>
>> > >> How hard would it be to lift the limitation?
>> > >
>> > > Taking this as a problematic example:
>> > >
>> > > void function(first,
>> > > #ifdef A
>> > >     a,
>> > > #endif
>> > > #ifdef B
>> > >     b
>> > > #endif
>> > > )
>> 
>> I am NOT a fan of preprocessor conditionals mid-function-signature.
>> It gets really nasty, really fast.  Is there any way we can have:
>> 
>> struct S {
>> #ifdef A
>>   type a;
>> #endif
>> #ifdef B
>>   type b;
>> #endif
>> };
>> 
>> void function(struct S)
>> 
>> so that the preprocessor conditionals never appear inside ()?

Yes, there is a way: we have conditional object type members, and we
have 'boxed': true for commands.

> I'd question whether we should be doing conditional arguments
> at all.

Note that conditional arguments already exist.  This patch merely makes
them work as advertized even without 'boxed': true.

If we decide they shouldn't exist, we need to make the generator reject
them.  But what *exactly* shouldn't exist?

In my view, a command takes *one* argument (of complex type) and returns
*one* result (of any type, but only because we had to grandfather
non-complex types).

For *struct* arguments, we support a special way to pass arguments:
unboxed.  Actually used for most commands.

Support for conditional members of complex types implies support for
conditional members of (complex) argument types.

We could restrict them to boxed.  Perhaps we should.

> IMHO having an API contract that changes based on configuration
> file settings is going to be nothing but trouble. Not only does
> it make the declaration ugly, but all callers become ugly too
> with conditionals. It will lead to bugs where a caller is written
> and tested with one build combination, and find it forgot the
> conditional calling needed for a different build combination.

Two separate points: ugly and test matrix.

"Ugly" is a valid point.  Ugly in two generated places (generated
declaration and handwritten definition) is kind of bad, ugly in all
places (plus all callers) is worse.

"Test matrix" applies to conditionals anywhere, not just command
arguments.  You could perhaps argue certain conditionals are more
problematic than others.

> Any fields that we conditionally disable must already be marked
> as optional in the schema, to indicate to mgmt apps that they
> may or may not be present depend on what QEMU build the app is
> talking to.

Not quite.

Neither the code nor docs/devel/qapi-code-gen.txt require conditional
members of complex types to be optional.  qapi-schema-test.json covers
conditional mandatory members:

    { 'struct': 'TestIfStruct',
      'data': { 'foo': 'int',
--->            'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} },
      'if': 'TEST_IF_STRUCT' }

"Optional" isn't for indicating "that a member may or may not be present
depend on what QEMU build" via introspection, it's for indicating the
member exists in *this* QEMU build, but it need not be present on the
wire, no more, no less.

We could perhaps derive "conditional member must be optional" from our
compatibility promise, but my cold-addled brain is not up to that task
right now.

> So if they're optional, what is wrong with generating the arguments
> unconditionally and just leaving them unused/unset in builds that
> don't require them ?  I think it'd be fine if the qmp_getfd API
> decl in QEMU had an 'const char *wsainfo' field even on Linux
> builds. The Linux impl can simply ignore it, or raise an error if
> it is set.

Raise an error.  Silently ignoring is no good.

Taking a step back...  both proposed solutions are kind of ugly.  Let me
recap:

1. QMP command getfd takes an additional argument when QEMU runs on a
   Windows host.

   a. The additional argument is mandatory.

   b. The additional argument in optional, but only nominally; if
      absent, the command fails.

2. QMP comamnd getfd takes an optional argument.  If it's present and
   QEMU runs on a POSIX host, the command fails.  Likewise when it's
   absent and QEMU runs on a Windows host.

What about 3. have an additional command conditional on CONFIG_WIN32?
Existing getfd stays the same: always fails when QEMU runs on a Windows
host.  The new command exists only when QEMU runs on a Windows host.



  reply	other threads:[~2023-03-01 13:17 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07 14:25 [PATCH v3 00/10] Teach 'getfd' QMP command to import win32 sockets marcandre.lureau
2023-02-07 14:25 ` [PATCH v3 01/10] tests: fix path separator, use g_build_filename() marcandre.lureau
2023-02-07 14:25 ` [PATCH v3 02/10] char: do not double-close fd when failing to add client marcandre.lureau
2023-02-07 14:43   ` Thomas Huth
2023-02-07 14:25 ` [PATCH v3 03/10] tests/docker: fix a win32 error due to portability marcandre.lureau
2023-02-27 12:11   ` Alex Bennée
2023-02-07 14:25 ` [PATCH v3 04/10] osdep: implement qemu_socketpair() for win32 marcandre.lureau
2023-02-07 14:25 ` [PATCH v3 05/10] qmp: 'add_client' actually expects sockets marcandre.lureau
2023-02-14 13:25   ` Markus Armbruster
2023-02-07 14:25 ` [PATCH v3 06/10] monitor: release the lock before calling close() marcandre.lureau
2023-02-07 14:52   ` Philippe Mathieu-Daudé
2023-02-14 13:33   ` Markus Armbruster
2023-02-14 13:36     ` Marc-André Lureau
2023-02-14 13:49       ` Daniel P. Berrangé
2023-02-14 16:23         ` Markus Armbruster
2023-02-14 16:55           ` Peter Xu
2023-02-28 18:51         ` Dr. David Alan Gilbert
2023-03-02  9:34   ` Alex Bennée
2023-03-06 15:29     ` Markus Armbruster
2023-03-06 15:35     ` Markus Armbruster
2023-02-07 14:25 ` [PATCH v3 07/10] qapi: implement conditional command arguments marcandre.lureau
2023-02-09 12:41   ` Markus Armbruster
2023-02-12 20:59     ` Marc-André Lureau
2023-02-17  8:28   ` Markus Armbruster
2023-02-18 10:45     ` Marc-André Lureau
2023-02-20  8:09       ` Markus Armbruster
2023-02-22  8:05         ` Marc-André Lureau
2023-02-22 10:23           ` Markus Armbruster
2023-02-22 10:29             ` Marc-André Lureau
2023-02-27 11:22               ` Marc-André Lureau
2023-02-28 15:58             ` Eric Blake
2023-03-01  9:24               ` Daniel P. Berrangé
2023-03-01 13:16                 ` Markus Armbruster [this message]
2023-03-01 13:21                   ` Marc-André Lureau
2023-03-02  6:58                     ` Markus Armbruster
2023-03-02  9:31                       ` Daniel P. Berrangé
2023-03-02 11:09                         ` Markus Armbruster
2023-03-02 13:30                           ` Markus Armbruster
2023-02-28 15:54   ` Eric Blake
2023-02-28 19:16     ` Marc-André Lureau
2023-02-07 14:25 ` [PATCH v3 08/10] qmp: teach 'getfd' to import sockets on win32 marcandre.lureau
2023-02-07 14:50   ` Philippe Mathieu-Daudé
2023-02-07 14:54   ` Daniel P. Berrangé
2023-02-08  7:28     ` Marc-André Lureau
2023-02-17  9:48   ` Markus Armbruster
2023-02-18 10:15     ` Marc-André Lureau
2023-02-20  8:26       ` Markus Armbruster
2023-02-20  9:30         ` Daniel P. Berrangé
2023-02-20  9:52         ` Marc-André Lureau
2023-02-20 10:50           ` Markus Armbruster
2023-02-07 14:25 ` [PATCH v3 09/10] libqtest: make qtest_qmp_add_client work " marcandre.lureau
2023-02-07 14:50   ` Philippe Mathieu-Daudé
2023-02-07 14:25 ` [PATCH v3 10/10] qtest: enable vnc-display test " marcandre.lureau
2023-02-07 14:37   ` Philippe Mathieu-Daudé

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=875ybkwr10.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=bleal@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    --cc=thuth@redhat.com \
    --cc=wainersm@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.