qdev-properties: PropertyInfo: add realized_set_allowed field

Add field, so property can declare support for setting the property
when device is realized. To be used in the following commit.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210824083856.17408-4-vsementsov@virtuozzo.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2021-08-24 11:38:25 +03:00 committed by Hanna Reitz
parent ed089506ee
commit deb2bb163f
2 changed files with 4 additions and 3 deletions

View File

@ -26,11 +26,11 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
/* returns: true if property is allowed to be set, false otherwise */ /* returns: true if property is allowed to be set, false otherwise */
static bool qdev_prop_allow_set(Object *obj, const char *name, static bool qdev_prop_allow_set(Object *obj, const char *name,
Error **errp) const PropertyInfo *info, Error **errp)
{ {
DeviceState *dev = DEVICE(obj); DeviceState *dev = DEVICE(obj);
if (dev->realized) { if (dev->realized && !info->realized_set_allowed) {
qdev_prop_set_after_realize(dev, name, errp); qdev_prop_set_after_realize(dev, name, errp);
return false; return false;
} }
@ -79,7 +79,7 @@ static void field_prop_set(Object *obj, Visitor *v, const char *name,
{ {
Property *prop = opaque; Property *prop = opaque;
if (!qdev_prop_allow_set(obj, name, errp)) { if (!qdev_prop_allow_set(obj, name, prop->info, errp)) {
return; return;
} }

View File

@ -32,6 +32,7 @@ struct PropertyInfo {
const char *name; const char *name;
const char *description; const char *description;
const QEnumLookup *enum_table; const QEnumLookup *enum_table;
bool realized_set_allowed; /* allow setting property on realized device */
int (*print)(Object *obj, Property *prop, char *dest, size_t len); int (*print)(Object *obj, Property *prop, char *dest, size_t len);
void (*set_default_value)(ObjectProperty *op, const Property *prop); void (*set_default_value)(ObjectProperty *op, const Property *prop);
ObjectProperty *(*create)(ObjectClass *oc, const char *name, ObjectProperty *(*create)(ObjectClass *oc, const char *name,