[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Chardev: delete the QemuOpts reserved in vm_config_groups

From: ????????????
Subject: Chardev: delete the QemuOpts reserved in vm_config_groups
Date: Sat, 6 Nov 2021 18:23:38 +0800

We have found that qemu cannot plug in the previously unplugged device.
        start qemu with the following command:
./qemu-system-x86_64 -enable-kvm -m 8192 -smp 16 \
   -object memory-backend-file,id=mem,size=8192M,mem-path=/dev/hugepages,share=on \
   -numa node,memdev=mem -mem-prealloc \
   -chardev socket,id=drive-virtio-disk1,path=/var/run/spdk/vhost_blk_socket-30dcf467-486a-45cf-b754-093bf5cf24d1,reconnect=10 \
   -device vhost-user-blk-pci,chardev=drive-virtio-disk1,num-queues=1,bus=pci.0,addr=0x5,id=virtio-disk1 \

(qemu) info chardev
serial0: filename=pty:/dev/pts/0
drive-virtio-disk1: filename=unix:
(qemu) device_del virtio-disk1
(qemu) chardev-remove drive-virtio-disk1
(qemu) info chardev
serial0: filename=pty:/dev/pts/0
(qemu) chardev-add socket,id=drive-virtio-disk1,path=/var/run/spdk/vhost_blk_socket-30dcf467-486a-45cf-b754-093bf5cf24d1,reconnect=10
device failed: Duplicate ID 'drive-virtio-disk1' for chardev Error: Parsing chardev args failed

The root cause of this issue is that the QemuOpts is still reserved in vm_config_groups list,
so qemu_opts_create will fail with the error above. So the QemuOpts should be removed when
invoking qmp_chardev_remove.

Signed-off-by: Zhoujian Yu <windyu@tencent.com>
Reviewed-by: Lei Wang <kaierwang@tencent.com>
Reviewed-by: Xun Ni <richardni@tencent.com>
Reviewed-by: Zhigang Lu <tonnylu@tencent.com>
 chardev/char.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index 398f09d..d2087bd 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -37,6 +37,7 @@
 #include "qemu/help_option.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
+#include "qemu/option_int.h"
 #include "qemu/id.h"
 #include "qemu/coroutine.h"
 #include "qemu/yank.h"
@@ -1159,6 +1160,7 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
 void qmp_chardev_remove(const char *id, Error **errp)
     Chardev *chr;
+   QemuOpts *opts;
     chr = qemu_chr_find(id);
     if (chr == NULL) {
@@ -1175,6 +1177,10 @@ void qmp_chardev_remove(const char *id, Error **errp)
+    /* delete the opts reserved in vm_config_groups list.  */
+    opts = qemu_opts_find(qemu_find_opts("chardev"), id);
+    if (opts)
+        qemu_opts_del(opts);
 void qmp_chardev_send_break(const char *id, Error **errp)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]