qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Roman Kagan" <rkagan@virtuozzo.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [Qemu-devel] [PULL 02/25] qdev-properties: add UUID property type
Date: Thu, 21 Dec 2017 16:28:01 +0200	[thread overview]
Message-ID: <1513866427-27125-3-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1513866427-27125-1-git-send-email-mst@redhat.com>

From: Roman Kagan <rkagan@virtuozzo.com>

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 <rkagan@virtuozzo.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 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

  parent reply	other threads:[~2017-12-21 14:28 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 14:27 [Qemu-devel] [PULL 00/25] pc, pci, virtio: features, fixes, cleanups Michael S. Tsirkin
2017-12-21 14:27 ` [Qemu-devel] [PULL 01/25] smbios: support setting OEM strings table Michael S. Tsirkin
2017-12-21 14:28 ` Michael S. Tsirkin [this message]
2017-12-21 14:28 ` [Qemu-devel] [PULL 03/25] vmgenid: use UUID property type Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 04/25] tests: add test to check VirtQueue object Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 05/25] pci: Rename root bus initialization functions for clarity Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 06/25] pci: Move bridge data structures from pci_bus.h to pci_bridge.h Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 07/25] pci: Add pci_dev_bus_num() helper Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 08/25] pci: Eliminate redundant PCIDevice::bus pointer Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 09/25] pci: Eliminate pci_find_primary_bus() Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 10/25] virtio_error: don't invoke status callbacks Michael S. Tsirkin
2018-02-13 20:53   ` [Qemu-devel] [Qemu-stable] " Peter Lieven
2018-02-13 22:23     ` Michael S. Tsirkin
2018-02-14 21:12       ` Peter Lieven
2017-12-21 14:29 ` [Qemu-devel] [PULL 11/25] tests/pxe-test: Remove unnecessary special case test functions Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 12/25] tests/pxe-test: Use table of testcases rather than open-coding Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 13/25] tests/pxe-test: Test net booting over IPv6 in some cases Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 14/25] tests/pxe-test: Add some extra tests Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 15/25] hw/block/nvme: QOM'ify PCI NVME Michael S. Tsirkin
2017-12-21 20:38   ` Michael S. Tsirkin
2017-12-21 23:02     ` Philippe Mathieu-Daudé
2017-12-21 14:29 ` [Qemu-devel] [PULL 16/25] hw/pci-host/piix: QOM'ify the IGD Passthrough host bridge Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 17/25] hw/pci-host/xilinx: QOM'ify the AXI-PCIe " Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 18/25] hw/pci: remove obsolete PCIDevice->init() Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 19/25] vhost-user: fix indentation in protocol specification Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 20/25] vhost-user: document memory accesses Michael S. Tsirkin
2017-12-21 14:30 ` [Qemu-devel] [PULL 23/25] virtio-pci: Don't force Subsystem Vendor ID = Vendor ID Michael S. Tsirkin
2017-12-21 14:31 ` [Qemu-devel] [PULL 24/25] dump-guest-memory.py: fix "You can't do that without a process to debug" Michael S. Tsirkin
2017-12-21 14:31 ` [Qemu-devel] [PULL 25/25] smbus: do not immediately complete commands Michael S. Tsirkin
2017-12-21 14:33 ` [Qemu-devel] [PULL 21/25] intel_iommu: remove X86_IOMMU_PCI_DEVFN_MAX Michael S. Tsirkin
2017-12-21 14:34 ` [Qemu-devel] [PULL 22/25] intel_iommu: fix error param in string Michael S. Tsirkin
2017-12-21 20:26 ` [Qemu-devel] [PULL 00/25] pc, pci, virtio: features, fixes, cleanups Peter Maydell
2017-12-21 20:37   ` Michael S. Tsirkin
2017-12-21 23:05     ` Peter Maydell
2017-12-21 23:42       ` Michael S. Tsirkin
2017-12-22  0:44         ` Philippe Mathieu-Daudé
2017-12-21 23:05     ` Philippe Mathieu-Daudé
2017-12-21 23:43       ` Michael S. Tsirkin
2018-01-08  9:14         ` Peter Maydell
2018-01-08 17:04           ` Michael S. Tsirkin
2018-01-08 18:10           ` Michael S. Tsirkin
2018-01-09  1:10             ` David Gibson
2018-01-09  4:09               ` Michael S. Tsirkin
2018-01-16  2:48               ` Michael S. Tsirkin
2018-01-16  6:28                 ` Jason Wang
2018-01-16  6:33                   ` Jason Wang
2018-01-16  8:03                   ` Dmitry Fleytman
2018-01-17  3:14                     ` Jason Wang
2018-01-09  4:11           ` Michael S. Tsirkin
2018-01-11 15:31             ` Peter Maydell
2018-01-11 19:59               ` Michael S. Tsirkin
2018-01-11 20:06               ` Michael S. Tsirkin
2018-01-11 21:05               ` Michael S. Tsirkin
2018-01-12 10:44                 ` Peter Maydell
2018-01-12 16:02                   ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513866427-27125-3-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rkagan@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).