All of lore.kernel.org
 help / color / mirror / Atom feed
From: Corey Minyard <tcminyard@gmail.com>
To: Roman Kagan <rkagan@virtuozzo.com>,
	qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	Ben Warren <ben@skyportsystems.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Denis V. Lunev" <den@openvz.org>
Subject: Re: [Qemu-devel] [PATCH 1/2] qdev-properties: add UUID property type
Date: Fri, 24 Nov 2017 20:36:53 -0600	[thread overview]
Message-ID: <1f37e2f7-e83e-8605-4e86-b296abcc826d@gmail.com> (raw)
In-Reply-To: <20171124153656.30199-2-rkagan@virtuozzo.com>

On 11/24/2017 09:36 AM, Roman Kagan wrote:
> UUIDs (GUIDs) are widely used in VMBus-related stuff, so a dedicated
> property type becomes helpful.
>
> Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
> ---
>   include/hw/qdev-properties.h |  3 +++
>   hw/core/qdev-properties.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 55 insertions(+)
>
> diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
> index e2321f1cc1..d4da7dd1f1 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;
>   
> @@ -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()               \
>       {}
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 1dc80fcea2..49fea5a40a 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,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,

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

> +};
> +
>   /* --- support for array properties --- */
>   
>   /* Used as an opaque for the object properties we add for each

  parent reply	other threads:[~2017-11-25  2:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-24 15:36 [Qemu-devel] [PATCH 0/2] add UUID property type Roman Kagan
2017-11-24 15:36 ` [Qemu-devel] [PATCH 1/2] qdev-properties: " Roman Kagan
2017-11-24 17:57   ` Marc-André Lureau
2017-11-25  2:36   ` Corey Minyard [this message]
2017-11-27 10:06     ` Roman Kagan
2017-12-07 19:48       ` Corey Minyard
2017-11-27 10:35     ` Daniel P. Berrange
2017-11-25  6:58   ` Ben Warren
2017-11-24 15:36 ` [Qemu-devel] [PATCH 2/2] vmgenid: use " Roman Kagan
2017-11-24 17:59   ` Marc-André Lureau
2017-11-25  6:50   ` Ben Warren

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=1f37e2f7-e83e-8605-4e86-b296abcc826d@gmail.com \
    --to=tcminyard@gmail.com \
    --cc=armbru@redhat.com \
    --cc=ben@skyportsystems.com \
    --cc=den@openvz.org \
    --cc=imammedo@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=minyard@acm.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.