On Tue, Nov 23, 2021 at 5:11 PM Paolo Bonzini <pbonz...@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 <pbonz...@redhat.com> > Reviewed-by: Marc-André Lureau <marcandre.lur...@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