From: Pankaj Gupta <pagupta@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, marcandre.lureau@redhat.com,
eblake@redhat.com, xiaohli@redhat.com, pagupta@redhat.com
Subject: [Qemu-devel] [PATCH v2] chardev: Avoid adding duplicate chardev
Date: Tue, 29 Jan 2019 11:58:01 +0530 [thread overview]
Message-ID: <20190129062801.15799-1-pagupta@redhat.com> (raw)
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 exists"}}
# 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>
---
v1->v2
Correct error message - Eric
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 exists", id);
+ return NULL;
+ }
+
cc = char_get_class(ChardevBackendKind_str(backend->type), errp);
if (!cc) {
return NULL;
--
2.14.3
next reply other threads:[~2019-01-29 6:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-29 6:28 Pankaj Gupta [this message]
2019-01-29 8:34 ` [Qemu-devel] [PATCH v2] chardev: Avoid adding duplicate chardev Stefano Garzarella
2019-02-06 16:08 ` Marc-André Lureau
2019-02-06 16:29 ` Daniel P. Berrangé
2019-02-07 7:21 ` Pankaj Gupta
2019-02-07 9:11 ` Marc-André Lureau
2019-02-07 9:34 ` Daniel P. Berrangé
2019-02-07 10:13 ` Pankaj Gupta
2019-02-07 10:15 ` Marc-André Lureau
2019-02-07 10:24 ` Pankaj Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190129062801.15799-1-pagupta@redhat.com \
--to=pagupta@redhat.com \
--cc=eblake@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=xiaohli@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).