Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging

QOM infrastructure fixes and device conversions

* Changes to name string ownership for alias properties
* Improvements around enum properties
* Cleanups around -object handling
* New helper functions
* Cleanups of qdev init helper functions
* Add path argument to qom-tree script
* QTest cleanup to use new qtest_add_data_func() consistently

# gpg: Signature made Fri Jun 19 18:14:38 2015 BST using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg:                 aka "Andreas Färber <afaerber@suse.com>"

* remotes/afaerber/tags/qom-devices-for-peter:
  qdev: Un-deprecate qdev_init_nofail()
  qdev: Deprecated qdev_init() is finally unused, drop
  qom: Don't pass string table to object_get_enum() function
  qom: Add an object_property_add_enum() helper function
  qom: Make enum string tables const-correct
  qom: Add object_new_with_props() / object_new_withpropv() helpers
  qom: Add helper function for getting user objects root
  vl: Create (most) objects before creating chardev backends
  doc: Document user creatable object types in help text
  backends: Fix typename of 'policy' enum property in hostmem obj
  scripts: Add support for path as argument of qom-tree
  tests: Use qtest_add_data_func() consistently
  qdev: Free property names after registering gpio aliases
  qom: strdup() target property name on object_property_add_alias()

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell
2015-06-22 12:50:30 +01:00
28 changed files with 837 additions and 125 deletions
+8 -14
View File
@@ -113,24 +113,17 @@ host_memory_backend_set_host_nodes(Object *obj, Visitor *v, void *opaque,
#endif
}
static void
host_memory_backend_get_policy(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
static int
host_memory_backend_get_policy(Object *obj, Error **errp G_GNUC_UNUSED)
{
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
int policy = backend->policy;
visit_type_enum(v, &policy, HostMemPolicy_lookup, NULL, name, errp);
return backend->policy;
}
static void
host_memory_backend_set_policy(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
host_memory_backend_set_policy(Object *obj, int policy, Error **errp)
{
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
int policy;
visit_type_enum(v, &policy, HostMemPolicy_lookup, NULL, name, errp);
backend->policy = policy;
#ifndef CONFIG_NUMA
@@ -252,9 +245,10 @@ static void host_memory_backend_init(Object *obj)
object_property_add(obj, "host-nodes", "int",
host_memory_backend_get_host_nodes,
host_memory_backend_set_host_nodes, NULL, NULL, NULL);
object_property_add(obj, "policy", "str",
host_memory_backend_get_policy,
host_memory_backend_set_policy, NULL, NULL, NULL);
object_property_add_enum(obj, "policy", "HostMemPolicy",
HostMemPolicy_lookup,
host_memory_backend_get_policy,
host_memory_backend_set_policy, NULL);
}
MemoryRegion *
+18 -31
View File
@@ -126,9 +126,9 @@ void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp)
qbus_set_hotplug_handler_internal(bus, OBJECT(bus), errp);
}
/* Create a new device. This only initializes the device state structure
and allows properties to be set. qdev_init should be called to
initialize the actual device emulation. */
/* Create a new device. This only initializes the device state
structure and allows properties to be set. The device still needs
to be realized. See qdev-core.h. */
DeviceState *qdev_create(BusState *bus, const char *name)
{
DeviceState *dev;
@@ -168,27 +168,6 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
return dev;
}
/* Initialize a device. Device properties should be set before calling
this function. IRQs and MMIO regions should be connected/mapped after
calling this function.
On failure, destroy the device and return negative value.
Return 0 on success. */
int qdev_init(DeviceState *dev)
{
Error *local_err = NULL;
assert(!dev->realized);
object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
if (local_err != NULL) {
qerror_report_err(local_err);
error_free(local_err);
object_unparent(OBJECT(dev));
return -1;
}
return 0;
}
static QTAILQ_HEAD(device_listeners, DeviceListener) device_listeners
= QTAILQ_HEAD_INITIALIZER(device_listeners);
@@ -364,13 +343,19 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
object_unparent(OBJECT(dev));
}
/* Like qdev_init(), but terminate program via error_report() instead of
returning an error value. This is okay during machine creation.
Don't use for hotplug, because there callers need to recover from
failure. Exception: if you know the device's init() callback can't
fail, then qdev_init_nofail() can't fail either, and is therefore
usable even then. But relying on the device implementation that
way is somewhat unclean, and best avoided. */
/*
* Realize @dev.
* Device properties should be set before calling this function. IRQs
* and MMIO regions should be connected/mapped after calling this
* function.
* On failure, report an error with error_report() and terminate the
* program. This is okay during machine creation. Don't use for
* hotplug, because there callers need to recover from failure.
* Exception: if you know the device's init() callback can't fail,
* then qdev_init_nofail() can't fail either, and is therefore usable
* even then. But relying on the device implementation that way is
* somewhat unclean, and best avoided.
*/
void qdev_init_nofail(DeviceState *dev)
{
Error *err = NULL;
@@ -563,6 +548,7 @@ void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
object_property_add_alias(OBJECT(container), propname,
OBJECT(dev), propname,
&error_abort);
g_free(propname);
}
for (i = 0; i < ngl->num_out; i++) {
const char *nm = ngl->name ? ngl->name : "unnamed-gpio-out";
@@ -571,6 +557,7 @@ void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
object_property_add_alias(OBJECT(container), propname,
OBJECT(dev), propname,
&error_abort);
g_free(propname);
}
QLIST_REMOVE(ngl, node);
QLIST_INSERT_HEAD(&container->gpios, ngl, node);
+3 -4
View File
@@ -65,8 +65,8 @@ struct VMStateDescription;
* Operations depending on @props static properties should go into @realize.
* After successful realization, setting static properties will fail.
*
* As an interim step, the #DeviceState:realized property is set by deprecated
* functions qdev_init() and qdev_init_nofail().
* As an interim step, the #DeviceState:realized property can also be
* set with qdev_init_nofail().
* In the future, devices will propagate this state change to their children
* and along busses they expose.
* The point in time will be deferred to machine creation, so that values
@@ -236,7 +236,7 @@ struct Property {
struct PropertyInfo {
const char *name;
const char *description;
const char **enum_table;
const char * const *enum_table;
int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
ObjectPropertyAccessor *get;
ObjectPropertyAccessor *set;
@@ -262,7 +262,6 @@ typedef struct GlobalProperty {
DeviceState *qdev_create(BusState *bus, const char *name);
DeviceState *qdev_try_create(BusState *bus, const char *name);
int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
void qdev_init_nofail(DeviceState *dev);
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
int required_for_version);
+1 -1
View File
@@ -11,7 +11,7 @@
#ifndef QAPI_UTIL_H
#define QAPI_UTIL_H
int qapi_enum_parse(const char *lookup[], const char *buf,
int qapi_enum_parse(const char * const lookup[], const char *buf,
int max, int def, Error **errp);
#endif
+3 -3
View File
@@ -30,7 +30,7 @@ struct Visitor
GenericList *(*next_list)(Visitor *v, GenericList **list, Error **errp);
void (*end_list)(Visitor *v, Error **errp);
void (*type_enum)(Visitor *v, int *obj, const char *strings[],
void (*type_enum)(Visitor *v, int *obj, const char * const strings[],
const char *kind, const char *name, Error **errp);
void (*get_next_type)(Visitor *v, int *kind, const int *qobjects,
const char *name, Error **errp);
@@ -59,9 +59,9 @@ struct Visitor
void (*end_union)(Visitor *v, bool data_present, Error **errp);
};
void input_type_enum(Visitor *v, int *obj, const char *strings[],
void input_type_enum(Visitor *v, int *obj, const char * const strings[],
const char *kind, const char *name, Error **errp);
void output_type_enum(Visitor *v, int *obj, const char *strings[],
void output_type_enum(Visitor *v, int *obj, const char * const strings[],
const char *kind, const char *name, Error **errp);
#endif
+1 -1
View File
@@ -43,7 +43,7 @@ void visit_optional(Visitor *v, bool *present, const char *name,
Error **errp);
void visit_get_next_type(Visitor *v, int *obj, const int *qtypes,
const char *name, Error **errp);
void visit_type_enum(Visitor *v, int *obj, const char *strings[],
void visit_type_enum(Visitor *v, int *obj, const char * const strings[],
const char *kind, const char *name, Error **errp);
void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp);
void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp);
+6
View File
@@ -24,6 +24,12 @@
#define QEMU_WARN_UNUSED_RESULT
#endif
#if QEMU_GNUC_PREREQ(4, 0)
#define QEMU_SENTINEL __attribute__((sentinel))
#else
#define QEMU_SENTINEL
#endif
#if QEMU_GNUC_PREREQ(4, 3)
#define QEMU_ARTIFICIAL __attribute__((always_inline, artificial))
#else
+161 -2
View File
@@ -606,6 +606,134 @@ Object *object_new(const char *typename);
*/
Object *object_new_with_type(Type type);
/**
* object_new_with_props:
* @typename: The name of the type of the object to instantiate.
* @parent: the parent object
* @id: The unique ID of the object
* @errp: pointer to error object
* @...: list of property names and values
*
* This function will initialize a new object using heap allocated memory.
* The returned object has a reference count of 1, and will be freed when
* the last reference is dropped.
*
* The @id parameter will be used when registering the object as a
* child of @parent in the composition tree.
*
* The variadic parameters are a list of pairs of (propname, propvalue)
* strings. The propname of %NULL indicates the end of the property
* list. If the object implements the user creatable interface, the
* object will be marked complete once all the properties have been
* processed.
*
* <example>
* <title>Creating an object with properties</title>
* <programlisting>
* Error *err = NULL;
* Object *obj;
*
* obj = object_new_with_props(TYPE_MEMORY_BACKEND_FILE,
* object_get_objects_root(),
* "hostmem0",
* &err,
* "share", "yes",
* "mem-path", "/dev/shm/somefile",
* "prealloc", "yes",
* "size", "1048576",
* NULL);
*
* if (!obj) {
* g_printerr("Cannot create memory backend: %s\n",
* error_get_pretty(err));
* }
* </programlisting>
* </example>
*
* The returned object will have one stable reference maintained
* for as long as it is present in the object hierarchy.
*
* Returns: The newly allocated, instantiated & initialized object.
*/
Object *object_new_with_props(const char *typename,
Object *parent,
const char *id,
Error **errp,
...) QEMU_SENTINEL;
/**
* object_new_with_propv:
* @typename: The name of the type of the object to instantiate.
* @parent: the parent object
* @id: The unique ID of the object
* @errp: pointer to error object
* @vargs: list of property names and values
*
* See object_new_with_props() for documentation.
*/
Object *object_new_with_propv(const char *typename,
Object *parent,
const char *id,
Error **errp,
va_list vargs);
/**
* object_set_props:
* @obj: the object instance to set properties on
* @errp: pointer to error object
* @...: list of property names and values
*
* This function will set a list of properties on an existing object
* instance.
*
* The variadic parameters are a list of pairs of (propname, propvalue)
* strings. The propname of %NULL indicates the end of the property
* list.
*
* <example>
* <title>Update an object's properties</title>
* <programlisting>
* Error *err = NULL;
* Object *obj = ...get / create object...;
*
* obj = object_set_props(obj,
* &err,
* "share", "yes",
* "mem-path", "/dev/shm/somefile",
* "prealloc", "yes",
* "size", "1048576",
* NULL);
*
* if (!obj) {
* g_printerr("Cannot set properties: %s\n",
* error_get_pretty(err));
* }
* </programlisting>
* </example>
*
* The returned object will have one stable reference maintained
* for as long as it is present in the object hierarchy.
*
* Returns: -1 on error, 0 on success
*/
int object_set_props(Object *obj,
Error **errp,
...) QEMU_SENTINEL;
/**
* object_set_propv:
* @obj: the object instance to set properties on
* @errp: pointer to error object
* @vargs: list of property names and values
*
* See object_set_props() for documentation.
*
* Returns: -1 on error, 0 on success
*/
int object_set_propv(Object *obj,
Error **errp,
va_list vargs);
/**
* object_initialize_with_type:
* @data: A pointer to the memory to be used for the object.
@@ -945,7 +1073,7 @@ int64_t object_property_get_int(Object *obj, const char *name,
* object_property_get_enum:
* @obj: the object
* @name: the name of the property
* @strings: strings corresponding to enums
* @typename: the name of the enum data type
* @errp: returns an error if this function fails
*
* Returns: the value of the property, converted to an integer, or
@@ -953,7 +1081,7 @@ int64_t object_property_get_int(Object *obj, const char *name,
* an enum).
*/
int object_property_get_enum(Object *obj, const char *name,
const char *strings[], Error **errp);
const char *typename, Error **errp);
/**
* object_property_get_uint16List:
@@ -1026,6 +1154,18 @@ const char *object_property_get_type(Object *obj, const char *name,
*/
Object *object_get_root(void);
/**
* object_get_objects_root:
*
* Get the container object that holds user created
* object instances. This is the object at path
* "/objects"
*
* Returns: the user object container
*/
Object *object_get_objects_root(void);
/**
* object_get_canonical_path_component:
*
@@ -1203,6 +1343,25 @@ void object_property_add_bool(Object *obj, const char *name,
void (*set)(Object *, bool, Error **),
Error **errp);
/**
* object_property_add_enum:
* @obj: the object to add a property to
* @name: the name of the property
* @typename: the name of the enum data type
* @get: the getter or %NULL if the property is write-only.
* @set: the setter or %NULL if the property is read-only
* @errp: if an error occurs, a pointer to an area to store the error
*
* Add an enum property using getters/setters. This function will add a
* property of type '@typename'.
*/
void object_property_add_enum(Object *obj, const char *name,
const char *typename,
const char * const *strings,
int (*get)(Object *, Error **),
void (*set)(Object *, int, Error **),
Error **errp);
/**
* object_property_add_tm:
* @obj: the object to add a property to
+1 -3
View File
@@ -19,8 +19,6 @@
#include "qmp-commands.h"
#include "qemu/error-report.h"
#define IOTHREADS_PATH "/objects"
typedef ObjectClass IOThreadClass;
#define IOTHREAD_GET_CLASS(obj) \
@@ -160,7 +158,7 @@ IOThreadInfoList *qmp_query_iothreads(Error **errp)
{
IOThreadInfoList *head = NULL;
IOThreadInfoList **prev = &head;
Object *container = container_get(object_get_root(), IOTHREADS_PATH);
Object *container = object_get_objects_root();
object_child_foreach(container, query_one_iothread, &prev);
return head;
+2 -2
View File
@@ -456,7 +456,7 @@ static int query_memdev(Object *obj, void *opaque)
m->value->policy = object_property_get_enum(obj,
"policy",
HostMemPolicy_lookup,
"HostMemPolicy",
&err);
if (err) {
goto error;
@@ -485,7 +485,7 @@ MemdevList *qmp_query_memdev(Error **errp)
Object *obj;
MemdevList *list = NULL;
obj = object_resolve_path("/objects", NULL);
obj = object_get_objects_root();
if (obj == NULL) {
return NULL;
}
+2 -1
View File
@@ -156,7 +156,8 @@ static void qapi_dealloc_type_size(Visitor *v, uint64_t *obj, const char *name,
{
}
static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[],
static void qapi_dealloc_type_enum(Visitor *v, int *obj,
const char * const strings[],
const char *kind, const char *name,
Error **errp)
{
+1 -1
View File
@@ -14,7 +14,7 @@
#include "qapi/error.h"
#include "qapi/util.h"
int qapi_enum_parse(const char *lookup[], const char *buf,
int qapi_enum_parse(const char * const lookup[], const char *buf,
int max, int def, Error **errp)
{
int i;
+3 -3
View File
@@ -89,7 +89,7 @@ void visit_get_next_type(Visitor *v, int *obj, const int *qtypes,
}
}
void visit_type_enum(Visitor *v, int *obj, const char *strings[],
void visit_type_enum(Visitor *v, int *obj, const char * const strings[],
const char *kind, const char *name, Error **errp)
{
v->type_enum(v, obj, strings, kind, name, errp);
@@ -260,7 +260,7 @@ void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp)
v->type_number(v, obj, name, errp);
}
void output_type_enum(Visitor *v, int *obj, const char *strings[],
void output_type_enum(Visitor *v, int *obj, const char * const strings[],
const char *kind, const char *name,
Error **errp)
{
@@ -279,7 +279,7 @@ void output_type_enum(Visitor *v, int *obj, const char *strings[],
visit_type_str(v, &enum_str, name, errp);
}
void input_type_enum(Visitor *v, int *obj, const char *strings[],
void input_type_enum(Visitor *v, int *obj, const char * const strings[],
const char *kind, const char *name,
Error **errp)
{
+54 -16
View File
@@ -3487,22 +3487,6 @@ DEF("no-kvm-irqchip", 0, QEMU_OPTION_no_kvm_irqchip, "", QEMU_ARCH_I386)
HXCOMM Deprecated (ignored)
DEF("tdf", 0, QEMU_OPTION_tdf,"", QEMU_ARCH_ALL)
DEF("object", HAS_ARG, QEMU_OPTION_object,
"-object TYPENAME[,PROP1=VALUE1,...]\n"
" create an new object of type TYPENAME setting properties\n"
" in the order they are specified. Note that the 'id'\n"
" property must be set. These objects are placed in the\n"
" '/objects' path.\n",
QEMU_ARCH_ALL)
STEXI
@item -object @var{typename}[,@var{prop1}=@var{value1},...]
@findex -object
Create an new object of type @var{typename} setting properties
in the order they are specified. Note that the 'id'
property must be set. These objects are placed in the
'/objects' path.
ETEXI
DEF("msg", HAS_ARG, QEMU_OPTION_msg,
"-msg timestamp[=on|off]\n"
" change the format of messages\n"
@@ -3528,6 +3512,60 @@ Dump json-encoded vmstate information for current machine type to file
in @var{file}
ETEXI
DEFHEADING(Generic object creation)
DEF("object", HAS_ARG, QEMU_OPTION_object,
"-object TYPENAME[,PROP1=VALUE1,...]\n"
" create a new object of type TYPENAME setting properties\n"
" in the order they are specified. Note that the 'id'\n"
" property must be set. These objects are placed in the\n"
" '/objects' path.\n",
QEMU_ARCH_ALL)
STEXI
@item -object @var{typename}[,@var{prop1}=@var{value1},...]
@findex -object
Create a new object of type @var{typename} setting properties
in the order they are specified. Note that the 'id'
property must be set. These objects are placed in the
'/objects' path.
@table @option
@item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
Creates a memory file backend object, which can be used to back
the guest RAM with huge pages. The @option{id} parameter is a
unique ID that will be used to reference this memory region
when configuring the @option{-numa} argument. The @option{size}
option provides the size of the memory region, and accepts
common suffixes, eg @option{500M}. The @option{mem-path} provides
the path to either a shared memory or huge page filesystem mount.
The @option{share} boolean option determines whether the memory
region is marked as private to QEMU, or shared. The latter allows
a co-operating external process to access the QEMU memory region.
@item -object rng-random,id=@var{id},filename=@var{/dev/random}
Creates a random number generator backend which obtains entropy from
a device on the host. The @option{id} parameter is a unique ID that
will be used to reference this entropy backend from the @option{virtio-rng}
device. The @option{filename} parameter specifies which file to obtain
entropy from and if omitted defaults to @option{/dev/random}.
@item -object rng-egd,id=@var{id},chardev=@var{chardevid}
Creates a random number generator backend which obtains entropy from
an external daemon running on the host. The @option{id} parameter is
a unique ID that will be used to reference this entropy backend from
the @option{virtio-rng} device. The @option{chardev} parameter is
the unique ID of a character device backend that provides the connection
to the RNG daemon.
@end table
ETEXI
HXCOMM This is the last statement. Insert new options before this line!
STEXI
@end table
+3 -3
View File
@@ -651,7 +651,7 @@ void object_add(const char *type, const char *id, const QDict *qdict,
}
}
object_property_add_child(container_get(object_get_root(), "/objects"),
object_property_add_child(object_get_objects_root(),
id, obj, &local_err);
if (local_err) {
goto out;
@@ -659,7 +659,7 @@ void object_add(const char *type, const char *id, const QDict *qdict,
user_creatable_complete(obj, &local_err);
if (local_err) {
object_property_del(container_get(object_get_root(), "/objects"),
object_property_del(object_get_objects_root(),
id, &error_abort);
goto out;
}
@@ -706,7 +706,7 @@ void qmp_object_del(const char *id, Error **errp)
Object *container;
Object *obj;
container = container_get(object_get_root(), "/objects");
container = object_get_objects_root();
obj = object_resolve_path_component(container, id);
if (!obj) {
error_setg(errp, "object id not found");
+192 -4
View File
@@ -11,6 +11,7 @@
*/
#include "qom/object.h"
#include "qom/object_interfaces.h"
#include "qemu-common.h"
#include "qapi/visitor.h"
#include "qapi-visit.h"
@@ -439,6 +440,114 @@ Object *object_new(const char *typename)
return object_new_with_type(ti);
}
Object *object_new_with_props(const char *typename,
Object *parent,
const char *id,
Error **errp,
...)
{
va_list vargs;
Object *obj;
va_start(vargs, errp);
obj = object_new_with_propv(typename, parent, id, errp, vargs);
va_end(vargs);
return obj;
}
Object *object_new_with_propv(const char *typename,
Object *parent,
const char *id,
Error **errp,
va_list vargs)
{
Object *obj;
ObjectClass *klass;
Error *local_err = NULL;
klass = object_class_by_name(typename);
if (!klass) {
error_setg(errp, "invalid object type: %s", typename);
return NULL;
}
if (object_class_is_abstract(klass)) {
error_setg(errp, "object type '%s' is abstract", typename);
return NULL;
}
obj = object_new(typename);
if (object_set_propv(obj, &local_err, vargs) < 0) {
goto error;
}
object_property_add_child(parent, id, obj, &local_err);
if (local_err) {
goto error;
}
if (object_dynamic_cast(obj, TYPE_USER_CREATABLE)) {
user_creatable_complete(obj, &local_err);
if (local_err) {
object_unparent(obj);
goto error;
}
}
object_unref(OBJECT(obj));
return obj;
error:
if (local_err) {
error_propagate(errp, local_err);
}
object_unref(obj);
return NULL;
}
int object_set_props(Object *obj,
Error **errp,
...)
{
va_list vargs;
int ret;
va_start(vargs, errp);
ret = object_set_propv(obj, errp, vargs);
va_end(vargs);
return ret;
}
int object_set_propv(Object *obj,
Error **errp,
va_list vargs)
{
const char *propname;
Error *local_err = NULL;
propname = va_arg(vargs, char *);
while (propname != NULL) {
const char *value = va_arg(vargs, char *);
g_assert(value != NULL);
object_property_parse(obj, value, propname, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return -1;
}
propname = va_arg(vargs, char *);
}
return 0;
}
Object *object_dynamic_cast(Object *obj, const char *typename)
{
if (obj && object_class_dynamic_cast(object_get_class(obj), typename)) {
@@ -960,13 +1069,34 @@ int64_t object_property_get_int(Object *obj, const char *name,
return retval;
}
typedef struct EnumProperty {
const char * const *strings;
int (*get)(Object *, Error **);
void (*set)(Object *, int, Error **);
} EnumProperty;
int object_property_get_enum(Object *obj, const char *name,
const char *strings[], Error **errp)
const char *typename, Error **errp)
{
StringOutputVisitor *sov;
StringInputVisitor *siv;
char *str;
int ret;
ObjectProperty *prop = object_property_find(obj, name, errp);
EnumProperty *enumprop;
if (prop == NULL) {
return 0;
}
if (!g_str_equal(prop->type, typename)) {
error_setg(errp, "Property %s on %s is not '%s' enum type",
name, object_class_get_name(
object_get_class(obj)), typename);
return 0;
}
enumprop = prop->opaque;
sov = string_output_visitor_new(false);
object_property_get(obj, string_output_get_visitor(sov), name, errp);
@@ -974,7 +1104,7 @@ int object_property_get_enum(Object *obj, const char *name,
siv = string_input_visitor_new(str);
string_output_visitor_cleanup(sov);
visit_type_enum(string_input_get_visitor(siv),
&ret, strings, NULL, name, errp);
&ret, enumprop->strings, NULL, name, errp);
g_free(str);
string_input_visitor_cleanup(siv);
@@ -1054,6 +1184,11 @@ Object *object_get_root(void)
return root;
}
Object *object_get_objects_root(void)
{
return container_get(object_get_root(), "/objects");
}
static void object_get_child_property(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
@@ -1559,6 +1694,58 @@ void object_property_add_bool(Object *obj, const char *name,
}
}
static void property_get_enum(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
EnumProperty *prop = opaque;
int value;
value = prop->get(obj, errp);
visit_type_enum(v, &value, prop->strings, NULL, name, errp);
}
static void property_set_enum(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
EnumProperty *prop = opaque;
int value;
visit_type_enum(v, &value, prop->strings, NULL, name, errp);
prop->set(obj, value, errp);
}
static void property_release_enum(Object *obj, const char *name,
void *opaque)
{
EnumProperty *prop = opaque;
g_free(prop);
}
void object_property_add_enum(Object *obj, const char *name,
const char *typename,
const char * const *strings,
int (*get)(Object *, Error **),
void (*set)(Object *, int, Error **),
Error **errp)
{
Error *local_err = NULL;
EnumProperty *prop = g_malloc(sizeof(*prop));
prop->strings = strings;
prop->get = get;
prop->set = set;
object_property_add(obj, name, typename,
get ? property_get_enum : NULL,
set ? property_set_enum : NULL,
property_release_enum,
prop, &local_err);
if (local_err) {
error_propagate(errp, local_err);
g_free(prop);
}
}
typedef struct TMProperty {
void (*get)(Object *, struct tm *, Error **);
} TMProperty;
@@ -1705,7 +1892,7 @@ void object_property_add_uint64_ptr(Object *obj, const char *name,
typedef struct {
Object *target_obj;
const char *target_name;
char *target_name;
} AliasProperty;
static void property_get_alias(Object *obj, struct Visitor *v, void *opaque,
@@ -1736,6 +1923,7 @@ static void property_release_alias(Object *obj, const char *name, void *opaque)
{
AliasProperty *prop = opaque;
g_free(prop->target_name);
g_free(prop);
}
@@ -1763,7 +1951,7 @@ void object_property_add_alias(Object *obj, const char *name,
prop = g_malloc(sizeof(*prop));
prop->target_obj = target_obj;
prop->target_name = target_name;
prop->target_name = g_strdup(target_name);
op = object_property_add(obj, name, prop_type,
property_get_alias,
+2 -2
View File
@@ -105,7 +105,7 @@ struct %(name)s
def generate_enum_lookup(name, values):
ret = mcgen('''
const char *%(name)s_lookup[] = {
const char * const %(name)s_lookup[] = {
''',
name=c_name(name))
i = 0
@@ -128,7 +128,7 @@ const char *%(name)s_lookup[] = {
def generate_enum(name, values):
name = c_name(name)
lookup_decl = mcgen('''
extern const char *%(name)s_lookup[];
extern const char * const %(name)s_lookup[];
''',
name=name)
+7 -2
View File
@@ -65,6 +65,11 @@ def list_node(path):
print ''
for item in items:
if item['type'].startswith('child<'):
list_node(path + '/' + item['name'])
list_node((path if (path != '/') else '') + '/' + item['name'])
list_node('/machine')
if len(args) == 0:
path = '/'
else:
path = args[0]
list_node(path)
+1
View File
@@ -5,6 +5,7 @@ check-qjson
check-qlist
check-qstring
check-qom-interface
check-qom-proplist
rcutorture
test-aio
test-bitops
+4 -1
View File
@@ -68,6 +68,8 @@ check-unit-y += tests/test-bitops$(EXESUF)
check-unit-$(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) += tests/test-qdev-global-props$(EXESUF)
check-unit-y += tests/check-qom-interface$(EXESUF)
gcov-files-check-qom-interface-y = qom/object.c
check-unit-y += tests/check-qom-proplist$(EXESUF)
gcov-files-check-qom-proplist-y = qom/object.c
check-unit-y += tests/test-qemu-opts$(EXESUF)
gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c
check-unit-y += tests/test-write-threshold$(EXESUF)
@@ -267,7 +269,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
$(test-obj-y): QEMU_INCLUDES += -Itests
QEMU_CFLAGS += -I$(SRC_PATH)/tests
qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o
qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o qom/object_interfaces.o
tests/check-qint$(EXESUF): tests/check-qint.o libqemuutil.a
tests/check-qstring$(EXESUF): tests/check-qstring.o libqemuutil.a
@@ -276,6 +278,7 @@ tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a
tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a
tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a
tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(qom-core-obj) libqemuutil.a libqemustub.a
tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(qom-core-obj) libqemuutil.a libqemustub.a
tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) libqemuutil.a libqemustub.a
tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a libqemustub.a
tests/test-rfifolock$(EXESUF): tests/test-rfifolock.o libqemuutil.a libqemustub.a

Some files were not shown because too many files have changed in this diff Show More