Skip to contentSkip to conversation

add UUID property type

PATCH Superseded Roman Kagan 5 participants 11 messages Nov 24, 2017 – Dec 7, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover add UUID property type

UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful.

In the existing code, vmgenid can immediately profit from it.

Roman Kagan (2):
qdev-properties: add UUID property type
vmgenid: use UUID property type

 include/hw/qdev-properties.h |  3 +++
 hw/acpi/vmgenid.c            | 30 +++++++------------------
 hw/core/qdev-properties.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 22 deletions(-)
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/2 qdev-properties: add UUID property type

UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful.

---
 include/hw/qdev-properties.h |  3 +++
 hw/core/qdev-properties.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
include/hw/qdev-properties.h +3 -0
index e2321f1cc1..d4da7dd1f1 100644
@@ -30,6 +30,7 @@ extern const PropertyInfo qdev_prop_vlan;
 extern const PropertyInfo qdev_prop_pci_devfn;
 extern const PropertyInfo qdev_prop_blocksize;
 extern const PropertyInfo qdev_prop_pci_host_devaddr;
+extern const PropertyInfo qdev_prop_uuid;
 extern const PropertyInfo qdev_prop_arraylen;
 extern const PropertyInfo qdev_prop_link;
 
@@ -212,6 +213,8 @@ extern const PropertyInfo qdev_prop_link;
     DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
 #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
+#define DEFINE_PROP_UUID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_uuid, QemuUUID)
 
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
hw/core/qdev-properties.c +52 -0

64 lines not on this page · raw message

Signature · 1 line
2.14.3
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev-properties: add UUID property type

Quoted 4 lines · Roman Kagan

UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful.

Quoted 100 lines
---
 include/hw/qdev-properties.h |  3 +++
 hw/core/qdev-properties.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
include/hw/qdev-properties.h +3 -0
index e2321f1cc1..d4da7dd1f1 100644
@@ -30,6 +30,7 @@ extern const PropertyInfo qdev_prop_vlan;
 extern const PropertyInfo qdev_prop_pci_devfn;
 extern const PropertyInfo qdev_prop_blocksize;
 extern const PropertyInfo qdev_prop_pci_host_devaddr;
+extern const PropertyInfo qdev_prop_uuid;
 extern const PropertyInfo qdev_prop_arraylen;
 extern const PropertyInfo qdev_prop_link;
 
@@ -212,6 +213,8 @@ extern const PropertyInfo qdev_prop_link;
     DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
 #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
+#define DEFINE_PROP_UUID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_uuid, QemuUUID)
 
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
hw/core/qdev-properties.c +52 -1
index 1dc80fcea2..49fea5a40a 100644
@@ -10,6 +10,7 @@
 #include "net/hub.h"
 #include "qapi/visitor.h"
 #include "chardev/char.h"
+#include "qemu/uuid.h"
 
 void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
                                   Error **errp)
@@ -883,6 +884,57 @@ const PropertyInfo qdev_prop_pci_host_devaddr = {
     .set = set_pci_host_devaddr,
 };
 
+/* --- UUID --- */
+
+static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                     Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    char buffer[UUID_FMT_LEN + 1];
+    char *p = buffer;
+
+    qemu_uuid_unparse(uuid, buffer);
+
+    visit_type_str(v, name, &p, errp);
+}
+
+static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    char *str;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_str(v, name, &str, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (!strcmp(str, "auto")) {
+        qemu_uuid_generate(uuid);
+    } else if (qemu_uuid_parse(str, uuid) < 0) {
+        error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    }
+    g_free(str);
+}
+
+const PropertyInfo qdev_prop_uuid = {
+    .name  = "str",
+    .description = "UUID (aka GUID) or \"auto\" for random value",
+    .get   = get_uuid,
+    .set   = set_uuid,
+};
+
 /* --- support for array properties --- */
 
 /* Used as an opaque for the object properties we add for each
--

2.14.3

Signature · 1 line
Marc-André Lureau
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev-properties: add UUID property type

In reply to Roman Kagan
Quoted 85 lines · Roman Kagan

UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful.

---
  include/hw/qdev-properties.h |  3 +++
  hw/core/qdev-properties.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 55 insertions(+)
include/hw/qdev-properties.h +3 -0
index e2321f1cc1..d4da7dd1f1 100644
@@ -30,6 +30,7 @@ extern const PropertyInfo qdev_prop_vlan;
  extern const PropertyInfo qdev_prop_pci_devfn;
  extern const PropertyInfo qdev_prop_blocksize;
  extern const PropertyInfo qdev_prop_pci_host_devaddr;
+extern const PropertyInfo qdev_prop_uuid;
  extern const PropertyInfo qdev_prop_arraylen;
  extern const PropertyInfo qdev_prop_link;
 
@@ -212,6 +213,8 @@ extern const PropertyInfo qdev_prop_link;
      DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
  #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f)             \
      DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
+#define DEFINE_PROP_UUID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_uuid, QemuUUID)
 
  #define DEFINE_PROP_END_OF_LIST()               \
      {}
hw/core/qdev-properties.c +40 -0
index 1dc80fcea2..49fea5a40a 100644
@@ -10,6 +10,7 @@
  #include "net/hub.h"
  #include "qapi/visitor.h"
  #include "chardev/char.h"
+#include "qemu/uuid.h"
 
  void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
                                    Error **errp)
@@ -883,6 +884,57 @@ const PropertyInfo qdev_prop_pci_host_devaddr = {
      .set = set_pci_host_devaddr,
  };
 
+/* --- UUID --- */
+
+static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                     Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    char buffer[UUID_FMT_LEN + 1];
+    char *p = buffer;
+
+    qemu_uuid_unparse(uuid, buffer);
+
+    visit_type_str(v, name, &p, errp);
+}
+
+static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    char *str;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_str(v, name, &str, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (!strcmp(str, "auto")) {
+        qemu_uuid_generate(uuid);
+    } else if (qemu_uuid_parse(str, uuid) < 0) {

hw/core/qdev-properties.c const PropertyInfo qdev_prop_pci_host_devaddr = { · line 935

Quoted 10 lines
hw/core/qdev-properties.c +10 -0
+        error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    }
+    g_free(str);
+}
+
+const PropertyInfo qdev_prop_uuid = {
+    .name  = "str",
+    .description = "UUID (aka GUID) or \"auto\" for random value",
+    .get   = get_uuid,
+    .set   = set_uuid,

There is a UUID value you can use as a default in  vl.c, named qemu_uuid. Just in case you want to set a default value here.

-corey

Quoted 5 lines
hw/core/qdev-properties.c +2 -0
+};
+
  /* --- support for array properties --- */
 
  /* Used as an opaque for the object properties we add for each
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev-properties: add UUID property type

Quoted 87 lines · Corey Minyard
Quoted 86 lines · Roman Kagan

UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful.

---
  include/hw/qdev-properties.h |  3 +++
  hw/core/qdev-properties.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 55 insertions(+)
include/hw/qdev-properties.h +3 -0
index e2321f1cc1..d4da7dd1f1 100644
@@ -30,6 +30,7 @@ extern const PropertyInfo qdev_prop_vlan;
  extern const PropertyInfo qdev_prop_pci_devfn;
  extern const PropertyInfo qdev_prop_blocksize;
  extern const PropertyInfo qdev_prop_pci_host_devaddr;
+extern const PropertyInfo qdev_prop_uuid;
  extern const PropertyInfo qdev_prop_arraylen;
  extern const PropertyInfo qdev_prop_link;
@@ -212,6 +213,8 @@ extern const PropertyInfo qdev_prop_link;
      DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
  #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f)             \
      DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
+#define DEFINE_PROP_UUID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_uuid, QemuUUID)
  #define DEFINE_PROP_END_OF_LIST()               \
      {}
hw/core/qdev-properties.c +45 -0
index 1dc80fcea2..49fea5a40a 100644
@@ -10,6 +10,7 @@
  #include "net/hub.h"
  #include "qapi/visitor.h"
  #include "chardev/char.h"
+#include "qemu/uuid.h"
  void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
                                    Error **errp)
@@ -883,6 +884,57 @@ const PropertyInfo qdev_prop_pci_host_devaddr = {
      .set = set_pci_host_devaddr,
  };
+/* --- UUID --- */
+
+static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                     Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    char buffer[UUID_FMT_LEN + 1];
+    char *p = buffer;
+
+    qemu_uuid_unparse(uuid, buffer);
+
+    visit_type_str(v, name, &p, errp);
+}
+
+static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    char *str;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_str(v, name, &str, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (!strcmp(str, "auto")) {
+        qemu_uuid_generate(uuid);
+    } else if (qemu_uuid_parse(str, uuid) < 0) {
+        error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    }
+    g_free(str);
+}
+
Quoted 8 lines

hw/core/qdev-properties.c const PropertyInfo qdev_prop_pci_host_devaddr = { · line 935

Quoted 5 lines
hw/core/qdev-properties.c +5 -0
+const PropertyInfo qdev_prop_uuid = {
+    .name  = "str",
+    .description = "UUID (aka GUID) or \"auto\" for random value",
+    .get   = get_uuid,
+    .set   = set_uuid,

There is a UUID value you can use as a default in  vl.c, named qemu_uuid. Just in case you want to set a default value here.

I'm not sure what a common non-null default for all uuid properties would mean...

IMO most of the time it makes sense to default to "auto". I'll have a look if I can do it within this patch.

Thanks,
Roman.

#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev-properties: add UUID property type

Quoted 2 lines · Roman Kagan
Quoted 1 line · Corey Minyard

On 11/24/2017 09:36 AM, Roman Kagan wrote:

snip

Quoted 10 lines
Quoted 8 lines

hw/core/qdev-properties.c const PropertyInfo qdev_prop_pci_host_devaddr = { · line 935

Quoted 6 lines
hw/core/qdev-properties.c +6 -0
+
+const PropertyInfo qdev_prop_uuid = {
+    .name  = "str",
+    .description = "UUID (aka GUID) or \"auto\" for random value",
+    .get   = get_uuid,
+    .set   = set_uuid,

There is a UUID value you can use as a default in  vl.c, named qemu_uuid. Just in case you want to set a default value here.

I'm not sure what a common non-null default for all uuid properties would mean...

It depends on what the uuid is for.  If you are trying to uniquely identify devices to QEMU or the OS, then it make no sense.  If you are trying to identify qemu or what is running in it to outside entities, then it might make sense.  I didn't know the purpose of this uuid, so I thought I would suggest.

-corey

Quoted 6 lines

IMO most of the time it makes sense to default to "auto". I'll have a look if I can do it within this patch.

Thanks,
Roman.

#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev-properties: add UUID property type

In reply to Corey Minyard
Quoted 87 lines · Corey Minyard
Quoted 86 lines · Roman Kagan

UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful.

---
  include/hw/qdev-properties.h |  3 +++
  hw/core/qdev-properties.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 55 insertions(+)
include/hw/qdev-properties.h +3 -0
index e2321f1cc1..d4da7dd1f1 100644
@@ -30,6 +30,7 @@ extern const PropertyInfo qdev_prop_vlan;
  extern const PropertyInfo qdev_prop_pci_devfn;
  extern const PropertyInfo qdev_prop_blocksize;
  extern const PropertyInfo qdev_prop_pci_host_devaddr;
+extern const PropertyInfo qdev_prop_uuid;
  extern const PropertyInfo qdev_prop_arraylen;
  extern const PropertyInfo qdev_prop_link;
@@ -212,6 +213,8 @@ extern const PropertyInfo qdev_prop_link;
      DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
  #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f)             \
      DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
+#define DEFINE_PROP_UUID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_uuid, QemuUUID)
  #define DEFINE_PROP_END_OF_LIST()               \
      {}
hw/core/qdev-properties.c +45 -0
index 1dc80fcea2..49fea5a40a 100644
@@ -10,6 +10,7 @@
  #include "net/hub.h"
  #include "qapi/visitor.h"
  #include "chardev/char.h"
+#include "qemu/uuid.h"
  void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
                                    Error **errp)
@@ -883,6 +884,57 @@ const PropertyInfo qdev_prop_pci_host_devaddr = {
      .set = set_pci_host_devaddr,
  };
+/* --- UUID --- */
+
+static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                     Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    char buffer[UUID_FMT_LEN + 1];
+    char *p = buffer;
+
+    qemu_uuid_unparse(uuid, buffer);
+
+    visit_type_str(v, name, &p, errp);
+}
+
+static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    char *str;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_str(v, name, &str, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (!strcmp(str, "auto")) {
+        qemu_uuid_generate(uuid);
+    } else if (qemu_uuid_parse(str, uuid) < 0) {
+        error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    }
+    g_free(str);
+}
+
Quoted 8 lines

hw/core/qdev-properties.c const PropertyInfo qdev_prop_pci_host_devaddr = { · line 935

Quoted 5 lines
hw/core/qdev-properties.c +5 -0
+const PropertyInfo qdev_prop_uuid = {
+    .name  = "str",
+    .description = "UUID (aka GUID) or \"auto\" for random value",
+    .get   = get_uuid,
+    .set   = set_uuid,

There is a UUID value you can use as a default in  vl.c, named qemu_uuid. Just in case you want to set a default value here.

I don't think that would be a good idea. If this UUID property is used in a device type and the default were used, then every instance of the device would use the same UUID, at which point it is a non-unique ID. Much better to ue a random UUID, unless you know there is guaranteed to only ever be one instance of the device type.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 1/2
#7 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev-properties: add UUID property type

In reply to Roman Kagan
Quoted 7 lines · Roman Kagan

UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated property type becomes helpful.

Quoted 99 lines

---
include/hw/qdev-properties.h | 3 +++
hw/core/qdev-properties.c | 52 ++++++++++++++++++++++++++++++++++++++++++++

2 files changed, 55 insertions(+)
include/hw/qdev-properties.h +3 -0
index e2321f1cc1..d4da7dd1f1 100644
@@ -30,6 +30,7 @@ extern const PropertyInfo qdev_prop_vlan;
 extern const PropertyInfo qdev_prop_pci_devfn;
 extern const PropertyInfo qdev_prop_blocksize;
 extern const PropertyInfo qdev_prop_pci_host_devaddr;
+extern const PropertyInfo qdev_prop_uuid;
 extern const PropertyInfo qdev_prop_arraylen;
 extern const PropertyInfo qdev_prop_link;
 
@@ -212,6 +213,8 @@ extern const PropertyInfo qdev_prop_link;
    DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
 #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f)             \
    DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
+#define DEFINE_PROP_UUID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_uuid, QemuUUID)
 
 #define DEFINE_PROP_END_OF_LIST()               \
    {}
hw/core/qdev-properties.c +52 -0
index 1dc80fcea2..49fea5a40a 100644
@@ -10,6 +10,7 @@
 #include "net/hub.h"
 #include "qapi/visitor.h"
 #include "chardev/char.h"
+#include "qemu/uuid.h"
 
 void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
                                  Error **errp)
@@ -883,6 +884,57 @@ const PropertyInfo qdev_prop_pci_host_devaddr = {
    .set = set_pci_host_devaddr,
 };
 
+/* --- UUID --- */
+
+static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                     Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    char buffer[UUID_FMT_LEN + 1];
+    char *p = buffer;
+
+    qemu_uuid_unparse(uuid, buffer);
+
+    visit_type_str(v, name, &p, errp);
+}
+
+static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
+                    Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    QemuUUID *uuid = qdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    char *str;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_str(v, name, &str, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (!strcmp(str, "auto")) {
+        qemu_uuid_generate(uuid);
+    } else if (qemu_uuid_parse(str, uuid) < 0) {
+        error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    }
+    g_free(str);
+}
+
+const PropertyInfo qdev_prop_uuid = {
+    .name  = "str",
+    .description = "UUID (aka GUID) or \"auto\" for random value",
+    .get   = get_uuid,
+    .set   = set_uuid,
+};
+
 /* --- support for array properties --- */
 
 /* Used as an opaque for the object properties we add for each
Signature · 1 line
2.14.3
#8 lore raw

PATCH 2/2 vmgenid: use UUID property type

In reply to Roman Kagan

Switch vmgenid device to use the UUID property type introduced in the previous patch for its 'guid' property.

One semantic change it introduces is that post-realize modification of 'guid' via HMP or QMP will now be rejected with an error; however, according to docs/specs/vmgenid.txt this is actually desirable.

---
 hw/acpi/vmgenid.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)
hw/acpi/vmgenid.c +8 -22
index 105044f666..84ff015bda 100644
@@ -162,21 +162,6 @@ static void vmgenid_update_guest(VmGenIdState *vms)
     }
 }
 
-static void vmgenid_set_guid(Object *obj, const char *value, Error **errp)
-{
-    VmGenIdState *vms = VMGENID(obj);
-
-    if (!strcmp(value, "auto")) {
-        qemu_uuid_generate(&vms->guid);
-    } else if (qemu_uuid_parse(value, &vms->guid) < 0) {
-        error_setg(errp, "'%s. %s': Failed to parse GUID string: %s",
-                   object_get_typename(OBJECT(vms)), VMGENID_GUID, value);
-        return;
-    }
-
-    vmgenid_update_guest(vms);
-}
-
 /* After restoring an image, we need to update the guest memory and notify
  * it of a potential change to VM Generation ID
  */
@@ -224,23 +209,24 @@ static void vmgenid_realize(DeviceState *dev, Error **errp)
     }
 
     qemu_register_reset(vmgenid_handle_reset, vms);
+
+    vmgenid_update_guest(vms);
 }
 
+static Property vmgenid_device_properties[] = {
+    DEFINE_PROP_UUID("guid", VmGenIdState, guid),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void vmgenid_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_vmgenid;
     dc->realize = vmgenid_realize;
+    dc->props = vmgenid_device_properties;
     dc->hotpluggable = false;
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
-
-    object_class_property_add_str(klass, VMGENID_GUID, NULL,
-                                  vmgenid_set_guid, NULL);
-    object_class_property_set_description(klass, VMGENID_GUID,
-                                    "Set Global Unique Identifier "
-                                    "(big-endian) or auto for random value",
-                                    NULL);
 }
 
 static const TypeInfo vmgenid_device_info = {
Signature · 1 line
2.14.3
Reviewed-by on v1 2/2
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] vmgenid: use UUID property type

Hi

Quoted 8 lines · Roman Kagan

Switch vmgenid device to use the UUID property type introduced in the previous patch for its 'guid' property.

One semantic change it introduces is that post-realize modification of 'guid' via HMP or QMP will now be rejected with an error; however, according to docs/specs/vmgenid.txt this is actually desirable.

Quoted 66 lines
---
 hw/acpi/vmgenid.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)
hw/acpi/vmgenid.c +8 -23
index 105044f666..84ff015bda 100644
@@ -162,21 +162,6 @@ static void vmgenid_update_guest(VmGenIdState *vms)
     }
 }
 
-static void vmgenid_set_guid(Object *obj, const char *value, Error **errp)
-{
-    VmGenIdState *vms = VMGENID(obj);
-
-    if (!strcmp(value, "auto")) {
-        qemu_uuid_generate(&vms->guid);
-    } else if (qemu_uuid_parse(value, &vms->guid) < 0) {
-        error_setg(errp, "'%s. %s': Failed to parse GUID string: %s",
-                   object_get_typename(OBJECT(vms)), VMGENID_GUID, value);
-        return;
-    }
-
-    vmgenid_update_guest(vms);
-}
-
 /* After restoring an image, we need to update the guest memory and notify
  * it of a potential change to VM Generation ID
  */
@@ -224,23 +209,24 @@ static void vmgenid_realize(DeviceState *dev, Error **errp)
     }
 
     qemu_register_reset(vmgenid_handle_reset, vms);
+
+    vmgenid_update_guest(vms);
 }
 
+static Property vmgenid_device_properties[] = {
+    DEFINE_PROP_UUID("guid", VmGenIdState, guid),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void vmgenid_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_vmgenid;
     dc->realize = vmgenid_realize;
+    dc->props = vmgenid_device_properties;
     dc->hotpluggable = false;
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
-
-    object_class_property_add_str(klass, VMGENID_GUID, NULL,
-                                  vmgenid_set_guid, NULL);
-    object_class_property_set_description(klass, VMGENID_GUID,
-                                    "Set Global Unique Identifier "
-                                    "(big-endian) or auto for random value",
-                                    NULL);
 }
 
 static const TypeInfo vmgenid_device_info = {
--

2.14.3

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 2/2
#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] vmgenid: use UUID property type

In reply to Roman Kagan

Thanks Roman, this seems like a nice improvement. Fix the minor point below, and you can add my R-B.

Quoted 10 lines · Roman Kagan

Switch vmgenid device to use the UUID property type introduced in the previous patch for its 'guid' property.

One semantic change it introduces is that post-realize modification of 'guid' via HMP or QMP will now be rejected with an error; however, according to docs/specs/vmgenid.txt this is actually desirable.

Quoted 31 lines

---
hw/acpi/vmgenid.c | 30 ++++++++----------------------

1 file changed, 8 insertions(+), 22 deletions(-)
hw/acpi/vmgenid.c +0 -15
index 105044f666..84ff015bda 100644
@@ -162,21 +162,6 @@ static void vmgenid_update_guest(VmGenIdState *vms)
    }
 }
 
-static void vmgenid_set_guid(Object *obj, const char *value, Error **errp)
-{
-    VmGenIdState *vms = VMGENID(obj);
-
-    if (!strcmp(value, "auto")) {
-        qemu_uuid_generate(&vms->guid);
-    } else if (qemu_uuid_parse(value, &vms->guid) < 0) {
-        error_setg(errp, "'%s. %s': Failed to parse GUID string: %s",
-                   object_get_typename(OBJECT(vms)), VMGENID_GUID, value);
-        return;
-    }
-
-    vmgenid_update_guest(vms);
-}
-
 /* After restoring an image, we need to update the guest memory and notify
 * it of a potential change to VM Generation ID
 */

hw/acpi/vmgenid.c static void vmgenid_realize(DeviceState *dev, Error **errp) · line 217

Quoted 9 lines
hw/acpi/vmgenid.c +4 -0
@@ -224,23 +209,24 @@ static void vmgenid_realize(DeviceState *dev, Error **errp)
    }
 
    qemu_register_reset(vmgenid_handle_reset, vms);
+
+    vmgenid_update_guest(vms);
 }
 
+static Property vmgenid_device_properties[] = {
+    DEFINE_PROP_UUID("guid", VmGenIdState, guid),

Use VMGENID_GUID instead of “guid"

Quoted 25 lines
hw/acpi/vmgenid.c +4 -7
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void vmgenid_device_class_init(ObjectClass *klass, void *data)
 {
    DeviceClass *dc = DEVICE_CLASS(klass);
 
    dc->vmsd = &vmstate_vmgenid;
    dc->realize = vmgenid_realize;
+    dc->props = vmgenid_device_properties;
    dc->hotpluggable = false;
    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
-
-    object_class_property_add_str(klass, VMGENID_GUID, NULL,
-                                  vmgenid_set_guid, NULL);
-    object_class_property_set_description(klass, VMGENID_GUID,
-                                    "Set Global Unique Identifier "
-                                    "(big-endian) or auto for random value",
-                                    NULL);
 }
 
 static const TypeInfo vmgenid_device_info = {
Signature · 1 line
2.14.3