qdev: Move UUID property to qdev-properties-system.c
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> Message-Id: <20201211220529.2290218-15-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
364f7e833d
commit
38255efffe
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue