qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] chardev: delete QemuOpts when a chardev is removed


From: Marc-André Lureau
Subject: Re: [PATCH] chardev: delete QemuOpts when a chardev is removed
Date: Tue, 23 Nov 2021 17:30:49 +0400



On Tue, Nov 23, 2021 at 5:11 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
QEMU cannot add a chardev with the same id as a previously unplugged device.
The root cause of this issue is that the QemuOpts is still registered,
causing qemu_opts_create to fail.  Remove the QemuOpts when a character
device is removed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
 chardev/char.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index 0169d8dde4..d46b307830 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -277,6 +277,20 @@ static void char_init(Object *obj)

 }

+static void chr_unparent(Object *obj)
+{
+    const char *id;
+    QemuOpts *opts;
+
+    if (obj->parent == get_chardevs_root()) {
+        id = object_get_canonical_path_component(obj);
+        opts = qemu_opts_find(qemu_find_opts("chardev"), id);
+        if (opts) {
+            qemu_opts_del(opts);
+        }
+    }
+}
+
 static int null_chr_write(Chardev *chr, const uint8_t *buf, int len)
 {
     return len;
@@ -286,6 +300,7 @@ static void char_class_init(ObjectClass *oc, void *data)
 {
     ChardevClass *cc = CHARDEV_CLASS(oc);

+    oc->unparent = chr_unparent;
     cc->chr_write = null_chr_write;
     cc->chr_be_event = chr_be_event;
 }
--
2.33.1




--
Marc-André Lureau

reply via email to

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