From patchwork Tue Jan 29 06:28:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 10785535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36FD113BF for ; Tue, 29 Jan 2019 06:36:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 234D42AE96 for ; Tue, 29 Jan 2019 06:36:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1565C2B4A0; Tue, 29 Jan 2019 06:36:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B61502AE96 for ; Tue, 29 Jan 2019 06:36:40 +0000 (UTC) Received: from localhost ([127.0.0.1]:44161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goN0h-00088d-HO for patchwork-qemu-devel@patchwork.kernel.org; Tue, 29 Jan 2019 01:36:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goN03-0007pP-14 for qemu-devel@nongnu.org; Tue, 29 Jan 2019 01:35:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goN02-0005Q8-9S for qemu-devel@nongnu.org; Tue, 29 Jan 2019 01:35:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48640) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1goN02-0005Py-3c for qemu-devel@nongnu.org; Tue, 29 Jan 2019 01:35:58 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3121088E66 for ; Tue, 29 Jan 2019 06:28:10 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (dhcp-10-65-161-95.pnq.redhat.com [10.65.161.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 224CA17DD1; Tue, 29 Jan 2019 06:28:04 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Tue, 29 Jan 2019 11:58:01 +0530 Message-Id: <20190129062801.15799-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 29 Jan 2019 06:28:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] chardev: Avoid adding duplicate chardev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xiaohli@redhat.com, pbonzini@redhat.com, pagupta@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Pankaj Gupta Reviewed-by: Stefano Garzarella --- 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;