qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>
Subject: Re: [Socratic RFC PATCH] include: attempt to document device_class_set_props
Date: Mon, 27 Mar 2023 23:09:36 +0100	[thread overview]
Message-ID: <87edp9sv5p.fsf@linaro.org> (raw)
In-Reply-To: <28e374e3-5aa4-b5e3-0d8f-f885ca1142ca@ilande.co.uk>


Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:

> On 27/03/2023 17:12, Alex Bennée wrote:
>
>> Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:
>> 
>>> On 27/03/2023 14:15, Alex Bennée wrote:
>>>
>>>> I'm still not sure how I achieve by use case of the parent class
>>>> defining the following properties:
>>>>     static Property vud_properties[] = {
>>>>         DEFINE_PROP_CHR("chardev", VHostUserDevice, chardev),
>>>>         DEFINE_PROP_UINT16("id", VHostUserDevice, id, 0),
>>>>         DEFINE_PROP_UINT32("num_vqs", VHostUserDevice, num_vqs, 1),
>>>>         DEFINE_PROP_END_OF_LIST(),
>>>>     };
>>>> But for the specialisation of the class I want the id to default to
>>>> the actual device id, e.g.:
>>>>     static Property vu_rng_properties[] = {
>>>>         DEFINE_PROP_UINT16("id", VHostUserDevice, id, VIRTIO_ID_RNG),
>>>>         DEFINE_PROP_UINT32("num_vqs", VHostUserDevice, num_vqs, 1),
>>>>         DEFINE_PROP_END_OF_LIST(),
>>>>     };
>>>> And so far the API for doing that isn't super clear.
>>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>>> ---
>>>>    include/hw/qdev-core.h | 9 +++++++++
>>>>    1 file changed, 9 insertions(+)
>>>> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
>>>> index bd50ad5ee1..d4bbc30c92 100644
>>>> --- a/include/hw/qdev-core.h
>>>> +++ b/include/hw/qdev-core.h
>>>> @@ -776,6 +776,15 @@ BusState *sysbus_get_default(void);
>>>>    char *qdev_get_fw_dev_path(DeviceState *dev);
>>>>    char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev);
>>>>    +/**
>>>> + * device_class_set_props(): add a set of properties to an device
>>>> + * @dc: the parent DeviceClass all devices inherit
>>>> + * @props: an array of properties, terminate by DEFINE_PROP_END_OF_LIST()
>>>> + *
>>>> + * This will add a set of properties to the object. It will fault if
>>>> + * you attempt to add an existing property defined by a parent class.
>>>> + * To modify an inherited property you need to use????
>>>> + */
>>>>    void device_class_set_props(DeviceClass *dc, Property *props);
>>>>      /**
>>>
>>> Hmmm that's an interesting one. Looking at the source in
>>> hw/core/qdev-properties.c you could possibly get away with something
>>> like this in vu_rng_class_init():
>>>
>>>      ObjectProperty *op = object_class_property_find(klass, "id");
>>>      object_property_set_default_uint(op, VIRTIO_ID_RNG);
>>>
>>> Of course this is all completely untested :)
>> Sadly we assert on the existing prop->defval:
>>    static void object_property_set_default(ObjectProperty *prop,
>> QObject *defval)
>>    {
>>        assert(!prop->defval);
>>        assert(!prop->init);
>>        prop->defval = defval;
>>        prop->init = object_property_init_defval;
>>    }
>> Maybe the assert is too aggressive or we need a different helper,
>> maybe
>> a:
>>    void object_property_update_default_uint(ObjectProperty *prop,
>> uint64_t value)
>> ?
>
> It seems in that case once the default has been set, it is impossible
> to change. The only other immediate option I can think of is to define
> a specific DEFINE_VHOST_PROPERTIES macro in a similar way to
> DEFINE_AUDIO_PROPERTIES which you can use to set the common properties
> for all VHostUserDevice devices, including providing the default ID.

I tried this: allow the default to change

modified   qom/object.c
@@ -1557,11 +1557,16 @@ static void object_property_init_defval(Object *obj, ObjectProperty *prop)
 
 static void object_property_set_default(ObjectProperty *prop, QObject *defval)
 {
-    assert(!prop->defval);
-    assert(!prop->init);
+    if (prop->init == object_property_init_defval) {
+        fprintf(stderr, "%s: updating existing defval\n", __func__);
+        prop->defval = defval;
+    } else {
+        assert(!prop->defval);
+        assert(!prop->init);
 
-    prop->defval = defval;
-    prop->init = object_property_init_defval;
+        prop->defval = defval;
+        prop->init = object_property_init_defval;
+    }
 }
 


>
>
> ATB,
>
> Mark.


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2023-03-27 22:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-27 13:15 [Socratic RFC PATCH] include: attempt to document device_class_set_props Alex Bennée
2023-03-27 15:30 ` Mark Cave-Ayland
2023-03-27 16:12   ` Alex Bennée
2023-03-27 19:49     ` Mark Cave-Ayland
2023-03-27 22:09       ` Alex Bennée [this message]
2023-03-28  9:41         ` Peter Maydell
2023-03-28 11:05           ` Alex Bennée
2023-04-14 15:50             ` Alex Bennée

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=87edp9sv5p.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=mark.cave-ayland@ilande.co.uk \
    --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).