vl: Clean up user-creatable objects when exiting
Delete all user-creatable objects in /objects when exiting QEMU, so they
can perform cleanup actions.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20170824192315.5897-2-ehabkost@redhat.com>
Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Zack Cornelius <zack.cornelius@kove.net>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index d63c1c2..d23e11b 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -147,4 +147,12 @@
*/
void user_creatable_del(const char *id, Error **errp);
+/**
+ * user_creatable_cleanup:
+ *
+ * Delete all user-creatable objects and the user-creatable
+ * objects container.
+ */
+void user_creatable_cleanup(void);
+
#endif
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 3bb8959..6824a88 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -193,6 +193,11 @@
object_unparent(obj);
}
+void user_creatable_cleanup(void)
+{
+ object_unparent(object_get_objects_root());
+}
+
static void register_types(void)
{
static const TypeInfo uc_interface_info = {
diff --git a/vl.c b/vl.c
index 9e62e92..ad49314 100644
--- a/vl.c
+++ b/vl.c
@@ -4887,6 +4887,7 @@
audio_cleanup();
monitor_cleanup();
qemu_chr_cleanup();
+ user_creatable_cleanup();
/* TODO: unref root container, check all devices are ok */
return 0;