qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Thomas Huth <thuth@redhat.com>,
	Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Subject: Re: [Qemu-devel] QOM: Can devices having link properties be user-creatable?
Date: Fri, 12 Oct 2018 15:06:39 +0200	[thread overview]
Message-ID: <11e90911-c0f2-7710-2e7f-9dc856f9fe4b@redhat.com> (raw)
In-Reply-To: <CAFEAcA-TeU8SRPrZU_6=97yyL8UkMO_61P8oK4Xz2q0DweeBQA@mail.gmail.com>

On 12/10/2018 15:01, Peter Maydell wrote:
> On 12 October 2018 at 13:47, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>> While looking at Mao's series
>> (https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg02519.html) I
>> wondered if devices having link properties can be user-creatable.
>>
>> Using the following patch (I don't think this is correct to put qdev
>> code into qobject, but I used this as PoC):
>>
>> -- >8 --
>> diff --git a/qom/object.c b/qom/object.c
>> index 547dcf97c3..2dd3a25531 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -16,4 +16,5 @@
>>  #include "qom/object_interfaces.h"
>>  #include "qemu/cutils.h"
>> +#include "qemu/error-report.h"
>>  #include "qapi/visitor.h"
>>  #include "qapi/string-input-visitor.h"
>> @@ -1662,4 +1663,11 @@ void object_property_add_link(Object *obj, const
>> char *name,
>>      gchar *full_type;
>>      ObjectProperty *op;
>> +    ObjectClass *klass = object_get_class(obj);
>> +
>> +    if (klass && object_dynamic_cast(obj, TYPE_DEVICE) &&
>> +                 DEVICE_CLASS(klass)->user_creatable == false) {
>> +        warn_report("Device type '%s' is user_creatable "
>> +                    "(linked property: '%s')", type, name);
>> +    }
>>
>>      prop->child = child;
>> ---
>>
>> I get:
>>
>> $ aarch64-softmmu/qemu-system-aarch64 -M virt
>> qemu-system-aarch64: warning: Device type 'bus' is user_creatable
>> (linked property: 'parent_bus')
>> qemu-system-aarch64: warning: Device type 'qemu:memory-region' is
>> user_creatable (linked property: 'memory')
> 
> Is your warning printing the wrong thing? "bus", "irq",
> etc don't seem like names of devices...

Oh indeed I inverted (type, name) :)

> I think whether a device with a link property is
> user creatable might depend on what the property is
> for and whether the device has a useful fallback for
> "link not connected".

OK it now makes sens, reading this example:

    static void bcm2836_realize(DeviceState *dev, Error **errp)
    {
        Object *obj;
        Error *err = NULL;

        obj = object_property_get_link(OBJECT(dev), "ram", &err);
        if (obj == NULL) {
            error_setg(errp, "%s: required ram link not found: %s",
                       __func__, error_get_pretty(err));
            return;
        }
        ...

Thanks!

Phil.

  reply	other threads:[~2018-10-12 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-12 12:47 [Qemu-devel] QOM: Can devices having link properties be user-creatable? Philippe Mathieu-Daudé
2018-10-12 13:01 ` Peter Maydell
2018-10-12 13:06   ` Philippe Mathieu-Daudé [this message]
2018-10-12 13:14     ` Peter Maydell

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=11e90911-c0f2-7710-2e7f-9dc856f9fe4b@redhat.com \
    --to=philmd@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=maozhongyi@cmss.chinamobile.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 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).