Message ID | 20230418162140.373219-2-alex.bennee@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | virtio: add vhost-user-generic and reduce copy and paste | expand |
On 18/04/2023 17:21, 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); > > /** Can we say that the use case description above is now obsolete with the introduction of the abstract VHOST_USER_BASE class (i.e. it was a modelling issue)? If so, I think the comment is good, except that the last sentence can be removed. ATB, Mark.
On Tue, Apr 18, 2023 at 05:21:28PM +0100, 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. Does this mean this patch is an RFC and this patch is not intended to be merged? > > 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); I don't know the answer. There doesn't seem to be a way for child classes to override parent DeviceClass properties. The assumption is the sets of properties are disjoint (no property name collisions). Here is a workaround in the vhost-user-rng code: /* Set our default if the user didn't specify the id */ if (vud->id == 0) { vud->id = VIRTIO_ID_RNG; } This could be a problem because the value 0 may be valid and there is no way to distinguish between a user setting 0 and the default 0 value. Stefan
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); /**
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(+)