qdev: Move global validation to a single function

Currently GlobalProperty.not_used=false has multiple meanings:

* It may be a property for a hotpluggable device, which may or may not
  have been used by a device;
* It may be a machine-type-provided property, which may or may not have
  been used by a device.
* It may be a user-provided property that was actually not used by
  any device.

Simplify the logic by having two separate fields: 'user_provided' and
'used'. This allows the entire global property validation logic to be
contained in a single function, and allows more specific error messages.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Eduardo Habkost 2014-08-08 16:03:31 -03:00 committed by Michael S. Tsirkin
parent d828c430eb
commit b3ce84fea4
4 changed files with 83 additions and 39 deletions

View file

@ -961,13 +961,29 @@ int qdev_prop_check_globals(void)
int ret = 0;
QTAILQ_FOREACH(prop, &global_props, next) {
if (!prop->not_used) {
ObjectClass *oc;
DeviceClass *dc;
if (prop->used) {
continue;
}
if (!prop->user_provided) {
continue;
}
oc = object_class_by_name(prop->driver);
oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
if (!oc) {
error_report("Warning: global %s.%s has invalid class name",
prop->driver, prop->property);
ret = 1;
continue;
}
dc = DEVICE_CLASS(oc);
if (!dc->hotpluggable && !prop->used) {
error_report("Warning: global %s.%s=%s not used",
prop->driver, prop->property, prop->value);
ret = 1;
continue;
}
ret = 1;
error_report("Warning: \"-global %s.%s=%s\" not used",
prop->driver, prop->property, prop->value);
}
return ret;
}
@ -983,7 +999,7 @@ void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
if (strcmp(typename, prop->driver) != 0) {
continue;
}
prop->not_used = false;
prop->used = true;
object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
if (err != NULL) {
error_propagate(errp, err);