Patchwork [qom-cpu,for-1.5,2/4] qdev: Introduce qdev_prop_set_custom_globals()

login
register
mail settings
Submitter Andreas Färber
Date May 1, 2013, 4:07 p.m.
Message ID <1367424440-16687-3-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/240783/
State New
Headers show

Comments

Andreas Färber - May 1, 2013, 4:07 p.m.
Reuse it in qdev_prop_set_globals().

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/core/qdev-properties.c    | 35 ++++++++++++++++++++++++-----------
 include/hw/qdev-properties.h |  2 ++
 2 files changed, 26 insertions(+), 11 deletions(-)
Eduardo Habkost - May 2, 2013, 7:08 p.m.
On Wed, May 01, 2013 at 06:07:18PM +0200, Andreas Färber wrote:
> Reuse it in qdev_prop_set_globals().
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>

Very useful to allow us to implement sane bugfixes while the QOM
conversion is still work in progress, and much more flexible than having
to write special-purpose compat functions for code that isn't completely
QOMified yet.

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

I assume that although this works with "-global" on the command-line, we
will try to use the (currently) fake class names from patch 3/4 only for
the internal machine-type compat_props tables, and discourage users from
using them in the command-line.


> ---
>  hw/core/qdev-properties.c    | 35 ++++++++++++++++++++++++-----------
>  include/hw/qdev-properties.h |  2 ++
>  2 files changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 716ba19..68d1bff 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -1099,23 +1099,36 @@ void qdev_prop_register_global_list(GlobalProperty *props)
>      }
>  }
>  
> +void qdev_prop_set_custom_globals(DeviceState *dev, const char *driver,
> +                                  Error **errp)
> +{
> +    GlobalProperty *prop;
> +
> +    QTAILQ_FOREACH(prop, &global_props, next) {
> +        Error *err = NULL;
> +
> +        if (strcmp(driver, prop->driver) != 0) {
> +            continue;
> +        }
> +        qdev_prop_parse(dev, prop->property, prop->value, &err);
> +        if (err != NULL) {
> +            error_propagate(errp, err);
> +            return;
> +        }
> +    }
> +}
> +
>  void qdev_prop_set_globals(DeviceState *dev, Error **errp)
>  {
>      ObjectClass *class = object_get_class(OBJECT(dev));
>  
>      do {
> -        GlobalProperty *prop;
> -        QTAILQ_FOREACH(prop, &global_props, next) {
> -            Error *err = NULL;
> +        Error *err = NULL;
>  
> -            if (strcmp(object_class_get_name(class), prop->driver) != 0) {
> -                continue;
> -            }
> -            qdev_prop_parse(dev, prop->property, prop->value, &err);
> -            if (err != NULL) {
> -                error_propagate(errp, err);
> -                return;
> -            }
> +        qdev_prop_set_custom_globals(dev, object_class_get_name(class), &err);
> +        if (err != NULL) {
> +            error_propagate(errp, err);
> +            return;
>          }
>          class = object_class_get_parent(class);
>      } while (class);
> diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
> index 38469d4..833300c 100644
> --- a/include/hw/qdev-properties.h
> +++ b/include/hw/qdev-properties.h
> @@ -169,6 +169,8 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
>  void qdev_prop_register_global(GlobalProperty *prop);
>  void qdev_prop_register_global_list(GlobalProperty *props);
>  void qdev_prop_set_globals(DeviceState *dev, Error **errp);
> +void qdev_prop_set_custom_globals(DeviceState *dev, const char *driver,
> +                                  Error **errp);
>  void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
>                                      Property *prop, const char *value);
>  
> -- 
> 1.8.1.4
>

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 716ba19..68d1bff 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1099,23 +1099,36 @@  void qdev_prop_register_global_list(GlobalProperty *props)
     }
 }
 
+void qdev_prop_set_custom_globals(DeviceState *dev, const char *driver,
+                                  Error **errp)
+{
+    GlobalProperty *prop;
+
+    QTAILQ_FOREACH(prop, &global_props, next) {
+        Error *err = NULL;
+
+        if (strcmp(driver, prop->driver) != 0) {
+            continue;
+        }
+        qdev_prop_parse(dev, prop->property, prop->value, &err);
+        if (err != NULL) {
+            error_propagate(errp, err);
+            return;
+        }
+    }
+}
+
 void qdev_prop_set_globals(DeviceState *dev, Error **errp)
 {
     ObjectClass *class = object_get_class(OBJECT(dev));
 
     do {
-        GlobalProperty *prop;
-        QTAILQ_FOREACH(prop, &global_props, next) {
-            Error *err = NULL;
+        Error *err = NULL;
 
-            if (strcmp(object_class_get_name(class), prop->driver) != 0) {
-                continue;
-            }
-            qdev_prop_parse(dev, prop->property, prop->value, &err);
-            if (err != NULL) {
-                error_propagate(errp, err);
-                return;
-            }
+        qdev_prop_set_custom_globals(dev, object_class_get_name(class), &err);
+        if (err != NULL) {
+            error_propagate(errp, err);
+            return;
         }
         class = object_class_get_parent(class);
     } while (class);
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 38469d4..833300c 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -169,6 +169,8 @@  void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 void qdev_prop_register_global(GlobalProperty *prop);
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev, Error **errp);
+void qdev_prop_set_custom_globals(DeviceState *dev, const char *driver,
+                                  Error **errp);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);