All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] chardev: Avoid adding duplicate chardev
@ 2019-01-22 14:41 Pankaj Gupta
  2019-01-22 22:25 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: Pankaj Gupta @ 2019-01-22 14:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcandre.lureau, pbonzini, xiaohli, pagupta

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
 
Reported-by: Xiaohui Li <xiaohli@redhat.com>
Signed-off-by: Pankaj Gupta <pagupta@redhat.com>
---
 chardev/char.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index ccba36bafb..cab0d3df16 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -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;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] chardev: Avoid adding duplicate chardev
  2019-01-22 14:41 [Qemu-devel] [PATCH] chardev: Avoid adding duplicate chardev Pankaj Gupta
@ 2019-01-22 22:25 ` Eric Blake
  2019-01-23 12:30   ` Pankaj Gupta
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2019-01-22 22:25 UTC (permalink / raw)
  To: Pankaj Gupta, qemu-devel; +Cc: marcandre.lureau, xiaohli, pbonzini

[-- Attachment #1: Type: text/plain, Size: 653 bytes --]

On 1/22/19 8:41 AM, Pankaj Gupta wrote:
> 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.c
> @@ -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/

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] chardev: Avoid adding duplicate chardev
  2019-01-22 22:25 ` Eric Blake
@ 2019-01-23 12:30   ` Pankaj Gupta
  0 siblings, 0 replies; 3+ messages in thread
From: Pankaj Gupta @ 2019-01-23 12:30 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel, marcandre lureau, pbonzini, xiaohli



> 
> On 1/22/19 8:41 AM, Pankaj Gupta wrote:
> > 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.c
> > @@ -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/

Will correct this in v2.

Thanks,
Pankaj

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-23 12:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-22 14:41 [Qemu-devel] [PATCH] chardev: Avoid adding duplicate chardev Pankaj Gupta
2019-01-22 22:25 ` Eric Blake
2019-01-23 12:30   ` Pankaj Gupta

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.