diff mbox series

[v3,14/19] qom: Don't ignore defval on UUID property

Message ID 20201123194818.2773508-15-ehabkost@redhat.com (mailing list archive)
State New, archived
Headers show
Series qom: Use qlit to represent property defaults | expand

Commit Message

Eduardo Habkost Nov. 23, 2020, 7:48 p.m. UTC
UUID properties were weird because the value of .defval was
completely ignored.  Fix this by setting the default value to
QLIT_QSTR("auto") on the default case, and actually using .defval
inside .set_default_value.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
This is a new patch added in v3 of this series.

This is similar (but not completely the same) to changes that
were submitted as part of
"[PATCH v2 8/8] qom: Use qlit to represent property defaults".
---
 include/hw/qdev-properties-system.h |  9 +++------
 hw/core/qdev-properties-system.c    | 10 +++++-----
 2 files changed, 8 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properties-system.h
index 6221da704e..834ca84904 100644
--- a/include/hw/qdev-properties-system.h
+++ b/include/hw/qdev-properties-system.h
@@ -63,14 +63,11 @@  extern const PropertyInfo qdev_prop_pcie_link_width;
     DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \
                         PCIExpLinkWidth)
 
+#define UUID_VALUE_AUTO        "auto"
+
 #define DEFINE_PROP_UUID(_name, _state, _field) \
     DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \
-                /*                                               \
-                 * Note that set_default_uuid_auto() currently   \
-                 * ignores the actual value value of .defval,    \
-                 * we just need it to not be not QTYPE_NONE      \
-                 */                                              \
-                .defval = QLIT_QNULL)
+                .defval = QLIT_QSTR(UUID_VALUE_AUTO))
 
 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 6071f672a4..117c540254 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -15,6 +15,7 @@ 
 #include "hw/qdev-properties-system.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
+#include "qapi/qmp/qstring.h"
 #include "qapi/qapi-types-block.h"
 #include "qapi/qapi-types-machine.h"
 #include "qapi/qapi-types-migration.h"
@@ -1059,8 +1060,6 @@  static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
     visit_type_str(v, name, &p, errp);
 }
 
-#define UUID_VALUE_AUTO        "auto"
-
 static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
                     Error **errp)
 {
@@ -1080,10 +1079,11 @@  static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
     g_free(str);
 }
 
-static void set_default_uuid_auto(ObjectProperty *op, const Property *prop,
+static void set_default_uuid(ObjectProperty *op, const Property *prop,
                                   const QObject *defval)
 {
-    object_property_set_default_str(op, UUID_VALUE_AUTO);
+    QString *qs = qobject_to(QString, defval);
+    object_property_set_default_str(op, qstring_get_str(qs));
 }
 
 const PropertyInfo qdev_prop_uuid = {
@@ -1092,5 +1092,5 @@  const PropertyInfo qdev_prop_uuid = {
         "\" for random value",
     .get   = get_uuid,
     .set   = set_uuid,
-    .set_default_value = set_default_uuid_auto,
+    .set_default_value = set_default_uuid,
 };