diff mbox

[v10,01/10] qmp: delete qemu opts when delete an object

Message ID 1441783481-17698-2-git-send-email-yanghy@cn.fujitsu.com
State New
Headers show

Commit Message

Yang Hongyang Sept. 9, 2015, 7:24 a.m. UTC
When delete an object, we need to delete the associated qemu opts,
otherwise, we can not add another object with the same name using
object_add.
The case happens when we start qemu with:
-object xxx,id=aa
then we delete this object with:
object_del aa
then add the object with:
object_add xxx,id=aa

QEMU will return error with Duplicate ID error.

Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
---
 qmp.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox

Patch

diff --git a/qmp.c b/qmp.c
index 403805a..c6b85dd 100644
--- a/qmp.c
+++ b/qmp.c
@@ -680,6 +680,7 @@  void qmp_object_del(const char *id, Error **errp)
 {
     Object *container;
     Object *obj;
+    QemuOpts *opts;
 
     container = object_get_objects_root();
     obj = object_resolve_path_component(container, id);
@@ -693,6 +694,9 @@  void qmp_object_del(const char *id, Error **errp)
         return;
     }
     object_unparent(obj);
+
+    opts = qemu_opts_find(qemu_find_opts_err("object", NULL), id);
+    qemu_opts_del(opts);
 }
 
 MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)