[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 14/32] qdev: Move UUID property to qdev-properties-system.
From: |
Igor Mammedov |
Subject: |
Re: [PATCH v4 14/32] qdev: Move UUID property to qdev-properties-system.c |
Date: |
Mon, 14 Dec 2020 15:18:54 +0100 |
On Fri, 11 Dec 2020 17:05:11 -0500
Eduardo Habkost <ehabkost@redhat.com> wrote:
> Only softmmu code uses DEFINE_PROP_UUID, and it currently depends
> on error_set_from_qdev_prop_error(). Move it to
> qdev-properties-system.c to get out of our way when refactoring
> the qdev property system.
>
> We can eventually move it back to the core property system later,
> after removing usage of error_set_from_qdev_prop_error().
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> This is a new patch added in series v2
> ---
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: "Daniel P. Berrangé" <berrange@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
> hw/core/qdev-properties-system.c | 57 ++++++++++++++++++++++++++++++++
> hw/core/qdev-properties.c | 57 --------------------------------
> 2 files changed, 57 insertions(+), 57 deletions(-)
>
> diff --git a/hw/core/qdev-properties-system.c
> b/hw/core/qdev-properties-system.c
> index 5796ed2619..7a9a1d6404 100644
> --- a/hw/core/qdev-properties-system.c
> +++ b/hw/core/qdev-properties-system.c
> @@ -21,6 +21,7 @@
> #include "qemu/ctype.h"
> #include "qemu/cutils.h"
> #include "qemu/units.h"
> +#include "qemu/uuid.h"
> #include "qemu/error-report.h"
> #include "qdev-prop-internal.h"
>
> @@ -1106,3 +1107,59 @@ const PropertyInfo qdev_prop_pcie_link_width = {
> .set = set_prop_pcielinkwidth,
> .set_default_value = qdev_propinfo_set_default_value_enum,
> };
> +
> +/* --- UUID --- */
> +
> +static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
> + Error **errp)
> +{
> + Property *prop = opaque;
> + QemuUUID *uuid = qdev_get_prop_ptr(obj, 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(obj, prop);
> + char *str;
> +
> + if (dev->realized) {
> + qdev_prop_set_after_realize(dev, name, errp);
> + return;
> + }
> +
> + if (!visit_type_str(v, name, &str, errp)) {
> + 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, obj, prop, str);
> + }
> + g_free(str);
> +}
> +
> +static void set_default_uuid_auto(ObjectProperty *op, const Property *prop)
> +{
> + object_property_set_default_str(op, UUID_VALUE_AUTO);
> +}
> +
> +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,
> +};
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 765e916c23..a2eaa43831 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -6,7 +6,6 @@
> #include "qemu/ctype.h"
> #include "qemu/error-report.h"
> #include "qapi/visitor.h"
> -#include "qemu/uuid.h"
> #include "qemu/units.h"
> #include "qemu/cutils.h"
> #include "qdev-prop-internal.h"
> @@ -544,62 +543,6 @@ const PropertyInfo qdev_prop_size32 = {
> .set_default_value = qdev_propinfo_set_default_value_uint,
> };
>
> -/* --- UUID --- */
> -
> -static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
> - Error **errp)
> -{
> - Property *prop = opaque;
> - QemuUUID *uuid = qdev_get_prop_ptr(obj, 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(obj, prop);
> - char *str;
> -
> - if (dev->realized) {
> - qdev_prop_set_after_realize(dev, name, errp);
> - return;
> - }
> -
> - if (!visit_type_str(v, name, &str, errp)) {
> - 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, obj, prop, str);
> - }
> - g_free(str);
> -}
> -
> -static void set_default_uuid_auto(ObjectProperty *op, const Property *prop)
> -{
> - object_property_set_default_str(op, UUID_VALUE_AUTO);
> -}
> -
> -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
- Re: [PATCH v4 05/32] sparc: Check dev->realized at sparc_set_nwindows(), (continued)
- [PATCH v4 07/32] qdev: Make PropertyInfo.print method get Object* argument, Eduardo Habkost, 2020/12/11
- [PATCH v4 08/32] qdev: Make bit_prop_set() get Object* argument, Eduardo Habkost, 2020/12/11
- [PATCH v4 09/32] qdev: Make qdev_get_prop_ptr() get Object* arg, Eduardo Habkost, 2020/12/11
- [PATCH v4 11/32] qdev: Make check_prop_still_unset() get Object* argument, Eduardo Habkost, 2020/12/11
- [PATCH v4 10/32] qdev: Make qdev_find_global_prop() get Object* argument, Eduardo Habkost, 2020/12/11
- [PATCH v4 12/32] qdev: Make error_set_from_qdev_prop_error() get Object* argument, Eduardo Habkost, 2020/12/11
- [PATCH v4 13/32] qdev: Make qdev_propinfo_get_uint16() static, Eduardo Habkost, 2020/12/11
- [PATCH v4 14/32] qdev: Move UUID property to qdev-properties-system.c, Eduardo Habkost, 2020/12/11
- Re: [PATCH v4 14/32] qdev: Move UUID property to qdev-properties-system.c,
Igor Mammedov <=
- [PATCH v4 16/32] qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros, Eduardo Habkost, 2020/12/11
- [PATCH v4 17/32] sparc: Use DEFINE_PROP for nwindows property, Eduardo Habkost, 2020/12/11
- Re: [PATCH v4 17/32] sparc: Use DEFINE_PROP for nwindows property, Mark Cave-Ayland, 2020/12/15
- [PATCH v4 18/32] qdev: Get just property name at error_set_from_qdev_prop_error(), Eduardo Habkost, 2020/12/11