QOM devices patch queue 2015-06-19
Hello Peter,
This is my QOM (devices) patch queue. Please pull.
v3 reverts use of GLib macros in v2 and adds three commits.
Regards,
Andreas
The following changes since commit 8ffe756da0481233e1bd518b2b16489f51856292:
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2015-06-18' into staging (2015-06-18 13:32:39 +0100)
are available in the git repository at:
git://github.com/afaerber/qemu-cpu.git tags/qom-devices-for-peter
for you to fetch changes up to daeba9699d41ad79e2f3d34acea9c85c5d67a2ac:
qdev: Un-deprecate qdev_init_nofail() (2015-06-19 19:14:32 +0200)
----------------------------------------------------------------
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
----------------------------------------------------------------
Andreas Färber (1):
tests: Use qtest_add_data_func() consistently
Daniel P. Berrange (8):
backends: Fix typename of 'policy' enum property in hostmem obj
doc: Document user creatable object types in help text
vl: Create (most) objects before creating chardev backends
qom: Add helper function for getting user objects root
qom: Add object_new_with_props() / object_new_withpropv() helpers
qom: Make enum string tables const-correct
qom: Add an object_property_add_enum() helper function
qom: Don't pass string table to object_get_enum() function
Eduardo Habkost (2):
qom: strdup() target property name on object_property_add_alias()
qdev: Free property names after registering gpio aliases
Markus Armbruster (2):
qdev: Deprecated qdev_init() is finally unused, drop
qdev: Un-deprecate qdev_init_nofail()
Martin Cerveny (1):
scripts: Add support for path as argument of qom-tree
backends/hostmem.c | 22 ++-- hw/core/qdev.c | 49 +++---- include/hw/qdev-core.h | 7 +- include/qapi/util.h | 2 +- include/qapi/visitor-impl.h | 6 +- include/qapi/visitor.h | 2 +- include/qemu/compiler.h | 6 + include/qom/object.h | 163 +++++++++++++++++++++++- iothread.c | 4 +- numa.c | 4 +- qapi/qapi-dealloc-visitor.c | 3 +- qapi/qapi-util.c | 2 +- qapi/qapi-visit-core.c | 6 +- qemu-options.hx | 70 +++++++--- qmp.c | 6 +- qom/object.c | 196 +++++++++++++++++++++++++++- scripts/qapi-types.py | 4 +- scripts/qmp/qom-tree | 9 +- tests/.gitignore | 1 + tests/Makefile | 5 +- tests/ahci-test.c | 9 +- tests/check-qom-proplist.c | 302 ++++++++++++++++++++++++++++++++++++++++++++ tests/e1000-test.c | 4 +- tests/eepro100-test.c | 5 +- tests/endianness-test.c | 18 +-- tests/pc-cpu-test.c | 13 +- tests/qom-test.c | 4 +- vl.c | 40 +++++- 28 files changed, 837 insertions(+), 125 deletions(-) create mode 100644 tests/check-qom-proplist.c
[Qemu-devel] [PULL v3 14/14] qdev: Un-deprecate qdev_init_nofail()
From: Markus Armbruster <[email protected]>
It's a perfectly sensible helper function.
--- include/hw/qdev-core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/hw/qdev-core.h +2 -2
@@ -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 -* function 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
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 05/14] backends: Fix typename of 'policy' enum property in hostmem obj
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
The 'policy' property was being registered with a typename of 'str', but it is in fact an enum of the 'HostMemPolicy' type.
--- backends/hostmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
backends/hostmem.c +1 -1
@@ -252,7 +252,7 @@ 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" , +object_property_add (obj,"policy" ,"HostMemPolicy" , host_memory_backend_get_policy, host_memory_backend_set_policy,NULL ,NULL ,NULL ); }
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 10/14] qom: Make enum string tables const-correct
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
The enum string table parameters in various QOM/QAPI methods are declared 'const char *strings[]'. This results in const warnings if passed a variable that was declared as
static const char * const strings[] = { .... };Add the extra const annotation to the parameters, since neither the string elements, nor the array itself should ever be modified.
--- include/hw/qdev-core.h | 2 +- include/qapi/util.h | 2 +- include/qapi/visitor-impl.h | 6 +++--- include/qapi/visitor.h | 2 +- include/qom/object.h | 2 +- qapi/qapi-dealloc-visitor.c | 3 ++- qapi/qapi-util.c | 2 +- qapi/qapi-visit-core.c | 6 +++--- qom/object.c | 2 +- scripts/qapi-types.py | 4 ++-- 10 files changed, 16 insertions(+), 15 deletions(-)
include/hw/qdev-core.h +1 -1
@@ -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;
include/qapi/util.h +1 -1
@@ -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
include/qapi/visitor-impl.h +3 -3
@@ -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
include/qapi/visitor.h +1 -1
@@ -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);
include/qom/object.h +1 -1
@@ -1081,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 *const strings[],Error **errp);/** * object_property_get_uint16List:
qapi/qapi-dealloc-visitor.c +2 -1
@@ -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) {
qapi/qapi-util.c +1 -1
@@ -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;
qapi/qapi-visit-core.c +3 -3
@@ -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) {
qom/object.c +1 -1
@@ -1070,7 +1070,7 @@ int64_t object_property_get_int(Object *obj, const char *name, }int object_property_get_enum (Object *obj,const char *name, -const char *strings[],Error **errp) +const char *const strings[],Error **errp) {StringOutputVisitor *sov;StringInputVisitor *siv;
scripts/qapi-types.py +2 -2
@@ -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)
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 11/14] qom: Add an object_property_add_enum() helper function
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
A QOM property can be parsed as enum using the visit_type_enum() helper function, but this forces callers to use the more complex generic object_property_add() method when registering it. It also requires that users of that object have access to the string map when they want to read the property value.
This patch introduces a specialized object_property_add_enum() method which simplifies the use of enum properties, so the setters/getters directly get passed the int value.
typedef enum {
MYDEV_TYPE_FROG,
MYDEV_TYPE_ALLIGATOR,
MYDEV_TYPE_PLATYPUS, MYDEV_TYPE_LAST
} MyDevType;
Then provide a table of enum <-> string mappings
static const char *const mydevtypemap[MYDEV_TYPE_LAST + 1] = {
[MYDEV_TYPE_FROG] = "frog",
[MYDEV_TYPE_ALLIGATOR] = "alligator",
[MYDEV_TYPE_PLATYPUS] = "platypus",
[MYDEV_TYPE_LAST] = NULL,
};Assuming an object struct of
typedef struct {
Object parent_obj;
MyDevType devtype;
...other fields...
} MyDev;The property can then be registered as follows:
static int mydev_prop_get_devtype(Object *obj,
Error **errp G_GNUC_UNUSED)
{
MyDev *dev = MYDEV(obj);return dev->devtype;
}
static void mydev_prop_set_devtype(Object *obj,
int value,
Error **errp G_GNUC_UNUSED)
{
MyDev *dev = MYDEV(obj);dev->devtype = value;
}
object_property_add_enum(obj, "devtype",
mydevtypemap, "MyDevType",
mydev_prop_get_devtype,
mydev_prop_set_devtype,
NULL);Note there is no need to check the range of 'value' in the setter, because the string->enum conversion code will have already done that and reported an error as required.
--- include/qom/object.h | 19 ++++++++++++ qom/object.c | 58 ++++++++++++++++++++++++++++++++++++ tests/check-qom-proplist.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+)
include/qom/object.h +19 -0
@@ -1344,6 +1344,25 @@ void object_property_add_bool(Object *obj, const char *name, 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 * @name: the name of the property
qom/object.c +58 -0
70 lines not on this page · raw message
tests/check-qom-proplist.c +73 -0
129 lines not on this page · raw message
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 12/14] qom: Don't pass string table to object_get_enum() function
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
Now that properties can be explicitly registered as an enum type, there is no need to pass the string table to the object_get_enum() function. The object property registration already has a pointer to the string table.
In changing this method signature, the hostmem backend object has to be converted to use the new enum property registration code, which simplifies it somewhat.
--- backends/hostmem.c | 22 ++++++++-------------- include/qom/object.h | 4 ++-- numa.c | 2 +- qom/object.c | 19 +++++++++++++++++-- tests/check-qom-proplist.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 19 deletions(-)
backends/hostmem.c +8 -14
@@ -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" ,"HostMemPolicy" , - 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 *
include/qom/object.h +2 -2
@@ -1073,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
@@ -1081,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 *const strings[],Error **errp); +const char *typename,Error **errp);/** * object_property_get_uint16List:
numa.c +1 -1
@@ -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;
qom/object.c +17 -2
@@ -1076,12 +1076,27 @@ typedef struct EnumProperty { } EnumProperty;int object_property_get_enum (Object *obj,const char *name, -const char *const 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);
@@ -1089,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);
tests/check-qom-proplist.c +43 -0
55 lines not on this page · raw message
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 13/14] qdev: Deprecated qdev_init() is finally unused, drop
In reply to Andreas FärberFrom: Markus Armbruster <[email protected]>
qdev_init() is a wrapper around setting property "realized" to true, plus error handling that passes errors to qerror_report_err(). qerror_report_err() is a transitional interface to help with converting existing monitor commands to QMP. It should not be used elsewhere.
All code has been modernized to avoid qdev_init() and its inappropriate error handling. We can finally drop it.
--- hw/core/qdev.c | 47 ++++++++++++++++------------------------------- include/hw/qdev-core.h | 3 +-- 2 files changed, 17 insertions(+), 33 deletions(-)
hw/core/qdev.c +16 -31
@@ -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 ;
include/hw/qdev-core.h +1 -2
@@ -66,7 +66,7 @@ struct VMStateDescription;* 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(). +* function 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
@@ -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);
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 01/14] qom: strdup() target property name on object_property_add_alias()
In reply to Andreas FärberFrom: Eduardo Habkost <[email protected]>
With this, object_property_add_alias() callers can safely free the target property name, like what already happens with the 'name' argument to all object_property_add*() functions.
--- qom/object.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
qom/object.c +3 -2
@@ -1705,7 +1705,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 +1736,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 +1764,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,
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 02/14] qdev: Free property names after registering gpio aliases
In reply to Andreas FärberFrom: Eduardo Habkost <[email protected]>
Now that object_property_add_alias() strdup()s target_name, we can free the property names in qdev_pass_gpios().
--- hw/core/qdev.c | 2 ++ 1 file changed, 2 insertions(+)
hw/core/qdev.c +2 -0
@@ -563,6 +563,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 +572,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);
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 06/14] doc: Document user creatable object types in help text
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
The QEMU help for -object is essentially useless, just giving users the generic syntax. Move it down into its own section and introduce a nested table where each user creatable object can be documented. The existing memory-backend-file, rng-random and rng-egd object types are documented.
--- qemu-options.hx | 70 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 16 deletions(-)
qemu-options.hx +54 -16
@@ -3476,22 +3476,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"
@@ -3517,6 +3501,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
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 07/14] vl: Create (most) objects before creating chardev backends
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
Some types of object must be created before chardevs, other types of object must be created after chardevs. As such there is no option but to create objects in two phases.
This takes the decision to create as many object types as possible right away before anyother backends are created, and only delay creation of those few which have an explicit dependency on the chardevs. Hopefully the set which need delaying will remain small over time.
--- vl.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
vl.c +39 -1
@@ -2671,6 +2671,33 @@ static int machine_set_property(void *opaque,return 0 ; } + +/* +* Initial object creation happens before all other +* QEMU data types are created. The majority of objects +* can be created at this point. The rng-egd object +* cannot be created here, as it depends on the chardev +* already existing. +*/ +static bool object_create_initial (const char *type) +{ +if (g_str_equal (type,"rng-egd" )) { +return false; + } +return true; +} + + +/* +* The remainder of object creation happens after the +* creation of chardev, fsdev and device data types. +*/ +static bool object_create_delayed (const char *type) +{ +return !object_create_initial (type); +} + +static int object_create (void *opaque,QemuOpts *opts,Error **errp) {Error *err =NULL ;
@@ -2679,6 +2706,7 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp)void *dummy =NULL ;OptsVisitor *ov;QDict *pdict; +bool (*type_predicate)(const char *) = opaque; ov =opts_visitor_new (opts); pdict =qemu_opts_to_qdict (opts,NULL );
@@ -2693,6 +2721,9 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp)if (err) { goto out; } +if (!type_predicate (type)) { + goto out; + }qdict_del (pdict,"id" );visit_type_str (opts_get_visitor (ov), &id,"id" , &err);
@@ -4114,6 +4145,12 @@ int main(int argc, char **argv, char **envp)socket_init (); +if (qemu_opts_foreach (qemu_find_opts ("object" ), + object_create, + object_create_initial,NULL )) { +exit (1 ); + } +if (qemu_opts_foreach (qemu_find_opts ("chardev" ), chardev_init_func,NULL ,NULL )) {exit (1 );
@@ -4137,7 +4174,8 @@ int main(int argc, char **argv, char **envp) }if (qemu_opts_foreach (qemu_find_opts ("object" ), - object_create,NULL ,NULL )) { + object_create, + object_create_delayed,NULL )) {exit (1 ); }
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 08/14] qom: Add helper function for getting user objects root
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
Add object_get_objects_root() function which is a convenience for obtaining the Object * located at /objects in the object composition tree. Convert existing code over to use the new API where appropriate.
--- include/qom/object.h | 12 ++++++++++++ iothread.c | 4 +--- numa.c | 2 +- qmp.c | 6 +++--- qom/object.c | 5 +++++ 5 files changed, 22 insertions(+), 7 deletions(-)
include/qom/object.h +12 -0
@@ -1026,6 +1026,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: *
iothread.c +1 -3
@@ -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;
numa.c +1 -1
@@ -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 ; }
qmp.c +3 -3
@@ -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" );
qom/object.c +5 -0
@@ -1054,6 +1054,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) {
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 09/14] qom: Add object_new_with_props() / object_new_withpropv() helpers
In reply to Andreas FärberFrom: "Daniel P. Berrange" <[email protected]>
It is reasonably common to want to create an object, set a number of properties, register it in the hierarchy and then mark it as complete (if a user creatable type). This requires quite a lot of error prone, verbose, boilerplate code to achieve.
First a pair of functions object_set_props() / object_set_propv() are added which allow for a list of objects to be set in one single API call.
Then object_new_with_props() / object_new_with_propv() constructors are added which simplify the sequence of calls to create an object, populate properties, register in the object composition tree and mark the object complete, into a single method call.
Usage would be:
Error *err = NULL;
Object *obj;
obj = object_new_with_propv(TYPE_MEMORY_BACKEND_FILE,
object_get_objects_root(),
"hostmem0",
&err,
"share", "yes",
"mem-path", "/dev/shm/somefile",
"prealloc", "yes",
"size", "1048576",
NULL);Note all property values are passed in string form and will be parsed into their required data types, using normal QOM semantics for parsing from string format.
--- include/qemu/compiler.h | 6 ++ include/qom/object.h | 128 +++++++++++++++++++++++++++++++ qom/object.c | 109 ++++++++++++++++++++++++++ tests/.gitignore | 1 + tests/Makefile | 5 +- tests/check-qom-proplist.c | 186 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 tests/check-qom-proplist.c
include/qemu/compiler.h +6 -0
@@ -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
include/qom/object.h +128 -0
134 lines not on this page · raw message
qom/object.c +109 -0
121 lines not on this page · raw message
tests/.gitignore +1 -0
@@ -5,6 +5,7 @@ check-qjson check-qlist check-qstring check-qom-interface +check-qom-proplist rcutorture test-aio test-bitops
tests/Makefile +4 -1
@@ -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
tests/check-qom-proplist.c new file +186 -0
186 lines not on this page · raw message
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 04/14] scripts: Add support for path as argument of qom-tree
In reply to Andreas FärberFrom: Martin Cerveny <[email protected]>
Add processing of optional argument path as "tree base".
--- scripts/qmp/qom-tree | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
scripts/qmp/qom-tree +7 -2
@@ -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)
Signature · 1 line
2.1.4
[Qemu-devel] [PULL v3 03/14] tests: Use qtest_add_data_func() consistently
In reply to Andreas FärberReplace uses of g_test_add_data_func() for QTest test cases.
It is still valid to use it for any non-QTest test cases, which are not run for multiple target binaries.
--- tests/ahci-test.c | 9 ++------- tests/e1000-test.c | 4 ++-- tests/eepro100-test.c | 5 ++--- tests/endianness-test.c | 18 +++++++++--------- tests/pc-cpu-test.c | 13 ++++++------- tests/qom-test.c | 4 ++-- 6 files changed, 23 insertions(+), 30 deletions(-)
tests/ahci-test.c +2 -7
@@ -1486,7 +1486,6 @@ static void test_io_interface(gconstpointer opaque)static void create_ahci_io_test (enum IOMode type,enum AddrMode addr,enum BuffLen len,enum OffsetType offset) { -static const char *arch;char *name;AHCIIOTestOptions *opts =g_malloc (sizeof (AHCIIOTestOptions));
@@ -1495,17 +1494,13 @@ static void create_ahci_io_test(enum IOMode type, enum AddrMode addr, opts->io_type = type; opts->offset = offset; -if (!arch) { - arch =qtest_get_arch (); - } - - name =g_strdup_printf ("/%s/ahci/io/%s/%s/%s/%s" , arch, + name =g_strdup_printf ("ahci/io/%s/%s/%s/%s" , io_mode_str[type], addr_mode_str[addr], buff_len_str[len], offset_str[offset]); -g_test_add_data_func (name, opts, test_io_interface); +qtest_add_data_func (name, opts, test_io_interface);g_free (name); }
tests/e1000-test.c +2 -2
@@ -44,8 +44,8 @@ int main(int argc, char **argv)for (i =0 ; i <ARRAY_SIZE (models); i++) {char *path; - path =g_strdup_printf ("/%s/e1000/%s" ,qtest_get_arch (), models[i]); -g_test_add_data_func (path, models[i], test_device); + path =g_strdup_printf ("e1000/%s" , models[i]); +qtest_add_data_func (path, models[i], test_device); }return g_test_run ();
tests/eepro100-test.c +2 -3
@@ -54,9 +54,8 @@ int main(int argc, char **argv)for (i =0 ; i <ARRAY_SIZE (models); i++) {char *path; - path =g_strdup_printf ("/%s/eepro100/%s" , -qtest_get_arch (), models[i]); -g_test_add_data_func (path, models[i], test_device); + path =g_strdup_printf ("eepro100/%s" , models[i]); +qtest_add_data_func (path, models[i], test_device); }return g_test_run ();
tests/endianness-test.c +9 -9
@@ -296,17 +296,17 @@ int main(int argc, char **argv)if (strcmp (test_cases[i].arch, arch) !=0 ) {continue ; } - path =g_strdup_printf ("/%s/endianness/%s" , - arch, test_cases[i].machine); -g_test_add_data_func (path, &test_cases[i], test_endianness); + path =g_strdup_printf ("endianness/%s" , + test_cases[i].machine); +qtest_add_data_func (path, &test_cases[i], test_endianness); - path =g_strdup_printf ("/%s/endianness/split/%s" , - arch, test_cases[i].machine); -g_test_add_data_func (path, &test_cases[i], test_endianness_split); + path =g_strdup_printf ("endianness/split/%s" , + test_cases[i].machine); +qtest_add_data_func (path, &test_cases[i], test_endianness_split); - path =g_strdup_printf ("/%s/endianness/combine/%s" , - arch, test_cases[i].machine); -g_test_add_data_func (path, &test_cases[i], test_endianness_combine); + path =g_strdup_printf ("endianness/combine/%s" , + test_cases[i].machine); +qtest_add_data_func (path, &test_cases[i], test_endianness_combine); } ret =g_test_run ();
tests/pc-cpu-test.c +6 -7
@@ -75,7 +75,6 @@ static void test_pc_without_cpu_add(gconstpointer data)static void add_pc_test_cases (void ) { -const char *arch =qtest_get_arch ();QDict *response, *minfo;QList *list;const QListEntry *p;
@@ -119,15 +118,15 @@ static void add_pc_test_cases(void) (strcmp(mname, "pc-0.12") == 0) || (strcmp(mname, "pc-0.11") == 0) || (strcmp(mname, "pc-0.10") == 0)) { - path =g_strdup_printf ("/%s/cpu/%s/init/%ux%ux%u&maxcpus=%u" , - arch, mname, data->sockets, data->cores, + path =g_strdup_printf ("cpu/%s/init/%ux%ux%u&maxcpus=%u" , + mname, data->sockets, data->cores, data->threads, data->maxcpus); -g_test_add_data_func (path, data, test_pc_without_cpu_add); +qtest_add_data_func (path, data, test_pc_without_cpu_add); } else { - path =g_strdup_printf ("/%s/cpu/%s/add/%ux%ux%u&maxcpus=%u" , - arch, mname, data->sockets, data->cores, + path =g_strdup_printf ("cpu/%s/add/%ux%ux%u&maxcpus=%u" , + mname, data->sockets, data->cores, data->threads, data->maxcpus); -g_test_add_data_func (path, data, test_pc_with_cpu_add); +qtest_add_data_func (path, data, test_pc_with_cpu_add); } }qtest_end ();
tests/qom-test.c +2 -2
@@ -128,8 +128,8 @@ static void add_machine_test_cases(void)g_assert (qstr); mname =qstring_get_str (qstr);if (!is_blacklisted (arch, mname)) { - path =g_strdup_printf ("/%s/qom/%s" , arch, mname); -g_test_add_data_func (path, mname, test_machine); + path =g_strdup_printf ("qom/%s" , mname); +qtest_add_data_func (path, mname, test_machine); } }qtest_end ();
Signature · 1 line
2.1.4
Peter Maydell
AppliedQuoted 30 lines · Andreas Färber
Hello Peter,
This is my QOM (devices) patch queue. Please pull.
v3 reverts use of GLib macros in v2 and adds three commits.
Regards,
AndreasCc Peter Maydell <[email protected]>Cc Eduardo Habkost <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Daniel P. Berrange <[email protected]>Cc Markus Armbruster <[email protected]>The following changes since commit
8ffe756da0481233e1bd518b2b16489f51856292:Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2015-06-18' into staging (2015-06-18 13:32:39 +0100)
are available in the git repository at:
git://github.com/afaerber/qemu-cpu.gittags/qom-devices-for-peterfor you to fetch changes up to
daeba9699d41ad79e2f3d34acea9c85c5d67a2ac:qdev: Un-deprecate
qdev_init_nofail()(2015-06-19 19:14:32 +0200)----------------------------------------------------------------
QOM infrastructure fixes and device conversions
Quoted 8 lines
* 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 newqtest_add_data_func()consistently
Applied, thanks.
-- PMM