All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Markus Armbruster <armbru@redhat.com>
Cc: Chris Wright <chrisw@redhat.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [Qemu-devel] KVM call minutes for Feb 8
Date: Wed, 09 Feb 2011 08:44:58 -0600	[thread overview]
Message-ID: <4D52A86A.1030407@codemonkey.ws> (raw)
In-Reply-To: <m3pqr1s86w.fsf@blackfin.pond.sub.org>

On 02/09/2011 06:28 AM, Markus Armbruster wrote:
>> Except that construction of a device requires initialization from an
>> array of variants (which is then type checked).  The way we store the
>> variants is lossy because we convert back and forth to a string.
>>      
> Yes, there's overlap, but no, a qdev property isn't yet another variant
> type scheme.  Exhibit A of the defense: qdev uses QemuOpts for variant
> types.
>
> Let me elaborate.  qdev_device_add() uses QemuOpts as map from name to
> variant type value, uses the name to look up the property, then uses
> property methods to stuff the variant value it got from QemuOpts into
> the (non-variant) struct member described by the property.
>
> I figure QemuOpts was adopted for this purpose because it was already in
> use with command line and human monitor.  With QMP added to the mix,
> there's friction: QMP uses QDict, not QemuOpts.
>    

I'm going to finish QMP before tackling qdev, but at a high level, 
here's how I think we fix this.

Right now, qdev only really supports construction properties.  In 
GObject parlance, this would be properties with G_PARAM_CONSTRUCT_ONLY.

Instead of the current approach of having the construction properties 
automagically set as part of the object prior to initfn() being invoked, 
we should have an init function that takes the full set of construction 
only properties in the native type.

With a schema description of the device's constructor, we can generate 
code that invokes the native constructor based on a QemuOpts, or based 
on a QDict.

So instead of:

static int serial_isa_initfn(ISADevice *dev);

static ISADeviceInfo serial_isa_info = {
     .init       = serial_isa_initfn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_UINT32("index", ISASerialState, index,   -1),
         DEFINE_PROP_HEX32("iobase", ISASerialState, iobase,  -1),
         DEFINE_PROP_UINT32("irq",   ISASerialState, isairq,  -1),
         DEFINE_PROP_CHR("chardev",  ISASerialState, state.chr),
         DEFINE_PROP_END_OF_LIST(),
     },
};

We'd have:

void isa_serial_init(ISASerialState *obj, uint32_t index, uint32_t 
iobase, uint32_t irq, CharDriverState *chardev, Error **errp);

// isa_serial.json
[ 'ISASerialState', {'index': 'uint32_t', 'iobase': 'uint32_t', 'irq': 
'uint32_t', 'chardev': 'CharDriverState *'} ]

 From this definition, we can generate code that handles the -device 
argument doing conversion from string to the appropriate types while 
also doing QObject/GVariant conversion to support the qmp_device_add() 
interface.

Also, having a well typed constructor means that we can do safer 
composition because instead of doing:

DeviceState *dev;

dev = qdev_create(NULL, "isa-serial");
qdev_prop_set_uint32(dev, "iobase", 0x274);
qdev_prop_set_uint32(dev, "irq", 0x07);
qdev_init_nofail(dev);

We can just do:

ISASerialState dev;

isa_serial_init(&dev, 0, 0x274, 0x07, NULL, NULL);

I think one of the reasons qdev has not been thoroughly embraced in much 
of QEMU is that the interface is obnoxious to work with in C.  By 
addressing that, I think it'll be much more successful.

Regards,

Anthony Liguori

  reply	other threads:[~2011-02-09 14:45 UTC|newest]

Thread overview: 118+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-08 15:55 KVM call minutes for Feb 8 Chris Wright
2011-02-08 15:55 ` [Qemu-devel] " Chris Wright
2011-02-08 16:14 ` Stefan Hajnoczi
2011-02-08 16:14   ` [Qemu-devel] " Stefan Hajnoczi
2011-02-08 16:39 ` [Qemu-devel] " Anthony Liguori
2011-02-08 16:39   ` Anthony Liguori
2011-02-08 17:13 ` Markus Armbruster
2011-02-08 17:13   ` Markus Armbruster
2011-02-08 19:02   ` Peter Maydell
2011-02-08 21:11     ` Anthony Liguori
2011-02-08 21:11       ` Anthony Liguori
2011-02-09  8:11     ` Markus Armbruster
2011-02-09  8:20       ` Peter Maydell
2011-02-09  9:02         ` Markus Armbruster
2011-02-08 19:30   ` Alexander Graf
2011-02-08 19:30   ` Aurelien Jarno
2011-02-09  8:23     ` Markus Armbruster
2011-02-09 10:43     ` Anthony Liguori
2011-02-09 10:43       ` Anthony Liguori
2011-02-09 17:38       ` Blue Swirl
2011-02-09 17:38         ` Blue Swirl
2011-02-08 21:12   ` Anthony Liguori
2011-02-09  8:01     ` Markus Armbruster
2011-02-09 10:31       ` Anthony Liguori
2011-02-09 12:28         ` Markus Armbruster
2011-02-09 14:44           ` Anthony Liguori [this message]
2011-02-09 17:48             ` Blue Swirl
2011-02-09 17:48               ` Blue Swirl
2011-02-09 19:53               ` Anthony Liguori
2011-02-09 19:59               ` Anthony Liguori
2011-02-09 20:15                 ` Blue Swirl
2011-02-10  7:47                   ` Anthony Liguori
2011-02-10  8:16                     ` Peter Maydell
2011-02-10  8:36                       ` Anthony Liguori
2011-02-10  9:04                         ` Peter Maydell
2011-02-10 10:13                           ` Anthony Liguori
2011-02-10 10:38                             ` Peter Maydell
2011-02-10 11:24                               ` Gleb Natapov
2011-02-10 11:24                                 ` Gleb Natapov
2011-02-10 12:23                               ` Anthony Liguori
2011-02-10 13:06                                 ` Peter Maydell
2011-02-10 19:17                       ` Scott Wood
2011-02-10 19:17                         ` Scott Wood
2011-02-10 19:22                         ` Peter Maydell
2011-02-10 19:22                           ` Peter Maydell
2011-02-10 19:29                           ` Scott Wood
2011-02-10 19:29                             ` Scott Wood
2011-02-10  9:07                     ` Gleb Natapov
2011-02-10 10:00                       ` Anthony Liguori
2011-02-10 10:10                         ` Gleb Natapov
2011-02-10 10:19                           ` Anthony Liguori
2011-02-10 10:49                             ` Gleb Natapov
2011-02-10 12:47                               ` Anthony Liguori
2011-02-10 13:12                                 ` Gleb Natapov
2011-02-10 10:25                       ` Avi Kivity
2011-02-10 10:25                         ` Avi Kivity
2011-02-10 11:13                         ` Gleb Natapov
2011-02-10 11:13                           ` Gleb Natapov
2011-02-10 12:51                           ` Anthony Liguori
2011-02-10 12:51                             ` Anthony Liguori
2011-02-10 13:00                             ` Avi Kivity
2011-02-10 13:00                               ` Avi Kivity
2011-02-10 13:29                               ` Gleb Natapov
2011-02-10 13:29                                 ` Gleb Natapov
2011-02-10 14:00                               ` Anthony Liguori
2011-02-10 14:00                                 ` Anthony Liguori
2011-02-10 13:27                             ` Gleb Natapov
2011-02-10 13:27                               ` Gleb Natapov
2011-02-10 14:04                               ` Anthony Liguori
2011-02-10 14:20                                 ` Gleb Natapov
2011-02-10 16:05                                   ` Anthony Liguori
2011-02-11 18:14                                     ` Blue Swirl
2011-02-11 18:14                                       ` Blue Swirl
2011-02-13  9:24                                       ` Gleb Natapov
2011-02-13  9:24                                         ` Gleb Natapov
2011-02-13 15:31                                       ` Anthony Liguori
2011-02-13 15:31                                         ` Anthony Liguori
2011-02-13 19:37                                         ` Blue Swirl
2011-02-13 19:37                                           ` Blue Swirl
2011-02-13 19:57                                           ` Anthony Liguori
2011-02-13 19:57                                             ` Anthony Liguori
2011-02-13 21:00                                             ` Blue Swirl
2011-02-13 21:00                                               ` Blue Swirl
2011-02-13 22:42                                               ` Anthony Liguori
2011-02-13 22:42                                                 ` Anthony Liguori
2011-02-14 17:31                                                 ` Blue Swirl
2011-02-14 17:31                                                   ` Blue Swirl
2011-02-14 20:53                                                   ` Anthony Liguori
2011-02-14 20:53                                                     ` Anthony Liguori
2011-02-14 21:25                                                     ` Blue Swirl
2011-02-14 21:25                                                       ` Blue Swirl
2011-02-14 21:47                                                       ` Anthony Liguori
2011-02-14 21:47                                                         ` Anthony Liguori
2011-02-15 17:11                                                         ` Blue Swirl
2011-02-15 17:11                                                           ` Blue Swirl
2011-02-15 23:07                                                           ` Anthony Liguori
2011-02-15 23:07                                                             ` Anthony Liguori
2011-02-16  9:52                                                             ` Gleb Natapov
2011-02-16  9:52                                                               ` Gleb Natapov
2011-02-14  9:44                                             ` Paolo Bonzini
2011-02-14  9:44                                               ` Paolo Bonzini
2011-02-10 10:29                     ` Avi Kivity
2011-02-13 15:38                       ` Anthony Liguori
2011-02-13 15:38                         ` Anthony Liguori
2011-02-13 15:56                         ` Avi Kivity
2011-02-13 16:56                           ` Anthony Liguori
2011-02-13 18:08                             ` Gleb Natapov
2011-02-13 18:08                               ` Gleb Natapov
2011-02-13 19:38                               ` Anthony Liguori
2011-02-14 10:23                                 ` Gleb Natapov
2011-02-13 21:24                             ` Peter Maydell
2011-02-13 21:24                               ` Peter Maydell
2011-02-13 22:43                               ` Anthony Liguori
2011-02-13 22:43                                 ` Anthony Liguori
2011-02-13 23:35                                 ` Peter Maydell
2011-02-13 15:39                       ` Anthony Liguori
2011-02-13 15:39                         ` Anthony Liguori
2011-02-11 17:54                     ` Blue Swirl

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=4D52A86A.1030407@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=chrisw@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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 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.