[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] chardev: delete QemuOpts when a chardev is removed
From: |
Paolo Bonzini |
Subject: |
[PATCH] chardev: delete QemuOpts when a chardev is removed |
Date: |
Tue, 23 Nov 2021 14:09:15 +0100 |
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>
---
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
- [PATCH] chardev: delete QemuOpts when a chardev is removed,
Paolo Bonzini <=