In order to create qdev objects via -late-object, we almost always have to specify the parent_bus which is usually created during machine init. Until we properly support two stage init, introduce a -late-object option that allows for creation of objects post-machine init.
Signed-off-by: Anthony Liguori <aligu...@us.ibm.com> --- qemu-config.c | 10 ++++++++++ qemu-options.hx | 12 ++++++++++++ vl.c | 14 +++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 8135430..cdaeb9f 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -623,6 +623,15 @@ QemuOptsList qemu_object_opts = { }, }; +QemuOptsList qemu_late_object_opts = { + .name = "late-object", + .implied_opt_name = "qom-type", + .head = QTAILQ_HEAD_INITIALIZER(qemu_late_object_opts.head), + .desc = { + { } + }, +}; + static QemuOptsList *vm_config_groups[32] = { &qemu_drive_opts, &qemu_chardev_opts, @@ -639,6 +648,7 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_boot_opts, &qemu_iscsi_opts, &qemu_object_opts, + &qemu_late_object_opts, NULL, }; diff --git a/qemu-options.hx b/qemu-options.hx index 20cfe1c..88b1466 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2751,6 +2751,18 @@ DEF("object", HAS_ARG, QEMU_OPTION_object, " '/objects' path.\n", QEMU_ARCH_ALL) +DEF("late-object", HAS_ARG, QEMU_OPTION_late_object, + "-late-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" + "\n" + " Late objects are made after machine\n" + " initialization so they can refer to objects created by\n" + " the machine init function.\n", + QEMU_ARCH_ALL) + HXCOMM This is the last statement. Insert new options before this line! STEXI @end table diff --git a/vl.c b/vl.c index ac25153..2c05d42 100644 --- a/vl.c +++ b/vl.c @@ -2293,13 +2293,14 @@ static int object_create(QemuOpts *opts, void *opaque) } obj = object_new(type); - if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) { - return -1; - } object_property_add_child(container_get(object_get_root(), "/objects"), id, obj, NULL); + if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) { + return -1; + } + return 0; } @@ -3250,6 +3251,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_object: opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); break; + case QEMU_OPTION_late_object: + opts = qemu_opts_parse(qemu_find_opts("late-object"), optarg, 1); + break; default: os_parse_cmd_args(popt->index, optarg); } @@ -3582,6 +3586,10 @@ int main(int argc, char **argv, char **envp) current_machine = machine; + if (qemu_opts_foreach(qemu_find_opts("late-object"), object_create, NULL, 0) != 0) { + exit(1); + } + /* init USB devices */ if (usb_enabled) { if (foreach_device_config(DEV_USB, usb_parse) < 0) -- 1.7.5.4