All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] we allow passing -machine type=foo more than once but are confused about which to use...
Date: Wed, 08 Nov 2017 08:42:09 +0100	[thread overview]
Message-ID: <871sl9w71q.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <832ea538-6347-9b00-6a44-48159f94748f@redhat.com> (Thomas Huth's message of "Wed, 1 Nov 2017 07:22:16 +0100")

Thomas Huth <thuth@redhat.com> writes:

> On 31.10.2017 19:33, Peter Maydell wrote:
>> (cc Markus because I know how much he likes weirdnesses in our
>> command line parsing :-))

Heh!

Let me give you a guided tour to this corner of the CLI swamp :)

>> https://stackoverflow.com/questions/46955244/qemu-run-arm-ubuntu-unsupported-machine-type/47042282
>> has a user who's run into a confusing error message, because
>> we allow the user to pass "-machine type=foo" more than once on
>> the command line. When we decide which one to use, we go with the
>> last one on the list. However if it's not valid, when we print the
>> "don't recognize that machine type" message, the name we use in
>> the message is the *first* one on the list :-)

As so often, this is a case of a perfectly decent initial design messed
up by a number of enhancements that all made sense in isolation, but
fall apart together.

QemuOpts was designed to collect all parsed option arguments of a
certain kind in one instance of QemuOptsList.  For example, the
arguments of all -mon options get collected in the QemuOptsList named
"mon".  Each of the -mon arguments must have a distinct value of "id".
Absent "id" counts as a distinct value, i.e. "id" may be absent at most
once.  Each argument is represented as an instance of QemuOpts.

Yours truly enhanced QemuOpts to track locations in member @loc (commit
ab5b027ee6..0f0bc3f1d5).  This is what enables error_report() to report
the location, both on the command line and in configuration files:

    $ qemu-system-x86_64 -chardev bogus,id=chr1
    qemu-system-x86_64: -chardev bogus,id=chr1: 'bogus' is not a valid char driver name
    $ qemu-system-x86_64 -readconfig example.cfg
    qemu-system-x86_64:example.cfg:4: Invalid parameter 'type'
    qemu-system-x86_64: -readconfig example.cfg: read config example.cfg: Invalid argument

Sometimes, it's convienient to build up configuration in multiple
places.  Say your example.cfg configures a QMP monitor on stdio like
this:

    # qemu config file

    [chardev "stdio"]
      backend = "stdio"

    [mon "qmp-stdio"]
      chardev = "stdio"
      mode = "control"

To set pretty=on just for a quick test run, you could add a line to the
file, run the test, then delete it again.  Or you can modify the test
run's configuration with -set:

    $ qemu-system-x86_64 -readconfig example.cfg -set mon.qmp-stdio.pretty=on

This is certainly one of the lesser known QemuOpts features.  It's
asymmetric: the -set is quite different from the -mon it modifies.
Location reporting works fine for parse errors:

    $ qemu-system-x86_64 -nodefaults -S -readconfig example.cfg -set mon.qmp-stdio.pretty=of
    qemu-system-x86_64: -set mon.qmp-stdio.pretty=of: Parameter 'pretty' expects 'on' or 'off'

It breaks down for errors detected after the -set was applied to the
QemuOpts:

    $ qemu-system-x86_64 -nodefaults -S -netdev user,id=net1 -device e1000,id=nic1 -set device.nic1.netev=net1
    qemu-system-x86_64: -device e1000,id=nic1: Property '.netev' not found

A certain Peter Maydell (*grin*) enhanced QemuOpts to permit symmetric
modifications (commit da93318), but only for certain options, currently
-machine, -accel, -boot, -name, -memory, -icount, -smp.  Example:

    $ qemu-system-x86_64 -machine accel=kvm -machine type=q35

Without this feature, the second -machine would be rejected as
duplicate.  With the feature, it is merged into the first -machine, so
the two together become equivalent to:

    $ qemu-system-x86_64 -machine accel=kvm,type=q35

However, there's still only *one* location, since there's just one
QemuOpts!

    $ qemu-system-x86_64 --machine accel=kvm -machine type=q36
    qemu-system-x86_64: --machine accel=kvm: unsupported machine type
    Use -machine help to list supported machines

>> Maybe we should just not allow users to pass the argument
>> more than once...?

Insufficient.  We'd have to revert the options merging wholesale, and
ditch -set.

To really fix this, we'd have to move the location information from
QemuOpts to QemuOpt (the thing representing a key=value within a
QemuOpt).  Lots of client code would have to be updated, too.

> I think we at least need that in some of our qtests - to override the
> default "-M accel=qtest" with "-M accel=tcg". So if we disallow to use
> the option more than once, we've got to find a different solution for
> the qtests.

I'm afraid this feature is used not just by qtest.

Of course, given how much I expect to suffer for CLI backward
compatibility during my CLI QAPIfication work, I'd be *delighted* to
have a nice precedent for breaking it some ;)

      reply	other threads:[~2017-11-08  7:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31 18:33 [Qemu-devel] we allow passing -machine type=foo more than once but are confused about which to use Peter Maydell
2017-11-01  6:22 ` Thomas Huth
2017-11-08  7:42   ` Markus Armbruster [this message]

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=871sl9w71q.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@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.