[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 02/25] qdev-properties: add UUID property type
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 02/25] qdev-properties: add UUID property type |
Date: |
Thu, 21 Dec 2017 16:28:01 +0200 |
From: Roman Kagan <address@hidden>
UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated
property type becomes helpful.
The property accepts a string-formatted UUID or a special keyword "auto"
meaning a randomly generated UUID; the latter is also the default when
the property is not given a value explicitly.
Signed-off-by: Roman Kagan <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/hw/qdev-properties.h | 9 +++++++
hw/core/qdev-properties.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index e2321f1..97e810e 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -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;
@@ -213,6 +214,14 @@ extern const PropertyInfo qdev_prop_link;
#define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
+#define DEFINE_PROP_UUID(_name, _state, _field) { \
+ .name = (_name), \
+ .info = &qdev_prop_uuid, \
+ .offset = offsetof(_state, _field) \
+ + type_check(QemuUUID, typeof_field(_state, _field)), \
+ .set_default = true, \
+ }
+
#define DEFINE_PROP_END_OF_LIST() \
{}
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 1dc80fc..24c1780 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -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,66 @@ 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);
+}
+
+#define UUID_VALUE_AUTO "auto"
+
+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, UUID_VALUE_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);
+}
+
+static void set_default_uuid_auto(Object *obj, const Property *prop)
+{
+ object_property_set_str(obj, UUID_VALUE_AUTO, prop->name, &error_abort);
+}
+
+const PropertyInfo qdev_prop_uuid = {
+ .name = "str",
+ .description = "UUID (aka GUID) or \"" UUID_VALUE_AUTO
+ "\" for random value (default)",
+ .get = get_uuid,
+ .set = set_uuid,
+ .set_default_value = set_default_uuid_auto,
+};
+
/* --- support for array properties --- */
/* Used as an opaque for the object properties we add for each
--
MST
- [Qemu-devel] [PULL 00/25] pc, pci, virtio: features, fixes, cleanups, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 01/25] smbios: support setting OEM strings table, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 02/25] qdev-properties: add UUID property type,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 03/25] vmgenid: use UUID property type, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 04/25] tests: add test to check VirtQueue object, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 05/25] pci: Rename root bus initialization functions for clarity, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 06/25] pci: Move bridge data structures from pci_bus.h to pci_bridge.h, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 07/25] pci: Add pci_dev_bus_num() helper, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 10/25] virtio_error: don't invoke status callbacks, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 09/25] pci: Eliminate pci_find_primary_bus(), Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 11/25] tests/pxe-test: Remove unnecessary special case test functions, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 14/25] tests/pxe-test: Add some extra tests, Michael S. Tsirkin, 2017/12/21
- [Qemu-devel] [PULL 08/25] pci: Eliminate redundant PCIDevice::bus pointer, Michael S. Tsirkin, 2017/12/21