|
@@ -539,10 +539,28 @@ static BusState *qbus_find(const char *path, Error **errp)
|
|
return bus;
|
|
return bus;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void qdev_set_id(DeviceState *dev, const char *id)
|
|
|
|
+{
|
|
|
|
+ if (id) {
|
|
|
|
+ dev->id = id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (dev->id) {
|
|
|
|
+ object_property_add_child(qdev_get_peripheral(), dev->id,
|
|
|
|
+ OBJECT(dev), NULL);
|
|
|
|
+ } else {
|
|
|
|
+ static int anon_count;
|
|
|
|
+ gchar *name = g_strdup_printf("device[%d]", anon_count++);
|
|
|
|
+ object_property_add_child(qdev_get_peripheral_anon(), name,
|
|
|
|
+ OBJECT(dev), NULL);
|
|
|
|
+ g_free(name);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
|
|
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
|
|
{
|
|
{
|
|
DeviceClass *dc;
|
|
DeviceClass *dc;
|
|
- const char *driver, *path, *id;
|
|
|
|
|
|
+ const char *driver, *path;
|
|
DeviceState *dev;
|
|
DeviceState *dev;
|
|
BusState *bus = NULL;
|
|
BusState *bus = NULL;
|
|
Error *err = NULL;
|
|
Error *err = NULL;
|
|
@@ -591,21 +609,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
|
|
qdev_set_parent_bus(dev, bus);
|
|
qdev_set_parent_bus(dev, bus);
|
|
}
|
|
}
|
|
|
|
|
|
- id = qemu_opts_id(opts);
|
|
|
|
- if (id) {
|
|
|
|
- dev->id = id;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (dev->id) {
|
|
|
|
- object_property_add_child(qdev_get_peripheral(), dev->id,
|
|
|
|
- OBJECT(dev), NULL);
|
|
|
|
- } else {
|
|
|
|
- static int anon_count;
|
|
|
|
- gchar *name = g_strdup_printf("device[%d]", anon_count++);
|
|
|
|
- object_property_add_child(qdev_get_peripheral_anon(), name,
|
|
|
|
- OBJECT(dev), NULL);
|
|
|
|
- g_free(name);
|
|
|
|
- }
|
|
|
|
|
|
+ qdev_set_id(dev, qemu_opts_id(opts));
|
|
|
|
|
|
/* set properties */
|
|
/* set properties */
|
|
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
|
|
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
|