chardev: Avoid adding duplicate chardev
PATCH 1/1 chardev: Avoid adding duplicate chardev
Hotplugging existing char chardev with qmp, dereferences(removes) existing chardev. This patch avoids adding a chardev if a chardev with same id exists.
RH BZ 1660831:
# (host) ls -lt /tmp/helloworld*
srwxr-xr-x. /tmp/helloworld1
srwxr-xr-x. /tmp/helloworld2
Before this patch:
hotplug existed chardev(channel1) in qmp:
{"execute":"chardev-add","arguments":{"id":"charchannel1","backend":{"type":"socket", "data":{"addr":{"type":"unix", "data": {"path": "/tmp/helloworld1"}}}}}}
{"error": {"class": "GenericError", "desc": "attempt to add duplicate property 'charchannel1' to object (type 'container')"}}
# ls -lt /tmp/helloworld* srwxr-xr-x. 1 root root 0 Dec 19 16:39 /tmp/helloworld2
After this patch:
{"execute":"chardev-add","arguments":{"id":"charchannel1","backend":{"type":"socket", "data":{"addr":{"type":"unix", "data": {"path": "/tmp/helloworld1"}}}}}} {"error": {"class": "GenericError", "desc": "Chardev 'charchannel1' already exist"}}
# ls -lt /tmp/helloworld* srwxr-xr-x. 1 /tmp/helloworld1 srwxr-xr-x. 1 /tmp/helloworld2
--- chardev/char.c | 6 ++++++ 1 file changed, 6 insertions(+)
chardev/char.c +6 -0
@@ -985,6 +985,12 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,ChardevReturn *ret;Chardev *chr; + chr =qemu_chr_find (id); +if (chr) { +error_setg (errp,"Chardev '%s' already exist" , id); +return NULL ; + } + cc =char_get_class (ChardevBackendKind_str (backend->type), errp);if (!cc) {return NULL ;
Signature · 1 line
2.14.3
chardev/char.c ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, · line 990
Quoted 13 lines · Pankaj Gupta
Hotplugging existing char chardev with qmp, dereferences(removes) existing chardev. This patch avoids adding a chardev if a chardev with same id exists.
+++
b/chardev/char.cchardev/char.c +3
-0@@ -985,6 +985,12 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,ChardevReturn *ret;Chardev *chr; + chr =qemu_chr_find (id); +if (chr) { +error_setg (errp,"Chardev '%s' already exist" , id);
s/exist/exists/
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 15 lines · Pankaj Gupta
Quoted 11 lines
Hotplugging existing char chardev with qmp, dereferences(removes) existing chardev. This patch avoids adding a chardev if a chardev with same id exists.
+++
b/chardev/char.cchardev/char.c +0
-0@@ -985,6 +985,12 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, ChardevReturn *ret;Chardev *chr;
Quoted 5 lines
chardev/char.c ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, · line 990
Quoted 3 lines
chardev/char.c +3
-0+ chr =qemu_chr_find (id); +if (chr) { +error_setg (errp,"Chardev '%s' already exist" , id);s/exist/exists/
Will correct this in v2.
Thanks,
Pankaj